Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
13 changes: 9 additions & 4 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 @@ -476,14 +476,19 @@ def get_all_universes(self):
:class:`Universe` instances

"""

universes = {}

if memo and self in memo:
return universes

if memo is not None:
memo.add(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
10 changes: 8 additions & 2 deletions 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=None):
"""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 All @@ -226,7 +232,7 @@ def get_all_universes(self):

# Append all Universes containing each cell to the dictionary
for universe in unique_universes.values():
all_universes.update(universe.get_all_universes())
all_universes.update(universe.get_all_universes(memo))

return all_universes

Expand Down
13 changes: 10 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 @@ -100,10 +100,17 @@ def get_all_universes(self):
:class:`Universe` instances

"""

if memo and self in memo:
return {}

if memo is not None:
memo.add(self)
Comment thread
paulromano marked this conversation as resolved.
Resolved

# 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=set()).values():
universes.update(cell.get_all_universes(memo))

return universes

Expand Down