Go to the documentation of this file.
   19 #include "libmesh/dof_map.h" 
   20 #include "libmesh/elem.h" 
   21 #include "libmesh/exact_solution.h" 
   22 #include "libmesh/equation_systems.h" 
   23 #include "libmesh/fe_base.h" 
   24 #include "libmesh/function_base.h" 
   25 #include "libmesh/mesh_base.h" 
   26 #include "libmesh/mesh_function.h" 
   27 #include "libmesh/numeric_vector.h" 
   28 #include "libmesh/parallel.h" 
   29 #include "libmesh/quadrature.h" 
   30 #include "libmesh/wrapped_function.h" 
   31 #include "libmesh/fe_interface.h" 
   32 #include "libmesh/raw_accessor.h" 
   33 #include "libmesh/tensor_tools.h" 
   34 #include "libmesh/enum_norm_type.h" 
   35 #include "libmesh/utility.h" 
   36 #include "libmesh/auto_ptr.h"  
   42   _equation_systems(es),
 
   43   _equation_systems_fine(nullptr),
 
   54       const std::string & sys_name = system.
name();
 
   63           sem[var_name] = std::vector<Real>(5, 0.);
 
  217                                                  const std::string & unknown_name)
 
  221   auto & system_error_map = libmesh_map_find(
_errors, sys_name);
 
  222   return libmesh_map_find(system_error_map, unknown_name);
 
  228                                   const std::string & unknown_name)
 
  232   std::vector<Real> & error_vals = this->
