Fix writing identical filters with different user IDs to tallies.xml

This commit is contained in:
amandalund 2017-03-28 15:19:05 -05:00
parent 8b1953b7e1
commit 3670d6eda9

View file

@ -3468,6 +3468,20 @@ class Tallies(cv.CheckedList):
# Continue iterating from the first loop
break
def remove_duplicate_filters(self):
"""Search all tallies for any identical filters and set the IDs of
identical filters to the same value. This prevents a filter from being
written multiple times to the tallies.xml input file.
"""
for tally1 in self:
for filter1 in tally1.filters:
for tally2 in self:
for filter2 in tally2.filters:
if filter1 == filter2:
filter2.id = filter1.id
def add_mesh(self, mesh):
"""Add a mesh to the file
@ -3539,16 +3553,23 @@ class Tallies(cv.CheckedList):
for d in derivs:
root_element.append(d.to_xml_element())
def export_to_xml(self, path='tallies.xml'):
def export_to_xml(self, path='tallies.xml', reduce_filters=True):
"""Create a tallies.xml file that can be used for a simulation.
Parameters
----------
path : str
Path to file to write. Defaults to 'tallies.xml'.
reduce_filters : bool
Indicates whether duplicate filters should be removed. This
prevents identical filters with different user IDs from being
written to the tallies.xml input file. Defaults to True.
"""
if reduce_filters:
self.remove_duplicate_filters()
root_element = ET.Element("tallies")
self._create_mesh_subelements(root_element)
self._create_filter_subelements(root_element)