forked from PyPSA/PyPSA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_lopf_multilink.py
210 lines (179 loc) · 4.91 KB
/
test_lopf_multilink.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
# -*- coding: utf-8 -*-
import numpy as np
import pytest
from conftest import SUPPORTED_APIS, optimize
import pypsa
@pytest.fixture
def network():
override_component_attrs = pypsa.descriptors.Dict(
{k: v.copy() for k, v in pypsa.components.component_attrs.items()}
)
override_component_attrs["Link"].loc["bus2"] = [
"string",
np.nan,
np.nan,
"2nd bus",
"Input (optional)",
]
override_component_attrs["Link"].loc["bus3"] = [
"string",
np.nan,
np.nan,
"3rd bus",
"Input (optional)",
]
override_component_attrs["Link"].loc["efficiency2"] = [
"static or series",
"per unit",
1.0,
"2nd bus efficiency",
"Input (optional)",
]
override_component_attrs["Link"].loc["efficiency3"] = [
"static or series",
"per unit",
1.0,
"3rd bus efficiency",
"Input (optional)",
]
override_component_attrs["Link"].loc["p2"] = [
"series",
"MW",
0.0,
"2nd bus output",
"Output",
]
override_component_attrs["Link"].loc["p3"] = [
"series",
"MW",
0.0,
"3rd bus output",
"Output",
]
n = pypsa.Network(override_component_attrs=override_component_attrs)
n.set_snapshots(range(10))
n.add("Bus", "bus")
n.add("Load", "load", bus="bus", p_set=1.0)
n.add("Bus", "transport")
n.add("Load", "transport", bus="transport", p_set=1.0)
n.add("Bus", "diesel")
n.add("Store", "diesel", bus="diesel", e_cyclic=True, e_nom=1000.0)
n.add("Bus", "hydrogen")
n.add("Store", "hydrogen", bus="hydrogen", e_cyclic=True, e_nom=1000.0)
n.add(
"Link", "electrolysis", p_nom=2.0, efficiency=0.8, bus0="bus", bus1="hydrogen"
)
n.add(
"Link",
"FT",
p_nom=4,
bus0="hydrogen",
bus1="diesel",
bus2="co2 stored",
efficiency=1.0,
efficiency2=-1,
)
# minus sign because opposite to how fossil fuels used:
# CH4 burning puts CH4 down, atmosphere up
n.add("Carrier", "co2", co2_emissions=-1.0)
# this tracks CO2 in the atmosphere
n.add("Bus", "co2 atmosphere", carrier="co2")
# NB: can also be negative
n.add("Store", "co2 atmosphere", e_nom=1000, e_min_pu=-1, bus="co2 atmosphere")
# this tracks CO2 stored, e.g. underground
n.add("Bus", "co2 stored")
# NB: can also be negative
n.add("Store", "co2 stored", e_nom=1000, e_min_pu=-1, bus="co2 stored")
n.add(
"Link",
"DAC",
bus0="bus",
bus1="co2 stored",
bus2="co2 atmosphere",
efficiency=1,
efficiency2=-1,
p_nom=5.0,
)
n.add(
"Link",
"diesel car",
bus0="diesel",
bus1="transport",
bus2="co2 atmosphere",
efficiency=1.0,
efficiency2=1.0,
p_nom=2.0,
)
n.add("Bus", "gas")
n.add("Store", "gas", e_initial=50, e_nom=50, marginal_cost=20, bus="gas")
n.add(
"Link",
"OCGT",
bus0="gas",
bus1="bus",
bus2="co2 atmosphere",
p_nom_extendable=True,
efficiency=0.5,
efficiency2=1,
)
n.add(
"Link",
"OCGT+CCS",
bus0="gas",
bus1="bus",
bus2="co2 stored",
bus3="co2 atmosphere",
p_nom_extendable=True,
efficiency=0.4,
efficiency2=0.9,
efficiency3=0.1,
)
# Add a cheap and a expensive biomass generator.
biomass_marginal_cost = [20.0, 50.0]
biomass_stored = [40.0, 15.0]
for i in range(2):
n.add("Bus", "biomass" + str(i))
n.add(
"Store",
"biomass" + str(i),
bus="biomass" + str(i),
e_nom_extendable=True,
marginal_cost=biomass_marginal_cost[i],
e_nom=biomass_stored[i],
e_initial=biomass_stored[i],
)
# simultaneously empties and refills co2 atmosphere
n.add(
"Link",
"biomass" + str(i),
bus0="biomass" + str(i),
bus1="bus",
p_nom_extendable=True,
efficiency=0.5,
)
n.add(
"Link",
"biomass+CCS" + str(i),
bus0="biomass" + str(i),
bus1="bus",
bus2="co2 stored",
bus3="co2 atmosphere",
p_nom_extendable=True,
efficiency=0.4,
efficiency2=1.0,
efficiency3=-1,
)
# can go to -50, but at some point can't generate enough electricity for DAC and demand
target = -50
n.add(
"GlobalConstraint",
"co2_limit",
sense="<=",
carrier_attribute="co2_emissions",
constant=target,
)
return n
@pytest.mark.parametrize("api", SUPPORTED_APIS)
def test_lopf(network, api):
status, condition = optimize(network, api)
assert status == "ok"