SECompartmentManager.h
1 /**************************************************************************************
2 Copyright 2015 Applied Research Associates, Inc.
3 Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 this file except in compliance with the License. You may obtain a copy of the License
5 at:
6 http://www.apache.org/licenses/LICENSE-2.0
7 Unless required by applicable law or agreed to in writing, software distributed under
8 the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
9 CONDITIONS OF ANY KIND, either express or implied. See the License for the
10 specific language governing permissions and limitations under the License.
11 **************************************************************************************/
12 
13 #pragma once
14 #include <string>
15 #include <vector>
16 #include <map>
17 
18 #include <biogears/exports.h>
19 
20 #include <biogears/cdm/CommonDataModel.h>
21 #include <biogears/cdm/circuit/SECircuitManager.h>
22 #include <biogears/cdm/compartment/fluid/SEGasCompartmentGraph.h>
23 #include <biogears/cdm/compartment/fluid/SELiquidCompartmentGraph.h>
24 #include <biogears/cdm/compartment/thermal/SEThermalCompartment.h>
25 #include <biogears/cdm/compartment/thermal/SEThermalCompartmentLink.h>
26 #include <biogears/cdm/compartment/tissue/SETissueCompartment.h>
27 #include <biogears/schema/cdm/Compartment.hxx>
28 
29 CDM_BIND_DECL(CompartmentManagerData)
30 
31 namespace biogears {
32 class BIOGEARS_API SECompartmentManager : public Loggable {
33 public:
35  virtual ~SECompartmentManager();
36 
37  virtual void Clear(); //clear memory
38 
39  virtual bool Load(const CDM::CompartmentManagerData& in, SECircuitManager* circuits = nullptr);
40  virtual CDM::CompartmentManagerData* Unload() const;
41 
42 protected:
43  void Unload(CDM::CompartmentManagerData& data) const;
44 
45 public:
46  virtual void StateChange(); // Identify leaves and other bookkeeping
47  virtual void UpdateLinks();
48  virtual void UpdateLinks(SEGasCompartmentGraph& graph);
49  virtual void UpdateLinks(SELiquidCompartmentGraph& graph);
50 
51  virtual bool HasCompartment(CDM::enumCompartmentType::value type, const char* name) const;
52  virtual bool HasCompartment(CDM::enumCompartmentType::value type, const std::string& name) const;
53  virtual SECompartment* GetCompartment(CDM::enumCompartmentType::value type, const char* name);
54  virtual SECompartment* GetCompartment(CDM::enumCompartmentType::value type, const std::string& name);
55  virtual const SECompartment* GetCompartment(CDM::enumCompartmentType::value type, const char* name) const;
56  virtual const SECompartment* GetCompartment(CDM::enumCompartmentType::value type, const std::string& name) const;
57 
58  virtual SEGasCompartment& CreateGasCompartment(const char* name);
59  virtual SEGasCompartment& CreateGasCompartment(const std::string& name);
60  virtual void DeleteGasCompartment(const char* name);
61  virtual void DeleteGasCompartment(const std::string& name);
62  virtual bool HasGasCompartment(const char* name) const;
63  virtual bool HasGasCompartment(const std::string& name) const;
64  virtual SEGasCompartment* GetGasCompartment(const char* name);
65  virtual SEGasCompartment* GetGasCompartment(const std::string& name);
66  virtual const SEGasCompartment* GetGasCompartment(const char* name) const;
67  virtual const SEGasCompartment* GetGasCompartment(const std::string& name) const;
68  virtual const std::vector<SEGasCompartment*>& GetGasCompartments();
69  virtual const std::vector<SEGasCompartment*>& GetGasLeafCompartments();
70  virtual SEGasCompartmentLink& CreateGasLink(SEGasCompartment& src, SEGasCompartment& tgt, const char* name);
71  virtual SEGasCompartmentLink& CreateGasLink(SEGasCompartment& src, SEGasCompartment& tgt, const std::string& name);
72  virtual void DeleteGasLink(const char* name);
73  virtual void DeleteGasLink(const std::string& name);
74  virtual bool HasGasLink(const char* name) const;
75  virtual bool HasGasLink(const std::string& name) const;
76  virtual SEGasCompartmentLink* GetGasLink(const char* name);
77  virtual SEGasCompartmentLink* GetGasLink(const std::string& name);
78  virtual const SEGasCompartmentLink* GetGasLink(const char* name) const;
79  virtual const SEGasCompartmentLink* GetGasLink(const std::string& name) const;
80  virtual const std::vector<SEGasCompartmentLink*>& GetGasLinks();
81  virtual SEGasCompartmentGraph& CreateGasGraph(const char* name);
82  virtual SEGasCompartmentGraph& CreateGasGraph(const std::string& name);
83  virtual void DeleteGasGraph(const char* name);
84  virtual void DeleteGasGraph(const std::string& name);
85  virtual bool HasGasGraph(const char* name) const;
86  virtual bool HasGasGraph(const std::string& name) const;
87  virtual SEGasCompartmentGraph* GetGasGraph(const char* name);
88  virtual SEGasCompartmentGraph* GetGasGraph(const std::string& name);
89  virtual const SEGasCompartmentGraph* GetGasGraph(const char* name) const;
90  virtual const SEGasCompartmentGraph* GetGasGraph(const std::string& name) const;
91  virtual const std::vector<SEGasCompartmentGraph*>& GetGasGraphs();
92  virtual void AddGasCompartmentSubstance(SESubstance& sub);
93  virtual const std::vector<SESubstance*>& GetGasCompartmentSubstances() const;
94 
95  virtual SELiquidCompartment& CreateLiquidCompartment(const char* name);
96  virtual SELiquidCompartment& CreateLiquidCompartment(const std::string& name);
97  virtual void DeleteLiquidCompartment(const char* name);
98  virtual void DeleteLiquidCompartment(const std::string& name);
99  virtual bool HasLiquidCompartment(const char* name) const;
100  virtual bool HasLiquidCompartment(const std::string& name) const;
101  virtual SELiquidCompartment* GetLiquidCompartment(const char* name);
102  virtual SELiquidCompartment* GetLiquidCompartment(const std::string& name);
103  virtual const SELiquidCompartment* GetLiquidCompartment(const char* name) const;
104  virtual const SELiquidCompartment* GetLiquidCompartment(const std::string& name) const;
105  virtual const std::vector<SELiquidCompartment*>& GetLiquidCompartments();
106  virtual const std::vector<SELiquidCompartment*>& GetLiquidLeafCompartments();
107  virtual SELiquidCompartmentLink& CreateLiquidLink(SELiquidCompartment& src, SELiquidCompartment& tgt, const char* name);
108  virtual SELiquidCompartmentLink& CreateLiquidLink(SELiquidCompartment& src, SELiquidCompartment& tgt, const std::string& name);
109  virtual void DeleteLiquidLink(const char* name);
110  virtual void DeleteLiquidLink(const std::string& name);
111  virtual bool HasLiquidLink(const char* name) const;
112  virtual bool HasLiquidLink(const std::string& name) const;
113  virtual SELiquidCompartmentLink* GetLiquidLink(const char* name);
114  virtual SELiquidCompartmentLink* GetLiquidLink(const std::string& name);
115  virtual const SELiquidCompartmentLink* GetLiquidLink(const char* name) const;
116  virtual const SELiquidCompartmentLink* GetLiquidLink(const std::string& name) const;
117  virtual const std::vector<SELiquidCompartmentLink*>& GetLiquidLinks();
118  virtual SELiquidCompartmentGraph& CreateLiquidGraph(const char* name);
119  virtual SELiquidCompartmentGraph& CreateLiquidGraph(const std::string& name);
120  virtual void DeleteLiquidGraph(const char* name);
121  virtual void DeleteLiquidGraph(const std::string& name);
122  virtual bool HasLiquidGraph(const char* name) const;
123  virtual bool HasLiquidGraph(const std::string& name) const;
124  virtual SELiquidCompartmentGraph* GetLiquidGraph(const char* name);
125  virtual SELiquidCompartmentGraph* GetLiquidGraph(const std::string& name);
126  virtual const SELiquidCompartmentGraph* GetLiquidGraph(const char* name) const;
127  virtual const SELiquidCompartmentGraph* GetLiquidGraph(const std::string& name) const;
128  virtual const std::vector<SELiquidCompartmentGraph*>& GetLiquidGraphs();
129  virtual void AddLiquidCompartmentSubstance(SESubstance& sub);
130  virtual const std::vector<SESubstance*>& GetLiquidCompartmentSubstances() const;
131 
132  virtual SEThermalCompartment& CreateThermalCompartment(const char* name);
133  virtual SEThermalCompartment& CreateThermalCompartment(const std::string& name);
134  virtual void DeleteThermalCompartment(const char* name);
135  virtual void DeleteThermalCompartment(const std::string& name);
136  virtual bool HasThermalCompartment(const char* name) const;
137  virtual bool HasThermalCompartment(const std::string& name) const;
138  virtual SEThermalCompartment* GetThermalCompartment(const char* name);
139  virtual SEThermalCompartment* GetThermalCompartment(const std::string& name);
140  virtual const SEThermalCompartment* GetThermalCompartment(const char* name) const;
141  virtual const SEThermalCompartment* GetThermalCompartment(const std::string& name) const;
142  virtual const std::vector<SEThermalCompartment*>& GetThermalCompartments();
143  virtual const std::vector<SEThermalCompartment*>& GetThermalLeafCompartments();
144  virtual SEThermalCompartmentLink& CreateThermalLink(SEThermalCompartment& src, SEThermalCompartment& tgt, const char* name);
145  virtual SEThermalCompartmentLink& CreateThermalLink(SEThermalCompartment& src, SEThermalCompartment& tgt, const std::string& name);
146  virtual void DeleteThermalLink(const char* name);
147  virtual void DeleteThermalLink(const std::string& name);
148  virtual bool HasThermalLink(const char* name) const;
149  virtual bool HasThermalLink(const std::string& name) const;
150  virtual SEThermalCompartmentLink* GetThermalLink(const char* name);
151  virtual SEThermalCompartmentLink* GetThermalLink(const std::string& name);
152  virtual const SEThermalCompartmentLink* GetThermalLink(const char* name) const;
153  virtual const SEThermalCompartmentLink* GetThermalLink(const std::string& name) const;
154  virtual const std::vector<SEThermalCompartmentLink*>& GetThermalLinks();
155 
156  virtual bool HasTissueCompartment(const char* name) const;
157  virtual bool HasTissueCompartment(const std::string& name) const;
158  virtual void DeleteTissueCompartment(const char* name);
159  virtual void DeleteTissueCompartment(const std::string& name);
160  virtual SETissueCompartment& CreateTissueCompartment(const char* name);
161  virtual SETissueCompartment& CreateTissueCompartment(const std::string& name);
162  virtual SETissueCompartment* GetTissueCompartment(const char* name);
163  virtual SETissueCompartment* GetTissueCompartment(const std::string& name);
164  virtual const SETissueCompartment* GetTissueCompartment(const char* name) const;
165  virtual const SETissueCompartment* GetTissueCompartment(const std::string& name) const;
166  virtual const std::vector<SETissueCompartment*>& GetTissueCompartments();
167  virtual const std::vector<SETissueCompartment*>& GetTissueLeafCompartments();
168 
169 protected:
170  std::vector<SEGasCompartment*> m_GasCompartments;
171  std::vector<SEGasCompartment*> m_GasLeafCompartments;
172  std::map<std::string, SEGasCompartment*> m_GasName2Compartments;
173  std::vector<SEGasCompartmentLink*> m_GasLinks;
174  std::map<std::string, SEGasCompartmentLink*> m_GasName2Links;
175  std::vector<SEGasCompartmentGraph*> m_GasGraphs;
176  std::map<std::string, SEGasCompartmentGraph*> m_GasName2Graphs;
177  std::vector<SESubstance*> m_GasSubstances;
178 
179  std::vector<SELiquidCompartment*> m_LiquidCompartments;
180  std::vector<SELiquidCompartment*> m_LiquidLeafCompartments;
181  std::map<std::string, SELiquidCompartment*> m_LiquidName2Compartments;
182  std::vector<SELiquidCompartmentLink*> m_LiquidLinks;
183  std::map<std::string, SELiquidCompartmentLink*> m_LiquidName2Links;
184  std::vector<SELiquidCompartmentGraph*> m_LiquidGraphs;
185  std::map<std::string, SELiquidCompartmentGraph*> m_LiquidName2Graphs;
186  std::vector<SESubstance*> m_LiquidSubstances;
187 
188  std::vector<SEThermalCompartment*> m_ThermalCompartments;
189  std::vector<SEThermalCompartment*> m_ThermalLeafCompartments;
190  std::map<std::string, SEThermalCompartment*> m_ThermalName2Compartments;
191  std::vector<SEThermalCompartmentLink*> m_ThermalLinks;
192  std::map<std::string, SEThermalCompartmentLink*> m_ThermalName2Links;
193 
194  std::vector<SETissueCompartment*> m_TissueCompartments;
195  std::vector<SETissueCompartment*> m_TissueLeafCompartments;
196  std::map<std::string, SETissueCompartment*> m_TissueName2Compartments;
197 
198  template <typename CompartmentType, typename LinkType>
199  void UpdateLinks(const std::vector<CompartmentType*>& compartments, const std::vector<LinkType*>& links) const;
200 
201  template <typename CompartmentType, typename LinkType>
202  void GetChildLinks(CompartmentType* pnt, CompartmentType* child) const;
203 
204  template <typename CompartmentType>
205  void FindLeaves(CompartmentType* cmpt, std::vector<CompartmentType*>& leaves) const;
206 
207  template <typename CompartmentType>
208  CompartmentType& CreateCompartment(const std::string& name, std::map<std::string, CompartmentType*>& name2cmpt, std::vector<SESubstance*>* substances);
209 
210  template <typename CompartmentType>
211  bool HasCompartment(const std::string& name, const std::map<std::string, CompartmentType*>& name2cmpt) const;
212 
213  template <typename CompartmentType>
214  CompartmentType* GetCompartment(const std::string& name, std::map<std::string, CompartmentType*>& name2cmpt) const;
215 
216  template <typename CompartmentType>
217  const CompartmentType* GetCompartment(const std::string& name, const std::map<std::string, CompartmentType*>& name2cmpt) const;
218 
219  template <typename LinkType, typename CompartmentType>
220  LinkType& CreateLink(CompartmentType& src, CompartmentType& tgt, const std::string& name, std::map<std::string, LinkType*>& name2link) const;
221 
222  template <typename LinkType>
223  bool HasLink(const std::string& name, const std::map<std::string, LinkType*>& name2link) const;
224 
225  template <typename LinkType>
226  LinkType* GetLink(const std::string& name, std::map<std::string, LinkType*>& name2link) const;
227 
228  template <typename LinkType>
229  const LinkType* GetLink(const std::string& name, const std::map<std::string, LinkType*>& name2link) const;
230 
231  template <typename CompartmentType>
232  void SetSubstances(CompartmentType& cmpt, std::vector<SESubstance*>& substances) const;
233 
234  template <typename CompartmentType>
235  void AddSubstance(SESubstance& s, CompartmentType& cmpt) const;
236 
237  // By default, every compartment gets every substance. Override these if you want to discritize better who gets what
238  virtual bool AllowGasSubstance(SESubstance& s, SEGasCompartment& cmpt) const { return true; }
239  virtual bool AllowLiquidSubstance(SESubstance& s, SELiquidCompartment& cmpt) const { return true; }
240 
250 };
251 }
std::vector< SESubstance * > m_LiquidSubstances
Definition: SECompartmentManager.h:186
value
Underlying enum type.
Definition: Compartment.hxx:708
std::vector< SEGasCompartment * > m_GasCompartments
Definition: SECompartmentManager.h:170
std::map< std::string, SEThermalCompartmentLink * > m_ThermalName2Links
Definition: SECompartmentManager.h:192
std::map< std::string, SEGasCompartmentLink * > m_GasName2Links
Definition: SECompartmentManager.h:174
std::map< std::string, SELiquidCompartment * > m_LiquidName2Compartments
Definition: SECompartmentManager.h:181
SESubstance * m_HbO2CO2
Definition: SECompartmentManager.h:247
SESubstance * m_HbCO2
Definition: SECompartmentManager.h:246
std::map< std::string, SEGasCompartment * > m_GasName2Compartments
Definition: SECompartmentManager.h:172
Definition: SELiquidCompartmentGraph.h:24
std::vector< SEGasCompartmentLink * > m_GasLinks
Definition: SECompartmentManager.h:173
std::map< std::string, SEThermalCompartment * > m_ThermalName2Compartments
Definition: SECompartmentManager.h:190
Definition: SEThermalCompartment.h:26
Definition: SECompartmentManager.h:32
std::vector< SELiquidCompartment * > m_LiquidCompartments
Definition: SECompartmentManager.h:179
std::vector< SEThermalCompartmentLink * > m_ThermalLinks
Definition: SECompartmentManager.h:191
std::map< std::string, SETissueCompartment * > m_TissueName2Compartments
Definition: SECompartmentManager.h:196
Definition: Logger.h:27
SESubstance * m_CO
Definition: SECompartmentManager.h:243
std::vector< SEGasCompartment * > m_GasLeafCompartments
Definition: SECompartmentManager.h:171
Definition: SELiquidCompartment.h:27
std::vector< SEThermalCompartment * > m_ThermalCompartments
Definition: SECompartmentManager.h:188
std::map< std::string, SELiquidCompartmentGraph * > m_LiquidName2Graphs
Definition: SECompartmentManager.h:185
std::vector< SETissueCompartment * > m_TissueCompartments
Definition: SECompartmentManager.h:194
std::vector< SELiquidCompartmentLink * > m_LiquidLinks
Definition: SECompartmentManager.h:182
SESubstance * m_HbO2
Definition: SECompartmentManager.h:245
std::map< std::string, SEGasCompartmentGraph * > m_GasName2Graphs
Definition: SECompartmentManager.h:176
virtual bool AllowGasSubstance(SESubstance &s, SEGasCompartment &cmpt) const
Definition: SECompartmentManager.h:238
SESubstanceManager & m_subMgr
Definition: SECompartmentManager.h:249
virtual bool AllowLiquidSubstance(SESubstance &s, SELiquidCompartment &cmpt) const
Definition: SECompartmentManager.h:239
Definition: SESubstance.h:49
Definition: SEGasCompartmentGraph.h:25
std::vector< SELiquidCompartment * > m_LiquidLeafCompartments
Definition: SECompartmentManager.h:180
SESubstance * m_CO2
Definition: SECompartmentManager.h:242
SESubstance * m_HbCO
Definition: SECompartmentManager.h:248
Definition: SECompartment.h:31
std::vector< SEGasCompartmentGraph * > m_GasGraphs
Definition: SECompartmentManager.h:175
std::vector< SELiquidCompartmentGraph * > m_LiquidGraphs
Definition: SECompartmentManager.h:184
SESubstance * m_O2
Definition: SECompartmentManager.h:241
std::vector< SEThermalCompartment * > m_ThermalLeafCompartments
Definition: SECompartmentManager.h:189
Class corresponding to the CompartmentManagerData schema type.
Definition: Compartment.hxx:5467
std::map< std::string, SELiquidCompartmentLink * > m_LiquidName2Links
Definition: SECompartmentManager.h:183
Definition: SESubstanceManager.h:23
Definition: SEElectricalCircuit.h:18
Definition: SETissueCompartment.h:32
std::vector< SETissueCompartment * > m_TissueLeafCompartments
Definition: SECompartmentManager.h:195
Definition: SECircuitManager.h:53
SESubstance * m_Hb
Definition: SECompartmentManager.h:244
std::vector< SESubstance * > m_GasSubstances
Definition: SECompartmentManager.h:177
Definition: SEGasCompartment.h:24