Skip to content

Lost particle track files#3976

Open
viktormai wants to merge 5 commits into
openmc-dev:developfrom
viktormai:lost-particle-tracks-pr
Open

Lost particle track files#3976
viktormai wants to merge 5 commits into
openmc-dev:developfrom
viktormai:lost-particle-tracks-pr

Conversation

@viktormai

@viktormai viktormai commented Jun 19, 2026

Copy link
Copy Markdown

Description

When a particle is lost during transport, OpenMC now (with this PR) automatically replays it from its original source site with tracking enabled, writing the full track history to tracks.h5 without requiring a manual -r/-t restart. Previously, diagnosing a lost particle required identifying it from the warning output, then re-running with the restart file — this change eliminates that step entirely. If there are multiple lost particles, each is written to separate parts of one tracks.h5 file to avoid clogging up the directory.

  • Added run_lost_particle_track() in particle_restart.cpp which reconstructs and replays the lost particle from the source bank with write_track = true
  • Added in_lost_track thread-local flag to prevent infinite recursion if the replayed particle is also lost
  • Added lost_particle_track_file_open flag to manage a separate track file lifecycle from the normal --track workflow
  • Wrapped warning() and track file abort logic in appropriate #pragma omp critical blocks for thread safety
  • Guarded all HDF5 file operations with >= 0 checks after initializing track_file and track_dtype to -1
  • Added dataset name deduplication via H5Lexists to prevent HDF5 errors if multiple lost particles share an ID
  • Reset all track state variables on simulation_init and ensured proper file closure on simulation_finalize
  • Also, a suggested change to the naming format for particle restart files: "batch_{}_particle_{}" as opposed to "particle_{}_{}" for clarity on which batch a restart file belongs to

This will also later support functionality in the plotter to help visualize particle failures in the geometry.

Checklist

  • I have performed a self-review of my own code
  • I have run clang-format (version 18) on any C++ source files (if applicable)
  • I have followed the style guidelines for Python source files (if applicable)
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

@viktormai viktormai changed the title Lost particle tracks pr Lost particle tracks writing Jun 19, 2026
@viktormai viktormai changed the title Lost particle tracks writing Lost particle track files Jun 19, 2026
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