Skip to content

Implementation of point detectors - #3757

Draft
GuySten wants to merge 22 commits into
openmc-dev:developfrom
GuySten:point-detector
Draft

GuySten wants to merge 22 commits into
openmc-dev:developfrom
GuySten:point-detector

Conversation

@GuySten

@GuySten GuySten commented Jan 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR implements point detectors in openmc.
It is based on the work done in #3109 but with classical kinematics.

Currently only continuous energy neutrons are supported.

This PR depends on #3881, #3935.

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)

@GuySten
GuySten requested a review from paulromano as a code owner January 29, 2026 17:58
@GuySten
GuySten marked this pull request as draft January 29, 2026 17:58
@GuySten

GuySten commented May 11, 2026

Copy link
Copy Markdown
Contributor Author

Some tests from the paper using this PR:

U235 test:

image

He4 test:

image

@GuySten GuySten changed the title Testing point detectors Implementation of point detectors May 11, 2026
@GuySten
GuySten marked this pull request as ready for review May 11, 2026 11:51
@itay-space

Copy link
Copy Markdown
Contributor

Hi @GuySten, @paulromano, just wondering if there’s an estimate for when this might be merged?
Thanks!

@GuySten
GuySten marked this pull request as draft September 10, 2026 18:49
ParticleRay was spelled `public Ray, public Particle`, which required both
Ray and ParticleData to inherit GeometryState virtually so that the two
halves would share one copy. That is paid for by the whole code: a virtual
base means every geometry access through a Particle -- r(), u(), coord(),
material() -- reaches its data through the vtable. Reading coord_[0]
compiled to

    movq (%rdi), %rax          load vptr
    movq -24(%rax), %rax       load vbase offset from the vtable
    movq 24(%rdi,%rax), %rax   only now index coord_

where a plain base needs just `movq 24(%rdi), %rax`. Particle is the hottest
class in the code and this reached every user of it, for the sake of one kind
of ray.

Split the per-flight bookkeeping into RayState, which carries no geometry,
and move the tracing loop into a trace_ray() template explicitly instantiated
for Ray and ParticleRay. Ray becomes a plain `GeometryState, RayState` and
ParticleRay a plain `Particle, RayState`, each reaching GeometryState once,
non-virtually. Sharing the loop through a template rather than a base class
is what removes the need for the two to meet at a common base at all, and it
devirtualizes the on_intersection() and update_distance() hooks for
ParticleRay as a side effect. This also clears the -Wvirtual-move-assign
warning the virtual base produced.

Also here, both consequences of building a ParticleData outside the transport
machinery:

- Default-initialize seeds_ and stream_. init_particle_seeds() is what
  normally sets them, and a ParticleRay is built without it, leaving
  current_seed() indexing seeds_ with an indeterminate stream_.

- Add ParticleRay::reset(), which re-initializes a ray in place. The buffers
  ParticleData's constructor sizes from the loaded model -- the microscopic
  cross section caches, the filter matches, the flux derivatives -- come to
  tens of kilobytes, so a caller launching many rays wants to reuse one
  rather than construct each. Note that init_from_r_u() clears material(),
  which is what stops a reused ray from carrying stale cross sections into
  its next flight.

Verified by rendering both ray-traced plot types, which drive the same loop
through ProjectionRay and PhongRay: output is byte-identical to before.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WtCexLeoCYmBVQocfBaEG5
Implement a next-event estimator that scores the flux at fixed points in
space. At every collision -- and at every source emission -- a
deterministic contribution is made to each active detector:

    phi = (1/W) * sum_i w_i * p_i(Omega_i) * exp(-tau_i) / R_i^2

where p_i is the scattering PDF evaluated in the direction of the
detector, tau_i is the optical depth along the line of sight, and R_i is
the distance to it. The optical depth is found by launching a ParticleRay
toward the detector and accumulating mean free paths along the flight.

The 1/R^2 kernel is singular at the detector, so each detector carries an
exclusion sphere of radius r0 inside which the estimator is replaced by
its analytic average over the sphere,

    <K> = 3 * (1 - exp(-Sigma_t * r0)) / (Sigma_t * r0^3)

evaluated as 3 * exprel(-Sigma_t * r0) / r0^2 to stay accurate as
Sigma_t * r0 -> 0.

The pieces:

  - PointFilter (filter_point.{h,cpp}) holds the detector positions and
    exclusion radii, and maps a traced ray back to the bins that share
    its endpoint. It scores only under the point-detector estimator.
  - next_event_scoring.{h,cpp} provides the per-reaction entry points
    (elastic, inelastic, fission, S(a,b) and source) and a pool of rays
    reused across contributions, guarded by a PointDetectorStream RAII
    object that switches the RNG to a dedicated substream so that
    scoring cannot perturb the parent random walk.
  - tally.{h,cpp} validates the estimator (scores, filters and a
    non-vacuum outer boundary), collects the active detectors and sizes
    the ray pool.
  - physics.cpp and source.cpp call the scoring hooks at each collision
    and at emission.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WtCexLeoCYmBVQocfBaEG5
Expose PointFilter in openmc.filter and openmc.lib.filter, and let
Tally accept the 'point-detector' estimator. PointFilter takes a
sequence of (x, y, z, exclusion_radius) detectors, validates them on
construction and round-trips through XML and HDF5 like every other
filter.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WtCexLeoCYmBVQocfBaEG5
Cover PointFilter construction and validation, XML/HDF5 round-tripping,
the estimator guards in Tally.scores, and the physics of the estimator
itself: a bare point source in a void against the analytic 1/(4 pi R^2),
attenuation through a slab, and agreement with a collision-estimator
flux tally in a scattering medium.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WtCexLeoCYmBVQocfBaEG5
Add the next-event estimator to the methods manual (the estimator
itself, the exclusion sphere, and the variance and bias caveats that
come with a singular kernel), describe the point filter and the
'point-detector' estimator in the user's guide, and add the filter to
the tallies.xml, statepoint and Python API references.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WtCexLeoCYmBVQocfBaEG5
@coderabbitai

coderabbitai Bot commented Oct 15, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
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.

3 participants