|
1
|
|
|
""" |
|
2
|
|
|
General description |
|
3
|
|
|
------------------- |
|
4
|
|
|
The gradient constraint can restrict a component to change the output within |
|
5
|
|
|
one time step. In this example a storage will buffer this restriction, so the |
|
6
|
|
|
more flexible the power plant can be run the less the storage will be used. |
|
7
|
|
|
|
|
8
|
|
|
Change the GRADIENT variable in the example to see the effect on the usage of |
|
9
|
|
|
the storage. |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
Installation requirements |
|
13
|
|
|
------------------------- |
|
14
|
|
|
This example requires oemof.solph (v0.5.x), install by: |
|
15
|
|
|
|
|
16
|
|
|
pip install oemof.solph[examples] |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
License |
|
20
|
|
|
------- |
|
21
|
|
|
`MIT license <https://github.com/oemof/oemof-solph/blob/dev/LICENSE>`_ |
|
22
|
|
|
""" |
|
23
|
|
|
|
|
24
|
|
|
import matplotlib.pyplot as plt |
|
25
|
|
|
import pandas as pd |
|
26
|
|
|
|
|
27
|
|
|
from oemof.solph import EnergySystem |
|
28
|
|
|
from oemof.solph import Model |
|
29
|
|
|
from oemof.solph import buses |
|
30
|
|
|
from oemof.solph import components as cmp |
|
31
|
|
|
from oemof.solph import flows |
|
32
|
|
|
from oemof.solph import processing |
|
33
|
|
|
|
|
34
|
|
|
# The gradient for the output of the natural gas power plant. |
|
35
|
|
|
# Change the gradient between 0.1 and 0.0001 and check the results. The |
|
36
|
|
|
# more flexible the power plant can be run the less the storage will be used. |
|
37
|
|
|
GRADIENT = 0.01 |
|
38
|
|
|
|
|
39
|
|
|
date_time_index = pd.date_range("1/1/2012", periods=48, freq="H") |
|
40
|
|
|
print(date_time_index) |
|
41
|
|
|
energysystem = EnergySystem(timeindex=date_time_index, timemode="explicit") |
|
42
|
|
|
|
|
43
|
|
|
demand = [ |
|
44
|
|
|
209643, |
|
45
|
|
|
207497, |
|
46
|
|
|
200108, |
|
47
|
|
|
191892, |
|
48
|
|
|
185717, |
|
49
|
|
|
180672, |
|
50
|
|
|
172683, |
|
51
|
|
|
170048, |
|
52
|
|
|
171132, |
|
53
|
|
|
179532, |
|
54
|
|
|
189155, |
|
55
|
|
|
201026, |
|
56
|
|
|
208466, |
|
57
|
|
|
207718, |
|
58
|
|
|
205443, |
|
59
|
|
|
206255, |
|
60
|
|
|
217240, |
|
61
|
|
|
232798, |
|
62
|
|
|
237321, |
|
63
|
|
|
232387, |
|
64
|
|
|
224306, |
|
65
|
|
|
219280, |
|
66
|
|
|
223701, |
|
67
|
|
|
213926, |
|
68
|
|
|
201834, |
|
69
|
|
|
192215, |
|
70
|
|
|
187152, |
|
71
|
|
|
184355, |
|
72
|
|
|
184438, |
|
73
|
|
|
182786, |
|
74
|
|
|
180105, |
|
75
|
|
|
191509, |
|
76
|
|
|
207104, |
|
77
|
|
|
222501, |
|
78
|
|
|
231127, |
|
79
|
|
|
238410, |
|
80
|
|
|
241184, |
|
81
|
|
|
237413, |
|
82
|
|
|
234469, |
|
83
|
|
|
235193, |
|
84
|
|
|
242730, |
|
85
|
|
|
264196, |
|
86
|
|
|
265950, |
|
87
|
|
|
260283, |
|
88
|
|
|
245578, |
|
89
|
|
|
238849, |
|
90
|
|
|
241553, |
|
91
|
|
|
231372, |
|
92
|
|
|
] |
|
93
|
|
|
|
|
94
|
|
|
# create natural gas bus |
|
95
|
|
|
bgas = buses.Bus(label="natural_gas") |
|
96
|
|
|
|
|
97
|
|
|
# create electricity bus |
|
98
|
|
|
bel = buses.Bus(label="electricity") |
|
99
|
|
|
|
|
100
|
|
|
# adding the buses to the energy system |
|
101
|
|
|
energysystem.add(bgas, bel) |
|
102
|
|
|
|
|
103
|
|
|
# create excess component for the electricity bus to allow overproduction |
|
104
|
|
|
energysystem.add(cmp.Sink(label="excess_bel", inputs={bel: flows.Flow()})) |
|
105
|
|
|
|
|
106
|
|
|
# create source object representing the natural gas commodity (annual limit) |
|
107
|
|
|
energysystem.add( |
|
108
|
|
|
cmp.Source( |
|
109
|
|
|
label="rgas", |
|
110
|
|
|
outputs={bgas: flows.Flow(variable_costs=5)}, |
|
111
|
|
|
) |
|
112
|
|
|
) |
|
113
|
|
|
|
|
114
|
|
|
# create simple sink object representing the electrical demand |
|
115
|
|
|
energysystem.add( |
|
116
|
|
|
cmp.Sink( |
|
117
|
|
|
label="demand", |
|
118
|
|
|
inputs={bel: flows.Flow(fix=demand, nominal_value=1)}, |
|
119
|
|
|
) |
|
120
|
|
|
) |
|
121
|
|
|
|
|
122
|
|
|
# create simple transformer object representing a gas power plant |
|
123
|
|
|
energysystem.add( |
|
124
|
|
|
cmp.Transformer( |
|
125
|
|
|
label="pp_gas", |
|
126
|
|
|
inputs={bgas: flows.Flow()}, |
|
127
|
|
|
outputs={ |
|
128
|
|
|
bel: flows.Flow( |
|
129
|
|
|
nominal_value=10e5, |
|
130
|
|
|
negative_gradient={"ub": GRADIENT}, |
|
131
|
|
|
positive_gradient={"ub": GRADIENT}, |
|
132
|
|
|
) |
|
133
|
|
|
}, |
|
134
|
|
|
conversion_factors={bel: 0.58}, |
|
135
|
|
|
) |
|
136
|
|
|
) |
|
137
|
|
|
|
|
138
|
|
|
# create storage object representing a battery |
|
139
|
|
|
storage = cmp.GenericStorage( |
|
140
|
|
|
nominal_storage_capacity=999999999, |
|
141
|
|
|
label="storage", |
|
142
|
|
|
inputs={bel: flows.Flow()}, |
|
143
|
|
|
outputs={bel: flows.Flow()}, |
|
144
|
|
|
loss_rate=0.0, |
|
145
|
|
|
initial_storage_level=None, |
|
146
|
|
|
inflow_conversion_factor=1, |
|
147
|
|
|
outflow_conversion_factor=0.8, |
|
148
|
|
|
) |
|
149
|
|
|
|
|
150
|
|
|
energysystem.add(storage) |
|
151
|
|
|
|
|
152
|
|
|
# initialise the operational model |
|
153
|
|
|
model = Model(energysystem) |
|
154
|
|
|
|
|
155
|
|
|
# solve |
|
156
|
|
|
model.solve(solver="cbc") |
|
157
|
|
|
|
|
158
|
|
|
# processing the results |
|
159
|
|
|
results = processing.results(model) |
|
160
|
|
|
|
|
161
|
|
|
# ****** Create a table with all sequences and store it into a file (csv/xlsx) |
|
162
|
|
|
flows_to_bus = pd.DataFrame( |
|
163
|
|
|
{ |
|
164
|
|
|
str(k[0].label): v["sequences"]["flow"] |
|
165
|
|
|
for k, v in results.items() |
|
166
|
|
|
if k[1] is not None and k[1] == bel |
|
167
|
|
|
} |
|
168
|
|
|
) |
|
169
|
|
|
flows_from_bus = pd.DataFrame( |
|
170
|
|
|
{ |
|
171
|
|
|
str(k[1].label): v["sequences"]["flow"] |
|
172
|
|
|
for k, v in results.items() |
|
173
|
|
|
if k[1] is not None and k[0] == bel |
|
174
|
|
|
} |
|
175
|
|
|
) |
|
176
|
|
|
|
|
177
|
|
|
storage = pd.DataFrame( |
|
178
|
|
|
{ |
|
179
|
|
|
str(k[0].label): v["sequences"]["storage_content"] |
|
180
|
|
|
for k, v in results.items() |
|
181
|
|
|
if k[1] is None and k[0] == storage |
|
182
|
|
|
} |
|
183
|
|
|
) |
|
184
|
|
|
|
|
185
|
|
|
my_flows = pd.concat( |
|
186
|
|
|
[flows_to_bus, flows_from_bus, storage], |
|
187
|
|
|
keys=["to_bus", "from_bus", "content", "duals"], |
|
188
|
|
|
axis=1, |
|
189
|
|
|
) |
|
190
|
|
|
|
|
191
|
|
|
print(my_flows) |
|
192
|
|
|
my_flows.plot() |
|
193
|
|
|
plt.show() |
|
194
|
|
|
|