mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 06:05:58 -04:00
Added __hash__ routines to all Python classes based on __repr__ methods
This commit is contained in:
parent
a7c923a82c
commit
4be3c64da9
8 changed files with 23 additions and 19 deletions
|
|
@ -58,7 +58,7 @@ class Element(object):
|
|||
return not self == other
|
||||
|
||||
def __hash__(self):
|
||||
return hash((self._name, self._xs))
|
||||
return hash(str(self))
|
||||
|
||||
def __repr__(self):
|
||||
string = 'Element - {0}\n'.format(self._name)
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ class Filter(object):
|
|||
return not self == other
|
||||
|
||||
def __hash__(self):
|
||||
return hash((self.type, tuple(self.bins)))
|
||||
return hash(str(self))
|
||||
|
||||
def __deepcopy__(self, memo):
|
||||
existing = memo.get(id(self))
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ class Geometry(object):
|
|||
if cell._type == 'normal':
|
||||
material_cells.add(cell)
|
||||
|
||||
material_cells = list(material_cells)
|
||||
material_cells = list(set(material_cells))
|
||||
material_cells.sort(key=lambda x: x.id)
|
||||
return material_cells
|
||||
|
||||
|
|
|
|||
|
|
@ -108,6 +108,9 @@ class Material(object):
|
|||
def __ne__(self, other):
|
||||
return not self == other
|
||||
|
||||
def __hash__(self):
|
||||
return hash(str(self))
|
||||
|
||||
def __repr__(self):
|
||||
string = 'Material\n'
|
||||
string += '{0: <16}{1}{2}\n'.format('\tID', '=\t', self._id)
|
||||
|
|
|
|||
|
|
@ -189,6 +189,9 @@ class Mesh(object):
|
|||
cv.check_length('mesh width', width, 2, 3)
|
||||
self._width = width
|
||||
|
||||
def __hash__(self):
|
||||
return hash(str(self))
|
||||
|
||||
def __repr__(self):
|
||||
string = 'Mesh\n'
|
||||
string += '{0: <16}{1}{2}\n'.format('\tID', '=\t', self._id)
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ class Nuclide(object):
|
|||
return not self == other
|
||||
|
||||
def __hash__(self):
|
||||
return hash((self._name, self._xs))
|
||||
return hash(str(self))
|
||||
|
||||
def __repr__(self):
|
||||
string = 'Nuclide - {0}\n'.format(self._name)
|
||||
|
|
|
|||
|
|
@ -190,21 +190,7 @@ class Tally(object):
|
|||
return not self == other
|
||||
|
||||
def __hash__(self):
|
||||
hashable = []
|
||||
|
||||
for filter in self.filters:
|
||||
hashable.append((filter.type, tuple(filter.bins)))
|
||||
|
||||
for nuclide in self.nuclides:
|
||||
hashable.append(nuclide.name)
|
||||
|
||||
for score in self.scores:
|
||||
hashable.append(score)
|
||||
|
||||
hashable.append(self.estimator)
|
||||
hashable.append(self.name)
|
||||
|
||||
return hash(tuple(hashable))
|
||||
return hash(str(self))
|
||||
|
||||
def __repr__(self):
|
||||
string = 'Tally\n'
|
||||
|
|
|
|||
|
|
@ -94,6 +94,9 @@ class Cell(object):
|
|||
def __ne__(self, other):
|
||||
return not self == other
|
||||
|
||||
def __hash__(self):
|
||||
return hash(str(self))
|
||||
|
||||
def __repr__(self):
|
||||
string = 'Cell\n'
|
||||
string += '{0: <16}{1}{2}\n'.format('\tID', '=\t', self._id)
|
||||
|
|
@ -479,6 +482,9 @@ class Universe(object):
|
|||
def __ne__(self, other):
|
||||
return not self == other
|
||||
|
||||
def __hash__(self):
|
||||
return hash(str(self))
|
||||
|
||||
def __repr__(self):
|
||||
string = 'Universe\n'
|
||||
string += '{0: <16}{1}{2}\n'.format('\tID', '=\t', self._id)
|
||||
|
|
@ -964,6 +970,9 @@ class RectLattice(Lattice):
|
|||
def __ne__(self, other):
|
||||
return not self == other
|
||||
|
||||
def __hash__(self):
|
||||
return hash(str(self))
|
||||
|
||||
def __repr__(self):
|
||||
string = 'RectLattice\n'
|
||||
string += '{0: <16}{1}{2}\n'.format('\tID', '=\t', self._id)
|
||||
|
|
@ -1198,6 +1207,9 @@ class HexLattice(Lattice):
|
|||
def __ne__(self, other):
|
||||
return not self == other
|
||||
|
||||
def __hash__(self):
|
||||
return hash(str(self))
|
||||
|
||||
def __repr__(self):
|
||||
string = 'HexLattice\n'
|
||||
string += '{0: <16}{1}{2}\n'.format('\tID', '=\t', self._id)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue