-
Notifications
You must be signed in to change notification settings - Fork 465
/
test_dcline.py
145 lines (110 loc) · 5.71 KB
/
test_dcline.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
# -*- coding: utf-8 -*-
# Copyright (c) 2016-2020 by University of Kassel and Fraunhofer Institute for Energy Economics
# and Energy System Technology (IEE), Kassel. All rights reserved.
import pytest
from numpy import array, allclose, isclose
import pandapower as pp
from pandapower.test.consistency_checks import consistency_checks
try:
import pplog as logging
except ImportError:
import logging
logger = logging.getLogger(__name__)
@pytest.fixture
def dcline_net():
net = pp.create_empty_network()
b5 = pp.create_bus(net, 380)
b3 = pp.create_bus(net, 380)
b2 = pp.create_bus(net, 380)
b4 = pp.create_bus(net, 380)
b1 = pp.create_bus(net, 380)
pp.create_ext_grid(net, b1, 1.02, min_p_mw=0., max_p_mw=1e9)
pp.create_line(net, b1, b2, 30, "490-AL1/64-ST1A 380.0")
pp.create_dcline(net, name="dc line", from_bus=b2, to_bus=b3, p_mw=200, loss_percent=1.0,
loss_mw=0.5, vm_from_pu=1.01, vm_to_pu=1.012, max_p_mw=1000,
in_service=True, index=4)
pp.create_line(net, b3, b4, 20, "490-AL1/64-ST1A 380.0")
pp.create_load(net, bus=b4, p_mw=800, controllable=False)
pp.create_line(net, b4, b5, 20, "490-AL1/64-ST1A 380.0")
pp.create_ext_grid(net, b5, 1.02, min_p_mw=0., max_p_mw=1e9)
return net
def get_delta_try_except(net):
for delta in [1e-5, 1e-6, 1e-7, 1e-8, 1e-9, 1e-10, 1e-11, 1e-12]:
try:
pp.runopp(net, delta=delta)
return delta
except pp.OPFNotConverged:
continue
return 1e-10
@pytest.mark.xfail(reason="numerical issue with OPF convergence. The failure seems to depend on the"
" python version. Should be reworked.")
def test_dispatch1(dcline_net):
net = dcline_net
pp.create_pwl_cost(net, 0, "ext_grid", [[-1e12, 1e9, 100]])
pp.create_pwl_cost(net, 1, "ext_grid", [[-1e12, 1e9, 80]])
net.bus["max_vm_pu"] = 2
net.bus["min_vm_pu"] = 0 # needs to be constrained more than default
net.line["max_loading_percent"] = 1000 # does not converge if unconstrained
pp.runopp(net, delta=1e-8)
consistency_checks(net)
rel_loss_expect = (net.res_dcline.pl_mw - net.dcline.loss_mw) / \
(net.res_dcline.p_from_mw - net.res_dcline.pl_mw) * 100
assert allclose(rel_loss_expect.values, net.dcline.loss_percent.values, rtol=1e-2)
assert allclose(net.res_ext_grid.p_mw.values, [0.5, 805], atol=0.1)
assert allclose(net.res_ext_grid.q_mvar.values, [-7.78755773243, 0.62830727889], atol=1e-3)
assert allclose(net.res_dcline.p_from_mw.values, [0.500754071], atol=1e-3)
assert allclose(net.res_dcline.q_from_mvar.values, [7.78745600524])
assert allclose(net.res_dcline.p_to_mw.values, array([-5.48553789e-05]))
assert allclose(net.res_dcline.q_to_mvar.values, array([-.62712636707]))
@pytest.mark.xfail(reason="numerical issue with OPF convergence. If vm_pu delta is != 0. at "
"ext_grid -> fail. See build_gen() in line 111 + 112")
def test_dcline_dispatch2(dcline_net):
net = dcline_net
pp.create_poly_cost(net, 0, "ext_grid", cp1_eur_per_mw=80)
pp.create_poly_cost(net, 1, "ext_grid", cp1_eur_per_mw=100)
# pp.create_poly_cost(net, 0, "ext_grid", array([.08, 0]))
# pp.create_poly_cost(net, 1, "ext_grid", array([.1, 0]))
net.bus["max_vm_pu"] = 2
net.bus["min_vm_pu"] = 0 # needs to be constrained more than default
net.line["max_loading_percent"] = 1000 # does not converge if unconstrained
# pp.runopp(net, delta=get_delta_try_except(net))
pp.runopp(net)
consistency_checks(net, rtol=1e-3)
rel_loss_expect = (net.res_dcline.pl_mw - net.dcline.loss_mw) / \
(net.res_dcline.p_from_mw - net.res_dcline.pl_mw) * 100
assert allclose(rel_loss_expect.values, net.dcline.loss_percent.values)
p_eg_expect = array([8.21525358e+02, 5.43498903e-05])
q_eg_expect = array([-7787.55852923e-3, -21048.59213887e-3])
assert allclose(net.res_ext_grid.p_mw.values, p_eg_expect)
assert allclose(net.res_ext_grid.q_mvar.values, q_eg_expect)
p_from_expect = array([813573.88366999e-3])
q_from_expect = array([-26446.0473644e-3])
assert allclose(net.res_dcline.p_from_mw.values, p_from_expect)
assert allclose(net.res_dcline.q_from_mvar.values, q_from_expect)
p_to_expect = array([-805023.64719801e-3])
q_to_expect = array([-21736.31196315e-3])
assert allclose(net.res_dcline.p_to_mw.values, p_to_expect)
assert allclose(net.res_dcline.q_to_mvar.values, q_to_expect)
@pytest.mark.xfail(reason="numerical issue with OPF convergence. If vm_pu delta is != 0. at "
"ext_grid -> fail. See build_gen() in line 111 + 112")
def test_dcline_dispatch3(dcline_net):
net = dcline_net
pp.create_poly_cost(net, 4, "dcline", cp1_eur_per_mw=1.5)
net.bus["max_vm_pu"] = 1.03 # needs to be constrained more than default
net.line["max_loading_percent"] = 1000 # does not converge if unconstrained
# pp.runopp(net, delta=get_delta_try_except(net))
pp.runopp(net)
consistency_checks(net, rtol=1e-1)
# dc line is not dispatched because of the assigned costs
assert isclose(net.res_dcline.at[4, "p_to_mw"], 0, atol=1e-2)
assert all(net.res_ext_grid.p_mw.values > 0)
# costs for ext_grid at the end of the DC line get double the costs of DC line transfer
pp.create_poly_cost(net, 1, "ext_grid", cp1_eur_per_mw=2000)
pp.runopp(net)
# pp.runopp(net, delta=get_delta_try_except(net))
# now the total power is supplied through the DC line
assert (net.res_dcline.at[4, "p_to_mw"]) < 1e3
assert net.res_ext_grid.p_mw.at[1] < 1
assert isclose(net.res_cost, net.res_dcline.at[4, "p_from_mw"] * 1.5)
if __name__ == "__main__":
pytest.main([__file__])