Skip to content

Commit

Permalink
adding get_all_nuclides method to geometry class (#2796)
Browse files Browse the repository at this point in the history
Co-authored-by: Paul Romano <[email protected]>
  • Loading branch information
shimwell and paulromano authored Dec 12, 2023
1 parent 124e62f commit 15a2199
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions openmc/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,20 @@ def get_all_universes(self) -> typing.Dict[int, openmc.Universe]:
universes.update(self.root_universe.get_all_universes())
return universes

def get_all_nuclides(self) -> typing.List[str]:
"""Return all nuclides within the geometry.
Returns
-------
list
Sorted list of all nuclides in materials appearing in the geometry
"""
all_nuclides = set()
for material in self.get_all_materials().values():
all_nuclides |= set(material.get_nuclides())
return sorted(all_nuclides)

def get_all_materials(self) -> typing.Dict[int, openmc.Material]:
"""Return all materials within the geometry.
Expand Down
12 changes: 12 additions & 0 deletions tests/unit_tests/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,15 @@ def get_cyl_cell(r1, r2, z1, z2, fill):
# There should be 0 remaining redundant surfaces
n_redundant_surfs = len(geom.remove_redundant_surfaces().keys())
assert n_redundant_surfs == 0

def test_get_all_nuclides():
m1 = openmc.Material()
m1.add_nuclide('Fe56', 1)
m1.add_nuclide('Be9', 1)
m2 = openmc.Material()
m2.add_nuclide('Be9', 1)
s = openmc.Sphere()
c1 = openmc.Cell(fill=m1, region=-s)
c2 = openmc.Cell(fill=m2, region=+s)
geom = openmc.Geometry([c1, c2])
assert geom.get_all_nuclides() == ['Be9', 'Fe56']

0 comments on commit 15a2199

Please sign in to comment.