SubstanceManager.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#include "cdm/substance/SESubstanceManager.h"
10
11namespace pulse
12{
13 class Data;
14 class PULSE_DECL SizeIndependentDepositionEfficencyCoefficient
15 {
16 friend class SubstanceManager;
17 public:
18 SizeIndependentDepositionEfficencyCoefficient() {};
19 ~SizeIndependentDepositionEfficencyCoefficient() {}
20
21 double GetAirway() const { return m_airway; }
22 double GetCarina() const { return m_carina; }
23 double GetDeadSpace() const { return m_deadSpace; }
24 double GetAlveoli() const { return m_alveoli; }
25
26 protected:
27 double m_airway = 0;
28 double m_carina = 0;
29 double m_deadSpace = 0;
30 double m_alveoli = 0;
31 };
32
36 class PULSE_DECL SubstanceManager : public SESubstanceManager
37 {
38 friend class EngineTest;
39 public:
40 SubstanceManager(Data& data);
41 virtual ~SubstanceManager() = default;
42
43 void Clear() override;
44 bool LoadSubstanceDirectory(const std::string& data_dir = ".") override;
45
46 virtual bool Setup();
47 virtual void InitializeSubstances();
48
49 virtual void AddActiveSubstance(const SESubstance& substance) override;
50 virtual bool IsActive(const SESubstance& sub) const override;
51
52 inline SESubstance& GetO2() { return *m_O2; }
53 inline SESubstance& GetCO() { return *m_CO; }
54 inline SESubstance& GetCO2() { return *m_CO2; }
55 inline SESubstance& GetN2() { return *m_N2; }
56 inline SESubstance& GetHb() { return *m_Hb; }
57 inline SESubstance& GetHbO2() { return *m_HbO2; }
58 inline SESubstance& GetHbCO2() { return *m_HbCO2; }
59 inline SESubstance& GetHbCO() { return *m_HbCO; }
60 inline SESubstance& GetHbO2CO2() { return *m_HbO2CO2; }
61 inline SESubstance& GetHCO3() { return *m_HCO3; }
62 inline SESubstance& GetEpi() { return *m_epi; }
63 inline SESubstance& GetNorepi() { return *m_norepi; }
64
65 inline SESubstance& GetAcetoacetate() { return *m_acetoacetate; }
66 inline SESubstance& GetAlbumin() { return *m_albumin; }
67 inline SESubstance& GetBicarbonate() { return *m_HCO3; }
68 inline SESubstance& GetCalcium() { return *m_calcium; }
69 inline SESubstance& GetChloride() { return *m_chloride; }
70 inline SESubstance& GetCreatinine() { return *m_creatinine; }
71 inline SESubstance& GetGlobulin() { return *m_globulin; }
72 inline SESubstance& GetGlucose() { return *m_glucose; }
73 inline SESubstance& GetInsulin() { return *m_insulin; }
74 inline SESubstance& GetLactate() { return *m_lactate; }
75 inline SESubstance& GetPotassium() { return *m_potassium; }
76 inline SESubstance& GetTristearin() { return *m_tristearin; }
77 inline SESubstance& GetSodium() { return *m_sodium; }
78 inline SESubstance& GetUrea() { return *m_urea; }
79
80 void CalculateGenericClearance(double volumeCleared_mL, SELiquidCompartment& cmpt, SESubstance& sub, SEScalarMass* cleared = nullptr);
81 void CalculateGenericClearance(double volumeCleared_mL, SETissueCompartment& cmpt, SESubstance& sub, SEScalarMass* cleared = nullptr);
82 void CalculateGenericExcretion(double VascularFlow_mL_Per_s, SETissueCompartment& cmpt, SESubstance& sub, double FractionExcreted, double timestep_s, SEScalarMass* excreted = nullptr);
83
84 const SizeIndependentDepositionEfficencyCoefficient& GetSizeIndependentDepositionEfficencyCoefficient(const SESubstance& substance);
85
86 double GetSubstanceMass(SESubstance&, const std::vector<SELiquidCompartment*>&, const MassUnit& unit);
87 double GetSubstanceMass(SESubstance&, const std::vector<SETissueCompartment*>&, const MassUnit& unit);
88
89 void WriteBloodGases();
90 void WritePulmonaryGases();
91 void ProbeBloodGases(SELiquidCompartment& cmpt, const std::string& prefix = "");
92
93 virtual void InitializeGasCompartments();
94 virtual void InitializeLiquidCompartmentGases();
95 virtual void InitializeLiquidCompartmentNonGases();
96
97 protected:
98 virtual void CopyConcentrations(SELiquidCompartment& src, SELiquidCompartment& tgt);
99 virtual void InitializeBloodGases(SETissueCompartment& tissue, SELiquidCompartment& vascular);
100 virtual void InitializeBloodGases(SELiquidCompartment& cmpt, double Hb_total_mM, double O2_sat, double O2_mmol_Per_L, double CO2_sat, double CO2_mmol_Per_L, double HCO3_mmol_Per_L, double pH, bool distribute = true);
101
102 void SetSubstanceMolarity(SESubstance&, const std::vector<SELiquidCompartment*>&, const SEScalarAmountPerVolume& molarity);
103 void SetSubstanceMolarity(SESubstance&, const std::vector<SETissueCompartment*>&, const SEScalarAmountPerVolume& molarity);
104 void SetSubstanceMolarity(SESubstance&, const std::vector<SETissueCompartment*>&, const SEScalarAmountPerVolume& extracellular, const SEScalarAmountPerVolume& intracellular);
105
106 void SetSubstanceConcentration(SESubstance&, const std::vector<SELiquidCompartment*>&, const SEScalarMassPerVolume& concentration);
107 void SetSubstanceConcentration(SESubstance&, const std::vector<SETissueCompartment*>&, const SEScalarMassPerVolume& concentration);
108 void SetSubstanceConcentration(SESubstance&, const std::vector<SETissueCompartment*>&, const SEScalarMassPerVolume& extracellular, const SEScalarMassPerVolume& intracellular);
109
110 // Common Substances
111 //Substances
112 SESubstance* m_O2;
113 SESubstance* m_CO;
114 SESubstance* m_CO2;
115 SESubstance* m_N2;
116 SESubstance* m_Hb;
117 SESubstance* m_HbO2;
118 SESubstance* m_HbCO2;
119 SESubstance* m_HbCO;
120 SESubstance* m_HbO2CO2;
121 SESubstance* m_HCO3;
122 SESubstance* m_epi;
123 SESubstance* m_norepi;
124
125 SESubstance* m_acetoacetate;
126 SESubstance* m_albumin;
127 SESubstance* m_calcium;
128 SESubstance* m_chloride;
129 SESubstance* m_creatinine;
130 SESubstance* m_globulin;
131 SESubstance* m_glucose;
132 SESubstance* m_insulin;
133 SESubstance* m_lactate;
134 SESubstance* m_tristearin;
135 SESubstance* m_potassium;
136 SESubstance* m_sodium;
137 SESubstance* m_urea;
138
139 bool m_isCOActive;
140
141 std::map<const SESubstance*, SizeIndependentDepositionEfficencyCoefficient*> m_SIDECoefficients;
142
143 Data& m_data;
144 };
145END_NAMESPACE
Definition: SEScalarMass.h:8
Definition: SELiquidCompartment.h:11
Definition: SEScalarAmountPerVolume.h:31
Definition: SEScalarMass.h:28
Definition: SEScalarMassPerVolume.h:37
Definition: SESubstance.h:15
Definition: SESubstanceManager.h:9
Definition: SETissueCompartment.h:9
Definition: Logger.h:14

Distributed under the Apache License, Version 2.0.

See accompanying NOTICE file for details.