SECircuitManager.hxx
1/* Distributed under the Apache License, Version 2.0.
2 See accompanying NOTICE file for details.*/
3
4#include "cdm/circuit/fluid/SEFluidCircuit.h"
5#include "cdm/circuit/fluid/SEFluidCircuitNode.h"
6#include "cdm/circuit/fluid/SEFluidCircuitPath.h"
7
8#include "cdm/circuit/thermal/SEThermalCircuit.h"
9#include "cdm/circuit/thermal/SEThermalCircuitNode.h"
10#include "cdm/circuit/thermal/SEThermalCircuitPath.h"
11
12#include "cdm/circuit/electrical/SEElectricalCircuit.h"
13#include "cdm/circuit/electrical/SEElectricalCircuitNode.h"
14#include "cdm/circuit/electrical/SEElectricalCircuitPath.h"
15
16
17template<CIRCUIT_LEDGER_TEMPLATE>
19{
20 DELETE_MAP_SECOND(nodes);
21 DELETE_MAP_SECOND(paths);
22 DELETE_MAP_SECOND(circuits);
23}
24
25template<CIRCUIT_LEDGER_TEMPLATE> NodeType& SECircuitManager::CreateNode(const std::string& name, SECircuitLedger<CIRCUIT_LEDGER_TYPES>& ledger)
26{
27 NodeType* node = ledger.nodes[name];
28 if (node != nullptr)
29 {
30 Error("Node already exists with name " + name + ", not creating a new node, returning the existing node");
31 return *node;
32 }
33 node = new NodeType(name, GetLogger());
34 ledger.nodes[name] = node;
35 return *node;
36}
37template SEFluidCircuitNode& SECircuitManager::CreateNode<FLUID_LEDGER_TYPES>(const std::string& name, SECircuitLedger<FLUID_LEDGER_TYPES>& ledger);
38template SEElectricalCircuitNode& SECircuitManager::CreateNode<ELECTRICAL_LEDGER_TYPES>(const std::string& name, SECircuitLedger<ELECTRICAL_LEDGER_TYPES>& ledger);
39template SEThermalCircuitNode& SECircuitManager::CreateNode<THERMAL_LEDGER_TYPES>(const std::string& name, SECircuitLedger<THERMAL_LEDGER_TYPES>& ledger);
40
41template<CIRCUIT_LEDGER_TEMPLATE> void SECircuitManager::DeleteNode(const std::string& name, SECircuitLedger<CIRCUIT_LEDGER_TYPES>& ledger)
42{
43 PathType* path;
44 NodeType* node = GetNode(name, ledger);
45 if (node == nullptr)
46 return;
47 // Remove this node from any circuits
48 for (auto citr : ledger.circuits)
49 citr.second->RemoveNode(*node);
50 // Search the paths and delete any paths that has this node
51 // And remove those paths from any circuits
52 for (auto pitr = ledger.paths.begin(); pitr != ledger.paths.end();)
53 {
54 if (pitr->second->GetSourceNode().GetName() == name)
55 {
56 path = pitr->second;
57 ledger.paths.erase(pitr++);
58 for (auto citr : ledger.circuits)
59 citr.second->RemovePath(*path);
60 SAFE_DELETE(path);
61 }
62 else
63 pitr++;
64 }
65 ledger.nodes.erase(node->GetName());
66 SAFE_DELETE(node);
67}
68template void SECircuitManager::DeleteNode<FLUID_LEDGER_TYPES>(const std::string& name, SECircuitLedger<FLUID_LEDGER_TYPES>& ledger);
69template void SECircuitManager::DeleteNode<ELECTRICAL_LEDGER_TYPES>(const std::string& name, SECircuitLedger<ELECTRICAL_LEDGER_TYPES>& ledger);
70template void SECircuitManager::DeleteNode<THERMAL_LEDGER_TYPES>(const std::string& name, SECircuitLedger<THERMAL_LEDGER_TYPES>& ledger);
71
72template<CIRCUIT_LEDGER_TEMPLATE> bool SECircuitManager::HasNode(const std::string& name, const SECircuitLedger<CIRCUIT_LEDGER_TYPES>& ledger) const
73{
74 return ledger.nodes.find(name) != ledger.nodes.end();
75}
76template bool SECircuitManager::HasNode<FLUID_LEDGER_TYPES>(const std::string& name, const SECircuitLedger<FLUID_LEDGER_TYPES>& ledger) const;
77template bool SECircuitManager::HasNode<ELECTRICAL_LEDGER_TYPES>(const std::string& name, const SECircuitLedger<ELECTRICAL_LEDGER_TYPES>& ledger) const;
78template bool SECircuitManager::HasNode<THERMAL_LEDGER_TYPES>(const std::string& name, const SECircuitLedger<THERMAL_LEDGER_TYPES>& ledger) const;
79
80template<CIRCUIT_LEDGER_TEMPLATE> NodeType* SECircuitManager::GetNode(const std::string& name, SECircuitLedger<CIRCUIT_LEDGER_TYPES>& ledger)
81{
82 auto itr = ledger.nodes.find(name);
83 if (itr != ledger.nodes.end())
84 return itr->second;
85 return nullptr;
86}
87template SEFluidCircuitNode* SECircuitManager::GetNode<FLUID_LEDGER_TYPES>(const std::string& name, SECircuitLedger<FLUID_LEDGER_TYPES>& ledger);
88template SEElectricalCircuitNode* SECircuitManager::GetNode<ELECTRICAL_LEDGER_TYPES>(const std::string& name, SECircuitLedger<ELECTRICAL_LEDGER_TYPES>& ledger);
89template SEThermalCircuitNode* SECircuitManager::GetNode<THERMAL_LEDGER_TYPES>(const std::string& name, SECircuitLedger<THERMAL_LEDGER_TYPES>& ledger);
90
91template<CIRCUIT_LEDGER_TEMPLATE> const NodeType* SECircuitManager::GetNode(const std::string& name, const SECircuitLedger<CIRCUIT_LEDGER_TYPES>& ledger) const
92{
93 auto itr = ledger.nodes.find(name);
94 if (itr != ledger.nodes.end())
95 return itr->second;
96 return nullptr;
97}
98template const SEFluidCircuitNode* SECircuitManager::GetNode<FLUID_LEDGER_TYPES>(const std::string& name, const SECircuitLedger<FLUID_LEDGER_TYPES>& ledger) const;
99template const SEElectricalCircuitNode* SECircuitManager::GetNode<ELECTRICAL_LEDGER_TYPES>(const std::string& name, const SECircuitLedger<ELECTRICAL_LEDGER_TYPES>& ledger) const;
100template const SEThermalCircuitNode* SECircuitManager::GetNode<THERMAL_LEDGER_TYPES>(const std::string& name, const SECircuitLedger<THERMAL_LEDGER_TYPES>& ledger) const;
101
102template<CIRCUIT_LEDGER_TEMPLATE> PathType& SECircuitManager::CreatePath(NodeType& src, NodeType& tgt, const std::string& name, SECircuitLedger<CIRCUIT_LEDGER_TYPES>& ledger)
103{
104 PathType* path = ledger.paths[name];
105 if (path != nullptr)
106 {
107 Warning("Path already exists with name " + name + ", not creating a new path, returning the existing path");
108 return *path;
109 }
110 path = new PathType(src, tgt, name);
111 ledger.paths[name] = path;
112 return *path;
113}
114template SEFluidCircuitPath& SECircuitManager::CreatePath<FLUID_LEDGER_TYPES>(SEFluidCircuitNode& src, SEFluidCircuitNode& tgt, const std::string& name, SECircuitLedger<FLUID_LEDGER_TYPES>& ledger);
115template SEElectricalCircuitPath& SECircuitManager::CreatePath<ELECTRICAL_LEDGER_TYPES>(SEElectricalCircuitNode& src, SEElectricalCircuitNode& tgt, const std::string& name, SECircuitLedger<ELECTRICAL_LEDGER_TYPES>& ledger);
116template SEThermalCircuitPath& SECircuitManager::CreatePath<THERMAL_LEDGER_TYPES>(SEThermalCircuitNode& src, SEThermalCircuitNode& tgt, const std::string& name, SECircuitLedger<THERMAL_LEDGER_TYPES>& ledger);
117
118template<CIRCUIT_LEDGER_TEMPLATE> void SECircuitManager::DeletePath(const std::string& name, SECircuitLedger<CIRCUIT_LEDGER_TYPES>& ledger)
119{
120 PathType* path = GetPath(name, ledger);
121 if (path == nullptr)
122 return;
123 ledger.paths.erase(name);
124 for (auto itr : ledger.circuits)
125 itr.second->RemovePath(*path);
126 SAFE_DELETE(path);
127}
128template void SECircuitManager::DeletePath<FLUID_LEDGER_TYPES>(const std::string& name, SECircuitLedger<FLUID_LEDGER_TYPES>& ledger);
129template void SECircuitManager::DeletePath<ELECTRICAL_LEDGER_TYPES>(const std::string& name, SECircuitLedger<ELECTRICAL_LEDGER_TYPES>& ledger);
130template void SECircuitManager::DeletePath<THERMAL_LEDGER_TYPES>(const std::string& name, SECircuitLedger<THERMAL_LEDGER_TYPES>& ledger);
131
132template<CIRCUIT_LEDGER_TEMPLATE> bool SECircuitManager::HasPath(const std::string& name, const SECircuitLedger<CIRCUIT_LEDGER_TYPES>& ledger) const
133{
134 return ledger.paths.find(name) != ledger.paths.end();
135}
136template bool SECircuitManager::HasPath<FLUID_LEDGER_TYPES>(const std::string& name, const SECircuitLedger<FLUID_LEDGER_TYPES>& ledger) const;
137template bool SECircuitManager::HasPath<ELECTRICAL_LEDGER_TYPES>(const std::string& name, const SECircuitLedger<ELECTRICAL_LEDGER_TYPES>& ledger) const;
138template bool SECircuitManager::HasPath<THERMAL_LEDGER_TYPES>(const std::string& name, const SECircuitLedger<THERMAL_LEDGER_TYPES>& ledger) const;
139
140template<CIRCUIT_LEDGER_TEMPLATE> PathType* SECircuitManager::GetPath(const std::string& name, SECircuitLedger<CIRCUIT_LEDGER_TYPES>& ledger)
141{
142 auto itr = ledger.paths.find(name);
143 if (itr != ledger.paths.end())
144 return itr->second;
145 return nullptr;
146}
147template SEFluidCircuitPath* SECircuitManager::GetPath<FLUID_LEDGER_TYPES>(const std::string& name, SECircuitLedger<FLUID_LEDGER_TYPES>& ledger);
148template SEElectricalCircuitPath* SECircuitManager::GetPath<ELECTRICAL_LEDGER_TYPES>(const std::string& name, SECircuitLedger<ELECTRICAL_LEDGER_TYPES>& ledger);
149template SEThermalCircuitPath* SECircuitManager::GetPath<THERMAL_LEDGER_TYPES>(const std::string& name, SECircuitLedger<THERMAL_LEDGER_TYPES>& ledger);
150
151template<CIRCUIT_LEDGER_TEMPLATE> const PathType* SECircuitManager::GetPath(const std::string& name, const SECircuitLedger<CIRCUIT_LEDGER_TYPES>& ledger) const
152{
153 auto itr = ledger.paths.find(name);
154 if (itr != ledger.paths.end())
155 return itr->second;
156 return nullptr;
157}
158template const SEFluidCircuitPath* SECircuitManager::GetPath<FLUID_LEDGER_TYPES>(const std::string& name, const SECircuitLedger<FLUID_LEDGER_TYPES>& ledger) const;
159template const SEElectricalCircuitPath* SECircuitManager::GetPath<ELECTRICAL_LEDGER_TYPES>(const std::string& name, const SECircuitLedger<ELECTRICAL_LEDGER_TYPES>& ledger) const;
160template const SEThermalCircuitPath* SECircuitManager::GetPath<THERMAL_LEDGER_TYPES>(const std::string& name, const SECircuitLedger<THERMAL_LEDGER_TYPES>& ledger) const;
161
162template<CIRCUIT_LEDGER_TEMPLATE> CircuitType& SECircuitManager::CreateCircuit(const std::string& name, SECircuitLedger<CIRCUIT_LEDGER_TYPES>& ledger)
163{
164 CircuitType* circuit = ledger.circuits[name];
165 if (circuit != nullptr)
166 {
167 Error(" Circuit already exists with name " + name + ", not creating a new circuit, returning the existing circuit");
168 return *circuit;
169 }
170 circuit = new CircuitType(name, *this);
171 ledger.circuits[name] = circuit;
172 return *circuit;
173}
174template SEFluidCircuit& SECircuitManager::CreateCircuit<FLUID_LEDGER_TYPES>(const std::string& name, SECircuitLedger<FLUID_LEDGER_TYPES>& ledger);
175template SEElectricalCircuit& SECircuitManager::CreateCircuit<ELECTRICAL_LEDGER_TYPES>(const std::string& name, SECircuitLedger<ELECTRICAL_LEDGER_TYPES>& ledger);
176template SEThermalCircuit& SECircuitManager::CreateCircuit<THERMAL_LEDGER_TYPES>(const std::string& name, SECircuitLedger<THERMAL_LEDGER_TYPES>& ledger);
177
178template<CIRCUIT_LEDGER_TEMPLATE> void SECircuitManager::DeleteCircuit(const std::string& name, SECircuitLedger<CIRCUIT_LEDGER_TYPES>& ledger)
179{
180 CircuitType* circuit = GetCircuit(name, ledger);
181 if (circuit == nullptr)
182 return;
183 ledger.circuits.erase(name);
184 SAFE_DELETE(circuit);
185}
186template void SECircuitManager::DeleteCircuit<FLUID_LEDGER_TYPES>(const std::string& name, SECircuitLedger<FLUID_LEDGER_TYPES>& ledger);
187template void SECircuitManager::DeleteCircuit<ELECTRICAL_LEDGER_TYPES>(const std::string& name, SECircuitLedger<ELECTRICAL_LEDGER_TYPES>& ledger);
188template void SECircuitManager::DeleteCircuit<THERMAL_LEDGER_TYPES>(const std::string& name, SECircuitLedger<THERMAL_LEDGER_TYPES>& ledger);
189
190template<CIRCUIT_LEDGER_TEMPLATE> bool SECircuitManager::HasCircuit(const std::string& name, const SECircuitLedger<CIRCUIT_LEDGER_TYPES>& ledger) const
191{
192 return ledger.circuits.find(name) != ledger.circuits.end();
193}
194template bool SECircuitManager::HasCircuit<FLUID_LEDGER_TYPES>(const std::string& name, const SECircuitLedger<FLUID_LEDGER_TYPES>& ledger) const;
195template bool SECircuitManager::HasCircuit<ELECTRICAL_LEDGER_TYPES>(const std::string& name, const SECircuitLedger<ELECTRICAL_LEDGER_TYPES>& ledger) const;
196template bool SECircuitManager::HasCircuit<THERMAL_LEDGER_TYPES>(const std::string& name, const SECircuitLedger<THERMAL_LEDGER_TYPES>& ledger) const;
197
198template<CIRCUIT_LEDGER_TEMPLATE> CircuitType* SECircuitManager::GetCircuit(const std::string& name, SECircuitLedger<CIRCUIT_LEDGER_TYPES>& ledger)
199{
200 auto itr = ledger.circuits.find(name);
201 if (itr != ledger.circuits.end())
202 return itr->second;
203 return nullptr;
204}
205template SEFluidCircuit* SECircuitManager::GetCircuit<FLUID_LEDGER_TYPES>(const std::string& name, SECircuitLedger<FLUID_LEDGER_TYPES>& ledger);
206template SEElectricalCircuit* SECircuitManager::GetCircuit<ELECTRICAL_LEDGER_TYPES>(const std::string& name, SECircuitLedger<ELECTRICAL_LEDGER_TYPES>& ledger);
207template SEThermalCircuit* SECircuitManager::GetCircuit<THERMAL_LEDGER_TYPES>(const std::string& name, SECircuitLedger<THERMAL_LEDGER_TYPES>& ledger);
208
209template<CIRCUIT_LEDGER_TEMPLATE> const CircuitType* SECircuitManager::GetCircuit(const std::string& name, const SECircuitLedger<CIRCUIT_LEDGER_TYPES>& ledger) const
210{
211 auto itr = ledger.circuits.find(name);
212 if (itr != ledger.circuits.end())
213 return itr->second;
214 return nullptr;
215}
216template const SEFluidCircuit* SECircuitManager::GetCircuit<FLUID_LEDGER_TYPES>(const std::string& name, const SECircuitLedger<FLUID_LEDGER_TYPES>& ledger) const;
217template const SEElectricalCircuit* SECircuitManager::GetCircuit<ELECTRICAL_LEDGER_TYPES>(const std::string& name, const SECircuitLedger<ELECTRICAL_LEDGER_TYPES>& ledger) const;
218template const SEThermalCircuit* SECircuitManager::GetCircuit<THERMAL_LEDGER_TYPES>(const std::string& name, const SECircuitLedger<THERMAL_LEDGER_TYPES>& ledger) const;
virtual void Warning(std::string const &msg) const
Definition: SimpleLogger.cpp:359
virtual Logger * GetLogger() const
Definition: SimpleLogger.cpp:317
virtual void Error(std::string const &msg) const
Definition: SimpleLogger.cpp:377
Definition: SECircuitManager.h:20
void Clear()
Definition: SECircuitManager.hxx:18
std::map< std::string, PathType * > paths
Definition: SECircuitManager.h:29
std::map< std::string, NodeType * > nodes
Definition: SECircuitManager.h:28
std::map< std::string, CircuitType * > circuits
Definition: SECircuitManager.h:30
PathType * GetPath(const std::string &name, SECircuitLedger< CIRCUIT_LEDGER_TYPES > &ledger)
Definition: SECircuitManager.hxx:140
CircuitType & CreateCircuit(const std::string &name, SECircuitLedger< CIRCUIT_LEDGER_TYPES > &ledger)
Definition: SECircuitManager.hxx:162
PathType & CreatePath(NodeType &src, NodeType &tgt, const std::string &name, SECircuitLedger< CIRCUIT_LEDGER_TYPES > &ledger)
Definition: SECircuitManager.hxx:102
NodeType & CreateNode(const std::string &name, SECircuitLedger< CIRCUIT_LEDGER_TYPES > &ledger)
Definition: SECircuitManager.hxx:25
CircuitType * GetCircuit(const std::string &name, SECircuitLedger< CIRCUIT_LEDGER_TYPES > &ledger)
Definition: SECircuitManager.hxx:198
NodeType * GetNode(const std::string &name, SECircuitLedger< CIRCUIT_LEDGER_TYPES > &ledger)
Definition: SECircuitManager.hxx:80
bool HasNode(const std::string &name, const SECircuitLedger< CIRCUIT_LEDGER_TYPES > &ledger) const
Definition: SECircuitManager.hxx:72
bool HasPath(const std::string &name, const SECircuitLedger< CIRCUIT_LEDGER_TYPES > &ledger) const
Definition: SECircuitManager.hxx:132
void DeletePath(const std::string &name, SECircuitLedger< CIRCUIT_LEDGER_TYPES > &ledger)
Definition: SECircuitManager.hxx:118
void DeleteNode(const std::string &name, SECircuitLedger< CIRCUIT_LEDGER_TYPES > &ledger)
Definition: SECircuitManager.hxx:41
bool HasCircuit(const std::string &name, const SECircuitLedger< CIRCUIT_LEDGER_TYPES > &ledger) const
Definition: SECircuitManager.hxx:190
void DeleteCircuit(const std::string &name, SECircuitLedger< CIRCUIT_LEDGER_TYPES > &ledger)
Definition: SECircuitManager.hxx:178
Definition: SEElectricalCircuit.h:12
Definition: SEElectricalCircuitNode.h:10
Definition: SEElectricalCircuitPath.h:9
Definition: SEFluidCircuit.h:12
Definition: SEFluidCircuitNode.h:10
Definition: SEFluidCircuitPath.h:9
Definition: SEThermalCircuit.h:12
Definition: SEThermalCircuitNode.h:10
Definition: SEThermalCircuitPath.h:9

Distributed under the Apache License, Version 2.0.

See accompanying NOTICE file for details.