https://mooseframework.inl.gov
NestedKKSMultiACBulkF.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 
10 #include "NestedKKSMultiACBulkF.h"
11 
13 
16 {
18  params.addClassDescription("KKS model kernel (part 1 of 2) for the Bulk Allen-Cahn. This "
19  "includes all terms NOT dependent on chemical potential.");
20  params.addRequiredCoupledVar("global_cs", "The interpolated concentrations c, b, etc.");
21  params.addRequiredCoupledVar("all_etas", "Order parameters.");
22  params.addRequiredParam<std::vector<MaterialPropertyName>>(
23  "ci_names",
24  "Phase concentrations. They must have the same order as Fj_names and global_cs, for "
25  "example, c1, c2, b1, b2.");
26  params.addRequiredParam<Real>("wi", "Double well height parameter.");
27  params.addRequiredParam<MaterialPropertyName>(
28  "gi_name", "Base name for the double well function g_i(eta_i).");
29  return params;
30 }
31 
33  : KKSMultiACBulkBase(parameters),
34  _c_names(coupledNames("global_cs")),
35  _c_map(getParameterJvarMap("global_cs")),
36  _num_c(coupledComponents("global_cs")),
37  _eta_names(coupledNames("all_etas")),
38  _eta_map(getParameterJvarMap("all_etas")),
39  _k(-1),
40  _ci_names(getParam<std::vector<MaterialPropertyName>>("ci_names")),
41  _dcidetaj(_num_c),
42  _dcidb(_num_c),
43  _wi(getParam<Real>("wi")),
44  _gi_name(getParam<MaterialPropertyName>("gi_name")),
45  _dgi(getMaterialPropertyDerivative<Real>("gi_name", _etai_name)),
46  _d2gi(getMaterialPropertyDerivative<Real>("gi_name", _etai_name, _etai_name)),
47  _d2hjdetaidetap(_num_j),
48  _dF1dc1(_num_c),
49  _dFidarg(_num_j)
50 {
51  for (const auto i : make_range(_num_j))
52  {
53  // get order parameter names and variable indices
54  _eta_names[i] = getVar("all_etas", i)->name();
55 
56  // Set _k to the position of the nonlinear variable in the list of etaj's
57  if (coupled("all_etas", i) == _var.number())
58  _k = i;
59  }
60 
61  // _dcideta and _dcidb are computed in KKSPhaseConcentrationDerivatives
62  for (const auto m : make_range(_num_c))
63  {
64  _dcidetaj[m].resize(_num_j);
65  _dcidb[m].resize(_num_j);
66 
67  for (const auto n : make_range(_num_j))
68  {
69  _dcidetaj[m][n].resize(_num_j);
70  _dcidb[m][n].resize(_num_c);
71 
72  for (const auto l : make_range(_num_j))
73  _dcidetaj[m][n][l] =
74  &getMaterialPropertyDerivative<Real>(_ci_names[n + m * _num_j], _eta_names[l]);
75 
76  for (const auto l : make_range(_num_c))
77  _dcidb[m][n][l] =
78  &getMaterialPropertyDerivative<Real>(_ci_names[n + m * _num_j], _c_names[l]);
79  }
80  }
81 
82  // _dF1dc1 is computed in KKSPhaseConcentrationMaterial
83  for (const auto m : make_range(_num_c))
84  _dF1dc1[m] = &getMaterialPropertyDerivative<Real>(_Fj_names[0], _ci_names[m * _num_j]);
85 
86  for (const auto m : make_range(_num_j))
87  {
88  _d2hjdetaidetap[m].resize(_num_j);
89 
90  for (const auto n : make_range(_num_j))
91  _d2hjdetaidetap[m][n] =
92  &getMaterialPropertyDerivative<Real>(_hj_names[m], _eta_names[_k], _eta_names[n]);
93  }
94 
95  // _dFidarg is computed in KKSPhaseConcentrationMaterial
96  for (const auto m : make_range(_num_j))
97  {
98  _dFidarg[m].resize(_n_args);
99 
100  for (const auto n : make_range(_n_args))
101  _dFidarg[m][n] = &getMaterialPropertyDerivative<Real>(_Fj_names[m], m);
102  }
103 }
104 
105 Real
107 {
108  Real sum = 0.0;
109 
110  switch (type)
111  {
112  case Residual:
113  for (const auto m : make_range(_num_j))
114  sum += (*_prop_dhjdetai[m])[_qp] * (*_prop_Fj[m])[_qp];
115 
116  return sum + _wi * _dgi[_qp];
117 
118  case Jacobian:
119  // For when this kernel is used in the Lagrange multiplier equation. In that case the
120  // Lagrange multiplier is the nonlinear variable
121  if (_etai_var != _var.number())
122  return 0.0;
123 
124  // if eta_i is the nonlinear variable
125  for (const auto m : make_range(_num_j))
126  {
127  Real sum1 = 0.0;
128 
129  for (const auto n : make_range(_num_c))
130  sum1 += (*_dF1dc1[n])[_qp] * (*_dcidetaj[n][m][_k])[_qp];
131 
132  sum +=
133  (*_d2hjdetaidetap[m][_k])[_qp] * (*_prop_Fj[m])[_qp] + (*_prop_dhjdetai[m])[_qp] * sum1;
134  }
135 
136  return _phi[_j][_qp] * (sum + _wi * _d2gi[_qp]);
137  }
138 
139  mooseError("Invalid type passed in");
140 }
141 
142 Real
144 {
145  // first get dependence of mobility _L on other variables using parent class member function Real
147 
148  Real sum = 0.0;
149 
150  // if concentrations are the coupled variables
151  auto compvar = mapJvarToCvar(jvar, _c_map);
152  if (compvar >= 0)
153  {
154  for (const auto m : make_range(_num_j))
155  {
156  Real sum1 = 0.0;
157 
158  for (const auto n : make_range(_num_c))
159  sum1 += (*_dF1dc1[n])[_qp] * (*_dcidb[n][m][compvar])[_qp];
160 
161  sum += (*_prop_dhjdetai[m])[_qp] * sum1;
162  }
163 
164  res += _L[_qp] * sum * _phi[_j][_qp] * _test[_i][_qp];
165 
166  return res;
167  }
168 
169  // if order parameters are the coupled variables
170  auto etavar = mapJvarToCvar(jvar, _eta_map);
171  if (etavar >= 0)
172  {
173  for (const auto m : make_range(_num_j))
174  {
175  Real sum1 = 0.0;
176 
177  for (const auto n : make_range(_num_c))
178  sum1 += (*_dF1dc1[n])[_qp] * (*_dcidetaj[n][m][etavar])[_qp];
179 
180  sum += (*_d2hjdetaidetap[m][etavar])[_qp] * (*_prop_Fj[m])[_qp] +
181  (*_prop_dhjdetai[m])[_qp] * sum1;
182  }
183 
184  res += _L[_qp] * sum * _phi[_j][_qp] * _test[_i][_qp];
185 
186  return res;
187  }
188 
189  // Handle the case when this kernel is used in the Lagrange multiplier equation. In this case
190  // the second derivative of the barrier function contributes to the off-diagonal Jacobian
191  if (jvar == _etai_var)
192  {
193  sum += _wi * _d2gi[_qp];
194 
195  res += _L[_qp] * sum * _phi[_j][_qp] * _test[_i][_qp];
196  }
197 
198  // for all other vars get the coupled variable jvar is referring to
199  const unsigned int cvar = mapJvarToCvar(jvar);
200  for (const auto m : make_range(_num_j))
201  res -= _L[_qp] * (*_prop_dhjdetai[m])[_qp] * (*_dFidarg[m][cvar])[_qp] * _phi[_j][_qp] *
202  _test[_i][_qp];
203 
204  return res;
205 }
std::vector< std::vector< const MaterialProperty< Real > * > > _dFidarg
Derivative of the free energy function .
const MaterialProperty< Real > & _L
Mobility.
Definition: ACBulk.h:46
registerMooseObject("PhaseFieldApp", NestedKKSMultiACBulkF)
std::vector< MaterialPropertyName > _ci_names
Phase concentrations`.
const MaterialProperty< Real > & _d2gi
Second derivative of barrier function.
ACBulk child class that sets up necessary variables and materials for calculation of residual contrib...
KKSMultiACBulkBase child class for the free energy term in the the Allen-Cahn bulk residual...
std::vector< const MaterialProperty< Real > * > _dF1dc1
Derivative of the free energy function .
void mooseError(Args &&... args)
std::vector< MaterialPropertyName > _Fj_names
Names of free energy functions for each phase .
std::vector< VariableName > _eta_names
Phase parameters.
NestedKKSMultiACBulkF(const InputParameters &parameters)
void addRequiredParam(const std::string &name, const std::string &doc_string)
int _k
Position of the nonlinear variable in the list of cj&#39;s.
std::vector< std::vector< std::vector< const MaterialProperty< Real > * > > > _dcidetaj
Derivative of phase concentrations wrt etaj .
std::vector< const MaterialProperty< Real > * > _prop_dhjdetai
Derivatives of the switching functions wrt the order parameter for this kernel.
std::vector< std::vector< std::vector< const MaterialProperty< Real > * > > > _dcidb
Derivative of phase concentrations wrt global concentrations .
std::vector< MaterialPropertyName > _hj_names
switching function names
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
std::vector< VariableName > _c_names
Global concentrations.
static InputParameters validParams()
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< const MaterialProperty< Real > * > _prop_Fj
Values of the free energy functions for each phase .
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
Definition: ACBulk.h:110
static InputParameters validParams()
IntRange< T > make_range(T beg, T end)
std::vector< std::vector< const MaterialProperty< Real > * > > _d2hjdetaidetap
Second derivative of switching function .
void addClassDescription(const std::string &doc_string)
const MaterialProperty< Real > & _dgi
Derivatives of barrier function.
unsigned int _num_c
Number of global concentrations.
virtual Real computeDFDOP(PFFunctionType type)
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
unsigned int _etai_var
index of order parameter that derivatives are taken wrt
Real _wi
double well height parameter