https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
14
15template <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
29template <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
39template <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
68void
70{
71 validateNonlinearCoupling<Real>("reaction_rate");
72}
73
74Real
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
83Real
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
98template class MatReactionTempl<false>;
99template class MatReactionTempl<true>;
registerMooseObject("MooseApp", MatReaction)
Moose::GenericType< Real, is_ad > GenericReal
Definition MooseTypes.h:698
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:473
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:154
Interface class ("Veneer") to provide generator methods for derivative material property names.
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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...
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.
void addCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
const unsigned int _n_args
number of coupled moose variables
unsigned int mapJvarToCvar(unsigned int jvar)
Return index into the _coupled_moose_vars array for a given jvar.
Interface class ("Veneer") for Kernel to provide a mapping from 'jvar' in computeQpOffDiagJacobian in...
MooseVariable & _var
This is a regular kernel so we cast to a regular MooseVariable.
Definition Kernel.h:72
This kernel adds to the residual a contribution of where is a material property and is a variable ...
Definition MatReaction.h:22
static InputParameters validParams()
Definition MatReaction.C:17
MatReactionTempl(const InputParameters &parameters)
Definition MatReaction.C:30
virtual GenericReal< is_ad > computeQpResidual()
Compute this Kernel's contribution to the residual at the current quadrature point.
Definition MatReaction.C:41
virtual void initialSetup()
Definition MatReaction.C:69
unsigned int _v_var
Definition MatReaction.h:67
const bool _is_coupled
is the kernel used in a coupled form?
Definition MatReaction.h:59
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
Definition MatReaction.C:84
static InputParameters validParams()
Definition MatReaction.C:47
virtual Real computeQpJacobian()
Definition MatReaction.C:75
const MaterialProperty< Real > & _drate_du
Reaction rate derivative w.r.t. primal variable.
Definition MatReaction.h:70
std::vector< const MaterialProperty< Real > * > _drate_darg
Reaction rate derivatives w.r.t. other coupled variables.
Definition MatReaction.h:76
const MaterialProperty< Real > & _drate_dv
Reaction rate derivative w.r.t. the variable being added by this kernel.
Definition MatReaction.h:73
MatReaction(const InputParameters &parameters)
Definition MatReaction.C:54
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:457
unsigned int number() const
Get variable number coming from libMesh.