www.mooseframework.org
KKSMultiPhaseConcentration.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<Kernel>();
14  params.addClassDescription(
15  "KKS multi-phase model kernel to enforce $c = h_1c_1 + h_2c_2 + h_3c_3 + \\dots$"
16  ". The non-linear variable of this kernel is $c_n$, the final phase "
17  "concentration in the list.");
18  params.addRequiredCoupledVar(
19  "cj", "Array of phase concentrations cj. Place in same order as hj_names!");
20  params.addRequiredCoupledVar("c", "Physical concentration");
21  params.addCoupledVar("etas", "Order parameters for all phases");
22  params.addRequiredParam<std::vector<MaterialPropertyName>>(
23  "hj_names", "Switching Function Materials that provide $h(\\eta_1, \\eta_2,\\dots)$");
24  return params;
25 }
26 
27 // Phase interpolation func
28 KKSMultiPhaseConcentration::KKSMultiPhaseConcentration(const InputParameters & parameters)
29  : DerivativeMaterialInterface<Kernel>(parameters),
30  _num_j(coupledComponents("cj")),
31  _cjs(_num_j),
32  _cjs_var(_num_j),
33  _k(-1),
34  _c(coupledValue("c")),
35  _c_var(coupled("c")),
36  _hj_names(getParam<std::vector<MaterialPropertyName>>("hj_names")),
37  _prop_hj(_hj_names.size()),
38  _eta_names(coupledComponents("etas")),
39  _eta_vars(coupledComponents("etas")),
40  _prop_dhjdetai(_num_j)
41 {
42  // Check to make sure the the number of hj's is the same as the number of cj's
43  if (_num_j != _hj_names.size())
44  mooseError("Need to pass in as many hj_names as cjs in KKSMultiPhaseConcentration", name());
45  // Check to make sure the the number of etas is the same as the number of cj's
46  if (_num_j != _eta_names.size())
47  mooseError("Need to pass in as many etas as cjs in KKSMultiPhaseConcentration", name());
48 
49  if (_num_j == 0)
50  mooseError("Need to supply at least 1 phase concentration cj in KKSMultiPhaseConcentration",
51  name());
52 
53  // get order parameter names and variable indices
54  for (unsigned int i = 0; i < _num_j; ++i)
55  {
56  _eta_names[i] = getVar("etas", i)->name();
57  _eta_vars[i] = coupled("etas", i);
58  }
59 
60  // Load concentration variables into the arrays
61  for (unsigned int m = 0; m < _num_j; ++m)
62  {
63  _cjs[m] = &coupledValue("cj", m);
64  _cjs_var[m] = coupled("cj", m);
65  _prop_hj[m] = &getMaterialPropertyByName<Real>(_hj_names[m]);
66  _prop_dhjdetai[m].resize(_num_j);
67  // Set _k to the position of the nonlinear variable in the list of cj's
68  if (coupled("cj", m) == _var.number())
69  _k = m;
70 
71  // Get derivatives of switching functions wrt order parameters
72  for (unsigned int n = 0; n < _num_j; ++n)
73  _prop_dhjdetai[m][n] = &getMaterialPropertyDerivative<Real>(_hj_names[m], _eta_names[n]);
74  }
75 
76  // Check to make sure the nonlinear variable is set to one of the cj's
77  if (_k < 0)
78  mooseError("Need to set nonlinear variable to one of the cj's in KKSMultiPhaseConcentration",
79  name());
80 }
81 
82 Real
84 {
85  // R = sum_i (h_i * c_i) - c
86  Real sum_ch = 0.0;
87  for (unsigned int m = 0; m < _num_j; ++m)
88  sum_ch += (*_cjs[m])[_qp] * (*_prop_hj[m])[_qp];
89 
90  return _test[_i][_qp] * (sum_ch - _c[_qp]);
91 }
92 
93 Real
95 {
96  return _test[_i][_qp] * (*_prop_hj[_k])[_qp] * _phi[_j][_qp];
97 }
98 
99 Real
101 {
102  if (jvar == _c_var)
103  return -_test[_i][_qp] * _phi[_j][_qp];
104 
105  for (unsigned int m = 0; m < _num_j; ++m)
106  if (jvar == _cjs_var[m])
107  return _test[_i][_qp] * (*_prop_hj[m])[_qp] * _phi[_j][_qp];
108 
109  for (unsigned int m = 0; m < _num_j; ++m)
110  if (jvar == _eta_vars[m])
111  {
112  Real sum = 0.0;
113 
114  for (unsigned int n = 0; n < _num_j; ++n)
115  sum += (*_prop_dhjdetai[n][m])[_qp] * (*_cjs[n])[_qp];
116 
117  return _test[_i][_qp] * sum * _phi[_j][_qp];
118  }
119 
120  return 0.0;
121 }
std::vector< unsigned int > _cjs_var
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
int _k
Position of the nonlinear variable in the list of cj&#39;s.
std::vector< VariableName > _eta_names
Order parameters for each phase .
KKSMultiPhaseConcentration(const InputParameters &parameters)
std::vector< MaterialPropertyName > _hj_names
Switching functions for each phase .
std::vector< const MaterialProperty< Real > * > _prop_hj
std::vector< const VariableValue * > _cjs
std::vector< std::vector< const MaterialProperty< Real > * > > _prop_dhjdetai
Derivative of the switching function .
std::vector< unsigned int > _eta_vars
InputParameters validParams< KKSMultiPhaseConcentration >()