Harmony
HARMONic stabilitY assessment of PE-penetrated power systems
Loading...
Searching...
No Matches
network.h
Go to the documentation of this file.
1
6#ifndef NETWORK_H
7#define NETWORK_H
8
9#include "Constants.h"
10
11#include <memory>
12
13class Bus;
14class Element;
15class SubNetwork;
16
22using Net = std::unordered_map<Bus*, std::vector<Element*>>;
23
36class Network {
37protected:
38 std::unordered_map<std::string, Bus*> buses;
39 std::unordered_map<std::string, Element*> elements;
40 std::unordered_map<Bus*, std::vector<Element*>> connections;
41
42 int pins = 0;
43
44 std::vector<std::string> ac_grid_names;
45 std::vector<std::string> dc_grid_names;
46
47 std::unordered_map<std::string, SubNetwork*> ac_grids;
48 std::unordered_map<std::string, SubNetwork*> dc_grids;
49 std::unordered_map<std::string, Element*> converters;
50
52 bool ownsResources_ = true;
53
54private:
55 std::unordered_map<std::string, std::unique_ptr<Bus>> ownedBuses_;
56 std::unordered_map<std::string, std::unique_ptr<Element>> ownedElements_;
57 std::unordered_map<std::string, std::unique_ptr<SubNetwork>> ownedGrids_;
58
59public:
60
65
69 virtual ~Network();
70
72 void addBus(const std::string& busName, std::unique_ptr<Bus> bus);
73
75 void addBus(Bus* bus);
76
78 void addBus(const std::string& busName, Bus* bus);
79
81 void addBusView(const std::string& busName, Bus* bus);
82
84 void addElement(const std::string& designator, std::unique_ptr<Element> elem);
85
87 void addElement(Element* elem);
88
90 void addElement(const std::string& designator, Element* elem);
91
93 void addElementView(const std::string& designator, Element* elem);
94
101 void connectElementToBus(Element* elem, int terminal, Bus* bus);
102
107 void deleteElement(const std::string& designator);
108
113 void deleteBus(const std::string& busName);
114
118 void printConnections();
119
123 void printBuses();
124
128 void printElements();
129
133 void print_summary() const;
134
139 const std::unordered_map<std::string, Bus*>& getBuses() const { return buses; }
140
145 const std::unordered_map<std::string, Element*>& getElements() const { return elements; }
146
151 std::unordered_map<std::string, Element*>& getElements() { return elements; }
152
157 const std::unordered_map<Bus*, std::vector<Element*>>& getConnections() const { return connections; }
158
163 std::unordered_map<Bus*, std::vector<Element*>>& getConnections() { return connections; }
164
168 void add_areas();
169
176 void empty_areas();
177
182 bool is_area_empty() {return ac_grids.empty() && dc_grids.empty(); }
183
188 vector<string> get_ac_grid_names() { return ac_grid_names; };
189
194 vector<string> get_dc_grid_names() { return dc_grid_names; };
195
200 std::unordered_map<std::string, SubNetwork*>& get_ac_grids() { return ac_grids; }
201
206 std::unordered_map<std::string, SubNetwork*>& get_dc_grids() { return dc_grids; }
207
212 std::unordered_map<std::string, Element*>& get_converters() { return converters; }
213
214};
215
// end of network group
217
218#endif // NETWORK_H
Central include hub for Harmony: third-party libraries, standard headers, and shared type aliases.
A network node connecting one or more element terminals.
Definition Bus.h:21
Base class for multi-phase network elements with Y-parameters and MNA stamping hooks.
Definition Element.h:29
Root network model holding buses, elements, and AC/DC grid hierarchy.
Definition network.h:36
const std::unordered_map< Bus *, std::vector< Element * > > & getConnections() const
Const access to the bus-to-connected-elements map.
Definition network.h:157
bool is_area_empty()
Check whether both AC and DC grid maps are empty.
Definition network.h:182
void addBus(const std::string &busName, std::unique_ptr< Bus > bus)
Register an owned bus (transfers ownership on root networks).
Definition network.cpp:31
std::unordered_map< std::string, Bus * > buses
Definition network.h:38
void printConnections()
Print bus-to-element connection listing to standard output.
Definition network.cpp:158
bool ownsResources_
When true, buses/elements registered via addBus/addElement are owned.
Definition network.h:52
Network()
Construct an empty network with zero pins.
std::unordered_map< std::string, Element * > & get_converters()
Mutable access to the converter element map.
Definition network.h:212
void addElementView(const std::string &designator, Element *elem)
Register a non-owning element pointer (used by SubNetwork views).
Definition network.cpp:50
std::unordered_map< Bus *, std::vector< Element * > > & getConnections()
Mutable access to the bus-to-connected-elements map.
Definition network.h:163
void print_summary() const
Print a concise summary of network contents (counts and names).
Definition network.cpp:184
std::unordered_map< std::string, SubNetwork * > dc_grids
Definition network.h:48
const std::unordered_map< std::string, Element * > & getElements() const
Const access to the element designator-to-pointer map.
Definition network.h:145
const std::unordered_map< std::string, Bus * > & getBuses() const
Const access to the bus name-to-pointer map.
Definition network.h:139
void printBuses()
Print all registered buses to standard output.
Definition network.cpp:169
void addElement(const std::string &designator, std::unique_ptr< Element > elem)
Register an owned element.
Definition network.cpp:55
virtual ~Network()
Destroy the network and all owned buses, elements, and grid sub-networks.
Definition network.cpp:13
std::unordered_map< std::string, SubNetwork * > ac_grids
Definition network.h:47
vector< string > get_ac_grid_names()
Return ordered names of registered AC grids.
Definition network.h:188
std::unordered_map< std::string, SubNetwork * > & get_dc_grids()
Mutable access to the DC grid sub-network map.
Definition network.h:206
std::unordered_map< std::string, Element * > & getElements()
Mutable access to the element designator-to-pointer map.
Definition network.h:151
void addBusView(const std::string &busName, Bus *bus)
Register a non-owning bus pointer (used by SubNetwork views).
Definition network.cpp:23
std::vector< std::string > ac_grid_names
Definition network.h:44
void printElements()
Print all registered elements to standard output.
Definition network.cpp:175
void deleteBus(const std::string &busName)
Remove and destroy a bus by name.
Definition network.cpp:135
void deleteElement(const std::string &designator)
Remove and destroy an element by designator.
Definition network.cpp:113
std::unordered_map< Bus *, std::vector< Element * > > connections
Definition network.h:40
std::unordered_map< std::string, Element * > elements
Definition network.h:39
void empty_areas()
Destroy all grid sub-networks and clear grid/converter registries.
Definition network.cpp:253
std::vector< std::string > dc_grid_names
Definition network.h:45
vector< string > get_dc_grid_names()
Return ordered names of registered DC grids.
Definition network.h:194
int pins
Definition network.h:42
void connectElementToBus(Element *elem, int terminal, Bus *bus)
Connect an element terminal to a bus and record the association in both directions.
Definition network.cpp:74
std::unordered_map< std::string, Element * > converters
Definition network.h:49
std::unordered_map< std::string, SubNetwork * > & get_ac_grids()
Mutable access to the AC grid sub-network map.
Definition network.h:200
void add_areas()
Populate AC and DC grid sub-networks from the current flat network topology.
Definition network.cpp:263
Named sub-network that inherits Network topology APIs but acts as a non-owning view.
Definition SubNetwork.h:20
std::unordered_map< Bus *, std::vector< Element * > > Net
Maps each bus to the elements connected at its terminals.
Definition network.h:22