Building Medical Digital Twins with Pulse: Open Source Simulation Tools for Developers and Researchers
×
Saturation.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/CommonDefs.h"
7 
8 class SESubstance;
12 
13 namespace pulse
14 {
19  class PULSE_DECL SaturationCalculator : public Loggable
20  {
21  struct CompartmentState
22  {
23  SELiquidSubstanceQuantity* subO2Q = nullptr;
24  SELiquidSubstanceQuantity* subCO2Q = nullptr;
25  SELiquidSubstanceQuantity* subCOQ = nullptr;
26  SELiquidSubstanceQuantity* subHbCOQ = nullptr;
27  SELiquidSubstanceQuantity* subHCO3Q = nullptr;
28  SELiquidSubstanceQuantity* subHbQ = nullptr;
29  SELiquidSubstanceQuantity* subHbO2Q = nullptr;
30  SELiquidSubstanceQuantity* subHbCO2Q = nullptr;
31  SELiquidSubstanceQuantity* subHbO2CO2Q = nullptr;
32  };
33  friend class Controller;
34  friend struct error_functor;
35  friend class EngineTest;
36  public:
37  SaturationCalculator(Data& data);
38  virtual ~SaturationCalculator();
39 
40  bool Setup();
41 
42  void SetBodyState(const SEScalarMassPerVolume& AlbuminConcentration, const SEScalar0To1& Hematocrit, const SEScalarTemperature& Temperature, const SEScalarAmountPerVolume& StrongIonDifference, const SEScalarAmountPerVolume& Phosphate);
43  void CalculateBloodGasDistribution(SELiquidCompartment& cmpt) const;
44  void CalculateCarbonMonoxideSpeciesDistribution(CompartmentState& cs, SELiquidCompartment& cmpt) const;
45 
46  protected:
47  // Stewart Model + Dash-Bassingthwaighte Model + Henderson-Hasselbach Model
48  void CalculateHemoglobinSaturations(CompartmentState& cs, double O2PartialPressureGuess_mmHg, double CO2PartialPressureGuess_mmHg, double pH, double temperature_C, double hematocrit, double& OxygenSaturation, double& CarbonDioxideSaturation, double CO2_scaling_factor) const;
49  bool DistributeHemoglobinBySaturation(CompartmentState& cs) const;
50 
51  Data& m_data;
52  std::stringstream ss;
53  // All properties are stateless and are set by either the Initialize method or SetBodyState method
54  SESubstance* m_O2;
55  SESubstance* m_Hb;
56  SESubstance* m_HbO2;
57  SESubstance* m_HbO2CO2;
58  SESubstance* m_CO2;
59  SESubstance* m_CO;
60  SESubstance* m_HbCO;
61  SESubstance* m_HCO3;
62  SESubstance* m_HbCO2;
63  // The current state of the body to balance to
64  double m_albumin_g_per_L;
65  double m_hematocrit;
66  double m_temperature_C;
67  // Here is the stuff that will need to go into the CDM
68  double m_StrongIonDifference_mmol_Per_L; // BloodChemistrySystemData mmol/L
69  double m_Phosphate_mmol_Per_L; //BloodChemistryData mmol/L
70  };
71 END_NAMESPACE
Definition: Logger.h:23
Definition: SELiquidCompartment.h:11
Definition: SELiquidSubstanceQuantity.h:12
Definition: SEScalar0To1.h:8
Definition: SEScalarAmountPerVolume.h:31
Definition: SEScalarMassPerVolume.h:37
Definition: SEScalarTemperature.h:27
Definition: SESubstance.h:15
Definition: SESubstanceManager.h:9
Definition: Logger.h:14

Distributed under the Apache License, Version 2.0.

See accompanying NOTICE file for details.