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 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 Clear(); //clear memory
32 
33  virtual void StateChange();// Identify leaves and other bookkeeping
34  virtual void UpdateLinks();
35  virtual void UpdateLinks(SEGasCompartmentGraph& graph);
36  virtual void UpdateLinks(SELiquidCompartmentGraph& graph);
37 
38  virtual bool HasCompartment(eCompartment_Type type, const std::string& name) const;
39  virtual SECompartment* GetCompartment(eCompartment_Type type, const std::string& name);
40  virtual const SECompartment* GetCompartment(eCompartment_Type type, const std::string& name) const;
41 
42  virtual SEGasCompartment& CreateGasCompartment(const std::string& name);
43  virtual void DeleteGasCompartment(const std::string& name);
44  virtual bool HasGasCompartment(const std::string& name) const;
45  virtual SEGasCompartment* GetGasCompartment(const std::string& name);
46  virtual const SEGasCompartment* GetGasCompartment(const std::string& name) const;
47  virtual const std::vector<SEGasCompartment*>& GetGasCompartments();
48  virtual const std::vector<SEGasCompartment*>& GetGasLeafCompartments();
49  virtual SEGasCompartmentLink& CreateGasLink(SEGasCompartment& src, SEGasCompartment& tgt, const std::string& name);
50  virtual void DeleteGasLink(const std::string& name);
51  virtual bool HasGasLink(const std::string& name) const;
52  virtual SEGasCompartmentLink* GetGasLink(const std::string& name);
53  virtual const SEGasCompartmentLink* GetGasLink(const std::string& name) const;
54  virtual const std::vector<SEGasCompartmentLink*>& GetGasLinks();
55  virtual SEGasCompartmentGraph& CreateGasGraph(const std::string& name);
56  virtual void DeleteGasGraph(const std::string& name);
57  virtual bool HasGasGraph(const std::string& name) const;
58  virtual SEGasCompartmentGraph* GetGasGraph(const std::string& name);
59  virtual const SEGasCompartmentGraph* GetGasGraph(const std::string& name) const;
60  virtual const std::vector<SEGasCompartmentGraph*>& GetGasGraphs();
61  virtual void AddGasCompartmentSubstance(SESubstance& sub);
62  virtual const std::vector<SESubstance*>& GetGasCompartmentSubstances() const;
63 
64  virtual SELiquidCompartment& CreateLiquidCompartment(const std::string& name);
65  virtual void DeleteLiquidCompartment(const std::string& name);
66  virtual bool HasLiquidCompartment(const std::string& name) const;
67  virtual SELiquidCompartment* GetLiquidCompartment(const std::string& name);
68  virtual const SELiquidCompartment* GetLiquidCompartment(const std::string& name) const;
69  virtual const std::vector<SELiquidCompartment*>& GetLiquidCompartments();
70  virtual const std::vector<SELiquidCompartment*>& GetLiquidLeafCompartments();
71  virtual SELiquidCompartmentLink& CreateLiquidLink(SELiquidCompartment& src, SELiquidCompartment& tgt, const std::string& name);
72  virtual void DeleteLiquidLink(const std::string& name);
73  virtual bool HasLiquidLink(const std::string& name) const;
74  virtual SELiquidCompartmentLink* GetLiquidLink(const std::string& name);
75  virtual const SELiquidCompartmentLink* GetLiquidLink(const std::string& name) const;
76  virtual const std::vector<SELiquidCompartmentLink*>& GetLiquidLinks();
77  virtual SELiquidCompartmentGraph& CreateLiquidGraph(const std::string& name);
78  virtual void DeleteLiquidGraph(const std::string& name);
79  virtual bool HasLiquidGraph(const std::string& name) const;
80  virtual SELiquidCompartmentGraph* GetLiquidGraph(const std::string& name);
81  virtual const SELiquidCompartmentGraph* GetLiquidGraph(const std::string& name) const;
82  virtual const std::vector<SELiquidCompartmentGraph*>& GetLiquidGraphs();
83  virtual void AddLiquidCompartmentSubstance(SESubstance& sub);
84  virtual const std::vector<SESubstance*>& GetLiquidCompartmentSubstances() const;
85 
86  virtual SEThermalCompartment& CreateThermalCompartment(const std::string& name);
87  virtual void DeleteThermalCompartment(const std::string& name);
88  virtual bool HasThermalCompartment(const std::string& name) const;
89  virtual SEThermalCompartment* GetThermalCompartment(const std::string& name);
90  virtual const SEThermalCompartment* GetThermalCompartment(const std::string& name) const;
91  virtual const std::vector<SEThermalCompartment*>& GetThermalCompartments();
92  virtual const std::vector<SEThermalCompartment*>& GetThermalLeafCompartments();
93  virtual SEThermalCompartmentLink& CreateThermalLink(SEThermalCompartment& src, SEThermalCompartment& tgt, const std::string& name);
94  virtual void DeleteThermalLink(const std::string& name);
95  virtual bool HasThermalLink(const std::string& name) const;
96  virtual SEThermalCompartmentLink* GetThermalLink(const std::string& name);
97  virtual const SEThermalCompartmentLink* GetThermalLink(const std::string& name) const;
98  virtual const std::vector<SEThermalCompartmentLink*>& GetThermalLinks();
99 
100  virtual bool HasTissueCompartment(const std::string& name) const;
101  virtual void DeleteTissueCompartment(const std::string& name);
102  virtual SETissueCompartment& CreateTissueCompartment(const std::string& name);
103  virtual SETissueCompartment* GetTissueCompartment(const std::string& name);
104  virtual const SETissueCompartment* GetTissueCompartment(const std::string& name) const;
105  virtual const std::vector<SETissueCompartment*>& GetTissueCompartments();
106  virtual const std::vector<SETissueCompartment*>& GetTissueLeafCompartments();
107 
108 protected:
109  std::vector<SEGasCompartment*> m_GasCompartments;
110  std::vector<SEGasCompartment*> m_GasLeafCompartments;
111  std::map<std::string, SEGasCompartment*> m_GasName2Compartments;
112  std::vector<SEGasCompartmentLink*> m_GasLinks;
113  std::map<std::string, SEGasCompartmentLink*> m_GasName2Links;
114  std::vector<SEGasCompartmentGraph*> m_GasGraphs;
115  std::map<std::string, SEGasCompartmentGraph*> m_GasName2Graphs;
116  std::vector<SESubstance*> m_GasSubstances;
117 
118  std::vector<SELiquidCompartment*> m_LiquidCompartments;
119  std::vector<SELiquidCompartment*> m_LiquidLeafCompartments;
120  std::map<std::string, SELiquidCompartment*> m_LiquidName2Compartments;
121  std::vector<SELiquidCompartmentLink*> m_LiquidLinks;
122  std::map<std::string, SELiquidCompartmentLink*> m_LiquidName2Links;
123  std::vector<SELiquidCompartmentGraph*> m_LiquidGraphs;
124  std::map<std::string, SELiquidCompartmentGraph*> m_LiquidName2Graphs;
125  std::vector<SESubstance*> m_LiquidSubstances;
126 
127  std::vector<SEThermalCompartment*> m_ThermalCompartments;
128  std::vector<SEThermalCompartment*> m_ThermalLeafCompartments;
129  std::map<std::string, SEThermalCompartment*> m_ThermalName2Compartments;
130  std::vector<SEThermalCompartmentLink*> m_ThermalLinks;
131  std::map<std::string, SEThermalCompartmentLink*> m_ThermalName2Links;
132 
133  std::vector<SETissueCompartment*> m_TissueCompartments;
134  std::vector<SETissueCompartment*> m_TissueLeafCompartments;
135  std::map<std::string, SETissueCompartment*> m_TissueName2Compartments;
136 
137  template<typename CompartmentType, typename LinkType>
138  void UpdateLinks(const std::vector<CompartmentType*>& compartments, const std::vector<LinkType*>& links) const;
139 
140  template<typename CompartmentType, typename LinkType>
141  void GetChildLinks(CompartmentType* pnt, CompartmentType* child) const;
142 
143  template<typename CompartmentType>
144  void FindLeaves(CompartmentType* cmpt, std::vector<CompartmentType*>& leaves) const;
145 
146  template<typename CompartmentType>
147  CompartmentType& CreateCompartment(const std::string& name, std::map<std::string, CompartmentType*>& name2cmpt, std::vector<SESubstance*>* substances);
148 
149  template<typename CompartmentType>
150  bool HasCompartment(const std::string& name, const std::map<std::string, CompartmentType*>& name2cmpt) const;
151 
152  template<typename CompartmentType>
153  CompartmentType* GetCompartment(const std::string& name, std::map<std::string, CompartmentType*>& name2cmpt) const;
154 
155  template<typename CompartmentType>
156  const CompartmentType* GetCompartment(const std::string& name, const std::map<std::string, CompartmentType*>& name2cmpt) const;
157 
158  template<typename LinkType, typename CompartmentType>
159  LinkType& CreateLink(CompartmentType& src, CompartmentType& tgt, const std::string& name, std::map<std::string, LinkType*>& name2link) const;
160 
161  template<typename LinkType>
162  bool HasLink(const std::string& name, const std::map<std::string, LinkType*> &name2link) const;
163 
164  template<typename LinkType>
165  LinkType* GetLink(const std::string& name, std::map<std::string, LinkType*>& name2link) const;
166 
167  template<typename LinkType>
168  const LinkType* GetLink(const std::string& name, const std::map<std::string, LinkType*>& name2link) const;
169 
170  template<typename CompartmentType>
171  void SetSubstances(CompartmentType& cmpt, std::vector<SESubstance*>& substances) const;
172 
173  template<typename CompartmentType>
174  void AddSubstance(SESubstance& s, CompartmentType& cmpt) const;
175 
176  // By default, every compartment gets every substance. Override these if you want to discritize better who gets what
177  virtual bool AllowGasSubstance(SESubstance& s, SEGasCompartment& cmpt) const { return true; }
178  virtual bool AllowLiquidSubstance(SESubstance& s, SELiquidCompartment& cmpt) const { return true; }
179 
180 
190 };
Definition: SESubstanceManager.h:8
SESubstance * m_HbCO2
Definition: SECompartmentManager.h:186
SESubstance * m_Hb
Definition: SECompartmentManager.h:184
Definition: SEGasCompartment.h:12
std::vector< SELiquidCompartment * > m_LiquidLeafCompartments
Definition: SECompartmentManager.h:119
std::map< std::string, SEThermalCompartment * > m_ThermalName2Compartments
Definition: SECompartmentManager.h:129
SESubstance * m_HbO2CO2
Definition: SECompartmentManager.h:187
std::vector< SESubstance * > m_LiquidSubstances
Definition: SECompartmentManager.h:125
SESubstance * m_CO2
Definition: SECompartmentManager.h:182
std::vector< SEThermalCompartment * > m_ThermalCompartments
Definition: SECompartmentManager.h:127
SESubstance * m_O2
Definition: SECompartmentManager.h:181
std::map< std::string, SEGasCompartment * > m_GasName2Compartments
Definition: SECompartmentManager.h:111
std::vector< SEThermalCompartment * > m_ThermalLeafCompartments
Definition: SECompartmentManager.h:128
std::map< std::string, SEGasCompartmentLink * > m_GasName2Links
Definition: SECompartmentManager.h:113
std::vector< SETissueCompartment * > m_TissueLeafCompartments
Definition: SECompartmentManager.h:134
std::vector< SELiquidCompartmentLink * > m_LiquidLinks
Definition: SECompartmentManager.h:121
Definition: Logger.h:11
Definition: SELiquidCompartment.h:10
Definition: SECompartmentManager.h:24
This class encapsulates logic necessary to connect independent systems together.
Definition: Tissue.h:22
std::vector< SETissueCompartment * > m_TissueCompartments
Definition: SECompartmentManager.h:133
std::vector< SEGasCompartmentLink * > m_GasLinks
Definition: SECompartmentManager.h:112
std::vector< SEGasCompartment * > m_GasLeafCompartments
Definition: SECompartmentManager.h:110
Definition: SETissueCompartment.h:8
std::vector< SELiquidCompartment * > m_LiquidCompartments
Definition: SECompartmentManager.h:118
virtual bool AllowGasSubstance(SESubstance &s, SEGasCompartment &cmpt) const
Definition: SECompartmentManager.h:177
std::map< std::string, SEThermalCompartmentLink * > m_ThermalName2Links
Definition: SECompartmentManager.h:131
std::vector< SELiquidCompartmentGraph * > m_LiquidGraphs
Definition: SECompartmentManager.h:123
std::vector< SEGasCompartmentGraph * > m_GasGraphs
Definition: SECompartmentManager.h:114
Definition: SECircuitManager.h:37
std::map< std::string, SETissueCompartment * > m_TissueName2Compartments
Definition: SECompartmentManager.h:135
Definition: SELiquidCompartmentGraph.h:11
std::map< std::string, SELiquidCompartmentLink * > m_LiquidName2Links
Definition: SECompartmentManager.h:122
virtual bool AllowLiquidSubstance(SESubstance &s, SELiquidCompartment &cmpt) const
Definition: SECompartmentManager.h:178
SESubstance * m_HbCO
Definition: SECompartmentManager.h:188
std::vector< SESubstance * > m_GasSubstances
Definition: SECompartmentManager.h:116
std::map< std::string, SELiquidCompartment * > m_LiquidName2Compartments
Definition: SECompartmentManager.h:120
std::vector< SEGasCompartment * > m_GasCompartments
Definition: SECompartmentManager.h:109
std::vector< SEThermalCompartmentLink * > m_ThermalLinks
Definition: SECompartmentManager.h:130
Definition: SEGasCompartmentGraph.h:10
Definition: PBCompartment.h:27
Definition: SECompartment.h:12
std::map< std::string, SELiquidCompartmentGraph * > m_LiquidName2Graphs
Definition: SECompartmentManager.h:124
Definition: SESubstance.h:14
SESubstance * m_CO
Definition: SECompartmentManager.h:183
Definition: SEThermalCompartment.h:10
SESubstanceManager & m_subMgr
Definition: SECompartmentManager.h:189
SESubstance * m_HbO2
Definition: SECompartmentManager.h:185
std::map< std::string, SEGasCompartmentGraph * > m_GasName2Graphs
Definition: SECompartmentManager.h:115