Add two methods on Nuclide: add_decay_mode and add_reaction

This commit is contained in:
Paul Romano 2020-07-23 14:15:10 -05:00
parent 1d187b3a8a
commit d83b9568c9
2 changed files with 81 additions and 62 deletions

View file

@ -415,7 +415,7 @@ class Chain:
for m in data.modes[:-1])
# Append decay mode
nuclide.decay_modes.append(DecayTuple(type_, target, br))
nuclide.add_decay_mode(type_, target, br)
fissionable = False
if parent in reactions:
@ -441,47 +441,44 @@ class Chain:
else:
q_value = 0.0
nuclide.reactions.append(ReactionTuple(
name, daughter, q_value, 1.0))
nuclide.add_reaction(name, daughter, q_value, 1.0)
if any(mt in reactions_available for mt in openmc.data.FISSION_MTS):
q_value = reactions[parent][18]
nuclide.reactions.append(
ReactionTuple('fission', None, q_value, 1.0))
nuclide.add_reaction('fission', None, q_value, 1.0)
fissionable = True
if fissionable:
if parent in fpy_data:
fpy = fpy_data[parent]
if fpy.energies is not None:
yield_energies = fpy.energies
else:
yield_energies = [0.0]
yield_data = {}
for E, yield_table in zip(yield_energies, fpy.independent):
yield_replace = 0.0
yields = defaultdict(float)
for product, y in yield_table.items():
# Handle fission products that have no decay data
if product not in decay_data:
daughter = replace_missing(product, decay_data)
product = daughter
yield_replace += y.nominal_value
yields[product] += y.nominal_value
if yield_replace > 0.0:
missing_fp.append((parent, E, yield_replace))
yield_data[E] = yields
nuclide.yield_data = FissionYieldDistribution(yield_data)
else:
nuclide._fpy = replace_missing_fpy(parent, fpy_data, decay_data)
missing_fpy.append((parent, nuclide._fpy))
continue
if fpy.energies is not None:
yield_energies = fpy.energies
else:
yield_energies = [0.0]
yield_data = {}
for E, yield_table in zip(yield_energies, fpy.independent):
yield_replace = 0.0
yields = defaultdict(float)
for product, y in yield_table.items():
# Handle fission products that have no decay data
if product not in decay_data:
daughter = replace_missing(product, decay_data)
product = daughter
yield_replace += y.nominal_value
yields[product] += y.nominal_value
if yield_replace > 0.0:
missing_fp.append((parent, E, yield_replace))
yield_data[E] = yields
nuclide.yield_data = FissionYieldDistribution(yield_data)
# Add nuclide to chain
chain.add_nuclide(nuclide)
@ -881,8 +878,7 @@ class Chain:
all_meta = True
for target, br in new_ratios.items():
all_meta = all_meta and ("_m" in target)
parent.reactions.append(ReactionTuple(
reaction, target, rxn_Q, br))
parent.add_reaction(reaction, target, rxn_Q, br)
# If branching ratios don't add to unity, add reaction to ground
# with remainder of branching ratio
@ -893,8 +889,7 @@ class Chain:
pz, pa, pm = zam(parent_name)
ground_target = gnd_name(pz, pa + 1, 0)
new_ratios[ground_target] = ground_br
parent.reactions.append(ReactionTuple(
reaction, ground_target, rxn_Q, ground_br))
parent.add_reaction(reaction, ground_target, rxn_Q, ground_br)
@property
def fission_yields(self):
@ -1018,9 +1013,7 @@ class Chain:
# Avoid re-sorting for fission yields
name_sort = sorted(all_isotopes)
nuclides = []
nuclide_dict = {}
reactions = set()
new_chain = type(self)()
for idx, iso in enumerate(sorted(all_isotopes, key=openmc.data.zam)):
previous = self[iso]
@ -1030,44 +1023,29 @@ class Chain:
if hasattr(previous, '_fpy'):
new_nuclide._fpy = previous._fpy
new_decay = []
for mode in previous.decay_modes:
if mode.target in all_isotopes:
new_decay.append(mode)
new_nuclide.add_decay_mode(*mode)
else:
new_decay.append(DecayTuple(
mode.type, None, mode.branching_ratio))
new_nuclide.decay_modes = new_decay
new_nuclide.add_decay_mode(mode.type, None, mode.branching_ratio)
new_reactions = []
for rxn in previous.reactions:
if rxn.target in all_isotopes:
new_reactions.append(rxn)
reactions.add(rxn.type)
elif rxn.type == "fission":
for rx in previous.reactions:
if rx.target in all_isotopes:
new_nuclide.add_reaction(*rx)
elif rx.type == "fission":
new_yields = new_nuclide.yield_data = (
previous.yield_data.restrict_products(name_sort))
if new_yields is not None:
new_reactions.append(rxn)
reactions.add("fission")
new_nuclide.add_reaction(*rx)
# Maintain total destruction rates but set no target
else:
new_reactions.append(ReactionTuple(
rxn.type, None, rxn.Q, rxn.branching_ratio))
reactions.add(rxn.type)
new_nuclide.add_reaction(rx.type, None, rx.Q, rx.branching_ratio)
new_nuclide.reactions = new_reactions
nuclides.append(new_nuclide)
nuclide_dict[iso] = idx
new_chain = type(self)()
new_chain.nuclides = nuclides
new_chain.nuclide_dict = nuclide_dict
new_chain.add_nuclide(new_nuclide)
# Doesn't appear that the ordering matters for the reactions,
# just the contents
new_chain.reactions = sorted(reactions)
new_chain.reactions = sorted(new_chain.reactions)
return new_chain

View file

@ -154,6 +154,47 @@ class Nuclide:
return None
return self.yield_data.energies
def add_decay_mode(self, type, target, branching_ratio):
"""Add decay mode to the nuclide
Parameters
----------
type : str
Type of the decay mode, e.g., 'beta-'
target : str or None
Nuclide resulting from decay. A value of ``None`` implies the
target does not exist in the currently configured depletion
chain
branching_ratio : float
Branching ratio of the decay mode
"""
self.decay_modes.append(
DecayTuple(type, target, branching_ratio)
)
def add_reaction(self, type, target, Q, branching_ratio):
"""Add transmutation reaction to the nuclide
Parameters
----------
type : str
Type of the reaction, e.g., 'fission'
target : str or None
Nuclide resulting from reaction. A value of ``None``
implies either no single target, e.g. from fission,
or that the target nuclide is not considered
in the current depletion chain
Q : float
Q value of the reaction in [eV]
branching_ratio : float
Branching ratio of the reaction
"""
self.reactions.append(
ReactionTuple(type, target, Q, branching_ratio)
)
@classmethod
def from_xml(cls, element, root=None, fission_q=None):
"""Read nuclide from an XML element.