Hydrogen storage charge and discharge

Hello people,
I am building a system for green hydrogen production, i want my hydrogen storage to be the only provider for the fuel cell to function .Right now what is happening is that fuel cell takes hydrogen from the electrolyser even when there is enough hydrogen stored in the storage .I also want the charging and discharging to not happen at the same time but i am not so sure if its possible on oemof. My objects looks somehow like this:

Create excess sink

excess = solph.components.Sink(
    label="excess_electricity",
    inputs={bel_dc: solph.Flow()}
)

# Create PV source
pv = solph.components.Source(
    label="pv",
    outputs={
        bel_dc: solph.Flow(
            fix=pv_data,
            nominal_value=1,                  ) }  )

Create grid source

grid = solph.components.Source(
    label="grid",
    outputs={bel_dc: solph.Flow(variable_costs=price_data,
                            nominal_value=solph.Investment(ep_costs=epc_grid))}
)

electrolyser = solph.components.Converter(
    label="electrolyser",
    
    inputs={bel_dc: solph.Flow(nominal_value=160,)},
    outputs={b_h_el: solph.Flow(nominal_value=4)},
    conversion_factors={b_h_el: 0.9 / (40)}
)
h2_storage = solph.components.GenericStorage(
label='storage',
inputs={b_h_el: solph.Flow(
    variable_costs=10,
    nominal_value=4, 
)},
outputs={b_h_st: solph.Flow(
    nominal_value=83,  
    variable_costs=0.01, 
)},
loss_rate=0.00,
initial_storage_level=0.05,balanced=True,
nominal_storage_capacity=90, 

)
fc = solph.components.Converter(
label=“fuel_cell”,

    inputs={b_h_st: solph.Flow(
        nominal_value=83,
        
    )},
    outputs={b_demand: solph.Flow(nominal_value=1375)},
    conversion_factors={b_demand:(33.38*0.54)}
)   

demand =solph.components.Sink(
    label="demand",
    inputs={b_demand:solph.flows.Flow(fix=demand_data,nominal_value=1)}

)



# Add components to energy system
energysystem.add(excess, pv,fc, bel_dc,electrolyser,b_h_st,b_h_el,grid,h2_storage,demand,b_demand)

As i am relatively very new to oemof and energy modelling in general , I think i might ask very childish questions but at the moment any help would be highly appreciatied

Hi @vishal,

Thanks for reaching out. As our introductory material is not in the best shape at the moment, I very mush appreciate beginners’ questions. In particular the one about storage charging and discharging at the same time is rather common. (It will be covered in the new introduction we are currently working on.)

Your code style looks pretty clean but the formatting seems to have broken while copying to this board. I hope this does not distract me from a relevant detail. Having said that: The program will find an (almost) optimal solution. So, when there is no good reason why to avoid something, it is a perfectly valid solution if that something is done.

Just suppressing simultaneous charging and discharging is possible, however, it is computationally expensive and typically just a sign that something could be modeled more carefully. In your case, you might want to either add an inflow_conversion_factor (or outflow_conversion_factor) or some variable_costs to a Flow connecting it, so that looping through the storage isn’t free anymore.

Hey @pschoen
Thank you for being patient and replying to my query,
The thing is , I have tried adding the parameters you suggested , even tried increasing and decreasing the variable costs for the flow but i still have a system where charge and discharge happens together at certain timestamps. I also get error of infeasibility when i decrease the inflow_conversion_factor by a certain amount and i think its probably because my numerical values for the rest of the system is pretty restricted. My current requirement is to have a hydrogen storage which can be filled up in 24 hours but the discharge should happen in 1 hour, that is why i kept the numerical values so restricted , i am not so sure if this would be possible to design since i also want alternate discharge and charge.
Again , Thanks a lot for your input

I see.

And sorry that I did not see the variable costs in the storage at first. Now I do see that you had them in the code snipped you shared initially. Also, I did not see that your storage is passing through energy and not looping from/to a bus, which is what people typically do. If your storage is needed to pass through energy (no bypass), conversion factors and costs don’t help. Maybe, you fix the code boxes (merge 2nd and 3rd) in your initial post.

I also guess the infeasibility is because the system is set up too tightly. Can you maybe provide a rendering of the energy system graph? You can use either dash or the pre-release version of oemof.visio.

Hello @vishal,

Not at all specific oemof, but more on the theoretical aspect, here is my article on the battery loss (but when a energy reservoir model is used, then H2 storage is just the same). In particular, Fig. 2 illustrates the nonconvexity of trying to forbid simultaneous charge and discharge. And that nonconvexity generaly implies using binary variables in MILP formulations. This is the mathematical reason which supports @pschoen remarks with which I agree (“Just suppressing simultaneous charging and discharging is possible, however, it is computationally expensive”).

Also, the article Introduction gives references about what I called the “positive price argument” where at the optimum there is no simultaneous charge and discharge. Are you in a case of grid congestion where it may be the case that at some node the marginal price of electricity is negative?