Skip to content

Commit

Permalink
Merge pull request #4 from nplinden/jendl_chain
Browse files Browse the repository at this point in the history
Jendl chain
  • Loading branch information
shimwell authored May 2, 2024
2 parents 7bc9ca8 + c8d05bd commit 8f08377
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 2 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ generate_fendl = "openmc_data.generate.generate_fendl:main"
generate_endf71_chain_casl = "openmc_data.depletion.generate_endf71_chain_casl:main"
generate_endf_chain = "openmc_data.depletion.generate_endf_chain:main"
generate_jeff_chain = "openmc_data.depletion.generate_jeff_chain:main"
generate_jendl_chain = "openmc_data.depletion.generate_jendl_chain:main"
generate_serpent_fissq = "openmc_data.depletion.generate_serpent_fissq:main"
generate_tendl_chain = "openmc_data.depletion.generate_tendl_chain:main"

Expand Down
127 changes: 127 additions & 0 deletions src/openmc_data/depletion/generate_jendl_chain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#!/usr/bin/env python3

import argparse
import ssl
from pathlib import Path
from urllib.parse import urljoin

import openmc.deplete

from openmc_data.utils import download, extract
from openmc_data import all_decay_release_details


# Parse command line arguments
parser = argparse.ArgumentParser(prog="generate_jeff_chain",
description="Generates a OpenMC chain file from JENDL nuclear data files",
)
parser.add_argument('-r', '--release', choices=['5.0'],
default='5.0', help="The nuclear data library release "
"version. The only currently supported option is 5.0.")
parser.add_argument(
"-d",
"--destination",
type=Path,
default=None,
help="filename of the chain file xml file produced. If left as None then "
"the filename will follow this format 'chain_jendl_{release}.xml'",
)
parser.add_argument(
"--neutron",
type=Path,
default=[],
nargs="+",
help="Path to neutron endf files, if not provided, neutron files will be downloaded.",
)
parser.add_argument(
"--decay",
type=Path,
default=[],
nargs="+",
help="Path to decay data files, if not provided, decay files will be downloaded.",
)
parser.add_argument(
"--fpy",
type=Path,
default=[],
nargs="+",
help="Path to neutron fission product yield files, if not provided, fission yield files will be downloaded.",
)
args = parser.parse_args()

def main():

library_name = 'jendl'

cwd = Path.cwd()

# DOWNLOAD NEUTRON DATA
endf_files_dir = cwd.joinpath('-'.join([library_name, args.release, 'endf']))
download_path = cwd.joinpath('-'.join([library_name, args.release, 'download']))
neutron_files = args.neutron
if not neutron_files:
details = all_decay_release_details[library_name][args.release]['neutron']

for f in details['compressed_files']:
# Establish connection to URL
download(
urljoin(details['base_url'], f),
context=ssl._create_unverified_context(),
output_path=download_path
)
extract(
compressed_files=[download_path / f for f in details['compressed_files']],
extraction_dir=endf_files_dir,
del_compressed_file=False
)
for erratum in details["errata"]:
files = Path('.').rglob(erratum)
for p in files:
p.rename((endf_files_dir / details["endf_files"]).parent / p.name)
neutron_files = endf_files_dir.glob(details['endf_files'])

decay_files = args.decay
if not decay_files:
details = all_decay_release_details[library_name][args.release]['decay']
for base_url, file in zip(details['base_url'], details['compressed_files']):
downloaded_file = download(
url=urljoin(base_url, file),
output_path=Path(".")
)

extract([downloaded_file], Path("."))
decay_files = list(Path('.').rglob(details["decay_files"]))

fpy_files = args.fpy
if not fpy_files:
details = all_decay_release_details[library_name][args.release]['nfy']
for base_url, file in zip(details['base_url'], details['compressed_files']):
downloaded_file = download(
url=urljoin(base_url, file),
output_path=Path(".")
)

extract([downloaded_file], Path("."))
fpy_files = list(Path('.').rglob(details["nfy_files"]))

# check files exist
for flist, ftype in [(decay_files, "decay"), (neutron_files, "neutron"),
(fpy_files, "neutron fission product yield")]:
if not flist:
raise IOError(f"No {ftype} endf files found in {endf_files_dir}")

chain = openmc.deplete.Chain.from_endf(
decay_files=decay_files,
fpy_files=fpy_files,
neutron_files=neutron_files,
reactions=list(openmc.deplete.chain.REACTIONS.keys())
)

if args.destination is None:
args.destination = f'chain_{library_name}_{args.release}.xml'
chain.export_to_xml(args.destination)
print(f'Chain file written to {args.destination}')


if __name__ == '__main__':
main()
5 changes: 4 additions & 1 deletion src/openmc_data/generate/generate_jendl.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class CustomFormatter(argparse.ArgumentDefaultsHelpFormatter,
parser.add_argument('--no-cleanup', dest='cleanup', action='store_false',
help="Do not remove download directories when data has "
"been processed")
parser.add_argument('--temperatures', type=float,
default=[250.0, 293.6, 600.0, 900.0, 1200.0, 2500.0],
help="Temperatures in Kelvin", nargs='+')
parser.set_defaults(download=True, extract=True, cleanup=False)
args = parser.parse_args()

Expand Down Expand Up @@ -109,7 +112,7 @@ def main():
with Pool() as pool:
results = []
for filename in sorted(neutron_files):
func_args = (filename, args.destination, args.libver)
func_args = (filename, args.destination, args.libver, args.temperatures)
r = pool.apply_async(process_neutron, func_args)
results.append(r)

Expand Down
23 changes: 23 additions & 0 deletions src/openmc_data/urls_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,28 @@
'compressed_files': ['TENDL-n.tgz'],
}
}
},
'jendl': {
'5.0': {
'neutron': {
'base_url': 'https://wwwndc.jaea.go.jp/ftpnd/ftp/JENDL/',
'compressed_files': ['jendl5-n.tar.gz', 'jendl5-n_upd1.tar.gz',
'jendl5-n_upd6.tar.gz', 'jendl5-n_upd7.tar.gz',
'jendl5-n_upd10.tar.gz', 'jendl5-n_upd11.tar.gz',
'jendl5-n_upd12.tar.gz'],
'endf_files': 'jendl5-n/*.dat',
'errata': ['jendl5-n_upd1/*.dat', 'jendl-n_upd6/*.dat', '*.dat'],
},
'decay': {
'base_url': ['https://wwwndc.jaea.go.jp/ftpnd/ftp/JENDL/'],
'compressed_files': ['jendl5-dec_upd5.tar.gz'],
'decay_files': 'jendl5-dec_upd5/*.dat'
},
'nfy': {
'base_url': ['https://wwwndc.jaea.go.jp/ftpnd/ftp/JENDL/'],
'compressed_files': ['jendl5-fpy_upd8.tar.gz'],
'nfy_files': 'jendl5-fpy_upd8/*.dat'
}
}
}
}
3 changes: 2 additions & 1 deletion src/openmc_data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,14 @@ def extract(
extraction_dir : str
The directory to extract the files to.
del_compressed_file : bool
Wheather the compressed file should be deleted (True) or not (False)
Whether the compressed file should be deleted (True) or not (False)
verbose : bool
Controls the printing to terminal, if True filenames of the extracted
files will be printed.
"""
Path.mkdir(extraction_dir, parents=True, exist_ok=True)

print(f'Extracting {compressed_files} to {extraction_dir}')
if not isinstance(compressed_files, Iterable):
compressed_files = [compressed_files]

Expand Down

0 comments on commit 8f08377

Please sign in to comment.