www.mooseframework.org
ExecuteMooseObjectWarehouse.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 #include "SetupInterface.h"
15 
24 template <typename T>
26 {
27 public:
32 
37  ExecuteMooseObjectWarehouse(const ExecFlagEnum & flags, bool threaded = true);
38 
40 
45  void addObject(std::shared_ptr<T> object, THREAD_ID tid = 0, bool recurse = true) override;
46 
48 
52  const MooseObjectWarehouse<T> & operator[](ExecFlagType exec_flag) const;
55 
57 
60  typename std::map<ExecFlagType, MooseObjectWarehouse<T>>::const_iterator begin() const
61  {
62  return _execute_objects.begin();
63  }
64  typename std::map<ExecFlagType, MooseObjectWarehouse<T>>::const_iterator end() const
65  {
66  return _execute_objects.end();
67  }
69 
73  void updateActive(THREAD_ID tid = 0) override;
74 
76 
81  void jacobianSetup(THREAD_ID tid = 0) const override;
82  void residualSetup(THREAD_ID tid = 0) const override;
83  void setup(const ExecFlagType & exec_flag, THREAD_ID tid = 0) const;
85 
90  void sort(THREAD_ID tid = 0);
91 
92  bool hasExecType(const ExecFlagType & exec_flag) { return _execute_objects.count(exec_flag) > 0; }
93 
94 protected:
95  // Map of execute objects to storage containers for MooseObjects
96  std::map<ExecFlagType, MooseObjectWarehouse<T>> _execute_objects;
97 
99  typename std::map<ExecFlagType, MooseObjectWarehouse<T>>::iterator
101  ExecFlagType exec_flag) const;
102 };
103 
104 template <typename T>
106  bool threaded)
107  : MooseObjectWarehouse<T>(threaded)
108 {
109  // Initialize the active/all data structures with the correct map entries and empty vectors
110  for (const auto & flag : flags.items())
111  _execute_objects.insert(std::make_pair(flag, MooseObjectWarehouse<T>(threaded)));
112 }
113 
114 template <typename T>
116 {
117 }
118 
119 template <typename T>
122 {
123  // Use find to avoid accidental insertion
124  const auto iter = _execute_objects.find(exec_flag);
125 
126  if (iter == _execute_objects.end())
127  mooseError("Unable to locate the desired execute flag (",
128  exec_flag,
129  "), the supplied execution flag was likely "
130  "not registered.");
131 
132  return iter->second;
133 }
134 
135 template <typename T>
138 {
139  // Use find to avoid accidental insertion
140  const auto iter = _execute_objects.find(exec_flag);
141 
142  if (iter == _execute_objects.end())
143  mooseError("Unable to locate the desired execute flag (",
144  exec_flag,
145  "), the supplied execution flag was likely "
146  "not registered.");
147 
148  return iter->second;
149 }
150 
151 template <typename T>
152 void
154 {
155  // Update all objects active list
157 
158  // Update the execute flag lists of objects
159  for (auto & object_pair : _execute_objects)
160  object_pair.second.updateActive(tid);
161 }
162 
163 template <typename T>
164 void
166 {
167  checkThreadID(tid);
168  const auto iter = _execute_objects.find(EXEC_NONLINEAR);
169  if (iter != _execute_objects.end())
170  iter->second.jacobianSetup(tid);
171 }
172 
173 template <typename T>
174 void
176 {
177  checkThreadID(tid);
178  const auto iter = _execute_objects.find(EXEC_LINEAR);
179  if (iter != _execute_objects.end())
180  iter->second.residualSetup(tid);
181 }
182 
183 template <typename T>
184 void
185 ExecuteMooseObjectWarehouse<T>::setup(const ExecFlagType & exec_flag, THREAD_ID tid /* = 0*/) const
186 {
187  checkThreadID(tid);
188  if (exec_flag == EXEC_INITIAL)
189  initialSetup(tid);
190  else if (exec_flag == EXEC_TIMESTEP_BEGIN)
191  timestepSetup(tid);
192  else if (exec_flag == EXEC_SUBDOMAIN)
193  subdomainSetup(tid);
194  else if (exec_flag == EXEC_NONLINEAR)
195  jacobianSetup(tid);
196  else if (exec_flag == EXEC_LINEAR)
197  residualSetup(tid);
198 }
199 
200 template <typename T>
201 void
203  THREAD_ID tid,
204  bool /*recurse*/)
205 {
206  // Update list of all objects
208 
209  // Update the execute flag lists of objects
210  if (const auto ptr = std::dynamic_pointer_cast<SetupInterface>(object))
211  for (const auto & flag : ptr->getExecuteOnEnum())
212  _execute_objects[flag].addObject(object, tid);
213  else
214  mooseError("The object being added (",
215  object->name(),
216  ") must inherit from SetupInterface to be added to the ExecuteMooseObjectWarehouse "
217  "container.");
218 }
219 
220 template <typename T>
221 void
223 {
224  // Sort execute object storage
225  for (auto & object_pair : _execute_objects)
226  object_pair.second.sort(tid);
227 }
void addObject(std::shared_ptr< T > object, THREAD_ID tid=0, bool recurse=true) override
Adds an object to the storage structure.
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:21
void sort(THREAD_ID tid=0)
Performs a sort using the DependencyResolver.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:299
void updateActive(THREAD_ID tid=0) override
Updates the active objects storage.
A storage container for MooseObjects that inherit from SetupInterface.
const MooseObjectWarehouse< T > & operator[](ExecFlagType exec_flag) const
Retrieve shared pointers for the given thread and execution type for all/active objects.
void setup(const ExecFlagType &exec_flag, THREAD_ID tid=0) const
A class for storing MooseObjects based on execution flag.
bool hasExecType(const ExecFlagType &exec_flag)
std::map< ExecFlagType, MooseObjectWarehouse< T > > _execute_objects
const std::set< ExecFlagType > & items() const
Reference the all the available items.
Definition: ExecFlagEnum.h:71
std::map< ExecFlagType, MooseObjectWarehouse< T > >::const_iterator begin() const
Provide access to begin/end iterators of the underlying map of execution flags.
const ExecFlagType EXEC_TIMESTEP_BEGIN
Definition: Moose.C:33
const ExecFlagType EXEC_LINEAR
Definition: Moose.C:29
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.
std::map< ExecFlagType, MooseObjectWarehouse< T > >::const_iterator end() const
void jacobianSetup(THREAD_ID tid=0) const override
Convenience methods for calling object setup methods.
const ExecFlagType EXEC_NONLINEAR
Definition: Moose.C:30
ExecuteMooseObjectWarehouse(const ExecFlagEnum &flags, bool threaded=true)
Constructor.
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:18
virtual void updateActive(THREAD_ID tid=0) override
Update the active status of Kernels.
const ExecFlagType EXEC_SUBDOMAIN
Definition: Moose.C:42
virtual void addObject(std::shared_ptr< T > object, THREAD_ID tid=0, bool recurse=true) override
Adds an object to the storage structure.
void residualSetup(THREAD_ID tid=0) const override
unsigned int THREAD_ID
Definition: MooseTypes.h:198
const ExecFlagType EXEC_INITIAL
Definition: Moose.C:28