www.mooseframework.org
MatDiffusionBase.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 MATDIFFUSIONBASE_H
8 #define MATDIFFUSIONBASE_H
9 
10 #include "Kernel.h"
11 #include "JvarMapInterface.h"
12 #include "DerivativeMaterialInterface.h"
13 
23 template <typename T>
24 class MatDiffusionBase : public DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>
25 {
26 public:
27  MatDiffusionBase(const InputParameters & parameters);
28 
29  virtual void initialSetup();
30 
32  static InputParameters validParams();
33 
34 protected:
35  virtual Real computeQpResidual();
36  virtual Real computeQpJacobian();
37  virtual Real computeQpOffDiagJacobian(unsigned int jvar);
38  virtual Real computeQpCJacobian();
39 
41  const MaterialProperty<T> & _D;
42 
44  const MaterialProperty<T> & _dDdc;
45 
47  std::vector<const MaterialProperty<T> *> _dDdarg;
48 
50  const bool _is_coupled;
51 
53  unsigned int _conc_var;
54 
56  const VariableGradient & _grad_conc;
57 };
58 
59 template <typename T>
60 InputParameters
62 {
63  InputParameters params = ::validParams<Kernel>();
64  params.addParam<MaterialPropertyName>("D_name", "D", "The name of the diffusivity");
65  params.addCoupledVar("args", "Vector of arguments of the diffusivity");
66  params.addCoupledVar("conc",
67  "Coupled concentration variable for kernel to operate on; if this "
68  "is not specified, the kernel's nonlinear variable will be used as "
69  "usual");
70  return params;
71 }
72 
73 template <typename T>
74 MatDiffusionBase<T>::MatDiffusionBase(const InputParameters & parameters)
75  : DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>(parameters),
76  _D(getMaterialProperty<T>("D_name")),
77  _dDdc(getMaterialPropertyDerivative<T>("D_name", _var.name())),
78  _dDdarg(_coupled_moose_vars.size()),
79  _is_coupled(isCoupled("conc")),
80  _conc_var(_is_coupled ? coupled("conc") : _var.number()),
81  _grad_conc(_is_coupled ? coupledGradient("conc") : _grad_u)
82 {
83  // fetch derivatives
84  for (unsigned int i = 0; i < _dDdarg.size(); ++i)
85  _dDdarg[i] = &getMaterialPropertyDerivative<T>("D_name", _coupled_moose_vars[i]->name());
86 }
87 
88 template <typename T>
89 void
91 {
92  validateNonlinearCoupling<Real>("D_name");
93 }
94 
95 template <typename T>
96 Real
98 {
99  return _D[_qp] * _grad_conc[_qp] * _grad_test[_i][_qp];
100 }
101 
102 template <typename T>
103 Real
105 {
106  Real sum = _phi[_j][_qp] * _dDdc[_qp] * _grad_conc[_qp] * _grad_test[_i][_qp];
107  if (!_is_coupled)
108  sum += computeQpCJacobian();
109 
110  return sum;
111 }
112 
113 template <typename T>
114 Real
116 {
117  // get the coupled variable jvar is referring to
118  const unsigned int cvar = mapJvarToCvar(jvar);
119 
120  Real sum = (*_dDdarg[cvar])[_qp] * _phi[_j][_qp] * _grad_conc[_qp] * _grad_test[_i][_qp];
121  if (_conc_var == jvar)
122  sum += computeQpCJacobian();
123 
124  return sum;
125 }
126 
127 template <typename T>
128 Real
130 {
131  return _D[_qp] * _grad_phi[_j][_qp] * _grad_test[_i][_qp];
132 }
133 #endif // MATDIFFUSIONBASE_H
const MaterialProperty< T > & _D
diffusion coefficient
const MaterialProperty< T > & _dDdc
diffusion coefficient derivative w.r.t. the kernel variable
const VariableGradient & _grad_conc
Gradient of the concentration.
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
virtual Real computeQpCJacobian()
unsigned int _conc_var
int label for the Concentration
std::vector< const MaterialProperty< T > * > _dDdarg
diffusion coefficient derivatives w.r.t. coupled variables
virtual Real computeQpResidual()
MatDiffusionBase(const InputParameters &parameters)
static InputParameters validParams()
in class templates this function has to be a static member
This class template implements a diffusion kernel with a mobility that can vary spatially and can dep...
virtual Real computeQpJacobian()
const bool _is_coupled
is the kernel used in a coupled form?
virtual void initialSetup()