oemof / oemof-solph

A model generator for energy system modelling and optimisation (LP/MILP).
https://oemof.org
MIT License
282 stars 124 forks source link

GenericCHP component example is broken #1050

Open fwitte opened 4 months ago

fwitte commented 4 months ago

Describe the bug The example

To Reproduce

from oemof import solph

date_time_index = solph.create_time_index(2012, number=3)
energysystem = solph.EnergySystem(
    timeindex=date_time_index, infer_last_interval=False
)

gas_bus = solph.Bus(label="gas")
heat_demand_bus = solph.Bus(label="heat demand")
electricity_bus = solph.Bus(label="electricity")

gas_source = solph.components.Source(
    label="gas source", outputs={gas_bus: solph.Flow(variable_costs=75)}
)
heat_sink = solph.components.Sink(
    label="heat sink",
    inputs={heat_demand_bus: solph.Flow(fix=[10, 11, 12], nominal_value=1)}
)
electricity_sink = solph.components.Sink(
    label="electricity sink", inputs={electricity_bus: solph.Flow(variable_costs=-100)}
)

ccet = solph.components.GenericCHP(
    label='combined_cycle_extraction_turbine',
    fuel_input={gas_bus: solph.flows.Flow(
        custom_attributes={"H_L_FG_share_max": [0.183]})},
    electrical_output={electricity_bus: solph.flows.Flow(
        custom_attributes={
            "P_max_woDH": [15.5946],
            "P_min_woDH": [6.8787],
            "Eta_el_max_woDH": [0.525],
            "Eta_el_min_woDH": [0.444],
        })},
    heat_output={heat_demand_bus: solph.flows.Flow(
        custom_attributes={"Q_CW_min": [1.0552]})},
    beta=[0.122], back_pressure=False
)

energysystem.add(
    gas_bus, gas_source, heat_demand_bus, heat_sink,
    ccet,
    electricity_bus, electricity_sink#, electricity_source
)

om = solph.Model(energysystem)

om.solve(solver="cbc", solve_kwargs={"tee": False})

Expected behavior Model solves

Screenshots

ERROR:pyomo.core:Rule failed when generating expression for Constraint GenericCHPBlock.H_F_1 with index ("<oemof.solph.components._generic_chp.GenericCHP: 'combined_cycle_extraction_turbine'>", 1):
IndexError: list index out of range
ERROR:pyomo.core:Constructing component 'GenericCHPBlock.H_F_1' from data=None failed:
IndexError: list index out of range

Desktop (please complete the following information):

p-snft commented 4 months ago

Interesting. Your code has the issue that you give lists that are too short ([15.5946]). However, changing that (to 3*[15.5946]) does not solve the issue.

At the same time, there is a test, test_gen_chp, that runs without issues. Probably, the parameters lead to an infeasible problem.

fwitte commented 4 months ago

The snippet is actually based on the the API docs example here https://oemof-solph.readthedocs.io/en/stable/reference/oemof.solph.components.html#module-oemof.solph.components._generic_chp. Interestingly, in that docstring example only the creation of the component is tested, not adding it to a energysystem and solving that.

Agree on the solving issue, I should have added a slack heat generator.