https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MooseObjectWarehouse.h
Go to the documentation of this file.
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
15#include "MooseVariableFE.h"
16#include "ResidualObject.h"
17
26template <typename T>
28{
29public:
35
40 MooseObjectWarehouse(bool threaded = true);
41
48 virtual void
49 addObject(std::shared_ptr<T> object, THREAD_ID tid = 0, bool recurse = true) override;
50
52
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;
63
67 bool hasVariableObjects(unsigned int variable_id, THREAD_ID tid = 0) const;
68
70
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;
80
84 virtual void updateActive(THREAD_ID tid = 0) override;
85
86protected:
88 std::map<unsigned int, MooseObjectWarehouse<T>> _variable_objects;
89};
90
91template <typename T>
93 : MooseObjectWarehouseBase<T>(threaded)
94{
95}
96
97template <typename T>
98void
99MooseObjectWarehouse<T>::addObject(std::shared_ptr<T> object,
100 THREAD_ID tid /*= 0*/,
101 bool recurse /* = true */)
102{
103 MooseObjectWarehouseBase<T>::addObject(object, tid, recurse);
104
105 if (recurse)
106 {
107 if (auto mvir = std::dynamic_pointer_cast<MooseVariableInterface<Real>>(object); mvir)
108 _variable_objects[mvir->mooseVariableBase()->number()].addObject(object, tid, false);
109 else if (auto mviv = std::dynamic_pointer_cast<MooseVariableInterface<RealVectorValue>>(object);
110 mviv)
111 _variable_objects[mviv->mooseVariableBase()->number()].addObject(object, tid, false);
112 else if (auto mvie = std::dynamic_pointer_cast<MooseVariableInterface<RealEigenVector>>(object);
113 mvie)
114 _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 else if (auto ro = std::dynamic_pointer_cast<ResidualObject>(object); ro)
119 _variable_objects[ro->variable().number()].addObject(object, tid, false);
120 }
121}
122
123template <typename T>
124bool
125MooseObjectWarehouse<T>::hasVariableObjects(const unsigned int variable_id, THREAD_ID tid) const
126{
127 auto iter = _variable_objects.find(variable_id);
128 return (iter != _variable_objects.end() && iter->second.hasObjects(tid));
129}
130
131template <typename T>
132bool
134 SubdomainID block_id,
135 THREAD_ID tid) const
136{
137 auto iter = _variable_objects.find(variable_id);
138 return (iter != _variable_objects.end() && iter->second.hasActiveBlockObjects(block_id, tid));
139}
140
141template <typename T>
142const std::vector<std::shared_ptr<T>> &
144 SubdomainID block_id,
145 THREAD_ID tid) const
146{
147 checkThreadID(tid);
148 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 return iter->second.getActiveBlockObjects(block_id, tid);
153}
154
155template <typename T>
156void
158{
159 checkThreadID(tid);
160 // Initial Setup should be called on all objects because they may become active later
161 for (const auto & object : _all_objects[tid])
162 object->initialSetup();
163}
164
165template <typename T>
166void
168{
169 checkThreadID(tid);
170 for (const auto & object : _active_objects[tid])
171 object->timestepSetup();
172}
173
174template <typename T>
175void
176MooseObjectWarehouse<T>::customSetup(const ExecFlagType & exec_type, THREAD_ID tid /* = 0*/) const
177{
178 checkThreadID(tid);
179 for (const auto & object : _active_objects[tid])
180 object->customSetup(exec_type);
181}
182
183template <typename T>
184void
186{
187 checkThreadID(tid);
188 if (hasActiveBlockObjects(id, tid))
189 {
190 const auto & objects = getActiveBlockObjects(id, tid);
191 for (const auto & object : objects)
192 object->subdomainSetup();
193 }
194}
195
196template <typename T>
197void
199{
200 checkThreadID(tid);
201 for (const auto & object : _active_objects[tid])
202 object->subdomainSetup();
203}
204
205template <typename T>
206void
208{
209 checkThreadID(tid);
210 for (const auto & object : _active_objects[tid])
211 object->jacobianSetup();
212}
213
214template <typename T>
215void
217{
218 checkThreadID(tid);
219 for (const auto & object : _active_objects[tid])
220 object->residualSetup();
221}
222
223template <typename T>
224void
226{
228
229 for (auto & it : _variable_objects)
230 it.second.updateActive(tid);
231}
unsigned int THREAD_ID
Definition MooseTypes.h:237
Class for containing MooseEnum item information.
A base storage container for MooseObjects.
std::vector< std::vector< std::shared_ptr< T > > > _all_objects
Storage container for the ALL pointers (THREAD_ID on outer vector)
const std::map< SubdomainID, std::vector< std::shared_ptr< T > > > & getActiveBlockObjects(THREAD_ID tid=0) const
std::vector< std::vector< std::shared_ptr< T > > > _active_objects
All active objects (THREAD_ID on outer vector)
virtual void updateActive(THREAD_ID tid=0)
Updates the active objects storage.
virtual void addObject(std::shared_ptr< T > object, THREAD_ID tid=0, bool recurse=true)
Adds an object to the storage structure.
bool hasActiveBlockObjects(THREAD_ID tid=0) const
void checkThreadID(THREAD_ID tid) const
Calls assert on thread id.
A storage container for MooseObjects that inherit from SetupInterface.
virtual void timestepSetup(THREAD_ID tid=0) const
bool hasVariableObjects(unsigned int variable_id, THREAD_ID tid=0) const
Checks for whether this warehouse has objects for a given variable.
virtual void customSetup(const ExecFlagType &exec_type, THREAD_ID tid=0) const
virtual void subdomainSetup(THREAD_ID tid=0) const
bool hasActiveVariableBlockObjects(unsigned int variable_id, SubdomainID block_id, THREAD_ID tid=0) const
Methods for checking/getting variable kernels for a variable and SubdomainID.
virtual void subdomainSetup(SubdomainID id, THREAD_ID tid=0) const
virtual void initialSetup(THREAD_ID tid=0) const
Convenience methods for calling object setup methods.
virtual void residualSetup(THREAD_ID tid=0) const
std::map< unsigned int, MooseObjectWarehouse< T > > _variable_objects
Variable based storage.
MooseObjectWarehouse(bool threaded=true)
Constructor.
const std::vector< std::shared_ptr< T > > & getActiveVariableBlockObjects(unsigned int variable_id, SubdomainID block_id, THREAD_ID tid=0) const
virtual void addObject(std::shared_ptr< T > object, THREAD_ID tid=0, bool recurse=true) override
Adds an object to the storage structure.
virtual void updateActive(THREAD_ID tid=0) override
Update the active status of Kernels.
virtual void jacobianSetup(THREAD_ID tid=0) const
Interface for objects that need to get values of MooseVariables.