21 #include "libmesh/libmesh_common.h" 22 #include "libmesh/exact_error_estimator.h" 23 #include "libmesh/dof_map.h" 24 #include "libmesh/equation_systems.h" 25 #include "libmesh/error_vector.h" 26 #include "libmesh/fe_base.h" 27 #include "libmesh/libmesh_logging.h" 28 #include "libmesh/elem.h" 29 #include "libmesh/mesh_base.h" 30 #include "libmesh/mesh_function.h" 31 #include "libmesh/numeric_vector.h" 32 #include "libmesh/quadrature.h" 33 #include "libmesh/system.h" 34 #include "libmesh/tensor_tools.h" 35 #include "libmesh/enum_error_estimator_type.h" 36 #include "libmesh/enum_norm_type.h" 51 _exact_value(nullptr),
52 _exact_deriv(nullptr),
53 _exact_hessian(nullptr),
54 _equation_systems_fine(nullptr),
191 bool estimate_parent_error)
200 const unsigned int dim =
mesh.mesh_dimension();
210 error_per_cell.resize (
mesh.max_elem_id());
211 std::fill (error_per_cell.begin(), error_per_cell.end(), 0.);
215 if (solution_vector && solution_vector != system.
solution.get())
220 newsol->
swap(*sys.solution);
225 for (
unsigned int var=0; var<
n_vars; var++)
239 std::unique_ptr<QBase> qrule =
243 fe->attach_quadrature_rule (qrule.get());
246 std::unique_ptr<MeshFunction> fine_values;
252 std::vector<Number> global_soln;
258 (cast_int<numeric_index_type>(global_soln.size()),
true,
260 (*fine_soln) = global_soln;
262 fine_values = std::make_unique<MeshFunction>
287 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES 292 #ifdef LIBMESH_ENABLE_AMR 295 std::vector<bool> computed_var_on_parent;
297 if (estimate_parent_error)
298 computed_var_on_parent.resize(error_per_cell.size(),
false);
307 for (
const auto & elem :
mesh.active_local_element_ptr_range())
311 #ifdef LIBMESH_ENABLE_AMR 318 bool compute_on_parent =
true;
319 if (!parent || !estimate_parent_error)
320 compute_on_parent =
false;
324 compute_on_parent =
false;
326 if (compute_on_parent &&
327 !computed_var_on_parent[parent->
id()])
329 computed_var_on_parent[parent->
id()] =
true;
334 dof_map, parent, Uparent,
337 error_per_cell[parent->
id()] +=
347 std::vector<dof_id_type> dof_indices;
349 const unsigned int n_dofs =
350 cast_int<unsigned int>(dof_indices.size());
352 for (
unsigned int i=0; i != n_dofs; ++i)
355 error_per_cell[e_id] +=
379 LOG_SCOPE(
"std::sqrt()",
"ExactErrorEstimator");
380 for (
auto & val : error_per_cell)
383 libmesh_assert_greater (val, 0.);
384 val = std::sqrt(val);
390 if (solution_vector && solution_vector != system.
solution.get())
395 newsol->
swap(*sys.solution);
403 const std::string & var_name,
410 const std::string & sys_name = system.
name();
411 const unsigned int sys_num = system.
number();
414 const unsigned int var_component =
424 const std::vector<Real> & JxW = fe->
get_JxW();
425 const std::vector<std::vector<Real>> & phi_values = fe->
get_phi();
426 const std::vector<std::vector<RealGradient>> & dphi_values = fe->
get_dphi();
427 const std::vector<Point> & q_point = fe->
get_xyz();
428 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES 429 const std::vector<std::vector<RealTensor>> & d2phi_values = fe->
get_d2phi();
433 const unsigned int n_sf =
434 cast_int<unsigned int>(Uelem.
size());
437 const unsigned int n_qp =
438 cast_int<unsigned int>(JxW.size());
444 for (
unsigned int qp=0; qp<n_qp; qp++)
452 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES 460 for (
unsigned int i=0; i<n_sf; i++)
463 u_h += phi_values[i][qp]*Uelem(i);
464 grad_u_h += dphi_values[i][qp]*Uelem(i);
465 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES 466 grad2_u_h += d2phi_values[i][qp]*Uelem(i);
477 val_error -=
_exact_value(q_point[qp],parameters,sys_name,var_name);
480 component(var_component, q_point[qp], system.
time);
482 val_error -= (*fine_values)(q_point[qp]);
496 grad_error -=
_exact_deriv(q_point[qp],parameters,sys_name,var_name);
499 component(var_component, q_point[qp], system.
time);
501 grad_error -= fine_values->
gradient(q_point[qp]);
503 error_val += JxW[qp]*grad_error.
norm_sq();
507 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES 513 Tensor grad2_error = grad2_u_h;
515 grad2_error -=
_exact_hessian(q_point[qp],parameters,sys_name,var_name);
518 component(var_component, q_point[qp], system.
time);
520 grad2_error -= fine_values->
hessian(q_point[qp]);
522 error_val += JxW[qp]*grad2_error.
norm_sq();
528 libmesh_assert_greater_equal (error_val, 0.);
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Real time
For time-dependent problems, this is the time t at the beginning of the current timestep.
HessianFunctionPointer _exact_hessian
Function pointer to user-provided function which computes the exact hessian of the solution...
This is the EquationSystems class.
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_n...
const Elem * parent() const
unsigned int variable_scalar_number(std::string_view var, unsigned int component) const
void update_global_solution(std::vector< Number > &global_soln) const
Fill the input vector global_soln so that it contains the global solution on all processors.
This class provides the ability to map between arbitrary, user-defined strings and several data types...
SystemNorm error_norm
When estimating the error in a single system, the error_norm is used to control the scaling and norm ...
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
std::vector< std::unique_ptr< FunctionBase< Tensor > > > _exact_hessians
User-provided functors which compute the exact hessians of the solution for each system.
int _extra_order
Extra order to use for quadrature rule.
The ErrorVector is a specialization of the StatisticsVector for error data computed on a finite eleme...
ErrorEstimatorType
Defines an enum for the different types of error estimators which are available.
void attach_exact_hessians(std::vector< FunctionBase< Tensor > *> h)
Clone and attach arbitrary functors which compute the exact second derivatives of the EquationSystems...
const FEType & variable_type(const unsigned int c) const
ExactErrorEstimator()
Constructor.
const EquationSystems & get_equation_systems() const
This is the base class from which all geometric element types are derived.
auto norm_sq() const -> decltype(std::norm(T()))
Gradient gradient(const Point &p, const Real time=0.)
const Parallel::Communicator & comm() const
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
The libMesh namespace provides an interface to certain functionality in the library.
ValueFunctionPointer _exact_value
Function pointer to user-provided function which computes the exact value of the solution.
const T_sys & get_system(std::string_view name) const
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 a...
const MeshBase & get_mesh() const
DIE A HORRIBLE DEATH HERE typedef float ErrorVectorReal
std::vector< std::unique_ptr< FunctionBase< Gradient > > > _exact_derivs
User-provided functors which compute the exact derivative of the solution for each system...
This is the MeshBase class.
SimpleRange< ChildRefIter > child_ref_range()
Returns a range with all children of a parent element, usable in range-based for loops.
Number current_solution(const dof_id_type global_dof_number) const
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
unsigned int variable_number(std::string_view var) const
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.
static void coarsened_dof_values(const NumericVector< Number > &global_vector, const DofMap &dof_map, const Elem *coarse_elem, DenseVector< Number > &coarse_dofs, const unsigned int var, const bool use_old_dof_indices=false)
Creates a local projection on coarse_elem, based on the DoF values in global_vector for it's children...
virtual ErrorEstimatorType type() const override
This class handles the numbering of degrees of freedom on a mesh.
std::unique_ptr< QBase > default_quadrature_rule(const unsigned int dim, const int extraorder=0) const
const std::vector< std::vector< OutputGradient > > & get_dphi() const
void libmesh_ignore(const Args &...)
unsigned int number() const
auto norm_sq() const -> decltype(std::norm(T()))
Manages consistently variables, degrees of freedom, and coefficient vectors.
FEMNormType type(unsigned int var) const
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
This class holds functions that will estimate the error in a finite element solution on a given mesh...
virtual_for_inffe const std::vector< Real > & get_JxW() const
virtual void reinit(const Elem *elem, const std::vector< Point > *const pts=nullptr, const std::vector< Real > *const weights=nullptr)=0
This is at the core of this class.
const std::string & variable_name(const unsigned int i) const
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 th...
virtual_for_inffe const std::vector< Point > & get_xyz() const
const std::vector< std::vector< OutputTensor > > & get_d2phi() const
void clear_functors()
Helper method for cleanup.
void attach_exact_derivs(std::vector< FunctionBase< Gradient > *> g)
Clone and attach arbitrary functors which compute the exact gradients of the EquationSystems' solutio...
Real weight(unsigned int var) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
GradientFunctionPointer _exact_deriv
Function pointer to user-provided function which computes the exact derivative of the solution...
EquationSystems * _equation_systems_fine
Constant pointer to the EquationSystems object containing a fine grid solution.
virtual void swap(NumericVector< T > &v)
Swaps the contents of this with v.
Gradient gptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
static std::unique_ptr< NumericVector< T > > build(const Parallel::Communicator &comm, SolverPackage solver_package=libMesh::default_solver_package(), ParallelType parallel_type=AUTOMATIC)
Builds a NumericVector on the processors in communicator comm using the linear solver package specifi...
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.
Parameters parameters
Data structure holding arbitrary parameters.
virtual unsigned int size() const override final
std::unique_ptr< NumericVector< Number > > current_local_solution
All the values I need to compute my contribution to the simulation at hand.
virtual std::unique_ptr< FunctionBase< Output > > clone() const =0
void attach_exact_values(std::vector< FunctionBase< Number > *> f)
Clone and attach arbitrary functors which compute the exact values of the EquationSystems' solutions ...
const std::string & name() const
This class provides function-like objects for data distributed over a mesh.
void attach_reference_solution(EquationSystems *es_fine)
Attach function similar to system.h which allows the user to attach a second EquationSystems object w...
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 solutio...
unsigned int n_vars() const
const DofMap & get_dof_map() const
Tensor hessian(const Point &p, const Real time=0.)
std::vector< std::unique_ptr< FunctionBase< Number > > > _exact_values
User-provided functors which compute the exact value of the solution for each system.
This class forms the foundation from which generic finite elements may be derived.
This class defines a tensor in LIBMESH_DIM dimensional Real or Complex space.
const std::vector< std::vector< OutputShape > > & get_phi() const