From afaf3b04bf82e37e36c0c3a0466d1fd2f36d8d20 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 13 Oct 2020 11:40:07 -0500 Subject: [PATCH] Updates to the Python API to support model generation with DAGMC universes. --- openmc/cell.py | 9 ++++----- openmc/filter.py | 10 +++++----- openmc/geometry.py | 9 ++++----- openmc/lattice.py | 2 +- openmc/universe.py | 13 ++++++++++++- 5 files changed, 26 insertions(+), 17 deletions(-) diff --git a/openmc/cell.py b/openmc/cell.py index c55238df86..af1a07f9a9 100644 --- a/openmc/cell.py +++ b/openmc/cell.py @@ -27,7 +27,7 @@ class Cell(IDManagerMixin): automatically be assigned. name : str, optional Name of the cell. If not specified, the name is the empty string. - fill : openmc.Material or openmc.Universe or openmc.Lattice or None or iterable of openmc.Material, optional + fill : openmc.Material or openmc.UniverseBase or openmc.Lattice or None or iterable of openmc.Material, optional Indicates what the region of space is filled with region : openmc.Region, optional Region of space that is assigned to the cell. @@ -38,7 +38,7 @@ class Cell(IDManagerMixin): Unique identifier for the cell name : str Name of the cell - fill : openmc.Material or openmc.Universe or openmc.Lattice or None or iterable of openmc.Material + fill : openmc.Material or openmc.UniverseBase or openmc.Lattice or None or iterable of openmc.Material Indicates what the region of space is filled with. If None, the cell is treated as a void. An iterable of materials is used to fill repeated instances of a cell with different materials. @@ -156,7 +156,7 @@ class Cell(IDManagerMixin): def fill_type(self): if isinstance(self.fill, openmc.Material): return 'material' - elif isinstance(self.fill, openmc.Universe): + elif isinstance(self.fill, openmc.UniverseBase): return 'universe' elif isinstance(self.fill, openmc.Lattice): return 'lattice' @@ -278,11 +278,10 @@ class Cell(IDManagerMixin): cv.check_type('cell.fill[i]', f, openmc.Material) elif not isinstance(fill, (openmc.Material, openmc.Lattice, - openmc.Universe)): + openmc.UniverseBase)): msg = ('Unable to set Cell ID="{0}" to use a non-Material or ' 'Universe fill "{1}"'.format(self._id, fill)) raise ValueError(msg) - self._fill = fill # Info about atom content can now be invalid diff --git a/openmc/filter.py b/openmc/filter.py index 8da3cf78f6..f0ea7d7215 100644 --- a/openmc/filter.py +++ b/openmc/filter.py @@ -15,7 +15,7 @@ from .cell import Cell from .material import Material from .mixin import IDManagerMixin from .surface import Surface -from .universe import Universe +from .universe import UniverseBase _FILTER_TYPES = ( @@ -408,8 +408,8 @@ class UniverseFilter(WithIDFilter): Parameters ---------- - bins : openmc.Universe, int, or iterable thereof - The Universes to tally. Either openmc.Universe objects or their + bins : openmc.UniverseBase, int, or iterable thereof + The Universes to tally. Either openmc.UniverseBase objects or their Integral ID numbers can be used. filter_id : int Unique identifier for the filter @@ -417,14 +417,14 @@ class UniverseFilter(WithIDFilter): Attributes ---------- bins : Iterable of Integral - openmc.Universe IDs. + openmc.UniverseBase IDs. id : int Unique identifier for the filter num_bins : Integral The number of filter bins """ - expected_type = Universe + expected_type = UniverseBase class MaterialFilter(WithIDFilter): diff --git a/openmc/geometry.py b/openmc/geometry.py index 30decd9ff8..36cff94e30 100644 --- a/openmc/geometry.py +++ b/openmc/geometry.py @@ -14,13 +14,13 @@ class Geometry: Parameters ---------- - root : openmc.Universe or Iterable of openmc.Cell, optional + 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. Attributes ---------- - root_universe : openmc.Universe + root_universe : openmc.UniverseBase Root universe which contains all others bounding_box : 2-tuple of numpy.array Lower-left and upper-right coordinates of an axis-aligned bounding box @@ -32,7 +32,7 @@ class Geometry: self._root_universe = None self._offsets = {} if root is not None: - if isinstance(root, openmc.Universe): + if isinstance(root, openmc.UniverseBase): self.root_universe = root else: univ = openmc.Universe() @@ -50,8 +50,7 @@ class Geometry: @root_universe.setter def root_universe(self, root_universe): - check_type('root universe', root_universe, - (openmc.Universe, openmc.DAGMCUniverse)) + check_type('root universe', root_universe, openmc.UniverseBase) self._root_universe = root_universe def add_volume_information(self, volume_calc): diff --git a/openmc/lattice.py b/openmc/lattice.py index 252fbf3274..5112dde05a 100644 --- a/openmc/lattice.py +++ b/openmc/lattice.py @@ -488,7 +488,7 @@ class RectLattice(Lattice): @Lattice.universes.setter def universes(self, universes): - cv.check_iterable_type('lattice universes', universes, openmc.Universe, + cv.check_iterable_type('lattice universes', universes, openmc.UniverseBase, min_depth=2, max_depth=3) self._universes = np.asarray(universes) diff --git a/openmc/universe.py b/openmc/universe.py index be6aa00fd7..f71aec664a 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -4,6 +4,7 @@ from collections.abc import Iterable from copy import copy, deepcopy from numbers import Real import random +from xml.etree import ElementTree as ET import numpy as np @@ -677,10 +678,20 @@ class DAGMCUniverse(UniverseBase): def clone(self, clone_materials=True, clone_regions=True, memo=None): pass + def get_all_cells(self, memo=None): + return OrderedDict() + def create_xml_subelement(self, xml_element, memo=None): + + if memo and self in memo: + return + + if memo is not None: + memo.add(self) + # Set xml element values dagmc_element = ET.Element('dagmc') - dagmc_element.set('id', self.id) + dagmc_element.set('id', str(self.id)) dagmc_element.set('name', self.name) dagmc_element.set('filename', self.filename) xml_element.append(dagmc_element)