mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 13:45:36 -04:00
Remove several data generation scripts (will move to data repository)
This commit is contained in:
parent
d95fcbc559
commit
a489fe22d0
3 changed files with 0 additions and 199 deletions
|
|
@ -1,77 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
from pathlib import Path
|
||||
import zipfile
|
||||
|
||||
import openmc.data
|
||||
from openmc._utils import download
|
||||
|
||||
|
||||
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 = 'https://www.nndc.bnl.gov/endf/b7.1/zips/'
|
||||
files = ['ENDF-B-VII.1-photoat.zip', 'ENDF-B-VII.1-atomic_relax.zip']
|
||||
block_size = 16384
|
||||
|
||||
# ==============================================================================
|
||||
# DOWNLOAD FILES FROM NNDC SITE
|
||||
|
||||
output = Path('photon_hdf5')
|
||||
output.mkdir(exist_ok=True)
|
||||
|
||||
for f in files:
|
||||
download(base_url + f)
|
||||
|
||||
# ==============================================================================
|
||||
# EXTRACT FILES
|
||||
|
||||
for f in files:
|
||||
print('Extracting {}...'.format(f))
|
||||
zipfile.ZipFile(f).extractall()
|
||||
|
||||
# ==============================================================================
|
||||
# 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 = output / 'cross_sections.xml'
|
||||
library = openmc.data.DataLibrary()
|
||||
|
||||
# Iterate over each natural element from Z=1 to Z=100
|
||||
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))
|
||||
data = openmc.data.IncidentPhoton.from_endf(photo_file, atom_file)
|
||||
|
||||
# Write HDF5 file and register it
|
||||
hdf5_file = output / (element + '.h5')
|
||||
data.export_to_hdf5(hdf5_file, 'w')
|
||||
library.register_file(hdf5_file)
|
||||
|
||||
library.export_to_xml(lib_path)
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import tarfile
|
||||
|
||||
import numpy as np
|
||||
import h5py
|
||||
|
||||
from openmc._utils import download
|
||||
|
||||
|
||||
base_url = 'http://geant4.cern.ch/support/source/'
|
||||
filename = 'G4EMLOW.6.48.tar.gz'
|
||||
|
||||
# ==============================================================================
|
||||
# DOWNLOAD FILES FROM GEANT4 SITE
|
||||
|
||||
download(base_url + filename)
|
||||
|
||||
# ==============================================================================
|
||||
# EXTRACT FILES FROM TGZ
|
||||
|
||||
if not os.path.isdir('G4EMLOW6.48'):
|
||||
with tarfile.open(filename, 'r') as tgz:
|
||||
print('Extracting {}...'.format(filename))
|
||||
tgz.extractall()
|
||||
|
||||
# ==============================================================================
|
||||
# GENERATE COMPTON PROFILE HDF5 FILE
|
||||
|
||||
print('Generating compton_profiles.h5...')
|
||||
|
||||
shell_file = os.path.join('G4EMLOW6.48', 'doppler', 'shell-doppler.dat')
|
||||
|
||||
with open(shell_file, 'r') as shell, h5py.File('compton_profiles.h5', 'w') as f:
|
||||
# Read/write electron momentum values
|
||||
pz = np.loadtxt(os.path.join('G4EMLOW6.48', 'doppler', 'p-biggs.dat'))
|
||||
f.create_dataset('pz', data=pz)
|
||||
|
||||
for z in range(1, 101):
|
||||
# Create group for this element
|
||||
group = f.create_group('{:03}'.format(z))
|
||||
|
||||
# Read data into one long array
|
||||
path = os.path.join('G4EMLOW6.48', 'doppler', 'profile-{}.dat'.format(z))
|
||||
with open(path, 'r') as profile:
|
||||
j = np.fromstring(profile.read(), sep=' ')
|
||||
|
||||
# Determine number of electron shells and reshape. Profiles are
|
||||
# tabulated against a grid of 31 momentum values.
|
||||
n_shells = j.size // 31
|
||||
j.shape = (n_shells, 31)
|
||||
|
||||
# Write Compton profile for this Z
|
||||
group.create_dataset('J', data=j)
|
||||
|
||||
# Determine binding energies and number of electrons for each shell
|
||||
num_electrons = []
|
||||
binding_energy = []
|
||||
while True:
|
||||
words = shell.readline().split()
|
||||
if words[0] == '-1':
|
||||
break
|
||||
num_electrons.append(float(words[0]))
|
||||
binding_energy.append(float(words[1]))
|
||||
|
||||
# Write binding energies and number of electrons
|
||||
group.create_dataset('num_electrons', data=num_electrons)
|
||||
group.create_dataset('binding_energy', data=binding_energy)
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from urllib.parse import urlencode
|
||||
from urllib.request import urlopen
|
||||
from lxml import html
|
||||
|
||||
import numpy as np
|
||||
import h5py
|
||||
from openmc.data import ATOMIC_SYMBOL
|
||||
|
||||
|
||||
base_url = 'https://physics.nist.gov/cgi-bin/Star/e_table-t.pl'
|
||||
energies = np.logspace(-3, 3, 200)
|
||||
data = {'matno': '', 'Energies': '\n'.join(str(x) for x in energies)}
|
||||
columns = {1: 's_collision', 2: 's_radiative'}
|
||||
|
||||
# ==============================================================================
|
||||
# SCRAPE DATA FROM ESTAR SITE AND GENERATE STOPPING POWER HDF5 FILE
|
||||
|
||||
print('Generating stopping_powers.h5...')
|
||||
|
||||
with h5py.File('stopping_powers.h5', 'w') as f:
|
||||
|
||||
# Write energies
|
||||
f.create_dataset('energy', data=energies)
|
||||
|
||||
# Look over atomic number; ESTAR only goes up to Z=98 (Californium)
|
||||
for Z in range(1, 99):
|
||||
print('Processing {} data...'.format(ATOMIC_SYMBOL[Z]))
|
||||
|
||||
# Update form-encoded data to send in POST request for this element
|
||||
data['matno'] = '{:03}'.format(Z)
|
||||
payload = urlencode(data).encode("utf-8")
|
||||
|
||||
# Retrieve data from ESTAR site
|
||||
with urlopen(url=base_url, data=payload) as response:
|
||||
r = response.read()
|
||||
|
||||
# Remove text and reformat data -- omit first 12 and last 5 lines to get
|
||||
# only data in table
|
||||
r = html.fromstring(r).xpath('//pre//text()')
|
||||
values = np.fromstring(' '.join(r[12:-5]), sep=' ').reshape((-1, 5)).T
|
||||
|
||||
# Create group for this element
|
||||
group = f.create_group('{:03}'.format(Z))
|
||||
|
||||
# Write the mean excitation energy
|
||||
attributes = np.fromstring(r[3], sep=' ')
|
||||
group.attrs['I'] = attributes[2]
|
||||
|
||||
# Write collision and radiative stopping powers
|
||||
for i in columns:
|
||||
group.create_dataset(columns[i], data=values[i])
|
||||
Loading…
Add table
Add a link
Reference in a new issue