def create_library(xsdir, table_names, hdf5_dir, xsdata_dir=None): """Convert the ACE data from the MCNP or Serpent distribution into an HDF5 library that can be used by OpenMC and create and XSDATA directory file for use with Serpent. Parameters ---------- xsdir : str Path of the XSDIR directory file table_names : str or iterable Names of the ACE tables to convert hdf5_dir : str Directory to write the HDF5 library to xsdata_dir : str If specified, an XSDATA directory file containing entries for each of the table names provided will be written to this directory. """ # Create data library data_lib = openmc.data.DataLibrary() # Load the XSDIR directory file xsdir = XSDIR(xsdir) # Get the ACE cross section tables tables = xsdir.get_tables(table_names) for table in tables: zaid, suffix = table.name.split('.') # Convert cross section data if suffix[-1] == 'c': match = '(7[0-4]c)|(8[0-6]c)|(71[0-6]nc)' scheme = 'mcnp' if re.match(match, suffix) else 'nndc' data = openmc.data.IncidentNeutron.from_ace(table, scheme) elif suffix[-1] == 'p': data = openmc.data.IncidentPhoton.from_ace(table) elif suffix[-1] == 't': data = openmc.data.ThermalScattering.from_ace(table) else: msg = ('Unknown data class: cannot convert cross section data ' f'from table {table.name}') raise ValueError(msg) # Export HDF5 files and register with library h5_file = Path(hdf5_dir) / f'{data.name}.h5' data.export_to_hdf5(h5_file, 'w') data_lib.register_file(h5_file) # Write cross_sections.xml data_lib.export_to_xml(Path(hdf5_dir) / 'cross_sections.xml') # Write the Serpent XSDATA file if xsdata_dir is not None: xsdir.export_to_xsdata(Path(xsdata_dir) / 'xsdata', table_names)
def process_neutron_random(nuc, i, out_dir, in_dir, file_num): """Process ENDF neutron sublibrary file into HDF5 and write into a specified output directory.""" fileIn = in_dir / f"{nuc}-{i}" fileOut = out_dir / f"{nuc}-{i}.h5" data = openmc.data.IncidentNeutron.from_njoy(fileIn) data.name = f"{nuc}-{i}" data.export_to_hdf5(fileOut, "w") if i % 40 == 0: print(f"Nuclide {nuc} {i}/{file_num} finished")
def process_neutron(filename, output_dir): """Process ENDF neutron sublibrary file into HDF5 and write into a specified output directory.""" try: with warnings.catch_warnings(): warnings.simplefilter('ignore', UserWarning) data = openmc.data.IncidentNeutron.from_njoy( filename, temperatures=temperatures ) except Exception as e: print(filename, e) raise data.export_to_hdf5(output_dir / f'{data.name}.h5', 'w') print(f'Finished {filename}')
def process_thermal(path_neutron, path_thermal, output_dir, libver): """Process ENDF thermal scattering sublibrary file into HDF5 and write into a specified output directory.""" print(f'Converting: {path_thermal}') try: with warnings.catch_warnings(): warnings.simplefilter('ignore', UserWarning) data = openmc.data.ThermalScattering.from_njoy( path_neutron, path_thermal) except Exception as e: print(path_neutron, path_thermal, e) raise h5_file = output_dir / f'{data.name}.h5' print(f'Writing {h5_file} ...') data.export_to_hdf5(h5_file, 'w', libver=libver)
def process_neutron(path, output_dir, libver, temperatures=None): """Process ENDF neutron sublibrary file into HDF5 and write into a specified output directory.""" print(f'Converting: {path}') try: with warnings.catch_warnings(): warnings.simplefilter('ignore', UserWarning) data = openmc.data.IncidentNeutron.from_njoy( path, temperatures=temperatures) except Exception as e: print(path, e) raise h5_file = output_dir / f'{data.name}.h5' print(f'Writing {h5_file} ...') data.export_to_hdf5(h5_file, 'w', libver=libver)
def process_thermal(path_neutron, path_thermal, output_dir): """Process ENDF thermal scattering sublibrary file into HDF5 and write into a specified output directory.""" try: with warnings.catch_warnings(): warnings.simplefilter('ignore', UserWarning) data = openmc.data.ThermalScattering.from_njoy( path_neutron, path_thermal) except Exception as e: print(path_neutron, path_thermal, e) raise data.export_to_hdf5(output_dir / f'{data.name}.h5', 'w', libver=args.libver) print(f'Finished {path_thermal}')
# Create output directory if it doesn't exist args.destination.mkdir(parents=True, exist_ok=True) library = openmc.data.DataLibrary() for filename in sorted(neutron_files): # this is a fix for the TENDL-2017 release where the B10 ACE file which has an error on one of the values if library_name == 'tendl' and args.release == '2017' and filename.name == 'B010': text = open(filename, 'r').read() if text[423:428] == '86843': print('Manual fix for incorrect value in ACE file') # see OpenMC user group issue for more details text = ''.join(text[:423]) + '86896' + ''.join(text[428:]) open(filename, 'w').write(text) print(f'Converting: {filename}') data = openmc.data.IncidentNeutron.from_ace(filename) # Export HDF5 file h5_file = args.destination / f'{data.name}.h5' print('Writing {}...'.format(h5_file)) data.export_to_hdf5(h5_file, 'w', libver=args.libver) # Register with library library.register_file(h5_file) # Write cross_sections.xml library.export_to_xml(args.destination / 'cross_sections.xml')
# ========================================================================= # INCIDENT PHOTON DATA for z in range(1, 101): element = openmc.data.ATOMIC_SYMBOL[z] print('Generating HDF5 file for Z={} ({})...'.format(z, element)) # Generate instance of IncidentPhoton photo_file = Path('photoat') / f'photoat-{z:03}_{element}_000.endf' atom_file = Path('atomic_relax') / f'atom-{z:03}_{element}_000.endf' data = openmc.data.IncidentPhoton.from_endf(photo_file, atom_file) # Write HDF5 file and register it outfile = output_dir / 'photon' / f'{element}.h5' data.export_to_hdf5(outfile, 'w') library.register_file(outfile) # ========================================================================= # WINDOWED MULTIPOLE DATA # Download and extract data download(urljoin(wmp_base, wmp_filename)) with tarfile.open(wmp_filename, 'r') as tgz: tgz.extractall(output_dir) os.rename(output_dir / 'WMP_Library', output_dir / 'wmp') # Add multipole data to library for f in sorted(glob.glob(f'{output_dir}/wmp/*.h5')): library.register_file(f)
def test_photodat_only(run_in_tmpdir): endf_dir = Path(os.environ['OPENMC_ENDF_DATA']) photoatomic_file = endf_dir / 'photoat' / 'photoat-001_H_000.endf' data = openmc.data.IncidentPhoton.from_endf(photoatomic_file) data.export_to_hdf5('tmp.h5', 'w')