|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
|
|
3
|
|
|
""" |
|
4
|
|
|
General description |
|
5
|
|
|
------------------- |
|
6
|
|
|
|
|
7
|
|
|
This example illustrates the effect of activity_costs. |
|
8
|
|
|
|
|
9
|
|
|
There are the following components: |
|
10
|
|
|
|
|
11
|
|
|
- demand_heat: heat demand (constant, for the sake of simplicity) |
|
12
|
|
|
- fireplace: wood firing, burns "for free" if somebody is around |
|
13
|
|
|
- boiler: gas firing, consumes (paid) gas |
|
14
|
|
|
|
|
15
|
|
|
Notice that activity_costs is an attribute to NonConvex. |
|
16
|
|
|
This is because it relies on the activity status of a component |
|
17
|
|
|
which is only available for nonconvex flows. |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
Installation requirements |
|
21
|
|
|
------------------------- |
|
22
|
|
|
This example requires oemof.solph (v0.5.x), install by: |
|
23
|
|
|
|
|
24
|
|
|
pip install oemof.solph[examples] |
|
25
|
|
|
|
|
26
|
|
|
License |
|
27
|
|
|
------- |
|
28
|
|
|
`MIT license <https://github.com/oemof/oemof-solph/blob/dev/LICENSE>`_ |
|
29
|
|
|
|
|
30
|
|
|
""" |
|
31
|
|
|
|
|
32
|
|
|
import matplotlib.pyplot as plt |
|
33
|
|
|
import numpy as np |
|
34
|
|
|
import pandas as pd |
|
35
|
|
|
|
|
36
|
|
|
from oemof import solph |
|
37
|
|
|
|
|
38
|
|
|
########################################################################## |
|
39
|
|
|
# Calculate parameters and initialize the energy system and |
|
40
|
|
|
########################################################################## |
|
41
|
|
|
|
|
42
|
|
|
periods = 24 |
|
43
|
|
|
time = pd.date_range("1/1/2018", periods=periods, freq="H") |
|
44
|
|
|
|
|
45
|
|
|
demand_heat = np.full(periods, 5) |
|
46
|
|
|
demand_heat[:4] = 0 |
|
47
|
|
|
demand_heat[4:18] = 4 |
|
48
|
|
|
|
|
49
|
|
|
activity_costs = np.full(periods, 5) |
|
50
|
|
|
activity_costs[18:] = 0 |
|
51
|
|
|
|
|
52
|
|
|
es = solph.EnergySystem(timeindex=time) |
|
53
|
|
|
|
|
54
|
|
|
b_heat = solph.Bus(label="b_heat") |
|
55
|
|
|
|
|
56
|
|
|
es.add(b_heat) |
|
57
|
|
|
|
|
58
|
|
|
sink_heat = solph.components.Sink( |
|
59
|
|
|
label="demand", |
|
60
|
|
|
inputs={b_heat: solph.Flow(fix=demand_heat, nominal_value=1)}, |
|
61
|
|
|
) |
|
62
|
|
|
|
|
63
|
|
|
fireplace = solph.components.Source( |
|
64
|
|
|
label="fireplace", |
|
65
|
|
|
outputs={ |
|
66
|
|
|
b_heat: solph.Flow( |
|
67
|
|
|
nominal_value=3, |
|
68
|
|
|
variable_costs=0, |
|
69
|
|
|
nonconvex=solph.NonConvex(activity_costs=activity_costs), |
|
70
|
|
|
) |
|
71
|
|
|
}, |
|
72
|
|
|
) |
|
73
|
|
|
|
|
74
|
|
|
boiler = solph.components.Source( |
|
75
|
|
|
label="boiler", |
|
76
|
|
|
outputs={b_heat: solph.Flow(nominal_value=10, variable_costs=1)}, |
|
77
|
|
|
) |
|
78
|
|
|
|
|
79
|
|
|
es.add(sink_heat, fireplace, boiler) |
|
80
|
|
|
|
|
81
|
|
|
########################################################################## |
|
82
|
|
|
# Optimise the energy system |
|
83
|
|
|
########################################################################## |
|
84
|
|
|
|
|
85
|
|
|
# create an optimization problem and solve it |
|
86
|
|
|
om = solph.Model(es) |
|
87
|
|
|
|
|
88
|
|
|
# solve model |
|
89
|
|
|
om.solve(solver="cbc", solve_kwargs={"tee": True}) |
|
90
|
|
|
|
|
91
|
|
|
########################################################################## |
|
92
|
|
|
# Check and plot the results |
|
93
|
|
|
########################################################################## |
|
94
|
|
|
|
|
95
|
|
|
results = solph.processing.results(om) |
|
96
|
|
|
|
|
97
|
|
|
# plot data |
|
98
|
|
|
data = solph.views.node(results, "b_heat")["sequences"] |
|
99
|
|
|
ax = data.plot(kind="line", drawstyle="steps-post", grid=True, rot=0) |
|
100
|
|
|
ax.set_xlabel("Time") |
|
101
|
|
|
ax.set_ylabel("Heat (arb. units)") |
|
102
|
|
|
plt.show() |
|
103
|
|
|
|