https://mooseframework.inl.gov
NestedKKSACBulkC.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 "NestedKKSACBulkC.h"
11 
12 registerMooseObject("PhaseFieldApp", NestedKKSACBulkC);
13 
16 {
18  params.addClassDescription("KKS model kernel (part 2 of 2) for the Bulk Allen-Cahn. This "
19  "includes all terms dependent on chemical potential.");
20  params.addRequiredCoupledVar("global_cs", "The interpolated concentrations c, b, etc");
21  params.addRequiredParam<std::vector<MaterialPropertyName>>(
22  "ci_names",
23  "Phase concentrations. The order must match Fa, Fb, and global_cs, for example, c1, "
24  "c2, b1, b2, etc");
25  return params;
26 }
27 
29  : KKSACBulkBase(parameters),
30  _c_names(coupledNames("global_cs")),
31  _c_map(getParameterJvarMap("global_cs")),
32  _num_c(coupledComponents("global_cs")),
33  _ci_names(getParam<std::vector<MaterialPropertyName>>("ci_names")),
34  _prop_ci(_num_c),
35  _dcideta(_num_c * 2),
36  _dcidb(_num_c * 2),
37  _Fa_name(getParam<MaterialPropertyName>("fa_name")),
38  _dFadca(_num_c),
39  _d2Fadcadba(_num_c),
40  _d2Fadcadarg(_n_args)
41 {
42  // Declare _prop_ci to be a matrix for easy reference. In _prop_ci[m][n], m is species index, n
43  // is the phase index.
44  for (const auto m : make_range(_num_c))
45  {
46  _prop_ci[m].resize(2);
47  for (const auto n : make_range(2))
48  _prop_ci[m][n] = &getMaterialPropertyByName<Real>(_ci_names[m * 2 + n]);
49  }
50 
51  // _dcideta and _dcidb are computed in KKSPhaseConcentrationDerivatives
52  for (const auto m : make_range(_num_c))
53  {
54  _dcideta[m].resize(2);
55  _dcidb[m].resize(2);
56  for (const auto n : make_range(2))
57  {
58  _dcideta[m][n] = &getMaterialPropertyDerivative<Real>(_ci_names[m * 2 + n], _var.name());
59  _dcidb[m][n].resize(_num_c);
60  for (const auto l : make_range(_num_c))
61  _dcidb[m][n][l] = &getMaterialPropertyDerivative<Real>(_ci_names[m * 2 + n], _c_names[l]);
62  }
63  }
64 
65  // _dFadca and _d2Fadcadba are computed in KKSPhaseConcentrationMaterial
66  for (const auto m : make_range(_num_c))
67  {
68  _dFadca[m] = &getMaterialPropertyDerivative<Real>("cp" + _Fa_name, _ci_names[m * 2]);
69  _d2Fadcadba[m].resize(_num_c);
70  for (const auto n : make_range(_num_c))
71  _d2Fadcadba[m][n] =
72  &getMaterialPropertyDerivative<Real>("cp" + _Fa_name, _ci_names[m * 2], _ci_names[n * 2]);
73  }
74 
75  // _d2Fadcadarg are computed in KKSPhaseConcentrationMaterial
76  for (const auto m : make_range(_num_c))
77  {
78  _d2Fadcadarg[m].resize(_n_args);
79  for (const auto n : make_range(_n_args))
80  _d2Fadcadarg[m][n] =
81  &getMaterialPropertyDerivative<Real>("cp" + _Fa_name, _ci_names[m * 2], n);
82  }
83 }
84 
85 Real
87 {
88  Real sum = 0.0;
89  switch (type)
90  {
91  case Residual:
92  for (unsigned int m = 0; m < _num_c; ++m)
93  sum += (*_dFadca[m])[_qp] * ((*_prop_ci[m][0])[_qp] - (*_prop_ci[m][1])[_qp]);
94 
95  return _prop_dh[_qp] * sum;
96 
97  case Jacobian:
98  Real sum1 = 0.0;
99  for (unsigned int m = 0; m < _num_c; ++m)
100  sum1 += (*_dFadca[m])[_qp] * ((*_prop_ci[m][0])[_qp] - (*_prop_ci[m][1])[_qp]);
101 
102  Real sum2 = 0.0;
103  for (unsigned int m = 0; m < _num_c; ++m)
104  {
105  Real sum3 = 0.0;
106  for (unsigned int n = 0; n < _num_c; ++n)
107  sum3 += (*_d2Fadcadba[m][n])[_qp] * (*_dcideta[n][0])[_qp];
108 
109  sum2 += sum3 * ((*_prop_ci[m][0])[_qp] - (*_prop_ci[m][1])[_qp]) +
110  (*_dFadca[m])[_qp] * ((*_dcideta[m][0])[_qp] - (*_dcideta[m][1])[_qp]);
111  }
112 
113  return (_prop_d2h[_qp] * sum1 + _prop_dh[_qp] * sum2) * _phi[_j][_qp];
114  }
115 
116  mooseError("Invalid type passed in");
117 }
118 
119 Real
121 {
122  // first get dependence of mobility _L on other variables using parent class member function
124 
125  // Then add dependence of KKSACBulkF on other variables.
126  // Treat c specially using chain rule.
127  auto compvar = mapJvarToCvar(jvar, _c_map);
128  if (compvar >= 0)
129  {
130  Real sum1 = 0.0;
131  for (unsigned int m = 0; m < _num_c; ++m)
132  {
133  Real sum2 = 0.0;
134  for (unsigned int n = 0; n < _num_c; ++n)
135  sum2 += (*_d2Fadcadba[m][n])[_qp] * (*_dcidb[n][0][compvar])[_qp];
136 
137  sum1 += sum2 * ((*_prop_ci[m][0])[_qp] - (*_prop_ci[m][1])[_qp]) +
138  (*_dFadca[m])[_qp] * ((*_dcidb[m][0][compvar])[_qp] - (*_dcidb[m][1][compvar])[_qp]);
139  }
140 
141  res += _L[_qp] * _prop_dh[_qp] * sum1 * _phi[_j][_qp] * _test[_i][_qp];
142  }
143 
144  // for all other vars get the coupled variable jvar is referring to
145  const unsigned int cvar = mapJvarToCvar(jvar);
146  for (unsigned int n = 0; n < _num_c; ++n)
147  res += _L[_qp] * _prop_dh[_qp] * (*_d2Fadcadarg[n][cvar])[_qp] *
148  ((*_prop_ci[n][0])[_qp] - (*_prop_ci[n][1])[_qp]) * _phi[_j][_qp] * _test[_i][_qp];
149 
150  return res;
151 }
virtual Real computeDFDOP(PFFunctionType type)
const MaterialProperty< Real > & _L
Mobility.
Definition: ACBulk.h:46
std::vector< std::vector< const MaterialProperty< Real > * > > _dcideta
Derivative of phase concentrations wrt eta .
NestedKKSACBulkC(const InputParameters &parameters)
const JvarMap & _c_map
void mooseError(Args &&... args)
std::vector< std::vector< const MaterialProperty< Real > * > > _d2Fadcadba
Second derivative of the free energy function .
std::vector< const MaterialProperty< Real > * > _dFadca
Derivative of the free energy function .
const MaterialPropertyName _Fa_name
Free energy of phase a.
static InputParameters validParams()
void addRequiredParam(const std::string &name, const std::string &doc_string)
static InputParameters validParams()
Definition: KKSACBulkBase.C:13
registerMooseObject("PhaseFieldApp", NestedKKSACBulkC)
ACBulk child class that takes all the necessary data from a KKSBaseMaterial and sets up the Allen-Cah...
Definition: KKSACBulkBase.h:22
std::vector< std::vector< std::vector< const MaterialProperty< Real > * > > > _dcidb
Derivative of phase concentrations wrt global concentrations .
std::vector< std::vector< const MaterialProperty< Real > * > > _prop_ci
Phase concentration properties.
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
const MaterialProperty< Real > & _prop_dh
Derivative of the switching function .
Definition: KKSACBulkBase.h:48
const std::vector< MaterialPropertyName > _ci_names
Phase concentrations.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
Definition: ACBulk.h:110
IntRange< T > make_range(T beg, T end)
const unsigned int _num_c
Number of global concentrations.
void addClassDescription(const std::string &doc_string)
std::vector< std::vector< const MaterialProperty< Real > * > > _d2Fadcadarg
Mixed partial derivatives of the free energy function wrt c and any other coupled variables ...
const MaterialProperty< Real > & _prop_d2h
Second derivative of the switching function .
Definition: KKSACBulkBase.h:51
std::vector< VariableName > _c_names
Global concentrations.
KKSACBulkBase child class for the phase concentration difference term in the the Allen-Cahn bulk res...