www.mooseframework.org
ADTestDerivativeFunction.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
13 
16  ADMaterial,
17  params.addClassDescription(
18  "Material that implements the a function of one variable and its first derivative.");
19  MooseEnum functionEnum("F1 F2 F3");
20  params.addRequiredParam<MooseEnum>("function",
21  functionEnum,
22  "F1 = 2 op[0]^2 (1 - op[0])^2 - 0.2 op[0]; "
23  "F2 = 0.1 op[0]^2 + op[1]^2; "
24  "F3 = op[0] * op[1]");
25  params.addParam<MaterialPropertyName>("f_name", "F", "function property name");
26  params.addRequiredCoupledVar("op", "Order parameter variables"););
27 
28 template <ComputeStage compute_stage>
30  const InputParameters & parameters)
31  : ADMaterial<compute_stage>(parameters),
32  _function(getParam<MooseEnum>("function").template getEnum<FunctionEnum>()),
33  _op(coupledComponents("op")),
34  _f_name(getParam<MaterialPropertyName>("f_name")),
35  _prop_F(declareADProperty<Real>(_f_name)),
36  _prop_dFdop(coupledComponents("op"))
37 {
38  for (std::size_t i = 0; i < _op.size(); ++i)
39  {
40  _op[i] = &adCoupledValue("op", i);
41  _prop_dFdop[i] = &declareADProperty<Real>(
42  derivativePropertyNameFirst(_f_name, this->getVar("op", i)->name()));
43  }
44 
45  if (_function == FunctionEnum::F1 && _op.size() != 1)
46  paramError("op", "Specify exactly one variable to an F1 type function.");
47  if (_function == FunctionEnum::F2 && _op.size() != 2)
48  paramError("op", "Specify exactly two variables to an F2 type function.");
49  if (_function == FunctionEnum::F3 && _op.size() != 2)
50  paramError("op", "Specify exactly two variables to an F3 type function.");
51 }
52 
53 template <ComputeStage compute_stage>
54 void
56 {
57  const ADReal & a = (*_op[0])[_qp];
58 
59  switch (_function)
60  {
61  case FunctionEnum::F1:
62  _prop_F[_qp] = 2.0 * a * a * (1.0 - a) * (1.0 - a) - 0.2 * a;
63  (*_prop_dFdop[0])[_qp] = 4.0 * a * a * (a - 1.0) + 4.0 * a * (1.0 - a) * (1.0 - a) - 0.2;
64  break;
65 
66  case FunctionEnum::F2:
67  {
68  const ADReal & b = (*_op[1])[_qp];
69  _prop_F[_qp] = 0.1 * a * a + b * b;
70  (*_prop_dFdop[0])[_qp] = 0.2 * a;
71  (*_prop_dFdop[1])[_qp] = 2.0 * b;
72  break;
73  }
74 
75  case FunctionEnum::F3:
76  {
77  const ADReal & b = (*_op[1])[_qp];
78  _prop_F[_qp] = a * b;
79  (*_prop_dFdop[0])[_qp] = b;
80  (*_prop_dFdop[1])[_qp] = a;
81  break;
82  }
83 
84  default:
85  mooseError("Invalid function enum value");
86  }
87 }
ADTestDerivativeFunction::FunctionEnum::F1
ADTestDerivativeFunction::FunctionEnum
FunctionEnum
Definition: ADTestDerivativeFunction.h:35
defineADValidParams
defineADValidParams(ADTestDerivativeFunction, ADMaterial, params.addClassDescription("Material that implements the a function of one variable and its first derivative.");MooseEnum functionEnum("F1 F2 F3");params.addRequiredParam< MooseEnum >("function", functionEnum, "F1 = 2 op[0]^2 (1 - op[0])^2 - 0.2 op[0]; " "F2 = 0.1 op[0]^2 + op[1]^2; " "F3 = op[0] * op[1]");params.addParam< MaterialPropertyName >("f_name", "F", "function property name");params.addRequiredCoupledVar("op", "Order parameter variables");)
ADTestDerivativeFunction::computeQpProperties
virtual void computeQpProperties()
Definition: ADTestDerivativeFunction.C:55
ADTestDerivativeFunction::ADTestDerivativeFunction
ADTestDerivativeFunction(const InputParameters &parameters)
Definition: ADTestDerivativeFunction.C:29
ADTestDerivativeFunction
Material class that creates the math free energy and its derivatives for use with ADSplitCHParsed.
Definition: ADTestDerivativeFunction.h:17
ADTestDerivativeFunction::_function
enum ADTestDerivativeFunction::FunctionEnum _function
ADTestDerivativeFunction::_prop_dFdop
std::vector< ADMaterialProperty(Real) * > _prop_dFdop
function value derivative
Definition: ADTestDerivativeFunction.h:52
ADTestDerivativeFunction::FunctionEnum::F2
name
const std::string name
Definition: Setup.h:21
registerADMooseObject
registerADMooseObject("PhaseFieldTestApp", ADTestDerivativeFunction)
ADTestDerivativeFunction::FunctionEnum::F3
ADTestDerivativeFunction::_op
std::vector< const ADVariableValue * > _op
Coupled variable value for the order parameter.
Definition: ADTestDerivativeFunction.h:43
ADTestDerivativeFunction.h
ADTestDerivativeFunction::_f_name
const MaterialPropertyName _f_name
property name
Definition: ADTestDerivativeFunction.h:46