|
9 | 9 |
|
10 | 10 | #pragma once |
11 | 11 |
|
12 | | -#include "Kernel.h" |
| 12 | +#include "GenericKernelGrad.h" |
13 | 13 | #include "JvarMapInterface.h" |
14 | 14 | #include "DerivativeMaterialInterface.h" |
15 | 15 |
|
|
22 | 22 | * \tparam T Type of the diffusion coefficient parameter. This can be Real for |
23 | 23 | * isotropic diffusion or RealTensorValue for the general anisotropic case. |
24 | 24 | */ |
25 | | -template <typename T> |
26 | | -class MatDiffusionBase : public DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>> |
| 25 | +template <typename T, bool is_ad> |
| 26 | +class MatDiffusionBaseTempl |
| 27 | + : public DerivativeMaterialInterface<JvarMapKernelInterface<GenericKernelGrad<is_ad>>> |
27 | 28 | { |
28 | 29 | public: |
29 | 30 | static InputParameters validParams(); |
30 | 31 |
|
31 | | - MatDiffusionBase(const InputParameters & parameters); |
32 | | - |
33 | | - virtual void initialSetup() override; |
| 32 | + MatDiffusionBaseTempl(const InputParameters & parameters); |
34 | 33 |
|
35 | 34 | protected: |
36 | | - virtual Real computeQpResidual() override; |
37 | | - virtual Real computeQpJacobian() override; |
38 | | - virtual Real computeQpOffDiagJacobian(unsigned int jvar) override; |
39 | | - virtual Real computeQpCJacobian(); |
| 35 | + virtual GenericRealVectorValue<is_ad> precomputeQpResidual() override; |
40 | 36 |
|
41 | 37 | /// diffusion coefficient |
42 | | - const MaterialProperty<T> & _D; |
43 | | - |
44 | | - /// diffusion coefficient derivative w.r.t. the kernel variable |
45 | | - const MaterialProperty<T> & _dDdc; |
46 | | - |
47 | | - /// diffusion coefficient derivatives w.r.t. coupled variables |
48 | | - std::vector<const MaterialProperty<T> *> _dDdarg; |
49 | | - |
50 | | - /// is the kernel used in a coupled form? |
51 | | - const bool _is_coupled; |
52 | | - |
53 | | - /// int label for the Concentration |
54 | | - unsigned int _v_var; |
| 38 | + const GenericMaterialProperty<T, is_ad> & _diffusivity; |
55 | 39 |
|
56 | 40 | /// Gradient of the concentration |
57 | | - const VariableGradient & _grad_v; |
58 | | -}; |
59 | | - |
60 | | -template <typename T> |
61 | | -InputParameters |
62 | | -MatDiffusionBase<T>::validParams() |
63 | | -{ |
64 | | - InputParameters params = Kernel::validParams(); |
65 | | - params.addDeprecatedParam<MaterialPropertyName>( |
66 | | - "D_name", |
67 | | - "The name of the diffusivity", |
68 | | - "This parameter has been renamed to 'diffusivity', which is more mnemonic and more conducive " |
69 | | - "to passing a number literal"); |
70 | | - params.addParam<MaterialPropertyName>( |
71 | | - "diffusivity", "D", "The diffusivity value or material property"); |
72 | | - params.addCoupledVar("args", |
73 | | - "Optional vector of arguments for the diffusivity. If provided and " |
74 | | - "diffusivity is a derivative parsed material, Jacobian contributions from " |
75 | | - "the diffusivity will be automatically computed"); |
76 | | - params.addCoupledVar("conc", "Deprecated! Use 'v' instead"); |
77 | | - params.addCoupledVar("v", |
78 | | - "Coupled concentration variable for kernel to operate on; if this " |
79 | | - "is not specified, the kernel's nonlinear variable will be used as " |
80 | | - "usual"); |
81 | | - return params; |
82 | | -} |
83 | | - |
84 | | -template <typename T> |
85 | | -MatDiffusionBase<T>::MatDiffusionBase(const InputParameters & parameters) |
86 | | - : DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>(parameters), |
87 | | - _D(isParamValid("D_name") ? getMaterialProperty<T>("D_name") |
88 | | - : getMaterialProperty<T>("diffusivity")), |
89 | | - _dDdc(getMaterialPropertyDerivative<T>(isParamValid("D_name") ? "D_name" : "diffusivity", |
90 | | - _var.name())), |
91 | | - _dDdarg(_coupled_moose_vars.size()), |
92 | | - _is_coupled(isCoupled("v")), |
93 | | - _v_var(_is_coupled ? coupled("v") : (isCoupled("conc") ? coupled("conc") : _var.number())), |
94 | | - _grad_v(_is_coupled ? coupledGradient("v") |
95 | | - : (isCoupled("conc") ? coupledGradient("conc") : _grad_u)) |
96 | | -{ |
97 | | - // deprecated variable parameter conc |
98 | | - if (isCoupled("conc")) |
99 | | - mooseDeprecated("In '", name(), "' the parameter 'conc' is deprecated, please use 'v' instead"); |
| 41 | + const GenericVariableGradient<is_ad> & _grad_v; |
100 | 42 |
|
101 | | - // fetch derivatives |
102 | | - for (unsigned int i = 0; i < _dDdarg.size(); ++i) |
103 | | - _dDdarg[i] = &getMaterialPropertyDerivative<T>( |
104 | | - isParamValid("D_name") ? "D_name" : "diffusivity", _coupled_moose_vars[i]->name()); |
105 | | -} |
| 43 | + usingGenericKernelGradMembers; |
| 44 | +}; |
106 | 45 |
|
107 | 46 | template <typename T> |
108 | | -void |
109 | | -MatDiffusionBase<T>::initialSetup() |
| 47 | +class MatDiffusionBase : public MatDiffusionBaseTempl<T, false> |
110 | 48 | { |
111 | | - validateNonlinearCoupling<Real>(parameters().isParamSetByUser("D_name") ? "D_name" |
112 | | - : "diffusivity"); |
113 | | -} |
| 49 | +public: |
| 50 | + static InputParameters validParams(); |
114 | 51 |
|
115 | | -template <typename T> |
116 | | -Real |
117 | | -MatDiffusionBase<T>::computeQpResidual() |
118 | | -{ |
119 | | - return _D[_qp] * _grad_v[_qp] * _grad_test[_i][_qp]; |
120 | | -} |
| 52 | + MatDiffusionBase(const InputParameters & parameters); |
121 | 53 |
|
122 | | -template <typename T> |
123 | | -Real |
124 | | -MatDiffusionBase<T>::computeQpJacobian() |
125 | | -{ |
126 | | - Real sum = _phi[_j][_qp] * _dDdc[_qp] * _grad_v[_qp] * _grad_test[_i][_qp]; |
127 | | - if (!_is_coupled) |
128 | | - sum += computeQpCJacobian(); |
| 54 | + using MatDiffusionBaseTempl<T, false>::MatDiffusionBaseTempl; |
129 | 55 |
|
130 | | - return sum; |
131 | | -} |
| 56 | +protected: |
| 57 | + virtual void initialSetup() override; |
| 58 | + virtual RealGradient precomputeQpJacobian() override; |
| 59 | + virtual Real computeQpOffDiagJacobian(unsigned int jvar) override; |
| 60 | + virtual RealGradient precomputeQpCJacobian(); |
132 | 61 |
|
133 | | -template <typename T> |
134 | | -Real |
135 | | -MatDiffusionBase<T>::computeQpOffDiagJacobian(unsigned int jvar) |
136 | | -{ |
137 | | - // get the coupled variable jvar is referring to |
138 | | - const unsigned int cvar = mapJvarToCvar(jvar); |
| 62 | + /// diffusion coefficient derivative w.r.t. the kernel variable |
| 63 | + const MaterialProperty<T> & _ddiffusivity_dc; |
139 | 64 |
|
140 | | - Real sum = (*_dDdarg[cvar])[_qp] * _phi[_j][_qp] * _grad_v[_qp] * _grad_test[_i][_qp]; |
| 65 | + /// diffusion coefficient derivatives w.r.t. coupled variables |
| 66 | + std::vector<const MaterialProperty<T> *> _ddiffusivity_darg; |
141 | 67 |
|
142 | | - if (_v_var == jvar) |
143 | | - sum += computeQpCJacobian(); |
| 68 | + /// is the kernel used in a coupled form? |
| 69 | + const bool _is_coupled; |
144 | 70 |
|
145 | | - return sum; |
146 | | -} |
| 71 | + /// int label for the Concentration |
| 72 | + unsigned int _v_var; |
147 | 73 |
|
148 | | -template <typename T> |
149 | | -Real |
150 | | -MatDiffusionBase<T>::computeQpCJacobian() |
151 | | -{ |
152 | | - return _D[_qp] * _grad_phi[_j][_qp] * _grad_test[_i][_qp]; |
153 | | -} |
| 74 | + using MatDiffusionBaseTempl<T, false>::_diffusivity; |
| 75 | + using MatDiffusionBaseTempl<T, false>::_qp; |
| 76 | + using MatDiffusionBaseTempl<T, false>::_grad_phi; |
| 77 | + using MatDiffusionBaseTempl<T, false>::_j; |
| 78 | + using MatDiffusionBaseTempl<T, false>::_i; |
| 79 | + using MatDiffusionBaseTempl<T, false>::_phi; |
| 80 | + using MatDiffusionBaseTempl<T, false>::_grad_v; |
| 81 | + using MatDiffusionBaseTempl<T, false>::_grad_test; |
| 82 | + using MatDiffusionBaseTempl<T, false>::_var; |
| 83 | + using MatDiffusionBaseTempl<T, false>::_coupled_moose_vars; |
| 84 | +}; |
0 commit comments