Hi Jakob,
with some help of Uwe I could solve the problem of the different component investment sizes. Some additional constraints connecting the invest variables of the trafos were necessary. I’ll post the adapted code below. I hope this works…
Best regards!
import pandas as pd
from oemof import solph
import oemof.outputlib as outputlib
import pyomo.environ as po
date_time_index = pd.date_range('1/1/2012', periods=50, freq='H')
energysystem = solph.EnergySystem(timeindex=date_time_index)
b_gas = solph.Bus(label='gas')
b_el = solph.Bus(label='electricity')
# Auxiliary electricity bus to realize the additional constraint
b_aux_el = solph.Bus(label='aux_el')
b_heat = solph.Bus(label='heat')
energysystem.add(b_gas, b_el, b_heat, b_aux_el)
energysystem.add(solph.Source(label='gassupply',
outputs={b_gas: solph.Flow(variable_costs=1)}))
energysystem.add(solph.Sink(label='grid',
inputs={b_el: solph.Flow(variable_costs=-2)}))
energysystem.add(solph.Sink(label='DH',
inputs={b_heat: solph.Flow(variable_costs=-1,
nominal_value=5,
actual_value=1,
fixed=True)}))
energysystem.add(solph.Transformer(
label='CHP',
inputs={b_gas: solph.Flow()},
outputs={
b_heat: solph.Flow(),
b_aux_el: solph.Flow(variable_costs=-1,
investment=solph.Investment(ep_costs=10))},# maximum=3.75))},
conversion_factors={b_aux_el: 0.3, b_heat: 0.4}))
# Full load hours (flh): determines the amount of electricity with high_revenue
flh = 10
# KWK-Vergütung (additional revenue for electricity from CHP)
addition_chp_revenue = -5
energysystem.add(solph.Transformer(
label='aux_trafo_01',
inputs={b_aux_el: solph.Flow()},
outputs={b_el: solph.Flow(investment=solph.Investment(ep_costs=0))},
variable_costs=0,
conversion_factor=1
))
# Auxiliary component that provides additional income for electricity from
# the CHP for a certain amount of electricity (german:"KWK-Vergütung").
# The 'summed_max' attribute of this component will be used in the
# additional constraint.
energysystem.add(solph.Transformer(
label='aux_trafo_02',
inputs={b_aux_el: solph.Flow()},
outputs={b_el: solph.Flow(investment=solph.Investment(ep_costs=0))},
variable_costs=addition_chp_revenue,
conversion_factor=1
))
om = solph.Model(energysystem)
chp = energysystem.groups['CHP']
low_revenue_trafo = energysystem.groups['aux_trafo_01']
high_revenue_trafo = energysystem.groups['aux_trafo_02']
# grid = energysystem.groups['grid']
# Add an additional constraint that limits the amount of electricity that can
# go through aux_trafo_02
myconstrains = po.Block()
om.add_component('MyBlock', myconstrains)
myconstrains.solar_constr = po.Constraint(
expr=((sum(om.flow[high_revenue_trafo, b_el, t] for t in om.TIMESTEPS))
<= flh*om.InvestmentFlow.invest[chp, b_aux_el]))
# Add additional constraints to connect investment variables
# of CHP, aux_trafo_01 and aux_trafo_02
solph.constraints.equate_variables(
om,
om.InvestmentFlow.invest[chp, b_aux_el],
om.InvestmentFlow.invest[high_revenue_trafo, b_el])
solph.constraints.equate_variables(
om,
om.InvestmentFlow.invest[low_revenue_trafo, b_el],
om.InvestmentFlow.invest[high_revenue_trafo, b_el]),
solph.constraints.equate_variables(
om,
om.InvestmentFlow.invest[chp, b_aux_el],
om.InvestmentFlow.invest[low_revenue_trafo, b_el])
om.solve(solver='cbc', solve_kwargs={'tee': True})
energysystem.results['main'] = outputlib.processing.results(om)
energysystem.results['meta'] = outputlib.processing.meta_results(om)
results = energysystem.results['main']
nominal_invest_CHP = (outputlib.views.node(results, 'CHP')[
'scalars'][(('CHP', 'aux_el'), 'invest')])
electricity_bus = outputlib.views.node(results, 'electricity')
aux_bus = outputlib.views.node(results, 'aux_el')
heat_bus = outputlib.views.node(results, 'heat')
CHP = outputlib.views.node(results, 'CHP')
print('********* Main results *********')
print('seq_sum electricity_bus\n', electricity_bus['sequences'].sum(axis=0))
print('seq_max electricity_bus\n', electricity_bus['sequences'].max())
print('seq_sum aux_bus\n', aux_bus['sequences'].sum(axis=0))
print('seq_max aux_bus\n', aux_bus['sequences'].max())
print('seq_sum heat_bus\n', heat_bus['sequences'].sum(axis=0))
print("")
print("Capacity (electr.) of CHP (nominal_value):", nominal_invest_CHP)
print("Total amount of full load hours:",
aux_bus['sequences'].sum(axis=0)/nominal_invest_CHP, "h")
print("Amount of full load hours with higher revenue: ", flh, "h")