def test_xslibs(): exp = {42: {'_type': 'xsfpy', '_subtype': 'activation_products', 'title': 'PyNE Cross Section Data for Activation Products'}, 43: {'_type': 'xsfpy', '_subtype': 'actinides', 'title': 'PyNE Cross Section Data for Actinides & Daughters'}, 44: {'_type': 'xsfpy', '_subtype': 'fission_products', 'title': 'PyNE Cross Section Data for Fission Products'}, } xsc = XSCache(data_sources=[NullDataSource]) nucs = [922350000, 10010000, 461080000] obs = origen22.xslibs(nucs=nucs, xscache=xsc, nlb=(42, 43, 44)) obs_meta = {} for n in exp: obs_meta[n] = {} for field in ['_type', '_subtype', 'title']: obs_meta[n][field] = obs[n][field] assert_equal(exp, obs_meta) for n in exp: for field in obs[n]: if not field.startswith('sigma_'): continue assert_true(all([v == 0.0 for v in obs[n][field].values()])) assert_true(set(obs[42].keys()) >= set(origen22.ACTIVATION_PRODUCT_FIELDS + origen22.XSFPY_FIELDS)) assert_true(set(obs[43].keys()) >= set(origen22.ACTINIDE_FIELDS + origen22.XSFPY_FIELDS)) assert_true(set(obs[44].keys()) >= set(origen22.FISSION_PRODUCT_FIELDS + origen22.XSFPY_FIELDS))
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_xslibs(): exp = { 42: { "_type": "xsfpy", "_subtype": "activation_products", "title": "PyNE Cross Section Data for Activation Products", }, 43: { "_type": "xsfpy", "_subtype": "actinides", "title": "PyNE Cross Section Data for Actinides & Daughters", }, 44: { "_type": "xsfpy", "_subtype": "fission_products", "title": "PyNE Cross Section Data for Fission Products", }, } xsc = XSCache(data_sources=[NullDataSource]) nucs = [922350000, 10010000, 461080000] obs = origen22.xslibs(nucs=nucs, xscache=xsc, nlb=(42, 43, 44)) obs_meta = {} for n in exp: obs_meta[n] = {} for field in ["_type", "_subtype", "title"]: obs_meta[n][field] = obs[n][field] assert_equal(exp, obs_meta) for n in exp: for field in obs[n]: if not field.startswith("sigma_"): continue assert_true(all([v == 0.0 for v in obs[n][field].values()])) assert_true( set(obs[42].keys()) >= set(origen22.ACTIVATION_PRODUCT_FIELDS + origen22.XSFPY_FIELDS) ) assert_true( set(obs[43].keys()) >= set(origen22.ACTINIDE_FIELDS + origen22.XSFPY_FIELDS) ) assert_true( set(obs[44].keys()) >= set(origen22.FISSION_PRODUCT_FIELDS + origen22.XSFPY_FIELDS) )
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 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
def origen(self, state, xs): """Runs ORIGEN calulations to obtain transmutation matix.""" t9 = origen22.xslibs(xscache=self.xscache, verbose=self.rc.verbose) import pdb; pdb.set_trace()