LCOV - code coverage report
Current view: top level - include/warehouses - MooseObjectWarehouse.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 69 69 100.0 %
Date: 2025-07-17 01:28:37 Functions: 217 366 59.3 %
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    27512907 : MooseObjectWarehouse<T>::MooseObjectWarehouse(bool threaded /*=true*/)
      93    27512907 :   : MooseObjectWarehouseBase<T>(threaded)
      94             : {
      95    27512907 : }
      96             : 
      97             : template <typename T>
      98             : void
      99     1401568 : MooseObjectWarehouse<T>::addObject(std::shared_ptr<T> object,
     100             :                                    THREAD_ID tid /*= 0*/,
     101             :                                    bool recurse /* = true */)
     102             : {
     103     1401568 :   MooseObjectWarehouseBase<T>::addObject(object, tid, recurse);
     104             : 
     105     1401536 :   if (recurse)
     106             :   {
     107     1795576 :     if (auto mvir = std::dynamic_pointer_cast<MooseVariableInterface<Real>>(object); mvir)
     108      493116 :       _variable_objects[mvir->mooseVariableBase()->number()].addObject(object, tid, false);
     109     1214016 :     else if (auto mviv = std::dynamic_pointer_cast<MooseVariableInterface<RealVectorValue>>(object);
     110      404672 :              mviv)
     111        3114 :       _variable_objects[mviv->mooseVariableBase()->number()].addObject(object, tid, false);
     112     1204674 :     else if (auto mvie = std::dynamic_pointer_cast<MooseVariableInterface<RealEigenVector>>(object);
     113      401558 :              mvie)
     114        5976 :       _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      397124 :     else if (auto ro = std::dynamic_pointer_cast<ResidualObject>(object); ro)
     119        1542 :       _variable_objects[ro->variable().number()].addObject(object, tid, false);
     120             :   }
     121     1401536 : }
     122             : 
     123             : template <typename T>
     124             : bool
     125         325 : MooseObjectWarehouse<T>::hasVariableObjects(const unsigned int variable_id, THREAD_ID tid) const
     126             : {
     127         325 :   auto iter = _variable_objects.find(variable_id);
     128         325 :   return (iter != _variable_objects.end() && iter->second.hasObjects(tid));
     129             : }
     130             : 
     131             : template <typename T>
     132             : bool
     133    28554757 : MooseObjectWarehouse<T>::hasActiveVariableBlockObjects(unsigned int variable_id,
     134             :                                                        SubdomainID block_id,
     135             :                                                        THREAD_ID tid) const
     136             : {
     137    28554757 :   auto iter = _variable_objects.find(variable_id);
     138    28554757 :   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    26298056 : MooseObjectWarehouse<T>::getActiveVariableBlockObjects(unsigned int variable_id,
     144             :                                                        SubdomainID block_id,
     145             :                                                        THREAD_ID tid) const
     146             : {
     147    26298056 :   checkThreadID(tid);
     148    26298056 :   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    52596112 :   return iter->second.getActiveBlockObjects(block_id, tid);
     153             : }
     154             : 
     155             : template <typename T>
     156             : void
     157     1512152 : MooseObjectWarehouse<T>::initialSetup(THREAD_ID tid /* = 0*/) const
     158             : {
     159     1512152 :   checkThreadID(tid);
     160             :   // Initial Setup should be called on all objects because they may become active later
     161     1959683 :   for (const auto & object : _all_objects[tid])
     162      447611 :     object->initialSetup();
     163     1512072 : }
     164             : 
     165             : template <typename T>
     166             : void
     167     7323461 : MooseObjectWarehouse<T>::timestepSetup(THREAD_ID tid /* = 0*/) const
     168             : {
     169     7323461 :   checkThreadID(tid);
     170     9308731 :   for (const auto & object : _active_objects[tid])
     171     1985270 :     object->timestepSetup();
     172     7323461 : }
     173             : 
     174             : template <typename T>
     175             : void
     176    45119736 : MooseObjectWarehouse<T>::customSetup(const ExecFlagType & exec_type, THREAD_ID tid /* = 0*/) const
     177             : {
     178    45119736 :   checkThreadID(tid);
     179    56909193 :   for (const auto & object : _active_objects[tid])
     180    11789457 :     object->customSetup(exec_type);
     181    45119736 : }
     182             : 
     183             : template <typename T>
     184             : void
     185    48994671 : MooseObjectWarehouse<T>::subdomainSetup(SubdomainID id, THREAD_ID tid /* = 0*/) const
     186             : {
     187    48994671 :   checkThreadID(tid);
     188    48994671 :   if (hasActiveBlockObjects(id, tid))
     189             :   {
     190     7878111 :     const auto & objects = getActiveBlockObjects(id, tid);
     191    24448433 :     for (const auto & object : objects)
     192    16570322 :       object->subdomainSetup();
     193             :   }
     194    48994671 : }
     195             : 
     196             : template <typename T>
     197             : void
     198       75948 : MooseObjectWarehouse<T>::subdomainSetup(THREAD_ID tid /* = 0*/) const
     199             : {
     200       75948 :   checkThreadID(tid);
     201      137477 :   for (const auto & object : _active_objects[tid])
     202       61529 :     object->subdomainSetup();
     203       75948 : }
     204             : 
     205             : template <typename T>
     206             : void
     207    12101673 : MooseObjectWarehouse<T>::jacobianSetup(THREAD_ID tid /* = 0*/) const
     208             : {
     209    12101673 :   checkThreadID(tid);
     210    14812004 :   for (const auto & object : _active_objects[tid])
     211     2710331 :     object->jacobianSetup();
     212    12101673 : }
     213             : 
     214             : template <typename T>
     215             : void
     216    76661365 : MooseObjectWarehouse<T>::residualSetup(THREAD_ID tid /* = 0*/) const
     217             : {
     218    76661365 :   checkThreadID(tid);
     219    95755365 :   for (const auto & object : _active_objects[tid])
     220    19094000 :     object->residualSetup();
     221    76661365 : }
     222             : 
     223             : template <typename T>
     224             : void
     225   153085814 : MooseObjectWarehouse<T>::updateActive(THREAD_ID tid)
     226             : {
     227   153085814 :   MooseObjectWarehouseBase<T>::updateActive(tid);
     228             : 
     229   155132153 :   for (auto & it : _variable_objects)
     230     2046339 :     it.second.updateActive(tid);
     231   153085814 : }

Generated by: LCOV version 1.14