def bounding_box(self): regions = [ c.region for c in self.cells.values() if c.region is not None ] if regions: return openmc.Union(*regions).bounding_box else: # Infinite bounding box return openmc.Intersection().bounding_box
def __init__(self, domains, samples, lower_left=None, upper_right=None): self._atoms = {} self._volumes = {} self._threshold = None self._trigger_type = None self._iterations = None cv.check_type('domains', domains, Iterable, (openmc.Cell, openmc.Material, openmc.Universe)) if isinstance(domains[0], openmc.Cell): self._domain_type = 'cell' elif isinstance(domains[0], openmc.Material): self._domain_type = 'material' elif isinstance(domains[0], openmc.Universe): self._domain_type = 'universe' self.ids = [d.id for d in domains] self.samples = samples if lower_left is not None: if upper_right is None: raise ValueError('Both lower-left and upper-right coordinates ' 'should be specified') # For cell domains, try to compute bounding box and make sure # user-specified one is valid if self.domain_type == 'cell': for c in domains: ll, ur = c.bounding_box if np.any(np.isinf(ll)) or np.any(np.isinf(ur)): continue if (np.any(np.asarray(lower_left) > ll) or np.any(np.asarray(upper_right) < ur)): warnings.warn( "Specified bounding box is smaller than computed " "bounding box for cell {}. Volume calculation may " "be incorrect!".format(c.id)) self.lower_left = lower_left self.upper_right = upper_right else: if self.domain_type == 'cell': ll, ur = openmc.Union(c.region for c in domains).bounding_box if np.any(np.isinf(ll)) or np.any(np.isinf(ur)): raise ValueError( 'Could not automatically determine bounding ' 'box for stochastic volume calculation.') else: self.lower_left = ll self.upper_right = ur else: raise ValueError( 'Could not automatically determine bounding box ' 'for stochastic volume calculation.')
def get_openmc_region(openmoc_region): """Return an OpenMC region corresponding to an OpenMOC region. Parameters ---------- openmoc_region : openmoc.Region OpenMOC region Returns ------- openmc_region : openmc.Region Equivalent OpenMC region """ cv.check_type('openmoc_region', openmoc_region, openmoc.Region) # Recursively instantiate a region of the appropriate type 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 '+' openmc_region = openmc.Halfspace(surface, side) elif openmoc_region.getRegionType() == openmoc.INTERSECTION: openmc_region = openmc.Intersection([]) for openmoc_node in openmoc_region.getNodes(): openmc_node = get_openmc_region(openmoc_node) openmc_region.append(openmc_node) elif openmoc_region.getRegionType() == openmoc.UNION: openmc_region = openmc.Union([]) for openmoc_node in openmoc_region.getNodes(): openmc_node = get_openmc_region(openmoc_node) openmc_region.append(openmc_node) elif openmoc_region.getRegionType() == openmoc.COMPLEMENT: openmoc_nodes = openmoc_region.getNodes() openmc_node = get_openmc_region(openmoc_nodes[0]) openmc_region = openmc.Complement(openmc_node) return openmc_region