From 8942659fe0682cca23b2bb2571f22871e22f21f7 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 25 Jun 2021 07:38:37 -0500 Subject: [PATCH] Adding support for cloning DAGMC universes in the Python API. --- openmc/universe.py | 50 ++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/openmc/universe.py b/openmc/universe.py index d5d015eba5..fe08e27c98 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -35,6 +35,10 @@ class UniverseBase(ABC, IDManagerMixin): self._volume = None self._atoms = {} + # Keys - Cell IDs + # Values - Cells + self._cells = OrderedDict() + def __repr__(self): string = 'Universe\n' string += '{: <16}=\t{}\n'.format('\tID', self._id) @@ -101,7 +105,6 @@ class UniverseBase(ABC, IDManagerMixin): """ - @abstractmethod def clone(self, clone_materials=True, clone_regions=True, memo=None): """Create a copy of this universe with a new unique ID, and clones all cells within this universe. @@ -124,6 +127,24 @@ class UniverseBase(ABC, IDManagerMixin): The clone of this universe """ + if memo is None: + memo = {} + + # If no memoize'd clone exists, instantiate one + if self not in memo: + clone = deepcopy(self) + clone.id = None + + # Clone all cells for the universe clone + clone._cells = OrderedDict() + for cell in self._cells.values(): + clone.add_cell(cell.clone(clone_materials, clone_regions, + memo)) + + # Memoize the clone + memo[self] = clone + + return memo[self] class Universe(UniverseBase): @@ -161,10 +182,6 @@ class Universe(UniverseBase): def __init__(self, universe_id=None, name='', cells=None): super().__init__(universe_id, name) - # Keys - Cell IDs - # Values - Cells - self._cells = OrderedDict() - if cells is not None: self.add_cells(cells) @@ -546,26 +563,6 @@ class Universe(UniverseBase): return universes - def clone(self, clone_materials=True, clone_regions=True, memo=None): - if memo is None: - memo = {} - - # If no nemoize'd clone exists, instantiate one - if self not in memo: - clone = deepcopy(self) - clone.id = None - - # Clone all cells for the universe clone - clone._cells = OrderedDict() - for cell in self._cells.values(): - clone.add_cell(cell.clone(clone_materials, clone_regions, - memo)) - - # Memoize the clone - memo[self] = clone - - return memo[self] - def create_xml_subelement(self, xml_element, memo=None): # Iterate over all Cells for cell in self._cells.values(): @@ -709,9 +706,6 @@ class DAGMCUniverse(UniverseBase): cv.check_type('DAGMC automatic material ids', val, bool) self._auto_mat_ids = val - def clone(self, clone_materials=True, clone_regions=True, memo=None): - pass - def get_all_cells(self, memo=None): return OrderedDict()