https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MooseObjectTagWarehouse.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
14
22template <typename T>
24{
25public:
30
34 virtual void updateActive(THREAD_ID tid = 0) override;
35
43
52 THREAD_ID tid);
60
65
73 THREAD_ID tid);
74
75protected:
77
79 std::vector<std::map<TagID, MooseObjectWarehouse<T>>> _vector_tag_to_object_warehouse;
80
82 std::vector<std::map<std::set<TagID>, MooseObjectWarehouse<T>>> _vector_tags_to_object_warehouse;
83
85 std::vector<std::map<TagID, MooseObjectWarehouse<T>>> _matrix_tag_to_object_warehouse;
86
88 std::vector<std::map<std::set<TagID>, MooseObjectWarehouse<T>>> _matrix_tags_to_object_warehouse;
89};
90
91template <typename T>
93 : MooseObjectWarehouse<T>(num_threads),
94 _num_threads(num_threads),
95 _vector_tag_to_object_warehouse(_num_threads),
96 _vector_tags_to_object_warehouse(_num_threads),
97 _matrix_tag_to_object_warehouse(_num_threads),
98 _matrix_tags_to_object_warehouse(_num_threads)
99{
100}
101
102template <typename T>
103void
105{
107
108 for (auto & it : _vector_tag_to_object_warehouse[tid])
109 it.second.updateActive(tid);
110
111 for (auto & it : _vector_tags_to_object_warehouse[tid])
112 it.second.updateActive(tid);
113
114 for (auto & it : _matrix_tag_to_object_warehouse[tid])
115 it.second.updateActive(tid);
116
117 for (auto & it : _matrix_tags_to_object_warehouse[tid])
118 it.second.updateActive(tid);
119}
120
121template <typename T>
124{
125 auto & vector_tag_to_object_warehouse = _vector_tag_to_object_warehouse[tid];
126
127 const auto & house_end = vector_tag_to_object_warehouse.end();
128 const auto & tag_warehouse = vector_tag_to_object_warehouse.find(tag_id);
129
130 if (tag_warehouse != house_end)
131 return tag_warehouse->second;
132 else
133 vector_tag_to_object_warehouse[tag_id];
134
135 // Now add actual moose objects into warehouse
136 const auto & objects = MooseObjectWarehouse<T>::getObjects(tid);
137 for (auto & object : objects)
138 {
139 auto & tags = object->getVectorTags({});
140 for (auto & tag : tags)
141 {
142 if (tag == tag_id)
143 {
144 // Tag based storage
145 vector_tag_to_object_warehouse[tag_id].addObject(object, tid);
146 break;
147 }
148 }
149 }
150
151 return vector_tag_to_object_warehouse[tag_id];
152}
153
154template <typename T>
157{
158 auto & matrix_tag_to_object_warehouse = _matrix_tag_to_object_warehouse[tid];
159
160 const auto & house_end = matrix_tag_to_object_warehouse.end();
161 const auto & tag_warehouse = matrix_tag_to_object_warehouse.find(tag_id);
162
163 if (tag_warehouse != house_end)
164 return tag_warehouse->second;
165 else
166 matrix_tag_to_object_warehouse[tag_id];
167
168 // Add moose objects to matrix-tag warehouse
169 const auto & objects = MooseObjectWarehouse<T>::getObjects(tid);
170 for (auto & object : objects)
171 {
172 auto & tags = object->getMatrixTags({});
173 for (auto & tag : tags)
174 {
175 if (tag == tag_id)
176 {
177 // Tag based storage
178 matrix_tag_to_object_warehouse[tag_id].addObject(object, tid);
179
180 break;
181 }
182 }
183 }
184
185 return matrix_tag_to_object_warehouse[tag_id];
186}
187
188template <typename T>
191{
192 return const_cast<MooseObjectTagWarehouse<T> *>(this)->getMatrixTagObjectWarehouse(tag_id, tid);
193}
194
195template <typename T>
198 THREAD_ID tid)
199{
200 // std::map is not thread-safe for writes
201 auto & vector_tags_to_object_warehouse = _vector_tags_to_object_warehouse[tid];
202
203 const auto & house_end = vector_tags_to_object_warehouse.end();
204 const auto & tags_warehouse = vector_tags_to_object_warehouse.find(v_tags);
205
206 if (tags_warehouse != house_end)
207 return tags_warehouse->second;
208 else
209 vector_tags_to_object_warehouse[v_tags];
210
211 // Add moose objects to vector-tags warehouse
212 const auto & objects = MooseObjectWarehouse<T>::getObjects(tid);
213 for (auto & object : objects)
214 {
215 auto & tags = object->getVectorTags({});
216 const auto & tags_end = tags.end();
217 for (auto & v_tag : v_tags)
218 {
219 const auto & tag_found = tags.find(v_tag);
220 // Object contains at least one of required tags
221 if (tag_found != tags_end)
222 {
223 // std::vector<Tag> based storage
224 vector_tags_to_object_warehouse[v_tags].addObject(object, tid);
225 // Then we should work for next object
226 break;
227 }
228 }
229 }
230
231 return vector_tags_to_object_warehouse[v_tags];
232}
233
234template <typename T>
237 THREAD_ID tid)
238{
239 auto & matrix_tags_to_object_warehouse = _matrix_tags_to_object_warehouse[tid];
240
241 const auto & house_end = matrix_tags_to_object_warehouse.end();
242 const auto & tags_warehouse = matrix_tags_to_object_warehouse.find(m_tags);
243
244 if (tags_warehouse != house_end)
245 return tags_warehouse->second;
246 else
247 matrix_tags_to_object_warehouse[m_tags];
248
249 const auto & objects = MooseObjectWarehouse<T>::getObjects(tid);
250 for (auto & object : objects)
251 {
252 auto & tags = object->getMatrixTags({});
253 const auto & tags_end = tags.end();
254 for (auto & m_tag : m_tags)
255 {
256 const auto & tag_found = tags.find(m_tag);
257 // Object contains at least one of required tags
258 if (tag_found != tags_end)
259 {
260 // std::vector<Tag> based storage
261 matrix_tags_to_object_warehouse[m_tags].addObject(object, tid);
262 // Then we should work for next object
263 break;
264 }
265 }
266 }
267
268 return matrix_tags_to_object_warehouse[m_tags];
269}
unsigned int TagID
Definition MooseTypes.h:238
unsigned int THREAD_ID
Definition MooseTypes.h:237
A storage container for MooseObjects that inherit from SetupInterface.
MooseObjectWarehouse< T > & getVectorTagObjectWarehouse(TagID tag_id, THREAD_ID tid)
Retrieve a moose object warehouse in which every moose object has the given vector tag.
MooseObjectWarehouse< T > & getMatrixTagsObjectWarehouse(const std::set< TagID > &tags, THREAD_ID tid)
Retrieve a moose object warehouse in which every moose object has one of the given matrix tags.
virtual void updateActive(THREAD_ID tid=0) override
Update the active status of Kernels.
std::vector< std::map< std::set< TagID >, MooseObjectWarehouse< T > > > _matrix_tags_to_object_warehouse
std::set<TagID> based storage. Map from a std::set of tags to moose object warehouse for matrix tags.
std::vector< std::map< TagID, MooseObjectWarehouse< T > > > _vector_tag_to_object_warehouse
Tag based storage. Map from a tag to a moose object warehouse for vector tags.
const MooseObjectWarehouse< T > & getMatrixTagObjectWarehouse(TagID tag_id, THREAD_ID tid) const
const version of the above
MooseObjectWarehouse< T > & getVectorTagsObjectWarehouse(const std::set< TagID > &tags, THREAD_ID tid)
Retrieve a moose object warehouse in which every moose object at least has one of the given vector ta...
std::vector< std::map< std::set< TagID >, MooseObjectWarehouse< T > > > _vector_tags_to_object_warehouse
std::set<TagID> based storage. Map from a std::set of tags to a moose object warehouse for vector tag...
std::vector< std::map< TagID, MooseObjectWarehouse< T > > > _matrix_tag_to_object_warehouse
Tag based storage. Map fro a tag to moose object warehouse for matrix tags.
MooseObjectTagWarehouse(THREAD_ID num_threads=libMesh::n_threads())
Constructor.
MooseObjectWarehouse< T > & getMatrixTagObjectWarehouse(TagID tag_id, THREAD_ID tid)
Retrieve a moose object warehouse in which every moose object has the given matrix tag.
const std::vector< std::shared_ptr< T > > & getObjects(THREAD_ID tid=0) const
Retrieve complete vector to the all/block/boundary restricted objects for a given thread.
A storage container for MooseObjects that inherit from SetupInterface.
virtual void updateActive(THREAD_ID tid=0) override
Update the active status of Kernels.
unsigned int n_threads()