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