4#define ZERO_APPROX 1e-10
5#define OPEN_RESISTANCE 1e100
7template<CIRCUIT_TEMPLATE>
12template<CIRCUIT_TEMPLATE>
18template<CIRCUIT_TEMPLATE>
21 for (
auto& itr : m_TargetPathMap)
23 for (
auto& itr : m_SourcePathMap)
25 for (
auto& itr : m_ConnectedPathMap)
29 m_TargetPathMap.clear();
30 m_SourcePathMap.clear();
31 m_ConnectedPathMap.clear();
33 m_PolarizedElementPaths.clear();
36template<CIRCUIT_TEMPLATE>
40 for (
auto& itr : m_TargetPathMap)
42 for (
auto& itr : m_SourcePathMap)
44 for (
auto& itr : m_ConnectedPathMap)
46 m_TargetPathMap.clear();
47 m_SourcePathMap.clear();
48 m_ConnectedPathMap.clear();
50 m_PolarizedElementPaths.clear();
52 for (PathType* p : m_Paths)
54 if (!p->HasValidElements())
56 m_ss << p->GetName() <<
" has invalid elements";
69 NodeType* nTgt = &p->GetTargetNode();
70 NodeType* nSrc = &p->GetSourceNode();
71 std::vector<PathType*>* tgtPaths = m_TargetPathMap[nTgt];
72 std::vector<PathType*>* srcPaths = m_SourcePathMap[nSrc];
73 std::vector<PathType*>* conSrcPaths = m_ConnectedPathMap[nSrc];
74 std::vector<PathType*>* conTgtPaths = m_ConnectedPathMap[nTgt];
75 if (tgtPaths ==
nullptr)
77 tgtPaths =
new std::vector<PathType*>();
78 m_TargetPathMap[nTgt] = tgtPaths;
80 if (srcPaths ==
nullptr)
82 srcPaths =
new std::vector<PathType*>();
83 m_SourcePathMap[nSrc] = srcPaths;
85 if (conTgtPaths ==
nullptr)
87 conTgtPaths =
new std::vector<PathType*>();
88 m_ConnectedPathMap[nTgt] = conTgtPaths;
90 if (conSrcPaths ==
nullptr)
92 conSrcPaths =
new std::vector<PathType*>();
93 m_ConnectedPathMap[nSrc] = conSrcPaths;
97 if (std::find(m_ConnectedPathMap[nSrc]->begin(), m_ConnectedPathMap[nSrc]->end(), p) != m_ConnectedPathMap[nSrc]->end() ||
98 std::find(m_ConnectedPathMap[nTgt]->begin(), m_ConnectedPathMap[nTgt]->end(), p) != m_ConnectedPathMap[nTgt]->end())
100 m_ss << p->GetName() <<
" is defined multiple times.";
104 m_TargetPathMap[nTgt]->push_back(p);
105 m_SourcePathMap[nSrc]->push_back(p);
106 m_ConnectedPathMap[nSrc]->push_back(p);
107 m_ConnectedPathMap[nTgt]->push_back(p);
110 if (p->HasNextValve())
111 m_ValvePaths.push_back(p);
112 if (p->HasNextPolarizedState())
113 m_PolarizedElementPaths.push_back(p);
117 for (NodeType* n : m_Nodes)
119 if (n->IsBlackBoxMiddle())
121 auto paths = GetConnectedPaths(*n);
122 if(paths->size() != 2)
124 Fatal(n->GetName() +
" has invalid black box configuration, must have only 2 paths associated");
129 if ((m_ValvePaths.size()+m_PolarizedElementPaths.size()) > 64)
131 Fatal(
"There are too many assumed state options. The Circuit solver can only handle up to 64 Diodes and Polar Elements in a single circuit (i.e. ~1.8e19 possible combinations).");
135template<CIRCUIT_TEMPLATE>
141template<CIRCUIT_TEMPLATE>
144 for (NodeType* n : m_Nodes)
146 if (n->IsReferenceNode())
154template<CIRCUIT_TEMPLATE>
157 if (!Contains(this->m_Nodes, node))
158 this->m_Nodes.push_back(&node);
160template<CIRCUIT_TEMPLATE>
163 this->m_Nodes.push_back(&node);
165template<CIRCUIT_TEMPLATE>
168 return Contains(m_Nodes, node);
170template<CIRCUIT_TEMPLATE>
173 return GetNode(name) !=
nullptr;
175template<CIRCUIT_TEMPLATE>
178 for (NodeType* n : m_Nodes)
180 if (n->GetName() == name)
185template<CIRCUIT_TEMPLATE>
188 for (NodeType* n : m_Nodes)
190 if (n->GetName() == name)
195template<CIRCUIT_TEMPLATE>
200template<CIRCUIT_TEMPLATE>
204 for (NodeType* n : m_Nodes)
208 m_Nodes.erase(m_Nodes.begin() + i);
214template<CIRCUIT_TEMPLATE>
218 for (NodeType* n : m_Nodes)
220 if(n->GetName()==name)
222 m_Nodes.erase(m_Nodes.begin()+i);
229template<CIRCUIT_TEMPLATE>
232 if (!Contains(m_Paths, path))
233 m_Paths.push_back(&path);
235template<CIRCUIT_TEMPLATE>
238 m_Paths.push_back(&path);
240template<CIRCUIT_TEMPLATE>
243 return Contains(m_Paths, path);
245template<CIRCUIT_TEMPLATE>
248 return GetPath(name) !=
nullptr;
250template<CIRCUIT_TEMPLATE>
253 for (PathType* p : m_Paths)
255 if(p->GetName() == name)
260template<CIRCUIT_TEMPLATE>
263 for (PathType* p : m_Paths)
265 if (p->GetName() == name)
270template<CIRCUIT_TEMPLATE>
275template<CIRCUIT_TEMPLATE>
279 for (PathType* p : m_Paths)
283 m_Paths.erase(m_Paths.begin()+i);
289template<CIRCUIT_TEMPLATE>
293 for (PathType* p : m_Paths)
295 if (p->GetName() == name)
297 m_Paths.erase(m_Paths.begin() + i);
303template<CIRCUIT_TEMPLATE>
308template<CIRCUIT_TEMPLATE>
311 return m_PolarizedElementPaths;
326template<CIRCUIT_TEMPLATE>
329 auto itr = m_TargetPathMap.find(&node);
330 if (itr == m_TargetPathMap.end())
332 Error(
"Circuit does not have path information for node : " + node.GetName());
350template<CIRCUIT_TEMPLATE>
353 auto itr = m_SourcePathMap.find(&node);
354 if (itr == m_SourcePathMap.end())
356 Error(
"Circuit does not have path information for node : " + node.GetName());
374template<CIRCUIT_TEMPLATE>
377 auto itr = m_ConnectedPathMap.find(&node);
378 if (itr == m_ConnectedPathMap.end())
380 Error(
"Circuit does not have path information for node : " + node.GetName());
390template<CIRCUIT_TEMPLATE>
393 for(PathType* p : m_Paths)
395 if (p->HasResistanceBaseline())
397 p->GetResistance().Copy(p->GetResistanceBaseline());
398 p->GetNextResistance().Copy(p->GetResistanceBaseline());
401 if (p->HasCapacitanceBaseline())
403 p->GetCapacitance().Copy(p->GetCapacitanceBaseline());
404 p->GetNextCapacitance().Copy(p->GetCapacitanceBaseline());
407 if (p->HasInductanceBaseline())
409 p->GetInductance().Copy(p->GetInductanceBaseline());
410 p->GetNextInductance().Copy(p->GetInductanceBaseline());
413 if (p->HasFluxSourceBaseline())
415 p->GetFluxSource().Copy(p->GetFluxSourceBaseline());
416 p->GetNextFluxSource().Copy(p->GetFluxSourceBaseline());
419 if (p->HasPotentialSourceBaseline())
421 p->GetPotentialSource().Copy(p->GetPotentialSourceBaseline());
422 p->GetNextPotentialSource().Copy(p->GetPotentialSourceBaseline());
426 p->SetNextSwitch(p->GetSwitch());
428 p->SetNextValve(p->GetValve());
431 for (NodeType* n : m_Nodes)
433 if (n->HasQuantityBaseline())
435 n->GetQuantity().Copy(n->GetQuantityBaseline());
436 n->GetNextQuantity().Copy(n->GetQuantityBaseline());
441#include "cdm/circuit/electrical/SEElectricalCircuit.h"
443#include "cdm/circuit/fluid/SEFluidCircuit.h"
445#include "cdm/circuit/thermal/SEThermalCircuit.h"
virtual const std::vector< PathType * > & GetValvePaths()
Definition: SECircuit.cpp:307
virtual const std::vector< PathType * > * GetSourcePaths(const NodeType &node) const
Returns all source paths for a node.
Definition: SECircuit.cpp:354
virtual void RemoveNode(const NodeType &node)
Definition: SECircuit.cpp:204
virtual std::string GetName() const
Definition: SECircuit.cpp:139
virtual void RemovePath(const PathType &path)
Definition: SECircuit.cpp:279
virtual void AddPath(PathType &node)
Definition: SECircuit.cpp:233
virtual const std::vector< PathType * > * GetTargetPaths(const NodeType &node) const
Returns all target paths for a node.
Definition: SECircuit.cpp:330
virtual bool HasPath(PathType &node)
Definition: SECircuit.cpp:244
virtual void AddNode(NodeType &node)
Definition: SECircuit.cpp:158
virtual const std::vector< PathType * > * GetConnectedPaths(const NodeType &node) const
Returns all source paths for a node.
Definition: SECircuit.cpp:378
virtual ~SECircuit()
Definition: SECircuit.cpp:16
SECircuit(const std::string &name, Logger *logger)
Definition: SECircuit.cpp:11
virtual NodeType * GetNode(const std::string &name)
Definition: SECircuit.cpp:179
virtual void ForceAddNode(NodeType &node)
Definition: SECircuit.cpp:164
virtual void ForceAddPath(PathType &node)
Definition: SECircuit.cpp:239
virtual void SetNextAndCurrentFromBaselines()
Set all Current and Next values to the Baseline values for all Elements.
Definition: SECircuit.cpp:394
virtual bool HasNode(NodeType &node)
Definition: SECircuit.cpp:169
virtual bool HasReferenceNode() const
Definition: SECircuit.cpp:145
virtual const std::vector< NodeType * > & GetNodes() const
Definition: SECircuit.cpp:199
virtual const std::vector< PathType * > & GetPaths() const
Definition: SECircuit.cpp:274
virtual void Clear()
Definition: SECircuit.cpp:22
virtual PathType * GetPath(const std::string &name)
Definition: SECircuit.cpp:254
virtual void StateChange()
Definition: SECircuit.cpp:40
virtual const std::vector< PathType * > & GetPolarizedElementPaths()
Definition: SECircuit.cpp:312