From 6c78d129c3db8b09b0e8b21cb3a4965460127666 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 12 Jul 2022 15:49:40 +0100 Subject: [PATCH 1/4] added bbox by @pshriwise --- openmc/universe.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/openmc/universe.py b/openmc/universe.py index f3f95aebbe..bb1554de89 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -7,6 +7,7 @@ from pathlib import Path from tempfile import TemporaryDirectory from xml.etree import ElementTree as ET +import h5py import numpy as np import openmc @@ -630,6 +631,9 @@ class DAGMCUniverse(UniverseBase): auto_mat_ids : bool Set IDs automatically on initialization (True) or report overlaps in ID space between OpenMC and UWUW materials (False) + bounding_box : 2-tuple of numpy.array + Lower-left and upper-right coordinates of an axis-aligned bounding box + of the universe. """ def __init__(self, @@ -650,6 +654,15 @@ class DAGMCUniverse(UniverseBase): string += '{: <16}=\t{}\n'.format('\tFile', self.filename) return string + @property + def bounding_box(self): + dagmc_file = h5py.File(self.filename) + coords = dagmc_file['tstt']['nodes']['coordinates'][()] + lower_left_corner = coords.min(axis=0) + upper_right_corner = coords.max(axis=0) + bounding_box = (lower_left_corner, upper_right_corner) + return bounding_box + @property def filename(self): return self._filename From 48a3484c39ebd5737e1ced1a576160b0efb78c69 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Tue, 12 Jul 2022 16:36:43 +0100 Subject: [PATCH 2/4] context manager review suggestion from @pshriwise --- openmc/universe.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/openmc/universe.py b/openmc/universe.py index bb1554de89..e7be468223 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -656,12 +656,12 @@ class DAGMCUniverse(UniverseBase): @property def bounding_box(self): - dagmc_file = h5py.File(self.filename) - coords = dagmc_file['tstt']['nodes']['coordinates'][()] - lower_left_corner = coords.min(axis=0) - upper_right_corner = coords.max(axis=0) - bounding_box = (lower_left_corner, upper_right_corner) - return bounding_box + with h5py.File(self.filename) as dagmc_file: + coords = dagmc_file['tstt']['nodes']['coordinates'][()] + lower_left_corner = coords.min(axis=0) + upper_right_corner = coords.max(axis=0) + bounding_box = (lower_left_corner, upper_right_corner) + return bounding_box @property def filename(self): From 8b06863b37ff3a258080a33058ceb9311f15dea3 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Tue, 12 Jul 2022 16:52:02 +0100 Subject: [PATCH 3/4] added dagmc bounding box test --- tests/regression_tests/dagmc/universes/test.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/regression_tests/dagmc/universes/test.py b/tests/regression_tests/dagmc/universes/test.py index 01963986c5..6726b4b448 100644 --- a/tests/regression_tests/dagmc/universes/test.py +++ b/tests/regression_tests/dagmc/universes/test.py @@ -46,6 +46,11 @@ class DAGMCUniverseTest(PyAPITestHarness): # create the DAGMC universe pincell_univ = openmc.DAGMCUniverse(filename='dagmc.h5m', auto_geom_ids=True) + # checks that the bounding box is calculated correctly + bounding_box = pincell_univ.bounding_box + assert bounding_box[0].tolist() == [-25., -25., -25.] + assert bounding_box[1].tolist() == [25., 25., 25.] + # create a 2 x 2 lattice using the DAGMC pincell pitch = np.asarray((24.0, 24.0)) lattice = openmc.RectLattice() From 4784be1fc96d5b688681bedf22c752a55b719b0a Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Tue, 12 Jul 2022 21:03:24 +0100 Subject: [PATCH 4/4] review line removal from @paulromano Co-authored-by: Paul Romano --- openmc/universe.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/openmc/universe.py b/openmc/universe.py index e7be468223..b65263ef9c 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -660,8 +660,7 @@ class DAGMCUniverse(UniverseBase): coords = dagmc_file['tstt']['nodes']['coordinates'][()] lower_left_corner = coords.min(axis=0) upper_right_corner = coords.max(axis=0) - bounding_box = (lower_left_corner, upper_right_corner) - return bounding_box + return (lower_left_corner, upper_right_corner) @property def filename(self):