Skip to content

Fix plotting outside lattices without an outer universe - #4253

Open
paulromano wants to merge 5 commits into
openmc-dev:developfrom
paulromano:fix-lattice-plot-without-outer
Open

paulromano wants to merge 5 commits into
openmc-dev:developfrom
paulromano:fix-lattice-plot-without-outer

Conversation

@paulromano

@paulromano paulromano commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Description

Currently, a slice plot can segfault when a lattice has no outer universe and its containing cell extends beyond the lattice. The geometry lookup marks the state as lost but then tries to continue without a valid lower-level universe index.

Minimal working example
import openmc

mat = openmc.Material(components={'U235': 0.02}, density=0.5, density_units='g/cm3')
cell = openmc.Cell(fill=mat)
univ = openmc.Universe(cells=[cell])
lat = openmc.RectLattice()
lat.lower_left = (-1., -1.)
lat.pitch = (1, 1)
lat.universes = [
    [univ, univ],
    [univ, univ]
]

box = openmc.model.RectangularPrism(3., 3., boundary_type='vacuum')
cell = openmc.Cell(fill=lat, region=-box)
cell.plot()

To enable plotting to work in this case, this PR changes the geometry search to return false before descending when a point lies outside a lattice with no outer universe.

AI Assistance

  • Harness: Codex
  • Model: GPT-6.2-Sol
  • 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
    • Improved handling of particles and rays when cell searches fail, preventing further initialization or coordinate processing after an unsuccessful search.
    • Corrected behavior for particles outside a lattice without an outer universe.
    • Fixed lattice slice results so pixels outside the lattice are marked separately from interior pixels.

@paulromano
paulromano requested a review from jtramm as a code owner November 24, 2026 09:13
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The changes adjust how geometry lookup failures are handled in parent-cell searches, lattice lookup, and random-ray initialization. A unit test checks slice cell IDs for a lattice without an outer universe.

Changes: Geometry lookup failure handling

Layer / File(s) Summary
Handle failed geometry lookups
src/geometry.cpp, src/cell.cpp, src/random_ray/random_ray.cpp, tests/unit_tests/test_slice_data.py
Lattice lookup returns false when indices are invalid and no outer universe is configured. Parent-cell search falls back to exhaustive_find_parent_cells(instance) when cell lookup fails. Random-ray initialization returns after a failed lookup marks the ray lost. The new slice test checks cell IDs outside and inside the lattice.

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

Change: Bug fix

Suggested labels: Bugs, Geometry

Suggested reviewers: pshriwise

Merge Risk: Minimal · up to d32f0

This change prevents slice plots from crashing when a cell extends beyond a lattice that has no outer universe. Undefined regions are now reported as unfound, with a regression test for the slice case. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "Fix plotting outside lattices without an outer universe" matches the main change. The PR stops a segfault in slice plots when a point lies outside a lattice that has no outer universe. The …
Description check Passed The description states the problem, gives a minimal working example, and explains the fix. The AI assistance section is filled in with harness, model, and reasoning effort. The checklist is marked. It…
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 "Fix plotting outside lattices without an outer universe" matches the main change. The PR stops a segfault in slice plots when a point lies outside a lattice that has no outer universe. The title names the bug and the affected case. It does not name the code change itself, but that is expected.

Full details: Description check

Explanation

The description states the problem, gives a minimal working example, and explains the fix. The AI assistance section is filled in with harness, model, and reasoning effort. The checklist is marked. It does not link an issue under 'Fixes # (issue)', and it does not name the regression test added. The description is mostly complete, so the check passes.

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: e62a2a89-4b54-41f0-985b-69952ad5b50a
Commits

Reviewing files that changed from the base of the PR and between 5d63501 and d32f057.

Files selected for processing: 4

  • src/cell.cpp
  • src/geometry.cpp
  • src/random_ray/random_ray.cpp
  • tests/unit_tests/test_slice_data.py

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

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.

1 participant