diff --git a/openmc/cell.py b/openmc/cell.py index 8572a640d..9a744910c 100644 --- a/openmc/cell.py +++ b/openmc/cell.py @@ -618,7 +618,10 @@ class Cell(IDManagerMixin): Axes containing resulting image """ - return openmc.Universe(cells=[self]).plot(*args, **kwargs) + # Create dummy universe but preserve used_ids + u = openmc.Universe(cells=[self], universe_id=openmc.Universe.next_id + 1) + openmc.Universe.used_ids.remove(u.id) + return u.plot(*args, **kwargs) def create_xml_subelement(self, xml_element, memo=None): """Add the cell's xml representation to an incoming xml element diff --git a/tests/unit_tests/test_cell.py b/tests/unit_tests/test_cell.py index 1df3df9c5..888a0ef88 100644 --- a/tests/unit_tests/test_cell.py +++ b/tests/unit_tests/test_cell.py @@ -345,3 +345,21 @@ def test_rotation_from_xml(rotation): elem, {s.id: s}, {'void': None}, openmc.Universe ) np.testing.assert_allclose(new_cell.rotation, cell.rotation) + + +def test_plot(run_in_tmpdir): + zcyl = openmc.ZCylinder() + c = openmc.Cell(region=-zcyl) + + # create a universe before the plot + u_before = openmc.Universe() + + # create a plot of the cell + c.plot() + + # create a universe after the plot + u_after = openmc.Universe() + + # ensure that calling the plot method doesn't + # affect the universe ID space + assert u_before.id + 1 == u_after.id