diff --git a/openmc/data/fission_energy.py b/openmc/data/fission_energy.py index 5ce9f47d5c1..a7cf3dfed3b 100644 --- a/openmc/data/fission_energy.py +++ b/openmc/data/fission_energy.py @@ -107,7 +107,7 @@ def write_compact_458_library(endf_files, output_name='fission_Q_data.h5', """ # Open the output file. - out = h5py.File(output_name, 'w', libver='latest') + out = h5py.File(output_name, 'w', libver='earliest') # Write comments, if given. This commented out comment is the one used for # the library distributed with OpenMC. diff --git a/openmc/data/neutron.py b/openmc/data/neutron.py index ed2f4f8b75e..08d12106c2e 100644 --- a/openmc/data/neutron.py +++ b/openmc/data/neutron.py @@ -478,7 +478,7 @@ def get_reaction_components(self, mt): mts = new_mts return mts - def export_to_hdf5(self, path, mode='a'): + def export_to_hdf5(self, path, mode='a', libver='earliest'): """Export incident neutron data to an HDF5 file. Parameters @@ -488,6 +488,9 @@ def export_to_hdf5(self, path, mode='a'): mode : {'r', r+', 'w', 'x', 'a'} Mode that is used to open the HDF5 file. This is the second argument to the :class:`h5py.File` constructor. + libver : {'earliest', 'latest'} + Compatibility mode for the HDF5 file. 'latest' will produce files + that are less backwards compatible but have performance benefits. """ # If data come from ENDF, don't allow exporting to HDF5 @@ -496,7 +499,7 @@ def export_to_hdf5(self, path, mode='a'): 'originated from an ENDF file.') # Open file and write version - f = h5py.File(path, mode, libver='latest') + f = h5py.File(path, mode, libver=libver) f.attrs['version'] = np.array(HDF5_VERSION) # Write basic data diff --git a/openmc/data/thermal.py b/openmc/data/thermal.py index 6e7b0fe02cd..99e4b5a5374 100644 --- a/openmc/data/thermal.py +++ b/openmc/data/thermal.py @@ -245,7 +245,7 @@ def __repr__(self): def temperatures(self): return ["{}K".format(int(round(kT / K_BOLTZMANN))) for kT in self.kTs] - def export_to_hdf5(self, path, mode='a'): + def export_to_hdf5(self, path, mode='a', libver='earliest'): """Export table to an HDF5 file. Parameters @@ -255,10 +255,13 @@ def export_to_hdf5(self, path, mode='a'): mode : {'r', r+', 'w', 'x', 'a'} Mode that is used to open the HDF5 file. This is the second argument to the :class:`h5py.File` constructor. + libver : {'earliest', 'latest'} + Compatibility mode for the HDF5 file. 'latest' will produce files + that are less backwards compatible but have performance benefits. """ # Open file and write version - f = h5py.File(path, mode, libver='latest') + f = h5py.File(path, mode, libver=libver) f.attrs['version'] = np.array(HDF5_VERSION) # Write basic data diff --git a/openmc/mgxs/library.py b/openmc/mgxs/library.py index 3cdd0fbf542..b83305783f9 100644 --- a/openmc/mgxs/library.py +++ b/openmc/mgxs/library.py @@ -760,7 +760,7 @@ def get_subdomain_avg_library(self): def build_hdf5_store(self, filename='mgxs.h5', directory='mgxs', subdomains='all', nuclides='all', xs_type='macro', - row_column='inout'): + row_column='inout', libver='earliest'): """Export the multi-group cross section library to an HDF5 binary file. This method constructs an HDF5 file which stores the library's @@ -794,6 +794,9 @@ def build_hdf5_store(self, filename='mgxs.h5', directory='mgxs', Store scattering matrices indexed first by incoming group and second by outgoing group ('inout'), or vice versa ('outin'). Defaults to 'inout'. + libver : {'earliest', 'latest'} + Compatibility mode for the HDF5 file. 'latest' will produce files + that are less backwards compatible but have performance benefits. Raises ------ @@ -823,7 +826,7 @@ def build_hdf5_store(self, filename='mgxs.h5', directory='mgxs', # Add an attribute for the number of energy groups to the HDF5 file full_filename = os.path.join(directory, filename) full_filename = full_filename.replace(' ', '-') - f = h5py.File(full_filename, 'w') + f = h5py.File(full_filename, 'w', libver=libver) f.attrs['# groups'] = self.num_groups f.close() diff --git a/openmc/mgxs/mgxs.py b/openmc/mgxs/mgxs.py index 192f484a5ef..b7ec652c7d6 100644 --- a/openmc/mgxs/mgxs.py +++ b/openmc/mgxs/mgxs.py @@ -1636,7 +1636,8 @@ def print_xs(self, subdomains='all', nuclides='all', xs_type='macro'): def build_hdf5_store(self, filename='mgxs.h5', directory='mgxs', subdomains='all', nuclides='all', - xs_type='macro', row_column='inout', append=True): + xs_type='macro', row_column='inout', append=True, + libver='earliest'): """Export the multi-group cross section data to an HDF5 binary file. This method constructs an HDF5 file which stores the multi-group @@ -1672,6 +1673,9 @@ def build_hdf5_store(self, filename='mgxs.h5', directory='mgxs', append : bool If true, appends to an existing HDF5 file with the same filename directory (if one exists). Defaults to True. + libver : {'earliest', 'latest'} + Compatibility mode for the HDF5 file. 'latest' will produce files + that are less backwards compatible but have performance benefits. Raises ------ @@ -1695,7 +1699,7 @@ def build_hdf5_store(self, filename='mgxs.h5', directory='mgxs', if append and os.path.isfile(filename): xs_results = h5py.File(filename, 'a') else: - xs_results = h5py.File(filename, 'w') + xs_results = h5py.File(filename, 'w', libver=libver) # Construct a collection of the subdomains to report if not isinstance(subdomains, string_types): diff --git a/openmc/mgxs_library.py b/openmc/mgxs_library.py index 93a3607d997..ebfae2fb0d2 100644 --- a/openmc/mgxs_library.py +++ b/openmc/mgxs_library.py @@ -2504,20 +2504,23 @@ def convert_scatter_format(self, target_format, target_order): return library - def export_to_hdf5(self, filename='mgxs.h5'): + def export_to_hdf5(self, filename='mgxs.h5', libver='earliest'): """Create an hdf5 file that can be used for a simulation. Parameters ---------- filename : str Filename of file, default is mgxs.h5. + libver : {'earliest', 'latest'} + Compatibility mode for the HDF5 file. 'latest' will produce files + that are less backwards compatible but have performance benefits. """ check_type('filename', filename, string_types) # Create and write to the HDF5 file - file = h5py.File(filename, "w") + file = h5py.File(filename, "w", libver=libver) file.attrs['filetype'] = np.string_(_FILETYPE_MGXS_LIBRARY) file.attrs['version'] = [_VERSION_MGXS_LIBRARY, 0] file.attrs['energy_groups'] = self.energy_groups.num_groups diff --git a/scripts/openmc-ace-to-hdf5 b/scripts/openmc-ace-to-hdf5 index bfc1c1a54d9..3235a2da638 100755 --- a/scripts/openmc-ace-to-hdf5 +++ b/scripts/openmc-ace-to-hdf5 @@ -46,7 +46,8 @@ parser.add_argument('libraries', nargs='*', help='ACE libraries to convert to HDF5') parser.add_argument('-d', '--destination', default='.', help='Directory to create new library in') -parser.add_argument('-m', '--metastable', choices=['mcnp', 'nndc'], default='nndc', +parser.add_argument('-m', '--metastable', choices=['mcnp', 'nndc'], + default='nndc', help='How to interpret ZAIDs for metastable nuclides') parser.add_argument('--xml', help='Old-style cross_sections.xml that ' 'lists ACE libraries') @@ -56,6 +57,10 @@ parser.add_argument('--xsdata', help='Serpent xsdata file that lists ' 'ACE libraries') parser.add_argument('--fission_energy_release', help='HDF5 file containing ' 'fission energy release data') +parser.add_argument('--libver', choices=['earliest', 'latest'], + default='earliest', help="Output HDF5 versioning. Use " + "'earliest' for backwards compatibility or 'latest' for " + "performance") args = parser.parse_args() if not os.path.isdir(args.destination): @@ -150,7 +155,7 @@ for filename in ace_libraries: # Determine filename outfile = os.path.join(args.destination, neutron.name.replace('.', '_') + '.h5') - neutron.export_to_hdf5(outfile, 'w') + neutron.export_to_hdf5(outfile, 'w', libver=args.libver) # Register with library library.register_file(outfile) @@ -162,10 +167,11 @@ for filename in ace_libraries: try: neutron = \ openmc.data.IncidentNeutron.from_hdf5(nuclides[name]) - print('Converting {} (ACE) to {} (HDF5)'.format(table.name, - neutron.name)) + print('Converting {} (ACE) to {} (HDF5)' + .format(table.name, neutron.name)) neutron.add_temperature_from_ace(table, args.metastable) - neutron.export_to_hdf5(nuclides[name] + '_1', 'w') + neutron.export_to_hdf5(nuclides[name] + '_1', 'w', + libver=args.libver) os.rename(nuclides[name] + '_1', nuclides[name]) except Exception as e: print('Failed to convert {}: {}'.format(table.name, e)) @@ -187,7 +193,7 @@ for filename in ace_libraries: # Determine filename outfile = os.path.join(args.destination, thermal.name.replace('.', '_') + '.h5') - thermal.export_to_hdf5(outfile, 'w') + thermal.export_to_hdf5(outfile, 'w', libver=args.libver) # Register with library library.register_file(outfile) @@ -198,11 +204,13 @@ for filename in ace_libraries: else: # Then we only need to append the data try: - thermal = openmc.data.ThermalScattering.from_hdf5(nuclides[name]) - print('Converting {} (ACE) to {} (HDF5)'.format(table.name, - thermal.name)) + thermal = openmc.data.ThermalScattering.from_hdf5( + nuclides[name]) + print('Converting {} (ACE) to {} (HDF5)' + .format(table.name,thermal.name)) thermal.add_temperature_from_ace(table) - thermal.export_to_hdf5(nuclides[name] + '_1', 'w') + thermal.export_to_hdf5(nuclides[name] + '_1', 'w', + libver=args.libver) os.rename(nuclides[name] + '_1', nuclides[name]) except Exception as e: print('Failed to convert {}: {}'.format(table.name, e)) diff --git a/scripts/openmc-convert-mcnp70-data b/scripts/openmc-convert-mcnp70-data index a3081e3ee14..0489b25de41 100755 --- a/scripts/openmc-convert-mcnp70-data +++ b/scripts/openmc-convert-mcnp70-data @@ -26,6 +26,10 @@ parser = argparse.ArgumentParser( ) parser.add_argument('-d', '--destination', default='mcnp_endfb70', help='Directory to create new library in') +parser.add_argument('--libver', choices=['earliest', 'latest'], + default='earliest', help="Output HDF5 versioning. Use " + "'earliest' for backwards compatibility or 'latest' for " + "performance") parser.add_argument('mcnpdata', help='Directory containing endf70[a-k] and endf70sab') args = parser.parse_args() assert os.path.isdir(args.mcnpdata) @@ -62,7 +66,7 @@ for path in sorted(endf70): # Export HDF5 file h5_file = os.path.join(args.destination, data.name + '.h5') print('Writing {}...'.format(h5_file)) - data.export_to_hdf5(h5_file, 'w') + data.export_to_hdf5(h5_file, 'w', libver=args.libver) # Register with library library.register_file(h5_file) @@ -91,7 +95,7 @@ if os.path.exists(endf70sab): # Export HDF5 file h5_file = os.path.join(args.destination, data.name + '.h5') print('Writing {}...'.format(h5_file)) - data.export_to_hdf5(h5_file, 'w') + data.export_to_hdf5(h5_file, 'w', libver=args.libver) # Register with library library.register_file(h5_file) diff --git a/scripts/openmc-convert-mcnp71-data b/scripts/openmc-convert-mcnp71-data index 9440959197a..061f8f46f09 100755 --- a/scripts/openmc-convert-mcnp71-data +++ b/scripts/openmc-convert-mcnp71-data @@ -28,6 +28,10 @@ parser.add_argument('-d', '--destination', default='mcnp_endfb71', help='Directory to create new library in') parser.add_argument('-f', '--fission_energy_release', help='HDF5 file containing fission energy release data') +parser.add_argument('--libver', choices=['earliest', 'latest'], + default='earliest', help="Output HDF5 versioning. Use " + "'earliest' for backwards compatibility or 'latest' for " + "performance") parser.add_argument('mcnpdata', help='Directory containing endf71x and ENDF71SaB') args = parser.parse_args() assert os.path.isdir(args.mcnpdata) @@ -80,7 +84,7 @@ for basename, xs_list in sorted(suffixes.items()): # Export HDF5 file h5_file = os.path.join(args.destination, data.name + '.h5') print('Writing {}...'.format(h5_file)) - data.export_to_hdf5(h5_file, 'w') + data.export_to_hdf5(h5_file, 'w', libver=args.libver) # Register with library library.register_file(h5_file) diff --git a/scripts/openmc-get-jeff-data b/scripts/openmc-get-jeff-data index 3166b3854ed..6d9e086a91d 100755 --- a/scripts/openmc-get-jeff-data +++ b/scripts/openmc-get-jeff-data @@ -43,6 +43,10 @@ parser.add_argument('-b', '--batch', action='store_true', help='supresses standard in') parser.add_argument('-d', '--destination', default='jeff-3.2-hdf5', help='Directory to create new library in') +parser.add_argument('--libver', choices=['earliest', 'latest'], + default='earliest', help="Output HDF5 versioning. Use " + "'earliest' for backwards compatibility or 'latest' for " + "performance") args = parser.parse_args() response = input(download_warning) if not args.batch else 'y' @@ -179,7 +183,7 @@ for name, filenames in sorted(tables.items()): # Export HDF5 file h5_file = os.path.join(args.destination, data.name + '.h5') print('Writing {}...'.format(h5_file)) - data.export_to_hdf5(h5_file, 'w') + data.export_to_hdf5(h5_file, 'w', libver=args.libver) # Register with library library.register_file(h5_file) @@ -222,7 +226,7 @@ for name, filenames in sorted(tables.items()): # Export HDF5 file h5_file = os.path.join(args.destination, data.name + '.h5') print('Writing {}...'.format(h5_file)) - data.export_to_hdf5(h5_file, 'w') + data.export_to_hdf5(h5_file, 'w', libver=args.libver) # Register with library library.register_file(h5_file) diff --git a/scripts/openmc-get-nndc-data b/scripts/openmc-get-nndc-data index f1da2241ab6..e2c1e7ce3aa 100755 --- a/scripts/openmc-get-nndc-data +++ b/scripts/openmc-get-nndc-data @@ -33,6 +33,10 @@ parser = argparse.ArgumentParser( ) parser.add_argument('-b', '--batch', action='store_true', help='supresses standard in') +parser.add_argument('--libver', choices=['earliest', 'latest'], + default='earliest', help="Output HDF5 versioning. Use " + "'earliest' for backwards compatibility or 'latest' for " + "performance") args = parser.parse_args() @@ -154,7 +158,10 @@ ace_files = sorted(glob.glob(os.path.join('nndc', '**', '*.ace*'))) data_dir = os.path.dirname(sys.modules['openmc.data'].__file__) fer_file = os.path.join(data_dir, 'fission_Q_data_endfb71.h5') +# Call the ace-to-hdf5 conversion script pwd = os.path.dirname(os.path.realpath(__file__)) ace2hdf5 = os.path.join(pwd, 'openmc-ace-to-hdf5') -subprocess.call([ace2hdf5, '-d', 'nndc_hdf5', '--fission_energy_release', - fer_file] + ace_files) +subprocess.call([ace2hdf5, + '-d', 'nndc_hdf5', + '--fission_energy_release', fer_file, + '--libver', args.libver] + ace_files)