LCOV - code coverage report
Current view: top level - include/warehouses - MooseObjectWarehouse.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #31706 (f8ed4a) with base bb0a08 Lines: 69 69 100.0 %
Date: 2025-11-03 17:23:24 Functions: 242 387 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             : // MOOSE includes
      13             : #include "MooseObjectWarehouseBase.h"
      14             : #include "MooseVariableInterface.h"
      15             : #include "MooseVariableFE.h"
      16             : #include "ResidualObject.h"
      17             : 
      18             : /**
      19             :  * A storage container for MooseObjects that inherit from SetupInterface.
      20             :  *
      21             :  * Objects that inherit from SetupInterface have various functions (e.g., initialSetup). This
      22             :  * class provides convenience functions for looping over all active objects stored in the warehouse
      23             :  * and
      24             :  * calling the setup methods.
      25             :  */
      26             : template <typename T>
      27             : class MooseObjectWarehouse : public MooseObjectWarehouseBase<T>
      28             : {
      29             : public:
      30             :   using MooseObjectWarehouseBase<T>::checkThreadID;
      31             :   using MooseObjectWarehouseBase<T>::_all_objects;
      32             :   using MooseObjectWarehouseBase<T>::_active_objects;
      33             :   using MooseObjectWarehouseBase<T>::hasActiveBlockObjects;
      34             :   using MooseObjectWarehouseBase<T>::getActiveBlockObjects;
      35             : 
      36             :   /**
      37             :    * Constructor.
      38             :    * @param threaded When true (default) threaded storage is enabled.
      39             :    */
      40             :   MooseObjectWarehouse(bool threaded = true);
      41             : 
      42             :   /**
      43             :    * Adds an object to the storage structure.
      44             :    * @param object A shared pointer to the object being added
      45             :    * @param tid The thread ID (default is 0)
      46             :    * @param recurse Whether or not to build recusive warehouses (typically for Kernels)
      47             :    */
      48             :   virtual void
      49             :   addObject(std::shared_ptr<T> object, THREAD_ID tid = 0, bool recurse = true) override;
      50             : 
      51             :   ///@{
      52             :   /**
      53             :    * Convenience methods for calling object setup methods.
      54             :    */
      55             :   virtual void initialSetup(THREAD_ID tid = 0) const;
      56             :   virtual void timestepSetup(THREAD_ID tid = 0) const;
      57             :   virtual void customSetup(const ExecFlagType & exec_type, THREAD_ID tid = 0) const;
      58             :   virtual void subdomainSetup(THREAD_ID tid = 0) const;
      59             :   virtual void subdomainSetup(SubdomainID id, THREAD_ID tid = 0) const;
      60             :   virtual void jacobianSetup(THREAD_ID tid = 0) const;
      61             :   virtual void residualSetup(THREAD_ID tid = 0) const;
      62             :   ///@}
      63             : 
      64             :   /**
      65             :    * Checks for whether this warehouse has objects for a given variable
      66             :    */
      67             :   bool hasVariableObjects(unsigned int variable_id, THREAD_ID tid = 0) const;
      68             : 
      69             :   ///@{
      70             :   /**
      71             :    * Methods for checking/getting variable kernels for a variable and SubdomainID
      72             :    */
      73             :   bool hasActiveVariableBlockObjects(unsigned int variable_id,
      74             :                                      SubdomainID block_id,
      75             :                                      THREAD_ID tid = 0) const;
      76             :   const std::vector<std::shared_ptr<T>> & getActiveVariableBlockObjects(unsigned int variable_id,
      77             :                                                                         SubdomainID block_id,
      78             :                                                                         THREAD_ID tid = 0) const;
      79             :   ///@}
      80             : 
      81             :   /**
      82             :    * Update the active status of Kernels
      83             :    */
      84             :   virtual void updateActive(THREAD_ID tid = 0) override;
      85             : 
      86             : protected:
      87             :   /// Variable based storage
      88             :   std::map<unsigned int, MooseObjectWarehouse<T>> _variable_objects;
      89             : };
      90             : 
      91             : template <typename T>
      92    34506748 : MooseObjectWarehouse<T>::MooseObjectWarehouse(bool threaded /*=true*/)
      93    34474757 :   : MooseObjectWarehouseBase<T>(threaded)
      94             : {
      95    34506748 : }
      96             : 
      97             : template <typename T>
      98             : void
      99     1598514 : MooseObjectWarehouse<T>::addObject(std::shared_ptr<T> object,
     100             :                                    THREAD_ID tid /*= 0*/,
     101             :                                    bool recurse /* = true */)
     102             : {
     103     1598514 :   MooseObjectWarehouseBase<T>::addObject(object, tid, recurse);
     104             : 
     105     1598482 :   if (recurse)
     106             :   {
     107     2082038 :     if (auto mvir = std::dynamic_pointer_cast<MooseVariableInterface<Real>>(object); mvir)
     108      536638 :       _variable_objects[mvir->mooseVariableBase()->number()].addObject(object, tid, false);
     109     1510844 :     else if (auto mviv = std::dynamic_pointer_cast<MooseVariableInterface<RealVectorValue>>(object);
     110      502082 :              mviv)
     111        3318 :       _variable_objects[mviv->mooseVariableBase()->number()].addObject(object, tid, false);
     112     1500890 :     else if (auto mvie = std::dynamic_pointer_cast<MooseVariableInterface<RealEigenVector>>(object);
     113      498764 :              mvie)
     114        6441 :       _variable_objects[mvie->mooseVariableBase()->number()].addObject(object, tid, false);
     115             :     // Some objects, such as ScalarKernels, do not inherit from the MooseVariableInterface (which is
     116             :     // for field variables). These objects *do* inherit from ResidualObject which has this more
     117             :     // generic variable() API
     118      505688 :     else if (auto ro = std::dynamic_pointer_cast<ResidualObject>(object); ro)
     119       11066 :       _variable_objects[ro->variable().number()].addObject(object, tid, false);
     120             :   }
     121     1598482 : }
     122             : 
     123             : template <typename T>
     124             : bool
     125         397 : MooseObjectWarehouse<T>::hasVariableObjects(const unsigned int variable_id, THREAD_ID tid) const
     126             : {
     127         397 :   auto iter = _variable_objects.find(variable_id);
     128         397 :   return (iter != _variable_objects.end() && iter->second.hasObjects(tid));
     129             : }
     130             : 
     131             : template <typename T>
     132             : bool
     133    31938860 : MooseObjectWarehouse<T>::hasActiveVariableBlockObjects(unsigned int variable_id,
     134             :                                                        SubdomainID block_id,
     135             :                                                        THREAD_ID tid) const
     136             : {
     137    31938860 :   auto iter = _variable_objects.find(variable_id);
     138    31938860 :   return (iter != _variable_objects.end() && iter->second.hasActiveBlockObjects(block_id, tid));
     139             : }
     140             : 
     141             : template <typename T>
     142             : const std::vector<std::shared_ptr<T>> &
     143    29612428 : MooseObjectWarehouse<T>::getActiveVariableBlockObjects(unsigned int variable_id,
     144             :                                                        SubdomainID block_id,
     145             :                                                        THREAD_ID tid) const
     146             : {
     147    29612428 :   checkThreadID(tid);
     148    29612428 :   const auto iter = _variable_objects.find(variable_id);
     149             :   mooseAssert(iter != _variable_objects.end(),
     150             :               "Unable to locate variable kernels for the given variable id: " << variable_id
     151             :                                                                               << ".");
     152    59224856 :   return iter->second.getActiveBlockObjects(block_id, tid);
     153             : }
     154             : 
     155             : template <typename T>
     156             : void
     157     1929454 : MooseObjectWarehouse<T>::initialSetup(THREAD_ID tid /* = 0*/) const
     158             : {
     159     1929454 :   checkThreadID(tid);
     160             :   // Initial Setup should be called on all objects because they may become active later
     161     2460568 :   for (const auto & object : _all_objects[tid])
     162      531198 :     object->initialSetup();
     163     1929370 : }
     164             : 
     165             : template <typename T>
     166             : void
     167     9863071 : MooseObjectWarehouse<T>::timestepSetup(THREAD_ID tid /* = 0*/) const
     168             : {
     169     9863071 :   checkThreadID(tid);
     170    12448114 :   for (const auto & object : _active_objects[tid])
     171     2585043 :     object->timestepSetup();
     172     9863071 : }
     173             : 
     174             : template <typename T>
     175             : void
     176    61475808 : MooseObjectWarehouse<T>::customSetup(const ExecFlagType & exec_type, THREAD_ID tid /* = 0*/) const
     177             : {
     178    61475808 :   checkThreadID(tid);
     179    76846505 :   for (const auto & object : _active_objects[tid])
     180    15370697 :     object->customSetup(exec_type);
     181    61475808 : }
     182             : 
     183             : template <typename T>
     184             : void
     185    55299307 : MooseObjectWarehouse<T>::subdomainSetup(SubdomainID id, THREAD_ID tid /* = 0*/) const
     186             : {
     187    55299307 :   checkThreadID(tid);
     188    55299307 :   if (hasActiveBlockObjects(id, tid))
     189             :   {
     190     9285595 :     const auto & objects = getActiveBlockObjects(id, tid);
     191    28102409 :     for (const auto & object : objects)
     192    18816814 :       object->subdomainSetup();
     193             :   }
     194    55299307 : }
     195             : 
     196             : template <typename T>
     197             : void
     198       83961 : MooseObjectWarehouse<T>::subdomainSetup(THREAD_ID tid /* = 0*/) const
     199             : {
     200       83961 :   checkThreadID(tid);
     201      151999 :   for (const auto & object : _active_objects[tid])
     202       68038 :     object->subdomainSetup();
     203       83961 : }
     204             : 
     205             : template <typename T>
     206             : void
     207    16518368 : MooseObjectWarehouse<T>::jacobianSetup(THREAD_ID tid /* = 0*/) const
     208             : {
     209    16518368 :   checkThreadID(tid);
     210    20110870 :   for (const auto & object : _active_objects[tid])
     211     3592502 :     object->jacobianSetup();
     212    16518368 : }
     213             : 
     214             : template <typename T>
     215             : void
     216   104106890 : MooseObjectWarehouse<T>::residualSetup(THREAD_ID tid /* = 0*/) const
     217             : {
     218   104106890 :   checkThreadID(tid);
     219   129068970 :   for (const auto & object : _active_objects[tid])
     220    24962080 :     object->residualSetup();
     221   104106890 : }
     222             : 
     223             : template <typename T>
     224             : void
     225   192151993 : MooseObjectWarehouse<T>::updateActive(THREAD_ID tid)
     226             : {
     227   192151993 :   MooseObjectWarehouseBase<T>::updateActive(tid);
     228             : 
     229   194411798 :   for (auto & it : _variable_objects)
     230     2259805 :     it.second.updateActive(tid);
     231   192151993 : }

Generated by: LCOV version 1.14