www.mooseframework.org
ElementH1ErrorFunctionAux.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 // MOOSE includes
17 #include "Function.h"
18 
19 #include "libmesh/quadrature.h"
20 
21 template <>
24 {
26  params.addClassDescription(
27  "Computes the H1 or W^{1,p} error between an exact function and a coupled variable.");
28 
29  return params;
30 }
31 
33  : ElementL2ErrorFunctionAux(parameters), _grad_coupled_var(coupledGradient("coupled_variable"))
34 {
35 }
36 
37 void
39 {
41 
42  if (isNodal())
43  mooseError("ElementH1ErrorFunctionAux only makes sense as an Elemental AuxVariable.");
44 
45  Real summed_value = 0;
46  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
47  {
48  Real val = computeValue(); // already raised to the p, see below.
49  summed_value += _JxW[_qp] * _coord[_qp] * val;
50  }
51 
52  _var.setNodalValue(std::pow(summed_value, 1. / _p));
53 }
54 
55 Real
57 {
59  Real funcdiff = _func.value(_t, _q_point[_qp]) - _coupled_var[_qp];
60 
61  // Raise the absolute function value difference to the pth power
62  Real val = std::pow(std::abs(funcdiff), _p);
63 
64  // Add all of the absolute gradient component differences to the pth power
65  for (unsigned int i = 0; i < LIBMESH_DIM; ++i)
66  val += std::pow(std::abs(graddiff(i)), _p);
67 
68  return val;
69 }
RealVectorValue RealGradient
Definition: Assembly.h:43
virtual Real value(Real t, const Point &p)
Override this to evaluate the scalar function at point (t,x,y,z), by default this returns zero...
Definition: Function.C:43
virtual RealGradient gradient(Real t, const Point &p)
Function objects can optionally provide a gradient at a point.
Definition: Function.C:49
const MooseArray< Real > & _coord
Definition: AuxKernel.h:164
A class for computing the element-wise L^2 error (actually L^p error, if you set the value of p to so...
virtual void precalculateValue()
This callback is used for AuxKernels that need to perform a per-element calculation.
Definition: AuxKernel.h:135
const MooseArray< Point > & _q_point
Dimension of the problem being solved.
Definition: AuxKernel.h:159
QBase *& _qrule
Quadrature rule being used.
Definition: AuxKernel.h:161
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const VariableValue & _coupled_var
A reference to the variable to compute the norm of.
InputParameters validParams< ElementL2ErrorFunctionAux >()
ElementH1ErrorFunctionAux(const InputParameters &parameters)
Class constructor.
virtual void compute() override
Overrides ElementLpNormAux since we want to raise to a power in computeValue() instead.
const VariableGradient & _grad_coupled_var
The gradient of the computed solution.
void setNodalValue(Number value, unsigned int idx=0)
Set the nodal value for this variable to keep everything up to date.
Function & _func
Function representing the exact solution.
virtual Real computeValue() override
Computes the error at the current qp.
bool isNodal()
Nodal or elemental kernel?
Definition: AuxKernel.h:89
unsigned int _qp
Quadrature point index.
Definition: AuxKernel.h:192
const MooseArray< Real > & _JxW
Transformed Jacobian weights.
Definition: AuxKernel.h:163
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
MooseVariable & _var
Variable this kernel is acting on.
Definition: AuxKernel.h:148
InputParameters validParams< ElementH1ErrorFunctionAux >()