RespiratoryModel.h
1/* Distributed under the Apache License, Version 2.0.
2 See accompanying NOTICE file for details.*/
3
4#pragma once
5
6#include "engine/common/system/Model.h"
7#include "engine/common/system/Systems.h"
8#include "cdm/circuit/fluid/SEFluidCircuitCalculator.h"
9#include "cdm/compartment/fluid/SEGasCompartmentGraph.h"
10#include "cdm/compartment/fluid/SELiquidCompartmentGraph.h"
11
12class SEPatient;
18class SEFluidCircuit;
23
24namespace pulse
25{
26 class PBPhysiology;
27 class EngineTest;
39 class PULSE_DECL RespiratoryModel : public RespiratorySystem, public Model
40 {
41 friend PBPhysiology;//friend the serialization class
42 friend EngineTest;
43 public:
44 RespiratoryModel(Data& data);
45 virtual ~RespiratoryModel();
46
47 virtual void Clear() override;
48
49 // Set members to a stable homeostatic state
50 virtual void Initialize() override;
51 // Set pointers and other member varialbes common to both homeostatic initialization and loading a state
52 virtual void SetUp() override;
53
54 virtual void AtSteadyState() override;
55 virtual void PreProcess() override;
56 virtual void Process(bool solve_and_transport=true) override;
57 virtual void PostProcess(bool solve_and_transport=true) override;
58
59 protected:
60 void ComputeExposedModelParameters() override;
61 eLungCompartment GetLungCompartment(const std::string& cmpt);
62 std::string GetCompartmentName(eLungCompartment m);
63
64 //Tuning
65 void TuneCircuit();
66
67 //PreProcess
68 void CalculateWork();
69 void CalculateFatigue();
70 void UpdateChestWallCompliances();
71 void UpdateVolumes();
72 void UpdateResistances();
73 void UpdateAlveolarCompliances();
74 void UpdateInspiratoryExpiratoryRatio();
75 void UpdateDiffusion();
76 void UpdatePulmonaryCapillary();
77 void UpdatePulmonaryShunt();
78 SESegment* GetSegement(const std::vector<SESegment*>& segments, double volume_L);
79 //Overrides
80 void SetRespiratoryResistance();
81 void SetRespiratoryCompliance();
82
83 //Actions
84 void Pneumothorax();
85 void Hemothorax();
86 void MechanicalVentilation();
87 void SupplementalOxygen();
88 // Driver
89 void CalculateDriver();
90 void ApplyDriver();
91 void SetBreathCycleFractions();
92 void ConsciousRespiration();
93 double VolumeToDriverPressure(double TargetVolume);
94 void UpdateDriverPressure();
95 /****/void CalculateMechanoreceptors();
96 void UpdateDriverPeriod();
97 double UpdateTargetVentilation(double targetAlveolarVentilation_L_Per_min);
98 // Aerosol Deposition and various Effects
99 void ProcessAerosolSubstances();
100
101 //Process
102 void CalculateVitalSigns();
103 void Debugging();
104
105 // Serializable member variables (Set in Initialize and in schema)
106
107 // CalculateVitalSigns()
108 bool m_BreathingCycle;
109 bool m_NotBreathing;
110 double m_TopBreathTotalVolume_L;
111 double m_TopCarinaO2;
112 double m_TopBreathElapsedTime_min;
113 double m_BottomBreathElapsedTime_min;
114 double m_BottomBreathTotalVolume_L;
115 double m_BottomBreathAlveoliPressure_cmH2O;
116 double m_BottomBreathAirwayPressure_cmH2O;
117 double m_PeakAlveolarPressure_cmH2O;
118 double m_MaximalAlveolarPressure_cmH2O;
119 double m_LastCardiacCycleBloodPH;
120 SERunningAverage* m_BloodPHRunningAverage;
121 SERunningAverage* m_MeanAirwayPressure_cmH2O;
122
123 // Expanded pulmonary methodology
124 std::vector<double> m_AlveoliVolumeIncrement_L;
125 std::vector<double> m_TopBreathAcinarZoneVolumes_L;
126 std::vector<double> m_BottomBreathAcinarZoneVolumes_L;
127 double m_PreviousPleuralVolume_L;
128
129 // Respiratory Driver
130 double m_ArterialO2PartialPressure_mmHg;
131 double m_ArterialCO2PartialPressure_mmHg;
132 double m_BreathingCycleTime_s;
133 double m_DriverPressure_cmH2O;
134 double m_ElapsedBreathingCycleTime_min;
135 double m_IERatioScaleFactor;
136 double m_PeakInspiratoryPressure_cmH2O;
137 double m_PeakExpiratoryPressure_cmH2O;
138 double m_PreviousTargetAlveolarVentilation_L_Per_min;
139 double m_VentilationFrequency_Per_min;
140 double m_VentilationPeriod_s;
141 double m_VentilationToTidalVolumeSlope;
142 SERunningAverage* m_ArterialO2RunningAverage_mmHg;
143 SERunningAverage* m_ArterialCO2RunningAverage_mmHg;
144
145 // Muscle Pressure Waveform
146 double m_ExpiratoryHoldFraction;
147 double m_ExpiratoryReleaseFraction;
148 double m_ExpiratoryRiseFraction;
149 double m_InspiratoryHoldFraction;
150 double m_InspiratoryReleaseFraction;
151 double m_InspiratoryRiseFraction;
152 double m_InspiratoryToExpiratoryPauseFraction;
153 double m_ResidueFraction;
154 double m_PreviousDyspneaSeverity;
155 double m_MechanoreceptorsDyspneaFactor;
156
157 // Conscious Respiration
158 bool m_ActiveConsciousRespirationCommand;
159
160 // Disease States
161 double m_LeftAlveoliDecrease_L;
162 double m_RightAlveoliDecrease_L;
163
164 // Overrides
165 double m_RespiratoryResistanceOverride_cmH2O_s_Per_L;
166 double m_RespiratoryComplianceOverride_L_Per_cmH2O;
167
168 // Stateless member variable (Set in SetUp())
169 SERespiratoryMechanicsModifiers* m_MechanicsModifiers;
170 // Respiratory Driver
171 double m_MaxDriverPressure_cmH2O;
172 // Configuration parameters
173 double m_CentralControlGainConstant;
174 double m_DefaultOpenResistance_cmH2O_s_Per_L;
175 double m_DefaultClosedResistance_cmH2O_s_Per_L;
176 double m_PeripheralControlGainConstant;
177 double m_RespOpenResistance_cmH2O_s_Per_L;
178 double m_RespClosedResistance_cmH2O_s_Per_L;
179 double m_VentilationTidalVolumeIntercept;
180 double m_VentilatoryOcclusionPressure_cmH2O;
181 double m_MinimumAllowableTidalVolume_L;
182 double m_MinimumAllowableInpiratoryAndExpiratoryPeriod_s;
183 // State between functions (i.e. shared between methods in preprocess, set to a default value at the start of preprocess)
184 double m_AverageLocalTissueBronchodilationEffects;
185
186 // Patient
187 SEPatientActionCollection* m_PatientActions;
188
189 // Compartments
190 SEGasCompartment* m_Environment;
191 SEGasCompartment* m_Lungs;
192 SEGasCompartment* m_LeftAlveoli;
193 SEGasCompartment* m_RightAlveoli;
194 SEGasCompartment* m_PleuralCavity;
195 SEGasCompartment* m_LeftPleuralCavity;
196 SEGasCompartment* m_RightPleuralCavity;
197 SEGasCompartment* m_Carina;
198 SEGasCompartment* m_LeftLung;
199 SEGasCompartment* m_RightLung;
200 SEGasCompartment* m_AnatomicDeadSpace;
201 SEGasCompartment* m_AlveolarDeadSpace;
202 SEGasCompartment* m_RightAlveolarDeadSpace;
203 SEGasCompartment* m_LeftAlveolarDeadSpace;
204 SEGasCompartment* m_Alveoli;
205 SEGasSubstanceQuantity* m_CarinaO2;
206 SEGasSubstanceQuantity* m_LeftAlveoliO2;
207 SEGasSubstanceQuantity* m_RightAlveoliO2;
208 // Mechanical Ventilation
209 SEGasCompartment* m_MechanicalVentilationConnection;
210 SELiquidCompartment* m_MechanicalVentilationAerosolConnection;
211 // Aerosol
212 SELiquidCompartment* m_AerosolAirway;
213 SELiquidCompartment* m_AerosolCarina;
214 SELiquidCompartment* m_AerosolLeftAnatomicDeadSpace;
215 SELiquidCompartment* m_AerosolLeftAlveolarDeadSpace;
216 SELiquidCompartment* m_AerosolLeftAlveoli;
217 SELiquidCompartment* m_AerosolRightAnatomicDeadSpace;
218 SELiquidCompartment* m_AerosolRightAlveolarDeadSpace;
219 SELiquidCompartment* m_AerosolRightAlveoli;
220 std::vector<SELiquidCompartment*> m_AerosolEffects;
221 SELiquidCompartment* m_LeftLungExtravascular;
222 SELiquidCompartment* m_RightLungExtravascular;
223 // Cardiovascular
224 SELiquidCompartment* m_LeftPulmonaryCapillaries;
225 SELiquidCompartment* m_RightPulmonaryCapillaries;
226 SELiquidSubstanceQuantity* m_AortaO2;
227 SELiquidSubstanceQuantity* m_AortaCO2;
228
229 // Circuits
230 SEFluidCircuit* m_RespiratoryCircuit;
231
232 // These are the components we will iterate on for actions
233 struct LungComponent
234 {
235 eSide Side;
236 SEFluidCircuitNode* AlveoliNode;
237 SEFluidCircuitNode* DeadSpaceNode;
238 SEFluidCircuitPath* ResistancePath;
239 SEFluidCircuitPath* CompliancePath;
240 SEFluidCircuitPath* ShuntPath;
241 SEFluidCircuitPath* CapillaryPath;
242 SEGasCompartment* AlveoliCompartment;
243 SELiquidCompartment* CapillaryCompartment;
244 };
245 std::map<eLungCompartment, LungComponent> m_LungComponents;
246 // Nodes
247 SEFluidCircuitNode* m_AirwayNode;
248 SEFluidCircuitNode* m_LeftPleuralNode;
249 SEFluidCircuitNode* m_RespiratoryMuscleNode;
250 SEFluidCircuitNode* m_RightPleuralNode;
251 SEFluidCircuitNode* m_AmbientNode;
252 SEFluidCircuitNode* m_StomachNode;
253 // Paths
254 SEFluidCircuitPath* m_CarinaToLeftAnatomicDeadSpace; // base only
255 SEFluidCircuitPath* m_CarinaToRightAnatomicDeadSpace; // base only
256 SEFluidCircuitPath* m_LeftAnatomicDeadSpaceToLeftAlveolarDeadSpace; // base only
257 SEFluidCircuitPath* m_RightAnatomicDeadSpaceToRightAlveolarDeadSpace; // base only
258 SEFluidCircuitPath* m_LeftAlveolarDeadSpaceToLeftAlveoli; // base only
259 SEFluidCircuitPath* m_RightAlveolarDeadSpaceToRightAlveoli; // base only
260
261 SEFluidCircuitPath* m_LeftPleuralToRespiratoryMuscle;
262 SEFluidCircuitPath* m_RightPleuralToRespiratoryMuscle;
263 SEFluidCircuitPath* m_DriverPressurePath;
264 SEFluidCircuitPath* m_AirwayToPharynx;
265 SEFluidCircuitPath* m_PharynxToEnvironment;
266 SEFluidCircuitPath* m_PharynxToCarina;
267 SEFluidCircuitPath* m_AirwayToStomach;
268 SEFluidCircuitPath* m_EnvironmentToLeftChestLeak;
269 SEFluidCircuitPath* m_EnvironmentToRightChestLeak;
270 SEFluidCircuitPath* m_LeftAlveoliLeakToLeftPleural;
271 SEFluidCircuitPath* m_RightAlveoliLeakToRightPleural;
272 SEFluidCircuitPath* m_LeftNeedleToLeftPleural;
273 SEFluidCircuitPath* m_RightNeedleToRightPleural;
274 SEFluidCircuitPath* m_LeftPulmonaryCapillary;
275 SEFluidCircuitPath* m_RightPulmonaryCapillary;
276 SEFluidCircuitPath* m_ConnectionToAirway;
277 SEFluidCircuitPath* m_GroundToConnection;
278
279 SEFluidCircuitPath* m_LeftCardiovascularLeak;
280 SEFluidCircuitPath* m_RightCardiovascularLeak;
281 SEFluidCircuitPath* m_LeftRespirtoryLeak;
282 SEFluidCircuitPath* m_RightRespirtoryLeak;
283
284 SEFluidCircuitPath* m_LeftAlveoliToLeftPleuralConnection;
285 SEFluidCircuitPath* m_RightAlveoliToRightPleuralConnection;
286
287 SEFluidCircuitCalculator* m_Calculator;
288 SEGasTransporter* m_GasTransporter;
289 SELiquidTransporter* m_AerosolTransporter;
290
291 // Substance
292 SESubstance* m_Oversedation;
293 };
294END_NAMESPACE
Definition: PBPhysiology.h:24
Definition: SECircuitCalculator.h:24
Definition: SEConsciousRespirationCommand.h:8
Definition: SEFluidCircuit.h:12
Definition: SEFluidCircuitNode.h:10
Definition: SEFluidCircuitPath.h:9
Definition: SEGasCompartment.h:14
Definition: SEGasSubstanceQuantity.h:10
Definition: SELiquidCompartment.h:11
Definition: SELiquidSubstanceQuantity.h:12
Definition: SEPatientActionCollection.h:50
Definition: SEPatient.h:13
Definition: SERespiratoryMechanicsModifiers.h:9
Definition: SERunningAverage.h:8
Definition: SESegment.h:7
Definition: SESubstance.h:15
Definition: SESubstanceTransport.h:86
Definition: Logger.h:14

Distributed under the Apache License, Version 2.0.

See accompanying NOTICE file for details.