mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 06:05:58 -04:00
Move scripts in data/ folder to scripts/
This commit is contained in:
parent
aafc89d475
commit
f1ea8cfaaa
7 changed files with 14 additions and 57 deletions
88
scripts/openmc-convert-mcnp70-data
Executable file
88
scripts/openmc-convert-mcnp70-data
Executable file
|
|
@ -0,0 +1,88 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import print_function
|
||||
from argparse import ArgumentParser
|
||||
from collections import defaultdict
|
||||
import glob
|
||||
import os
|
||||
|
||||
import openmc.data
|
||||
|
||||
|
||||
# Get path to MCNP data
|
||||
parser = ArgumentParser()
|
||||
parser.add_argument('-d', '--destination', default='mcnp_endfb70',
|
||||
help='Directory to create new library in')
|
||||
parser.add_argument('mcnpdata', help='Directory containing endf70[a-k] and endf70sab')
|
||||
args = parser.parse_args()
|
||||
assert os.path.isdir(args.mcnpdata)
|
||||
|
||||
# Get a list of all neutron ACE files
|
||||
endf70 = glob.glob(os.path.join(args.mcnpdata, 'endf70[a-k]'))
|
||||
|
||||
# Create output directory if it doesn't exist
|
||||
if not os.path.isdir(args.destination):
|
||||
os.mkdir(args.destination)
|
||||
|
||||
library = openmc.data.DataLibrary()
|
||||
|
||||
for path in sorted(endf70):
|
||||
print('Loading data from {}...'.format(path))
|
||||
lib = openmc.data.ace.Library(path)
|
||||
|
||||
# Group together tables for the same nuclide
|
||||
tables = defaultdict(list)
|
||||
for table in lib.tables:
|
||||
zaid, xs = table.name.split('.')
|
||||
tables[zaid].append(table)
|
||||
|
||||
for zaid, tables in sorted(tables.items()):
|
||||
# Convert first temperature for the table
|
||||
print('Converting: ' + tables[0].name)
|
||||
data = openmc.data.IncidentNeutron.from_ace(tables[0], 'mcnp')
|
||||
|
||||
# For each higher temperature, add cross sections to the existing table
|
||||
for table in tables[1:]:
|
||||
print('Adding: ' + table.name)
|
||||
data.add_temperature_from_ace(table, 'mcnp')
|
||||
|
||||
# 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')
|
||||
|
||||
# Register with library
|
||||
library.register_file(h5_file)
|
||||
|
||||
# Handle S(a,b) tables
|
||||
endf70sab = os.path.join(args.mcnpdata, 'endf70sab')
|
||||
if os.path.exists(endf70sab):
|
||||
lib = openmc.data.ace.Library(endf70sab)
|
||||
|
||||
# Group together tables for the same nuclide
|
||||
tables = defaultdict(list)
|
||||
for table in lib.tables:
|
||||
name, xs = table.name.split('.')
|
||||
tables[name].append(table)
|
||||
|
||||
for zaid, tables in sorted(tables.items()):
|
||||
# Convert first temperature for the table
|
||||
print('Converting: ' + tables[0].name)
|
||||
data = openmc.data.ThermalScattering.from_ace(tables[0])
|
||||
|
||||
# For each higher temperature, add cross sections to the existing table
|
||||
for table in tables[1:]:
|
||||
print('Adding: ' + table.name)
|
||||
data.add_temperature_from_ace(table)
|
||||
|
||||
# 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')
|
||||
|
||||
# Register with library
|
||||
library.register_file(h5_file)
|
||||
|
||||
# Write cross_sections.xml
|
||||
libpath = os.path.join(args.destination, 'cross_sections.xml')
|
||||
library.export_to_xml(libpath)
|
||||
77
scripts/openmc-convert-mcnp71-data
Executable file
77
scripts/openmc-convert-mcnp71-data
Executable file
|
|
@ -0,0 +1,77 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import print_function
|
||||
from argparse import ArgumentParser
|
||||
from collections import defaultdict
|
||||
import glob
|
||||
import os
|
||||
|
||||
import openmc.data
|
||||
|
||||
|
||||
# Get path to MCNP data
|
||||
parser = ArgumentParser()
|
||||
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('mcnpdata', help='Directory containing endf71x and ENDF71SaB')
|
||||
args = parser.parse_args()
|
||||
assert os.path.isdir(args.mcnpdata)
|
||||
|
||||
# Get a list of all ACE files
|
||||
endf71x = glob.glob(os.path.join(args.mcnpdata, 'endf71x', '*', '*.71?nc'))
|
||||
endf71sab = glob.glob(os.path.join(args.mcnpdata, 'ENDF71SaB' , '*.2?t'))
|
||||
|
||||
# There's a bug in H-Zr at 1200 K
|
||||
endf71sab.remove(os.path.join(args.mcnpdata, 'ENDF71SaB' , 'h-zr.27t'))
|
||||
|
||||
# Group together tables for the same nuclide
|
||||
suffixes = defaultdict(list)
|
||||
for filename in sorted(endf71x + endf71sab):
|
||||
dirname, basename = os.path.split(filename)
|
||||
zaid, xs = basename.split('.')
|
||||
suffixes[os.path.join(dirname, zaid)].append(xs)
|
||||
|
||||
# Create output directory if it doesn't exist
|
||||
if not os.path.isdir(args.destination):
|
||||
os.mkdir(args.destination)
|
||||
|
||||
library = openmc.data.DataLibrary()
|
||||
|
||||
for basename, xs_list in sorted(suffixes.items()):
|
||||
# Convert first temperature for the table
|
||||
filename = '.'.join((basename, xs_list[0]))
|
||||
print('Converting: ' + filename)
|
||||
if filename.endswith('t'):
|
||||
data = openmc.data.ThermalScattering.from_ace(filename)
|
||||
else:
|
||||
data = openmc.data.IncidentNeutron.from_ace(filename, 'mcnp')
|
||||
|
||||
# Add fission energy release data, if available
|
||||
if args.fission_energy_release is not None:
|
||||
fer = openmc.data.FissionEnergyRelease.from_compact_hdf5(
|
||||
args.fission_energy_release, data)
|
||||
if fer is not None:
|
||||
data.fission_energy = fer
|
||||
|
||||
# For each higher temperature, add cross sections to the existing table
|
||||
for xs in xs_list[1:]:
|
||||
filename = '.'.join((basename, xs))
|
||||
print('Adding: ' + filename)
|
||||
if filename.endswith('t'):
|
||||
data.add_temperature_from_ace(filename)
|
||||
else:
|
||||
data.add_temperature_from_ace(filename, 'mcnp')
|
||||
|
||||
# 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')
|
||||
|
||||
# Register with library
|
||||
library.register_file(h5_file)
|
||||
|
||||
# Write cross_sections.xml
|
||||
libpath = os.path.join(args.destination, 'cross_sections.xml')
|
||||
library.export_to_xml(libpath)
|
||||
226
scripts/openmc-get-jeff-data
Executable file
226
scripts/openmc-get-jeff-data
Executable file
|
|
@ -0,0 +1,226 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import print_function
|
||||
import os
|
||||
from collections import defaultdict
|
||||
import sys
|
||||
import tarfile
|
||||
import zipfile
|
||||
import glob
|
||||
import argparse
|
||||
from string import digits
|
||||
|
||||
import openmc.data
|
||||
|
||||
try:
|
||||
from urllib.request import urlopen
|
||||
except ImportError:
|
||||
from urllib2 import urlopen
|
||||
|
||||
if sys.version_info[0] < 3:
|
||||
askuser = raw_input
|
||||
else:
|
||||
askuser = input
|
||||
|
||||
|
||||
download_warning = """
|
||||
WARNING: This script will download approximately 9 GB of data. Extracting and
|
||||
processing the data may require as much as 40 GB of additional free disk
|
||||
space. Note that if you don't need all 11 temperatures, you can modify the
|
||||
'files' list in the script to download only the data you want.
|
||||
|
||||
Are you sure you want to continue? ([y]/n)
|
||||
"""
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
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')
|
||||
args = parser.parse_args()
|
||||
|
||||
response = askuser(download_warning) if not args.batch else 'y'
|
||||
if response.lower().startswith('n'):
|
||||
sys.exit()
|
||||
|
||||
base_url = 'https://www.oecd-nea.org/dbforms/data/eva/evatapes/jeff_32/Processed/'
|
||||
files = ['JEFF32-ACE-293K.tar.gz',
|
||||
'JEFF32-ACE-400K.tar.gz',
|
||||
'JEFF32-ACE-500K.tar.gz',
|
||||
'JEFF32-ACE-600K.tar.gz',
|
||||
'JEFF32-ACE-700K.tar.gz',
|
||||
'JEFF32-ACE-800K.zip',
|
||||
'JEFF32-ACE-900K.tar.gz',
|
||||
'JEFF32-ACE-1000K.tar.gz',
|
||||
'JEFF32-ACE-1200K.tar.gz',
|
||||
'JEFF32-ACE-1500K.tar.gz',
|
||||
'JEFF32-ACE-1800K.tar.gz',
|
||||
'TSLs.tar.gz']
|
||||
|
||||
block_size = 16384
|
||||
|
||||
# ==============================================================================
|
||||
# DOWNLOAD FILES FROM OECD SITE
|
||||
|
||||
files_complete = []
|
||||
for f in files:
|
||||
# Establish connection to URL
|
||||
url = base_url + f
|
||||
req = urlopen(url)
|
||||
|
||||
# Get file size from header
|
||||
if sys.version_info[0] < 3:
|
||||
file_size = int(req.info().getheaders('Content-Length')[0])
|
||||
else:
|
||||
file_size = req.length
|
||||
downloaded = 0
|
||||
|
||||
# Check if file already downloaded
|
||||
if os.path.exists(f):
|
||||
if os.path.getsize(f) == file_size:
|
||||
print('Skipping {}, already downloaded'.format(f))
|
||||
files_complete.append(f)
|
||||
continue
|
||||
else:
|
||||
overwrite = askuser('Overwrite {}? ([y]/n) '.format(f))
|
||||
if overwrite.lower().startswith('n'):
|
||||
continue
|
||||
|
||||
# Copy file to disk
|
||||
print('Downloading {}... '.format(f), end='')
|
||||
with open(f, 'wb') as fh:
|
||||
while True:
|
||||
chunk = req.read(block_size)
|
||||
if not chunk: break
|
||||
fh.write(chunk)
|
||||
downloaded += len(chunk)
|
||||
status = '{:10} [{:3.2f}%]'.format(downloaded, downloaded * 100. / file_size)
|
||||
print(status + chr(8)*len(status), end='')
|
||||
print('')
|
||||
files_complete.append(f)
|
||||
|
||||
# ==============================================================================
|
||||
# EXTRACT FILES FROM TGZ
|
||||
|
||||
for f in files:
|
||||
if f not in files_complete:
|
||||
continue
|
||||
|
||||
# Extract files
|
||||
if f.endswith('.zip'):
|
||||
with zipfile.ZipFile(f, 'r') as zipf:
|
||||
print('Extracting {}...'.format(f))
|
||||
zipf.extractall('jeff-3.2')
|
||||
|
||||
else:
|
||||
suffix = 'ACEs_293K' if '293' in f else ''
|
||||
with tarfile.open(f, 'r') as tgz:
|
||||
print('Extracting {}...'.format(f))
|
||||
tgz.extractall(os.path.join('jeff-3.2', suffix))
|
||||
|
||||
# Remove thermal scattering tables from 293K data since they are
|
||||
# redundant
|
||||
if '293' in f:
|
||||
for path in glob.glob(os.path.join('jeff-3.2', 'ACEs_293K', '*-293.ACE')):
|
||||
os.remove(path)
|
||||
|
||||
# ==============================================================================
|
||||
# CHANGE ZAID FOR METASTABLES
|
||||
|
||||
metastables = glob.glob(os.path.join('jeff-3.2', '**', '*M.ACE'))
|
||||
for path in metastables:
|
||||
print(' Fixing {} (ensure metastable)...'.format(path))
|
||||
text = open(path, 'r').read()
|
||||
mass_first_digit = int(text[3])
|
||||
if mass_first_digit <= 2:
|
||||
text = text[:3] + str(mass_first_digit + 4) + text[4:]
|
||||
open(path, 'w').write(text)
|
||||
|
||||
# ==============================================================================
|
||||
# GENERATE HDF5 LIBRARY -- NEUTRON FILES
|
||||
|
||||
# Get a list of all ACE files
|
||||
neutron_files = glob.glob(os.path.join('jeff-3.2', '*', '*.ACE'))
|
||||
|
||||
# Group together tables for same nuclide
|
||||
tables = defaultdict(list)
|
||||
for filename in sorted(neutron_files):
|
||||
dirname, basename = os.path.split(filename)
|
||||
name = basename.split('.')[0]
|
||||
tables[name].append(filename)
|
||||
|
||||
# Sort temperatures from lowest to highest
|
||||
for name, filenames in sorted(tables.items()):
|
||||
filenames.sort(key=lambda x: int(
|
||||
x.split(os.path.sep)[1].split('_')[1][:-1]))
|
||||
|
||||
# Create output directory if it doesn't exist
|
||||
if not os.path.isdir(args.destination):
|
||||
os.mkdir(args.destination)
|
||||
|
||||
library = openmc.data.DataLibrary()
|
||||
|
||||
for name, filenames in sorted(tables.items()):
|
||||
# Convert first temperature for the table
|
||||
print('Converting: ' + filenames[0])
|
||||
data = openmc.data.IncidentNeutron.from_ace(filenames[0])
|
||||
|
||||
# For each higher temperature, add cross sections to the existing table
|
||||
for filename in filenames[1:]:
|
||||
print('Adding: ' + filename)
|
||||
data.add_temperature_from_ace(filename)
|
||||
|
||||
# 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')
|
||||
|
||||
# Register with library
|
||||
library.register_file(h5_file)
|
||||
|
||||
# ==============================================================================
|
||||
# GENERATE HDF5 LIBRARY -- S(A,B) FILES
|
||||
|
||||
sab_files = glob.glob(os.path.join('jeff-3.2', 'ANNEX_6_3_STLs', '*', '*.ace'))
|
||||
|
||||
# Group together tables for same nuclide
|
||||
tables = defaultdict(list)
|
||||
for filename in sorted(sab_files):
|
||||
dirname, basename = os.path.split(filename)
|
||||
name = basename.split('-')[0]
|
||||
tables[name].append(filename)
|
||||
|
||||
# Sort temperatures from lowest to highest
|
||||
for name, filenames in sorted(tables.items()):
|
||||
filenames.sort(key=lambda x: int(
|
||||
os.path.split(x)[1].split('-')[1].split('.')[0]))
|
||||
|
||||
for name, filenames in sorted(tables.items()):
|
||||
# Convert first temperature for the table
|
||||
print('Converting: ' + filenames[0])
|
||||
|
||||
# Take numbers out of table name, e.g. lw10.32t -> lw.32t
|
||||
table = openmc.data.ace.get_table(filenames[0])
|
||||
name, xs = table.name.split('.')
|
||||
table.name = '.'.join((name.strip(digits), xs))
|
||||
data = openmc.data.ThermalScattering.from_ace(table)
|
||||
|
||||
# For each higher temperature, add cross sections to the existing table
|
||||
for filename in filenames[1:]:
|
||||
print('Adding: ' + filename)
|
||||
table = openmc.data.ace.get_table(filename)
|
||||
name, xs = table.name.split('.')
|
||||
table.name = '.'.join((name.strip(digits), xs))
|
||||
data.add_temperature_from_ace(table)
|
||||
|
||||
# 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')
|
||||
|
||||
# Register with library
|
||||
library.register_file(h5_file)
|
||||
|
||||
# Write cross_sections.xml
|
||||
libpath = os.path.join(args.destination, 'cross_sections.xml')
|
||||
library.export_to_xml(libpath)
|
||||
125
scripts/openmc-get-multipole-data
Executable file
125
scripts/openmc-get-multipole-data
Executable file
|
|
@ -0,0 +1,125 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import print_function
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tarfile
|
||||
import glob
|
||||
import hashlib
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-b', '--batch', action='store_true',
|
||||
help='supresses standard in')
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
from urllib.request import urlopen
|
||||
except ImportError:
|
||||
from urllib2 import urlopen
|
||||
|
||||
cwd = os.getcwd()
|
||||
sys.path.insert(0, os.path.join(cwd, '..'))
|
||||
|
||||
baseUrl = 'https://github.com/smharper/windowed_multipole_library/blob/master/'
|
||||
files = ['multipole_lib.tar.gz?raw=true']
|
||||
checksums = ['3985aea96f7162a9419c7ed8352e6abb']
|
||||
block_size = 16384
|
||||
|
||||
# ==============================================================================
|
||||
# DOWNLOAD FILES FROM GITHUB REPO
|
||||
|
||||
filesComplete = []
|
||||
for f in files:
|
||||
# Establish connection to URL
|
||||
url = baseUrl + f
|
||||
req = urlopen(url)
|
||||
|
||||
# Get file size from header
|
||||
if sys.version_info[0] < 3:
|
||||
file_size = int(req.info().getheaders('Content-Length')[0])
|
||||
else:
|
||||
file_size = req.length
|
||||
downloaded = 0
|
||||
|
||||
# Remove GitHub junk from the file name.
|
||||
fname = f[:-9] if f.endswith('?raw=true') else f
|
||||
|
||||
# Check if file already downloaded
|
||||
if os.path.exists(fname):
|
||||
if os.path.getsize(fname) == file_size:
|
||||
print('Skipping ' + fname)
|
||||
filesComplete.append(fname)
|
||||
continue
|
||||
else:
|
||||
if sys.version_info[0] < 3:
|
||||
overwrite = raw_input('Overwrite {0}? ([y]/n) '.format(fname))
|
||||
else:
|
||||
overwrite = input('Overwrite {0}? ([y]/n) '.format(fname))
|
||||
if overwrite.lower().startswith('n'):
|
||||
continue
|
||||
|
||||
# Copy file to disk
|
||||
print('Downloading {0}... '.format(f), end='')
|
||||
with open(fname, 'wb') as fh:
|
||||
while True:
|
||||
chunk = req.read(block_size)
|
||||
if not chunk: break
|
||||
fh.write(chunk)
|
||||
downloaded += len(chunk)
|
||||
status = '{0:10} [{1:3.2f}%]'.format(downloaded, downloaded * 100. / file_size)
|
||||
print(status + chr(8)*len(status), end='')
|
||||
print('')
|
||||
filesComplete.append(fname)
|
||||
|
||||
# ==============================================================================
|
||||
# VERIFY MD5 CHECKSUMS
|
||||
|
||||
print('Verifying MD5 checksums...')
|
||||
for f, checksum in zip(files, checksums):
|
||||
fname = f[:-9] if f.endswith('?raw=true') else f
|
||||
downloadsum = hashlib.md5(open(fname, 'rb').read()).hexdigest()
|
||||
if downloadsum != checksum:
|
||||
raise IOError("MD5 checksum for {} does not match. If this is your first "
|
||||
"time receiving this message, please re-run the script. "
|
||||
"Otherwise, please contact OpenMC developers by emailing "
|
||||
"openmc-users@googlegroups.com.".format(f))
|
||||
|
||||
# ==============================================================================
|
||||
# EXTRACT FILES FROM TGZ
|
||||
|
||||
for f in files:
|
||||
fname = f[:-9] if f.endswith('?raw=true') else f
|
||||
if fname not in filesComplete:
|
||||
continue
|
||||
|
||||
# Extract files
|
||||
with tarfile.open(fname, 'r') as tgz:
|
||||
print('Extracting {0}...'.format(fname))
|
||||
tgz.extractall(path='wmp/')
|
||||
|
||||
# Move data files down one level
|
||||
for filename in glob.glob('wmp/multipole_lib/*'):
|
||||
shutil.move(filename, 'wmp/')
|
||||
os.rmdir('wmp/multipole_lib')
|
||||
|
||||
# ==============================================================================
|
||||
# PROMPT USER TO DELETE .TAR.GZ FILES
|
||||
|
||||
# Ask user to delete
|
||||
if not args.batch:
|
||||
if sys.version_info[0] < 3:
|
||||
response = raw_input('Delete *.tar.gz files? ([y]/n) ')
|
||||
else:
|
||||
response = input('Delete *.tar.gz files? ([y]/n) ')
|
||||
else:
|
||||
response = 'y'
|
||||
|
||||
# Delete files if requested
|
||||
if not response or response.lower().startswith('y'):
|
||||
for f in files:
|
||||
if os.path.exists(f):
|
||||
print('Removing {0}...'.format(f))
|
||||
os.remove(f)
|
||||
156
scripts/openmc-get-nndc-data
Executable file
156
scripts/openmc-get-nndc-data
Executable file
|
|
@ -0,0 +1,156 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import print_function
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tarfile
|
||||
import glob
|
||||
import hashlib
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-b', '--batch', action='store_true',
|
||||
help='supresses standard in')
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
from urllib.request import urlopen
|
||||
except ImportError:
|
||||
from urllib2 import urlopen
|
||||
|
||||
baseUrl = 'http://www.nndc.bnl.gov/endf/b7.1/aceFiles/'
|
||||
files = ['ENDF-B-VII.1-neutron-293.6K.tar.gz',
|
||||
'ENDF-B-VII.1-tsl.tar.gz']
|
||||
checksums = ['9729a17eb62b75f285d8a7628ace1449',
|
||||
'e17d827c92940a30f22f096d910ea186']
|
||||
block_size = 16384
|
||||
|
||||
# ==============================================================================
|
||||
# DOWNLOAD FILES FROM NNDC SITE
|
||||
|
||||
filesComplete = []
|
||||
for f in files:
|
||||
# Establish connection to URL
|
||||
url = baseUrl + f
|
||||
req = urlopen(url)
|
||||
|
||||
# Get file size from header
|
||||
if sys.version_info[0] < 3:
|
||||
file_size = int(req.info().getheaders('Content-Length')[0])
|
||||
else:
|
||||
file_size = req.length
|
||||
downloaded = 0
|
||||
|
||||
# Check if file already downloaded
|
||||
if os.path.exists(f):
|
||||
if os.path.getsize(f) == file_size:
|
||||
print('Skipping ' + f)
|
||||
filesComplete.append(f)
|
||||
continue
|
||||
else:
|
||||
if sys.version_info[0] < 3:
|
||||
overwrite = raw_input('Overwrite {0}? ([y]/n) '.format(f))
|
||||
else:
|
||||
overwrite = input('Overwrite {0}? ([y]/n) '.format(f))
|
||||
if overwrite.lower().startswith('n'):
|
||||
continue
|
||||
|
||||
# Copy file to disk
|
||||
print('Downloading {0}... '.format(f), end='')
|
||||
with open(f, 'wb') as fh:
|
||||
while True:
|
||||
chunk = req.read(block_size)
|
||||
if not chunk: break
|
||||
fh.write(chunk)
|
||||
downloaded += len(chunk)
|
||||
status = '{0:10} [{1:3.2f}%]'.format(downloaded, downloaded * 100. / file_size)
|
||||
print(status + chr(8)*len(status), end='')
|
||||
print('')
|
||||
filesComplete.append(f)
|
||||
|
||||
# ==============================================================================
|
||||
# VERIFY MD5 CHECKSUMS
|
||||
|
||||
print('Verifying MD5 checksums...')
|
||||
for f, checksum in zip(files, checksums):
|
||||
downloadsum = hashlib.md5(open(f, 'rb').read()).hexdigest()
|
||||
if downloadsum != checksum:
|
||||
raise IOError("MD5 checksum for {} does not match. If this is your first "
|
||||
"time receiving this message, please re-run the script. "
|
||||
"Otherwise, please contact OpenMC developers by emailing "
|
||||
"openmc-users@googlegroups.com.".format(f))
|
||||
|
||||
# ==============================================================================
|
||||
# EXTRACT FILES FROM TGZ
|
||||
|
||||
for f in files:
|
||||
if f not in filesComplete:
|
||||
continue
|
||||
|
||||
# Extract files
|
||||
suffix = f[f.rindex('-') + 1:].rstrip('.tar.gz')
|
||||
with tarfile.open(f, 'r') as tgz:
|
||||
print('Extracting {0}...'.format(f))
|
||||
tgz.extractall(path='nndc/' + suffix)
|
||||
|
||||
# Move ACE files down one level
|
||||
for filename in glob.glob('nndc/293.6K/ENDF-B-VII.1-neutron-293.6K/*'):
|
||||
shutil.move(filename, 'nndc/293.6K/')
|
||||
|
||||
#===============================================================================
|
||||
# EDIT GRAPHITE ZAID (6012 to 6000)
|
||||
|
||||
print('Changing graphite ZAID from 6012 to 6000')
|
||||
graphite = os.path.join('nndc', 'tsl', 'graphite.acer')
|
||||
with open(graphite) as fh:
|
||||
text = fh.read()
|
||||
text = text.replace('6012', '6000', 1)
|
||||
with open(graphite, 'w') as fh:
|
||||
fh.write(text)
|
||||
|
||||
# ==============================================================================
|
||||
# PROMPT USER TO DELETE .TAR.GZ FILES
|
||||
|
||||
# Ask user to delete
|
||||
if not args.batch:
|
||||
if sys.version_info[0] < 3:
|
||||
response = raw_input('Delete *.tar.gz files? ([y]/n) ')
|
||||
else:
|
||||
response = input('Delete *.tar.gz files? ([y]/n) ')
|
||||
else:
|
||||
response = 'y'
|
||||
|
||||
# Delete files if requested
|
||||
if not response or response.lower().startswith('y'):
|
||||
for f in files:
|
||||
if os.path.exists(f):
|
||||
print('Removing {0}...'.format(f))
|
||||
os.remove(f)
|
||||
|
||||
# ==============================================================================
|
||||
# PROMPT USER TO GENERATE HDF5 LIBRARY
|
||||
|
||||
# Ask user to convert
|
||||
if not args.batch:
|
||||
if sys.version_info[0] < 3:
|
||||
response = raw_input('Generate HDF5 library? ([y]/n) ')
|
||||
else:
|
||||
response = input('Generate HDF5 library? ([y]/n) ')
|
||||
else:
|
||||
response = 'y'
|
||||
|
||||
# Convert files if requested
|
||||
if not response or response.lower().startswith('y'):
|
||||
# get a list of all ACE files
|
||||
ace_files = sorted(glob.glob(os.path.join('nndc', '**', '*.ace*')))
|
||||
|
||||
# Ensure 'import openmc.data' works in the openmc-ace-to-xml script
|
||||
cwd = os.getcwd()
|
||||
env = os.environ.copy()
|
||||
env['PYTHONPATH'] = os.path.join(cwd, '..')
|
||||
|
||||
subprocess.call(['../scripts/openmc-ace-to-hdf5', '-d', 'nndc_hdf5',
|
||||
'--fission_energy_release', 'fission_Q_data_endfb71.h5']
|
||||
+ ace_files, env=env)
|
||||
Loading…
Add table
Add a link
Reference in a new issue