From e37d63498676d0fc3219dbe4bd6c73573dbb256b Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Tue, 29 Sep 2015 15:07:39 +0700 Subject: [PATCH] Fix OpenCG compatibility module to work with simple cells --- openmc/opencg_compatible.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/openmc/opencg_compatible.py b/openmc/opencg_compatible.py index 65e980c003..9439a6eaf4 100644 --- a/openmc/opencg_compatible.py +++ b/openmc/opencg_compatible.py @@ -9,6 +9,8 @@ except ImportError: raise ImportError(msg) import openmc +from openmc.region import Intersection +from openmc.surface import Halfspace # A dictionary of all OpenMC Materials created @@ -480,12 +482,24 @@ def get_opencg_cell(openmc_cell): if openmc_cell._translation is not None: opencg_cell.setTranslation(openmc_cell._translation) - surfaces = openmc_cell._surfaces - - for surface_id in surfaces: - surface = surfaces[surface_id][0] - halfspace = surfaces[surface_id][1] + # Add surfaces to OpenCG cell from OpenMC cell region. Right now this only + # works if the region is a single half-space or an intersection of + # half-spaces, i.e., no complex cells. + region = openmc_cell.region + if isinstance(region, Halfspace): + surface = region.surface + halfspace = -1 if region.side == '-' else 1 opencg_cell.addSurface(get_opencg_surface(surface), halfspace) + elif isinstance(region, Intersection): + for node in region.nodes: + if not isinstance(node, Halfspace): + raise NotImplementedError("Complex cells not yet supported " + "in OpenCG.") + surface = node.surface + halfspace = -1 if node.side == '-' else 1 + opencg_cell.addSurface(get_opencg_surface(surface), halfspace) + else: + raise NotImplementedError("Complex cells not yet supported in OpenCG.") # Add the OpenMC Cell to the global collection of all OpenMC Cells OPENMC_CELLS[cell_id] = openmc_cell