Skip to content

Commit

Permalink
Ensure that Model.run() works when specifying a custom XML path (#2889)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulromano committed Mar 12, 2024
1 parent 7ed1278 commit c4a75f7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
10 changes: 7 additions & 3 deletions openmc/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,11 @@ def export_to_model_xml(self, path='model.xml', remove_surfs=False):
# if the provided path doesn't end with the XML extension, assume the
# input path is meant to be a directory. If the directory does not
# exist, create it and place a 'model.xml' file there.
if not str(xml_path).endswith('.xml') and not xml_path.exists():
os.mkdir(xml_path)
if not str(xml_path).endswith('.xml'):
if not xml_path.exists():
os.mkdir(xml_path)
elif not xml_path.is_dir():
raise FileExistsError(f"File exists and is not a directory: '{xml_path}'")
xml_path /= 'model.xml'
# if this is an XML file location and the file's parent directory does
# not exist, create it before continuing
Expand Down Expand Up @@ -709,9 +712,10 @@ def run(self, particles=None, threads=None, geometry_debug=False,
self.export_to_model_xml(**export_kwargs)
else:
self.export_to_xml(**export_kwargs)
path_input = export_kwargs.get("path", None)
openmc.run(particles, threads, geometry_debug, restart_file,
tracks, output, Path('.'), openmc_exec, mpi_args,
event_based)
event_based, path_input)

# Get output directory and return the last statepoint written
if self.settings.output and 'path' in self.settings.output:
Expand Down
5 changes: 3 additions & 2 deletions tests/unit_tests/test_deplete_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from math import log
import os
from pathlib import Path
import warnings

import numpy as np
from openmc.mpi import comm
Expand Down Expand Up @@ -438,9 +439,9 @@ def test_validate(simple_chain):
simple_chain["C"].yield_data = {0.0253: {"A": 1.4, "B": 0.6}}

assert simple_chain.validate(strict=True, tolerance=0.0)
with pytest.warns(None) as record:
with warnings.catch_warnings():
warnings.simplefilter("error")
assert simple_chain.validate(strict=False, quiet=False, tolerance=0.0)
assert len(record) == 0

# Mess up "earlier" nuclide's reactions
decay_mode = simple_chain["A"].decay_modes.pop()
Expand Down
5 changes: 3 additions & 2 deletions tests/unit_tests/test_deplete_nuclide.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Tests for the openmc.deplete.Nuclide class."""

import copy
import warnings

import lxml.etree as ET
import numpy as np
Expand Down Expand Up @@ -277,9 +278,9 @@ def test_validate():
}

# nuclide is good and should have no warnings raise
with pytest.warns(None) as record:
with warnings.catch_warnings():
warnings.simplefilter("error")
assert nuc.validate(strict=True, quiet=False, tolerance=0.0)
assert len(record) == 0

# invalidate decay modes
decay = nuc.decay_modes.pop()
Expand Down
6 changes: 6 additions & 0 deletions tests/unit_tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,3 +585,9 @@ def test_single_xml_exec(run_in_tmpdir):

with pytest.raises(RuntimeError, match='input_dir'):
openmc.run(path_input='input_dir/pincell.xml')

# Make sure path can be specified with run
pincell_model.run(path='my_model.xml')

os.mkdir('subdir')
pincell_model.run(path='subdir')

0 comments on commit c4a75f7

Please sign in to comment.