Go to the documentation of this file.
23 #include "libmesh/libmesh.h"
24 #include "libmesh/mesh.h"
25 #include "libmesh/equation_systems.h"
26 #include "libmesh/exact_solution.h"
27 #include "libmesh/mesh_function.h"
28 #include "libmesh/namebased_io.h"
29 #include "libmesh/numeric_vector.h"
30 #include "libmesh/enum_norm_type.h"
31 #include "libmesh/int_range.h"
35 unsigned char dim = 2;
37 int main(
int argc,
char ** argv)
45 <<
" coarsemesh coarsesolution finemesh finesolution [outputdiff]" << std::endl;
50 coarse_mesh.read(argv[1]);
51 libMesh::out <<
"Loaded coarse mesh " << argv[1] << std::endl;
52 coarse_es.read(argv[2]);
53 libMesh::out <<
"Loaded coarse solution " << argv[2] << std::endl;
54 fine_mesh.read(argv[3]);
55 libMesh::out <<
"Loaded fine mesh " << argv[3] << std::endl;
56 fine_es.read(argv[4]);
57 libMesh::out <<
"Loaded fine solution " << argv[4] << std::endl;
62 std::vector<std::string> sysnames;
63 sysnames.reserve(coarse_es.n_systems());
65 for (
unsigned int i = 0; i != coarse_es.n_systems(); ++i)
66 if (fine_es.has_system(coarse_es.get_system(i).name()))
67 sysnames.push_back(coarse_es.get_system(i).name());
70 << coarse_es.get_system(i).name()
71 <<
" not found in fine solution!" << std::endl;
73 for (
unsigned int i = 0; i != fine_es.n_systems(); ++i)
74 if (!coarse_es.has_system(fine_es.get_system(i).name()))
76 << fine_es.get_system(i).name()
77 <<
" not found in coarse solution!" << std::endl;
79 if (!coarse_es.n_systems() && !fine_es.n_systems())
80 libMesh::out <<
"No systems found in fine or coarse solution!"
85 const std::string sysname = sysnames[i];
86 const System & coarse_sys = coarse_es.get_system(sysname);
87 const System & fine_sys = fine_es.get_system(sysname);
89 for (
unsigned int j = 0; j != coarse_sys.
n_vars(); ++j)
96 <<
" variable " << varname
97 <<
" not found in coarse solution!" << std::endl;
104 libMesh::out <<
"Errors in system " << sysname <<
", variable " << varname <<
":" << std::endl;
116 for (
unsigned int j = 0; j != fine_sys.
n_vars(); ++j)
123 <<
" variable " << varname
124 <<
" not found in fine solution!" << std::endl;
130 libMesh::out <<
"No variables found in fine or coarse solution system "
131 << sysname <<
'!' << std::endl;
136 libMesh::out <<
"Writing diff solution " << argv[5] << std::endl;
140 const std::string sysname = sysnames[i];
141 const System & coarse_sys = coarse_es.get_system(sysname);
142 const System & fine_sys = fine_es.get_system(sysname);
144 std::unique_ptr<NumericVector<Number>> fine_solution = fine_sys.
solution->clone();
147 std::vector<unsigned int>
150 for (
unsigned int j = 0; j != fine_sys.
n_vars(); ++j)
161 coarse_solution.
init();
163 coarse_solution.enable_out_of_mesh_mode(oom_value);
166 *fine_sys.
solution -= *fine_solution;
Manages consistently variables, degrees of freedom, and coefficient vectors.
This class handles the computation of the L2 and/or H1 error for the Systems in the EquationSystems o...
unsigned int n_vars() const
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
virtual void init() override
Override the FunctionBase::init() member function by calling our own and specifying the Trees::NODES ...
This class provides function-like objects for data distributed over a mesh.
const std::string & variable_name(const unsigned int i) const
IntRange< std::size_t > index_range(const std::vector< T > &vec)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
The libMesh namespace provides an interface to certain functionality in the library.
Real h1_error(const std::string &sys_name, const std::string &unknown_name)
Real h2_error(const std::string &sys_name, const std::string &unknown_name)
int main(int argc, char **argv)
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
bool has_variable(const std::string &var) const
void attach_reference_solution(const EquationSystems *es_fine)
Attach function similar to system.h which allows the user to attach a second EquationSystems object w...
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Real l2_error(const std::string &sys_name, const std::string &unknown_name)
void compute_error(const std::string &sys_name, const std::string &unknown_name)
Computes and stores the error in the solution value e = u-u_h, the gradient grad(e) = grad(u) - grad(...
This is the EquationSystems class.
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
virtual void write_equation_systems(const std::string &filename, const EquationSystems &es, const std::set< std::string > *system_names=nullptr) override
This method implements writing a mesh with data to a specified file where the data is taken from the ...
unsigned short int variable_number(const std::string &var) const
Real calculate_norm(const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type, std::set< unsigned int > *skip_dimensions=nullptr) const
const DofMap & get_dof_map() const
This class supports simple reads and writes in any libMesh-supported format, by dispatching to one of...
void project_solution(FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr) const
Projects arbitrary functions onto the current solution.