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