Go to the documentation of this file.
   26 #include "libmesh/libmesh_common.h" 
   27 #include "libmesh/exact_error_estimator.h" 
   28 #include "libmesh/dof_map.h" 
   29 #include "libmesh/equation_systems.h" 
   30 #include "libmesh/error_vector.h" 
   31 #include "libmesh/fe_base.h" 
   32 #include "libmesh/libmesh_logging.h" 
   33 #include "libmesh/elem.h" 
   34 #include "libmesh/mesh_base.h" 
   35 #include "libmesh/mesh_function.h" 
   36 #include "libmesh/numeric_vector.h" 
   37 #include "libmesh/quadrature.h" 
   38 #include "libmesh/system.h" 
   39 #include "libmesh/tensor_tools.h" 
   40 #include "libmesh/enum_error_estimator_type.h" 
   41 #include "libmesh/enum_norm_type.h" 
   42 #include "libmesh/auto_ptr.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())
 
  219       System & sys = const_cast<System &>(system);
 
  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 = libmesh_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()] +=
 
  338                 static_cast<ErrorVectorReal>
 
  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] +=
 
  356             static_cast<ErrorVectorReal>
 
  379     LOG_SCOPE(
"std::sqrt()", 
"ExactErrorEstimator");
 
  380     for (
auto & val : error_per_cell)
 
  383           libmesh_assert_greater (val, 0.);
 
  390   if (solution_vector && solution_vector != system.
solution.get())
 
  394       System & sys = const_cast<System &>(system);
 
  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.);
 
  
GradientFunctionPointer _exact_deriv
Function pointer to user-provided function which computes the exact derivative of the solution.
 
Manages consistently variables, degrees of freedom, and coefficient vectors.
 
unsigned int n_vars() const
 
void attach_reference_solution(EquationSystems *es_fine)
Attach function similar to system.h which allows the user to attach a second EquationSystems object w...
 
const EquationSystems & get_equation_systems() const
 
const std::vector< Point > & get_xyz() const
 
std::vector< std::unique_ptr< FunctionBase< Gradient > > > _exact_derivs
User-provided functors which compute the exact derivative of the solution for each system.
 
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
Fills the vector di with the global degree of freedom indices for the element.
 
ErrorEstimatorType
Defines an enum for the different types of error estimators which are available.
 
SimpleRange< ChildRefIter > child_ref_range()
Returns a range with all children of a parent element, usable in range-based for loops.
 
virtual void swap(NumericVector< T > &v)
Swaps the contents of this with v.
 
virtual std::unique_ptr< FunctionBase< Output > > clone() const =0
 
This class provides function-like objects for data distributed over a mesh.
 
const std::string & variable_name(const unsigned int i) const
 
This class holds functions that will estimate the error in a finite element solution on a given mesh.
 
The libMesh namespace provides an interface to certain functionality in the library.
 
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...
 
This class forms the foundation from which generic finite elements may be derived.
 
const T_sys & get_system(const std::string &name) 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.
 
const std::vector< Real > & get_JxW() const
 
MetaPhysicL::DualNumber< T, D > sqrt(const MetaPhysicL::DualNumber< T, D > &in)
 
const Parallel::Communicator & comm() const
 
const std::vector< std::vector< OutputTensor > > & get_d2phi() const
 
ValueFunctionPointer _exact_value
Function pointer to user-provided function which computes the exact value of the solution.
 
unsigned int number() const
 
Real weight(unsigned int var) const
 
ExactErrorEstimator()
Constructor.
 
const std::vector< std::vector< OutputGradient > > & get_dphi() const
 
Tensor hessian(const Point &p, const Real time=0.)
 
static std::unique_ptr< NumericVector< T > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
Builds a NumericVector on the processors in communicator comm using the linear solver package specifi...
 
FEMNormType type(unsigned int var) const
 
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
 
Number current_solution(const dof_id_type global_dof_number) 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.
 
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.
 
This is the MeshBase class.
 
virtual ErrorEstimatorType type() const override
 
auto norm_sq() const -> decltype(std::norm(T()))
 
unsigned int variable_scalar_number(const std::string &var, unsigned int component) const
 
auto norm_sq() const -> decltype(std::norm(T()))
 
const MeshBase & get_mesh() const
 
void libmesh_ignore(const Args &...)
 
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.
 
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
 
std::unique_ptr< NumericVector< Number > > current_local_solution
All the values I need to compute my contribution to the simulation at hand.
 
This class defines a tensor in LIBMESH_DIM dimensional Real or Complex space.
 
The ErrorVector is a specialization of the StatisticsVector for error data computed on a finite eleme...
 
EquationSystems * _equation_systems_fine
Constant pointer to the EquationSystems object containing a fine grid solution.
 
const FEType & variable_type(const unsigned int c) const
 
void attach_exact_hessians(std::vector< FunctionBase< Tensor > * > h)
Clone and attach arbitrary functors which compute the exact second derivatives of the EquationSystems...
 
std::unique_ptr< QBase > default_quadrature_rule(const unsigned int dim, const int extraorder=0) const
 
Gradient gptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
 
virtual unsigned int size() const override
 
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...
 
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...
 
This is the EquationSystems class.
 
Real time
For time-dependent problems, this is the time t at the beginning of the current timestep.
 
const Elem * parent() const
 
std::vector< std::unique_ptr< FunctionBase< Number > > > _exact_values
User-provided functors which compute the exact value of the solution for each system.
 
HessianFunctionPointer _exact_hessian
Function pointer to user-provided function which computes the exact hessian of the solution.
 
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
 
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
 
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...
 
void clear_functors()
Helper method for cleanup.
 
This class handles the numbering of degrees of freedom on a mesh.
 
const std::string & 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...
 
This is the base class from which all geometric element types are derived.
 
unsigned short int variable_number(const std::string &var) const
 
void attach_exact_values(std::vector< FunctionBase< Number > * > f)
Clone and attach arbitrary functors which compute the exact values of the EquationSystems' solutions ...
 
const DofMap & get_dof_map() const
 
const std::vector< std::vector< OutputShape > > & get_phi() const
 
void attach_exact_derivs(std::vector< FunctionBase< Gradient > * > g)
Clone and attach arbitrary functors which compute the exact gradients of the EquationSystems' solutio...
 
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
 
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.
 
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
 
Gradient gradient(const Point &p, const Real time=0.)
 
This class provides the ability to map between arbitrary, user-defined strings and several data types...
 
Parameters parameters
Data structure holding arbitrary parameters.