|
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 pytest |
|
12
|
|
|
|
|
13
|
|
|
from oemof import solph |
|
14
|
|
|
|
|
15
|
|
|
from . import _run_flow_model |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
def test_gradient_limit(): |
|
19
|
|
|
price_pattern = [8] + 8 * [-1] + [8] |
|
20
|
|
|
|
|
21
|
|
|
flow = solph.flows.Flow( |
|
22
|
|
|
nominal_capacity=2, |
|
23
|
|
|
variable_costs=price_pattern, |
|
24
|
|
|
positive_gradient_limit=0.4, |
|
25
|
|
|
negative_gradient_limit=0.25, |
|
26
|
|
|
) |
|
27
|
|
|
flow_result = list(_run_flow_model(flow)["flow"][:-1]) |
|
28
|
|
|
|
|
29
|
|
|
assert flow_result == pytest.approx( |
|
30
|
|
|
[0, 0.8, 1.6, 2.0, 2.0, 2.0, 1.5, 1.0, 0.5, 0] |
|
31
|
|
|
) |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
def test_full_load_time_max(): |
|
35
|
|
|
price_pattern = [-i for i in range(10)] |
|
36
|
|
|
|
|
37
|
|
|
flow = solph.flows.Flow( |
|
38
|
|
|
nominal_capacity=2, |
|
39
|
|
|
variable_costs=price_pattern, |
|
40
|
|
|
full_load_time_max=4.5, |
|
41
|
|
|
) |
|
42
|
|
|
flow_result = list(_run_flow_model(flow)["flow"][:-1]) |
|
43
|
|
|
|
|
44
|
|
|
assert flow_result == pytest.approx(5 * [0] + [1] + 4 * [2]) |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
def test_full_load_time_min(): |
|
48
|
|
|
price_pattern = [i for i in range(10)] |
|
49
|
|
|
|
|
50
|
|
|
flow = solph.flows.Flow( |
|
51
|
|
|
nominal_capacity=2, |
|
52
|
|
|
variable_costs=price_pattern, |
|
53
|
|
|
full_load_time_min=4.5, |
|
54
|
|
|
) |
|
55
|
|
|
flow_result = list(_run_flow_model(flow)["flow"][:-1]) |
|
56
|
|
|
|
|
57
|
|
|
assert flow_result == pytest.approx(4 * [2] + [1] + 5 * [0]) |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
# --- BEGIN: The following code can be removed for versions >= v0.7 --- |
|
61
|
|
|
def test_nominal_capacity_warning(): |
|
62
|
|
|
with pytest.warns(FutureWarning, match="nominal_value"): |
|
63
|
|
|
_ = solph.flows.Flow(nominal_value=2) |
|
64
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
def test_nominal_capacity_error(): |
|
67
|
|
|
with pytest.raises(AttributeError, match="nominal_capacity"): |
|
68
|
|
|
_ = solph.flows.Flow(nominal_value=2, nominal_capacity=1) |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
def test_minimum_error(): |
|
72
|
|
|
with pytest.raises(AttributeError, match="minimum"): |
|
73
|
|
|
_ = solph.flows.Flow(min=0.5, minimum=0.5) |
|
74
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
def test_minimum_warning(): |
|
77
|
|
|
with pytest.warns(FutureWarning, match="min"): |
|
78
|
|
|
_ = solph.flows.Flow(min=2, nominal_capacity=5) |
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
def test_maximum_warning(): |
|
82
|
|
|
with pytest.warns(FutureWarning, match="max"): |
|
83
|
|
|
_ = solph.flows.Flow(max=2, nominal_capacity=5) |
|
84
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
def test_maximum_error(): |
|
87
|
|
|
with pytest.raises(AttributeError, match="maximum"): |
|
88
|
|
|
_ = solph.flows.Flow(max=0.5, maximum=0.5) |
|
89
|
|
|
# --- END --- |
|
90
|
|
|
|