2023-02-16 16:28:05 -06:00
|
|
|
from pathlib import Path
|
2018-01-29 10:53:46 -06:00
|
|
|
|
2016-04-25 09:04:52 -05:00
|
|
|
import openmc
|
2015-06-25 00:10:07 -06:00
|
|
|
|
2018-01-29 10:53:46 -06:00
|
|
|
from tests.testing_harness import TestHarness
|
2018-01-29 13:46:40 -06:00
|
|
|
from tests.regression_tests import config
|
2023-02-16 16:28:05 -06:00
|
|
|
from tests import cdtemp
|
2018-01-29 10:53:46 -06:00
|
|
|
|
2015-06-25 00:10:07 -06:00
|
|
|
class StatepointRestartTestHarness(TestHarness):
|
2017-04-07 10:25:24 -05:00
|
|
|
def __init__(self, final_sp, restart_sp):
|
2018-02-06 13:14:17 -05:00
|
|
|
super().__init__(final_sp)
|
2016-02-19 15:11:39 -05:00
|
|
|
self._restart_sp = restart_sp
|
|
|
|
|
|
2015-06-25 00:10:07 -06:00
|
|
|
def execute_test(self):
|
2015-06-29 18:50:53 -06:00
|
|
|
"""Run OpenMC with the appropriate arguments and check the outputs."""
|
2015-06-25 00:10:07 -06:00
|
|
|
try:
|
|
|
|
|
self._run_openmc()
|
|
|
|
|
self._test_output_created()
|
2015-06-28 00:06:33 -06:00
|
|
|
results = self._get_results()
|
|
|
|
|
self._write_results(results)
|
2015-06-25 00:10:07 -06:00
|
|
|
self._compare_results()
|
|
|
|
|
|
2015-06-28 13:23:24 -06:00
|
|
|
self._run_openmc_restart()
|
2015-06-25 00:10:07 -06:00
|
|
|
self._test_output_created()
|
2015-06-28 00:06:33 -06:00
|
|
|
results = self._get_results()
|
|
|
|
|
self._write_results(results)
|
2015-06-25 00:10:07 -06:00
|
|
|
self._compare_results()
|
|
|
|
|
finally:
|
|
|
|
|
self._cleanup()
|
|
|
|
|
|
2015-06-29 18:50:53 -06:00
|
|
|
def update_results(self):
|
|
|
|
|
"""Update the results_true using the current version of OpenMC."""
|
|
|
|
|
try:
|
|
|
|
|
self._run_openmc()
|
|
|
|
|
self._test_output_created()
|
|
|
|
|
results = self._get_results()
|
|
|
|
|
self._write_results(results)
|
|
|
|
|
self._overwrite_results()
|
|
|
|
|
finally:
|
|
|
|
|
self._cleanup()
|
|
|
|
|
|
2015-06-28 13:23:24 -06:00
|
|
|
def _run_openmc_restart(self):
|
|
|
|
|
# Get the name of the statepoint file.
|
2023-02-21 07:28:32 -06:00
|
|
|
statepoint = list(Path.cwd().glob(self._restart_sp))
|
2016-02-19 15:11:39 -05:00
|
|
|
assert len(statepoint) == 1
|
|
|
|
|
statepoint = statepoint[0]
|
2015-06-25 00:10:07 -06:00
|
|
|
|
2015-06-28 13:23:24 -06:00
|
|
|
# Run OpenMC
|
2018-01-29 13:46:40 -06:00
|
|
|
if config['mpi']:
|
|
|
|
|
mpi_args = [config['mpiexec'], '-n', config['mpi_np']]
|
|
|
|
|
openmc.run(restart_file=statepoint, openmc_exec=config['exe'],
|
2018-01-23 07:18:33 -06:00
|
|
|
mpi_args=mpi_args)
|
2015-06-30 23:20:54 -06:00
|
|
|
else:
|
2018-01-29 13:46:40 -06:00
|
|
|
openmc.run(openmc_exec=config['exe'], restart_file=statepoint)
|
2013-02-01 15:22:32 -05:00
|
|
|
|
2014-02-25 13:21:54 -05:00
|
|
|
|
2018-01-29 12:10:24 -06:00
|
|
|
def test_statepoint_restart():
|
2016-02-19 15:11:39 -05:00
|
|
|
harness = StatepointRestartTestHarness('statepoint.10.h5',
|
2017-04-07 10:25:24 -05:00
|
|
|
'statepoint.07.h5')
|
2015-06-29 18:50:53 -06:00
|
|
|
harness.main()
|
2023-02-16 16:28:05 -06:00
|
|
|
|
|
|
|
|
|
2024-04-24 17:09:56 -05:00
|
|
|
def test_batch_check(request, capsys):
|
2023-02-21 00:42:27 -06:00
|
|
|
xmls = list(request.path.parent.glob('*.xml'))
|
2023-02-16 16:28:05 -06:00
|
|
|
|
|
|
|
|
with cdtemp(xmls):
|
|
|
|
|
model = openmc.Model.from_xml()
|
|
|
|
|
model.settings.particles = 100
|
2024-04-24 17:09:56 -05:00
|
|
|
|
2023-02-16 16:28:05 -06:00
|
|
|
# run the model
|
2024-04-24 17:09:56 -05:00
|
|
|
sp_file = model.run(export_model_xml=False)
|
|
|
|
|
assert sp_file is not None
|
2023-02-16 16:28:05 -06:00
|
|
|
|
|
|
|
|
# run a restart with the resulting statepoint
|
|
|
|
|
# and the settings unchanged
|
2024-04-24 17:09:56 -05:00
|
|
|
model.settings.batches = 6
|
|
|
|
|
# ensure we capture output only from the next run
|
|
|
|
|
capsys.readouterr()
|
|
|
|
|
sp_file = model.run(export_model_xml=False, restart_file=sp_file)
|
|
|
|
|
# indicates that a new statepoint file was not created
|
|
|
|
|
assert sp_file is None
|
|
|
|
|
|
|
|
|
|
output = capsys.readouterr().out
|
|
|
|
|
assert "WARNING" in output
|
|
|
|
|
assert "The number of batches specified for simulation" in output
|
|
|
|
|
|
|
|
|
|
# update the number of batches and run again,
|
|
|
|
|
# this restart run should be successful
|
2023-02-16 16:28:05 -06:00
|
|
|
model.settings.batches = 15
|
|
|
|
|
model.settings.statepoint = {}
|
2024-04-24 17:09:56 -05:00
|
|
|
sp_file = model.run(export_model_xml=False, restart_file=sp_file)
|
2023-02-16 16:28:05 -06:00
|
|
|
|
|
|
|
|
sp = openmc.StatePoint(sp_file)
|
2023-02-21 00:48:23 -06:00
|
|
|
assert sp.n_batches == 15
|