Skip to content

Geometry debug function#4012

Draft
viktormai wants to merge 32 commits into
openmc-dev:developfrom
viktormai:geometry-debug-function
Draft

Geometry debug function#4012
viktormai wants to merge 32 commits into
openmc-dev:developfrom
viktormai:geometry-debug-function

Conversation

@viktormai

Copy link
Copy Markdown
Contributor

This PR adds a 3D geometry debugging utility to Model for identifying overlap and undefined regions within an OpenMC geometry by sampling a user-defined bounding box.

Main changes

Added Model.geometry_debug():

  • Samples a 3D region using a stack of 2D slices obtained through openmc.lib.slice_data.
  • Detects both overlap regions (using the overlap sentinel) and internal undefined regions, returning a summary containing the total number of overlap and undefined samples and example coordinates for each type of geometry issue.
  • Optionally prints a human-readable summary.

Added _classify_undefined_regions() helper:

  • Separates undefined pixels into boundary-connected ("outside") undefined regions and internal undefined regions enclosed within the geometry.
  • Uses a breadth-first search starting from the image boundary to identify boundary-connected undefined pixels.
  • Issues a warning when undefined regions exist but none are connected to the sampled slice boundary, indicating a potentially enclosed undefined region or insufficient sampling resolution.

This pair of functions provides a simple way to locate common geometry construction problems—particularly overlaps and enclosed undefined regions—by returning representative coordinates that users can inspect directly, rather than relying solely on transport failures or visual inspection. These sample points can also be leveraged by AI agents to easily fix geometry issues in the model. Reusable undefined-region classification logic that can be leveraged by future plotting and geometry diagnostics for plotting undefined regions is also established.

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)

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