https://mooseframework.inl.gov
MatDiffusionBase.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
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"
15 #include "RankThreeTensor.h"
16 
17 template <typename T>
18 struct GradientType;
19 
20 template <>
22 {
24 };
25 
31 template <>
33 {
35 };
36 
46 template <typename T>
47 class MatDiffusionBase : public DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>
48 {
49 public:
51 
53 
54  virtual void initialSetup() override;
55 
56 protected:
57  virtual Real computeQpResidual() override;
58  virtual Real computeQpJacobian() override;
59  virtual Real computeQpOffDiagJacobian(unsigned int jvar) override;
60  virtual Real computeQpCJacobian();
61 
64 
67 
69  std::vector<const MaterialProperty<T> *> _dDdarg;
70 
73 
75  const bool _is_coupled;
76 
78  unsigned int _v_var;
79 
82 
84  unsigned int _surface_op_var;
85 };
86 
87 template <typename T>
90 {
92  params.addDeprecatedParam<MaterialPropertyName>(
93  "D_name",
94  "The name of the diffusivity",
95  "This parameter has been renamed to 'diffusivity', which is more mnemonic and more conducive "
96  "to passing a number literal");
97  params.addParam<MaterialPropertyName>(
98  "diffusivity", "D", "The diffusivity value or material property");
99  params.addCoupledVar("args",
100  "Optional vector of arguments for the diffusivity. If provided and "
101  "diffusivity is a derivative parsed material, Jacobian contributions from "
102  "the diffusivity will be automatically computed");
103  params.addCoupledVar("conc", "Deprecated! Use 'v' instead");
104  params.addCoupledVar("v",
105  "Coupled concentration variable for kernel to operate on; if this "
106  "is not specified, the kernel's nonlinear variable will be used as "
107  "usual");
108  params.addCoupledVar(
109  "surface_op_var",
110  "Name of the order parameter for solid-pore surface. For use when diffusivity "
111  "depends on these OP gradients, leave this parameter un-set otherwise. ");
112  return params;
113 }
114 
115 template <typename T>
118  _D(isParamValid("D_name") ? getMaterialProperty<T>("D_name")
119  : getMaterialProperty<T>("diffusivity")),
120  _dDdc(getMaterialPropertyDerivative<T>(isParamValid("D_name") ? "D_name" : "diffusivity",
121  _var.name())),
122  _dDdarg(_coupled_moose_vars.size()),
123  _dDdgradc(getMaterialPropertyDerivative<typename GradientType<T>::type>(
124  isParamValid("D_name") ? "D_name" : "diffusivity", "gradc")),
125  _is_coupled(isCoupled("v")),
126  _v_var(_is_coupled ? coupled("v") : (isCoupled("conc") ? coupled("conc") : _var.number())),
127  _grad_v(_is_coupled ? coupledGradient("v")
128  : (isCoupled("conc") ? coupledGradient("conc") : _grad_u)),
129  _surface_op_var(isCoupled("surface_op_var") ? coupled("surface_op_var") : libMesh::invalid_uint)
130 {
131  // deprecated variable parameter conc
132  if (isCoupled("conc"))
133  mooseDeprecated("In '", name(), "' the parameter 'conc' is deprecated, please use 'v' instead");
134 
135  // fetch derivatives
136  for (unsigned int i = 0; i < _dDdarg.size(); ++i)
137  _dDdarg[i] = &getMaterialPropertyDerivative<T>(
138  isParamValid("D_name") ? "D_name" : "diffusivity", _coupled_moose_vars[i]->name());
139 }
140 
141 template <typename T>
142 void
144 {
145  validateNonlinearCoupling<Real>(parameters().isParamSetByUser("D_name") ? "D_name"
146  : "diffusivity");
147 }
148 
149 template <typename T>
150 Real
152 {
153  return _D[_qp] * _grad_v[_qp] * _grad_test[_i][_qp];
154 }
155 
156 template <typename T>
157 Real
159 {
160  Real sum = _phi[_j][_qp] * _dDdc[_qp] * _grad_v[_qp] * _grad_test[_i][_qp];
161  if (!_is_coupled)
162  sum += computeQpCJacobian();
163 
164  return sum;
165 }
166 
167 template <typename T>
168 Real
170 {
171  // get the coupled variable jvar is referring to
172  const unsigned int cvar = mapJvarToCvar(jvar);
173 
174  Real sum = (*_dDdarg[cvar])[_qp] * _phi[_j][_qp] * _grad_v[_qp] * _grad_test[_i][_qp];
175  if (jvar == _surface_op_var)
176  sum += _dDdgradc[_qp] * _grad_phi[_j][_qp] * _grad_v[_qp] * _grad_test[_i][_qp];
177 
178  if (_v_var == jvar)
179  sum += computeQpCJacobian();
180 
181  return sum;
182 }
183 
184 template <typename T>
185 Real
187 {
188  return _D[_qp] * _grad_phi[_j][_qp] * _grad_test[_i][_qp];
189 }
std::string name(const ElemQuality q)
OutputTools< Real >::VariableGradient VariableGradient
Definition: MooseTypes.h:315
virtual bool isCoupled(const std::string &var_name, unsigned int i=0) const
Returns true if a variables has been coupled as name.
Definition: Coupleable.C:129
const MaterialProperty< T > & _D
diffusion coefficient
const MaterialProperty< T > & _dDdc
diffusion coefficient derivative w.r.t. the kernel variable
const MaterialProperty< typename GradientType< T >::type > & _dDdgradc
diffusion coefficient derivatives w.r.t. variables that have explicit dependence on gradients ...
static InputParameters validParams()
Definition: Kernel.C:24
void addDeprecatedParam(const std::string &name, const T &value, const std::string &doc_string, const std::string &deprecation_message)
const unsigned int invalid_uint
void mooseDeprecated(Args &&... args) const
virtual Real computeQpJacobian() override
Compute this Kernel&#39;s contribution to the Jacobian at the current quadrature point.
virtual Real computeQpCJacobian()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::vector< const MaterialProperty< T > * > _dDdarg
diffusion coefficient derivatives w.r.t. coupled variables
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
Interface class ("Veneer") for Kernel to provide a mapping from &#39;jvar&#39; in computeQpOffDiagJacobian in...
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:57
RankThreeTensor is designed to handle any N-dimensional third order tensor, r.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
const VariableGradient & _grad_v
Gradient of the concentration.
TensorValue< Real > RealTensorValue
virtual Real computeQpResidual() override
Compute this Kernel&#39;s contribution to the residual at the current quadrature point.
MatDiffusionBase(const InputParameters &parameters)
virtual Real computeQpOffDiagJacobian(unsigned int jvar) override
For coupling standard variables.
static InputParameters validParams()
This class template implements a diffusion kernel with a mobility that can vary spatially and can dep...
virtual void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job...
void addCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
std::vector< MooseVariableFieldBase * > _coupled_moose_vars
Vector of all coupled variables.
Definition: Coupleable.h:1412
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Interface class ("Veneer") to provide generator methods for derivative material property names...
Definition: Kernel.h:15
const InputParameters & parameters() const
Get the parameters of the object.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
RealVectorValue type
unsigned int _surface_op_var
For solid-pore systems, mame of the order parameter identifies the solid-pore surface.
const bool _is_coupled
is the kernel used in a coupled form?
unsigned int _v_var
int label for the Concentration