Skip to content

Commit d90f05f

Browse files
committed
examples: use multi-output link for chained reservoir example
Allows water out of first turbine to feed second reservoir. Link between reservoirs is then for spillage.
1 parent 88d0cb9 commit d90f05f

File tree

1 file changed

+46
-29
lines changed

1 file changed

+46
-29
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,36 @@
11
## Two chained reservoirs with inflow in one supply two electric loads
22
#
3-
#Two disconnected electrical loads are fed from two reservoirs linked by a river; the first reservoir has inflow from a water basin.
3+
#Two disconnected electrical loads are fed from two reservoirs linked by a river; the first reservoir has inflow from rain onto a water basin.
44
#
55
#Note that the two reservoirs are tightly coupled, meaning there is no time delay between the first one emptying and the second one filling, as there would be if there were a long stretch of river between the reservoirs. The reservoirs are essentially assumed to be close to each other. A time delay would require a "Link" element between different snapshots, which is not yet supported by PyPSA (but could be enabled by passing network.lopf() an extra_functionality function).
66

77
import pypsa
88
import pandas as pd
9+
import numpy as np
910

1011
from pyomo.environ import Constraint
1112

13+
#First tell PyPSA that links will have a 2nd bus by
14+
#overriding the component_attrs. This is needed so that
15+
#water can both go through a turbine AND feed the next reservoir
1216

13-
network = pypsa.Network()
17+
override_component_attrs = pypsa.descriptors.Dict({k : v.copy() for k,v in pypsa.components.component_attrs.items()})
18+
override_component_attrs["Link"].loc["bus2"] = ["string",np.nan,np.nan,"2nd bus","Input (optional)"]
19+
override_component_attrs["Link"].loc["efficiency2"] = ["static or series","per unit",1.,"2nd bus efficiency","Input (optional)"]
20+
override_component_attrs["Link"].loc["p2"] = ["series","MW",0.,"2nd bus output","Output"]
21+
22+
23+
network = pypsa.Network(override_component_attrs=override_component_attrs)
1424

1525
network.set_snapshots(pd.date_range("2016-01-01 00:00","2016-01-01 03:00",freq="H"))
1626

27+
network.add("Carrier",
28+
"reservoir")
29+
30+
network.add("Carrier",
31+
"rain")
32+
33+
1734
network.add("Bus",
1835
"0",
1936
carrier="AC")
@@ -22,20 +39,15 @@
2239
"1",
2340
carrier="AC")
2441

42+
2543
network.add("Bus",
2644
"0 reservoir",
2745
carrier="reservoir")
2846

29-
3047
network.add("Bus",
3148
"1 reservoir",
3249
carrier="reservoir")
3350

34-
network.add("Carrier",
35-
"reservoir")
36-
37-
network.add("Carrier",
38-
"rain")
3951

4052
network.add("Generator",
4153
"rain",
@@ -44,22 +56,38 @@
4456
p_nom=1000,
4557
p_max_pu=[0.,0.2,0.7,0.4])
4658

59+
4760
network.add("Load",
4861
"0 load",
4962
bus="0",
5063
p_set=20.)
5164

52-
5365
network.add("Load",
5466
"1 load",
5567
bus="1",
5668
p_set=30.)
5769

70+
71+
#The efficiency of a river is the relation between the gravitational potential
72+
#energy of 1 m^3 of water in reservoir 0 relative to its turbine versus the
73+
#potential energy of 1 m^3 of water in reservoir 1 relative to its turbine
74+
75+
network.add("Link",
76+
"spillage",
77+
bus0="0 reservoir",
78+
bus1="1 reservoir",
79+
efficiency=0.5,
80+
p_nom_extendable=True)
81+
82+
83+
#water from turbine also goes into next reservoir
5884
network.add("Link",
5985
"0 turbine",
6086
bus0="0 reservoir",
6187
bus1="0",
88+
bus2="1 reservoir",
6289
efficiency=0.9,
90+
efficiency2=0.5,
6391
capital_cost=1000,
6492
p_nom_extendable=True)
6593

@@ -70,29 +98,14 @@
7098
efficiency=0.9,
7199
capital_cost=1000,
72100
p_nom_extendable=True)
73-
74-
75-
76-
77-
#The efficiency of a river is the relation between the gravitational potential
78-
#energy of 1 m^3 of water in reservoir 0 relative to its turbine versus the
79-
#potential energy of 1 m^3 of water in reservoir 1 relative to its turbine
80-
81-
network.add("Link",
82-
"river",
83-
bus0="0 reservoir",
84-
bus1="1 reservoir",
85-
efficiency=0.5,
86-
p_nom_extendable=True)
87-
101+
88102

89103
network.add("Store",
90104
"0 reservoir",
91105
bus="0 reservoir",
92106
e_cyclic=True,
93107
e_nom_extendable=True)
94108

95-
96109
network.add("Store",
97110
"1 reservoir",
98111
bus="1 reservoir",
@@ -102,11 +115,15 @@
102115
network.lopf(network.snapshots)
103116
print("Objective:",network.objective)
104117

105-
print(pd.DataFrame({attr: network.stores_t[attr]["0 reservoir"] for attr in ["p","e"]}))
106-
107-
print(pd.DataFrame({attr: network.stores_t[attr]["1 reservoir"] for attr in ["p","e"]}))
118+
print(network.generators_t.p)
108119

109120
print(network.links_t.p0)
110121

111-
print(network.generators_t.p)
122+
print(network.links_t.p1)
123+
124+
print(network.links_t.p2)
125+
126+
print(pd.DataFrame({attr: network.stores_t[attr]["0 reservoir"] for attr in ["p","e"]}))
127+
128+
print(pd.DataFrame({attr: network.stores_t[attr]["1 reservoir"] for attr in ["p","e"]}))
112129

0 commit comments

Comments
 (0)