From cd60109a77dd7a3e6a492ef734684af272fb5cce Mon Sep 17 00:00:00 2001 From: shimwell Date: Wed, 13 Jul 2022 19:14:14 +0100 Subject: [PATCH] added bounding_region --- openmc/universe.py | 43 +++++++++++++++++++ .../regression_tests/dagmc/universes/test.py | 14 ++++++ 2 files changed, 57 insertions(+) diff --git a/openmc/universe.py b/openmc/universe.py index b65263ef9..2fd931506 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -713,6 +713,49 @@ class DAGMCUniverse(UniverseBase): dagmc_element.set('filename', self.filename) xml_element.append(dagmc_element) + def bounding_region(self, bounded_type='box', boundary_type='vacuum'): + """Creates a either a spherical or box shaped bounding region around + the DAGMC geometry. + Parameters + ---------- + bounded_type : str + The type of bounding surface(s) to use when constructing the region. + Options include a single spherical surface (sphere) or a rectangle + made from siz planes (box). + boundary_type : str + Boundary condition that defines the behavior for particles hitting + the surface. Defaults to vacuum boundary condition. Passed into + Returns + ------- + openmc.Region + Region instance + """ + + bounding_box = self.bounding_box + + if bounded_type == 'sphere': + import math + bounding_box_center = (bounding_box[0] + bounding_box[1])/2 + radius = math.dist(bounding_box[0], bounding_box[1]) + bounding_surface = openmc.Sphere(x0=bounding_box_center[0], y0=bounding_box_center[1], z0=bounding_box_center[2], r=radius) + + return -bounding_surface + + if bounded_type == 'box': + # defines plane surfaces for all six faces of the bounding box + lower_x = openmc.XPlane(bounding_box[0][0], boundary_type=boundary_type) + upper_x = openmc.XPlane(bounding_box[1][0], boundary_type=boundary_type) + lower_y = openmc.YPlane(bounding_box[0][1], boundary_type=boundary_type) + upper_y = openmc.YPlane(bounding_box[1][1], boundary_type=boundary_type) + lower_z = openmc.ZPlane(bounding_box[0][2], boundary_type=boundary_type) + upper_z = openmc.ZPlane(bounding_box[1][2], boundary_type=boundary_type) + + return +lower_x & -upper_x & +lower_y & -upper_y & +lower_z & -upper_z + + def bounded_universe(self, **kwargs): + bounding_cell = openmc.Cell(fill=self, region=self.bounding_region(**kwargs)) + return openmc.Universe(cells=[bounding_cell]) + @classmethod def from_hdf5(cls, group): """Create DAGMC universe from HDF5 group diff --git a/tests/regression_tests/dagmc/universes/test.py b/tests/regression_tests/dagmc/universes/test.py index 6726b4b44..f6964857d 100644 --- a/tests/regression_tests/dagmc/universes/test.py +++ b/tests/regression_tests/dagmc/universes/test.py @@ -51,6 +51,20 @@ class DAGMCUniverseTest(PyAPITestHarness): assert bounding_box[0].tolist() == [-25., -25., -25.] assert bounding_box[1].tolist() == [25., 25., 25.] + # checks that the bounding region is six surfaces each with a vacuum boundary type + b_region = pincell_univ.bounding_region(bounded_type='box', boundary_type='vacuum') + assert isinstance(b_region, openmc.Region) + assert len(b_region.get_surfaces()) == 6 + for surface in list(b_region.get_surfaces().values()): + assert surface.boundary_type == 'vacuum' + + # checks that the bounding region is a single surface with a reflective boundary type + b_region = pincell_univ.bounding_region(bounded_type='sphere', boundary_type='reflective') + assert isinstance(b_region, openmc.Region) + assert len(b_region.get_surfaces()) == 1 + for surface in list(b_region.get_surfaces().values()): + assert surface.boundary_type == 'reflective' + # create a 2 x 2 lattice using the DAGMC pincell pitch = np.asarray((24.0, 24.0)) lattice = openmc.RectLattice()