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