Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions openmc/lib/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ class _PlotBase(Structure):

C-Type Attributes
-----------------
origin : openmc.lib.plot._Position
origin_ : openmc.lib.plot._Position
A position defining the origin of the plot.
width_ : openmc.lib.plot._Position
The width of the plot along the x, y, and z axes, respectively
basis_ : c_int
The axes basis of the plot view.
pixels_ : c_size_t[3]
The resolution of the plot in the horizontal and vertical dimensions
color_overlaps_ : c_bool
Whether to assign unique IDs (-3) to overlapping regions.
level_ : c_int
The universe level for the plot view

Expand Down Expand Up @@ -187,14 +189,6 @@ def color_overlaps(self):
def color_overlaps(self, color_overlaps):
self.color_overlaps_ = color_overlaps

@property
def color_overlaps(self):
return self.color_overlaps_

@color_overlaps.setter
def color_overlaps(self, val):
self.color_overlaps_ = val

def __repr__(self):
out_str = ["-----",
"Plot:",
Expand Down
6 changes: 6 additions & 0 deletions openmc/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,7 @@ def id_map(
width: Sequence[float] | None = None,
pixels: int | Sequence[int] = 40000,
basis: str = 'xy',
color_overlaps: bool = False,
**init_kwargs
) -> np.ndarray:
"""Generate an ID map for domains based on the plot parameters
Expand Down Expand Up @@ -1065,6 +1066,10 @@ def id_map(
total and the image aspect ratio based on the width argument.
basis : {'xy', 'yz', 'xz'}, optional
Basis of the plot.
color_overlaps : bool, optional
Whether to assign unique IDs (-3) to overlapping regions. If False,
overlapping regions will be assigned the ID of the lowest-numbered
cell that occupies that region. Defaults to False.
**init_kwargs
Keyword arguments passed to :meth:`Model.init_lib`.

Expand All @@ -1089,6 +1094,7 @@ def id_map(
plot_obj.h_res = pixels[0]
plot_obj.v_res = pixels[1]
plot_obj.basis = basis
plot_obj.color_overlaps = color_overlaps

# Silence output by default. Also set arguments to start in volume
# calculation mode to avoid loading cross sections
Expand Down
26 changes: 26 additions & 0 deletions tests/unit_tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,32 @@ def test_id_map_aligned_model():
assert tr_material == 5, f"Expected material ID 5 at top-right corner, got {tr_material}"


def test_id_map_model_with_overlaps():
"""Test id_map with a model that has overlaps and color_overlaps option"""
surface1 = openmc.Sphere(r=50, boundary_type="vacuum")
surface2 = openmc.Sphere(r=30)
cell1 = openmc.Cell(region=-surface1)
cell2 = openmc.Cell(region=-surface2)
geometry = openmc.Geometry([cell1, cell2])
settings = openmc.Settings()
model = openmc.Model(geometry=geometry, settings=settings)
id_slice = model.id_map(
pixels=(10, 10),
basis='xy',
origin=(0, 0, 0),
width=(100, 100),
)
assert -3 not in id_slice # -3 indicates overlap region
id_slice = model.id_map(
pixels=(10, 10),
basis='xy',
origin=(0, 0, 0),
width=(100, 100),
color_overlaps=True, # enables id_map to return -3 for overlaps
)
assert -3 in id_slice


def test_setter_from_list():
mat = openmc.Material()
model = openmc.Model(materials=[mat])
Expand Down
Loading