Skip to content

Add analytic tests for ray-traced intersection distances#4014

Merged
paulromano merged 2 commits into
openmc-dev:developfrom
mazy1998:codex/test-ray-distances
Jul 19, 2026
Merged

Add analytic tests for ray-traced intersection distances#4014
paulromano merged 2 commits into
openmc-dev:developfrom
mazy1998:codex/test-ray-distances

Conversation

@mazy1998

Copy link
Copy Markdown
Contributor

Description

Add focused C++ unit tests for Ray::trace() using a concentric-sphere CSG geometry.

The tests verify:

  • the analytic chord length through a sphere, 2 * sqrt(R^2 - b^2);
  • all four cumulative intersection distances for a ray crossing a spherical shell and its inner region.

Together, these cases exercise entry from outside the model, multiple internal surface crossings, re-entry into a cell, and final leakage through a vacuum boundary. This adds direct analytic coverage for the reusable Ray implementation generalized in #3816 and separated into its own source files in #3845.

No production behavior or public API is changed.

Testing

  • cmake --build build --target test_ray -j2
  • ctest --test-dir build -R '^test_ray$' --output-on-failure
  • All nine locally available C++ test executables pass; the optional MCPL test was excluded because MCPL is not installed.
  • A local mutation check confirmed the assertions detect TINY_BIT-scale errors in accumulated traversal distances.

Checklist

  • I have performed a self-review of my own code
  • I have run clang-format (version 18) on the C++ source file
  • I have followed the style guidelines for Python source files (not applicable)
  • I have made corresponding changes to the documentation (not applicable; test-only change)
  • I have added tests that prove the covered behavior works

@paulromano paulromano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The new test is failing on the DAGMC-enabled configuration because the OPENMC_DAGMC_ENABLED compile definition is used in a header file but is set by CMakeLists.txt to private, which means the test_ray executable ends up with a different definition of the GeometryState and Ray classes than libopenmc itself. The following fix is needed:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d5af01610..61d2cc6c5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -532,7 +532,7 @@ else()
 endif()
 
 if(OPENMC_USE_DAGMC)
-  target_compile_definitions(libopenmc PRIVATE OPENMC_DAGMC_ENABLED)
+  target_compile_definitions(libopenmc PUBLIC OPENMC_DAGMC_ENABLED)
   target_link_libraries(libopenmc dagmc-shared)
 
   if(OPENMC_USE_UWUW)

@paulromano
paulromano merged commit 05d0127 into openmc-dev:develop Jul 19, 2026
17 checks passed
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.

2 participants