void test_mm(Mesh *mesh) { _F_ // testing a visualization of a vector-valued solution, where each component is on // a different mesh Mesh mesh0, mesh1, mesh2; mesh0.copy(*mesh); mesh1.copy(*mesh); mesh2.copy(*mesh); mesh0.refine_element(1, H3D_REFT_HEX_X); mesh1.refine_element(1, H3D_REFT_HEX_Y); mesh2.refine_element(1, H3D_REFT_HEX_Z); ExactSolution ex_sln0(&mesh0, exact_solution0); ExactSolution ex_sln1(&mesh1, exact_solution1); ExactSolution ex_sln2(&mesh2, exact_solution2); output.out(&ex_sln0, &ex_sln1, &ex_sln2, "U"); }
int main(int argc, char **args) { // Test variable. int success_test = 1; if (argc < 2) error("Not enough parameters."); // Load the mesh. Mesh mesh; H3DReader mloader; if (!mloader.load(args[1], &mesh)) error("Loading mesh file '%s'.", args[1]); // Initialize the space 1. Ord3 o1(2, 2, 2); H1Space space1(&mesh, bc_types, NULL, o1); // Initialize the space 2. Ord3 o2(4, 4, 4); H1Space space2(&mesh, bc_types, NULL, o2); WeakForm wf(2); wf.add_matrix_form(0, 0, bilinear_form_1_1<double, scalar>, bilinear_form_1_1<Ord, Ord>, HERMES_SYM); wf.add_matrix_form(0, 1, bilinear_form_1_2<double, scalar>, bilinear_form_1_2<Ord, Ord>, HERMES_SYM); wf.add_vector_form(0, linear_form_1<double, scalar>, linear_form_1<Ord, Ord>); wf.add_matrix_form(1, 1, bilinear_form_2_2<double, scalar>, bilinear_form_2_2<Ord, Ord>, HERMES_SYM); wf.add_vector_form(1, linear_form_2<double, scalar>, linear_form_2<Ord, Ord>); // Initialize the FE problem. bool is_linear = true; DiscreteProblem dp(&wf, Tuple<Space *>(&space1, &space2), is_linear); // Initialize the solver in the case of SOLVER_PETSC or SOLVER_MUMPS. initialize_solution_environment(matrix_solver, argc, args); // Set up the solver, matrix, and rhs according to the solver selection. SparseMatrix* matrix = create_matrix(matrix_solver); Vector* rhs = create_vector(matrix_solver); Solver* solver = create_linear_solver(matrix_solver, matrix, rhs); // Initialize the preconditioner in the case of SOLVER_AZTECOO. if (matrix_solver == SOLVER_AZTECOO) { ((AztecOOSolver*) solver)->set_solver(iterative_method); ((AztecOOSolver*) solver)->set_precond(preconditioner); // Using default iteration parameters (see solver/aztecoo.h). } // Assemble the linear problem. info("Assembling (ndof: %d).", Space::get_num_dofs(Tuple<Space *>(&space1, &space2))); dp.assemble(matrix, rhs); // Solve the linear system. If successful, obtain the solution. info("Solving."); Solution sln1(&mesh); Solution sln2(&mesh); if(solver->solve()) Solution::vector_to_solutions(solver->get_solution(), Tuple<Space *>(&space1, &space2), Tuple<Solution *>(&sln1, &sln2)); else error ("Matrix solver failed.\n"); ExactSolution ex_sln1(&mesh, exact_sln_fn_1); ExactSolution ex_sln2(&mesh, exact_sln_fn_2); // Calculate exact error. info("Calculating exact error."); Adapt *adaptivity = new Adapt(Tuple<Space *>(&space1, &space2), Tuple<ProjNormType>(HERMES_H1_NORM, HERMES_H1_NORM)); bool solutions_for_adapt = false; double err_exact = adaptivity->calc_err_exact(Tuple<Solution *>(&sln1, &sln2), Tuple<Solution *>(&ex_sln1, &ex_sln2), solutions_for_adapt, HERMES_TOTAL_ERROR_ABS); if (err_exact > EPS) // Calculated solution is not precise enough. success_test = 0; // Clean up. delete matrix; delete rhs; delete solver; delete adaptivity; // Properly terminate the solver in the case of SOLVER_PETSC or SOLVER_MUMPS. finalize_solution_environment(matrix_solver); if (success_test) { info("Success!"); return ERR_SUCCESS; } else { info("Failure!"); return ERR_FAILURE; } }
int main(int argc, char **args) { if (argc < 3) error("Not enough parameters."); char *type = args[1]; Mesh mesh; H3DReader mesh_loader; if (!mesh_loader.load(args[2], &mesh)) error("Loading mesh file '%s'\n", args[2]); if (strcmp(type, "sln") == 0) { // Testing on Exact solution which always gives the same value (values from Solution may differ by epsilon) ExactSolution ex_sln(&mesh, exact_solution); output.out(&ex_sln, "U"); } else if (strcmp(type, "vec-sln") == 0) { // Testing on Exact solution which always gives the same value (values from Solution may differ by epsilon) ExactSolution ex_sln(&mesh, exact_vec_solution); output.out(&ex_sln, "U"); } else if (strcmp(type, "3sln") == 0) { // Testing on Exact solution which always gives the same value (values from Solution may differ by epsilon) ExactSolution ex_sln0(&mesh, exact_solution0); ExactSolution ex_sln1(&mesh, exact_solution1); ExactSolution ex_sln2(&mesh, exact_solution2); output.out(&ex_sln0, &ex_sln1, &ex_sln2, "U"); } else if (strcmp(type, "ord") == 0) { Ord3 order; if (mesh.elements[1]->get_mode() == HERMES_MODE_HEX) order = Ord3(2, 3, 4); else if (mesh.elements[1]->get_mode() == HERMES_MODE_TET) order = Ord3(3); else error(HERMES_ERR_NOT_IMPLEMENTED); H1Space space(&mesh, bc_types, essential_bc_values, order); #if defined GMSH output.out_orders_gmsh(&space, "orders_gmsh"); #elif defined VTK output.out_orders_vtk(&space, "orders_vtk"); #endif } else if (strcmp(type, "bc") == 0) { #if defined GMSH output.out_bc_gmsh(&mesh); #elif defined VTK output.out_bc_vtk(&mesh); #endif } else if (strcmp(type, "mat") == 0) { StiffMatrix mat; test_mat(&mesh, mat); output.out(&mat); } else if (strcmp(type, "mm") == 0) { test_mm(&mesh); } return 0; }
int main(int argc, char **args) { set_verbose(false); if (argc < 3) error("Not enough parameters"); char *type = args[1]; Mesh mesh; Mesh3DReader mesh_loader; if (!mesh_loader.load(args[2], &mesh)) error("Loading mesh file '%s'\n", args[2]); if (strcmp(type, "sln") == 0) { // Testing on Exact solution which always gives the same value (values from Solution may differ by epsilon) ExactSolution ex_sln(&mesh, exact_solution); output.out(&ex_sln, "U"); } else if (strcmp(type, "vec-sln") == 0) { // Testing on Exact solution which always gives the same value (values from Solution may differ by epsilon) ExactSolution ex_sln(&mesh, exact_vec_solution); output.out(&ex_sln, "U"); } else if (strcmp(type, "3sln") == 0) { // Testing on Exact solution which always gives the same value (values from Solution may differ by epsilon) ExactSolution ex_sln0(&mesh, exact_solution0); ExactSolution ex_sln1(&mesh, exact_solution1); ExactSolution ex_sln2(&mesh, exact_solution2); output.out(&ex_sln0, &ex_sln1, &ex_sln2, "U"); } else if (strcmp(type, "ord") == 0) { H1ShapesetLobattoHex shapeset; H1Space space(&mesh, &shapeset); space.set_bc_types(bc_types); space.set_essential_bc_values(essential_bc_values); order3_t order; if (mesh.elements[1]->get_mode() == MODE_HEXAHEDRON) order = order3_t(2, 3, 4); else if (mesh.elements[1]->get_mode() == MODE_TETRAHEDRON) order = order3_t(3); else error(H3D_ERR_NOT_IMPLEMENTED); space.set_uniform_order(order); output.out_orders(&space, "orders"); } else if (strcmp(type, "bc") == 0) { output.out_bc(&mesh); } else if (strcmp(type, "mat") == 0) { StiffMatrix mat; test_mat(&mesh, mat); output.out(&mat); } else if (strcmp(type, "mm") == 0) { test_mm(&mesh); } return 0; }