-
Notifications
You must be signed in to change notification settings - Fork 3
/
PowerSystemData.hpp
242 lines (218 loc) · 6.91 KB
/
PowerSystemData.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#pragma once
#include <regex>
#include <string>
#include <iomanip>
#include <sstream>
/**
*
* @file PowerSystemData.hpp
* @author Asher Mancinelli <asher.mancinelli@pnnl.gov>
*
* @remark `std::stringstream` is preferred over `operator+(std::string, ...)`
* since stringstream does not reallocate on append.
*
*/
namespace GridKit
{
namespace PowerSystemData
{
template <typename RealT = double, typename IdxT = int>
struct BusData
{
IdxT bus_i; ///< Bus ID
IdxT type; ///< Bus type: 1 = PQ, 2 = PV, 3 = ref, 4 = isolated
RealT Gs; ///< Shunt conductance (MW demanded at V = 1.0 p.u.)
RealT Bs; ///< Shunt susceptance (MVAr injected at V = 1.0 p.u.)
IdxT area; ///< Area number (>0)
RealT Vm; ///< Voltage magnitude (p.u.)
RealT Va; ///< Voltage phase (deg)
RealT baseKV; ///< Base voltage [kV]
IdxT zone; ///< Loss zone number (>0)
RealT Vmax; ///< Maximum voltage magnitude (p.u.)
RealT Vmin; ///< Minimum voltage magnitude (p.u.)
inline std::string str() const
{
std::stringstream ss;
std::cerr << std::setw(10) << bus_i
<< std::setw(10) << type
<< std::setw(10) << Gs
<< std::setw(10) << Bs
<< std::setw(10) << area
<< std::setw(10) << Vm
<< std::setw(10) << Va
<< std::setw(10) << baseKV
<< std::setw(10) << zone
<< std::setw(10) << Vmax
<< std::setw(10) << Vmin;
ss << "\n";
return ss.str();
}
};
template <typename RealT = double, typename IdxT = int>
struct LoadData
{
IdxT bus_i; ///< Bus ID
RealT Pd; ///< Active power demand [MW]
RealT Qd; ///< Reactive power demand [MVAr]
inline std::string str() const
{
std::stringstream ss;
std::cerr << std::setw(10) << bus_i
<< std::setw(10) << Pd
<< std::setw(10) << Qd;
ss << "\n";
return ss.str();
}
};
template <typename RealT = double, typename IdxT = int>
struct GenData
{
IdxT bus; ///< Bus ID
RealT Pg; ///< Active power output [MW]
RealT Qg; ///< Reactive power output [MVAr]
RealT Qmax; ///< Maximum reactive power output [MVAr]
RealT Qmin; ///< Minimum reactive power output [MVAr]
RealT Vg; ///<
RealT mBase; ///< Total MVA base of machine
IdxT status; ///< Service status (>0 in service, <=0 out of service)
RealT Pmax; ///< Maximum active power output [MVAr]
RealT Pmin; ///< Minimum active power output [MVAr]
RealT Pc1; ///<
RealT Pc2; ///<
RealT Qc1min; ///<
RealT Qc1max; ///<
RealT Qc2min; ///<
RealT Qc2max; ///<
RealT ramp_agc; ///<
RealT ramp_10; ///<
RealT ramp_30; ///<
RealT ramp_q; ///<
RealT apf; ///<
inline std::string str() const
{
std::stringstream ss;
ss << std::setw(10) << bus
<< std::setw(10) << Pg
<< std::setw(10) << Qg
<< std::setw(10) << Qmax
<< std::setw(10) << Qmin
<< std::setw(10) << Vg
<< std::setw(10) << mBase
<< std::setw(10) << status
<< std::setw(10) << Pmax
<< std::setw(10) << Pmin
<< std::setw(10) << Pc1
<< std::setw(10) << Pc2
<< std::setw(10) << Qc1min
<< std::setw(10) << Qc1max
<< std::setw(10) << Qc2min
<< std::setw(10) << Qc2max
<< std::setw(10) << ramp_agc
<< std::setw(10) << ramp_10
<< std::setw(10) << ramp_30
<< std::setw(10) << ramp_q
<< std::setw(10) << apf;
ss << "\n";
return ss.str();
}
};
template <typename RealT = double, typename IdxT = int>
struct BranchData
{
IdxT fbus; ///< "From" bus ID
IdxT tbus; ///< "To" bus ID
RealT r; ///< Resistance (p.u.)
RealT x; ///< Reactance (p.u.)
RealT b; ///< Total line charging susceptance (p.u.)
RealT rateA; ///< MVA rating A (long term rating), 0=unlimited
RealT rateB; ///< MVA rating B (short term rating), 0=unlimited
RealT rateC; ///< MVA rating C (emergency rating), 0=unlimited
RealT ratio; ///< Transformer off nominal turns ratio
RealT angle; ///< Transformer phase shift angle [deg], positive ⇒ delay
IdxT status; ///< Initial service status: 1=in-service, 0=out-of-service
RealT angmin; ///< Minimum anngle difference af - at [deg]
RealT angmax; ///< Maximum anngle difference af - at [deg]
inline std::string str() const
{
std::stringstream ss;
ss << std::setw(10) << fbus
<< std::setw(10) << tbus
<< std::setw(10) << r
<< std::setw(10) << x
<< std::setw(10) << b
<< std::setw(10) << rateA
<< std::setw(10) << rateB
<< std::setw(10) << rateC
<< std::setw(10) << ratio
<< std::setw(10) << angle
<< std::setw(10) << status
<< std::setw(10) << angmin
<< std::setw(10) << angmax;
ss << "\n";
return ss.str();
}
};
template <typename RealT = double, typename IdxT = int>
struct GenCostData
{
IdxT kind;
IdxT startup;
IdxT shutdown;
IdxT n;
std::vector<RealT> rest;
inline std::string str() const
{
std::stringstream ss;
ss << std::setw(10) << kind
<< std::setw(10) << startup
<< std::setw(10) << shutdown
<< std::setw(10) << n;
for (const auto& val : rest)
ss << std::setw(10) << val;
ss << "\n";
return ss.str();
}
};
template <typename RealT = double, typename IdxT = int>
struct SystemModelData
{
using BusDataT = BusData<RealT, IdxT>;
using GenDataT = GenData<RealT, IdxT>;
using BranchDataT = BranchData<RealT, IdxT>;
using GenCostDataT = GenCostData<RealT, IdxT>;
using LoadDataT = LoadData<RealT, IdxT>;
std::string version;
IdxT baseMVA;
std::vector<BusDataT> bus;
std::vector<GenDataT> gen;
std::vector<BranchDataT> branch;
std::vector<GenCostDataT> gencost;
std::vector<LoadDataT> load;
// Not sure if these should be in this struct... Not all matpower files
// I found contained them.
//
// std::string name;
// std::vector<std::string> bus_name;
inline std::string str() const
{
std::stringstream ss;
ss << "Version: " << version << "\n"
<< "Base MVA: " << baseMVA << "\n";
ss << "Bus:\n";
for (const auto& v : bus)
ss << bus.str() << "\n";
ss << "Gen:\n";
for (const auto& v : gen)
ss << gen.str();
ss << "Branch:\n";
for (const auto& v : branch)
ss << branch.str();
ss << "GenCost:\n";
for (const auto& v : gencost)
ss << gencost.str();
ss << "\n";
return ss.str();
}
}; // struct SystemModelData
} // namespace PowerSystemData
} // namespace GridKit