LCOV - code coverage report
Current view: top level - include/kernels - KernelScalarBase.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 6 9 66.7 %
Date: 2025-07-17 01:28:37 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             : protected:
      52             :   /**
      53             :    * Precalculate method that is executed prior to scalar coupled variable loop
      54             :    * within computeOffDiagJacobianScalar; analogous to precalculateResidual(),
      55             :    * precalculateJacobian(), and precalculateOffDiagJacobian().
      56             :    */
      57          64 :   virtual void precalculateOffDiagJacobianScalar(unsigned int /* svar_num */) {}
      58             : 
      59             :   /**
      60             :    * Method for computing the scalar part of residual
      61             :    */
      62             :   virtual void computeScalarResidual();
      63             : 
      64             :   /**
      65             :    * Method for computing the scalar part of residual at quadrature points
      66             :    */
      67             :   virtual Real computeScalarQpResidual();
      68             : 
      69             :   /**
      70             :    * Method for computing the scalar variable part of Jacobian
      71             :    */
      72             :   virtual void computeScalarJacobian();
      73             : 
      74             :   /**
      75             :    * Method for computing the scalar variable part of Jacobian at
      76             :    * quadrature points
      77             :    */
      78           0 :   virtual Real computeScalarQpJacobian() { return 0; }
      79             : 
      80             :   /**
      81             :    * Method for computing an off-diagonal jacobian component d-_kappa-residual / d-jvar
      82             :    */
      83             :   virtual void computeScalarOffDiagJacobian(const unsigned int jvar_num);
      84             : 
      85             :   /**
      86             :    * Method for computing an off-diagonal jacobian component at quadrature points.
      87             :    */
      88           0 :   virtual Real computeScalarQpOffDiagJacobian(const unsigned int /*jvar_num*/) { return 0; }
      89             : 
      90             :   /**
      91             :    * Method for computing an off-diagonal jacobian component d-_var-residual / d-scalar
      92             :    * Revised version of Kernel::computeOffDiagJacobianScalar
      93             :    */
      94             :   virtual void computeOffDiagJacobianScalarLocal(const unsigned int svar_num);
      95             : 
      96             :   /**
      97             :    * Method for computing an off-diagonal jacobian component d-_kappa-residual / d-scalar
      98             :    */
      99             :   virtual void computeScalarOffDiagJacobianScalar(const unsigned int svar_num);
     100             : 
     101             :   /**
     102             :    * Method for computing an off-diagonal jacobian component at quadrature points.
     103             :    */
     104           0 :   virtual Real computeScalarQpOffDiagJacobianScalar(const unsigned int /*svar_num*/) { return 0; }
     105             : 
     106             :   /**
     107             :    * Put necessary evaluations depending on qp but independent of test functions here
     108             :    */
     109        1155 :   virtual void initScalarQpResidual() {}
     110             : 
     111             :   /**
     112             :    * Put necessary evaluations depending on qp but independent of test and shape functions here
     113             :    */
     114        1152 :   virtual void initScalarQpJacobian(const unsigned int /*svar_num*/) {}
     115             : 
     116             :   /**
     117             :    * Put necessary evaluations depending on qp but independent of test and shape functions here for
     118             :    * off-diagonal Jacobian assembly
     119             :    */
     120         576 :   virtual void initScalarQpOffDiagJacobian(const MooseVariableFEBase &) {}
     121             : 
     122             :   /// Whether a scalar variable is declared for this kernel
     123             :   const bool _use_scalar;
     124             : 
     125             :   /// Whether to compute scalar contributions for this instance
     126             :   const bool _compute_scalar_residuals;
     127             : 
     128             :   /// Whether to compute field contributions for this instance
     129             :   const bool _compute_field_residuals;
     130             : 
     131             :   /// (Pointer to) Scalar variable this kernel operates on
     132             :   const MooseVariableScalar * const _kappa_var_ptr;
     133             : 
     134             :   /// The unknown scalar variable ID
     135             :   const unsigned int _kappa_var;
     136             : 
     137             :   /// Order of the scalar variable, used in several places
     138             :   const unsigned int _k_order;
     139             : 
     140             :   /// Reference to the current solution at the current quadrature point
     141             :   const VariableValue & _kappa;
     142             : 
     143             :   /// Used internally to iterate over each scalar component
     144             :   unsigned int _h;
     145             :   unsigned int _l;
     146             : };
     147             : 
     148             : inline Real
     149           3 : KernelScalarBase::computeScalarQpResidual()
     150             : {
     151           3 :   mooseError(
     152             :       "A scalar_variable has been set and compute_scalar_residuals=true, ",
     153             :       "but the computeScalarQpResidual method was not overridden. Accidental call of base class?");
     154             :   return 0;
     155             : }

Generated by: LCOV version 1.14