Add minor changes from code review to deplete.Nuclide.validate

This commit is contained in:
Andrew Johnson 2019-08-19 10:07:20 -05:00
parent 0de7618f95
commit 32f3c27cf6
No known key found for this signature in database
GPG key ID: 253418E91B7F6FEB
3 changed files with 5 additions and 8 deletions

View file

@ -623,7 +623,7 @@ class Chain(object):
1) For all non-fission reactions, does the sum of branching
ratios equal about one?
2) For fission reactions, does the sum of fission yield
fractions equal about 2?
fractions equal about two?
Parameters
----------
@ -639,6 +639,7 @@ class Chain(object):
value ``x`` to intended value ``y`` as::
valid = (y - tolerance <= x <= y + tolerance)
Returns
-------
valid : bool

View file

@ -4,7 +4,6 @@ Contains the per-nuclide components of a depletion chain.
"""
from collections import namedtuple, defaultdict
from operator import attrgetter, itemgetter
from warnings import warn
try:
import lxml.etree as ET
@ -266,10 +265,8 @@ class Nuclide(object):
openmc.deplete.Chain.validate
"""
branch_getter = attrgetter("branching_ratio")
msg_func = ("Nuclide {name} has {prop} that sum to {actual} "
"instead of {expected} +/- {tol:7.4e}").format
type_map = defaultdict(set)
valid = True
# check decay modes
@ -288,7 +285,7 @@ class Nuclide(object):
valid = False
if self.reactions:
type_map.clear()
type_map = defaultdict(set)
for reaction in self.reactions:
type_map[reaction.type].add(reaction)
for rxn_type, reactions in type_map.items():
@ -306,8 +303,7 @@ class Nuclide(object):
warn(msg)
valid = False
if self.yield_data > 0:
yield_getter = itemgetter(1)
if self.yield_data:
for energy, yield_list in self.yield_data.items():
sum_yield = sum(y[1] for y in yield_list)
stat = 2.0 - tolerance <= sum_yield <= 2.0 + tolerance

View file

@ -176,7 +176,7 @@ def test_validate():
# restore reactions, invalidate fission yields
nuc.reactions.append(reaction)
fission_yields = nuc.yield_data[1e6].pop()
nuc.yield_data[1e6].pop()
with pytest.raises(ValueError, match=r"fission yields.*1\.0*e"):
nuc.validate(strict=True, quiet=False, tolerance=0.0)