www.mooseframework.org
MatDiffusionBase.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"
15 
25 template <typename T>
26 class MatDiffusionBase : public DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>
27 {
28 public:
30 
32 
33  virtual void initialSetup() override;
34 
35 protected:
36  virtual Real computeQpResidual() override;
37  virtual Real computeQpJacobian() override;
38  virtual Real computeQpOffDiagJacobian(unsigned int jvar) override;
39  virtual Real computeQpCJacobian();
40 
43 
46 
48  std::vector<const MaterialProperty<T> *> _dDdarg;
49 
51  const bool _is_coupled;
52 
54  unsigned int _v_var;
55 
58 };
59 
60 template <typename T>
63 {
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>
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");
100 
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 }
106 
107 template <typename T>
108 void
110 {
111  validateNonlinearCoupling<Real>(parameters().isParamSetByUser("D_name") ? "D_name"
112  : "diffusivity");
113 }
114 
115 template <typename T>
116 Real
118 {
119  return _D[_qp] * _grad_v[_qp] * _grad_test[_i][_qp];
120 }
121 
122 template <typename T>
123 Real
125 {
126  Real sum = _phi[_j][_qp] * _dDdc[_qp] * _grad_v[_qp] * _grad_test[_i][_qp];
127  if (!_is_coupled)
128  sum += computeQpCJacobian();
129 
130  return sum;
131 }
132 
133 template <typename T>
134 Real
136 {
137  // get the coupled variable jvar is referring to
138  const unsigned int cvar = mapJvarToCvar(jvar);
139 
140  Real sum = (*_dDdarg[cvar])[_qp] * _phi[_j][_qp] * _grad_v[_qp] * _grad_test[_i][_qp];
141  if (_v_var == jvar)
142  sum += computeQpCJacobian();
143 
144  return sum;
145 }
146 
147 template <typename T>
148 Real
150 {
151  return _D[_qp] * _grad_phi[_j][_qp] * _grad_test[_i][_qp];
152 }
std::string name(const ElemQuality q)
OutputTools< Real >::VariableGradient VariableGradient
Definition: MooseTypes.h:303
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:124
const MaterialProperty< T > & _D
diffusion coefficient
const MaterialProperty< T > & _dDdc
diffusion coefficient derivative w.r.t. the kernel variable
static InputParameters validParams()
Definition: Kernel.C:23
void addDeprecatedParam(const std::string &name, const T &value, const std::string &doc_string, const std::string &deprecation_message)
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
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:56
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
const VariableGradient & _grad_v
Gradient of the concentration.
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:1327
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 option parameter and a documentation string to the InputParameters object...
const bool _is_coupled
is the kernel used in a coupled form?
unsigned int _v_var
int label for the Concentration