From a67b330d8f1ae8bcef1e5534459dc116f2bda21d Mon Sep 17 00:00:00 2001 From: Ethan Peterson Date: Thu, 13 Oct 2022 11:57:39 -0400 Subject: [PATCH 1/9] round and change default to True --- openmc/geometry.py | 5 +++-- openmc/model/model.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/openmc/geometry.py b/openmc/geometry.py index 58a33c1b1..edf4c4782 100644 --- a/openmc/geometry.py +++ b/openmc/geometry.py @@ -75,7 +75,7 @@ class Geometry: if universe.id in volume_calc.volumes: universe.add_volume_information(volume_calc) - def export_to_xml(self, path='geometry.xml', remove_surfs=False): + def export_to_xml(self, path='geometry.xml', remove_surfs=True): """Export geometry to an XML file. Parameters @@ -411,7 +411,8 @@ class Geometry: """ tally = defaultdict(list) for surf in self.get_all_surfaces().values(): - coeffs = tuple(surf._coefficients[k] for k in surf._coeff_keys) + coeffs = tuple(round(surf._coefficients[k], 10) + for k in surf._coeff_keys) key = (surf._type,) + coeffs tally[key].append(surf) return {replace.id: keep diff --git a/openmc/model/model.py b/openmc/model/model.py index 625094cce..a48730091 100644 --- a/openmc/model/model.py +++ b/openmc/model/model.py @@ -397,7 +397,7 @@ class Model: depletion_operator.cleanup_when_done = True depletion_operator.finalize() - def export_to_xml(self, directory='.', remove_surfs=False): + def export_to_xml(self, directory='.', remove_surfs=True): """Export model to XML files. Parameters From 1ab2cbec40ab75452b710b4a3d200ec3f2b5011f Mon Sep 17 00:00:00 2001 From: Ethan Peterson Date: Thu, 13 Oct 2022 13:24:03 -0400 Subject: [PATCH 2/9] revert to False because of failing tests --- openmc/geometry.py | 2 +- openmc/model/model.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/openmc/geometry.py b/openmc/geometry.py index edf4c4782..0fd8e02fe 100644 --- a/openmc/geometry.py +++ b/openmc/geometry.py @@ -75,7 +75,7 @@ class Geometry: if universe.id in volume_calc.volumes: universe.add_volume_information(volume_calc) - def export_to_xml(self, path='geometry.xml', remove_surfs=True): + def export_to_xml(self, path='geometry.xml', remove_surfs=False): """Export geometry to an XML file. Parameters diff --git a/openmc/model/model.py b/openmc/model/model.py index a48730091..625094cce 100644 --- a/openmc/model/model.py +++ b/openmc/model/model.py @@ -397,7 +397,7 @@ class Model: depletion_operator.cleanup_when_done = True depletion_operator.finalize() - def export_to_xml(self, directory='.', remove_surfs=True): + def export_to_xml(self, directory='.', remove_surfs=False): """Export model to XML files. Parameters From 4604c10da11f2ef3c66c44ae80d6a7f8f452b2d3 Mon Sep 17 00:00:00 2001 From: Ethan Peterson Date: Sun, 16 Oct 2022 13:06:37 -0400 Subject: [PATCH 3/9] added attributes and warnings --- openmc/geometry.py | 76 +++++++++++++++++++++++++++++++++++++++---- openmc/model/model.py | 7 +++- 2 files changed, 75 insertions(+), 8 deletions(-) diff --git a/openmc/geometry.py b/openmc/geometry.py index 0fd8e02fe..e3bb4a1cd 100644 --- a/openmc/geometry.py +++ b/openmc/geometry.py @@ -3,10 +3,11 @@ from collections.abc import Iterable from copy import deepcopy from pathlib import Path from xml.etree import ElementTree as ET +import warnings import openmc import openmc._xml as xml -from .checkvalue import check_type +from .checkvalue import check_type, check_less_than, check_greater_than class Geometry: @@ -17,6 +18,13 @@ class Geometry: root : openmc.UniverseBase or Iterable of openmc.Cell, optional Root universe which contains all others, or an iterable of cells that should be used to create a root universe. + cull_surfaces : bool, optional + Whether to remove redundant surfaces when the geometry is exported. + Defaults to False. + surface_precision : int, optional + Number of decimal places to round to for comparing the coefficients of + surfaces for considering them topologically equivalent. Defaults to 10 + decimal places. Attributes ---------- @@ -25,12 +33,19 @@ class Geometry: bounding_box : 2-tuple of numpy.array Lower-left and upper-right coordinates of an axis-aligned bounding box of the universe. + cull_surfaces : bool + Whether to remove redundant surfaces when the geometry is exported. + surface_precision : int + Number of decimal places to round to for comparing the coefficients of + surfaces for considering them topologically equivalent. """ - def __init__(self, root=None): + def __init__(self, root=None, cull_surfaces=False, surface_precision=10): self._root_universe = None self._offsets = {} + self.cull_surfaces = cull_surfaces + self.surface_precision = surface_precision if root is not None: if isinstance(root, openmc.UniverseBase): self.root_universe = root @@ -48,11 +63,31 @@ class Geometry: def bounding_box(self): return self.root_universe.bounding_box + @property + def cull_surfaces(self): + return self._cull_surfaces + + @property + def surface_precision(self): + return self._surface_precision + @root_universe.setter def root_universe(self, root_universe): check_type('root universe', root_universe, openmc.UniverseBase) self._root_universe = root_universe + @cull_surfaces.setter + def cull_surfaces(self, cull_surfaces): + check_type('cull surfaces', cull_surfaces, bool) + self._cull_surfaces = cull_surfaces + + @surface_precision.setter + def surface_precision(self, surface_precision): + check_type('surface precision', surface_precision, int) + check_less_than('surface_precision', surface_precision, 16) + check_greater_than('surface_precision', surface_precision, 0) + self._surface_precision = surface_precision + def add_volume_information(self, volume_calc): """Add volume information from a stochastic volume calculation. @@ -91,6 +126,11 @@ class Geometry: """ # Find and remove redundant surfaces from the geometry if remove_surfs: + warnings.warn("remove_surfs kwarg will be deprecated soon, please " + "set the Geometry.cull_surfaces attribute instead.") + self.cull_surfaces = True + + if self.cull_surfaces: self.remove_redundant_surfaces() # Create XML representation @@ -396,11 +436,18 @@ class Geometry: surfaces = cell.region.get_surfaces(surfaces) return surfaces - def get_redundant_surfaces(self): + def get_redundant_surfaces(self, precision=None): """Return all of the topologically redundant surface IDs .. versionadded:: 0.12 + Parameters + ---------- + precision : int, optional + The number of decimal places to round to for considering surface + coefficients to be equal. Defaults to the value specified by + Geometry.surface_precision. + Returns ------- dict @@ -409,9 +456,12 @@ class Geometry: that should replace it. """ + precision = self.surface_precision if precision is None else precision + check_less_than('precision', precision, 16) + check_greater_than('precision', precision, 0) tally = defaultdict(list) for surf in self.get_all_surfaces().values(): - coeffs = tuple(round(surf._coefficients[k], 10) + coeffs = tuple(round(surf._coefficients[k], precision) for k in surf._coeff_keys) key = (surf._type,) + coeffs tally[key].append(surf) @@ -565,11 +615,23 @@ class Geometry: """ return self._get_domains_by_name(name, case_sensitive, matching, 'lattice') - def remove_redundant_surfaces(self): - """Remove redundant surfaces from the geometry""" + def remove_redundant_surfaces(self, precision=None): + """Remove redundant surfaces from the geometry. + + Parameters + ---------- + precision : int, optional + The number of decimal places to round to for considering surface + coefficients to be equal. Defaults to the value specified by + Geometry.surface_precision. + + """ + precision = self.surface_precision if precision is None else precision + check_less_than('precision', precision, 16) + check_greater_than('precision', precision, 0) # Get redundant surfaces - redundant_surfaces = self.get_redundant_surfaces() + redundant_surfaces = self.get_redundant_surfaces(precision=precision) # Iterate through all cells contained in the geometry for cell in self.get_all_cells().values(): diff --git a/openmc/model/model.py b/openmc/model/model.py index 625094cce..8a57c88e4 100644 --- a/openmc/model/model.py +++ b/openmc/model/model.py @@ -5,6 +5,7 @@ import os from pathlib import Path from numbers import Integral from tempfile import NamedTemporaryFile +import warnings import h5py @@ -417,7 +418,11 @@ class Model: d.mkdir(parents=True) self.settings.export_to_xml(d) - self.geometry.export_to_xml(d, remove_surfs=remove_surfs) + if remove_surfs: + warnings.warn("remove_surfs kwarg will be deprecated soon, please " + "set the Geometry.cull_surfaces attribute instead.") + self.geometry.cull_surfaces = True + self.geometry.export_to_xml(d) # If a materials collection was specified, export it. Otherwise, look # for all materials in the geometry and use that to automatically build From fec53aa1fa8690757141a196f71abe20e0694b78 Mon Sep 17 00:00:00 2001 From: Ethan Peterson Date: Tue, 18 Oct 2022 09:16:09 -0400 Subject: [PATCH 4/9] updated tests --- tests/unit_tests/test_geometry.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/unit_tests/test_geometry.py b/tests/unit_tests/test_geometry.py index 64a97e0a1..2034a5764 100644 --- a/tests/unit_tests/test_geometry.py +++ b/tests/unit_tests/test_geometry.py @@ -302,7 +302,7 @@ def test_rotation_matrix(): assert geom.find((0.0, -0.5, 0.0))[-1] == c1 assert geom.find((0.0, -1.5, 0.0))[-1] == c2 -def test_remove_redundant_surfaces(): +def test_remove_redundant_surfaces(run_in_tmpdir): """Test ability to remove redundant surfaces""" m1 = openmc.Material() @@ -338,13 +338,16 @@ def test_remove_redundant_surfaces(): 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 = openmc.Geometry(root, cull_surfaces=True) + model = openmc.model.Model(geometry=geom, + materials=openmc.Materials([m1, m2, m3])) + # There should be 6 redundant surfaces in this geometry n_redundant_surfs = len(geom.get_redundant_surfaces().keys()) assert n_redundant_surfs == 6 - # Remove redundant surfaces - geom.remove_redundant_surfaces() + # Remove redundant surfaces on export + model.export_to_xml() + geom = openmc.Geometry.from_xml() # There should be 0 remaining redundant surfaces n_redundant_surfs = len(geom.get_redundant_surfaces().keys()) assert n_redundant_surfs == 0 From 33021f7af18c095fa8b0a18cb51c5aac852eeb28 Mon Sep 17 00:00:00 2001 From: Ethan Peterson Date: Mon, 24 Oct 2022 16:55:48 -0400 Subject: [PATCH 5/9] removed precision parameter --- openmc/geometry.py | 37 +++++++++---------------------------- 1 file changed, 9 insertions(+), 28 deletions(-) diff --git a/openmc/geometry.py b/openmc/geometry.py index e3bb4a1cd..5efd5381e 100644 --- a/openmc/geometry.py +++ b/openmc/geometry.py @@ -436,18 +436,14 @@ class Geometry: surfaces = cell.region.get_surfaces(surfaces) return surfaces - def get_redundant_surfaces(self, precision=None): - """Return all of the topologically redundant surface IDs + def get_redundant_surfaces(self): + """Return all of the topologically redundant surface IDs. + + Uses surface_precision attribute of Geometry instance for rounding and + comparing surface coefficients. .. versionadded:: 0.12 - Parameters - ---------- - precision : int, optional - The number of decimal places to round to for considering surface - coefficients to be equal. Defaults to the value specified by - Geometry.surface_precision. - Returns ------- dict @@ -456,12 +452,9 @@ class Geometry: that should replace it. """ - precision = self.surface_precision if precision is None else precision - check_less_than('precision', precision, 16) - check_greater_than('precision', precision, 0) tally = defaultdict(list) for surf in self.get_all_surfaces().values(): - coeffs = tuple(round(surf._coefficients[k], precision) + coeffs = tuple(round(surf._coefficients[k], self.surface_precision) for k in surf._coeff_keys) key = (surf._type,) + coeffs tally[key].append(surf) @@ -615,23 +608,11 @@ class Geometry: """ return self._get_domains_by_name(name, case_sensitive, matching, 'lattice') - def remove_redundant_surfaces(self, precision=None): - """Remove redundant surfaces from the geometry. - - Parameters - ---------- - precision : int, optional - The number of decimal places to round to for considering surface - coefficients to be equal. Defaults to the value specified by - Geometry.surface_precision. - - """ - precision = self.surface_precision if precision is None else precision - check_less_than('precision', precision, 16) - check_greater_than('precision', precision, 0) + def remove_redundant_surfaces(self): + """Remove redundant surfaces from the geometry.""" # Get redundant surfaces - redundant_surfaces = self.get_redundant_surfaces(precision=precision) + redundant_surfaces = self.get_redundant_surfaces() # Iterate through all cells contained in the geometry for cell in self.get_all_cells().values(): From a46cafa7fe05a391f9c3e85a5f89c53233af29c1 Mon Sep 17 00:00:00 2001 From: Ethan Peterson Date: Wed, 26 Oct 2022 08:20:25 -0400 Subject: [PATCH 6/9] addressed @pshriwise comments --- openmc/geometry.py | 33 ++++++++++++------------------- openmc/model/model.py | 4 ++-- tests/unit_tests/test_geometry.py | 3 ++- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/openmc/geometry.py b/openmc/geometry.py index 5efd5381e..2cdc356e8 100644 --- a/openmc/geometry.py +++ b/openmc/geometry.py @@ -18,13 +18,6 @@ class Geometry: root : openmc.UniverseBase or Iterable of openmc.Cell, optional Root universe which contains all others, or an iterable of cells that should be used to create a root universe. - cull_surfaces : bool, optional - Whether to remove redundant surfaces when the geometry is exported. - Defaults to False. - surface_precision : int, optional - Number of decimal places to round to for comparing the coefficients of - surfaces for considering them topologically equivalent. Defaults to 10 - decimal places. Attributes ---------- @@ -33,7 +26,7 @@ class Geometry: bounding_box : 2-tuple of numpy.array Lower-left and upper-right coordinates of an axis-aligned bounding box of the universe. - cull_surfaces : bool + merge_surfaces : bool Whether to remove redundant surfaces when the geometry is exported. surface_precision : int Number of decimal places to round to for comparing the coefficients of @@ -41,11 +34,11 @@ class Geometry: """ - def __init__(self, root=None, cull_surfaces=False, surface_precision=10): + def __init__(self, root=None): self._root_universe = None self._offsets = {} - self.cull_surfaces = cull_surfaces - self.surface_precision = surface_precision + self.merge_surfaces = False + self.surface_precision = 10 if root is not None: if isinstance(root, openmc.UniverseBase): self.root_universe = root @@ -64,8 +57,8 @@ class Geometry: return self.root_universe.bounding_box @property - def cull_surfaces(self): - return self._cull_surfaces + def merge_surfaces(self): + return self._merge_surfaces @property def surface_precision(self): @@ -76,10 +69,10 @@ class Geometry: check_type('root universe', root_universe, openmc.UniverseBase) self._root_universe = root_universe - @cull_surfaces.setter - def cull_surfaces(self, cull_surfaces): - check_type('cull surfaces', cull_surfaces, bool) - self._cull_surfaces = cull_surfaces + @merge_surfaces.setter + def merge_surfaces(self, merge_surfaces): + check_type('merge surfaces', merge_surfaces, bool) + self._merge_surfaces = merge_surfaces @surface_precision.setter def surface_precision(self, surface_precision): @@ -127,10 +120,10 @@ class Geometry: # Find and remove redundant surfaces from the geometry if remove_surfs: warnings.warn("remove_surfs kwarg will be deprecated soon, please " - "set the Geometry.cull_surfaces attribute instead.") - self.cull_surfaces = True + "set the Geometry.merge_surfaces attribute instead.") + self.merge_surfaces = True - if self.cull_surfaces: + if self.merge_surfaces: self.remove_redundant_surfaces() # Create XML representation diff --git a/openmc/model/model.py b/openmc/model/model.py index 8a57c88e4..7126987cb 100644 --- a/openmc/model/model.py +++ b/openmc/model/model.py @@ -420,8 +420,8 @@ class Model: self.settings.export_to_xml(d) if remove_surfs: warnings.warn("remove_surfs kwarg will be deprecated soon, please " - "set the Geometry.cull_surfaces attribute instead.") - self.geometry.cull_surfaces = True + "set the Geometry.merge_surfaces attribute instead.") + self.geometry.merge_surfaces = True self.geometry.export_to_xml(d) # If a materials collection was specified, export it. Otherwise, look diff --git a/tests/unit_tests/test_geometry.py b/tests/unit_tests/test_geometry.py index 2034a5764..6a092126e 100644 --- a/tests/unit_tests/test_geometry.py +++ b/tests/unit_tests/test_geometry.py @@ -338,7 +338,8 @@ def test_remove_redundant_surfaces(run_in_tmpdir): 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, cull_surfaces=True) + geom = openmc.Geometry(root) + geom.merge_surfaces=True model = openmc.model.Model(geometry=geom, materials=openmc.Materials([m1, m2, m3])) From e8d3e14adf16ad0ebe6413e0d7e81a22bab0cee2 Mon Sep 17 00:00:00 2001 From: Ethan Peterson Date: Wed, 26 Oct 2022 12:13:43 -0400 Subject: [PATCH 7/9] cache redundant_surfaces --- openmc/geometry.py | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/openmc/geometry.py b/openmc/geometry.py index 2cdc356e8..08608a5cd 100644 --- a/openmc/geometry.py +++ b/openmc/geometry.py @@ -37,6 +37,7 @@ class Geometry: def __init__(self, root=None): self._root_universe = None self._offsets = {} + self._redundant_surface_map = None self.merge_surfaces = False self.surface_precision = 10 if root is not None: @@ -445,15 +446,21 @@ class Geometry: that should replace it. """ - tally = defaultdict(list) - for surf in self.get_all_surfaces().values(): - coeffs = tuple(round(surf._coefficients[k], self.surface_precision) - for k in surf._coeff_keys) - key = (surf._type,) + coeffs - tally[key].append(surf) - return {replace.id: keep - for keep, *redundant in tally.values() - for replace in redundant} + # check if redundant surfaces have not been calculated yet + if self._redundant_surface_map is None: + tally = defaultdict(list) + for surf in self.get_all_surfaces().values(): + coeffs = tuple(round(surf._coefficients[k], + self.surface_precision) + for k in surf._coeff_keys) + key = (surf._type,) + coeffs + tally[key].append(surf) + + self._redundant_surface_map = {replace.id: keep + for keep, *redundant in tally.values() + for replace in redundant} + + return self._redundant_surface_map def _get_domains_by_name(self, name, case_sensitive, matching, domain_type): if not case_sensitive: @@ -607,11 +614,14 @@ class Geometry: # Get redundant surfaces redundant_surfaces = self.get_redundant_surfaces() - # Iterate through all cells contained in the geometry - for cell in self.get_all_cells().values(): - # Recursively remove redundant surfaces from regions - if cell.region: - cell.region.remove_redundant_surfaces(redundant_surfaces) + if redundant_surfaces: + # Iterate through all cells contained in the geometry + for cell in self.get_all_cells().values(): + # Recursively remove redundant surfaces from regions + if cell.region: + cell.region.remove_redundant_surfaces(redundant_surfaces) + + self._redundant_surface_map = None def determine_paths(self, instances_only=False): """Determine paths through CSG tree for cells and materials. From f5f42a4c80536ee39c154a518fad0acc375d3956 Mon Sep 17 00:00:00 2001 From: Ethan Peterson Date: Wed, 26 Oct 2022 13:37:09 -0400 Subject: [PATCH 8/9] Update openmc/geometry.py Co-authored-by: Patrick Shriwise --- openmc/geometry.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openmc/geometry.py b/openmc/geometry.py index 08608a5cd..379a2bb4e 100644 --- a/openmc/geometry.py +++ b/openmc/geometry.py @@ -448,16 +448,16 @@ class Geometry: """ # check if redundant surfaces have not been calculated yet if self._redundant_surface_map is None: - tally = defaultdict(list) + redundancies = defaultdict(list) for surf in self.get_all_surfaces().values(): coeffs = tuple(round(surf._coefficients[k], self.surface_precision) for k in surf._coeff_keys) key = (surf._type,) + coeffs - tally[key].append(surf) + redundancies[key].append(surf) self._redundant_surface_map = {replace.id: keep - for keep, *redundant in tally.values() + for keep, *redundant in redundancies.values() for replace in redundant} return self._redundant_surface_map From 1110038939b8d72d36e9ac7e202f6a6899bfe708 Mon Sep 17 00:00:00 2001 From: Ethan Peterson Date: Tue, 8 Nov 2022 21:04:15 -0500 Subject: [PATCH 9/9] remove get_redundant_surfaces and cache --- openmc/geometry.py | 62 +++++++++++++------------------ openmc/model/model.py | 3 ++ tests/unit_tests/test_geometry.py | 9 ++--- 3 files changed, 32 insertions(+), 42 deletions(-) diff --git a/openmc/geometry.py b/openmc/geometry.py index 379a2bb4e..3b6933362 100644 --- a/openmc/geometry.py +++ b/openmc/geometry.py @@ -37,7 +37,6 @@ class Geometry: def __init__(self, root=None): self._root_universe = None self._offsets = {} - self._redundant_surface_map = None self.merge_surfaces = False self.surface_precision = 10 if root is not None: @@ -430,38 +429,6 @@ class Geometry: surfaces = cell.region.get_surfaces(surfaces) return surfaces - def get_redundant_surfaces(self): - """Return all of the topologically redundant surface IDs. - - Uses surface_precision attribute of Geometry instance for rounding and - comparing surface coefficients. - - .. versionadded:: 0.12 - - Returns - ------- - dict - Dictionary whose keys are the ID of a redundant surface and whose - values are the topologically equivalent :class:`openmc.Surface` - that should replace it. - - """ - # check if redundant surfaces have not been calculated yet - if self._redundant_surface_map is None: - redundancies = defaultdict(list) - for surf in self.get_all_surfaces().values(): - coeffs = tuple(round(surf._coefficients[k], - self.surface_precision) - for k in surf._coeff_keys) - key = (surf._type,) + coeffs - redundancies[key].append(surf) - - self._redundant_surface_map = {replace.id: keep - for keep, *redundant in redundancies.values() - for replace in redundant} - - return self._redundant_surface_map - def _get_domains_by_name(self, name, case_sensitive, matching, domain_type): if not case_sensitive: name = name.lower() @@ -609,10 +576,33 @@ class Geometry: return self._get_domains_by_name(name, case_sensitive, matching, 'lattice') def remove_redundant_surfaces(self): - """Remove redundant surfaces from the geometry.""" + """Remove and return all of the redundant surfaces. + Uses surface_precision attribute of Geometry instance for rounding and + comparing surface coefficients. + + .. versionadded:: 0.12 + + Returns + ------- + redundant_surfaces + Dictionary whose keys are the ID of a redundant surface and whose + values are the topologically equivalent :class:`openmc.Surface` + that should replace it. + + """ # Get redundant surfaces - redundant_surfaces = self.get_redundant_surfaces() + redundancies = defaultdict(list) + for surf in self.get_all_surfaces().values(): + coeffs = tuple(round(surf._coefficients[k], + self.surface_precision) + for k in surf._coeff_keys) + key = (surf._type,) + coeffs + redundancies[key].append(surf) + + redundant_surfaces = {replace.id: keep + for keep, *redundant in redundancies.values() + for replace in redundant} if redundant_surfaces: # Iterate through all cells contained in the geometry @@ -621,7 +611,7 @@ class Geometry: if cell.region: cell.region.remove_redundant_surfaces(redundant_surfaces) - self._redundant_surface_map = None + return redundant_surfaces def determine_paths(self, instances_only=False): """Determine paths through CSG tree for cells and materials. diff --git a/openmc/model/model.py b/openmc/model/model.py index 7126987cb..98136b2d5 100644 --- a/openmc/model/model.py +++ b/openmc/model/model.py @@ -422,6 +422,9 @@ class Model: warnings.warn("remove_surfs kwarg will be deprecated soon, please " "set the Geometry.merge_surfaces attribute instead.") self.geometry.merge_surfaces = True + # Can be used to modify tallies in case any surfaces are redundant + redundant_surfaces = self.geometry.remove_redundant_surfaces() + self.geometry.export_to_xml(d) # If a materials collection was specified, export it. Otherwise, look diff --git a/tests/unit_tests/test_geometry.py b/tests/unit_tests/test_geometry.py index 6a092126e..9db112fd2 100644 --- a/tests/unit_tests/test_geometry.py +++ b/tests/unit_tests/test_geometry.py @@ -302,7 +302,7 @@ def test_rotation_matrix(): assert geom.find((0.0, -0.5, 0.0))[-1] == c1 assert geom.find((0.0, -1.5, 0.0))[-1] == c2 -def test_remove_redundant_surfaces(run_in_tmpdir): +def test_remove_redundant_surfaces(): """Test ability to remove redundant surfaces""" m1 = openmc.Material() @@ -344,11 +344,8 @@ def test_remove_redundant_surfaces(run_in_tmpdir): materials=openmc.Materials([m1, m2, m3])) # There should be 6 redundant surfaces in this geometry - n_redundant_surfs = len(geom.get_redundant_surfaces().keys()) + n_redundant_surfs = len(geom.remove_redundant_surfaces().keys()) assert n_redundant_surfs == 6 - # Remove redundant surfaces on export - model.export_to_xml() - geom = openmc.Geometry.from_xml() # There should be 0 remaining redundant surfaces - n_redundant_surfs = len(geom.get_redundant_surfaces().keys()) + n_redundant_surfs = len(geom.remove_redundant_surfaces().keys()) assert n_redundant_surfs == 0