4#include "cdm/properties/SEScalarVolumePerTime.h"
5#include "cdm/properties/SEScalarPressure.h"
6#include "cdm/properties/SEScalarVolume.h"
7#include "cdm/properties/SERunningAverage.h"
9template<FLUID_COMPARTMENT_TEMPLATE>
22template<FLUID_COMPARTMENT_TEMPLATE>
28template<FLUID_COMPARTMENT_TEMPLATE>
33 SAFE_DELETE(m_Inflow);
34 SAFE_DELETE(m_Outflow);
35 SAFE_DELETE(m_AverageInflow);
36 SAFE_DELETE(m_AverageOutflow);
37 SAFE_DELETE(m_AverageInflow_mL_Per_s);
38 SAFE_DELETE(m_AverageOutflow_mL_Per_s);
39 SAFE_DELETE(m_Pressure);
40 SAFE_DELETE(m_Volume);
42 m_FluidChildren.clear();
43 DELETE_VECTOR(m_SubstanceQuantities);
47template<FLUID_COMPARTMENT_TEMPLATE>
50 if (name.compare(
"Inflow") == 0)
52 if (name.compare(
"Outflow") == 0)
54 if (name.compare(
"AverageInflow") == 0)
55 return &GetAverageInflow();
56 if (name.compare(
"AverageOutflow") == 0)
57 return &GetAverageOutflow();
58 if (name.compare(
"Pressure") == 0)
60 if (name.compare(
"Volume") == 0)
65template<FLUID_COMPARTMENT_TEMPLATE>
69 Fatal(
"You cannot map nodes to compartments with children.");
71 m_Nodes.MapNode(node);
74template<FLUID_COMPARTMENT_TEMPLATE>
85 m_AverageInflow_mL_Per_s->Invalidate();
86 m_AverageOutflow_mL_Per_s->Invalidate();
91template<FLUID_COMPARTMENT_TEMPLATE>
99template<FLUID_COMPARTMENT_TEMPLATE>
104 for (
auto* link : m_Links)
109template<FLUID_COMPARTMENT_TEMPLATE>
112 if (m_Inflow ==
nullptr)
114 m_Inflow->SetReadOnly(
false);
116 m_Inflow->Invalidate();
119 m_Inflow->SetReadOnly(
true);
122template<FLUID_COMPARTMENT_TEMPLATE>
130template<FLUID_COMPARTMENT_TEMPLATE>
133 return m_AverageInflow ==
nullptr ? false : m_AverageInflow->IsValid();
135template<FLUID_COMPARTMENT_TEMPLATE>
138 if (m_AverageInflow ==
nullptr)
143 return *m_AverageInflow;
145template<FLUID_COMPARTMENT_TEMPLATE>
148 if (m_AverageInflow ==
nullptr)
150 return m_AverageInflow->GetValue(unit);
153template<FLUID_COMPARTMENT_TEMPLATE>
158 for (
auto* link : m_Links)
163template<FLUID_COMPARTMENT_TEMPLATE>
166 if (m_Outflow ==
nullptr)
168 m_Outflow->SetReadOnly(
false);
170 m_Outflow->Invalidate();
173 m_Outflow->SetReadOnly(
true);
176template<FLUID_COMPARTMENT_TEMPLATE>
184template<FLUID_COMPARTMENT_TEMPLATE>
187 return m_AverageOutflow ==
nullptr ? false : m_AverageOutflow->IsValid();
189template<FLUID_COMPARTMENT_TEMPLATE>
192 if (m_AverageOutflow ==
nullptr)
197 return *m_AverageOutflow;
199template<FLUID_COMPARTMENT_TEMPLATE>
202 if (m_AverageOutflow ==
nullptr)
204 return m_AverageOutflow->GetValue(unit);
207template<FLUID_COMPARTMENT_TEMPLATE>
210 double flow_mL_Per_s = 0;
213 for (
auto* link : m_IncomingLinks)
216 f = &link->GetFlow();
220 for (
auto* link : m_OutgoingLinks)
222 f = &link->GetFlow();
227 if (flow_mL_Per_s < 0)
229 return flow_mL_Per_s;
232template<FLUID_COMPARTMENT_TEMPLATE>
235 double flow_mL_Per_s = 0;
238 for (
auto* link : m_IncomingLinks)
241 f = &link->GetFlow();
245 for (
auto* link : m_OutgoingLinks)
247 f = &link->GetFlow();
251 if (flow_mL_Per_s < 0)
253 return flow_mL_Per_s;
256template<FLUID_COMPARTMENT_TEMPLATE>
259 if (m_Nodes.HasMapping())
260 return m_Nodes.HasPotential();
261 if (!m_FluidChildren.empty())
263 for (
auto* child : m_FluidChildren)
264 if (child->HasPressure())
268 return m_Pressure ==
nullptr ? false : m_Pressure->IsValid();
270template<FLUID_COMPARTMENT_TEMPLATE>
273 if (m_Nodes.HasMapping())
274 return m_Nodes.GetPotential();
275 if (m_Pressure ==
nullptr)
277 if (!m_FluidChildren.empty())
279 m_Pressure->SetReadOnly(
false);
280 m_Pressure->Invalidate();
284 if (child->HasPressure())
286 pUnit = child->GetPressure().GetUnit();
291 m_Pressure->SetValue(GetPressure(*pUnit),*pUnit);
292 m_Pressure->SetReadOnly(
true);
296template<FLUID_COMPARTMENT_TEMPLATE>
301 if (m_Nodes.HasMapping())
302 return m_Nodes.GetPotential(unit);
303 if (!m_FluidChildren.empty())
311 if (child->HasPressure() && child->HasVolume())
313 Pressure += child->GetPressure(unit) * (child->GetVolume(
VolumeUnit::mL) / totalVolume_mL);
323 if (child->HasPressure())
326 Pressure += child->GetPressure(unit);
333 if (m_Pressure ==
nullptr)
335 return m_Pressure->GetValue(unit);
338template<FLUID_COMPARTMENT_TEMPLATE>
341 if (m_Nodes.HasMapping())
342 return m_Nodes.HasQuantity();
343 if (!m_FluidChildren.empty())
345 for (
auto* child : m_FluidChildren)
346 if (child->HasVolume())
350 return m_Volume ==
nullptr ? false : m_Volume->IsValid();
352template<FLUID_COMPARTMENT_TEMPLATE>
355 if (m_Nodes.HasMapping())
356 return m_Nodes.GetQuantity();
357 if (m_Volume ==
nullptr)
359 if (!m_FluidChildren.empty())
361 m_Volume->SetReadOnly(
false);
362 m_Volume->Invalidate();
364 if (child->HasVolume())
365 m_Volume->Increment(child->GetVolume());
366 m_Volume->SetReadOnly(
true);
370template<FLUID_COMPARTMENT_TEMPLATE>
373 if (m_Nodes.HasMapping())
374 return m_Nodes.GetQuantity(unit);
375 if (!m_FluidChildren.empty())
379 if (child->HasVolume())
380 volume += child->GetVolume(unit);
383 if (m_Volume ==
nullptr)
385 return m_Volume->GetValue(unit);
388template<FLUID_COMPARTMENT_TEMPLATE>
391 return !m_SubstanceQuantities.empty();
393template<FLUID_COMPARTMENT_TEMPLATE>
396 for (SubstanceQuantityType* sq : m_SubstanceQuantities)
398 if (&sq->GetSubstance() == &substance)
404template<FLUID_COMPARTMENT_TEMPLATE>
407 for (SubstanceQuantityType* sq : m_SubstanceQuantities)
409 if (&sq->GetSubstance() == &substance)
414template<FLUID_COMPARTMENT_TEMPLATE>
417 for (SubstanceQuantityType* sq : m_SubstanceQuantities)
419 if (&sq->GetSubstance() == &substance)
424template<FLUID_COMPARTMENT_TEMPLATE>
427 return m_SubstanceQuantities;
429template<FLUID_COMPARTMENT_TEMPLATE>
432 for (
size_t i = 0; i < m_SubstanceQuantities.size(); i++)
434 if (&m_SubstanceQuantities[i]->GetSubstance() == &substance)
436 SAFE_DELETE(m_SubstanceQuantities[i]);
437 SAFE_DELETE(m_TransportSubstances[i]);
438 m_SubstanceQuantities.erase(m_SubstanceQuantities.begin()+i);
439 m_TransportSubstances.erase(m_TransportSubstances.begin()+i);
444template<FLUID_COMPARTMENT_TEMPLATE>
447 for (SubstanceQuantityType* sq : m_SubstanceQuantities)
453template<FLUID_COMPARTMENT_TEMPLATE>
456 if (!Contains(m_Links, link))
458 m_Links.push_back(&link);
464 if(
this!= &src && !HasChild(src))
465 m_IncomingLinks.push_back(&link);
466 else if (
this!=&tgt && !HasChild(tgt))
467 m_OutgoingLinks.push_back(&link);
472 if (
this == &link.GetSourceCompartment())
473 m_OutgoingLinks.push_back(&link);
474 else if (
this == &link.GetTargetCompartment())
475 m_IncomingLinks.push_back(&link);
479template<FLUID_COMPARTMENT_TEMPLATE>
482 Remove(m_Links, &link);
483 Remove(m_IncomingLinks, &link);
484 Remove(m_OutgoingLinks, &link);
486template<FLUID_COMPARTMENT_TEMPLATE>
491template<FLUID_COMPARTMENT_TEMPLATE>
497template<FLUID_COMPARTMENT_TEMPLATE>
504 if (child->HasChild(cmpt))
Definition: SEScalarPressure.h:8
Definition: SECompartment.h:14
virtual void Clear()
Definition: SECompartment.cpp:18
Definition: SEFluidCircuitNode.h:10
Definition: SEFluidCompartment.h:19
virtual bool HasVolume() const
Definition: SEFluidCompartment.hxx:339
virtual void ZeroSubstanceQuantities()
Definition: SEFluidCompartment.hxx:445
virtual void RemoveSubstanceQuantity(const SESubstance &substance)
Definition: SEFluidCompartment.hxx:430
virtual ~SEFluidCompartment()
Definition: SEFluidCompartment.hxx:23
SEScalarVolumePerTime * m_AverageOutflow
Definition: SEFluidCompartment.h:95
virtual SEScalarPressure & GetPressure()
Definition: SEFluidCompartment.hxx:271
virtual void RemoveLink(LinkType &link)
Definition: SEFluidCompartment.hxx:480
SEScalarVolumePerTime * m_AverageInflow
Definition: SEFluidCompartment.h:94
virtual void AddLink(LinkType &link)
Definition: SEFluidCompartment.hxx:454
virtual double CalculateInflow_mL_Per_s() const
Definition: SEFluidCompartment.hxx:208
virtual bool HasOutflow() const
Definition: SEFluidCompartment.hxx:154
virtual const std::vector< SubstanceQuantityType * > & GetSubstanceQuantities() const
Definition: SEFluidCompartment.hxx:425
virtual const SEScalarVolumePerTime & GetOutflow() const
Definition: SEFluidCompartment.hxx:164
SERunningAverage * m_AverageOutflow_mL_Per_s
Definition: SEFluidCompartment.h:97
virtual bool HasAverageOutflow() const
Definition: SEFluidCompartment.hxx:185
virtual bool HasSubstanceQuantity(const SESubstance &substance) const
Definition: SEFluidCompartment.hxx:394
virtual void RemoveLinks()
Definition: SEFluidCompartment.hxx:487
virtual SubstanceQuantityType * GetSubstanceQuantity(const SESubstance &substance)
Definition: SEFluidCompartment.hxx:405
virtual bool HasSubstanceQuantities() const
Definition: SEFluidCompartment.hxx:389
virtual const SEScalarVolumePerTime & GetAverageInflow() const
Definition: SEFluidCompartment.hxx:136
virtual void MapNode(SEFluidCircuitNode &node)
Definition: SEFluidCompartment.hxx:66
virtual bool HasInflow() const
Definition: SEFluidCompartment.hxx:100
SEScalarVolumePerTime * m_Inflow
Definition: SEFluidCompartment.h:91
virtual bool HasPressure() const
Definition: SEFluidCompartment.hxx:257
SEScalarVolumePerTime * m_Outflow
Definition: SEFluidCompartment.h:92
bool m_SampleFlow
Definition: SEFluidCompartment.h:93
virtual bool HasChild(const SEFluidCompartment &cmpt)
Definition: SEFluidCompartment.hxx:498
virtual SEScalarVolume & GetVolume()
Definition: SEFluidCompartment.hxx:353
void Clear() override
Definition: SEFluidCompartment.hxx:29
SERunningAverage * m_AverageInflow_mL_Per_s
Definition: SEFluidCompartment.h:96
SEFluidCompartment(const std::string &name, Logger *logger)
Definition: SEFluidCompartment.hxx:10
virtual const std::vector< LinkType * > & GetLinks()
Definition: SEFluidCompartment.hxx:492
virtual void SampleFlow()
Definition: SEFluidCompartment.hxx:92
virtual bool HasAverageInflow() const
Definition: SEFluidCompartment.hxx:131
SEScalarVolume * m_Volume
Definition: SEFluidCompartment.h:100
SEScalarPressure * m_Pressure
Definition: SEFluidCompartment.h:99
virtual void Sample(bool CycleStart)
Definition: SEFluidCompartment.hxx:75
const SEScalar * GetScalar(const std::string &name) override
Definition: SEFluidCompartment.hxx:48
virtual const SEScalarVolumePerTime & GetAverageOutflow() const
Definition: SEFluidCompartment.hxx:190
virtual double CalculateOutflow_mL_Per_s() const
Definition: SEFluidCompartment.hxx:233
virtual const SEScalarVolumePerTime & GetInflow() const
Definition: SEFluidCompartment.hxx:110
Definition: SERunningAverage.h:8
Definition: SEScalar.h:19
static double dNaN()
Definition: SEScalar.cpp:10
bool IsPositive() const
Definition: SEScalar.cpp:115
bool IsZero(double limit=ZERO_APPROX) const
Definition: SEScalar.cpp:108
bool IsNegative() const
Definition: SEScalar.cpp:122
Definition: SEScalarPressure.h:29
double GetValue(const CCompoundUnit &unit) const override
Definition: SEScalar.hxx:125
Definition: SEScalarVolume.h:28
Definition: SEScalarVolumePerTime.h:32
Definition: SESubstance.h:16
Definition: SEScalarVolumePerTime.h:8
static const VolumePerTimeUnit mL_Per_s
Definition: SEScalarVolumePerTime.h:23
Definition: SEScalarVolume.h:8
static const VolumeUnit mL
Definition: SEScalarVolume.h:22