AuxKernels System
The AuxKernel system mimics the Kernels System but compute values that can be defined explicitly with a known function. There are two main use cases for the AuxKernel system: computing a quantity that varies with space and time for postprocessing purposes or for decoupling systems of equations. Examples for both of these use cases shall be discussed further in the following sections.
Creating a custom AuxKernel object is done by creating a new C++ object that inherits from AuxKernel
, VectorAuxKernel
or ArrayAuxKernel
and overriding the computeValue
method, which returns a scalar (Real
), vector (RealVectorValue
) or a Eigen vector (RealEigenVector
) for the three types respectively. A forth type (AuxScalarKernel
) also exists, but the syntax for these objects is different and detailed in the AuxScalarKernels System.
AuxKernel objects, like Kernel objects, must operate on a variable. Thus, there is a required parameter ("variable") that indicates the variable that the AuxKernel object is computing. These variables are defined in the AuxVariables block of the input file. AuxKernel objects derived from AuxKernel
, VectorAuxKernel
or ArrayAuxKernel
operate on standard scalar, vector or array field variables respectively. For example the following input file snippet creates an auxiliary variable suitable for use with an VectorAuxKernel
.
[AuxVariables]
[vec]
family = LAGRANGE_VEC
order = FIRST
[]
[]
(moose/test/tests/auxkernels/vector_function_aux/vector_function_aux.i)Nodal vs Elemental AuxKernel Objects
There are two flavors of AuxKernel objects: nodal and elemental. The distinction is based on the type of variable that is being operated on by the object. If the variable family is LAGRANGE
or LAGRANGE_VEC
then the AuxKernel will behave as nodal. If the variable family is MONOMIAL
then the AuxKernel will behave as elemental.
The difference is based on how the computeValue
method of the object is called when the kernel is executed. In the nodal case the computeValue
method will be executed on each node within the finite element mesh and the value returned from the method will directly assign the value of the shape function at that node.
In the elemental case the computeValue
method will be executed on each quadrature point of an element of the finite element mesh. The values computed at the quadrature points are used to perform the correct finite element projection automatically and set the values for the degrees of freedom. This is achieved by assembling and solving a local finite element projection problem for each and every element in the domain (or blocks) of interest. Typically, in the elemental case the order of the monomial finite element is set to constant so there is a single DOF per element, but higher monomials are also supported.
As is evident by the functionality detailed, the distinction between the two arises from the nature of the finite element shape functions. For Lagrange shape functions the DOF values correspond with the nodes, while for elemental shape functions the DOF values are not associated with nodes.
The same AuxKernel object can be designed work both as elemental or nodal, for example the computeValue
method for the FunctionAux object properly handles using the correct spatial location based on if the object is nodal or elemental with the isNodal
method.
Block vs Boundary Restricted AuxKernel Objects
While auxiliary variables are always defined on mesh subdomains, MOOSE allows auxiliary kernels to be either block (mesh subdomain) or boundary restricted. When an auxiliary kernel is boundary restricted, it evaluates an auxiliary variable only on the designated boundaries. Because of this, the auxiliary variable will only have meaningful values on the boundaries even though it is defined on mesh subdomains. When an auxiliary kernel is block restricted, the variable that it evaluates must be defined on a subdomain covering the blocks where the auxiliary kernel is defined. When an auxiliary kernel is boundary restricted, the variable must be defined on a subdomain that all the sides on the boundaries are connected with. An elemental auxiliary variable defined on an element that has multiple boundary sides cannot be properly evaluated within a boundary restricted auxiliary kernel because elemental auxiliary variables can only store one value per element. Users can split the boundaries and define multiple elemental auxiliary variables for each split to avoid the situation of element connecting with multiple boundary sides.
Real
FunctionAux::computeValue()
{
if (isNodal())
return _func.value(_t, *_current_node);
else
return _func.value(_t, _q_point[_qp]);
}
(moose/framework/src/auxkernels/FunctionAux.C)Nodal AuxKernel objects abuse the notion of quadrature points, the _qp
member variable is set to zero, but still must be used to access coupled variable values and material properties. This is done to allow the syntax to be consistent regardless of the AuxKernel flavor: nodal or elemental.
Mortar Nodal Auxiliary Kernel Objects
In order to compute properties in the mortar sense, it is necessary to loop over the mortar segment mesh to spatially integrate variables. MortarNodalAuxKernel
s offer this functionality where these "weighted" variables, which intervene in the computation of contact constraints and their residuals, can be coupled to generate the desired output value. Therefore, if postprocessing of mortar quantities is required, nodal mortar auxiliary kernels can be employed. Objects inheriting from MortarNodalAuxKernel
allow for said operations on the mortar lower-dimensional domains featuring similar functionality to other nodal auxiliary kernels, including the possibility of computing quantities in an incremental
manner.
Execute Flags
AuxKernel objects inherit from the SetupInterface so they include the "execute_on" variable. By default this parameter is set to EXEC_LINEAR
and EXEC_TIMESTEP_END
. The EXEC_LINEAR
flag is set because it is possible to couple values compute by an AuxKernel object to other objects such as Kernel or Material objects that are used in the residual calculation. In order to ensure that the values from the auxiliary variable are correct during the iterative solve they are computed for each iteration.
However, if the auxiliary variable be computed is not being coupled to objects computing the residual evaluating the AuxKernel on each linear iteration is not necessary and can slow down the execution of a simulation. In this case, the EXEC_LINEAR
flag should be removed. Likely the EXEC_INITIAL
flag should be added to perform the auxiliary variable calculation during the initial setup phase as well.
Populating lower-dimensional auxiliary variables
Lower-dimensional auxiliary variables may be populated using boundary restricted auxiliary kernels. The boundary restriction of the aux kernel should be coincident with (a subset of) the lower-dimensional blocks that the lower-dimensional variable lives on. Using a boundary restricted auxiliary kernel as opposed to a lower-d block-restricted auxiliary kernel allows pulling in coincident face evaluations of higher-dimensional variables and material properties as well as evaluations of coupled lower-dimensional variables.
Example A: Post processing with AuxKernel
The following example is extracted from step 4 of the Darcy Flow and Thermomechanics Tutorial. Consider Darcy's Law for flow in porous media neglecting changes in time and gravity:
(1) where is the permeability tensor, is the fluid viscosity, and is the pressure and the velocity () may be computed as:
(2)
The left-hand side of Eq. (1) would be solved with a nonlinear variable and an appropriate Kernel object. The AuxKernel system can be used computing the velocity following Eq. (2). In the tutorial the exact calculation is performed using the DarcyVelocity object, the header and source files for this object are listed below.
#pragma once
#include "AuxKernel.h"
/**
* Auxiliary kernel responsible for computing the Darcy velocity given
* several fluid properties and the pressure gradient.
*/
class DarcyVelocity : public VectorAuxKernel
{
public:
static InputParameters validParams();
DarcyVelocity(const InputParameters & parameters);
protected:
/**
* AuxKernels MUST override computeValue. computeValue() is called on
* every quadrature point. For Nodal Auxiliary variables those quadrature
* points coincide with the nodes.
*/
virtual RealVectorValue computeValue() override;
/// The gradient of a coupled variable
const VariableGradient & _pressure_gradient;
/// Holds the permeability and viscosity from the material system
const ADMaterialProperty<Real> & _permeability;
const ADMaterialProperty<Real> & _viscosity;
};
(moose/tutorials/darcy_thermo_mech/step04_velocity_aux/include/auxkernels/DarcyVelocity.h)
#include "DarcyVelocity.h"
#include "metaphysicl/raw_type.h"
registerMooseObject("DarcyThermoMechApp", DarcyVelocity);
InputParameters
DarcyVelocity::validParams()
{
InputParameters params = VectorAuxKernel::validParams();
// Add a "coupling paramater" to get a variable from the input file.
params.addRequiredCoupledVar("pressure", "The pressure field.");
return params;
}
DarcyVelocity::DarcyVelocity(const InputParameters & parameters)
: VectorAuxKernel(parameters),
// Get the gradient of the variable
_pressure_gradient(coupledGradient("pressure")),
// Set reference to the permeability MaterialProperty.
// Only AuxKernels operating on Elemental Auxiliary Variables can do this
_permeability(getADMaterialProperty<Real>("permeability")),
// Set reference to the viscosity MaterialProperty.
// Only AuxKernels operating on Elemental Auxiliary Variables can do this
_viscosity(getADMaterialProperty<Real>("viscosity"))
{
}
RealVectorValue
DarcyVelocity::computeValue()
{
// Access the gradient of the pressure at this quadrature point, then pull out the "component" of
// it requested (x, y or z). Note, that getting a particular component of a gradient is done using
// the parenthesis operator.
return -MetaPhysicL::raw_value(_permeability[_qp] / _viscosity[_qp]) * _pressure_gradient[_qp];
}
(moose/tutorials/darcy_thermo_mech/step04_velocity_aux/src/auxkernels/DarcyVelocity.C)Example B: Decoupling Equations
Auxiliary variables may be used interchangeably with nonlinear variables with respect to coupling allowing complicated systems of equations to be decoupled for solving individually. This is very useful for testing and validation.
Consider the heat equation with an advective term that is coupled to the pressure computed in Eq. (1) as in step 6 of the Darcy Flow and Thermomechanics Tutorial:
(3) where is temperature, is the heat capacity, is the thermal conductivity, and is the porosity. The advective term () is computed in a kernel object ((moose/tutorials/darcy_thermo_mech/step06_coupled_darcy_heat_conduction/src/kernels/DarcyAdvection.C)) and requires the pressure variable be provided as a variable:
params.addRequiredCoupledVar("pressure", "The variable representing the pressure.");
(moose/tutorials/darcy_thermo_mech/step06_coupled_darcy_heat_conduction/src/kernels/DarcyAdvection.C)For testing purposes is it not desirable to include the solve for the pressure variable when examining the correctness of the heat equation solve, so an auxiliary variable that is assigned an arbitrary function of space and time is used instead. The following input file snippet demonstrates the decoupling of the pressure variable by computing it using an AuxVariable the FunctionAux object.
[AuxVariables]
[pressure]
[]
[]
[AuxKernels]
[pressure]
type = FunctionAux
variable = pressure
function = '4000 - 3000 * x - 3000 * t*x*x*y'
execute_on = timestep_end
[]
[]
(moose/tutorials/darcy_thermo_mech/step06_coupled_darcy_heat_conduction/problems/step6c_decoupled.i)Available Objects
- Moose App
- ADDivergenceAuxComputes the divergence of a vector of functors.
- ADFunctorElementalAuxEvaluates a functor (variable, function or functor material property) on the current element, quadrature point, or node.
- ADFunctorElementalGradientAuxEvaluates the gradient of a functor (variable, function or functor material property) on the current element or quadrature point.
- ADFunctorMaterialRealAuxOutputs element volume-averaged material properties
- ADFunctorMaterialRealVectorValueAuxCapture a component of a vector material property in an auxiliary variable.
- ADFunctorVectorElementalAuxEvaluates a vector functor (material property usually) on the current element.For finite volume, this evaluates the vector functor at the centroid.
- ADMaterialRankFourTensorAuxAccess a component of a RankFourTensor for automatic material property output
- ADMaterialRankTwoTensorAuxAccess a component of a RankTwoTensor for automatic material property output
- ADMaterialRateRealAuxOutputs element material properties rate of change
- ADMaterialRealAuxOutputs element volume-averaged material properties
- ADMaterialRealTensorValueAuxObject for extracting a component of a rank two tensor material property to populate an auxiliary variable.
- ADMaterialRealVectorValueAuxCapture a component of a vector material property in an auxiliary variable.
- ADMaterialStdVectorAuxExtracts a component of a material type std::vector<Real> to an aux variable. If the std::vector is not of sufficient size then zero is returned
- ADMaterialSymmetricRankFourTensorAuxAccess a component of a RankTwoTensor for automatic material property output
- ADMaterialSymmetricRankTwoTensorAuxCapture a component of a vector material property in an auxiliary variable.
- ADProjectedStatefulMaterialRankFourTensorAuxPicks a component of an indexable material property to get projected on an elemental Auxvariable. For use by ProjectedStatefulMaterialStorageAction.
- ADProjectedStatefulMaterialRankTwoTensorAuxPicks a component of an indexable material property to get projected on an elemental Auxvariable. For use by ProjectedStatefulMaterialStorageAction.
- ADProjectedStatefulMaterialRealAuxPicks a component of an indexable material property to get projected on an elemental Auxvariable. For use by ProjectedStatefulMaterialStorageAction.
- ADProjectedStatefulMaterialRealVectorValueAuxPicks a component of an indexable material property to get projected on an elemental Auxvariable. For use by ProjectedStatefulMaterialStorageAction.
- ADVectorMaterialRealVectorValueAuxConverts a vector-quantity material property into a vector auxiliary variable
- AdvectiveFluxAuxCompute components of flux vector for advection problems .
- ArrayParsedAuxSets field array variable values to the evaluation of a parsed expression.
- ArrayVarReductionAuxTakes an array variable and performs a reduction operation on it (max, min, sum, average) and stores as a standard variable.
- ArrayVariableComponentCopy a component of an array variable.
- BuildArrayVariableAuxCombines multiple standard variables into an array variable.
- ConstantAuxCreates a constant field in the domain.
- ContainsPointAuxComputes a binary field where the field is 1 in the elements that contain the point and 0 everywhere else
- CopyValueAuxReturns the specified variable as an auxiliary variable with a simple copy of the variable values.
- DebugResidualAuxPopulate an auxiliary variable with the residual contribution of a variable.
- DiffusionFluxAuxCompute components of flux vector for diffusion problems .
- DivergenceAuxComputes the divergence of a vector of functors.
- ElemExtraIDAuxPuts element extra IDs into an aux variable.
- ElementH1ErrorFunctionAuxComputes the H1 or W^{1,p} error between an exact function and a coupled variable.
- ElementIntegerAuxCreates a field showing the element integer.
- ElementL2ErrorFunctionAuxA class for computing the element-wise L^2 (Euclidean) error between a function and a coupled variable.
- ElementLengthAuxCompute the element size using Elem::hmin() or Elem::hmax() from libMesh.
- ElementLpNormAuxCompute an elemental field variable (single value per element) equal to the Lp-norm of a coupled Variable.
- ElementQualityAuxGenerates a field containing the quality metric for each element. Useful for visualizing mesh quality.
- ElementUOAuxAux Kernel to display generic spatial (elemental) information from a UserObject that satisfies the underlying ElementUOProvider interface.
- ExtraElementIDAuxPuts element extra IDs into an aux variable.
- ForcingFunctionAuxAuxiliary Kernel that adds a forcing function to the value of an AuxVariable from the previous time step.
- FunctionArrayAuxAuxiliary Kernel that creates and updates an array field variable by sampling functions through space and time.
- FunctionAuxAuxiliary Kernel that creates and updates a field variable by sampling a function through space and time.
- FunctorAuxEvaluates a functor (variable, function or functor material property) on the current element, quadrature point, or node.
- FunctorCoordinatesFunctionAuxAuxiliary Kernel that creates and updates a field variable by sampling a function with functors (variables, functions, others) as the coordinates.
- FunctorElementalAuxEvaluates a functor (variable, function or functor material property) on the current element, quadrature point, or node.
- FunctorElementalGradientAuxEvaluates the gradient of a functor (variable, function or functor material property) on the current element or quadrature point.
- FunctorMaterialRealAuxOutputs element volume-averaged material properties
- FunctorMaterialRealVectorValueAuxCapture a component of a vector material property in an auxiliary variable.
- FunctorVectorElementalAuxEvaluates a vector functor (material property usually) on the current element.For finite volume, this evaluates the vector functor at the centroid.
- GapValueAuxReturn the nearest value of a variable on a boundary from across a gap.
- GhostingAuxColors the elements ghosted to the chosen PID.
- GhostingFromUOAuxColors the elements ghosted to the chosen PID.
- HardwareIDAuxCreates a field showing the assignment of partitions to physical nodes in the cluster.
- InterfaceValueUserObjectAuxGet stored value from the specified InterfaceQpUserObjectBase.
- MaterialRankFourTensorAuxAccess a component of a RankFourTensor for automatic material property output
- MaterialRankTwoTensorAuxAccess a component of a RankTwoTensor for automatic material property output
- MaterialRateRealAuxOutputs element material properties rate of change
- MaterialRealAuxOutputs element volume-averaged material properties
- MaterialRealDenseMatrixAuxPopulate an auxiliary variable with an entry from a dense matrix material property.
- MaterialRealTensorValueAuxObject for extracting a component of a rank two tensor material property to populate an auxiliary variable.
- MaterialRealVectorValueAuxCapture a component of a vector material property in an auxiliary variable.
- MaterialStdVectorAuxExtracts a component of a material type std::vector<Real> to an aux variable. If the std::vector is not of sufficient size then zero is returned
- MaterialStdVectorRealGradientAuxExtracts a component of a material's std::vector<RealGradient> to an aux variable. If the std::vector is not of sufficient size then zero is returned
- MaterialSymmetricRankFourTensorAuxAccess a component of a RankTwoTensor for automatic material property output
- MaterialSymmetricRankTwoTensorAuxCapture a component of a vector material property in an auxiliary variable.
- MeshDivisionAuxReturns the value of the mesh division index for each element / node
- NearestNodeDistanceAuxStores the distance between a block and boundary or between two boundaries.
- NearestNodeValueAuxRetrieves a field value from the closest node on the paired boundary and stores it on this boundary or block.
- NodalPatchRecoveryAuxThis Auxkernel solves a least squares problem at each node to fit a value from quantities defined on quadrature points.
- NormalizationAuxNormalizes a variable based on a Postprocessor value.
- ParsedAuxSets a field variable value to the evaluation of a parsed expression.
- ParsedVectorAuxSets a field vector variable value to the evaluation of a parsed expression.
- PenetrationAuxAuxiliary Kernel for computing several geometry related quantities between two contacting bodies.
- ProcessorIDAuxCreates a field showing the processors and partitioning.
- ProjectedMaterialPropertyNodalPatchRecoveryAuxThis Auxkernel solves a least squares problem at each node to fit a value from quantities defined on quadrature points.
- ProjectedStatefulMaterialRankFourTensorAuxPicks a component of an indexable material property to get projected on an elemental Auxvariable. For use by ProjectedStatefulMaterialStorageAction.
- ProjectedStatefulMaterialRankTwoTensorAuxPicks a component of an indexable material property to get projected on an elemental Auxvariable. For use by ProjectedStatefulMaterialStorageAction.
- ProjectedStatefulMaterialRealAuxPicks a component of an indexable material property to get projected on an elemental Auxvariable. For use by ProjectedStatefulMaterialStorageAction.
- ProjectedStatefulMaterialRealVectorValueAuxPicks a component of an indexable material property to get projected on an elemental Auxvariable. For use by ProjectedStatefulMaterialStorageAction.
- ProjectionAuxReturns the specified variable as an auxiliary variable with a projection of the source variable. If they are the same type, this amounts to a simple copy.
- QuotientAuxDivides two coupled variables.
- SecondTimeDerivativeAuxReturns the second order time derivative of the specified variable as an auxiliary variable.
- SelfAuxReturns the specified variable as an auxiliary variable with a projection of the source variable. If they are the same type, this amounts to a simple copy.
- SolutionAuxCreates fields by using information from a SolutionUserObject.
- SpatialUserObjectAuxPopulates an auxiliary variable with a spatial value returned from a UserObject spatialValue method.
- TagMatrixAuxCouple the diagonal of a tag matrix, and return its nodal value
- TagVectorArrayVariableAuxCouple a tagged vector, and return its evaluations at degree of freedom indices corresponding to the coupled array variable.
- TagVectorArrayVariableValueAuxCouple a tagged vector, and return its array value.
- TagVectorAuxCouple a tag vector, and return its nodal value
- TimeDerivativeAuxReturns the time derivative of the specified variable/functor as an auxiliary variable.
- VariableGradientComponentCreates a field consisting of one component of the gradient of a coupled variable.
- VariableTimeIntegrationAuxIntegrates a field variable in time.
- VectorFunctionAuxAuxiliary Kernel that creates and updates a vector field variable by sampling a Function object, via the vectorValue method, through space and time.
- VectorMagnitudeAuxCreates a field representing the magnitude of three coupled variables using an Euclidean norm.
- VectorMaterialRealVectorValueAuxConverts a vector-quantity material property into a vector auxiliary variable
- VectorPostprocessorVisualizationAuxRead values from a VectorPostprocessor that is producing vectors that are 'number of processors' * in length. Puts the value for each processor into an elemental auxiliary field.
- VectorVariableComponentAuxCreates a field consisting of one component of a coupled vector variable.
- VectorVariableMagnitudeAuxCreates a field consisting of the magnitude of a coupled vector variable.
- VolumeAuxAuxiliary Kernel that samples volumes.
- WeightedGapAuxReturns the specified variable as an auxiliary variable with the same value.
- Solid Mechanics App
- ADKineticEnergyAuxCompute the kinetic energy of continuum-based finite elements
- ADRankFourAuxAccess a component of a RankFourTensor
- ADRankTwoAuxAccess a component of a RankTwoTensor
- ADRankTwoScalarAuxCompute a scalar property of a RankTwoTensor
- AccumulateAuxAccumulates one or more variables and this auxiliary variable into this auxiliary variable
- CylindricalRankTwoAuxTakes RankTwoTensor material and outputs component in cylindrical coordinates
- DomainIntegralQFunctionComputes the q-function for a segment along the crack front, used in the calculation of the J-integral
- DomainIntegralTopologicalQFunctionDetermines if a node is within the ring of the crack front defintion; this object is normally created by the DomainIntegralAction.
- ElasticEnergyAuxCompute the local elastic energy
- GlobalDisplacementAuxAuxKernel to visualize the displacements generated by the global strain tensor
- KineticEnergyAuxCompute the kinetic energy of continuum-based finite elements
- NewmarkAccelAuxComputes the current acceleration using the Newmark method.
- NewmarkVelAuxCalculates the current velocity using Newmark method.
- RadialDisplacementCylinderAuxCompute the radial component of the displacement vector for cylindrical models.
- RadialDisplacementSphereAuxCompute the radial component of the displacement vector for spherical models.
- RankFourAuxAccess a component of a RankFourTensor
- RankTwoAuxAccess a component of a RankTwoTensor
- RankTwoScalarAuxCompute a scalar property of a RankTwoTensor
- RotationAngleCompute the field of angular rotations of points around an axis defined by an origin point and a direction vector
- TestNewmarkTIAssigns the velocity/acceleration calculated by time integrator to the velocity/acceleration auxvariable.
- Phase Field App
- BndsCalcAuxCalculate location of grain boundaries in a polycrystalline sample
- CrossTermGradientFreeEnergyFree energy contribution from the cross terms in ACMultiInterface
- DiscreteNucleationAuxProject the DiscreteNucleationMap state onto an AuxVariable
- EBSDReaderAvgDataAuxOutputs the requested EBSD reader average data, for a given phase if specified, for the grain at the local node/element.
- EBSDReaderPointDataAuxOutputs the requested EBSD reader point data.
- EulerAngleProvider2RGBAuxOutput RGB representation of crystal orientation from user object to an AuxVariable. The entire domain must have the same crystal structure.
- EulerAngleVariables2RGBAuxOutputs one color or a scalar for the RGB-encoding of the local Euler angles for the grain orientation
- FeatureFloodCountAuxFeature detection by connectivity analysis
- GrainAdvectionAuxCalculates the advection velocity of grain due to rigid body translation and rotation
- GrainBoundaryVelocityCompute the velocity of grain boundaries.
- KKSGlobalFreeEnergyTotal free energy in KKS system, including chemical, barrier and gradient terms
- KKSMultiFreeEnergyTotal free energy in multi-phase KKS system, including chemical, barrier and gradient terms
- LinearizedInterfaceAuxCalculates the order parameter from the linearized interface function
- OutputEulerAnglesOutput Euler angles from user object to an AuxVariable.
- PFCEnergyDensityComputes the crystal free energy density
- PFCRFFEnergyDensityComputes the crystal free energy density for the RFF form of the phase field crystal model
- SolutionAuxMisorientationBoundaryCalculate location of grain boundaries by using information from a SolutionUserObject.
- TotalFreeEnergyTotal free energy (both the bulk and gradient parts), where the bulk free energy has been defined in a material
- Heat Transfer App
- JouleHeatingHeatGeneratedAuxCompute heat generated from Joule heating .
Available Subsystems
Available Actions
- Moose App
- AddKernelActionAdd a Kernel object to the simulation.