https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ElementLpNormAux.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
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 const auto & fe_type = mooseVariableBase()->feType();
32 if (fe_type.order != CONSTANT || fe_type.family != MONOMIAL)
33 paramError("variable", "Must be of type CONSTANT MONOMIAL");
34 if (fe_type.p_refinement && _subproblem.doingPRefinement())
35 paramError("variable",
36 "p_refinement can push the MONOMIAL order above CONSTANT, which is not supported");
37}
38
39void
41{
43
44 // Sum up the squared-error values by calling computeValue(), then
45 // return the sqrt of the result.
46 Real summed_value = 0;
47 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
48 {
49 Real val = computeValue();
50 summed_value += _JxW[_qp] * _coord[_qp] * std::pow(std::abs(val), _p);
51 }
52
53 _var.setDofValue(std::pow(summed_value, 1. / _p), 0);
54}
55
56Real
registerMooseObject("MooseApp", ElementLpNormAux)
SubProblem & _subproblem
Subproblem this kernel is part of.
virtual void precalculateValue()
This callback is used for AuxKernelTempls that need to perform a per-element calculation.
Definition AuxKernel.h:96
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
static InputParameters validParams()
Definition AuxKernel.C:27
Compute an elemental field variable (single value per element) equal to the Lp-norm of a coupled Vari...
static InputParameters validParams()
virtual void compute() override
Override the base class functionality to compute the element integral withou scaling by element volum...
ElementLpNormAux(const InputParameters &parameters)
Class constructor.
const VariableValue & _coupled_var
A reference to the variable to compute the norm of.
virtual Real computeValue() override
Called by compute() to get the value of the integrand at the current qp.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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 addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
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 ...
Definition MooseBase.h:457
const libMesh::FEType & feType() const
Get the type of finite element object.
virtual void setDofValue(const DofValue &value, unsigned int index)=0
Degree of freedom value setters.
MooseVariableBase * mooseVariableBase() const
Get the variable that this object is using.
bool doingPRefinement() const
MooseUnits pow(const MooseUnits &, int)
Definition Units.C:537