Disabling spillage variable for storage units

56 views
Skip to first unread message

Georgios Mavromatidis

unread,
Oct 4, 2022, 7:19:04 AM10/4/22
to pypsa
Dear PyPSA community,

We are working with a model based on PyPSA-Eur data and for some analysis we are performing, we are interested in disabling the possibility of spillage from hydro plants.

Is there an easy option for us to do that without needing to fully remove it from the model's formulation? Something like "fixing" it to 0 for all time steps?

Any pointers? Thanks!

P.S. I am aware that this might lead to feasibility issues in case the storage fills up and there is inflow but no demand to use the stored energy, but we can deal with that :)

Fabian Neumann

unread,
Oct 4, 2022, 2:47:19 PM10/4/22
to py...@googlegroups.com
Hi Georgios,

I don't think there's an option for disabling spillage when defining
storage unit components.

I think the easiest would be to write an extra_functionality where the
spillage variables are forced to 0.

Best wishes,

Fabian N
> --
> You received this message because you are subscribed to the Google
> Groups "pypsa" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to pypsa+un...@googlegroups.com
> <mailto:pypsa+un...@googlegroups.com>.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/pypsa/29e60fb1-6324-4e62-928c-4040d6d5e78an%40googlegroups.com
> <https://groups.google.com/d/msgid/pypsa/29e60fb1-6324-4e62-928c-4040d6d5e78an%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
Dr.-Ing.
Fabian Neumann (he/him)
Postdoctoral Researcher

Department of Digital Transformation in Energy Systems
Institute of Energy Technology
Technische Universität Berlin

Group website: https://tub-ensys.github.io
Personal website: https://neumann.fyi
Schedule Meeting: https://calendly.com/fneum

Einsteinufer 25 (TA 8)
10587 Berlin

My working hours may not be your working hours. Do not feel pressure to
reply to this email outside your working hours.

Georgios Mavromatidis

unread,
Oct 5, 2022, 4:10:12 AM10/5/22
to pypsa
Thank you, Fabian.

That sounds like a good approach - will try it then and write the approach here to anyone needing it for future reference.

Best,
Georgios

Tom Brown

unread,
Oct 5, 2022, 4:23:28 AM10/5/22
to py...@googlegroups.com
Hi Georgios,

Alternatively you could build the hydro with stores, generators and
links instead, then exclude the spillage. For this you could use this
code, which automatically builds storage units from lower components:

https://github.com/PyPSA/PyPSA/blob/master/examples/sector-coupling/replace-generator-storage-units-with-store.py

Best wishes,

Tom
> <https://groups.google.com/d/msgid/pypsa/29e60fb1-6324-4e62-928c-4040d6d5e78an%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/pypsa/29e60fb1-6324-4e62-928c-4040d6d5e78an%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
>
> --
> Dr.-Ing.
> Fabian Neumann (he/him)
> Postdoctoral Researcher
>
> Department of Digital Transformation in Energy Systems
> Institute of Energy Technology
> Technische Universität Berlin
>
> Group website: https://tub-ensys.github.io
> <https://tub-ensys.github.io>
> Personal website: https://neumann.fyi <https://neumann.fyi>
> Schedule Meeting: https://calendly.com/fneum
> <https://calendly.com/fneum>
>
> Einsteinufer 25 (TA 8)
> 10587 Berlin
>
> My working hours may not be your working hours. Do not feel pressure to
> reply to this email outside your working hours.
>
> --
> You received this message because you are subscribed to the Google
> Groups "pypsa" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to pypsa+un...@googlegroups.com
> <mailto:pypsa+un...@googlegroups.com>.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/pypsa/a5dab515-eae6-47b2-bb5d-cc5734938d19n%40googlegroups.com
> <https://groups.google.com/d/msgid/pypsa/a5dab515-eae6-47b2-bb5d-cc5734938d19n%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
Tom Brown (he/him)
Professor of Digital Transformation in Energy Systems
Institute of Energy Technology
Technische Universität Berlin

Group website: https://tub-ensys.github.io/
Personal website: https://nworbmot.org/

Visitor Address:

Georgios Mavromatidis

unread,
Oct 5, 2022, 4:55:02 AM10/5/22
to pypsa
Thank you, Tom. That is indeed useful.

In the meantime, I was able to have the results that I want with the "extra_functionality" approach, as follows:

def extra_functionality(n, snapshots):
    vars_soc = get_var(n, "StorageUnit", "spill")    
    lhs = linexpr((1, vars_soc))    
    define_constraints(n, lhs, "=", 0, "StorageUnit", "spill_zero")

network.lopf(solver_name="gurobi",pyomo=False, extra_functionality=extra_functionality)

Thank you both for your help!

Franco Ferrucci

unread,
Jun 22, 2024, 11:53:05 PMJun 22
to pypsa
Hi there,
With the new linopy interface, you could do this:

m = n.optimize.create_model()
hydro_spill = m.variables['StorageUnit-spill']
hydro_spill_total = hydro_spill.sum()
constraint_expression = hydro_spill_total == 0
m.add_constraints(constraint_expression, name="StorageUnit-no_spill")
result_status = n.optimize.solve_model()

(in this case, all StorageUnits are hydro power)

Franco Ferrucci

unread,
Jun 23, 2024, 12:13:14 AMJun 23
to pypsa
Hi again,

Sometimes it is too restrictive to force spillage to zero. Instead, you could add a cost to the spilled power by changing the objective function:

m = n.optimize.create_model()
hydro_spill = m.variables['StorageUnit-spill']
# Modify objective function:
m.objective = m.objective + hydro_spill * 0.01


In this case, 0.01 is the marginal cost of spilled power.

Cheers,
Franco
Reply all
Reply to author
Forward
0 new messages