Skip to content

Fix double normalization in random ray VTK flux - #4192

Open
agourakis82 wants to merge 1 commit into
openmc-dev:developfrom
agourakis82:fix/random-ray-vtk-normalization
Open

agourakis82 wants to merge 1 commit into
openmc-dev:developfrom
agourakis82:fix/random-ray-vtk-normalization

Conversation

@agourakis82

@agourakis82 agourakis82 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #4137. Random-ray VTK flux was normalized by the active batch count twice.

RandomRaySimulation::simulate() already applies the final source normalization to the scalar flux. The flat and linear source-domain point evaluators then divided their values by the active batch count again. Linear source moments also did not receive the final normalization applied to scalar flux.

This patch:

  • applies the final normalization factor to linear flux moments;
  • removes the duplicate active-batch division from flat-source point evaluation;
  • removes the duplicate active-batch division from linear-source point evaluation;
  • adds a regression test comparing mean random-ray VTK flux with the source tally.

Validation

  • ctest: 14 passed, 1 skipped
  • focused random-ray regression tests: 12 passed
  • ruff check tests/regression_tests/random_ray_vtk_normalization/test.py
  • git diff --check

The focused regression test fails against the unpatched baseline and passes with this change. OpenMP cluster validation was attempted, but the workspace Slurm executor terminated even a minimal probe with RaisedSignal:53 before running the payload.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected flux normalization for random-ray simulations using linear sources, including flux moments.
    • Improved consistency between flux values shown in VTK plots and source-tally results.

Signed-off-by: Demetrios Agourakis <demetrios@agourakis.med.br>
@agourakis82
agourakis82 requested a review from jtramm as a code owner October 13, 2026 05:44
@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8b7c08c6-599e-4df9-ad3e-4d29a4062f77
📥 Commits

Reviewing files that changed from the base of the PR and between aa4afc4 and 104ec66.

📒 Files selected for processing (5)
  • src/random_ray/flat_source_domain.cpp
  • src/random_ray/linear_source_domain.cpp
  • src/random_ray/random_ray_simulation.cpp
  • tests/regression_tests/random_ray_vtk_normalization/__init__.py
  • tests/regression_tests/random_ray_vtk_normalization/test.py
💤 Files with no reviewable changes (1)
  • src/random_ray/linear_source_domain.cpp

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

Random-ray point evaluation no longer divides accumulated flux values by the active-batch count. Simulation also normalizes linear-source flux moments with the scalar-flux normalization factor. A regression test compares VTK flux values with a source tally.

Changes: Random-ray VTK flux normalization

Layer / File(s) Summary
Normalize point-evaluation flux and validate VTK output
src/random_ray/random_ray_simulation.cpp, src/random_ray/flat_source_domain.cpp, src/random_ray/linear_source_domain.cpp, tests/regression_tests/random_ray_vtk_normalization/test.py
Simulation applies the scalar-flux normalization factor to linear-source flux moments. Flat- and linear-source point evaluation use accumulated values without another active-batch division. The regression test compares mean VTK flux with the source-tally mean.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 104ec

The test can exercise the linear flux contribution, and no actionable issue remains from this review. The change is ready for normal merge checks.

Pre-merge checks · Passed 4 · Failed 1

Failed Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary fix: preventing double normalization of random-ray VTK flux.
Description check Passed The description explains the bug, motivation, implementation, linked issue, regression test, and validation results. It omits the template's AI Assistance and Checklist sections, but the core descript…
Linked Issues check Passed The changes satisfy the coding requirements in issue #4137. RandomRaySimulation::simulate() now applies the final source normalization factor to flux_moments_t for linear sources. Both point evalu…
Out of Scope Changes check Passed The pull request changes only random-ray normalization code and its regression test. These changes directly support issue #4137 and do not demonstrate unrelated behavior or files.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • 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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Random ray VTK plot flux is divided by the active batch count twice

1 participant