-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc_criteria.py
323 lines (261 loc) · 11.3 KB
/
calc_criteria.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
import win32com.client
import regime_config
rastr = win32com.client.Dispatch('Astra.Rastr')
def criteria1(p_fluctuations: float) -> float:
"""
Calculation of the maximum power flow (MPF) in normal regime
p_fluctuations: float value of active power fluctuation
"""
# Load a regime files and set weighting parameters
regime_config.load_clean_regime(rastr)
regime_config.load_sech(rastr)
regime_config.load_traj(rastr)
regime_config.set_regime(rastr, 200, 1, 1, 1)
# Iterative weighting of regime
regime_config.do_regime_weight(rastr)
# Maximum power flow by criteria 1
mpf_1 = abs(
rastr.Tables('sechen').Cols('psech').Z(0)) * 0.8 - p_fluctuations
mpf_1 = round(mpf_1, 2)
return mpf_1
def criteria2(p_fluctuations: float) -> float:
"""
Calculation of the maximum power flow by the acceptable voltage level
in the pre-emergency regime
p_fluctuations: float value of active power fluctuation
"""
# Load a regime files and set weighting parameters
regime_config.load_clean_regime(rastr)
regime_config.load_sech(rastr)
regime_config.load_traj(rastr)
regime_config.set_regime(rastr, 200, 1, 0, 1)
# Redefine the COM path to the RastrWin3 node table
nodes = rastr.Tables('node')
# Determining the acceptable voltage level of nodes with load
for i in range(nodes.Size):
# Load node search (1 - type of node with load)
if nodes.Cols('tip').Z(i) == 1:
u_kr = nodes.Cols('uhom').Z(i) * 0.7 # Critical voltage level
u_min = u_kr * 1.15 # Acceptable voltage level
nodes.Cols('umin').SetZ(i, u_min)
nodes.Cols('contr_v').SetZ(i, 1)
# Iterative weighting of regime
regime_config.do_regime_weight(rastr)
# MPF by criteria 2
mpf_2 = abs(rastr.Tables('sechen').Cols('psech').Z(0)) - p_fluctuations
mpf_2 = round(mpf_2, 2)
return mpf_2
def criteria3(p_fluctuations: float, faults_lines: dict) -> float:
"""
Calculation of the maximum power flow (MPF)
in the post-emergency regime after fault
p_fluctuations: float value of active power fluctuation
faults_lines: dict of modeling faults
"""
# Load a regime files and set weighting parameters
regime_config.load_clean_regime(rastr)
regime_config.load_sech(rastr)
regime_config.load_traj(rastr)
regime_config.set_regime(rastr, 200, 1, 1, 1)
# Redefine the COM path to the RastrWin3 branch table
branches = rastr.Tables('vetv')
# Redefine the COM path to the RastrWin3 flowgate table
flowgate = rastr.Tables('sechen')
# List of MPF for each fault
mpf_3 = []
# Iterating over each fault
for line in faults_lines:
# Node number of the start branch
node_start_branch = faults_lines[line]['ip']
# Node number of the start branch
node_end_branch = faults_lines[line]['iq']
# Number of parallel branch
parallel_number = faults_lines[line]['np']
# Status of branch (0 - on / 1 - off)
branch_status = faults_lines[line]['sta']
# Iterating over each branches in RastrWin3
for i in range(branches.Size):
# Search branch with fault
if (branches.Cols('ip').Z(i) == node_start_branch) and \
(branches.Cols('iq').Z(i) == node_end_branch) and \
(branches.Cols('np').Z(i) == parallel_number):
# Remember previous branch status
pr_branch_status = branches.Cols('sta').Z(i)
# Do fault
branches.Cols('sta').SetZ(i, branch_status)
# Do regime weighing
regime_config.do_regime_weight(rastr)
# MPF in the post-emergency regime after fault
mpf = abs(flowgate.Cols('psech').Z(0))
# Acceptable level of MPF in such scheme
mpf_acceptable = abs(flowgate.Cols('psech').Z(0)) * 0.92
# Redefine the COM path to the RastrWin3 regime collections
toggle = rastr.GetToggle()
# Iterative return to Acceptable level of MPF
j = 1
while mpf > mpf_acceptable:
toggle.MoveOnPosition(len(toggle.GetPositions()) - j)
mpf = abs(flowgate.Cols('psech').Z(0))
j += 1
# Remove fault
branches.Cols('sta').SetZ(i, pr_branch_status)
# Re-calculation of regime
rastr.rgm('p')
# MPF by criteria 3
mpf = abs(
rastr.Tables('sechen').Cols('psech').Z(0)) - p_fluctuations
mpf = round(mpf, 2)
mpf_3.append(mpf)
# Reset to clean regime
toggle.MoveOnPosition(1)
branches.Cols('sta').SetZ(i, pr_branch_status)
break
return min(mpf_3)
def criteria4(p_fluctuations: float, faults_lines: dict) -> float:
"""
Calculation of the maximum power flow (MPF) by the acceptable voltage level
in the post-emergency regime after fault
p_fluctuations: float value of active power fluctuation
faults_lines: dict of modeling faults
"""
# Load a regime files and set weighting parameters
regime_config.load_clean_regime(rastr)
regime_config.load_sech(rastr)
regime_config.load_traj(rastr)
regime_config.set_regime(rastr, 200, 1, 0, 1)
# Redefine the COM path to the RastrWin3 node table
nodes = rastr.Tables('node')
# Redefine the COM path to the RastrWin3 branch table
branches = rastr.Tables('vetv')
# Redefine the COM path to the RastrWin3 flowgate table
flowgate = rastr.Tables('sechen')
# Determining the acceptable voltage level of nodes with load
for j in range(nodes.Size):
# Load node search (1 - type of node with load)
if nodes.Cols('tip').Z(j) == 1:
# Critical voltage level
u_kr = nodes.Cols('uhom').Z(j) * 0.7
# Acceptable voltage level
u_min = u_kr * 1.1
nodes.Cols('umin').SetZ(j, u_min)
# List of MPF for each fault
mpf_4 = []
# Iterating over each fault
for line in faults_lines:
# Node number of the start transmission line
node_start_branch = faults_lines[line]['ip']
# Node number of the start transmission line
node_end_branch = faults_lines[line]['iq']
# Number of branch
parallel_number = faults_lines[line]['np']
# Status of branch (0 - on / 1 - off)
branch_status = faults_lines[line]['sta']
# Iterating over branch in RastrWin3
for i in range(branches.Size):
# Search branch with fault
if (branches.Cols('ip').Z(i) == node_start_branch) and \
(branches.Cols('iq').Z(i) == node_end_branch) and \
(branches.Cols('np').Z(i) == parallel_number):
# Remember previous branch status
pr_branch_status = branches.Cols('sta').Z(i)
# Do fault
branches.Cols('sta').SetZ(i, branch_status)
# Do regime weighing
regime_config.do_regime_weight(rastr)
# Remove fault
branches.Cols('sta').SetZ(i, pr_branch_status)
# Re-calculation of regime
rastr.rgm('p')
# MPF be criteria 4
mpf = abs(
flowgate.Cols('psech').Z(0)) - p_fluctuations
mpf = round(mpf, 2)
mpf_4.append(mpf)
# Reset to clean regime
rastr.GetToggle().MoveOnPosition(1)
branches.Cols('sta').SetZ(i, pr_branch_status)
break
return min(mpf_4)
def criteria5(p_fluctuations: float) -> float:
"""
Calculation of a maximum power flow (MPF) by acceptable current
in normal regime
p_fluctuations: float value of active power fluctuation
"""
# Load a regime files and set weighting parameters
regime_config.load_clean_regime(rastr)
regime_config.load_sech(rastr)
regime_config.load_traj(rastr)
regime_config.set_regime(rastr, 200, 1, 1, 0)
# Redefine the COM path to the RastrWin3 branch table
branches = rastr.Tables('vetv')
# Redefine the COM path to the RastrWin3 flowgate table
flowgate = rastr.Tables('sechen')
# Redefine the COM path to collection of regimes RastrWin3
# Iterating over each branches in RastrWin3
for i in range(branches.Size):
branches.Cols('contr_i').SetZ(i, 1)
branches.Cols('i_dop').SetZ(i, branches.Cols('i_dop_r').Z(i))
# Iterative weighting of regime
regime_config.do_regime_weight(rastr)
# MPF by criteria 5
mpf_5 = abs(flowgate.Cols('psech').Z(0)) - p_fluctuations
mpf_5 = round(mpf_5, 2)
return mpf_5
def criteria6(p_fluctuations: float, faults_lines: dict):
"""
Calculation of a maximum power flow (MPF) by acceptable current
in the post-emergency regime after fault
p_fluctuations: float value of active power fluctuation
faults_lines: dict of modeling faults
"""
# Load a regime files and set weighting parameters
regime_config.load_clean_regime(rastr)
regime_config.load_sech(rastr)
regime_config.load_traj(rastr)
regime_config.set_regime(rastr, 200, 1, 1, 0)
# Redefine the COM path to the RastrWin3 branch table
branches = rastr.Tables('vetv')
# Redefine the COM path to the RastrWin3 flowgate table
flowgate = rastr.Tables('sechen')
# Iterating over each branch in RastrWin3
for j in range(branches.Size):
branches.Cols('contr_i').SetZ(j, 1)
branches.Cols('i_dop').SetZ(j, branches.Cols('i_dop_r_av').Z(j))
# List of MPF for each fault
mpf_6 = []
# Iterating over each fault
for line in faults_lines:
# Node number of the start branch
node_start_branch = faults_lines[line]['ip']
# Node number of the end branch
node_end_branch = faults_lines[line]['iq']
# Number of parallel branch
parallel_number = faults_lines[line]['np']
# Status of branch (0 - on / 1 - off)
branch_status = faults_lines[line]['sta']
# Iterating over each branch in RastrWin3
for i in range(branches.Size):
# Search branch with fault
if (branches.Cols('ip').Z(i) == node_start_branch) and \
(branches.Cols('iq').Z(i) == node_end_branch) and \
(branches.Cols('np').Z(i) == parallel_number):
# Remember previous branch status
pr_branch_status = branches.Cols('sta').Z(i)
# Do fault
branches.Cols('sta').SetZ(i, branch_status)
# Iterative weighting of regime
regime_config.do_regime_weight(rastr)
# Remove fault
branches.Cols('sta').SetZ(i, pr_branch_status)
# Re-calculation of regime
rastr.rgm('p')
# MPF by criteria 6
mpf = abs(flowgate.Cols('psech').Z(0)) - p_fluctuations
mpf = round(mpf, 2)
mpf_6.append(mpf)
# Reset to clean regime
rastr.GetToggle().MoveOnPosition(1)
branches.Cols('sta').SetZ(i, pr_branch_status)
break
return min(mpf_6)