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 
39 namespace libMesh
40 {
41 
42 
43 // Forward Declarations
44 class Point;
45 class EquationSystems;
46 class Parameters;
47 class Mesh;
48 template <typename Output> class FunctionBase;
49 
50 // Is there any way to simplify this?
51 // All we need are Tensor and Gradient. - RHS
52 template <typename T> class TensorValue;
53 template <typename T> class VectorValue;
58 
73 {
74 
75 public:
81  explicit
82  ExactSolution (const EquationSystems & es);
83 
90  ExactSolution(const ExactSolution &) = delete;
91  ExactSolution & operator= (const ExactSolution &) = delete;
92  ExactSolution & operator= (ExactSolution &&) = delete;
93 
100 
106  void attach_reference_solution (const EquationSystems * es_fine);
107 
112  void attach_exact_values (const std::vector<FunctionBase<Number> *> & f);
113 
118  void attach_exact_value (unsigned int sys_num,
120 
125  typedef Number (*ValueFunctionPointer)(const Point & p,
126  const Parameters & Parameters,
127  const std::string & sys_name,
128  const std::string & unknown_name);
130 
135  void attach_exact_derivs (const std::vector<FunctionBase<Gradient> *> & g);
136 
141  void attach_exact_deriv (unsigned int sys_num,
143 
148  typedef Gradient (*GradientFunctionPointer)(const Point & p,
149  const Parameters & parameters,
150  const std::string & sys_name,
151  const std::string & unknown_name);
153 
158  void attach_exact_hessians (std::vector<FunctionBase<Tensor> *> h);
159 
164  void attach_exact_hessian (unsigned int sys_num,
166 
171  typedef Tensor (*HessianFunctionPointer)(const Point & p,
172  const Parameters & parameters,
173  const std::string & sys_name,
174  const std::string & unknown_name);
176 
181  void extra_quadrature_order (const int extraorder)
182  { _extra_order = extraorder; }
183 
191  void compute_error(const std::string & sys_name,
192  const std::string & unknown_name);
193 
201  Real l2_error(const std::string & sys_name,
202  const std::string & unknown_name);
203 
211  Real l1_error(const std::string & sys_name,
212  const std::string & unknown_name);
213 
226  Real l_inf_error(const std::string & sys_name,
227  const std::string & unknown_name);
228 
236  Real h1_error(const std::string & sys_name,
237  const std::string & unknown_name);
238 
249  Real hcurl_error(const std::string & sys_name,
250  const std::string & unknown_name);
251 
262  Real hdiv_error(const std::string & sys_name,
263  const std::string & unknown_name);
264 
272  Real h2_error(const std::string & sys_name,
273  const std::string & unknown_name);
274 
285  Real error_norm(const std::string & sys_name,
286  const std::string & unknown_name,
287  const FEMNormType & norm);
288 private:
289 
296  template<typename OutputShape>
297  void _compute_error(const std::string & sys_name,
298  const std::string & unknown_name,
299  std::vector<Real> & error_vals);
300 
307  std::vector<Real> & _check_inputs(const std::string & sys_name,
308  const std::string & unknown_name);
309 
314  std::vector<std::unique_ptr<FunctionBase<Number>>> _exact_values;
315 
320  std::vector<std::unique_ptr<FunctionBase<Gradient>>> _exact_derivs;
321 
326  std::vector<std::unique_ptr<FunctionBase<Tensor>>> _exact_hessians;
327 
336  typedef std::map<std::string, std::vector<Real>> SystemErrorMap;
337 
344  std::map<std::string, SystemErrorMap> _errors;
345 
351 
357 
362 };
363 
364 
365 
366 } // namespace libMesh
367 
368 
369 #endif // LIBMESH_EXACT_SOLUTION_H
This class handles the computation of the L2 and/or H1 error for the Systems in the EquationSystems o...
This is the EquationSystems class.
This class provides the ability to map between arbitrary, user-defined strings and several data types...
Definition: parameters.h:63
const EquationSystems & _equation_systems
Constant reference to the EquationSystems object used for the simulation.
ExactSolution(const EquationSystems &es)
Constructor.
void attach_exact_values(const std::vector< FunctionBase< Number > *> &f)
Clone and attach arbitrary functors which compute the exact values of the EquationSystems&#39; solutions ...
int _extra_order
Extra order to use for quadrature rule.
Real h2_error(const std::string &sys_name, const std::string &unknown_name)
Real hdiv_error(const std::string &sys_name, const std::string &unknown_name)
FEMNormType
defines an enum for norms defined on vectors of finite element coefficients
void extra_quadrature_order(const int extraorder)
Increases or decreases the order of the quadrature rule used for numerical integration.
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
The libMesh namespace provides an interface to certain functionality in the library.
void attach_exact_derivs(const std::vector< FunctionBase< Gradient > *> &g)
Clone and attach arbitrary functors which compute the exact gradients of the EquationSystems&#39; solutio...
Real error_norm(const std::string &sys_name, const std::string &unknown_name, const FEMNormType &norm)
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(...
const EquationSystems * _equation_systems_fine
Constant pointer to the EquationSystems object containing the fine grid solution. ...
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...
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...
TensorValue< Number > NumberTensorValue
void attach_exact_hessians(std::vector< FunctionBase< Tensor > *> h)
Clone and attach arbitrary functors which compute the exact second derivatives of the EquationSystems...
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...
ExactSolution & operator=(const ExactSolution &)=delete
NumberVectorValue Gradient
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_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 l1_error(const std::string &sys_name, const std::string &unknown_name)
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...
std::vector< std::unique_ptr< FunctionBase< Tensor > > > _exact_hessians
User-provided functors which compute the exact hessians of the solution for each system.
Real hcurl_error(const std::string &sys_name, const std::string &unknown_name)
MetaPhysicL::DualNumber< T, D > norm(const MetaPhysicL::DualNumber< T, D > &in)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::map< std::string, SystemErrorMap > _errors
A map of SystemErrorMaps, which contains entries for each system in the EquationSystems object...
NumberTensorValue Tensor
Real h1_error(const std::string &sys_name, const std::string &unknown_name)
Real l_inf_error(const std::string &sys_name, const std::string &unknown_name)
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...
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...
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...
Real l2_error(const std::string &sys_name, const std::string &unknown_name)
VectorValue< Number > NumberVectorValue
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...
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
std::vector< std::unique_ptr< FunctionBase< Number > > > _exact_values
User-provided functors which compute the exact value of the solution for each system.
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...
This class defines a tensor in LIBMESH_DIM dimensional Real or Complex space.