LCOV - code coverage report
Current view: top level - include/kernels - KernelScalarBase.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: fef103 Lines: 6 9 66.7 %
Date: 2025-09-03 20:01:23 Functions: 5 8 62.5 %
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             : #pragma once
      11             : 
      12             : #include "Kernel.h"
      13             : 
      14             : /**
      15             :  * This Kernel adds standardized methods for assembling to a primary
      16             :  * scalar variable associated with the primary variable of the Kernel
      17             :  * object. Essentially, the entire row of the residual and Jacobian
      18             :  * associated with this scalar variable will also be assembled here
      19             :  * using the loops over volumetric elements.
      20             :  * This variable is "scalar_variable" in the input file and "kappa"
      21             :  * within the source code.
      22             :  */
      23             : class KernelScalarBase : public Kernel
      24             : {
      25             : public:
      26             :   static InputParameters validParams();
      27             : 
      28             :   KernelScalarBase(const InputParameters & parameters);
      29             : 
      30             :   /**
      31             :    * The scalar variable that this kernel operates on.
      32             :    */
      33             :   const MooseVariableScalar & scalarVariable() const
      34             :   {
      35             :     mooseAssert(_kappa_var_ptr, "kappa pointer should have been set in the constructor");
      36             :     return *_kappa_var_ptr;
      37             :   }
      38             : 
      39             :   virtual void computeResidual() override;
      40             :   virtual void computeJacobian() override;
      41             :   /**
      42             :    * Computes d-_var-residual / d-jvar as well as d-_kappa-residual / d-jvar
      43             :    */
      44             :   virtual void computeOffDiagJacobian(unsigned int jvar_num) override;
      45             :   /**
      46             :    * Computes jacobian block with respect to a scalar variable
      47             :    * @param svar_num, the number of the (other) scalar variable
      48             :    */
      49             :   void computeOffDiagJacobianScalar(unsigned int svar_num) override;
      50             : 
      51             :   /// Compute the residual and Jacobian together
      52             :   virtual void computeResidualAndJacobian() override;
      53             : 
      54             : protected:
      55             :   /**
      56             :    * Precalculate method that is executed prior to scalar coupled variable loop
      57             :    * within computeOffDiagJacobianScalar; analogous to precalculateResidual(),
      58             :    * precalculateJacobian(), and precalculateOffDiagJacobian().
      59             :    */
      60          72 :   virtual void precalculateOffDiagJacobianScalar(unsigned int /* svar_num */) {}
      61             : 
      62             :   /**
      63             :    * Method for computing the scalar part of residual
      64             :    */
      65             :   virtual void computeScalarResidual();
      66             : 
      67             :   /**
      68             :    * Method for computing the scalar part of residual at quadrature points
      69             :    */
      70             :   virtual Real computeScalarQpResidual();
      71             : 
      72             :   /**
      73             :    * Method for computing the scalar variable part of Jacobian
      74             :    */
      75             :   virtual void computeScalarJacobian();
      76             : 
      77             :   /**
      78             :    * Method for computing the scalar variable part of Jacobian at
      79             :    * quadrature points
      80             :    */
      81           0 :   virtual Real computeScalarQpJacobian() { return 0; }
      82             : 
      83             :   /**
      84             :    * Method for computing an off-diagonal jacobian component d-_kappa-residual / d-jvar
      85             :    */
      86             :   virtual void computeScalarOffDiagJacobian(const unsigned int jvar_num);
      87             : 
      88             :   /**
      89             :    * Method for computing an off-diagonal jacobian component at quadrature points.
      90             :    */
      91           0 :   virtual Real computeScalarQpOffDiagJacobian(const unsigned int /*jvar_num*/) { return 0; }
      92             : 
      93             :   /**
      94             :    * Method for computing an off-diagonal jacobian component d-_var-residual / d-scalar
      95             :    * Revised version of Kernel::computeOffDiagJacobianScalar
      96             :    */
      97             :   virtual void computeOffDiagJacobianScalarLocal(const unsigned int svar_num);
      98             : 
      99             :   /**
     100             :    * Method for computing an off-diagonal jacobian component d-_kappa-residual / d-scalar
     101             :    */
     102             :   virtual void computeScalarOffDiagJacobianScalar(const unsigned int svar_num);
     103             : 
     104             :   /**
     105             :    * Method for computing an off-diagonal jacobian component at quadrature points.
     106             :    */
     107           0 :   virtual Real computeScalarQpOffDiagJacobianScalar(const unsigned int /*svar_num*/) { return 0; }
     108             : 
     109             :   /**
     110             :    * Put necessary evaluations depending on qp but independent of test functions here
     111             :    */
     112        1301 :   virtual void initScalarQpResidual() {}
     113             : 
     114             :   /**
     115             :    * Put necessary evaluations depending on qp but independent of test and shape functions here
     116             :    */
     117        1296 :   virtual void initScalarQpJacobian(const unsigned int /*svar_num*/) {}
     118             : 
     119             :   /**
     120             :    * Put necessary evaluations depending on qp but independent of test and shape functions here for
     121             :    * off-diagonal Jacobian assembly
     122             :    */
     123         648 :   virtual void initScalarQpOffDiagJacobian(const MooseVariableFEBase &) {}
     124             : 
     125             :   /// Whether a scalar variable is declared for this kernel
     126             :   const bool _use_scalar;
     127             : 
     128             :   /// Whether to compute scalar contributions for this instance
     129             :   const bool _compute_scalar_residuals;
     130             : 
     131             :   /// Whether to compute field contributions for this instance
     132             :   const bool _compute_field_residuals;
     133             : 
     134             :   /// (Pointer to) Scalar variable this kernel operates on
     135             :   const MooseVariableScalar * const _kappa_var_ptr;
     136             : 
     137             :   /// The unknown scalar variable ID
     138             :   const unsigned int _kappa_var;
     139             : 
     140             :   /// Order of the scalar variable, used in several places
     141             :   const unsigned int _k_order;
     142             : 
     143             :   /// Reference to the current solution at the current quadrature point
     144             :   const VariableValue & _kappa;
     145             : 
     146             :   /// Used internally to iterate over each scalar component
     147             :   unsigned int _h;
     148             :   unsigned int _l;
     149             : };
     150             : 
     151             : inline Real
     152           5 : KernelScalarBase::computeScalarQpResidual()
     153             : {
     154           5 :   mooseError(
     155             :       "A scalar_variable has been set and compute_scalar_residuals=true, ",
     156             :       "but the computeScalarQpResidual method was not overridden. Accidental call of base class?");
     157             :   return 0;
     158             : }

Generated by: LCOV version 1.14