www.mooseframework.org
SplitCHWResBase.h
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 #pragma once
11 
12 #include "Kernel.h"
13 #include "JvarMapInterface.h"
14 #include "DerivativeMaterialInterface.h"
15 
16 // Forward declarations
17 template <typename T = void>
19 
20 template <>
21 InputParameters validParams<SplitCHWResBase<>>();
22 
29 template <typename T>
30 class SplitCHWResBase : public DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>
31 {
32 public:
33  SplitCHWResBase(const InputParameters & parameters);
34 
35 protected:
36  virtual Real computeQpResidual();
37  virtual Real computeQpJacobian();
38  virtual Real computeQpWJacobian();
39  virtual Real computeQpOffDiagJacobian(unsigned int jvar);
40 
41  const MaterialPropertyName _mob_name;
42  const MaterialProperty<T> & _mob;
43 
45  const bool _is_coupled;
46 
48  unsigned int _w_var;
49 
51  const VariableGradient & _grad_w;
52 
54  std::vector<const MaterialProperty<T> *> _dmobdarg;
55 };
56 
57 template <typename T>
58 SplitCHWResBase<T>::SplitCHWResBase(const InputParameters & parameters)
59  : DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>(parameters),
60  _mob_name(getParam<MaterialPropertyName>("mob_name")),
61  _mob(getMaterialProperty<T>("mob_name")),
62  _is_coupled(isCoupled("w")),
63  _w_var(_is_coupled ? coupled("w") : _var.number()),
64  _grad_w(_is_coupled ? coupledGradient("w") : _grad_u)
65 {
66  // Get number of coupled variables
67  unsigned int nvar = _coupled_moose_vars.size();
68 
69  // reserve space for derivatives
70  _dmobdarg.resize(nvar);
71 
72  // Iterate over all coupled variables
73  for (unsigned int i = 0; i < nvar; ++i)
74  _dmobdarg[i] = &getMaterialPropertyDerivative<T>(_mob_name, _coupled_moose_vars[i]->name());
75 }
76 
77 template <typename T>
78 Real
80 {
81  return _mob[_qp] * _grad_w[_qp] * _grad_test[_i][_qp];
82 }
83 
84 template <typename T>
85 Real
87 {
88  return (_is_coupled && _w_var != _var.number()) ? 0.0 : computeQpWJacobian();
89 }
90 
91 template <typename T>
92 Real
94 {
95  return _mob[_qp] * _grad_phi[_j][_qp] * _grad_test[_i][_qp];
96 }
97 
98 template <typename T>
99 Real
101 {
102  // c Off-Diagonal Jacobian
103  if (_w_var == jvar)
104  return computeQpWJacobian();
105 
106  // get the coupled variable jvar is referring to
107  const unsigned int cvar = mapJvarToCvar(jvar);
108 
109  return (*_dmobdarg[cvar])[_qp] * _phi[_j][_qp] * _grad_w[_qp] * _grad_test[_i][_qp];
110 }
SplitCHWResBase::computeQpJacobian
virtual Real computeQpJacobian()
Definition: SplitCHWResBase.h:86
SplitCHWResBase::computeQpWJacobian
virtual Real computeQpWJacobian()
Definition: SplitCHWResBase.h:93
SplitCHWResBase::_w_var
unsigned int _w_var
int label for the chemical potential
Definition: SplitCHWResBase.h:48
SplitCHWResBase::_mob_name
const MaterialPropertyName _mob_name
Definition: SplitCHWResBase.h:41
SplitCHWResBase::computeQpOffDiagJacobian
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
Definition: SplitCHWResBase.h:100
SplitCHWResBase::SplitCHWResBase
SplitCHWResBase(const InputParameters &parameters)
Definition: SplitCHWResBase.h:58
SplitCHWResBase::_dmobdarg
std::vector< const MaterialProperty< T > * > _dmobdarg
derivatives of the mobility
Definition: SplitCHWResBase.h:54
SplitCHWResBase::_mob
const MaterialProperty< T > & _mob
Definition: SplitCHWResBase.h:42
SplitCHWResBase
SplitCHWresBase implements the residual for the chemical potential in the split form of the Cahn-Hill...
Definition: SplitCHWResBase.h:18
SplitCHWResBase::computeQpResidual
virtual Real computeQpResidual()
Definition: SplitCHWResBase.h:79
name
const std::string name
Definition: Setup.h:21
SplitCHWResBase::_is_coupled
const bool _is_coupled
is the kernel used in a coupled form?
Definition: SplitCHWResBase.h:45
SplitCHWResBase::_grad_w
const VariableGradient & _grad_w
Variable value for the chemical potential.
Definition: SplitCHWResBase.h:51