https://mooseframework.inl.gov
KKSMultiPhaseConcentration.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
11 
13 
16 {
18  params.addClassDescription(
19  "KKS multi-phase model kernel to enforce $c = h_1c_1 + h_2c_2 + h_3c_3 + \\dots$"
20  ". The non-linear variable of this kernel is $c_n$, the final phase "
21  "concentration in the list.");
22  params.addRequiredCoupledVar(
23  "cj", "Array of phase concentrations cj. Place in same order as hj_names!");
24  params.addRequiredCoupledVar("c", "Physical concentration");
25  params.addCoupledVar("etas", "Order parameters for all phases");
26  params.addRequiredParam<std::vector<MaterialPropertyName>>(
27  "hj_names", "Switching Function Materials that provide $h(\\eta_1, \\eta_2,\\dots)$");
28  return params;
29 }
30 
31 // Phase interpolation func
34  _num_j(coupledComponents("cj")),
35  _cj(coupledValues("cj")),
36  _cj_map(getParameterJvarMap("cj")),
37  _k(-1),
38  _c(coupledValue("c")),
39  _c_var(coupled("c")),
40  _hj_names(getParam<std::vector<MaterialPropertyName>>("hj_names")),
41  _prop_hj(_hj_names.size()),
42  _eta_names(coupledComponents("etas")),
43  _eta_map(getParameterJvarMap("etas")),
44  _prop_dhjdetai(_num_j)
45 {
46  // Check to make sure the the number of hj's is the same as the number of cj's
47  if (_num_j != _hj_names.size())
48  paramError("hj_names", "Need to pass in as many hj_names as cjs");
49  // Check to make sure the the number of etas is the same as the number of cj's
50  if (_num_j != _eta_names.size())
51  paramError("etas", "Need to pass in as many etas as cjs");
52 
53  if (_num_j == 0)
54  mooseError("Need to supply at least 1 phase concentration cj in KKSMultiPhaseConcentration",
55  name());
56 
57  // get order parameter names and variable indices
58  for (unsigned int i = 0; i < _num_j; ++i)
59  _eta_names[i] = coupledName("etas", i);
60 
61  // Load concentration variables into the arrays
62  for (unsigned int m = 0; m < _num_j; ++m)
63  {
64  _prop_hj[m] = &getMaterialPropertyByName<Real>(_hj_names[m]);
65  _prop_dhjdetai[m].resize(_num_j);
66  // Set _k to the position of the nonlinear variable in the list of cj's
67  if (coupled("cj", m) == _var.number())
68  _k = m;
69 
70  // Get derivatives of switching functions wrt order parameters
71  for (unsigned int n = 0; n < _num_j; ++n)
72  _prop_dhjdetai[m][n] = &getMaterialPropertyDerivative<Real>(_hj_names[m], _eta_names[n]);
73  }
74 
75  // Check to make sure the nonlinear variable is set to one of the cj's
76  if (_k < 0)
77  mooseError("Need to set nonlinear variable to one of the cj's in KKSMultiPhaseConcentration",
78  name());
79 }
80 
81 Real
83 {
84  // R = sum_i (h_i * c_i) - c
85  Real sum_ch = 0.0;
86  for (unsigned int m = 0; m < _num_j; ++m)
87  sum_ch += (*_cj[m])[_qp] * (*_prop_hj[m])[_qp];
88 
89  return sum_ch - _c[_qp];
90 }
91 
92 Real
94 {
95  return (*_prop_hj[_k])[_qp] * _phi[_j][_qp];
96 }
97 
98 Real
100 {
101  if (jvar == _c_var)
102  return -_test[_i][_qp] * _phi[_j][_qp];
103 
104  auto cjvar = mapJvarToCvar(jvar, _cj_map);
105  if (cjvar >= 0)
106  return _test[_i][_qp] * (*_prop_hj[cjvar])[_qp] * _phi[_j][_qp];
107 
108  auto etavar = mapJvarToCvar(jvar, _eta_map);
109  if (etavar >= 0)
110  {
111  Real sum = 0.0;
112 
113  for (unsigned int n = 0; n < _num_j; ++n)
114  sum += (*_prop_dhjdetai[n][etavar])[_qp] * (*_cj[n])[_qp];
115 
116  return _test[_i][_qp] * sum * _phi[_j][_qp];
117  }
118 
119  return 0.0;
120 }
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
void mooseError(Args &&... args)
int _k
Position of the nonlinear variable in the list of cj&#39;s.
static InputParameters validParams()
std::vector< VariableName > _eta_names
Order parameters for each phase .
KKSMultiPhaseConcentration(const InputParameters &parameters)
void addRequiredParam(const std::string &name, const std::string &doc_string)
std::vector< MaterialPropertyName > _hj_names
Switching functions for each phase .
std::vector< const MaterialProperty< Real > * > _prop_hj
const std::string name
Definition: Setup.h:20
Enforce sum of phase concentrations to be the real concentration.
void addCoupledVar(const std::string &name, const std::string &doc_string)
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
registerMooseObject("PhaseFieldApp", KKSMultiPhaseConcentration)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void addClassDescription(const std::string &doc_string)
std::vector< std::vector< const MaterialProperty< Real > * > > _prop_dhjdetai
Derivative of the switching function .
static InputParameters validParams()
const std::vector< const VariableValue * > _cj