From 5b7929b6ef178fce979ba6e02b0950a228fd8bf4 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Tue, 17 Mar 2020 10:40:53 -0500 Subject: [PATCH 1/3] Ensure NJOY output for multiple temperatures goes to specified output dir --- openmc/data/njoy.py | 48 ++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/openmc/data/njoy.py b/openmc/data/njoy.py index 0c853102f3..69035f7071 100644 --- a/openmc/data/njoy.py +++ b/openmc/data/njoy.py @@ -411,8 +411,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 / fname.format("ace", temperature) + tapeout[ndir] = output_dir / fname.format("xsdir", temperature) commands += 'stop\n' run(commands, tapein, tapeout, **kwargs) @@ -422,7 +422,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 = open(output_dir / fname.format("ace", temperature), 'r').read() # If the target is metastable, make sure that ZAID in the ACE # file reflects this by adding 400 @@ -435,18 +435,13 @@ 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() + text = open(output_dir / fname.format("xsdir", temperature), 'r').read() xsdir_file.write(text) - # Remove ACE/xsdir files for each temperature - for temperature in temperatures: - os.remove(fname.format("ace", temperature)) - os.remove(fname.format("xsdir", temperature)) - 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 +456,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 +481,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'] @@ -573,21 +580,18 @@ 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 / fname.format(ace, temperature) + tapeout[ndir] = output_dir / fname.format(xsdir, temperature) commands += 'stop\n' run(commands, tapein, tapeout, **kwargs) - with open(ace, 'w') as ace_file, open(xsdir, 'w') as xsdir_file: + ace_out = (output_dir / ace) + xsdir = (ace.parent / "xsdir") if xsdir is None else xsdir + with open(ace_out, 'w') as ace_file, open(xsdir, 'w') as xsdir_file: # Concatenate ACE and xsdir files together for temperature in temperatures: - text = open(fname.format(ace, temperature), 'r').read() + text = open(output_dir / fname.format(ace, temperature), 'r').read() ace_file.write(text) - text = open(fname.format(xsdir, temperature), 'r').read() + text = open(output_dir / fname.format(xsdir, temperature), 'r').read() xsdir_file.write(text) - - # Remove ACE/xsdir files for each temperature - for temperature in temperatures: - os.remove(fname.format(ace, temperature)) - os.remove(fname.format(xsdir, temperature)) From 3a79748ec33a5dd5f9f4c0e376b1060bcf9d9aec Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Tue, 17 Mar 2020 14:37:40 -0500 Subject: [PATCH 2/3] Fix for Python 3.5 --- openmc/data/njoy.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/openmc/data/njoy.py b/openmc/data/njoy.py index 69035f7071..c9bbd9c85b 100644 --- a/openmc/data/njoy.py +++ b/openmc/data/njoy.py @@ -422,7 +422,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(output_dir / fname.format("ace", temperature), 'r').read() + text = (output_dir / fname.format("ace", temperature)).read_text() # If the target is metastable, make sure that ZAID in the ACE # file reflects this by adding 400 @@ -435,8 +435,8 @@ def make_ace(filename, temperatures=None, acer=True, xsdir=None, ace_file.write(text) # Concatenate into destination xsdir file - text = open(output_dir / fname.format("xsdir", temperature), 'r').read() - xsdir_file.write(text) + xsdir_in = output_dir / fname.format("xsdir", temperature) + xsdir_file.write(xsdir_in.read_text()) def make_ace_thermal(filename, filename_thermal, temperatures=None, @@ -585,13 +585,13 @@ def make_ace_thermal(filename, filename_thermal, temperatures=None, commands += 'stop\n' run(commands, tapein, tapeout, **kwargs) - ace_out = (output_dir / ace) - xsdir = (ace.parent / "xsdir") if xsdir is None else xsdir - with open(ace_out, 'w') as ace_file, open(xsdir, 'w') as xsdir_file: + ace_out = output_dir / ace + xsdir = (ace.parent / "xsdir") if xsdir is None else Path(xsdir) + with ace_out.open('w') as ace_file, xsdir.open('w') as xsdir_file: # Concatenate ACE and xsdir files together for temperature in temperatures: - text = open(output_dir / fname.format(ace, temperature), 'r').read() - ace_file.write(text) + ace_in = output_dir / fname.format(ace, temperature) + ace_file.write(ace_in.read_text()) - text = open(output_dir / fname.format(xsdir, temperature), 'r').read() - xsdir_file.write(text) + xsdir_in = output_dir / fname.format(xsdir, temperature) + xsdir_file.write(xsdir_in.read_text()) From c109a205e483a1c8b2c3cb52a8e108dc843fd4ec Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 20 Mar 2020 06:51:50 -0500 Subject: [PATCH 3/3] Fix output directory for xsdir in make_ace_thermal --- openmc/data/njoy.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/openmc/data/njoy.py b/openmc/data/njoy.py index c9bbd9c85b..0ef77695b5 100644 --- a/openmc/data/njoy.py +++ b/openmc/data/njoy.py @@ -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] = output_dir / fname.format("ace", temperature) - tapeout[ndir] = output_dir / 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 = (output_dir / fname.format("ace", temperature)).read_text() + 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,9 +434,14 @@ def make_ace(filename, temperatures=None, acer=True, xsdir=None, ace_file.write(text) # Concatenate into destination xsdir file - xsdir_in = output_dir / fname.format("xsdir", temperature) + 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: + (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=None, output_dir=None, error=0.001, @@ -571,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 @@ -580,18 +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] = output_dir / fname.format(ace, temperature) - tapeout[ndir] = output_dir / 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) - ace_out = output_dir / ace + ace = output_dir / ace xsdir = (ace.parent / "xsdir") if xsdir is None else Path(xsdir) - with ace_out.open('w') as ace_file, xsdir.open('w') as xsdir_file: + with ace.open('w') as ace_file, xsdir.open('w') as xsdir_file: # Concatenate ACE and xsdir files together for temperature in temperatures: - ace_in = output_dir / fname.format(ace, temperature) + ace_in = output_dir / "ace_{:.1f}".format(temperature) ace_file.write(ace_in.read_text()) - xsdir_in = output_dir / fname.format(xsdir, temperature) + 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: + (output_dir / "ace_{:.1f}".format(temperature)).unlink() + (output_dir / "xsdir_{:.1f}".format(temperature)).unlink()