Geometry debug function - #4012
Conversation
paulromano
left a comment
There was a problem hiding this comment.
Thanks for the initial shot at this! Here are my initial thoughts:
|
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. |
paulromano
left a comment
There was a problem hiding this comment.
Thanks for the updates @viktormai! Here is another round of comments:
paulromano
left a comment
There was a problem hiding this comment.
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.
| result : dict | ||
| Dictionary summarizing the sampled geometry. |
There was a problem hiding this comment.
This doesn't really tell the user how to interpret the dict that's returned. There should be a description of the (key, value) pairs in the dictionary.
| xc = x0 + (pix[:, 1] + 0.5) * (x1 - x0) / nx | ||
| yc = y1 - (pix[:, 0] + 0.5) * (y1 - y0) / ny |
There was a problem hiding this comment.
This looks like it just uses the pixel centers. I think it would be more conservative to use the bounds of the pixel itself rather than just its center (if I'm interpreting it correctly, this is already how it works for the undefined pixels?).
| for box in overlap_boxes + undefined_boxes: | ||
| bbox = box["bbox"] | ||
| bbox.lower_left = np.round(bbox.lower_left, 4) | ||
| bbox.upper_right = np.round(bbox.upper_right, 4) |
There was a problem hiding this comment.
While it's OK to round numbers in the output if print_summary=True (looks like that's already the case), I wouldn't modify the data that is actually returned in the dictionary
| "n_overlaps": len(overlap_boxes), | ||
| "n_undefined_regions": len(undefined_boxes), |
There was a problem hiding this comment.
These are easily inspectable from the data itself and can be removed IMO
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():
Added _classify_undefined_regions() helper:
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