Modelleing a two way transformer with an investment object in oemof

Hi everyone,

my task is to model a transformator between a medium and a low voltage grid with energy flows in two directions symbolising the two cases:

  • Feeding energy from the low voltage grid into the medium voltage grid in case of high renewable generation and

  • consume energy from the medium voltage grid in case of to less renewable generation to satisfy the load at the low voltage side.

The approach was to use two linear transformers with different flow directions connecting the two grids. The objective function of the Investment-Flow-Method uses the invest (equivalent to the nominal value of the flows after optimization) to calculate the total investment costs. As I have two connections between the grids to simulate the energy flow in two directions I have two invests with different values dependent on the energy flows on that connection. This is the problem. What I want to have is the maximum of the two invests.

So I want to write a Constraint which takes the maximum invest of both flow directions to calculate the total investment costs.
For this, does anyone got an idea? Or got an idea how to get access to the invest variable respectively how to index decent energy flows?

Hope you all got the problem and looking forward for some advice.

Cheers, Bastian

You can add a constraint to equalizing both investment variables. Below is a working but trivial example. You have to add your own components.

The best way is to create a very simple example (e.g. pv, wind, demand connected to bel1 and an excess Sink and a shortage Source connected to bel2). Afterwards you can test it with and without the additional constraint.

from oemof import solph
from pyomo import environ
import pandas

# Basic example
date_time_index = pandas.date_range('1/1/2012', periods=100, freq='H')
energysystem = solph.EnergySystem(timeindex=date_time_index)

bel1 = solph.Bus(label="electricity1")
bel2 = solph.Bus(label="electricity2")

line12 = solph.LinearTransformer(
    label="line12",
    inputs={bel1: solph.Flow()},
    outputs={bel2: solph.Flow(investment=solph.Investment(ep_costs=20))},
    conversion_factors={bel2: 1})

line21 = solph.LinearTransformer(
    label="line21",
    inputs={bel2: solph.Flow()},
    outputs={bel1: solph.Flow(investment=solph.Investment(ep_costs=20))},
    conversion_factors={bel1: 1})

om = solph.OperationalModel(energysystem)

# Adding your own constraint:
my_block = environ.Block()

def connect_invest_rule(m):
    expr = (om.InvestmentFlow.invest[line12, bel2] ==
            om.InvestmentFlow.invest[line21, bel1])
    return expr

my_block.invest_connect_constr = environ.Constraint(
    rule=connect_invest_rule)
om.add_component('ConnectInvest', my_block)

om.solve(solver='cbc')
print('ok')

This was the exact solution, thank you very much

Hello everyone,
first of all I wanted to build an energy system like this:

Lignite source >> Lignite bus            >> Lignite powerplant >> Electricity bus   >> El_Demand
solar source   >> solar bus              >> PV powerplant      >> power bus         >> El_Demand
Gas source     >> [Gas bus, methane bus] >> Gas powerplant     >> Electricity bus   >> El_Demand
                                            Gas powerplant     >> Heat bus          >> Th_demand
                  Electricity bus        >> Methane powerplant >> methane bus 

But it seems that there is no way for oemof to solve this problem. Or to decide which input is the cheaper one.

My idea was to split the gas power plant. In one with a gas input and one with a methane input. But both must have the same investment. So I wanted to add a constraint.
I ended up here in this thread with a similar problem.

But it seems that the solution doesn’t work anymore with the latest oemof version.
I tried
om.InvestmentFlow.investment_costs.expr()
from
https://oemof-solph.readthedocs.io/en/latest/reference/oemof.solph.html?highlight=investmentflow#oemof.solph.blocks.investment_flow.InvestmentFlow

But I don’t understand the command correctly.
I have tried this in different versions:
om.InvestmentFlow.investment_costs.expr(invest[i, o])
The output is always the total investment of all transformers, no matter what the input is.

Do you have a solution?
Greetings
Philipp

Could you explain this statement.

Can you build the LP-file?
Does the LP-file looks as expected?
Does the solver ends with infeasible?
Are you unhappy with the results?

I guess the power bus in line two should be Electricity bus. Beside that everything looks fine to me.

BTW: It is better to open a new topic for a new question, because this question is already marked as solved.

1 Like