libMesh
|
This class handles the computation of the L2 and/or H1 error for the Systems in the EquationSystems object which is passed to it. More...
#include <exact_solution.h>
Public Types | |
typedef Number(* | ValueFunctionPointer) (const Point &p, const Parameters &Parameters, const std::string &sys_name, const std::string &unknown_name) |
Attach an arbitrary function which computes the exact value of the solution at any point. More... | |
typedef Gradient(* | GradientFunctionPointer) (const Point &p, const Parameters ¶meters, const std::string &sys_name, const std::string &unknown_name) |
Attach an arbitrary function which computes the exact gradient of the solution at any point. More... | |
typedef Tensor(* | HessianFunctionPointer) (const Point &p, const Parameters ¶meters, const std::string &sys_name, const std::string &unknown_name) |
Attach an arbitrary function which computes the exact second derivatives of the solution at any point. More... | |
Public Member Functions | |
ExactSolution (const EquationSystems &es) | |
Constructor. More... | |
ExactSolution (const ExactSolution &)=delete | |
The copy constructor and copy/move assignment operators are deleted. More... | |
ExactSolution & | operator= (const ExactSolution &)=delete |
ExactSolution & | operator= (ExactSolution &&)=delete |
ExactSolution (ExactSolution &&) | |
Move constructor and destructor are defaulted out-of-line (in the C file) to play nicely with our forward declarations. More... | |
~ExactSolution () | |
void | set_excluded_subdomains (const std::set< subdomain_id_type > &excluded) |
The user can indicate that elements in certain subdomains should be excluded from the error calculation by passing in a set of subdomain ids to ignore. More... | |
void | attach_reference_solution (const EquationSystems *es_fine) |
Attach function similar to system.h which allows the user to attach a second EquationSystems object with a reference fine grid solution. More... | |
void | attach_exact_values (const std::vector< FunctionBase< Number > *> &f) |
Clone and attach arbitrary functors which compute the exact values of the EquationSystems' solutions at any point. More... | |
void | attach_exact_value (unsigned int sys_num, FunctionBase< Number > *f) |
Clone and attach an arbitrary functor which computes the exact value of the system sys_num solution at any point. More... | |
void | attach_exact_value (ValueFunctionPointer fptr) |
void | attach_exact_derivs (const std::vector< FunctionBase< Gradient > *> &g) |
Clone and attach arbitrary functors which compute the exact gradients of the EquationSystems' solutions at any point. More... | |
void | attach_exact_deriv (unsigned int sys_num, FunctionBase< Gradient > *g) |
Clone and attach an arbitrary functor which computes the exact gradient of the system sys_num solution at any point. More... | |
void | attach_exact_deriv (GradientFunctionPointer gptr) |
void | attach_exact_hessians (std::vector< FunctionBase< Tensor > *> h) |
Clone and attach arbitrary functors which compute the exact second derivatives of the EquationSystems' solutions at any point. More... | |
void | attach_exact_hessian (unsigned int sys_num, FunctionBase< Tensor > *h) |
Clone and attach an arbitrary functor which computes the exact second derivatives of the system sys_num solution at any point. More... | |
void | attach_exact_hessian (HessianFunctionPointer hptr) |
void | extra_quadrature_order (const int extraorder) |
Increases or decreases the order of the quadrature rule used for numerical integration. More... | |
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(u_h), and possibly the hessian grad(grad(e)) = grad(grad(u)) - grad(grad(u_h)). More... | |
Real | l2_error (std::string_view sys_name, std::string_view unknown_name) |
Real | l1_error (std::string_view sys_name, std::string_view unknown_name) |
Real | l_inf_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 | hcurl_error (std::string_view sys_name, std::string_view unknown_name) |
Real | hdiv_error (std::string_view sys_name, std::string_view unknown_name) |
Real | h2_error (std::string_view sys_name, std::string_view unknown_name) |
Real | error_norm (std::string_view sys_name, std::string_view unknown_name, const FEMNormType &norm) |
Private Types | |
typedef std::map< std::string, std::vector< Real >, std::less<> > | SystemErrorMap |
Data structure which stores the errors: ||e|| = ||u - u_h|| ||grad(e)|| = ||grad(u) - grad(u_h)|| for each unknown in a single system. More... | |
Private Member Functions | |
template<typename OutputShape > | |
void | _compute_error (std::string_view sys_name, std::string_view unknown_name, std::vector< Real > &error_vals) |
This function computes the error (in the solution and its first derivative) for a single unknown in a single system. More... | |
std::vector< Real > & | _check_inputs (std::string_view sys_name, std::string_view unknown_name) |
This function is responsible for checking the validity of the sys_name and unknown_name inputs. More... | |
Private Attributes | |
std::vector< std::unique_ptr< FunctionBase< Number > > > | _exact_values |
User-provided functors which compute the exact value of the solution for each system. More... | |
std::vector< std::unique_ptr< FunctionBase< Gradient > > > | _exact_derivs |
User-provided functors which compute the exact derivative of the solution for each system. More... | |
std::vector< std::unique_ptr< FunctionBase< Tensor > > > | _exact_hessians |
User-provided functors which compute the exact hessians of the solution for each system. More... | |
std::map< std::string, SystemErrorMap, std::less<> > | _errors |
A map of SystemErrorMaps, which contains entries for each system in the EquationSystems object. More... | |
const EquationSystems & | _equation_systems |
Constant reference to the EquationSystems object used for the simulation. More... | |
const EquationSystems * | _equation_systems_fine |
Constant pointer to the EquationSystems object containing the fine grid solution. More... | |
int | _extra_order |
Extra order to use for quadrature rule. More... | |
std::set< subdomain_id_type > | _excluded_subdomains |
Elements in a subdomain from this set are skipped during the error computation. More... | |
This class handles the computation of the L2 and/or H1 error for the Systems in the EquationSystems object which is passed to it.
exact_value
and exact_deriv
functions below.Definition at line 65 of file exact_solution.h.
typedef Gradient(* libMesh::ExactSolution::GradientFunctionPointer) (const Point &p, const Parameters ¶meters, const std::string &sys_name, const std::string &unknown_name) |
Attach an arbitrary function which computes the exact gradient of the solution at any point.
Definition at line 149 of file exact_solution.h.
typedef Tensor(* libMesh::ExactSolution::HessianFunctionPointer) (const Point &p, const Parameters ¶meters, const std::string &sys_name, const std::string &unknown_name) |
Attach an arbitrary function which computes the exact second derivatives of the solution at any point.
Definition at line 172 of file exact_solution.h.
|
private |
Data structure which stores the errors: ||e|| = ||u - u_h|| ||grad(e)|| = ||grad(u) - grad(u_h)|| for each unknown in a single system.
The name of the unknown is the key for the map.
Definition at line 341 of file exact_solution.h.
typedef Number(* libMesh::ExactSolution::ValueFunctionPointer) (const Point &p, const Parameters &Parameters, const std::string &sys_name, const std::string &unknown_name) |
Attach an arbitrary function which computes the exact value of the solution at any point.
Definition at line 126 of file exact_solution.h.
|
explicit |
Constructor.
The ExactSolution object must be initialized with an EquationSystems object.
Definition at line 45 of file exact_solution.C.
References _equation_systems, _errors, libMesh::EquationSystems::get_system(), libMesh::make_range(), libMesh::EquationSystems::n_systems(), libMesh::System::n_vars(), libMesh::System::name(), and libMesh::System::variable_name().
|
delete |
The copy constructor and copy/move assignment operators are deleted.
This class has containers of unique_ptrs so it can't be default (shallow) copied, and it has a const reference so it can't be assigned to after creation.
|
default |
Move constructor and destructor are defaulted out-of-line (in the C file) to play nicely with our forward declarations.
|
default |
|
private |
This function is responsible for checking the validity of the sys_name
and unknown_name
inputs.
Definition at line 220 of file exact_solution.C.
References _errors.
Referenced by compute_error(), error_norm(), h1_error(), h2_error(), l1_error(), l2_error(), and l_inf_error().
|
private |
This function computes the error (in the solution and its first derivative) for a single unknown in a single system.
It is a private function since it is used by the implementation when solving for several unknowns in several systems.
Definition at line 452 of file exact_solution.C.
References _equation_systems, _equation_systems_fine, _exact_derivs, _exact_hessians, _exact_values, _excluded_subdomains, _extra_order, libMesh::Variable::active_on_subdomain(), libMesh::FEGenericBase< OutputType >::build(), libMesh::NumericVector< T >::build(), libMesh::ParallelObject::comm(), communicator, libMesh::TensorTools::curl_from_grad(), libMesh::System::current_solution(), libMesh::FEType::default_quadrature_rule(), dim, libMesh::TensorTools::div_from_grad(), libMesh::DofMap::dof_indices(), libMesh::err, exact_grad(), libMesh::FEInterface::field_type(), libMesh::FEGenericBase< OutputType >::get_curl_phi(), libMesh::FEGenericBase< OutputType >::get_d2phi(), libMesh::FEGenericBase< OutputType >::get_div_phi(), libMesh::System::get_dof_map(), libMesh::FEGenericBase< OutputType >::get_dphi(), libMesh::FEAbstract::get_JxW(), libMesh::EquationSystems::get_mesh(), libMesh::System::get_mesh(), libMesh::FEGenericBase< OutputType >::get_phi(), libMesh::EquationSystems::get_system(), libMesh::FEAbstract::get_xyz(), libMesh::libmesh_assert(), libMesh::make_range(), mesh, libMesh::QBase::n_points(), libMesh::FEInterface::n_vec_dim(), libMesh::TensorTools::norm(), libMesh::TensorTools::norm_sq(), libMesh::TypeVector< T >::norm_sq(), libMesh::System::number(), libMesh::Real, libMesh::FEAbstract::reinit(), libMesh::SERIAL, libMesh::System::solution, std::sqrt(), libMesh::TYPE_VECTOR, libMesh::System::update_global_solution(), libMesh::System::variable(), libMesh::System::variable_number(), libMesh::DofMap::variable_type(), and libMesh::System::variable_type().
void libMesh::ExactSolution::attach_exact_deriv | ( | unsigned int | sys_num, |
FunctionBase< Gradient > * | g | ||
) |
Clone and attach an arbitrary functor which computes the exact gradient of the system sys_num
solution at any point.
Definition at line 168 of file exact_solution.C.
References _exact_derivs, and libMesh::FunctionBase< Output >::clone().
Referenced by main().
void libMesh::ExactSolution::attach_exact_deriv | ( | GradientFunctionPointer | gptr | ) |
Definition at line 138 of file exact_solution.C.
References _equation_systems, _equation_systems_fine, _exact_derivs, libMesh::EquationSystems::get_system(), gptr(), libMesh::libmesh_assert(), libMesh::make_range(), libMesh::EquationSystems::n_systems(), and libMesh::EquationSystems::parameters.
void libMesh::ExactSolution::attach_exact_derivs | ( | const std::vector< FunctionBase< Gradient > *> & | g | ) |
Clone and attach arbitrary functors which compute the exact gradients of the EquationSystems' solutions at any point.
Definition at line 157 of file exact_solution.C.
References _exact_derivs.
Referenced by main().
void libMesh::ExactSolution::attach_exact_hessian | ( | unsigned int | sys_num, |
FunctionBase< Tensor > * | h | ||
) |
Clone and attach an arbitrary functor which computes the exact second derivatives of the system sys_num
solution at any point.
Definition at line 209 of file exact_solution.C.
References _exact_hessians, and libMesh::FunctionBase< Output >::clone().
Referenced by main().
void libMesh::ExactSolution::attach_exact_hessian | ( | HessianFunctionPointer | hptr | ) |
Definition at line 179 of file exact_solution.C.
References _equation_systems, _equation_systems_fine, _exact_hessians, libMesh::EquationSystems::get_system(), libMesh::libmesh_assert(), libMesh::make_range(), libMesh::EquationSystems::n_systems(), and libMesh::EquationSystems::parameters.
void libMesh::ExactSolution::attach_exact_hessians | ( | std::vector< FunctionBase< Tensor > *> | h | ) |
Clone and attach arbitrary functors which compute the exact second derivatives of the EquationSystems' solutions at any point.
Definition at line 198 of file exact_solution.C.
References _exact_hessians.
void libMesh::ExactSolution::attach_exact_value | ( | unsigned int | sys_num, |
FunctionBase< Number > * | f | ||
) |
Clone and attach an arbitrary functor which computes the exact value of the system sys_num
solution at any point.
Definition at line 127 of file exact_solution.C.
References _exact_values, and libMesh::FunctionBase< Output >::clone().
Referenced by main(), and ConstraintOperatorTest::test1DCoarseningOperator().
void libMesh::ExactSolution::attach_exact_value | ( | ValueFunctionPointer | fptr | ) |
Definition at line 97 of file exact_solution.C.
References _equation_systems, _equation_systems_fine, _exact_values, fptr(), libMesh::EquationSystems::get_system(), libMesh::libmesh_assert(), libMesh::make_range(), libMesh::EquationSystems::n_systems(), and libMesh::EquationSystems::parameters.
void libMesh::ExactSolution::attach_exact_values | ( | const std::vector< FunctionBase< Number > *> & | f | ) |
Clone and attach arbitrary functors which compute the exact values of the EquationSystems' solutions at any point.
Definition at line 116 of file exact_solution.C.
References _exact_values.
Referenced by main().
void libMesh::ExactSolution::attach_reference_solution | ( | const EquationSystems * | es_fine | ) |
Attach function similar to system.h which allows the user to attach a second EquationSystems object with a reference fine grid solution.
Definition at line 85 of file exact_solution.C.
References _equation_systems_fine, _exact_derivs, _exact_hessians, _exact_values, and libMesh::libmesh_assert().
Referenced by main().
void libMesh::ExactSolution::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(u_h), and possibly the hessian grad(grad(e)) = grad(grad(u)) - grad(grad(u_h)).
Does not return any value. For that you need to call the l2_error(), h1_error() or h2_error() functions respectively.
Definition at line 231 of file exact_solution.C.
References _check_inputs(), _equation_systems, libMesh::FEInterface::field_type(), libMesh::EquationSystems::get_system(), libMesh::EquationSystems::has_system(), libMesh::libmesh_assert(), libMesh::TYPE_SCALAR, and libMesh::TYPE_VECTOR.
Referenced by main(), and ConstraintOperatorTest::test1DCoarseningOperator().
Real libMesh::ExactSolution::error_norm | ( | std::string_view | sys_name, |
std::string_view | unknown_name, | ||
const FEMNormType & | norm | ||
) |
sys_name
for the unknown unknown_name
.compute_error()
for that.Definition at line 268 of file exact_solution.C.
References _check_inputs(), _equation_systems, libMesh::FEInterface::field_type(), libMesh::EquationSystems::get_system(), libMesh::H1, libMesh::H1_SEMINORM, libMesh::H2, libMesh::H2_SEMINORM, libMesh::EquationSystems::has_system(), libMesh::HCURL, libMesh::HCURL_SEMINORM, libMesh::HDIV, libMesh::HDIV_SEMINORM, libMesh::L1, libMesh::L2, libMesh::L_INF, libMesh::libmesh_assert(), libMesh::TensorTools::norm(), std::sqrt(), and libMesh::TYPE_SCALAR.
Referenced by hcurl_error(), hdiv_error(), and main().
|
inline |
Increases or decreases the order of the quadrature rule used for numerical integration.
The default extraorder
is 1, because properly integrating L2 error requires integrating the squares of terms with order p+1, and 2p+2 is 1 higher than what we default to using for reasonable mass matrix integration.
Definition at line 185 of file exact_solution.h.
References _extra_order.
Referenced by main().
Real libMesh::ExactSolution::h1_error | ( | std::string_view | sys_name, |
std::string_view | unknown_name | ||
) |
sys_name
for the unknown unknown_name
.compute_error()
for that. Definition at line 397 of file exact_solution.C.
References _check_inputs(), and std::sqrt().
Referenced by main().
Real libMesh::ExactSolution::h2_error | ( | std::string_view | sys_name, |
std::string_view | unknown_name | ||
) |
sys_name
for the unknown unknown_name
.compute_error()
for that. Definition at line 429 of file exact_solution.C.
References _check_inputs(), and std::sqrt().
Referenced by main().
Real libMesh::ExactSolution::hcurl_error | ( | std::string_view | sys_name, |
std::string_view | unknown_name | ||
) |
sys_name
for the unknown unknown_name
.compute_error()
for that.Definition at line 414 of file exact_solution.C.
References error_norm(), and libMesh::HCURL.
Referenced by main().
Real libMesh::ExactSolution::hdiv_error | ( | std::string_view | sys_name, |
std::string_view | unknown_name | ||
) |
sys_name
for the unknown unknown_name
.compute_error()
for that.Definition at line 421 of file exact_solution.C.
References error_norm(), and libMesh::HDIV.
Referenced by main().
Real libMesh::ExactSolution::l1_error | ( | std::string_view | sys_name, |
std::string_view | unknown_name | ||
) |
sys_name
for the unknown unknown_name
.compute_error()
for that. Definition at line 357 of file exact_solution.C.
References _check_inputs().
Real libMesh::ExactSolution::l2_error | ( | std::string_view | sys_name, |
std::string_view | unknown_name | ||
) |
sys_name
for the unknown unknown_name
.compute_error()
for that. Definition at line 337 of file exact_solution.C.
References _check_inputs(), and std::sqrt().
Referenced by main(), and ConstraintOperatorTest::test1DCoarseningOperator().
Real libMesh::ExactSolution::l_inf_error | ( | std::string_view | sys_name, |
std::string_view | unknown_name | ||
) |
sys_name
for the unknown unknown_name
.Definition at line 377 of file exact_solution.C.
References _check_inputs().
|
delete |
|
delete |
void libMesh::ExactSolution::set_excluded_subdomains | ( | const std::set< subdomain_id_type > & | excluded | ) |
The user can indicate that elements in certain subdomains should be excluded from the error calculation by passing in a set of subdomain ids to ignore.
By default, all subdomains are considered in the error calculation.
Definition at line 80 of file exact_solution.C.
References _excluded_subdomains.
|
private |
Constant reference to the EquationSystems
object used for the simulation.
Definition at line 355 of file exact_solution.h.
Referenced by _compute_error(), attach_exact_deriv(), attach_exact_hessian(), attach_exact_value(), compute_error(), error_norm(), and ExactSolution().
|
private |
Constant pointer to the EquationSystems
object containing the fine grid solution.
Definition at line 361 of file exact_solution.h.
Referenced by _compute_error(), attach_exact_deriv(), attach_exact_hessian(), attach_exact_value(), and attach_reference_solution().
|
private |
A map of SystemErrorMaps, which contains entries for each system in the EquationSystems object.
This is required, since it is possible for two systems to have unknowns with the same name.
Definition at line 349 of file exact_solution.h.
Referenced by _check_inputs(), and ExactSolution().
|
private |
User-provided functors which compute the exact derivative of the solution for each system.
Definition at line 324 of file exact_solution.h.
Referenced by _compute_error(), attach_exact_deriv(), attach_exact_derivs(), and attach_reference_solution().
|
private |
User-provided functors which compute the exact hessians of the solution for each system.
Definition at line 330 of file exact_solution.h.
Referenced by _compute_error(), attach_exact_hessian(), attach_exact_hessians(), and attach_reference_solution().
|
private |
User-provided functors which compute the exact value of the solution for each system.
Definition at line 318 of file exact_solution.h.
Referenced by _compute_error(), attach_exact_value(), attach_exact_values(), and attach_reference_solution().
|
private |
Elements in a subdomain from this set are skipped during the error computation.
Definition at line 372 of file exact_solution.h.
Referenced by _compute_error(), and set_excluded_subdomains().
|
private |
Extra order to use for quadrature rule.
Definition at line 366 of file exact_solution.h.
Referenced by _compute_error(), and extra_quadrature_order().