mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 21:55:41 -04:00
created script for adding photo data to cross_sections.xml and turned on photon transport
This commit is contained in:
parent
b4f9badfdb
commit
5da591d36a
7 changed files with 117 additions and 18 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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'])
|
||||
|
||||
|
|
|
|||
93
scripts/openmc-get-photo-endf71
Executable file
93
scripts/openmc-get-photo-endf71
Executable file
|
|
@ -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)
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue