|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
|
|
3
|
|
|
""" |
|
4
|
|
|
General description |
|
5
|
|
|
------------------- |
|
6
|
|
|
Example that shows how to add an emission constraint in a model. |
|
7
|
|
|
|
|
8
|
|
|
Installation requirements |
|
9
|
|
|
------------------------- |
|
10
|
|
|
|
|
11
|
|
|
This example requires oemof.solph (v0.5.x), install by: |
|
12
|
|
|
|
|
13
|
|
|
pip install oemof.solph[examples] |
|
14
|
|
|
|
|
15
|
|
|
License |
|
16
|
|
|
------- |
|
17
|
|
|
`MIT license <https://github.com/oemof/oemof-solph/blob/dev/LICENSE>`_ |
|
18
|
|
|
|
|
19
|
|
|
""" |
|
20
|
|
|
import matplotlib.pyplot as plt |
|
21
|
|
|
import pandas as pd |
|
22
|
|
|
|
|
23
|
|
|
from oemof import solph |
|
24
|
|
|
from oemof.solph import constraints |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
def main(): |
|
28
|
|
|
# create energy system |
|
29
|
|
|
energysystem = solph.EnergySystem( |
|
30
|
|
|
timeindex=pd.date_range("1/1/2012", periods=3, freq="H") |
|
31
|
|
|
) |
|
32
|
|
|
|
|
33
|
|
|
# create gas bus |
|
34
|
|
|
bgas = solph.Bus(label="gas") |
|
35
|
|
|
|
|
36
|
|
|
# create electricity bus |
|
37
|
|
|
bel = solph.Bus(label="electricity") |
|
38
|
|
|
|
|
39
|
|
|
# adding the buses to the energy system |
|
40
|
|
|
energysystem.add(bel, bgas) |
|
41
|
|
|
|
|
42
|
|
|
# create fixed source object representing biomass plants |
|
43
|
|
|
energysystem.add( |
|
44
|
|
|
solph.components.Source( |
|
45
|
|
|
label="biomass", |
|
46
|
|
|
outputs={ |
|
47
|
|
|
bel: solph.Flow( |
|
48
|
|
|
nominal_value=100, |
|
49
|
|
|
variable_costs=10, |
|
50
|
|
|
emission_factor=0.01, |
|
51
|
|
|
fix=[0.1, 0.2, 0.3], |
|
52
|
|
|
) |
|
53
|
|
|
}, |
|
54
|
|
|
) |
|
55
|
|
|
) |
|
56
|
|
|
|
|
57
|
|
|
# create source object representing the gas commodity |
|
58
|
|
|
energysystem.add( |
|
59
|
|
|
solph.components.Source( |
|
60
|
|
|
label="gas-source", |
|
61
|
|
|
outputs={bgas: solph.Flow(variable_costs=10, emission_factor=0.2)}, |
|
62
|
|
|
) |
|
63
|
|
|
) |
|
64
|
|
|
|
|
65
|
|
|
energysystem.add( |
|
66
|
|
|
solph.components.Sink( |
|
67
|
|
|
label="demand", |
|
68
|
|
|
inputs={ |
|
69
|
|
|
bel: solph.Flow( |
|
70
|
|
|
nominal_value=200, variable_costs=10, fix=[0.1, 0.2, 0.3] |
|
71
|
|
|
) |
|
72
|
|
|
}, |
|
73
|
|
|
) |
|
74
|
|
|
) |
|
75
|
|
|
|
|
76
|
|
|
# create simple transformer object representing a gas power plant |
|
77
|
|
|
energysystem.add( |
|
78
|
|
|
solph.components.Transformer( |
|
79
|
|
|
label="pp_gas", |
|
80
|
|
|
inputs={bgas: solph.Flow()}, |
|
81
|
|
|
outputs={bel: solph.Flow(nominal_value=200)}, |
|
82
|
|
|
conversion_factors={bel: 0.58}, |
|
83
|
|
|
) |
|
84
|
|
|
) |
|
85
|
|
|
|
|
86
|
|
|
# initialise the operational model |
|
87
|
|
|
model = solph.Model(energysystem) |
|
88
|
|
|
|
|
89
|
|
|
# add the emission constraint |
|
90
|
|
|
constraints.emission_limit(model, limit=100) |
|
91
|
|
|
|
|
92
|
|
|
# print out the emission constraint |
|
93
|
|
|
model.integral_limit_emission_factor_constraint.pprint() |
|
94
|
|
|
model.integral_limit_emission_factor.pprint() |
|
95
|
|
|
|
|
96
|
|
|
# solve the model |
|
97
|
|
|
model.solve() |
|
98
|
|
|
|
|
99
|
|
|
# print out the amount of emissions from the emission constraint |
|
100
|
|
|
print(model.integral_limit_emission_factor()) |
|
101
|
|
|
|
|
102
|
|
|
results = solph.processing.results(model) |
|
103
|
|
|
|
|
104
|
|
|
data = solph.views.node(results, "electricity")["sequences"] |
|
105
|
|
|
ax = data.plot(kind="line", grid=True) |
|
106
|
|
|
ax.set_xlabel("Time (h)") |
|
107
|
|
|
ax.set_ylabel("P (MW)") |
|
108
|
|
|
plt.show() |
|
109
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
if __name__ == "__main__": |
|
112
|
|
|
main() |
|
113
|
|
|
|