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 
20 {
22  params.addClassDescription(
23  "Computes the H1 or W^{1,p} error between an exact function and a coupled variable.");
24 
25  return params;
26 }
27 
29  : ElementL2ErrorFunctionAux(parameters), _grad_coupled_var(coupledGradient("coupled_variable"))
30 {
31 }
32 
33 void
35 {
37 
38  if (isNodal())
39  mooseError("ElementH1ErrorFunctionAux only makes sense as an Elemental AuxVariable.");
40 
41  Real summed_value = 0;
42  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
43  {
44  Real val = computeValue(); // already raised to the p, see below.
45  summed_value += _JxW[_qp] * _coord[_qp] * val;
46  }
47 
48  _var.setNodalValue(std::pow(summed_value, 1. / _p));
49 }
50 
51 Real
53 {
55  Real funcdiff = _func.value(_t, _q_point[_qp]) - _coupled_var[_qp];
56 
57  // Raise the absolute function value difference to the pth power
58  Real val = std::pow(std::abs(funcdiff), _p);
59 
60  // Add all of the absolute gradient component differences to the pth power
61  for (const auto i : make_range(Moose::dim))
62  val += std::pow(std::abs(graddiff(i)), _p);
63 
64  return val;
65 }
const MooseArray< Real > & _coord
Definition: AuxKernel.h:201
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...
virtual void setNodalValue(const OutputType &value, unsigned int idx=0)=0
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.
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:148
static InputParameters validParams()
ElementH1ErrorFunctionAux(const InputParameters &parameters)
Class constructor.
const MooseArray< Real > & _JxW
Transformed Jacobian weights.
Definition: AuxKernel.h:200
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
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.
virtual void precalculateValue()
This callback is used for AuxKernelTempls that need to perform a per-element calculation.
Definition: AuxKernel.h:137
virtual Real computeValue() override
Computes the error at the current qp.
static InputParameters validParams()
MooseVariableField< Real > & _var
This is a regular kernel so we cast to a regular MooseVariable.
Definition: AuxKernel.h:174
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const QBase *const & _qrule
Quadrature rule being used.
Definition: AuxKernel.h:198
IntRange< T > make_range(T beg, T end)
virtual RealGradient gradient(Real t, const Point &p) const
Function objects can optionally provide a gradient at a point.
Definition: Function.C:73
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
unsigned int _qp
Quadrature point index.
Definition: AuxKernel.h:230
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...
virtual Real value(Real t, const Point &p) const
Override this to evaluate the scalar function at point (t,x,y,z), by default this returns zero...
Definition: Function.C:41
const MooseArray< Point > & _q_point
Active quadrature points.
Definition: AuxKernel.h:196
MooseUnits pow(const MooseUnits &, int)
Definition: Units.C:537
bool isNodal() const
Nodal or elemental kernel?
Definition: AuxKernel.h:86
const Function & _func
Function representing the exact solution.