Example #1
0
def test_branch_ratio():
    assert_equal(data.branch_ratio('H1', 'H1'), 1.0)
    assert_equal(data.branch_ratio(922350001, 922350000), 1.0)
    assert_equal(data.branch_ratio(922350001, 922360000), 0.0)
    assert_equal(data.branch_ratio(611460000, 621460000), 0.34)

    children = data.decay_children('U235')
    for child in children:
        obs = data.branch_ratio('U235', child)
        assert_true(obs >= 0.0 and obs <= 1.0)
Example #2
0
def k_a_from_hl(chain, short=1e-16, small=1e-16):
    hl = np.array([half_life(n, False) for n in chain])
    hl = hl[~np.isnan(hl)]
    outerdiff = hl - hl[:, np.newaxis]
    outerzeros = outerdiff == 0.0
    a = -1.0 / hl
    gamma = np.prod([branch_ratio(p, c) for p, c in zip(chain[:-1], chain[1:])])
    if gamma == 0.0 or np.isnan(gamma):
        return None, None, None
    ends_stable = np.isinf(hl[-1])
    k = (
        k_from_hl_stable(hl, gamma, outerdiff, outerzeros)
        if ends_stable
        else k_from_hl_unstable(hl, gamma, outerdiff, outerzeros)
    )
    t_term = np.zeros(len(k), dtype=bool)
    asmask = almost_stable_mask(hl, k)
    if np.any(asmask):
        # handle case some nuclide is effectively stable and
        # we obtained an overflow through the normal method
        k, a, t_term = (
            k_almost_stable(hl, a, gamma, asmask)
            if ends_stable
            else k_almost_unstable(hl, a, gamma, asmask)
        )
    else:
        k, a, t_term = hl_degeneracy(hl, k, a, outerzeros)
    # filtering makes compiling faster by pre-ignoring negligible species
    # in this chain. They'll still be picked up in their own chains.
    mask = k_filter(k, t_term, small=small)
    if mask.sum() == 0:
        return None, None, None
    return k[mask], a[mask], t_term[mask]
Example #3
0
def _build_matrix(N):
    """This function  builds burnup matrix, A. Decay only."""

    A = np.zeros((len(N), len(N)))

    # convert N to id form
    N_id = []
    for i in range(len(N)):
        if isinstance(N[i], str):
            ID = nucname.id(N[i])
        else:
            ID = N[i]
        N_id.append(ID)

    sds = SimpleDataSource()

    # Decay
    for i in range(len(N)):
        A[i, i] -= decay_const(N_id[i])

        # Find decay parents
        for k in range(len(N)):
            if N_id[i] in decay_children(N_id[k]):
                A[i,
                  k] += branch_ratio(N_id[k], N_id[i]) * decay_const(N_id[k])
    return A
Example #4
0
def graph(nuc):
    """Returns a graphviz Digraph object for the decay chain starting from nuc."""
    i = nucname.name(nuc)
    name = nucname.name(nuc)
    dot = Digraph(comment='Decay chain for ' + nuc)
    dot.node(name)
    nodes_seen = {name}
    kids = data.decay_children(i)
    from_to = {(i, j) for j in kids}
    edges_seen = set()
    while len(from_to) != 0:
        new_from_to = set()
        for ft in from_to:
            i, j = ft
            jname = nucname.name(j)
            if jname not in nodes_seen:
                dot.node(jname)
                nodes_seen.add(jname)
            if ft not in edges_seen:
                iname = nucname.name(i)
                try:
                    label = rxname.name(i, j, 'decay')
                except RuntimeError:
                    label = 'sf'
                label = PRETTY_RX.get(label, label)
                br = data.branch_ratio(i, j)
                if br < 1.0:
                    label += ', br={0:.3}'.format(br)
                dot.edge(iname, jname, label=label)
                edges_seen.add(ft)
            kids = data.decay_children(j)
            new_from_to |= {(j, k) for k in kids}
        from_to = new_from_to
    return dot
Example #5
0
def add_child_decays(nuc, symbols):
    try:
        childname = nucname.name(nuc)
    except RuntimeError:
        return
    for rx in DECAY_RXS:
        try:
            parent = rxname.parent(nuc, rx, b'decay')
        except RuntimeError:
            continue
        if data.branch_ratio(parent, nuc) < 1e-16:
            continue
        parname = nucname.name(parent)
        symbols['lambda_' + parname] = data.decay_const(parent)
        gamma = 'gamma_{0}_{1}_{2}'.format(parname, childname, rx)
        symbols[gamma] = data.branch_ratio(parent, nuc)
