Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding get_all_nuclides method to geometry class #2796

Merged
merged 2 commits into from
Dec 12, 2023
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
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']