www.mooseframework.org
ElementH1ErrorFunctionAux.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 // MOOSE includes
12 #include "Function.h"
13 
14 #include "libmesh/quadrature.h"
15 
17 
18 template <>
21 {
23  params.addClassDescription(
24  "Computes the H1 or W^{1,p} error between an exact function and a coupled variable.");
25 
26  return params;
27 }
28 
30  : ElementL2ErrorFunctionAux(parameters), _grad_coupled_var(coupledGradient("coupled_variable"))
31 {
32 }
33 
34 void
36 {
38 
39  if (isNodal())
40  mooseError("ElementH1ErrorFunctionAux only makes sense as an Elemental AuxVariable.");
41 
42  Real summed_value = 0;
43  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
44  {
45  Real val = computeValue(); // already raised to the p, see below.
46  summed_value += _JxW[_qp] * _coord[_qp] * val;
47  }
48 
49  _var.setNodalValue(std::pow(summed_value, 1. / _p));
50 }
51 
52 Real
54 {
55  RealGradient graddiff = _func.gradient(_t, _q_point[_qp]) - _grad_coupled_var[_qp];
56  Real funcdiff = _func.value(_t, _q_point[_qp]) - _coupled_var[_qp];
57 
58  // Raise the absolute function value difference to the pth power
59  Real val = std::pow(std::abs(funcdiff), _p);
60 
61  // Add all of the absolute gradient component differences to the pth power
62  for (unsigned int i = 0; i < LIBMESH_DIM; ++i)
63  val += std::pow(std::abs(graddiff(i)), _p);
64 
65  return val;
66 }
MooseVariableFE< ComputeValueType > & _var
This is a regular kernel so we cast to a regular MooseVariable.
Definition: AuxKernel.h:167
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:38
MetaPhysicL::DualNumber< T, D > abs(const MetaPhysicL::DualNumber< T, D > &in)
virtual RealGradient gradient(Real t, const Point &p)
Function objects can optionally provide a gradient at a point.
Definition: Function.C:44
const MooseArray< Real > & _coord
Definition: AuxKernel.h:200
A class for computing the element-wise H1 error (actually W^{1,p} error, if you set the value of p to...
A class for computing the element-wise L^2 error (actually L^p error, if you set the value of p to so...
registerMooseObject("MooseApp", ElementH1ErrorFunctionAux)
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 >()
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
ElementH1ErrorFunctionAux(const InputParameters &parameters)
Class constructor.
const MooseArray< Real > & _JxW
Transformed Jacobian weights.
Definition: AuxKernel.h:199
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.
Real pow(Real x, int e)
Definition: MathUtils.C:211
virtual void precalculateValue()
This callback is used for AuxKernelTempls that need to perform a per-element calculation.
Definition: AuxKernel.h:154
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:84
const QBase *const & _qrule
Quadrature rule being used.
Definition: AuxKernel.h:197
void setNodalValue(OutputType value, unsigned int idx=0)
unsigned int _qp
Quadrature point index.
Definition: AuxKernel.h:219
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...
const MooseArray< Point > & _q_point
Dimension of the problem being solved.
Definition: AuxKernel.h:195
InputParameters validParams< ElementH1ErrorFunctionAux >()