def test_wgt_group_collapse1(): E_g = np.array([0.0, 4.0, 8.0]) E_n = np.array([0.0, 2.5, 5.0, 7.5, 10.0]) phi_n = np.array([0.0, 2.0, 1.0, 0.5]) sigma_n = np.array([1.0, 2.0, 3.0, 4.0]) wgts = np.array([0.00001, 0.00001, 0.00001, 0.00001]) observed = group_collapse(sigma_n, phi_n, E_g=E_g, E_n=E_n, weights=wgts) expected = group_collapse(sigma_n, phi_n, E_g=E_g, E_n=E_n) assert_array_almost_equal(observed, expected)
def discretize(self, nuc, rx, temp=300.0, src_phi_g=None, dst_phi_g=None): """Discretizes the reaction channel from the source group structure to that of the destination weighted by the group fluxes. This implemenation is only valid for multi-group data sources. Non-multigroup data source should also override this method. Parameters ---------- nuc : int or str A nuclide. rx : int or str Reaction key ('gamma', 'alpha', 'p', etc.) or MT number. temp : float, optional Temperature [K] of material, defaults to 300.0. src_phi_g : array-like, optional Group fluxes for this data source, length src_ngroups. dst_phi_g : array-like, optional Group fluxes for the destiniation structure, length dst_ngroups. Returns ------- dst_sigma : ndarry Destination cross section data, length dst_ngroups. """ src_phi_g = self.src_phi_g if src_phi_g is None else np.asarray(src_phi_g) src_sigma = self.reaction(nuc, rx, temp) dst_sigma = None if src_sigma is None else group_collapse(src_sigma, src_phi_g, dst_phi_g, self._src_to_dst_matrix) return dst_sigma
def sigma_a_reaction(nuc, rx, E_g=None, E_n=None, phi_n=None): """Calculates the neutron absorption reaction cross-section for a nuclide for a new, lower resolution group structure using a higher fidelity flux. Note that g indexes G, n indexes N, and G < N. Parameters ---------- nuc : int, str, Material, or dict-like A nuclide or nuclide-atom fraction mapping for which to calculate the absorption reaction cross-section. rx : str Reaction key. ('gamma', 'alpha', 'p', etc.) E_g : array-like of floats, optional New, lower fidelity energy group structure [MeV] that is of length G+1. E_n : array-like of floats, optional Higher resolution energy group structure [MeV] that is of length N+1. phi_n : array-like of floats, optional The high-fidelity flux [n/cm^2/s] to collapse the fission cross-section over. Length N. Returns ------- sigma_rx_g : ndarray An array of the collapsed absorption reaction cross section. Notes ----- This always pulls the absorption reaction cross-section out of the nuc_data. See Also -------- pyne.xs.cache.ABSORPTION_RX pyne.xs.cache.ABSORPTION_RX_MAP """ _prep_cache(E_g, E_n, phi_n) if isinstance(nuc, collections.Iterable) and not isinstance(nuc, basestring): return _atom_weight_channel(sigma_a_reaction, nuc, rx) # Get the absorption XS nuc_zz = nucname.zzaaam(nuc) key_n = ('sigma_rx_n', nuc_zz, rx) key_g = ('sigma_rx_g', nuc_zz, rx) # Don't recalculate anything if you don't have to if key_g in xs_cache: return xs_cache[key_g] else: sigma_rx_n = xs_cache[key_n] # Perform the group collapse, knowing that the right data is in the cache sigma_rx_g = group_collapse(sigma_rx_n, xs_cache['phi_n'], phi_g=xs_cache['phi_g'], partial_energies=xs_cache['partial_energy_matrix']) # Put this value back into the cache, with the appropriate label xs_cache[key_g] = sigma_rx_g return sigma_rx_g
def sigma_f(nuc, E_g=None, E_n=None, phi_n=None): """Calculates the neutron fission cross-section for a nuclide for a new, lower resolution group structure using a higher fidelity flux. Note that g indexes G, n indexes N, and G < N. If any of these are None-valued, values from the cache are used. The energy groups and fluxes are normally ordered from highest-to-lowest energy. Parameters ---------- nuc : int, str, Material, or dict-like A nuclide or nuclide-atom fraction mapping for which to calculate the fission cross-section. E_g : array-like of floats, optional New, lower fidelity energy group structure [MeV] that is of length G+1. E_n : array-like of floats, optional Higher resolution energy group structure [MeV] that is of length N+1. phi_n : array-like of floats, optional The high-fidelity flux [n/cm^2/s] to collapse the fission cross-section over. Length N. Returns ------- sigma_f_g : ndarray An array of the collapsed fission cross-section. Notes ----- This always pulls the fission cross-section out of nuc_data library. """ _prep_cache(E_g, E_n, phi_n) if isinstance(nuc, collections.Iterable) and not isinstance(nuc, basestring): return _atom_weight_channel(sigma_f, nuc) # Get the fission XS nuc_zz = nucname.zzaaam(nuc) sigma_f_n_nuc_zz = ('sigma_f_n', nuc_zz) sigma_f_g_nuc_zz = ('sigma_f_g', nuc_zz) # Don't recalculate anything if you don't have to if sigma_f_g_nuc_zz in xs_cache: return xs_cache[sigma_f_g_nuc_zz] else: sigma_f_n = xs_cache[sigma_f_n_nuc_zz] # Perform the group collapse, knowing that the right data is in the cache sigma_f_g = group_collapse(sigma_f_n, xs_cache['phi_n'], phi_g=xs_cache['phi_g'], partial_energies=xs_cache['partial_energy_matrix']) # Put this value back into the cache, with the appropriate label xs_cache[sigma_f_g_nuc_zz] = sigma_f_g return sigma_f_g
def test_group_collapse1(): E_g = np.array([0.0, 4.0, 8.0]) E_n = np.array([0.0, 2.5, 5.0, 7.5, 10.0]) phi_n = np.array([0.0, 2.0, 1.0, 0.5]) sigma_n = np.array([1.0, 2.0, 3.0, 4.0]) expected = np.array([2.0, 5.0 / 1.9]) # First way of calling observed = group_collapse(sigma_n, phi_n, E_g=E_g, E_n=E_n) assert_array_almost_equal(observed, expected) # Second method of calling p_g = phi_g(E_g, E_n, phi_n) pem = partial_energy_matrix(E_g, E_n) observed = group_collapse(sigma_n, phi_n, phi_g=p_g, partial_energies=pem) assert_array_almost_equal(observed, expected) # bad call assert_raises(ValueError, group_collapse, sigma_n, phi_n)