Merge pull request #2388 from shimwell/moving_gau_method_up_one_layer

testing get_all_universes is in DAGMCUniverse
This commit is contained in:
Patrick Shriwise 2023-02-20 12:36:53 -06:00 committed by GitHub
commit 7aaf114d8e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 20 deletions

View file

@ -91,6 +91,23 @@ class UniverseBase(ABC, IDManagerMixin):
else:
raise ValueError('No volume information found for this universe.')
def get_all_universes(self):
"""Return all universes that are contained within this one.
Returns
-------
universes : collections.OrderedDict
Dictionary whose keys are universe IDs and values are
:class:`Universe` instances
"""
# Append all Universes within each Cell to the dictionary
universes = OrderedDict()
for cell in self.get_all_cells().values():
universes.update(cell.get_all_universes())
return universes
@abstractmethod
def create_xml_subelement(self, xml_element, memo=None):
"""Add the universe xml representation to an incoming xml element
@ -538,23 +555,6 @@ class Universe(UniverseBase):
return materials
def get_all_universes(self):
"""Return all universes that are contained within this one.
Returns
-------
universes : collections.OrderedDict
Dictionary whose keys are universe IDs and values are
:class:`Universe` instances
"""
# Append all Universes within each Cell to the dictionary
universes = OrderedDict()
for cell in self.get_all_cells().values():
universes.update(cell.get_all_universes())
return universes
def create_xml_subelement(self, xml_element, memo=None):
# Iterate over all Cells
for cell in self._cells.values():

View file

@ -93,10 +93,12 @@ def test_get_all_universes():
u2 = openmc.Universe(cells=[c2])
c3 = openmc.Cell(fill=u1)
c4 = openmc.Cell(fill=u2)
u3 = openmc.Universe(cells=[c3, c4])
u3 = openmc.DAGMCUniverse(filename="")
c5 = openmc.Cell(fill=u3)
u4 = openmc.Universe(cells=[c3, c4, c5])
univs = set(u3.get_all_universes().values())
assert not (univs ^ {u1, u2})
univs = set(u4.get_all_universes().values())
assert not (univs ^ {u1, u2, u3})
def test_clone():