mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 06:05:58 -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
74
scripts/openmc-get-photon-data
Executable file
74
scripts/openmc-get-photon-data
Executable file
|
|
@ -0,0 +1,74 @@
|
|||
#!/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 argparse
|
||||
from io import BytesIO
|
||||
|
||||
import requests
|
||||
|
||||
import openmc.data
|
||||
|
||||
|
||||
class CustomFormatter(argparse.ArgumentDefaultsHelpFormatter,
|
||||
argparse.RawDescriptionHelpFormatter):
|
||||
pass
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description=__doc__,
|
||||
formatter_class=CustomFormatter
|
||||
)
|
||||
parser.add_argument('-c', '--cross-sections',
|
||||
help='cross_sections.xml file to append libraries to')
|
||||
args = parser.parse_args()
|
||||
|
||||
base_url = 'http://www.nndc.bnl.gov/endf/b7.1/zips/'
|
||||
files = ['ENDF-B-VII.1-photoat.zip', 'ENDF-B-VII.1-atomic_relax.zip']
|
||||
|
||||
# ==============================================================================
|
||||
# DOWNLOAD FILES FROM NNDC SITE
|
||||
|
||||
if not os.path.exists('photon_hdf5'):
|
||||
os.mkdir('photon_hdf5')
|
||||
|
||||
library = openmc.data.DataLibrary()
|
||||
|
||||
for f in files:
|
||||
# Establish connection to URL
|
||||
print('Downloading {}...'.format(f))
|
||||
url = base_url + f
|
||||
r = requests.get(url, stream=True)
|
||||
zipfile.ZipFile(BytesIO(r.content)).extractall()
|
||||
|
||||
# ==============================================================================
|
||||
# GENERATE HDF5 LIBRARY
|
||||
|
||||
for z in range(1, 101):
|
||||
element = openmc.data.ATOMIC_SYMBOL[z]
|
||||
print('Generating HDF5 file for Z={} ({})...'.format(z, element))
|
||||
|
||||
# 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)
|
||||
|
||||
# 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 = os.path.join('photon_hdf5', 'cross_sections.xml')
|
||||
library.export_to_xml(path)
|
||||
Loading…
Add table
Add a link
Reference in a new issue