Skip to content

Reshape each mesh filter along its expanded axes - #4240

Merged
pshriwise merged 4 commits into
openmc-dev:developfrom
rpinho:fix-mesh-tally-reshape
Nov 26, 2026
Merged

pshriwise merged 4 commits into
openmc-dev:developfrom
rpinho:fix-mesh-tally-reshape

Conversation

@rpinho

@rpinho rpinho commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Description

Tallies with both a MeshFilter and a MeshBornFilter get spatial axes in the wrong order from get_reshaped_data(expand_dims=True). A tally on meshes of dimensions (2, 3, 1) and (3, 1, 2) returns dimensions (1, 2, 2, 3, 1, 3). This patch records expanded axis positions and restores the axis order for each mesh filter. Tests check both filter orders and compare every spatial bin with get_values.

AI Assistance

  • Harness: Codex CLI (found the bug, wrote the patch and tests); Claude Code (separate reproduction from scratch, opened this PR)
  • Model: GPT-6.1-Sol (Codex); Claude Opus 5.5 (Claude Code)
  • Reasoning effort: high (both)

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
    • Improved reshaped tally data for spherical mesh and mesh-born filters. Spatial dimensions and per-bin values now remain correctly aligned when multiple mesh filters are used, including when their order varies. This provides consistent expanded tally results across supported mesh filter combinations.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LKxc9GKLwnyeV2jaZBxH9N

@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Tally.get_reshaped_data now restores spatial axis order for each expanded mesh-based filter. Unit tests use synthetic tally data to check shapes and values for spherical and regular mesh-born filter combinations in both orders.

Changes: Mesh Filter Reshaping

Layer / File(s) Summary
Track and restore mesh axes
openmc/tallies.py, tests/unit_tests/test_filter_mesh.py
get_reshaped_data records axis pairs for expanded mesh-based filters and swaps each pair after reshaping. Tests check shapes and per-bin values using synthetic tally data, without running a simulation.

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

Change: Bug fix

Suggested reviewers: eepeterson, paulromano

Merge Risk: Minimal · up to f76c1

This change fixes the spatial axis order that get_reshaped_data returns for tallies with several mesh-based filters. No concrete merge-blocking risk was found. The remaining step is to resolve the reported branch conflicts.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "Reshape each mesh filter along its expanded axes" matches the main change: get_reshaped_data(expand_dims=True) now records expanded axis positions and swaps spatial axes for each MeshFilter…
Description check Passed The description states the problem (wrong spatial axis order for tallies with both a MeshFilter and a MeshBornFilter), gives a concrete reproduction example with expected and actual shapes, summarizes…
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.
Full details: Title check

Explanation

The title "Reshape each mesh filter along its expanded axes" matches the main change: get_reshaped_data(expand_dims=True) now records expanded axis positions and swaps spatial axes for each MeshFilter/MeshBornFilter instead of using a single filter position. It is specific and descriptive, and a reviewer scanning history can identify the primary change.

Full details: Description check

Explanation

The description states the problem (wrong spatial axis order for tallies with both a MeshFilter and a MeshBornFilter), gives a concrete reproduction example with expected and actual shapes, summarizes the fix, and notes the tests. The template's required sections are present and filled in: Description, AI Assistance (harness, model, reasoning effort), and the checklist, with the test item checked. Gaps: the 'Fixes # (issue)' line is left as the template placeholder and no linked issue is given, the self-review and documentation items are unchecked, and the AI Assistance section lists tools that may not match the template's expected format. These are minor and do not block merge.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 66217229-1a5f-4e60-aaad-8c989d68ecdd
Commits

Reviewing files that changed from the base of the PR and between 1d3cb46 and f76c192.

Files selected for processing: 2

  • openmc/tallies.py
  • tests/unit_tests/test_filter_mesh.py

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

@pshriwise

Copy link
Copy Markdown
Contributor

Seems some of my latest changes to other branches now caused conflicts here. I'd cringe a bit to force push to your branch @rpinho. Would you mind taking a look? Once they're resolved I think we can get this merged in.

@rpinho

rpinho commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Sure! I merged develop and kept both sets of tests. They pass locally.

@pshriwise pshriwise 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 @rpinho and @claude for the fix!

@pshriwise
pshriwise merged commit dbaaa54 into openmc-dev:develop Nov 26, 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