www.mooseframework.org
KKSCHBulk.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 "KKSCHBulk.h"
8 
9 template <>
10 InputParameters
12 {
13  InputParameters params = CHBulk<Real>::validParams();
14  params.addClassDescription("KKS model kernel for the Bulk Cahn-Hilliard term. This operates on "
15  "the concentration 'c' as the non-linear variable");
16  params.addRequiredParam<MaterialPropertyName>("fa_name",
17  "Base name of the free energy function "
18  "F (f_name in the corresponding "
19  "derivative function material)");
20  params.addRequiredParam<MaterialPropertyName>("fb_name",
21  "Base name of the free energy function "
22  "F (f_name in the corresponding "
23  "derivative function material)");
24  params.addRequiredCoupledVar(
25  "ca", "phase concentration corresponding to the non-linear variable of this kernel");
26  params.addRequiredCoupledVar(
27  "cb", "phase concentration corresponding to the non-linear variable of this kernel");
28  params.addCoupledVar("args_a", "Vector of additional arguments to Fa");
29  params.addParam<MaterialPropertyName>(
30  "h_name", "h", "Base name for the switching function h(eta)"); // TODO: everywhere else this
31  // is called just "h"
32  return params;
33 }
34 
35 KKSCHBulk::KKSCHBulk(const InputParameters & parameters)
36  : CHBulk<Real>(parameters),
37  // number of coupled variables (ca, args_a[])
38  _nvar(_coupled_moose_vars.size()),
39  _ca_var(coupled("ca")),
40  _ca_name(getVar("ca", 0)->name()),
41  _cb_var(coupled("cb")),
42  _cb_name(getVar("cb", 0)->name()),
43  _prop_h(getMaterialProperty<Real>("h_name")),
44  _second_derivative_Fa(getMaterialPropertyDerivative<Real>("fa_name", _ca_name, _ca_name)),
45  _second_derivative_Fb(getMaterialPropertyDerivative<Real>("fb_name", _cb_name, _cb_name))
46 {
47  // reserve space for derivatives
48  _second_derivatives.resize(_nvar);
49  _third_derivatives.resize(_nvar);
51  _grad_args.resize(_nvar);
52 
53  // Iterate over all coupled variables
54  for (unsigned int i = 0; i < _nvar; ++i)
55  {
56  MooseVariable * cvar = _coupled_moose_vars[i];
57 
58  // get the second derivative material property (TODO:warn)
60  &getMaterialPropertyDerivative<Real>("fa_name", _ca_name, cvar->name());
61 
62  // get the third derivative material properties
63  _third_derivatives[i].resize(_nvar);
64  for (unsigned int j = 0; j < _nvar; ++j)
65  _third_derivatives[i][j] = &getMaterialPropertyDerivative<Real>(
66  "fa_name", _ca_name, cvar->name(), _coupled_moose_vars[j]->name());
67 
68  // third derivative for the on-diagonal jacobian
70  &getMaterialPropertyDerivative<Real>("fa_name", _ca_name, cvar->name(), _ca_name);
71 
72  // get the gradient
73  _grad_args[i] = &(cvar->gradSln());
74  }
75 }
76 
84 RealGradient
86 {
87  RealGradient res = 0.0;
88 
89  switch (type)
90  {
91  case Residual:
92  for (unsigned int i = 0; i < _nvar; ++i)
93  res += (*_second_derivatives[i])[_qp] * (*_grad_args[i])[_qp];
94 
95  return res;
96 
97  case Jacobian:
98  // the non linear variable is c, but the free energy only contains the
99  // phase concentrations. Equation (23) in the KKS paper gives the chain-
100  // rule derivative dca/dc
101  /* Real dcadc = _second_derivative_Fb[_qp]
102  / ( (1.0 - _prop_h[_qp]) * _second_derivative_Fb[_qp]
103  + _prop_h[_qp] * _second_derivative_Fa[_qp]); */
104  // The (1-h)*X_b, h*X_a pairing is opposite to what the KKSPhaseConcentration kernel does!
105 
106  res = _second_derivative_Fa[_qp] * _grad_phi[_j][_qp];
107 
108  for (unsigned int i = 0; i < _nvar; ++i)
109  res += (*_third_derivatives_ca[i])[_qp] * (*_grad_args[i])[_qp] * _phi[_j][_qp];
110 
111  // convergence improves if we return 0.0 here
112  return 0.0; // res * dcadc;
113  }
114 
115  mooseError("Invalid type passed in");
116 }
117 
118 Real
120 {
121  // get the coupled variable jvar is referring to
122  const unsigned int cvar = mapJvarToCvar(jvar);
123 
124  RealGradient res = (*_second_derivatives[cvar])[_qp] * _grad_phi[_j][_qp];
125 
126  for (unsigned int i = 0; i < _nvar; ++i)
127  res += (*_third_derivatives[i][cvar])[_qp] * (*_grad_args[i])[_qp] * _phi[_j][_qp];
128 
129  // keeping this term seems to improve the solution.
130  return res * _grad_test[_i][_qp];
131 }
std::vector< const MaterialProperty< Real > * > _third_derivatives_ca
Derivatives of with respect to all coupled variables.
Definition: KKSCHBulk.h:58
std::vector< const MaterialProperty< Real > * > _second_derivatives
Derivatives of with respect to all coupled variables.
Definition: KKSCHBulk.h:52
const VariableName _ca_name
Definition: KKSCHBulk.h:46
This is the Cahn-Hilliard equation base class that implements the bulk or local energy term of the eq...
Definition: CHBulk.h:23
const MaterialProperty< Real > & _second_derivative_Fa
Second derivative .
Definition: KKSCHBulk.h:67
std::vector< const VariableGradient * > _grad_args
Gradients for all coupled variables.
Definition: KKSCHBulk.h:61
virtual RealGradient computeGradDFDCons(PFFunctionType type)
Note that per product and chain rules: which is: .
Definition: KKSCHBulk.C:85
InputParameters validParams< KKSCHBulk >()
Definition: KKSCHBulk.C:11
unsigned int _nvar
Number of coupled variables.
Definition: KKSCHBulk.h:41
KKSCHBulk(const InputParameters &parameters)
Definition: KKSCHBulk.C:35
static InputParameters validParams()
Definition: CHBulk.h:73
std::vector< std::vector< const MaterialProperty< Real > * > > _third_derivatives
Second derivatives of dFa/dca with respect to all coupled variables.
Definition: KKSCHBulk.h:55
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
Definition: KKSCHBulk.C:119