https://mooseframework.inl.gov
ADTestDerivativeFunction.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
11 
12 registerMooseObject("PhaseFieldTestApp", ADTestDerivativeFunction);
13 
16 {
18  params.addClassDescription(
19  "Material that implements the a function of one variable and its first derivative.");
20  MooseEnum functionEnum("F1 F2 F3");
21  params.addRequiredParam<MooseEnum>("function",
22  functionEnum,
23  "F1 = 2 op[0]^2 (1 - op[0])^2 - 0.2 op[0]; "
24  "F2 = 0.1 op[0]^2 + op[1]^2; "
25  "F3 = op[0] * op[1]");
26  params.addParam<MaterialPropertyName>("f_name", "F", "function property name");
27  params.addRequiredCoupledVar("op", "Order parameter variables");
28  return params;
29 }
30 
32  : Material(parameters),
33  _function(getParam<MooseEnum>("function").template getEnum<FunctionEnum>()),
34  _op(adCoupledValues("op")),
35  _f_name(getParam<MaterialPropertyName>("f_name")),
36  _prop_F(declareADProperty<Real>(_f_name)),
37  _prop_dFdop(coupledComponents("op"))
38 {
39  for (std::size_t i = 0; i < _op.size(); ++i)
40  _prop_dFdop[i] =
41  &declareADProperty<Real>(derivativePropertyNameFirst(_f_name, this->coupledName("op", i)));
42 
43  if (_function == FunctionEnum::F1 && _op.size() != 1)
44  paramError("op", "Specify exactly one variable to an F1 type function.");
45  if (_function == FunctionEnum::F2 && _op.size() != 2)
46  paramError("op", "Specify exactly two variables to an F2 type function.");
47  if (_function == FunctionEnum::F3 && _op.size() != 2)
48  paramError("op", "Specify exactly two variables to an F3 type function.");
49 }
50 
51 void
53 {
54  const ADReal & a = (*_op[0])[_qp];
55 
56  switch (_function)
57  {
58  case FunctionEnum::F1:
59  _prop_F[_qp] = 2.0 * a * a * (1.0 - a) * (1.0 - a) - 0.2 * a;
60  (*_prop_dFdop[0])[_qp] = 4.0 * a * a * (a - 1.0) + 4.0 * a * (1.0 - a) * (1.0 - a) - 0.2;
61  break;
62 
63  case FunctionEnum::F2:
64  {
65  const ADReal & b = (*_op[1])[_qp];
66  _prop_F[_qp] = 0.1 * a * a + b * b;
67  (*_prop_dFdop[0])[_qp] = 0.2 * a;
68  (*_prop_dFdop[1])[_qp] = 2.0 * b;
69  break;
70  }
71 
72  case FunctionEnum::F3:
73  {
74  const ADReal & b = (*_op[1])[_qp];
75  _prop_F[_qp] = a * b;
76  (*_prop_dFdop[0])[_qp] = b;
77  (*_prop_dFdop[1])[_qp] = a;
78  break;
79  }
80 
81  default:
82  mooseError("Invalid function enum value");
83  }
84 }
registerMooseObject("PhaseFieldTestApp", ADTestDerivativeFunction)
VariableName coupledName(const std::string &var_name, unsigned int comp=0) const
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
std::vector< ADMaterialProperty< Real > * > _prop_dFdop
function value derivative
const MaterialPropertyName derivativePropertyNameFirst(const MaterialPropertyName &base, const SymbolName &c1) const
const MaterialPropertyName _f_name
property name
enum ADTestDerivativeFunction::FunctionEnum _function
void addRequiredParam(const std::string &name, const std::string &doc_string)
ADTestDerivativeFunction(const InputParameters &parameters)
unsigned int _qp
static InputParameters validParams()
const std::vector< const ADVariableValue * > _op
Coupled variable value for the order parameter.
void paramError(const std::string &param, Args... args) const
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
Material class that creates the math free energy and its derivatives for use with ADSplitCHParsed...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static InputParameters validParams()
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
ADMaterialProperty< Real > & _prop_F
function value