Created
October 13, 2020 08:32
-
-
Save liangjg/dba56938c13ebc663dc99ccfebcc50d0 to your computer and use it in GitHub Desktop.
A script for generating WMP library from ENDF/BVIII.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import glob | |
import time | |
from multiprocessing import Pool | |
from contextlib import redirect_stdout | |
import openmc.data | |
neutron_dir = '/home/jingang/nucdata/ENDF-B-VIII.0/neutrons/' | |
endf_files = [i for i in glob.glob(os.path.join(neutron_dir, "*.endf")) if os.path.isfile(i)] | |
out_dir = "WMP_Lib_8.0" | |
print("Start processing {} nuclides - {}".format(len(endf_files), time.ctime())) | |
def process(endf_file): | |
nuc_name = (openmc.data.IncidentNeutron.from_endf(endf_file)).name | |
path_out = os.path.join(out_dir, nuc_name) | |
if not os.path.exists(path_out): | |
os.makedirs(path_out) | |
# print message | |
print("Processing {} - {} {} ".format(endf_file, nuc_name, time.ctime())) | |
# run wmp | |
time_start = time.time() | |
wmp_file = os.path.join(out_dir, nuc_name+".h5") | |
try: | |
if os.path.isfile(wmp_file): | |
print('Done. {} time={:.1f} s'.format(nuc_name, time.time()-time_start)) | |
else: | |
# initial tolenrance | |
rtol = 1e-3 | |
mp_file = os.path.join(path_out, nuc_name+"_mp.pickle") | |
if not os.path.isfile(mp_file): | |
with open(os.path.join(path_out, nuc_name+".log"),'w') as f: | |
with redirect_stdout(f): | |
try: | |
nuc = openmc.data.WindowedMultipole.from_endf(endf_file, | |
vf_options={"rtol": rtol, "path_out": path_out}, | |
wmp_options={"search": True, "rtol": rtol}) | |
except: | |
print('Broken 1. {} {:.1f} s'.format(nuc_name, time.time()-time_start)) | |
# relax tolenrance | |
rtol = 5e-3 | |
nuc = openmc.data.WindowedMultipole.from_endf(endf_file, log=True, | |
vf_options={"rtol": rtol, "path_out": path_out}, | |
wmp_options={"search": True, "rtol": rtol}) | |
else: | |
with open(os.path.join(path_out, nuc_name+"_windowing.log"),'w') as f: | |
with redirect_stdout(f): | |
try: | |
nuc = openmc.data.WindowedMultipole.from_multipole(mp_file, search=True, log=True, rtol=rtol) | |
except: | |
print('Broken 1. {} {:.1f} s'.format(nuc_name, time.time()-time_start)) | |
# relax tolenrance | |
rtol = 5e-3 | |
try: | |
nuc = openmc.data.WindowedMultipole.from_multipole(mp_file, search=True, log=True, rtol=rtol) | |
except: | |
print('Broken 2. {} {:.1f} s'.format(nuc_name, time.time()-time_start)) | |
# relax tolenrance | |
rtol = 1e-2 | |
try: | |
nuc = openmc.data.WindowedMultipole.from_multipole(mp_file, search=True, log=2, rtol=rtol) | |
except: | |
# Ar38 | |
print('Broken 3. {} {:.1f} s'.format(nuc_name, time.time()-time_start)) | |
# relax tolenrance | |
rtol = 5e-2 | |
nuc = openmc.data.WindowedMultipole.from_multipole(mp_file, search=True, log=2, rtol=rtol) | |
nuc.export_to_hdf5(wmp_file) | |
print('Done. {} time={:.1f} s rtol={:.1e}'.format(nuc_name, time.time()-time_start, rtol)) | |
except: | |
print('Failed. {} time={:.1f} s rtol={:.1e}'.format(nuc_name, time.time()-time_start, rtol)) | |
sys.stdout.flush() | |
with Pool(16) as p: | |
p.map(process, endf_files) | |
print("Finish processing all nuclides - {}".format(time.ctime())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note:
B10
needs to be processed manually becauseopenmc.data
fails readingB10
ace file produced by NJOY.