From 8c0d269843bb222a61e46e488a96b3b58c5def6e Mon Sep 17 00:00:00 2001 From: "wbinventor@gmail.com" Date: Wed, 25 Nov 2015 13:44:20 -0500 Subject: [PATCH 1/5] Commented out material density and nuclides comparision on __eq__ - need to confer with @paulromano on how to properly implement this --- openmc/material.py | 18 ++++++++++-------- openmc/universe.py | 6 ++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/openmc/material.py b/openmc/material.py index caad3a1cd6..5138cc59e2 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -90,14 +90,16 @@ 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: This won't work since OpenMC only outputs densities in units + # of atom/b-cm in summary.h5 irregardless of input units, and it we + # cannot compute the sum percent in Python since we lack AWR + # elif self.density != other.density: + # return False + # FIXME: The nuclide densities are different in summary.h5??? + # elif self._nuclides != other._nuclides: + # return False + # elif self._elements != other._elements: + # return False elif self._sab != other._sab: return False else: diff --git a/openmc/universe.py b/openmc/universe.py index 1fb29e2603..0eb77cdf9a 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -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: From a7c923a82c8bfc6debc3042de9c886a7d8d52b7b Mon Sep 17 00:00:00 2001 From: "wbinventor@gmail.com" Date: Wed, 25 Nov 2015 14:15:54 -0500 Subject: [PATCH 2/5] The openmc geometry setter for the mgxs library now clears any old opencg geometry --- openmc/mgxs/library.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openmc/mgxs/library.py b/openmc/mgxs/library.py index fa49d24e64..0bf9732549 100644 --- a/openmc/mgxs/library.py +++ b/openmc/mgxs/library.py @@ -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: From 4be3c64da91ac224c1f4ff2056cf68253589eed5 Mon Sep 17 00:00:00 2001 From: "wbinventor@gmail.com" Date: Sun, 29 Nov 2015 09:00:47 -0500 Subject: [PATCH 3/5] Added __hash__ routines to all Python classes based on __repr__ methods --- openmc/element.py | 2 +- openmc/filter.py | 2 +- openmc/geometry.py | 2 +- openmc/material.py | 3 +++ openmc/mesh.py | 3 +++ openmc/nuclide.py | 2 +- openmc/tallies.py | 16 +--------------- openmc/universe.py | 12 ++++++++++++ 8 files changed, 23 insertions(+), 19 deletions(-) diff --git a/openmc/element.py b/openmc/element.py index d395b434f7..cdc422ed2b 100644 --- a/openmc/element.py +++ b/openmc/element.py @@ -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) diff --git a/openmc/filter.py b/openmc/filter.py index 2c4915f511..4c058c0855 100644 --- a/openmc/filter.py +++ b/openmc/filter.py @@ -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)) diff --git a/openmc/geometry.py b/openmc/geometry.py index e848e0cddf..c0b248780e 100644 --- a/openmc/geometry.py +++ b/openmc/geometry.py @@ -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 diff --git a/openmc/material.py b/openmc/material.py index 5138cc59e2..88c8443086 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -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) diff --git a/openmc/mesh.py b/openmc/mesh.py index 3b66076b79..b963a25a8e 100644 --- a/openmc/mesh.py +++ b/openmc/mesh.py @@ -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) diff --git a/openmc/nuclide.py b/openmc/nuclide.py index 2dd8eb1534..b95601bf7d 100644 --- a/openmc/nuclide.py +++ b/openmc/nuclide.py @@ -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) diff --git a/openmc/tallies.py b/openmc/tallies.py index 0661ab67b1..8498fbb5b5 100644 --- a/openmc/tallies.py +++ b/openmc/tallies.py @@ -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' diff --git a/openmc/universe.py b/openmc/universe.py index 0eb77cdf9a..9a8262af39 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -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) From f09ec9582b731500d19405957b88c998cfd77f5d Mon Sep 17 00:00:00 2001 From: "wbinventor@gmail.com" Date: Sun, 29 Nov 2015 09:06:25 -0500 Subject: [PATCH 4/5] Shortened FIXME block in Material.__eq__ --- openmc/material.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/openmc/material.py b/openmc/material.py index 88c8443086..9e0a6b93b3 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -90,16 +90,15 @@ class Material(object): return False elif self.name != other.name: return False - # FIXME: This won't work since OpenMC only outputs densities in units - # of atom/b-cm in summary.h5 irregardless of input units, and it we + # 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: + #elif self.density != other.density: # return False - # FIXME: The nuclide densities are different in summary.h5??? - # elif self._nuclides != other._nuclides: - # return False - # elif self._elements != other._elements: + #elif self._nuclides != other._nuclides: # return False + #elif self._elements != other._elements: + # return False elif self._sab != other._sab: return False else: From d26a86f5f1862c34ae4444a8dfca926471c6ccda Mon Sep 17 00:00:00 2001 From: "wbinventor@gmail.com" Date: Sun, 29 Nov 2015 09:13:28 -0500 Subject: [PATCH 5/5] Reverted to set notation in Geometry.get_all_material_cells() now that __hash__ is implemented everywhere --- openmc/geometry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openmc/geometry.py b/openmc/geometry.py index c0b248780e..e848e0cddf 100644 --- a/openmc/geometry.py +++ b/openmc/geometry.py @@ -147,7 +147,7 @@ class Geometry(object): if cell._type == 'normal': material_cells.add(cell) - material_cells = list(set(material_cells)) + material_cells = list(material_cells) material_cells.sort(key=lambda x: x.id) return material_cells