PhysiologyEnginePool.h
1/* Distributed under the Apache License, Version 2.0.
2See accompanying NOTICE file for details.*/
3
4#pragma once
5
6#include "cdm/PhysiologyEngineThunk.h"
7#include "cdm/utils/ThreadPool.h"
8#include <chrono>
9
10#include "cdm/engine/SEDataRequested.h"
11#include "cdm/engine/SEEngineInitialization.h"
12#include "cdm/substance/SESubstanceManager.h"
13
14// TODO Template these class and move to CDM
15// (Template is the PhysiologEngine type)
16
18{
21protected:
22 SEPhysiologyEnginePoolEngine(Logger* logger = nullptr);
23
24public:
26
27 bool IsActive=false;
29 std::vector<const SEAction*> Actions;
31 std::unique_ptr<PhysiologyEngine> Engine;
32};
33
34class CDM_DECL SEPhysiologyEnginePool : public Loggable
35{
37public:
38 SEPhysiologyEnginePool(size_t poolSize = 0, const std::string& dataDir="./", Logger* logger = nullptr);
40
41 const size_t GetWorkerCount() const { return m_Pool.workerCount(); }
42
43 bool RemoveEngine(int id);
44 const std::map<int, SEPhysiologyEnginePoolEngine*>& GetEngines() const;
45 SEPhysiologyEnginePoolEngine* GetEngine(int id) const;
46 SEPhysiologyEnginePoolEngine* CreateEngine(int id);
47
48 bool InitializeEngines();
49
50 // Advance all engines the same amount of time
51 // If you want to advance individual engines/different times
52 // Add an SEAdvanceTime action to the SEPhysiologyEnginePoolEngine Actions vector
53 bool AdvanceModelTime(double time, const TimeUnit& unit);
54
55 // Process the same action on all engines
56 bool ProcessAction(const SEAction& action);
57
58 // Process all the actions on each engine pool engine
59 bool ProcessActions();
60
61 void ClearDataRequested();// Call to clear out log/events after you PullData and examine it
62 // If not, the vector of events/logs can get large...
63 void PullDataRequested(std::vector<SEDataRequested*>&);
64
65protected:
67
70 std::map<int, SEPhysiologyEnginePoolEngine*> m_Engines;
72};
73
79{
80public:
81 PhysiologyEnginePoolThunk(size_t poolSize = 0, const std::string& dataDir="./");
83
84 bool InitializeEngines(std::string const& engineInitializationList, eSerializationFormat format);
85
86 bool RemoveEngine(int id);
87
88 bool ProcessActions(std::string const& actions, eSerializationFormat format);
89
90 std::string PullRequestedData(eSerializationFormat format);
91
92private:
93 class pimpl;
95};
96
97
123
126
Definition: Logger.h:23
Definition: Logger.h:71
Definition: PhysiologyEnginePool.cpp:213
Definition: PhysiologyEnginePool.h:79
pimpl * data
Definition: PhysiologyEnginePool.h:94
bool ProcessActions(std::string const &actions, eSerializationFormat format)
Definition: PhysiologyEnginePool.cpp:265
bool InitializeEngines(std::string const &engineInitializationList, eSerializationFormat format)
Definition: PhysiologyEnginePool.cpp:238
bool RemoveEngine(int id)
Definition: PhysiologyEnginePool.cpp:260
Definition: SEAction.h:14
Definition: SEDataRequested.h:11
Definition: SEEngineInitialization.h:9
Definition: PhysiologyEnginePool.h:18
SEDataRequested DataRequested
Definition: PhysiologyEnginePool.h:30
~SEPhysiologyEnginePoolEngine()
Definition: PhysiologyEnginePool.cpp:28
SEPhysiologyEnginePoolEngine(Logger *logger=nullptr)
Definition: PhysiologyEnginePool.cpp:24
std::unique_ptr< PhysiologyEngine > Engine
Definition: PhysiologyEnginePool.h:31
bool IsActive
Definition: PhysiologyEnginePool.h:27
std::vector< const SEAction * > Actions
Definition: PhysiologyEnginePool.h:29
SEEngineInitialization EngineInitialization
Definition: PhysiologyEnginePool.h:28
Definition: PhysiologyEnginePool.h:35
ThreadPool m_Pool
Definition: PhysiologyEnginePool.h:71
const size_t GetWorkerCount() const
Definition: PhysiologyEnginePool.h:41
SESubstanceManager m_SubMgr
Definition: PhysiologyEnginePool.h:69
virtual void AllocateEngine(SEPhysiologyEnginePoolEngine &pe)=0
std::map< int, SEPhysiologyEnginePoolEngine * > m_Engines
Definition: PhysiologyEnginePool.h:70
bool m_IsActive
Definition: PhysiologyEnginePool.h:68
Definition: SESubstanceManager.h:9
Definition: ThreadPool.h:485
Definition: SEScalarTime.h:8

Distributed under the Apache License, Version 2.0.

See accompanying NOTICE file for details.