libMesh
exact_solution.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 #ifndef LIBMESH_EXACT_SOLUTION_H
19 #define LIBMESH_EXACT_SOLUTION_H
20 
21 
22 // Local Includes
23 #include "libmesh/libmesh_common.h" // for Number
24 
25 #ifdef LIBMESH_FORWARD_DECLARE_ENUMS
26 namespace libMesh
27 {
28 enum FEMNormType : int;
29 }
30 #else
31 #include "libmesh/enum_norm_type.h"
32 #endif
33 
34 // C++ includes
35 #include <map>
36 #include <vector>
37 #include <memory>
38 #include <set>
39 
40 namespace libMesh
41 {
42 
43 
44 // Forward Declarations
45 class Point;
46 class EquationSystems;
47 class Parameters;
48 class Mesh;
49 template <typename Output> class FunctionBase;
50 
51 // Is there any way to simplify this?
52 // All we need are Tensor and Gradient. - RHS
53 template <typename T> class TensorValue;
54 template <typename T> class VectorValue;
59 
74 {
75 
76 public:
82  explicit
83  ExactSolution (const EquationSystems & es);
84 
91  ExactSolution(const ExactSolution &) = delete;
92  ExactSolution & operator= (const ExactSolution &) = delete;
93  ExactSolution & operator= (ExactSolution &&) = delete;
94 
100  ~ExactSolution();
101 
108  void set_excluded_subdomains(const std::set<subdomain_id_type> & excluded);
109 
115  void attach_reference_solution (const EquationSystems * es_fine);
116 
121  void attach_exact_values (const std::vector<FunctionBase<Number> *> & f);
122 
127  void attach_exact_value (unsigned int sys_num,
129 
134  typedef Number (*ValueFunctionPointer)(const Point & p,
135  const Parameters & Parameters,
136  const std::string & sys_name,
137  const std::string & unknown_name);
139 
144  void attach_exact_derivs (const std::vector<FunctionBase<Gradient> *> & g);
145 
150  void attach_exact_deriv (unsigned int sys_num,
152 
157  typedef Gradient (*GradientFunctionPointer)(const Point & p,
158  const Parameters & parameters,
159  const std::string & sys_name,
160  const std::string & unknown_name);
162 
167  void attach_exact_hessians (std::vector<FunctionBase<Tensor> *> h);
168 
173  void attach_exact_hessian (unsigned int sys_num,
175 
180  typedef Tensor (*HessianFunctionPointer)(const Point & p,
181  const Parameters & parameters,
182  const std::string & sys_name,
183  const std::string & unknown_name);
185 
190  void extra_quadrature_order (const int extraorder)
191  { _extra_order = extraorder; }
192 
200  void compute_error(const std::string & sys_name,
201  const std::string & unknown_name);
202 
210  Real l2_error(const std::string & sys_name,
211  const std::string & unknown_name);
212 
220  Real l1_error(const std::string & sys_name,
221  const std::string & unknown_name);
222 
235  Real l_inf_error(const std::string & sys_name,
236  const std::string & unknown_name);
237 
245  Real h1_error(const std::string & sys_name,
246  const std::string & unknown_name);
247 
258  Real hcurl_error(const std::string & sys_name,
259  const std::string & unknown_name);
260 
271  Real hdiv_error(const std::string & sys_name,
272  const std::string & unknown_name);
273 
281  Real h2_error(const std::string & sys_name,
282  const std::string & unknown_name);
283 
294  Real error_norm(const std::string & sys_name,
295  const std::string & unknown_name,
296  const FEMNormType & norm);
297 private:
298 
305  template<typename OutputShape>
306  void _compute_error(const std::string & sys_name,
307  const std::string & unknown_name,
308  std::vector<Real> & error_vals);
309 
316  std::vector<Real> & _check_inputs(const std::string & sys_name,
317  const std::string & unknown_name);
318 
323  std::vector<std::unique_ptr<FunctionBase<Number>>> _exact_values;
324 
329  std::vector<std::unique_ptr<FunctionBase<Gradient>>> _exact_derivs;
330 
335  std::vector<std::unique_ptr<FunctionBase<Tensor>>> _exact_hessians;
336 
345  typedef std::map<std::string, std::vector<Real>> SystemErrorMap;
346 
353  std::map<std::string, SystemErrorMap> _errors;
354 
360 
366 
371 
376  std::set<subdomain_id_type> _excluded_subdomains;
377 };
378 
379 
380 
381 } // namespace libMesh
382 
383 
384 #endif // LIBMESH_EXACT_SOLUTION_H
libMesh::ExactSolution::_extra_order
int _extra_order
Extra order to use for quadrature rule.
Definition: exact_solution.h:370
libMesh::ExactSolution
This class handles the computation of the L2 and/or H1 error for the Systems in the EquationSystems o...
Definition: exact_solution.h:73
libMesh::Number
Real Number
Definition: libmesh_common.h:195
libMesh::ExactSolution::ExactSolution
ExactSolution(const EquationSystems &es)
Constructor.
Definition: exact_solution.C:41
libMesh::FunctionBase< Number >
libMesh::ExactSolution::attach_exact_derivs
void attach_exact_derivs(const std::vector< FunctionBase< Gradient > * > &g)
Clone and attach arbitrary functors which compute the exact gradients of the EquationSystems' solutio...
Definition: exact_solution.C:153
libMesh::ExactSolution::_excluded_subdomains
std::set< subdomain_id_type > _excluded_subdomains
Elements in a subdomain from this set are skipped during the error computation.
Definition: exact_solution.h:376
libMesh::ExactSolution::set_excluded_subdomains
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...
Definition: exact_solution.C:76
libMesh::ExactSolution::l1_error
Real l1_error(const std::string &sys_name, const std::string &unknown_name)
Definition: exact_solution.C:353
libMesh::ExactSolution::GradientFunctionPointer
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.
Definition: exact_solution.h:157
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::ExactSolution::_exact_hessians
std::vector< std::unique_ptr< FunctionBase< Tensor > > > _exact_hessians
User-provided functors which compute the exact hessians of the solution for each system.
Definition: exact_solution.h:335
libMesh::ExactSolution::h1_error
Real h1_error(const std::string &sys_name, const std::string &unknown_name)
Definition: exact_solution.C:393
libMesh::ExactSolution::HessianFunctionPointer
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...
Definition: exact_solution.h:180
libMesh::ExactSolution::h2_error
Real h2_error(const std::string &sys_name, const std::string &unknown_name)
Definition: exact_solution.C:425
libMesh::ExactSolution::hcurl_error
Real hcurl_error(const std::string &sys_name, const std::string &unknown_name)
Definition: exact_solution.C:410
libMesh::VectorValue
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
Definition: exact_solution.h:54
libMesh::ExactSolution::_errors
std::map< std::string, SystemErrorMap > _errors
A map of SystemErrorMaps, which contains entries for each system in the EquationSystems object.
Definition: exact_solution.h:353
libMesh::FEMNormType
FEMNormType
Definition: enum_norm_type.h:34
libMesh::ExactSolution::attach_exact_value
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...
Definition: exact_solution.C:123
libMesh::ExactSolution::_exact_values
std::vector< std::unique_ptr< FunctionBase< Number > > > _exact_values
User-provided functors which compute the exact value of the solution for each system.
Definition: exact_solution.h:323
libMesh::ExactSolution::extra_quadrature_order
void extra_quadrature_order(const int extraorder)
Increases or decreases the order of the quadrature rule used for numerical integration.
Definition: exact_solution.h:190
libMesh::ExactSolution::attach_reference_solution
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...
Definition: exact_solution.C:81
libMesh::ExactSolution::attach_exact_hessian
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...
Definition: exact_solution.C:205
libMesh::ExactSolution::hdiv_error
Real hdiv_error(const std::string &sys_name, const std::string &unknown_name)
Definition: exact_solution.C:417
libMesh::TensorValue
This class defines a tensor in LIBMESH_DIM dimensional Real or Complex space.
Definition: exact_solution.h:53
libMesh::Point
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
libMesh::ExactSolution::error_norm
Real error_norm(const std::string &sys_name, const std::string &unknown_name, const FEMNormType &norm)
Definition: exact_solution.C:264
libMesh::NumberTensorValue
TensorValue< Number > NumberTensorValue
Definition: exact_solution.h:54
libMesh::ExactSolution::_exact_derivs
std::vector< std::unique_ptr< FunctionBase< Gradient > > > _exact_derivs
User-provided functors which compute the exact derivative of the solution for each system.
Definition: exact_solution.h:329
libMesh::ExactSolution::attach_exact_hessians
void attach_exact_hessians(std::vector< FunctionBase< Tensor > * > h)
Clone and attach arbitrary functors which compute the exact second derivatives of the EquationSystems...
Definition: exact_solution.C:194
libMesh::ExactSolution::~ExactSolution
~ExactSolution()
libMesh::ExactSolution::_equation_systems
const EquationSystems & _equation_systems
Constant reference to the EquationSystems object used for the simulation.
Definition: exact_solution.h:359
gptr
Gradient gptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:95
libMesh::ExactSolution::l2_error
Real l2_error(const std::string &sys_name, const std::string &unknown_name)
Definition: exact_solution.C:333
libMesh::ExactSolution::compute_error
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(...
Definition: exact_solution.C:227
libMesh::EquationSystems
This is the EquationSystems class.
Definition: equation_systems.h:74
libMesh::ExactSolution::attach_exact_values
void attach_exact_values(const std::vector< FunctionBase< Number > * > &f)
Clone and attach arbitrary functors which compute the exact values of the EquationSystems' solutions ...
Definition: exact_solution.C:112
libMesh::ExactSolution::operator=
ExactSolution & operator=(const ExactSolution &)=delete
libMesh::Gradient
NumberVectorValue Gradient
Definition: exact_solution.h:58
libMesh::ExactSolution::ValueFunctionPointer
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.
Definition: exact_solution.h:134
libMesh::NumberVectorValue
VectorValue< Number > NumberVectorValue
Definition: exact_solution.h:57
libMesh::ExactSolution::_compute_error
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...
Definition: exact_solution.C:448
std::norm
MetaPhysicL::DualNumber< T, D > norm(const MetaPhysicL::DualNumber< T, D > &in)
libMesh::ExactSolution::_check_inputs
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.
Definition: exact_solution.C:216
libMesh::ExactSolution::l_inf_error
Real l_inf_error(const std::string &sys_name, const std::string &unknown_name)
Definition: exact_solution.C:373
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::Tensor
NumberTensorValue Tensor
Definition: exact_solution.h:56
fptr
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::ExactSolution::SystemErrorMap
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...
Definition: exact_solution.h:345
libMesh::ExactSolution::attach_exact_deriv
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...
Definition: exact_solution.C:164
libMesh::ExactSolution::_equation_systems_fine
const EquationSystems * _equation_systems_fine
Constant pointer to the EquationSystems object containing the fine grid solution.
Definition: exact_solution.h:365
int
void ErrorVector unsigned int
Definition: adjoints_ex3.C:360
libMesh::Parameters
This class provides the ability to map between arbitrary, user-defined strings and several data types...
Definition: parameters.h:59