From 9e88e706fe92860ce973630a4a288b15a4a8b66c Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 16 Feb 2023 16:20:44 +0000 Subject: [PATCH 1/2] testing get_all_universes is in DAGMCUniverse --- tests/unit_tests/test_universe.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/unit_tests/test_universe.py b/tests/unit_tests/test_universe.py index 26b7779a7..a70bd4667 100644 --- a/tests/unit_tests/test_universe.py +++ b/tests/unit_tests/test_universe.py @@ -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(): From 04d9e27866dad92dc1a6fbc7676e76750c96cb63 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 16 Feb 2023 16:24:24 +0000 Subject: [PATCH 2/2] moving get_all_universes method --- openmc/universe.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/openmc/universe.py b/openmc/universe.py index c56cce7ca..2ed96f4bc 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -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():