6#include "engine/CommonDefs.h"
7#include "engine/PulseConfiguration.h"
8#include "engine/common/controller/BlackBoxManager.h"
9#include "engine/common/controller/CircuitManager.h"
10#include "engine/common/controller/CompartmentManager.h"
11#include "engine/common/controller/SubstanceManager.h"
19#include "cdm/engine/SEEventManager.h"
20#include "cdm/engine/SEEngineStabilization.h"
21#include "cdm/properties/SEScalarTime.h"
25 class StabilizationController;
28 class EnvironmentModel;
30 class BloodChemistryModel;
31 class CardiovascularModel;
34 class GastrointestinalModel;
38 class RespiratoryModel;
42 class AnesthesiaMachineModel;
43 class BagValveMaskModel;
45 class ElectroCardioGramModel;
47 class MechanicalVentilatorModel;
49 class SaturationCalculator;
51 enum class EngineState
57 SecondaryStabilization,
58 AtSecondaryStableState,
64 enum class eAirwayMode
70 MechanicalVentilation,
78 class PULSE_DECL Data :
public Loggable
82 Data(
Logger* logger =
nullptr);
86 virtual std::string GetDataRoot()
const {
return m_DataDir; }
87 virtual void SetDataRoot(
const std::string& dir) { m_DataDir = dir; }
89 virtual void AdvanceCallback(
double time_s);
91 virtual EngineState GetState()
const {
return m_State; }
95 virtual SaturationCalculator& GetSaturationCalculator()
const;
97 virtual SubstanceManager& GetSubstances()
const;
99 virtual const SEPatient& GetInitialPatient()
const;
100 virtual SEPatient& GetCurrentPatient()
const;
102 virtual bool HasBloodChemistry()
const;
104 virtual bool HasCardiovascular()
const;
106 virtual bool HasDrugs()
const;
108 virtual bool HasEndocrine()
const;
110 virtual bool HasEnergy()
const;
112 virtual bool HasGastrointestinal()
const;
114 virtual bool HasHepatic()
const;
116 virtual bool HasNervous()
const;
118 virtual bool HasRenal()
const;
120 virtual bool HasRespiratory()
const;
122 virtual bool HasTissue()
const;
125 virtual bool HasEnvironment()
const;
127 virtual bool HasAnesthesiaMachine()
const;
129 virtual bool HasBagValveMask()
const;
131 virtual bool HasECG()
const;
133 virtual bool HasECMO()
const;
134 virtual SEECMO& GetECMO()
const;
135 virtual bool HasInhaler()
const;
137 virtual bool HasMechanicalVentilator()
const;
146 virtual CircuitManager& GetCircuits()
const;
148 virtual CompartmentManager& GetCompartments()
const;
150 virtual BlackBoxManager& GetBlackBoxes()
const;
154 virtual double GetTimeStep_s()
const;
158 virtual const SEScalarTime& GetStabilizationTime()
const;
160 virtual bool IsAirwayModeSupported(eAirwayMode ) {
return true; }
161 virtual eAirwayMode GetAirwayMode()
const {
return m_AirwayMode; }
162 virtual void SetAirwayMode(eAirwayMode mode);
164 virtual eSwitch GetIntubation()
const {
return m_Intubation; }
166 virtual void SetAdvanceHandler(
SEAdvanceHandler* handler) { m_AdvanceHandler = handler; }
168 virtual const SEScalarProperties& GetOverrides()
const;
170 std::stringstream m_ss;
172 virtual void SetupTracker();
177 eEngineInitializationState m_EngineInitializationState;
182 double m_SpareAdvanceTime_s;
183 eAirwayMode m_AirwayMode;
184 eSwitch m_Intubation;
187 SaturationCalculator* m_SaturationCalculator =
nullptr;
189 SubstanceManager* m_Substances =
nullptr;
193 CircuitManager* m_Circuits =
nullptr;
194 CompartmentManager* m_Compartments =
nullptr;
195 BlackBoxManager* m_BlackBoxes =
nullptr;
197 EnvironmentModel* m_EnvironmentModel =
nullptr;
199 BloodChemistryModel* m_BloodChemistryModel =
nullptr;
200 CardiovascularModel* m_CardiovascularModel =
nullptr;
201 EndocrineModel* m_EndocrineModel =
nullptr;
202 EnergyModel* m_EnergyModel =
nullptr;
203 GastrointestinalModel* m_GastrointestinalModel =
nullptr;
204 HepaticModel* m_HepaticModel =
nullptr;
205 NervousModel* m_NervousModel =
nullptr;
206 RenalModel* m_RenalModel =
nullptr;
207 RespiratoryModel* m_RespiratoryModel =
nullptr;
208 DrugModel* m_DrugModel =
nullptr;
209 TissueModel* m_TissueModel =
nullptr;
211 AnesthesiaMachineModel* m_AnesthesiaMachineModel =
nullptr;
212 BagValveMaskModel* m_BagValveMaskModel =
nullptr;
213 ECMOModel* m_ECMOModel =
nullptr;
214 ElectroCardioGramModel* m_ElectroCardioGramModel =
nullptr;
215 InhalerModel* m_InhalerModel =
nullptr;
216 MechanicalVentilatorModel* m_MechanicalVentilatorModel =
nullptr;
226 std::string m_DataDir;
228 SEScalarProperties m_ScalarOverrides;
230 std::vector<pulse::Model*> m_Models;
236 class PULSE_DECL Controller :
public Data
239 friend class EngineTest;
240 friend class PBState;
242 Controller(
Logger* logger =
nullptr);
244 virtual ~Controller();
246 virtual Data& GetData() {
return (*
this); }
247 virtual const Data& GetData()
const {
return (*
this); }
249 virtual bool SerializeFromFile(
const std::string& file);
250 virtual bool SerializeToFile(
const std::string& file)
const;
252 virtual bool SerializeFromString(
const std::string& state, eSerializationFormat m);
253 virtual bool SerializeToString(std::string& state, eSerializationFormat m)
const;
255 virtual bool InitializeEngine(
const std::string& patient_configuration, eSerializationFormat m);
257 virtual bool IsReady()
const;
258 virtual eEngineInitializationState GetInitializationState()
const;
260 virtual void Clear();
264 virtual void SetSimulationTime(
const SEScalarTime& time);
266 virtual bool AdvanceModelTime();
267 virtual bool AdvanceModelTime(
double time,
const TimeUnit& unit);
268 virtual bool ProcessAction(
const SEAction& action);
272 virtual bool CreateCircuitsAndCompartments();
274 virtual void CheckIntubation();
276 virtual std::string GetTypeName()
const = 0;
277 virtual void LogBuildInfo()
const;
281 virtual void SetupCardiovascular();
282 virtual void SetupRenal();
283 virtual void SetupTissue();
284 virtual void SetupCerebrospinalFluid();
287 virtual void SetupExpandedCardiovascular();
288 virtual void SetupExpandedCardiovascularRenal();
289 virtual void SetupExpandedCardiovascularTissue();
290 virtual void SetupExpandedCardiovascularCerebrospinalFluid();
293 virtual void SetupGastrointestinal();
296 virtual void SetupRespiratory();
299 virtual void SetupExpandedPulmonaryRespiratory();
300 virtual void SetupExpandedPulmonaryCardiovascular();
303 virtual void SetupAnesthesiaMachine();
304 virtual void SetupBagValveMask();
305 virtual void SetupECMO();
306 virtual void SetupInhaler();
307 virtual void SetupMechanicalVentilation();
308 virtual void SetupMechanicalVentilator();
309 virtual void SetupNasalCannula();
310 virtual void SetupSimpleMask();
311 virtual void SetupNonRebreatherMask();
314 virtual void SetupExternalTemperature();
315 virtual void SetupInternalTemperature();
317 virtual bool OverrideCircuits();
318 virtual bool ModifyCircuits(
const SEScalarProperties& modifiers);
320 virtual bool Initialize(
const SEPatient& patient);
324 virtual void Allocate();
325 virtual bool SetupPatient(
const SEPatient& patient) = 0;
327 virtual void InitializeModels();
329 virtual void AtSteadyState(EngineState state);
330 virtual void PreProcess();
331 virtual void Process();
332 virtual void PostProcess();
335 StabilizationController *m_Stabilizer =
nullptr;
341 StabilizationController(pulse::Controller& pc) : _pc(pc) {}
342 virtual ~StabilizationController() =
default;
344 bool AdvanceTime()
override {
return _pc.AdvanceModelTime(); }
347 return &_pc.GetData().GetEngineTracker();
349 double GetTimeStep(
const TimeUnit& unit)
override
351 return _pc.GetData().GetTimeStep().
GetValue(unit);
353 double GetSimulationTime(
const TimeUnit& unit)
override
355 return _pc.GetData().GetSimulationTime().GetValue(unit);
359 pulse::Controller& _pc;
366 ~FatalListner() =
default;
368 void ForwardDebug(
const std::string& )
override { }
369 void ForwardInfo(
const std::string& )
override { }
370 void ForwardWarning(
const std::string& )
override { }
371 void ForwardError(
const std::string& )
override { }
372 void ForwardFatal(
const std::string& )
override
374 m_Events.SetEvent(eEvent::IrreversibleState,
true, m_CurrentTime);
Definition: DataTrack.h:17
Pulse specific configuration parameters for all systems/equipment
Definition: PulseConfiguration.h:20
Definition: SEAction.h:14
Definition: SEActionManager.h:12
Definition: SEAdvanceHandler.h:8
Definition: SEAnesthesiaMachine.h:24
Definition: SEBagValveMask.h:14
Definition: SEBloodChemistrySystem.h:10
Definition: SECardiovascularSystem.h:24
Definition: SEConditionManager.h:26
Definition: SEDataRequested.h:11
Definition: SEDrugSystem.h:9
Definition: SEElectroCardioGram.h:9
Definition: SEEndocrineSystem.h:8
Definition: SEEnergySystem.h:8
Definition: SEEngineConfiguration.h:8
Definition: SEEngineStabilization.h:18
Definition: SEEngineTracker.h:66
double GetValue(const SEDataRequest &dr) const
Definition: SEEngineTracker.cpp:131
Definition: SEEnvironment.h:13
Definition: SEEventManager.h:117
Definition: SEGastrointestinalSystem.h:9
Definition: SEHepaticSystem.h:8
Definition: SEInhaler.h:12
Definition: SEMechanicalVentilator.h:10
Definition: SENervousSystem.h:9
Data formed at a level of a clinicians report. This is high level data, such as a mean or generalized...
Definition: SEPatientAssessment.h:22
Definition: SEPatientConfiguration.h:11
Definition: SEPatient.h:13
Definition: SERenalSystem.h:8
Definition: SERespiratorySystem.h:25
Definition: SEScalarTime.h:28
Definition: SETissueSystem.h:8
Definition: SEScalarTime.h:8
const std::string & eAirwayMode_Name(eAirwayMode m)
Definition: PBEnums.cpp:12
Definition: PulseEngine.h:23