Skip to content

Add VTK plotting for unstructured meshes - #5689

Open
aabills wants to merge 19 commits into
mainfrom
ufv-3-plotting
Open

Add VTK plotting for unstructured meshes#5689
aabills wants to merge 19 commits into
mainfrom
ufv-3-plotting

Conversation

@aabills

@aabills aabills commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Stack

  1. Generalise VectorField to N components #5686 — VectorField N-comp
  2. Add unstructured mesh infrastructure #5687 — Meshing
  3. Add unstructured finite volume spatial method #5688 — Spatial method + ProcessedVariable
  4. This PR (Add VTK plotting for unstructured meshes #5689) — VTK plotting
  5. Add unstructured 2D/3D DFN battery models #5690 — Unstructured DFN models

Test plan

  • tests/unit/test_plotting/test_plot_vtk.py (18 passed locally)
  • CI unit suite (incl. Windows OSMesa path)

Also in this stack: #5691 deprecates pybamm.Magnitude.

@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.20%. Comparing base (258fdc8) to head (eb5518e).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5689      +/-   ##
==========================================
- Coverage   98.24%   98.20%   -0.05%     
==========================================
  Files         341      343       +2     
  Lines       33712    34465     +753     
==========================================
+ Hits        33121    33845     +724     
- Misses        591      620      +29     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Base automatically changed from ufv-2-spatial to main September 5, 2026 00:18
aabills and others added 3 commits September 4, 2026 17:26
Add VTKQuickPlot, QuickPlot/dynamic_plot hooks, the vtk optional extra,
and headless OSMesa CI setup for GIF export. Extracted from the
unstructured finite-volume stack.

Co-authored-by: Cursor <cursoragent@cursor.com>
Every panel was built from the FIRST spatial variable's mesh, so a
3-domain variable (e.g. electrolyte concentration) plotted alongside
a 5-domain one was painted onto the larger grid: all values shifted
by the leading domains' cell count, rendering electrolyte data on
current-collector tabs. Build each panel's grid from that variable's
own mesh, and make _set_cell/point_scalars raise on a length mismatch
so this bug class errors instead of drawing a wrong picture.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The regular visualisation grid, mid-plane slices, quiver sampling and
slice-plane positions used to live on the unstructured processed variables;
the spatial-method PR now ships them as pure point interpolators. Add
pybamm.plotting.unstructured_plot_grid with plot_grid, default_slice_positions,
midplane_slices and quiver_data, and have QuickPlot own the grid and slice
positions per plotted variable (the slice sliders update QuickPlot state).
Meshes expose `vertices`, not `nodes`; fix plot_vtk and its test stand-ins.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
aabills and others added 14 commits September 7, 2026 14:02
The CI matrix installs extras unlocked (prebuilt-solver-wheel mode uses
uv pip install), so it picked up VTK 9.7.0, where the legacy AddActor2D
name no longer exists. AddViewProp is the underlying method in every
supported VTK. Lock VTK 9.7.0 so local environments test the same version.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
matplotlib 3.11 (which the unlocked CI matrix installs) emits a
PendingDeprecationWarning for Colormap.set_bad, and the test suite treats
warnings as errors. with_extremes(bad=...) has been available since 3.4.
Lock matplotlib 3.11.1 so local runs see what CI sees.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Tests for dynamic_plot(backend="vtk"), the on-screen render window, the
matplotlib-less lookup-table fallback, QuickPlot's 3D "tight" limits path
and the wireframe helper's 3D guard. The interactive-only lines in
VTKQuickPlot.dynamic_plot (interactor.Start and the render inside the
slider callback) cannot run headless and are marked no cover, as
QuickPlot already does for plt.show.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
… window

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
… numbers

VTK's automatic major ticks piled a dozen labels onto short or stretched
axes ("0.060.080.100.12") and the through-cell axis became a smear under
the 100x display stretch. Set three explicit labels per axis, print the
range of any axis thinner than 5% of the largest in its title instead of
ticks, drop the "(x10^-6)" label scaling, and format scalar-bar values
with %.4g so "1.27e+03" is no longer clipped to "1.27e+" and "303." loses
its dangling point. Slightly smaller axis and panel-title fonts.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Only unstructured-mesh scalars and 0D time series are plottable; vector
fields and structured spatial variables used to fall through to the 0D
chart path, crashing or silently plotting mesh node 0.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
ScikitFemSubMesh3D stores coordinates as nodes, not vertices, so the
FEM path of VTKQuickPlot only worked against test fakes. The node-data
fixture now mirrors the real mesh.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The VTK branch re-passed output_variables by keyword next to *args, so
the positional form raised TypeError; unknown backends now raise
OptionError instead of silently using matplotlib.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Slice position and axis ranges came from the first variable's mesh, so a
panel on a sub-domain mesh was cut and labelled against the wrong
extents. 2D meshes now map their (x, z) columns explicitly instead of
indexing a missing third column.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The OSMesa packages and default window class were wired only into the
reusable workflow, so the periodic matrix ran the unit suite without
them. The env default now lives in noxfile.py for headless Linux, and
the periodic workflow installs the same system packages.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Off-screen Linux no longer hard-codes the OSMesa window class, which
crashed desktops without libOSMesa; headless hosts select it through
VTK_DEFAULT_OPENGL_WINDOW instead. save_gif's PIL import is now an
optional-dependency import backed by the vtk extra.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The 2D quiver, unstructured pcolormesh and 3D slice blocks were pasted
into both methods; they now live in one helper each. The pcolormesh
helper also replaces the previous frame's artists instead of stacking
them, and the fixed-limits scan uses a single comprehension pair.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The plot_surface panels and the y/z slice sliders used raw metres with
unit-less labels while every other panel honoured spatial_unit.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
aabills and others added 2 commits September 8, 2026 11:18
Points, connectivity and per-frame scalar updates went through
per-element Python loops; they are now single vectorised copies, and the
cell/point scalar setters share one implementation.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Log through pybamm.logger, raise OptionError/ShapeError/GeometryError
instead of ValueError, import optional dependencies through
import_optional_dependency, keep inline comments to two lines, add the
future-annotations import and type hints on the public functions.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

ProjectPyBaMM
Branchufv-3-plotting
Testbedbare-metal

⚠️ WARNING: Truncated view!

The full continuous benchmarking report exceeds the maximum length allowed on this platform.

🐰 View full continuous benchmarking report in Bencher

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.

1 participant