def test_discretize(): from os.path import isfile try: import urllib.request as urllib except ImportError: import urllib try_download("http://t2.lanl.gov/nis/data/data/ENDFB-VII.1-neutron/Ni/59", "Ni59.txt", "") endfds = ENDFDataSource("Ni59.txt") nonelastic_rx = endfds.reaction("Ni59", "nonelastic") nonelastic_rx['dst_group_struct'] = np.logspace(7, -5, 33) nonelastic_c = endfds.discretize("Ni59", "nonelastic") exp = [0.54334609294912528, 0.21206255570566626, 0.079089998725708668, 0.039061531003500925, 0.056193960028285306, 0.062581135526972767, 0.086088778452663009, 0.1519375415918513, 0.015156525895127398, 0.18503957567677801, 0.0039443417078627837, 0.082573739674287688, 17.523219940338304, 0.97176481236488554, 0.60307330340022303, 0.71684581122716162, 0.99386518962022252, 1.4726882603418707, 2.2391970686479672, 3.405589441800994, 5.2453926977834398, 8.0731410528834182, 12.384026334168054, 19.175694435799141, 29.334824378652982, 45.254982026071197, 74.217617672501689, 162.26091389706099, 218.90153743636509, 312.62178192130619, 590.40136068709603, 724.64216445611373] assert_array_almost_equal(nonelastic_c, exp) os.remove(Ni59.txt)
def convert(endfFile): if not isfile(endfFile): return 1 ext = '.endf' if not endfFile.endswith(ext): return 1 en = ENDFDataSource(endfFile) isotope = (endfFile.split('/'))[-1].replace(ext, '') dict_list = [] for i in range(2000): #arbitrarily chosen try: react = en.reaction(isotope, i) for key, value in react.items(): if type(value) is np.ndarray: react.update({key: value.tolist()}) # Finally make sure the reaction knows which reaction # it actually is!! react.update({'reaction': i}) dict_list.append(react) except (RuntimeError, KeyError) as er: pass new_ext = '.json' with open(endfFile.replace(ext, new_ext), 'w') as fname: json.dump(dict_list, fname, indent=2) print('Wrote to:', fname.name)
def readendf(self, datafile): endfds = ENDFDataSource(os.path.join(self.csdir, datafile)) endfds.load() # print endfds.library.intdict print "++++ The File contains data for the following nuclides:" self.lines = {} for nuc, value in endfds.library.mat_dict.iteritems() : cname = nucname.name(nuc) print "+++ Data for nuclide " + cname elname = elements[nucname.znum(nuc)].name elname = elname.capitalize() nuclidefilename = str(nucname.znum(nuc)) + "_" + str(nucname.anum(nuc)) + "_" + elname if (nucname.snum(nuc) != 0): print "Found nuclide in exited state, will add _<state> to filename" nuclidefilename = nuclidefilename + "_" + str(nucname.snum(nuc)) for keyb, valueb in value['mfs'].iteritems() : print "+++ The nuclide has data for MF=", keyb[0], " and MT=", keyb[1] # MF=3 (cs) if(keyb[0] == 3) : print "Convert to geant compatible lines for MF=3" reactiondata = endfds.reaction(nuc, keyb[1]) if (len(reactiondata['intschemes']) == 1): if (reactiondata['intschemes'] == 2) : writeline = "" writeline += " {:12d}".format(len(reactiondata['xs'])) writeline += "\n" zippedxs = zip(reactiondata['xs'], reactiondata['e_int']) count = 0 for sxs, se in zippedxs: count += 1 writeline += " {:8.6e} {:8.6e}".format(se, sxs) if (count == 3): writeline += "\n" count = 0 if(count != 0): writeline += "\n" if(not keyb[1] in self.lines): self.lines.update({keyb[1]: {}}) self.lines[keyb[1]].update({keyb[0]: writeline}) else: print "Non-linear interpolation scheme (Type {}) is currently not supported.".format(reactiondata['intschemes']) else: print "Multiple interpolation schemes are currently not supprted." #print reactiondata #exit() if(keyb[0] == 1) : # xsdata = endfds.library.get_rx(key, 1, keyb[1]).reshape(-1,6) # print xsdata print "Conversion for MF=1 not yet possible" if(keyb[0] == 6) : print "Convert to geant compatible lines for MF=6" mf6data = newmf.mf6() mf6data.setdatasource(endfds) mf6data.loadmtenangdata(nuc, keyb[1]) enangdist = mf6data.getdata() gdata = geantdata.geantdata() gdata.importenangdist(enangdist) gdata.writesection(6, keyb[1]) if(not gdata.producterror): if(not keyb[1] in self.lines): self.lines.update({keyb[1]: {}}) self.lines[keyb[1]].update({keyb[0]: gdata.getline()}) else: print("No output for MT/MF combination because of errors") return nuclidefilename