www.mooseframework.org
DerivativeTwoPhaseMaterial.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
8 
9 template <>
10 InputParameters
12 {
13  InputParameters params = validParams<DerivativeFunctionMaterialBase>();
14  params.addClassDescription(
15  "Two phase material that combines two single phase materials using a switching function.");
16 
17  // Two base materials
18  params.addRequiredParam<MaterialPropertyName>("fa_name", "Phase A material (at eta=0)");
19  params.addRequiredParam<MaterialPropertyName>("fb_name", "Phase A material (at eta=1)");
20  params.addParam<MaterialPropertyName>(
21  "h", "h", "Switching Function Material that provides h(eta)");
22  params.addParam<MaterialPropertyName>("g", "g", "Barrier Function Material that provides g(eta)");
23 
24  // All arguments of the phase free energies
25  params.addCoupledVar("args", "Arguments of fa and fb - use vector coupling");
26  params.addCoupledVar("displacement_gradients",
27  "Vector of displacement gradient variables (see "
28  "Modules/PhaseField/DisplacementGradients "
29  "action)");
30 
31  // Order parameter which determines the phase
32  params.addRequiredCoupledVar("eta", "Order parameter");
33 
34  // Variables with applied tolerances and their tolerance values
35  params.addParam<Real>("W", 0.0, "Energy barrier for the phase transformation from A to B");
36 
37  return params;
38 }
39 
40 DerivativeTwoPhaseMaterial::DerivativeTwoPhaseMaterial(const InputParameters & parameters)
41  : DerivativeFunctionMaterialBase(parameters),
42  _eta(coupledValue("eta")),
43  _eta_name(getVar("eta", 0)->name()),
44  _eta_var(coupled("eta")),
45  _h(getMaterialProperty<Real>("h")),
46  _dh(getMaterialPropertyDerivative<Real>("h", _eta_name)),
47  _d2h(getMaterialPropertyDerivative<Real>("h", _eta_name, _eta_name)),
48  _d3h(getMaterialPropertyDerivative<Real>("h", _eta_name, _eta_name, _eta_name)),
49  _g(getMaterialProperty<Real>("g")),
50  _dg(getMaterialPropertyDerivative<Real>("g", _eta_name)),
51  _d2g(getMaterialPropertyDerivative<Real>("g", _eta_name, _eta_name)),
52  _d3g(getMaterialPropertyDerivative<Real>("g", _eta_name, _eta_name, _eta_name)),
53  _W(getParam<Real>("W")),
54  _prop_Fa(getMaterialProperty<Real>("fa_name")),
55  _prop_Fb(getMaterialProperty<Real>("fb_name"))
56 {
57  // reserve space for phase A and B material properties
58  _prop_dFa.resize(_nargs);
59  _prop_d2Fa.resize(_nargs);
60  _prop_d3Fa.resize(_nargs);
61  _prop_dFb.resize(_nargs);
62  _prop_d2Fb.resize(_nargs);
63  _prop_d3Fb.resize(_nargs);
64  for (unsigned int i = 0; i < _nargs; ++i)
65  {
66  _prop_dFa[i] = &getMaterialPropertyDerivative<Real>("fa_name", _arg_names[i]);
67  _prop_dFb[i] = &getMaterialPropertyDerivative<Real>("fb_name", _arg_names[i]);
68 
69  _prop_d2Fa[i].resize(_nargs);
70  _prop_d2Fb[i].resize(_nargs);
71 
72  // TODO: maybe we should reserve and initialize to NULL...
74  {
75  _prop_d3Fa[i].resize(_nargs);
76  _prop_d3Fb[i].resize(_nargs);
77  }
78 
79  for (unsigned int j = 0; j < _nargs; ++j)
80  {
81  _prop_d2Fa[i][j] =
82  &getMaterialPropertyDerivative<Real>("fa_name", _arg_names[i], _arg_names[j]);
83  _prop_d2Fb[i][j] =
84  &getMaterialPropertyDerivative<Real>("fb_name", _arg_names[i], _arg_names[j]);
85 
87  {
88  _prop_d3Fa[i][j].resize(_nargs);
89  _prop_d3Fb[i][j].resize(_nargs);
90 
91  for (unsigned int k = 0; k < _nargs; ++k)
92  {
93  _prop_d3Fa[i][j][k] = &getMaterialPropertyDerivative<Real>(
94  "fa_name", _arg_names[i], _arg_names[j], _arg_names[k]);
95  _prop_d3Fb[i][j][k] = &getMaterialPropertyDerivative<Real>(
96  "fb_name", _arg_names[i], _arg_names[j], _arg_names[k]);
97  }
98  }
99  }
100  }
101 }
102 
103 void
105 {
106  validateCoupling<Real>("fa_name");
107  validateCoupling<Real>("fb_name");
108 }
109 
110 Real
112 {
113  return _h[_qp] * _prop_Fb[_qp] + (1.0 - _h[_qp]) * _prop_Fa[_qp] + _W * _g[_qp];
114 }
115 
116 Real
118 {
119  if (i_var == _eta_var)
120  return _dh[_qp] * (_prop_Fb[_qp] - _prop_Fa[_qp]) + _W * _dg[_qp];
121  else
122  {
123  unsigned int i = argIndex(i_var);
124  return _h[_qp] * (*_prop_dFb[i])[_qp] + (1.0 - _h[_qp]) * (*_prop_dFa[i])[_qp];
125  }
126 }
127 
128 Real
129 DerivativeTwoPhaseMaterial::computeD2F(unsigned int i_var, unsigned int j_var)
130 {
131  if (i_var == _eta_var && j_var == _eta_var)
132  return _d2h[_qp] * (_prop_Fb[_qp] - _prop_Fa[_qp]) + _W * _d2g[_qp];
133 
134  unsigned int i = argIndex(i_var);
135  unsigned int j = argIndex(j_var);
136 
137  if (i_var == _eta_var)
138  return _dh[_qp] * ((*_prop_dFb[j])[_qp] - (*_prop_dFa[j])[_qp]);
139  if (j_var == _eta_var)
140  return _dh[_qp] * ((*_prop_dFb[i])[_qp] - (*_prop_dFa[i])[_qp]);
141 
142  return _h[_qp] * (*_prop_d2Fb[i][j])[_qp] + (1.0 - _h[_qp]) * (*_prop_d2Fa[i][j])[_qp];
143 }
144 
145 Real
146 DerivativeTwoPhaseMaterial::computeD3F(unsigned int i_var, unsigned int j_var, unsigned int k_var)
147 {
148  if (i_var == _eta_var && j_var == _eta_var && k_var == _eta_var)
149  return _d3h[_qp] * (_prop_Fb[_qp] - _prop_Fa[_qp]) + _W * _d3g[_qp];
150 
151  unsigned int i = argIndex(i_var);
152  unsigned int j = argIndex(j_var);
153  unsigned int k = argIndex(k_var);
154 
155  if (j_var == _eta_var && k_var == _eta_var)
156  return _d2h[_qp] * ((*_prop_dFb[i])[_qp] - (*_prop_dFa[i])[_qp]);
157  if (i_var == _eta_var && k_var == _eta_var)
158  return _d2h[_qp] * ((*_prop_dFb[j])[_qp] - (*_prop_dFa[j])[_qp]);
159  if (i_var == _eta_var && j_var == _eta_var)
160  return _d2h[_qp] * ((*_prop_dFb[k])[_qp] - (*_prop_dFa[k])[_qp]);
161 
162  if (i_var == _eta_var)
163  return _dh[_qp] * (*_prop_d2Fb[j][k])[_qp] + (1.0 - _dh[_qp]) * (*_prop_d2Fa[j][k])[_qp];
164  if (j_var == _eta_var)
165  return _dh[_qp] * (*_prop_d2Fb[i][k])[_qp] + (1.0 - _dh[_qp]) * (*_prop_d2Fa[i][k])[_qp];
166  if (k_var == _eta_var)
167  return _dh[_qp] * (*_prop_d2Fb[i][j])[_qp] + (1.0 - _dh[_qp]) * (*_prop_d2Fa[i][j])[_qp];
168 
169  return _h[_qp] * (*_prop_d3Fb[i][j][k])[_qp] + (1.0 - _h[_qp]) * (*_prop_d3Fa[i][j][k])[_qp];
170 }
virtual Real computeF() override
Override this method to provide the free energy function.
virtual Real computeDF(unsigned int i_var) override
Override this method for calculating the first derivatives.
DerivativeTwoPhaseMaterial(const InputParameters &parameters)
InputParameters validParams< DerivativeTwoPhaseMaterial >()
const MaterialProperty< Real > & _dh
InputParameters validParams< DerivativeFunctionMaterialBase >()
const MaterialProperty< Real > & _d3g
const MaterialProperty< Real > & _prop_Fa
Function value of the A and B phase.
std::vector< std::vector< const MaterialProperty< Real > * > > _prop_d2Fa
Second derivatives of Fa and Fb.
const MaterialProperty< Real > & _g
std::vector< const MaterialProperty< Real > * > _prop_dFb
virtual Real computeD3F(unsigned int i_var, unsigned int j_var, unsigned int k_var) override
Override this method to calculate the third derivatives.
std::vector< std::vector< std::vector< const MaterialProperty< Real > * > > > _prop_d3Fb
const MaterialProperty< Real > & _d2h
std::vector< std::vector< std::vector< const MaterialProperty< Real > * > > > _prop_d3Fa
Third derivatives of Fa and Fb.
Material base class central to compute the a phase free energy and its derivatives.
bool _third_derivatives
Calculate (and allocate memory for) the third derivatives of the free energy.
Real _W
Phase transformatuion energy barrier.
unsigned int _nargs
Number of coupled arguments.
const MaterialProperty< Real > & _d3h
virtual void initialSetup() override
Check if we got the right number of components in the &#39;args&#39; coupled variable vector.
const MaterialProperty< Real > & _h
const MaterialProperty< Real > & _d2g
const MaterialProperty< Real > & _dg
std::vector< std::string > _arg_names
String vector of all argument names.
std::vector< const MaterialProperty< Real > * > _prop_dFa
Derivatives of Fa and Fb with respect to arg[i].
const MaterialProperty< Real > & _prop_Fb
unsigned int _eta_var
libMesh variable number for eta
virtual Real computeD2F(unsigned int i_var, unsigned int j_var) override
Override this method to calculate the second derivatives.
std::vector< std::vector< const MaterialProperty< Real > * > > _prop_d2Fb
unsigned int argIndex(unsigned int i_var) const
FunctionMaterialBase keeps an internal list of all the variables the derivatives are taken w...