www.mooseframework.org
ElementLpNormAux.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 // MOOSE includes
16 #include "ElementLpNormAux.h"
17 
18 #include "libmesh/quadrature.h"
19 
20 template <>
23 {
25  params.addClassDescription("Compute an elemental field variable (single value per element) equal "
26  "to the Lp-norm of a coupled Variable.");
27  params.addRangeCheckedParam<Real>("p", 2.0, "p>=1", "The exponent used in the norm.");
28  params.addRequiredCoupledVar("coupled_variable", "The variable to compute the norm of.");
29  return params;
30 }
31 
33  : AuxKernel(parameters), _p(getParam<Real>("p")), _coupled_var(coupledValue("coupled_variable"))
34 {
35 }
36 
37 void
39 {
41 
42  if (isNodal())
43  mooseError("ElementLpNormAux only makes sense as an Elemental AuxVariable.");
44 
45  // Sum up the squared-error values by calling computeValue(), then
46  // return the sqrt of the result.
47  Real summed_value = 0;
48  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
49  {
50  Real val = computeValue();
51  summed_value += _JxW[_qp] * _coord[_qp] * std::pow(std::abs(val), _p);
52  }
53 
54  _var.setNodalValue(std::pow(summed_value, 1. / _p));
55 }
56 
57 Real
59 {
60  return _coupled_var[_qp];
61 }
const MooseArray< Real > & _coord
Definition: AuxKernel.h:164
virtual void precalculateValue()
This callback is used for AuxKernels that need to perform a per-element calculation.
Definition: AuxKernel.h:135
QBase *& _qrule
Quadrature rule being used.
Definition: AuxKernel.h:161
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 setNodalValue(Number value, unsigned int idx=0)
Set the nodal value for this variable to keep everything up to date.
InputParameters validParams< AuxKernel >()
Definition: AuxKernel.C:30
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:89
unsigned int _qp
Quadrature point index.
Definition: AuxKernel.h:192
Base class for creating new auxiliary kernels and auxiliary boundary conditions.
Definition: AuxKernel.h:51
const MooseArray< Real > & _JxW
Transformed Jacobian weights.
Definition: AuxKernel.h:163
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
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...
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
InputParameters validParams< ElementLpNormAux >()
MooseVariable & _var
Variable this kernel is acting on.
Definition: AuxKernel.h:148
ElementLpNormAux(const InputParameters &parameters)
Class constructor.
virtual Real computeValue() override
Called by compute() to get the value of the integrand at the current qp.