int main(int argc, char* args[]) { // Load the mesh. Mesh mesh; MeshReaderH2D mloader; mloader.load("square.mesh", &mesh); // Perform initial mesh refinement. for (int i=0; i<INIT_REF; i++) mesh.refine_all_elements(); mesh.refine_by_criterion(criterion, INIT_REF_CRITERION); MeshView m; m.show(&mesh); // Set up the solver, matrix, and rhs according to the solver selection. SparseMatrix<double>* matrix = create_matrix<double>(matrix_solver_type); Vector<double>* rhs = create_vector<double>(matrix_solver_type); LinearSolver<double>* solver = create_linear_solver<double>(matrix_solver_type, matrix, rhs); ScalarView view1("Solution - Discontinuous Galerkin FEM", new WinGeom(900, 0, 450, 350)); ScalarView view2("Solution - Standard continuous FEM", new WinGeom(900, 400, 450, 350)); if(WANT_DG) { // Create an L2 space. L2Space<double> space_l2(&mesh, P_INIT); // Initialize the solution. Solution<double> sln_l2; // Initialize the weak formulation. CustomWeakForm wf_l2(BDY_BOTTOM_LEFT); // Initialize the FE problem. DiscreteProblem<double> dp_l2(&wf_l2, &space_l2); info("Assembling Discontinuous Galerkin (nelem: %d, ndof: %d).", mesh.get_num_active_elements(), space_l2.get_num_dofs()); dp_l2.assemble(matrix, rhs); // Solve the linear system. If successful, obtain the solution. info("Solving Discontinuous Galerkin."); if(solver->solve()) if(DG_SHOCK_CAPTURING) { FluxLimiter flux_limiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), &space_l2, true); flux_limiter.limit_second_orders_according_to_detector(); flux_limiter.limit_according_to_detector(); flux_limiter.get_limited_solution(&sln_l2); view1.set_title("Solution - limited Discontinuous Galerkin FEM"); } else Solution<double>::vector_to_solution(solver->get_sln_vector(), &space_l2, &sln_l2); else error ("Matrix solver failed.\n"); // View the solution. view1.show(&sln_l2); } if(WANT_FEM) { // Create an H1 space. H1Space<double> space_h1(&mesh, P_INIT); // Initialize the solution. Solution<double> sln_h1; // Initialize the weak formulation. CustomWeakForm wf_h1(BDY_BOTTOM_LEFT, false); // Initialize the FE problem. DiscreteProblem<double> dp_h1(&wf_h1, &space_h1); // Set up the solver, matrix, and rhs according to the solver selection. SparseMatrix<double>* matrix = create_matrix<double>(matrix_solver_type); Vector<double>* rhs = create_vector<double>(matrix_solver_type); LinearSolver<double>* solver = create_linear_solver<double>(matrix_solver_type, matrix, rhs); info("Assembling Continuous FEM (nelem: %d, ndof: %d).", mesh.get_num_active_elements(), space_h1.get_num_dofs()); dp_h1.assemble(matrix, rhs); // Solve the linear system. If successful, obtain the solution. info("Solving Continuous FEM."); if(solver->solve()) Solution<double>::vector_to_solution(solver->get_sln_vector(), &space_h1, &sln_h1); else error ("Matrix solver failed.\n"); // View the solution. view2.show(&sln_h1); } // Clean up. delete solver; delete matrix; delete rhs; // Wait for keyboard or mouse input. View::wait(); return 0; }
int main(int argc, char* args[]) { // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("square.mesh", mesh); // Perform initial mesh refinement. for (int i=0; i<INIT_REF; i++) mesh->refine_all_elements(); mesh->refine_by_criterion(criterion, INIT_REF_CRITERION); ScalarView view1("Solution - Discontinuous Galerkin FEM", new WinGeom(900, 0, 450, 350)); ScalarView view2("Solution - Standard continuous FEM", new WinGeom(900, 400, 450, 350)); if(WANT_DG) { // Create an L2 space. SpaceSharedPtr<double> space_l2(new L2Space<double>(mesh, P_INIT)); // Initialize the solution. MeshFunctionSharedPtr<double> sln_l2(new Solution<double>); // Initialize the weak formulation. CustomWeakForm wf_l2(BDY_BOTTOM_LEFT); // Initialize the FE problem. DiscreteProblem<double> dp_l2(&wf_l2, space_l2); dp_l2.set_linear(); // Initialize linear solver. Hermes::Hermes2D::LinearSolver<double> linear_solver(&dp_l2); Hermes::Mixins::Loggable::Static::info("Assembling Discontinuous Galerkin (nelem: %d, ndof: %d).", mesh->get_num_active_elements(), space_l2->get_num_dofs()); // Solve the linear system. If successful, obtain the solution. Hermes::Mixins::Loggable::Static::info("Solving Discontinuous Galerkin."); try { linear_solver.solve(); if(DG_SHOCK_CAPTURING) { FluxLimiter flux_limiter(FluxLimiter::Kuzmin, linear_solver.get_sln_vector(), space_l2, true); flux_limiter.limit_second_orders_according_to_detector(); flux_limiter.limit_according_to_detector(); flux_limiter.get_limited_solution(sln_l2); view1.set_title("Solution - limited Discontinuous Galerkin FEM"); } else Solution<double>::vector_to_solution(linear_solver.get_sln_vector(), space_l2, sln_l2); // View the solution. view1.show(sln_l2); } catch(std::exception& e) { std::cout << e.what(); } } if(WANT_FEM) { // Create an H1 space. SpaceSharedPtr<double> space_h1(new H1Space<double>(mesh, P_INIT)); // Initialize the solution. MeshFunctionSharedPtr<double> sln_h1(new Solution<double>); // Initialize the weak formulation. CustomWeakForm wf_h1(BDY_BOTTOM_LEFT, false); // Initialize the FE problem. DiscreteProblem<double> dp_h1(&wf_h1, space_h1); dp_h1.set_linear(); Hermes::Mixins::Loggable::Static::info("Assembling Continuous FEM (nelem: %d, ndof: %d).", mesh->get_num_active_elements(), space_h1->get_num_dofs()); // Initialize linear solver. Hermes::Hermes2D::LinearSolver<double> linear_solver(&dp_h1); // Solve the linear system. If successful, obtain the solution. Hermes::Mixins::Loggable::Static::info("Solving Continuous FEM."); try { linear_solver.solve(); Solution<double>::vector_to_solution(linear_solver.get_sln_vector(), space_h1, sln_h1); // View the solution. view2.show(sln_h1); } catch(std::exception& e) { std::cout << e.what(); } } // Wait for keyboard or mouse input. View::wait(); return 0; }