Skip to content

Add implied a_0 to File 6 two-body Legendre distributions - #4190

Merged
paulromano merged 1 commit into
openmc-dev:developfrom
GuySten:fix-mf6-law2-legendre
Oct 13, 2026
Merged

paulromano merged 1 commit into
openmc-dev:developfrom
GuySten:fix-mf6-law2-legendre

Conversation

@GuySten

@GuySten GuySten commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Description

In ENDF-6 File 6, two-body scattering (LAW=2) with Legendre data (LANG=0) stores only the coefficients a_1 to a_NL; a_0 = 1 is implied. ENDF-102 §6.2.4, Eq. 6.8 gives the distribution as 1/2 + Σ_{l=1}^{NL} (2l+1)/2 a_l P_l(μ) with NW = NL. NJOY reads these records the same way, passing them to ptleg2 as for File 4.

_get_products in openmc/data/reaction.py passed the stored values straight to Legendre, so a_1 was used as a_0 and every order shifted down by one. The File 4 reader (AngleDistribution.from_endf) already prepends a_0 = 1. This change does the same for File 6.

Only IncidentNeutron.from_endf reaches this code, so it affects users who read ENDF files directly and use the angular distributions of reaction products. Libraries built with NJOY (from_njoy / from_ace), depletion chains and multigroup data are not affected.

Checked on ENDF/B-VIII.0 Si-29 MT51, Al-27 MT51 and H-1 MT102 (201 distributions):

Integral of the distribution Mean cosine
Before 0 for isotropic levels; 0.257 for Al-27 MT51 at 13.5 MeV, which also went negative —
After 1 to within roundoff equals a_1

AI Assistance

  • Harness: Claude Code
  • Model: Opus 5.5
  • Reasoning effort: High

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).

Summary by CodeRabbit

  • Bug Fixes
    • Corrected angular distribution handling for a discrete two-body scattering case, ensuring the zeroth Legendre coefficient is included.

In ENDF-6 File 6, LAW=2 with LANG=0 stores the Legendre coefficients a_1
to a_NL only; a_0 = 1 is implied (ENDF-102, Eq. 6.8), as in File 4.
_get_products passed the stored values straight to Legendre, so a_1 was
used as a_0 and every order shifted down by one. The File 4 reader
already prepends a_0 = 1.

For example, Al-27 MT51 at 13.5 MeV in ENDF/B-VIII.0 gave a distribution
that integrated to 0.257 and went negative; it now integrates to 1 with
mean cosine 0.257.

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

coderabbitai Bot commented Oct 12, 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: c18ade9c-20f4-4c4e-ad43-62659f26784a

📥 Commits

Reviewing files that changed from the base of the PR and between aa4afc4 and 4273b40.


📒 Files selected for processing (1)
  • openmc/data/reaction.py

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

Walkthrough

For ENDF LAW=2 discrete two-body scattering with LANG=0, the code now prepends the implied Legendre coefficient a₀ = 1 before it constructs the angular distribution. Other angular-distribution cases are unchanged.

Changes

LANG=0 Legendre Distribution

Layer / File(s) Summary
Prepend implied coefficient
openmc/data/reaction.py
For LANG=0, the Legendre distribution now uses a₀ = 1 before the supplied coefficients.

Priority: ➖ Normal

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

Change: Bug fix


Merge Risk: ⚪ Minimal · up to 4273b

The change supplies the implicit zeroth coefficient for conforming LANG=0 data. No actionable merge-blocking risk remains.

Architecture Summary

Architecture risk: 🔵 Low · up to 4273b

The change affects 1 system.

Changed systems: openmc

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — openmc (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in openmc/data/reaction.py: For LANG=0, the Legendre distribution now inserts the implied coefficient a₀ = 1 before the supplied coefficients; previously it used the supplied coefficients unchanged.

Pre-merge checks · Passed 5
Passed Passed checks (5 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: adding the implied a₀ coefficient to File 6 two-body Legendre distributions.
Description check Passed The description is complete and relevant. It explains the ENDF behavior, the defect, the fix, affected code paths, validation results, AI assistance, and applicable checklist items. No issue number is…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

✨ 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.

@GuySten
GuySten marked this pull request as ready for review October 12, 2026 19:19
@GuySten
GuySten requested a review from paulromano as a code owner October 12, 2026 19:19

@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.

Thanks for the fix!

@paulromano
paulromano merged commit 3aec0ed into openmc-dev:develop Oct 13, 2026
26 of 32 checks passed
@GuySten
GuySten deleted the fix-mf6-law2-legendre branch October 13, 2026 16:41
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