-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathgenerate_tendl_chain.py
More file actions
executable file
·112 lines (86 loc) · 3.31 KB
/
generate_tendl_chain.py
File metadata and controls
executable file
·112 lines (86 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env python3
"""
Generate a depletion chain based on TENDL 2019 data. Note that TENDL 2019 does
not contain any decay or fission product yield (FPY) sublibraries, so these must
be borrowed from another library. The --lib flag for this script indicates what
library should be used for decay and FPY evaluations and defaults to JEFF 3.3.
"""
from argparse import ArgumentParser
import json
import os
from pathlib import Path
import tarfile
from zipfile import ZipFile
import openmc.deplete as dep
import openmc.data
from utils import download
NEUTRON_LIB = 'https://tendl.web.psi.ch/tendl_2019/tar_files/TENDL-n.tgz'
DECAY_LIB = {
'jeff33': 'https://www.oecd-nea.org/dbdata/jeff/jeff33/downloads/JEFF33-rdd.zip',
'endf80': 'https://www.nndc.bnl.gov/endf-b8.0/zips/ENDF-B-VIII.0_decay.zip',
}
NFY_LIB = {
'jeff33': 'https://www.oecd-nea.org/dbdata/jeff/jeff33/downloads/JEFF33-nfy.asc',
'endf80': 'https://www.nndc.bnl.gov/endf-b8.0/zips/ENDF-B-VIII.0_nfy.zip',
}
def extract(filename, path=".", verbose=True):
# Determine function to open archive
if Path(filename).suffix == '.zip':
func = ZipFile
else:
func = tarfile.open
# Open archive and extract files
with func(filename, 'r') as fh:
if verbose:
print(f'Extracting {filename}...')
fh.extractall(path)
def fix_jeff33_nfy(path):
print(f'Fixing TPID in {path}...')
new_path = path.with_name(path.name + '_fixed')
if not new_path.exists():
with path.open('r') as f:
data = f.read()
with new_path.open('w') as f:
# Write missing TPID line
f.write(" "*66 + " 1 0 0 0\n")
f.write(data)
return new_path
def main():
# Parse command line arguments
parser = ArgumentParser()
parser.add_argument('--lib', choices=('jeff33', 'endf80'), default='jeff33',
help='Library to use for decay and fission product yields')
args = parser.parse_args()
# Setup output directories
endf_dir = Path("tendl-download")
neutron_dir = endf_dir / "neutrons"
decay_dir = endf_dir / "decay"
nfy_dir = endf_dir / "nfy"
# ==========================================================================
# Incident neutron data
neutron_tgz = download(NEUTRON_LIB, output_path=endf_dir)
extract(neutron_tgz, neutron_dir)
neutron_files = [
p
for p in (endf_dir / "neutrons").glob("*.tendl")
]
# ==========================================================================
# Decay and fission product yield data
decay_zip = download(DECAY_LIB[args.lib], output_path=endf_dir)
nfy_file = download(NFY_LIB[args.lib], output_path=endf_dir)
extract(decay_zip, decay_dir)
if args.lib == 'jeff33':
decay_files = list(decay_dir.glob('*.ASC'))
nfy_file_fixed = fix_jeff33_nfy(nfy_file)
nfy_files = openmc.data.endf.get_evaluations(nfy_file_fixed)
elif args.lib == 'endf80':
decay_files = list(decay_dir.rglob('*.endf'))
extract(nfy_file, nfy_dir)
nfy_files = list(nfy_dir.rglob('*.endf'))
chain = dep.Chain.from_endf(
decay_files, nfy_files, neutron_files,
reactions=dep.chain.REACTIONS.keys()
)
chain.export_to_xml(f'chain_tendl2019_{args.lib}.xml')
if __name__ == '__main__':
main()