Improvements in scripts, remove append argument of DataLibrary.export_to_xml

This commit is contained in:
Paul Romano 2017-07-19 16:24:38 -05:00
parent 92d951e080
commit cb0ebe62fb
5 changed files with 29 additions and 22 deletions

View file

@ -63,7 +63,7 @@ class DataLibrary(EqualityMixin):
library = {'path': filename, 'type': filetype, 'materials': materials}
self.libraries.append(library)
def export_to_xml(self, path='cross_sections.xml', append=False):
def export_to_xml(self, path='cross_sections.xml'):
"""Export cross section data library to an XML file.
Parameters
@ -75,17 +75,23 @@ class DataLibrary(EqualityMixin):
Defaults to False.
"""
root = ET.Element('cross_sections')
if append:
root = ET.parse(path).getroot()
else:
root = ET.Element('cross_sections')
# Determine common directory for library paths
common_dir = os.path.dirname(os.path.commonprefix(
[lib['path'] for lib in self.libraries]))
if common_dir == '':
common_dir = '.'
directory = os.path.relpath(common_dir, os.path.dirname(path))
if directory != '.':
dir_element = ET.SubElement(root, "directory")
dir_element.text = directory
for library in self.libraries:
lib_element = ET.SubElement(root, "library")
lib_element.set('materials', ' '.join(library['materials']))
lib_element.set('path', os.path.relpath(library['path'],
os.path.dirname(path)))
lib_element.set('path', os.path.relpath(library['path'], common_dir))
lib_element.set('type', library['type'])
# Clean the indentation to be user-readable

View file

@ -32,11 +32,10 @@ parser = argparse.ArgumentParser(
)
parser.add_argument('-b', '--batch', action='store_true',
help='supresses standard in')
parser.add_argument('-n', '--neutron-only', action='store_false',
parser.add_argument('-n', '--neutron-only', action='store_true',
help='Whether to exclude photon interaction/atomic data')
args = parser.parse_args()
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']
@ -163,5 +162,6 @@ subprocess.call([ace2hdf5, '-d', 'nndc_hdf5', '--fission_energy_release',
# Generate photo interaction library files
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'])
photo_endf = os.path.join(pwd, 'openmc-get-photon-data')
subprocess.call([photo_endf, '-c', 'cross_sections.xml'],
cwd='nndc_hdf5')

View file

@ -40,7 +40,6 @@ files = ['ENDF-B-VII.1-photoat.zip', 'ENDF-B-VII.1-atomic_relax.zip']
if not os.path.exists('photon_hdf5'):
os.mkdir('photon_hdf5')
library = openmc.data.DataLibrary()
for f in files:
# Establish connection to URL
@ -50,7 +49,15 @@ for f in files:
zipfile.ZipFile(BytesIO(r.content)).extractall()
# ==============================================================================
# GENERATE HDF5 LIBRARY
# GENERATE HDF5 DATA LIBRARY
# If previous cross_sections.xml was specified, load it in
if args.cross_sections is not None:
lib_path = args.cross_sections
library = openmc.data.DataLibrary.from_xml(lib_path)
else:
lib_path = os.path.join('photon_hdf5', 'cross_sections.xml')
library = openmc.data.DataLibrary()
for z in range(1, 101):
element = openmc.data.ATOMIC_SYMBOL[z]
@ -66,9 +73,4 @@ for z in range(1, 101):
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)
library.export_to_xml(lib_path)

View file

@ -341,8 +341,8 @@ module constants
SCORE_DELAYED_NU_FISSION = -19, & ! delayed neutron production rate
SCORE_PROMPT_NU_FISSION = -20, & ! prompt neutron production rate
SCORE_INVERSE_VELOCITY = -21, & ! flux-weighted inverse velocity
SCORE_FISS_Q_RECOV = -22, & ! recoverable fission Q-value
SCORE_FISS_Q_PROMPT = -23, & ! prompt fission Q-value
SCORE_FISS_Q_PROMPT = -22, & ! prompt fission Q-value
SCORE_FISS_Q_RECOV = -23, & ! recoverable fission Q-value
SCORE_DECAY_RATE = -24 ! delayed neutron precursor decay rate
! Maximum scattering order supported

View file

@ -63,7 +63,6 @@ module tally_filter
!===============================================================================
type, extends(TallyFilter) :: ParticleFilter
integer, allocatable :: particles(:)
type(DictIntInt) :: map
contains
procedure :: get_next_bin => get_next_bin_particle
procedure :: to_statepoint => to_statepoint_particle