www.mooseframework.org
KKSPhaseChemicalPotential.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 /****************************************************************/
8 #include "MathUtils.h"
9 
10 using namespace MathUtils;
11 
12 template <>
13 InputParameters
15 {
16  InputParameters params = validParams<Kernel>();
17  params.addClassDescription("KKS model kernel to enforce the pointwise equality of phase chemical "
18  "potentials dFa/dca = dFb/dcb. The non-linear variable of this "
19  "kernel is ca.");
20  params.addRequiredCoupledVar(
21  "cb", "Phase b concentration"); // note that ca is u, the non-linear variable!
22  params.addRequiredParam<MaterialPropertyName>("fa_name",
23  "Base name of the free energy function "
24  "Fa (f_name in the corresponding "
25  "derivative function material)");
26  params.addRequiredParam<MaterialPropertyName>("fb_name",
27  "Base name of the free energy function "
28  "Fb (f_name in the corresponding "
29  "derivative function material)");
30  params.addCoupledVar(
31  "args_a",
32  "Vector of further parameters to Fa (optional, to add in second cross derivatives of Fa)");
33  params.addCoupledVar(
34  "args_b",
35  "Vector of further parameters to Fb (optional, to add in second cross derivatives of Fb)");
36  return params;
37 }
38 
39 KKSPhaseChemicalPotential::KKSPhaseChemicalPotential(const InputParameters & parameters)
40  : DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>(parameters),
41  _cb_var(coupled("cb")),
42  _cb_name(getVar("cb", 0)->name()),
43  // first derivatives
44  _dfadca(getMaterialPropertyDerivative<Real>("fa_name", _var.name())),
45  _dfbdcb(getMaterialPropertyDerivative<Real>("fb_name", _cb_name)),
46  // second derivatives d2F/dx*dca for jacobian diagonal elements
47  _d2fadca2(getMaterialPropertyDerivative<Real>("fa_name", _var.name(), _var.name())),
48  _d2fbdcbca(getMaterialPropertyDerivative<Real>("fb_name", _cb_name, _var.name()))
49 {
50  MooseVariable * arg;
51  unsigned int i;
52 
53 #ifdef DEBUG
54  _console << "KKSPhaseChemicalPotential(" << name() << ") " << _var.name() << ' ' << _cb_name
55  << '\n';
56 #endif
57 
58  unsigned int nvar = _coupled_moose_vars.size();
59  _d2fadcadarg.resize(nvar);
60  _d2fbdcbdarg.resize(nvar);
61 
62  for (i = 0; i < nvar; ++i)
63  {
64  // get the moose variable
65  arg = _coupled_moose_vars[i];
66 
67  // lookup table for the material properties representing the derivatives needed for the
68  // off-diagonal jacobian
69  _d2fadcadarg[i] = &getMaterialPropertyDerivative<Real>("fa_name", _var.name(), arg->name());
70  _d2fbdcbdarg[i] = &getMaterialPropertyDerivative<Real>("fb_name", _cb_name, arg->name());
71  }
72 }
73 
74 void
76 {
77  validateNonlinearCoupling<Real>("fa_name");
78  validateNonlinearCoupling<Real>("fb_name");
79 }
80 
81 Real
83 {
84  // enforce _dfadca==_dfbdcb
85  return _test[_i][_qp] * (_dfadca[_qp] - _dfbdcb[_qp]);
86 }
87 
88 Real
90 {
91  // for on diagonal we return the d/dca derivative of the residual
92  return _test[_i][_qp] * _phi[_j][_qp] * (_d2fadca2[_qp] - _d2fbdcbca[_qp]);
93 }
94 
95 Real
97 {
98  // get the coupled variable jvar is referring to
99  const unsigned int cvar = mapJvarToCvar(jvar);
100 
101  return _test[_i][_qp] * _phi[_j][_qp] * ((*_d2fadcadarg[cvar])[_qp] - (*_d2fbdcbdarg[cvar])[_qp]);
102 }
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
const MaterialProperty< Real > & _dfadca
material properties we need to access
InputParameters validParams< KKSPhaseChemicalPotential >()
std::vector< const MaterialProperty< Real > * > _d2fbdcbdarg
const MaterialProperty< Real > & _d2fbdcbca
const MaterialProperty< Real > & _d2fadca2
std::vector< const MaterialProperty< Real > * > _d2fadcadarg
const MaterialProperty< Real > & _dfbdcb
KKSPhaseChemicalPotential(const InputParameters &parameters)