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"
37int main(
int argc,
char ** argv)
41 Mesh coarse_mesh(init.comm(),
dim), fine_mesh(init.comm(),
dim);
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()))
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);
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);
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)
160 coarse_sys.
get_dof_map(), std::move(var_remapping));
161 coarse_solution.
init();
166 *fine_sys.
solution -= *fine_solution;
Defines a dense vector for use in Finite Element-type computations.
This is the EquationSystems class.
unsigned int n_systems() const
void read(std::string_view name, const XdrMODE, const unsigned int read_flags=(READ_HEADER|READ_DATA), bool partition_agnostic=true)
Read & initialize the systems from disk using the XDR data format.
bool has_system(std::string_view name) const
const T_sys & get_system(std::string_view name) const
This class handles the computation of the L2 and/or H1 error for the Systems in the EquationSystems o...
Real l2_error(std::string_view sys_name, std::string_view unknown_name)
Real h1_error(std::string_view sys_name, std::string_view unknown_name)
Real h2_error(std::string_view sys_name, std::string_view unknown_name)
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...
void compute_error(std::string_view sys_name, std::string_view unknown_name)
Computes and stores the error in the solution value e = u-u_h, the gradient grad(e) = grad(u) - grad(...
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
This class provides function-like objects for data distributed over a mesh.
virtual void init() override
Override the FunctionBase::init() member function.
void enable_out_of_mesh_mode(const DenseVector< Number > &value)
Enables out-of-mesh mode.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
This class supports simple reads and writes in any libMesh-supported format, by dispatching to one of...
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 ...
Manages consistently variables, degrees of freedom, and coefficient vectors.
void project_solution(FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr, std::optional< ConstElemRange > active_local_range=std::nullopt, std::optional< std::vector< unsigned int > > variable_numbers=std::nullopt) const
Projects arbitrary functions onto the current solution.
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
const std::string & variable_name(const unsigned int i) const
unsigned int variable_number(std::string_view var) const
bool has_variable(std::string_view var) const
Real calculate_norm(const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type, std::set< unsigned int > *skip_dimensions=nullptr) const
unsigned int n_vars() const
const DofMap & get_dof_map() const
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false, bool skip_detect_interior_parents=false) override
Reads the file specified by name.
The libMesh namespace provides an interface to certain functionality in the library.
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value for an unsigned int...