int main(int argc, char **argv) { int res = ERR_SUCCESS; set_verbose(false); if (argc < 2) error("Not enough parameters"); printf("* Loading mesh '%s'\n", argv[1]); Mesh mesh; Mesh3DReader mesh_loader; if (!mesh_loader.load(argv[1], &mesh)) error("loading mesh file '%s'\n", argv[1]); H1ShapesetLobattoHex shapeset; #if defined NONLIN1 order3_t order(1, 1, 1); #else order3_t order(2, 2, 2); #endif printf("* Setting the space up\n"); H1Space space(&mesh, &shapeset); space.set_bc_types(bc_types); space.set_essential_bc_values(essential_bc_values); printf(" - Setting uniform order to (%d, %d, %d)\n", order.x, order.y, order.z); space.set_uniform_order(order); int ndofs = space.assign_dofs(); printf(" - Number of DOFs: %d\n", ndofs); #if defined NONLIN2 // do L2 projection of zero function WeakForm proj_wf; proj_wf.add_matrix_form(biproj_form<double, scalar>, biproj_form<ord_t, ord_t>, SYM); proj_wf.add_vector_form(liproj_form<double, scalar>, liproj_form<ord_t, ord_t>); LinearProblem lp(&proj_wf, &space); #ifdef WITH_UMFPACK UMFPackMatrix m; UMFPackVector v; UMFPackLinearSolver sl(&m, &v); #elif defined WITH_MUMPS MumpsMatrix m; MumpsVector v; MumpsSolver sl(&m, &v); #endif lp.assemble(&m, &v); sl.solve(); double *ps = sl.get_solution(); #endif printf("* Calculating a solution\n"); WeakForm wf(1); wf.add_matrix_form(0, 0, jacobi_form<double, scalar>, jacobi_form<ord_t, ord_t>, UNSYM); wf.add_vector_form(0, resid_form<double, scalar>, resid_form<ord_t, ord_t>); DiscreteProblem dp(&wf, &space); NoxSolver solver(&dp); #if defined NONLIN2 solver.set_init_sln(ps); #endif solver.set_conv_iters(10); printf(" - solving..."); fflush(stdout); Timer solve_timer; solve_timer.start(); bool solved = solver.solve(); solve_timer.stop(); if (solved) { printf(" done in %s (%lf secs), iters = %d\n", solve_timer.get_human_time(), solve_timer.get_seconds(), solver.get_num_iters()); double *s = solver.get_solution(); Solution sln(&mesh); sln.set_coeff_vector(&space, s); Solution ex_sln(&mesh); #ifdef NONLIN1 ex_sln.set_const(100.0); #else ex_sln.set_exact(exact_solution); #endif double h1_err = h1_error(&sln, &ex_sln); printf(" - H1 error norm: % le\n", h1_err); double l2_err = l2_error(&sln, &ex_sln); printf(" - L2 error norm: % le\n", l2_err); if (h1_err > EPS || l2_err > EPS) { // calculated solution is not enough precise res = ERR_FAILURE; } #ifdef OUTPUT_DIR printf("* Output\n"); // output const char *of_name = OUTPUT_DIR "/solution.vtk"; FILE *ofile = fopen(of_name, "w"); if (ofile != NULL) { VtkOutputEngine output(ofile); output.out(&sln, "Uh", FN_VAL_0); fclose(ofile); } else { warning("Cann not open '%s' for writing.", of_name); } #endif } else res = ERR_FAILURE; return res; }
int main(int argc, char **args) { // Test variable. int success_test = 1; if (argc < 3) 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 according to the // command-line parameters passed. int o = 4; sscanf(args[2], "%d", &o); H1Space space(&mesh, bc_types, NULL, o); // Initialize the weak formulation. WeakForm wf; wf.add_matrix_form(bilinear_form<double, scalar>, bilinear_form<Ord, Ord>, HERMES_SYM); wf.add_matrix_form_surf(bilinear_form_surf<double, scalar>, bilinear_form_surf<Ord, Ord>); wf.add_vector_form(linear_form<double, scalar>, linear_form<Ord, Ord>); wf.add_vector_form_surf(linear_form_surf<double, scalar>, linear_form_surf<Ord, Ord>); // Initialize the FE problem. bool is_linear = true; DiscreteProblem dp(&wf, &space, is_linear); // 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(&space)); dp.assemble(matrix, rhs); // Solve the linear system. If successful, obtain the solution. info("Solving."); Solution sln(&mesh); if(solver->solve()) Solution::vector_to_solution(solver->get_solution(), &space, &sln); else error ("Matrix solver failed.\n"); ExactSolution ex_sln(&mesh, exact_solution); // Calculate exact error. info("Calculating exact error."); Adapt *adaptivity = new Adapt(&space, HERMES_H1_NORM); bool solutions_for_adapt = false; double err_exact = adaptivity->calc_err_exact(&sln, &ex_sln, 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; if (success_test) { info("Success!"); return ERR_SUCCESS; } else { info("Failure!"); return ERR_FAILURE; } }
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. #if defined NONLIN1 Ord3 order(1, 1, 1); #else Ord3 order(2, 2, 2); #endif H1Space space(&mesh, bc_types, essential_bc_values, order); #if defined NONLIN2 // Do L2 projection of zero function. WeakForm proj_wf; proj_wf.add_matrix_form(biproj_form<double, scalar>, biproj_form<Ord, Ord>, HERMES_SYM); proj_wf.add_vector_form(liproj_form<double, scalar>, liproj_form<Ord, Ord>); bool is_linear = true; DiscreteProblem lp(&proj_wf, &space, is_linear); // 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_proj = create_linear_solver(matrix_solver, matrix, rhs); // Initialize the preconditioner in the case of SOLVER_AZTECOO. if (matrix_solver == SOLVER_AZTECOO) { ((AztecOOSolver*) solver_proj)->set_solver(iterative_method); ((AztecOOSolver*) solver_proj)->set_precond(preconditioner); // Using default iteration parameters (see solver/aztecoo.h). } // Assemble the linear problem. info("Assembling (ndof: %d).", Space::get_num_dofs(&space)); lp.assemble(matrix, rhs); // Solve the linear system. info("Solving."); if(!solver_proj->solve()) error ("Matrix solver failed.\n"); delete matrix; delete rhs; #endif // Initialize the weak formulation. WeakForm wf(1); wf.add_matrix_form(0, 0, jacobi_form<double, scalar>, jacobi_form<Ord, Ord>, HERMES_NONSYM); wf.add_vector_form(0, resid_form<double, scalar>, resid_form<Ord, Ord>); // Initialize the FE problem. #if defined NONLIN2 is_linear = false; #else bool is_linear = false; #endif DiscreteProblem dp(&wf, &space, is_linear); NoxSolver solver(&dp); #if defined NONLIN2 solver.set_init_sln(solver_proj->get_solution()); delete solver_proj; #endif solver.set_conv_iters(10); info("Solving."); Solution sln(&mesh); if(solver.solve()) Solution::vector_to_solution(solver.get_solution(), &space, &sln); else error ("Matrix solver failed.\n"); Solution ex_sln(&mesh); #ifdef NONLIN1 ex_sln.set_const(100.0); #else ex_sln.set_exact(exact_solution); #endif // Calculate exact error. info("Calculating exact error."); Adapt *adaptivity = new Adapt(&space, HERMES_H1_NORM); bool solutions_for_adapt = false; double err_exact = adaptivity->calc_err_exact(&sln, &ex_sln, solutions_for_adapt, HERMES_TOTAL_ERROR_ABS); if (err_exact > EPS) // Calculated solution is not precise enough. success_test = 0; if (success_test) { info("Success!"); return ERR_SUCCESS; } else { info("Failure!"); return ERR_FAILURE; } }
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. int mx = 2; Ord3 order(mx, mx, mx); H1Space space(&mesh, bc_types, NULL, order); #if defined LIN_DIRICHLET || defined NLN_DIRICHLET space.set_essential_bc_values(essential_bc_values); #endif // Initialize the weak formulation. WeakForm wf; wf.add_vector_form(form_0<double, scalar>, form_0<Ord, Ord>); #if defined LIN_NEUMANN || defined LIN_NEWTON wf.add_vector_form_surf(form_0_surf<double, scalar>, form_0_surf<Ord, Ord>); #endif #if defined LIN_DIRICHLET || defined NLN_DIRICHLET // preconditioner wf.add_matrix_form(precond_0_0<double, scalar>, precond_0_0<Ord, Ord>, HERMES_SYM); #endif // Initialize the FE problem. DiscreteProblem fep(&wf, &space); #if defined LIN_DIRICHLET || defined NLN_DIRICHLET // use ML preconditioner to speed-up things MlPrecond pc("sa"); pc.set_param("max levels", 6); pc.set_param("increasing or decreasing", "decreasing"); pc.set_param("aggregation: type", "MIS"); pc.set_param("coarse: type", "Amesos-KLU"); #endif NoxSolver solver(&fep); #if defined LIN_DIRICHLET || defined NLN_DIRICHLET // solver.set_precond(&pc); #endif info("Solving."); Solution sln(&mesh); if(solver.solve()) Solution::vector_to_solution(solver.get_solution(), &space, &sln); else error ("Matrix solver failed.\n"); Solution ex_sln(&mesh); ex_sln.set_exact(exact_solution); // Calculate exact error. info("Calculating exact error."); Adapt *adaptivity = new Adapt(&space, HERMES_H1_NORM); bool solutions_for_adapt = false; double err_exact = adaptivity->calc_err_exact(&sln, &ex_sln, solutions_for_adapt, HERMES_TOTAL_ERROR_ABS); if (err_exact > EPS) // Calculated solution is not precise enough. success_test = 0; if (success_test) { info("Success!"); return ERR_SUCCESS; } else { info("Failure!"); return ERR_FAILURE; } }
int main(int argc, char **argv) { int res = ERR_SUCCESS; #ifdef WITH_PETSC PetscInitialize(&argc, &argv, (char *) PETSC_NULL, PETSC_NULL); #endif set_verbose(false); if (argc < 3) error("Not enough parameters"); printf("* Loading mesh '%s'\n", argv[1]); Mesh mesh; H3DReader mesh_loader; if (!mesh_loader.load(argv[1], &mesh)) error("Loading mesh file '%s'\n", argv[1]); int o; sscanf(argv[2], "%d", &o); printf(" - Setting uniform order to %d\n", o); printf("* Setting the space up\n"); H1Space space(&mesh, bc_types, NULL, o); int ndofs = space.assign_dofs(); printf(" - Number of DOFs: %d\n", ndofs); printf("* Calculating a solution\n"); #if defined WITH_UMFPACK UMFPackMatrix mat; UMFPackVector rhs; UMFPackLinearSolver solver(&mat, &rhs); #elif defined WITH_PARDISO PardisoMatrix mat; PardisoVector rhs; PardisoLinearSolver solver(&mat, &rhs); #elif defined WITH_PETSC PetscMatrix mat; PetscVector rhs; PetscLinearSolver solver(&mat, &rhs); #elif defined WITH_MUMPS MumpsMatrix mat; MumpsVector rhs; MumpsSolver solver(&mat, &rhs); #endif WeakForm wf; wf.add_matrix_form(FORM_CB(bilinear_form), SYM); wf.add_vector_form(FORM_CB(linear_form)); DiscreteProblem dp(&wf, &space, true); // assemble stiffness matrix Timer assemble_timer("Assembling stiffness matrix"); assemble_timer.start(); dp.assemble(&mat, &rhs); assemble_timer.stop(); // solve the stiffness matrix Timer solve_timer("Solving stiffness matrix"); solve_timer.start(); bool solved = solver.solve(); solve_timer.stop(); // output the measured values printf("%s: %s (%lf secs)\n", assemble_timer.get_name(), assemble_timer.get_human_time(), assemble_timer.get_seconds()); printf("%s: %s (%lf secs)\n", solve_timer.get_name(), solve_timer.get_human_time(), solve_timer.get_seconds()); // mat.dump(stdout, "a"); // rhs.dump(stdout, "b"); if (solved) { Solution sln(&mesh); sln.set_coeff_vector(&space, solver.get_solution() ); ExactSolution ex_sln(&mesh, exact_solution); // norm // double h1_sln_norm = h1_norm(&sln); double h1_err_norm = h1_error(&sln, &ex_sln); // printf(" - H1 solution norm: % le\n", h1_sln_norm); printf(" - H1 error norm: % le\n", h1_err_norm); // double l2_sln_norm = l2_norm(&sln); // double l2_err_norm = l2_error(&sln, &ex_sln); // printf(" - L2 solution norm: % le\n", l2_sln_norm); // printf(" - L2 error norm: % le\n", l2_err_norm); // if (h1_err_norm > EPS || l2_err_norm > EPS) { // calculated solution is not enough precise // res = ERR_FAILURE; // } #ifdef AOUTPUT_DIR // output const char *of_name = OUTPUT_DIR "/solution.pos"; FILE *ofile = fopen(of_name, "w"); if (ofile != NULL) { DiffFilter eh(&sln, &ex_sln); // DiffFilter eh_dx(&sln, &ex_sln, FN_DX, FN_DX); // DiffFilter eh_dy(&sln, &ex_sln, FN_DY, FN_DY); // DiffFilter eh_dz(&sln, &ex_sln, FN_DZ, FN_DZ); GmshOutputEngine output(ofile); output.out(&sln, "Uh"); // output.out(&sln, "Uh dx", FN_DX_0); // output.out(&sln, "Uh dy", FN_DY_0); // output.out(&sln, "Uh dz", FN_DZ_0); output.out(&eh, "Eh"); // output.out(&eh_dx, "Eh dx"); // output.out(&eh_dy, "Eh dy"); // output.out(&eh_dz, "Eh dz"); output.out(&ex_sln, "U"); // output.out(&ex_sln, "U dx", FN_DX_0); // output.out(&ex_sln, "U dy", FN_DY_0); // output.out(&ex_sln, "U dz", FN_DZ_0); fclose(ofile); } else { warning("Can not open '%s' for writing.", of_name); } #endif } #ifdef WITH_PETSC mat.free(); rhs.free(); PetscFinalize(); #endif return res; }
int main(int argc, char **argv) { int res = ERR_SUCCESS; #ifdef WITH_PETSC PetscInitialize(&argc, &argv, (char *) PETSC_NULL, PETSC_NULL); #endif set_verbose(false); if (argc < 3) error("Not enough parameters"); HcurlShapesetLobattoHex shapeset; printf("* Loading mesh '%s'\n", argv[1]); Mesh mesh; Mesh3DReader mesh_loader; if (!mesh_loader.load(argv[1], &mesh)) error("Loading mesh file '%s'\n", argv[1]); printf("* Setting the space up\n"); HcurlSpace space(&mesh, &shapeset); space.set_bc_types(bc_types); int order; sscanf(argv[2], "%d", &order); int dir_x = order, dir_y = order, dir_z = order; order3_t o(dir_x, dir_y, dir_z); printf(" - Setting uniform order to (%d, %d, %d)\n", o.x, o.y ,o.z); space.set_uniform_order(o); int ndofs = space.assign_dofs(); printf(" - Number of DOFs: %d\n", ndofs); printf("* Calculating a solution\n"); #if defined WITH_UMFPACK UMFPackMatrix mat; UMFPackVector rhs; UMFPackLinearSolver solver(&mat, &rhs); #elif defined WITH_PARDISO PardisoMatrix mat; PardisoVector rhs; PardisoSolver solver(&mat, &rhs); #elif defined WITH_PETSC PetscMatrix mat; PetscVector rhs; PetscLinearSolver solver(&mat, &rhs); #elif defined WITH_MUMPS MumpsMatrix mat; MumpsVector rhs; MumpsSolver solver(&mat, &rhs); #endif WeakForm wf; wf.add_matrix_form(bilinear_form<double, scalar>, bilinear_form<ord_t, ord_t>, SYM); wf.add_matrix_form_surf(bilinear_form_surf<double, scalar>, bilinear_form_surf<ord_t, ord_t>); wf.add_vector_form(linear_form<double, scalar>, linear_form<ord_t, ord_t>); wf.add_vector_form_surf(linear_form_surf<double, scalar>, linear_form_surf<ord_t, ord_t>); LinearProblem lp(&wf, &space); // assemble stiffness matrix Timer assemble_timer("Assembling stiffness matrix"); assemble_timer.start(); lp.assemble(&mat, &rhs); assemble_timer.stop(); // solve the stiffness matrix Timer solve_timer("Solving stiffness matrix"); solve_timer.start(); bool solved = solver.solve(); solve_timer.stop(); //#ifdef OUTPUT_DIR mat.dump(stdout, "a"); rhs.dump(stdout, "b"); //#endif if (solved) { scalar *s = solver.get_solution(); Solution sln(&mesh); sln.set_coeff_vector(&space, s); printf("* Solution:\n"); for (int i = 1; i <= ndofs; i++) { printf(" x[% 3d] = " SCALAR_FMT "\n", i, SCALAR(s[i])); } // output the measured values printf("%s: %s (%lf secs)\n", assemble_timer.get_name(), assemble_timer.get_human_time(), assemble_timer.get_seconds()); printf("%s: %s (%lf secs)\n", solve_timer.get_name(), solve_timer.get_human_time(), solve_timer.get_seconds()); // norm ExactSolution ex_sln(&mesh, exact_solution); double hcurl_sln_norm = hcurl_norm(&sln); double hcurl_err_norm = hcurl_error(&sln, &ex_sln); printf(" - Hcurl solution norm: % le\n", hcurl_sln_norm); printf(" - Hcurl error norm: % le\n", hcurl_err_norm); double l2_sln_norm = l2_norm_hcurl(&sln); double l2_err_norm = l2_error_hcurl(&sln, &ex_sln); printf(" - L2 solution norm: % le\n", l2_sln_norm); printf(" - L2 error norm: % le\n", l2_err_norm); if (hcurl_err_norm > EPS || l2_err_norm > EPS) { // calculated solution is not enough precise res = ERR_FAILURE; } #if 0 //def OUTPUT_DIR // output printf("starting output\n"); const char *of_name = OUTPUT_DIR "/solution.vtk"; FILE *ofile = fopen(of_name, "w"); if (ofile != NULL) { ExactSolution ex_sln(&mesh, exact_solution_0, exact_solution_1, exact_solution_2); RealPartFilter real_sln(&mesh, &sln, FN_VAL); ImagPartFilter imag_sln(&mesh, &sln, FN_VAL); DiffFilter eh(&mesh, &sln, &ex_sln); DiffFilter eh_dx(&mesh, &sln, &ex_sln, FN_DX, FN_DX); // DiffFilter eh_dy(&mesh, &sln, &ex_sln, FN_DY, FN_DY); // DiffFilter eh_dz(&mesh, &sln, &ex_sln, FN_DZ, FN_DZ); // GmshOutputEngine output(ofile); VtkOutputEngine output(ofile); output.out(&real_sln, "real_Uh", FN_VAL); output.out(&imag_sln, "imag_Uh", FN_VAL); output.out(&real_sln, "real_Uh_0", FN_VAL_0); output.out(&real_sln, "real_Uh_1", FN_VAL_1); output.out(&real_sln, "real_Uh_2", FN_VAL_2); output.out(&imag_sln, "imag_Uh_0", FN_VAL_0); output.out(&imag_sln, "imag_Uh_1", FN_VAL_1); output.out(&imag_sln, "imag_Uh_2", FN_VAL_2); fclose(ofile); } else { warning("Can not open '%s' for writing.", of_name); } #endif } #ifdef WITH_PETSC mat.free(); rhs.free(); PetscFinalize(); #endif return res; }
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) { int res = ERR_SUCCESS; #ifdef WITH_PETSC PetscInitialize(&argc, &args, (char *) PETSC_NULL, PETSC_NULL); #endif set_verbose(false); TRACE_START("trace.txt"); DEBUG_OUTPUT_ON; SET_VERBOSE_LEVEL(0); if (argc < 5) error("Not enough parameters"); sscanf(args[2], "%d", &m); sscanf(args[3], "%d", &n); sscanf(args[4], "%d", &o); printf("* Loading mesh '%s'\n", args[1]); Mesh mesh; Mesh3DReader mloader; if (!mloader.load(args[1], &mesh)) error("Loading mesh file '%s'\n", args[1]); H1ShapesetLobattoHex shapeset; printf("* Setting the space up\n"); H1Space space(&mesh, &shapeset); space.set_bc_types(bc_types); int mx = maxn(4, m, n, o, 4); order3_t order(mx, mx, mx); // order3_t order(1, 1, 1); // order3_t order(m, n, o); printf(" - Setting uniform order to (%d, %d, %d)\n", mx, mx, mx); space.set_uniform_order(order); int ndofs = space.assign_dofs(); printf(" - Number of DOFs: %d\n", ndofs); printf("* Calculating a solution\n"); #if defined WITH_UMFPACK UMFPackMatrix mat; UMFPackVector rhs; UMFPackLinearSolver solver(&mat, &rhs); #elif defined WITH_PARDISO PardisoMatrix mat; PardisoVector rhs; PardisoLinearSolver solver(&mat, &rhs); #elif defined WITH_PETSC PetscMatrix mat; PetscVector rhs; PetscLinearSolver solver(&mat, &rhs); #elif defined WITH_MUMPS MumpsMatrix mat; MumpsVector rhs; MumpsSolver solver(&mat, &rhs); #endif WeakForm wf; wf.add_matrix_form(bilinear_form<double, scalar>, bilinear_form<ord_t, ord_t>, SYM); wf.add_vector_form(linear_form<double, scalar>, linear_form<ord_t, ord_t>); wf.add_vector_form_surf(linear_form_surf<double, scalar>, linear_form_surf<ord_t, ord_t>); LinearProblem lp(&wf, &space); // assemble stiffness matrix printf(" - assembling...\n"); fflush(stdout); Timer assemble_timer; assemble_timer.start(); lp.assemble(&mat, &rhs); assemble_timer.stop(); printf("%s (%lf secs)\n", assemble_timer.get_human_time(), assemble_timer.get_seconds()); // solve the stiffness matrix printf(" - solving... "); fflush(stdout); Timer solve_timer; solve_timer.start(); bool solved = solver.solve(); solve_timer.stop(); printf("%s (%lf secs)\n", solve_timer.get_human_time(), solve_timer.get_seconds()); // mat.dump(stdout, "a"); // rhs.dump(stdout, "b"); if (solved) { Solution sln(&mesh); sln.set_coeff_vector(&space, solver.get_solution()); // printf("* Solution:\n"); // double *s = solver.get_solution(); // for (int i = 1; i <= ndofs; i++) { // printf(" x[% 3d] = % lf\n", i, s[i]); // } ExactSolution ex_sln(&mesh, exact_solution); // norm double h1_sln_norm = h1_norm(&sln); double h1_err_norm = h1_error(&sln, &ex_sln); printf(" - H1 solution norm: % le\n", h1_sln_norm); printf(" - H1 error norm: % le\n", h1_err_norm); double l2_sln_norm = l2_norm(&sln); double l2_err_norm = l2_error(&sln, &ex_sln); printf(" - L2 solution norm: % le\n", l2_sln_norm); printf(" - L2 error norm: % le\n", l2_err_norm); if (h1_err_norm > EPS || l2_err_norm > EPS) { // calculated solution is not enough precise res = ERR_FAILURE; } #if 0 //def OUTPUT_DIR printf("* Output\n"); // output const char *of_name = OUTPUT_DIR "/solution.pos"; FILE *ofile = fopen(of_name, "w"); if (ofile != NULL) { ExactSolution ex_sln(&mesh, exact_solution); DiffFilter eh(&sln, &ex_sln); // DiffFilter eh_dx(&mesh, &sln, &ex_sln, FN_DX, FN_DX); // DiffFilter eh_dy(&mesh, &sln, &ex_sln, FN_DY, FN_DY); // DiffFilter eh_dz(&mesh, &sln, &ex_sln, FN_DZ, FN_DZ); GmshOutputEngine output(ofile); output.out(&sln, "Uh"); // output.out(&sln, "Uh dx", FN_DX_0); // output.out(&sln, "Uh dy", FN_DY_0); // output.out(&sln, "Uh dz", FN_DZ_0); output.out(&eh, "Eh"); // output.out(&eh_dx, "Eh dx"); // output.out(&eh_dy, "Eh dy"); // output.out(&eh_dz, "Eh dz"); output.out(&ex_sln, "U"); // output.out(&ex_sln, "U dx", FN_DX_0); // output.out(&ex_sln, "U dy", FN_DY_0); // output.out(&ex_sln, "U dz", FN_DZ_0); fclose(ofile); } else { warning("Can not open '%s' for writing.", of_name); } #endif } else res = ERR_FAILURE; #ifdef WITH_PETSC mat.free(); rhs.free(); PetscFinalize(); #endif TRACE_END; return res; }
int main(int argc, char **args) { // Test variable. int success_test = 1; if (argc < 5) 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 according to the // command-line parameters passed. sscanf(args[2], "%d", &P_INIT_X); sscanf(args[3], "%d", &P_INIT_Y); sscanf(args[4], "%d", &P_INIT_Z); Ord3 order(P_INIT_X, P_INIT_Y, P_INIT_Z); H1Space space(&mesh, bc_types, essential_bc_values, order); // Initialize the weak formulation. WeakForm wf; wf.add_matrix_form(bilinear_form<double, scalar>, bilinear_form<Ord, Ord>, HERMES_SYM, HERMES_ANY); wf.add_vector_form(linear_form<double, scalar>, linear_form<Ord, Ord>, HERMES_ANY); // Time measurement. TimePeriod cpu_time; cpu_time.tick(); // Initialize the solver in the case of SOLVER_PETSC or SOLVER_MUMPS. initialize_solution_environment(matrix_solver, argc, args); // Adaptivity loop. int as = 1; bool done = false; do { info("---- Adaptivity step %d:", as); // Construct globally refined reference mesh and setup reference space. Space* ref_space = construct_refined_space(&space,1 , H3D_H3D_H3D_REFT_HEX_XYZ); out_orders_vtk(ref_space, "space", as); // Initialize the FE problem. bool is_linear = true; DiscreteProblem lp(&wf, ref_space, is_linear); // 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 reference problem. info("Assembling on reference mesh (ndof: %d).", Space::get_num_dofs(ref_space)); lp.assemble(matrix, rhs); // Time measurement. cpu_time.tick(); // Solve the linear system on reference mesh. If successful, obtain the solution. info("Solving on reference mesh."); Solution ref_sln(ref_space->get_mesh()); if(solver->solve()) Solution::vector_to_solution(solver->get_solution(), ref_space, &ref_sln); else { printf("Matrix solver failed.\n"); success_test = 0; } // Time measurement. cpu_time.tick(); // Project the reference solution on the coarse mesh. Solution sln(space.get_mesh()); info("Projecting reference solution on coarse mesh."); OGProjection::project_global(&space, &ref_sln, &sln, matrix_solver); // Time measurement. cpu_time.tick(); // Calculate element errors and total error estimate. info("Calculating error estimate and exact error."); Adapt *adaptivity = new Adapt(&space, HERMES_H1_NORM); bool solutions_for_adapt = true; double err_est_rel = adaptivity->calc_err_est(&sln, &ref_sln, solutions_for_adapt) * 100; // Report results. info("ndof_coarse: %d, ndof_fine: %d.", Space::get_num_dofs(&space), Space::get_num_dofs(ref_space)); info("err_est_rel: %g%%.", err_est_rel); // If err_est_rel is too large, adapt the mesh. if (err_est_rel < ERR_STOP) { done = true; ExactSolution ex_sln(&mesh, exact_solution); // Calculate exact error. info("Calculating exact error."); Adapt *adaptivity = new Adapt(&space, HERMES_H1_NORM); bool solutions_for_adapt = false; double err_exact = adaptivity->calc_err_exact(&sln, &ex_sln, solutions_for_adapt, HERMES_TOTAL_ERROR_ABS); if (err_exact > EPS) // Calculated solution is not precise enough. success_test = 0; break; } else { info("Adapting coarse mesh."); adaptivity->adapt(THRESHOLD); } // If we reached the maximum allowed number of degrees of freedom, set the return flag to failure. if (Space::get_num_dofs(&space) >= NDOF_STOP) { done = true; success_test = 0; } // Clean up. delete ref_space->get_mesh(); delete ref_space; delete matrix; delete rhs; delete solver; delete adaptivity; // Increase the counter of performed adaptivity steps. as++; } while (!done); // 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) { // Test variable. int success_test = 1; for (int i = 0; i < 48; i++) { for (int j = 0; j < 48; j++) { info("Config: %d, %d ", i, j); Mesh mesh; for (unsigned int k = 0; k < countof(vtcs); k++) mesh.add_vertex(vtcs[k].x, vtcs[k].y, vtcs[k].z); unsigned int h1[] = { hexs[0][i][0] + 1, hexs[0][i][1] + 1, hexs[0][i][2] + 1, hexs[0][i][3] + 1, hexs[0][i][4] + 1, hexs[0][i][5] + 1, hexs[0][i][6] + 1, hexs[0][i][7] + 1 }; mesh.add_hex(h1); unsigned int h2[] = { hexs[1][j][0] + 1, hexs[1][j][1] + 1, hexs[1][j][2] + 1, hexs[1][j][3] + 1, hexs[1][j][4] + 1, hexs[1][j][5] + 1, hexs[1][j][6] + 1, hexs[1][j][7] + 1 }; mesh.add_hex(h2); // bc for (unsigned int k = 0; k < countof(bnd); k++) { unsigned int facet_idxs[Quad::NUM_VERTICES] = { bnd[k][0] + 1, bnd[k][1] + 1, bnd[k][2] + 1, bnd[k][3] + 1 }; mesh.add_quad_boundary(facet_idxs, bnd[k][4]); } mesh.ugh(); // Initialize the space. H1Space space(&mesh, bc_types, essential_bc_values); #ifdef XM_YN_ZO Ord3 ord(4, 4, 4); #elif defined XM_YN_ZO_2 Ord3 ord(4, 4, 4); #elif defined X2_Y2_Z2 Ord3 ord(2, 2, 2); #endif space.set_uniform_order(ord); // Initialize the weak formulation. WeakForm wf; #ifdef DIRICHLET wf.add_matrix_form(bilinear_form<double, scalar>, bilinear_form<Ord, Ord>, HERMES_SYM); wf.add_vector_form(linear_form<double, scalar>, linear_form<Ord, Ord>); #elif defined NEWTON wf.add_matrix_form(bilinear_form<double, scalar>, bilinear_form<Ord, Ord>, HERMES_SYM); wf.add_matrix_form_surf(bilinear_form_surf<double, scalar>, bilinear_form_surf<Ord, Ord>); wf.add_vector_form(linear_form<double, scalar>, linear_form<Ord, Ord>); wf.add_vector_form_surf(linear_form_surf<double, scalar>, linear_form_surf<Ord, Ord>); #endif // Initialize the FE problem. bool is_linear = true; DiscreteProblem dp(&wf, &space, is_linear); // 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(&space)); dp.assemble(matrix, rhs); // Solve the linear system. If successful, obtain the solution. info("Solving."); Solution sln(space.get_mesh()); if(solver->solve()) Solution::vector_to_solution(solver->get_solution(), &space, &sln); else error ("Matrix solver failed.\n"); ExactSolution ex_sln(&mesh, exact_solution); // Calculate exact error. info("Calculating exact error."); Adapt *adaptivity = new Adapt(&space, HERMES_H1_NORM); bool solutions_for_adapt = false; double err_exact = adaptivity->calc_err_exact(&sln, &ex_sln, solutions_for_adapt, HERMES_TOTAL_ERROR_ABS); if (err_exact > EPS) { // Calculated solution is not precise enough. success_test = 0; info("failed, error:%g", err_exact); } else info("passed"); // Clean up. delete matrix; delete rhs; delete solver; delete adaptivity; } } if (success_test) { info("Success!"); return ERR_SUCCESS; } else { info("Failure!"); return ERR_FAILURE; } }
int main(int argc, char **args) { int res = ERR_SUCCESS; #ifdef WITH_PETSC PetscInitialize(&argc, &args, (char *) PETSC_NULL, PETSC_NULL); #endif if (argc < 2) error("Not enough parameters."); printf("* Loading mesh '%s'\n", args[1]); Mesh mesh1; H3DReader mesh_loader; if (!mesh_loader.load(args[1], &mesh1)) error("Loading mesh file '%s'\n", args[1]); #if defined RHS2 Ord3 order(P_INIT_X, P_INIT_Y, P_INIT_Z); printf(" - Setting uniform order to (%d, %d, %d)\n", order.x, order.y, order.z); // Create an H1 space with default shapeset. printf("* Setting the space up\n"); H1Space space(&mesh1, bc_types, essential_bc_values, order); int ndofs = space.assign_dofs(); printf(" - Number of DOFs: %d\n", ndofs); printf("* Calculating a solution\n"); // duplicate the mesh Mesh mesh2; mesh2.copy(mesh1); // do some changes mesh2.refine_all_elements(H3D_H3D_H3D_REFT_HEX_XYZ); mesh2.refine_all_elements(H3D_H3D_H3D_REFT_HEX_XYZ); Solution fsln(&mesh2); fsln.set_const(-6.0); #else // duplicate the mesh Mesh mesh2; mesh2.copy(mesh1); Mesh mesh3; mesh3.copy(mesh1); // change meshes mesh1.refine_all_elements(H3D_REFT_HEX_X); mesh2.refine_all_elements(H3D_REFT_HEX_Y); mesh3.refine_all_elements(H3D_REFT_HEX_Z); printf("* Setup spaces\n"); Ord3 o1(2, 2, 2); printf(" - Setting uniform order to (%d, %d, %d)\n", o1.x, o1.y, o1.z); H1Space space1(&mesh1, bc_types_1, essential_bc_values_1, o1); Ord3 o2(2, 2, 2); printf(" - Setting uniform order to (%d, %d, %d)\n", o2.x, o2.y, o2.z); H1Space space2(&mesh2, bc_types_2, essential_bc_values_2, o2); Ord3 o3(1, 1, 1); printf(" - Setting uniform order to (%d, %d, %d)\n", o3.x, o3.y, o3.z); H1Space space3(&mesh3, bc_types_3, essential_bc_values_3, o3); int ndofs = 0; ndofs += space1.assign_dofs(); ndofs += space2.assign_dofs(ndofs); ndofs += space3.assign_dofs(ndofs); printf(" - Number of DOFs: %d\n", ndofs); #endif #if defined WITH_UMFPACK MatrixSolverType matrix_solver = SOLVER_UMFPACK; #elif defined WITH_PETSC MatrixSolverType matrix_solver = SOLVER_PETSC; #elif defined WITH_MUMPS MatrixSolverType matrix_solver = SOLVER_MUMPS; #endif #ifdef RHS2 WeakForm wf; wf.add_matrix_form(bilinear_form<double, scalar>, bilinear_form<Ord, Ord>, HERMES_SYM); wf.add_vector_form(linear_form<double, scalar>, linear_form<Ord, Ord>, HERMES_ANY_INT, &fsln); // Initialize discrete problem. bool is_linear = true; DiscreteProblem dp(&wf, &space, is_linear); #elif defined SYS3 WeakForm wf(3); wf.add_matrix_form(0, 0, biform_1_1<double, scalar>, biform_1_1<Ord, Ord>, HERMES_SYM); wf.add_matrix_form(0, 1, biform_1_2<double, scalar>, biform_1_2<Ord, Ord>, HERMES_NONSYM); wf.add_vector_form(0, liform_1<double, scalar>, liform_1<Ord, Ord>); wf.add_matrix_form(1, 1, biform_2_2<double, scalar>, biform_2_2<Ord, Ord>, HERMES_SYM); wf.add_matrix_form(1, 2, biform_2_3<double, scalar>, biform_2_3<Ord, Ord>, HERMES_NONSYM); wf.add_vector_form(1, liform_2<double, scalar>, liform_2<Ord, Ord>); wf.add_matrix_form(2, 2, biform_3_3<double, scalar>, biform_3_3<Ord, Ord>, HERMES_SYM); // Initialize discrete problem. bool is_linear = true; DiscreteProblem dp(&wf, Hermes::vector<Space *>(&space1, &space2, &space3), is_linear); #endif // Time measurement. TimePeriod cpu_time; cpu_time.tick(); // 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 stiffness matrix and load vector. dp.assemble(matrix, rhs); // Solve the linear system. If successful, obtain the solution. info("Solving the linear problem."); bool solved = solver->solve(); // Time measurement. cpu_time.tick(); // Print timing information. info("Solution and mesh with polynomial orders saved. Total running time: %g s", cpu_time.accumulated()); // Time measurement. TimePeriod sln_time; sln_time.tick(); if (solved) { #ifdef RHS2 // Solve the linear system. If successful, obtain the solution. info("Solving the linear problem."); Solution sln(&mesh1); Solution::vector_to_solution(solver->get_solution(), &space, &sln); // Set exact solution. ExactSolution ex_sln(&mesh1, exact_solution); // Norm. double h1_sln_norm = h1_norm(&sln); double h1_err_norm = h1_error(&sln, &ex_sln); printf(" - H1 solution norm: % le\n", h1_sln_norm); printf(" - H1 error norm: % le\n", h1_err_norm); double l2_sln_norm = l2_norm(&sln); double l2_err_norm = l2_error(&sln, &ex_sln); printf(" - L2 solution norm: % le\n", l2_sln_norm); printf(" - L2 error norm: % le\n", l2_err_norm); if (h1_err_norm > EPS || l2_err_norm > EPS) { // Calculated solution is not enough precise. res = ERR_FAILURE; } #elif defined SYS3 // Solution 1. Solution sln1(&mesh1); Solution sln2(&mesh2); Solution sln3(&mesh3); Solution::vector_to_solution(solver->get_solution(), &space1, &sln1); Solution::vector_to_solution(solver->get_solution(), &space2, &sln2); Solution::vector_to_solution(solver->get_solution(), &space3, &sln3); ExactSolution esln1(&mesh1, exact_sln_fn_1); ExactSolution esln2(&mesh2, exact_sln_fn_2); ExactSolution esln3(&mesh3, exact_sln_fn_3); // Norm. double h1_err_norm1 = h1_error(&sln1, &esln1); double h1_err_norm2 = h1_error(&sln2, &esln2); double h1_err_norm3 = h1_error(&sln3, &esln3); double l2_err_norm1 = l2_error(&sln1, &esln1); double l2_err_norm2 = l2_error(&sln2, &esln2); double l2_err_norm3 = l2_error(&sln3, &esln3); printf(" - H1 error norm: % le\n", h1_err_norm1); printf(" - L2 error norm: % le\n", l2_err_norm1); if (h1_err_norm1 > EPS || l2_err_norm1 > EPS) { // Calculated solution is not enough precise. res = ERR_FAILURE; } printf(" - H1 error norm: % le\n", h1_err_norm2); printf(" - L2 error norm: % le\n", l2_err_norm2); if (h1_err_norm2 > EPS || l2_err_norm2 > EPS) { // Calculated solution is not enough precise. res = ERR_FAILURE; } printf(" - H1 error norm: % le\n", h1_err_norm3); printf(" - L2 error norm: % le\n", l2_err_norm3); if (h1_err_norm3 > EPS || l2_err_norm3 > EPS) { // Calculated solution is not enough precise. res = ERR_FAILURE; } #endif #ifdef RHS2 out_fn_vtk(&sln, "solution"); #elif defined SYS3 out_fn_vtk(&sln1, "sln1"); out_fn_vtk(&sln2, "sln2"); out_fn_vtk(&sln3, "sln3"); #endif } else res = ERR_FAILURE; // Print timing information. info("Solution and mesh with polynomial orders saved. Total running time: %g s", sln_time.accumulated()); // Clean up. delete matrix; delete rhs; delete solver; return res; }
int main(int argc, char **argv) { int res = ERR_SUCCESS; #ifdef WITH_PETSC PetscInitialize(&argc, &argv, (char *) PETSC_NULL, PETSC_NULL); #endif set_verbose(false); if (argc < 5) error("Not enough parameters."); H1ShapesetLobattoHex shapeset; printf("* Loading mesh '%s'\n", argv[1]); Mesh mesh; Mesh3DReader mloader; if (!mloader.load(argv[1], &mesh)) error("Loading mesh file '%s'\n", argv[1]); printf("* Setting the space up\n"); H1Space space(&mesh, &shapeset); space.set_bc_types(bc_types); space.set_essential_bc_values(essential_bc_values); int o[3] = { 0, 0, 0 }; sscanf(argv[2], "%d", o + 0); sscanf(argv[3], "%d", o + 1); sscanf(argv[4], "%d", o + 2); order3_t order(o[0], o[1], o[2]); printf(" - Setting uniform order to (%d, %d, %d)\n", order.x, order.y, order.z); space.set_uniform_order(order); WeakForm wf; wf.add_matrix_form(bilinear_form<double, scalar>, bilinear_form<ord_t, ord_t>, SYM, ANY); wf.add_vector_form(linear_form<double, scalar>, linear_form<ord_t, ord_t>, ANY); LinearProblem lp(&wf); lp.set_space(&space); bool done = false; int iter = 0; do { Timer assemble_timer("Assembling stiffness matrix"); Timer solve_timer("Solving stiffness matrix"); printf("\n=== Iter #%d ================================================================\n", iter); printf("\nSolution\n"); #if defined WITH_UMFPACK UMFPackMatrix mat; UMFPackVector rhs; UMFPackLinearSolver solver(&mat, &rhs); #elif defined WITH_PARDISO PardisoMatrix mat; PardisoVector rhs; PardisoLinearSolver solver(&mat, &rhs); #elif defined WITH_PETSC PetscMatrix mat; PetscVector rhs; PetscLinearSolver solver(&mat, &rhs); #elif defined WITH_MUMPS MumpsMatrix mat; MumpsVector rhs; MumpsSolver solver(&mat, &rhs); #endif int ndofs = space.assign_dofs(); printf(" - Number of DOFs: %d\n", ndofs); // assemble stiffness matrix printf(" - Assembling... "); fflush(stdout); assemble_timer.reset(); assemble_timer.start(); lp.assemble(&mat, &rhs); assemble_timer.stop(); printf("done in %s (%lf secs)\n", assemble_timer.get_human_time(), assemble_timer.get_seconds()); // solve the stiffness matrix printf(" - Solving... "); fflush(stdout); solve_timer.reset(); solve_timer.start(); bool solved = solver.solve(); solve_timer.stop(); if (solved) printf("done in %s (%lf secs)\n", solve_timer.get_human_time(), solve_timer.get_seconds()); else { res = ERR_FAILURE; printf("failed\n"); break; } printf("Reference solution\n"); #if defined WITH_UMFPACK UMFPackLinearSolver rsolver(&mat, &rhs); #elif defined WITH_PARDISO PardisoLinearSolver rsolver(&mat, &rhs); #elif defined WITH_PETSC PetscLinearSolver rsolver(&mat, &rhs); #elif defined WITH_MUMPS MumpsSolver rsolver(&mat, &rhs); #endif Mesh rmesh; rmesh.copy(mesh); rmesh.refine_all_elements(H3D_H3D_H3D_REFT_HEX_XYZ); Space *rspace = space.dup(&rmesh); rspace->copy_orders(space, 1); LinearProblem rlp(&wf); rlp.set_space(rspace); int rndofs = rspace->assign_dofs(); printf(" - Number of DOFs: %d\n", rndofs); printf(" - Assembling... "); fflush(stdout); assemble_timer.reset(); assemble_timer.start(); rlp.assemble(&mat, &rhs); assemble_timer.stop(); printf("done in %s (%lf secs)\n", assemble_timer.get_human_time(), assemble_timer.get_seconds()); printf(" - Solving... "); fflush(stdout); solve_timer.reset(); solve_timer.start(); bool rsolved = rsolver.solve(); solve_timer.stop(); if (rsolved) printf("done in %s (%lf secs)\n", solve_timer.get_human_time(), solve_timer.get_seconds()); else { res = ERR_FAILURE; printf("failed\n"); break; } Solution sln(&mesh); sln.set_coeff_vector(&space, solver.get_solution()); Solution rsln(&rmesh); rsln.set_coeff_vector(rspace, rsolver.get_solution()); printf("Adaptivity:\n"); H1Adapt hp(&space); double tol = hp.calc_error(&sln, &rsln) * 100; printf(" - tolerance: "); fflush(stdout); printf("% lf\n", tol); if (tol < TOLERANCE) { printf("\nDone\n"); ExactSolution ex_sln(&mesh, exact_solution); // norm double h1_sln_norm = h1_norm(&sln); double h1_err_norm = h1_error(&sln, &ex_sln); printf(" - H1 solution norm: % le\n", h1_sln_norm); printf(" - H1 error norm: % le\n", h1_err_norm); double l2_sln_norm = l2_norm(&sln); double l2_err_norm = l2_error(&sln, &ex_sln); printf(" - L2 solution norm: % le\n", l2_sln_norm); printf(" - L2 error norm: % le\n", l2_err_norm); if (h1_err_norm > EPS || l2_err_norm > EPS) { // calculated solution is not enough precise res = ERR_FAILURE; } break; } Timer t(""); printf(" - adapting... "); fflush(stdout); t.start(); hp.adapt(THRESHOLD); t.stop(); printf("done in %lf secs (refined %d element(s))\n", t.get_seconds(), hp.get_num_refined_elements()); iter++; } while (!done); #ifdef WITH_PETSC PetscFinalize(); #endif return res; }
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; }