mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-25 20:45:35 -04:00
Some changes in data scripts
This commit is contained in:
parent
cd185bb33d
commit
92d951e080
2 changed files with 42 additions and 55 deletions
|
|
@ -1,5 +1,11 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Download ENDF/B-VII.1 incident neutron ACE data and incident photon ENDF data
|
||||
from NNDC and convert it to an HDF5 library for use with OpenMC. This data is
|
||||
used for OpenMC's regression test suite.
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
import os
|
||||
import shutil
|
||||
|
|
@ -16,29 +22,22 @@ 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. This data is used for OpenMC's regression test suite.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
class CustomFormatter(argparse.ArgumentDefaultsHelpFormatter,
|
||||
argparse.RawDescriptionHelpFormatter):
|
||||
pass
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description=description,
|
||||
description=__doc__,
|
||||
formatter_class=CustomFormatter
|
||||
)
|
||||
parser.add_argument('-b', '--batch', action='store_true',
|
||||
help='supresses standard in')
|
||||
parser.add_argument('-p', '--photo', default='generate_true',
|
||||
help='Whether to include photo-atomic interaction data')
|
||||
parser.add_argument('-n', '--neutron-only', action='store_false',
|
||||
help='Whether to exclude photon interaction/atomic data')
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
baseUrl = 'http://www.nndc.bnl.gov/endf/b7.1/aceFiles/'
|
||||
base_url = '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',
|
||||
|
|
@ -48,10 +47,10 @@ block_size = 16384
|
|||
# ==============================================================================
|
||||
# DOWNLOAD FILES FROM NNDC SITE
|
||||
|
||||
filesComplete = []
|
||||
files_complete = []
|
||||
for f in files:
|
||||
# Establish connection to URL
|
||||
url = baseUrl + f
|
||||
url = base_url + f
|
||||
req = urlopen(url)
|
||||
|
||||
# Get file size from header
|
||||
|
|
@ -65,15 +64,15 @@ for f in files:
|
|||
if os.path.exists(f):
|
||||
if os.path.getsize(f) == file_size:
|
||||
print('Skipping ' + f)
|
||||
filesComplete.append(f)
|
||||
files_complete.append(f)
|
||||
continue
|
||||
else:
|
||||
overwrite = input('Overwrite {0}? ([y]/n) '.format(f))
|
||||
overwrite = input('Overwrite {}? ([y]/n) '.format(f))
|
||||
if overwrite.lower().startswith('n'):
|
||||
continue
|
||||
|
||||
# Copy file to disk
|
||||
print('Downloading {0}... '.format(f), end='')
|
||||
print('Downloading {}... '.format(f), end='')
|
||||
with open(f, 'wb') as fh:
|
||||
while True:
|
||||
chunk = req.read(block_size)
|
||||
|
|
@ -84,7 +83,7 @@ for f in files:
|
|||
downloaded, downloaded * 100. / file_size)
|
||||
print(status + chr(8)*len(status), end='')
|
||||
print('')
|
||||
filesComplete.append(f)
|
||||
files_complete.append(f)
|
||||
|
||||
# ==============================================================================
|
||||
# VERIFY MD5 CHECKSUMS
|
||||
|
|
@ -102,13 +101,13 @@ for f, checksum in zip(files, checksums):
|
|||
# EXTRACT FILES FROM TGZ
|
||||
|
||||
for f in files:
|
||||
if f not in filesComplete:
|
||||
if f not in files_complete:
|
||||
continue
|
||||
|
||||
# Extract files
|
||||
suffix = f[f.rindex('-') + 1:].rstrip('.tar.gz')
|
||||
with tarfile.open(f, 'r') as tgz:
|
||||
print('Extracting {0}...'.format(f))
|
||||
print('Extracting {}...'.format(f))
|
||||
tgz.extractall(path='nndc/' + suffix)
|
||||
|
||||
# Move ACE files down one level
|
||||
|
|
@ -143,7 +142,7 @@ else:
|
|||
if not response or response.lower().startswith('y'):
|
||||
for f in files:
|
||||
if os.path.exists(f):
|
||||
print('Removing {0}...'.format(f))
|
||||
print('Removing {}...'.format(f))
|
||||
os.remove(f)
|
||||
|
||||
# ==============================================================================
|
||||
|
|
@ -162,8 +161,7 @@ subprocess.call([ace2hdf5, '-d', 'nndc_hdf5', '--fission_energy_release',
|
|||
fer_file] + ace_files)
|
||||
|
||||
# Generate photo interaction library files
|
||||
if args.photo == 'generate_true':
|
||||
if not args.neutron_only:
|
||||
pwd = os.path.dirname(os.path.realpath(__file__))
|
||||
photo_endf = os.path.join(pwd, 'openmc-get-photo-endf71')
|
||||
subprocess.call([photo_endf, '-c', 'nndc_hdf5/cross_sections.xml'])
|
||||
|
||||
|
|
|
|||
|
|
@ -1,34 +1,33 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Download ENDF/B-VII.1 ENDF data from NNDC for photo-atomic and atomic
|
||||
relaxation data and convert it to an HDF5 library for use with OpenMC.
|
||||
This data is used for photon transport in OpenMC.
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
import zipfile
|
||||
import requests
|
||||
import argparse
|
||||
|
||||
from io import BytesIO
|
||||
|
||||
import requests
|
||||
|
||||
import openmc.data
|
||||
from openmc.data import ATOMIC_SYMBOL
|
||||
|
||||
description = """
|
||||
Download ENDF/B-VII.1 ENDF data from NNDC for photo-atomic and atomic
|
||||
relaxation data and convert it to an HDF5 library for use with OpenMC.
|
||||
This data is used for photon transport in OpenMC.
|
||||
|
||||
"""
|
||||
|
||||
class CustomFormatter(argparse.ArgumentDefaultsHelpFormatter,
|
||||
argparse.RawDescriptionHelpFormatter):
|
||||
pass
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description=description,
|
||||
description=__doc__,
|
||||
formatter_class=CustomFormatter
|
||||
)
|
||||
parser.add_argument('-c', '--cross-sections-file',
|
||||
parser.add_argument('-c', '--cross-sections',
|
||||
help='cross_sections.xml file to append libraries to')
|
||||
args = parser.parse_args()
|
||||
|
||||
|
|
@ -38,14 +37,12 @@ files = ['ENDF-B-VII.1-photoat.zip', 'ENDF-B-VII.1-atomic_relax.zip']
|
|||
# ==============================================================================
|
||||
# DOWNLOAD FILES FROM NNDC SITE
|
||||
|
||||
if not os.path.exists('photo_hdf5'):
|
||||
os.mkdir('photo_hdf5')
|
||||
if not os.path.exists('photon_hdf5'):
|
||||
os.mkdir('photon_hdf5')
|
||||
|
||||
library = openmc.data.DataLibrary()
|
||||
|
||||
filesComplete = []
|
||||
for f in files:
|
||||
|
||||
# Establish connection to URL
|
||||
print('Downloading {}...'.format(f))
|
||||
url = base_url + f
|
||||
|
|
@ -56,30 +53,22 @@ for f in files:
|
|||
# GENERATE HDF5 LIBRARY
|
||||
|
||||
for z in range(1, 101):
|
||||
element = openmc.data.ATOMIC_SYMBOL[z]
|
||||
print('Generating HDF5 file for Z={} ({})...'.format(z, element))
|
||||
|
||||
element = ATOMIC_SYMBOL[z]
|
||||
print('Extracting {} interaction data...'.format(element))
|
||||
|
||||
# Load files
|
||||
filename = 'photoat/photoat-{:03}_{}_000.endf'.format(z, element)
|
||||
photo_file = 'photoat/' + element + '.endf'
|
||||
shutil.move(filename, photo_file)
|
||||
|
||||
filename = 'atomic_relax/atom-{:03}_{}_000.endf'.format(z, element)
|
||||
atom_file = 'atomic_relax/' + element + '.endf'
|
||||
shutil.move(filename, atom_file)
|
||||
|
||||
hdf5_file = 'photo_hdf5/' + element + '.h5'
|
||||
if os.path.isfile(hdf5_file):
|
||||
os.remove(hdf5_file)
|
||||
|
||||
# Generate instance of IncidentPhoton
|
||||
photo_file = os.path.join('photoat', 'photoat-{:03}_{}_000.endf'.format(z, element))
|
||||
atom_file = os.path.join('atomic_relax', 'atom-{:03}_{}_000.endf'.format(z, element))
|
||||
f = openmc.data.IncidentPhoton.from_endf(photo_file, atom_file)
|
||||
f.export_to_hdf5(hdf5_file)
|
||||
|
||||
# Write HDF5 file and register it
|
||||
hdf5_file = os.path.join('photon_hdf5', element + '.h5')
|
||||
f.export_to_hdf5(hdf5_file, 'w')
|
||||
library.register_file(hdf5_file)
|
||||
|
||||
if args.cross_sections_file is not None:
|
||||
path = args.cross_sections_file
|
||||
library.export_to_xml(path, True)
|
||||
else:
|
||||
path = 'photo_hdf5/cross_sections.xml'
|
||||
path = os.path.join('photon_hdf5', 'cross_sections.xml')
|
||||
library.export_to_xml(path)
|
||||
Loading…
Add table
Add a link
Reference in a new issue