def get_openmoc_region(openmc_region): """Return an OpenMOC region corresponding to an OpenMC region. Parameters ---------- openmc_region : openmc.Region OpenMC region Returns ------- openmoc_region : openmoc.Region Equivalent OpenMOC region """ cv.check_type('openmc_region', openmc_region, openmc.Region) # Recursively instantiate a region of the appropriate type if isinstance(openmc_region, openmc.Halfspace): surface = openmc_region.surface halfspace = -1 if openmc_region.side == '-' else 1 openmoc_region = \ openmoc.Halfspace(halfspace, get_openmoc_surface(surface)) elif isinstance(openmc_region, openmc.Intersection): openmoc_region = openmoc.Intersection() for openmc_node in openmc_region: openmoc_region.addNode(get_openmoc_region(openmc_node)) elif isinstance(openmc_region, openmc.Union): openmoc_region = openmoc.Union() for openmc_node in openmc_region: openmoc_region.addNode(get_openmoc_region(openmc_node)) elif isinstance(openmc_region, openmc.Complement): openmoc_region = openmoc.Complement() openmoc_region.addNode(get_openmoc_region(openmc_region.node)) return openmoc_region
def test_union(self): union = openmoc.Union() # Define surfaces p1x = openmoc.XPlane(x=3) p2x = openmoc.XPlane(x=-2) p1y = openmoc.YPlane(y=1) p2y = openmoc.YPlane(y=-0.5) p1z = openmoc.ZPlane(z=8) p2z = openmoc.ZPlane(z=-4) # Define boundary types p1x.setBoundaryType(openmoc.VACUUM) p2x.setBoundaryType(openmoc.REFLECTIVE) p1y.setBoundaryType(openmoc.PERIODIC) p2y.setBoundaryType(openmoc.REFLECTIVE) p1z.setBoundaryType(openmoc.PERIODIC) p2z.setBoundaryType(openmoc.VACUUM) # Define halfspaces h1x = openmoc.Halfspace(-1, p1x) h2x = openmoc.Halfspace(+1, p2x) h1y = openmoc.Halfspace(-1, p1y) h2y = openmoc.Halfspace(+1, p2y) h1z = openmoc.Halfspace(-1, p1z) h2z = openmoc.Halfspace(+1, p2z) # Test getMaxXYZ + MaxXYZboundary union.addNode(h1x, True) self.assertEqual(union.getMaxX(), 3) self.assertEqual(union.getMaxXBoundaryType(), openmoc.VACUUM) #union.removeHalfspace(p1x, -1) #FIXME seg faults union = openmoc.Union() union.addNode(h1y) self.assertEqual(union.getMaxY(), 1) self.assertEqual(union.getMaxYBoundaryType(), openmoc.PERIODIC) #union.removeHalfspace(p1y, -1) union = openmoc.Union() union.addNode(h1z) self.assertEqual(union.getMaxZ(), 8) self.assertEqual(union.getMaxZBoundaryType(), openmoc.PERIODIC) #union.removeHalfspace(p1z, -1) # Test getMinXYZ + MinXYZboundary union = openmoc.Union() union.addNode(h2x) self.assertEqual(union.getMinX(), -2) self.assertEqual(union.getMinXBoundaryType(), openmoc.REFLECTIVE) #union.removeHalfspace(h2x) union = openmoc.Union() union.addNode(h2y) self.assertEqual(union.getMinY(), -0.5) self.assertEqual(union.getMinYBoundaryType(), openmoc.REFLECTIVE) #union.removeHalfspace(h2y) union = openmoc.Union() union.addNode(h2z) self.assertEqual(union.getMinZ(), -4) self.assertEqual(union.getMinZBoundaryType(), openmoc.VACUUM)
def test_parent(self): region = openmoc.Union() self.assertEqual(region.getParentRegion(), None) region.setParentRegion(openmoc.Union()) self.assertNotEqual(region.getParentRegion(), None)