Line data Source code
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); 13 : 14 : InputParameters 15 28607 : MatReaction::validParams() 16 : { 17 28607 : InputParameters params = Kernel::validParams(); 18 28607 : params.addCoupledVar("v", 19 : "Set this to make v a coupled variable, otherwise it will use the " 20 : "kernel's nonlinear variable for v"); 21 28607 : params.addClassDescription("Kernel to add -L*v, where L=reaction rate, v=variable"); 22 28607 : params.addRequiredParam<MaterialPropertyName>("mob_name", 23 : "The reaction rate used with the kernel"); 24 28607 : params.deprecateParam("mob_name", "reaction_rate", "01/01/2025"); 25 28607 : params.addCoupledVar("args", "Vector of nonlinear variable arguments this object depends on"); 26 28607 : return params; 27 0 : } 28 : 29 40 : MatReaction::MatReaction(const InputParameters & parameters) 30 : : DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>(parameters), 31 40 : _is_coupled(isCoupled("v")), 32 40 : _v_name(_is_coupled ? coupledName("v") : _var.name()), 33 40 : _v(_is_coupled ? coupledValue("v") : _u), 34 40 : _v_var(_is_coupled ? coupled("v") : _var.number()), 35 40 : _L(getMaterialProperty<Real>("reaction_rate")), 36 40 : _eta_name(_var.name()), 37 40 : _dLdop(getMaterialPropertyDerivative<Real>("reaction_rate", _eta_name)), 38 40 : _dLdv(getMaterialPropertyDerivative<Real>("reaction_rate", _v_name)), 39 80 : _dLdarg(_n_args) 40 : { 41 : // Get reaction rate derivatives 42 40 : for (unsigned int i = 0; i < _n_args; ++i) 43 0 : _dLdarg[i] = &getMaterialPropertyDerivative<Real>("reaction_rate", i); 44 40 : } 45 : 46 : void 47 40 : MatReaction::initialSetup() 48 : { 49 40 : validateNonlinearCoupling<Real>("reaction_rate"); 50 40 : } 51 : 52 : Real 53 124240 : MatReaction::computeQpResidual() 54 : { 55 124240 : return -_L[_qp] * _test[_i][_qp] * _v[_qp]; 56 : } 57 : 58 : Real 59 97760 : MatReaction::computeQpJacobian() 60 : { 61 97760 : if (_is_coupled) 62 0 : return -_dLdop[_qp] * _v[_qp] * _phi[_j][_qp] * _test[_i][_qp]; 63 : 64 97760 : return -(_L[_qp] + _dLdop[_qp] * _v[_qp]) * _phi[_j][_qp] * _test[_i][_qp]; 65 : } 66 : 67 : Real 68 0 : MatReaction::computeQpOffDiagJacobian(unsigned int jvar) 69 : { 70 : // first handle the case where jvar is a coupled variable v being added to residual 71 : // the first term in the sum just multiplies by L which is always needed 72 : // the second term accounts for cases where L depends on v 73 0 : if ((jvar == _v_var) && _is_coupled) 74 0 : return -(_L[_qp] + _dLdv[_qp] * _v[_qp]) * _test[_i][_qp] * _phi[_j][_qp]; 75 : 76 : // for all other vars get the coupled variable jvar is referring to 77 0 : const unsigned int cvar = mapJvarToCvar(jvar); 78 : 79 0 : return -(*_dLdarg[cvar])[_qp] * _v[_qp] * _test[_i][_qp] * _phi[_j][_qp]; 80 : }