예제 #1
0
def chainexpr(chain, cse, b, bt, short=1e-8):
    child = chain[-1]
    if len(chain) == 1:
        a_i = -1.0 / half_life(child, False)
        b = ensure_cse(a_i, b, cse)
        terms = B_EXPR.format(b=b_from_a(cse, a_i))
    else:
        k, a = k_a(chain, short=short)
        if k is None:
            return None, b, bt
        terms = [] 
        for k_i, a_i in zip(k, a):
            if k_i == 1.0 and a_i == 0.0:
                term = str(1.0 - bt)  # a slight optimization
                bt = 1
            elif a_i == 0.0:
                if not np.isnan(k_i):
                    if bt < 1:
                        if k_i + bt < 1:
                            term = '{0:e}'.format(k_i)  # another slight optimization 
                            bt += k_i
                        else:
                            term = '{0:e}'.format(1.0 - bt)
                            bt = 1.0
                    else:
                        term = '0'
                else:
                    term = '0'
            else:
                b = ensure_cse(a_i, b, cse)
                term = kbexpr(k_i, b_from_a(cse, a_i))
            terms.append(term)
        terms = ' + '.join(terms)
    return CHAIN_EXPR.format(terms), b, bt
예제 #2
0
def test_transmuters_cram():
    n0 = {"H3": 1.0}
    A = -cram.DECAY_MATRIX * data.half_life("H3")
    n1 = transmuters.cram(A, n0, order=16)
    assert_equal(2, len(n1))
    assert_almost_equal(0.5, n1[nucname.id("H3")])
    assert_almost_equal(0.5, n1[nucname.id("He3")])
예제 #3
0
파일: decaygen.py 프로젝트: zxkjack123/pyne
def chainexpr(chain, cse, b, bt, short=1e-8):
    child = chain[-1]
    if len(chain) == 1:
        a_i = -1.0 / half_life(child, False)
        b = ensure_cse(a_i, b, cse)
        terms = B_EXPR.format(b=b_from_a(cse, a_i))
    else:
        k, a = k_a(chain, short=short)
        if k is None:
            return None, b, bt
        terms = []
        for k_i, a_i in zip(k, a):
            if k_i == 1.0 and a_i == 0.0:
                term = str(1.0 - bt)  # a slight optimization
                bt = 1
            elif a_i == 0.0:
                if not np.isnan(k_i):
                    if bt < 1:
                        if k_i + bt < 1:
                            term = '{0:e}'.format(
                                k_i)  # another slight optimization
                            bt += k_i
                        else:
                            term = '{0:e}'.format(1.0 - bt)
                            bt = 1.0
                    else:
                        term = '0'
                else:
                    term = '0'
            else:
                b = ensure_cse(a_i, b, cse)
                term = kbexpr(k_i, b_from_a(cse, a_i))
            terms.append(term)
        terms = ' + '.join(terms)
    return CHAIN_EXPR.format(terms), b, bt
예제 #4
0
파일: decaygen.py 프로젝트: pyne/pyne
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]
예제 #5
0
def hl_relerr(nuc):
    """Half-life relative error."""
    dhl = data.half_life(nuc) or np.inf
    ohl = t9_half_life(nuc) or np.inf
    if np.isinf(ohl) and np.isinf(dhl):
        return 0.0
    hlre = np.abs(ohl - dhl) * 2 / (ohl + dhl)
    return np.inf if np.isnan(hlre) else hlre
예제 #6
0
def hl_relerr(nuc):
    """Half-life relative error."""
    dhl = data.half_life(nuc) or np.inf
    ohl = t9_half_life(nuc) or np.inf
    if np.isinf(ohl) and np.isinf(dhl):
        return 0.0
    hlre = np.abs(ohl - dhl) * 2 / (ohl + dhl)
    return np.inf if np.isnan(hlre) else hlre
