11#include <unordered_set>
18template <
typename ModuleType>
21 module.getNameLocal();
24 } -> std::constructible_from<std::string>;
30 std::string m_error_string;
43 std::ostringstream
oss;
44 oss <<
"[ChainManager]: Failed to resolve dependencies for the following modules:\n";
47 oss <<
module->getNameLocal() << "\n";
49 oss <<
"Please check the dependencies and resolve the circular or missing "
51 m_error_string =
oss.str();
68template <
typename ModuleType>
72 using ModuleList = std::vector<std::shared_ptr<ModuleType>>;
73 std::map<std::string_view, ModuleList> m_chain_map{};
75 bool checkDependencyCurrentModule(std::shared_ptr<ModuleType>
module,
104template <
typename ModuleType>
114template <
typename ModuleType>
119 m_chain_map.insert({
"InitChain", std::vector<std::shared_ptr<ModuleType>>{}});
120 m_chain_map.insert({
"PreTimeStepChain", std::vector<std::shared_ptr<ModuleType>>{}});
121 m_chain_map.insert({
"PostNonLinIterChain", std::vector<std::shared_ptr<ModuleType>>{}});
122 m_chain_map.insert({
"PostTimeStepChain", std::vector<std::shared_ptr<ModuleType>>{}});
123 m_chain_map.insert({
"OutputChain", std::vector<std::shared_ptr<ModuleType>>{}});
133template <
typename ModuleType>
135 const std::shared_ptr<ModuleType>&
module)
145template <
typename ModuleType>
164template <
typename ModuleType>
186template <
typename ModuleType>
191 for (
auto&
key :
module->getChainInsertion())
193 insertModule(key, module);
196 resolveDependencies();
207template <
typename ModuleType>
216 std::string
mod_name{
module->getNameLocal()};
219 for (
auto&
key :
module->getChainInsertion())
221 insertModule(key, module);
225 resolveDependencies();
233template <
typename ModuleType>
251 if (checkDependencyCurrentModule(module, sorted_chain_module_vector))
253 sorted_chain_module_vector.push_back(module);
267 std::cerr <<
"[ChainManager]: Failed to resovle all dependencies - terminating "
268 "simulation due to DependencyError!\n";
284template <
typename ModuleType>
304 { return resolved_names.contains(dependency); });
310template <
typename ModuleType>
315 for (
const auto& [
key,
chain] : m_chain_map)
328template <
typename ModuleType>
Template generalized ChainManager. It stores pointers to the modules and runs their exec-function on ...
Definition ChainManager.h:70
void runChain(std::string_view key)
Runs the exec-functions of each module within the specified chain (if existing).
Definition ChainManager.h:146
void autoLoader(const ModuleList &all_modules, const std::vector< std::string > &modules_to_load)
Inserts only user specified modules derived from a module type into the chain in the load-order....
Definition ChainManager.h:208
void autoLoader(const ModuleList &all_modules)
Inserts all modules derived from a module type into the chain in the load-order. Only used for module...
Definition ChainManager.h:187
std::unordered_set< std::string > getManagingModuleNames() const
Function that returns the names of the requested/loaded managing modules.
Definition ChainManager.h:329
void insertModule(std::string_view key, const std::shared_ptr< ModuleType > &module)
Insert modules into chains. Generates a new chain, if the chain key does not yet exist.
Definition ChainManager.h:134
std::vector< std::string > getChainNames() const
Getter function for the chain names.
Definition ChainManager.h:311
void resolveDependencies()
Guarantees that the module order is correct to ensure all dependencies are met. Throws a DependencyEr...
Definition ChainManager.h:234
void runSingleModuleInChain(std::string_view chain_key, std::string_view module_key)
Runs the exec-function of a singular specified module within a specified chain (if existing).
Definition ChainManager.h:165
ChainManager(std::string_view chain_type)
Constructor of the chain manager with possibility to specify chain type. Option(s): "global"....
Definition ChainManager.h:115
ChainManager()
Constructor of the chain manager without arguments. Does not initialize chains, so the have to be add...
Definition ChainManager.h:105
Concrete implementation of a matrix class representing a Compressed Sparse Rows (CSR) matrix....
Definition CsrMatrix.h:37
CsrSparseMatrix()
Constructor for an empty CsrSparseMatrix object. Leaves all storage arrays empty but sets the flag to...
Definition CsrMatrix.h:94
Error class to throw when a module chain has circular or missing dependencies. Inherits from std::exc...
Definition ChainManager.h:28
DependencyError(const std::vector< std::shared_ptr< ModuleType > > unresolved_dependency_modules)
Definition ChainManager.h:40
~DependencyError() override=default
const char * what() const noexcept override
Supplies the error message as a c-style string/char array.
Definition ChainManager.h:57