https://mooseframework.inl.gov
NestedKKSACBulkF.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 "NestedKKSACBulkF.h"
11 
12 registerMooseObject("PhaseFieldApp", NestedKKSACBulkF);
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.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  params.addRequiredParam<MaterialPropertyName>(
26  "fb_name", "Free energy function Fb (fa_name is in the KKSACBulkBase).");
27  params.addParam<MaterialPropertyName>(
28  "g_name", "g", "Base name for the double well function g(eta)");
29  params.addRequiredParam<Real>("w", "Double well height parameter");
30  return params;
31 }
32 
34  : KKSACBulkBase(parameters),
35  _c_map(getParameterJvarMap("global_cs")),
36  _num_c(coupledComponents("global_cs")),
37  _c_names(coupledNames("global_cs")),
38  _ci_names(getParam<std::vector<MaterialPropertyName>>("ci_names")),
39  _Fa_name(getParam<MaterialPropertyName>("fa_name")),
40  _dFadca(_num_c),
41  _Fb_name(getParam<MaterialPropertyName>("fb_name")),
42  _dFbdcb(_num_c),
43  _prop_dg(getMaterialPropertyDerivative<Real>("g_name", _eta_name)),
44  _prop_d2g(getMaterialPropertyDerivative<Real>("g_name", _eta_name, _eta_name)),
45  _w(getParam<Real>("w")),
46  _prop_Fi(2),
47  _dcideta(_num_c * 2),
48  _dcidb(_num_c * _num_c * 2),
49  _dFadarg(_n_args),
50  _dFbdarg(_n_args)
51 {
52  // _prop_Fi is computed in KKSPhaseConcentrationMaterial
53  _prop_Fi[0] = &getMaterialPropertyByName<Real>("cp" + _Fa_name);
54  _prop_Fi[1] = &getMaterialPropertyByName<Real>("cp" + _Fb_name);
55 
56  // _dcideta and _dcid are computed in KKSPhaseConcentrationDerivatives
57  for (const auto m : make_range(_num_c))
58  {
59  _dcideta[m].resize(2);
60  _dcidb[m].resize(2);
61  for (const auto n : make_range(2))
62  {
63  _dcideta[m][n] = &getMaterialPropertyDerivative<Real>(_ci_names[m * 2 + n], _var.name());
64  _dcidb[m][n].resize(_num_c);
65 
66  for (const auto l : make_range(_num_c))
67  _dcidb[m][n][l] = &getMaterialPropertyDerivative<Real>(_ci_names[m * 2 + n], _c_names[l]);
68  }
69  }
70 
71  // _dFadca and _dFbdcb are computed in KKSPhaseConcentrationMaterial
72  for (const auto m : make_range(_num_c))
73  {
74  _dFadca[m] = &getMaterialPropertyDerivative<Real>("cp" + _Fa_name, _ci_names[m * 2]);
75  _dFbdcb[m] = &getMaterialPropertyDerivative<Real>("cp" + _Fb_name, _ci_names[m * 2 + 1]);
76  }
77 
78  // _dFadarg and _dFbdarg are computed in KKSPhaseConcentrationMaterial
79  for (const auto m : make_range(_n_args))
80  {
81  _dFadarg[m] = &getMaterialPropertyDerivative<Real>("cp" + _Fa_name, m);
82  _dFbdarg[m] = &getMaterialPropertyDerivative<Real>("cp" + _Fb_name, m);
83  }
84 }
85 
86 Real
88 {
89  const Real A1 = (*_prop_Fi[0])[_qp] - (*_prop_Fi[1])[_qp];
90  switch (type)
91  {
92  case Residual:
93  return -_prop_dh[_qp] * A1 + _w * _prop_dg[_qp];
94 
95  case Jacobian:
96  Real sum = 0.0;
97  for (const auto m : make_range(_num_c))
98  sum += (*_dFadca[m])[_qp] * (*_dcideta[m][0])[_qp] -
99  (*_dFbdcb[m])[_qp] * (*_dcideta[m][1])[_qp];
100 
101  return (-(_prop_d2h[_qp] * A1 + _prop_dh[_qp] * sum) + _w * _prop_d2g[_qp]) * _phi[_j][_qp];
102  }
103  mooseError("Invalid type passed in");
104 }
105 
106 Real
108 {
109  // first get dependence of mobility _L on other variables using parent class member function
111 
112  // Then add dependence of KKSACBulkF on other variables, and treat c specially using chain rule
113  auto compvar = mapJvarToCvar(jvar, _c_map);
114 
115  if (compvar >= 0)
116  {
117  Real sum = 0.0;
118  for (const auto m : make_range(_num_c))
119  sum += (*_dFadca[m])[_qp] * (*_dcidb[m][0][compvar])[_qp] -
120  (*_dFbdcb[m])[_qp] * (*_dcidb[m][1][compvar])[_qp];
121 
122  res -= _L[_qp] * _prop_dh[_qp] * sum * _phi[_j][_qp] * _test[_i][_qp];
123  }
124 
125  // for all other vars get the coupled variable jvar is referring to
126  const unsigned int cvar = mapJvarToCvar(jvar);
127 
128  res -= _L[_qp] * _prop_dh[_qp] * ((*_dFadarg[cvar])[_qp] - (*_dFbdarg[cvar])[_qp]) *
129  _phi[_j][_qp] * _test[_i][_qp];
130 
131  return res;
132 }
const MaterialProperty< Real > & _prop_d2g
Second derivative of barrier function g.
const MaterialProperty< Real > & _L
Mobility.
Definition: ACBulk.h:46
std::vector< const MaterialProperty< Real > * > _dFadarg
Partial derivative of the free energy function Fa wrt coupled variables .
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void mooseError(Args &&... args)
std::vector< std::vector< const MaterialProperty< Real > * > > _dcideta
Derivative of phase concentration wrt eta .
std::vector< std::vector< std::vector< const MaterialProperty< Real > * > > > _dcidb
Derivative of phase concentration wrt global concentration .
std::vector< const MaterialProperty< Real > * > _dFbdarg
Partial derivative of the free energy function Fb wrt coupled variables .
const MaterialPropertyName _Fb_name
Free energy of phase b.
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
registerMooseObject("PhaseFieldApp", NestedKKSACBulkF)
const Real _w
Double well height parameter.
void addRequiredParam(const std::string &name, const std::string &doc_string)
static InputParameters validParams()
Definition: KKSACBulkBase.C:13
virtual Real computeDFDOP(PFFunctionType type)
const MaterialProperty< Real > & _prop_dg
Derivative of barrier function g.
ACBulk child class that takes all the necessary data from a KKSBaseMaterial and sets up the Allen-Cah...
Definition: KKSACBulkBase.h:22
static InputParameters validParams()
const std::vector< MaterialPropertyName > _ci_names
Phase concentrations.
const MaterialPropertyName _Fa_name
Free energy of phase a.
KKSACBulkBase child class for the free energy difference term in the the Allen-Cahn bulk residual...
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
std::vector< const MaterialProperty< Real > * > _prop_Fi
Free energy properties.
std::vector< const MaterialProperty< Real > * > _dFbdcb
Derivative of the free energy function .
const MaterialProperty< Real > & _prop_dh
Derivative of the switching function .
Definition: KKSACBulkBase.h:48
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
Definition: ACBulk.h:110
const std::vector< VariableName > _c_names
Global concentrations.
IntRange< T > make_range(T beg, T end)
std::vector< const MaterialProperty< Real > * > _dFadca
Derivative of the free energy function .
void addClassDescription(const std::string &doc_string)
const MaterialProperty< Real > & _prop_d2h
Second derivative of the switching function .
Definition: KKSACBulkBase.h:51
const JvarMap & _c_map
const unsigned int _num_c
Number of global concentrations.
NestedKKSACBulkF(const InputParameters &parameters)