www.mooseframework.org
CHInterfaceBase.h
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 #ifndef CHINTERFACEBASE_H
8 #define CHINTERFACEBASE_H
9 
10 #include "Kernel.h"
11 #include "Material.h"
12 #include "JvarMapInterface.h"
14 
20 template <typename T>
21 class CHInterfaceBase : public DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>
22 {
23 public:
24  CHInterfaceBase(const InputParameters & parameters);
25 
26  static InputParameters validParams();
27 
28 protected:
29  virtual Real computeQpResidual();
30  virtual Real computeQpJacobian();
31  virtual Real computeQpOffDiagJacobian(unsigned int jvar);
32 
33  const MaterialProperty<Real> & _kappa;
34 
37  const MaterialProperty<T> & _M;
38  const MaterialProperty<T> & _dMdc;
39  const MaterialProperty<T> & _d2Mdc2;
41 
44  const VariableSecond & _second_u;
45  const VariableTestSecond & _second_test;
46  const VariablePhiSecond & _second_phi;
48 
50  unsigned int _nvar;
51 
54  std::vector<const MaterialProperty<T> *> _dMdarg;
55  std::vector<const MaterialProperty<T> *> _d2Mdcdarg;
56  std::vector<std::vector<const MaterialProperty<T> *>> _d2Mdargdarg;
58 
60  std::vector<const VariableGradient *> _coupled_grad_vars;
61 };
62 
63 template <typename T>
64 CHInterfaceBase<T>::CHInterfaceBase(const InputParameters & parameters)
65  : DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>(parameters),
66  _kappa(getMaterialProperty<Real>("kappa_name")),
67  _M(getMaterialProperty<T>("mob_name")),
68  _dMdc(getMaterialPropertyDerivative<T>("mob_name", _var.name())),
69  _d2Mdc2(getMaterialPropertyDerivative<T>("mob_name", _var.name(), _var.name())),
70  _second_u(second()),
71  _second_test(secondTest()),
72  _second_phi(secondPhi()),
73  _nvar(_coupled_moose_vars.size()),
74  _dMdarg(_nvar),
78 {
79  // Iterate over all coupled variables
80  for (unsigned int i = 0; i < _nvar; ++i)
81  {
82  // Set material property values
83  _dMdarg[i] = &getMaterialPropertyDerivative<T>("mob_name", _coupled_moose_vars[i]->name());
84  _d2Mdcdarg[i] =
85  &getMaterialPropertyDerivative<T>("mob_name", _var.name(), _coupled_moose_vars[i]->name());
86  _d2Mdargdarg[i].resize(_nvar);
87  for (unsigned int j = 0; j < _nvar; ++j)
88  _d2Mdargdarg[i][j] = &getMaterialPropertyDerivative<T>(
89  "mob_name", _coupled_moose_vars[i]->name(), _coupled_moose_vars[j]->name());
90 
91  // Set coupled variable gradients
92  _coupled_grad_vars[i] = &coupledGradient("args", i);
93  }
94 }
95 
96 template <typename T>
97 InputParameters
99 {
100  InputParameters params = ::validParams<Kernel>();
101  params.addClassDescription("Gradient energy Cahn-Hilliard base Kernel");
102  params.addRequiredParam<MaterialPropertyName>("kappa_name", "The kappa used with the kernel");
103  params.addRequiredParam<MaterialPropertyName>("mob_name", "The mobility used with the kernel");
104  params.addCoupledVar("args", "Vector of arguments of the mobility");
105  return params;
106 }
107 
108 template <typename T>
109 Real
111 {
112  RealGradient grad_M = _dMdc[_qp] * _grad_u[_qp];
113  for (unsigned int i = 0; i < _nvar; ++i)
114  grad_M += (*_dMdarg[i])[_qp] * (*_coupled_grad_vars[i])[_qp];
115 
116  return _kappa[_qp] * _second_u[_qp].tr() *
117  ((_M[_qp] * _second_test[_i][_qp]).tr() + grad_M * _grad_test[_i][_qp]);
118 }
119 
120 template <typename T>
121 Real
123 {
124  // Set the gradient and gradient derivative values
125  RealGradient grad_M = _dMdc[_qp] * _grad_u[_qp];
126 
127  RealGradient dgrad_Mdc =
128  _d2Mdc2[_qp] * _phi[_j][_qp] * _grad_u[_qp] + _dMdc[_qp] * _grad_phi[_j][_qp];
129 
130  for (unsigned int i = 0; i < _nvar; ++i)
131  {
132  grad_M += (*_dMdarg[i])[_qp] * (*_coupled_grad_vars[i])[_qp];
133  dgrad_Mdc += (*_d2Mdcdarg[i])[_qp] * _phi[_j][_qp] * (*_coupled_grad_vars[i])[_qp];
134  }
135 
136  // Jacobian value using product rule
137  Real value = _kappa[_qp] * _second_phi[_j][_qp].tr() *
138  ((_M[_qp] * _second_test[_i][_qp]).tr() + grad_M * _grad_test[_i][_qp]) +
139  _kappa[_qp] * _second_u[_qp].tr() *
140  ((_dMdc[_qp] * _second_test[_i][_qp]).tr() * _phi[_j][_qp] +
141  dgrad_Mdc * _grad_test[_i][_qp]);
142 
143  return value;
144 }
145 
146 template <typename T>
147 Real
149 {
150  // get the coupled variable jvar is referring to
151  const unsigned int cvar = mapJvarToCvar(jvar);
152 
153  // Set the gradient derivative
154  RealGradient dgrad_Mdarg = (*_d2Mdcdarg[cvar])[_qp] * _phi[_j][_qp] * _grad_u[_qp] +
155  (*_dMdarg[cvar])[_qp] * _grad_phi[_j][_qp];
156 
157  for (unsigned int i = 0; i < _nvar; ++i)
158  dgrad_Mdarg += (*_d2Mdargdarg[cvar][i])[_qp] * _phi[_j][_qp] * (*_coupled_grad_vars[cvar])[_qp];
159 
160  // Jacobian value using product rule
161  Real value = _kappa[_qp] * _second_u[_qp].tr() *
162  (((*_dMdarg[cvar])[_qp] * _second_test[_i][_qp]).tr() * _phi[_j][_qp] +
163  dgrad_Mdarg * _grad_test[_i][_qp]);
164 
165  return value;
166 }
167 
168 #endif // CHINTERFACE_H
const VariablePhiSecond & _second_phi
unsigned int _nvar
Number of variables.
This is the Cahn-Hilliard equation base class that implements the interfacial or gradient energy term...
static InputParameters validParams()
virtual Real computeQpJacobian()
std::vector< const VariableGradient * > _coupled_grad_vars
Coupled variables used in mobility.
virtual Real computeQpResidual()
const MaterialProperty< T > & _d2Mdc2
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
std::vector< const MaterialProperty< T > * > _dMdarg
const VariableTestSecond & _second_test
const MaterialProperty< T > & _M
const VariableSecond & _second_u
const MaterialProperty< Real > & _kappa
CHInterfaceBase(const InputParameters &parameters)
std::vector< const MaterialProperty< T > * > _d2Mdcdarg
std::vector< std::vector< const MaterialProperty< T > * > > _d2Mdargdarg
const MaterialProperty< T > & _dMdc