<
    Kitware and KbPort announce the launch of SimPulse
×
PhysiologyEnginePool.h
1 /* Distributed under the Apache License, Version 2.0.
2 See 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 {
19  friend class SEPhysiologyEnginePool;
21 protected:
22  SEPhysiologyEnginePoolEngine(Logger* logger = nullptr);
23 
24 public:
26 
27  bool IsActive=false;
29  std::vector<const SEAction*> Actions;
31  std::unique_ptr<PhysiologyEngine> Engine;
32 };
33 
34 class CDM_DECL SEPhysiologyEnginePool : public Loggable
35 {
37 public:
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 
65 protected:
66  virtual void AllocateEngine(SEPhysiologyEnginePoolEngine& pe) = 0;
67 
68  bool m_IsActive;
70  std::map<int, SEPhysiologyEnginePoolEngine*> m_Engines;
72 };
73 
79 {
80 public:
81  PhysiologyEnginePoolThunk(size_t poolSize = 0, const std::string& dataDir="./");
82  virtual ~PhysiologyEnginePoolThunk();
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 
92 private:
93  class pimpl;
94  pimpl* data;
95 };
96 
97 
123 
126 
Definition: SESubstanceManager.h:8
Definition: PhysiologyEnginePool.h:78
SEEngineInitialization EngineInitialization
Definition: PhysiologyEnginePool.h:28
pimpl * data
Definition: PhysiologyEnginePool.h:93
Definition: Logger.h:66
Definition: PhysiologyEnginePool.h:17
SEDataRequested DataRequested
Definition: PhysiologyEnginePool.h:30
Definition: SEAction.h:13
bool RemoveEngine(int id)
Definition: PhysiologyEnginePool.cpp:259
SESubstanceManager m_SubMgr
Definition: PhysiologyEnginePool.h:69
bool m_IsActive
Definition: PhysiologyEnginePool.h:68
Definition: ThreadPool.h:16
Definition: PhysiologyEnginePool.h:34
Definition: SEScalarTime.h:7
bool IsActive
Definition: PhysiologyEnginePool.h:27
bool ProcessActions(std::string const &actions, eSerializationFormat format)
Definition: PhysiologyEnginePool.cpp:264
Definition: Logger.h:18
const size_t GetWorkerCount() const
Definition: PhysiologyEnginePool.h:41
Definition: SEDataRequested.h:9
friend class SEPhysiologyEnginePool
Definition: PhysiologyEnginePool.h:19
~SEPhysiologyEnginePoolEngine()
Definition: PhysiologyEnginePool.cpp:28
ThreadPool m_Pool
Definition: PhysiologyEnginePool.h:71
Definition: SEEngineInitialization.h:9
std::unique_ptr< PhysiologyEngine > Engine
Definition: PhysiologyEnginePool.h:31
bool InitializeEngines(std::string const &engineInitializationList, eSerializationFormat format)
Definition: PhysiologyEnginePool.cpp:237
friend class PhysiologyEnginePoolThunk
Definition: PhysiologyEnginePool.h:20
SEPhysiologyEnginePoolEngine(Logger *logger=nullptr)
Definition: PhysiologyEnginePool.cpp:24
std::map< int, SEPhysiologyEnginePoolEngine * > m_Engines
Definition: PhysiologyEnginePool.h:70
Definition: PhysiologyEnginePool.cpp:211
std::vector< const SEAction * > Actions
Definition: PhysiologyEnginePool.h:29

Distributed under the Apache License, Version 2.0.

See accompanying NOTICE file for details.