Skip to content

Implement own visualization module with Sankey and waterfall#35

Open
fwitte wants to merge 11 commits into
mainfrom
feature/#25-sankey
Open

Implement own visualization module with Sankey and waterfall#35
fwitte wants to merge 11 commits into
mainfrom
feature/#25-sankey

Conversation

@fwitte

@fwitte fwitte commented Jun 26, 2026

Copy link
Copy Markdown
Member

This PR

  • moves waterfall to own module
  • allows passing color dictionary to waterfall to have custom bar coloring
  • implements a plotly variant of the waterfall
  • brings back a draft for the Sankey similar to the one (likely better) originally available from tespy
    • the Sankey (optionally) separates the different types of exergy (thermal, mechanical, chemical) per flow between two components
    • you can group multiple components to an aggregate
    • you can skip passthrough components that do have identical inlet and outlet side
    • you can pass colors to have different styles for nodes (via node label), links are automatically colored by type of fluid or exergy (this could/should be customizable)
    • export to html

I created this with the help of Claude and need to do some thorough testing, I think a meeting to discuss it would be nice @sertomas.

@fwitte

fwitte commented Jun 26, 2026

Copy link
Copy Markdown
Member Author

For testing:

  • test if number of nodes and links is as expected for given example applications
  • test if E_F, E_P and E_L get helper nodes in case there are both inputs and outputs
  • test what happens with negative exergy flow
  • futher tests?

@jfreissmann

Copy link
Copy Markdown

I would appreciate if this PR would come to fruition, as it would be nice to not lose the sankey diagram with the TESPy version bump and accompanied change to exerpy for heatpumps. Let me know if you need any help.

@sertomas

Copy link
Copy Markdown
Member

Pushed some fixes on top: removed Mixer from the no-destruction set (mixers do destroy exergy — the ccpp deaerator's 2.7 MW was missing and the Sankey didn't balance), rewrote plot_exergy_waterfall_plotly with go.Bar(go.Waterfall has no marker property, so it crashed on every call), and applied black (fixes the failing check job). Also added a runnable usage example in examples/visualization/. Still open from my side: unit tests for the builder and whether plotly/matplotlib should be hard deps or a [viz] extra.

@fwitte

fwitte commented Jul 17, 2026

Copy link
Copy Markdown
Member Author

mixers do destroy exergy — the ccpp deaerator's 2.7 MW was missing and the Sankey didn't balance

Maybe that is what caused #36?

plotly/matplotlib should be hard deps or a [viz] extra

I would put them as optional, but I'd leave final decision up to you

unit tests for the builder

I think we should make some more testing with graphs for other systems. Especially heat pumps are interesting, when exergy flow is negative on some edges and see how that looks like. For unit tests I would suggest following situations:

  • cycle with pure fluids only and very simple with single input for fuel, single output for product
  • cycle with mixture
  • activate and deactivate physical exergy splitting
  • cycle with mixture/combustion and check split of phyiscal and chemical exergy
  • cycles with inputs and outputs for fuel and separately same for product (and does it make sense for loss?)
  • cycles where exergy flow is negative on some connections
  • any others?

@sertomas

Copy link
Copy Markdown
Member

@fwitte Regarding your points:

#36: Not caused by the Mixer issue. That bug only dropped the deaerator's E_D link in the diagram, the analysis totals were always correct. I could reproduce #36 exactly: in your CGAM snippet, stream 1 is missing from E_F and stream 8 from the E_P outputs. Their exergies (E_1 = -39.3 kW, E_8 = +61.6 kW) account precisely for the 22292.19 W discrepancy. With the full definitions the balance closes to 0.00 W.

Dependencies: moved to an optional [viz] extra as you suggested (pip install exerpy[viz]).

Tests: implemented your list as synthetic-cycle unit tests: pure-fluid closed cycle, mixtures, splitting on/off, E_PH/E_CH and E_T/E_M/E_CH splits, fuel/product with inputs and outputs, and negative flows.

On "does it make sense for loss?": yes, the ccpp cooling water does exactly that (fresh water in, warm water out), covered too. Negative links are currently dropped silently.

I'll think of this last thing next week. Then I would close this PR. I hope it is fine @jfreissmann

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.

3 participants