-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadflow_utilities.py
176 lines (157 loc) · 9.68 KB
/
loadflow_utilities.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
import pandapower as pp
import numpy as np
import pandas as pd
import copy
from topology_utilities import separate_subnetworks,sorting_network,merge_networks,find_lines_between_given_line_and_ext_grid
import math as m
def clean_network(net,original_net):
net.converter=original_net.converter
net.res_converter=original_net.res_converter
# net.res_converter=pd.DataFrame(columns=["p_mw","loading (%)"])
# for i, row in net.converter.iterrows():
# b=row.from_bus
# l=net.load.loc[net.load.bus==b]
# if len(l)>0:
# net.res_converter.loc[len(net.res_converter)]={"p_mw":l.p_mw.values[0],"loading (%)":l.p_mw.values[0]/row.P*100}
# else:
# net.res_converter.loc[len(net.res_converter)]={"p_mw":None,"loading (%)":None}
del_load=['Load of net' in str(x) for x in net.load.name.values]
net.load.drop(net.load.loc[del_load].index,inplace=True)
net.res_load.drop(net.res_load.loc[del_load].index,inplace=True)
del_ext_grid=['Converter emulation' in str(x) for x in net.ext_grid.name.values]
net.ext_grid.drop(net.ext_grid.loc[del_ext_grid].index,inplace=True)
net.res_ext_grid.drop(net.res_ext_grid.loc[del_ext_grid].index,inplace=True)
return net
def LF_DC(net):
subnetwork_list = separate_subnetworks(net)
dic_of_subs=sorting_network(net, subnetwork_list)
#print(dic_of_subs)
loadflowed_sub=[]
net.res_converter=pd.DataFrame(data=np.empty((len(net.converter),3)),columns=["p_mw","loading (%)",'pl_mw'])
while not all(elem in loadflowed_sub for elem in dic_of_subs.keys()):
for n in list(set(list(dic_of_subs.keys()))-set(loadflowed_sub)):
if all(elem in loadflowed_sub for elem in [x[0] for x in dic_of_subs[n]['direct_downstream_network']]):
tmp_net=dic_of_subs[n]['network']
for c in dic_of_subs[n]['direct_upstream_network']:
b=[x[1] for x in dic_of_subs[c[0]]['direct_downstream_network'] if x[0]==n][0]
pp.create_ext_grid(tmp_net,bus=b,vm_pu=1.0,name='Converter emulation')
print(tmp_net.line)
print('>> Loadflow of network '+ str(n))
pp.runpp(tmp_net)
print(tmp_net.res_line)
print("*************************************")
dic_of_subs[n]['network']=tmp_net
loadflowed_sub.append(n)
for c in dic_of_subs[n]['direct_upstream_network']:
up_net=dic_of_subs[c[0]]['network']
p=tmp_net.res_ext_grid.p_mw.values[0]
converter=net.converter.loc[net.converter.name==c[2]]
eff = np.interp(abs(p), converter.efficiency.values[0][:, 0] / 1000, converter.efficiency.values[0][:, 1])
pp.create_load(up_net,
bus=c[1],
p_mw=p*eff*int(p<0)+p/eff*int(p>0), # Convert kW to MW
q_mvar=0,name='Load of net '+ str(n))
dic_of_subs[c[0]]['network']=up_net
net.res_converter.loc[net.converter.name==c[2],'p_mw']=p*eff*int(p<0)+p/eff*int(p>0)
net.res_converter.loc[net.converter.name==c[2],'loading (%)']=p/net.converter.loc[net.converter.name==c[2],'P']*100
net.res_converter.loc[net.converter.name==c[2],'pl_mw']=p-(p*eff*int(p<0)+p/eff*int(p>0))
net_res=merge_networks([dic_of_subs[n]['network'] for n in dic_of_subs.keys()])
net=clean_network(net_res,net)
return net
def LF_sizing(net,cable_catalogue,use_case):
if use_case['Project details']['Ecosystem']=='ODCA':
min_v=0.92
max_v=1.08
elif use_case['Project details']['Ecosystem']=='CurrentOS':
min_v=0.98
max_v=1.02
else :
min_v=0.95
max_v=1.05
subnetwork_list = separate_subnetworks(net)
dic_of_subs=sorting_network(net, subnetwork_list)
#print(dic_of_subs)
loadflowed_sub=[]
net.res_converter=pd.DataFrame(data=np.empty((len(net.converter),3)),columns=["p_mw","loading (%)",'pl_mw'])
while not all(elem in loadflowed_sub for elem in dic_of_subs.keys()):
for n in list(set(list(dic_of_subs.keys()))-set(loadflowed_sub)):
if all(elem in loadflowed_sub for elem in [x[0] for x in dic_of_subs[n]['direct_downstream_network']]):
tmp_net=dic_of_subs[n]['network']
for c in dic_of_subs[n]['direct_upstream_network']:
b=[x[1] for x in dic_of_subs[c[0]]['direct_downstream_network'] if x[0]==n][0]
pp.create_ext_grid(tmp_net,bus=b,vm_pu=1.0,name='Converter emulation')
# print(tmp_net.line)
# print('>> Loadflow of network '+ str(n))
pp.runpp(tmp_net)
# print(tmp_net.res_line)
# print("*************************************")
tmp_net.res_line.i_ka.sort_values()
if len(tmp_net.res_line)>0:
for i in tmp_net.res_line.i_ka.sort_values(ascending=False).index:
optimal=False
while (not optimal):
if tmp_net.res_line.loc[i,'p_from_mw']>0:
tension_of_interest = 'vm_to_pu'
else:
tension_of_interest = 'vm_from_pu'
idx_new_cable = tmp_net.line.loc[i,"cable_rank"]
idx_cable=idx_new_cable
load_flow_converge=True
lines_beetween=find_lines_between_given_line_and_ext_grid(tmp_net,i)
while ((tmp_net.res_line.loc[i,"loading_percent"]<100)
and (tmp_net.res_line.loc[i,tension_of_interest]<max_v)
and (tmp_net.res_line.loc[i,tension_of_interest]>min_v)
and (idx_new_cable>=1)
and (load_flow_converge)):
idx_cable = idx_new_cable
idx_new_cable = idx_cable -1
new_cable = cable_catalogue.loc[idx_new_cable]
tmp_net.line.r_ohm_per_km.loc[i] = new_cable['R'] * 1000
tmp_net.line.max_i_ka.loc[i] = new_cable['Imax'] / 1000
tmp_net.line.cable_rank.loc[i] = idx_new_cable
try :
pp.runpp(tmp_net)
except :
load_flow_converge = False
if not ((tmp_net.res_line.loc[i,"loading_percent"]<100)
and (tmp_net.res_line.loc[i,tension_of_interest]<max_v)
and (tmp_net.res_line.loc[i,tension_of_interest]>min_v)
and (load_flow_converge)):
new_cable = cable_catalogue.loc[idx_cable]
tmp_net.line.r_ohm_per_km.loc[i] = new_cable['R'] * 1000
tmp_net.line.max_i_ka.loc[i] = new_cable['Imax'] / 1000
tmp_net.line.cable_rank.loc[i] = idx_cable
pp.runpp(tmp_net)
optimal=True
for l in lines_beetween:
cable_rank_beetween=tmp_net.line.loc[l,'cable_rank']
print(cable_rank_beetween,tmp_net.line.loc[i,'cable_rank'])
if cable_rank_beetween<tmp_net.line.loc[i,'cable_rank']:
new_cable = cable_catalogue.loc[cable_rank_beetween+1]
tmp_net.line.r_ohm_per_km.loc[l] = new_cable['R'] * 1000
tmp_net.line.max_i_ka.loc[l] = new_cable['Imax'] / 1000
tmp_net.line.cable_rank.loc[l] = cable_rank_beetween+1
new_cable = cable_catalogue.loc[cable_rank_beetween+1]
tmp_net.line.r_ohm_per_km.loc[i] = new_cable['R'] * 1000
tmp_net.line.max_i_ka.loc[i] = new_cable['Imax'] / 1000
tmp_net.line.cable_rank.loc[i] = cable_rank_beetween+1
optimal=False
pp.runpp(tmp_net)
dic_of_subs[n]['network']=tmp_net
loadflowed_sub.append(n)
for c in dic_of_subs[n]['direct_upstream_network']:
up_net=dic_of_subs[c[0]]['network']
p=tmp_net.res_ext_grid.p_mw.values[0]
converter=net.converter.loc[net.converter.name==c[2]]
eff = np.interp(abs(p), converter.efficiency.values[0][:, 0] / 1000, converter.efficiency.values[0][:, 1])
pp.create_load(up_net,
bus=c[1],
p_mw=p*eff*int(p<0)+p/eff*int(p>0), # Convert kW to MW
q_mvar=0,name='Load of net '+ str(n))
dic_of_subs[c[0]]['network']=up_net
net.res_converter.loc[net.converter.name==c[2],'p_mw']=p*eff*int(p<0)+p/eff*int(p>0)
net.res_converter.loc[net.converter.name==c[2],'loading (%)']=p/net.converter.loc[net.converter.name==c[2],'P']*100
net.res_converter.loc[net.converter.name==c[2],'pl_mw']=p-(p*eff*int(p<0)+p/eff*int(p>0))
net_res=merge_networks([dic_of_subs[n]['network'] for n in dic_of_subs.keys()])
net=clean_network(net_res,net)
return net