Add property setters for Tally.scores, nuclides, filters, triggers

This commit is contained in:
Paul Romano 2016-02-02 10:07:08 -06:00
parent 12f2467d6e
commit 9b152b0ddf
14 changed files with 257 additions and 279 deletions

View file

@ -1,6 +1,7 @@
from numbers import Real
from xml.etree import ElementTree as ET
import sys
import warnings
from openmc.checkvalue import check_type, check_value
@ -8,6 +9,10 @@ if sys.version_info[0] >= 3:
basestring = str
# DeprecationWarning filter for the Trigger.add_score(...) method
warnings.simplefilter('always', DeprecationWarning)
class Trigger(object):
"""A criterion for when to finish a simulation based on tally uncertainties.
@ -46,9 +51,7 @@ class Trigger(object):
clone._trigger_type = self._trigger_type
clone._threshold = self._threshold
clone._scores = []
for score in self._scores:
clone.add_score(score)
clone.scores = self.scores
memo[id(self)] = clone
@ -97,6 +100,17 @@ class Trigger(object):
check_type('tally trigger threshold', threshold, Real)
self._threshold = threshold
@scores.setter
def scores(self, scores):
cv.check_type('trigger scores', scores, Iterable, basestring)
# Set scores making sure not to have duplicates
self._scores = []
for score in scores:
if score not in self._scores:
self._scores.append(score)
def add_score(self, score):
"""Add a score to the list of scores to be checked against the trigger.
@ -107,16 +121,11 @@ class Trigger(object):
"""
if not isinstance(score, basestring):
msg = 'Unable to add score "{0}" to tally trigger since ' \
'it is not a string'.format(score)
raise ValueError(msg)
# If the score is already in the Tally, don't add it again
if score in self._scores:
return
else:
self._scores.append(score)
warnings.warn("Trigger.add_score(...) has been deprecated and may be "
"removed in a future version. Tally trigger scores should "
"be defined using the scores property directly.",
DeprecationWarning)
self.scores.append(score)
def get_trigger_xml(self, element):
"""Return XML representation of the trigger