LCOV - code coverage report
Current view: top level - include/base - ResidualObject.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 99787a Lines: 8 11 72.7 %
Date: 2025-10-14 20:01:24 Functions: 7 10 70.0 %
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 "MooseObject.h"
      13             : #include "SetupInterface.h"
      14             : #include "FunctionInterface.h"
      15             : #include "UserObjectInterface.h"
      16             : #include "TransientInterface.h"
      17             : #include "PostprocessorInterface.h"
      18             : #include "VectorPostprocessorInterface.h"
      19             : #include "RandomInterface.h"
      20             : #include "Restartable.h"
      21             : #include "MeshChangedInterface.h"
      22             : #include "TaggingInterface.h"
      23             : 
      24             : class FEProblemBase;
      25             : class MooseMesh;
      26             : class SubProblem;
      27             : class Assembly;
      28             : class MooseVariableBase;
      29             : class MooseVariableFieldBase;
      30             : class InputParameters;
      31             : class SystemBase;
      32             : 
      33             : /**
      34             :  * This is the common base class for objects that give residual contributions.
      35             :  */
      36             : class ResidualObject : public MooseObject,
      37             :                        public SetupInterface,
      38             :                        public FunctionInterface,
      39             :                        public UserObjectInterface,
      40             :                        public TransientInterface,
      41             :                        public PostprocessorInterface,
      42             :                        public VectorPostprocessorInterface,
      43             :                        public RandomInterface,
      44             :                        public Restartable,
      45             :                        public MeshChangedInterface,
      46             :                        public TaggingInterface
      47             : {
      48             : public:
      49             :   static InputParameters validParams();
      50             : 
      51             :   /**
      52             :    * Class constructor.
      53             :    * @param parameters The InputParameters for the object
      54             :    * @param nodal Whether this object is applied to nodes or not
      55             :    */
      56             :   ResidualObject(const InputParameters & parameters, bool nodal = false);
      57             : 
      58             : #ifdef MOOSE_KOKKOS_ENABLED
      59             :   /**
      60             :    * Special constructor used for Kokkos functor copy during parallel dispatch
      61             :    */
      62             :   ResidualObject(const ResidualObject & object, const Moose::Kokkos::FunctorCopy & key);
      63             : #endif
      64             : 
      65             :   /// Compute this object's contribution to the residual
      66             :   virtual void computeResidual() = 0;
      67             : 
      68             :   /// Compute this object's contribution to the diagonal Jacobian entries
      69             :   virtual void computeJacobian() = 0;
      70             : 
      71             :   /// Compute this object's contribution to the residual and Jacobian simultaneously
      72             :   virtual void computeResidualAndJacobian();
      73             : 
      74             :   /**
      75             :    * Computes this object's contribution to off-diagonal blocks of the system Jacobian matrix
      76             :    * @param jvar The number of the coupled variable. We pass the number of the coupled variable
      77             :    * instead of an actual variable object because we can query our system and obtain the variable
      78             :    * object associated with it. E.g. we need to make sure we are getting undisplaced variables if we
      79             :    * are working on the undisplaced mesh, and displaced variables if we are working on the displaced
      80             :    * mesh
      81             :    */
      82         320 :   virtual void computeOffDiagJacobian(unsigned int /*jvar*/) {}
      83             : 
      84             :   /**
      85             :    * Computes jacobian block with respect to a scalar variable
      86             :    * @param jvar The number of the scalar variable
      87             :    */
      88           0 :   virtual void computeOffDiagJacobianScalar(unsigned int /*jvar*/) {}
      89             : 
      90             :   /**
      91             :    * Compute this object's contribution to the diagonal Jacobian entries
      92             :    * corresponding to nonlocal dofs of the variable
      93             :    */
      94           0 :   virtual void computeNonlocalJacobian() {}
      95             : 
      96             :   /**
      97             :    * Computes Jacobian entries corresponding to nonlocal dofs of the jvar
      98             :    */
      99           0 :   virtual void computeNonlocalOffDiagJacobian(unsigned int /* jvar */) {}
     100             : 
     101             :   /**
     102             :    * Returns the variable that this object operates on.
     103             :    */
     104             :   virtual const MooseVariableBase & variable() const = 0;
     105             : 
     106             :   /**
     107             :    * Returns a reference to the SubProblem for which this Kernel is active
     108             :    */
     109       42235 :   const SubProblem & subProblem() const { return _subproblem; }
     110             : 
     111             :   /**
     112             :    * Prepare shape functions
     113             :    * @param var_num The variable number whose shape functions should be prepared
     114             :    */
     115             :   virtual void prepareShapes(unsigned int var_num);
     116             : 
     117             :   /**
     118             :    * @returns Additional variables covered by this residual object in addition to \p variable(). A
     119             :    * covered variable here means a variable for whom this object computes residuals/Jacobians
     120             :    */
     121       84424 :   virtual std::set<std::string> additionalROVariables() { return {}; }
     122             : 
     123             : protected:
     124   735855228 :   virtual void precalculateResidual() {}
     125   122002343 :   virtual void precalculateJacobian() {}
     126    20323770 :   virtual void precalculateOffDiagJacobian(unsigned int /* jvar */) {}
     127             : 
     128             :   /**
     129             :    * Retrieve the variable object from our system associated with \p jvar_num
     130             :    */
     131    21582535 :   const MooseVariableFieldBase & getVariable(unsigned int jvar_num) const
     132             :   {
     133    21582535 :     return _sys.getVariable(_tid, jvar_num);
     134             :   }
     135             : 
     136             : protected:
     137             :   /// Reference to this kernel's SubProblem
     138             :   SubProblem & _subproblem;
     139             : 
     140             :   /// Reference to this kernel's FEProblemBase
     141             :   FEProblemBase & _fe_problem;
     142             : 
     143             :   /// Reference to the EquationSystem object
     144             :   SystemBase & _sys;
     145             : 
     146             :   /// The thread ID for this kernel
     147             :   THREAD_ID _tid;
     148             : 
     149             :   /// Reference to this Kernel's assembly object
     150             :   Assembly & _assembly;
     151             : 
     152             :   /// Reference to this Kernel's mesh object
     153             :   MooseMesh & _mesh;
     154             : };

Generated by: LCOV version 1.14