# Modelleing a two way transformer with an investment object in oemof

#1

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

#2

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)

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)