https://mooseframework.inl.gov
MatReaction.C
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 #include "MatReaction.h"
11 
12 registerMooseObject("MooseApp", MatReaction);
14 
15 template <bool is_ad>
18 {
20  params.addClassDescription("Kernel to add -L*v, where L=reaction rate, v=variable");
21  params.addCoupledVar("v",
22  "Set this to make v a coupled variable, otherwise it will use the "
23  "kernel's nonlinear variable for v");
24  params.addRequiredParam<MaterialPropertyName>("reaction_rate",
25  "The reaction rate used with the kernel");
26  return params;
27 }
28 
29 template <bool is_ad>
31  : GenericKernel<is_ad>(parameters),
32  _rate(this->template getGenericMaterialProperty<Real, is_ad>("reaction_rate")),
33  _v(this->isCoupled("v") ? this->template coupledGenericValue<is_ad>("v") : this->_u)
34 {
35  if (this->isCoupled("v") && coupled("v") == _var.number())
36  paramError("v", "In order to correctly couple the primal variable, leave 'v' blank");
37 }
38 
39 template <bool is_ad>
42 {
43  return -_rate[_qp] * _v[_qp] * _test[_i][_qp];
44 }
45 
48 {
50  params.addCoupledVar("args", "Vector of nonlinear variable arguments this object depends on");
51  return params;
52 }
53 
56  _is_coupled(isCoupled("v")),
57  _v_name(_is_coupled ? coupledName("v") : _var.name()),
58  _v_var(_is_coupled ? coupled("v") : _var.number()),
59  _drate_du(getMaterialPropertyDerivative<Real>("reaction_rate", _var.name())),
60  _drate_dv(getMaterialPropertyDerivative<Real>("reaction_rate", _v_name)),
61  _drate_darg(_n_args)
62 {
63  // Get reaction rate derivatives
64  for (unsigned int i = 0; i < _n_args; ++i)
65  _drate_darg[i] = &getMaterialPropertyDerivative<Real>("reaction_rate", i);
66 }
67 
68 void
70 {
71  validateNonlinearCoupling<Real>("reaction_rate");
72 }
73 
74 Real
76 {
77  if (_is_coupled)
78  return -_drate_du[_qp] * _v[_qp] * _phi[_j][_qp] * _test[_i][_qp];
79 
80  return -(_rate[_qp] + _drate_du[_qp] * _v[_qp]) * _phi[_j][_qp] * _test[_i][_qp];
81 }
82 
83 Real
85 {
86  // first handle the case where jvar is a coupled variable v being added to residual
87  // the first term in the sum just multiplies by L which is always needed
88  // the second term accounts for cases where L depends on v
89  if (jvar == _v_var && _is_coupled)
90  return -(_rate[_qp] + _drate_dv[_qp] * _v[_qp]) * _test[_i][_qp] * _phi[_j][_qp];
91 
92  // for all other vars get the coupled variable jvar is referring to
93  const auto cvar = mapJvarToCvar(jvar);
94 
95  return -(*_drate_darg[cvar])[_qp] * _v[_qp] * _test[_i][_qp] * _phi[_j][_qp];
96 }
97 
98 template class MatReactionTempl<false>;
99 template class MatReactionTempl<true>;
std::string name(const ElemQuality q)
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:159
const MaterialProperty< Real > & _drate_dv
Reaction rate derivative w.r.t. the variable being added by this kernel.
Definition: MatReaction.h:73
Moose::GenericType< Real, is_ad > GenericReal
Definition: MooseTypes.h:693
virtual unsigned int coupled(const std::string &var_name, unsigned int comp=0) const
Returns the index for a coupled variable by name.
Definition: Coupleable.C:478
virtual GenericReal< is_ad > computeQpResidual()
Compute this Kernel&#39;s contribution to the residual at the current quadrature point.
Definition: MatReaction.C:41
MooseVariable & _var
This is a regular kernel so we cast to a regular MooseVariable.
Definition: Kernel.h:72
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseBase.h:467
MatReactionTempl(const InputParameters &parameters)
Definition: MatReaction.C:30
unsigned int number() const
Get variable number coming from libMesh.
static InputParameters validParams()
Definition: MatReaction.C:47
static InputParameters validParams()
Definition: GenericKernel.h:19
virtual void initialSetup()
Gets called at the beginning of the simulation before this object is asked to do its job...
Definition: MatReaction.C:69
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Interface class ("Veneer") for Kernel to provide a mapping from &#39;jvar&#39; in computeQpOffDiagJacobian in...
MatReaction(const InputParameters &parameters)
Definition: MatReaction.C:54
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
unsigned int _v_var
Definition: MatReaction.h:67
const VariableTestValue & _test
the current test function
Definition: Kernel.h:75
std::vector< const MaterialProperty< Real > * > _drate_darg
Reaction rate derivatives w.r.t. other coupled variables.
Definition: MatReaction.h:76
unsigned int _i
current index for the test function
Definition: KernelBase.h:58
unsigned int mapJvarToCvar(unsigned int jvar)
Return index into the _coupled_moose_vars array for a given jvar.
const MaterialProperty< Real > & _drate_du
Reaction rate derivative w.r.t. primal variable.
Definition: MatReaction.h:70
void addCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
unsigned int _j
current index for the shape function
Definition: KernelBase.h:61
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
For coupling standard variables.
Definition: MatReaction.C:84
const bool _is_coupled
is the kernel used in a coupled form?
Definition: MatReaction.h:59
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Interface class ("Veneer") to provide generator methods for derivative material property names...
const GenericVariableValue< is_ad > & _v
Kernel variable (can be nonlinear or coupled variable) (For constrained Allen-Cahn problems...
Definition: MatReaction.h:39
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
This kernel adds to the residual a contribution of where is a material property and is a variable ...
Definition: MatReaction.h:21
const unsigned int _n_args
number of coupled moose variables
const VariablePhiValue & _phi
the current shape functions
Definition: Kernel.h:81
registerMooseObject("MooseApp", MatReaction)
const GenericMaterialProperty< Real, is_ad > & _rate
Reaction rate.
Definition: MatReaction.h:32
static InputParameters validParams()
Definition: MatReaction.C:17
unsigned int _qp
The current quadrature point index.
Definition: KernelBase.h:43
virtual Real computeQpJacobian()
Compute this Kernel&#39;s contribution to the Jacobian at the current quadrature point.
Definition: MatReaction.C:75