From d47e9a10928d594dcf5e29acccdb65bc75950c4c Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Sun, 23 Jul 2023 23:26:13 +0100 Subject: [PATCH] allowing geometry to be fully made via constructor (#2602) Co-authored-by: Paul Romano --- openmc/geometry.py | 11 ++++++++--- tests/unit_tests/test_geometry.py | 9 +++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/openmc/geometry.py b/openmc/geometry.py index d4e7aa201d0..f32e979bb7a 100644 --- a/openmc/geometry.py +++ b/openmc/geometry.py @@ -39,11 +39,16 @@ class Geometry: """ - def __init__(self, root=None): + def __init__( + self, + root: typing.Optional[openmc.UniverseBase] = None, + merge_surfaces: bool = False, + surface_precision: int = 10 + ): self._root_universe = None self._offsets = {} - self.merge_surfaces = False - self.surface_precision = 10 + self.merge_surfaces = merge_surfaces + self.surface_precision = surface_precision if root is not None: if isinstance(root, openmc.UniverseBase): self.root_universe = root diff --git a/tests/unit_tests/test_geometry.py b/tests/unit_tests/test_geometry.py index 6fa34d26d01..ebb185642fd 100644 --- a/tests/unit_tests/test_geometry.py +++ b/tests/unit_tests/test_geometry.py @@ -362,8 +362,13 @@ def get_cyl_cell(r1, r2, z1, z2, fill): clad = get_cyl_cell(r1, r2, z1, z2, m2) water = get_cyl_cell(r2, r3, z1, z2, m3) root = openmc.Universe(cells=[fuel, clad, water]) - geom = openmc.Geometry(root) - geom.merge_surfaces=True + geom = openmc.Geometry(root=root, merge_surfaces=True, surface_precision=11) + assert geom.merge_surfaces is True + geom.merge_surfaces = False + assert geom.merge_surfaces is False + assert geom.surface_precision == 11 + geom.surface_precision = 10 + assert geom.surface_precision == 10 model = openmc.model.Model(geometry=geom, materials=openmc.Materials([m1, m2, m3]))