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

Generated by: LCOV version 1.14