mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 22:26:08 -04:00
Ensure that Model.run() works when specifying a custom XML path (#2889)
This commit is contained in:
parent
7ed12788df
commit
c4a75f7062
4 changed files with 19 additions and 7 deletions
|
|
@ -488,8 +488,11 @@ class Model:
|
|||
# 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
|
||||
|
|
@ -709,9 +712,10 @@ class Model:
|
|||
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:
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ from itertools import product
|
|||
from math import log
|
||||
import os
|
||||
from pathlib import Path
|
||||
import warnings
|
||||
|
||||
import numpy as np
|
||||
from openmc.mpi import comm
|
||||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
"""Tests for the openmc.deplete.Nuclide class."""
|
||||
|
||||
import copy
|
||||
import warnings
|
||||
|
||||
import lxml.etree as ET
|
||||
import numpy as np
|
||||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue