diff --git a/openmc/geometry.py b/openmc/geometry.py index fb2488f7813..60f4a390d44 100644 --- a/openmc/geometry.py +++ b/openmc/geometry.py @@ -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. diff --git a/tests/unit_tests/test_geometry.py b/tests/unit_tests/test_geometry.py index ff94bc932ad..f5a1bd7db69 100644 --- a/tests/unit_tests/test_geometry.py +++ b/tests/unit_tests/test_geometry.py @@ -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']