LCOV - code coverage report
Current view: top level - include/systems - AuxiliarySystem.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 18 18 100.0 %
Date: 2026-05-29 20:35:17 Functions: 11 11 100.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             : // MOOSE includes
      13             : #include "SystemBase.h"
      14             : #include "LinearFVGradientInterface.h"
      15             : #include "ExecuteMooseObjectWarehouse.h"
      16             : #include "PerfGraphInterface.h"
      17             : 
      18             : #include "libmesh/system.h"
      19             : #include "libmesh/transient_system.h"
      20             : 
      21             : // Forward declarations
      22             : class AuxKernelBase;
      23             : template <typename ComputeValueType>
      24             : class AuxKernelTempl;
      25             : typedef AuxKernelTempl<Real> AuxKernel;
      26             : typedef AuxKernelTempl<RealVectorValue> VectorAuxKernel;
      27             : typedef AuxKernelTempl<RealEigenVector> ArrayAuxKernel;
      28             : class FEProblemBase;
      29             : class TimeIntegrator;
      30             : class AuxScalarKernel;
      31             : 
      32             : // libMesh forward declarations
      33             : namespace libMesh
      34             : {
      35             : template <typename T>
      36             : class NumericVector;
      37             : }
      38             : 
      39             : /**
      40             :  * A system that holds auxiliary variables
      41             :  *
      42             :  */
      43             : class AuxiliarySystem : public SystemBase,
      44             :                         public PerfGraphInterface,
      45             :                         public LinearFVGradientInterface
      46             : {
      47             : public:
      48             :   AuxiliarySystem(FEProblemBase & subproblem, const std::string & name);
      49             :   virtual ~AuxiliarySystem();
      50             : 
      51             :   virtual void initialSetup() override;
      52             :   virtual void reinit() override;
      53             :   virtual void timestepSetup() override;
      54             :   virtual void customSetup(const ExecFlagType & exec_type) override;
      55             :   virtual void subdomainSetup() override;
      56             :   virtual void residualSetup() override;
      57             :   virtual void jacobianSetup() override;
      58             :   virtual void updateActive(THREAD_ID tid);
      59             : 
      60             :   virtual void addVariable(const std::string & var_type,
      61             :                            const std::string & name,
      62             :                            InputParameters & parameters) override;
      63             : 
      64             :   /**
      65             :    * Adds an auxiliary kernel
      66             :    * @param kernel_name The type of the kernel
      67             :    * @param name The name of the kernel
      68             :    * @param parameters Parameters for this kernel
      69             :    */
      70             :   void addKernel(const std::string & kernel_name,
      71             :                  const std::string & name,
      72             :                  InputParameters & parameters);
      73             : 
      74             : #ifdef MOOSE_KOKKOS_ENABLED
      75             :   void addKokkosKernel(const std::string & kernel_name,
      76             :                        const std::string & name,
      77             :                        InputParameters & parameters);
      78             : #endif
      79             : 
      80             :   /**
      81             :    * Adds a scalar kernel
      82             :    * @param kernel_name The type of the kernel
      83             :    * @param name The name of the kernel
      84             :    * @param parameters Kernel parameters
      85             :    */
      86             :   void addScalarKernel(const std::string & kernel_name,
      87             :                        const std::string & name,
      88             :                        InputParameters & parameters);
      89             : 
      90             :   virtual void reinitElem(const Elem * elem, THREAD_ID tid) override;
      91             :   virtual void reinitElemFace(const Elem * elem, unsigned int side, THREAD_ID tid) override;
      92             : 
      93     4291743 :   const NumericVector<Number> * const & currentSolution() const override
      94             :   {
      95     4291743 :     return _current_solution;
      96             :   }
      97             : 
      98             :   virtual void serializeSolution();
      99             : 
     100             :   // This is an empty function since the Aux system doesn't have a matrix!
     101             :   virtual void augmentSparsity(libMesh::SparsityPattern::Graph & /*sparsity*/,
     102             :                                std::vector<dof_id_type> & /*n_nz*/,
     103             :                                std::vector<dof_id_type> & /*n_oz*/) override;
     104             : 
     105             :   /**
     106             :    * Compute auxiliary variables
     107             :    * @param type Time flag of which variables should be computed
     108             :    */
     109             :   virtual void compute(ExecFlagType type) override;
     110             : 
     111             : #ifdef MOOSE_KOKKOS_ENABLED
     112             :   void kokkosCompute(ExecFlagType type);
     113             : #endif
     114             : 
     115             :   /**
     116             :    * Get a list of dependent UserObjects for this exec type
     117             :    * @param type Execution flag type
     118             :    * @return a set of dependent user objects
     119             :    */
     120             :   std::set<std::string> getDependObjects(ExecFlagType type);
     121             :   std::set<std::string> getDependObjects();
     122             : 
     123             :   /**
     124             :    * Get the minimum quadrature order for evaluating elemental auxiliary variables
     125             :    */
     126             :   virtual libMesh::Order getMinQuadratureOrder() override;
     127             : 
     128             :   /**
     129             :    * Indicated whether this system needs material properties on boundaries.
     130             :    * @return Boolean if IntegratedBCs are active
     131             :    */
     132             :   bool needMaterialOnSide(BoundaryID bnd_id);
     133             : 
     134       75887 :   virtual libMesh::System & sys() { return _sys; }
     135             : 
     136     4778763 :   virtual libMesh::System & system() override { return _sys; }
     137   170989852 :   virtual const libMesh::System & system() const override { return _sys; }
     138             : 
     139             :   using LinearFVGradientInterface::linearFVLimitedGradientContainer;
     140             :   using LinearFVGradientInterface::requestLinearFVLimitedGradients;
     141             : 
     142             :   /// Copies the current solution into the previous nonlinear iteration solution
     143             :   virtual void copyCurrentIntoPreviousNL();
     144             : 
     145             :   void setScalarVariableCoupleableTags(ExecFlagType type);
     146             : 
     147             :   void clearScalarVariableCoupleableTags();
     148             : 
     149             :   const ExecuteMooseObjectWarehouse<AuxKernel> & nodalAuxWarehouse() const;
     150             :   const ExecuteMooseObjectWarehouse<VectorAuxKernel> & nodalVectorAuxWarehouse() const;
     151             :   const ExecuteMooseObjectWarehouse<ArrayAuxKernel> & nodalArrayAuxWarehouse() const;
     152             : 
     153             :   const ExecuteMooseObjectWarehouse<AuxKernel> & elemAuxWarehouse() const;
     154             :   const ExecuteMooseObjectWarehouse<VectorAuxKernel> & elemVectorAuxWarehouse() const;
     155             :   const ExecuteMooseObjectWarehouse<ArrayAuxKernel> & elemArrayAuxWarehouse() const;
     156             : 
     157             : #ifdef MOOSE_KOKKOS_ENABLED
     158             :   const ExecuteMooseObjectWarehouse<AuxKernelBase> & kokkosNodalAuxWarehouse() const;
     159             :   const ExecuteMooseObjectWarehouse<AuxKernelBase> & kokkosElemAuxWarehouse() const;
     160             : #endif
     161             : 
     162             :   /// Computes and stores ||current - old|| / ||current|| for each variable in the given vector
     163             :   /// @param var_diffs a vector being filled with the L2 norm of the solution difference
     164             :   void variableWiseRelativeSolutionDifferenceNorm(std::vector<Number> & var_diffs) const;
     165             : 
     166             : protected:
     167             :   void computeScalarVars(ExecFlagType type);
     168             :   void computeNodalVars(ExecFlagType type);
     169             :   void computeMortarNodalVars(ExecFlagType type);
     170             :   void computeNodalVecVars(ExecFlagType type);
     171             :   void computeNodalArrayVars(ExecFlagType type);
     172             :   void computeElementalVars(ExecFlagType type);
     173             :   void computeElementalVecVars(ExecFlagType type);
     174             :   void computeElementalArrayVars(ExecFlagType type);
     175             : 
     176             :   template <typename AuxKernelType>
     177             :   void computeElementalVarsHelper(const MooseObjectWarehouse<AuxKernelType> & warehouse);
     178             : 
     179             :   template <typename AuxKernelType>
     180             :   void computeNodalVarsHelper(const MooseObjectWarehouse<AuxKernelType> & warehouse);
     181             : 
     182             :   libMesh::System & _sys;
     183             : 
     184             :   /// solution vector from nonlinear solver
     185             :   const NumericVector<Number> * _current_solution;
     186             : 
     187             :   /// The current states of the solution (0 = current, 1 = old, etc)
     188             :   std::vector<NumericVector<Number> *> _solution_state;
     189             : 
     190             :   // Variables
     191             :   std::vector<std::vector<MooseVariableFEBase *>> _nodal_vars;
     192             : 
     193             :   ///@{
     194             :   /**
     195             :    * Elemental variables. These may be either finite element or finite volume variables
     196             :    */
     197             :   std::vector<std::vector<MooseVariableFieldBase *>> _elem_vars;
     198             :   ///@}
     199             : 
     200             :   // Storage for AuxScalarKernel objects
     201             :   ExecuteMooseObjectWarehouse<AuxScalarKernel> _aux_scalar_storage;
     202             : 
     203             :   // Storage for AuxKernel objects
     204             :   ExecuteMooseObjectWarehouse<AuxKernel> _nodal_aux_storage;
     205             :   ExecuteMooseObjectWarehouse<AuxKernel> _mortar_nodal_aux_storage;
     206             :   ExecuteMooseObjectWarehouse<AuxKernel> _elemental_aux_storage;
     207             : 
     208             :   // Storage for VectorAuxKernel objects
     209             :   ExecuteMooseObjectWarehouse<VectorAuxKernel> _nodal_vec_aux_storage;
     210             :   ExecuteMooseObjectWarehouse<VectorAuxKernel> _elemental_vec_aux_storage;
     211             : 
     212             :   // Storage for ArrayAuxKernel objects
     213             :   ExecuteMooseObjectWarehouse<ArrayAuxKernel> _nodal_array_aux_storage;
     214             :   ExecuteMooseObjectWarehouse<ArrayAuxKernel> _elemental_array_aux_storage;
     215             : 
     216             : #ifdef MOOSE_KOKKOS_ENABLED
     217             :   // Storage for KokkosAuxKernel objects
     218             :   ExecuteMooseObjectWarehouse<AuxKernelBase> _kokkos_nodal_aux_storage;
     219             :   ExecuteMooseObjectWarehouse<AuxKernelBase> _kokkos_elemental_aux_storage;
     220             : #endif
     221             : 
     222             :   friend class ComputeIndicatorThread;
     223             :   friend class ComputeMarkerThread;
     224             :   friend class FlagElementsThread;
     225             :   friend class ComputeNodalKernelsThread;
     226             :   friend class ComputeNodalKernelBcsThread;
     227             :   friend class ComputeNodalKernelJacobiansThread;
     228             :   friend class ComputeNodalKernelBCJacobiansThread;
     229             : 
     230       60207 :   NumericVector<Number> & solutionInternal() const override { return *_sys.solution; }
     231             : };
     232             : 
     233             : inline const ExecuteMooseObjectWarehouse<AuxKernel> &
     234       59091 : AuxiliarySystem::nodalAuxWarehouse() const
     235             : {
     236       59091 :   return _nodal_aux_storage;
     237             : }
     238             : 
     239             : inline const ExecuteMooseObjectWarehouse<VectorAuxKernel> &
     240       59091 : AuxiliarySystem::nodalVectorAuxWarehouse() const
     241             : {
     242       59091 :   return _nodal_vec_aux_storage;
     243             : }
     244             : 
     245             : inline const ExecuteMooseObjectWarehouse<ArrayAuxKernel> &
     246       59091 : AuxiliarySystem::nodalArrayAuxWarehouse() const
     247             : {
     248       59091 :   return _nodal_array_aux_storage;
     249             : }
     250             : 
     251             : inline const ExecuteMooseObjectWarehouse<AuxKernel> &
     252       59055 : AuxiliarySystem::elemAuxWarehouse() const
     253             : {
     254       59055 :   return _elemental_aux_storage;
     255             : }
     256             : 
     257             : inline const ExecuteMooseObjectWarehouse<VectorAuxKernel> &
     258       59055 : AuxiliarySystem::elemVectorAuxWarehouse() const
     259             : {
     260       59055 :   return _elemental_vec_aux_storage;
     261             : }
     262             : 
     263             : inline const ExecuteMooseObjectWarehouse<ArrayAuxKernel> &
     264       59055 : AuxiliarySystem::elemArrayAuxWarehouse() const
     265             : {
     266       59055 :   return _elemental_array_aux_storage;
     267             : }
     268             : 
     269             : #ifdef MOOSE_KOKKOS_ENABLED
     270             : inline const ExecuteMooseObjectWarehouse<AuxKernelBase> &
     271             : AuxiliarySystem::kokkosNodalAuxWarehouse() const
     272             : {
     273             :   return _kokkos_nodal_aux_storage;
     274             : }
     275             : 
     276             : inline const ExecuteMooseObjectWarehouse<AuxKernelBase> &
     277             : AuxiliarySystem::kokkosElemAuxWarehouse() const
     278             : {
     279             :   return _kokkos_elemental_aux_storage;
     280             : }
     281             : #endif

Generated by: LCOV version 1.14