From 2e716589a14d2465ab4a494e12ddf86172af72e3 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 3 Nov 2022 23:57:22 -0500 Subject: [PATCH] Other bug fixes --- openmc/geometry.py | 32 ++++++++++++++++---------------- openmc/model/model.py | 6 +++--- openmc/plots.py | 7 ++++--- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/openmc/geometry.py b/openmc/geometry.py index b4f8046bd2..d036df9c74 100644 --- a/openmc/geometry.py +++ b/openmc/geometry.py @@ -204,24 +204,24 @@ class Geometry: surfaces[s1].periodic_surface = surfaces[s2] # Add any DAGMC universes - for elem in elem.findall('dagmc_universe'): - dag_univ = openmc.DAGMCUniverse.from_xml_element(elem) + for e in elem.findall('dagmc_universe'): + dag_univ = openmc.DAGMCUniverse.from_xml_element(e) universes[dag_univ.id] = dag_univ # Dictionary that maps each universe to a list of cells/lattices that # contain it (needed to determine which universe is the elem) child_of = defaultdict(list) - for elem in elem.findall('lattice'): - lat = openmc.RectLattice.from_xml_element(elem, get_universe) + for e in elem.findall('lattice'): + lat = openmc.RectLattice.from_xml_element(e, get_universe) universes[lat.id] = lat if lat.outer is not None: child_of[lat.outer].append(lat) for u in lat.universes.ravel(): child_of[u].append(lat) - for elem in elem.findall('hex_lattice'): - lat = openmc.HexLattice.from_xml_element(elem, get_universe) + for e in elem.findall('hex_lattice'): + lat = openmc.HexLattice.from_xml_element(e, get_universe) universes[lat.id] = lat if lat.outer is not None: child_of[lat.outer].append(lat) @@ -235,15 +235,8 @@ class Geometry: for u in ring: child_of[u].append(lat) - # Create dictionary to easily look up materials - if materials is None: - filename = Path(path).parent / 'materials.xml' - materials = openmc.Materials.from_xml(str(filename)) - mats = {str(m.id): m for m in materials} - mats['void'] = None - - for elem in elem.findall('cell'): - c = openmc.Cell.from_xml_element(elem, surfaces, mats, get_universe) + for e in elem.findall('cell'): + c = openmc.Cell.from_xml_element(e, surfaces, materials, get_universe) if c.fill_type in ('universe', 'lattice'): child_of[c.fill].append(c) @@ -276,7 +269,14 @@ class Geometry: tree = ET.parse(path) root = tree.getroot() - return cls.from_xml_element(root, materials) + # Create dictionary to easily look up materials + if materials is None: + filename = Path(path).parent / 'materials.xml' + materials = openmc.Materials.from_xml(str(filename)) + mats = {str(m.id): m for m in materials} + mats['void'] = None + + return cls.from_xml_element(root, mats) def find(self, point): """Find cells/universes/lattices which contain a given point diff --git a/openmc/model/model.py b/openmc/model/model.py index 2193084c36..a839dc8f0c 100644 --- a/openmc/model/model.py +++ b/openmc/model/model.py @@ -208,11 +208,11 @@ class Model: self._plots.append(plot) @classmethod - def from_xml(cls, separate_xmls=True, **kwargs): + def from_xml(cls, *args, separate_xmls=True, **kwargs): if separate_xmls: - return cls.from_separate_xmls(**kwargs) + return cls.from_separate_xmls(*args, **kwargs) else: - return cls.from_model_xml(**kwargs) + return cls.from_model_xml(*args, **kwargs) @classmethod def from_model_xml(cls, path='model.xml'): diff --git a/openmc/plots.py b/openmc/plots.py index badea2e586..b1f1927876 100644 --- a/openmc/plots.py +++ b/openmc/plots.py @@ -919,6 +919,7 @@ class Plots(cv.CheckedList): # Clean the indentation in the file to be user-readable clean_indentation(self._plots_file) + reorder_attributes(self._plots_file) # TODO: Remove when support is Python 3.8+ return self._plots_file @@ -936,8 +937,8 @@ class Plots(cv.CheckedList): if p.is_dir(): p /= 'plots.xml' + self.to_xml_element() # Write the XML Tree to the plots.xml file - reorder_attributes(self._plots_file) # TODO: Remove when support is Python 3.8+ tree = ET.ElementTree(self._plots_file) tree.write(str(p), xml_declaration=True, encoding='utf-8') @@ -958,8 +959,8 @@ class Plots(cv.CheckedList): """ # Generate each plot plots = cls() - for elem in elem.findall('plot'): - plots.append(Plot.from_xml_element(elem)) + for e in elem.findall('plot'): + plots.append(Plot.from_xml_element(e)) return plots @classmethod