|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
|
|
3
|
|
|
"""Tests for Flows with NonConvex attribute |
|
4
|
|
|
|
|
5
|
|
|
SPDX-FileCopyrightText: Deutsches Zentrum für Luft- und Raumfahrt e.V. |
|
6
|
|
|
SPDX-FileCopyrightText: Patrik Schönfeldt |
|
7
|
|
|
|
|
8
|
|
|
SPDX-License-Identifier: MIT |
|
9
|
|
|
""" |
|
10
|
|
|
|
|
11
|
|
|
import pandas as pd |
|
12
|
|
|
import pytest |
|
13
|
|
|
|
|
14
|
|
|
from oemof import solph |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
def test_equate_flows(): |
|
18
|
|
|
date_time_index = pd.date_range("1/1/2012", periods=3, freq="h") |
|
19
|
|
|
energysystem = solph.EnergySystem( |
|
20
|
|
|
timeindex=date_time_index, |
|
21
|
|
|
infer_last_interval=False, |
|
22
|
|
|
) |
|
23
|
|
|
|
|
24
|
|
|
b1 = solph.buses.Bus(label="b1", balanced=False) |
|
25
|
|
|
s0 = solph.components.Sink( |
|
26
|
|
|
label="s1", |
|
27
|
|
|
inputs={ |
|
28
|
|
|
b1: solph.Flow( |
|
29
|
|
|
variable_costs=-0.5, |
|
30
|
|
|
max=[0.5, 1], |
|
31
|
|
|
nominal_capacity=4, |
|
32
|
|
|
custom_attributes={"keyword1": "group 1"}, |
|
33
|
|
|
) |
|
34
|
|
|
}, |
|
35
|
|
|
) |
|
36
|
|
|
s1 = solph.components.Sink( |
|
37
|
|
|
label="s2", |
|
38
|
|
|
inputs={ |
|
39
|
|
|
b1: solph.Flow( |
|
40
|
|
|
variable_costs=0.1, |
|
41
|
|
|
nominal_capacity=2, |
|
42
|
|
|
custom_attributes={"keyword2": "group 2"}, |
|
43
|
|
|
) |
|
44
|
|
|
}, |
|
45
|
|
|
) |
|
46
|
|
|
s2 = solph.components.Sink( |
|
47
|
|
|
label="s3", |
|
48
|
|
|
inputs={ |
|
49
|
|
|
b1: solph.Flow( |
|
50
|
|
|
variable_costs=0.2, |
|
51
|
|
|
nominal_capacity=3, |
|
52
|
|
|
custom_attributes={"keyword2": "group 2"}, |
|
53
|
|
|
) |
|
54
|
|
|
}, |
|
55
|
|
|
) |
|
56
|
|
|
s3 = solph.components.Sink( |
|
57
|
|
|
label="s4", |
|
58
|
|
|
inputs={ |
|
59
|
|
|
b1: solph.Flow( |
|
60
|
|
|
variable_costs=0.2, |
|
61
|
|
|
nominal_capacity=3, |
|
62
|
|
|
custom_attributes={"keyword3": "no group"}, |
|
63
|
|
|
) |
|
64
|
|
|
}, |
|
65
|
|
|
) |
|
66
|
|
|
energysystem.add(b1, s0, s1, s2, s3) |
|
67
|
|
|
|
|
68
|
|
|
model = solph.Model(energysystem) |
|
69
|
|
|
|
|
70
|
|
|
solph.constraints.equate_flows_by_keyword( |
|
71
|
|
|
model, "keyword1", "keyword2", 0.75 |
|
72
|
|
|
) |
|
73
|
|
|
|
|
74
|
|
|
model.solve() |
|
75
|
|
|
|
|
76
|
|
|
results = solph.processing.results(model) |
|
77
|
|
|
|
|
78
|
|
|
flow = [ |
|
79
|
|
|
list(results[(b1, s)]["sequences"]["flow"][:-1]) |
|
80
|
|
|
for s in [s0, s1, s2, s3] |
|
81
|
|
|
] |
|
82
|
|
|
|
|
83
|
|
|
assert flow[0] == pytest.approx([2, 4]) |
|
84
|
|
|
assert flow[1] == pytest.approx([1.5, 2]) |
|
85
|
|
|
assert flow[2] == pytest.approx([0, 1]) |
|
86
|
|
|
assert flow[3] == pytest.approx([0, 0]) |
|
87
|
|
|
|