libMesh
exact_solution.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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 #include "libmesh/enum_norm_type.h"
25 
26 // C++ includes
27 #include <map>
28 #include <vector>
29 
30 namespace libMesh
31 {
32 
33 
34 // Forward Declarations
35 class Point;
36 class EquationSystems;
37 class Parameters;
38 class Mesh;
39 template <typename Output> class FunctionBase;
40 
41 // Is there any way to simplify this?
42 // All we need are Tensor and Gradient. - RHS
43 template <typename T> class TensorValue;
44 template <typename T> class VectorValue;
45 typedef TensorValue<Number> NumberTensorValue;
46 typedef NumberTensorValue Tensor;
47 typedef VectorValue<Number> NumberVectorValue;
48 typedef NumberVectorValue Gradient;
49 
64 {
65 
66 public:
72  explicit
73  ExactSolution (const EquationSystems & es);
74 
79 
80 
86  void attach_reference_solution (const EquationSystems * es_fine);
87 
92  void attach_exact_values (const std::vector<FunctionBase<Number> *> & f);
93 
98  void attach_exact_value (unsigned int sys_num,
100 
105  void attach_exact_value (Number fptr(const Point & p,
106  const Parameters & Parameters,
107  const std::string & sys_name,
108  const std::string & unknown_name));
109 
114  void attach_exact_derivs (const std::vector<FunctionBase<Gradient> *> & g);
115 
120  void attach_exact_deriv (unsigned int sys_num,
122 
127  void attach_exact_deriv (Gradient gptr(const Point & p,
128  const Parameters & parameters,
129  const std::string & sys_name,
130  const std::string & unknown_name));
131 
136  void attach_exact_hessians (std::vector<FunctionBase<Tensor> *> h);
137 
142  void attach_exact_hessian (unsigned int sys_num,
144 
149  void attach_exact_hessian (Tensor hptr(const Point & p,
150  const Parameters & parameters,
151  const std::string & sys_name,
152  const std::string & unknown_name));
153 
158  void extra_quadrature_order (const int extraorder)
159  { _extra_order = extraorder; }
160 
168  void compute_error(const std::string & sys_name,
169  const std::string & unknown_name);
170 
178  Real l2_error(const std::string & sys_name,
179  const std::string & unknown_name);
180 
188  Real l1_error(const std::string & sys_name,
189  const std::string & unknown_name);
190 
203  Real l_inf_error(const std::string & sys_name,
204  const std::string & unknown_name);
205 
213  Real h1_error(const std::string & sys_name,
214  const std::string & unknown_name);
215 
226  Real hcurl_error(const std::string & sys_name,
227  const std::string & unknown_name);
228 
239  Real hdiv_error(const std::string & sys_name,
240  const std::string & unknown_name);
241 
249  Real h2_error(const std::string & sys_name,
250  const std::string & unknown_name);
251 
262  Real error_norm(const std::string & sys_name,
263  const std::string & unknown_name,
264  const FEMNormType & norm);
265 private:
266 
273  template<typename OutputShape>
274  void _compute_error(const std::string & sys_name,
275  const std::string & unknown_name,
276  std::vector<Real> & error_vals);
277 
284  std::vector<Real> & _check_inputs(const std::string & sys_name,
285  const std::string & unknown_name);
286 
291  std::vector<FunctionBase<Number> *> _exact_values;
292 
297  std::vector<FunctionBase<Gradient> *> _exact_derivs;
298 
303  std::vector<FunctionBase<Tensor> *> _exact_hessians;
304 
313  typedef std::map<std::string, std::vector<Real>> SystemErrorMap;
314 
321  std::map<std::string, SystemErrorMap> _errors;
322 
328 
334 
339 };
340 
341 
342 
343 } // namespace libMesh
344 
345 
346 #endif // LIBMESH_EXACT_SOLUTION_H
This class handles the computation of the L2 and/or H1 error for the Systems in the EquationSystems o...
std::vector< FunctionBase< Tensor > * > _exact_hessians
User-provided functors which compute the exact hessians of the solution for each system.
This is the EquationSystems class.
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...
This class provides the ability to map between arbitrary, user-defined strings and several data types...
Definition: parameters.h:63
std::vector< FunctionBase< Number > * > _exact_values
User-provided functors which compute the exact value of the solution for each system.
const EquationSystems & _equation_systems
Constant reference to the EquationSystems object used for the simulation.
ExactSolution(const EquationSystems &es)
Constructor.
int _extra_order
Extra order to use for quadrature rule.
Real h2_error(const std::string &sys_name, const std::string &unknown_name)
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 ...
Real hdiv_error(const std::string &sys_name, const std::string &unknown_name)
void extra_quadrature_order(const int extraorder)
Increases or decreases the order of the quadrature rule used for numerical integration.
void attach_exact_hessians(std::vector< FunctionBase< Tensor > * > h)
Clone and attach arbitrary functors which compute the exact second derivatives of the EquationSystems...
The libMesh namespace provides an interface to certain functionality in the library.
std::vector< FunctionBase< Gradient > * > _exact_derivs
User-provided functors which compute the exact derivative of the solution for each system...
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. ...
~ExactSolution()
Destructor.
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:78
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
NumberVectorValue Gradient
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...
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 hcurl_error(const std::string &sys_name, const std::string &unknown_name)
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)
Gradient gptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
Definition: projection.C:93
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
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
FEMNormType
defines an enum for norms defined on vectors of finite element coefficients
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...