Skip to content

Geometry debug function - #4012

Merged
paulromano merged 43 commits into
openmc-dev:developfrom
viktormai:geometry-debug-function
Sep 5, 2026
Merged

Geometry debug function#4012
paulromano merged 43 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)

@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 initial shot at this! Here are my initial thoughts:

Comment thread openmc/model/model.py
Comment thread openmc/model/model.py Outdated
Comment thread openmc/model/model.py
@viktormai

Copy link
Copy Markdown
Contributor Author

Thanks for checking it out @paulromano. I have added some updates for the bounding box idea for both overlapping and undefined regions, including a warning if undefined regions are under-resolved. Let me know what you think.

@viktormai
viktormai marked this pull request as ready for review July 22, 2026 15:10

@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 updates @viktormai! Here is another round of comments:

Comment thread openmc/model/model.py Outdated
Comment thread openmc/model/model.py Outdated
Comment thread openmc/model/model.py Outdated
Comment thread openmc/model/model.py Outdated
Comment thread openmc/model/model.py Outdated
Comment thread openmc/model/model.py Outdated
Comment thread openmc/model/model.py Outdated

@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 updates @viktormai! This is getting closer. Now that it is looking better, you should also add some unit tests for the capability to ensure it works properly.

Comment thread openmc/model/model.py Outdated
Comment thread openmc/model/model.py Outdated
Comment thread openmc/model/model.py Outdated
Comment thread openmc/model/model.py Outdated

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

All set now; thanks @viktormai!

@paulromano
paulromano enabled auto-merge (squash) September 5, 2026 22:04
@paulromano
paulromano merged commit d7d3284 into openmc-dev:develop Sep 5, 2026
16 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