예제 #7
0
파일: pre.py 프로젝트: FlanFlanagan/xsgen
    def _ensure_nl(self, rc):
        "Validate the tracked nuclides in the run control."
        if isinstance(rc.track_nucs, basestring):
            track_nucs = self.load_nuc_file(rc.track_nucs)
        else:
            track_nucs = [nucname.id(nuc) for nuc in rc.track_nucs]

        avg_timestep = 60*60*24*np.mean(rc.burn_times[1:]-rc.burn_times[:-1])
        min_halflife = rc.track_nuc_threshold * avg_timestep
        track_nucs = [nucid for nucid in track_nucs
                      if half_life(nucid) > min_halflife]
        rc.track_nucs = sorted(set(track_nucs))
예제 #8
0
파일: decaygen.py 프로젝트: zxkjack123/pyne
def k_a(chain, short=1e-8):
    # gather data
    hl = np.array([half_life(n, False) for n in chain])
    a = -1.0 / hl
    dc = np.array(list(map(lambda nuc: decay_const(nuc, False), chain)))
    if np.isnan(dc).any():
        # NaNs are bad, mmmkay.  Nones mean we should skip
        return None, None
    ends_stable = (dc[-1] < 1e-16)  # check if last nuclide is a stable species
    # compute cij -> ci in prep for k
    cij = dc[:, np.newaxis] / (dc[:, np.newaxis] - dc)
    if ends_stable:
        cij[-1] = -1.0 / dc  # adjustment for stable end nuclide
    mask = np.ones(len(chain), dtype=bool)
    cij[mask, mask] = 1.0  # identity is ignored, set to unity
    ci = cij.prod(axis=0)
    # compute k
    if ends_stable:
        k = dc * ci
        k[-1] = 1.0
    else:
        k = (dc / dc[-1]) * ci
    if np.isinf(k).any():
        # if this happens then something wen very wrong, skip
        return None, None
    # compute and apply branch ratios
    gamma = np.prod(
        [all_branch_ratio(p, c) for p, c in zip(chain[:-1], chain[1:])])
    if gamma == 0.0 or np.isnan(gamma):
        return None, None
    k *= gamma
    # half-life  filter, makes compiling faster by pre-ignoring negligible species
    # in this chain. They'll still be picked up in their own chains.
    if ends_stable:
        mask = (hl[:-1] / hl[:-1].sum()) > short
        mask = np.append(mask, True)
    else:
        mask = (hl / hl.sum()) > short
    if mask.sum() < 2:
        mask = np.ones(len(chain), dtype=bool)
    return k[mask], a[mask]
예제 #9
0
def k_a(chain, short=1e-8):
    # gather data
    hl = np.array([half_life(n, False) for n in chain])
    a = -1.0 / hl 
    dc = np.array(list(map(lambda nuc: decay_const(nuc, False), chain)))
    if np.isnan(dc).any():
        # NaNs are bad, mmmkay.  Nones mean we should skip
        return None, None
    ends_stable = (dc[-1] < 1e-16)  # check if last nuclide is a stable species
    # compute cij -> ci in prep for k
    cij = dc[:, np.newaxis] / (dc[:, np.newaxis] - dc)
    if ends_stable:
        cij[-1] = -1.0 / dc  # adjustment for stable end nuclide
    mask = np.ones(len(chain), dtype=bool)
    cij[mask, mask] = 1.0  # identity is ignored, set to unity
    ci = cij.prod(axis=0)
    # compute k
    if ends_stable:
        k = dc * ci
        k[-1] = 1.0
    else:
        k = (dc / dc[-1]) * ci
    if np.isinf(k).any():
        # if this happens then something wen very wrong, skip
        return None, None
    # compute and apply branch ratios
    gamma = np.prod([all_branch_ratio(p, c) for p, c in zip(chain[:-1], chain[1:])])
    if gamma == 0.0 or np.isnan(gamma):
        return None, None
    k *= gamma
    # half-life  filter, makes compiling faster by pre-ignoring negligible species 
    # in this chain. They'll still be picked up in their own chains.
    if ends_stable:
        mask = (hl[:-1] / hl[:-1].sum()) > short
        mask = np.append(mask, True)
    else:
        mask = (hl / hl.sum()) > short
    if mask.sum() < 2:
        mask = np.ones(len(chain), dtype=bool)
    return k[mask], a[mask]
