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 30657692 : MooseObjectWarehouse<T>::MooseObjectWarehouse(bool threaded /*=true*/) 93 30657692 : : MooseObjectWarehouseBase<T>(threaded) 94 : { 95 30657692 : } 96 : 97 : template <typename T> 98 : void 99 1538397 : MooseObjectWarehouse<T>::addObject(std::shared_ptr<T> object, 100 : THREAD_ID tid /*= 0*/, 101 : bool recurse /* = true */) 102 : { 103 1538397 : MooseObjectWarehouseBase<T>::addObject(object, tid, recurse); 104 : 105 1538365 : if (recurse) 106 : { 107 1997236 : if (auto mvir = std::dynamic_pointer_cast<MooseVariableInterface<Real>>(object); mvir) 108 528375 : _variable_objects[mvir->mooseVariableBase()->number()].addObject(object, tid, false); 109 1410729 : else if (auto mviv = std::dynamic_pointer_cast<MooseVariableInterface<RealVectorValue>>(object); 110 470243 : mviv) 111 3321 : _variable_objects[mviv->mooseVariableBase()->number()].addObject(object, tid, false); 112 1400766 : else if (auto mvie = std::dynamic_pointer_cast<MooseVariableInterface<RealEigenVector>>(object); 113 466922 : mvie) 114 6391 : _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 462191 : else if (auto ro = std::dynamic_pointer_cast<ResidualObject>(object); ro) 119 1660 : _variable_objects[ro->variable().number()].addObject(object, tid, false); 120 : } 121 1538365 : } 122 : 123 : template <typename T> 124 : bool 125 345 : MooseObjectWarehouse<T>::hasVariableObjects(const unsigned int variable_id, THREAD_ID tid) const 126 : { 127 345 : auto iter = _variable_objects.find(variable_id); 128 345 : return (iter != _variable_objects.end() && iter->second.hasObjects(tid)); 129 : } 130 : 131 : template <typename T> 132 : bool 133 31569990 : MooseObjectWarehouse<T>::hasActiveVariableBlockObjects(unsigned int variable_id, 134 : SubdomainID block_id, 135 : THREAD_ID tid) const 136 : { 137 31569990 : auto iter = _variable_objects.find(variable_id); 138 31569990 : 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 29245108 : MooseObjectWarehouse<T>::getActiveVariableBlockObjects(unsigned int variable_id, 144 : SubdomainID block_id, 145 : THREAD_ID tid) const 146 : { 147 29245108 : checkThreadID(tid); 148 29245108 : 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 58490216 : return iter->second.getActiveBlockObjects(block_id, tid); 153 : } 154 : 155 : template <typename T> 156 : void 157 1626366 : MooseObjectWarehouse<T>::initialSetup(THREAD_ID tid /* = 0*/) const 158 : { 159 1626366 : checkThreadID(tid); 160 : // Initial Setup should be called on all objects because they may become active later 161 2139014 : for (const auto & object : _all_objects[tid]) 162 512732 : object->initialSetup(); 163 1626282 : } 164 : 165 : template <typename T> 166 : void 167 7947144 : MooseObjectWarehouse<T>::timestepSetup(THREAD_ID tid /* = 0*/) const 168 : { 169 7947144 : checkThreadID(tid); 170 10103837 : for (const auto & object : _active_objects[tid]) 171 2156693 : object->timestepSetup(); 172 7947144 : } 173 : 174 : template <typename T> 175 : void 176 48891625 : MooseObjectWarehouse<T>::customSetup(const ExecFlagType & exec_type, THREAD_ID tid /* = 0*/) const 177 : { 178 48891625 : checkThreadID(tid); 179 61684488 : for (const auto & object : _active_objects[tid]) 180 12792863 : object->customSetup(exec_type); 181 48891625 : } 182 : 183 : template <typename T> 184 : void 185 53186513 : MooseObjectWarehouse<T>::subdomainSetup(SubdomainID id, THREAD_ID tid /* = 0*/) const 186 : { 187 53186513 : checkThreadID(tid); 188 53186513 : if (hasActiveBlockObjects(id, tid)) 189 : { 190 8560137 : const auto & objects = getActiveBlockObjects(id, tid); 191 26484748 : for (const auto & object : objects) 192 17924611 : object->subdomainSetup(); 193 : } 194 53186513 : } 195 : 196 : template <typename T> 197 : void 198 83836 : MooseObjectWarehouse<T>::subdomainSetup(THREAD_ID tid /* = 0*/) const 199 : { 200 83836 : checkThreadID(tid); 201 151775 : for (const auto & object : _active_objects[tid]) 202 67939 : object->subdomainSetup(); 203 83836 : } 204 : 205 : template <typename T> 206 : void 207 13043781 : MooseObjectWarehouse<T>::jacobianSetup(THREAD_ID tid /* = 0*/) const 208 : { 209 13043781 : checkThreadID(tid); 210 15962269 : for (const auto & object : _active_objects[tid]) 211 2918488 : object->jacobianSetup(); 212 13043781 : } 213 : 214 : template <typename T> 215 : void 216 82193507 : MooseObjectWarehouse<T>::residualSetup(THREAD_ID tid /* = 0*/) const 217 : { 218 82193507 : checkThreadID(tid); 219 102654937 : for (const auto & object : _active_objects[tid]) 220 20461430 : object->residualSetup(); 221 82193507 : } 222 : 223 : template <typename T> 224 : void 225 171922423 : MooseObjectWarehouse<T>::updateActive(THREAD_ID tid) 226 : { 227 171922423 : MooseObjectWarehouseBase<T>::updateActive(tid); 228 : 229 174147744 : for (auto & it : _variable_objects) 230 2225321 : it.second.updateActive(tid); 231 171922423 : }