Skip to content

AD Migration Guide

Robert Carlsen edited this page Jan 22, 2019 · 1 revision

Automatic Differentiation Migration Guide

Top-level Declarations

  • class and validParams predeclarations:
// from
class Foo

template <>
InputParameters validParams<Foo>();

// to
template <ComputeStage>
class Foo;

declareADValidParams(Foo);
  • class declaration:
// from
class Foo : public Material/Kernel/BoundaryCondition/etc
{
  ...

// to
template <ComputeStage compute_stage>
class Foo : public ADMaterial/ADKernel/ADBoundaryCondition/etc<compute_stage>
{
  ...
  • validParams implementation:
// from
template <>
InputParameters
validParams<Foo>()
{
  auto params = validParams<Material/Kernel/BoundaryCondition/etc>();
  params.addRequiredCoupledVar("bar", "blah");
  params.addParam("baz", "blah");
  ...
  return params;
}

// to
defineADValidParams(
    Foo,
    ADMaterial/ADKernel/ADBoundary/etc,

    params.addRequiredCoupledVar("bar", "blah");
    params.addParam("baz", "blah");
    ...
    );
  • For AD intermediate base classes explicit instantiation is required if Foo inherits from an AD class and other classes inherit from Foo. At the bottom of your Foo.C put:
adBaseClass(Foo);

Materials

  • variables (e.g. member vars):
// from
MaterialProperty<Foo>
// to
ADMaterialProperty(Foo)
  • use material property:
// from
getMaterialProperty<Foo>(...);
// to
adGetADMaterialProperty<Foo>(...);
  • declare material property:
// from
declareProperty<Foo>(...);
// to
adDeclareADProperty<Foo>(...);

FE Variables and Coupling

  • coupled stuff:
// from
coupledValue(...)
coupledGradient(...)
// to
adCoupledValue(...)
adCoupledGradient(...)
  • Setting unused dimensions to zero
// something like this
for (unsigned i = _ndims; i < 3; ++i)
{
  _foo[i] = &adZero();
  _grad_foo[i] = &adGradZero();
}

Variables

  • predefined:
Real   -->   ADReal
RankTwoTensor   -->   ADRankTwoTensor
RankFourTensor   -->   ADRankFourTensor
???? more?