Skip to content

Overlap detection for plotter#3969

Open
viktormai wants to merge 27 commits into
openmc-dev:developfrom
viktormai:overlap-detection-for-plotter
Open

Overlap detection for plotter#3969
viktormai wants to merge 27 commits into
openmc-dev:developfrom
viktormai:overlap-detection-for-plotter

Conversation

@viktormai

Copy link
Copy Markdown

Description

This PR adds overlap detection support to the slice data API, enabling
the OpenMC plotter to identify and display which specific cells are
overlapping at a given pixel.

Changes

  • Modified check_cell_overlap to return an OverlapResult struct instead
    of a simple boolean, containing a list of OverlapKey pairs (cell1_id,
    cell2_id, universe_id) for each detected overlap
  • Added pixel_overlaps_ field to RasterData to store per-pixel overlap
    pair data during raster plot generation
  • Added openmc_slice_data_overlap_count C API function to query the number
    of overlapping cell pairs at a given pixel
  • Added openmc_slice_data_overlap_info C API function to retrieve the
    overlapping cell IDs and universe ID at a given pixel
  • Added corresponding Python bindings in openmc/lib/plot.py

Previously the plotter could color overlap pixels but had no way to tell
the user which cells were overlapping. This change stores the overlap
pair data during plot generation so the plotter can display meaningful
overlap information when a user hovers over an overlap pixel.

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)

@viktormai viktormai requested a review from pshriwise as a code owner June 10, 2026 22:52

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

@viktormai Thanks a lot for the PR here, which is a really great start!. In my comments below, I've proposed a different way of handling the storage of the overlaps. It would also be good if you could put a draft PR on the plotter that uses this branch so that I can test it out in practice there.

Comment thread include/openmc/plot.h Outdated
Comment on lines +194 to +195
// Vector for storing overlaps to later be flattened and sent through the API
std::vector<std::vector<OverlapKey>> pixel_overlaps_;

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.

I see here that currently we're storing this vector of overlap results for each pixel in the image. I have a different concept in my head for how we can store and reference the overlap results. First, we would have a global variable of type std::vector<OverlapKey>. Then, rather than having check_cell_overlap return an OverlapResult, it would return an index into that global vector of OverlapKey. See my next comment about how that index would be used.

Comment thread include/openmc/plot.h Outdated
Comment on lines +286 to +288
auto overlap = check_cell_overlap(p, false);
if (!overlap.pairs.empty()) {
data.set_overlap(y, x, overlap.pairs);

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.

Here, if check_cell_overlap returns an index into a global vector of OverlapKey, we can pass that index to set_overlap, which will be used in RasterData::set_overlap to set one of the entries in id_data_ to OVERLAP - index - 1. That is, if the index 0 in the global vector is 0 will result in the pixel being set to -4, index 1 in the vector will result in the pixel being set to -5, etc. Then the openmc_slice_data_overlap_info function can be used to get the corresponding data from the OverlapKey -- rather than passing the x/y pixel indices, it would be passed the index into the global vector of OverlapKey. Each time openmc_slice_data is called, the global vector of OverlapKey should be cleared.

Now that I'm thinking about it, one alternative could be to have the overlap info function return all the data in the global vector:

int openmc_slice_data_overlap_count(size_t* count);
int openmc_slice_data_overlap_info(size_t count, int32_t* overlap_info);

where count is the size of the global vector, and overlap_info would be an array allocated from openmc.lib of size 3*count that has the data written into it as [universe_0, cell1_0, cell2_0, universe_1, cell1_1, cell2_1, ..., universe_count, cell1_count, cell2_count]. That would allow us to minimize the number of calls that are needed through the C API (rather than having to call the overlap info function once for each pixel where there is an overlap, we would call it only once).

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