_check_inputs(sys_name,
 
  243         this->_compute_error<Real>(sys_name,
 
  250         this->_compute_error<RealGradient>(sys_name,
 
  256       libmesh_error_msg(
"Invalid variable type!");
 
  265                                const std::string & unknown_name,
 
  270   std::vector<Real> & error_vals = this->
_check_inputs(sys_name,
 
  282       return std::sqrt(error_vals[0] + error_vals[1]);
 
  284       return std::sqrt(error_vals[0] + error_vals[1] + error_vals[2]);
 
  288           libmesh_error_msg(
"Cannot compute HCurl error norm of scalar-valued variables!");
 
  290           return std::sqrt(error_vals[0] + error_vals[5]);
 
  295           libmesh_error_msg(
"Cannot compute HDiv error norm of scalar-valued variables!");
 
  297           return std::sqrt(error_vals[0] + error_vals[6]);
 
  306           libmesh_error_msg(
"Cannot compute HCurl error seminorm of scalar-valued variables!");
 
  313           libmesh_error_msg(
"Cannot compute HDiv error seminorm of scalar-valued variables!");
 
  318       return error_vals[3];
 
  320       return error_vals[4];
 
  323       libmesh_error_msg(
"Currently only Sobolev norms/seminorms are supported!");
 
  334                              const std::string & unknown_name)
 
  339   std::vector<Real> & error_vals = this->
_check_inputs(sys_name,
 
  354                              const std::string & unknown_name)
 
  359   std::vector<Real> & error_vals = this->
_check_inputs(sys_name,
 
  364   return error_vals[3];
 
  374                                 const std::string & unknown_name)
 
  379   std::vector<Real> & error_vals = this->
_check_inputs(sys_name,
 
  384   return error_vals[4];
 
  394                              const std::string & unknown_name)
 
  402   std::vector<Real> & error_vals = this->
_check_inputs(sys_name,
 
  406   return std::sqrt(error_vals[0] + error_vals[1]);
 
  411                                 const std::string & unknown_name)
 
  418                                const std::string & unknown_name)
 
  426                              const std::string & unknown_name)
 
  434   std::vector<Real> & error_vals = this->
_check_inputs(sys_name,
 
  438   return std::sqrt(error_vals[0] + error_vals[1] + error_vals[2]);
 
  447 template<
typename OutputShape>
 
  449                                    const std::string & unknown_name,
 
  450                                    std::vector<Real> & error_vals)
 
  459   libmesh_parallel_only(communicator);
 
  470   const unsigned int sys_num = computed_system.
number();
 
  471   const unsigned int var = computed_system.
variable_number(unknown_name);
 
  472   const unsigned int var_component =
 
  476   std::unique_ptr<MeshFunction> coarse_values;
 
  480       const System & comparison_system
 
  483       std::vector<Number> global_soln;
 
  485       comparison_soln->init(comparison_system.
solution->size(), 
true, 
SERIAL);
 
  486       (*comparison_soln) = global_soln;
 
  488       coarse_values = libmesh_make_unique<MeshFunction>
 
  493       coarse_values->init();
 
  515   const std::set<unsigned char> & elem_dims = 
mesh.elem_dimensions();
 
  525   error_vals = std::vector<Real>(7, 0.);
 
  536       libMesh::err << 
"Error calculation using reference solution not yet\n" 
  537                    << 
"supported for vector-valued elements." 
  539       libmesh_not_implemented();
 
  544   std::vector<std::unique_ptr<FEGenericBase<OutputShape>>> fe_ptrs(4);
 
  545   std::vector<std::unique_ptr<QBase>> q_rules(4);
 
  548   for (
const auto dim : elem_dims)
 
  557       fe_ptrs[
dim]->attach_quadrature_rule (q_rules[
dim].
get());
 
  562   std::vector<dof_id_type> dof_indices;
 
  571   for (
const auto & elem : 
mesh.active_local_element_ptr_range())
 
  580       const unsigned int dim = elem->dim();
 
  590       std::set<subdomain_id_type> subdomain_id;
 
  591       subdomain_id.insert(elem_subid);
 
  599       const std::vector<Real> & JxW = fe->
get_JxW();
 
  603       const std::vector<std::vector<OutputShape>> &  phi_values = fe->
get_phi();
 
  606       const std::vector<std::vector<typename FEGenericBase<OutputShape>::OutputGradient>> &
 
  611       const std::vector<std::vector<typename FEGenericBase<OutputShape>::OutputShape>> * curl_values = 
nullptr;
 
  615       const std::vector<std::vector<typename FEGenericBase<OutputShape>::OutputDivergence>> * div_values = 
nullptr;
 
  623 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES 
  625       const std::vector<std::vector<typename FEGenericBase<OutputShape>::OutputTensor>> &
 
  630       const std::vector<Point> & q_point = fe->
get_xyz();
 
  637       computed_dof_map.
dof_indices    (elem, dof_indices, var);
 
  640       const unsigned int n_qp = qrule->
n_points();
 
  643       const unsigned int n_sf =
 
  644         cast_int<unsigned int>(dof_indices.size());
 
  649       for (
unsigned int qp=0; qp<n_qp; qp++)
 
  657 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES 
  667           for (
unsigned int i=0; i<n_sf; i++)
 
  671               grad_u_h += dphi_values[i][qp]*computed_system.
current_solution (dof_indices[i]);
 
  672 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES 
  673               grad2_u_h += d2phi_values[i][qp]*computed_system.
current_solution (dof_indices[i]);
 
  677                   curl_u_h += (*curl_values)[i][qp]*computed_system.
current_solution (dof_indices[i]);
 
  678                   div_u_h += (*div_values)[i][qp]*computed_system.
current_solution (dof_indices[i]);
 
  687               for (
unsigned int c = 0; c < n_vec_dim; c++)
 
  688                 exact_val_accessor(c) =
 
  690                   component(var_component+c, q_point[qp], time);
 
  696               (*coarse_values)(q_point[qp],time,output,&subdomain_id);
 
  697               exact_val = output(0);
 
  703           error_vals[0] += JxW[qp]*error_sq;
 
  706           error_vals[3] += JxW[qp]*
norm;
 
  708           if (error_vals[4]<
norm) { error_vals[4] = 
norm; }
 
  716               for (
unsigned int c = 0; c < n_vec_dim; c++)
 
  717                 for (
unsigned int d = 0; d < LIBMESH_DIM; d++)
 
  718                   exact_grad_accessor(d + c*LIBMESH_DIM) =
 
  720                     component(var_component+c, q_point[qp], time)(d);
 
  725               std::vector<Gradient> output(1);
 
  726               coarse_values->gradient(q_point[qp],time,output,&subdomain_id);
 
  732           error_vals[1] += JxW[qp]*grad_error.
norm_sq();
 
  772 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES 
  783                 libmesh_not_implemented();
 
  785               for (
unsigned int c = 0; c < n_vec_dim; c++)
 
  786                 for (
unsigned int d = 0; d < 
dim; d++)
 
  787                   for (
unsigned int e =0; e < 
dim; e++)
 
  788                     exact_hess_accessor(d + e*
dim + c*
dim*
dim) =
 
  790                       component(var_component+c, q_point[qp], time)(d,e);
 
  795               std::vector<Tensor> output(1);
 
  796               coarse_values->hessian(q_point[qp],time,output,&subdomain_id);
 
  797               exact_hess = output[0];
 
  803           error_vals[2] += JxW[qp]*grad2_error.
norm_sq();
 
  811   Real l_infty_norm = error_vals[4];
 
  812   communicator.max(l_infty_norm);
 
  813   communicator.sum(error_vals);
 
  814   error_vals[4] = l_infty_norm;
 
  818 template void ExactSolution::_compute_error<Real>(
const std::string &, 
const std::string &, std::vector<Real> &);
 
  819 template void ExactSolution::_compute_error<RealGradient>(
const std::string &, 
const std::string &, std::vector<Real> &);
 
  
The QBase class provides the basic functionality from which various quadrature rules can be derived.
 
Manages consistently variables, degrees of freedom, and coefficient vectors.
 
int _extra_order
Extra order to use for quadrature rule.
 
This class handles the computation of the L2 and/or H1 error for the Systems in the EquationSystems o...
 
This class provides single index access to FieldType (i.e.
 
unsigned int n_vars() const
 
Gradient exact_grad(const Point &, const Parameters &, const std::string &, const std::string &)
 
ExactSolution(const EquationSystems &es)
Constructor.
 
void attach_exact_derivs(const std::vector< FunctionBase< Gradient > * > &g)
Clone and attach arbitrary functors which compute the exact gradients of the EquationSystems' solutio...
 
std::set< subdomain_id_type > _excluded_subdomains
Elements in a subdomain from this set are skipped during the error computation.
 
const std::vector< Point > & get_xyz() const
 
static unsigned int n_vec_dim(const MeshBase &mesh, const FEType &fe_type)
 
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 calculati...
 
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.
 
Real l1_error(const std::string &sys_name, const std::string &unknown_name)
 
virtual std::unique_ptr< FunctionBase< Output > > clone() const =0
 
unsigned int n_points() const
 
const std::string & variable_name(const unsigned int i) const
 
The libMesh namespace provides an interface to certain functionality in the library.
 
std::vector< std::unique_ptr< FunctionBase< Tensor > > > _exact_hessians
User-provided functors which compute the exact hessians of the solution for each system.
 
This class forms the foundation from which generic finite elements may be derived.
 
const T_sys & get_system(const std::string &name) const
 
Real h1_error(const std::string &sys_name, const std::string &unknown_name)
 
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
 
unsigned int number() const
 
Real h2_error(const std::string &sys_name, const std::string &unknown_name)
 
const std::vector< std::vector< OutputGradient > > & get_dphi() const
 
const std::vector< std::vector< OutputDivergence > > & get_div_phi() const
 
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
 
Real hcurl_error(const std::string &sys_name, const std::string &unknown_name)
 
bool has_system(const std::string &name) const
 
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...
 
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
 
Number current_solution(const dof_id_type global_dof_number) const
 
std::map< std::string, SystemErrorMap > _errors
A map of SystemErrorMaps, which contains entries for each system in the EquationSystems object.
 
The IntRange templated class is intended to make it easy to loop over integers which are indices of a...
 
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...
 
std::vector< std::unique_ptr< FunctionBase< Number > > > _exact_values
User-provided functors which compute the exact value of the solution for each system.
 
This is the MeshBase class.
 
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...
 
auto norm_sq() const -> decltype(std::norm(T()))
 
Wrap a libMesh-style function pointer into a FunctionBase object.
 
unsigned int variable_scalar_number(const std::string &var, unsigned int component) const
 
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...
 
Real hdiv_error(const std::string &sys_name, const std::string &unknown_name)
 
const MeshBase & get_mesh() 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.
 
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
 
Real error_norm(const std::string &sys_name, const std::string &unknown_name, const FEMNormType &norm)
 
std::vector< std::unique_ptr< FunctionBase< Gradient > > > _exact_derivs
User-provided functors which compute the exact derivative of the solution for each system.
 
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
 
const EquationSystems & _equation_systems
Constant reference to the EquationSystems object used for the simulation.
 
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)
 
unsigned int n_systems() const
 
TensorTools::MakeNumber< OutputShape >::type OutputNumber
 
Real l2_error(const std::string &sys_name, const std::string &unknown_name)
 
void compute_error(const std::string &sys_name, const std::string &unknown_name)
Computes and stores the error in the solution value e = u-u_h, the gradient grad(e) = grad(u) - grad(...
 
This is the EquationSystems class.
 
void attach_exact_values(const std::vector< FunctionBase< Number > * > &f)
Clone and attach arbitrary functors which compute the exact values of the EquationSystems' solutions ...
 
TensorTools::DecrementRank< OutputNumber >::type OutputNumberDivergence
 
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
 
const Elem & get(const ElemType type_in)
 
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
 
This class handles the numbering of degrees of freedom on a mesh.
 
const std::string & name() const
 
static FEFieldType field_type(const FEType &fe_type)
 
const std::vector< std::vector< OutputShape > > & get_curl_phi() const
 
void _compute_error(const std::string &sys_name, const std::string &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...
 
unsigned short int variable_number(const std::string &var) const
 
MetaPhysicL::DualNumber< T, D > norm(const MetaPhysicL::DualNumber< T, D > &in)
 
std::vector< Real > & _check_inputs(const std::string &sys_name, const std::string &unknown_name)
This function is responsible for checking the validity of the sys_name and unknown_name inputs.
 
const DofMap & get_dof_map() const
 
const std::vector< std::vector< OutputShape > > & get_phi() const
 
Real l_inf_error(const std::string &sys_name, const std::string &unknown_name)
 
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
 
bool active_on_subdomain(subdomain_id_type sid) 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.
 
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
 
std::map< std::string, std::vector< Real > > SystemErrorMap
Data structure which stores the errors: ||e|| = ||u - u_h|| ||grad(e)|| = ||grad(u) - grad(u_h)|| for...
 
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...
 
const EquationSystems * _equation_systems_fine
Constant pointer to the EquationSystems object containing the fine grid solution.
 
Parameters parameters
Data structure holding arbitrary parameters.