diff --git a/openmc/model/model.py b/openmc/model/model.py index 5e93d98040c..8117226e492 100644 --- a/openmc/model/model.py +++ b/openmc/model/model.py @@ -855,6 +855,8 @@ def plot( legend: bool = False, axis_units: str = 'cm', outline: bool | str = False, + show_overlaps: bool = False, + overlap_color: Sequence[int] | str | None = None, n_samples: int | None = None, plane_tolerance: float = 1., legend_kwargs: dict | None = None, @@ -933,6 +935,9 @@ def plot( plot.pixels = pixels plot.basis = basis plot.color_by = color_by + plot.show_overlaps = show_overlaps + if overlap_color is not None: + plot.overlap_color = overlap_color if colors is not None: plot.colors = colors self.plots.append(plot) diff --git a/openmc/plots.py b/openmc/plots.py index 24607659844..9c1e31575e5 100644 --- a/openmc/plots.py +++ b/openmc/plots.py @@ -209,16 +209,21 @@ legend : bool Whether a legend showing material or cell names should be drawn + .. versionadded:: 0.14.0 + axis_units : {'km', 'm', 'cm', 'mm'} + Units used on the plot axis + .. versionadded:: 0.14.0 outline : bool or str Whether outlines between color boundaries should be drawn. If set to 'only', only outlines will be drawn. .. versionadded:: 0.14.0 - axis_units : {'km', 'm', 'cm', 'mm'} - Units used on the plot axis - - .. versionadded:: 0.14.0 + show_overlaps: bool + Indicate whether or not overlapping regions are shown. + Default is False. + overlap_color: Iterable of int or str + Color to apply to overlapping regions. Default is red. n_samples : int, optional The number of source particles to sample and add to plot. Defaults to None which doesn't plot any particles on the plot. diff --git a/tests/unit_tests/test_model.py b/tests/unit_tests/test_model.py index 4b567c56d62..7dc36d22573 100644 --- a/tests/unit_tests/test_model.py +++ b/tests/unit_tests/test_model.py @@ -620,3 +620,14 @@ def test_model_plot(): plot = model.plot(n_samples=1, plane_tolerance=0.1, basis="xy") coords = plot.axes.collections[0].get_offsets().data.flatten() assert (coords == np.array([])).all() + + # modify model to include another cell that overlaps the original cell entirely + model.geometry.root_universe.add_cell(openmc.Cell(region=-surface)) + axes = model.plot(show_overlaps=True) + white = np.array((1.0, 1.0, 1.0)) + red = np.array((1.0, 0.0, 0.0)) + axes_image = axes.get_images()[0] + image_data = axes_image.get_array() + # ensure that all of the data in the image data is either white or red + test_mask = (image_data == white) | (image_data == red) + assert np.all(test_mask), "Colors other than white or red found in overlap plot image"