https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ElementH1ErrorFunctionAux.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
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{
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
33void
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
51Real
53{
54 RealGradient graddiff = _func.gradient(_t, _q_point[_qp]) - _grad_coupled_var[_qp];
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}
registerMooseObject("MooseApp", ElementH1ErrorFunctionAux)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
virtual void precalculateValue()
This callback is used for AuxKernelTempls that need to perform a per-element calculation.
Definition AuxKernel.h:96
bool isNodal() const
Nodal or elemental kernel?
Definition AuxKernel.h:43
const MooseArray< Point > & _q_point
Active quadrature points.
Definition AuxKernel.h:125
const MooseArray< Real > & _coord
Definition AuxKernel.h:130
const MooseArray< Real > & _JxW
Transformed Jacobian weights.
Definition AuxKernel.h:129
unsigned int _qp
Quadrature point index.
Definition AuxKernel.h:155
MooseVariableField< Real > & _var
This is a regular kernel so we cast to a regular MooseVariable, hides base _var.
Definition AuxKernel.h:113
const QBase *const & _qrule
Quadrature rule being used.
Definition AuxKernel.h:127
A class for computing the element-wise H1 error (actually W^{1,p} error, if you set the value of p to...
const VariableGradient & _grad_coupled_var
The gradient of the computed solution.
virtual Real computeValue() override
Computes the error at the current qp.
static InputParameters validParams()
ElementH1ErrorFunctionAux(const InputParameters &parameters)
Class constructor.
virtual void compute() override
Overrides ElementLpNormAux since we want to raise to a power in computeValue() instead.
A class for computing the element-wise L^2 error (actually L^p error, if you set the value of p to so...
const Function & _func
Function representing the exact solution.
static InputParameters validParams()
const VariableValue & _coupled_var
A reference to the variable to compute the norm of.
virtual RealGradient gradient(Real t, const Point &p) const
Function objects can optionally provide a gradient at a point.
Definition Function.C:62
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:30
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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 void setNodalValue(const OutputType &value, unsigned int idx=0)=0
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition Moose.h:165
MooseUnits pow(const MooseUnits &, int)
Definition Units.C:537