SEBlackBoxManager.h
1/* Distributed under the Apache License, Version 2.0.
2 See accompanying NOTICE file for details.*/
3
4#pragma once
5#include "cdm/blackbox/electrical/SEElectricalBlackBox.h"
6#include "cdm/blackbox/fluid/SEGasBlackBox.h"
7#include "cdm/blackbox/fluid/SELiquidBlackBox.h"
8#include "cdm/blackbox/thermal/SEThermalBlackBox.h"
9
10class CDM_DECL SEBlackBoxManager : public Loggable
11{
12 friend class CommonDataModelTest;
13public:
15 virtual ~SEBlackBoxManager();
16
17 virtual bool HasElectricalBlackBox(const std::string& name) const;
18 virtual bool HasElectricalBlackBox(const std::string& srcCmptName, const std::string& tgtCmptName) const;
19 virtual bool HasGasBlackBox(const std::string& name) const;
20 virtual bool HasGasBlackBox(const std::string& srcCmptName, const std::string& tgtCmptName) const;
21 virtual bool HasLiquidBlackBox(const std::string& name) const;
22 virtual bool HasLiquidBlackBox(const std::string& srcCmptName, const std::string& tgtCmptName) const;
23 virtual bool HasThermalBlackBox(const std::string& name) const;
24 virtual bool HasThermalBlackBox(const std::string& srcCmptName, const std::string& tgtCmptName) const;
25
26 virtual SEElectricalBlackBox* GetElectricalBlackBox(const std::string& srcCmptName, const std::string& tgtCmptName, std::string name="");
27 virtual SEGasBlackBox* GetGasBlackBox(const std::string& srcCmptName, const std::string& tgtCmptName, std::string name = "");
28 virtual SELiquidBlackBox* GetLiquidBlackBox(const std::string& srcCmptName, const std::string& tgtCmptName, std::string name = "");
29 virtual SEThermalBlackBox* GetThermalBlackBox(const std::string& srcCmptName, const std::string& tgtCmptName, std::string name = "");
30
31protected:
32 virtual SEElectricalBlackBox* CreateElectricalBlackBox(const std::string& srcCmptName, const std::string& tgtCmptName, const std::string& name);
33 virtual SEGasBlackBox* CreateGasBlackBox(const std::string& srcCmptName, const std::string& tgtCmptName, const std::string& name);
34 virtual SELiquidBlackBox* CreateLiquidBlackBox(const std::string& srcCmptName, const std::string& tgtCmptName, const std::string& name);
35 virtual SEThermalBlackBox* CreateThermalBlackBox(const std::string& srcCmptName, const std::string& tgtCmptName, const std::string& name);
36
37 virtual std::string GetBlackBoxName(const std::string& srcCmptName, const std::string& tgtCmptName) const;
38 template<typename tBlackBox> tBlackBox* CreateBlackBox(const std::string& name, std::map<std::string, tBlackBox*>& ledger);
39
40 // Map circuit compartments in a separate function, to support unit tests
41 template<typename tBlackBox, typename tCompartment, typename tLink, typename tNode, typename tPath>
42 bool MapBlackBox(tBlackBox& bb, tLink& src2bbLink, tLink& bb2tgtLink)
43 {
44 if (bb.HasCompartment())
45 Warning("Blackbox " + bb.GetName() + " already has a compartment mapped, only 1 black box can be between 2 compartments");
46
47 tCompartment& midCmpt = src2bbLink.GetTargetCompartment();
48 tCompartment& srcCmpt = src2bbLink.GetSourceCompartment();
49 tCompartment& tgtCmpt = bb2tgtLink.GetTargetCompartment();
50 bb.SetCompartment(&midCmpt);
51 bb.SetSourceCompartment(&srcCmpt);
52 bb.SetSourceLink(&src2bbLink);
53 bb.SetTargetCompartment(&tgtCmpt);
54 bb.SetTargetLink(&bb2tgtLink);
55
56 tPath& srcPath = *src2bbLink.GetPath();
57 tPath& tgtPath = *bb2tgtLink.GetPath();
58
59 return MapBlackBox<tBlackBox, tNode, tPath>(bb, srcPath, tgtPath);
60 }
61
62 // Map circuit components in a separate function, to support unit tests
63 template<typename tBlackBox, typename tNode, typename tPath>
64 bool MapBlackBox(tBlackBox& bb, tPath& srcPath, tPath& tgtPath)
65 {
66 if (bb.HasMiddleNode())
67 Warning("Blackbox " + bb.GetName() + " already has nodes mapped, only 1 blackbox can be between nodes");
68
69 tNode* midNode=nullptr;
70 tNode* srcNode=nullptr;
71 tNode* tgtNode=nullptr;
72
73 //Middle node is the shared one
74 if (&srcPath.GetSourceNode() == &tgtPath.GetSourceNode())
75 {
76 midNode = &srcPath.GetSourceNode();
77 srcNode = &srcPath.GetTargetNode();
78 tgtNode = &tgtPath.GetTargetNode();
79 }
80 else if (&srcPath.GetSourceNode() == &tgtPath.GetTargetNode())
81 {
82 midNode = &srcPath.GetSourceNode();
83 srcNode = &srcPath.GetTargetNode();
84 tgtNode = &tgtPath.GetSourceNode();
85 }
86 else if (&srcPath.GetTargetNode() == &tgtPath.GetSourceNode())
87 {
88 midNode = &srcPath.GetTargetNode();
89 srcNode = &srcPath.GetSourceNode();
90 tgtNode = &tgtPath.GetTargetNode();
91 }
92 else if (&srcPath.GetTargetNode() == &tgtPath.GetTargetNode())
93 {
94 midNode = &srcPath.GetTargetNode();
95 srcNode = &srcPath.GetSourceNode();
96 tgtNode = &tgtPath.GetSourceNode();
97 }
98 else
99 {
100 Fatal("Blackbox nodes/paths incorrectly setup.");
101 return false;
102 }
103
104 midNode->SetPartOfBlackBox(true);
105 midNode->SetBlackBoxSourceTargetNodes(*srcNode, *tgtNode);
106 midNode->SetBlackBoxSourceTargetPaths(srcPath, tgtPath);
107 srcNode->SetPartOfBlackBox(true);
108 tgtNode->SetPartOfBlackBox(true);
109 srcPath.SetPartOfBlackBox(true);
110 tgtPath.SetPartOfBlackBox(true);
111
112 bb.SetMiddleNode(midNode);
113 bb.SetSourceNode(srcNode);
114 bb.SetSourcePath(&srcPath);
115 bb.SetTargetNode(tgtNode);
116 bb.SetTargetPath(&tgtPath);
117
118 return true;
119 }
120 std::map<std::string, SEElectricalBlackBox*> m_ElectricalBoxes;
121 std::map<std::string, SEGasBlackBox*> m_GasBoxes;
122 std::map<std::string, SELiquidBlackBox*> m_LiquidBoxes;
123 std::map<std::string, SEThermalBlackBox*> m_ThermalBoxes;
124};
Definition: CommonDataModelTest.h:26
Definition: Logger.h:23
virtual void Warning(std::string const &msg) const
Definition: SimpleLogger.cpp:359
virtual void Fatal(std::string const &msg) const
Definition: SimpleLogger.cpp:407
Definition: Logger.h:71
Definition: SEBlackBoxManager.h:11
tBlackBox * CreateBlackBox(const std::string &name, std::map< std::string, tBlackBox * > &ledger)
std::map< std::string, SEGasBlackBox * > m_GasBoxes
Definition: SEBlackBoxManager.h:121
bool MapBlackBox(tBlackBox &bb, tPath &srcPath, tPath &tgtPath)
Definition: SEBlackBoxManager.h:64
std::map< std::string, SEElectricalBlackBox * > m_ElectricalBoxes
Definition: SEBlackBoxManager.h:120
std::map< std::string, SELiquidBlackBox * > m_LiquidBoxes
Definition: SEBlackBoxManager.h:122
bool MapBlackBox(tBlackBox &bb, tLink &src2bbLink, tLink &bb2tgtLink)
Definition: SEBlackBoxManager.h:42
std::map< std::string, SEThermalBlackBox * > m_ThermalBoxes
Definition: SEBlackBoxManager.h:123
Definition: SEElectricalBlackBox.h:11
Definition: SEGasBlackBox.h:11
Definition: SELiquidBlackBox.h:11
Definition: SEThermalBlackBox.h:11

Distributed under the Apache License, Version 2.0.

See accompanying NOTICE file for details.