예제 #10
0
파일: decaygen.py 프로젝트: pyne/pyne
def chainexpr(chain, cse, b, bt, short=1e-16, small=1e-16):
    child = chain[-1]
    if len(chain) == 1:
        a_i = -1.0 / half_life(child, False)
        b = ensure_cse(a_i, b, cse)
        terms = B_EXPR.format(b=b_from_a(cse, a_i))
    else:
        k, a, t_term = k_a_from_hl(chain, short=short, small=small)
        if k is None:
            return None, b, bt
        terms = []
        for k_i, a_i, t_term_i in zip(k, a, t_term):
            if k_i == 1.0 and a_i == 0.0:
                term = str(1.0 - bt)  # a slight optimization
                bt = 1
            elif a_i == 0.0:
                if not np.isnan(k_i):
                    if bt < 1:
                        if k_i + bt < 1:
                            term = "{0:.17e}".format(k_i)  # another slight optimization
                            bt += k_i
                        else:
                            term = "{0:.17e}".format(1.0 - bt)
                            bt = 1.0
                    else:
                        term = "0"
                else:
                    term = "0"
            else:
                b = ensure_cse(a_i, b, cse)
                term = kbexpr(k_i, b_from_a(cse, a_i))
            # multiply by t if needed
            if t_term_i:
                term += "*t"
            terms.append(term)
        terms = " + ".join(terms)
    return CHAIN_EXPR.format(terms), b, bt
예제 #11
0
    nums = len(child)
    if nums == 1:
        IDS.append(child[0])
        j += 1
        generation.append(j)
        parent_to_child.append(str(iso) + '-->' + str(child[0]))
        parent_text.append(
            str(nucname.name(IDS[i])) + '-->' + str(nucname.name(child[0])))
    if nums == 2:
        IDS.append(child[0])
        parent_to_child.append(str(iso) + '-->' + str(child[0]))
        parent_text.append(
            str(nucname.name(IDS[i])) + '-->' + str(nucname.name(child[0])))
        IDS.append(child[1])
        parent_to_child.append(str(iso) + '-->' + str(child[1]))
        parent_text.append(
            str(nucname.name(IDS[i])) + '-->' + str(nucname.name(child[1])))
        j += 1
        generation.append(j)
        generation.append(j)
half_lives = []
for i in IDS:
    half_life = data.half_life(str(i))
    half_lives.append(half_life)
