www.mooseframework.org
DerivativeMultiPhaseBase.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 
15  // Phase materials 1-n
16  params.addRequiredParam<std::vector<MaterialPropertyName>>(
17  "fi_names", "List of free energies for the n phases");
18  params.addParam<std::vector<MaterialPropertyName>>(
19  "hi_names", "Switching Function Materials that provide h(eta_i)");
20 
21  // All arguments of the phase free energies
22  params.addCoupledVar("args", "Arguments of the fi free energies - use vector coupling");
23  params.addCoupledVar("displacement_gradients",
24  "Vector of displacement gradient variables (see "
25  "Modules/PhaseField/DisplacementGradients "
26  "action)");
27 
28  // Barrier
29  params.addParam<MaterialPropertyName>(
30  "g", "g", "Barrier Function Material that provides g(eta_i)");
31  params.addParam<Real>("W", 0.0, "Energy barrier for the phase transformation from A to B");
32 
33  return params;
34 }
35 
36 DerivativeMultiPhaseBase::DerivativeMultiPhaseBase(const InputParameters & parameters)
37  : DerivativeFunctionMaterialBase(parameters),
38  _eta_index(_nargs, -1),
39  _num_etas(coupledComponents("etas")),
40  _eta_names(_num_etas),
41  _eta_vars(_num_etas),
42  _fi_names(getParam<std::vector<MaterialPropertyName>>("fi_names")),
43  _num_fi(_fi_names.size()),
44  _prop_Fi(_num_fi),
45  _prop_dFi(_num_fi),
46  _prop_d2Fi(_num_fi),
47  _prop_d3Fi(_num_fi),
48  _hi_names(getParam<std::vector<MaterialPropertyName>>("hi_names")),
49  _num_hi(_hi_names.size()),
50  _hi(_num_hi),
51  _g(getMaterialProperty<Real>("g")),
52  _dg(_num_etas),
53  _d2g(_num_etas),
54  _d3g(_num_etas),
55  _W(getParam<Real>("W"))
56 {
57  // check passed in parameter vectors
58  if (_num_fi != _num_hi)
59  mooseError("Need to pass in as many hi_names as fi_names in DerivativeMultiPhaseBase ", name());
60 
61  // get order parameter names and libmesh variable names, set barrier function derivatives
62  for (unsigned int i = 0; i < _num_etas; ++i)
63  {
64  _eta_names[i] = getVar("etas", i)->name();
65  _eta_vars[i] = coupled("etas", i);
66 
67  // for each coupled variable we need to know if it was coupled through "etas"
68  // and - if so - which coupled component of "etas" it comes from
69  _eta_index[argIndex(_eta_vars[i])] = i;
70 
71  // barrier function derivatives
72  _dg[i] = &getMaterialPropertyDerivative<Real>("g", _eta_names[i]);
73  _d2g[i].resize(_num_etas);
75  _d3g[i].resize(_num_etas);
76 
77  for (unsigned int j = 0; j < _num_etas; ++j)
78  {
79  _d2g[i][j] = &getMaterialPropertyDerivative<Real>("g", _eta_names[i], _eta_names[j]);
80 
82  {
83  _d3g[i][j].resize(_num_etas);
84  for (unsigned int k = 0; k < _num_etas; ++k)
85  _d3g[i][j][k] = &getMaterialPropertyDerivative<Real>(
86  "g", _eta_names[i], _eta_names[j], _eta_names[k]);
87  }
88  }
89  }
90 
91  // reserve space and set phase material properties
92  for (unsigned int n = 0; n < _num_fi; ++n)
93  {
94  // get phase free energy
95  _prop_Fi[n] = &getMaterialPropertyByName<Real>(_fi_names[n]);
96  _prop_dFi[n].resize(_nargs);
97  _prop_d2Fi[n].resize(_nargs);
98  _prop_d3Fi[n].resize(_nargs);
99 
100  // get switching function
101  _hi[n] = &getMaterialPropertyByName<Real>(_hi_names[n]);
102 
103  for (unsigned int i = 0; i < _nargs; ++i)
104  {
105  _prop_dFi[n][i] = &getMaterialPropertyDerivative<Real>(_fi_names[n], _arg_names[i]);
106  _prop_d2Fi[n][i].resize(_nargs);
107 
108  if (_third_derivatives)
109  _prop_d3Fi[n][i].resize(_nargs);
110 
111  for (unsigned int j = 0; j < _nargs; ++j)
112  {
113  _prop_d2Fi[n][i][j] =
114  &getMaterialPropertyDerivative<Real>(_fi_names[n], _arg_names[i], _arg_names[j]);
115 
116  if (_third_derivatives)
117  {
118  _prop_d3Fi[n][i][j].resize(_nargs);
119 
120  for (unsigned int k = 0; k < _nargs; ++k)
121  _prop_d3Fi[n][i][j][k] = &getMaterialPropertyDerivative<Real>(
122  _fi_names[n], _arg_names[i], _arg_names[j], _arg_names[k]);
123  }
124  }
125  }
126  }
127 }
128 
129 void
131 {
132  for (unsigned int n = 0; n < _num_fi; ++n)
133  validateCoupling<Real>(_fi_names[n]);
134 }
135 
136 Real
138 {
139  Real F = 0.0;
140  for (unsigned n = 0; n < _num_fi; ++n)
141  F += (*_hi[n])[_qp] * (*_prop_Fi[n])[_qp];
142  return F + _W * _g[_qp];
143 }
virtual void initialSetup()
Check if we got the right number of components in the &#39;args&#39; coupled variable vector.
std::vector< std::vector< std::vector< const MaterialProperty< Real > * > > > _prop_d2Fi
Second derivatives of Fi.
InputParameters validParams< DerivativeFunctionMaterialBase >()
std::vector< std::vector< std::vector< const MaterialProperty< Real > * > > > _d3g
std::vector< const MaterialProperty< Real > * > _dg
Barrier function derivatives.
const MaterialProperty< Real > & _g
Barrier function .
std::vector< MaterialPropertyName > _hi_names
phase switching function names
unsigned int _num_etas
name of the order parameter variable
std::vector< std::vector< std::vector< std::vector< const MaterialProperty< Real > * > > > > _prop_d3Fi
Third derivatives of Fi.
Real _W
Phase transformation energy barrier.
std::vector< MaterialPropertyName > _fi_names
phase derivative material names
virtual Real computeF()
Override this method to provide the free energy function.
std::vector< const MaterialProperty< Real > * > _hi
Switching functions.
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.
unsigned int _nargs
Number of coupled arguments.
std::vector< VariableName > _eta_names
DerivativeMultiPhaseBase(const InputParameters &parameters)
std::vector< std::vector< const MaterialProperty< Real > * > > _d2g
InputParameters validParams< DerivativeMultiPhaseBase >()
std::vector< std::string > _arg_names
String vector of all argument names.
std::vector< int > _eta_index
If the variable a non-conserved OP this array holds the index into the etas parameter vector for a gi...
std::vector< const MaterialProperty< Real > * > _prop_Fi
Function value of the i phase.
std::vector< std::vector< const MaterialProperty< Real > * > > _prop_dFi
Derivatives of Fi w.r.t. arg[i].
std::vector< unsigned int > _eta_vars
unsigned int argIndex(unsigned int i_var) const
FunctionMaterialBase keeps an internal list of all the variables the derivatives are taken w...