Skip to content

Commit

Permalink
Add ADMatReaction (idaholab#13484)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschwen committed May 28, 2019
1 parent 3ca651d commit 9da2573
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
3 changes: 1 addition & 2 deletions modules/heat_conduction/include/kernels/ADHeatConduction.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "ADDiffusion.h"

template <ComputeStage compute_stage>
template <ComputeStage>
class ADHeatConduction;

declareADValidParams(ADHeatConduction);
Expand All @@ -29,4 +29,3 @@ class ADHeatConduction : public ADDiffusion<compute_stage>

usingKernelGradMembers;
};

45 changes: 45 additions & 0 deletions modules/phase_field/include/kernels/ADMatReaction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "ADKernel.h"

// Forward Declaration
template <ComputeStage>
class ADMatReaction;

declareADValidParams(ADMatReaction);

/**
* This kernel adds to the residual a contribution of \f$ -L*v \f$ where \f$ L \f$ is a material
* property and \f$ v \f$ is a variable (nonlinear or coupled).
*/
template <ComputeStage compute_stage>
class ADMatReaction : public ADKernel<compute_stage>
{
public:
ADMatReaction(const InputParameters & parameters);
virtual void initialSetup();

protected:
virtual ADReal computeQpResidual();

/**
* Kernel variable (can be nonlinear or coupled variable)
* (For constrained Allen-Cahn problems, v = lambda
* where lambda is the Lagrange multiplier)
*/
const ADVariableValue & _v;

/// Reaction rate
const ADMaterialProperty(Real) & _mob;

usingKernelMembers;
};
38 changes: 38 additions & 0 deletions modules/phase_field/src/kernels/ADMatReaction.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "ADMatReaction.h"

registerADMooseObject("PhaseFieldApp", ADMatReaction);

defineADValidParams(
ADMatReaction,
ADKernel,
params.addCoupledVar("v",
"Set this to make v a coupled variable, otherwise it will use the "
"kernel's nonlinear variable for v");
params.addClassDescription("Kernel to add -L*v, where L=reaction rate, v=variable");
params.addParam<MaterialPropertyName>("mob_name",
"L",
"The reaction rate used with the kernel"););

template <ComputeStage compute_stage>
ADMatReaction<compute_stage>::ADMatReaction(const InputParameters & parameters)
: ADKernel<compute_stage>(parameters),
_v(isCoupled("v") ? adCoupledValue("v") : _u),
_mob(adGetADMaterialProperty<Real>("mob_name"))
{
}

template <ComputeStage compute_stage>
ADReal
ADMatReaction<compute_stage>::computeQpResidual()
{
return -_mob[_qp] * _test[_i][_qp] * _v[_qp];
}

0 comments on commit 9da2573

Please sign in to comment.