Hello Laura, IIRC, the exact solution class is to enable comparisons of a numerical solution with an analytic solution. Since you are seeking to compare a coarse and fine numerical solution, I think the UniformRefinementEstimator might be the right functionality to use.
Adaptivity example 3 (libmesh/examples/adaptivity/adaptivity_ex3) might be a good place to start. It provides examples of the use of both ExactErrorEstimator and UniformRefinementEstimator. Thanks. On Wed, Jun 21, 2017 at 2:48 PM, Laura Scarabosio <scara...@ma.tum.de> wrote: > Hi everybody, > > I would like to perform a convergence study computing the difference in L2 > and H1 norm between the solution on a coarser grid and another one on a > finer grid, obtained using uniformly_refine(). > > To do this, I saved the two meshes and solutions in .xdr. Then I took the > meshdiff.C implementation in the src/apps folder, and made a simplification > of it. The code uses the ExactSolution class and looks like this: > > int main(int argc, char ** argv) > { > LibMeshInit init(argc, argv); > > Mesh coarse_mesh(init.comm(), dim), fine_mesh(init.comm(), dim); > EquationSystems coarse_es(coarse_mesh), fine_es(fine_mesh); > > libMesh::out << "Usage: " << argv[0] > << " coarsemesh coarsesolution finemesh finesolution > [outputdiff]" << std::endl; > > if (argc < 5) > libmesh_error(); > > coarse_mesh.read(argv[1]); > libMesh::out << "Loaded coarse mesh " << argv[1] << std::endl; > coarse_es.read(argv[2]); > libMesh::out << "Loaded coarse solution " << argv[2] << std::endl; > fine_mesh.read(argv[3]); > libMesh::out << "Loaded fine mesh " << argv[3] << std::endl; > fine_es.read(argv[4]); > libMesh::out << "Loaded fine solution " << argv[4] << std::endl; > > ExactSolution exact_sol(coarse_es); > exact_sol.attach_reference_solution(&fine_es); > > exact_sol.compute_error("S0_Tum", "v0_tum"); > > const System & coarse_sys = coarse_es.get_system("S0_Tum"); > const System & fine_sys = fine_es.get_system("S0_Tum"); > > > libMesh::out << "Errors in system " << "S0_Tum" << ", variable " << > "v0_tum" << ":" << std::endl; > libMesh::out << "L2 error: " << exact_sol.l2_error("S0_Tum", "v0_tum") > << ", coarse norm: " << > coarse_sys.calculate_norm(*coarse_sys.solution, > 0, L2) > << ", fine norm: " << > fine_sys.calculate_norm(*fine_sys.solution, > 0, L2) << std::endl; > libMesh::out << "H1 error: " << exact_sol.h1_error("S0_Tum", "v0_tum") > << ", coarse norm: " << > coarse_sys.calculate_norm(*coarse_sys.solution, > 0, H1) > << ", fine norm: " << > fine_sys.calculate_norm(*fine_sys.solution, > 0, H1) << std::endl; > > > return 0; > } > > Then I launch it, for example, with > > ./main cvg_study/mesh_0refs_b.xdr cvg_study/solution_0refs_b.xdr > cvg_study/mesh_1refs_b.xdr cvg_study/solution_1refs_b.xdr > > However, when the L2 and H1 errors are printed on screen, they are the > very same as the norm of the solution on the fine mesh. It seems like the > solution on the coarse mesh gets not subtracted. I tried printing on screen > the solution from the system on the coarse grid, and it looked ok > (nonzero), and looking at the previous discussion > https://sourceforge.net/p/libmesh/mailman/message/25861781/, it seems I > am in the right direction, so I cannot really understand what is going > wrong. Could anyone help me understanding what is the problem with my code? > > Thank you, > Laura. > > ------------------------------------------------------------ > ------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > _______________________________________________ > Libmesh-users mailing list > Libmesh-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/libmesh-users > -- Vikram Garg Postdoctoral Associate The University of Texas at Austin http://vikramvgarg.wordpress.com/ http://www.runforindia.org/runners/vikramg ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Libmesh-users mailing list Libmesh-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libmesh-users