Skip to content

Commit 4839148

Browse files
committed
Add basic v34 support and other features/fixes
1 parent eedb571 commit 4839148

File tree

4 files changed

+773
-520
lines changed

4 files changed

+773
-520
lines changed

include/private/psse.hpp

Lines changed: 145 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <array>
44
#include <istream>
5+
#include <limits>
56
#include <string>
67
#include <vector>
78
#include <unordered_map>
@@ -11,6 +12,13 @@
1112
namespace exago {
1213
namespace psse {
1314

15+
template <typename T>
16+
inline constexpr T Invalid = std::numeric_limits<T>::max();
17+
18+
template <typename T> inline constexpr bool IsInvalid(const T &val) noexcept {
19+
return val == Invalid<T>;
20+
}
21+
1422
struct CaseID {
1523
int ic;
1624
double sbase;
@@ -23,163 +31,168 @@ struct CaseID {
2331

2432
struct Bus {
2533
std::size_t i;
26-
std::string name;
27-
double baskv;
28-
int ide;
29-
int area;
30-
int zone;
31-
int owner;
32-
double vm;
33-
double va;
34+
std::string name{};
35+
double baskv{0.0};
36+
int ide{1};
37+
std::size_t area{1};
38+
std::size_t zone{1};
39+
std::size_t owner{1};
40+
double vm{1.0};
41+
double va{0.0};
3442
double nvhi{1.1};
3543
double nvlo{0.9};
3644
double evhi{1.1};
3745
double evlo{0.9};
3846
};
3947

48+
struct BusRef {
49+
std::size_t id{Invalid<std::size_t>};
50+
std::string name{};
51+
const Bus *bus{nullptr};
52+
53+
operator std::size_t() const { return id; }
54+
};
55+
4056
struct Load {
41-
std::size_t i;
42-
std::string i_bus_name;
43-
std::string id;
44-
int status;
45-
int area;
46-
int zone;
47-
double pl;
48-
double ql;
49-
double ip;
50-
double iq;
51-
double yp;
52-
double yq;
53-
int owner;
57+
BusRef i;
58+
std::string id{"1"};
59+
int status{1};
60+
std::size_t area{Invalid<std::size_t>}; // Default is area of bus i
61+
std::size_t zone{Invalid<std::size_t>}; // Default is zone of bus i
62+
double pl{0.0};
63+
double ql{0.0};
64+
double ip{0.0};
65+
double iq{0.0};
66+
double yp{0.0};
67+
double yq{0.0};
68+
std::size_t owner{Invalid<std::size_t>}; // Default is owner of bus i
5469
int scale{1};
5570
int intrpt{0};
71+
double dgenp{0.0};
72+
double dgenq{0.0};
73+
int dgenm{0};
5674
};
5775

5876
struct FixedBusShunt {
59-
std::size_t i;
60-
std::string i_bus_name;
61-
std::string id;
62-
int status;
63-
double gl;
64-
double bl;
77+
BusRef i;
78+
std::string id{"1"};
79+
int status{1};
80+
double gl{0.0};
81+
double bl{0.0};
6582
};
6683

6784
struct Ownership {
68-
int owner;
69-
double fraction;
85+
std::size_t owner{0};
86+
double fraction{1.0};
7087
};
7188

7289
struct Generator {
73-
std::size_t i;
74-
std::string i_bus_name;
75-
std::string id;
76-
double pg;
77-
double qg;
78-
double qt;
79-
double qb;
80-
double vs;
81-
std::size_t ireg;
82-
std::string ireg_bus_name;
83-
double mbase;
84-
double zr;
85-
double zx;
86-
double rt;
87-
double xt;
88-
double gtap;
89-
int stat;
90-
double rmpct;
91-
double pt;
92-
double pb;
93-
std::array<Ownership, 4> owners;
90+
BusRef i;
91+
std::string id{"1"};
92+
double pg{0.0};
93+
double qg{0.0};
94+
double qt{9999.0};
95+
double qb{-9999.0};
96+
double vs{1.0};
97+
BusRef ireg{0, ""};
98+
double mbase{Invalid<double>}; // Default is system MVA base
99+
double zr{0.0};
100+
double zx{1.0};
101+
double rt{0.0};
102+
double xt{0.0};
103+
double gtap{1.0};
104+
int stat{1};
105+
double rmpct{100.0};
106+
double pt{9999.0};
107+
double pb{-9999.0};
108+
std::array<Ownership, 4> owners{};
94109
int wmod{0};
95110
double wpf{1.0};
111+
std::size_t nreg{0};
96112
};
97113

98114
struct Branch {
99-
std::size_t i;
100-
std::string i_bus_name;
101-
std::size_t j;
102-
std::string j_bus_name;
115+
BusRef i;
116+
BusRef j;
103117
std::string ckt;
104118
double r;
105119
double x;
106-
double b;
107-
double ratea;
108-
double rateb;
109-
double ratec;
110-
double gi;
111-
double bi;
112-
double gj;
113-
double bj;
114-
int st;
115-
int met;
116-
double len;
117-
std::array<Ownership, 4> owners;
120+
double b{0.0};
121+
std::string name{};
122+
std::array<double, 12> rates{};
123+
double gi{0.0};
124+
double bi{0.0};
125+
double gj{0.0};
126+
double bj{0.0};
127+
int st{1};
128+
int met{1};
129+
double len{0.0};
130+
std::array<Ownership, 4> owners{};
118131
};
119132

133+
struct SystemSwitchingDevice {};
134+
120135
struct Impedence {
121136
double r;
122137
double x;
123-
double sbase;
138+
double sbase{Invalid<double>}; // Default is system base MVA
124139
};
125140

126141
struct Winding {
127-
double windv;
128-
double nomv;
129-
double ang;
130-
double rata;
131-
double ratb;
132-
double ratc;
133-
int cod;
134-
int cont;
135-
double rma;
136-
double rmi;
137-
double vma;
138-
double vmi;
139-
int ntp;
140-
int tab;
141-
double cr;
142-
double cx;
143-
double cnxa;
142+
/**
143+
* Default depends on Transformer::cw:
144+
* - cw in {1, 3} => 1.0
145+
* - cw == 2 => base voltage of corresponding bus (baskv of bus i, j or k)
146+
*/
147+
double windv{Invalid<double>};
148+
double nomv{0.0};
149+
double ang{0.0};
150+
std::array<double, 12> rates{};
151+
int cod{0};
152+
int cont{0};
153+
double rma{1.1};
154+
double rmi{0.9};
155+
double vma{1.1};
156+
double vmi{0.9};
157+
int ntp{33};
158+
int tab{0};
159+
double cr{0.0};
160+
double cx{0.0};
161+
double cnxa{0.0};
162+
std::size_t node{0};
144163
};
145164

146165
struct Transformer {
147-
std::size_t i;
148-
std::string i_bus_name;
149-
std::size_t j;
150-
std::string j_bus_name;
151-
std::size_t k;
152-
std::string k_bus_name;
153-
std::string ckt;
154-
int cw;
155-
int cz;
156-
int cm;
157-
double mag1;
158-
double mag2;
159-
int nmetr;
160-
std::string name;
161-
int stat;
162-
std::array<Ownership, 4> owners;
163-
std::string vecgrp;
166+
BusRef i;
167+
BusRef j;
168+
BusRef k;
169+
std::string ckt{"1"};
170+
int cw{1};
171+
int cz{1};
172+
int cm{1};
173+
double mag1{0.0};
174+
double mag2{0.0};
175+
int nmetr{2};
176+
std::string name{};
177+
int stat{1};
178+
std::array<Ownership, 4> owners{};
179+
std::string vecgrp{};
164180
Impedence imp12;
165181
Impedence imp23;
166182
Impedence imp31;
167-
double vmstar;
168-
double anstar;
169-
std::array<Winding, 3> windings;
183+
double vmstar{1.0};
184+
double anstar{0.0};
185+
std::array<Winding, 3> windings{};
170186
};
171187

172-
struct Area {
188+
struct AreaInterchange {
173189
int i;
174-
std::size_t isw;
175-
std::string isw_bus_name; // TODO: resolve
176-
double pdes;
177-
double ptol;
178-
std::string arname;
190+
BusRef isw{0, ""}; // TODO: resolve
191+
double pdes{0.0};
192+
double ptol{10.0};
193+
std::string arname{};
179194
};
180195

181-
struct AreaInterchange {};
182-
183196
struct TwoTerminalDCLine {};
184197

185198
struct VSCDCLine {};
@@ -200,26 +213,28 @@ struct FACTSDevice {};
200213

201214
struct SwitchedShunt {
202215
struct Block {
203-
int n;
204-
double b;
216+
std::size_t n{0};
217+
double b{0.0};
205218
};
206-
std::size_t i;
207-
std::string i_bus_name;
208-
int modsw;
209-
int adjm;
210-
int stat;
211-
double vswhi;
212-
double vswlo;
213-
std::size_t swrem;
214-
std::string swrem_bus_name;
215-
double rmpct;
216-
std::string rmidnt;
217-
double binit;
218-
std::array<Block, 8> blocks;
219+
220+
BusRef i;
221+
int modsw{1};
222+
int adjm{0};
223+
int stat{1};
224+
double vswhi{1.0};
225+
double vswlo{1.0};
226+
BusRef swreg{0, ""};
227+
double rmpct{100.0};
228+
std::string rmidnt{};
229+
double binit{0.0};
230+
std::array<Block, 8> blocks{};
231+
BusRef nreg{0, ""};
219232
};
220233

221234
struct GNEDevice {};
222235

236+
struct InductionMachine {};
237+
223238
class BusMapping {
224239
public:
225240
struct Optional {
@@ -241,8 +256,7 @@ class BusMapping {
241256
const Bus &GetBus(const std::string &bus_name) const;
242257
const Bus &GetBus(std::size_t bus_number) const;
243258

244-
void Resolve(std::size_t &bus_number, std::string &bus_name,
245-
Optional opt = Optional{false}) const;
259+
void Resolve(BusRef &bus, Optional opt = Optional{false}) const;
246260

247261
const auto &GetIdToIdMap() const { return id_map_; }
248262
const auto &GetNameToIdMap() const { return name_map_; }
@@ -260,6 +274,7 @@ struct Network {
260274
std::vector<SwitchedShunt> &&);
261275

262276
void ResolveBusIds();
277+
void ResolveDefaults();
263278

264279
std::string file_name;
265280
CaseID case_id;
@@ -269,6 +284,7 @@ struct Network {
269284
std::vector<FixedBusShunt> fixed_bus_shunts;
270285
std::vector<Generator> generators;
271286
std::vector<Branch> branches;
287+
// std::vector<SystemSwitchingDevice> system_switching_devices;
272288
std::vector<Transformer> transformers;
273289
// std::vector<AreaInterchange> area_interchanges;
274290
// std::vector<TwoTerminalDCLine> two_terminal_dc_lines;

0 commit comments

Comments
 (0)