Skip to content

Add Particle.write_vtkhdf to visualize lost particles in ParaView#3997

Open
Sammy-Dabbas wants to merge 1 commit into
openmc-dev:developfrom
Sammy-Dabbas:issue-3922-lost-particles-vtkhdf
Open

Add Particle.write_vtkhdf to visualize lost particles in ParaView#3997
Sammy-Dabbas wants to merge 1 commit into
openmc-dev:developfrom
Sammy-Dabbas:issue-3922-lost-particles-vtkhdf

Conversation

@Sammy-Dabbas

Copy link
Copy Markdown

Closes #3922.

Adds openmc.Particle.write_vtkhdf(particle_files, filename), a static method that reads one or more lost-particle restart files and writes a single VTKHDF PolyData file so lost particles can be visualized directly in ParaView. Each particle becomes a vertex at its xyz position, with PointData arrays for energy, weight, direction, particle type (PDG code), batch, generation, and id. Only h5py and numpy are used to write the file, following the approach in the issue.

The VTKHDF layout mirrors the existing writer in openmc/mesh.py (VTKHDF group, Version attribute, ascii PolyData type, vertex cells, empty Lines/Polygons/Strips). Each input file is read through the existing Particle class so its filetype and version validation is reused.

Tests build synthetic lost-particle files matching the schema written by Particle::write_restart in src/particle.cpp, then assert the full VTKHDF structure and every point-data array. One test is gated behind pytest.importorskip("vtk") and round-trips the output through vtk.vtkHDFReader (the same reader ParaView uses), confirming it parses as vtkPolyData with the correct points, vertex cells, and arrays. Ruff is clean on both files.

One open question for reviewers: whether you would prefer this as a standalone function rather than a static method on Particle, or a different default filename.

Adds a static method that reads one or more lost-particle restart files
and writes a single VTKHDF PolyData file, one vertex per particle, with
point data for energy, weight, direction, particle type, batch,
generation, and id. Only h5py and numpy are required. See openmc-dev#3922.
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.

lost particle h5 files to vtkhdf to allow visualization in paraview

1 participant