From 77d40effb15aad4ee9d39883ca7b9bac8db75c0b Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 15 Jul 2019 14:35:02 -0500 Subject: [PATCH] Adding a test for complex cell bounding boxes. --- openmc/capi/cell.py | 8 +++++++ tests/regression_tests/complex_cell/test.py | 25 +++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/openmc/capi/cell.py b/openmc/capi/cell.py index 5f38e823e..1388d9732 100644 --- a/openmc/capi/cell.py +++ b/openmc/capi/cell.py @@ -183,6 +183,14 @@ class Cell(_FortranObjectWithID): _dll.openmc_cell_set_temperature(self._index, T, instance) + @property + def bounding_box(self): + llc = np.zeros((3,), dtype=float) + urc = np.zeros((3,), dtype=float) + _dll.openmc_bounding_box(b'Cell', self.id, + llc.ctypes.data_as(POINTER(c_double)), + urc.ctypes.data_as(POINTER(c_double))) + return llc, urc class _CellMapping(Mapping): def __getitem__(self, key): diff --git a/tests/regression_tests/complex_cell/test.py b/tests/regression_tests/complex_cell/test.py index 77cbd6cb7..816902b4c 100755 --- a/tests/regression_tests/complex_cell/test.py +++ b/tests/regression_tests/complex_cell/test.py @@ -1,6 +1,31 @@ from tests.testing_harness import TestHarness +import sys + +import openmc.capi def test_complex_cell(): harness = TestHarness('statepoint.10.h5') harness.main() + +def test_complex_cell_capi(): + # initialize + openmc.capi.init([]) + + inf = sys.float_info.max + + expected_boxes = { 1 : (( -4., -4., -inf), ( 4., 4., inf)), + 2 : (( -7., -7., -inf), ( 7., 7., inf)), + 3 : ((-10., -10., -inf), (10., 10., inf)), + 4 : ((-10., -10., -inf), (10., 10., inf)) } + + for cell_id, cell in openmc.capi.cells.items(): + cell_box = cell.bounding_box + + assert tuple(cell_box[0]) == expected_boxes[cell_id][0] + assert tuple(cell_box[1]) == expected_boxes[cell_id][1] + + cell_box = openmc.capi.bounding_box("Cell", cell_id) + + assert tuple(cell_box[0]) == expected_boxes[cell_id][0] + assert tuple(cell_box[1]) == expected_boxes[cell_id][1]