Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Adding a memo to get_all_universes
  • Loading branch information
pshriwise committed May 8, 2024
commit 472e156a7745e645ef5f5f38b99eb5bbf17ada6c
6 changes: 3 additions & 3 deletions openmc/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def get_all_materials(self, memo=None):

return materials

def get_all_universes(self):
def get_all_universes(self, memo=None):
"""Return all universes that are contained within this one if any of
its cells are filled with a universe or lattice.

Expand All @@ -481,9 +481,9 @@ def get_all_universes(self):

if self.fill_type == 'universe':
universes[self.fill.id] = self.fill
universes.update(self.fill.get_all_universes())
universes.update(self.fill.get_all_universes(memo))
elif self.fill_type == 'lattice':
universes.update(self.fill.get_all_universes())
universes.update(self.fill.get_all_universes(memo))

return universes

Expand Down
2 changes: 1 addition & 1 deletion openmc/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def get_all_universes(self) -> typing.Dict[int, openmc.Universe]:
"""
universes = {}
universes[self.root_universe.id] = self.root_universe
universes.update(self.root_universe.get_all_universes())
universes.update(self.root_universe.get_all_universes(memo=set()))
Comment thread
paulromano marked this conversation as resolved.
Resolved
return universes

def get_all_nuclides(self) -> typing.List[str]:
Expand Down
8 changes: 7 additions & 1 deletion openmc/lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def get_all_materials(self, memo=None):

return materials

def get_all_universes(self):
def get_all_universes(self, memo):
"""Return all universes that are contained within the lattice

Returns
Expand All @@ -218,6 +218,12 @@ def get_all_universes(self):
# in each nested Universe level
all_universes = {}

if memo and self in memo:
return all_universes

if memo is not None:
memo.add(self)

# Get all unique Universes contained in each of the lattice cells
unique_universes = self.get_unique_universes()

Expand Down
6 changes: 3 additions & 3 deletions openmc/universe.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def add_volume_information(self, volume_calc):
else:
raise ValueError('No volume information found for this universe.')

def get_all_universes(self):
def get_all_universes(self, memo=None):
"""Return all universes that are contained within this one.

Returns
Expand All @@ -102,8 +102,8 @@ def get_all_universes(self):
"""
# Append all Universes within each Cell to the dictionary
universes = {}
for cell in self.get_all_cells().values():
universes.update(cell.get_all_universes())
for cell in self.get_all_cells(memo).values():
universes.update(cell.get_all_universes(memo))

return universes

Expand Down