libMesh
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
libMesh::ExactSolution Class Reference

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 &parameters, 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 &parameters, 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...
 
ExactSolutionoperator= (const ExactSolution &)=delete
 
ExactSolutionoperator= (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...
 

Detailed Description

This class handles the computation of the L2 and/or H1 error for the Systems in the EquationSystems object which is passed to it.

Note
For this to be useful, the user must attach at least one, and possibly two, functions which can compute the exact solution and its derivative for any component of any system. These are the exact_value and exact_deriv functions below.
Author
Benjamin S. Kirk
John W. Peterson (modifications for libmesh)
Date
2004

Definition at line 65 of file exact_solution.h.

Member Typedef Documentation

◆ GradientFunctionPointer

typedef Gradient(* libMesh::ExactSolution::GradientFunctionPointer) (const Point &p, const Parameters &parameters, 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.

◆ HessianFunctionPointer

typedef Tensor(* libMesh::ExactSolution::HessianFunctionPointer) (const Point &p, const Parameters &parameters, 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.

◆ SystemErrorMap

typedef std::map<std::string, std::vector<Real>, std::less<> > libMesh::ExactSolution::SystemErrorMap
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.

◆ ValueFunctionPointer

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.

Constructor & Destructor Documentation

◆ ExactSolution() [1/3]

libMesh::ExactSolution::ExactSolution ( const EquationSystems es)
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().

45  :
47  _equation_systems_fine(nullptr),
48  _extra_order(1)
49 {
50  // Initialize the _errors data structure which holds all
51  // the eventual values of the error.
52  for (auto sys : make_range(_equation_systems.n_systems()))
53  {
54  // Reference to the system
55  const System & system = _equation_systems.get_system(sys);
56 
57  // The name of the system
58  const std::string & sys_name = system.name();
59 
60  // The SystemErrorMap to be inserted
62 
63  for (auto var : make_range(system.n_vars()))
64  {
65  // The name of this variable
66  const std::string & var_name = system.variable_name(var);
67  sem[var_name] = std::vector<Real>(5, 0.);
68  }
69 
70  _errors[sys_name] = sem;
71  }
72 }
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...
unsigned int n_systems() const
const EquationSystems & _equation_systems
Constant reference to the EquationSystems object used for the simulation.
std::map< std::string, SystemErrorMap, std::less<> > _errors
A map of SystemErrorMaps, which contains entries for each system in the EquationSystems object...
int _extra_order
Extra order to use for quadrature rule.
const T_sys & get_system(std::string_view name) const
const EquationSystems * _equation_systems_fine
Constant pointer to the EquationSystems object containing the fine grid solution. ...
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:134

◆ ExactSolution() [2/3]

libMesh::ExactSolution::ExactSolution ( const ExactSolution )
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.

◆ ExactSolution() [3/3]

libMesh::ExactSolution::ExactSolution ( ExactSolution &&  )
default

Move constructor and destructor are defaulted out-of-line (in the C file) to play nicely with our forward declarations.

◆ ~ExactSolution()

libMesh::ExactSolution::~ExactSolution ( )
default

Member Function Documentation

◆ _check_inputs()

std::vector< Real > & libMesh::ExactSolution::_check_inputs ( std::string_view  sys_name,
std::string_view  unknown_name 
)
private

This function is responsible for checking the validity of the sys_name and unknown_name inputs.

Returns
A reference to the proper vector for storing the values.

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().

222 {
223  // Return a reference to the proper error entry, or throw an error
224  // if it doesn't exist.
225  auto & system_error_map = libmesh_map_find(_errors, sys_name);
226  return libmesh_map_find(system_error_map, unknown_name);
227 }
std::map< std::string, SystemErrorMap, std::less<> > _errors
A map of SystemErrorMaps, which contains entries for each system in the EquationSystems object...

◆ _compute_error()

template<typename OutputShape >
template LIBMESH_EXPORT void libMesh::ExactSolution::_compute_error< RealGradient > ( std::string_view  sys_name,
std::string_view  unknown_name,
std::vector< Real > &  error_vals 
)
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().

455 {
456  // Make sure we aren't "overconfigured"
458 
459  // We need a communicator.
460  const Parallel::Communicator & communicator(_equation_systems.comm());
461 
462  // This function must be run on all processors at once
463  libmesh_parallel_only(communicator);
464 
465  // Get a reference to the system whose error is being computed.
466  // If we have a fine grid, however, we'll integrate on that instead
467  // for more accuracy.
468  const System & computed_system = _equation_systems_fine ?
470  _equation_systems.get_system (sys_name);
471 
472  const MeshBase & mesh = computed_system.get_mesh();
473 
474  const Real time = _equation_systems.get_system(sys_name).time;
475 
476  const unsigned int sys_num = computed_system.number();
477  const unsigned int var = computed_system.variable_number(unknown_name);
478  unsigned int var_component = 0;
479  for (const auto var_num : make_range(var))
480  {
481  const auto & var_fe_type = computed_system.variable_type(var_num);
482  const auto var_vec_dim = FEInterface::n_vec_dim(mesh, var_fe_type);
483  var_component += var_vec_dim;
484  }
485 
486  // Prepare a global solution, a serialized mesh, and a MeshFunction
487  // of the coarse system, if we need them for fine-system integration
488  std::unique_ptr<MeshFunction> coarse_values;
489  std::unique_ptr<NumericVector<Number>> comparison_soln =
491  MeshSerializer
492  serial(const_cast<MeshBase&>(_equation_systems.get_mesh()),
495  {
496  const System & comparison_system
497  = _equation_systems.get_system(sys_name);
498 
499  std::vector<Number> global_soln;
500  comparison_system.update_global_solution(global_soln);
501  comparison_soln->init(comparison_system.solution->size(), true, SERIAL);
502  (*comparison_soln) = global_soln;
503 
504  coarse_values = std::make_unique<MeshFunction>
506  *comparison_soln,
507  comparison_system.get_dof_map(),
508  comparison_system.variable_number(unknown_name));
509  coarse_values->init();
510  }
511 
512  // Initialize any functors we're going to use
513  for (auto & ev : _exact_values)
514  if (ev)
515  ev->init();
516 
517  for (auto & ed : _exact_derivs)
518  if (ed)
519  ed->init();
520 
521  for (auto & eh : _exact_hessians)
522  if (eh)
523  eh->init();
524 
525  // Get a reference to the dofmap and mesh for that system
526  const DofMap & computed_dof_map = computed_system.get_dof_map();
527 
528  // Grab which element dimensions are present in the mesh
529  const std::set<unsigned char> & elem_dims = mesh.elem_dimensions();
530 
531  // Zero the error before summation
532  // 0 - sum of square of function error (L2)
533  // 1 - sum of square of gradient error (H1 semi)
534  // 2 - sum of square of Hessian error (H2 semi)
535  // 3 - sum of sqrt(square of function error) (L1)
536  // 4 - max of sqrt(square of function error) (Linfty)
537  // 5 - sum of square of curl error (HCurl semi)
538  // 6 - sum of square of div error (HDiv semi)
539  error_vals = std::vector<Real>(7, 0.);
540 
541  // Construct Quadrature rule based on default quadrature order
542  const FEType & fe_type = computed_dof_map.variable_type(var);
543  const auto field_type = FEInterface::field_type(fe_type);
544 
545  unsigned int n_vec_dim = FEInterface::n_vec_dim( mesh, fe_type );
546 
547  // FIXME: MeshFunction needs to be updated to support vector-valued
548  // elements before we can use a reference solution.
549  if ((n_vec_dim > 1) && _equation_systems_fine)
550  {
551  libMesh::err << "Error calculation using reference solution not yet\n"
552  << "supported for vector-valued elements."
553  << std::endl;
554  libmesh_not_implemented();
555  }
556 
557 
558  // Allow space for dims 0-3, even if we don't use them all
559  std::vector<std::unique_ptr<FEGenericBase<OutputShape>>> fe_ptrs(4);
560  std::vector<std::unique_ptr<QBase>> q_rules(4);
561 
562  // Prepare finite elements for each dimension present in the mesh
563  for (const auto dim : elem_dims)
564  {
565  // Build a quadrature rule.
566  q_rules[dim] = fe_type.default_quadrature_rule (dim, _extra_order);
567 
568  // Construct finite element object
569  fe_ptrs[dim] = FEGenericBase<OutputShape>::build(dim, fe_type);
570 
571  // Attach quadrature rule to FE object
572  fe_ptrs[dim]->attach_quadrature_rule (q_rules[dim].get());
573  }
574 
575  // The global degree of freedom indices associated
576  // with the local degrees of freedom.
577  std::vector<dof_id_type> dof_indices;
578 
579 
580  //
581  // Begin the loop over the elements
582  //
583  // TODO: this ought to be threaded (and using subordinate
584  // MeshFunction objects in each thread rather than a single
585  // master)
586  for (const auto & elem : mesh.active_local_element_ptr_range())
587  {
588  // Skip this element if it is in a subdomain excluded by the user.
589  const subdomain_id_type elem_subid = elem->subdomain_id();
590  if (_excluded_subdomains.count(elem_subid))
591  continue;
592 
593  // The spatial dimension of the current Elem. FEs and other data
594  // are indexed on dim.
595  const unsigned int dim = elem->dim();
596 
597  // If the variable is not active on this subdomain, don't bother
598  if (!computed_system.variable(var).active_on_subdomain(elem_subid))
599  continue;
600 
601  /* If the variable is active, then we're going to restrict the
602  MeshFunction evaluations to the current element subdomain.
603  This is for cases such as mixed dimension meshes where we want
604  to restrict the calculation to one particular domain. */
605  std::set<subdomain_id_type> subdomain_id;
606  subdomain_id.insert(elem_subid);
607 
608  FEGenericBase<OutputShape> * fe = fe_ptrs[dim].get();
609  QBase * qrule = q_rules[dim].get();
610  libmesh_assert(fe);
611  libmesh_assert(qrule);
612 
613  // The Jacobian*weight at the quadrature points.
614  const std::vector<Real> & JxW = fe->get_JxW();
615 
616  // The value of the shape functions at the quadrature points
617  // i.e. phi(i) = phi_values[i][qp]
618  const std::vector<std::vector<OutputShape>> & phi_values = fe->get_phi();
619 
620  // The value of the shape function gradients at the quadrature points
621  const std::vector<std::vector<typename FEGenericBase<OutputShape>::OutputGradient>> &
622  dphi_values = fe->get_dphi();
623 
624  // The value of the shape function curls at the quadrature points
625  // Only computed for vector-valued elements
626  const std::vector<std::vector<typename FEGenericBase<OutputShape>::OutputShape>> * curl_values = nullptr;
627 
628  // The value of the shape function divergences at the quadrature points
629  // Only computed for vector-valued elements
630  const std::vector<std::vector<typename FEGenericBase<OutputShape>::OutputDivergence>> * div_values = nullptr;
631 
632  if (field_type == TYPE_VECTOR)
633  {
634  curl_values = &fe->get_curl_phi();
635  div_values = &fe->get_div_phi();
636  }
637 
638 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
639  // The value of the shape function second derivatives at the quadrature points
640  // Not computed for vector-valued elements
641  const std::vector<std::vector<typename FEGenericBase<OutputShape>::OutputTensor>> *
642  d2phi_values = nullptr;
643 
644  if (field_type != TYPE_VECTOR)
645  d2phi_values = &fe->get_d2phi();
646 #endif
647 
648  // The XYZ locations (in physical space) of the quadrature points
649  const std::vector<Point> & q_point = fe->get_xyz();
650 
651  // reinitialize the element-specific data
652  // for the current element
653  fe->reinit (elem);
654 
655  // Get the local to global degree of freedom maps
656  computed_dof_map.dof_indices (elem, dof_indices, var);
657 
658  // The number of quadrature points
659  const unsigned int n_qp = qrule->n_points();
660 
661  // The number of shape functions
662  const unsigned int n_sf =
663  cast_int<unsigned int>(dof_indices.size());
664 
665  //
666  // Begin the loop over the Quadrature points.
667  //
668  for (unsigned int qp=0; qp<n_qp; qp++)
669  {
670  // Real u_h = 0.;
671  // RealGradient grad_u_h;
672 
674 
676 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
678 #endif
679  typename FEGenericBase<OutputShape>::OutputNumber curl_u_h(0.0);
681 
682  // Compute solution values at the current
683  // quadrature point. This requires a sum
684  // over all the shape functions evaluated
685  // at the quadrature point.
686  for (unsigned int i=0; i<n_sf; i++)
687  {
688  // Values from current solution.
689  u_h += phi_values[i][qp]*computed_system.current_solution (dof_indices[i]);
690  grad_u_h += dphi_values[i][qp]*computed_system.current_solution (dof_indices[i]);
691  if (field_type == TYPE_VECTOR)
692  {
693  curl_u_h += (*curl_values)[i][qp]*computed_system.current_solution (dof_indices[i]);
694  div_u_h += (*div_values)[i][qp]*computed_system.current_solution (dof_indices[i]);
695  }
696  else
697  {
698 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
699  grad2_u_h += (*d2phi_values)[i][qp]*computed_system.current_solution (dof_indices[i]);
700 #endif
701  }
702  }
703 
704  // Compute the value of the error at this quadrature point
705  typename FEGenericBase<OutputShape>::OutputNumber exact_val(0);
706  RawAccessor<typename FEGenericBase<OutputShape>::OutputNumber> exact_val_accessor( exact_val, dim );
707  if (_exact_values.size() > sys_num && _exact_values[sys_num])
708  {
709  for (unsigned int c = 0; c < n_vec_dim; c++)
710  exact_val_accessor(c) =
711  _exact_values[sys_num]->
712  component(var_component+c, q_point[qp], time);
713  }
714  else if (_equation_systems_fine)
715  {
716  // FIXME: Needs to be updated for vector-valued elements
717  DenseVector<Number> output(1);
718  (*coarse_values)(q_point[qp],time,output,&subdomain_id);
719  exact_val = output(0);
720  }
721  const typename FEGenericBase<OutputShape>::OutputNumber val_error = u_h - exact_val;
722 
723  // Add the squares of the error to each contribution
724  Real error_sq = TensorTools::norm_sq(val_error);
725  error_vals[0] += JxW[qp]*error_sq;
726 
727  Real norm = sqrt(error_sq);
728  error_vals[3] += JxW[qp]*norm;
729 
730  if (error_vals[4]<norm) { error_vals[4] = norm; }
731 
732  // Compute the value of the error in the gradient at this
733  // quadrature point
735  RawAccessor<typename FEGenericBase<OutputShape>::OutputNumberGradient> exact_grad_accessor( exact_grad, LIBMESH_DIM );
736  if (_exact_derivs.size() > sys_num && _exact_derivs[sys_num])
737  {
738  for (unsigned int c = 0; c < n_vec_dim; c++)
739  for (unsigned int d = 0; d < LIBMESH_DIM; d++)
740  exact_grad_accessor(d + c*LIBMESH_DIM) =
741  _exact_derivs[sys_num]->
742  component(var_component+c, q_point[qp], time)(d);
743  }
744  else if (_equation_systems_fine)
745  {
746  // FIXME: Needs to be updated for vector-valued elements
747  std::vector<Gradient> output(1);
748  coarse_values->gradient(q_point[qp],time,output,&subdomain_id);
749  exact_grad = output[0];
750  }
751 
752  const typename FEGenericBase<OutputShape>::OutputNumberGradient grad_error = grad_u_h - exact_grad;
753 
754  error_vals[1] += JxW[qp]*grad_error.norm_sq();
755 
756 
757  if (field_type == TYPE_VECTOR)
758  {
759  // Compute the value of the error in the curl at this
760  // quadrature point
761  typename FEGenericBase<OutputShape>::OutputNumber exact_curl(0.0);
762  if (_exact_derivs.size() > sys_num && _exact_derivs[sys_num])
763  {
764  exact_curl = TensorTools::curl_from_grad( exact_grad );
765  }
766  else if (_equation_systems_fine)
767  {
768  // FIXME: Need to implement curl for MeshFunction and support reference
769  // solution for vector-valued elements
770  }
771 
772  const typename FEGenericBase<OutputShape>::OutputNumber curl_error = curl_u_h - exact_curl;
773 
774  error_vals[5] += JxW[qp]*TensorTools::norm_sq(curl_error);
775 
776  // Compute the value of the error in the divergence at this
777  // quadrature point
779  if (_exact_derivs.size() > sys_num && _exact_derivs[sys_num])
780  {
781  exact_div = TensorTools::div_from_grad( exact_grad );
782  }
783  else if (_equation_systems_fine)
784  {
785  // FIXME: Need to implement div for MeshFunction and support reference
786  // solution for vector-valued elements
787  }
788 
789  const typename FEGenericBase<OutputShape>::OutputNumberDivergence div_error = div_u_h - exact_div;
790 
791  error_vals[6] += JxW[qp]*TensorTools::norm_sq(div_error);
792  }
793 
794 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
795  // Compute the value of the error in the hessian at this
796  // quadrature point
798  RawAccessor<typename FEGenericBase<OutputShape>::OutputNumberTensor> exact_hess_accessor( exact_hess, dim );
799  if (_exact_hessians.size() > sys_num && _exact_hessians[sys_num])
800  {
801  //FIXME: This needs to be implemented to support rank 3 tensors
802  // which can't happen until type_n_tensor is fully implemented
803  // and a RawAccessor<TypeNTensor> is fully implemented
804  if (field_type == TYPE_VECTOR)
805  libmesh_not_implemented();
806 
807  for (unsigned int c = 0; c < n_vec_dim; c++)
808  for (unsigned int d = 0; d < dim; d++)
809  for (unsigned int e =0; e < dim; e++)
810  exact_hess_accessor(d + e*dim + c*dim*dim) =
811  _exact_hessians[sys_num]->
812  component(var_component+c, q_point[qp], time)(d,e);
813 
814  // FIXME: operator- is not currently implemented for TypeNTensor
815  const typename FEGenericBase<OutputShape>::OutputNumberTensor grad2_error = grad2_u_h - exact_hess;
816  error_vals[2] += JxW[qp]*grad2_error.norm_sq();
817  }
818  else if (_equation_systems_fine)
819  {
820  // FIXME: Needs to be updated for vector-valued elements
821  std::vector<Tensor> output(1);
822  coarse_values->hessian(q_point[qp],time,output,&subdomain_id);
823  exact_hess = output[0];
824 
825  // FIXME: operator- is not currently implemented for TypeNTensor
826  const typename FEGenericBase<OutputShape>::OutputNumberTensor grad2_error = grad2_u_h - exact_hess;
827  error_vals[2] += JxW[qp]*grad2_error.norm_sq();
828  }
829 #endif
830 
831  } // end qp loop
832  } // end element loop
833 
834  // Add up the error values on all processors, except for the L-infty
835  // norm, for which the maximum is computed.
836  Real l_infty_norm = error_vals[4];
837  communicator.max(l_infty_norm);
838  communicator.sum(error_vals);
839  error_vals[4] = l_infty_norm;
840 }
OStreamProxy err
TensorTools::DecrementRank< OutputNumber >::type OutputNumberDivergence
Definition: fe_base.h:126
Number div_from_grad(const VectorValue< Number > &grad)
Dummy. Divergence of a scalar not defined, but is needed for ExactSolution to compile.
Definition: tensor_tools.C:54
const EquationSystems & _equation_systems
Constant reference to the EquationSystems object used for the simulation.
unsigned int dim
TestClass subdomain_id_type
Based on the 4-byte comment warning above, this probably doesn&#39;t work with exodusII at all...
Definition: id_types.h:43
int _extra_order
Extra order to use for quadrature rule.
TensorTools::IncrementRank< OutputNumberGradient >::type OutputNumberTensor
Definition: fe_base.h:125
MeshBase & mesh
static FEFieldType field_type(const FEType &fe_type)
const Parallel::Communicator & comm() const
TensorTools::IncrementRank< OutputNumber >::type OutputNumberGradient
Definition: fe_base.h:124
ADRealEigenVector< T, D, asd > sqrt(const ADRealEigenVector< T, D, asd > &)
Definition: type_vector.h:53
const T_sys & get_system(std::string_view name) const
const EquationSystems * _equation_systems_fine
Constant pointer to the EquationSystems object containing the fine grid solution. ...
Gradient exact_grad(const Point &, const Parameters &, const std::string &, const std::string &)
Definition: mysystems.h:25
std::set< subdomain_id_type > _excluded_subdomains
Elements in a subdomain from this set are skipped during the error computation.
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
libmesh_assert(ctx)
std::vector< std::unique_ptr< FunctionBase< Gradient > > > _exact_derivs
User-provided functors which compute the exact derivative of the solution for each system...
auto norm(const T &a) -> decltype(std::abs(a))
Definition: tensor_tools.h:74
TensorTools::MakeNumber< OutputShape >::type OutputNumber
Definition: fe_base.h:123
static unsigned int n_vec_dim(const MeshBase &mesh, const FEType &fe_type)
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...
std::vector< std::unique_ptr< FunctionBase< Tensor > > > _exact_hessians
User-provided functors which compute the exact hessians of the solution for each system.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
DIE A HORRIBLE DEATH HERE typedef MPI_Comm communicator
auto norm_sq(const T &a) -> decltype(std::norm(a))
Definition: tensor_tools.h:104
const MeshBase & get_mesh() const
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:134
std::vector< std::unique_ptr< FunctionBase< Number > > > _exact_values
User-provided functors which compute the exact value of the solution for each system.
Number curl_from_grad(const VectorValue< Number > &)
Definition: tensor_tools.C:28

◆ attach_exact_deriv() [1/2]

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().

170 {
171  if (_exact_derivs.size() <= sys_num)
172  _exact_derivs.resize(sys_num+1);
173 
174  if (g)
175  _exact_derivs[sys_num] = g->clone();
176 }
std::vector< std::unique_ptr< FunctionBase< Gradient > > > _exact_derivs
User-provided functors which compute the exact derivative of the solution for each system...
virtual std::unique_ptr< FunctionBase< Output > > clone() const =0

◆ attach_exact_deriv() [2/2]

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.

139 {
141 
142  // Clear out any previous _exact_derivs entries, then add a new
143  // entry for each system.
144  _exact_derivs.clear();
145 
146  for (auto sys : make_range(_equation_systems.n_systems()))
147  {
148  const System & system = _equation_systems.get_system(sys);
149  _exact_derivs.emplace_back(std::make_unique<WrappedFunction<Gradient>>(system, gptr, &_equation_systems.parameters));
150  }
151 
152  // If we're using exact values, we're not using a fine grid solution
153  _equation_systems_fine = nullptr;
154 }
unsigned int n_systems() const
const EquationSystems & _equation_systems
Constant reference to the EquationSystems object used for the simulation.
const T_sys & get_system(std::string_view name) const
const EquationSystems * _equation_systems_fine
Constant pointer to the EquationSystems object containing the fine grid solution. ...
libmesh_assert(ctx)
std::vector< std::unique_ptr< FunctionBase< Gradient > > > _exact_derivs
User-provided functors which compute the exact derivative of the solution for each system...
Gradient gptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:95
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:134
Parameters parameters
Data structure holding arbitrary parameters.

◆ attach_exact_derivs()

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().

158 {
159  // Automatically delete any previous _exact_derivs entries, then add a new
160  // entry for each system.
161  _exact_derivs.clear();
162 
163  for (auto ptr : g)
164  _exact_derivs.emplace_back(ptr ? ptr->clone() : nullptr);
165 }
std::vector< std::unique_ptr< FunctionBase< Gradient > > > _exact_derivs
User-provided functors which compute the exact derivative of the solution for each system...

◆ attach_exact_hessian() [1/2]

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().

211 {
212  if (_exact_hessians.size() <= sys_num)
213  _exact_hessians.resize(sys_num+1);
214 
215  if (h)
216  _exact_hessians[sys_num] = h->clone();
217 }
std::vector< std::unique_ptr< FunctionBase< Tensor > > > _exact_hessians
User-provided functors which compute the exact hessians of the solution for each system.

◆ attach_exact_hessian() [2/2]

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.

180 {
181  libmesh_assert(hptr);
182 
183  // Clear out any previous _exact_hessians entries, then add a new
184  // entry for each system.
185  _exact_hessians.clear();
186 
187  for (auto sys : make_range(_equation_systems.n_systems()))
188  {
189  const System & system = _equation_systems.get_system(sys);
190  _exact_hessians.emplace_back(std::make_unique<WrappedFunction<Tensor>>(system, hptr, &_equation_systems.parameters));
191  }
192 
193  // If we're using exact values, we're not using a fine grid solution
194  _equation_systems_fine = nullptr;
195 }
unsigned int n_systems() const
const EquationSystems & _equation_systems
Constant reference to the EquationSystems object used for the simulation.
const T_sys & get_system(std::string_view name) const
const EquationSystems * _equation_systems_fine
Constant pointer to the EquationSystems object containing the fine grid solution. ...
libmesh_assert(ctx)
std::vector< std::unique_ptr< FunctionBase< Tensor > > > _exact_hessians
User-provided functors which compute the exact hessians of the solution for each system.
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:134
Parameters parameters
Data structure holding arbitrary parameters.

◆ attach_exact_hessians()

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.

199 {
200  // Automatically delete any previous _exact_hessians entries, then add a new
201  // entry for each system.
202  _exact_hessians.clear();
203 
204  for (auto ptr : h)
205  _exact_hessians.emplace_back(ptr ? ptr->clone() : nullptr);
206 }
std::vector< std::unique_ptr< FunctionBase< Tensor > > > _exact_hessians
User-provided functors which compute the exact hessians of the solution for each system.

◆ attach_exact_value() [1/2]

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().

129 {
130  if (_exact_values.size() <= sys_num)
131  _exact_values.resize(sys_num+1);
132 
133  if (f)
134  _exact_values[sys_num] = f->clone();
135 }
virtual std::unique_ptr< FunctionBase< Output > > clone() const =0
std::vector< std::unique_ptr< FunctionBase< Number > > > _exact_values
User-provided functors which compute the exact value of the solution for each system.

◆ attach_exact_value() [2/2]

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.

98 {
100 
101  // Clear out any previous _exact_values entries, then add a new
102  // entry for each system.
103  _exact_values.clear();
104 
105  for (auto sys : make_range(_equation_systems.n_systems()))
106  {
107  const System & system = _equation_systems.get_system(sys);
108  _exact_values.emplace_back(std::make_unique<WrappedFunction<Number>>(system, fptr, &_equation_systems.parameters));
109  }
110 
111  // If we're using exact values, we're not using a fine grid solution
112  _equation_systems_fine = nullptr;
113 }
unsigned int n_systems() const
const EquationSystems & _equation_systems
Constant reference to the EquationSystems object used for the simulation.
const T_sys & get_system(std::string_view name) const
const EquationSystems * _equation_systems_fine
Constant pointer to the EquationSystems object containing the fine grid solution. ...
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:80
libmesh_assert(ctx)
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:134
Parameters parameters
Data structure holding arbitrary parameters.
std::vector< std::unique_ptr< FunctionBase< Number > > > _exact_values
User-provided functors which compute the exact value of the solution for each system.

◆ attach_exact_values()

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().

117 {
118  // Automatically delete any previous _exact_values entries, then add a new
119  // entry for each system.
120  _exact_values.clear();
121 
122  for (auto ptr : f)
123  _exact_values.emplace_back(ptr ? ptr->clone() : nullptr);
124 }
std::vector< std::unique_ptr< FunctionBase< Number > > > _exact_values
User-provided functors which compute the exact value of the solution for each system.

◆ attach_reference_solution()

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().

86 {
87  libmesh_assert(es_fine);
88  _equation_systems_fine = es_fine;
89 
90  // If we're using a fine grid solution, we're not using exact values
91  _exact_values.clear();
92  _exact_derivs.clear();
93  _exact_hessians.clear();
94 }
const EquationSystems * _equation_systems_fine
Constant pointer to the EquationSystems object containing the fine grid solution. ...
libmesh_assert(ctx)
std::vector< std::unique_ptr< FunctionBase< Gradient > > > _exact_derivs
User-provided functors which compute the exact derivative of the solution for each system...
std::vector< std::unique_ptr< FunctionBase< Tensor > > > _exact_hessians
User-provided functors which compute the exact hessians of the solution for each system.
std::vector< std::unique_ptr< FunctionBase< Number > > > _exact_values
User-provided functors which compute the exact value of the solution for each system.

◆ compute_error()

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().

233 {
234  // Check the inputs for validity, and get a reference
235  // to the proper location to store the error
236  std::vector<Real> & error_vals = this->_check_inputs(sys_name,
237  unknown_name);
238 
240  const System & sys = _equation_systems.get_system<System>( sys_name );
241 
242  libmesh_assert( sys.has_variable( unknown_name ) );
243  switch( FEInterface::field_type(sys.variable_type( unknown_name )) )
244  {
245  case TYPE_SCALAR:
246  {
247  this->_compute_error<Real>(sys_name,
248  unknown_name,
249  error_vals);
250  break;
251  }
252  case TYPE_VECTOR:
253  {
254  this->_compute_error<RealGradient>(sys_name,
255  unknown_name,
256  error_vals);
257  break;
258  }
259  default:
260  libmesh_error_msg("Invalid variable type!");
261  }
262 }
const EquationSystems & _equation_systems
Constant reference to the EquationSystems object used for the simulation.
bool has_system(std::string_view name) const
static FEFieldType field_type(const FEType &fe_type)
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...
const T_sys & get_system(std::string_view name) const
libmesh_assert(ctx)

◆ error_norm()

Real libMesh::ExactSolution::error_norm ( std::string_view  sys_name,
std::string_view  unknown_name,
const FEMNormType norm 
)
Returns
The error in the requested norm for the system sys_name for the unknown unknown_name.
Note
No error computations are actually performed, you must call compute_error() for that.
The result is not exact, but an approximation based on the chosen quadrature rule.

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().

271 {
272  // Check the inputs for validity, and get a reference
273  // to the proper location to store the error
274  std::vector<Real> & error_vals = this->_check_inputs(sys_name,
275  unknown_name);
276 
278  libmesh_assert(_equation_systems.get_system(sys_name).has_variable( unknown_name ));
279  const FEType & fe_type = _equation_systems.get_system(sys_name).variable_type(unknown_name);
280 
281  switch (norm)
282  {
283  case L2:
284  return std::sqrt(error_vals[0]);
285  case H1:
286  return std::sqrt(error_vals[0] + error_vals[1]);
287  case H2:
288  return std::sqrt(error_vals[0] + error_vals[1] + error_vals[2]);
289  case HCURL:
290  {
291  libmesh_error_msg_if(FEInterface::field_type(fe_type) == TYPE_SCALAR,
292  "Cannot compute HCurl error norm of scalar-valued variables!");
293 
294  return std::sqrt(error_vals[0] + error_vals[5]);
295  }
296  case HDIV:
297  {
298  libmesh_error_msg_if(FEInterface::field_type(fe_type) == TYPE_SCALAR,
299  "Cannot compute HDiv error norm of scalar-valued variables!");
300 
301  return std::sqrt(error_vals[0] + error_vals[6]);
302  }
303  case H1_SEMINORM:
304  return std::sqrt(error_vals[1]);
305  case H2_SEMINORM:
306  return std::sqrt(error_vals[2]);
307  case HCURL_SEMINORM:
308  {
309  libmesh_error_msg_if(FEInterface::field_type(fe_type) == TYPE_SCALAR,
310  "Cannot compute HCurl error seminorm of scalar-valued variables!");
311 
312  return std::sqrt(error_vals[5]);
313  }
314  case HDIV_SEMINORM:
315  {
316  libmesh_error_msg_if(FEInterface::field_type(fe_type) == TYPE_SCALAR,
317  "Cannot compute HDiv error seminorm of scalar-valued variables!");
318 
319  return std::sqrt(error_vals[6]);
320  }
321  case L1:
322  return error_vals[3];
323  case L_INF:
324  return error_vals[4];
325 
326  default:
327  libmesh_error_msg("Currently only Sobolev norms/seminorms are supported!");
328  }
329 }
const EquationSystems & _equation_systems
Constant reference to the EquationSystems object used for the simulation.
bool has_system(std::string_view name) const
static FEFieldType field_type(const FEType &fe_type)
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...
ADRealEigenVector< T, D, asd > sqrt(const ADRealEigenVector< T, D, asd > &)
Definition: type_vector.h:53
const T_sys & get_system(std::string_view name) const
libmesh_assert(ctx)
auto norm(const T &a) -> decltype(std::abs(a))
Definition: tensor_tools.h:74

◆ extra_quadrature_order()

void libMesh::ExactSolution::extra_quadrature_order ( const int  extraorder)
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().

186  { _extra_order = extraorder; }
int _extra_order
Extra order to use for quadrature rule.

◆ h1_error()

Real libMesh::ExactSolution::h1_error ( std::string_view  sys_name,
std::string_view  unknown_name 
)
Returns
The H1 error for the system sys_name for the unknown unknown_name.
Note
No error computations are actually performed, you must call compute_error() for that.

Definition at line 397 of file exact_solution.C.

References _check_inputs(), and std::sqrt().

Referenced by main().

399 {
400  // If the user has supplied no exact derivative function, we
401  // just integrate the H1 norm of the solution; i.e. its
402  // difference from an "exact solution" of zero.
403 
404  // Check the inputs for validity, and get a reference
405  // to the proper location to store the error
406  std::vector<Real> & error_vals = this->_check_inputs(sys_name,
407  unknown_name);
408 
409  // Return the square root of the sum of the computed errors.
410  return std::sqrt(error_vals[0] + error_vals[1]);
411 }
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...
ADRealEigenVector< T, D, asd > sqrt(const ADRealEigenVector< T, D, asd > &)
Definition: type_vector.h:53

◆ h2_error()

Real libMesh::ExactSolution::h2_error ( std::string_view  sys_name,
std::string_view  unknown_name 
)
Returns
The H2 error for the system sys_name for the unknown unknown_name.
Note
No error computations are actually performed, you must call compute_error() for that.

Definition at line 429 of file exact_solution.C.

References _check_inputs(), and std::sqrt().

Referenced by main().

431 {
432  // If the user has supplied no exact derivative functions, we
433  // just integrate the H2 norm of the solution; i.e. its
434  // difference from an "exact solution" of zero.
435 
436  // Check the inputs for validity, and get a reference
437  // to the proper location to store the error
438  std::vector<Real> & error_vals = this->_check_inputs(sys_name,
439  unknown_name);
440 
441  // Return the square root of the sum of the computed errors.
442  return std::sqrt(error_vals[0] + error_vals[1] + error_vals[2]);
443 }
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...
ADRealEigenVector< T, D, asd > sqrt(const ADRealEigenVector< T, D, asd > &)
Definition: type_vector.h:53

◆ hcurl_error()

Real libMesh::ExactSolution::hcurl_error ( std::string_view  sys_name,
std::string_view  unknown_name 
)
Returns
The H(curl) error for the system sys_name for the unknown unknown_name.
Note
No error computations are actually performed, you must call compute_error() for that.
This is only valid for vector-valued elements. An error is thrown if requested for scalar-valued elements.

Definition at line 414 of file exact_solution.C.

References error_norm(), and libMesh::HCURL.

Referenced by main().

416 {
417  return this->error_norm(sys_name,unknown_name,HCURL);
418 }
Real error_norm(std::string_view sys_name, std::string_view unknown_name, const FEMNormType &norm)

◆ hdiv_error()

Real libMesh::ExactSolution::hdiv_error ( std::string_view  sys_name,
std::string_view  unknown_name 
)
Returns
The H(div) error for the system sys_name for the unknown unknown_name.
Note
No error computations are actually performed, you must call compute_error() for that.
This is only valid for vector-valued elements. An error is thrown if requested for scalar-valued elements.

Definition at line 421 of file exact_solution.C.

References error_norm(), and libMesh::HDIV.

Referenced by main().

423 {
424  return this->error_norm(sys_name,unknown_name,HDIV);
425 }
Real error_norm(std::string_view sys_name, std::string_view unknown_name, const FEMNormType &norm)

◆ l1_error()

Real libMesh::ExactSolution::l1_error ( std::string_view  sys_name,
std::string_view  unknown_name 
)
Returns
The integrated L1 error for the system sys_name for the unknown unknown_name.
Note
No error computations are actually performed, you must call compute_error() for that.

Definition at line 357 of file exact_solution.C.

References _check_inputs().

359 {
360 
361  // Check the inputs for validity, and get a reference
362  // to the proper location to store the error
363  std::vector<Real> & error_vals = this->_check_inputs(sys_name,
364  unknown_name);
365 
366  // Return the square root of the first component of the
367  // computed error.
368  return error_vals[3];
369 }
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...

◆ l2_error()

Real libMesh::ExactSolution::l2_error ( std::string_view  sys_name,
std::string_view  unknown_name 
)
Returns
The integrated L2 error for the system sys_name for the unknown unknown_name.
Note
No error computations are actually performed, you must call 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().

339 {
340 
341  // Check the inputs for validity, and get a reference
342  // to the proper location to store the error
343  std::vector<Real> & error_vals = this->_check_inputs(sys_name,
344  unknown_name);
345 
346  // Return the square root of the first component of the
347  // computed error.
348  return std::sqrt(error_vals[0]);
349 }
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...
ADRealEigenVector< T, D, asd > sqrt(const ADRealEigenVector< T, D, asd > &)
Definition: type_vector.h:53

◆ l_inf_error()

Real libMesh::ExactSolution::l_inf_error ( std::string_view  sys_name,
std::string_view  unknown_name 
)
Returns
The L_INF error for the system sys_name for the unknown unknown_name.
Note
No error computations are actually performed, you must call compute_error() for that.
The result (as for the other norms as well) is not exact, but an approximation based on the chosen quadrature rule: to compute it, we take the max of the absolute value of the error over all the quadrature points.

Definition at line 377 of file exact_solution.C.

References _check_inputs().

379 {
380 
381  // Check the inputs for validity, and get a reference
382  // to the proper location to store the error
383  std::vector<Real> & error_vals = this->_check_inputs(sys_name,
384  unknown_name);
385 
386  // Return the square root of the first component of the
387  // computed error.
388  return error_vals[4];
389 }
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...

◆ operator=() [1/2]

ExactSolution& libMesh::ExactSolution::operator= ( const ExactSolution )
delete

◆ operator=() [2/2]

ExactSolution& libMesh::ExactSolution::operator= ( ExactSolution &&  )
delete

◆ set_excluded_subdomains()

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.

81 {
82  _excluded_subdomains = excluded;
83 }
std::set< subdomain_id_type > _excluded_subdomains
Elements in a subdomain from this set are skipped during the error computation.

Member Data Documentation

◆ _equation_systems

const EquationSystems& libMesh::ExactSolution::_equation_systems
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().

◆ _equation_systems_fine

const EquationSystems* libMesh::ExactSolution::_equation_systems_fine
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().

◆ _errors

std::map<std::string, SystemErrorMap, std::less<> > libMesh::ExactSolution::_errors
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().

◆ _exact_derivs

std::vector<std::unique_ptr<FunctionBase<Gradient> > > libMesh::ExactSolution::_exact_derivs
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().

◆ _exact_hessians

std::vector<std::unique_ptr<FunctionBase<Tensor> > > libMesh::ExactSolution::_exact_hessians
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().

◆ _exact_values

std::vector<std::unique_ptr<FunctionBase<Number> > > libMesh::ExactSolution::_exact_values
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().

◆ _excluded_subdomains

std::set<subdomain_id_type> libMesh::ExactSolution::_excluded_subdomains
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().

◆ _extra_order

int libMesh::ExactSolution::_extra_order
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().


The documentation for this class was generated from the following files: