Skip to content

Commit b26c10a

Browse files
committed
Add bus mappings and handle number-vs-name inputs
1 parent ee90542 commit b26c10a

File tree

5 files changed

+325
-69
lines changed

5 files changed

+325
-69
lines changed

include/private/psse.hpp

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct CaseID {
2121
};
2222

2323
struct Bus {
24-
int i;
24+
std::size_t i;
2525
std::string name;
2626
double baskv;
2727
int ide;
@@ -37,7 +37,8 @@ struct Bus {
3737
};
3838

3939
struct Load {
40-
int i; // TODO: could also be specified as bus name (???)
40+
std::size_t i;
41+
std::string i_bus_name;
4142
std::string id;
4243
int status;
4344
int area;
@@ -54,7 +55,8 @@ struct Load {
5455
};
5556

5657
struct FixedBusShunt {
57-
int i; // TODO: could be bus name (???)
58+
std::size_t i;
59+
std::string i_bus_name;
5860
std::string id;
5961
int status;
6062
double gl;
@@ -67,14 +69,16 @@ struct Ownership {
6769
};
6870

6971
struct Generator {
70-
int i; // TODO: could be bus name (???)
72+
std::size_t i;
73+
std::string i_bus_name;
7174
std::string id;
7275
double pg;
7376
double qg;
7477
double qt;
7578
double qb;
7679
double vs;
77-
int ireg; // TODO: could be bus name (???)
80+
std::size_t ireg;
81+
std::string ireg_bus_name;
7882
double mbase;
7983
double zr;
8084
double zx;
@@ -91,8 +95,10 @@ struct Generator {
9195
};
9296

9397
struct Branch {
94-
int i; // TODO: could be bus name (???)
95-
int j; // TODO: could be bus name (???)
98+
std::size_t i;
99+
std::string i_bus_name;
100+
std::size_t j;
101+
std::string j_bus_name;
96102
std::string ckt;
97103
double r;
98104
double x;
@@ -137,9 +143,12 @@ struct Winding {
137143
};
138144

139145
struct Transformer {
140-
int i;
141-
int j;
142-
int k;
146+
std::size_t i;
147+
std::string i_bus_name;
148+
std::size_t j;
149+
std::string j_bus_name;
150+
std::size_t k;
151+
std::string k_bus_name;
143152
std::string ckt;
144153
int cw;
145154
int cz;
@@ -160,17 +169,51 @@ struct Transformer {
160169

161170
struct Area {
162171
int i;
163-
int isw; // TODO: could be bus name (???)
172+
std::size_t isw;
173+
std::string isw_bus_name; // TODO: resolve
164174
double pdes;
165175
double ptol;
166176
std::string arname;
167177
};
168178

179+
class BusMapping {
180+
public:
181+
struct Optional {
182+
operator bool() { return value; }
183+
bool value{false};
184+
};
185+
186+
BusMapping(const std::vector<Bus> &buses);
187+
188+
std::size_t getInternalIndex(std::size_t bus_number) const;
189+
std::size_t getInternalIndex(const std::string &bus_name) const;
190+
191+
std::size_t getBusNumber(const std::string &bus_name) const;
192+
const std::string &getBusName(std::size_t bus_number) const;
193+
194+
const Bus &getBus(const std::string &bus_name) const;
195+
const Bus &getBus(std::size_t bus_number) const;
196+
197+
void resolve(std::size_t &bus_number, std::string &bus_name,
198+
Optional opt = Optional{false}) const;
199+
200+
private:
201+
const std::vector<Bus> &buses_;
202+
std::unordered_map<std::size_t, std::size_t> id_map_;
203+
std::unordered_map<std::string, std::size_t> name_map_;
204+
};
205+
169206
struct Network {
207+
Network(CaseID &&, std::vector<Bus> &&, std::vector<Load> &&,
208+
std::vector<FixedBusShunt> &&, std::vector<Generator> &&,
209+
std::vector<Branch> &&, std::vector<Transformer> &&);
210+
211+
void resolveBusIds();
212+
170213
std::string file_name;
171214
CaseID case_id;
172215
std::vector<Bus> buses;
173-
std::unordered_map<int, int> bus_id_map;
216+
BusMapping bus_mapping;
174217
std::vector<Load> loads;
175218
std::vector<FixedBusShunt> shunts;
176219
std::vector<Generator> generators;

src/ps/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
set(PS_SRC ps.cpp psreaddata.cpp psoutput.cpp psislanding.cpp psse.cpp)
33

44
set(PS_HEADERS ${CMAKE_SOURCE_DIR}/include/ps.h
5-
${CMAKE_SOURCE_DIR}/include/psse.hpp)
5+
${CMAKE_SOURCE_DIR}/include/psse.hpp
6+
)
67

78
set_source_files_properties(${PS_SRC} PROPERTIES LANGUAGE CXX)
89

0 commit comments

Comments
 (0)