|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
|
|
3
|
|
|
""" |
|
4
|
|
|
SPDX-FileCopyrightText: Patrik Schönfeldt |
|
5
|
|
|
SPDX-FileCopyrightText: Daniel Niederhöfer |
|
6
|
|
|
SPDX-FileCopyrightText: DLR e.V. |
|
7
|
|
|
|
|
8
|
|
|
SPDX-License-Identifier: MIT |
|
9
|
|
|
""" |
|
10
|
|
|
# %%[imports] |
|
11
|
|
|
import os |
|
12
|
|
|
|
|
13
|
|
|
import matplotlib.pyplot as plt |
|
14
|
|
|
import networkx as nx |
|
15
|
|
|
import numpy as np |
|
16
|
|
|
import pandas as pd |
|
17
|
|
|
|
|
18
|
|
|
from oemof import solph |
|
19
|
|
|
from oemof.network.graph import create_nx_graph |
|
20
|
|
|
from oemof.solph import Results |
|
21
|
|
|
|
|
22
|
|
|
# %%[input_data] |
|
23
|
|
|
|
|
24
|
|
|
file_path = os.path.dirname(__file__) |
|
25
|
|
|
filename = os.path.join(file_path, "pv_example_data.csv") |
|
26
|
|
|
input_data = pd.read_csv( |
|
27
|
|
|
filename, index_col="timestep", parse_dates=["timestep"] |
|
28
|
|
|
) |
|
29
|
|
|
|
|
30
|
|
|
# %%[energy_system] |
|
31
|
|
|
|
|
32
|
|
|
# parse_dates does not set the freq attribute. |
|
33
|
|
|
# However, we want to use it for the EnergySystem. |
|
34
|
|
|
input_data.index.freq = pd.infer_freq(input_data.index) |
|
35
|
|
|
|
|
36
|
|
|
energy_system = solph.EnergySystem( |
|
37
|
|
|
timeindex=input_data.index, |
|
38
|
|
|
infer_last_interval=True, |
|
39
|
|
|
) |
|
40
|
|
|
|
|
41
|
|
|
# %%[dispatch_model] |
|
42
|
|
|
|
|
43
|
|
|
ac_bus = solph.Bus(label="electricity") |
|
44
|
|
|
|
|
45
|
|
|
demand = solph.components.Sink( |
|
46
|
|
|
label="demand", |
|
47
|
|
|
inputs={ |
|
48
|
|
|
ac_bus: solph.Flow( |
|
49
|
|
|
nominal_capacity=1, |
|
50
|
|
|
fix=input_data["electricity demand (kW)"], |
|
51
|
|
|
) |
|
52
|
|
|
}, |
|
53
|
|
|
) |
|
54
|
|
|
|
|
55
|
|
|
energy_system.add(ac_bus, demand) |
|
56
|
|
|
|
|
57
|
|
|
# %%[grid] |
|
58
|
|
|
|
|
59
|
|
|
grid = solph.Bus( |
|
60
|
|
|
label="grid", |
|
61
|
|
|
inputs={ac_bus: solph.Flow(variable_costs=-0.06)}, |
|
62
|
|
|
outputs={ |
|
63
|
|
|
ac_bus: solph.Flow( |
|
64
|
|
|
nominal_capacity=42, |
|
65
|
|
|
full_load_time_max=5, |
|
66
|
|
|
variable_costs=0.3, |
|
67
|
|
|
) |
|
68
|
|
|
}, |
|
69
|
|
|
balanced=False, |
|
70
|
|
|
) |
|
71
|
|
|
|
|
72
|
|
|
energy_system.add(grid) |
|
73
|
|
|
|
|
74
|
|
|
# %%[pv_system] |
|
75
|
|
|
dc_bus = solph.Bus(label="DC") |
|
76
|
|
|
|
|
77
|
|
|
pv_specific_costs = 1200 # €/kW |
|
78
|
|
|
pv_lifetime = 20 # years |
|
79
|
|
|
pv_epc = pv_specific_costs / pv_lifetime |
|
80
|
|
|
print(pv_epc) |
|
81
|
|
|
|
|
82
|
|
|
pv_panels = solph.components.Source( |
|
83
|
|
|
label="PV", |
|
84
|
|
|
outputs={ |
|
85
|
|
|
dc_bus: solph.Flow( |
|
86
|
|
|
nominal_capacity=solph.Investment(ep_costs=pv_epc, maximum=10), |
|
87
|
|
|
max=input_data["pv yield (kW/kW)"] / 0.95, |
|
88
|
|
|
) |
|
89
|
|
|
}, |
|
90
|
|
|
) |
|
91
|
|
|
|
|
92
|
|
|
inverter_specific_costs = 300 # €/kW |
|
93
|
|
|
inverter_lifetime = 20 # years |
|
94
|
|
|
inverter_epc = inverter_specific_costs / inverter_lifetime |
|
95
|
|
|
print(inverter_epc) |
|
96
|
|
|
|
|
97
|
|
|
inverter = solph.components.Converter( |
|
98
|
|
|
label="inverter", |
|
99
|
|
|
inputs={ |
|
100
|
|
|
dc_bus: solph.Flow( |
|
101
|
|
|
nominal_capacity=solph.Investment( |
|
102
|
|
|
ep_costs=inverter_epc, nonconvex=True, offset=400, maximum=150 |
|
103
|
|
|
) |
|
104
|
|
|
) |
|
105
|
|
|
}, |
|
106
|
|
|
outputs={ac_bus: solph.Flow()}, |
|
107
|
|
|
conversion_factors={ac_bus: 0.95}, |
|
108
|
|
|
) |
|
109
|
|
|
|
|
110
|
|
|
energy_system.add(dc_bus, pv_panels, inverter) |
|
111
|
|
|
|
|
112
|
|
|
# %%[battery] |
|
113
|
|
|
battery_specific_costs = 750 # €/kW |
|
114
|
|
|
battery_lifetime = 20 # years |
|
115
|
|
|
battery_epc = battery_specific_costs / battery_lifetime |
|
116
|
|
|
battery_size = solph.Investment(ep_costs=battery_epc) |
|
117
|
|
|
|
|
118
|
|
|
battery = solph.components.GenericStorage( |
|
119
|
|
|
label="Battery", |
|
120
|
|
|
nominal_capacity=battery_size, |
|
121
|
|
|
inputs={ac_bus: solph.Flow()}, |
|
122
|
|
|
outputs={ac_bus: solph.Flow()}, |
|
123
|
|
|
inflow_conversion_factor=0.9, |
|
124
|
|
|
loss_rate=0.01, |
|
125
|
|
|
) |
|
126
|
|
|
|
|
127
|
|
|
energy_system.add(battery) |
|
128
|
|
|
|
|
129
|
|
|
battery2 = solph.components.GenericStorage( |
|
130
|
|
|
label="Battery2", |
|
131
|
|
|
nominal_capacity=battery_size, |
|
132
|
|
|
inputs={ac_bus: solph.Flow()}, |
|
133
|
|
|
outputs={ac_bus: solph.Flow()}, |
|
134
|
|
|
inflow_conversion_factor=0.9, |
|
135
|
|
|
loss_rate=0.01, |
|
136
|
|
|
) |
|
137
|
|
|
|
|
138
|
|
|
energy_system.add(battery2) |
|
139
|
|
|
|
|
140
|
|
|
# %%[graph_plotting] |
|
141
|
|
|
plt.figure() |
|
142
|
|
|
graph = create_nx_graph(energy_system) |
|
143
|
|
|
nx.drawing.nx_pydot.write_dot(graph, "home_pv_graph_6.dot") |
|
144
|
|
|
nx.draw(graph, with_labels=True, font_size=8) |
|
145
|
|
|
# %%[model_optimisation] |
|
146
|
|
|
model = solph.Model(energy_system) |
|
147
|
|
|
|
|
148
|
|
|
model.solve(solver="gurobi", solve_kwargs={"tee": False}) |
|
149
|
|
|
results = solph.processing.results(model) |
|
150
|
|
|
meta_results = solph.processing.meta_results(model) |
|
151
|
|
|
|
|
152
|
|
|
new_results = Results(model, eval_economy=True) |
|
153
|
|
|
# %% |
|
154
|
|
|
keys = new_results.keys() |
|
155
|
|
|
|
|
156
|
|
|
print("---------------------------------------------") |
|
157
|
|
|
print("Hier findet sich die Ausgabe nach dem Solve") |
|
158
|
|
|
print("---------------------------------------------") |
|
159
|
|
|
print("Das sind die keys, welche man für die Results nutzen kann: ") |
|
160
|
|
|
print(keys) |
|
161
|
|
|
|
|
162
|
|
|
# %% |
|
163
|
|
|
|
|
164
|
|
|
# opex = new_results.calc_opex() |
|
165
|
|
|
# print(opex) |
|
166
|
|
|
|
|
167
|
|
|
opex = new_results.to_df("yearly_investment_costs") |
|
168
|
|
|
print(opex) |
|
169
|
|
|
|