DPsim
Loading...
Searching...
No Matches
SystemTopology.h
1/* Copyright 2017-2021 Institute for Automation of Complex Power Systems,
2 * EONERC, RWTH Aachen University
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7 *********************************************************************************/
8
9#pragma once
10
11#include <algorithm>
12#include <vector>
13
14#include <dpsim-models/SimNode.h>
15#include <dpsim-models/SimPowerComp.h>
16#include <dpsim-models/TopologicalPowerComp.h>
17
18#ifdef WITH_GRAPHVIZ
19#include <dpsim-models/Graph.h>
20#endif
21
22namespace CPS {
24public:
25 using Ptr = std::shared_ptr<SystemTopology>;
26
30 TopologicalNode::List mNodes;
32 IdentifiedObject::List mComponents;
35 IdentifiedObject::List mTearComponents;
37 std::map<TopologicalNode::Ptr, TopologicalPowerComp::List> mComponentsAtNode;
38
39 // #### Deprecated ####
40 // Better use mFrequencies
45
48
51 SystemTopology(Real frequency)
52 : mFrequencies(initFrequency(frequency)), mSystemFrequency(frequency),
53 mSystemOmega(2 * PI * frequency) {}
54
57 SystemTopology(Real frequency, IdentifiedObject::List components)
58 : SystemTopology(frequency) {
59 mComponents = components;
60 }
61
63 SystemTopology(Real frequency, TopologicalNode::List nodes,
64 IdentifiedObject::List components)
65 : SystemTopology(frequency) {
66 addNodes(nodes);
67 addComponents(components);
68 componentsAtNodeList();
69 }
70
72 SystemTopology(Real frequency, Matrix frequencies,
73 TopologicalNode::List nodes, IdentifiedObject::List components)
74 : mFrequencies(frequencies), mSystemFrequency(frequency),
75 mSystemOmega(2 * PI * frequency) {
76 addNodes(nodes);
77 addComponents(components);
78 componentsAtNodeList();
79 }
80
81 Matrix initFrequency(Real frequency) const;
82
84 void reset();
85
86 // #### Add Objects to SystemTopology ####
87
89 void addNode(TopologicalNode::Ptr topNode);
90
92 void addNodeAt(TopologicalNode::Ptr topNode, UInt index);
93
95 void addNodes(const TopologicalNode::List &topNodes);
96
98 void addComponent(IdentifiedObject::Ptr component);
99
101 template <typename VarType>
102 void connectComponentToNodes(typename SimPowerComp<VarType>::Ptr component,
103 typename SimNode<VarType>::List simNodes);
104
105 void componentsAtNodeList();
106
108 void addComponents(const IdentifiedObject::List &components);
109
111 void initWithPowerflow(const SystemTopology &systemPF, CPS::Domain domain);
112
114 void addTearComponent(IdentifiedObject::Ptr component);
115
117 void addTearComponents(const IdentifiedObject::List &components);
118
119 // #### Get Objects from SystemTopology ####
120
122 template <typename Type> typename std::shared_ptr<Type> node(UInt index);
123
125 template <typename Type>
126 typename std::shared_ptr<Type> node(std::string_view name);
127
129 template <typename Type>
130 typename std::shared_ptr<Type> component(const String &name) {
131 for (auto comp : mComponents) {
132 if (comp->name() == name) {
133 auto comp2 = std::dynamic_pointer_cast<Type>(comp);
134 if (comp2)
135 return comp2;
136 else
137 return nullptr;
138 }
139 }
140 return nullptr;
141 }
142
143 std::map<String, String, std::less<>> listIdObjects() const;
144
145 // #### Operations on the SystemTopology ####
146
148 void multiply(Int numberCopies);
149
152 void removeComponent(const String &name);
153
154 void removeNode(const String &name);
155
157 template <typename VarType>
158 int checkTopologySubnets(
159 std::unordered_map<typename CPS::SimNode<VarType>::Ptr, int> &subnet);
160
162 template <typename VarType>
163 void splitSubnets(std::vector<CPS::SystemTopology> &splitSystems);
164
165#ifdef WITH_GRAPHVIZ
166 Graph::Graph topologyGraph();
167 String render();
168 void renderToFile(String filename);
169#endif
170
171private:
172 template <typename VarType> void multiplyPowerComps(Int numberCopies);
173};
174} // namespace CPS
Real mSystemOmega
System angular frequency - omega.
void addNodes(const TopologicalNode::List &topNodes)
Add multiple nodes.
Real mSystemFrequency
System frequency.
IdentifiedObject::List mComponents
List of network components.
std::shared_ptr< Type > node(UInt index)
Returns TopologicalNode by index in node list.
void initWithPowerflow(const SystemTopology &systemPF, CPS::Domain domain)
Initialize nodes and SG power from PowerFlow.
void removeComponent(const String &name)
Remove system component.
void addNode(TopologicalNode::Ptr topNode)
Adds node and initializes frequencies.
void addTearComponent(IdentifiedObject::Ptr component)
Adds component and initializes frequencies.
std::shared_ptr< Type > component(const String &name)
Returns Component by name.
TopologicalNode::List mNodes
List of network nodes.
SystemTopology(Real frequency)
void reset()
Reset state of components.
void addNodeAt(TopologicalNode::Ptr topNode, UInt index)
Adds node at specified position and initializes frequencies.
void addComponents(const IdentifiedObject::List &components)
Add multiple components.
Matrix mFrequencies
List of considered network frequencies.
void connectComponentToNodes(typename SimPowerComp< VarType >::Ptr component, typename SimNode< VarType >::List simNodes)
Connect component to simNodes.
void addComponent(IdentifiedObject::Ptr component)
Adds component and initializes frequencies.
SystemTopology(Real frequency, Matrix frequencies, TopologicalNode::List nodes, IdentifiedObject::List components)
Standard constructor for multi frequency simulations.
SystemTopology(Real frequency, IdentifiedObject::List components)
SystemTopology(Real frequency, TopologicalNode::List nodes, IdentifiedObject::List components)
Standard constructor for single frequency simulations.
void multiply(Int numberCopies)
Copy the whole topology the given number of times and add the resulting components and nodes to the t...
IdentifiedObject::List mTearComponents
SystemTopology()
Do not use this constructor.
void addTearComponents(const IdentifiedObject::List &components)
Add multiple components.
std::map< TopologicalNode::Ptr, TopologicalPowerComp::List > mComponentsAtNode
Map of network components connected to network nodes.