-
Notifications
You must be signed in to change notification settings - Fork 19
/
main_step0_powerflow.py
121 lines (103 loc) · 4.17 KB
/
main_step0_powerflow.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
# --------------------------------------------
# EMT solver main function - create large cases and save in .json format
# 2020-2021 Bin Wang, Deepthi Vaidhynathan, Min Xiong
# Last modified: 08/15/24
# --------------------------------------------
# PSSE/python compatibility summary:
# psspy27 - to be used with python 2.7
# psspy34 - to be used with python 3.4
# psspy37 - to be used with python 3.7
# note: Our PSSE v34.4 does not have psspy37, but has psspy27 and psspy34, so Python 2.7 and psspy27 are used here.
# note: Regarding EMT simulation, Python 3.7 will be used for better performance. So the function for generating large
# systems was separated from Lib_BW, and named as Lib_BW_CreateLargeCases.
# In our next version, this PSSE license required power flow solver will be replaced by ANDES
# For simulating the systems in put under 'models', the users can skip this setp. Because the generated files are already included in 'cases'.
import os, sys
import numpy
import json
# sys_path_PSSE = r"C:\Program Files (x86)\PTI\PSSE34\PSSBIN"
# os_path_PSSE = r"C:\Program Files (x86)\PTI\PSSE34\PSSBIN"
sys_path_PSSE = r"C:\Program Files (x86)\PTI\PSSE34\PSSPY37"
sys.path.append(sys_path_PSSE)
os_path_PSSE = r"C:\Program Files (x86)\PTI\PSSE34\PSSPY37"
os.environ['PATH'] += ';' + os_path_PSSE
import psse34
import psspy
workingfolder = os.getcwd()
os.chdir(workingfolder)
import json
import pickle
from Lib_BW_CreateLargeCases import *
def main_2():
systemN = 1
psspy.psseinit()
# load PSS/E model
if systemN == 1:
psspy.read(0, workingfolder + """\\models\\2gen_psse\\2gen.raw""")
elif systemN == 2:
psspy.read(0, workingfolder + """\\models\\9bus_psse\\ieee9.raw""")
elif systemN == 3:
psspy.read(0, workingfolder + """\\models\\39bus_psse\\39bus.raw""")
elif systemN == 4:
psspy.read(0, workingfolder + """\\models\\179bus_psse\\wecc179.raw""")
elif systemN == 5:
psspy.read(0,workingfolder + """\\models\\240bus_psse\\WECC240.raw""")
elif systemN == 6:
psspy.read(0, workingfolder + """\\models\\2area_psse\\twoarea.raw""")
else:
pass
psspy.nsol([0, 0, 0, 1, 1, 0, 0]) # fast decouple with "Do not flat start"
psspy.fnsl([0, 0, 0, 1, 1, 0, 0, 0])
psspy.fnsl([0, 0, 0, 1, 1, 0, 0, 0])
psspy.fnsl([0, 0, 0, 1, 1, 0, 0, 0])
psspy.fnsl([0, 0, 0, 1, 1, 0, 0, 0])
psspy.fnsl([0, 0, 0, 1, 1, 0, 0, 0])
psspy.fnsl([0, 0, 0, 1, 1, 0, 0, 0])
psspy.fnsl([0, 0, 0, 1, 1, 0, 0, 0])
psspy.fnsl([0, 0, 0, 1, 1, 0, 0, 0])
psspy.fnsl([0, 0, 0, 1, 1, 0, 0, 0])
psspy.fnsl([0, 0, 0, 1, 1, 0, 0, 0])
pfd0 = PFData()
pfd0.getdata(psspy) # IBR, switch shunts
# Create large cases y connecting multiple replications:
N_row = 1
N_col = 1
# select interfacing buses (need to be PV buses)
if systemN == 1:
ItfcBus = [1, 4, 1, 4]
pfd_name = r"""4_""" + str(N_row) + """_""" + str(N_col)
elif systemN == 2:
ItfcBus = [1, 2, 3, 1]
pfd_name = r"""9_""" + str(N_row) + """_""" + str(N_col)
elif systemN == 3:
ItfcBus = [37, 36, 32, 39]
pfd_name = r"""39_""" + str(N_row) + """_""" + str(N_col)
elif systemN == 4:
ItfcBus = [35, 4, 149, 70]
pfd_name = r"""179_""" + str(N_row) + """_""" + str(N_col)
elif systemN == 5:
ItfcBus = []
pfd_name = r"""240_""" + str(N_row) + """_""" + str(N_col)
pfd = pfd0
elif systemN == 6:
ItfcBus = []
pfd_name = r"""2area_""" + str(N_row) + """_""" + str(N_col)
pfd = pfd0
if len(ItfcBus) != 0:
pfd = pfd0.LargeSysGenerator(ItfcBus, N_row, N_col)
pfd_dict = pfd.__dict__
pddd = {}
for x in pfd_dict.keys():
if type(pfd_dict[x]) != numpy.ndarray:
pddd[x] = pfd_dict[x]
else:
if pfd_dict[x].dtype == 'complex128':
pddd[x] = pfd_dict[x].tolist()
pddd[x] = [str(y) for y in pddd[x]]
else:
pddd[x] = pfd_dict[x].tolist()
with open(workingfolder + '\\cases\\pfd_' + pfd_name + '.json', 'w') as fp:
json.dump(pddd, fp)
# disconnect PSSE license after the use
psspy.pssehalt_2()
main_2()