def test_writeread(self): ff = pp.FilesFile() self._assertDefaults(ff) # change default flux ff.fluxes = "flux1" # set some other paths ff.ind_nuc = "/path/to/ind_nuc" ff.enbins = "/path/to/enbins" d = ff.to_dict() # 4 defaults + 2 set above self.assertEqual(6, len(d), "Assert size of set paths") self.assertTrue('fluxes' in d, "Assert fluxes is set") self.assertTrue('xs_endf' not in d, "Assert xs_endf is not set") self.assertEqual("flux1", d['fluxes'], "Assert fluxes") self.assertEqual("flux1", ff.fluxes, "Assert fluxes") self.assertEqual("/path/to/ind_nuc", d['ind_nuc'], "Assert /path/to/ind_nuc") self.assertEqual("/path/to/ind_nuc", ff.ind_nuc, "Assert ind_nuc") self.assertEqual("/path/to/enbins", d['enbins'], "Assert /path/to/enbins") self.assertEqual("/path/to/enbins", ff.enbins, "Assert enbins") # write to file filename = '_PYPACT_TEST_writeread_files' pp.to_file(ff, filename) # reset ff.reset() d = ff.to_dict() self.assertEqual(0, len(d), "Assert size of set paths") self.assertEqual("null", ff.fluxes, "Assert fluxes") self.assertEqual("null", ff.collapxi, "Assert collapxi") self.assertEqual("null", ff.collapxo, "Assert collapxo") self.assertEqual("null", ff.arrayx, "Assert arrayx") self.assertEqual("null", ff.ind_nuc, "Assert ind_nuc") self.assertEqual("null", ff.xs_endf, "Assert xs_endf") self.assertEqual("null", ff.ggbins, "Assert ggbins") # read from file filename = '_PYPACT_TEST_writeread_files' pp.from_file(ff, filename) d = ff.to_dict() # 4 defaults + 2 set above self.assertEqual(6, len(d), "Assert size of set paths") self.assertTrue('fluxes' in d, "Assert fluxes is set") self.assertTrue('xs_endf' not in d, "Assert xs_endf is not set") self.assertEqual("flux1", d['fluxes'], "Assert fluxes") self.assertEqual("flux1", ff.fluxes, "Assert fluxes") self.assertEqual("/path/to/ind_nuc", d['ind_nuc'], "Assert /path/to/ind_nuc") self.assertEqual("/path/to/ind_nuc", ff.ind_nuc, "Assert ind_nuc") self.assertEqual("/path/to/enbins", d['enbins'], "Assert /path/to/enbins") self.assertEqual("/path/to/enbins", ff.enbins, "Assert enbins")
def test_todict(self): ff = pp.FilesFile() self._assertDefaults(ff) # change default flux ff.fluxes = "flux1" # set some other paths ff.ind_nuc = "/path/to/ind_nuc" ff.enbins = "/path/to/enbins" d = ff.to_dict() # 4 defaults + 2 set above self.assertEqual(6, len(d), "Assert size of set paths") self.assertTrue('fluxes' in d, "Assert fluxes is set") self.assertTrue('xs_endf' not in d, "Assert xs_endf is not set") self.assertEqual("flux1", d['fluxes'], "Assert fluxes") self.assertEqual("flux1", ff.fluxes, "Assert fluxes") self.assertEqual("/path/to/ind_nuc", d['ind_nuc'], "Assert /path/to/ind_nuc") self.assertEqual("/path/to/ind_nuc", ff.ind_nuc, "Assert ind_nuc") self.assertEqual("/path/to/enbins", d['enbins'], "Assert /path/to/enbins") self.assertEqual("/path/to/enbins", ff.enbins, "Assert enbins")
def createfiles(): nuclear_data_base = os.getenv('NUCLEAR_DATA', os.path.join(os.sep, 'opt', 'fispact', 'nuclear_data')) ff = pp.FilesFile(base_dir=nuclear_data_base) ff.setXS('TENDL2015') ff.setFissionYield('GEFY52') ff.setProbTab('TENDL2015') ff.setDecay('DECAY') ff.setRegulatory('DECAY') ff.setGammaAbsorb('DECAY') for invalid in ff.invalidpaths(): print("FilesFile:: missing file: {}".format(invalid)) return ff
def main(): # Command line argument support parser = argparse.ArgumentParser(description='Files file path changer') parser.add_argument('oldfile', type=argparse.FileType('r'), help='The fispact files file to be read') parser.add_argument('newfile', type=argparse.FileType('w'), help='The changed fispact files file to be written') parser.add_argument('oldpath', type=str, default='/opt/fispact/nuclear_data', help='The old file path to change in old file') parser.add_argument('newpath', type=str, default='/nuclear_data', help='The new file path to use in new file') args = parser.parse_args() old_file = args.oldfile.name new_file = args.newfile.name old_path = args.oldpath new_path = args.newpath ff = pp.FilesFile() pp.from_file(ff, old_file) # change paths here for k, v in ff.to_dict().items(): if old_path in v: new_v = v.replace(old_path, new_path) ff.__setattr__(k, new_v) # validate new paths print(" * Invalid paths are: ") for k, p in ff.invalidpaths(): print("Key: {}, Path: {}".format(k, p)) pp.to_file(ff, new_file)
#!/usr/bin/env python3 import os import pypact as pp base_dir = os.getenv('NUCLEAR_DATA', os.path.join(os.sep, 'opt', 'fispact', 'nuclear_data')) # write a files file ff = pp.FilesFile(base_dir=base_dir) ff.setXS('TENDL2017') ff.setFissionYield('GEFY52') ff.setProbTab('TENDL2015') ff.setDecay('DECAY') ff.setRegulatory('DECAY') ff.setGammaAbsorb('DECAY') pp.to_file(ff, os.path.join('files', 'newfilesfile'))
def getinventory(output): fuel = [] # get the last entry only for n in output[-1].nuclides: fuel.append(("{}{}{}".format(n.element, n.isotope, n.state), n.atoms)) return fuel ipt1 = makeinput(inventory=[("W", 100.0)], usemass=True, irradschedule=[(0.0, 1.1e14), (300., 1.1e14)]) fluxes = pp.FluxesFile() files = pp.FilesFile() pp.from_file(fluxes, 'fluxes.1') pp.from_file(files, 'files.1') opt1 = pp.compute(ipt1, files, fluxes, cleanup=False) print(opt1.run_data.run_name) irradschedule = [(0.0, 1.3e14), (600.0, 1.3e14)] for i in range(10): irradschedule.extend((1.0 * YEAR_IN_SECS, 0.0)) ipt2 = makeinput(inventory=getinventory(opt1), irradschedule=irradschedule) pp.from_file(fluxes, 'fluxes.1') pp.from_file(files, 'files.1') opt2 = pp.compute(ipt2, files, fluxes)
import pypact as pp filename = "dummyfiles" # read a files file ff = pp.FilesFile() pp.deserialize(ff, filename) print("Decay data: ", ff.dk_endf) print("Condense output file: ", ff.arrayx)
def test_default(self): ff = pp.FilesFile() self._assertDefaults(ff)