mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 06:05:58 -04:00
Renamed clone memoize param as memo per request by @paulromano
This commit is contained in:
parent
12a0e00305
commit
120dca7703
6 changed files with 71 additions and 64 deletions
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue