www.mooseframework.org
KKSMultiACBulkC.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 /****************************************************************/
7 #include "KKSMultiACBulkC.h"
8 
9 template <>
10 InputParameters
12 {
13  InputParameters params = validParams<KKSMultiACBulkBase>();
14  params.addClassDescription("Multi-phase KKS model kernel (part 2 of 2) for the Bulk Allen-Cahn. "
15  "This includes all terms dependent on chemical potential.");
16  params.addRequiredCoupledVar(
17  "cj_names", "Array of phase concentrations cj. Place in same order as Fj_names!");
18  return params;
19 }
20 
21 KKSMultiACBulkC::KKSMultiACBulkC(const InputParameters & parameters)
22  : KKSMultiACBulkBase(parameters),
23  _c1_name(getVar("cj_names", 0)
24  ->name()), // Can use any dFj/dcj since they are equal so pick first cj in the list
25  _cjs(_num_j),
26  _cjs_var(_num_j),
27  _prop_dF1dc1(getMaterialPropertyDerivative<Real>(_Fj_names[0],
28  _c1_name)), // Use first Fj in list for dFj/dcj
29  _prop_d2F1dc12(getMaterialPropertyDerivative<Real>(_Fj_names[0], _c1_name, _c1_name))
30 {
31  if (_num_j != coupledComponents("cj_names"))
32  mooseError("Need to pass in as many cj_names as Fj_names in KKSMultiACBulkC ", name());
33 
34  // Load concentration variables into the arrays
35  for (unsigned int i = 0; i < _num_j; ++i)
36  {
37  _cjs[i] = &coupledValue("cj_names", i);
38  _cjs_var[i] = coupled("cj_names", i);
39  }
40 
41  // Resize to number of coupled variables (_nvar from KKSMultiACBulkBase constructor)
42  _prop_d2F1dc1darg.resize(_nvar);
43 
44  // Iterate over all coupled variables
45  for (unsigned int i = 0; i < _nvar; ++i)
46  {
47  MooseVariable * cvar = _coupled_moose_vars[i];
48 
49  // get second partial derivatives wrt c1 and other coupled variable
51  &getMaterialPropertyDerivative<Real>(_Fj_names[0], _c1_name, cvar->name());
52  }
53 }
54 
55 Real
57 {
58  Real sum = 0.0;
59 
60  switch (type)
61  {
62  case Residual:
63  for (unsigned int n = 0; n < _num_j; ++n)
64  sum += (*_prop_dhjdetai[n])[_qp] * (*_cjs[n])[_qp];
65 
66  return -_prop_dF1dc1[_qp] * sum;
67 
68  case Jacobian:
69  // For when this kernel is used in the Lagrange multiplier equation
70  // In that case the Lagrange multiplier is the nonlinear variable
71  if (_etai_var != _var.number())
72  return 0.0;
73 
74  // For when eta_i is the nonlinear variable
75  for (unsigned int n = 0; n < _num_j; ++n)
76  sum += (*_prop_d2hjdetai2[n])[_qp] * (*_cjs[n])[_qp];
77 
78  return -_phi[_j][_qp] * _prop_dF1dc1[_qp] * sum;
79  }
80 
81  mooseError("Invalid type passed in");
82 }
83 
84 Real
86 {
87  // first get dependence of mobility _L on other variables using parent class
88  // member function
90 
91  Real sum = 0.0;
92  // Then add dependence of KKSACBulkC on other variables
93  // Treat cj variables specially, as they appear in the residual
94  if (jvar == _cjs_var[0])
95  {
96  for (unsigned int n = 0; n < _num_j; ++n)
97  sum += (*_prop_dhjdetai[n])[_qp] * (*_cjs[n])[_qp];
98 
99  res -= _L[_qp] * (sum * _prop_d2F1dc12[_qp] + _prop_dF1dc1[_qp] * (*_prop_dhjdetai[0])[_qp]) *
100  _phi[_j][_qp] * _test[_i][_qp];
101  return res;
102  }
103 
104  for (unsigned int i = 1; i < _num_j; ++i)
105  {
106  if (jvar == _cjs_var[i])
107  {
108  res -=
109  _L[_qp] * _prop_dF1dc1[_qp] * (*_prop_dhjdetai[i])[_qp] * _phi[_j][_qp] * _test[_i][_qp];
110  return res;
111  }
112  }
113 
114  // for all other vars get the coupled variable jvar is referring to
115  const unsigned int cvar = mapJvarToCvar(jvar);
116 
117  for (unsigned int n = 0; n < _num_j; ++n)
118  sum += _prop_dF1dc1[_qp] * (*_prop_d2hjdetaidarg[n][cvar])[_qp] * (*_cjs[n])[_qp] +
119  (*_prop_d2F1dc1darg[cvar])[_qp] * (*_prop_dhjdetai[n])[_qp] * (*_cjs[n])[_qp];
120 
121  res -= _L[_qp] * sum * _phi[_j][_qp] * _test[_i][_qp];
122 
123  return res;
124 }
unsigned int _nvar
Number of coupled variables.
const MaterialProperty< Real > & _L
Mobility.
Definition: ACBulk.h:44
ACBulk child class that sets up necessary variables and materials for calculation of residual contrib...
KKSMultiACBulkC(const InputParameters &parameters)
std::vector< const MaterialProperty< Real > * > _prop_d2F1dc1darg
Mixed partial derivatives of the free energy function wrt c1 and any other coupled variables ...
std::vector< MaterialPropertyName > _Fj_names
Names of free energy functions for each phase .
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
MaterialPropertyName _c1_name
Names of phase concentration variables.
std::vector< std::vector< const MaterialProperty< Real > * > > _prop_d2hjdetaidarg
Second derivatives of the switching functions (needed for off-diagonal Jacobians) ...
virtual Real computeDFDOP(PFFunctionType type)
std::vector< const MaterialProperty< Real > * > _prop_dhjdetai
Derivatives of the switching functions wrt the order parameter for this kernel.
std::vector< unsigned int > _cjs_var
InputParameters validParams< KKSMultiACBulkC >()
InputParameters validParams< KKSMultiACBulkBase >()
std::vector< const VariableValue * > _cjs
const MaterialProperty< Real > & _prop_d2F1dc12
Second derivative of the free energy function .
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
Definition: ACBulk.h:114
std::vector< const MaterialProperty< Real > * > _prop_d2hjdetai2
Second derivatives of the switching functions wrt the order parameter for this kernel.
const MaterialProperty< Real > & _prop_dF1dc1
Derivative of the free energy function .
unsigned int _etai_var
index of order parameter that derivatives are taken wrt