Skip to content

Implement angular PDF evaluation for angle-energy distributions#3550

Merged
GuySten merged 113 commits intoopenmc-dev:developfrom
itay-space:get_pdf
Mar 14, 2026
Merged

Implement angular PDF evaluation for angle-energy distributions#3550
GuySten merged 113 commits intoopenmc-dev:developfrom
itay-space:get_pdf

Conversation

@itay-space
Copy link
Copy Markdown
Contributor

@itay-space itay-space commented Aug 27, 2025

Description

This PR is the first step in breaking down the point detector tally project into smaller, reviewable pieces, following the large PR #3109
and the paper Development and benchmarking of a point detector in OpenMC.

As suggested during the earlier discussion (thanks @GuySten, @gridley, @shimwell !), the natural starting point is to add the ability to correctly calculate PDFs on the C++ side.

Accordingly, this PR introduces the get_pdf implementations for the distribution classes. This is essentially a clean cut from the original large PR, with the goal of keeping the scope focused and review manageable.

We plan to follow up with tests and additional pieces of the point detector work in subsequent PRs.

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)

@itay-space itay-space changed the title Implement get_pdf functionality [Point Detector] Add distribution get_pdf functionality Aug 27, 2025
Copy link
Copy Markdown
Contributor

@GuySten GuySten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @itay-space!

My review focus more on the code structure side of things.
I did not check the maths.

Comment thread include/openmc/distribution.h Outdated
Comment thread include/openmc/particle_data.h Outdated
Comment thread include/openmc/particle_data.h Outdated
Comment thread src/physics.cpp Outdated
Comment thread src/physics.cpp Outdated
Comment thread src/secondary_correlated.cpp Outdated
Comment thread src/secondary_correlated.cpp Outdated
Comment thread src/secondary_kalbach.cpp Outdated
Comment thread src/secondary_thermal.cpp Outdated
Comment thread src/thermal.cpp Outdated
itay-space and others added 6 commits August 28, 2025 08:32
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>
Comment thread src/distribution.cpp Outdated
Comment thread include/openmc/angle_energy.h Outdated
Comment thread include/openmc/reaction_product.h Outdated
Comment thread src/distribution.cpp Outdated
Comment thread src/distribution.cpp Outdated
Comment thread src/distribution.cpp
Comment thread src/distribution_angle.cpp Outdated
Comment thread src/reaction_product.cpp Outdated
Comment thread src/secondary_correlated.cpp Outdated
Comment thread src/secondary_correlated.cpp Outdated
Comment thread src/secondary_nbody.cpp Outdated
Comment thread include/openmc/angle_energy.h Outdated
Comment thread include/openmc/distribution_angle.h Outdated
Comment thread include/openmc/secondary_correlated.h Outdated
Comment thread include/openmc/secondary_kalbach.h Outdated
Comment thread include/openmc/secondary_correlated.h Outdated
Comment thread src/secondary_thermal.cpp Outdated
Comment thread src/secondary_uncorrelated.cpp Outdated
Comment thread src/secondary_uncorrelated.cpp Outdated
Comment thread src/thermal.cpp Outdated
Comment thread vendor/gsl-lite Outdated
Comment thread src/reaction_product.cpp Outdated
Co-authored-by: GuySten <62616591+GuySten@users.noreply.github.com>
@GuySten GuySten mentioned this pull request Jan 29, 2026
5 tasks
@GuySten
Copy link
Copy Markdown
Contributor

GuySten commented Mar 2, 2026

I've removed all dynamic allocations.
@itay-space, can you check that you agree with my changes?

@paulromano, this PR is ready for review again.

@GuySten GuySten requested a review from paulromano March 2, 2026 20:19
Reconstructing the azimuth with acos(u.dot(v_ref_) / sqrt(1 - mu*mu))
loses the sign of the w_ref_ component, so directions at azimuth phi
and 2π - phi collapse to the same value.
CoherentElasticAE::sample_energy_and_pdf returns zero whenever E_in >
bragg_edges_.back(), but coherent elastic scattering is still valid
above the highest Bragg edge; CoherentElasticXS::operator() continues
to use the final cumulative structure factor there.

Additionally, the call to bragg_edges_.slice(0, n) /
factors_diff_.slice(0, n) is not valid for a 1-D Tensor. In the tensor
API, slice(0, n) means two axis indices, not a range.
@paulromano
Copy link
Copy Markdown
Contributor

@GuySten Thanks for the updates on this branch -- it was definitely looking much better. There were still a few issues that I found and fixed:

  • PolarAzimuthal::evaluate reconstructed phi in a way that loses the sign of the w component, so directions at phi and 2π - phi would evaluate to the same value (even if phi is asymmetric). I updated the logic to fix this.
  • CoherentElasticAE::sample_energy_and_pdf returned zero when E_in > bragg_edges.back() but coherent elastic scattering is still valid above the highest Bragg edge. Also, the tensor slicing was incorrect (slice(0, n) would slice single values on two dimensions, whereas we needed a range in 1D).
  • The thermal discrete PDF routines did not match the distributions that the actual sample routines generate. Namely, in the actual sampling, the discrete cosines are interpolated and then smeared using neighboring interpolated points. I've refactored the get_pdf_discrete functions to reflect this.

Let me know if you agree with the changes and if so, I think this is ready to merge!

@paulromano paulromano changed the title [Point Detector] Add distribution get_pdf functionality Implement angular PDF evaluation for angle-energy distributions Mar 13, 2026
@GuySten
Copy link
Copy Markdown
Contributor

GuySten commented Mar 14, 2026

I agree with these changes.
Thanks @paulromano for the various improvements.

@GuySten GuySten merged commit 1578698 into openmc-dev:develop Mar 14, 2026
17 checks passed
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.

7 participants