From cb0ebe62fbaf3193be4768e923aef58c85066331 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Wed, 19 Jul 2017 16:24:38 -0500 Subject: [PATCH] Improvements in scripts, remove append argument of DataLibrary.export_to_xml --- openmc/data/library.py | 20 +++++++++++++------- scripts/openmc-get-nndc-data | 8 ++++---- scripts/openmc-get-photon-data | 18 ++++++++++-------- src/constants.F90 | 4 ++-- src/tally_filter.F90 | 1 - 5 files changed, 29 insertions(+), 22 deletions(-) diff --git a/openmc/data/library.py b/openmc/data/library.py index baf8f6ae0..123a0aa84 100644 --- a/openmc/data/library.py +++ b/openmc/data/library.py @@ -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 diff --git a/scripts/openmc-get-nndc-data b/scripts/openmc-get-nndc-data index e1cf926e5..8c39f6d05 100755 --- a/scripts/openmc-get-nndc-data +++ b/scripts/openmc-get-nndc-data @@ -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') diff --git a/scripts/openmc-get-photon-data b/scripts/openmc-get-photon-data index 0d9a2d264..b7025db74 100755 --- a/scripts/openmc-get-photon-data +++ b/scripts/openmc-get-photon-data @@ -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) diff --git a/src/constants.F90 b/src/constants.F90 index 16d266a5a..cdc3be5c5 100644 --- a/src/constants.F90 +++ b/src/constants.F90 @@ -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 diff --git a/src/tally_filter.F90 b/src/tally_filter.F90 index a010a61d5..dc8136b44 100644 --- a/src/tally_filter.F90 +++ b/src/tally_filter.F90 @@ -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