Skip to content

Implement pressure loss calculation via pandapipes - #181

Draft
jnettels wants to merge 3 commits into
devfrom
features/pandapipes_pressure_loss
Draft

Implement pressure loss calculation via pandapipes#181
jnettels wants to merge 3 commits into
devfrom
features/pandapipes_pressure_loss

Conversation

@jnettels

@jnettels jnettels commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

I have added a new argument calculation to delta_p() and the functions which call it (v_max_secant(), v_max_bisection()) which allows using a pandapipes simulation to calculate pressure losses in a pipe as an alternative to the existing internal implementation.

  • Update code
  • Add new test
  • Update changelog
  • Update documentation

Fixes #162

Context

dhnx includes the precalc_hydraulic module which allows converting the resulting capacity of each pipe into norm diameters.
For this, a pressure loss calculation is needed, for which precalc_hydraulic provides an internal solution.

In my workflows, I design a network with dhnx and then run a simulation of temperature and pressure distribution with pandapipes to check if the network is valid in terms of pressure drops and velocities. In some rare edge cases I noticed differences where dhnx was supposed to only give e.g. a maximum of 100 Pa/m pressure losses in any given pipe segment but pandapipes showed slightly larger values.

Implementing a new function delta_p_pandapipes() in precalc_hydraulic solved the issue because it synchronizes the precalculation and post-processing. It allows calculating the pressure loss with pandapipes instead of using the internal implementation.

Independently, in #162 another user describes issues with the internal implementation. Instead of trying to fix/improve the internal pressure loss equations I think it is the best approach to use external modules that have already put more resources into this problem. (Nevertheless: pandapipes itself offers different friction models, and judging by the issues there, not all of them are perfect, either.)

Considerations / feedback

  • My approach gives room to add other calculation methods in the future, which may coexist. I hope that is useful
  • Running pandapipes is significantly slower than the internal method. But in the context of a long optimization procedure that is fine
  • precalc_hydraulic is briefly mentioned in the documentation, but not actually documented. Thus there was no documentation to update
  • I have added matching tests
  • In order for the new test to work, I have added pandapipes to the deps in testenv in tox.ini. But I am unsure if this is the best way and I need feedback. I guess I could create a new entry of optional dependencies in pyproject.toml instead, but that feels like overkill to me. If a user knows they want to use pandapipes alongside dhnx, they can just install it.
  • pandapipes requires pandapower, which is currently still restricted to pandas<3.0. Thus with this change all of our tests here will run with pandas 2.x, which is not ideal, I think. But I see no way around that. Thoughts?

As an alternative to the existing internal
pressure loss calculation, the pandapipes module
can be used to calculate the pressure loss
in a pipe
@jnettels jnettels self-assigned this Aug 12, 2026
@github-actions

Copy link
Copy Markdown

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  src/dhnx/optimization
  precalc_hydraulic.py
Project Total  

This report was generated by python-coverage-comment-action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Used friction factor formula provides wrong values

1 participant