www.mooseframework.org
SwitchingFunctionMultiPhaseMaterial.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<Material>();
14  params.addRequiredParam<MaterialPropertyName>(
15  "h_name", "Name of the switching function material property for the given phase");
16  params.addRequiredCoupledVar("phase_etas", "Vector of order parameters for the given phase");
17  params.addRequiredCoupledVar("all_etas", "Vector of all order parameters for all phases");
18  params.addClassDescription("Calculates the switching function for a given phase for a "
19  "multi-phase, multi-order parameter model");
20  return params;
21 }
22 
24  const InputParameters & parameters)
25  : DerivativeMaterialInterface<Material>(parameters),
26  _h_name(getParam<MaterialPropertyName>("h_name")),
27  _num_eta_p(coupledComponents("phase_etas")),
28  _eta_p(_num_eta_p),
29  _eta_p_names(_num_eta_p),
30  _num_eta(coupledComponents("all_etas")),
31  _eta(_num_eta),
32  _eta_names(_num_eta),
33  _is_p(_num_eta),
34  _prop_h(declareProperty<Real>(_h_name)),
35  _prop_dh(_num_eta),
36  _prop_d2h(_num_eta)
37 {
38  // Fetch eta values and names for phase etas
39  for (unsigned int i = 0; i < _num_eta_p; ++i)
40  {
41  _eta_p[i] = &coupledValue("phase_etas", i);
42  _eta_p_names[i] = getVar("phase_etas", i)->name();
43  }
44 
45  // Declare h derivative properties, fetch eta values for all eta
46  for (unsigned int i = 0; i < _num_eta; ++i)
47  {
48  _prop_d2h[i].resize(_num_eta);
49  _eta_names[i] = getVar("all_etas", i)->name();
50  }
51 
52  for (unsigned int i = 0; i < _num_eta; ++i)
53  {
54  _prop_dh[i] = &declarePropertyDerivative<Real>(_h_name, _eta_names[i]);
55  _eta[i] = &coupledValue("all_etas", i);
56  for (unsigned int j = i; j < _num_eta; ++j)
57  {
58  _prop_d2h[i][j] = _prop_d2h[j][i] =
59  &declarePropertyDerivative<Real>(_h_name, _eta_names[i], _eta_names[j]);
60  }
61  }
62 
63  // Determine which order parameters in the list of all etas belong to phase p
64  for (unsigned int i = 0; i < _num_eta; ++i)
65  {
66  _is_p[i] = false;
67  for (unsigned int j = 0; j < _num_eta_p; ++j)
68  {
69  if (_eta_names[i] == _eta_p_names[j])
70  _is_p[i] = true;
71  }
72  }
73 }
74 
75 void
77 {
78  Real sum_p = 0.0;
79  Real sum_all = 0.0;
80 
81  for (unsigned int i = 0; i < _num_eta_p; ++i)
82  sum_p += (*_eta_p[i])[_qp] * (*_eta_p[i])[_qp];
83 
84  for (unsigned int i = 0; i < _num_eta; ++i)
85  sum_all += (*_eta[i])[_qp] * (*_eta[i])[_qp];
86 
87  Real sum_notp = sum_all - sum_p;
88 
89  _prop_h[_qp] = sum_p / sum_all;
90 
91  for (unsigned int i = 0; i < _num_eta; ++i)
92  {
93  // First derivatives
94  if (_is_p[i])
95  (*_prop_dh[i])[_qp] = 2.0 * (*_eta[i])[_qp] * sum_notp / (sum_all * sum_all);
96  else
97  (*_prop_dh[i])[_qp] = -2.0 * (*_eta[i])[_qp] * sum_p / (sum_all * sum_all);
98 
99  // Second derivatives
100  for (unsigned int j = 0; j < _num_eta; ++j)
101  {
102  if (i == j)
103  {
104  if (_is_p[i])
105  (*_prop_d2h[i][j])[_qp] =
106  (2.0 * sum_all * sum_notp - 8.0 * (*_eta[i])[_qp] * (*_eta[i])[_qp] * sum_notp) /
107  (sum_all * sum_all * sum_all);
108  else
109  (*_prop_d2h[i][j])[_qp] =
110  (-2.0 * sum_p * sum_all + 8.0 * (*_eta[i])[_qp] * (*_eta[i])[_qp] * sum_p) /
111  (sum_all * sum_all * sum_all);
112  }
113  else if (_is_p[i] && _is_p[j])
114  (*_prop_d2h[i][j])[_qp] =
115  -8.0 * (*_eta[i])[_qp] * (*_eta[j])[_qp] * sum_notp / (sum_all * sum_all * sum_all);
116  else if (!_is_p[i] && !_is_p[j])
117  (*_prop_d2h[i][j])[_qp] =
118  8.0 * (*_eta[i])[_qp] * (*_eta[j])[_qp] * sum_p / (sum_all * sum_all * sum_all);
119  else
120  (*_prop_d2h[i][j])[_qp] = (4.0 * sum_all - 8.0 * sum_notp) * (*_eta[i])[_qp] *
121  (*_eta[j])[_qp] / (sum_all * sum_all * sum_all);
122  }
123  }
124 }
unsigned int _num_eta
Order parameters for all phases (including alpha)
MaterialPropertyName _h_name
Name of the function.
std::vector< bool > _is_p
List of which order parameters in the full list of all etas belong to phase p.
SwitchingFunctionMultiPhaseMaterial(const InputParameters &parameters)
MaterialProperty< Real > & _prop_h
Switching function and derivatives.
std::vector< MaterialProperty< Real > * > _prop_dh
InputParameters validParams< SwitchingFunctionMultiPhaseMaterial >()
unsigned int _num_eta_p
Order parameters for phase alpha.
std::vector< std::vector< MaterialProperty< Real > * > > _prop_d2h