nuclide_data = zip(IDS, generation, half_lives, parent_text)
print(list(nuclide_data))
print('Parent to child relationship:' + str(parent_text))
print(parent_to_child)
print('generations:' + str(generation))
print('list of nucname.ids:' + str(IDS))
예제 #12
0
파일: tape9.py 프로젝트: NukespudWork/pyne
def gendecay(decays, branches, metastable_cutoff=1.0):
    """This computes ORIGEN TAPE9 decay data based on ENSDF data.

    Parameters
    ----------
    decays : list
        decay list from parse_ensdf()
    branches : list
        branches list from parse_ensdf()
    metastable_cutoff : float, optional
        minimum lifetime of metastable state (in seconds) to be included.

    Returns
    -------
    t9 : dict
        a TAPE9 dictionary for the decay library
    """
    t9 = {1: {'_type': 'decay', 'title': 'PyNE Decay Data for Activation Products'}, 
          2: {'_type': 'decay', 'title': 'PyNE Decay Data for Actinides & Daughters'}, 
          3: {'_type': 'decay', 'title': 'PyNE Decay Data for Fission Products'}, 
          }
    for nlb, lib in t9.items():
        for field in origen22.DECAY_FIELDS:
            lib[field] = {}

    longest = {}
    longest2 = {}
    for item in decays:
        nuc = nucname.id(item[0])
        key = nucname.zzaaam(nuc)
        if _is_metastable_beta_decay_0(item, metastable_cutoff):
            if 'B-' in item[5]:
                _plus_eq_decay_t9(t9, 'frac_beta_minus_x', nuc, key, item[6]/100.0)
            if 'B+' in item[5] or "EC" in item[5]:
                _plus_eq_decay_t9(t9, 'frac_beta_plus_or_electron_capture_x', nuc, 
                                  key, item[6]/100.0)
        if _is_metastable_beta_decay_x(item, metastable_cutoff):
            key += 1
            longest2[key] = longest2.get(key, 0)
            if item[1] == longest2[key]:
                if 'B-' in item[5]:
                    _plus_eq_decay_t9(t9, 'frac_beta_minus_x', nuc, key, 
                                      item[6]/100.0)
                                      #item[6]*item[8]/100.0)
                if 'B+' in item[5] or "EC" in item[5]:
                    _plus_eq_decay_t9(t9, 'frac_beta_plus_or_electron_capture_x', nuc,
                                      key, item[6]/100.0)
                                      #key, item[6]*item[8]/100.0)
            elif item[1] > longest2[key]:
                longest2[key] = item[1]
                if 'B-' in item[5]:
                    #_eq_decay_t9(t9, 'frac_beta_minus_x', nuc, key, item[6]*item[8]/100.0)
                    _eq_decay_t9(t9, 'frac_beta_minus_x', nuc, key, item[6]/100.0)
                if 'B+' in item[5] or "EC" in item[5]:
                    _eq_decay_t9(t9, 'frac_beta_plus_or_electron_capture_x', nuc,
                                      key, item[6]/100.0)
                                      #key, item[6]*item[8]/100.0)
    for item in branches:
        nuc = nucname.id(item[0])
        key = nucname.zzaaam(nuc)
        if (item[1] == 0) and (item[2] > metastable_cutoff):
            _set_branch_item(t9, nuc, key, item)
        if (item[1] != 0) and (item[2] > metastable_cutoff):
            key += 1
            longest[key] = longest.get(key, 0)
            if (item[2] <= longest[key]):
                continue 
            _set_branch_item(t9, nuc, key, item)
    for nucs, hl in zip([origen22.ACTIVATION_PRODUCT_NUCS, 
                         origen22.ACTINIDE_AND_DAUGHTER_NUCS, 
                         origen22.FISSION_PRODUCT_NUCS], 
                        [t9[i]['half_life'] for i in range(1, 4)]):
        for nuc in nucs:
            key = nucname.zzaaam(nuc)
            if key not in hl:
                hl[key] = data.half_life(nuc)
    return t9
