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