SEBlackBox.h
1/* Distributed under the Apache License, Version 2.0.
2 See accompanying NOTICE file for details.*/
3
4#pragma once
5
6#include "cdm/properties/SEScalar.h"
7#include "cdm/circuit/SECircuitNode.h"
8#include "cdm/circuit/SECircuitPath.h"
9
10#define BLACK_BOX_TEMPLATE typename NodeType, typename PathType, \
11 typename PotentialScalar, typename QuantityScalar, typename FluxScalar, \
12 typename PotentialUnit, typename QuantityUnit, typename FluxUnit
13
14#define BLACK_BOX_TYPES NodeType, PathType, \
15 PotentialScalar, QuantityScalar, FluxScalar, \
16 PotentialUnit,QuantityUnit, FluxUnit
17
18#define ELECTRICAL_BLACK_BOX SEElectricalCircuitNode, SEElectricalCircuitPath, \
19 SEScalarElectricPotential, SEScalarElectricCharge, SEScalarElectricCurrent, \
20 ElectricPotentialUnit, ElectricChargeUnit, ElectricCurrentUnit
21
22#define MAP_ELECTRICAL_BLACK_BOX SEElectricalBlackBox,SEElectricalCircuitNode, SEElectricalCircuitPath
23
24#define FLUID_BLACK_BOX SEFluidCircuitNode, SEFluidCircuitPath, \
25 SEScalarPressure, SEScalarVolume, SEScalarVolumePerTime, \
26 PressureUnit, VolumeUnit, VolumePerTimeUnit
27
28#define MAP_FLUID_BLACK_BOX SEFluidBlackBox,SEFluidCircuitNode, SEFluidCircuitPath
29
30#define THERMAL_BLACK_BOX SEThermalCircuitNode, SEThermalCircuitPath, \
31 SEScalarTemperature, SEScalarEnergy, SEScalarPower, \
32 TemperatureUnit, EnergyUnit, PowerUnit
33
34#define MAP_THERMAL_BLACK_BOX SEThermalBlackBox,SEThermalCircuitNode, SEThermalCircuitPath
35
36#define CCT typename CT, typename NT, typename PT, \
37 typename CU, typename FU, typename IU, \
38 typename PU, typename QU, typename RU
39
40template<BLACK_BOX_TEMPLATE>
41class CDM_DECL SEBlackBox : public Loggable
42{
43 friend class SEBlackBoxManager;
44 friend class CommonDataModelTest;
45 template<CCT> friend class SECircuitCalculator;
46protected:
47 SEBlackBox(const std::string& name, Logger* logger) : Loggable(logger), m_Name(name) {}
48public:
49 virtual ~SEBlackBox() {}
50
51 virtual void Clear() { }
52
53 virtual std::string GetName() const { return m_Name; }
54
55 virtual void RemoveImposedPotential() { m_MiddleNode->RemoveImposedPotential(); }
56 virtual bool IsPotentialImposed() const { return m_MiddleNode->IsPotentialImposed(); }
57 virtual void ImposePotential(double v, const PotentialUnit& unit) { m_MiddleNode->ImposePotential(v, unit); }
58 virtual void ImposePotential(const PotentialScalar& s) { return m_MiddleNode->ImposePotential(s); }
59 virtual double GetPotential(const PotentialUnit& unit) const { return m_MiddleNode->GetNextPotential().GetValue(unit); }
60
61 virtual void RemoveImposedSourcePotential() { m_SourceNode->RemoveImposedPotential(); }
62 virtual bool IsSourcePotentialImposed() const { return m_SourceNode->IsPotentialImposed(); }
63 virtual void ImposeSourcePotential(double v, const PotentialUnit& unit) { m_SourceNode->ImposePotential(v, unit); }
64 virtual void ImposeSourcePotential(const PotentialScalar& s) { return m_SourceNode->ImposePotential(s); }
65 virtual double GetSourcePotential(const PotentialUnit& unit) const { return m_SourceNode->GetNextPotential().GetValue(unit); }
66
67 virtual void RemoveImposedTargetPotential() { m_TargetNode->RemoveImposedPotential(); }
68 virtual bool IsTargetPotentialImposed() const { return m_TargetNode->IsPotentialImposed(); }
69 virtual void ImposeTargetPotential(double v, const PotentialUnit& unit) { m_TargetNode->ImposePotential(v, unit); }
70 virtual void ImposeTargetPotential(const PotentialScalar& s) { return m_TargetNode->ImposePotential(s); }
71 virtual double GetTargetPotential(const PotentialUnit& unit) const { return m_TargetNode->GetNextPotential().GetValue(unit); }
72
73 virtual void RemoveImposedSourceFlux() { m_SourcePath->RemoveImposedFlux(); }
74 virtual bool IsSourceFluxImposed() const { return m_SourcePath->IsFluxImposed(); }
75 virtual void ImposeSourceFlux(double v, const FluxUnit& unit) { m_SourcePath->ImposeFlux(v, unit); }
76 virtual void ImposeSourceFlux(const FluxScalar& s) { m_SourcePath->ImposeFlux(s); }
77 virtual double GetSourceFlux(const FluxUnit& unit) const { return m_SourcePath->GetNextFlux().GetValue(unit); }
78
79 virtual void RemoveImposedTargetFlux() { m_TargetPath->RemoveImposedFlux(); }
80 virtual bool IsTargetFluxImposed() const { return m_TargetPath->IsFluxImposed(); }
81 virtual void ImposeTargetFlux(double v, const FluxUnit& unit) { m_TargetPath->ImposeFlux(v, unit); }
82 virtual void ImposeTargetFlux(const FluxScalar& s) { m_TargetPath->ImposeFlux(s); }
83 virtual double GetTargetFlux(const FluxUnit& unit) const { return m_TargetPath->GetNextFlux().GetValue(unit); }
84
85 virtual void RemoveImposedQuantity() { m_MiddleNode->RemoveImposedQuantity(); }
86 virtual bool IsQuantityImposed() const { return m_MiddleNode->IsQuantityImposed(); }
87 virtual void ImposeQuantity(double v, const QuantityUnit& unit) { m_MiddleNode->ImposeQuantity(v, unit); }
88 virtual void ImposeQuantity(const QuantityScalar& s) { m_MiddleNode->ImposeQuantity(s); }
89 virtual double GetQuantity(const QuantityUnit& unit) const { return m_MiddleNode->GetNextQuantity().GetValue(unit); }
90
91 // Circuit Elements (If available)
92 virtual bool HasMiddleNode() const { return m_MiddleNode != nullptr; }
93 virtual NodeType* GetMiddleNode() const { return m_MiddleNode; }
94
95 virtual bool HasSourceNode() const { return m_SourceNode != nullptr; }
96 virtual NodeType* GetSourceNode() const { return m_SourceNode; }
97
98 virtual bool HasTargetNode() const { return m_TargetNode != nullptr; }
99 virtual NodeType* GetTargetNode() const { return m_TargetNode; }
100
101 virtual bool HasSourcePath() const { return m_SourcePath != nullptr; }
102 virtual PathType* GetSourcePath() const { return m_SourcePath; }
103
104 virtual bool HasTargetPath() const { return m_TargetPath != nullptr; }
105 virtual PathType* GetTargetPath() const { return m_TargetPath; }
106
107protected:
108 // Set Circuit Elements
109 virtual void SetMiddleNode(NodeType* n) { m_MiddleNode = n; }
110 virtual void SetSourceNode(NodeType* n) { m_SourceNode = n; }
111 virtual void SetTargetNode(NodeType* n) { m_TargetNode = n; }
112 virtual void SetSourcePath(PathType* p) { m_SourcePath = p; }
113 virtual void SetTargetPath(PathType* p) { m_TargetPath = p; }
114
115 std::string m_Name;
116 // Circuit Elements
117 NodeType* m_MiddleNode = nullptr;
118 NodeType* m_SourceNode = nullptr;
119 NodeType* m_TargetNode = nullptr;
120 PathType* m_SourcePath = nullptr;
121 PathType* m_TargetPath = nullptr;
122};
123
124#include "cdm/blackbox/SEBlackBox.hxx"
Definition: CommonDataModelTest.h:26
Definition: Logger.h:23
Definition: Logger.h:71
Definition: SEBlackBox.h:42
virtual NodeType * GetSourceNode() const
Definition: SEBlackBox.h:96
virtual void SetMiddleNode(NodeType *n)
Definition: SEBlackBox.h:109
virtual void SetSourceNode(NodeType *n)
Definition: SEBlackBox.h:110
virtual PathType * GetSourcePath() const
Definition: SEBlackBox.h:102
virtual void ImposeTargetFlux(double v, const FluxUnit &unit)
Definition: SEBlackBox.h:81
virtual void ImposeSourceFlux(const FluxScalar &s)
Definition: SEBlackBox.h:76
virtual PathType * GetTargetPath() const
Definition: SEBlackBox.h:105
virtual void ImposeTargetPotential(double v, const PotentialUnit &unit)
Definition: SEBlackBox.h:69
virtual bool HasTargetNode() const
Definition: SEBlackBox.h:98
virtual void ImposeQuantity(const QuantityScalar &s)
Definition: SEBlackBox.h:88
virtual void ImposePotential(double v, const PotentialUnit &unit)
Definition: SEBlackBox.h:57
std::string m_Name
Definition: SEBlackBox.h:115
virtual bool HasSourcePath() const
Definition: SEBlackBox.h:101
virtual double GetQuantity(const QuantityUnit &unit) const
Definition: SEBlackBox.h:89
virtual void ImposeQuantity(double v, const QuantityUnit &unit)
Definition: SEBlackBox.h:87
virtual double GetSourceFlux(const FluxUnit &unit) const
Definition: SEBlackBox.h:77
virtual void ImposeSourceFlux(double v, const FluxUnit &unit)
Definition: SEBlackBox.h:75
virtual double GetPotential(const PotentialUnit &unit) const
Definition: SEBlackBox.h:59
virtual bool HasSourceNode() const
Definition: SEBlackBox.h:95
virtual double GetTargetFlux(const FluxUnit &unit) const
Definition: SEBlackBox.h:83
virtual void RemoveImposedTargetPotential()
Definition: SEBlackBox.h:67
virtual ~SEBlackBox()
Definition: SEBlackBox.h:49
virtual NodeType * GetTargetNode() const
Definition: SEBlackBox.h:99
virtual void SetSourcePath(PathType *p)
Definition: SEBlackBox.h:112
virtual void ImposeTargetPotential(const PotentialScalar &s)
Definition: SEBlackBox.h:70
virtual bool IsTargetFluxImposed() const
Definition: SEBlackBox.h:80
SEBlackBox(const std::string &name, Logger *logger)
Definition: SEBlackBox.h:47
virtual void ImposeSourcePotential(double v, const PotentialUnit &unit)
Definition: SEBlackBox.h:63
virtual void SetTargetPath(PathType *p)
Definition: SEBlackBox.h:113
virtual bool IsTargetPotentialImposed() const
Definition: SEBlackBox.h:68
virtual void RemoveImposedQuantity()
Definition: SEBlackBox.h:85
virtual bool IsQuantityImposed() const
Definition: SEBlackBox.h:86
virtual void ImposeTargetFlux(const FluxScalar &s)
Definition: SEBlackBox.h:82
virtual std::string GetName() const
Definition: SEBlackBox.h:53
virtual void ImposeSourcePotential(const PotentialScalar &s)
Definition: SEBlackBox.h:64
virtual void RemoveImposedPotential()
Definition: SEBlackBox.h:55
virtual NodeType * GetMiddleNode() const
Definition: SEBlackBox.h:93
virtual void RemoveImposedTargetFlux()
Definition: SEBlackBox.h:79
virtual double GetTargetPotential(const PotentialUnit &unit) const
Definition: SEBlackBox.h:71
virtual void Clear()
Definition: SEBlackBox.h:51
virtual bool IsPotentialImposed() const
Definition: SEBlackBox.h:56
virtual bool IsSourcePotentialImposed() const
Definition: SEBlackBox.h:62
virtual double GetSourcePotential(const PotentialUnit &unit) const
Definition: SEBlackBox.h:65
virtual void RemoveImposedSourcePotential()
Definition: SEBlackBox.h:61
virtual bool IsSourceFluxImposed() const
Definition: SEBlackBox.h:74
virtual void ImposePotential(const PotentialScalar &s)
Definition: SEBlackBox.h:58
virtual bool HasMiddleNode() const
Definition: SEBlackBox.h:92
virtual void RemoveImposedSourceFlux()
Definition: SEBlackBox.h:73
virtual void SetTargetNode(NodeType *n)
Definition: SEBlackBox.h:111
virtual bool HasTargetPath() const
Definition: SEBlackBox.h:104
Definition: SEBlackBoxManager.h:11
Definition: SECircuitCalculator.h:24

Distributed under the Apache License, Version 2.0.

See accompanying NOTICE file for details.