From a614ba3a3baa96578b98f49fd48945a34f526972 Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Thu, 19 Mar 2015 11:51:02 -0400 Subject: [PATCH] Updated Tally.__eq__ routine to account for floating point precision --- src/utils/openmc/tallies.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/utils/openmc/tallies.py b/src/utils/openmc/tallies.py index 50b2888c94..dd0fc77cd2 100644 --- a/src/utils/openmc/tallies.py +++ b/src/utils/openmc/tallies.py @@ -51,8 +51,12 @@ class Filter(object): if self._type != filter2._type: return False + # Check number of bins + elif len(self._bins) != len(filter2._bins): + return False + # Check bin edges - elif list(self._bins) != list(filter2._bins): + elif not np.allclose(self._bins, filter2._bins): return False else: @@ -699,6 +703,24 @@ class Tally(object): 'string'.format(score, self._id) raise ValueError(msg) + elif 'scatter-' in score: + + moment = score.split('-')[-1] + + if 'p' in moment.lower() or 'y' in moment.lower(): + moment = moment[1:] + + if int(moment) < 0 or int(moment) > 10: + msg = 'Unable to add score {0} to Tally ID={1} since OpenMC ' \ + 'can only tally the scattering moments between 0 and ' \ + '10'.format(score, self._id) + raise ValueError(msg) + + elif not score in SCORE_TYPES.values(): + msg = 'Unable to add score {0} to Tally ID={1} since it is not a ' \ + 'supported score in OpenMC'.format(score, self._id) + raise ValueError(msg) + # If the score is already in the Tally, don't add it again if score in self._scores: return @@ -1232,4 +1254,4 @@ class TalliesFile(object): # Write the XML Tree to the tallies.xml file tree = ET.ElementTree(self._tallies_file) tree.write("tallies.xml", xml_declaration=True, - encoding='utf-8', method="xml") + encoding='utf-8', method="xml") \ No newline at end of file