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 
17 template <>
20 {
22  params.addClassDescription("Compute an elemental field variable (single value per element) equal "
23  "to the Lp-norm of a coupled Variable.");
24  params.addRangeCheckedParam<Real>("p", 2.0, "p>=1", "The exponent used in the norm.");
25  params.addRequiredCoupledVar("coupled_variable", "The variable to compute the norm of.");
26  return params;
27 }
28 
30  : AuxKernel(parameters), _p(getParam<Real>("p")), _coupled_var(coupledValue("coupled_variable"))
31 {
32 }
33 
34 void
36 {
38 
39  if (isNodal())
40  mooseError("ElementLpNormAux only makes sense as an Elemental AuxVariable.");
41 
42  // Sum up the squared-error values by calling computeValue(), then
43  // return the sqrt of the result.
44  Real summed_value = 0;
45  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
46  {
47  Real val = computeValue();
48  summed_value += _JxW[_qp] * _coord[_qp] * std::pow(std::abs(val), _p);
49  }
50 
51  _var.setNodalValue(std::pow(summed_value, 1. / _p));
52 }
53 
54 Real
56 {
57  return _coupled_var[_qp];
58 }
MooseVariableFE< ComputeValueType > & _var
This is a regular kernel so we cast to a regular MooseVariable.
Definition: AuxKernel.h:167
MetaPhysicL::DualNumber< T, D > abs(const MetaPhysicL::DualNumber< T, D > &in)
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:200
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.
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
const MooseArray< Real > & _JxW
Transformed Jacobian weights.
Definition: AuxKernel.h:199
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
InputParameters validParams< AuxKernel >()
Definition: AuxKernel.C:25
virtual void compute() override
Override the base class functionality to compute the element integral withou scaling by element volum...
bool isNodal()
Nodal or elemental kernel?
Definition: AuxKernel.h:84
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
registerMooseObject("MooseApp", ElementLpNormAux)
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...
Base class for creating new auxiliary kernels and auxiliary boundary conditions.
Definition: AuxKernel.h:33
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
InputParameters validParams< ElementLpNormAux >()
ElementLpNormAux(const InputParameters &parameters)
Class constructor.
virtual Real computeValue() override
Called by compute() to get the value of the integrand at the current qp.