mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 21:55:41 -04:00
Added __hash__ method to Surface class; revised clone methods memo param to use objects as keys
This commit is contained in:
parent
120dca7703
commit
400b5e2c1d
6 changed files with 44 additions and 41 deletions
|
|
@ -1,4 +1,4 @@
|
|||
from collections import OrderedDict, Iterable, defaultdict
|
||||
from collections import OrderedDict, Iterable
|
||||
from copy import deepcopy
|
||||
from math import cos, sin, pi
|
||||
from numbers import Real, Integral
|
||||
|
|
@ -511,7 +511,7 @@ class Cell(object):
|
|||
|
||||
Parameters
|
||||
----------
|
||||
memo : defaultdict(dict) or None
|
||||
memo : dict or None
|
||||
A nested dictionary of previously cloned objects. This parameter
|
||||
is used internally and should not be specified by the user.
|
||||
|
||||
|
|
@ -523,10 +523,10 @@ class Cell(object):
|
|||
"""
|
||||
|
||||
if memo is None:
|
||||
memo = defaultdict(dict)
|
||||
memo = {}
|
||||
|
||||
# If no nemoize'd clone exists, instantiate one
|
||||
if self.id not in memo['cells']:
|
||||
if self not in memo:
|
||||
clone = deepcopy(self)
|
||||
clone.id = None
|
||||
if self.region is not None:
|
||||
|
|
@ -539,9 +539,9 @@ class Cell(object):
|
|||
clone.fill = self.fill.clone(memo)
|
||||
|
||||
# Memoize the clone
|
||||
memo['cells'][self.id] = clone
|
||||
memo[self] = clone
|
||||
|
||||
return memo['cells'][self.id]
|
||||
return memo[self]
|
||||
|
||||
def create_xml_subelement(self, xml_element):
|
||||
element = ET.Element("cell")
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from __future__ import division
|
||||
|
||||
from abc import ABCMeta
|
||||
from collections import OrderedDict, Iterable, defaultdict
|
||||
from collections import OrderedDict, Iterable
|
||||
from copy import deepcopy
|
||||
from math import sqrt, floor
|
||||
from numbers import Real, Integral
|
||||
|
|
@ -421,7 +421,7 @@ class Lattice(object):
|
|||
|
||||
Parameters
|
||||
----------
|
||||
memo : defaultdict(dict) or None
|
||||
memo : dict or None
|
||||
A nested dictionary of previously cloned objects. This parameter
|
||||
is used internally and should not be specified by the user.
|
||||
|
||||
|
|
@ -433,15 +433,15 @@ class Lattice(object):
|
|||
"""
|
||||
|
||||
if memo is None:
|
||||
memo = defaultdict(dict)
|
||||
memo = {}
|
||||
|
||||
# If no nemoize'd clone exists, instantiate one
|
||||
if self.id not in memo['lattices']:
|
||||
if self not in memo:
|
||||
clone = deepcopy(self)
|
||||
clone.id = None
|
||||
|
||||
if self.outer is not None:
|
||||
clone.outer = self.outer.clone()
|
||||
clone.outer = self.outer.clone(memo)
|
||||
|
||||
# Clone all unique universes in the lattice
|
||||
univ_clones = self.get_unique_universes()
|
||||
|
|
@ -462,9 +462,9 @@ class Lattice(object):
|
|||
clone.universes[i[0]][i[1]][i[2]] = univ_clones[univ_id]
|
||||
|
||||
# Memoize the clone
|
||||
memo['lattices'][self.id] = clone
|
||||
memo[self] = clone
|
||||
|
||||
return memo['lattices'][self.id]
|
||||
return memo[self]
|
||||
|
||||
|
||||
class RectLattice(Lattice):
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from collections import OrderedDict, defaultdict
|
||||
from collections import OrderedDict
|
||||
from copy import deepcopy
|
||||
from numbers import Real, Integral
|
||||
import warnings
|
||||
|
|
@ -804,7 +804,7 @@ class Material(object):
|
|||
|
||||
Parameters
|
||||
----------
|
||||
memo : defaultdict(dict) or None
|
||||
memo : dict or None
|
||||
A nested dictionary of previously cloned objects. This parameter
|
||||
is used internally and should not be specified by the user.
|
||||
|
||||
|
|
@ -816,17 +816,17 @@ class Material(object):
|
|||
"""
|
||||
|
||||
if memo is None:
|
||||
memo = defaultdict(dict)
|
||||
memo = dict
|
||||
|
||||
# If no nemoize'd clone exists, instantiate one
|
||||
if self.id not in memo['materials']:
|
||||
if self not in memo:
|
||||
clone = deepcopy(self)
|
||||
clone.id = None
|
||||
|
||||
# Memoize the clone
|
||||
memo['materials'][self.id] = clone
|
||||
memo[self] = clone
|
||||
|
||||
return memo['materials'][self.id]
|
||||
return memo[self]
|
||||
|
||||
def _get_nuclide_xml(self, nuclide, distrib=False):
|
||||
xml_element = ET.Element("nuclide")
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from abc import ABCMeta, abstractmethod
|
||||
from collections import Iterable, OrderedDict, defaultdict
|
||||
from collections import Iterable, OrderedDict
|
||||
from copy import deepcopy
|
||||
|
||||
from six import add_metaclass
|
||||
|
|
@ -229,7 +229,7 @@ class Region(object):
|
|||
|
||||
Parameters
|
||||
----------
|
||||
memo : defaultdict(dict) or None
|
||||
memo : dict or None
|
||||
A nested dictionary of previously cloned objects. This parameter
|
||||
is used internally and should not be specified by the user.
|
||||
|
||||
|
|
@ -332,7 +332,7 @@ class Intersection(Region):
|
|||
|
||||
Parameters
|
||||
----------
|
||||
memo : defaultdict(dict) or None
|
||||
memo : dict or None
|
||||
A nested dictionary of previously cloned objects. This parameter
|
||||
is used internally and should not be specified by the user.
|
||||
|
||||
|
|
@ -344,7 +344,7 @@ class Intersection(Region):
|
|||
"""
|
||||
|
||||
if memo is None:
|
||||
memo = defaultdict(dict)
|
||||
memo = {}
|
||||
|
||||
clone = deepcopy(self)
|
||||
clone.nodes = [n.clone(memo) for n in self.nodes]
|
||||
|
|
@ -433,7 +433,7 @@ class Union(Region):
|
|||
|
||||
Parameters
|
||||
----------
|
||||
memo : defaultdict(dict) or None
|
||||
memo : dict or None
|
||||
A nested dictionary of previously cloned objects. This parameter
|
||||
is used internally and should not be specified by the user.
|
||||
|
||||
|
|
@ -445,7 +445,7 @@ class Union(Region):
|
|||
"""
|
||||
|
||||
if memo is None:
|
||||
memo = defaultdict(dict)
|
||||
memo = {}
|
||||
|
||||
clone = copy.deepcopy(self)
|
||||
clone.nodes = [n.clone(memo) for n in self.nodes]
|
||||
|
|
@ -554,7 +554,7 @@ class Complement(Region):
|
|||
|
||||
Parameters
|
||||
----------
|
||||
memo : defaultdict(dict) or None
|
||||
memo : dict or None
|
||||
A nested dictionary of previously cloned objects. This parameter
|
||||
is used internally and should not be specified by the user.
|
||||
|
||||
|
|
@ -566,7 +566,7 @@ class Complement(Region):
|
|||
"""
|
||||
|
||||
if memo is None:
|
||||
memo = defaultdict(dict)
|
||||
memo = {}
|
||||
|
||||
clone = copy.deepcopy(self)
|
||||
clone.node = self.node.clone(memo)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from abc import ABCMeta
|
||||
from collections import Iterable, OrderedDict, defaultdict
|
||||
from collections import Iterable, OrderedDict
|
||||
from copy import deepcopy
|
||||
from numbers import Real, Integral
|
||||
from xml.etree import ElementTree as ET
|
||||
|
|
@ -83,6 +83,9 @@ class Surface(object):
|
|||
def __pos__(self):
|
||||
return Halfspace(self, '+')
|
||||
|
||||
def __hash__(self):
|
||||
return hash(repr(self))
|
||||
|
||||
def __repr__(self):
|
||||
string = 'Surface\n'
|
||||
string += '{0: <16}{1}{2}\n'.format('\tID', '=\t', self._id)
|
||||
|
|
@ -177,7 +180,7 @@ class Surface(object):
|
|||
|
||||
Parameters
|
||||
----------
|
||||
memo : defaultdict(dict) or None
|
||||
memo : dict or None
|
||||
A nested dictionary of previously cloned objects. This parameter
|
||||
is used internally and should not be specified by the user.
|
||||
|
||||
|
|
@ -189,17 +192,17 @@ class Surface(object):
|
|||
"""
|
||||
|
||||
if memo is None:
|
||||
memo = defaultdict(dict)
|
||||
memo = {}
|
||||
|
||||
# If no nemoize'd clone exists, instantiate one
|
||||
if self.id not in memo['surfaces']:
|
||||
if self not in memo:
|
||||
clone = deepcopy(self)
|
||||
clone.id = None
|
||||
|
||||
# Memoize the clone
|
||||
memo['surfaces'][self.id] = clone
|
||||
memo[self] = clone
|
||||
|
||||
return memo['surfaces'][self.id]
|
||||
return memo[self]
|
||||
|
||||
def to_xml_element(self):
|
||||
"""Return XML representation of the surface
|
||||
|
|
@ -1938,7 +1941,7 @@ class Halfspace(Region):
|
|||
|
||||
Parameters
|
||||
----------
|
||||
memo : defaultdict(dict) or None
|
||||
memo : dict or None
|
||||
A nested dictionary of previously cloned objects. This parameter
|
||||
is used internally and should not be specified by the user.
|
||||
|
||||
|
|
@ -1950,7 +1953,7 @@ class Halfspace(Region):
|
|||
"""
|
||||
|
||||
if memo is None:
|
||||
memo = defaultdict(dict)
|
||||
memo = dict
|
||||
|
||||
clone = deepcopy(self)
|
||||
clone.surface = self.surface.clone(memo)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from __future__ import division
|
||||
from collections import OrderedDict, Iterable, defaultdict
|
||||
from collections import OrderedDict, Iterable
|
||||
from copy import copy, deepcopy
|
||||
from numbers import Integral, Real
|
||||
import random
|
||||
|
|
@ -523,7 +523,7 @@ class Universe(object):
|
|||
|
||||
Parameters
|
||||
----------
|
||||
memo : defaultdict(dict) or None
|
||||
memo : dict or None
|
||||
A nested dictionary of previously cloned objects. This parameter
|
||||
is used internally and should not be specified by the user.
|
||||
|
||||
|
|
@ -535,10 +535,10 @@ class Universe(object):
|
|||
"""
|
||||
|
||||
if memo is None:
|
||||
memo = defaultdict(dict)
|
||||
memo = {}
|
||||
|
||||
# If no nemoize'd clone exists, instantiate one
|
||||
if self.id not in memo['universes']:
|
||||
if self not in memo:
|
||||
clone = deepcopy(self)
|
||||
clone.id = None
|
||||
|
||||
|
|
@ -548,9 +548,9 @@ class Universe(object):
|
|||
clone.add_cell(cell.clone(memo))
|
||||
|
||||
# Memoize the clone
|
||||
memo['universes'][self.id] = clone
|
||||
memo[self] = clone
|
||||
|
||||
return memo['universes'][self.id]
|
||||
return memo[self]
|
||||
|
||||
def create_xml_subelement(self, xml_element):
|
||||
# Iterate over all Cells
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue