From 36ecaf9bd6a7fa4e51281881921f3506020a5f38 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 10 Aug 2022 09:19:08 -0500 Subject: [PATCH 1/9] Adding ability to specify starting ID for surfaces of the DAGMC bounding region --- openmc/universe.py | 45 ++++++++++++------- .../dagmc/universes/inputs_true.dat | 14 +++--- .../regression_tests/dagmc/universes/test.py | 5 ++- 3 files changed, 39 insertions(+), 25 deletions(-) diff --git a/openmc/universe.py b/openmc/universe.py index 3ef9e66509..aef4d660bb 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -2,7 +2,7 @@ from abc import ABC, abstractmethod from collections import OrderedDict from collections.abc import Iterable from copy import deepcopy -from numbers import Real +from numbers import Integral, Real from pathlib import Path from tempfile import TemporaryDirectory from xml.etree import ElementTree as ET @@ -723,7 +723,7 @@ class DAGMCUniverse(UniverseBase): dagmc_element.set('filename', self.filename) xml_element.append(dagmc_element) - def bounding_region(self, bounded_type='box', boundary_type='vacuum'): + def bounding_region(self, bounded_type='box', boundary_type='vacuum', starting_id=10000): """Creates a either a spherical or box shaped bounding region around the DAGMC geometry. Parameters @@ -736,6 +736,10 @@ class DAGMCUniverse(UniverseBase): Boundary condition that defines the behavior for particles hitting the surface. Defaults to vacuum boundary condition. Passed into the surface construction. + starting_id : int + Starting ID of the surface(s) used in the region. For bounded_type + 'box', the next 5 IDs will also be used. Defaults to 10000 to reduce + the chance of an overlap of surface IDs with the DAGMC geometry. Returns ------- openmc.Region @@ -744,19 +748,21 @@ class DAGMCUniverse(UniverseBase): check_type('boundary type', boundary_type, str) check_value('boundary type', boundary_type, _BOUNDARY_TYPES) + check_type('starting surface id', starting_id, Integral) check_type('bounded type', bounded_type, str) check_value('bounded type', bounded_type, ('box', 'sphere')) - bounding_box = self.bounding_box + bbox = 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]) + bbox_center = (bbox[0] + bbox[1])/2 + radius = math.dist(bbox[0], bbox[1]) bounding_surface = openmc.Sphere( - x0=bounding_box_center[0], - y0=bounding_box_center[1], - z0=bounding_box_center[2], + surface_id=starting_id, + x0=bbox_center[0], + y0=bbox_center[1], + z0=bbox_center[2], boundary_type=boundary_type, r=radius, ) @@ -764,15 +770,21 @@ class DAGMCUniverse(UniverseBase): return -bounding_surface if bounded_type == 'box': + surf_ids = [starting_id+i for i in range(6)] # 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) + lower_x = openmc.XPlane(bbox[0][0], surface_id=surf_ids[0]) + upper_x = openmc.XPlane(bbox[1][0], surface_id=surf_ids[1]) + lower_y = openmc.YPlane(bbox[0][1], surface_id=surf_ids[2]) + upper_y = openmc.YPlane(bbox[1][1], surface_id=surf_ids[3]) + lower_z = openmc.ZPlane(bbox[0][2], surface_id=surf_ids[4]) + upper_z = openmc.ZPlane(bbox[1][2], surface_id=surf_ids[5]) - return +lower_x & -upper_x & +lower_y & -upper_y & +lower_z & -upper_z + region = +lower_x & -upper_x & +lower_y & -upper_y & +lower_z & -upper_z + + for surface in region.get_surfaces().values(): + surface.boundary_type = boundary_type + + return region def bounded_universe(self, bounding_cell_id=10000, **kwargs): """Returns an openmc.Universe filled with this DAGMCUniverse and bounded @@ -783,7 +795,7 @@ class DAGMCUniverse(UniverseBase): Parameters ---------- bounding_cell_id : int - The cell ID number to use for the bounding cell, defaults to 1000 to reduce + The cell ID number to use for the bounding cell, defaults to 10000 to reduce the chance of overlapping ID numbers with the DAGMC geometry. Returns @@ -791,7 +803,6 @@ class DAGMCUniverse(UniverseBase): openmc.Universe Universe instance """ - bounding_cell = openmc.Cell(fill=self, cell_id=bounding_cell_id, region=self.bounding_region(**kwargs)) return openmc.Universe(cells=[bounding_cell]) diff --git a/tests/regression_tests/dagmc/universes/inputs_true.dat b/tests/regression_tests/dagmc/universes/inputs_true.dat index 2165a78b6c..ea6ad519bb 100644 --- a/tests/regression_tests/dagmc/universes/inputs_true.dat +++ b/tests/regression_tests/dagmc/universes/inputs_true.dat @@ -1,6 +1,6 @@ - + 24.0 24.0 @@ -10,12 +10,12 @@ 9 9 9 9 - - - - - - + + + + + + diff --git a/tests/regression_tests/dagmc/universes/test.py b/tests/regression_tests/dagmc/universes/test.py index f2eb3882f2..67c8f962d8 100644 --- a/tests/regression_tests/dagmc/universes/test.py +++ b/tests/regression_tests/dagmc/universes/test.py @@ -62,8 +62,10 @@ class DAGMCUniverseTest(PyAPITestHarness): 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()): + starting_id = 10000 + for i, surface in enumerate(b_region.get_surfaces().values()): assert surface.boundary_type == 'vacuum' + assert surface.id == 10000 + i # 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') @@ -71,6 +73,7 @@ class DAGMCUniverseTest(PyAPITestHarness): assert len(b_region.get_surfaces()) == 1 for surface in list(b_region.get_surfaces().values()): assert surface.boundary_type == 'reflective' + assert surface.id == 10000 # create a 2 x 2 lattice using the DAGMC pincell pitch = np.asarray((24.0, 24.0)) From dcbaa59cdbd83322881878377901f8f303d60a6b Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 10 Aug 2022 13:30:22 -0500 Subject: [PATCH 2/9] Using numpy rather than impoting math --- openmc/universe.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/openmc/universe.py b/openmc/universe.py index aef4d660bb..58b880280f 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -755,9 +755,8 @@ class DAGMCUniverse(UniverseBase): bbox = self.bounding_box if bounded_type == 'sphere': - import math bbox_center = (bbox[0] + bbox[1])/2 - radius = math.dist(bbox[0], bbox[1]) + radius = np.linalg.norm(np.asarray(bbox)) bounding_surface = openmc.Sphere( surface_id=starting_id, x0=bbox_center[0], From 84c25272b6a2e465138f1141d4a9539a3594dce1 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 11 Aug 2022 06:39:49 -0400 Subject: [PATCH 3/9] Apply suggestions from @shimwell Co-authored-by: Jonathan Shimwell --- openmc/universe.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/openmc/universe.py b/openmc/universe.py index 58b880280f..4317a3dd7d 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -771,12 +771,12 @@ class DAGMCUniverse(UniverseBase): if bounded_type == 'box': surf_ids = [starting_id+i for i in range(6)] # defines plane surfaces for all six faces of the bounding box - lower_x = openmc.XPlane(bbox[0][0], surface_id=surf_ids[0]) - upper_x = openmc.XPlane(bbox[1][0], surface_id=surf_ids[1]) - lower_y = openmc.YPlane(bbox[0][1], surface_id=surf_ids[2]) - upper_y = openmc.YPlane(bbox[1][1], surface_id=surf_ids[3]) - lower_z = openmc.ZPlane(bbox[0][2], surface_id=surf_ids[4]) - upper_z = openmc.ZPlane(bbox[1][2], surface_id=surf_ids[5]) + lower_x = openmc.XPlane(bbox[0][0], surface_id=starting_id) + upper_x = openmc.XPlane(bbox[1][0], surface_id=starting_id+1) + lower_y = openmc.YPlane(bbox[0][1], surface_id=starting_id+2) + upper_y = openmc.YPlane(bbox[1][1], surface_id=starting_id+3) + lower_z = openmc.ZPlane(bbox[0][2], surface_id=starting_id+4) + upper_z = openmc.ZPlane(bbox[1][2], surface_id=starting_id+5) region = +lower_x & -upper_x & +lower_y & -upper_y & +lower_z & -upper_z From 246a551feaf7eb2b0246a2947fd89d103bbc1d71 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 11 Aug 2022 08:36:46 -0400 Subject: [PATCH 4/9] Update openmc/universe.py Co-authored-by: Jonathan Shimwell --- openmc/universe.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openmc/universe.py b/openmc/universe.py index 4317a3dd7d..727e7a096d 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -769,7 +769,6 @@ class DAGMCUniverse(UniverseBase): return -bounding_surface if bounded_type == 'box': - surf_ids = [starting_id+i for i in range(6)] # defines plane surfaces for all six faces of the bounding box lower_x = openmc.XPlane(bbox[0][0], surface_id=starting_id) upper_x = openmc.XPlane(bbox[1][0], surface_id=starting_id+1) From 6f433fc429896ca0df716ea7d598c08e5d3edeb0 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 11 Aug 2022 17:29:42 +0100 Subject: [PATCH 5/9] unit tests DAGMCUniverse bounding_region bounding_box --- tests/unit_tests/test_dagmc_universe.py | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/unit_tests/test_dagmc_universe.py diff --git a/tests/unit_tests/test_dagmc_universe.py b/tests/unit_tests/test_dagmc_universe.py new file mode 100644 index 0000000000..3f5403693f --- /dev/null +++ b/tests/unit_tests/test_dagmc_universe.py @@ -0,0 +1,38 @@ +import openmc +import pytest + + +def test_bounding_box(): + + u = openmc.DAGMCUniverse("tests/regression_tests/dagmc/universes/dagmc.h5m") + + ll, ur = u.bounding_box + assert ll == pytest.approx((-25., -25., -25)) + assert ur == pytest.approx((25., 25., 25)) + + +def test_bounding_region(): + + u = openmc.DAGMCUniverse("tests/regression_tests/dagmc/universes/dagmc.h5m") + + region = u.bounding_region() # should default to bounded_type='box' + assert isinstance(region, openmc.Region) + assert len(region) == 6 + assert region[0].surface.type == 'x-plane' + assert region[1].surface.type == 'x-plane' + assert region[2].surface.type == 'y-plane' + assert region[3].surface.type == 'y-plane' + assert region[4].surface.type == 'z-plane' + assert region[5].surface.type == 'z-plane' + assert region[0].surface.boundary_type == 'vacuum' + assert region[1].surface.boundary_type == 'vacuum' + assert region[2].surface.boundary_type == 'vacuum' + assert region[3].surface.boundary_type == 'vacuum' + assert region[4].surface.boundary_type == 'vacuum' + assert region[5].surface.boundary_type == 'vacuum' + + region = u.bounding_region(bounded_type='sphere', boundary_type='reflective') + assert isinstance(region, openmc.Region) + assert isinstance(region, openmc.Halfspace) + assert region.surface.type == 'sphere' + assert region.surface.boundary_type == 'reflective' From b1ea00b6cb5101b61d521f04cfe4e0c7c7770721 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 11 Aug 2022 18:01:49 +0100 Subject: [PATCH 6/9] added test for args passed to bounded_universe --- tests/unit_tests/test_dagmc_universe.py | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/unit_tests/test_dagmc_universe.py b/tests/unit_tests/test_dagmc_universe.py index 3f5403693f..945d39d9b9 100644 --- a/tests/unit_tests/test_dagmc_universe.py +++ b/tests/unit_tests/test_dagmc_universe.py @@ -36,3 +36,33 @@ def test_bounding_region(): assert isinstance(region, openmc.Halfspace) assert region.surface.type == 'sphere' assert region.surface.boundary_type == 'reflective' + +def test_bounded_universe(): + + u = openmc.DAGMCUniverse("tests/regression_tests/dagmc/universes/dagmc.h5m") + + # bounded with defaults + bu = u.bounded_universe() + + cells = list(bu.get_all_cells().items()) + assert len(cells) == 1 + assert cells[0][0] == 10000 # default bounding_cell_id is 10000 + assert cells[0][1].id == 10000 # default bounding_cell_id is 10000 + surfaces = list(cells[0][1].region.get_surfaces().items()) + assert len(surfaces) == 6 + assert surfaces[0][1].id == 10000 + + # bounded with non defaults + bu = u.bounded_universe( + bounding_cell_id=42, + bounded_type='sphere', + starting_id=43 + ) + + cells = list(bu.get_all_cells().items()) + assert len(cells) == 1 + assert cells[0][0] == 42 # default bounding_cell_id is 10000 + assert cells[0][1].id == 42 # default bounding_cell_id is 10000 + surfaces = list(cells[0][1].region.get_surfaces().items()) + assert surfaces[0][1].type == 'sphere' + assert surfaces[0][1].id == 43 From 623b86703391b72712ced5aa9a8ec3cea6513f57 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 12 Aug 2022 10:43:40 +0100 Subject: [PATCH 7/9] updated path for dagmc file --- tests/unit_tests/test_dagmc_universe.py | 57 ++++++++++++++----------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/tests/unit_tests/test_dagmc_universe.py b/tests/unit_tests/test_dagmc_universe.py index 945d39d9b9..9904fa03b3 100644 --- a/tests/unit_tests/test_dagmc_universe.py +++ b/tests/unit_tests/test_dagmc_universe.py @@ -1,50 +1,58 @@ import openmc import pytest +from pathlib import Path def test_bounding_box(): + """Checks that the DAGMCUniverse.bounding_box returns the correct values""" - u = openmc.DAGMCUniverse("tests/regression_tests/dagmc/universes/dagmc.h5m") + u = openmc.DAGMCUniverse(str(Path(__file__).parent.resolve() / "dagmc/dagmc.h5m")) ll, ur = u.bounding_box - assert ll == pytest.approx((-25., -25., -25)) - assert ur == pytest.approx((25., 25., 25)) + assert ll == pytest.approx((-25.0, -25.0, -25)) + assert ur == pytest.approx((25.0, 25.0, 25)) def test_bounding_region(): + """Checks that the DAGMCUniverse.bounding_region() returns a region with + correct surfaces and boundary types""" - u = openmc.DAGMCUniverse("tests/regression_tests/dagmc/universes/dagmc.h5m") + u = openmc.DAGMCUniverse(str(Path(__file__).parent.resolve() / "dagmc/dagmc.h5m")) region = u.bounding_region() # should default to bounded_type='box' assert isinstance(region, openmc.Region) assert len(region) == 6 - assert region[0].surface.type == 'x-plane' - assert region[1].surface.type == 'x-plane' - assert region[2].surface.type == 'y-plane' - assert region[3].surface.type == 'y-plane' - assert region[4].surface.type == 'z-plane' - assert region[5].surface.type == 'z-plane' - assert region[0].surface.boundary_type == 'vacuum' - assert region[1].surface.boundary_type == 'vacuum' - assert region[2].surface.boundary_type == 'vacuum' - assert region[3].surface.boundary_type == 'vacuum' - assert region[4].surface.boundary_type == 'vacuum' - assert region[5].surface.boundary_type == 'vacuum' + assert region[0].surface.type == "x-plane" + assert region[1].surface.type == "x-plane" + assert region[2].surface.type == "y-plane" + assert region[3].surface.type == "y-plane" + assert region[4].surface.type == "z-plane" + assert region[5].surface.type == "z-plane" + assert region[0].surface.boundary_type == "vacuum" + assert region[1].surface.boundary_type == "vacuum" + assert region[2].surface.boundary_type == "vacuum" + assert region[3].surface.boundary_type == "vacuum" + assert region[4].surface.boundary_type == "vacuum" + assert region[5].surface.boundary_type == "vacuum" - region = u.bounding_region(bounded_type='sphere', boundary_type='reflective') + region = u.bounding_region(bounded_type="sphere", boundary_type="reflective") assert isinstance(region, openmc.Region) assert isinstance(region, openmc.Halfspace) - assert region.surface.type == 'sphere' - assert region.surface.boundary_type == 'reflective' + assert region.surface.type == "sphere" + assert region.surface.boundary_type == "reflective" + def test_bounded_universe(): + """Checks that the DAGMCUniverse.bounded_universe() returns a + openmc.Universe with correct surface ids and cell ids""" - u = openmc.DAGMCUniverse("tests/regression_tests/dagmc/universes/dagmc.h5m") + u = openmc.DAGMCUniverse(str(Path(__file__).parent.resolve() / "dagmc/dagmc.h5m")) # bounded with defaults bu = u.bounded_universe() cells = list(bu.get_all_cells().items()) + assert isinstance(bu, openmc.Universe) assert len(cells) == 1 assert cells[0][0] == 10000 # default bounding_cell_id is 10000 assert cells[0][1].id == 10000 # default bounding_cell_id is 10000 @@ -53,16 +61,13 @@ def test_bounded_universe(): assert surfaces[0][1].id == 10000 # bounded with non defaults - bu = u.bounded_universe( - bounding_cell_id=42, - bounded_type='sphere', - starting_id=43 - ) + bu = u.bounded_universe(bounding_cell_id=42, bounded_type="sphere", starting_id=43) cells = list(bu.get_all_cells().items()) + assert isinstance(bu, openmc.Universe) assert len(cells) == 1 assert cells[0][0] == 42 # default bounding_cell_id is 10000 assert cells[0][1].id == 42 # default bounding_cell_id is 10000 surfaces = list(cells[0][1].region.get_surfaces().items()) - assert surfaces[0][1].type == 'sphere' + assert surfaces[0][1].type == "sphere" assert surfaces[0][1].id == 43 From d47f41637f76f5ed81976d5c4c9a1027c8c6e320 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 12 Aug 2022 07:53:36 -0500 Subject: [PATCH 8/9] Some updates to DAGMC testing. --- openmc/universe.py | 4 ++-- tests/regression_tests/dagmc/legacy/test.py | 3 ++- .../regression_tests/dagmc/universes/test.py | 22 ------------------- .../test_bounds.py} | 12 +++++----- 4 files changed, 10 insertions(+), 31 deletions(-) rename tests/unit_tests/{test_dagmc_universe.py => dagmc/test_bounds.py} (87%) diff --git a/openmc/universe.py b/openmc/universe.py index 727e7a096d..65bcce7470 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -678,8 +678,8 @@ class DAGMCUniverse(UniverseBase): @filename.setter def filename(self, val): - cv.check_type('DAGMC filename', val, str) - self._filename = val + cv.check_type('DAGMC filename', val, (Path, str)) + self._filename = str(val) @property def auto_geom_ids(self): diff --git a/tests/regression_tests/dagmc/legacy/test.py b/tests/regression_tests/dagmc/legacy/test.py index e0fccb9344..dacbc19ee0 100644 --- a/tests/regression_tests/dagmc/legacy/test.py +++ b/tests/regression_tests/dagmc/legacy/test.py @@ -1,6 +1,7 @@ import openmc import openmc.lib +from pathlib import Path import pytest from tests.testing_harness import PyAPITestHarness @@ -27,7 +28,7 @@ def model(): model.settings.dagmc = True # geometry - dag_univ = openmc.DAGMCUniverse("dagmc.h5m") + dag_univ = openmc.DAGMCUniverse(Path("dagmc.h5m")) model.geometry = openmc.Geometry(dag_univ) # tally diff --git a/tests/regression_tests/dagmc/universes/test.py b/tests/regression_tests/dagmc/universes/test.py index 67c8f962d8..47897ad568 100644 --- a/tests/regression_tests/dagmc/universes/test.py +++ b/tests/regression_tests/dagmc/universes/test.py @@ -53,28 +53,6 @@ class DAGMCUniverseTest(PyAPITestHarness): # assigns the bound_dag_geometry to the model to test the type checks in model.Geometry setter model.Geometry = bound_pincell_geometry - # 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.] - - # 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 - starting_id = 10000 - for i, surface in enumerate(b_region.get_surfaces().values()): - assert surface.boundary_type == 'vacuum' - assert surface.id == 10000 + i - - # 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' - assert surface.id == 10000 - # create a 2 x 2 lattice using the DAGMC pincell pitch = np.asarray((24.0, 24.0)) lattice = openmc.RectLattice() diff --git a/tests/unit_tests/test_dagmc_universe.py b/tests/unit_tests/dagmc/test_bounds.py similarity index 87% rename from tests/unit_tests/test_dagmc_universe.py rename to tests/unit_tests/dagmc/test_bounds.py index 9904fa03b3..dbca3ca253 100644 --- a/tests/unit_tests/test_dagmc_universe.py +++ b/tests/unit_tests/dagmc/test_bounds.py @@ -3,21 +3,21 @@ import pytest from pathlib import Path -def test_bounding_box(): +def test_bounding_box(request): """Checks that the DAGMCUniverse.bounding_box returns the correct values""" - u = openmc.DAGMCUniverse(str(Path(__file__).parent.resolve() / "dagmc/dagmc.h5m")) + u = openmc.DAGMCUniverse(Path(request.fspath).parent / "dagmc.h5m") ll, ur = u.bounding_box assert ll == pytest.approx((-25.0, -25.0, -25)) assert ur == pytest.approx((25.0, 25.0, 25)) -def test_bounding_region(): +def test_bounding_region(request): """Checks that the DAGMCUniverse.bounding_region() returns a region with correct surfaces and boundary types""" - u = openmc.DAGMCUniverse(str(Path(__file__).parent.resolve() / "dagmc/dagmc.h5m")) + u = openmc.DAGMCUniverse(Path(request.fspath).parent / "dagmc.h5m") region = u.bounding_region() # should default to bounded_type='box' assert isinstance(region, openmc.Region) @@ -42,11 +42,11 @@ def test_bounding_region(): assert region.surface.boundary_type == "reflective" -def test_bounded_universe(): +def test_bounded_universe(request): """Checks that the DAGMCUniverse.bounded_universe() returns a openmc.Universe with correct surface ids and cell ids""" - u = openmc.DAGMCUniverse(str(Path(__file__).parent.resolve() / "dagmc/dagmc.h5m")) + u = openmc.DAGMCUniverse(Path(request.fspath).parent / "dagmc.h5m") # bounded with defaults bu = u.bounded_universe() From 1124bffb4b6749f6d2ed50f7d1d498c26253ff0a Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 12 Aug 2022 07:55:50 -0500 Subject: [PATCH 9/9] Leave dagmc filename as Path object until writing the XML file --- openmc/universe.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openmc/universe.py b/openmc/universe.py index 65bcce7470..4aa1775fb1 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -679,7 +679,7 @@ class DAGMCUniverse(UniverseBase): @filename.setter def filename(self, val): cv.check_type('DAGMC filename', val, (Path, str)) - self._filename = str(val) + self._filename = val @property def auto_geom_ids(self): @@ -720,7 +720,7 @@ class DAGMCUniverse(UniverseBase): dagmc_element.set('auto_geom_ids', 'true') if self.auto_mat_ids: dagmc_element.set('auto_mat_ids', 'true') - dagmc_element.set('filename', self.filename) + dagmc_element.set('filename', str(self.filename)) xml_element.append(dagmc_element) def bounding_region(self, bounded_type='box', boundary_type='vacuum', starting_id=10000):