From 726d1a268f9419db35f3aaf21b2cafa976a98c4a Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Tue, 28 Nov 2017 23:04:12 -0600 Subject: [PATCH] Sort materials list before creating elements --- openmc/geometry.py | 2 +- openmc/material.py | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/openmc/geometry.py b/openmc/geometry.py index 0b02210b7e..88c9f18348 100644 --- a/openmc/geometry.py +++ b/openmc/geometry.py @@ -87,7 +87,7 @@ class Geometry(object): # Write the XML Tree to the geometry.xml file tree = ET.ElementTree(root_element) - tree.write(path, xml_declaration=True, encoding='utf-8', method="xml") + tree.write(path, xml_declaration=True, encoding='utf-8') def find(self, point): """Find cells/universes/lattices which contain a given point diff --git a/openmc/material.py b/openmc/material.py index 03ef7fbc42..3800d89c67 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -10,7 +10,7 @@ import numpy as np import openmc import openmc.data import openmc.checkvalue as cv -from openmc.clean_xml import sort_xml_elements, clean_xml_indentation +from openmc.clean_xml import clean_xml_indentation from .mixin import IDManagerMixin @@ -1129,7 +1129,7 @@ class Materials(cv.CheckedList): material.make_isotropic_in_lab() def _create_material_subelements(self, root_element): - for material in self: + for material in sorted(self, key=lambda x: x.id): root_element.append(material.to_xml_element(self.cross_sections)) def _create_cross_sections_subelement(self, root_element): @@ -1153,14 +1153,13 @@ class Materials(cv.CheckedList): """ root_element = ET.Element("materials") - self._create_material_subelements(root_element) self._create_cross_sections_subelement(root_element) self._create_multipole_library_subelement(root_element) + self._create_material_subelements(root_element) # Clean the indentation in the file to be user-readable - sort_xml_elements(root_element) clean_xml_indentation(root_element) # Write the XML Tree to the materials.xml file tree = ET.ElementTree(root_element) - tree.write(path, xml_declaration=True, encoding='utf-8', method="xml") + tree.write(path, xml_declaration=True, encoding='utf-8')