Kokkos NodalKernels System
Before reading this documentation, consider reading the following materials first for a better understanding of this documentation:
NodalKernels System to understand the MOOSE nodal kernel system,
Getting Started with Kokkos-MOOSE to understand the programming practices for Kokkos-MOOSE,
Kokkos Kernels System to understand the common design pattern of objects in Kokkos-MOOSE,
Kokkos BCs System to understand the design pattern of nodal boundary conditions in Kokkos-MOOSE.
You can create your own nodal kernels by inheriting Moose::Kokkos::NodalKernel
and following the same pattern with kernels and boundary conditions. The interfaces of nodal kernels are identical to the nodal boundary conditions described in Kokkos BCs System, so they will not be explained here in detail. See the following source codes of KokkosCoupledForceNodalKernel
for an example of a nodal kernel:
Listing 1: The KokkosCoupledForceNodalKernel
header file.
#pragma once
#include "KokkosNodalKernel.h"
class KokkosCoupledForceNodalKernel final
: public Moose::Kokkos::NodalKernel<KokkosCoupledForceNodalKernel>
{
public:
static InputParameters validParams();
KokkosCoupledForceNodalKernel(const InputParameters & parameters);
KOKKOS_FUNCTION Real computeQpResidual(const ContiguousNodeID node) const;
KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int jvar,
const ContiguousNodeID node) const;
private:
/// The number of the coupled variable
const unsigned int _v_var;
/// The value of the coupled variable
const Moose::Kokkos::VariableNodalValue _v;
/// A multiplicative factor for computing the coupled force
const Real _coef;
};
KOKKOS_FUNCTION inline Real
KokkosCoupledForceNodalKernel::computeQpResidual(const ContiguousNodeID node) const
{
return -_coef * _v(node);
}
KOKKOS_FUNCTION inline Real
KokkosCoupledForceNodalKernel::computeQpOffDiagJacobian(const unsigned int jvar,
const ContiguousNodeID /* node */) const
{
if (jvar == _v_var)
return -_coef;
return 0;
}
(framework/include/kokkos/nodalkernels/KokkosCoupledForceNodalKernel.h)Listing 2: The KokkosCoupledForceNodalKernel
source file.
#include "KokkosCoupledForceNodalKernel.h"
registerMooseObject("MooseApp", KokkosCoupledForceNodalKernel);
InputParameters
KokkosCoupledForceNodalKernel::validParams()
{
InputParameters params = NodalKernel::validParams();
params.addClassDescription("Adds a force proportional to the value of the coupled variable");
params.addRequiredCoupledVar("v", "The coupled variable which provides the force");
params.addParam<Real>(
"coef", 1.0, "Coefficent ($\\sigma$) multiplier for the coupled force term.");
return params;
}
KokkosCoupledForceNodalKernel::KokkosCoupledForceNodalKernel(const InputParameters & parameters)
: NodalKernel(parameters),
_v_var(coupled("v")),
_v(kokkosCoupledNodalValue("v")),
_coef(getParam<Real>("coef"))
{
if (_var.number() == _v_var)
mooseError(
"Coupled variable 'v' needs to be different from 'variable' with CoupledForceNodalKernel, "
"consider using Reaction or somethig similar");
}
(framework/src/kokkos/nodalkernels/KokkosCoupledForceNodalKernel.K)Available Objects
- Moose App
- KokkosConstantRateComputes residual or the rate in a simple ODE of du/dt = rate.
- KokkosCoupledForceNodalKernelAdds a force proportional to the value of the coupled variable
- KokkosLowerBoundNodalKernelUsed to prevent a coupled variable from going below a lower bound
- KokkosReactionNodalKernelImplements a simple consuming reaction term at nodes
- KokkosTimeDerivativeNodalKernelForms the contribution to the residual and jacobian of the time derivative term from an ODE being solved at all nodes.
- KokkosUpperBoundNodalKernelUsed to prevent a coupled variable from going above a upper bound