Merge branch 'pyapi-__eq__' into mgxs-ipython-notebooks

This commit is contained in:
wbinventor@gmail.com 2015-11-30 22:52:23 -05:00
commit 1697dce546
8 changed files with 34 additions and 31 deletions

View file

@ -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)

View file

@ -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))

View file

@ -90,14 +90,15 @@ class Material(object):
return False
elif self.name != other.name:
return False
elif self.density != other.density:
return False
elif self.density_units != other.density_units:
return False
elif self._nuclides != other.nuclides:
return False
elif self._elements != other._elements:
return False
# FIXME: We cannot compare densities since OpenMC outputs densities
# in atom/b-cm in summary.h5 irregardless of input units, and we
# cannot compute the sum percent in Python since we lack AWR
#elif self.density != other.density:
# return False
#elif self._nuclides != other._nuclides:
# return False
#elif self._elements != other._elements:
# return False
elif self._sab != other._sab:
return False
else:
@ -106,6 +107,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)

View file

@ -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)

View file

@ -203,6 +203,7 @@ class Library(object):
def openmc_geometry(self, openmc_geometry):
cv.check_type('openmc_geometry', openmc_geometry, openmc.Geometry)
self._openmc_geometry = openmc_geometry
self._opencg_geometry = None
@name.setter
def name(self, name):
@ -362,7 +363,6 @@ class Library(object):
self._sp_filename = statepoint._f.filename
self._openmc_geometry = statepoint.summary.openmc_geometry
self._opencg_geometry = None
# Load tallies for each MGXS for each domain and mgxs type
for domain in self.domains:

View file

@ -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)

View file

@ -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'

View file

@ -80,10 +80,8 @@ class Cell(object):
return False
elif self.name != other.name:
return False
# FIXME: This won't work for materials fills since OpenMC only outputs
# nuclide densities in units of atom/b-cm irregardless of input units
# elif self.fill != other.fill:
# return False
elif self.fill != other.fill:
return False
elif self.region != other.region:
return False
elif self.rotation != other.rotation:
@ -96,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)
@ -481,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)
@ -966,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)
@ -1200,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)