|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
|
|
3
|
|
|
""" |
|
4
|
|
|
General description |
|
5
|
|
|
------------------- |
|
6
|
|
|
This example shows how to perform a capacity optimization for |
|
7
|
|
|
an energy system with storage. The following energy system is modeled: |
|
8
|
|
|
|
|
9
|
|
|
.. code-block:: text |
|
10
|
|
|
|
|
11
|
|
|
input/output bgas bel |
|
12
|
|
|
| | | |
|
13
|
|
|
| | | |
|
14
|
|
|
wind(FixedSource) |------------------>| |
|
15
|
|
|
| | | |
|
16
|
|
|
pv(FixedSource) |------------------>| |
|
17
|
|
|
| | | |
|
18
|
|
|
gas_resource |--------->| | |
|
19
|
|
|
(Commodity) | | | |
|
20
|
|
|
| | | |
|
21
|
|
|
demand(Sink) |<------------------| |
|
22
|
|
|
| | | |
|
23
|
|
|
| | | |
|
24
|
|
|
pp_gas(Transformer) |<---------| | |
|
25
|
|
|
|------------------>| |
|
26
|
|
|
| | | |
|
27
|
|
|
storage(Storage) |<------------------| |
|
28
|
|
|
|------------------>| |
|
29
|
|
|
|
|
30
|
|
|
The example exists in four variations. The following parameters describe |
|
31
|
|
|
the main setting for the optimization variation 1: |
|
32
|
|
|
|
|
33
|
|
|
- optimize wind, pv, gas_resource and storage |
|
34
|
|
|
- set investment cost for wind, pv and storage |
|
35
|
|
|
- set gas price for kWh |
|
36
|
|
|
|
|
37
|
|
|
Results show an installation of wind and the use of the gas resource. |
|
38
|
|
|
A renewable energy share of 51% is achieved. |
|
39
|
|
|
|
|
40
|
|
|
Have a look at different parameter settings. There are four variations |
|
41
|
|
|
of this example in the same folder. |
|
42
|
|
|
|
|
43
|
|
|
Data |
|
44
|
|
|
---- |
|
45
|
|
|
storage_investment.csv |
|
46
|
|
|
|
|
47
|
|
|
Installation requirements |
|
48
|
|
|
------------------------- |
|
49
|
|
|
|
|
50
|
|
|
This example requires oemof.solph (v0.5.x), install by: |
|
51
|
|
|
|
|
52
|
|
|
pip install oemof.solph[examples] |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
License |
|
56
|
|
|
------- |
|
57
|
|
|
`MIT license <https://github.com/oemof/oemof-solph/blob/dev/LICENSE>`_ |
|
58
|
|
|
|
|
59
|
|
|
""" |
|
60
|
|
|
|
|
61
|
|
|
############################################################################### |
|
62
|
|
|
# Imports |
|
63
|
|
|
############################################################################### |
|
64
|
|
|
|
|
65
|
|
|
import logging |
|
66
|
|
|
import os |
|
67
|
|
|
import pprint as pp |
|
68
|
|
|
import warnings |
|
69
|
|
|
|
|
70
|
|
|
import pandas as pd |
|
71
|
|
|
|
|
72
|
|
|
# Default logger of oemof |
|
73
|
|
|
from oemof.tools import economics |
|
74
|
|
|
from oemof.tools import logger |
|
75
|
|
|
|
|
76
|
|
|
from oemof import solph |
|
77
|
|
|
|
|
78
|
|
|
# Read data file |
|
79
|
|
|
filename = os.path.join(os.getcwd(), "storage_investmentd.csv") |
|
80
|
|
|
try: |
|
81
|
|
|
data = pd.read_csv(filename) |
|
82
|
|
|
except FileNotFoundError: |
|
83
|
|
|
msg = "Data file not found: {0}. Only one value used!" |
|
84
|
|
|
warnings.warn(msg.format(filename), UserWarning) |
|
85
|
|
|
data = pd.DataFrame( |
|
86
|
|
|
{"pv": [0.3, 0.5], "wind": [0.6, 0.8], "demand_el": [500, 600]} |
|
87
|
|
|
) |
|
88
|
|
|
|
|
89
|
|
|
number_timesteps = len(data) |
|
90
|
|
|
|
|
91
|
|
|
########################################################################## |
|
92
|
|
|
# Initialize the energy system and read/calculate necessary parameters |
|
93
|
|
|
########################################################################## |
|
94
|
|
|
|
|
95
|
|
|
logger.define_logging() |
|
96
|
|
|
logging.info("Initialize the energy system") |
|
97
|
|
|
date_time_index = solph.create_time_index(2012, number=number_timesteps) |
|
98
|
|
|
energysystem = solph.EnergySystem( |
|
99
|
|
|
timeindex=date_time_index, infer_last_interval=False |
|
100
|
|
|
) |
|
101
|
|
|
|
|
102
|
|
|
price_gas = 0.04 |
|
103
|
|
|
|
|
104
|
|
|
# If the period is one year the equivalent periodical costs (epc) of an |
|
105
|
|
|
# investment are equal to the annuity. Use oemof's economic tools. |
|
106
|
|
|
epc_wind = economics.annuity(capex=1000, n=20, wacc=0.05) |
|
107
|
|
|
epc_pv = economics.annuity(capex=1000, n=20, wacc=0.05) |
|
108
|
|
|
epc_storage = economics.annuity(capex=1000, n=20, wacc=0.05) |
|
109
|
|
|
|
|
110
|
|
|
########################################################################## |
|
111
|
|
|
# Create oemof objects |
|
112
|
|
|
########################################################################## |
|
113
|
|
|
|
|
114
|
|
|
logging.info("Create oemof objects") |
|
115
|
|
|
# create natural gas bus |
|
116
|
|
|
bgas = solph.Bus(label="natural_gas") |
|
117
|
|
|
|
|
118
|
|
|
# create electricity bus |
|
119
|
|
|
bel = solph.Bus(label="electricity") |
|
120
|
|
|
|
|
121
|
|
|
energysystem.add(bgas, bel) |
|
122
|
|
|
|
|
123
|
|
|
# create excess component for the electricity bus to allow overproduction |
|
124
|
|
|
excess = solph.components.Sink(label="excess_bel", inputs={bel: solph.Flow()}) |
|
125
|
|
|
|
|
126
|
|
|
# create source object representing the natural gas commodity (annual limit) |
|
127
|
|
|
gas_resource = solph.components.Source( |
|
128
|
|
|
label="rgas", outputs={bgas: solph.Flow(variable_costs=price_gas)} |
|
129
|
|
|
) |
|
130
|
|
|
|
|
131
|
|
|
# create fixed source object representing wind power plants |
|
132
|
|
|
wind = solph.components.Source( |
|
133
|
|
|
label="wind", |
|
134
|
|
|
outputs={ |
|
135
|
|
|
bel: solph.Flow( |
|
136
|
|
|
fix=data["wind"], investment=solph.Investment(ep_costs=epc_wind) |
|
137
|
|
|
) |
|
138
|
|
|
}, |
|
139
|
|
|
) |
|
140
|
|
|
|
|
141
|
|
|
# create fixed source object representing pv power plants |
|
142
|
|
|
pv = solph.components.Source( |
|
143
|
|
|
label="pv", |
|
144
|
|
|
outputs={ |
|
145
|
|
|
bel: solph.Flow( |
|
146
|
|
|
fix=data["pv"], investment=solph.Investment(ep_costs=epc_pv) |
|
147
|
|
|
) |
|
148
|
|
|
}, |
|
149
|
|
|
) |
|
150
|
|
|
|
|
151
|
|
|
# create simple sink object representing the electrical demand |
|
152
|
|
|
demand = solph.components.Sink( |
|
153
|
|
|
label="demand", |
|
154
|
|
|
inputs={bel: solph.Flow(fix=data["demand_el"], nominal_value=1)}, |
|
155
|
|
|
) |
|
156
|
|
|
|
|
157
|
|
|
# create simple transformer object representing a gas power plant |
|
158
|
|
|
pp_gas = solph.components.Transformer( |
|
159
|
|
|
label="pp_gas", |
|
160
|
|
|
inputs={bgas: solph.Flow()}, |
|
161
|
|
|
outputs={bel: solph.Flow(nominal_value=10e10, variable_costs=0)}, |
|
162
|
|
|
conversion_factors={bel: 0.58}, |
|
163
|
|
|
) |
|
164
|
|
|
|
|
165
|
|
|
# create storage object representing a battery |
|
166
|
|
|
storage = solph.components.GenericStorage( |
|
167
|
|
|
label="storage", |
|
168
|
|
|
inputs={bel: solph.Flow(variable_costs=0.0001)}, |
|
169
|
|
|
outputs={bel: solph.Flow()}, |
|
170
|
|
|
loss_rate=0.00, |
|
171
|
|
|
initial_storage_level=0, |
|
172
|
|
|
invest_relation_input_capacity=1 / 6, |
|
173
|
|
|
invest_relation_output_capacity=1 / 6, |
|
174
|
|
|
inflow_conversion_factor=1, |
|
175
|
|
|
outflow_conversion_factor=0.8, |
|
176
|
|
|
investment=solph.Investment(ep_costs=epc_storage), |
|
177
|
|
|
) |
|
178
|
|
|
|
|
179
|
|
|
energysystem.add(excess, gas_resource, wind, pv, demand, pp_gas, storage) |
|
180
|
|
|
|
|
181
|
|
|
########################################################################## |
|
182
|
|
|
# Optimise the energy system |
|
183
|
|
|
########################################################################## |
|
184
|
|
|
|
|
185
|
|
|
logging.info("Optimise the energy system") |
|
186
|
|
|
|
|
187
|
|
|
# initialise the operational model |
|
188
|
|
|
om = solph.Model(energysystem) |
|
189
|
|
|
|
|
190
|
|
|
# if tee_switch is true solver messages will be displayed |
|
191
|
|
|
logging.info("Solve the optimization problem") |
|
192
|
|
|
om.solve(solver="cbc", solve_kwargs={"tee": True}) |
|
193
|
|
|
|
|
194
|
|
|
########################################################################## |
|
195
|
|
|
# Check and plot the results |
|
196
|
|
|
########################################################################## |
|
197
|
|
|
|
|
198
|
|
|
# check if the new result object is working for custom components |
|
199
|
|
|
results = solph.processing.results(om) |
|
200
|
|
|
|
|
201
|
|
|
custom_storage = solph.views.node(results, "storage") |
|
202
|
|
|
electricity_bus = solph.views.node(results, "electricity") |
|
203
|
|
|
|
|
204
|
|
|
meta_results = solph.processing.meta_results(om) |
|
205
|
|
|
pp.pprint(meta_results) |
|
206
|
|
|
|
|
207
|
|
|
my_results = electricity_bus["scalars"] |
|
208
|
|
|
|
|
209
|
|
|
# installed capacity of storage in GWh |
|
210
|
|
|
my_results["storage_invest_GWh"] = ( |
|
211
|
|
|
results[(storage, None)]["scalars"]["invest"] / 1e6 |
|
212
|
|
|
) |
|
213
|
|
|
|
|
214
|
|
|
# installed capacity of wind power plant in MW |
|
215
|
|
|
my_results["wind_invest_MW"] = results[(wind, bel)]["scalars"]["invest"] / 1e3 |
|
216
|
|
|
|
|
217
|
|
|
# resulting renewable energy share |
|
218
|
|
|
my_results["res_share"] = ( |
|
219
|
|
|
1 |
|
220
|
|
|
- results[(pp_gas, bel)]["sequences"].sum() |
|
221
|
|
|
/ results[(bel, demand)]["sequences"].sum() |
|
222
|
|
|
) |
|
223
|
|
|
|
|
224
|
|
|
pp.pprint(my_results) |
|
225
|
|
|
|