Integrating custom components into optimization

229 views
Skip to first unread message

Uwe

unread,
Apr 17, 2020, 6:05:49 AM4/17/20
to pypsa
Hi,

as explained some threads ago, I am working with the integration of custom components, in my case a custom electrolyser, into the pypsa-eur model. To avoid any confusion, I am working with the electrolyser only to get a feeling for the pypsa model. Later, I will add very detailed components.

The electrolyser is a commitable demand, therefore, it's capacity and the power consumption should be included in the optimization, e.g. the power balance and investment decisions, and should have an impact on the marginal price of each node, as it changes the demand. Currently, I have done following adjustments in the pypsa model with the focus to only have the power system correct and not (yet) the systems costs:
  • Adjusting the csv file 'variables.csv' regarding the variables of the electrolyser
  • In the descriptors.py script at zsum function: Adding the p_nom of the electrolyser
  • In the linopf.py script at define_nodal_balance_constraint: Adding the commitable electrolyser power
Looking at the results of the optimization, the power balance constraints seems to be satisfied, as generation, demand, storage demand and electrolyser demand equal in a power around 0 each hour (deviations are a few kWh for the complete network, so I guess the rest are transmission losses etc.). Also, the electrolyser only produces hydrogen, when the marginal price is low, so there seems to be an impact here, too.

My question is, if this is enough to implement a custom component fully into the pypsa model similar to the already existing components of the model. Especially the bidding strategy to find the marginal prices is, as described from the pypsa-team some time ago, quite complex.

Best
Uwe

Fabian Hofmann

unread,
Apr 17, 2020, 10:47:39 AM4/17/20
to py...@googlegroups.com

Hey Uwe,


just a small question in advance. Have you thought about representing the electrolyser by a link? I don't have your exact purposes in mind, but in case the electrolyser converts power into hydrogen (with a constant efficiency) this can simply be done by a link which unidirectional converts power into hydrogen and feeds a hydrogen 'Store' in the pypsa network. This would allow you to not have to modify the source code.

However idk if this matches your needs.

Best,

Fabian H

--
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.
To view this discussion on the web, visit https://groups.google.com/d/msgid/pypsa/684ea8f5-9a82-4f35-b2d9-549fad24acfd%40googlegroups.com.

Uwe

unread,
Apr 17, 2020, 1:09:52 PM4/17/20
to pypsa
Hi Fabian,

is it possible to use the link format for other outputs? I know that it is possible to produce hydrogen, but what about hydrocarbons as product and so on. The electrolysis was only an example of a component, which uses electricity to produce something else. Using it as a ind of a training component to get used to the pypsa model. Sure, I don't want to change the whole model code, but it's kind of necessary to understand what's behind.

Best
Uwe

Fabian Neumann

unread,
Apr 18, 2020, 8:38:15 AM4/18/20
to Uwe, pypsa
Hi Uwe,

I have given your questions some thought.

In the long-term, you wouldn't be happy to hardcode changes into your
PyPSA source code (like the ones you outlined). It would make updates
very tedious!

The difficulty you encounter is that custom components are not reflected
in the standard constraints (foremost the nodal balance constraint).
Admittedly, amending constraints used to be easier with pyomo, because
pyomo allowed to add terms to existing constraints. To my knowledge,
this is not supported in the nomopyomo version. Adding terms to the
objective is however rather simple; you can just call write_objective()
again with the additional terms.

Therefore, I would encourage you to use the fundamental PyPSA components
for as much as possible.

Amending component *attributes* (rather than completely new components)
requires much less individual adjustments. This might be attractive for
your cause. I think the vast majority of technologies could be modelled
this way.

Using custom attributes you can for example define links with multiple
inputs and/or outputs (see
https://pypsa.readthedocs.io/en/latest/components.html#link-with-multiple-outputs-or-inputs).
For an example use (methanation), see
https://github.com/PyPSA/pypsa-eur-sec/blob/master/scripts/prepare_sector_network.py#L631-L641.

You can then define custom constraints (using `extra_functionality`) not
for each custom component, but for subsets of the fundamental PyPSA
components (e.g. all links with a certain carrier). For an example see
https://github.com/PyPSA/pypsa-eur-sec/blob/master/scripts/solve_network.py#L122-L155.

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/91f122a7-917f-46c0-b246-b662bb1bd351%40googlegroups.com
> <https://groups.google.com/d/msgid/pypsa/91f122a7-917f-46c0-b246-b662bb1bd351%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
Karlsruhe Institute of Technology (KIT)
Institute for Automation and Applied Informatics (IAI)

Fabian Neumann (he/him)
PhD Student in Energy System Modelling

Phone: +49 721 608 25707 | Mobile: +49 171 2943831 |
Group: www.iai.kit.edu/english/esm.php | Personal: www.neumann.fyi |
Github: @fneum | Twitter: @fneum_

Learn about nearly-optimal power system models:
https://arxiv.org/abs/1910.01891

KIT Campus North, Building 445, Office 304
Hermann-von-Helmholtz-Platz 1
76344 Eggenstein-Leopoldshafen

KIT – The Research University in the Helmholtz Association

Reply all
Reply to author
Forward
0 new messages