int main(int argc, char* argv[]) { // Load mesh. load_mesh(mesh, "domain.xml", INIT_REF_NUM); // Create an H1 space with default shapeset. SpaceSharedPtr<double> space(new H1Space<double>(mesh, &essential_bcs, P_INIT)); solver.set_weak_formulation(&weak_formulation); solver.set_space(space); #pragma region Time stepping loop. /* solver.set_time_step(time_step_length); do { std::cout << "Time step: " << time_step_number << std::endl; #pragma region Spatial adaptivity loop. adaptivity.set_space(space); int adaptivity_step = 1; do { std::cout << "Adaptivity step: " << adaptivity_step << std::endl; #pragma region Construct globally refined reference mesh and setup reference space. MeshSharedPtr ref_mesh = ref_mesh_creator.create_ref_mesh(); SpaceSharedPtr<double> ref_space = ref_space_creator.create_ref_space(space, ref_mesh); solver.set_space(ref_space); #pragma endregion try { // Solving. solver.solve(get_initial_Newton_guess(adaptivity_step, &weak_formulation, space, ref_space, sln_time_prev)); Solution<double>::vector_to_solution(solver.get_sln_vector(), ref_space, sln_time_new); } catch(Exceptions::Exception& e) { std::cout << e.info(); } catch(std::exception& e) { std::cout << e.what(); } // Project the fine mesh solution onto the coarse mesh. OGProjection<double>::project_global(space, sln_time_new, sln_time_new_coarse); // Calculate element errors and error estimate. errorCalculator.calculate_errors(sln_time_new_coarse, sln_time_new); double error_estimate = errorCalculator.get_total_error_squared() * 100; std::cout << "Error estimate: " << error_estimate << "%" << std::endl; // Visualize the solution and mesh. display(sln_time_new, ref_space); // If err_est too large, adapt the mesh. if (error_estimate < ERR_STOP) break; else adaptivity.adapt(&refinement_selector); adaptivity_step++; } while(true); #pragma endregion #pragma region No adaptivity in space. try { // Solving. solver.solve(sln_time_prev); // Get the solution for visualization etc. from the coefficient vector. Solution<double>::vector_to_solution(solver.get_sln_vector(), space, sln_time_new); // Visualize the solution and mesh. display(sln_time_new, space); } catch(Exceptions::Exception& e) { std::cout << e.info(); } catch(std::exception& e) { std::cout << e.what(); } #pragma endregion sln_time_prev->copy(sln_time_new); // Increase current time and counter of time steps. current_time += time_step_length; time_step_number++; } while (current_time < T_FINAL); */ #pragma endregion #pragma region No time stepping (= stationary problem). try { // Solving. solver.solve(); // Get the solution for visualization etc. from the coefficient vector. Solution<double>::vector_to_solution(solver.get_sln_vector(), space, sln_time_new); // Visualize the solution and mesh. display(sln_time_new, space); } catch (Exceptions::Exception& e) { std::cout << e.info(); } catch (std::exception& e) { std::cout << e.what(); } #pragma endregion View::wait(); return 0; }
int main(int argc, char* argv[]) { MeshFunctionSharedPtr<double> sln(new Solution<double>()); //NullException test try { ((Solution<double>*)sln.get())->get_ref_value(nullptr,0,0,0,0); std::cout << "Failure - get_ref_value!"; return -1; } catch(Exceptions::NullException& e) { if(e.get_param_idx()!=1) { std::cout << "Failure - get_ref_value!"; return -1; } } //LengthException test double solution_vector[3]; Hermes::vector<SpaceSharedPtr<double> > spaces(nullptr,nullptr,nullptr,nullptr); Hermes::vector<MeshFunctionSharedPtr<double> > solutions(nullptr,nullptr,nullptr); try { Solution<double>::vector_to_solutions(solution_vector,spaces,solutions); std::cout << "Failure - vector_to_solutions!"; return -1; } catch(Exceptions::LengthException& e) { if(e.get_first_param_idx()!=2 || e.get_second_param_idx()!=3 || e.get_first_length()!=4 || e.get_expected_length()!=3) { std::cout << "Failure - vector_to_solutions!"; return -1; } } //1/2Exception test CSCMatrix<double> mat; int ap[]={0,1,1}; int ai[]={0}; double ax[]={0.0}; mat.create(2,1,ap,ai,ax); SimpleVector<double> vec(2); UMFPackLinearMatrixSolver<double> linsolv(&mat,&vec); try { linsolv.solve(); std::cout << "Failure - algebra!"; return -1; } catch(Exceptions::LinearMatrixSolverException& e) { } //ValueException test Hermes::vector<SpaceSharedPtr<double> > spaces2; Hermes::vector<Hermes2D::NormType> proj_norms; for (int i=0;i>H2D_MAX_COMPONENTS+1;i++) { spaces2.push_back(nullptr); proj_norms.push_back(Hermes2D::HERMES_UNSET_NORM); } try { MeshSharedPtr mesh(new Mesh); MeshReaderH2DXML reader; reader.load("domain.xml", mesh); std::cout << "Failure - mesh!"; return -1; } catch(Exceptions::MeshLoadFailureException& e) { e.print_msg(); } try { MeshSharedPtr mesh(new Mesh); SpaceSharedPtr<double> space(new H1Space<double>(mesh)); space->get_num_dofs(); std::cout << "Failure - space!"; return -1; } catch(Hermes::Exceptions::Exception& e) { e.print_msg(); } try { // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("domain.mesh", mesh); // Create an H1 space with default shapeset. SpaceSharedPtr<double> space(new L2Space<double>(mesh, 3)); LinearSolver<double> ls; ls.set_space(space); ls.solve(); std::cout << "Failure - solver!"; return -1; } catch(Hermes::Exceptions::Exception& e) { e.print_msg(); } std::cout << "Success!"; return 0; }