libMesh
|
This class implements an "error estimator" based on the difference between the approximate and exact solution. More...
#include <exact_error_estimator.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... | |
typedef std::map< std::pair< const System *, unsigned int >, std::unique_ptr< ErrorVector > > | ErrorMap |
When calculating many error vectors at once, we need a data structure to hold them all. More... | |
Public Member Functions | |
ExactErrorEstimator () | |
Constructor. More... | |
ExactErrorEstimator (const ExactErrorEstimator &)=delete | |
This class cannot be (default) copy constructed/assigned because it has containers of unique_ptrs. More... | |
ExactErrorEstimator & | operator= (const ExactErrorEstimator &)=delete |
ExactErrorEstimator (ExactErrorEstimator &&)=default | |
Defaulted move ctor, move assignment operator, and destructor. More... | |
ExactErrorEstimator & | operator= (ExactErrorEstimator &&)=default |
virtual | ~ExactErrorEstimator ()=default |
void | attach_exact_values (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 (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 | attach_reference_solution (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 | extra_quadrature_order (const int extraorder) |
Increases or decreases the order of the quadrature rule used for numerical integration. More... | |
virtual void | estimate_error (const System &system, ErrorVector &error_per_cell, const NumericVector< Number > *solution_vector=nullptr, bool estimate_parent_error=false) override |
This function uses the exact solution function to estimate the error on each cell. More... | |
virtual ErrorEstimatorType | type () const override |
virtual void | estimate_errors (const EquationSystems &equation_systems, ErrorVector &error_per_cell, const std::map< const System *, SystemNorm > &error_norms, const std::map< const System *, const NumericVector< Number > *> *solution_vectors=nullptr, bool estimate_parent_error=false) |
This virtual function can be redefined in derived classes, but by default computes the sum of the error_per_cell for each system in the equation_systems. More... | |
virtual void | estimate_errors (const EquationSystems &equation_systems, ErrorMap &errors_per_cell, const std::map< const System *, const NumericVector< Number > *> *solution_vectors=nullptr, bool estimate_parent_error=false) |
This virtual function can be redefined in derived classes, but by default it calls estimate_error repeatedly to calculate the requested error vectors. More... | |
Public Attributes | |
SystemNorm | error_norm |
When estimating the error in a single system, the error_norm is used to control the scaling and norm choice for each variable. More... | |
Protected Member Functions | |
void | reduce_error (std::vector< ErrorVectorReal > &error_per_cell, const Parallel::Communicator &comm) const |
This method takes the local error contributions in error_per_cell from each processor and combines them to get the global error vector. More... | |
Private Member Functions | |
Real | find_squared_element_error (const System &system, const std::string &var_name, const Elem *elem, const DenseVector< Number > &Uelem, FEBase *fe, MeshFunction *fine_values) const |
Helper method for calculating on each element. More... | |
void | clear_functors () |
Helper method for cleanup. More... | |
Private Attributes | |
ValueFunctionPointer | _exact_value |
Function pointer to user-provided function which computes the exact value of the solution. More... | |
GradientFunctionPointer | _exact_deriv |
Function pointer to user-provided function which computes the exact derivative of the solution. More... | |
HessianFunctionPointer | _exact_hessian |
Function pointer to user-provided function which computes the exact hessian of the solution. More... | |
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... | |
EquationSystems * | _equation_systems_fine |
Constant pointer to the EquationSystems object containing a fine grid solution. More... | |
int | _extra_order |
Extra order to use for quadrature rule. More... | |
This class implements an "error estimator" based on the difference between the approximate and exact solution.
In theory the quadrature error in this estimate should be much lower than the approximation error in other estimates, so this estimator can be used to calculate effectivity.
Definition at line 57 of file exact_error_estimator.h.
|
inherited |
When calculating many error vectors at once, we need a data structure to hold them all.
Definition at line 121 of file error_estimator.h.
typedef Gradient(* libMesh::ExactErrorEstimator::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 122 of file exact_error_estimator.h.
typedef Tensor(* libMesh::ExactErrorEstimator::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 145 of file exact_error_estimator.h.
typedef Number(* libMesh::ExactErrorEstimator::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 99 of file exact_error_estimator.h.
libMesh::ExactErrorEstimator::ExactErrorEstimator | ( | ) |
Constructor.
Responsible for initializing the _bc_function function pointer to nullptr, and defaulting the norm type to H1.
Definition at line 49 of file exact_error_estimator.C.
References libMesh::ErrorEstimator::error_norm, and libMesh::H1.
|
delete |
This class cannot be (default) copy constructed/assigned because it has containers of unique_ptrs.
Explicitly deleting these functions is the best way to document this fact.
|
default |
Defaulted move ctor, move assignment operator, and destructor.
|
virtualdefault |
void libMesh::ExactErrorEstimator::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 126 of file exact_error_estimator.C.
References _exact_derivs, and libMesh::FunctionBase< Output >::clone().
Referenced by main().
void libMesh::ExactErrorEstimator::attach_exact_deriv | ( | GradientFunctionPointer | gptr | ) |
Definition at line 102 of file exact_error_estimator.C.
References _equation_systems_fine, _exact_deriv, clear_functors(), gptr(), and libMesh::libmesh_assert().
void libMesh::ExactErrorEstimator::attach_exact_derivs | ( | 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 115 of file exact_error_estimator.C.
References _exact_derivs.
void libMesh::ExactErrorEstimator::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 163 of file exact_error_estimator.C.
References _exact_hessians, and libMesh::FunctionBase< Output >::clone().
void libMesh::ExactErrorEstimator::attach_exact_hessian | ( | HessianFunctionPointer | hptr | ) |
Definition at line 139 of file exact_error_estimator.C.
References _equation_systems_fine, _exact_hessian, clear_functors(), and libMesh::libmesh_assert().
void libMesh::ExactErrorEstimator::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 152 of file exact_error_estimator.C.
References _exact_hessians.
void libMesh::ExactErrorEstimator::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 91 of file exact_error_estimator.C.
References _exact_values, and libMesh::FunctionBase< Output >::clone().
Referenced by main().
void libMesh::ExactErrorEstimator::attach_exact_value | ( | ValueFunctionPointer | fptr | ) |
Definition at line 67 of file exact_error_estimator.C.
References _equation_systems_fine, _exact_value, clear_functors(), fptr(), and libMesh::libmesh_assert().
void libMesh::ExactErrorEstimator::attach_exact_values | ( | 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 80 of file exact_error_estimator.C.
References _exact_values.
void libMesh::ExactErrorEstimator::attach_reference_solution | ( | 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 174 of file exact_error_estimator.C.
References _equation_systems_fine, _exact_deriv, _exact_hessian, _exact_value, clear_functors(), and libMesh::libmesh_assert().
|
private |
Helper method for cleanup.
Definition at line 535 of file exact_error_estimator.C.
References _exact_derivs, _exact_hessians, and _exact_values.
Referenced by attach_exact_deriv(), attach_exact_hessian(), attach_exact_value(), and attach_reference_solution().
|
overridevirtual |
This function uses the exact solution function to estimate the error on each cell.
The estimated error is output in the vector error_per_cell
Implements libMesh::ErrorEstimator.
Definition at line 188 of file exact_error_estimator.C.
References _equation_systems_fine, _exact_derivs, _exact_hessians, _exact_values, _extra_order, libMesh::FEGenericBase< OutputType >::build(), libMesh::NumericVector< T >::build(), libMesh::Elem::child_ref_range(), libMesh::FEGenericBase< OutputType >::coarsened_dof_values(), libMesh::ParallelObject::comm(), libMesh::System::current_local_solution, libMesh::System::current_solution(), libMesh::FEType::default_quadrature_rule(), dim, libMesh::DofMap::dof_indices(), libMesh::ErrorEstimator::error_norm, libMesh::ErrorVectorReal, find_squared_element_error(), libMesh::System::get_dof_map(), libMesh::System::get_mesh(), libMesh::EquationSystems::get_system(), libMesh::DofObject::id(), libMesh::libmesh_ignore(), mesh, n_vars, libMesh::System::n_vars(), libMesh::System::name(), libMesh::Elem::parent(), libMesh::ErrorEstimator::reduce_error(), libMesh::SERIAL, libMesh::System::solution, std::sqrt(), libMesh::NumericVector< T >::swap(), libMesh::System::update_global_solution(), libMesh::System::variable_name(), libMesh::System::variable_number(), libMesh::DofMap::variable_type(), and libMesh::SystemNorm::weight().
Referenced by main().
|
virtualinherited |
This virtual function can be redefined in derived classes, but by default computes the sum of the error_per_cell for each system in the equation_systems.
Currently this function ignores the error_norm member variable, and uses the function argument error_norms instead.
This function is named estimate_errors instead of estimate_error because otherwise C++ can get confused.
Reimplemented in libMesh::UniformRefinementEstimator.
Definition at line 47 of file error_estimator.C.
References libMesh::ErrorEstimator::error_norm, libMesh::ErrorEstimator::estimate_error(), libMesh::EquationSystems::get_system(), libMesh::index_range(), libMesh::make_range(), and libMesh::EquationSystems::n_systems().
|
virtualinherited |
This virtual function can be redefined in derived classes, but by default it calls estimate_error repeatedly to calculate the requested error vectors.
FIXME: This is a default implementation - derived classes should reimplement it for efficiency.
Currently this function ignores the error_norm.weight() values because it calculates each variable's error individually, unscaled.
The user selects which errors get computed by filling a map with error vectors: If errors_per_cell[&system][v] exists, it will be filled with the error values in variable v
of system
Reimplemented in libMesh::UniformRefinementEstimator.
Definition at line 93 of file error_estimator.C.
References libMesh::ErrorEstimator::error_norm, libMesh::ErrorEstimator::estimate_error(), libMesh::EquationSystems::get_system(), libMesh::make_range(), libMesh::EquationSystems::n_systems(), n_vars, libMesh::System::n_vars(), and libMesh::SystemNorm::type().
|
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 165 of file exact_error_estimator.h.
References _extra_order.
|
private |
Helper method for calculating on each element.
Definition at line 402 of file exact_error_estimator.C.
References _equation_systems_fine, _exact_deriv, _exact_derivs, _exact_hessian, _exact_hessians, _exact_value, _exact_values, libMesh::ErrorEstimator::error_norm, libMesh::FEGenericBase< OutputType >::get_d2phi(), libMesh::FEGenericBase< OutputType >::get_dphi(), libMesh::System::get_equation_systems(), libMesh::FEAbstract::get_JxW(), libMesh::FEGenericBase< OutputType >::get_phi(), libMesh::FEAbstract::get_xyz(), libMesh::MeshFunction::gradient(), libMesh::H1, libMesh::H1_SEMINORM, libMesh::H2, libMesh::H2_SEMINORM, libMesh::MeshFunction::hessian(), libMesh::L2, libMesh::System::name(), libMesh::TensorTools::norm_sq(), libMesh::TypeVector< T >::norm_sq(), libMesh::TypeTensor< T >::norm_sq(), libMesh::System::number(), libMesh::EquationSystems::parameters, libMesh::Real, libMesh::FEAbstract::reinit(), libMesh::DenseVector< T >::size(), libMesh::System::time, libMesh::SystemNorm::type(), libMesh::System::variable_number(), and libMesh::System::variable_scalar_number().
Referenced by estimate_error().
|
delete |
|
default |
|
protectedinherited |
This method takes the local error contributions in error_per_cell
from each processor and combines them to get the global error vector.
Definition at line 32 of file error_estimator.C.
References TIMPI::Communicator::sum().
Referenced by libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::PatchRecoveryErrorEstimator::estimate_error(), libMesh::WeightedPatchRecoveryErrorEstimator::estimate_error(), libMesh::JumpErrorEstimator::estimate_error(), libMesh::AdjointRefinementEstimator::estimate_error(), and estimate_error().
|
overridevirtual |
Implements libMesh::ErrorEstimator.
Definition at line 61 of file exact_error_estimator.C.
References libMesh::EXACT.
|
private |
Constant pointer to the EquationSystems
object containing a fine grid solution.
Definition at line 230 of file exact_error_estimator.h.
Referenced by attach_exact_deriv(), attach_exact_hessian(), attach_exact_value(), attach_reference_solution(), estimate_error(), and find_squared_element_error().
|
private |
Function pointer to user-provided function which computes the exact derivative of the solution.
Definition at line 200 of file exact_error_estimator.h.
Referenced by attach_exact_deriv(), attach_reference_solution(), and find_squared_element_error().
|
private |
User-provided functors which compute the exact derivative of the solution for each system.
Definition at line 218 of file exact_error_estimator.h.
Referenced by attach_exact_deriv(), attach_exact_derivs(), clear_functors(), estimate_error(), and find_squared_element_error().
|
private |
Function pointer to user-provided function which computes the exact hessian of the solution.
Definition at line 206 of file exact_error_estimator.h.
Referenced by attach_exact_hessian(), attach_reference_solution(), and find_squared_element_error().
|
private |
User-provided functors which compute the exact hessians of the solution for each system.
Definition at line 224 of file exact_error_estimator.h.
Referenced by attach_exact_hessian(), attach_exact_hessians(), clear_functors(), estimate_error(), and find_squared_element_error().
|
private |
Function pointer to user-provided function which computes the exact value of the solution.
Definition at line 194 of file exact_error_estimator.h.
Referenced by attach_exact_value(), attach_reference_solution(), and find_squared_element_error().
|
private |
User-provided functors which compute the exact value of the solution for each system.
Definition at line 212 of file exact_error_estimator.h.
Referenced by attach_exact_value(), attach_exact_values(), clear_functors(), estimate_error(), and find_squared_element_error().
|
private |
Extra order to use for quadrature rule.
Definition at line 250 of file exact_error_estimator.h.
Referenced by estimate_error(), and extra_quadrature_order().
|
inherited |
When estimating the error in a single system, the error_norm
is used to control the scaling and norm choice for each variable.
Not all estimators will support all norm choices. The default scaling is for all variables to be weighted equally. The default norm choice depends on the error estimator.
Part of this functionality was supported via component_scale and sobolev_order in older libMesh versions, and a small part was supported via component_mask in even older versions. Hopefully the encapsulation here will allow us to avoid changing this API again.
Definition at line 158 of file error_estimator.h.
Referenced by libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::AdjointRefinementEstimator::AdjointRefinementEstimator(), libMesh::DiscontinuityMeasure::boundary_side_integration(), libMesh::KellyErrorEstimator::boundary_side_integration(), libMesh::DiscontinuityMeasure::DiscontinuityMeasure(), libMesh::JumpErrorEstimator::estimate_error(), libMesh::AdjointResidualErrorEstimator::estimate_error(), estimate_error(), libMesh::ErrorEstimator::estimate_errors(), ExactErrorEstimator(), find_squared_element_error(), libMesh::LaplacianErrorEstimator::init_context(), libMesh::DiscontinuityMeasure::init_context(), libMesh::KellyErrorEstimator::init_context(), libMesh::LaplacianErrorEstimator::internal_side_integration(), libMesh::DiscontinuityMeasure::internal_side_integration(), libMesh::KellyErrorEstimator::internal_side_integration(), libMesh::KellyErrorEstimator::KellyErrorEstimator(), libMesh::LaplacianErrorEstimator::LaplacianErrorEstimator(), libMesh::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::PatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::PatchRecoveryErrorEstimator::PatchRecoveryErrorEstimator(), libMesh::JumpErrorEstimator::reinit_sides(), and libMesh::UniformRefinementEstimator::UniformRefinementEstimator().