Passed
Pull Request — dev (#1221)
by Patrik
01:43
created

test_status   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 38
dl 0
loc 83
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A test_non_convex_status_variables() 0 60 1
1
"""
2
This integration test validates that the Results object properly merges
3
status variables from NonConvexFlowBlock and InvestNonConvexFlowBlock
4
into one DataFrame.
5
6
The test scenario is using the following components:
7
* Gas boiler with insufficient minimal part load to supply heat in time step 2.
8
* Electrical heater without constraint but high operational costs.
9
* Heat pump (with extremely low investment costs) but a rather low power limit.
10
  It can only supply part of the heat. As the electrical heater is always
11
  needed as a complement, it is only run if the boiler cannot.
12
13
SPDX-FileCopyrightText: Patrik Schönfeldt
14
15
SPDX-License-Identifier: MIT
16
"""
17
18
import pandas as pd
19
20
from oemof import solph
21
22
23
def test_non_convex_status_variables():
24
    # Energy System
25
    energy_system = solph.EnergySystem(
26
        timeindex=pd.date_range(start="2025-01-01 12:00", freq="h", periods=3),
27
        infer_last_interval=False,
28
    )
29
30
    # Buses
31
    bus_heat = solph.Bus("heat")
32
33
    energy_system.add(bus_heat)
34
35
    demand_heat = solph.components.Sink(
36
        label="demand",
37
        inputs={bus_heat: solph.Flow(nominal_capacity=5, fix=[0.5, 0.3])},
38
    )
39
    energy_system.add(demand_heat)
40
41
    # gas boiler with minimal load
42
    boiler = solph.components.Source(
43
        label="gb",
44
        outputs={bus_heat: solph.Flow(
45
                nonconvex=solph.NonConvex(),
46
                nominal_capacity=5, min=0.5,
47
                variable_costs=0.15,
48
            ),
49
        },
50
    )
51
    energy_system.add(boiler)
52
53
    # heat pump with limited size
54
    heat_pump = solph.components.Source(
55
        label="hp",
56
        outputs={
57
            bus_heat: solph.Flow(
58
                nominal_capacity=solph.Investment(maximum=1, ep_costs=0.1),
59
                min=0.5,
60
                nonconvex=solph.NonConvex(),
61
                variable_costs=0.1,
62
            )
63
        },
64
    )
65
    energy_system.add(heat_pump)
66
67
    el_heater = solph.components.Source(
68
        label="rh",
69
        outputs={bus_heat: solph.Flow(variable_costs=0.3)},
70
    )
71
    energy_system.add(el_heater)
72
73
    # Model
74
    model = solph.Model(energy_system)
75
76
    # Optimization
77
    model.solve(solver="cbc", solve_kwargs={"tee": False})
78
79
    results = solph.Results(model)
80
81
    assert (results.status[(boiler, bus_heat)] == [1, 0]).all()
82
    assert (results.status[(heat_pump, bus_heat)] == [0, 1]).all()
83