Example #6
0
def test_branch_ratio():
    assert_equal(data.branch_ratio("H1", "H1"), 1.0)
    assert_equal(data.branch_ratio(922350001, 922350000), 1.0)
    assert_equal(data.branch_ratio(922350001, 922360000), 0.0)
    assert_equal(data.branch_ratio(611460000, 621460000), 0.34299999999999997)

    children = data.decay_children("U235")
    for child in children:
        obs = data.branch_ratio("U235", child)
        assert_true(obs >= 0.0 and obs <= 1.0)

    # There was a bug with metastable ids being dropped prematurely,
    # which would then lead to the branch ratio for the ground state being reported
    # Obviously, this was bad, so here is a test.
    assert_equal(data.branch_ratio("Se86", "Br86M"), 0.0)

    # Not all isomeric transitions have a 100% branch ratio
    assert_equal(data.branch_ratio(932400001, 932400000), 0.0012)
Example #7
0
    def _decay_branches(self, nuc):
        """Returns a dictionary that contains the decay children of nuc as keys
        to the branch ratio of that child's decay process.

        Parameters
        ----------
        nuc : int
            Name of parent nuclide to get decay children of.

        Returns
        -------
        decay_branches : dictionary
            Keys are decay children of nuc in zzaaam format.
            Values are the branch ratio of the decay child.

        """
        decay_branches = {}
        children = data.decay_children(nuc)
        for child in children:
            decay_branches[child] = data.branch_ratio(nuc, child)
        return decay_branches
Example #8
0
    def _decay_branches(self, nuc):
        """Returns a dictionary that contains the decay children of nuc as keys
        to the branch ratio of that child's decay process.

        Parameters
        ----------
        nuc : int
            Name of parent nuclide to get decay children of.

        Returns
        -------
        decay_branches : dictionary
            Keys are decay children of nuc in zzaaam format.
            Values are the branch ratio of the decay child.

        """
        decay_branches = {}
        children = data.decay_children(nuc)
        for child in children:
            decay_branches[child] = data.branch_ratio(nuc, child)
        return decay_branches
Example #9
0
def calc_decay_depletion(isotopes, DATA):
    # Create dictionary to keep track of daughters
    daughter_flags = dict()
    for iso in isotopes:
        daughter_flags[iso] = False

    dec_depletion = np.zeros([len(isotopes) + 2, len(isotopes) + 2])
    # Decay from j to i
    for i, iso_i in enumerate(isotopes):
        for j, iso_j in enumerate(isotopes):
            # Off-diagonal terms
            if j < i or j > i:
                # if j < i:
                ratio = data.branch_ratio(iso_j, iso_i)
                # print('print(iso_j, iso_i, ratio)')
                # print(iso_j, iso_i, ratio)
                # print(iso_j, iso_i, ratio)
                if ratio > 0:
                    decay_const = data.decay_const(iso_j)
                    dec_depletion[i, j] -= ratio * decay_const
                    daughter_flags[iso_j] = True

                # if iso_j=='932340':
                #     print(iso_j, iso_i, data.branch_ratio(iso_j,iso_i))

            # Diagonal terms
            elif i == j:
                # Add decay constant here
                # print(iso_j, data.half_life(iso_j))
                dec_depletion[i, j] += data.decay_const(iso_j)

    for i, iso in enumerate(isotopes):
        if not daughter_flags[iso] and dec_depletion[i, i] != 0:
            print("Warning: no decay daughter for ", iso)
            dec_depletion[-2, i] += -dec_depletion[i, i]

    return dec_depletion
Example #10
0
def test_branch_ratio():
    assert_equal(data.branch_ratio('H1', 'H1'), 1.0)
    assert_equal(data.branch_ratio(922350001, 922350000), 1.0)
    assert_equal(data.branch_ratio(922350001, 922360000), 0.0)
    assert_equal(data.branch_ratio(611460000, 621460000), 0.34)
Example #11
0
from pyne import data, nucname
import numpy as np

print(data.decay_const('U-235'))
print(data.decay_const('922350'))
print(data.decay_const('922350000'))
print(data.branch_ratio('932390000','942390000', use_metastable=False))
print(data.decay_children('932390000'))

print(data.decay_const('942420000'))
print(data.decay_children('942420000'))
print(np.log(2)/data.decay_const('922340000')/3.15e7)

print('-------Np-239 to Pu-239 test--------')
print(data.decay_const('932390'))
print(data.decay_children('932390'))

print(data.decay_const('932390'))
print(data.decay_children('932390'))
print(data.branch_ratio(932390,942390))

print('-------U-240 decay test--------')
print(np.log(2)/data.decay_const('922400')/3600)
print(data.branch_ratio('922400','932400', use_metastable=False))

print('-----U234 Capture Test-----')
print(float('922350')-float('922340') == 10)

print('-----Mass Test-----')
print(nucname.anum('922350'))
print('-----Name Test-----')