Modelling system with Grid connection in oemof.solph

Hi all,

I am trying to build an energy system include PV panels + battery and grid connection. Can I as which node should be for grid connection, to make sure only buy from or sell to grid at the same time.

I add grid as source & sink simultaneously, obviously, they had data at the same time.
Screenshot 2023-04-20 103837

# ===================================
# add grid connection
# ===================================
elec_buy = cmp.Source(
    outputs={bel: flows.Flow(variable_costs = 0.3)}) #elec price [0.3 EURO/kWh]


elec_sales = cmp.Sink(
    inputs={bel: flows.Flow(variable_costs = -0.1)})


Hi @guangxuan,

The way to model exclusive flows is by adding an additional constraint (oemof.solph.constraints ā€” oemof.solph 0.5.0 documentation). However, this will typically come with a significant slowdown in the optimisation. In you case, if you cannot make revenue by feeding in electricity you got from the grid, the constraint should not change the result. Thus, Iā€™d rather not implement it.


Hi Patrik @pschoen,
Thanks for the quick response, I really agree with you said that it will slow down the optimisation. Unfortunately in our case we have to consider revenue from sell to grid. What I did before is using SOS1 constraint to control.

## Special ordered set(SOS) for buy&sell status
for n in periods:

    SOSConstraint(var = [model.P_grid_sell[n], model.P_grid_buy[n]], sos = 1 )

My question is:

  • In oemof how can I get the variables name?
    • for example in case , if I define elec_buy as Source and elec_sale as Sink, how can I get variables that can add a SOS constraint?
  • Any other idea to add only-one constraint, like how to control inflow or outflow in storage component?

Best Regards,

We have a short handle to have binary either/or: oemof.solph.constraints ā€” oemof.solph 0.5.0 documentation

However, in your code example the costs for buying are higher than the revenue for selling. The constraint should not be necessary in that case.