From 120dca77035e5c6989e6f4bffe19c9e67bee743f Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Mon, 10 Apr 2017 12:10:34 -0400 Subject: [PATCH] Renamed clone memoize param as memo per request by @paulromano --- openmc/cell.py | 21 +++++++++++---------- openmc/lattice.py | 19 +++++++++++-------- openmc/material.py | 14 +++++++------- openmc/region.py | 34 +++++++++++++++++----------------- openmc/surface.py | 24 ++++++++++++------------ openmc/universe.py | 23 +++++++++++++---------- 6 files changed, 71 insertions(+), 64 deletions(-) diff --git a/openmc/cell.py b/openmc/cell.py index 61690e98c3..b0847fc047 100644 --- a/openmc/cell.py +++ b/openmc/cell.py @@ -505,13 +505,13 @@ class Cell(object): return universes - def clone(self, memoize=None): + def clone(self, memo=None): """Create a copy of this cell with a new unique ID, and clones the cell's region and fill. Parameters ---------- - memoize : defaultdict(dict) or None + memo : defaultdict(dict) or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -522,25 +522,26 @@ class Cell(object): """ - if memoize is None: - memoize = defaultdict(dict) + if memo is None: + memo = defaultdict(dict) # If no nemoize'd clone exists, instantiate one - if self.id not in memoize['cells']: + if self.id not in memo['cells']: clone = deepcopy(self) clone.id = None if self.region is not None: - clone.region = self.region.clone(memoize) + clone.region = self.region.clone(memo) if self.fill is not None: if self.fill_type == 'distribmat': - clone.fill = [fill.clone(memoize) for fill in self.fill] + clone.fill = [fill.clone(memo) if fill is not None else None + for fill in self.fill] else: - clone.fill = self.fill.clone(memoize) + clone.fill = self.fill.clone(memo) # Memoize the clone - memoize['cells'][self.id] = clone + memo['cells'][self.id] = clone - return memoize['cells'][self.id] + return memo['cells'][self.id] def create_xml_subelement(self, xml_element): element = ET.Element("cell") diff --git a/openmc/lattice.py b/openmc/lattice.py index 26eadbe7ff..f9fa63331a 100644 --- a/openmc/lattice.py +++ b/openmc/lattice.py @@ -415,13 +415,13 @@ class Lattice(object): return [] return [(self, idx)] + u.find(p) - def clone(self, memoize=None): + def clone(self, memo=None): """Create a copy of this lattice with a new unique ID, and clones all universes within this lattice. Parameters ---------- - memoize : defaultdict(dict) or None + memo : defaultdict(dict) or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -432,18 +432,21 @@ class Lattice(object): """ - if memoize is None: - memoize = defaultdict(dict) + if memo is None: + memo = defaultdict(dict) # If no nemoize'd clone exists, instantiate one - if self.id not in memoize['lattices']: + if self.id not in memo['lattices']: clone = deepcopy(self) clone.id = None + if self.outer is not None: + clone.outer = self.outer.clone() + # Clone all unique universes in the lattice univ_clones = self.get_unique_universes() for univ_id in univ_clones: - univ_clones[univ_id] = univ_clones[univ_id].clone(memoize) + univ_clones[univ_id] = univ_clones[univ_id].clone(memo) # Assign universe clones to the lattice clone for i in self.indices: @@ -459,9 +462,9 @@ class Lattice(object): clone.universes[i[0]][i[1]][i[2]] = univ_clones[univ_id] # Memoize the clone - memoize['lattices'][self.id] = clone + memo['lattices'][self.id] = clone - return memoize['lattices'][self.id] + return memo['lattices'][self.id] class RectLattice(Lattice): diff --git a/openmc/material.py b/openmc/material.py index 75c31f37c8..cdb82da03d 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -799,12 +799,12 @@ class Material(object): return nuclides - def clone(self, memoize=None): + def clone(self, memo=None): """Create a copy of this material with a new unique ID. Parameters ---------- - memoize : defaultdict(dict) or None + memo : defaultdict(dict) or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -815,18 +815,18 @@ class Material(object): """ - if memoize is None: - memoize = defaultdict(dict) + if memo is None: + memo = defaultdict(dict) # If no nemoize'd clone exists, instantiate one - if self.id not in memoize['materials']: + if self.id not in memo['materials']: clone = deepcopy(self) clone.id = None # Memoize the clone - memoize['materials'][self.id] = clone + memo['materials'][self.id] = clone - return memoize['materials'][self.id] + return memo['materials'][self.id] def _get_nuclide_xml(self, nuclide, distrib=False): xml_element = ET.Element("nuclide") diff --git a/openmc/region.py b/openmc/region.py index 37078eda85..0b1f970840 100644 --- a/openmc/region.py +++ b/openmc/region.py @@ -223,13 +223,13 @@ class Region(object): return output[0] @abstractmethod - def clone(self, memoize=None): + def clone(self, memo=None): """Create a copy of this region - each of the surfaces in the region's nodes will be cloned and will have new unique IDs. Parameters ---------- - memoize : defaultdict(dict) or None + memo : defaultdict(dict) or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -326,13 +326,13 @@ class Intersection(Region): check_type('nodes', nodes, Iterable, Region) self._nodes = nodes - def clone(self, memoize=None): + def clone(self, memo=None): """Create a copy of this region - each of the surfaces in the intersection's nodes will be cloned and will have new unique IDs. Parameters ---------- - memoize : defaultdict(dict) or None + memo : defaultdict(dict) or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -343,11 +343,11 @@ class Intersection(Region): """ - if memoize is None: - memoize = defaultdict(dict) + if memo is None: + memo = defaultdict(dict) clone = deepcopy(self) - clone.nodes = [n.clone(memoize) for n in self.nodes] + clone.nodes = [n.clone(memo) for n in self.nodes] return clone @@ -427,13 +427,13 @@ class Union(Region): check_type('nodes', nodes, Iterable, Region) self._nodes = nodes - def clone(self, memoize=None): + def clone(self, memo=None): """Create a copy of this region - each of the surfaces in the union's nodes will be cloned and will have new unique IDs. Parameters ---------- - memoize : defaultdict(dict) or None + memo : defaultdict(dict) or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -444,11 +444,11 @@ class Union(Region): """ - if memoize is None: - memoize = defaultdict(dict) + if memo is None: + memo = defaultdict(dict) clone = copy.deepcopy(self) - clone.nodes = [n.clone(memoize) for n in self.nodes] + clone.nodes = [n.clone(memo) for n in self.nodes] return clone @@ -548,13 +548,13 @@ class Complement(Region): surfaces = region.get_surfaces(surfaces) return surfaces - def clone(self, memoize=None): + def clone(self, memo=None): """Create a copy of this region - each of the surfaces in the complement's node will be cloned and will have new unique IDs. Parameters ---------- - memoize : defaultdict(dict) or None + memo : defaultdict(dict) or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -565,9 +565,9 @@ class Complement(Region): """ - if memoize is None: - memoize = defaultdict(dict) + if memo is None: + memo = defaultdict(dict) clone = copy.deepcopy(self) - clone.node = self.node.clone(memoize) + clone.node = self.node.clone(memo) return clone diff --git a/openmc/surface.py b/openmc/surface.py index 1eb69d2db6..1edae2cae7 100644 --- a/openmc/surface.py +++ b/openmc/surface.py @@ -172,12 +172,12 @@ class Surface(object): return (np.array([-np.inf, -np.inf, -np.inf]), np.array([np.inf, np.inf, np.inf])) - def clone(self, memoize=None): + def clone(self, memo=None): """Create a copy of this surface with a new unique ID. Parameters ---------- - memoize : defaultdict(dict) or None + memo : defaultdict(dict) or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -188,18 +188,18 @@ class Surface(object): """ - if memoize is None: - memoize = defaultdict(dict) + if memo is None: + memo = defaultdict(dict) # If no nemoize'd clone exists, instantiate one - if self.id not in memoize['surfaces']: + if self.id not in memo['surfaces']: clone = deepcopy(self) clone.id = None # Memoize the clone - memoize['surfaces'][self.id] = clone + memo['surfaces'][self.id] = clone - return memoize['surfaces'][self.id] + return memo['surfaces'][self.id] def to_xml_element(self): """Return XML representation of the surface @@ -1932,13 +1932,13 @@ class Halfspace(Region): surfaces[self.surface.id] = self.surface return surfaces - def clone(self, memoize=None): + def clone(self, memo=None): """Create a copy of this halfspace, with a cloned surface with a unique ID. Parameters ---------- - memoize : defaultdict(dict) or None + memo : defaultdict(dict) or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -1949,11 +1949,11 @@ class Halfspace(Region): """ - if memoize is None: - memoize = defaultdict(dict) + if memo is None: + memo = defaultdict(dict) clone = deepcopy(self) - clone.surface = self.surface.clone(memoize) + clone.surface = self.surface.clone(memo) return clone diff --git a/openmc/universe.py b/openmc/universe.py index 9453dfb11a..1fefa2372c 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -517,13 +517,13 @@ class Universe(object): return universes - def clone(self, memoize=None): + def clone(self, memo=None): """Create a copy of this universe with a new unique ID, and clones all cells within this universe. Parameters ---------- - memoize : defaultdict(dict) or None + memo : defaultdict(dict) or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -534,20 +534,23 @@ class Universe(object): """ - if memoize is None: - memoize = defaultdict(dict) + if memo is None: + memo = defaultdict(dict) # If no nemoize'd clone exists, instantiate one - if self.id not in memoize['universes']: - memoize['universes'][self.id] = deepcopy(self) - memoize['universes'][self.id].id = None + if self.id not in memo['universes']: + clone = deepcopy(self) + clone.id = None # Clone all cells for the universe clone - memoize['universes'][self.id]._cells = OrderedDict() + clone._cells = OrderedDict() for cell in self._cells.values(): - memoize['universes'][self.id].add_cell(cell.clone(memoize)) + clone.add_cell(cell.clone(memo)) - return memoize['universes'][self.id] + # Memoize the clone + memo['universes'][self.id] = clone + + return memo['universes'][self.id] def create_xml_subelement(self, xml_element): # Iterate over all Cells