SECompartmentManager.h
1 /* Distributed under the Apache License, Version 2.0.
2  See accompanying NOTICE file for details.*/
3 
4 #pragma once
5 
6 class SESubstance;
8 class SECircuitManager;
9 class SECompartment;
10 class SEGasCompartment;
19 
20 // Keep enums in sync with appropriate schema/cdm/CompartmentEnums.proto file !!
21 enum class eCompartment_Type { Electrical = 0, Gas, Liquid, Thermal, Tissue };
22 extern CDM_DECL const std::string& eCompartment_Type_Name(eCompartment_Type m);
23 
24 class CDM_DECL SECompartmentManager : public Loggable
25 {
26  friend class PBCompartment;//friend the serialization class
27 public:
29  virtual ~SECompartmentManager();
30 
31  virtual void Setup();
32  virtual void Clear(); //clear memory
33 
34  virtual void StateChange();// Identify leaves and other bookkeeping
35  virtual void UpdateLinks();
36  virtual void UpdateLinks(SEGasCompartmentGraph& graph);
37  virtual void UpdateLinks(SELiquidCompartmentGraph& graph);
38 
39 
40  virtual bool HasCompartment(eCompartment_Type type, const std::string& name) const;
41  virtual SECompartment* GetCompartment(eCompartment_Type type, const std::string& name);
42  virtual const SECompartment* GetCompartment(eCompartment_Type type, const std::string& name) const;
43 
44  virtual SEGasCompartment& CreateGasCompartment(const std::string& name);
45  virtual void DeleteGasCompartment(const std::string& name);
46  virtual bool HasGasCompartment(const std::string& name) const;
47  virtual SEGasCompartment* GetGasCompartment(const std::string& name);
48  virtual const SEGasCompartment* GetGasCompartment(const std::string& name) const;
49  virtual const std::vector<SEGasCompartment*>& GetGasCompartments();
50  virtual const std::vector<SEGasCompartment*>& GetGasLeafCompartments();
51  virtual SEGasCompartmentLink& CreateGasLink(SEGasCompartment& src, SEGasCompartment& tgt, const std::string& name);
52  virtual void DeleteGasLink(const std::string& name);
53  virtual bool HasGasLink(const std::string& name) const;
54  virtual SEGasCompartmentLink* GetGasLink(const std::string& name);
55  virtual const SEGasCompartmentLink* GetGasLink(const std::string& name) const;
56  virtual const std::vector<SEGasCompartmentLink*>& GetGasLinks();
57  virtual SEGasCompartmentGraph& CreateGasGraph(const std::string& name);
58  virtual void DeleteGasGraph(const std::string& name);
59  virtual bool HasGasGraph(const std::string& name) const;
60  virtual SEGasCompartmentGraph* GetGasGraph(const std::string& name);
61  virtual const SEGasCompartmentGraph* GetGasGraph(const std::string& name) const;
62  virtual const std::vector<SEGasCompartmentGraph*>& GetGasGraphs();
63  virtual void AddGasCompartmentSubstance(SESubstance& sub);
64  virtual const std::vector<SESubstance*>& GetGasCompartmentSubstances() const;
65 
66  virtual SELiquidCompartment& CreateLiquidCompartment(const std::string& name);
67  virtual void DeleteLiquidCompartment(const std::string& name);
68  virtual bool HasLiquidCompartment(const std::string& name) const;
69  virtual SELiquidCompartment* GetLiquidCompartment(const std::string& name);
70  virtual const SELiquidCompartment* GetLiquidCompartment(const std::string& name) const;
71  virtual const std::vector<SELiquidCompartment*>& GetLiquidCompartments();
72  virtual const std::vector<SELiquidCompartment*>& GetLiquidLeafCompartments();
73  virtual SELiquidCompartmentLink& CreateLiquidLink(SELiquidCompartment& src, SELiquidCompartment& tgt, const std::string& name);
74  virtual void DeleteLiquidLink(const std::string& name);
75  virtual bool HasLiquidLink(const std::string& name) const;
76  virtual SELiquidCompartmentLink* GetLiquidLink(const std::string& name);
77  virtual const SELiquidCompartmentLink* GetLiquidLink(const std::string& name) const;
78  virtual const std::vector<SELiquidCompartmentLink*>& GetLiquidLinks();
79  virtual SELiquidCompartmentGraph& CreateLiquidGraph(const std::string& name);
80  virtual void DeleteLiquidGraph(const std::string& name);
81  virtual bool HasLiquidGraph(const std::string& name) const;
82  virtual SELiquidCompartmentGraph* GetLiquidGraph(const std::string& name);
83  virtual const SELiquidCompartmentGraph* GetLiquidGraph(const std::string& name) const;
84  virtual const std::vector<SELiquidCompartmentGraph*>& GetLiquidGraphs();
85  virtual void AddLiquidCompartmentSubstance(SESubstance& sub);
86  virtual const std::vector<SESubstance*>& GetLiquidCompartmentSubstances() const;
87 
88  // Support to track compartment value averages based on the cardiac cycle
89  virtual void SampleByCardiacCyle(bool CycleStart);
90  virtual void SampleByCardiacCyle(SELiquidCompartment&);// Include this cmpt when sampling
91 
92  virtual SEThermalCompartment& CreateThermalCompartment(const std::string& name);
93  virtual void DeleteThermalCompartment(const std::string& name);
94  virtual bool HasThermalCompartment(const std::string& name) const;
95  virtual SEThermalCompartment* GetThermalCompartment(const std::string& name);
96  virtual const SEThermalCompartment* GetThermalCompartment(const std::string& name) const;
97  virtual const std::vector<SEThermalCompartment*>& GetThermalCompartments();
98  virtual const std::vector<SEThermalCompartment*>& GetThermalLeafCompartments();
99  virtual SEThermalCompartmentLink& CreateThermalLink(SEThermalCompartment& src, SEThermalCompartment& tgt, const std::string& name);
100  virtual void DeleteThermalLink(const std::string& name);
101  virtual bool HasThermalLink(const std::string& name) const;
102  virtual SEThermalCompartmentLink* GetThermalLink(const std::string& name);
103  virtual const SEThermalCompartmentLink* GetThermalLink(const std::string& name) const;
104  virtual const std::vector<SEThermalCompartmentLink*>& GetThermalLinks();
105 
106  virtual bool HasTissueCompartment(const std::string& name) const;
107  virtual void DeleteTissueCompartment(const std::string& name);
108  virtual SETissueCompartment& CreateTissueCompartment(const std::string& name);
109  virtual SETissueCompartment* GetTissueCompartment(const std::string& name);
110  virtual const SETissueCompartment* GetTissueCompartment(const std::string& name) const;
111  virtual const std::vector<SETissueCompartment*>& GetTissueCompartments();
112  virtual const std::vector<SETissueCompartment*>& GetTissueLeafCompartments();
113 
114 protected:
115  std::vector<SEGasCompartment*> m_GasCompartments;
116  std::vector<SEGasCompartment*> m_GasLeafCompartments;
117  std::map<std::string, SEGasCompartment*> m_GasName2Compartments;
118  std::vector<SEGasCompartmentLink*> m_GasLinks;
119  std::map<std::string, SEGasCompartmentLink*> m_GasName2Links;
120  std::vector<SEGasCompartmentGraph*> m_GasGraphs;
121  std::map<std::string, SEGasCompartmentGraph*> m_GasName2Graphs;
122  std::vector<SESubstance*> m_GasSubstances;
123 
124  std::vector<SELiquidCompartment*> m_LiquidCompartments;
125  std::vector<SELiquidCompartment*> m_LiquidLeafCompartments;
126  std::map<std::string, SELiquidCompartment*> m_LiquidName2Compartments;
127  std::vector<SELiquidCompartmentLink*> m_LiquidLinks;
128  std::map<std::string, SELiquidCompartmentLink*> m_LiquidName2Links;
129  std::vector<SELiquidCompartmentGraph*> m_LiquidGraphs;
130  std::map<std::string, SELiquidCompartmentGraph*> m_LiquidName2Graphs;
131  std::vector<SESubstance*> m_LiquidSubstances;
132  std::vector<SELiquidCompartment*> m_CardiacCycleSampledCompartments;
133 
134  std::vector<SEThermalCompartment*> m_ThermalCompartments;
135  std::vector<SEThermalCompartment*> m_ThermalLeafCompartments;
136  std::map<std::string, SEThermalCompartment*> m_ThermalName2Compartments;
137  std::vector<SEThermalCompartmentLink*> m_ThermalLinks;
138  std::map<std::string, SEThermalCompartmentLink*> m_ThermalName2Links;
139 
140  std::vector<SETissueCompartment*> m_TissueCompartments;
141  std::vector<SETissueCompartment*> m_TissueLeafCompartments;
142  std::map<std::string, SETissueCompartment*> m_TissueName2Compartments;
143 
144  template<typename CompartmentType, typename LinkType>
145  void UpdateLinks(const std::vector<CompartmentType*>& compartments, const std::vector<LinkType*>& links) const;
146 
147  template<typename CompartmentType, typename LinkType>
148  void GetChildLinks(CompartmentType* pnt, CompartmentType* child) const;
149 
150  template<typename CompartmentType>
151  void FindLeaves(CompartmentType* cmpt, std::vector<CompartmentType*>& leaves) const;
152 
153  template<typename CompartmentType>
154  CompartmentType& CreateCompartment(const std::string& name, std::map<std::string, CompartmentType*>& name2cmpt, std::vector<SESubstance*>* substances);
155 
156  template<typename CompartmentType>
157  bool HasCompartment(const std::string& name, const std::map<std::string, CompartmentType*>& name2cmpt) const;
158 
159  template<typename CompartmentType>
160  CompartmentType* GetCompartment(const std::string& name, std::map<std::string, CompartmentType*>& name2cmpt) const;
161 
162  template<typename CompartmentType>
163  const CompartmentType* GetCompartment(const std::string& name, const std::map<std::string, CompartmentType*>& name2cmpt) const;
164 
165  template<typename LinkType, typename CompartmentType>
166  LinkType& CreateLink(CompartmentType& src, CompartmentType& tgt, const std::string& name, std::map<std::string, LinkType*>& name2link) const;
167 
168  template<typename LinkType>
169  bool HasLink(const std::string& name, const std::map<std::string, LinkType*> &name2link) const;
170 
171  template<typename LinkType>
172  LinkType* GetLink(const std::string& name, std::map<std::string, LinkType*>& name2link) const;
173 
174  template<typename LinkType>
175  const LinkType* GetLink(const std::string& name, const std::map<std::string, LinkType*>& name2link) const;
176 
177  template<typename CompartmentType>
178  void SetSubstances(CompartmentType& cmpt, std::vector<SESubstance*>& substances) const;
179 
180  template<typename CompartmentType>
181  void AddSubstance(SESubstance& s, CompartmentType& cmpt) const;
182 
183  // By default, every compartment gets every substance. Override these if you want to discritize better who gets what
184  virtual bool AllowGasSubstance(SESubstance&, SEGasCompartment&) const { return true; }
185  virtual bool AllowLiquidSubstance(SESubstance&, SELiquidCompartment&) const { return true; }
186 
187 
197 };
Definition: Logger.h:23
Definition: PBCompartment.h:28
Definition: SECircuitManager.h:38
Definition: SECompartment.h:14
Definition: SECompartmentManager.h:25
std::vector< SELiquidCompartment * > m_LiquidCompartments
Definition: SECompartmentManager.h:124
SESubstance * m_Hb
Definition: SECompartmentManager.h:191
std::vector< SEThermalCompartment * > m_ThermalLeafCompartments
Definition: SECompartmentManager.h:135
std::map< std::string, SELiquidCompartmentGraph * > m_LiquidName2Graphs
Definition: SECompartmentManager.h:130
std::vector< SELiquidCompartment * > m_LiquidLeafCompartments
Definition: SECompartmentManager.h:125
std::vector< SESubstance * > m_LiquidSubstances
Definition: SECompartmentManager.h:131
SESubstance * m_CO
Definition: SECompartmentManager.h:190
SESubstance * m_CO2
Definition: SECompartmentManager.h:189
std::map< std::string, SEThermalCompartmentLink * > m_ThermalName2Links
Definition: SECompartmentManager.h:138
std::map< std::string, SEThermalCompartment * > m_ThermalName2Compartments
Definition: SECompartmentManager.h:136
std::vector< SELiquidCompartmentLink * > m_LiquidLinks
Definition: SECompartmentManager.h:127
std::vector< SELiquidCompartment * > m_CardiacCycleSampledCompartments
Definition: SECompartmentManager.h:132
std::vector< SETissueCompartment * > m_TissueLeafCompartments
Definition: SECompartmentManager.h:141
std::vector< SETissueCompartment * > m_TissueCompartments
Definition: SECompartmentManager.h:140
std::map< std::string, SETissueCompartment * > m_TissueName2Compartments
Definition: SECompartmentManager.h:142
std::map< std::string, SEGasCompartmentLink * > m_GasName2Links
Definition: SECompartmentManager.h:119
std::map< std::string, SELiquidCompartment * > m_LiquidName2Compartments
Definition: SECompartmentManager.h:126
virtual bool AllowLiquidSubstance(SESubstance &, SELiquidCompartment &) const
Definition: SECompartmentManager.h:185
SESubstance * m_HbO2
Definition: SECompartmentManager.h:192
std::vector< SEGasCompartment * > m_GasCompartments
Definition: SECompartmentManager.h:115
std::map< std::string, SEGasCompartment * > m_GasName2Compartments
Definition: SECompartmentManager.h:117
SESubstance * m_HbO2CO2
Definition: SECompartmentManager.h:194
std::vector< SEGasCompartmentLink * > m_GasLinks
Definition: SECompartmentManager.h:118
std::vector< SEThermalCompartment * > m_ThermalCompartments
Definition: SECompartmentManager.h:134
SESubstanceManager & m_subMgr
Definition: SECompartmentManager.h:196
std::map< std::string, SELiquidCompartmentLink * > m_LiquidName2Links
Definition: SECompartmentManager.h:128
virtual bool AllowGasSubstance(SESubstance &, SEGasCompartment &) const
Definition: SECompartmentManager.h:184
std::vector< SESubstance * > m_GasSubstances
Definition: SECompartmentManager.h:122
std::vector< SEGasCompartment * > m_GasLeafCompartments
Definition: SECompartmentManager.h:116
std::vector< SEGasCompartmentGraph * > m_GasGraphs
Definition: SECompartmentManager.h:120
std::vector< SELiquidCompartmentGraph * > m_LiquidGraphs
Definition: SECompartmentManager.h:129
SESubstance * m_O2
Definition: SECompartmentManager.h:188
SESubstance * m_HbCO
Definition: SECompartmentManager.h:195
std::vector< SEThermalCompartmentLink * > m_ThermalLinks
Definition: SECompartmentManager.h:137
SESubstance * m_HbCO2
Definition: SECompartmentManager.h:193
std::map< std::string, SEGasCompartmentGraph * > m_GasName2Graphs
Definition: SECompartmentManager.h:121
Definition: SEGasCompartmentGraph.h:15
Definition: SEGasCompartment.h:14
Definition: SELiquidCompartmentGraph.h:16
Definition: SELiquidCompartment.h:11
Definition: SESubstance.h:15
Definition: SESubstanceManager.h:9
Definition: SEThermalCompartment.h:12
Definition: SETissueCompartment.h:9

Distributed under the Apache License, Version 2.0.

See accompanying NOTICE file for details.