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>
15 m_AverageInFlow =
nullptr;
16 m_AverageOutFlow =
nullptr;
17 m_AverageInFlow_mL_Per_s =
nullptr;
18 m_AverageOutFlow_mL_Per_s =
nullptr;
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)
59 return &GetPressure();
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 return m_SubstanceQuantities;
419template<FLUID_COMPARTMENT_TEMPLATE>
422 for (
size_t i = 0; i < m_SubstanceQuantities.size(); i++)
424 if (&m_SubstanceQuantities[i]->GetSubstance() == &substance)
426 SAFE_DELETE(m_SubstanceQuantities[i]);
427 SAFE_DELETE(m_TransportSubstances[i]);
428 m_SubstanceQuantities.erase(m_SubstanceQuantities.begin()+i);
429 m_TransportSubstances.erase(m_TransportSubstances.begin()+i);
434template<FLUID_COMPARTMENT_TEMPLATE>
437 for (SubstanceQuantityType* sq : m_SubstanceQuantities)
443template<FLUID_COMPARTMENT_TEMPLATE>
446 if (!Contains(m_Links, link))
448 m_Links.push_back(&link);
454 if(
this!= &src && !HasChild(src))
455 m_IncomingLinks.push_back(&link);
456 else if (
this!=&tgt && !HasChild(tgt))
457 m_OutgoingLinks.push_back(&link);
462 if (
this == &link.GetSourceCompartment())
463 m_OutgoingLinks.push_back(&link);
464 else if (
this == &link.GetTargetCompartment())
465 m_IncomingLinks.push_back(&link);
469template<FLUID_COMPARTMENT_TEMPLATE>
472 Remove(m_Links, &link);
473 Remove(m_IncomingLinks, &link);
474 Remove(m_OutgoingLinks, &link);
476template<FLUID_COMPARTMENT_TEMPLATE>
481template<FLUID_COMPARTMENT_TEMPLATE>
487template<FLUID_COMPARTMENT_TEMPLATE>
494 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 double CalculateOutFlow_mL_Per_s() const
Definition: SEFluidCompartment.cpp:236
virtual bool HasVolume() const
Definition: SEFluidCompartment.cpp:342
virtual void ZeroSubstanceQuantities()
Definition: SEFluidCompartment.cpp:438
virtual void RemoveSubstanceQuantity(const SESubstance &substance)
Definition: SEFluidCompartment.cpp:423
virtual ~SEFluidCompartment()
Definition: SEFluidCompartment.cpp:26
virtual SEScalarPressure & GetPressure()
Definition: SEFluidCompartment.cpp:274
virtual void RemoveLink(LinkType &link)
Definition: SEFluidCompartment.cpp:473
virtual bool HasAverageOutFlow() const
Definition: SEFluidCompartment.cpp:188
virtual bool HasInFlow() const
Definition: SEFluidCompartment.cpp:103
virtual void AddLink(LinkType &link)
Definition: SEFluidCompartment.cpp:447
virtual const std::vector< SubstanceQuantityType * > & GetSubstanceQuantities() const
Definition: SEFluidCompartment.cpp:418
virtual bool HasSubstanceQuantity(const SESubstance &substance) const
Definition: SEFluidCompartment.cpp:397
virtual bool HasAverageInFlow() const
Definition: SEFluidCompartment.cpp:134
virtual void RemoveLinks()
Definition: SEFluidCompartment.cpp:480
virtual bool HasSubstanceQuantities() const
Definition: SEFluidCompartment.cpp:392
virtual const SEScalarVolumePerTime & GetAverageInFlow() const
Definition: SEFluidCompartment.cpp:139
virtual void MapNode(SEFluidCircuitNode &node)
Definition: SEFluidCompartment.cpp:69
virtual const SEScalarVolumePerTime & GetInFlow() const
Definition: SEFluidCompartment.cpp:113
virtual const SEScalarVolumePerTime & GetAverageOutFlow() const
Definition: SEFluidCompartment.cpp:193
virtual bool HasPressure() const
Definition: SEFluidCompartment.cpp:260
virtual bool HasChild(const SEFluidCompartment &cmpt)
Definition: SEFluidCompartment.cpp:491
virtual SEScalarVolume & GetVolume()
Definition: SEFluidCompartment.cpp:356
void Clear() override
Definition: SEFluidCompartment.cpp:32
SEFluidCompartment(const std::string &name, Logger *logger)
Definition: SEFluidCompartment.cpp:13
virtual const std::vector< LinkType * > & GetLinks()
Definition: SEFluidCompartment.cpp:485
virtual SubstanceQuantityType * GetSubstanceQuantity(const SESubstance &substance) const
Definition: SEFluidCompartment.cpp:408
virtual void SampleFlow()
Definition: SEFluidCompartment.cpp:95
virtual const SEScalarVolumePerTime & GetOutFlow() const
Definition: SEFluidCompartment.cpp:167
virtual void Sample(bool CycleStart)
Definition: SEFluidCompartment.cpp:78
const SEScalar * GetScalar(const std::string &name) override
Definition: SEFluidCompartment.cpp:51
virtual double CalculateInFlow_mL_Per_s() const
Definition: SEFluidCompartment.cpp:211
virtual bool HasOutFlow() const
Definition: SEFluidCompartment.cpp:157
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:15
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