Merge pull request #1522 from paulromano/njoy-aceoutput-fix

Ensure NJOY output goes to specified output directory
This commit is contained in:
Amanda Lund 2020-03-20 11:10:26 -05:00 committed by GitHub
commit 44563a30a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -402,7 +402,6 @@ def make_ace(filename, temperatures=None, acer=True, xsdir=None,
# acer
if acer:
nacer_in = nlast
fname = '{}_{:.1f}'
for i, temperature in enumerate(temperatures):
# Extend input with an ACER run for each temperature
nace = nacer_in + 1 + 2*i
@ -411,8 +410,8 @@ def make_ace(filename, temperatures=None, acer=True, xsdir=None,
commands += _TEMPLATE_ACER.format(**locals())
# Indicate tapes to save for each ACER run
tapeout[nace] = fname.format("ace", temperature)
tapeout[ndir] = fname.format("xsdir", temperature)
tapeout[nace] = output_dir / "ace_{:.1f}".format(temperature)
tapeout[ndir] = output_dir / "xsdir_{:.1f}".format(temperature)
commands += 'stop\n'
run(commands, tapein, tapeout, **kwargs)
@ -422,7 +421,7 @@ def make_ace(filename, temperatures=None, acer=True, xsdir=None,
with ace.open('w') as ace_file, xsdir.open('w') as xsdir_file:
for temperature in temperatures:
# Get contents of ACE file
text = open(fname.format("ace", temperature), 'r').read()
text = (output_dir / "ace_{:.1f}".format(temperature)).read_text()
# If the target is metastable, make sure that ZAID in the ACE
# file reflects this by adding 400
@ -435,18 +434,18 @@ def make_ace(filename, temperatures=None, acer=True, xsdir=None,
ace_file.write(text)
# Concatenate into destination xsdir file
text = open(fname.format("xsdir", temperature), 'r').read()
xsdir_file.write(text)
xsdir_in = output_dir / "xsdir_{:.1f}".format(temperature)
xsdir_file.write(xsdir_in.read_text())
# Remove ACE/xsdir files for each temperature
for temperature in temperatures:
os.remove(fname.format("ace", temperature))
os.remove(fname.format("xsdir", temperature))
(output_dir / "ace_{:.1f}".format(temperature)).unlink()
(output_dir / "xsdir_{:.1f}".format(temperature)).unlink()
def make_ace_thermal(filename, filename_thermal, temperatures=None,
ace='ace', xsdir='xsdir', error=0.001, iwt=2,
evaluation=None, evaluation_thermal=None, **kwargs):
ace='ace', xsdir=None, output_dir=None, error=0.001,
iwt=2, evaluation=None, evaluation_thermal=None, **kwargs):
"""Generate thermal scattering ACE file from ENDF files
Parameters
@ -461,7 +460,12 @@ def make_ace_thermal(filename, filename_thermal, temperatures=None,
ace : str, optional
Path of ACE file to write
xsdir : str, optional
Path of xsdir file to write
Path of xsdir file to write. Defaults to ``"xsdir"`` in the same
directory as ``ace``
output_dir : str, optional
Directory to write ace and xsdir files. If not provided, then write
output files to current directory. If given, must be a path to a
directory.
error : float, optional
Fractional error tolerance for NJOY processing
iwt : int
@ -481,6 +485,13 @@ def make_ace_thermal(filename, filename_thermal, temperatures=None,
If the NJOY process returns with a non-zero status
"""
if output_dir is None:
output_dir = Path()
else:
output_dir = Path(output_dir)
if not output_dir.is_dir():
raise IOError("{} is not a directory".format(output_dir))
ev = evaluation if evaluation is not None else endf.Evaluation(filename)
mat = ev.material
zsymam = ev.target['zsymam']
@ -564,7 +575,6 @@ def make_ace_thermal(filename, filename_thermal, temperatures=None,
# acer
nthermal_acer_in = nlast
fname = '{}_{:.1f}'
for i, temperature in enumerate(temperatures):
# Extend input with an ACER run for each temperature
nace = nthermal_acer_in + 1 + 2*i
@ -573,21 +583,23 @@ def make_ace_thermal(filename, filename_thermal, temperatures=None,
commands += _THERMAL_TEMPLATE_ACER.format(**locals())
# Indicate tapes to save for each ACER run
tapeout[nace] = fname.format(ace, temperature)
tapeout[ndir] = fname.format(xsdir, temperature)
tapeout[nace] = output_dir / "ace_{:.1f}".format(temperature)
tapeout[ndir] = output_dir / "xsdir_{:.1f}".format(temperature)
commands += 'stop\n'
run(commands, tapein, tapeout, **kwargs)
with open(ace, 'w') as ace_file, open(xsdir, 'w') as xsdir_file:
ace = output_dir / ace
xsdir = (ace.parent / "xsdir") if xsdir is None else Path(xsdir)
with ace.open('w') as ace_file, xsdir.open('w') as xsdir_file:
# Concatenate ACE and xsdir files together
for temperature in temperatures:
text = open(fname.format(ace, temperature), 'r').read()
ace_file.write(text)
ace_in = output_dir / "ace_{:.1f}".format(temperature)
ace_file.write(ace_in.read_text())
text = open(fname.format(xsdir, temperature), 'r').read()
xsdir_file.write(text)
xsdir_in = output_dir / "xsdir_{:.1f}".format(temperature)
xsdir_file.write(xsdir_in.read_text())
# Remove ACE/xsdir files for each temperature
for temperature in temperatures:
os.remove(fname.format(ace, temperature))
os.remove(fname.format(xsdir, temperature))
(output_dir / "ace_{:.1f}".format(temperature)).unlink()
(output_dir / "xsdir_{:.1f}".format(temperature)).unlink()