www.mooseframework.org
ExecuteMooseObjectWarehouse.h
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #ifndef EXECUTEMOOSEOBJECTWAREHOUSE_H
16 #define EXECUTEMOOSEOBJECTWAREHOUSE_H
17 
18 // MOOSE includes
19 #include "MooseObjectWarehouse.h"
20 #include "SetupInterface.h"
21 
30 template <typename T>
32 {
33 public:
38 
43  ExecuteMooseObjectWarehouse(bool threaded = true);
44 
46 
51  virtual void addObject(std::shared_ptr<T> object, THREAD_ID tid = 0);
52  void addObjectMask(std::shared_ptr<T> object,
53  THREAD_ID tid = 0,
54  std::uint16_t flag_mask = std::numeric_limits<std::uint16_t>::max());
55 
57 
61  const MooseObjectWarehouse<T> & operator[](ExecFlagType exec_flag) const;
64 
66 
69  typename std::map<ExecFlagType, MooseObjectWarehouse<T>>::const_iterator begin() const
70  {
71  return _execute_objects.begin();
72  }
73  typename std::map<ExecFlagType, MooseObjectWarehouse<T>>::const_iterator end() const
74  {
75  return _execute_objects.end();
76  }
78 
82  virtual void updateActive(THREAD_ID tid = 0);
83 
85 
90  void jacobianSetup(THREAD_ID tid = 0) const;
91  void residualSetup(THREAD_ID tid = 0) const;
92  void setup(ExecFlagType exec_flag, THREAD_ID tid = 0) const;
94 
99  void sort(THREAD_ID tid = 0);
100 
101 protected:
102  // Map of execute objects to storage containers for MooseObjects
103  std::map<ExecFlagType, MooseObjectWarehouse<T>> _execute_objects;
104 
106  typename std::map<ExecFlagType, MooseObjectWarehouse<T>>::iterator
108  ExecFlagType exec_flag) const;
109 };
110 
111 template <typename T>
113  : MooseObjectWarehouse<T>(threaded)
114 {
115  // Initialize the active/all data structures with the correct map entries and empty vectors
116  for (const auto & exec_type : Moose::exec_types)
117  _execute_objects.insert(std::make_pair(exec_type, MooseObjectWarehouse<T>(threaded)));
118 }
119 
120 template <typename T>
122 {
123 }
124 
125 template <typename T>
127 operator[](ExecFlagType exec_flag) const
128 {
129  // Use find to avoid accidental insertion
130  const auto iter = _execute_objects.find(exec_flag);
131 
132  if (iter == _execute_objects.end())
133  mooseError("Unable to locate the desired execute flag, the global list of execute parameters "
134  "is likely out-of-date.");
135 
136  return iter->second;
137 }
138 
139 template <typename T>
141 {
142  // Use find to avoid accidental insertion
143  const auto iter = _execute_objects.find(exec_flag);
144 
145  if (iter == _execute_objects.end())
146  mooseError("Unable to locate the desired execute flag, the global list of execute parameters "
147  "is likely out-of-date.");
148 
149  return iter->second;
150 }
151 
152 template <typename T>
153 void
155 {
156  // Update all objects active list
158 
159  // Update the execute flag lists of objects
160  for (auto & object_pair : _execute_objects)
161  object_pair.second.updateActive(tid);
162 }
163 
164 template <typename T>
165 void
167 {
168  checkThreadID(tid);
169  const auto iter = _execute_objects.find(EXEC_NONLINEAR);
170  if (iter != _execute_objects.end())
171  iter->second.jacobianSetup(tid);
172 }
173 
174 template <typename T>
175 void
177 {
178  checkThreadID(tid);
179  const auto iter = _execute_objects.find(EXEC_LINEAR);
180  if (iter != _execute_objects.end())
181  iter->second.residualSetup(tid);
182 }
183 
184 template <typename T>
185 void
187 {
188  checkThreadID(tid);
189  switch (exec_flag)
190  {
191  case EXEC_INITIAL:
192  initialSetup(tid);
193  break;
194  case EXEC_TIMESTEP_BEGIN:
195  timestepSetup(tid);
196  break;
197  case EXEC_SUBDOMAIN:
198  subdomainSetup(tid);
199  break;
200  case EXEC_NONLINEAR:
201  jacobianSetup(tid);
202  break;
203  case EXEC_LINEAR:
204  residualSetup(tid);
205  break;
206  default:
207  break;
208  }
209 }
210 
211 template <typename T>
212 void
214 
215 {
216  addObjectMask(object, tid, 0xFFFF);
217 }
218 
219 template <typename T>
220 void
222  THREAD_ID tid,
223  std::uint16_t flag_mask)
224 {
225  // Update list of all objects
227 
228  // Update the execute flag lists of objects
229  std::shared_ptr<SetupInterface> ptr = std::dynamic_pointer_cast<SetupInterface>(object);
230  if (ptr)
231  {
232  const std::vector<ExecFlagType> flags = ptr->execFlags();
233  for (auto flag : flags)
234  {
235  auto masked_flag = static_cast<std::uint16_t>(flag) & flag_mask;
236  if (masked_flag != 0)
237  _execute_objects[flag].addObject(object, tid);
238  }
239  }
240  else
241  mooseError("The object being added (",
242  object->name(),
243  ") must inherit from SetupInterface to "
244  "be added to the "
245  "ExecuteMooseObjectWarehouse "
246  "container.");
247 }
248 
249 template <typename T>
250 void
252 {
253  // Sort execute object storage
254  for (auto & object_pair : _execute_objects)
255  object_pair.second.sort(tid);
256 }
257 
258 #endif // EXECUTEMOOSEOBJECTWAREHOUSE_H
Object is evaluated in every residual computation.
Definition: MooseTypes.h:96
void addObjectMask(std::shared_ptr< T > object, THREAD_ID tid=0, std::uint16_t flag_mask=std::numeric_limits< std::uint16_t >::max())
virtual const std::vector< ExecFlagType > & execFlags() const
Get the execution flag for the object.
ExecuteMooseObjectWarehouse(bool threaded=true)
Constructor.
std::map< ExecFlagType, MooseObjectWarehouse< T > >::const_iterator end() const
void sort(THREAD_ID tid=0)
Performs a sort using the DependencyResolver.
Object is evaluated only once at the beginning of the simulation.
Definition: MooseTypes.h:94
void jacobianSetup(THREAD_ID tid=0) const
Convenience methods for calling object setup methods.
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
virtual void subdomainSetup(THREAD_ID tid=0) const
A storage container for MooseObjects that inherit from SetupInterface.
std::map< ExecFlagType, MooseObjectWarehouse< T > >::const_iterator begin() const
Provide access to begin/end iterators of the underlying map of execution flags.
virtual void addObject(std::shared_ptr< T > object, THREAD_ID tid=0)
Adds an object to the storage structure.
A class for storing MooseObjects based on execution flag.
void checkThreadID(THREAD_ID tid) const
Calls assert on thread id.
virtual void addObject(std::shared_ptr< T > object, THREAD_ID tid=0)
Adds an object to the storage structure.
std::map< ExecFlagType, MooseObjectWarehouse< T > > _execute_objects
virtual void timestepSetup(THREAD_ID tid=0) const
virtual void initialSetup(THREAD_ID tid=0) const
Convenience methods for calling object setup methods.
Objects is evaluated on subdomain.
Definition: MooseTypes.h:112
const MooseObjectWarehouse< T > & operator[](ExecFlagType exec_flag) const
Retrieve shared pointers for the given thread and execution type for all/active objects.
void residualSetup(THREAD_ID tid=0) const
Object is evaluated at the beginning of every time step.
Definition: MooseTypes.h:102
const std::vector< ExecFlagType > exec_types
A static list of all the exec types.
Definition: MooseTypes.C:40
ExecFlagType
Execution flags - when is the object executed/evaluated.
Definition: MooseTypes.h:90
Object is evaluated in every jacobian computation.
Definition: MooseTypes.h:98
virtual void updateActive(THREAD_ID tid=0)
Updates the active objects storage.
std::map< ExecFlagType, MooseObjectWarehouse< T > >::iterator getStorageHelper(std::map< ExecFlagType, MooseObjectWarehouse< T >> &objects, ExecFlagType exec_flag) const
A helper method for extracting objects from the various storage containers.
void setup(ExecFlagType exec_flag, THREAD_ID tid=0) const
virtual void updateActive(THREAD_ID tid=0)
Updates the active objects storage.
unsigned int THREAD_ID
Definition: MooseTypes.h:79