From ec1a4b5d2b8a092bc2bbec86b6f0f04882c685a5 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 5 Mar 2019 13:22:50 -0600 Subject: [PATCH] Adding documentation to create_xml_subelement methods. Removing old, now unused, path variables from those methods as well. --- openmc/cell.py | 17 ++++++++++++++++- openmc/lattice.py | 25 +++++++++++++++++-------- openmc/universe.py | 18 +++++++++++++++++- 3 files changed, 50 insertions(+), 10 deletions(-) diff --git a/openmc/cell.py b/openmc/cell.py index bb59b1d3a..fb39dd7ec 100644 --- a/openmc/cell.py +++ b/openmc/cell.py @@ -463,7 +463,23 @@ class Cell(IDManagerMixin): return memo[self] def create_xml_subelement(self, xml_element, memo=None): + """Add the cell's xml representation to an incoming xml element + Parameters + ---------- + xml_element : xml.etree.ElementTree.Element + XML element to be added to + + memo : dict or None + A dictionary containing sets of universe, lattice, cell, and surface + id sets already written to the xml_element. This parameter + is used internally and should not be specified by the user. + + Returns + ------- + None + + """ element = ET.Element("cell") element.set("id", str(self.id)) @@ -500,7 +516,6 @@ class Cell(IDManagerMixin): # thus far. def create_surface_elements(node, element, memo=None): if isinstance(node, Halfspace): - path = "./surface[@id='{}']".format(node.surface.id) if memo and node.surface.id in memo['surfaces']: return if memo is not None: diff --git a/openmc/lattice.py b/openmc/lattice.py index dff00306a..0434d626b 100644 --- a/openmc/lattice.py +++ b/openmc/lattice.py @@ -753,11 +753,24 @@ class RectLattice(Lattice): 0 <= idx[2] < self.shape[2]) def create_xml_subelement(self, xml_element, memo=None): - # Determine if XML element already contains subelement for this Lattice - path = './lattice[@id=\'{0}\']'.format(self._id) - test = xml_element.find(path) + """Add the lattice xml representation to an incoming xml element - # If the element does contain the Lattice subelement, then return + Parameters + ---------- + xml_element : xml.etree.ElementTree.Element + XML element to be added to + + memo : dict or None + A dictionary containing sets of universe, lattice, cell, and surface + id sets already written to the xml_element. This parameter + is used internally and should not be specified by the user. + + Returns + ------- + None + + """ + # If the element already contains the Lattice subelement, then return if memo and self._id in memo['lattices']: return if memo is not None: @@ -1275,10 +1288,6 @@ class HexLattice(Lattice): return g < self.num_rings and 0 <= idx[2] < self.num_axial def create_xml_subelement(self, xml_element, memo=None): - # Determine if XML element already contains subelement for this Lattice - path = './hex_lattice[@id=\'{0}\']'.format(self._id) - test = xml_element.find(path) - # If the element does contain the Lattice subelement, then return if memo and self._id in memo['lattices']: return diff --git a/openmc/universe.py b/openmc/universe.py index ea8c7f294..e1c1e1b0c 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -512,9 +512,25 @@ class Universe(IDManagerMixin): return memo[self] def create_xml_subelement(self, xml_element, memo=None): + """Add the universe xml representation to an incoming xml element + + Parameters + ---------- + xml_element : xml.etree.ElementTree.Element + XML element to be added to + + memo : dict or None + A dictionary containing sets of universe, lattice, cell, and surface + id sets already written to the xml_element. This parameter + is used internally and should not be specified by the user. + + Returns + ------- + None + + """ # Iterate over all Cells for cell_id, cell in self._cells.items(): - path = "./cell[@id='{}']".format(cell_id) # If the cell was not already written, write it if memo and cell_id in memo['cells']: