From 5da591d36a442a45b6d2c5f5ddf6931bbaa3f037 Mon Sep 17 00:00:00 2001 From: samuelshaner Date: Mon, 3 Jul 2017 17:01:46 -0400 Subject: [PATCH] created script for adding photo data to cross_sections.xml and turned on photon transport --- openmc/data/library.py | 23 ++++---- scripts/openmc-get-nndc-data | 9 ++++ scripts/openmc-get-photo-endf71 | 93 +++++++++++++++++++++++++++++++++ src/global.F90 | 2 +- src/photon_physics.F90 | 2 +- src/physics.F90 | 2 +- src/tracking.F90 | 4 +- 7 files changed, 117 insertions(+), 18 deletions(-) create mode 100755 scripts/openmc-get-photo-endf71 diff --git a/openmc/data/library.py b/openmc/data/library.py index 2f33743a6e..5522bdc632 100644 --- a/openmc/data/library.py +++ b/openmc/data/library.py @@ -63,32 +63,29 @@ class DataLibrary(EqualityMixin): library = {'path': filename, 'type': filetype, 'materials': materials} self.libraries.append(library) - def export_to_xml(self, path='cross_sections.xml'): + def export_to_xml(self, path='cross_sections.xml', append=False): """Export cross section data library to an XML file. Parameters ---------- path : str Path to file to write. Defaults to 'cross_sections.xml'. + append : bool + Whether to append to an existing file, it if exists. + Defaults to False. """ - 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 + if append: + root = ET.parse(path).getroot() + else: + root = ET.Element('cross_sections') 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'], common_dir)) + lib_element.set('path', os.path.relpath(library['path'], + os.path.dirname(path))) 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 f1da2241ab..43fa213a0b 100755 --- a/scripts/openmc-get-nndc-data +++ b/scripts/openmc-get-nndc-data @@ -33,6 +33,8 @@ parser = argparse.ArgumentParser( ) 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') args = parser.parse_args() @@ -158,3 +160,10 @@ 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) + +# Generate photo interaction library files +if args.photo == 'generate_true': + 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']) + diff --git a/scripts/openmc-get-photo-endf71 b/scripts/openmc-get-photo-endf71 new file mode 100755 index 0000000000..b2ee3bba2a --- /dev/null +++ b/scripts/openmc-get-photo-endf71 @@ -0,0 +1,93 @@ +#!/usr/bin/env python + +from __future__ import print_function +import os +import shutil +import zipfile +import requests +import argparse + +from io import BytesIO + +import openmc.data +from openmc.data import ATOMIC_SYMBOL + +description = """ +Download ENDF/B-VII.1 ENDF data from IAEA 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, + formatter_class=CustomFormatter +) +parser.add_argument('-c', '--cross-sections-file', + help='cross_sections.xml file to append libraries to') +args = parser.parse_args() + +base_url = 'http://www-nds.iaea.org/public/download-endf/ENDF-B-VII.1/' + +# ============================================================================== +# DOWNLOAD FILES FROM IAEA SITE AND GENERATE HDF5 LIBRARY + +# Make photo and ard directories +if not os.path.exists('photo'): + os.mkdir('photo') + +if not os.path.exists('photo_hdf5'): + os.mkdir('photo_hdf5') + +if not os.path.exists('ard'): + os.mkdir('ard') + +library = openmc.data.DataLibrary() + +for z in range(1,101): + + element = ATOMIC_SYMBOL[z] + print('Extracting {} interaction data...'.format(element)) + + # Download photo files + if z < 100: + filename = 'photo/photo_{:02}00_{}-{}-0'.format(z, z, element) + else: + filename = 'photo/photo_{}20_{}-{}-0'.format(z-1, z, element) + + url = base_url + filename + '.zip' + r = requests.get(url, stream=True) + zipfile.ZipFile(BytesIO(r.content)).extractall(path='photo') + photo_file = 'photo/' + element + '.dat' + shutil.move(filename + '.dat', photo_file) + + # Download ard files + if z < 100: + filename = 'ard/ard_{:02}00_{}-{}-0'.format(z, z, element) + else: + filename = 'ard/ard_{}20_{}-{}-0'.format(z-1, z, element) + + url = base_url + filename + '.zip' + r = requests.get(url, stream=True) + zipfile.ZipFile(BytesIO(r.content)).extractall(path='ard') + ard_file = 'ard/' + element + '.dat' + shutil.move(filename + '.dat', ard_file) + + hdf5_file = 'photo_hdf5/' + element + '.h5' + if os.path.isfile(hdf5_file): + os.remove(hdf5_file) + + f = openmc.data.IncidentPhoton.from_endf(photo_file, ard_file) + f.export_to_hdf5(hdf5_file) + 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' + library.export_to_xml(path) diff --git a/src/global.F90 b/src/global.F90 index d9da251bad..6d7b936485 100644 --- a/src/global.F90 +++ b/src/global.F90 @@ -120,7 +120,7 @@ module global integer :: n_log_bins ! number of bins for logarithmic grid real(8) :: log_spacing ! spacing on logarithmic grid - logical :: photon_transport = .false. + logical :: photon_transport = .true. ! ============================================================================ ! MULTI-GROUP CROSS SECTION RELATED VARIABLES diff --git a/src/photon_physics.F90 b/src/photon_physics.F90 index 7b7244fe70..39ae89d2b0 100644 --- a/src/photon_physics.F90 +++ b/src/photon_physics.F90 @@ -327,7 +327,7 @@ contains secondary = elm % shells(i_shell) % transition_subshells(2, i_transition) if (secondary == 0) then - ! Non-radiative trnasition -- Auger/Coster-Kronig effect + ! Non-radiative transition -- Auger/Coster-Kronig effect ! TODO: Create electron ! E_electron = transition_energy(i_transition) diff --git a/src/physics.F90 b/src/physics.F90 index 8fc3a501a9..e6d25cc45b 100644 --- a/src/physics.F90 +++ b/src/physics.F90 @@ -1595,7 +1595,7 @@ contains uvw = rotate_angle(p % coord(1) % uvw, mu) ! Create the secondary photon - !call p % create_secondary(uvw, E, PHOTON, run_CE=.true.) + call p % create_secondary(uvw, E, PHOTON, run_CE=.true.) end do end subroutine sample_secondary_photons diff --git a/src/tracking.F90 b/src/tracking.F90 index 7650f598ab..ce513624d8 100644 --- a/src/tracking.F90 +++ b/src/tracking.F90 @@ -135,7 +135,7 @@ contains ! Score track-length estimate of k-eff - if (run_mode == MODE_EIGENVALUE) then + if (run_mode == MODE_EIGENVALUE .and. p % type == NEUTRON) then global_tally_tracklength = global_tally_tracklength + p % wgt * & distance * material_xs % nu_fission end if @@ -166,7 +166,7 @@ contains ! PARTICLE HAS COLLISION ! Score collision estimate of keff - if (run_mode == MODE_EIGENVALUE) then + if (run_mode == MODE_EIGENVALUE .and. p % type == NEUTRON) then global_tally_collision = global_tally_collision + p % wgt * & material_xs % nu_fission / material_xs % total end if