Storage Constraints

Hi there,

i have difficulties to define constraints for a storage element.
I would like to integrate a constraints acoording to which the storage can be wither charged or discharged at each time step.
I would like to use the following function:
SOC (t) <= storage.capacity (t) * (1-storage.inputs(t).fix)
and
SOC (t) >= storage.capacity (t)*storage.outputs(t).fix)

If someone has anytips, i would be really grateful.

BR
Roberta

This is how i tried it, but it is not working:

datetimeindex = pd.date_range('04/08/2019', periods=8760, freq='60min')

esys = solph.EnergySystem(timeindex=datetimeindex)
esys = fill_energysystem(esys, esysd_filename)

# ***** Defining the Storages of the States *****

Electricity_Storage_State_1: GenericStorage = solph.GenericStorage(
    label="Electricity Storage State 1",
    inputs={esys.entities[4]: solph.Flow(nominal_value=10, variable_costs=0.1)},
    outputs={esys.entities[3]: solph.Flow(nominal_value=10, variable_costs=0.1)},
    loss_rate=0, nominal_storage_capacity=100000, initial_storage_level=0.5, balanced=True,
    inflow_conversion_factor=0.7, outflow_conversion_factor=0.7)

esys.add(Electricity_Storage_State_1)

model = solph.Model(esys)


For t in model.datetimeindex
 model.solph.constraints(
   expr=solph.Flow(Electricity_Storage_State_1, esys.entities[4])[t] <= storage.nominal_value[t] * (1 - Electricity_Storage_State_1.inputs[esys.entities[4]][t].fix),
   label='max_charge_' + str(t)
        )
 model.solph.constraints(
   expr=solph.Flow(Electricity_Storage_State_1, esys.entities[3])[t] >= -Electricity_Storage_State_1.nominal_value[t] * Electricity_Storage_State_1.outputs[esys.entities[3]][t].fix,
   label='max_discharge_' + str(t)
        )

# Add constraint function to the model for each time step
for t in esys.timeindex:
            charge_discharge_constraint(esys, t)```

Hi @Roberta,

I just wanted to start thinking about your question but got distracted by the format. Would you edit code indicators (three of those ` for start end end) into your post and intent the code?

Electricity_Storage_State_1 = solph.GenericStorage(
    label=“Electricity Storage State 1”,
    ...
)
1 Like

Sorry, I still don’t get it.

  1. Your code format seems to be broken, e.g. you call charge_discharge_constraint(esys, t) but you do not define it anywhere.
  2. I assume that you do not mean to fix the flows. (You don’t but you try to access the Flow.fix and say that you want to consider it.) However, if storage.inputs(t).fix and storage.outputs(t).fix are defined for all t, there is nothing to optimise for the storage. (And probably you will have a non-converging model because it’s almost impossible to manually set the flows so that sum(input - output - losses) = 0.)

Maybe, have a look at oemof/solph/constraints/equate_flows.py to have a look how others define constraints.