예제 #1
0
def test_child():
    assert_equal(rxname.child("U235", "absorption"), 922360000)
    assert_equal(rxname.child(922350000, "absorption"), 922360000)
    assert_equal(rxname.child("Co58M", "gamma"), 270590000)
    assert_equal(rxname.child("Co58M", "gamma_1"), 270590001)
    assert_equal(rxname.child("Co58M", "gamma_1", "n"), 270590001)
    assert_equal(rxname.child("Co58M", "gamma_1", b"n"), 270590001)
예제 #2
0
def test_child():
    assert_equal(rxname.child("U235", "absorption"), 922360000)
    assert_equal(rxname.child(922350000, "absorption"), 922360000)
예제 #3
0
    def _traversal(self, nuc, A, out, depth=0):
        """Nuclide transmutation traversal method.

        This method will traverse the reaction tree recursively, using a DFS
        algorithm. On termination, the method will return all number densities
        after a given time that are a result of the starting nuclide.

        Parameters
        ----------
        nuc : int
            ID of the active nuclide for the traversal.
        A : NumPy 2-dimensional array
            Current state of the coupled equation matrix.
        out : dict
            A dictionary containing the final recorded number densities for each
            nuclide. Keys are nuclide names in integer id form. Values are
            number densities for the coupled nuclide in float format.  This is 
            modified in place.
        depth : int
            Current depth of traversal (root at 0). Should never be provided by user.

        """
        t = self.t
        tol = self.tol
        phi = self.xscache['phi_g'][0]
        temp = self.temp
        xscache = self.xscache
        if self.log is not None:
            self._log_tree(depth, nuc, 1.0)
        prod = {}
        # decay info
        lam = data.decay_const(nuc)
        decay_branches = {} if lam == 0 else self._decay_branches(nuc)
        for decay_child, branch_ratio in decay_branches.items():
            prod[decay_child] = lam * branch_ratio
        # reaction daughters
        for rx in self.rxs:
            try:
                child = rxname.child(nuc, rx)
            except RuntimeError:
                continue
            child_xs = xscache[nuc, rx, temp][0]
            rr = utils.from_barns(child_xs, 'cm2') * phi  # reaction rate
            prod[child] = rr + prod.get(child, 0.0)
        # Cycle production dictionary
        for child in prod:
            # Grow matrix
            d = self._get_destruction(child)
            B = self._grow_matrix(A, prod[child], d)
            # Create initial density vector
            n = B.shape[0]
            N0 = np.zeros((n, 1), dtype=float)
            N0[0] = 1.0
            # Compute matrix exponential and dot with density vector
            eB = linalg.expm(B * t)
            N_final = np.dot(eB, N0)  # <-- DENSE
            #N_final = eB.dot(N0)  # <-- SPARSE
            if self.log is not None:
                self._log_tree(depth + 1, child, N_final[-1])
            # Check against tolerance and continue traversal
            if N_final[-1] > tol:
                self._traversal(child, B, out, depth=depth + 1)
            # On recursion exit or truncation, write data from this nuclide
            outval = N_final[-1, 0] + out.get(child, 0.0)
            if 0.0 < outval:
                out[child] = outval
예제 #4
0
def test_child():
    assert_equal(rxname.child("U235", "absorption"), 922360000)
    assert_equal(rxname.child(922350000, "absorption"), 922360000)
