def execute_origen(xs_tape9, time, nuclide, phi, origen, decay_tape9): xs_tape9 = xs_tape9 if not os.path.isabs(xs_tape9): xs_tape9 = os.path.join(LIBS_DIR, xs_tape9) parsed_xs_tape9 = parse_tape9(xs_tape9) parsed_decay_tape9 = parse_tape9(decay_tape9) merged_tape9 = merge_tape9([parsed_decay_tape9, parsed_xs_tape9]) # Can set outfile to change directory, but the file name needs to be # TAPE9.INP. write_tape9(merged_tape9) decay_nlb, xsfpy_nlb = nlbs(parsed_xs_tape9) # Can set outfile, but the file name should be called TAPE5.INP. write_tape5_irradiation("IRF", time/(60*60*24), phi, xsfpy_nlb=xsfpy_nlb, cut_off=0, out_table_num=[4, 5], out_table_nes=[True, False, False]) M = from_atom_frac({nuclide: 1}, mass=1, atoms_per_molecule=1) write_tape4(M) # Make pyne use naive atomic mass numbers to match ORIGEN for i in pyne.data.atomic_mass_map: pyne.data.atomic_mass_map[i] = float(pyne.nucname.anum(i)) origen_time, data = time_func(run_origen, origen) logger.info("ORIGEN runtime: %s", origen_time) return origen_time, data
def test_merge_tape9(): tape9_file = StringIO(sample_tape9) tape9_file = origen22.parse_tape9(tape9_file) tape9_dict = {1: {'_type': 'decay', 'half_life': {10010: 42.0}}, 2: {'_type': 'decay', '_bad_key': None}, 3: {'_type': 'decay', 'title': "Sweet Decay"}, 382: {'_type': 'xsfpy', '_subtype': 'actinides', 'sigma_f': {922350: 16.0}}, } # merge so that dict takes precedence tape9 = origen22.merge_tape9([tape9_dict, tape9_file]) # run tests assert_equal(tape9[1]['half_life'][10010], 42.0) assert_true('_bad_key' in tape9[2]) assert_equal(tape9[3]['title'], "Sweet Decay") assert_equal(tape9[382]['sigma_f'][922350], 16.0) assert_true('_cards' not in tape9[1]) assert_true('_cards' not in tape9[2]) assert_true('_cards' not in tape9[3]) assert_true('_cards' in tape9[381]) assert_true('_cards' not in tape9[382]) assert_true('_cards' in tape9[383])
def test_merge_tape9(): tape9_file = StringIO(sample_tape9) tape9_file = origen22.parse_tape9(tape9_file) tape9_dict = { 1: {"_type": "decay", "half_life": {10010: 42.0}}, 2: {"_type": "decay", "_bad_key": None}, 3: {"_type": "decay", "title": "Sweet Decay"}, 382: {"_type": "xsfpy", "_subtype": "actinides", "sigma_f": {922350: 16.0}}, } # merge so that dict takes precedence tape9 = origen22.merge_tape9([tape9_dict, tape9_file]) # run tests assert_equal(tape9[1]["half_life"][10010], 42.0) assert_true("_bad_key" in tape9[2]) assert_equal(tape9[3]["title"], "Sweet Decay") assert_equal(tape9[382]["sigma_f"][922350], 16.0) assert_true("_cards" not in tape9[1]) assert_true("_cards" not in tape9[2]) assert_true("_cards" not in tape9[3]) assert_true("_cards" in tape9[381]) assert_true("_cards" not in tape9[382]) assert_true("_cards" in tape9[383])
def __init__(self, *args, **kwargs): tape9 = kwargs.pop('tape9', None) super(OrigenReactorMG, self).__init__(*args, **kwargs) self._nearest_neighbors = [] if tape9 is None: raise ValueError("must supply a default TAPE9 file to OrigenReactorMG.") elif isinstance(tape9, basestring): self._tape9 = origen22.parse_tape9(tape9) elif hasattr(tape9, 'keys'): self._tape9 = tape9 else: # assume sequence of tape9s self._tape9 = origen22.merge_tape9(tape9)
def calc_transmutation(self): """Use ORIGEN as a backend to perform the transmutation calculation.""" K = self.K s = self.bt_s T_it = self.T_it # Make origen cross section library t9 = origen22.merge_tape9([self._xs, self._tape9]) origen22.write_tape9(t9) # Make input mass stream mat = Material({iso: 1E3 * T_it[iso][s] for iso in K}) origen22.write_tape4(mat) # Make origen input file irr_type = 'IRP' irr_time = self.burn_times[s+1] - self.burn_times[s] irr_value = self.specific_power t5kw = { 'decay_nlb': sorted(nlb for nlb in t9.keys() if t9[nlb]['_type'] == 'decay')[:3], 'xsfpy_nlb': sorted(nlb for nlb in t9.keys() if t9[nlb]['_type'] == 'xsfpy')[:3], 'out_table_nes': (True, False, False), 'cut_off': 1E-300, 'out_table_num': [5], } origen22.write_tape5_irradiation(irr_type, irr_time, irr_value, **t5kw) # Run origen rtn = subprocess.check_call("o2_therm_linux.exe", shell=True) # Parse origen output res = origen22.parse_tape6() #outvec = {key: sum([v[-1] for v in value]) * 1E-3 for key, value in res['table_5']['nuclide']['data'].items() if (key in K) and not np.isnan(value).any()} outvec = res['materials'][-1].comp nullvec = {k: 0.0 for k in K if k not in outvec} outvec.update(nullvec) # update the transmutation matrix sp1 = s + 1 for nuc in K: T_it[nuc][sp1] = outvec[nuc] self.T_it = T_it # update the burnup BU_t = self.BU_t deltaBU = irr_time * irr_value BU_t[sp1] = BU_t[s] + deltaBU self.BU_t = BU_t print " BU_t = {0}".format(BU_t[sp1])
def main_gen(ns): """Generates an open TAPE9.INP file. by default this only uses completely open data. """ files = glob(os.path.join(ns.build_dir, 'ENSDF', 'ensdf.*')) if len(files) == 0: grab_ensdf_decay(ns.build_dir) files = glob(os.path.join(ns.build_dir, 'ENSDF', 'ensdf.*')) print("parsing ENSDF decay data") decays, branches = parse_ensdf(files) print("creating ORIGEN decay libraries") t9decay = gendecay(decays, branches, metastable_cutoff=ns.metastable_cutoff) print("creating ORIGEN cross section libraries") xsc = XSCache(data_source_classes=[EAFDataSource, SimpleDataSource, NullDataSource]) xsc.load() t9xsfpy = origen22.xslibs(xscache=xsc, verbose=True) t9 = origen22.merge_tape9([t9decay, t9xsfpy]) origen22.write_tape9(t9, outfile=ns.filename)
def test_merge_tape9(): tape9_file = StringIO(sample_tape9) tape9_file = origen22.parse_tape9(tape9_file) tape9_dict = { 1: { '_type': 'decay', 'half_life': { 10010: 42.0 } }, 2: { '_type': 'decay', '_bad_key': None }, 3: { '_type': 'decay', 'title': "Sweet Decay" }, 382: { '_type': 'xsfpy', '_subtype': 'actinides', 'sigma_f': { 922350: 16.0 } }, } # merge so that dict takes precedence tape9 = origen22.merge_tape9([tape9_dict, tape9_file]) # run tests assert_equal(tape9[1]['half_life'][10010], 42.0) assert_true('_bad_key' in tape9[2]) assert_equal(tape9[3]['title'], "Sweet Decay") assert_equal(tape9[382]['sigma_f'][922350], 16.0) assert_true('_cards' not in tape9[1]) assert_true('_cards' not in tape9[2]) assert_true('_cards' not in tape9[3]) assert_true('_cards' in tape9[381]) assert_true('_cards' not in tape9[382]) assert_true('_cards' in tape9[383])
def run_all_the_origens(self, state, transmute_time, phi_tot, results): print("making tape9") self.tape9 = origen22.make_tape9(self.rc.track_nucs, self.xscache, nlb=(219, 220, 221)) self.tape9 = origen22.merge_tape9((self.tape9, origen22.loads_tape9(brightlitetape9))) origen22.write_tape9(self.tape9) for mat_id in results.keys(): pwd = self.pwd(state, "origen{}".format(mat_id)) mat = self.libs[mat_id]["material"][-1] if not os.path.isdir(pwd): os.makedirs(pwd) with indir(pwd): if not os.path.isfile("TAPE6.OUT"): self._make_origen_input(transmute_time, phi_tot, mat) origen_results = [] if self.rc.threads == 1: for mat_id in results.keys(): pwd = self.pwd(state, "origen{}".format(mat_id)) origen_params = (state.burn_times, transmute_time, phi_tot, mat_id, self.libs[mat_id]["material"][-1], pwd, self.origen_call) # self._make_origen_input) origen_results.append(_origen(origen_params)) else: origen_params_ls = [(state.burn_times, transmute_time, phi_tot, mat_id, self.libs[mat_id]["material"][-1], self.pwd(state, "origen{}".format(mat_id)), self.origen_call) for mat_id in results] pool = Pool(self.rc.threads) origen_results = pool.map(_origen, origen_params_ls) for result in origen_results: result[1]["material"] = Material(dict(result[1]["material"]), 1000, attrs={"units": "g"}) return dict(origen_results)
def main_gen(ns): """Generates an open TAPE9.INP file. by default this only uses completely open data. """ files = glob(os.path.join(ns.build_dir, 'ENSDF', 'ensdf.*')) if len(files) == 0: grab_ensdf_decay(ns.build_dir) files = glob(os.path.join(ns.build_dir, 'ENSDF', 'ensdf.*')) print("parsing ENSDF decay data") decays, branches = parse_ensdf(files) print("creating ORIGEN decay libraries") t9decay = gendecay(decays, branches, metastable_cutoff=ns.metastable_cutoff) print("creating ORIGEN cross section libraries") xsc = XSCache( data_source_classes=[EAFDataSource, SimpleDataSource, NullDataSource]) xsc.load() t9xsfpy = origen22.xslibs(xscache=xsc, verbose=True) t9 = origen22.merge_tape9([t9decay, t9xsfpy]) origen22.write_tape9(t9, outfile=ns.filename)
def run_all_the_origens(self, state, transmute_time, phi_tot, results): """Call ORIGEN as much as necessary and unite the results. Parameters ---------- state : namedtuple (State) A namedtuple containing the state parameters. transmute_time : float The length of the transmutation timestep. Has units of [days]. phi_tot : float The total neutron flux. results : dict A dict with material identifiers as keys, and dictionaries as values. The basic data structure to fill. Returns ------- dict A dict of all the ORIGEN results. """ if self.rc.verbose: print("making tape9 for {0} with phi={1}".format(state, phi_tot)) self.tape9 = origen22.make_tape9(self.rc.track_nucs, self.xscache, nlb=(219, 220, 221)) self.tape9 = origen22.merge_tape9((self.tape9, origen22.loads_tape9(brightlitetape9))) origen22.write_tape9(self.tape9) for mat_id in results.keys(): pwd = self.pwd(state, "origen{}".format(mat_id)) mat = self.libs[mat_id]["material"][-1] if not os.path.isdir(pwd): os.makedirs(pwd) with indir(pwd): if not os.path.isfile("TAPE6.OUT"): self._make_origen_input(transmute_time, phi_tot, mat) origen_results = [] if self.rc.threads == 1: for mat_id in results.keys(): pwd = self.pwd(state, "origen{}".format(mat_id)) origen_params = (state.burn_times, transmute_time, phi_tot, mat_id, self.libs[mat_id]["material"][-1], pwd, self.origen_call) origen_results.append(_origen(origen_params)) else: origen_params_ls = [(state.burn_times, transmute_time, phi_tot, mat_id, self.libs[mat_id]["material"][-1], self.pwd(state, "origen{}".format(mat_id)), self.origen_call) for mat_id in results] pool = Pool(self.rc.threads) origen_results = pool.map(_origen, origen_params_ls) pool.close() pool.join() for result in origen_results: result[1]["material"] = Material(dict(result[1]["material"]), 1000, attrs={"units": "g"}) return dict(origen_results)
def transmute(self, x, t=None, phi=None, tol=None, cwd=None, xscache=None, o2exe=None, *args, **kwargs): """Transmutes a material into its daughters. Parameters ---------- x : Material or similar Input material for transmutation. t : float Transmutations time [sec]. phi : float or array of floats Neutron flux vector [n/cm^2/sec]. Currently this must either be a scalar or match the group structure of EAF. tol : float Tolerance level for chain truncation. cwd : str, optional Current working directory for origen runs. Defaults to this dir. xscache : XSCache, optional A cross section cache to generate cross sections with. o2exe : str, optional Name or path to ORIGEN 2.2 executable. Returns ------- y : Material The output material post-transmutation. """ if not isinstance(x, Material): x = Material(x) if t is not None: self.t = t if phi is not None: self.phi = phi if tol is not None: self.tol = tol if cwd is not None: self.cwd = os.path.abspath(cwd) if xscache is not None: self.xscache = xscache if o2exe is not None: self.o2exe = o2exe # prepare new tape9 nucs = set(x.comp.keys()) base_tape9 = self.base_tape9 decay_nlb, xsfpy_nlb = origen22.nlbs(base_tape9) new_tape9 = origen22.xslibs(nucs=nucs, xscache=self.xscache, nlb=xsfpy_nlb) t9 = origen22.merge_tape9([new_tape9, base_tape9]) # write out files origen22.write_tape4(x, outfile=os.path.join(self.cwd, 'TAPE4.INP')) origen22.write_tape5_irradiation('IRF', self.t/86400.0, self.xscache['phi_g'][0], outfile=os.path.join(self.cwd, 'TAPE5.INP'), decay_nlb=decay_nlb, xsfpy_nlb=xsfpy_nlb, cut_off=self.tol) origen22.write_tape9(t9, outfile=os.path.join(self.cwd, 'TAPE9.INP')) # run origen & get results f = tempfile.NamedTemporaryFile() try: subprocess.check_call([self.o2exe], cwd=self.cwd, stdout=f, stderr=f) except subprocess.CalledProcessError: f.seek(0) print("ORIGEN output:\n\n{0}".format(f.read())) raise finally: f.close() t6 = origen22.parse_tape6(tape6=os.path.join(self.cwd, 'TAPE6.OUT')) y = t6['materials'][-1] return y
def transmute(self, x, t=None, phi=None, tol=None, cwd=None, xscache=None, o2exe=None, *args, **kwargs): """Transmutes a material into its daughters. Parameters ---------- x : Material or similar Input material for transmutation. t : float Transmutations time [sec]. phi : float or array of floats Neutron flux vector [n/cm^2/sec]. Currently this must either be a scalar or match the group structure of EAF. tol : float Tolerance level for chain truncation. cwd : str, optional Current working directory for origen runs. Defaults to this dir. xscache : XSCache, optional A cross section cache to generate cross sections with. o2exe : str, optional Name or path to ORIGEN 2.2 executable. Returns ------- y : Material The output material post-transmutation. """ if not isinstance(x, Material): x = Material(x) if t is not None: self.t = t if phi is not None: self.phi = phi if tol is not None: self.tol = tol if cwd is not None: self.cwd = os.path.abspath(cwd) if xscache is not None: self.xscache = xscache if o2exe is not None: self.o2exe = o2exe # prepare new tape9 nucs = set(x.comp.keys()) base_tape9 = self.base_tape9 decay_nlb, xsfpy_nlb = origen22.nlbs(base_tape9) new_tape9 = origen22.xslibs(nucs=nucs, xscache=self.xscache, nlb=xsfpy_nlb) t9 = origen22.merge_tape9([new_tape9, base_tape9]) # write out files origen22.write_tape4(x, outfile=os.path.join(self.cwd, 'TAPE4.INP')) origen22.write_tape5_irradiation('IRF', self.t / 86400.0, self.xscache['phi_g'][0], outfile=os.path.join( self.cwd, 'TAPE5.INP'), decay_nlb=decay_nlb, xsfpy_nlb=xsfpy_nlb, cut_off=self.tol) origen22.write_tape9(t9, outfile=os.path.join(self.cwd, 'TAPE9.INP')) # run origen & get results f = tempfile.NamedTemporaryFile() try: subprocess.check_call([self.o2exe], cwd=self.cwd, stdout=f, stderr=f) except subprocess.CalledProcessError: f.seek(0) print("ORIGEN output:\n\n{0}".format(f.read())) raise finally: f.close() t6 = origen22.parse_tape6(tape6=os.path.join(self.cwd, 'TAPE6.OUT')) y = t6['materials'][-1] return y
# Init a dumb overlay tape9 overlay_tape9 = {381: {'_type': 'xsfpy', '_subtype': 'activation_products', 'sigma_gamma': {10010: base_h1_xs}, } } # Run origen, increasing the cross section each time. h2_concentration = [] for i in range(11): overlay_tape9[381]['sigma_gamma'][10010] = (1.0 + i*0.1) * base_h1_xs # Merge the base and overlay, and write out new_tape9 = origen22.merge_tape9([overlay_tape9, base_tape9]) origen22.write_tape9(new_tape9, 'TAPE9.INP') # Run and parse origen output rtn = check_call(['o2_therm_linux.exe']) tape6 = origen22.parse_tape6('TAPE6.OUT') h2_concentration.append(tape6['table_5']['summary']['activation_products']['H2'][-1]) print print "H2 Concentration: ", h2_concentration # Clean up import os for f in os.listdir('.'): if (f.endswith('.INP') or f.endswith('.OUT')) and f != 'BASE_TAPE9.INP':
381: { '_type': 'xsfpy', '_subtype': 'activation_products', 'sigma_gamma': { 10010: base_h1_xs }, } } # Run origen, increasing the cross section each time. h2_concentration = [] for i in range(11): overlay_tape9[381]['sigma_gamma'][10010] = (1.0 + i * 0.1) * base_h1_xs # Merge the base and overlay, and write out new_tape9 = origen22.merge_tape9([overlay_tape9, base_tape9]) origen22.write_tape9(new_tape9, 'TAPE9.INP') # Run and parse origen output rtn = check_call(['o2_therm_linux.exe']) tape6 = origen22.parse_tape6('TAPE6.OUT') h2_concentration.append( tape6['table_5']['summary']['activation_products']['H2'][-1]) print print "H2 Concentration: ", h2_concentration # Clean up import os for f in os.listdir('.'): if (f.endswith('.INP') or f.endswith('.OUT')) and f != 'BASE_TAPE9.INP':