예제 #13
0
파일: tape9.py 프로젝트: rtpavlovsk21/pyne
def gendecay(decays, branches, metastable_cutoff=1.0):
    """This computes ORIGEN TAPE9 decay data based on ENSDF data.

    Parameters
    ----------
    decays : list
        decay list from parse_ensdf()
    branches : list
        branches list from parse_ensdf()
    metastable_cutoff : float, optional
        minimum lifetime of metastable state (in seconds) to be included.

    Returns
    -------
    t9 : dict
        a TAPE9 dictionary for the decay library
    """
    t9 = {
        1: {
            '_type': 'decay',
            'title': 'PyNE Decay Data for Activation Products'
        },
        2: {
            '_type': 'decay',
            'title': 'PyNE Decay Data for Actinides & Daughters'
        },
        3: {
            '_type': 'decay',
            'title': 'PyNE Decay Data for Fission Products'
        },
    }
    for nlb, lib in t9.items():
        for field in origen22.DECAY_FIELDS:
            lib[field] = {}

    longest = {}
    longest2 = {}
    for item in decays:
        nuc = nucname.id(item[0])
        key = nucname.zzaaam(nuc)
        if _is_metastable_beta_decay_0(item, metastable_cutoff):
            if 'B-' in item[5]:
                _plus_eq_decay_t9(t9, 'frac_beta_minus_x', nuc, key,
                                  item[6] / 100.0)
            if 'B+' in item[5] or "EC" in item[5]:
                _plus_eq_decay_t9(t9, 'frac_beta_plus_or_electron_capture_x',
                                  nuc, key, item[6] / 100.0)
        if _is_metastable_beta_decay_x(item, metastable_cutoff):
            key += 1
            longest2[key] = longest2.get(key, 0)
            if item[1] == longest2[key]:
                if 'B-' in item[5]:
                    _plus_eq_decay_t9(t9, 'frac_beta_minus_x', nuc, key,
                                      item[6] / 100.0)
                    #item[6]*item[8]/100.0)
                if 'B+' in item[5] or "EC" in item[5]:
                    _plus_eq_decay_t9(t9,
                                      'frac_beta_plus_or_electron_capture_x',
                                      nuc, key, item[6] / 100.0)
                    #key, item[6]*item[8]/100.0)
            elif item[1] > longest2[key]:
                longest2[key] = item[1]
                if 'B-' in item[5]:
                    #_eq_decay_t9(t9, 'frac_beta_minus_x', nuc, key, item[6]*item[8]/100.0)
                    _eq_decay_t9(t9, 'frac_beta_minus_x', nuc, key,
                                 item[6] / 100.0)
                if 'B+' in item[5] or "EC" in item[5]:
                    _eq_decay_t9(t9, 'frac_beta_plus_or_electron_capture_x',
                                 nuc, key, item[6] / 100.0)
                    #key, item[6]*item[8]/100.0)
    for item in branches:
        nuc = nucname.id(item[0])
        key = nucname.zzaaam(nuc)
        if (item[1] == 0) and (item[2] > metastable_cutoff):
            _set_branch_item(t9, nuc, key, item)
        if (item[1] != 0) and (item[2] > metastable_cutoff):
            key += 1
            longest[key] = longest.get(key, 0)
            if (item[2] <= longest[key]):
                continue
            _set_branch_item(t9, nuc, key, item)
    for nucs, hl in zip([
            origen22.ACTIVATION_PRODUCT_NUCS,
            origen22.ACTINIDE_AND_DAUGHTER_NUCS, origen22.FISSION_PRODUCT_NUCS
    ], [t9[i]['half_life'] for i in range(1, 4)]):
        for nuc in nucs:
            key = nucname.zzaaam(nuc)
            if key not in hl:
                hl[key] = data.half_life(nuc)
    return t9
예제 #14
0
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-----')
print(nucname.serpent('922350'))

print('-------U-236 test--------')
print(data.decay_const('922360'))
print(data.half_life('922360')/(3.15e7))

print('-------Np-234 to U-234 test--------')
print(data.decay_const('932340'))
print(data.decay_children('932340'))
print(data.branch_ratio(932340,922340))
예제 #15
0
def test_half_life():
    assert_equal(data.half_life('H1'), np.inf)
    assert_equal(data.half_life(922350001), 1560.0)
예제 #16
0
 def get_half_life(self):
     return [data.half_life(nuc_id) for nuc_id in self.keys()]
예제 #17
0
def test_half_life():
    assert_equal(data.half_life('H1'), np.inf)
    assert_equal(data.half_life(922351), 1560.0)
예제 #18
0
def test_half_life():
    assert_equal(data.half_life("H1"), np.inf)
    assert_equal(data.half_life(922351), 1560.0)
예제 #19
0
def test_half_life():
    assert_equal(data.half_life("H1"), np.inf)
    assert_equal(data.half_life(922350001), 1560.0)
    assert_equal(data.half_life("Eu151"), np.inf)