-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic_usage.py
420 lines (363 loc) · 9.29 KB
/
basic_usage.py
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
import psr.npf
import copy
"""
Example network:
1 3 AC Lines 4 CSC 5 6
(G)--|-OO--|----------|--)|--|------|-> SVC
2 | |----------| |-OO-|-[-(|-]->
(G)--|-| | |-> 7
| DC Links |
<-)|-|-[]----[]-|-|(->
|-[]----[]-|
"""
# Count the number of series network elements.
series_count = 1
data = psr.npf.NpFile()
data.revision = 1
data.description = "Case title"
# Create system, area and region.
system = psr.npf.System()
system.number = 1
system.name = "System"
system.id = "sy"
data.systems.append(system)
area1 = psr.npf.Area()
area1.number = 1
area1.name = "Area 1"
area1.id = "ar01"
area1.system = system
data.areas.append(area1)
area2 = psr.npf.Area()
area2.number = 2
area2.name = "Area 2"
area2.id = "ar02"
area2.system = system
data.areas.append(area2)
region = psr.npf.Region()
region.number = 1
region.name = "Region"
region.id = "re01"
region.system = system
data.regions.append(region)
# Create/add buses
bus1 = psr.npf.Bus()
bus1.number = 1
bus1.name = "Bus 1"
bus1.kvbase = 18.0
bus1.system = system
bus1.area = area1
bus1.region = region
data.buses.append(bus1)
bus2 = psr.npf.Bus()
bus2.number = 2
bus2.name = "Bus 2"
bus2.kvbase = 18.0
bus2.system = system
bus2.area = area1
bus2.region = region
data.buses.append(bus2)
bus3 = psr.npf.Bus()
bus3.number = 3
bus3.name = "Bus 3"
bus3.kvbase = 230.0
bus3.system = system
bus3.area = area2
bus3.region = region
data.buses.append(bus3)
bus4 = psr.npf.Bus()
bus4.number = 4
bus4.name = "Bus 4"
bus4.kvbase = 230.0
bus4.system = system
bus4.area = area2
bus4.region = region
data.buses.append(bus4)
bus5 = psr.npf.Bus()
bus5.number = 5
bus5.name = "Bus 5"
bus5.kvbase = 230.0
bus5.system = system
bus5.area = area2
bus5.region = region
data.buses.append(bus5)
bus6 = psr.npf.Bus()
bus6.number = 6
bus6.name = "Bus 6"
bus6.kvbase = 230.0
bus6.system = system
bus6.area = area2
bus6.region = region
data.buses.append(bus6)
bus7 = psr.npf.Bus()
bus7.number = 7
bus7.name = "Bus 7"
bus7.kvbase = 13.8
bus7.system = system
bus7.area = area2
bus7.region = region
data.buses.append(bus7)
# Demands
demand1 = psr.npf.Demand()
demand1.number = 1
demand1.name = "Demand 1"
demand1.bus = bus4
demand1.p_mw = 150.0
demand1.q_mw = 35.0
data.demands.append(demand1)
demand2 = psr.npf.Demand()
demand2.number = 2
demand2.name = "Demand 2"
demand2.bus = bus6
demand2.p_mw = 300.0
demand2.q_mw = 100.0
data.demands.append(demand2)
# Generators
generator1 = psr.npf.Generator()
generator1.number = 1
generator1.name = "G01"
generator1.bus = bus1
generator1.ctr_bus = bus3
generator1.pmax = 200.0
generator1.qmin = -180.0
generator1.qmax = +200.0
generator1.type = psr.npf.Generator.TYPE_THERMAL
data.generators.append(generator1)
generator2 = copy.copy(generator1)
generator2.number = 2
generator2.name = "G02"
generator2.bus = bus2
data.generators.append(generator2)
# Lines
line34_1 = psr.npf.Line()
line34_1.from_bus = bus3
line34_1.to_bus = bus4
line34_1.number = series_count
line34_1.name = "TL34-1"
line34_1.r_pct = 0.02
line34_1.x_pct = 0.40
data.lines.append(line34_1)
series_count += 1
line34_2 = copy.copy(line34_1)
line34_2.parallel_circuit_number = 2
line34_2.number = series_count
line34_2.name = "TL34-2"
data.lines.append(line34_2)
series_count += 1
line56 = psr.npf.Line()
line56.from_bus = bus5
line56.to_bus = bus6
line56.number = series_count
line56.name = "TL56"
line56.r_pct = 0.03
line56.x_pct = 0.60
data.lines.append(line56)
series_count += 1
# Line shunts
line56_shunt = psr.npf.LineShunt()
line56_shunt.number = 1
line56_shunt.name = "L56 shunt"
line56_shunt.circuit = line56
line56_shunt.terminal = psr.npf.LineShunt.TERMINAL_TO
line56_shunt.mvar = 60.0
data.line_shunts.append(line56_shunt)
# Two-winding transformer
trf67 = psr.npf.Transformer()
trf67.from_bus = bus6
trf67.to_bus = bus7
trf67.series_number = series_count
trf67.name = "TR67-SVC"
data.transformers.append(trf67)
series_count += 1
# Three-winding transformer
# It's composed of three equivalent two-winding transformers and a
# middle point bus.
middle_bus = psr.npf.MiddlePointBus()
middle_bus.number = 8
middle_bus.name = "Midpoint"
middle_bus.kvbase = 1.0
middle_bus.system = system
middle_bus.area = area1
middle_bus.region = region
data.middlepoint_buses.append(middle_bus)
eqv_trf1 = psr.npf.EquivalentTransformer()
eqv_trf1.series_number = series_count
eqv_trf1.from_bus = bus1
eqv_trf1.to_bus = middle_bus
eqv_trf1.name = "eqvtr1"
data.equivalent_transformers.append(eqv_trf1)
series_count += 1
eqv_trf2 = psr.npf.EquivalentTransformer()
eqv_trf2.series_number = series_count
eqv_trf2.from_bus = bus2
eqv_trf2.to_bus = middle_bus
eqv_trf2.name = "eqvtr2"
data.equivalent_transformers.append(eqv_trf2)
series_count += 1
eqv_trf3 = psr.npf.EquivalentTransformer()
eqv_trf3.series_number = series_count
eqv_trf3.from_bus = bus3
eqv_trf3.to_bus = middle_bus
eqv_trf3.name = "eqvtr3"
data.equivalent_transformers.append(eqv_trf3)
series_count += 1
trf3 = psr.npf.ThreeWindingTransformer()
trf3.series_number = series_count
trf3.name = "TRF-GEN"
trf3.primary_transformer = eqv_trf1
trf3.secondary_transformer = eqv_trf2
trf3.tertiary_transformer = eqv_trf3
trf3.middlepoint_bus = middle_bus
data.three_winding_transformers.append(trf3)
series_count += 1
# Controlled Series Capacitor
csc = psr.npf.ControlledSeriesCapacitor()
csc.number = 1
csc.name = "CSC 4-5"
csc.from_bus = bus4
csc.to_bus = bus5
csc.xmin_pct = -20.0
csc.xmax_pct = -5.0
csc.normal_rating = 300.0
csc.emergency_rating = 300.0
csc.series_number = series_count
data.cscs.append(csc)
series_count += 1
# Bus shunts
bshunt3 = psr.npf.BusShunt()
bshunt3.number = 1
bshunt3.name = "B03-cap"
bshunt3.bus = bus3
bshunt3.mvar = 50.0
bshunt3.type = psr.npf.BusShunt.CAPACITOR
bshunt3.ctr_bus = bus3
data.bus_shunts.append(bshunt3)
bshunt4 = copy.copy(bshunt3)
bshunt4.number = 2
bshunt4.name = "B04-cap"
bshunt4.bus = bus4
bshunt4.ctr_bus = bus4
data.bus_shunts.append(bshunt4)
# Static VAR compensator
svc = psr.npf.StaticVarCompensator()
svc.number = 1
svc.name = "SVC B07"
svc.bus = bus7
svc.ctr_bus = bus6
svc.droop = 5.0
svc.qmin = -20.0
svc.qmax = +20.0
data.svcs.append(svc)
# LCC DC Link components
lcc_link = psr.npf.DcLink()
lcc_link.number = 1
lcc_link.name = "LCC Link"
lcc_link.kvbase = 800.0
lcc_link.mwbase = 400.0
lcc_link.type = psr.npf.DcLink.TYPE_LCC
data.dclinks.append(lcc_link)
lcc_bus1 = psr.npf.DcBus()
lcc_bus1.number = 1
lcc_bus1.name = "DCB 1"
lcc_bus1.region = region
lcc_bus1.system = system
lcc_bus1.area = area2
lcc_bus1.dclink = lcc_link
data.dcbuses.append(lcc_bus1)
lcc_bus2 = copy.copy(lcc_bus1)
lcc_bus2.number = 2
lcc_bus2.name = "DCB 2"
data.dcbuses.append(lcc_bus2)
lcc_bus3 = copy.copy(lcc_bus1)
lcc_bus3.number = 3
lcc_bus3.name = "DCB 3N"
lcc_bus3.volt = 0.0
lcc_bus3.polarity = psr.npf.DcBus.POLARITY_NEUTRAL
data.dcbuses.append(lcc_bus3)
lcc_bus4 = copy.copy(lcc_bus3)
lcc_bus4.number = 4
lcc_bus4.name = "DCB 4N"
data.dcbuses.append(lcc_bus4)
lcc_line = psr.npf.DcLine()
lcc_line.series_number = 1
lcc_line.name = "DC Line 1-2"
lcc_line.from_bus = lcc_bus1
lcc_line.to_bus = lcc_bus2
lcc_line.r_ohm = 10.0
lcc_line.series_number = series_count
data.dclines.append(lcc_line)
series_count += 1
lcc_cnv_ret = psr.npf.AcDcConverterLcc()
lcc_cnv_ret.number = 1
lcc_cnv_ret.name = "LCC RET"
lcc_cnv_ret.ac_bus = bus3
lcc_cnv_ret.dc_bus = lcc_bus1
lcc_cnv_ret.neutral_bus = lcc_bus3
lcc_cnv_ret.type = psr.npf.AcDcConverterLcc.TYPE_RECTIFIER
data.lcc_converters.append(lcc_cnv_ret)
lcc_cnv_inv = psr.npf.AcDcConverterLcc()
lcc_cnv_inv.number = 2
lcc_cnv_inv.name = "LCC INV"
lcc_cnv_inv.ac_bus = bus4
lcc_cnv_inv.dc_bus = lcc_bus2
lcc_cnv_inv.neutral_bus = lcc_bus4
lcc_cnv_inv.type = psr.npf.AcDcConverterLcc.TYPE_INVERTER
data.lcc_converters.append(lcc_cnv_inv)
# VSC DC Link components
vsc_link = psr.npf.DcLink()
vsc_link.number = 2
vsc_link.name = "VSC Link"
vsc_link.kvbase = 400.0
vsc_link.mwbase = 200.0
vsc_link.type = psr.npf.DcLink.TYPE_VSC
data.dclinks.append(vsc_link)
vsc_bus5 = psr.npf.DcBus()
vsc_bus5.number = 5
vsc_bus5.name = "DCB 5"
vsc_bus5.region = region
vsc_bus5.system = system
vsc_bus5.area = area2
vsc_bus5.dclink = vsc_link
data.dcbuses.append(vsc_bus5)
vsc_bus6 = copy.copy(vsc_bus5)
vsc_bus6.number = 6
vsc_bus6.name = "DCB 6"
data.dcbuses.append(vsc_bus6)
vsc_bus7 = copy.copy(vsc_bus5)
vsc_bus7.number = 7
vsc_bus7.name = "DCB 7N"
vsc_bus7.volt = 0.0
vsc_bus7.polarity = psr.npf.DcBus.POLARITY_NEUTRAL
data.dcbuses.append(vsc_bus7)
vsc_bus8 = copy.copy(vsc_bus5)
vsc_bus8.number = 8
vsc_bus8.name = "DCB 8N"
data.dcbuses.append(vsc_bus8)
vsc_line = psr.npf.DcLine()
vsc_line.series_number = 2
vsc_line.name = "DC Line 5-6"
vsc_line.from_bus = vsc_bus5
vsc_line.to_bus = vsc_bus6
vsc_line.r_ohm = 10.0
vsc_line.series_number = series_count
data.dclines.append(vsc_line)
series_count += 1
vsc_cnv_ret = psr.npf.AcDcConverterVsc()
vsc_cnv_ret.number = 3
vsc_cnv_ret.name = "VSC RET"
vsc_cnv_ret.ac_bus = bus3
vsc_cnv_ret.dc_bus = vsc_bus5
vsc_cnv_ret.neutral_bus = vsc_bus7
vsc_cnv_ret.ctr_bus = bus3
data.vsc_converters.append(vsc_cnv_ret)
vsc_cnv_inv = psr.npf.AcDcConverterVsc()
vsc_cnv_inv.number = 4
vsc_cnv_inv.name = "VSC INV"
vsc_cnv_inv.ac_bus = bus4
vsc_cnv_inv.dc_bus = vsc_bus6
vsc_cnv_inv.neutral_bus = vsc_bus8
vsc_cnv_inv.ctr_bus = bus4
data.vsc_converters.append(vsc_cnv_inv)
print("NPF file contents:")
print("------------------")
print(data)
data.save("example_basic_usage.npf")