Allow optional 'latest' libver for HDF5 xs data

This commit is contained in:
Sterling Harper 2017-12-17 19:48:08 -05:00
parent f754357aea
commit 0460d9a538
10 changed files with 83 additions and 28 deletions

View file

@ -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,9 @@ 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('--latest_hdf5', help='Use latest HDF5 format for '
'performance over backwards compatibility',
action='store_true')
args = parser.parse_args()
if not os.path.isdir(args.destination):
@ -117,6 +121,10 @@ else:
nuclides = {}
library = openmc.data.DataLibrary()
if args.latest_hdf5:
libver = 'latest'
else:
libver = 'earliest'
for filename in ace_libraries:
# Check that ACE library exists
@ -150,7 +158,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=libver)
# Register with library
library.register_file(outfile)
@ -162,10 +170,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=libver)
os.rename(nuclides[name] + '_1', nuclides[name])
except Exception as e:
print('Failed to convert {}: {}'.format(table.name, e))
@ -187,7 +196,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=libver)
# Register with library
library.register_file(outfile)
@ -198,11 +207,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=libver)
os.rename(nuclides[name] + '_1', nuclides[name])
except Exception as e:
print('Failed to convert {}: {}'.format(table.name, e))

View file

@ -26,6 +26,9 @@ parser = argparse.ArgumentParser(
)
parser.add_argument('-d', '--destination', default='mcnp_endfb70',
help='Directory to create new library in')
parser.add_argument('--latest_hdf5', help='Use latest HDF5 format for '
'performance over backwards compatibility',
action='store_true')
parser.add_argument('mcnpdata', help='Directory containing endf70[a-k] and endf70sab')
args = parser.parse_args()
assert os.path.isdir(args.mcnpdata)
@ -38,6 +41,10 @@ if not os.path.isdir(args.destination):
os.mkdir(args.destination)
library = openmc.data.DataLibrary()
if args.latest_hdf5:
libver = 'latest'
else:
libver = 'earliest'
for path in sorted(endf70):
print('Loading data from {}...'.format(path))
@ -62,7 +69,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=libver)
# Register with library
library.register_file(h5_file)
@ -91,7 +98,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=libver)
# Register with library
library.register_file(h5_file)

View file

@ -28,6 +28,9 @@ 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('--latest_hdf5', help='Use latest HDF5 format for '
'performance over backwards compatibility',
action='store_true')
parser.add_argument('mcnpdata', help='Directory containing endf71x and ENDF71SaB')
args = parser.parse_args()
assert os.path.isdir(args.mcnpdata)
@ -51,6 +54,10 @@ if not os.path.isdir(args.destination):
os.mkdir(args.destination)
library = openmc.data.DataLibrary()
if args.latest_hdf5:
libver = 'latest'
else:
libver = 'earliest'
for basename, xs_list in sorted(suffixes.items()):
# Convert first temperature for the table
@ -80,7 +87,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=libver)
# Register with library
library.register_file(h5_file)

View file

@ -43,6 +43,9 @@ 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('--latest_hdf5', help='Use latest HDF5 format for '
'performance over backwards compatibility',
action='store_true')
args = parser.parse_args()
response = input(download_warning) if not args.batch else 'y'
@ -165,6 +168,10 @@ if not os.path.isdir(args.destination):
os.mkdir(args.destination)
library = openmc.data.DataLibrary()
if args.latest_hdf5:
libver = 'latest'
else:
libver = 'earliest'
for name, filenames in sorted(tables.items()):
# Convert first temperature for the table
@ -179,7 +186,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=libver)
# Register with library
library.register_file(h5_file)
@ -222,7 +229,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=libver)
# Register with library
library.register_file(h5_file)

View file

@ -33,6 +33,9 @@ parser = argparse.ArgumentParser(
)
parser.add_argument('-b', '--batch', action='store_true',
help='supresses standard in')
parser.add_argument('--latest_hdf5', help='Use latest HDF5 format for '
'performance over backwards compatibility',
action='store_true')
args = parser.parse_args()
@ -154,7 +157,11 @@ 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)
args_out = [ace2hdf5, '-d', 'nndc_hdf5', '--fission_energy_release', fer_file]
if args.latest_hdf5:
args_out += ['--latest_hdf5']
args_out += ace_files
subprocess.call(args_out)