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 AuxKerenel 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 or VectorAuxKernel and overriding the computeValue method, which returns a scalar (Real) or vector (RealVectorValue) for the two types respectively. A third 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, for example the following input file snippet creates an auxiliary variable suitable for use with an VectorAuxKernel.

    family = LAGRANGE_VEC
    order = FIRST

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 an 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 interpolation automatically and set the values for the degrees of freedom. 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 monomial 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.

  if (isNodal())
    return _func.value(_t, *_current_node);
    return _func.value(_t, _q_point[_qp]);

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.

Execute Flags

AuxKernel objects inherit from the SetupInterface (execute_on) 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.

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:


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
  static InputParameters validParams();

  DarcyVelocity(const InputParameters & parameters);

   * 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;

#include "DarcyVelocity.h"

#include "metaphysicl/raw_type.h"

registerMooseObject("DarcyThermoMechApp", DarcyVelocity);

  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

    // Set reference to the permeability MaterialProperty.
    // Only AuxKernels operating on Elemental Auxiliary Variables can do this

    // Set reference to the viscosity MaterialProperty.
    // Only AuxKernels operating on Elemental Auxiliary Variables can do this

  // 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];

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 (DarcyAdvection.C) and requires the pressure variable be provided as a variable:

  params.addRequiredCoupledVar("pressure", "The variable representing the pressure.");

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.


    type = FunctionAux
    variable = pressure
    function = 't*x*x*y'
    execute_on = timestep_end

Available Objects

Available Subsystems

Available Actions