Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix path handeling for thermal ace generAtion #3171

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions openmc/data/njoy.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ def make_ace(filename, temperatures=None, acer=True, xsdir=None,
if acer:
ace = (output_dir / "ace") if acer is True else Path(acer)
xsdir = (ace.parent / "xsdir") if xsdir is None else xsdir
with ace.open('w') as ace_file, xsdir.open('w') as xsdir_file:
with open(ace, 'w') as ace_file, open(xsdir, 'w') as xsdir_file:
for temperature in temperatures:
# Get contents of ACE file
text = (output_dir / f"ace_{temperature:.1f}").read_text()
Expand Down Expand Up @@ -589,16 +589,30 @@ def make_ace_thermal(filename, filename_thermal, temperatures=None,
commands += 'stop\n'
run(commands, tapein, tapeout, **kwargs)

ace = output_dir / ace
# Determine the path for the final ACE and xsdir files
# If 'ace' is an absolute path, use it directly
# If 'ace' is a relative path, place it in the current directory
if not os.path.isabs(ace):
ace = os.path.abspath(ace)

# Determine xsdir path similarly
if xsdir is None:
xsdir = os.path.join(os.path.dirname(ace), 'xsdir')
else:
if not os.path.isabs(xsdir):
xsdir = os.path.abspath(xsdir)

xsdir = (ace.parent / "xsdir") if xsdir is None else Path(xsdir)
with ace.open('w') as ace_file, xsdir.open('w') as xsdir_file:
with open(ace, 'w') as ace_file, open(xsdir, 'w') as xsdir_file:
# Concatenate ACE and xsdir files together
for temperature in temperatures:
ace_in = output_dir / f"ace_{temperature:.1f}"
ace_file.write(ace_in.read_text())
ace_in = os.path.join(output_dir, f"ace_{temperature:.1f}")
with open(ace_in, 'r') as f:
ace_file.write(f.read())

xsdir_in = output_dir / f"xsdir_{temperature:.1f}"
xsdir_file.write(xsdir_in.read_text())
xsdir_in = os.path.join(output_dir, f"xsdir_{temperature:.1f}")
with open(xsdir_in, 'r') as f:
xsdir_file.write(f.read())

# Remove ACE/xsdir files for each temperature
for temperature in temperatures:
Expand Down
14 changes: 11 additions & 3 deletions openmc/data/thermal.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,13 +839,22 @@ def from_njoy(cls, filename, filename_thermal, temperatures=None,
with tempfile.TemporaryDirectory() as tmpdir:
# Run NJOY to create an ACE library
kwargs.setdefault('output_dir', tmpdir)
kwargs.setdefault('ace', os.path.join(kwargs['output_dir'], 'ace'))

# Get the ace filename from kwargs or default to 'ace'
ace_filename = kwargs.get('ace', 'ace')
kwargs['ace'] = ace_filename

kwargs['evaluation'] = evaluation
kwargs['evaluation_thermal'] = evaluation_thermal
make_ace_thermal(filename, filename_thermal, temperatures, **kwargs)

# Read the ACE file from the correct path
ace_path = kwargs['ace']
if not os.path.isabs(ace_path):
ace_path = os.path.abspath(ace_path)

lib = Library(ace_path)
# Create instance from ACE tables within library
lib = Library(kwargs['ace'])
name = kwargs.get('table_name')
data = cls.from_ace(lib.tables[0], name=name)
for table in lib.tables[1:]:
Expand All @@ -867,7 +876,6 @@ def from_njoy(cls, filename, filename_thermal, temperatures=None,
if isinstance(rx_endf.xs[t], (IncoherentElastic, Sum)):
rx.xs[t] = rx_endf.xs[t]
rx.distribution[t] = rx_endf.distribution[t]

return data

@classmethod
Expand Down