mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 14:15:42 -04:00
Merge remote-tracking branch 'upstream/develop' into mg-mode-delayed
This commit is contained in:
commit
b3b81cef4c
49 changed files with 359 additions and 404 deletions
|
|
@ -108,7 +108,7 @@ elif args.xsdata is not None:
|
|||
for line in xsdata:
|
||||
words = line.split()
|
||||
if len(words) >= 9:
|
||||
path = os.path.join(os.path.dirname(args.xsdata, words[8]))
|
||||
path = os.path.join(os.path.dirname(args.xsdata), words[8])
|
||||
if path not in ace_libraries:
|
||||
ace_libraries.append(path)
|
||||
|
||||
|
|
|
|||
101
scripts/openmc-convert-mcnp70-data
Executable file
101
scripts/openmc-convert-mcnp70-data
Executable file
|
|
@ -0,0 +1,101 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import print_function
|
||||
import argparse
|
||||
from collections import defaultdict
|
||||
import glob
|
||||
import os
|
||||
|
||||
import openmc.data
|
||||
|
||||
|
||||
description = """
|
||||
Convert ENDF/B-VII.0 ACE data from the MCNP5/6 distribution into an HDF5 library
|
||||
that can be used by OpenMC. This assumes that you have a directory containing
|
||||
files named endf70a, endf70b, ..., endf70k, and endf70sab.
|
||||
|
||||
"""
|
||||
|
||||
class CustomFormatter(argparse.ArgumentDefaultsHelpFormatter,
|
||||
argparse.RawDescriptionHelpFormatter):
|
||||
pass
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description=description,
|
||||
formatter_class=CustomFormatter
|
||||
)
|
||||
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)
|
||||
90
scripts/openmc-convert-mcnp71-data
Executable file
90
scripts/openmc-convert-mcnp71-data
Executable file
|
|
@ -0,0 +1,90 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import print_function
|
||||
import argparse
|
||||
from collections import defaultdict
|
||||
import glob
|
||||
import os
|
||||
|
||||
import openmc.data
|
||||
|
||||
|
||||
description = """
|
||||
Convert ENDF/B-VII.1 ACE data from the MCNP6 distribution into an HDF5 library
|
||||
that can be used by OpenMC. This assumes that you have a directory containing
|
||||
subdirectories 'endf71x' and 'ENDF71SaB'.
|
||||
|
||||
"""
|
||||
|
||||
class CustomFormatter(argparse.ArgumentDefaultsHelpFormatter,
|
||||
argparse.RawDescriptionHelpFormatter):
|
||||
pass
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description=description,
|
||||
formatter_class=CustomFormatter
|
||||
)
|
||||
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)
|
||||
232
scripts/openmc-get-jeff-data
Executable file
232
scripts/openmc-get-jeff-data
Executable file
|
|
@ -0,0 +1,232 @@
|
|||
#!/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
|
||||
|
||||
from six.moves import input
|
||||
from six.moves.urllib.request import urlopen
|
||||
|
||||
import openmc.data
|
||||
|
||||
|
||||
description = """
|
||||
Download JEFF 3.2 ACE data from OECD/NEA and convert it to a multi-temperature
|
||||
HDF5 library for use with OpenMC.
|
||||
|
||||
"""
|
||||
|
||||
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)
|
||||
"""
|
||||
|
||||
class CustomFormatter(argparse.ArgumentDefaultsHelpFormatter,
|
||||
argparse.RawDescriptionHelpFormatter):
|
||||
pass
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description=description,
|
||||
formatter_class=CustomFormatter
|
||||
)
|
||||
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 = input(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 = input('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)
|
||||
128
scripts/openmc-get-multipole-data
Executable file
128
scripts/openmc-get-multipole-data
Executable file
|
|
@ -0,0 +1,128 @@
|
|||
#!/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
|
||||
|
||||
from six.moves import input
|
||||
from six.moves.urllib.request import urlopen
|
||||
|
||||
|
||||
description = """
|
||||
Download and extract windowed multipole data based on ENDF/B-VII.1.
|
||||
|
||||
"""
|
||||
|
||||
class CustomFormatter(argparse.ArgumentDefaultsHelpFormatter,
|
||||
argparse.RawDescriptionHelpFormatter):
|
||||
pass
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description=description,
|
||||
formatter_class=CustomFormatter
|
||||
)
|
||||
parser.add_argument('-b', '--batch', action='store_true',
|
||||
help='supresses standard in')
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
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:
|
||||
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:
|
||||
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
|
||||
|
||||
from six.moves import input
|
||||
from six.moves.urllib.request import urlopen
|
||||
|
||||
import openmc.data
|
||||
|
||||
|
||||
description = """
|
||||
Download ENDF/B-VII.1 ACE data from NNDC and convert it to an HDF5 library for
|
||||
use with OpenMC.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
class CustomFormatter(argparse.ArgumentDefaultsHelpFormatter,
|
||||
argparse.RawDescriptionHelpFormatter):
|
||||
pass
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description=description,
|
||||
formatter_class=CustomFormatter
|
||||
)
|
||||
parser.add_argument('-b', '--batch', action='store_true',
|
||||
help='supresses standard in')
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
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:
|
||||
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:
|
||||
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)
|
||||
|
||||
# ==============================================================================
|
||||
# GENERATE HDF5 LIBRARY
|
||||
|
||||
# get a list of all ACE files
|
||||
ace_files = sorted(glob.glob(os.path.join('nndc', '**', '*.ace*')))
|
||||
|
||||
# Get path to fission energy release data
|
||||
data_dir = os.path.dirname(sys.modules['openmc.data'].__file__)
|
||||
fer_file = os.path.join(data_dir, 'fission_Q_data_endfb71.h5')
|
||||
|
||||
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)
|
||||
|
|
@ -5,6 +5,11 @@
|
|||
import os
|
||||
import sys
|
||||
|
||||
import six.moves.tkinter as tk
|
||||
import six.moves.tkinter_filedialog as filedialog
|
||||
import six.moves.tkinter_font as font
|
||||
import six.moves.tkinter_messagebox as messagebox
|
||||
import six.moves.tkinter_ttk as ttk
|
||||
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
|
||||
from matplotlib.backends.backend_tkagg import NavigationToolbar2TkAgg
|
||||
from matplotlib.figure import Figure
|
||||
|
|
@ -13,19 +18,6 @@ import numpy as np
|
|||
|
||||
from openmc.statepoint import StatePoint
|
||||
|
||||
if sys.version_info[0] < 3:
|
||||
import Tkinter as tk
|
||||
import tkFileDialog as filedialog
|
||||
import tkFont as font
|
||||
import tkMessageBox as messagebox
|
||||
import ttk as ttk
|
||||
else:
|
||||
import tkinter as tk
|
||||
import tkinter.filedialog as filedialog
|
||||
import tkinter.font as font
|
||||
import tkinter.messagebox as messagebox
|
||||
import tkinter.ttk as ttk
|
||||
|
||||
|
||||
class MeshPlotter(tk.Frame):
|
||||
def __init__(self, parent, filename):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue