def reaction(self, nuc, rx, nuc_i = None): """Get reaction data. Parameters ---------- nuc : int or str Nuclide containing the reaction. rx : int or str Desired reaction nuc_i : int or str Nuclide containing the reaction. Defaults to nuc. group_bounds : tuple Low and high energy bounds of the new group. Returns ---------- rxdict : dict Dictionary containing source group structure, energy values, cross- section data, and interpolation data.""" if nuc_i is None: nuc_i = nuc nuc = nucname.id(nuc) rx = rxname.mt(rx) nuc_i = nucname.id(nuc_i) if (nuc, rx, nuc_i) not in self.rxcache: self._load_reaction(nuc, rx, nuc_i) return self.rxcache[nuc, rx, nuc_i]
def reaction(self, nuc, rx, nuc_i=None): """Get reaction data. Parameters ---------- nuc : int or str Nuclide containing the reaction. rx : int or str Desired reaction nuc_i : int or str Nuclide containing the reaction. Defaults to nuc. group_bounds : tuple Low and high energy bounds of the new group. Returns ---------- rxdict : dict Dictionary containing source group structure, energy values, cross- section data, and interpolation data.""" if nuc_i is None: nuc_i = nuc nuc = nucname.id(nuc) rx = rxname.mt(rx) nuc_i = nucname.id(nuc_i) if (nuc, rx, nuc_i) not in self.rxcache: self._load_reaction(nuc, rx, nuc_i) return self.rxcache[nuc, rx, nuc_i]
def _load_reaction(self, nuc, rx, nuc_i, src_phi_g=None, temp=300.0): """Note: ENDF data does not use temperature information (temp) Parameters ---------- nuc : int Nuclide in id form. rx : int or str Reaction MT # in nnnm form. OR: Reaction key: 'gamma', 'alpha', 'p', etc. nuc_i: : int Isotope in id form (optional). Default is None. Returns ------- rxdata: ndarray of floats, len ngroups """ nuc = nucname.id(nuc) rx = rxname.mt(rx) if nuc_i not in self.library.structure[nuc]['data']: self.library._read_res(nuc) rxdict = self.library.get_xs(nuc, rx, nuc_i)[0] rxdict['_src_phi_g'] = src_phi_g self.rxcache[nuc, rx, nuc_i] = rxdict self._load_group_structure(nuc, rx, nuc_i) return rxdict
def _load_reaction(self, nuc, rx, temp=300.0): """Loads reaction data from ACE files indexed by OpenMC. Parameters ---------- nuc : int Nuclide id. rx : int Reaction id. temp : float, optional The nuclide temperature in [K]. """ rx = rxname.id(rx) try: mt = rxname.mt(rx) except RuntimeError: return None totrx = rxname.id('total') absrx = rxname.id('absorption') ace_tables = self._rank_ace_tables(nuc, temp=temp) lib = ntab = None for atab in ace_tables: if atab not in self.libs: lib = self.libs[atab] = ace.Library(atab.abspath or atab.path) lib.read(atab.name) lib = self.libs[atab] ntab = lib.tables[atab.name] if mt in ntab.reactions or rx == totrx or rx == absrx: break lib = ntab = None if lib is None: return None # no reaction available E_g = self.src_group_struct E_points = ntab.energy if rx == totrx: rawdata = ntab.sigma_t elif rx == absrx: rawdata = ntab.sigma_a else: ntabrx = ntab.reactions[mt] if ntabrx.IE is None or ntabrx.IE == 0: rawdata = ntabrx.sigma else: rawdata = np.empty(len(E_points), dtype='f8') rawdata[:ntabrx.IE] = 0.0 rawdata[ntabrx.IE:] = ntabrx.sigma if (E_g[0] <= E_g[-1] and E_points[-1] <= E_points[0]) or \ (E_g[0] >= E_g[-1] and E_points[-1] >= E_points[0]): E_points = E_points[::-1] rawdata = rawdata[::-1] rxdata = bins.pointwise_linear_collapse(E_g, E_points, rawdata) return rxdata
def _load_group_structure(self, nuc, rx, nuc_i=None): """Loads the group structure from ENDF file.""" self.library._read_res(nuc) mt = rxname.mt(rx) rxdata = self.rxcache[nuc, rx, nuc_i] xsdata = self.library.get_xs(nuc, rx, nuc_i)[0] intpoints = xsdata['intpoints']#[::-1] e_int = xsdata["e_int"] src_group_struct = [e_int[intpoint-1] for intpoint in intpoints[::-1]] rxdata['src_group_struct'] = src_group_struct rxdata['src_ngroups'] = len(intpoints) rxdata['src_phi_g'] = np.ones(len(intpoints), dtype='f8') \ if rxdata['_src_phi_g'] is None \ else np.asarray(rxdata['src_phi_g'])
def test_mt_ids(): assert_equal(rxname.mt(_hash("a")), 107) assert_equal(rxname.mt(_hash("total")), 1) assert_equal(rxname.mt(long(_hash("a"))), 107) assert_equal(rxname.mt(long(_hash("total"))), 1) assert_equal(rxname.mt(str(_hash("a"))), 107) assert_equal(rxname.mt(str(_hash("total"))), 1)
def test_mt_mts(): assert_equal(rxname.mt(107), 107) assert_equal(rxname.mt(1), 1) assert_equal(rxname.mt(long(107)), 107) assert_equal(rxname.mt(long(1)), 1) assert_equal(rxname.mt("107"), 107) assert_equal(rxname.mt("1"), 1)
def _load_group_structure(self, nuc, rx, nuc_i=None): """Loads the group structure from ENDF file.""" self.library._read_res(nuc) mt = rxname.mt(rx) rxdata = self.rxcache[nuc, rx, nuc_i] xsdata = self.library.get_xs(nuc, rx, nuc_i)[0] intpoints = xsdata['intpoints'] #[::-1] e_int = xsdata["e_int"] src_group_struct = [ e_int[intpoint - 1] for intpoint in intpoints[::-1] ] rxdata['src_group_struct'] = src_group_struct rxdata['src_ngroups'] = len(intpoints) rxdata['src_phi_g'] = np.ones(len(intpoints), dtype='f8') \ if rxdata['_src_phi_g'] is None \ else np.asarray(rxdata['src_phi_g'])
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. Parameters ---------- nuc : int or str A nuclide. rx : int or str Reaction id or name. 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 : ndarray Destination cross section data, length dst_ngroups. """ nuc = nucname.id(nuc) nuc_i = nucname.id(nuc) rx = rxname.mt(rx) rxdata = self.reaction(nuc, rx, nuc_i=nuc_i) xs = rxdata['xs'] dst_group_struct = rxdata['dst_group_struct'] intpoints = [intpt for intpt in rxdata['intpoints'][::-1]] intschemes = rxdata['intschemes'][::-1] e_int = rxdata["e_int"] src_bounds = [e_int[intpoint - 1] for intpoint in intpoints] src_dict = dict(zip(src_bounds, intschemes)) dst_bounds = zip(dst_group_struct[1:], dst_group_struct[:-1]) dst_sigma = [ self.integrate_dst_group(dst_bound, src_bounds, src_dict, e_int, xs) for dst_bound in dst_bounds ] return dst_sigma
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. Parameters ---------- nuc : int or str A nuclide. rx : int or str Reaction id or name. 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 : ndarray Destination cross section data, length dst_ngroups. """ nuc = nucname.id(nuc) nuc_i = nucname.id(nuc) rx = rxname.mt(rx) rxdata = self.reaction(nuc, rx, nuc_i = nuc_i) xs = rxdata['xs'] dst_group_struct = rxdata['dst_group_struct'] intpoints = [intpt for intpt in rxdata['intpoints'][::-1]] intschemes = rxdata['intschemes'][::-1] e_int = rxdata["e_int"] src_bounds = [e_int[intpoint-1] for intpoint in intpoints] src_dict = dict(zip(src_bounds, intschemes)) dst_bounds = zip(dst_group_struct[1:], dst_group_struct[:-1]) dst_sigma = [self.integrate_dst_group(dst_bound, src_bounds, src_dict, e_int, xs) for dst_bound in dst_bounds] return dst_sigma
def test_mt_alts(): assert_equal(rxname.mt("alpha"), 107) assert_equal(rxname.mt("tot"), 1)
def test_mt_names(): assert_equal(rxname.mt("a"), 107) assert_equal(rxname.mt("total"), 1)
def test_mt_nucdelta(): assert_equal(rxname.mt("U235", "U236"), 27) assert_equal(rxname.mt("U235", "Np236", "p"), 27) assert_equal(rxname.mt(922350, 912350), 103)
def pointwise(self, nuc, rx, temp=300.0): """Returns pointwise reaction data from ACE files indexed by OpenMC. Parameters ---------- nuc : int Nuclide id. rx : int Reaction id. temp : float, optional The nuclide temperature in [K]. Returns ------- E_points : array-like The array or energy points that the reaction is evaluated at. rawdata : array-like Raw pointwise reaction data. """ nuc = nucname.id(nuc) rx = rxname.id(rx) try: mt = rxname.mt(rx) except RuntimeError: return None totrx = rxname.id("total") absrx = rxname.id("absorption") ace_tables = self._rank_ace_tables(nuc, temp=temp) lib = ntab = None for atab in ace_tables: if os.path.isfile(atab.abspath or atab.path): if atab not in self.libs: lib = self.libs[atab] = ace.Library(atab.abspath or atab.path) lib.read(atab.name) lib = self.libs[atab] ntab = lib.tables[atab.name] if mt in ntab.reactions or rx == totrx or rx == absrx: break lib = ntab = None if lib is None: return None # no reaction available E_g = self.src_group_struct E_points = ntab.energy if rx == totrx: rawdata = ntab.sigma_t elif rx == absrx: rawdata = ntab.sigma_a else: ntabrx = ntab.reactions[mt] if ntabrx.IE is None or ntabrx.IE == 0: rawdata = ntabrx.sigma else: rawdata = np.empty(len(E_points), dtype="f8") rawdata[:ntabrx.IE] = 0.0 rawdata[ntabrx.IE:] = ntabrx.sigma if (E_g[0] <= E_g[-1] and E_points[-1] <= E_points[0]) or ( E_g[0] >= E_g[-1] and E_points[-1] >= E_points[0]): E_points = E_points[::-1] rawdata = rawdata[::-1] return E_points, rawdata