From 822008bf587c33059014440421457c0beb13eadc Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Thu, 11 May 2017 14:04:58 -0400 Subject: [PATCH 1/4] Fixed OpenMOC compatiblity for generic planar surfaces; fixed OpenMOC-MC lattice universes conversion --- openmc/openmoc_compatible.py | 20 +++++++++++++++++--- openmc/universe.py | 13 ++++++++++--- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/openmc/openmoc_compatible.py b/openmc/openmoc_compatible.py index 98012fae96..996da2461c 100644 --- a/openmc/openmoc_compatible.py +++ b/openmc/openmoc_compatible.py @@ -363,6 +363,13 @@ def get_openmoc_region(openmc_region): if isinstance(openmc_region, openmc.Halfspace): surface = openmc_region.surface halfspace = -1 if openmc_region.side == '-' else 1 + + # OpenMOC implements generic planes using the opposite notation + # for halfspaces as OpenMC, so correct for that here + openmoc_surface = get_openmoc_surface(surface) + if openmoc_surface.getSurfaceType() == openmoc.PLANE: + halfspace *= -1 + openmoc_region = \ openmoc.Halfspace(halfspace, get_openmoc_surface(surface)) elif isinstance(openmc_region, openmc.Intersection): @@ -401,8 +408,16 @@ def get_openmc_region(openmoc_region): if openmoc_region.getRegionType() == openmoc.HALFSPACE: openmoc_region = openmoc.castRegionToHalfspace(openmoc_region) surface = get_openmc_surface(openmoc_region.getSurface()) - side = '-' if openmoc_region.getHalfspace() == -1 else '+' + + # OpenMOC implements generic planes using the opposite notation + # for halfspaces as OpenMC, so correct for that here + if openmoc_region.getSurface().getSurfaceType() == openmoc.PLANE: + side = '+' if openmoc_region.getHalfspace() == -1 else '-' + else: + side = '-' if openmoc_region.getHalfspace() == -1 else '+' + openmc_region = openmc.Halfspace(surface, side) + elif openmoc_region.getRegionType() == openmoc.INTERSECTION: openmc_region = openmc.Intersection() for openmoc_node in openmoc_region.getNodes(): @@ -708,8 +723,7 @@ def get_openmc_lattice(openmoc_lattice): universe_array[x][y][z] = \ unique_universes[universe_id] - universe_array = np.swapaxes(universe_array, 0, 1) - universe_array = universe_array[::-1, :, :] + universe_array = np.swapaxes(universe_array, 0, 2) # Convert axially infinite 3D OpenMOC lattice to a 2D OpenMC lattice if width[2] == np.finfo(np.float64).max: diff --git a/openmc/universe.py b/openmc/universe.py index c955934f2a..e69bbd7c41 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -76,10 +76,17 @@ class Universe(object): return False elif self.name != other.name: return False - elif self.cells != other.cells: + elif len(self.cells) != len(other.cells): return False - else: - return True + + # Check each cell + for cell_id in self.cells: + if cell_id not in other.cells: + return False + if self.cells[cell_id] != other.cells[cell_id]: + return False + + return True def __ne__(self, other): return not self == other From e3052fd315b3e4f6f8725e9182647c819ebfcfb7 Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Thu, 11 May 2017 21:45:43 -0400 Subject: [PATCH 2/4] Revised OpenMOC fix planes by reversing sign for D coefficient --- openmc/openmoc_compatible.py | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/openmc/openmoc_compatible.py b/openmc/openmoc_compatible.py index 996da2461c..21dc4b6a69 100644 --- a/openmc/openmoc_compatible.py +++ b/openmc/openmoc_compatible.py @@ -172,7 +172,9 @@ def get_openmoc_surface(openmc_surface): B = openmc_surface.b C = openmc_surface.c D = openmc_surface.d - openmoc_surface = openmoc.Plane(A, B, C, D, surface_id, name) + + # OpenMOC uses the opposite sign on D + openmoc_surface = openmoc.Plane(A, B, C, -D, surface_id, name) elif openmc_surface.type == 'x-plane': x0 = openmc_surface.x0 @@ -253,7 +255,9 @@ def get_openmc_surface(openmoc_surface): B = openmoc_surface.getB() C = openmoc_surface.getC() D = openmoc_surface.getD() - openmc_surface = openmc.Plane(surface_id, boundary, A, B, C, D, name) + + # OpenMOC uses the opposite sign on D + openmc_surface = openmc.Plane(surface_id, boundary, A, B, C, -D, name) elif openmoc_surface.getSurfaceType() == openmoc.XPLANE: openmoc_surface = openmoc.castSurfaceToXPlane(openmoc_surface) @@ -363,13 +367,6 @@ def get_openmoc_region(openmc_region): if isinstance(openmc_region, openmc.Halfspace): surface = openmc_region.surface halfspace = -1 if openmc_region.side == '-' else 1 - - # OpenMOC implements generic planes using the opposite notation - # for halfspaces as OpenMC, so correct for that here - openmoc_surface = get_openmoc_surface(surface) - if openmoc_surface.getSurfaceType() == openmoc.PLANE: - halfspace *= -1 - openmoc_region = \ openmoc.Halfspace(halfspace, get_openmoc_surface(surface)) elif isinstance(openmc_region, openmc.Intersection): @@ -408,16 +405,8 @@ def get_openmc_region(openmoc_region): if openmoc_region.getRegionType() == openmoc.HALFSPACE: openmoc_region = openmoc.castRegionToHalfspace(openmoc_region) surface = get_openmc_surface(openmoc_region.getSurface()) - - # OpenMOC implements generic planes using the opposite notation - # for halfspaces as OpenMC, so correct for that here - if openmoc_region.getSurface().getSurfaceType() == openmoc.PLANE: - side = '+' if openmoc_region.getHalfspace() == -1 else '-' - else: - side = '-' if openmoc_region.getHalfspace() == -1 else '+' - + side = '-' if openmoc_region.getHalfspace() == -1 else '+' openmc_region = openmc.Halfspace(surface, side) - elif openmoc_region.getRegionType() == openmoc.INTERSECTION: openmc_region = openmc.Intersection() for openmoc_node in openmoc_region.getNodes(): From 572000419d9955fb1575c3ce72fd76741cbe09be Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Fri, 12 May 2017 08:29:01 -0400 Subject: [PATCH 3/4] Simplified Universe equality operator per @paulromano suggestion --- openmc/lattice.py | 6 +++--- openmc/universe.py | 13 +++---------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/openmc/lattice.py b/openmc/lattice.py index 3bb6e825e1..be5f22db93 100644 --- a/openmc/lattice.py +++ b/openmc/lattice.py @@ -56,11 +56,11 @@ class Lattice(object): return False elif self.name != other.name: return False - elif self.pitch != other.pitch: + elif np.any(self.pitch != other.pitch): return False elif self.outer != other.outer: return False - elif self.universes != other.universes: + elif np.any(self.universes != other.universes): return False else: return True @@ -533,7 +533,7 @@ class RectLattice(Lattice): return False elif self.shape != other.shape: return False - elif self.lower_left != other.lower_left: + elif np.any(self.lower_left != other.lower_left): return False else: return True diff --git a/openmc/universe.py b/openmc/universe.py index e69bbd7c41..006a77a54d 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -76,17 +76,10 @@ class Universe(object): return False elif self.name != other.name: return False - elif len(self.cells) != len(other.cells): + elif dict.__eq__(self.cells, other.cells): return False - - # Check each cell - for cell_id in self.cells: - if cell_id not in other.cells: - return False - if self.cells[cell_id] != other.cells[cell_id]: - return False - - return True + else: + return True def __ne__(self, other): return not self == other From d5a6be95b512589fa0392d243d404c7d87abc841 Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Fri, 12 May 2017 15:36:48 -0400 Subject: [PATCH 4/4] Fixed issue in Universe.__eq__ per comment by @paulromano --- openmc/universe.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openmc/universe.py b/openmc/universe.py index 006a77a54d..d36b167a51 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -76,7 +76,7 @@ class Universe(object): return False elif self.name != other.name: return False - elif dict.__eq__(self.cells, other.cells): + elif dict.__ne__(self.cells, other.cells): return False else: return True