int main(int argc, char* argv[]) { // load the mesh Mesh mesh; H2DReader mloader; mloader.load("screen-quad.mesh", &mesh); // mloader.load("screen-tri.mesh", &mesh); // initialize the shapeset and the cache HcurlShapeset shapeset; PrecalcShapeset pss(&shapeset); // create finite element space HcurlSpace space(&mesh, &shapeset); space.set_bc_types(bc_types); space.set_bc_values(bc_values); space.set_uniform_order(P_INIT); // enumerate basis functions space.assign_dofs(); // initialize the weak formulation WeakForm wf(1); wf.add_biform(0, 0, callback(bilinear_form), SYM); // visualize solution and mesh ScalarView Xview_r("Electric field X - real", 0, 0, 450, 420); ScalarView Yview_r("Electric field Y - real", 460, 0, 450, 420); ScalarView Xview_i("Electric field X - imag", 920, 0, 450, 420); ScalarView Yview_i("Electric field Y - imag", 1380, 0, 450, 420); OrderView ord("Polynomial Orders", 0, 460, 450, 420); /* // view the basis functions VectorBaseView bview; vbview.show(&space); vbview.wait_for_keypress(); */ // matrix solver UmfpackSolver solver; // DOF and CPU convergence graphs SimpleGraph graph_dof_est, graph_dof_exact, graph_cpu_est, graph_cpu_exact; // adaptivity loop int it = 1, ndofs; bool done = false; double cpu = 0.0; Solution sln_coarse, sln_fine; do { info("\n---- Adaptivity step %d ---------------------------------------------\n", it++); // time measurement begin_time(); // solve the coarse mesh problem LinSystem sys(&wf, &solver); sys.set_spaces(1, &space); sys.set_pss(1, &pss); sys.assemble(); sys.solve(1, &sln_coarse); // time measurement cpu += end_time(); // calculating error wrt. exact solution Solution ex; ex.set_exact(&mesh, exact); double err_exact = 100 * hcurl_error(&sln_coarse, &ex); info("Exact solution error: %g%%", err_exact); // visualization RealFilter real(&sln_coarse); ImagFilter imag(&sln_coarse); Xview_r.set_min_max_range(-3.0, 1.0); //Xview_r.show_scale(false); Xview_r.show(&real, EPS_NORMAL, FN_VAL_0); Yview_r.set_min_max_range(-4.0, 4.0); //Yview_r.show_scale(false); Yview_r.show(&real, EPS_NORMAL, FN_VAL_1); Xview_i.set_min_max_range(-1.0, 4.0); //Xview_i.show_scale(false); Xview_i.show(&imag, EPS_NORMAL, FN_VAL_0); Yview_i.set_min_max_range(-4.0, 4.0); //Yview_i.show_scale(false); Yview_i.show(&imag, EPS_NORMAL, FN_VAL_1); ord.show(&space); // time measurement begin_time(); // solve the fine mesh problem RefSystem ref(&sys); ref.assemble(); ref.solve(1, &sln_fine); // calculate error estimate wrt. fine mesh solution HcurlOrthoHP hp(1, &space); double err_est_adapt = hp.calc_error(&sln_coarse, &sln_fine) * 100; double err_est_hcurl = hcurl_error(&sln_coarse, &sln_fine) * 100; info("Error estimate (adapt): %g%%", err_est_adapt); info("Error estimate (hcurl): %g%%", err_est_hcurl); // add entries to DOF convergence graphs graph_dof_exact.add_values(space.get_num_dofs(), err_exact); graph_dof_exact.save("conv_dof_exact.dat"); graph_dof_est.add_values(space.get_num_dofs(), err_est_hcurl); graph_dof_est.save("conv_dof_est.dat"); // add entries to CPU convergence graphs graph_cpu_exact.add_values(cpu, err_exact); graph_cpu_exact.save("conv_cpu_exact.dat"); graph_cpu_est.add_values(cpu, err_est_hcurl); graph_cpu_est.save("conv_cpu_est.dat"); // if err_est_adapt too large, adapt the mesh if (err_est_adapt < ERR_STOP) done = true; else { hp.adapt(THRESHOLD, STRATEGY, ADAPT_TYPE, ISO_ONLY, MESH_REGULARITY); ndofs = space.assign_dofs(); if (ndofs >= NDOF_STOP) done = true; } // time measurement cpu += end_time(); } while (!done); verbose("Total running time: %g sec", cpu); // wait for keyboard or mouse input View::wait("Waiting for all views to be closed."); return 0; }
int main(int argc, char* argv[]) { // load the mesh Mesh mesh; mesh.load("screen-quad.mesh"); // mesh.load("screen-tri.mesh"); // initialize the shapeset and the cache HcurlShapeset shapeset; PrecalcShapeset pss(&shapeset); // create finite element space HcurlSpace space(&mesh, &shapeset); space.set_bc_types(bc_types); space.set_bc_values(bc_values); space.set_uniform_order(P_INIT); // enumerate basis functions space.assign_dofs(); // initialize the weak formulation WeakForm wf(1); wf.add_biform(0, 0, callback(bilinear_form), SYM); // visualize solution and mesh ScalarView Xview_r("Electric field X - real", 0, 0, 320, 320); ScalarView Yview_r("Electric field Y - real", 325, 0, 320, 320); ScalarView Xview_i("Electric field X - imag", 650, 0, 320, 320); ScalarView Yview_i("Electric field Y - imag", 975, 0, 320, 320); OrderView ord("Polynomial Orders", 325, 400, 600, 600); // matrix solver UmfpackSolver solver; // convergence graph wrt. the number of degrees of freedom GnuplotGraph graph; graph.set_captions("Error Convergence for the Screen Problem in H(curl)", "Degrees of Freedom", "Error [%]"); graph.add_row("exact error", "k", "-", "o"); graph.add_row("error estimate", "k", "--"); graph.set_log_y(); // convergence graph wrt. CPU time GnuplotGraph graph_cpu; graph_cpu.set_captions("Error Convergence for the Screen Problem in H(curl)", "CPU Time", "Error [%]"); graph_cpu.add_row("exact error", "k", "-", "o"); graph_cpu.add_row("error estimate", "k", "--"); graph_cpu.set_log_y(); // adaptivity loop int it = 1, ndofs; bool done = false; double cpu = 0.0; Solution sln_coarse, sln_fine; do { info("\n---- Adaptivity step %d ---------------------------------------------\n", it++); // time measurement begin_time(); // solve the coarse mesh problem LinSystem sys(&wf, &solver); sys.set_spaces(1, &space); sys.set_pss(1, &pss); sys.assemble(); sys.solve(1, &sln_coarse); // time measurement cpu += end_time(); // calculating error wrt. exact solution Solution ex; ex.set_exact(&mesh, exact); double error = 100 * hcurl_error(&sln_coarse, &ex); info("Exact solution error: %g%%", error); // visualization RealFilter real(&sln_coarse); ImagFilter imag(&sln_coarse); Xview_r.set_min_max_range(-3.0, 1.0); Xview_r.show_scale(false); Xview_r.show(&real, EPS_NORMAL, FN_VAL_0); Yview_r.set_min_max_range(-4.0, 4.0); Yview_r.show_scale(false); Yview_r.show(&real, EPS_NORMAL, FN_VAL_1); Xview_i.set_min_max_range(-1.0, 4.0); Xview_i.show_scale(false); Xview_i.show(&imag, EPS_NORMAL, FN_VAL_0); Yview_i.set_min_max_range(-4.0, 4.0); Yview_i.show_scale(false); Yview_i.show(&imag, EPS_NORMAL, FN_VAL_1); ord.show(&space); // time measurement begin_time(); // solve the fine mesh problem RefSystem ref(&sys); ref.assemble(); ref.solve(1, &sln_fine); // calculate error estimate wrt. fine mesh solution HcurlOrthoHP hp(1, &space); double err_est = hp.calc_error(&sln_coarse, &sln_fine) * 100; info("Error estimate: %g%%", err_est); // add entry to DOF convergence graph graph.add_values(0, space.get_num_dofs(), error); graph.add_values(1, space.get_num_dofs(), err_est); graph.save("conv_dof.gp"); // add entry to CPU convergence graph graph_cpu.add_values(0, cpu, error); graph_cpu.add_values(1, cpu, err_est); graph_cpu.save("conv_cpu.gp"); // if err_est too large, adapt the mesh if (err_est < ERR_STOP) done = true; else { hp.adapt(THRESHOLD, STRATEGY, ADAPT_TYPE, ISO_ONLY, MESH_REGULARITY); ndofs = space.assign_dofs(); if (ndofs >= NDOF_STOP) done = true; } // time measurement cpu += end_time(); } while (!done); verbose("Total running time: %g sec", cpu); // wait for keyboard or mouse input View::wait("Waiting for keyboard or mouse input."); return 0; }