Releasing ID after creating dummy universe for cell plotting (#2663)

Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
This commit is contained in:
Patrick Shriwise 2023-09-01 14:31:37 -05:00 committed by GitHub
parent 1cae2f712a
commit 27540c5b8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View file

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

View file

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