Skip to content

Testing point detectors#3757

Draft
GuySten wants to merge 143 commits intoopenmc-dev:developfrom
GuySten:point-detector
Draft

Testing point detectors#3757
GuySten wants to merge 143 commits intoopenmc-dev:developfrom
GuySten:point-detector

Conversation

@GuySten
Copy link
Copy Markdown
Contributor

@GuySten GuySten commented Jan 29, 2026

Description

This PR is a draft.
It is used to test the functionality in PR #3550 in a classical (non-relativistic) way.

Checklist

  • I have performed a self-review of my own code
  • I have run clang-format (version 15) 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)

Your Name and others added 30 commits August 27, 2025 18:29
Co-authored-by: GuySten <62616591+GuySten@users.noreply.github.com>
Co-authored-by: GuySten <62616591+GuySten@users.noreply.github.com>
Co-authored-by: GuySten <62616591+GuySten@users.noreply.github.com>
Co-authored-by: GuySten <62616591+GuySten@users.noreply.github.com>
Co-authored-by: GuySten <62616591+GuySten@users.noreply.github.com>
Co-authored-by: GuySten <62616591+GuySten@users.noreply.github.com>
Co-authored-by: GuySten <62616591+GuySten@users.noreply.github.com>
Co-authored-by: GuySten <62616591+GuySten@users.noreply.github.com>
Co-authored-by: GuySten <62616591+GuySten@users.noreply.github.com>
Co-authored-by: GuySten <62616591+GuySten@users.noreply.github.com>
Co-authored-by: GuySten <62616591+GuySten@users.noreply.github.com>
Co-authored-by: GuySten <62616591+GuySten@users.noreply.github.com>
Co-authored-by: GuySten <62616591+GuySten@users.noreply.github.com>
Co-authored-by: GuySten <62616591+GuySten@users.noreply.github.com>
Co-authored-by: GuySten <62616591+GuySten@users.noreply.github.com>
Co-authored-by: GuySten <62616591+GuySten@users.noreply.github.com>
Co-authored-by: GuySten <62616591+GuySten@users.noreply.github.com>
GuySten and others added 30 commits January 30, 2026 00:55
Three bugs prevented point detector tallies from producing any results:

1. setup_active_tallies() had no case for TallyType::POINT, so
   active_point_tallies and active_point_detectors were never populated.
   All scoring hooks guarded by 'if (!active_point_tallies.empty())'
   silently skipped every event.

2. score_point_tally_impl() did not set ParticleRay position/energy
   state before calling score_tracklength_tally_general(). PointFilter
   requires p.r() == detector position and EnergyFilter reads p.E_last(),
   both of which were uninitialized/wrong after Ray::trace().

3. openmc_statepoint_write() had no branch for TallyEstimator::NEXT_EVENT,
   so the 'estimator' dataset was missing from the HDF5 output, causing
   Python StatePoint reader to crash with KeyError.

Fixes:
- Add TallyType::POINT case in setup_active_tallies() that pushes to
  active_point_tallies and inserts detector positions from PointFilter.
- Add corresponding clear() calls in setup_active_tallies() and
  free_memory_tally().
- Include filter_point.h in tally.cpp.
- Set p.r(), p.r_last(), and p.E_last() on the ParticleRay before scoring.
- Write 'next-event' estimator string in statepoint for NEXT_EVENT tallies.

Verified with smoke tests: water sphere with point detectors produces
non-zero flux, 1/r^2 scaling matches analytical expectation within 2%,
and symmetric detectors yield statistically consistent results.
…type

PointFilter lacked from_hdf5() and get_pandas_dataframe() overrides.
The base Filter.from_hdf5() passed a flat numpy array to PointFilter.__init__
which expects Sequence[tuple], causing TypeError. The base
get_pandas_dataframe() used np.repeat on the nested tuple structure,
causing ValueError.

Also add 'next-event' to ESTIMATOR_TYPES so the Tally.estimator setter
accepts the value read from statepoint files.

Fixes:
- Add PointFilter.from_hdf5() that reconstructs (pos, r0) tuples from
  flat HDF5 bins array.
- Add PointFilter.get_pandas_dataframe() that formats detector positions
  as readable string labels.
- Add 'next-event' to ESTIMATOR_TYPES set in tallies.py.
Fix point detector scoring: activate tallies, set ParticleRay state, fix Python reader
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants