www.mooseframework.org
DerivativeMultiPhaseMaterial.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<DerivativeMultiPhaseBase>();
14  params.addClassDescription("Two phase material that combines n phase materials using a switching "
15  "function with and n nonconserved order parameters (to be used with "
16  "SwitchingFunctionConstraint*).");
17  params.addCoupledVar("etas", "Order parameters for all phases.");
18  return params;
19 }
20 
22  : DerivativeMultiPhaseBase(parameters), _dhi(_num_etas), _d2hi(_num_etas), _d3hi(_num_etas)
23 {
24  // verify that the user supplied one less eta than the number of phases
25  if (_num_hi != _num_etas)
26  mooseError("The number of coupled etas must be equal to the number of hi_names in "
27  "DerivativeMultiPhaseMaterial ",
28  name());
29 
30  for (unsigned int i = 0; i < _num_etas; ++i)
31  {
32  _dhi[i] = &getMaterialPropertyDerivative<Real>(_hi_names[i], _eta_names[i]);
33  _d2hi[i] = &getMaterialPropertyDerivative<Real>(_hi_names[i], _eta_names[i], _eta_names[i]);
34 
36  _d3hi[i] = &getMaterialPropertyDerivative<Real>(
37  _hi_names[i], _eta_names[i], _eta_names[i], _eta_names[i]);
38  }
39 }
40 
41 Real
43 {
44  const unsigned int i = argIndex(i_var);
45  const int i_eta = _eta_index[i];
46 
47  if (i_eta >= 0)
48  return (*_dhi[i_eta])[_qp] * (*_prop_Fi[i_eta])[_qp] + _W * (*_dg[i_eta])[_qp];
49  else
50  {
51  Real dF = 0.0;
52  for (unsigned n = 0; n < _num_fi; ++n)
53  dF += (*_hi[n])[_qp] * (*_prop_dFi[n][i])[_qp];
54  return dF;
55  }
56 }
57 
58 Real
59 DerivativeMultiPhaseMaterial::computeD2F(unsigned int i_var, unsigned int j_var)
60 {
61  const unsigned int i = argIndex(i_var);
62  const int i_eta = _eta_index[i];
63  const unsigned int j = argIndex(j_var);
64  const int j_eta = _eta_index[j];
65 
66  // all arguments are eta-variables
67 
68  if (i_eta >= 0 && j_eta >= 0)
69  {
70  // if the derivatives are taken w.r.t. a single eta the d2hi term for eta_i appears, otherwise
71  // it drops out
72  // because we assume that hi _only_ depends on eta_i
73  Real d2F = (i_eta == j_eta) ? (*_d2hi[i_eta])[_qp] * (*_prop_Fi[i_eta])[_qp] : 0.0;
74 
75  return d2F + _W * (*_d2g[i_eta][j_eta])[_qp];
76  }
77 
78  // one argument is an eta-variable
79 
80  if (i_eta >= 0)
81  return (*_dhi[i_eta])[_qp] * (*_prop_dFi[i_eta][j])[_qp];
82 
83  if (j_eta >= 0)
84  return (*_dhi[j_eta])[_qp] * (*_prop_dFi[j_eta][i])[_qp];
85 
86  // no arguments are eta-variables
87 
88  Real d2F = 0.0;
89  for (unsigned n = 0; n < _num_fi; ++n)
90  d2F += (*_hi[n])[_qp] * (*_prop_d2Fi[n][i][j])[_qp];
91  return d2F;
92 }
93 
94 Real
95 DerivativeMultiPhaseMaterial::computeD3F(unsigned int i_var, unsigned int j_var, unsigned int k_var)
96 {
97  const unsigned int i = argIndex(i_var);
98  const int i_eta = _eta_index[i];
99  const unsigned int j = argIndex(j_var);
100  const int j_eta = _eta_index[j];
101  const unsigned int k = argIndex(k_var);
102  const int k_eta = _eta_index[k];
103 
104  // all arguments are eta-variables
105 
106  if (i_eta >= 0 && j_eta >= 0 && k_eta >= 0)
107  {
108  // if the derivatives are taken w.r.t. a single eta the d3hi term for eta_i appears, otherwise
109  // it drops out
110  // because we assume that hi _only_ depends on eta_i
111  Real d3F =
112  (i_eta == j_eta && j_eta == k_eta) ? (*_d3hi[i_eta])[_qp] * (*_prop_Fi[i_eta])[_qp] : 0.0;
113 
114  return d3F + _W * (*_d3g[i_eta][j_eta][k_eta])[_qp];
115  }
116 
117  // two arguments are eta-variables
118 
119  if (i_eta >= 0 && j_eta >= 0)
120  return (i_eta == j_eta) ? (*_d2hi[i_eta])[_qp] * (*_prop_dFi[i_eta][k])[_qp] : 0.0;
121 
122  if (j_eta >= 0 && k_eta >= 0)
123  return (j_eta == k_eta) ? (*_d2hi[j_eta])[_qp] * (*_prop_dFi[j_eta][i])[_qp] : 0.0;
124 
125  if (k_eta >= 0 && i_eta >= 0)
126  return (k_eta == i_eta) ? (*_d2hi[k_eta])[_qp] * (*_prop_dFi[k_eta][j])[_qp] : 0.0;
127 
128  // one argument is an eta-variable
129 
130  if (i_eta >= 0)
131  return (*_dhi[i_eta])[_qp] * (*_prop_d2Fi[i_eta][j][k])[_qp];
132 
133  if (j_eta >= 0)
134  return (*_dhi[j_eta])[_qp] * (*_prop_d2Fi[j_eta][i][k])[_qp];
135 
136  if (k_eta >= 0)
137  return (*_dhi[k_eta])[_qp] * (*_prop_d2Fi[k_eta][i][j])[_qp];
138 
139  // no arguments are eta-variables
140 
141  Real d3F = 0.0;
142  for (unsigned n = 0; n < _num_fi; ++n)
143  d3F += (*_hi[n])[_qp] * (*_prop_d3Fi[n][i][j][k])[_qp];
144  return d3F;
145 }
virtual Real computeDF(unsigned int i_var)
Override this method for calculating the first derivatives.
std::vector< std::vector< std::vector< const MaterialProperty< Real > * > > > _prop_d2Fi
Second derivatives of Fi.
std::vector< std::vector< std::vector< const MaterialProperty< Real > * > > > _d3g
std::vector< const MaterialProperty< Real > * > _dg
Barrier function derivatives.
std::vector< const MaterialProperty< Real > * > _d2hi
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< const MaterialProperty< Real > * > _hi
Switching functions.
bool _third_derivatives
Calculate (and allocate memory for) the third derivatives of the free energy.
std::vector< const MaterialProperty< Real > * > _d3hi
InputParameters validParams< DerivativeMultiPhaseMaterial >()
virtual Real computeD3F(unsigned int i_var, unsigned int j_var, unsigned int k_var)
Override this method to calculate the third derivatives.
std::vector< VariableName > _eta_names
std::vector< std::vector< const MaterialProperty< Real > * > > _d2g
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...
DerivativeMaterial child class to evaluate a parsed function for the free energy and automatically pr...
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< const MaterialProperty< Real > * > _dhi
Function value of the i phase.
DerivativeMultiPhaseMaterial(const InputParameters &parameters)
InputParameters validParams< DerivativeMultiPhaseBase >()
virtual Real computeD2F(unsigned int i_var, unsigned int j_var)
Override this method to calculate the second derivatives.
unsigned int argIndex(unsigned int i_var) const
FunctionMaterialBase keeps an internal list of all the variables the derivatives are taken w...