예제 #5
0
    def _traversal(self, nuc, A, out, depth=0):
        """Nuclide transmutation traversal method.

        This method will traverse the reaction tree recursively, using a DFS
        algorithm. On termination, the method will return all number densities
        after a given time that are a result of the starting nuclide.

        Parameters
        ----------
        nuc : int
            ID of the active nuclide for the traversal.
        A : NumPy 2-dimensional array
            Current state of the coupled equation matrix.
        out : dict
            A dictionary containing the final recorded number densities for each
            nuclide. Keys are nuclide names in integer id form. Values are
            number densities for the coupled nuclide in float format.  This is 
            modified in place.
        depth : int
            Current depth of traversal (root at 0). Should never be provided by user.

        """
        t = self.t
        tol = self.tol
        phi = self.xscache['phi_g'][0]
        temp = self.temp
        xscache = self.xscache
        if self.log is not None:
            self._log_tree(depth, nuc, 1.0)
        prod = {}
        # decay info
        lam = data.decay_const(nuc)
        decay_branches = {} if lam == 0 else self._decay_branches(nuc)
        for decay_child, branch_ratio in decay_branches.items():
            prod[decay_child] = lam * branch_ratio
        # reaction daughters
        for rx in self.rxs:
            try:
                child = rxname.child(nuc, rx)
            except RuntimeError:
                continue
            child_xs = xscache[nuc, rx, temp][0]
            rr = utils.from_barns(child_xs, 'cm2') * phi  # reaction rate
            prod[child] = rr + prod.get(child, 0.0)
        # Cycle production dictionary
        for child in prod:
            # Grow matrix
            d = self._get_destruction(child)
            B = self._grow_matrix(A, prod[child], d)
            # Create initial density vector
            n = B.shape[0]
            N0 = np.zeros((n, 1), dtype=float)
            N0[0] = 1.0
            # Compute matrix exponential and dot with density vector
            eB = linalg.expm(B * t)
            N_final = np.dot(eB, N0)  # <-- DENSE
            #N_final = eB.dot(N0)  # <-- SPARSE
            if self.log is not None:
                self._log_tree(depth+1, child, N_final[-1])
            # Check against tolerance and continue traversal
            if N_final[-1] > tol:
                self._traversal(child, B, out, depth=depth+1)
            # On recursion exit or truncation, write data from this nuclide
            outval = N_final[-1,0] + out.get(child, 0.0)
            if 0.0 < outval:
                out[child] = outval
예제 #6
0
def cross_section_data(t9, nlb=None, nucs=None):
    """Gets decay data from a TAPE9.

    Parameters
    ----------
    t9 : dict
        A TAPE9 dict that contains the decay data.
    nlb : tuple of ints or None, optional
        The cross section library numbers. If None, this will attempt to discover
        the numbers in the library.
    nucs : set or None, optional
        The known set of nuclides.

    Returns
    -------
    nucs : set
        The set of nuclide names.
    sigma_ij : dict
        Mapping from (i, j) nuclide name tuples to the cross section for this
        reaction. Note that this does not include the fission cross section [barns].
    sigma_fission : dict
        Mapping from fissionable nuclide names to the fission cross section [barns].
    fission_product_yields : dict
        Mapping from (i, j) nuclide name tuples to the fission product yields for
        that nuclide.
    """
    if rxname.child("Am242M", "gamma") != 952430000:
        raise RuntimeError("Pyne version too old. Need version 0.5.4 or newer")
    nlb = find_nlb(t9, nlb=nlb)
    nucs = set() if nucs is None else nucs
    sigma_ij = {}
    alpha_ij = {}
    sigma_fission = {}
    fission_product_yields = {}
    for n in nlb:
        # grab sigma_ij cross sections
        for rx in t9[n]:
            if not rx.startswith('sigma_') or rx == 'sigma_f':
                continue
            _, _, orx = rx.partition('_')
            xs_rs = ORIGEN_TO_XS[orx]
            for nuc in t9[n][rx]:
                val = t9[n][rx][nuc]
                if val == 0:
                    continue
                nname = nucname.name(int(nuc))
                try:
                    child = nucname.name(rxname.child(nname, xs_rs))
                except RuntimeError:
                    continue
                nucs.add(nname)
                nucs.add(child)
                sigma_ij[nname, child] = val
                if rx == 'sigma_alpha':
                    alpha_ij[nname, "He4"] = val
        # grab the fission cross section
        if 'sigma_f' in t9[n]:
            rx = 'sigma_f'
            for nuc in t9[n][rx]:
                val = t9[n][rx][nuc]
                if val == 0:
                    continue
                nname = nucname.name(int(nuc))
                nucs.add(nname)
                sigma_fission[nname] = val
        # grab the fission product yields
        for rx in t9[n]:
            if not rx.endswith('_fiss_yield'):
                continue
            fromnuc, *_ = rx.partition('_')
            fromnuc = nucname.name(fromnuc)
            for k, v in t9[n][rx].items():
                if v == 0:
                    continue
                tonuc = nucname.name(nucname.zzaaam_to_id(int(k)))
                # origen yields are in percent
                nucs.add(fromnuc)
                nucs.add(tonuc)
                fission_product_yields[fromnuc, tonuc] = v / 100
    return nucs, sigma_ij, sigma_fission, fission_product_yields, alpha_ij