Fix OpenCG compatibility module to work with simple cells

This commit is contained in:
Paul Romano 2015-09-29 15:07:39 +07:00
parent 6c6676cc14
commit e37d634986

View file

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