www.mooseframework.org
MooseObjectTagWarehouse.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
68  MooseObjectWarehouse<T> & getMatrixTagsObjectWarehouse(const std::set<TagID> & tags,
69  THREAD_ID tid);
70 
71 protected:
73 
75  std::vector<std::map<TagID, MooseObjectWarehouse<T>>> _vector_tag_to_object_warehouse;
76 
78  std::vector<std::map<std::set<TagID>, MooseObjectWarehouse<T>>> _vector_tags_to_object_warehouse;
79 
81  std::vector<std::map<TagID, MooseObjectWarehouse<T>>> _matrix_tag_to_object_warehouse;
82 
84  std::vector<std::map<std::set<TagID>, MooseObjectWarehouse<T>>> _matrix_tags_to_object_warehouse;
85 };
86 
87 template <typename T>
89  : MooseObjectWarehouse<T>(threaded),
90  _num_threads(threaded ? libMesh::n_threads() : 1),
91  _vector_tag_to_object_warehouse(_num_threads),
92  _vector_tags_to_object_warehouse(_num_threads),
93  _matrix_tag_to_object_warehouse(_num_threads),
94  _matrix_tags_to_object_warehouse(_num_threads)
95 {
96 }
97 
98 template <typename T>
99 void
101 {
103 
104  for (auto & it : _vector_tag_to_object_warehouse[tid])
105  it.second.updateActive(tid);
106 
107  for (auto & it : _vector_tags_to_object_warehouse[tid])
108  it.second.updateActive(tid);
109 
110  for (auto & it : _matrix_tag_to_object_warehouse[tid])
111  it.second.updateActive(tid);
112 
113  for (auto & it : _matrix_tags_to_object_warehouse[tid])
114  it.second.updateActive(tid);
115 }
116 
117 template <typename T>
120 {
121  auto & vector_tag_to_object_warehouse = _vector_tag_to_object_warehouse[tid];
122 
123  const auto & house_end = vector_tag_to_object_warehouse.end();
124  const auto & tag_warehouse = vector_tag_to_object_warehouse.find(tag_id);
125 
126  if (tag_warehouse != house_end)
127  return tag_warehouse->second;
128  else
129  vector_tag_to_object_warehouse[tag_id];
130 
131  // Now add actual moose objects into warehouse
132  const auto & objects = MooseObjectWarehouse<T>::getActiveObjects(tid);
133  for (auto & object : objects)
134  {
135  auto & tags = object->getVectorTags();
136  for (auto & tag : tags)
137  {
138  if (tag == tag_id)
139  {
140  // Tag based storage
141  vector_tag_to_object_warehouse[tag_id].addObject(object, tid);
142  break;
143  }
144  }
145  }
146 
147  return vector_tag_to_object_warehouse[tag_id];
148 }
149 
150 template <typename T>
153 {
154  auto & matrix_tag_to_object_warehouse = _matrix_tag_to_object_warehouse[tid];
155 
156  const auto & house_end = matrix_tag_to_object_warehouse.end();
157  const auto & tag_warehouse = matrix_tag_to_object_warehouse.find(tag_id);
158 
159  if (tag_warehouse != house_end)
160  return tag_warehouse->second;
161  else
162  matrix_tag_to_object_warehouse[tag_id];
163 
164  // Add moose objects to matrix-tag warehouse
165  const auto & objects = MooseObjectWarehouse<T>::getActiveObjects(tid);
166  for (auto & object : objects)
167  {
168  auto & tags = object->getMatrixTags();
169  for (auto & tag : tags)
170  {
171  if (tag == tag_id)
172  {
173  // Tag based storage
174  matrix_tag_to_object_warehouse[tag_id].addObject(object, tid);
175 
176  break;
177  }
178  }
179  }
180 
181  return matrix_tag_to_object_warehouse[tag_id];
182 }
183 
184 template <typename T>
187  THREAD_ID tid)
188 {
189  // std::map is not thread-safe for writes
190  auto & vector_tags_to_object_warehouse = _vector_tags_to_object_warehouse[tid];
191 
192  const auto & house_end = vector_tags_to_object_warehouse.end();
193  const auto & tags_warehouse = vector_tags_to_object_warehouse.find(v_tags);
194 
195  if (tags_warehouse != house_end)
196  return tags_warehouse->second;
197  else
198  vector_tags_to_object_warehouse[v_tags];
199 
200  // Add moose objects to vector-tags warehouse
201  const auto & objects = MooseObjectWarehouse<T>::getActiveObjects(tid);
202  for (auto & object : objects)
203  {
204  auto & tags = object->getVectorTags();
205  const auto & tags_end = tags.end();
206  for (auto & v_tag : v_tags)
207  {
208  const auto & tag_found = tags.find(v_tag);
209  // Object contains at least one of required tags
210  if (tag_found != tags_end)
211  {
212  // std::vector<Tag> based storage
213  vector_tags_to_object_warehouse[v_tags].addObject(object, tid);
214  // Then we should work for next object
215  break;
216  }
217  }
218  }
219 
220  return vector_tags_to_object_warehouse[v_tags];
221 }
222 
223 template <typename T>
226  THREAD_ID tid)
227 {
228  auto & matrix_tags_to_object_warehouse = _matrix_tags_to_object_warehouse[tid];
229 
230  const auto & house_end = matrix_tags_to_object_warehouse.end();
231  const auto & tags_warehouse = matrix_tags_to_object_warehouse.find(m_tags);
232 
233  if (tags_warehouse != house_end)
234  return tags_warehouse->second;
235  else
236  matrix_tags_to_object_warehouse[m_tags];
237 
238  const auto & objects = MooseObjectWarehouse<T>::getActiveObjects(tid);
239  for (auto & object : objects)
240  {
241  auto & tags = object->getMatrixTags();
242  const auto & tags_end = tags.end();
243  for (auto & m_tag : m_tags)
244  {
245  const auto & tag_found = tags.find(m_tag);
246  // Object contains at least one of required tags
247  if (tag_found != tags_end)
248  {
249  // std::vector<Tag> based storage
250  matrix_tags_to_object_warehouse[m_tags].addObject(object, tid);
251  // Then we should work for next object
252  break;
253  }
254  }
255  }
256 
257  return matrix_tags_to_object_warehouse[m_tags];
258 }
259 
unsigned int TagID
Definition: MooseTypes.h:162
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 > > & getActiveObjects(THREAD_ID tid=0) const
Retrieve complete vector to the active 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:161