Add Particle.write_vtkhdf to visualize lost particles in ParaView#3997
Open
Sammy-Dabbas wants to merge 1 commit into
Open
Add Particle.write_vtkhdf to visualize lost particles in ParaView#3997Sammy-Dabbas wants to merge 1 commit into
Sammy-Dabbas wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.