From 2948a1c0f9b0fc3e5ca952c1bec30ba9be808c39 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Mon, 26 Feb 2024 15:17:16 +0000 Subject: [PATCH 1/2] added get_reaction_pathways_to_target --- openmc/deplete/chain.py | 32 +++++++++++++++++++++++++- tests/unit_tests/test_deplete_chain.py | 12 ++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/openmc/deplete/chain.py b/openmc/deplete/chain.py index 60716895548..76b842fc90d 100644 --- a/openmc/deplete/chain.py +++ b/openmc/deplete/chain.py @@ -17,7 +17,7 @@ import scipy.sparse as sp from openmc.checkvalue import check_type, check_greater_than -from openmc.data import gnds_name, zam +from openmc.data import gnds_name, zam, DADZ from .nuclide import FissionYieldDistribution, Nuclide import openmc.data @@ -742,6 +742,36 @@ def form_rr_term(self, tr_rates, mats): dict.update(matrix_dok, matrix) return matrix_dok.tocsc() + def get_reaction_pathways_to_target(self): + """Return a dictionary with reaction pathways to targets. + + Returns + ------- + pathways : dict + dict of targets nuclide as keys with a list of reactions and nuclides + as the dictionary value. For example the reaction pathways for Gold + + chain.get_reaction_pathways_to_target()["Au197"] + [('Hg197', '(n,p)'), ('Hg197_m1', '(n,p)'), + ('Hg198', '(n,np)'), ('Hg198', '(n,d)')] + """ + + reaction_pathways = {} + for nuclide in self.nuclides: + for reaction in nuclide.reactions: + # if the reaction changes the A or Z number. + if reaction.type in DADZ.keys(): + secondaries = openmc.deplete.REACTIONS[reaction.type].secondaries + # includes secondary such as H1, H2, H3, He3 and He4 + for secondary in secondaries: + reaction_pathways.setdefault( + secondary, [] + ).append((nuclide.name, reaction.type)) + reaction_pathways.setdefault( + reaction.target, [] + ).append((nuclide.name, reaction.type)) + return reaction_pathways + def get_branch_ratios(self, reaction="(n,gamma)"): """Return a dictionary with reaction branching ratios diff --git a/tests/unit_tests/test_deplete_chain.py b/tests/unit_tests/test_deplete_chain.py index e4e0231355f..7963e231b4d 100644 --- a/tests/unit_tests/test_deplete_chain.py +++ b/tests/unit_tests/test_deplete_chain.py @@ -580,3 +580,15 @@ def test_reduce(gnd_simple_chain, endf_chain): reduced_chain = endf_chain.reduce(['U235']) assert 'H1' in reduced_chain assert 'H2' in reduced_chain + +def test_chain_sources(endf_chain): + pathways = endf_chain.get_reaction_pathways_to_target() + assert isinstance(pathways, dict) + assert isinstance(pathways['Au197'], list) + assert isinstance(pathways['Au197'][0], tuple) + assert isinstance(pathways['Au197'][0][0], str) + assert isinstance(pathways['Au197'][0][1], str) + for nuc, reaction in pathways['Au197']: + # checks nuclide is acceptable ZAM + _ = openmc.data.zam(nuc) + assert reaction in openmc.data.REACTION_MT.keys() From 2b0d6e81d566679e05a6c6258889349cf18ceac2 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Mon, 26 Feb 2024 15:52:36 +0000 Subject: [PATCH 2/2] changing chain --- tests/unit_tests/test_deplete_chain.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/unit_tests/test_deplete_chain.py b/tests/unit_tests/test_deplete_chain.py index 7963e231b4d..77c7dd03d50 100644 --- a/tests/unit_tests/test_deplete_chain.py +++ b/tests/unit_tests/test_deplete_chain.py @@ -9,6 +9,7 @@ import numpy as np from openmc.mpi import comm from openmc.deplete import Chain, reaction_rates, nuclide, cram, pool +from openmc.data import zam, REACTION_MT from openmc.stats import Discrete import pytest @@ -581,14 +582,14 @@ def test_reduce(gnd_simple_chain, endf_chain): assert 'H1' in reduced_chain assert 'H2' in reduced_chain -def test_chain_sources(endf_chain): - pathways = endf_chain.get_reaction_pathways_to_target() +def test_chain_sources(gnd_simple_chain): + pathways = gnd_simple_chain.get_reaction_pathways_to_target() assert isinstance(pathways, dict) - assert isinstance(pathways['Au197'], list) - assert isinstance(pathways['Au197'][0], tuple) - assert isinstance(pathways['Au197'][0][0], str) - assert isinstance(pathways['Au197'][0][1], str) - for nuc, reaction in pathways['Au197']: + assert isinstance(pathways['Xe136'], list) + assert isinstance(pathways['Xe136'][0], tuple) + assert isinstance(pathways['Xe136'][0][0], str) + assert isinstance(pathways['Xe136'][0][1], str) + for nuc, reaction in pathways['Xe136']: # checks nuclide is acceptable ZAM - _ = openmc.data.zam(nuc) - assert reaction in openmc.data.REACTION_MT.keys() + _ = zam(nuc) + assert reaction in REACTION_MT.keys()