LCOV - code coverage report
Current view: top level - src/kernels - MatReaction.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #31706 (f8ed4a) with base bb0a08 Lines: 27 35 77.1 %
Date: 2025-11-03 17:23:24 Functions: 5 6 83.3 %
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             : 
      14             : InputParameters
      15       29811 : MatReaction::validParams()
      16             : {
      17       29811 :   InputParameters params = Kernel::validParams();
      18      119244 :   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       59622 :   params.addClassDescription("Kernel to add -L*v, where L=reaction rate, v=variable");
      22      119244 :   params.addRequiredParam<MaterialPropertyName>("reaction_rate",
      23             :                                                 "The reaction rate used with the kernel");
      24       89433 :   params.addCoupledVar("args", "Vector of nonlinear variable arguments this object depends on");
      25       29811 :   return params;
      26           0 : }
      27             : 
      28          41 : MatReaction::MatReaction(const InputParameters & parameters)
      29             :   : DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>(parameters),
      30          41 :     _is_coupled(isCoupled("v")),
      31          41 :     _v_name(_is_coupled ? coupledName("v") : _var.name()),
      32          41 :     _v(_is_coupled ? coupledValue("v") : _u),
      33          41 :     _v_var(_is_coupled ? coupled("v") : _var.number()),
      34          82 :     _L(getMaterialProperty<Real>("reaction_rate")),
      35          41 :     _eta_name(_var.name()),
      36         246 :     _dLdop(getMaterialPropertyDerivative<Real>("reaction_rate", _eta_name)),
      37         246 :     _dLdv(getMaterialPropertyDerivative<Real>("reaction_rate", _v_name)),
      38         123 :     _dLdarg(_n_args)
      39             : {
      40             :   // Get reaction rate derivatives
      41          41 :   for (unsigned int i = 0; i < _n_args; ++i)
      42           0 :     _dLdarg[i] = &getMaterialPropertyDerivative<Real>("reaction_rate", i);
      43          41 : }
      44             : 
      45             : void
      46          41 : MatReaction::initialSetup()
      47             : {
      48          41 :   validateNonlinearCoupling<Real>("reaction_rate");
      49          41 : }
      50             : 
      51             : Real
      52      123360 : MatReaction::computeQpResidual()
      53             : {
      54      123360 :   return -_L[_qp] * _test[_i][_qp] * _v[_qp];
      55             : }
      56             : 
      57             : Real
      58       97440 : MatReaction::computeQpJacobian()
      59             : {
      60       97440 :   if (_is_coupled)
      61           0 :     return -_dLdop[_qp] * _v[_qp] * _phi[_j][_qp] * _test[_i][_qp];
      62             : 
      63       97440 :   return -(_L[_qp] + _dLdop[_qp] * _v[_qp]) * _phi[_j][_qp] * _test[_i][_qp];
      64             : }
      65             : 
      66             : Real
      67           0 : MatReaction::computeQpOffDiagJacobian(unsigned int jvar)
      68             : {
      69             :   // first handle the case where jvar is a coupled variable v being added to residual
      70             :   // the first term in the sum just multiplies by L which is always needed
      71             :   // the second term accounts for cases where L depends on v
      72           0 :   if ((jvar == _v_var) && _is_coupled)
      73           0 :     return -(_L[_qp] + _dLdv[_qp] * _v[_qp]) * _test[_i][_qp] * _phi[_j][_qp];
      74             : 
      75             :   //  for all other vars get the coupled variable jvar is referring to
      76           0 :   const unsigned int cvar = mapJvarToCvar(jvar);
      77             : 
      78           0 :   return -(*_dLdarg[cvar])[_qp] * _v[_qp] * _test[_i][_qp] * _phi[_j][_qp];
      79             : }

Generated by: LCOV version 1.14