From cd60109a77dd7a3e6a492ef734684af272fb5cce Mon Sep 17 00:00:00 2001 From: shimwell Date: Wed, 13 Jul 2022 19:14:14 +0100 Subject: [PATCH 01/15] 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 b65263ef9c..2fd9315067 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 6726b4b448..f6964857d3 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() From 227c4e330fa2a339afa9cb3e5fb5f536683f3689 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 14 Jul 2022 09:36:17 +0100 Subject: [PATCH 02/15] improved doc strings added checks --- openmc/universe.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/openmc/universe.py b/openmc/universe.py index 2fd9315067..06807bab3f 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -12,9 +12,12 @@ import numpy as np import openmc import openmc.checkvalue as cv + from ._xml import get_text +from .checkvalue import check_type, check_value from .mixin import IDManagerMixin from .plots import _SVG_COLORS +from .surface import _BOUNDARY_TYPES class UniverseBase(ABC, IDManagerMixin): @@ -724,13 +727,17 @@ class DAGMCUniverse(UniverseBase): 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 + the surface. Defaults to vacuum boundary condition. Passed into the + surface construction. Returns ------- openmc.Region Region instance """ + check_type('boundary type', boundary_type, str) + check_value('boundary type', boundary_type, _BOUNDARY_TYPES) + bounding_box = self.bounding_box if bounded_type == 'sphere': @@ -753,6 +760,10 @@ class DAGMCUniverse(UniverseBase): return +lower_x & -upper_x & +lower_y & -upper_y & +lower_z & -upper_z def bounded_universe(self, **kwargs): + """Returns an openmc.Universe filled with the DAGMCUniverse and bounded + with a cell. Defaults to a box cell with a vacuum surface. kwargs are + passed directly to DAGMCUniverse.bounding_region()""" + bounding_cell = openmc.Cell(fill=self, region=self.bounding_region(**kwargs)) return openmc.Universe(cells=[bounding_cell]) From 28e203c8286acd83ccd97ce23d4c8e19b4ceb559 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 14 Jul 2022 15:10:27 +0100 Subject: [PATCH 03/15] typos fixed in review by @pshriwise Co-authored-by: Patrick Shriwise --- openmc/universe.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openmc/universe.py b/openmc/universe.py index 06807bab3f..7ecf489ce0 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -724,7 +724,7 @@ class DAGMCUniverse(UniverseBase): 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). + made from six planes (box). boundary_type : str Boundary condition that defines the behavior for particles hitting the surface. Defaults to vacuum boundary condition. Passed into the @@ -760,7 +760,7 @@ class DAGMCUniverse(UniverseBase): return +lower_x & -upper_x & +lower_y & -upper_y & +lower_z & -upper_z def bounded_universe(self, **kwargs): - """Returns an openmc.Universe filled with the DAGMCUniverse and bounded + """Returns an openmc.Universe filled with this DAGMCUniverse and bounded with a cell. Defaults to a box cell with a vacuum surface. kwargs are passed directly to DAGMCUniverse.bounding_region()""" From 839b862d5645be785fd1f79dc6c3ba3f19e39b9e Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 14 Jul 2022 15:15:04 +0100 Subject: [PATCH 04/15] added type value check for bounded type --- openmc/universe.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/openmc/universe.py b/openmc/universe.py index 7ecf489ce0..e46d4d0275 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -737,6 +737,8 @@ class DAGMCUniverse(UniverseBase): check_type('boundary type', boundary_type, str) check_value('boundary type', boundary_type, _BOUNDARY_TYPES) + check_type('bounded type', bounded_type, str) + check_value('bounded type', bounded_type, ('box', 'sphere')) bounding_box = self.bounding_box From 4c62517b1aa4cbc4b1c742c97e39473551be4682 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 14 Jul 2022 16:50:33 +0100 Subject: [PATCH 05/15] added test to check bounded_universe is usable in model (should fail) --- tests/regression_tests/dagmc/universes/test.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/regression_tests/dagmc/universes/test.py b/tests/regression_tests/dagmc/universes/test.py index f6964857d3..7abd80ef7f 100644 --- a/tests/regression_tests/dagmc/universes/test.py +++ b/tests/regression_tests/dagmc/universes/test.py @@ -46,6 +46,13 @@ class DAGMCUniverseTest(PyAPITestHarness): # create the DAGMC universe pincell_univ = openmc.DAGMCUniverse(filename='dagmc.h5m', auto_geom_ids=True) + # creates another DAGMC universe, this time with within a bounded cell + bound_pincell_cell = openmc.DAGMCUniverse(filename='dagmc.h5m').bounded_universe() + # uses the bound_dag_cell as the root argument to test the type checks in openmc.Geometry + bound_pincell_geometry = openmc.Geometry(root=[bound_pincell_cell]) + # 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.] From 3d091a6cfbdb24242886e7a8d076852b8b085d4d Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 14 Jul 2022 16:51:22 +0100 Subject: [PATCH 06/15] returning Cell instead of Universe --- openmc/universe.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/openmc/universe.py b/openmc/universe.py index e46d4d0275..9931724fbb 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -762,12 +762,18 @@ class DAGMCUniverse(UniverseBase): return +lower_x & -upper_x & +lower_y & -upper_y & +lower_z & -upper_z def bounded_universe(self, **kwargs): - """Returns an openmc.Universe filled with this DAGMCUniverse and bounded - with a cell. Defaults to a box cell with a vacuum surface. kwargs are - passed directly to DAGMCUniverse.bounding_region()""" + """Returns an openmc.Cell that bounds the DAGMCUniverse and is filled + with the DAGMCUniverse. Defaults to a box cell with a vacuum surface. + kwargs are passed directly to DAGMCUniverse.bounding_region() + + Returns + ------- + openmc.Cell + cell filled with the DAGMCUniverse + """ bounding_cell = openmc.Cell(fill=self, region=self.bounding_region(**kwargs)) - return openmc.Universe(cells=[bounding_cell]) + return bounding_cell @classmethod def from_hdf5(cls, group): From c3e60da1b9f2c04545200e8d5f16360304c166ca Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 14 Jul 2022 16:55:26 +0100 Subject: [PATCH 07/15] testing and returing openmc.Universe --- openmc/universe.py | 12 ++++++------ tests/regression_tests/dagmc/universes/test.py | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/openmc/universe.py b/openmc/universe.py index 9931724fbb..811b27b315 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -762,18 +762,18 @@ class DAGMCUniverse(UniverseBase): return +lower_x & -upper_x & +lower_y & -upper_y & +lower_z & -upper_z def bounded_universe(self, **kwargs): - """Returns an openmc.Cell that bounds the DAGMCUniverse and is filled - with the DAGMCUniverse. Defaults to a box cell with a vacuum surface. - kwargs are passed directly to DAGMCUniverse.bounding_region() + """Returns an openmc.Universe filled with this DAGMCUniverse and bounded + with a cell. Defaults to a box cell with a vacuum surface. kwargs are + passed directly to DAGMCUniverse.bounding_region() Returns ------- - openmc.Cell - cell filled with the DAGMCUniverse + openmc.Universe + Universe instance """ bounding_cell = openmc.Cell(fill=self, region=self.bounding_region(**kwargs)) - return bounding_cell + return openmc.Universe(cells=[bounding_cell]) @classmethod def from_hdf5(cls, group): diff --git a/tests/regression_tests/dagmc/universes/test.py b/tests/regression_tests/dagmc/universes/test.py index 7abd80ef7f..f2eb3882f2 100644 --- a/tests/regression_tests/dagmc/universes/test.py +++ b/tests/regression_tests/dagmc/universes/test.py @@ -47,9 +47,9 @@ class DAGMCUniverseTest(PyAPITestHarness): pincell_univ = openmc.DAGMCUniverse(filename='dagmc.h5m', auto_geom_ids=True) # creates another DAGMC universe, this time with within a bounded cell - bound_pincell_cell = openmc.DAGMCUniverse(filename='dagmc.h5m').bounded_universe() + bound_pincell_universe = openmc.DAGMCUniverse(filename='dagmc.h5m').bounded_universe() # uses the bound_dag_cell as the root argument to test the type checks in openmc.Geometry - bound_pincell_geometry = openmc.Geometry(root=[bound_pincell_cell]) + bound_pincell_geometry = openmc.Geometry(root=bound_pincell_universe) # assigns the bound_dag_geometry to the model to test the type checks in model.Geometry setter model.Geometry = bound_pincell_geometry From 34e4a5efd12b8adc21ae9c3bb83fc073fc95df71 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 14 Jul 2022 18:06:07 +0100 Subject: [PATCH 08/15] setting auto_geom_ids to true for bounded universe --- openmc/universe.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/openmc/universe.py b/openmc/universe.py index 811b27b315..989b50c734 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -761,10 +761,18 @@ class DAGMCUniverse(UniverseBase): return +lower_x & -upper_x & +lower_y & -upper_y & +lower_z & -upper_z - def bounded_universe(self, **kwargs): + def bounded_universe(self, auto_geom_ids=True, **kwargs): """Returns an openmc.Universe filled with this DAGMCUniverse and bounded - with a cell. Defaults to a box cell with a vacuum surface. kwargs are - passed directly to DAGMCUniverse.bounding_region() + with a cell. Defaults to a box cell with a vacuum surface however this + can be changed using the kwargs which are passed directly to + DAGMCUniverse.bounding_region(). + + Parameters + ---------- + auto_geom_ids : bool + Set IDs automatically on initialization (True) or report overlaps + in ID space between CSG and DAGMC (False). Defaults to True to avoid + overlapping ID numbers between the CSG and DAGMC geometry ID numbers Returns ------- @@ -772,6 +780,7 @@ class DAGMCUniverse(UniverseBase): Universe instance """ + self.auto_geom_ids = auto_geom_ids bounding_cell = openmc.Cell(fill=self, region=self.bounding_region(**kwargs)) return openmc.Universe(cells=[bounding_cell]) From fbb15496db978693cb5df9e963d69853b6f1ee9f Mon Sep 17 00:00:00 2001 From: shimwell Date: Mon, 18 Jul 2022 21:33:37 +0100 Subject: [PATCH 09/15] boundary_type review suggestion from @pshriwise --- openmc/universe.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/openmc/universe.py b/openmc/universe.py index 989b50c734..959717b6a5 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -746,7 +746,13 @@ class DAGMCUniverse(UniverseBase): 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) + bounding_surface = openmc.Sphere( + x0=bounding_box_center[0], + y0=bounding_box_center[1], + z0=bounding_box_center[2], + boundary_type=boundary_type, + r=radius, + ) return -bounding_surface From c8fb5eb2bdbacfc53d4280030ecae99cf25f0157 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Tue, 19 Jul 2022 11:43:28 +0100 Subject: [PATCH 10/15] updated comparison input --- .../dagmc/universes/inputs_true.dat | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/regression_tests/dagmc/universes/inputs_true.dat b/tests/regression_tests/dagmc/universes/inputs_true.dat index 4443f9a35d..1a5ca74865 100644 --- a/tests/regression_tests/dagmc/universes/inputs_true.dat +++ b/tests/regression_tests/dagmc/universes/inputs_true.dat @@ -1,8 +1,8 @@ - + - + 24.0 24.0 2 2 -24.0 -24.0 @@ -10,12 +10,12 @@ 9 9 9 9 - - - - - - + + + + + + From ada2493a6b901aba7e404da2ca90f14ea9c166f6 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 21 Jul 2022 12:05:31 +0100 Subject: [PATCH 11/15] changed auto_geom_ids approach --- openmc/universe.py | 10 +--------- src/dagmc.cpp | 4 +++- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/openmc/universe.py b/openmc/universe.py index 959717b6a5..5bcbfde468 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -767,26 +767,18 @@ class DAGMCUniverse(UniverseBase): return +lower_x & -upper_x & +lower_y & -upper_y & +lower_z & -upper_z - def bounded_universe(self, auto_geom_ids=True, **kwargs): + def bounded_universe(self, **kwargs): """Returns an openmc.Universe filled with this DAGMCUniverse and bounded with a cell. Defaults to a box cell with a vacuum surface however this can be changed using the kwargs which are passed directly to DAGMCUniverse.bounding_region(). - Parameters - ---------- - auto_geom_ids : bool - Set IDs automatically on initialization (True) or report overlaps - in ID space between CSG and DAGMC (False). Defaults to True to avoid - overlapping ID numbers between the CSG and DAGMC geometry ID numbers - Returns ------- openmc.Universe Universe instance """ - self.auto_geom_ids = auto_geom_ids bounding_cell = openmc.Cell(fill=self, region=self.bounding_region(**kwargs)) return openmc.Universe(cells=[bounding_cell]) diff --git a/src/dagmc.cpp b/src/dagmc.cpp index 8ce5aabdad..c9a6e6ad21 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -183,7 +183,9 @@ void DAGUniverse::init_geometry() } else { warning(fmt::format("DAGMC Cell IDs: {}", dagmc_ids_for_dim(3))); fatal_error(fmt::format("Cell ID {} exists in both DAGMC Universe {} " - "and the CSG geometry.", + "and the CSG geometry. Setting auto_geom_ids + to True when initiating the DAGMC Universe may + resolve this issue", c->id_, this->id_)); } From 0256fe90d47a642ace88b5c6168fde50f832920b Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 21 Jul 2022 16:11:57 +0100 Subject: [PATCH 12/15] corrected end of line --- src/dagmc.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dagmc.cpp b/src/dagmc.cpp index c9a6e6ad21..dc3bc2b2ce 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -183,9 +183,9 @@ void DAGUniverse::init_geometry() } else { warning(fmt::format("DAGMC Cell IDs: {}", dagmc_ids_for_dim(3))); fatal_error(fmt::format("Cell ID {} exists in both DAGMC Universe {} " - "and the CSG geometry. Setting auto_geom_ids - to True when initiating the DAGMC Universe may - resolve this issue", + "and the CSG geometry. Setting auto_geom_ids " + "to True when initiating the DAGMC Universe may " + "resolve this issue", c->id_, this->id_)); } From ff5490e3ba432209a95cb75ce07d21b167f90efd Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 22 Jul 2022 08:01:28 +0100 Subject: [PATCH 13/15] User able to set bounding cell id --- openmc/universe.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/openmc/universe.py b/openmc/universe.py index 5bcbfde468..fe41674d54 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -767,19 +767,25 @@ class DAGMCUniverse(UniverseBase): return +lower_x & -upper_x & +lower_y & -upper_y & +lower_z & -upper_z - def bounded_universe(self, **kwargs): + def bounded_universe(self, bounding_cell_id=10000, **kwargs): """Returns an openmc.Universe filled with this DAGMCUniverse and bounded with a cell. Defaults to a box cell with a vacuum surface however this can be changed using the kwargs which are passed directly to DAGMCUniverse.bounding_region(). + Parameters + ---------- + bounding_cell_id : int + The cell ID number to use for the bounding cell, defaults to 1000 to reduce + the chance of overlapping ID numbers with the DAGMC geometry. + Returns ------- openmc.Universe Universe instance """ - bounding_cell = openmc.Cell(fill=self, region=self.bounding_region(**kwargs)) + bounding_cell = openmc.Cell(fill=self, id=bounding_cell_id, region=self.bounding_region(**kwargs)) return openmc.Universe(cells=[bounding_cell]) @classmethod From f0cda31e73311a2673bc7fb0dac698f396cf2933 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 22 Jul 2022 10:45:15 +0100 Subject: [PATCH 14/15] corrected arg name --- openmc/universe.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openmc/universe.py b/openmc/universe.py index fe41674d54..78f75bbfc1 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -785,7 +785,7 @@ class DAGMCUniverse(UniverseBase): Universe instance """ - bounding_cell = openmc.Cell(fill=self, id=bounding_cell_id, region=self.bounding_region(**kwargs)) + bounding_cell = openmc.Cell(fill=self, cell_id =bounding_cell_id, region=self.bounding_region(**kwargs)) return openmc.Universe(cells=[bounding_cell]) @classmethod From 717115938df14c8561da1052dd2e849bdc26b4bb Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Mon, 25 Jul 2022 16:25:29 +0100 Subject: [PATCH 15/15] updating fill id to match --- tests/regression_tests/dagmc/universes/inputs_true.dat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/regression_tests/dagmc/universes/inputs_true.dat b/tests/regression_tests/dagmc/universes/inputs_true.dat index 1a5ca74865..2165a78b6c 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