Pulse adds COVID-19 Simulation Support
×
Controller.h
1 /* Distributed under the Apache License, Version 2.0.
2  See accompanying NOTICE file for details.*/
3 
4 #pragma once
5 #include "CommonDataModel.h"
6 #include "engine/SEEngineStabilization.h"
7 
9 class PulseCircuits;
10 class PulseCompartments;
11 class PulseSubstances;
12 
13 // CDM
14 class SEActionManager;
15 class SEConditionManager;
16 
17 class DataTrack;
18 class SEEngineTracker;
19 
20 // Pulse
21 class BloodChemistry;
22 class Cardiovascular;
23 class Endocrine;
24 class Energy;
25 class Gastrointestinal;
26 class Hepatic;
27 class Nervous;
28 class Renal;
29 class Respiratory;
30 class Drugs;
31 class Tissue;
32 class Environment;
33 
34 class ECG;
35 class AnesthesiaMachine;
36 class Inhaler;
38 
40 
41 class PulseScenarioExec;
43 
44 enum class EngineState { NotReady=0,
45  Initialization,
46  InitialStabilization,
47  AtInitialStableState,
48  SecondaryStabilization,
49  AtSecondaryStableState,
50  Active };
51 
52 
53 // Keep enums in sync with appropriate proto file !!
54 enum class eAirwayMode{ Free=0,
56  Inhaler,
57  MechanicalVentilation,// Action
58  MechanicalVentilator, // Equipment
59  NasalCannula,
60  NonRebreatherMask,
61  SimpleMask};
62 extern const std::string& eAirwayMode_Name(eAirwayMode m);
63 
64 class PULSE_DECL PulseData : public Loggable
65 {
66  friend class PulseEngine;
67 public:
68  PulseData(Logger* logger=nullptr);
69  virtual ~PulseData();
70 
71  virtual std::string GetDataRoot() const { return m_DataDir; }
72  virtual void SetDataRoot(const std::string& dir) { m_DataDir = dir; }
73 
74  virtual void AdvanceCallback(double time_s);
75 
76  virtual EngineState GetState() const { return m_State; }
77 
78  virtual SEEngineTracker& GetEngineTracker() const;
79  virtual DataTrack& GetDataTrack() const;
80  virtual SaturationCalculator& GetSaturationCalculator() const;
81 
82  virtual PulseSubstances& GetSubstances() const;
83 
84  virtual const SEPatient& GetInitialPatient() const;
85  virtual SEPatient& GetCurrentPatient() const;
86 
87  virtual SEBloodChemistrySystem& GetBloodChemistry() const;
88  virtual SECardiovascularSystem& GetCardiovascular() const;
89  virtual SEDrugSystem& GetDrugs() const;
90  virtual SEEndocrineSystem& GetEndocrine() const;
91  virtual SEEnergySystem& GetEnergy() const;
92  virtual SEGastrointestinalSystem& GetGastrointestinal() const;
93  virtual SEHepaticSystem& GetHepatic() const;
94  virtual SENervousSystem& GetNervous() const;
95  virtual SERenalSystem& GetRenal() const;
96  virtual SERespiratorySystem& GetRespiratory() const;
97  virtual SETissueSystem& GetTissue() const;
98 
99  virtual SEEnvironment& GetEnvironment() const;
100  virtual SEAnesthesiaMachine& GetAnesthesiaMachine() const;
101  virtual SEElectroCardioGram& GetECG() const;
102  virtual SEInhaler& GetInhaler() const;
104 
105  virtual SEActionManager& GetActions() const;
106 
107  virtual SEConditionManager& GetConditions() const;
108 
109  virtual SEEventManager& GetEvents() const;
110 
111  virtual PulseCircuits& GetCircuits() const;
112 
113  virtual PulseCompartments& GetCompartments() const;
114 
115  virtual const PulseConfiguration& GetConfiguration() const;
116 
117  virtual const SEScalarTime& GetTimeStep() const;
118  virtual const SEScalarTime& GetEngineTime() const;
119  virtual const SEScalarTime& GetSimulationTime() const;
120 
121  virtual eAirwayMode GetAirwayMode() const { return m_AirwayMode; }
122  virtual void SetAirwayMode(eAirwayMode mode);
123 
124  virtual eSwitch GetIntubation() const { return m_Intubation; }
125  virtual void SetIntubation(eSwitch s);
126 
127  virtual void SetAdvanceHandler(SEAdvanceHandler* handler) { m_AdvanceHandler = handler; }
128 
129  virtual bool HasOverride() const;
130  virtual const std::vector<SEScalarProperty>& GetOverrides() const;
131 
132  std::stringstream m_ss;
133 protected:
134  EngineState m_State;
137 
141  eAirwayMode m_AirwayMode;
142  eSwitch m_Intubation;
143 
144  std::unique_ptr<PulseConfiguration> m_Config;
145  std::unique_ptr<SaturationCalculator> m_SaturationCalculator;
146 
147  std::unique_ptr<PulseSubstances> m_Substances;
148 
149  std::unique_ptr<SEActionManager> m_Actions;
150  std::unique_ptr<SEConditionManager> m_Conditions;
151  std::unique_ptr<PulseCircuits> m_Circuits;
152  std::unique_ptr<PulseCompartments> m_Compartments;
153 
154  std::unique_ptr<Environment> m_Environment;
155 
156  std::unique_ptr<BloodChemistry> m_BloodChemistrySystem;
157  std::unique_ptr<Cardiovascular> m_CardiovascularSystem;
158  std::unique_ptr<Endocrine> m_EndocrineSystem;
159  std::unique_ptr<Energy> m_EnergySystem;
160  std::unique_ptr<Gastrointestinal> m_GastrointestinalSystem;
161  std::unique_ptr<Hepatic> m_HepaticSystem;
162  std::unique_ptr<Nervous> m_NervousSystem;
163  std::unique_ptr<Renal> m_RenalSystem;
164  std::unique_ptr<Respiratory> m_RespiratorySystem;
165  std::unique_ptr<Drugs> m_DrugSystem;
166  std::unique_ptr<Tissue> m_TissueSystem;
167 
168  std::unique_ptr<ECG> m_ECG;
169 
170  std::unique_ptr<AnesthesiaMachine> m_AnesthesiaMachine;
171 
172  std::unique_ptr<Inhaler> m_Inhaler;
173 
174  std::unique_ptr<MechanicalVentilator> m_MechanicalVentilator;
175 
176  std::unique_ptr<SEPatient> m_InitialPatient;
177  std::unique_ptr<SEPatient> m_CurrentPatient;
178 
179  std::unique_ptr<SEEventManager> m_EventManager;
180 
182 
183  std::string m_DataDir;
184 
185  std::vector<SEScalarProperty> m_ScalarOverrides;
186 
187 };
188 
192 class PULSE_DECL PulseController : public PulseData
193 {
194  friend class PulseEngine;
195  friend class PulseEngineTest;
196  friend class PulseScenarioExec;
197  friend class PBPulseState;//friend the serialization class
198 public:
199 
200  PulseController(Logger* logger=nullptr);
201  virtual ~PulseController();
202 
203  virtual PulseData& GetData() { return (*this); }
204  virtual const PulseData& GetData() const { return (*this); }
205 
206  virtual bool SerializeFromFile(const std::string& file);
207  virtual bool SerializeToFile(const std::string& file) const;
208 
209  virtual bool SerializeFromString(const std::string& state, SerializationFormat m);
210  virtual bool SerializeToString(std::string& state, SerializationFormat m) const;
211 
212  virtual bool InitializeEngine(const std::string& patient_configuration, SerializationFormat m);
213  virtual bool InitializeEngine(const SEPatientConfiguration& patient_configuration);
214  virtual bool IsReady() const;
215 
216  virtual bool SetConfigurationOverride(const SEEngineConfiguration* config);
217 
218  virtual void SetSimulationTime(const SEScalarTime& time);
219 
220  virtual void AdvanceModelTime();
221  virtual void AdvanceModelTime(double time, const TimeUnit& unit);
222  virtual bool ProcessAction(const SEAction& action);
223 
224  virtual bool GetPatientAssessment(SEPatientAssessment& assessment) const;
225 
226  virtual bool CreateCircuitsAndCompartments();
227  virtual bool OverrideCircuits();
228 protected:
229 
230  virtual void SetupCardiovascular();
231  virtual void SetupRenal();
232  virtual void SetupTissue();
233  virtual void SetupCerebrospinalFluid();
234  virtual void SetupGastrointestinal();
235  virtual void SetupRespiratory();
236  virtual void SetupAnesthesiaMachine();
237  virtual void SetupInhaler();
238  virtual void SetupMechanicalVentilation();
239  virtual void SetupMechanicalVentilator();
240  virtual void SetupNasalCannula();
241  virtual void SetupSimpleMask();
242  virtual void SetupNonRebreatherMask();
243  virtual void SetupExternalTemperature();
244  virtual void SetupInternalTemperature();
245 
246  virtual bool Initialize(const SEPatient& patient);
247  virtual bool SetupPatient(const SEPatient& patient);
248 
249  // Notify systems that steady state has been achieved
250  virtual void AtSteadyState(EngineState state);
251  virtual void PreProcess();
252  virtual void Process();
253  virtual void PostProcess();
254 
255  virtual void ForwardFatal(const std::string& msg, const std::string& origin);
256 
259 };
260 
262 {
263 public:
265  ~PulseStabilizationController() = default;
266 
267  virtual void AdvanceTime() override { _pc.AdvanceModelTime(); }
268  virtual SEEngineTracker* GetEngineTracker() override
269  {
270  return &_pc.GetData().GetEngineTracker();
271  }
272  virtual double GetTimeStep(const TimeUnit& unit) override
273  {
274  return _pc.GetData().GetTimeStep().GetValue(unit);
275  }
276 
277 protected:
279 };
std::unique_ptr< Respiratory > m_RespiratorySystem
Definition: Controller.h:164
Definition: DataTrack.h:24
The nervous class holds models of the peripheral and central nervous system. Currently, on the baroreceptor reflex is modeled.
Definition: Nervous.h:15
Definition: SEElectroCardioGram.h:7
static bool SerializeFromString(const std::string &src, PulseController &dst, SerializationFormat m, const SEEngineConfiguration *config=nullptr)
Definition: PBPulseState.cpp:376
std::unique_ptr< SEEventManager > m_EventManager
Definition: Controller.h:179
Definition: Controller.h:261
SEScalarTime m_CurrentTime
Definition: Controller.h:138
The Respiratory System class handles the analysis and storage of data related the respiratory physiol...
Definition: Respiratory.h:32
eSwitch m_Intubation
Definition: Controller.h:142
std::stringstream m_ss
Definition: Controller.h:132
Definition: SEInhaler.h:11
Definition: SEPatient.h:12
Definition: SEEngineStabilization.h:13
std::unique_ptr< Cardiovascular > m_CardiovascularSystem
Definition: Controller.h:157
SEAdvanceHandler * m_AdvanceHandler
Definition: Controller.h:181
virtual std::string GetDataRoot() const
Definition: Controller.h:71
std::unique_ptr< Renal > m_RenalSystem
Definition: Controller.h:163
virtual void AdvanceTime() override
Definition: Controller.h:267
std::unique_ptr< PulseSubstances > m_Substances
Definition: Controller.h:147
Definition: Logger.h:75
virtual eAirwayMode GetAirwayMode() const
Definition: Controller.h:121
virtual const SEMechanicalVentilator * GetMechanicalVentilator() const override
Returns the current state of the Mechanical ventilator.
Definition: Engine.cpp:218
Manages and controls execution of all data/systems in Pulse.
Definition: Controller.h:192
Definition: SEAnesthesiaMachine.h:27
Definition: SEEngineConfiguration.h:7
PulseConfiguration const * m_ConfigOverride
Definition: Controller.h:257
Definition: SEEngineTracker.h:64
virtual double GetTimeStep(const TimeUnit &unit) override
Definition: Controller.h:272
Definition: SEMechanicalVentilator.h:20
std::unique_ptr< Environment > m_Environment
Definition: Controller.h:154
virtual double GetSimulationTime(const TimeUnit &unit) const override
returns the current time of the simulation.
Definition: Engine.cpp:78
std::unique_ptr< Gastrointestinal > m_GastrointestinalSystem
Definition: Controller.h:160
Definition: SEAction.h:7
Definition: SENervousSystem.h:8
Definition: Controller.h:64
Generic inhaler for substance administration.
Definition: Inhaler.h:15
std::unique_ptr< SEPatient > m_InitialPatient
Definition: Controller.h:176
static bool SerializeToString(const PulseController &src, std::string &output, SerializationFormat m)
Definition: PBPulseState.cpp:370
static bool SerializeFromFile(const std::string &filename, PulseController &dst, const SEEngineConfiguration *config=nullptr)
Definition: PBPulseState.cpp:354
virtual const PulseData & GetData() const
Definition: Controller.h:204
Definition: SEGastrointestinalSystem.h:8
Definition: SERespiratorySystem.h:11
Generic ECG machine to assess the heart rhythm.
Definition: ECG.h:13
double m_SpareAdvanceTime_s
Definition: Controller.h:140
std::unique_ptr< SEConditionManager > m_Conditions
Definition: Controller.h:150
std::unique_ptr< PulseCircuits > m_Circuits
Definition: Controller.h:151
Definition: SECardiovascularSystem.h:11
virtual const SEEngineConfiguration * GetConfiguration() const override
returns the engine configuration.
Definition: Engine.cpp:117
Overloaded scenario exector to run a Pulse specific scenario.
Definition: PulseScenarioExec.h:14
Definition: SEActionManager.h:11
std::unique_ptr< PulseCompartments > m_Compartments
Definition: Controller.h:152
Definition: SERenalSystem.h:7
std::unique_ptr< SEActionManager > m_Actions
Definition: Controller.h:149
The Cardiovascular system utilizes circuit methodology to characterize the intravascular fluid dynami...
Definition: Cardiovascular.h:31
std::unique_ptr< Endocrine > m_EndocrineSystem
Definition: Controller.h:158
The Environment class characterizes the environment and manages interactions between the body its sur...
Definition: Environment.h:17
Definition: SEScalarTime.h:7
Definition: SETissueSystem.h:7
This is the implementation of the PhysiologyEngine interface for the this engines.
Definition: Engine.h:16
Definition: Endocrine.h:16
std::unique_ptr< PulseConfiguration > m_Config
Definition: Controller.h:144
Definition: SEHepaticSystem.h:7
Definition: Logger.h:21
virtual const SEAnesthesiaMachine * GetAnesthesiaMachine() const override
Returns the current state of the Anesthesia machine.
Definition: Engine.cpp:203
Definition: Hepatic.h:11
This class encapsulates logic necessary to connect independent systems together.
Definition: Tissue.h:22
Manages all compartments and graphs associated with all Pulse systems/equipement. ...
Definition: Compartments.h:11
std::unique_ptr< ECG > m_ECG
Definition: Controller.h:168
Definition: SEConditionManager.h:24
virtual const SEInhaler * GetInhaler() const override
Returns the current state of the Inhaler.
Definition: Engine.cpp:213
Definition: SEPatientConfiguration.h:11
Definition: SEBloodChemistrySystem.h:9
Generic mechanical ventilator for positive pressure ventilation.
Definition: MechanicalVentilator.h:19
std::unique_ptr< Nervous > m_NervousSystem
Definition: Controller.h:162
virtual const SEPatient & GetInitialPatient() const override
Returns the initial simulation patient object used by the engine.
Definition: Engine.cpp:127
std::unique_ptr< AnesthesiaMachine > m_AnesthesiaMachine
Definition: Controller.h:170
The SaturationCalculator class holds the blood gas distribution model.
Definition: Saturation.h:15
std::string m_DataDir
Definition: Controller.h:183
virtual void SetAdvanceHandler(SEAdvanceHandler *handler)
Definition: Controller.h:127
static bool SerializeToFile(const PulseController &src, const std::string &filename)
Definition: PBPulseState.cpp:363
std::unique_ptr< BloodChemistry > m_BloodChemistrySystem
Definition: Controller.h:156
Definition: SEEventManager.h:107
virtual eSwitch GetIntubation() const
Definition: Controller.h:124
std::unique_ptr< MechanicalVentilator > m_MechanicalVentilator
Definition: Controller.h:174
virtual double GetTimeStep(const TimeUnit &unit) const override
returns the engine time step that is used when advancing time.
Definition: Engine.cpp:73
PulseStabilizationController(PulseController &pc)
Definition: Controller.h:264
virtual PulseData & GetData()
Definition: Controller.h:203
Definition: BloodChemistry.h:20
Definition: PBPulseState.h:9
Manages all circuits associated with all Pulse systems/equipement.
Definition: Circuits.h:13
Definition: SEEnergySystem.h:7
eAirwayMode m_AirwayMode
Definition: Controller.h:141
PulseController & _pc
Definition: Controller.h:278
Data formed at a level of a clinicians report. This is high level data, such as a mean or generalized...
Definition: SEPatientAssessment.h:21
Generic anesthesia machine for positive pressure ventilation.
Definition: AnesthesiaMachine.h:17
std::unique_ptr< SEPatient > m_CurrentPatient
Definition: Controller.h:177
Definition: SEEndocrineSystem.h:7
virtual EngineState GetState() const
Definition: Controller.h:76
Definition: Energy.h:18
Definition: SEScalarTime.h:23
std::unique_ptr< Tissue > m_TissueSystem
Definition: Controller.h:166
std::unique_ptr< Hepatic > m_HepaticSystem
Definition: Controller.h:161
Definition: EngineTest.h:28
Definition: SEEnvironment.h:12
std::unique_ptr< Inhaler > m_Inhaler
Definition: Controller.h:172
Definition: SEAdvanceHandler.h:7
virtual const SECompartmentManager & GetCompartments() const override
Retrieves the engine compartments, providing such data as: flows, pressure, volume as well as substan...
Definition: Engine.cpp:223
std::unique_ptr< SaturationCalculator > m_SaturationCalculator
Definition: Controller.h:145
The drug system contains the physiologically based pharmacokinetic (PBPK) model and the pharmacodynam...
Definition: Drugs.h:18
virtual SEEngineTracker * GetEngineTracker() const override
Retrieve the SEEngineTracker associated with tracking data from this engine to a file The SEEngineTra...
Definition: Engine.cpp:62
Definition: Renal.h:20
virtual void SetDataRoot(const std::string &dir)
Definition: Controller.h:72
Manages and initializes all systems with substances needed by Pulse.
Definition: Substances.h:31
Definition: SEDrugSystem.h:8
Pulse specific configuration parameters for all systems/equipment
Definition: PulseConfiguration.h:18
PulseStabilizationController * m_Stabilizer
Definition: Controller.h:258
SEEngineTracker * m_EngineTrack
Definition: Controller.h:135
Definition: Gastrointestinal.h:14
EngineState m_State
Definition: Controller.h:134
DataTrack * m_DataTrack
Definition: Controller.h:136
virtual const SEEnvironment * GetEnvironment() const override
Returns the environment object used by the engine.
Definition: Engine.cpp:138
SEScalarTime m_SimulationTime
Definition: Controller.h:139
std::unique_ptr< Energy > m_EnergySystem
Definition: Controller.h:159
virtual SEEngineTracker * GetEngineTracker() override
Definition: Controller.h:268
std::vector< SEScalarProperty > m_ScalarOverrides
Definition: Controller.h:185
std::unique_ptr< Drugs > m_DrugSystem
Definition: Controller.h:165

Distributed under the Apache License, Version 2.0.

See accompanying NOTICE file for details.