Skip to content

Commit 94ee938

Browse files
authored
Merge pull request #18 from openmc-data-storage/adding-tendls
added tendl 2023 generate script
2 parents 29ad53c + e67d6f5 commit 94ee938

File tree

4 files changed

+138
-0
lines changed

4 files changed

+138
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ A few categories of scripts are available:
7373
| generate_endf | ENDF/B | VII.1<br>VIII.0 | NNDC |
7474
| generate_fendl | FENDL | 3.2c<br>3.2b<br>3.2a<br>3.2<br>3.1d<br>3.1a<br>3.0 | |
7575
| generate_jendl | JENDL | 4.0<br>5.0 | |
76+
| generate_tendl | TENDL | 2023 | |
7677

7778

7879
### Download cross sections

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ generate_endf = "openmc_data.generate.generate_endf:main"
5959
generate_jeff33 = "openmc_data.generate.generate_jeff33:main"
6060
generate_jendl = "openmc_data.generate.generate_jendl:main"
6161
generate_fendl = "openmc_data.generate.generate_fendl:main"
62+
generate_tendl = "openmc_data.generate.generate_tendl:main"
6263

6364
generate_endf71_chain_casl = "openmc_data.depletion.generate_endf71_chain_casl:main"
6465
generate_endf_chain = "openmc_data.depletion.generate_endf_chain:main"
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#!/usr/bin/env python3
2+
3+
"""
4+
Download TENDL data from PSI and convert it to a HDF5 library for
5+
use with OpenMC.
6+
"""
7+
8+
import argparse
9+
import ssl
10+
from multiprocessing import Pool
11+
from pathlib import Path
12+
from urllib.parse import urljoin
13+
14+
import openmc.data
15+
from openmc_data import download, extract, process_neutron, state_download_size, all_release_details
16+
17+
18+
class CustomFormatter(argparse.ArgumentDefaultsHelpFormatter,
19+
argparse.RawDescriptionHelpFormatter):
20+
pass
21+
22+
23+
parser = argparse.ArgumentParser(
24+
description=__doc__,
25+
formatter_class=CustomFormatter
26+
)
27+
parser.add_argument('-d', '--destination', type=Path, default=None,
28+
help='Directory to create new library in')
29+
parser.add_argument('--download', action='store_true',
30+
help='Download files')
31+
parser.add_argument('--no-download', dest='download', action='store_false',
32+
help='Do not download files')
33+
parser.add_argument('--extract', action='store_true',
34+
help='Extract tar/zip files')
35+
parser.add_argument('--no-extract', dest='extract', action='store_false',
36+
help='Do not extract tar/zip files')
37+
parser.add_argument('--libver', choices=['earliest', 'latest'],
38+
default='latest', help="Output HDF5 versioning. Use "
39+
"'earliest' for backwards compatibility or 'latest' for "
40+
"performance")
41+
parser.add_argument('-r', '--release', choices=["2023"], default="2023",
42+
help="The nuclear data library release version. "
43+
"The options currently supported are 2023")
44+
parser.add_argument('--cleanup', action='store_true',
45+
help="Remove download directories when data has "
46+
"been processed")
47+
parser.add_argument('--no-cleanup', dest='cleanup', action='store_false',
48+
help="Do not remove download directories when data has "
49+
"been processed")
50+
parser.set_defaults(download=True, extract=True, cleanup=False)
51+
args = parser.parse_args()
52+
53+
54+
def main():
55+
56+
library_name = 'tendl'
57+
58+
cwd = Path.cwd()
59+
60+
endf_files_dir = cwd.joinpath('-'.join([library_name, args.release, 'endf']))
61+
download_path = cwd.joinpath('-'.join([library_name, args.release, 'download']))
62+
# the destination is decided after the release is known
63+
# to avoid putting the release in a folder with a misleading name
64+
if args.destination is None:
65+
args.destination = Path('-'.join([library_name, args.release, 'hdf5']))
66+
67+
# This dictionary contains all the unique information about each release.
68+
# This can be exstened to accommodated new releases
69+
details = all_release_details[library_name][args.release]['neutron']['endf']
70+
71+
# ==============================================================================
72+
# DOWNLOAD FILES FROM WEBSITE
73+
74+
if args.download:
75+
state_download_size(details['compressed_file_size'], details['uncompressed_file_size'], 'GB')
76+
for f in details['compressed_files']:
77+
# Establish connection to URL
78+
download(
79+
urljoin(details['base_url'], f),
80+
context=ssl._create_unverified_context(),
81+
output_path=download_path,
82+
as_browser=True
83+
)
84+
85+
# ==============================================================================
86+
# EXTRACT FILES FROM TGZ
87+
if args.extract:
88+
extract(
89+
compressed_files=[download_path/ f for f in details['compressed_files']],
90+
extraction_dir=endf_files_dir,
91+
del_compressed_file=args.cleanup
92+
)
93+
94+
# ==============================================================================
95+
# GENERATE HDF5 LIBRARY -- NEUTRON FILES
96+
97+
# Get a list of all ENDF files
98+
neutron_files = endf_files_dir.glob('*.tendl')
99+
100+
# Create output directory if it doesn't exist
101+
args.destination.mkdir(parents=True, exist_ok=True)
102+
103+
library = openmc.data.DataLibrary()
104+
105+
with Pool() as pool:
106+
results = []
107+
for filename in sorted(neutron_files):
108+
func_args = (filename, args.destination, args.libver)
109+
r = pool.apply_async(process_neutron, func_args)
110+
results.append(r)
111+
112+
for r in results:
113+
r.wait()
114+
115+
# Register with library
116+
for p in sorted((args.destination).glob('*.h5')):
117+
library.register_file(p)
118+
119+
# Write cross_sections.xml
120+
library.export_to_xml(args.destination / 'cross_sections.xml')
121+
122+
123+
if __name__ == '__main__':
124+
main()

src/openmc_data/urls.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@
4848
}
4949
}
5050
},
51+
"2023": {
52+
"neutron": {
53+
"endf": {
54+
"base_url": "https://tendl.web.psi.ch/tendl_2023/tar_files/",
55+
"compressed_files": ["TENDL-n.2024new.tgz"],
56+
"neutron_files": "tendl24c/*",
57+
"metastables": "tendl24c/*m",
58+
"compressed_file_size": 3.1,
59+
"uncompressed_file_size": 20,
60+
}
61+
}
62+
},
5163
},
5264
"fendl": {
5365
"3.2c": {

0 commit comments

Comments
 (0)