Browse files

Merge pull request #12543 from laagesen/maskedbodyforce_jacobians_9004

Add Jacobians for MaskedBodyForce
  • Loading branch information...
dschwen committed Dec 13, 2018
2 parents 2290c8d + 0cbab33 commit 67624fb20eed37a24e9bd91e9d5178f29f5263fa
@@ -22,7 +22,7 @@ validParams<BodyForce>()
params.addClassDescription("Demonstrates the multiple ways that scalar values can be introduced "
"into kernels, e.g. (controllable) constants, functions, and "
"postprocessors. Implements the weak form $(\\psi_i, -f)$.");
params.addParam<Real>("value", 1.0, "Coefficent to multiply by the body force term");
params.addParam<Real>("value", 1.0, "Coefficient to multiply by the body force term");
params.addParam<FunctionName>("function", "1", "A function that describes the body force");
"postprocessor", 1, "A postprocessor whose value is multiplied by the body force");
@@ -1,14 +1,17 @@
<!-- MOOSE Documentation Stub: Remove this when content is added. -->

# MaskedBodyForce

!alert construction title=Undocumented Class
The MaskedBodyForce has not been documented. The content contained on this page
includes the basic documentation associated with a MooseObject; however, what is contained is
ultimately determined by what is necessary to make the documentation clear for users.

!syntax description /Kernels/MaskedBodyForce

Implements a kernel for a source term/body force limited to a certain region by
a mask $m$ (material property). A function or a postprocessor can also be supplied
to multiply the source term by. Contributions added by this kernel have the form
-m C f P
where $m$ is the mask (supplied as a material property), $C$ is the constant source
term/body force, $f$ is a function (optional), and $P$ is the value of a postprocessor

!syntax parameters /Kernels/MaskedBodyForce

!syntax inputs /Kernels/MaskedBodyForce
@@ -11,6 +11,8 @@

#include "BodyForce.h"
#include "JvarMapInterface.h"
#include "DerivativeMaterialInterface.h"

// Forward Declarations
class MaskedBodyForce;
@@ -25,15 +27,30 @@ InputParameters validParams<MaskedBodyForce>();
* body force in certain regions of the mesh.

class MaskedBodyForce : public BodyForce
class MaskedBodyForce : public DerivativeMaterialInterface<JvarMapKernelInterface<BodyForce>>
MaskedBodyForce(const InputParameters & parameters);
virtual void initialSetup();

virtual Real computeQpResidual();
virtual Real computeQpJacobian();
virtual Real computeQpOffDiagJacobian(unsigned int jvar);

const MaterialProperty<Real> & _mask;

/// number of coupled variables
const unsigned int _nvar;

/// name of the nonlinear variable (needed to retrieve the derivative material properties)
VariableName _v_name;

/// derivative of the mask wrt the kernel's nonlinear variable
const MaterialProperty<Real> & _dmaskdv;

/// Reaction rate derivatives w.r.t. other coupled variables
std::vector<const MaterialProperty<Real> *> _dmaskdarg;

@@ -19,16 +19,47 @@ validParams<MaskedBodyForce>()
InputParameters params = validParams<BodyForce>();
params.addClassDescription("Kernel that defines a body force modified by a material mask");
params.addParam<MaterialPropertyName>("mask", "Material property defining the mask");
params.addCoupledVar("args", "Vector of nonlinear variable arguments this object depends on");
return params;

MaskedBodyForce::MaskedBodyForce(const InputParameters & parameters)
: BodyForce(parameters), _mask(getMaterialProperty<Real>("mask"))
: DerivativeMaterialInterface<JvarMapKernelInterface<BodyForce>>(parameters),
_dmaskdv(getMaterialPropertyDerivative<Real>("mask", _v_name)),
// Get derivatives of mask wrt coupled variables
for (unsigned int i = 0; i < _nvar; ++i)
MooseVariableFEBase * cvar = _coupled_moose_vars[i];
_dmaskdarg[i] = &getMaterialPropertyDerivative<Real>("mask", cvar->name());


return BodyForce::computeQpResidual() * _mask[_qp];

return _dmaskdv[_qp] * BodyForce::computeQpResidual() * _phi[_j][_qp];

MaskedBodyForce::computeQpOffDiagJacobian(unsigned int jvar)
const unsigned int cvar = mapJvarToCvar(jvar);
return (*_dmaskdarg[cvar])[_qp] * BodyForce::computeQpResidual() * _phi[_j][_qp];

0 comments on commit 67624fb

Please sign in to comment.