-
Notifications
You must be signed in to change notification settings - Fork 0
/
util_function.py
212 lines (173 loc) · 7.25 KB
/
util_function.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
import pandas as pd
import pandapower as pp
import numpy as np
import pandapower.networks as networks
import matplotlib.pyplot as plt
# https://pandapower.readthedocs.io/en/v2.9.0/networks/example.html
def compute_reactive_power(p_mw, cos_phi=0.97, operating_mode='inductive'):
"""Calculates reactive power according to given active power,
power factor and operation mode
:param p_mw: active power in mw
:param cos_phi: power factor
:param operating_mode: inductive or capacitive
:return: reactive power q_mvar
"""
abs_q = p_mw * np.tan(np.arccos(cos_phi))
# current phase after voltage phase, draw reactive power
if operating_mode == 'inductive':
return abs_q
# supply reactive power
elif operating_mode == 'capacitive':
return - abs_q
def create_net(switch_open=False):
net = pp.create_empty_network()
bus_hv = pp.create_bus(net, name="110 kV bar", vn_kv=110, type='b',
geodata=[0, 0])
bus_mv = pp.create_bus(net, name="20 kV bar", vn_kv=20, type='b',
geodata=[0, -1])
bus_2 = pp.create_bus(net, name="bus 2", vn_kv=20, type='b',
geodata=[-0.5, -2])
bus_3 = pp.create_bus(net, name="bus 3", vn_kv=20, type='b',
geodata=[-0.5, -3])
bus_4 = pp.create_bus(net, name="bus 4", vn_kv=20, type='b',
geodata=[-0.5, -4])
bus_5 = pp.create_bus(net, name="bus 5", vn_kv=20, type='b',
geodata=[0.5, -4])
bus_6 = pp.create_bus(net, name="bus 6", vn_kv=20, type='b',
geodata=[0.5, -3])
pp.create_ext_grid(net, 0, vm_pu=1)
pp.create_line(net, name="line 0", from_bus=bus_mv, to_bus=bus_2,
length_km=1,
std_type="NA2XS2Y 1x185 RM/25 12/20 kV")
pp.create_line(net, name="line 1", from_bus=bus_2, to_bus=bus_3,
length_km=1,
std_type="NA2XS2Y 1x185 RM/25 12/20 kV")
line_2 = pp.create_line(net, name="line 2", from_bus=bus_3, to_bus=bus_4,
length_km=1,
std_type="NA2XS2Y 1x185 RM/25 12/20 kV")
line_3 = pp.create_line(net, name="line 3", from_bus=bus_4, to_bus=bus_5,
length_km=1,
std_type="NA2XS2Y 1x185 RM/25 12/20 kV")
pp.create_line(net, name="line 4", from_bus=bus_5, to_bus=bus_6,
length_km=1,
std_type="NA2XS2Y 1x185 RM/25 12/20 kV")
pp.create_line(net, name="line 5", from_bus=bus_6, to_bus=bus_mv,
length_km=1,
std_type="NA2XS2Y 1x185 RM/25 12/20 kV")
pp.create_transformer(net, hv_bus=bus_hv, lv_bus=bus_mv,
std_type="25 MVA 110/20 kV")
pp.create_load(net, bus=bus_2, p_mw=50, q_mvar=compute_reactive_power(50),
name="load 0")
pp.create_sgen(net, bus_2, p_mw=1, q_mvar=compute_reactive_power(1),
name="sgen 0")
pp.create_load(net, bus_3, p_mw=50, q_mvar=compute_reactive_power(50),
name="load 1")
pp.create_sgen(net, bus_3, p_mw=1, q_mvar=compute_reactive_power(1),
name="sgen 1")
load_2 = pp.create_load(net, bus_4, p_mw=1,
q_mvar=compute_reactive_power(1), name="load 2")
pp.create_sgen(net, bus_4, p_mw=160, q_mvar=compute_reactive_power(160),
name="sgen 2")
load_3 = pp.create_load(net, bus_5, p_mw=1,
q_mvar=compute_reactive_power(1), name="load 3")
pp.create_sgen(net, bus_5, p_mw=100, q_mvar=compute_reactive_power(100),
name="sgen 3")
pp.create_load(net, bus_6, p_mw=1, q_mvar=compute_reactive_power(1),
name="load 4")
pp.create_sgen(net, bus_6, p_mw=100, q_mvar=compute_reactive_power(100),
name="sgen 4")
pp.create_switch(net, bus_3, line_2, et='l', closed=switch_open,
type='LBS')
return net
# scenario
def run_simulation(net):
csv = pd.read_csv('pv.csv', delimiter=';',
encoding="utf-8-sig")
dates = csv["Datum"].tolist()
power = csv["MW"].tolist()
bus_values = []
load_values = []
sgen_values = []
sgen_2_values = []
sgen_index = 2
idx_counter = 0
original_power_values = [170, 170, 170, 170, 130, 130, 90, 80, 80]
for time, power_value in zip(dates, power):
print('Aktueller Zeitschritt: ', time)
if original_power_values[
idx_counter] - power_value >= 100 or power_value < 0:
raise ValueError('Dieser Wert ist für die Anlage nicht erlaubt!')
net['sgen'].loc[sgen_index,
'p_mw'] = power_value
q = compute_reactive_power(power_value)
net['sgen'].loc[sgen_index,
'q_mvar'] = q
try:
pp.runpp(net, numba=False)
except:
print('Die Lastflussrechnung ist nicht konvergiert!')
res_vmpu = net['res_bus']['vm_pu'].tolist()
for idx in range(len(res_vmpu)):
if np.isnan(res_vmpu[idx]):
res_vmpu[idx] = 0
# res_vmpu[idx] = abs(res_[idx])
if len(res_vmpu) == 0:
bus_values.append(0)
else:
bus_values.append(np.mean(res_vmpu))
res_load = net['res_load']['p_mw'].tolist()
for idx in range(len(res_load)):
if np.isnan(res_load[idx]):
res_load[idx] = 0
# res_vmpu[idx] = abs(res_[idx])
load_values.append(np.mean(res_load))
res_sgen = net['res_sgen']['p_mw'].tolist()
for idx in range(len(res_sgen)):
if np.isnan(res_sgen[idx]):
res_sgen[idx] = 0
# res_sgen[idx] = abs(res_[idx])
sgen_values.append(np.mean(res_sgen))
res_sgen_2 = net['res_sgen']['p_mw'][sgen_index].tolist()
if np.isnan(res_sgen_2):
res_sgen_2 = 0
sgen_2_values.append(res_sgen_2)
idx_counter += 1
print('\n')
date_idx = [idx for idx in range(len(dates))]
return date_idx, sgen_values, bus_values, load_values, sgen_2_values, power
def plot_bus_values(dates, bus_values):
plt.plot(dates, bus_values)
plt.xlabel('Zeit')
plt.ylabel('Spannungswerte')
plt.title('Spannung der Busse')
# function to show the plot
plt.show()
def plot_load_values(dates, load_values):
plt.plot(dates, load_values)
plt.xlabel('Zeit')
plt.ylabel('Leistung')
plt.title('Leistungswerte der Lasten')
# function to show the plot
plt.show()
def plot_generator_values(dates, sgen_values):
plt.plot(dates, sgen_values)
plt.xlabel('Zeit')
plt.ylabel('Leistung')
plt.title('Leistungswerte der Generatoren')
# function to show the plot
plt.show()
def plot_sgen2_values(dates, sgen_2_values):
plt.plot(dates, sgen_2_values)
plt.xlabel('Zeit')
plt.ylabel('Leistung')
plt.title('Leistungswerte Generator 2')
# function to show the plot
plt.show()
def plot_schedule_values(dates, schedule_values):
# Fahrplanwerte
plt.plot(dates, schedule_values)
plt.xlabel('Zeit')
plt.ylabel('Leistung')
plt.title('Fahrplanwerte Generator 2')
# function to show the plot
plt.show()