LCOV - code coverage report
Current view: top level - src/kernels - MatReaction.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 32 42 76.2 %
Date: 2026-05-29 20:35:17 Functions: 10 11 90.9 %
Legend: Lines: hit not hit

          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             : registerMooseObject("MooseApp", ADMatReaction);
      14             : 
      15             : template <bool is_ad>
      16             : InputParameters
      17        9292 : MatReactionTempl<is_ad>::validParams()
      18             : {
      19        9292 :   InputParameters params = GenericKernel<is_ad>::validParams();
      20       18584 :   params.addClassDescription("Kernel to add -L*v, where L=reaction rate, v=variable");
      21       37168 :   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       27876 :   params.addRequiredParam<MaterialPropertyName>("reaction_rate",
      25             :                                                 "The reaction rate used with the kernel");
      26        9292 :   return params;
      27           0 : }
      28             : 
      29             : template <bool is_ad>
      30          59 : MatReactionTempl<is_ad>::MatReactionTempl(const InputParameters & parameters)
      31             :   : GenericKernel<is_ad>(parameters),
      32          59 :     _rate(this->template getGenericMaterialProperty<Real, is_ad>("reaction_rate")),
      33         177 :     _v(this->isCoupled("v") ? this->template coupledGenericValue<is_ad>("v") : this->_u)
      34             : {
      35         177 :   if (this->isCoupled("v") && coupled("v") == _var.number())
      36           0 :     paramError("v", "In order to correctly couple the primal variable, leave 'v' blank");
      37          59 : }
      38             : 
      39             : template <bool is_ad>
      40             : GenericReal<is_ad>
      41     2515040 : MatReactionTempl<is_ad>::computeQpResidual()
      42             : {
      43     2515040 :   return -_rate[_qp] * _v[_qp] * _test[_i][_qp];
      44             : }
      45             : 
      46             : InputParameters
      47        6187 : MatReaction::validParams()
      48             : {
      49        6187 :   InputParameters params = MatReactionTempl<false>::validParams();
      50       18561 :   params.addCoupledVar("args", "Vector of nonlinear variable arguments this object depends on");
      51        6187 :   return params;
      52           0 : }
      53             : 
      54          36 : MatReaction::MatReaction(const InputParameters & parameters)
      55             :   : DerivativeMaterialInterface<JvarMapKernelInterface<MatReactionTempl<false>>>(parameters),
      56          36 :     _is_coupled(isCoupled("v")),
      57          36 :     _v_name(_is_coupled ? coupledName("v") : _var.name()),
      58          36 :     _v_var(_is_coupled ? coupled("v") : _var.number()),
      59         216 :     _drate_du(getMaterialPropertyDerivative<Real>("reaction_rate", _var.name())),
      60         216 :     _drate_dv(getMaterialPropertyDerivative<Real>("reaction_rate", _v_name)),
      61         108 :     _drate_darg(_n_args)
      62             : {
      63             :   // Get reaction rate derivatives
      64          36 :   for (unsigned int i = 0; i < _n_args; ++i)
      65           0 :     _drate_darg[i] = &getMaterialPropertyDerivative<Real>("reaction_rate", i);
      66          36 : }
      67             : 
      68             : void
      69          36 : MatReaction::initialSetup()
      70             : {
      71          36 :   validateNonlinearCoupling<Real>("reaction_rate");
      72          36 : }
      73             : 
      74             : Real
      75      142080 : MatReaction::computeQpJacobian()
      76             : {
      77      142080 :   if (_is_coupled)
      78           0 :     return -_drate_du[_qp] * _v[_qp] * _phi[_j][_qp] * _test[_i][_qp];
      79             : 
      80      142080 :   return -(_rate[_qp] + _drate_du[_qp] * _v[_qp]) * _phi[_j][_qp] * _test[_i][_qp];
      81             : }
      82             : 
      83             : Real
      84           0 : MatReaction::computeQpOffDiagJacobian(unsigned int jvar)
      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           0 :   if (jvar == _v_var && _is_coupled)
      90           0 :     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           0 :   const auto cvar = mapJvarToCvar(jvar);
      94             : 
      95           0 :   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>;

Generated by: LCOV version 1.14