https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ExecuteMooseObjectWarehouse.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#include "SetupInterface.h"
15
24template <typename T>
26{
27public:
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
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
94protected:
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
104template <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
114template <typename T>
118
119template <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
135template <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
151template <typename T>
152void
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
163template <typename T>
164void
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
173template <typename T>
174void
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
183template <typename T>
184void
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
200template <typename T>
201void
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
220template <typename T>
221void
223{
224 // Sort execute object storage
225 for (auto & object_pair : _execute_objects)
226 object_pair.second.sort(tid);
227}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
unsigned int THREAD_ID
Definition MooseTypes.h:237
const ExecFlagType EXEC_SUBDOMAIN
Definition Moose.C:52
const ExecFlagType EXEC_TIMESTEP_BEGIN
Definition Moose.C:37
const ExecFlagType EXEC_INITIAL
Definition Moose.C:30
const ExecFlagType EXEC_LINEAR
Definition Moose.C:31
const ExecFlagType EXEC_NONLINEAR
Definition Moose.C:33
A MultiMooseEnum object to hold "execute_on" flags.
const std::set< ExecFlagType > & items() const
Reference the all the available items.
A class for storing MooseObjects based on execution flag.
MooseObjectWarehouse< T > & operator[](ExecFlagType exec_flag)
const MooseObjectWarehouse< T > & operator[](ExecFlagType exec_flag) const
Retrieve shared pointers for the given thread and execution type for all/active objects.
void jacobianSetup(THREAD_ID tid=0) const override
Convenience methods for calling object setup methods.
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
std::map< ExecFlagType, MooseObjectWarehouse< T > > _execute_objects
void updateActive(THREAD_ID tid=0) override
Updates the active objects storage.
ExecuteMooseObjectWarehouse(const ExecFlagEnum &flags, bool threaded=true)
Constructor.
std::map< ExecFlagType, MooseObjectWarehouse< T > >::const_iterator begin() const
Provide access to begin/end iterators of the underlying map of execution flags.
bool hasExecType(const ExecFlagType &exec_flag)
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
void sort(THREAD_ID tid=0)
Performs a sort using the DependencyResolver.
void setup(const ExecFlagType &exec_flag, THREAD_ID tid=0) const
Class for containing MooseEnum item information.
void checkThreadID(THREAD_ID tid) const
Calls assert on thread id.
A storage container for MooseObjects that inherit from SetupInterface.
virtual void timestepSetup(THREAD_ID tid=0) const
virtual void subdomainSetup(THREAD_ID tid=0) const
virtual void initialSetup(THREAD_ID tid=0) const
Convenience methods for calling object setup methods.
virtual void addObject(std::shared_ptr< T > object, THREAD_ID tid=0, bool recurse=true) override
Adds an object to the storage structure.
virtual void updateActive(THREAD_ID tid=0) override
Update the active status of Kernels.