www.mooseframework.org
ElementLpNormAux.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
11 #include "ElementLpNormAux.h"
12 
13 #include "libmesh/quadrature.h"
14 
16 
19 {
21  params.addClassDescription("Compute an elemental field variable (single value per element) equal "
22  "to the Lp-norm of a coupled Variable.");
23  params.addRangeCheckedParam<Real>("p", 2.0, "p>=1", "The exponent used in the norm.");
24  params.addRequiredCoupledVar("coupled_variable", "The variable to compute the norm of.");
25  return params;
26 }
27 
29  : AuxKernel(parameters), _p(getParam<Real>("p")), _coupled_var(coupledValue("coupled_variable"))
30 {
31  if (mooseVariableBase()->feType() != FEType(CONSTANT, MONOMIAL))
32  paramError("variable", "Must be of type CONSTANT MONOMIAL");
33 }
34 
35 void
37 {
39 
40  // Sum up the squared-error values by calling computeValue(), then
41  // return the sqrt of the result.
42  Real summed_value = 0;
43  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
44  {
45  Real val = computeValue();
46  summed_value += _JxW[_qp] * _coord[_qp] * std::pow(std::abs(val), _p);
47  }
48 
49  _var.setDofValue(std::pow(summed_value, 1. / _p), 0);
50 }
51 
52 Real
54 {
55  return _coupled_var[_qp];
56 }
Compute an elemental field variable (single value per element) equal to the Lp-norm of a coupled Vari...
const MooseArray< Real > & _coord
Definition: AuxKernel.h:201
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 InputParameters validParams()
virtual void setDofValue(const OutputData &value, unsigned int index)=0
Degree of freedom value setters.
const MooseArray< Real > & _JxW
Transformed Jacobian weights.
Definition: AuxKernel.h:200
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
CONSTANT
virtual void precalculateValue()
This callback is used for AuxKernelTempls that need to perform a per-element calculation.
Definition: AuxKernel.h:137
virtual void compute() override
Override the base class functionality to compute the element integral withou scaling by element volum...
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
MONOMIAL
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
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
registerMooseObject("MooseApp", ElementLpNormAux)
const QBase *const & _qrule
Quadrature rule being used.
Definition: AuxKernel.h:198
MooseVariableBase * mooseVariableBase() const
Get the variable that this object is using.
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...
static InputParameters validParams()
Definition: AuxKernel.C:27
Base class for creating new auxiliary kernels and auxiliary boundary conditions.
Definition: AuxKernel.h:36
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
MooseUnits pow(const MooseUnits &, int)
Definition: Units.C:537
ElementLpNormAux(const InputParameters &parameters)
Class constructor.
virtual Real computeValue() override
Called by compute() to get the value of the integrand at the current qp.