diff --git a/openmc/deplete/abc.py b/openmc/deplete/abc.py index c304b8dc621..4b43dd22149 100644 --- a/openmc/deplete/abc.py +++ b/openmc/deplete/abc.py @@ -818,10 +818,35 @@ def _get_bos_data_from_restart(self, source_rate, bos_conc): rates *= source_rate / res.source_rate return bos_conc, OperatorResult(k, rates) - def _get_start_data(self): + def _get_start_data(self) -> tuple[float, int]: + """ + This function fetches the starting state of a depletion simulation in + terms of the simulation physical time at which to start and the index at + which the depletion simulation should start. When no previous results + exist, the time and index are both zero. When previous results do exist, + it returns the time corresponding to beginning the previous results last + timestep and the index as N-1 where N is the number of previous + StepResults found in the previous Results (as expected from 0-based + indexing). + + Note that the openmc.deplete.Results.time object is a list of float with + [t,t+dt] where t is the beginning of timestep time and t+dt is the end + of timestep time. If the previous results correspond to a simulation + that finished to completeion, it will contain a results in the form of + [t,t], but if a simulation doesn't finish all the given timesteps, it is + the t that is the desired start time, not t+dt. Thus, it is always safe + to take time[0]. + + Returns + ------- + start_time : float + Time at which depletion simulation should start in [s] + index : int + Index at which depletion simulation should start + """ if self.operator.prev_res is None: return 0.0, 0 - return (self.operator.prev_res[-1].time[-1], + return (self.operator.prev_res[-1].time[0], len(self.operator.prev_res) - 1) def integrate( diff --git a/tests/unit_tests/test_deplete_continue.py b/tests/unit_tests/test_deplete_continue.py index 53c4c56d29f..637c9d5e440 100644 --- a/tests/unit_tests/test_deplete_continue.py +++ b/tests/unit_tests/test_deplete_continue.py @@ -4,6 +4,7 @@ """ import pytest +import numpy as np import openmc.deplete from tests import dummy_operator @@ -26,6 +27,43 @@ def test_continue(run_in_tmpdir): bundle.solver(operator, [1.0, 2.0, 3.0, 4.0], [1.0, 2.0, 3.0, 4.0], continue_timesteps=True).integrate() + final_res = openmc.deplete.Results(operator.output_dir / "depletion_results.h5") + + assert np.array_equal( + np.diff(final_res.get_times(time_units="s")), + [1.0, 2.0, 3.0, 4.0] + ) + + +def test_continue_continue(run_in_tmpdir): + """Test to ensure that a continue run can be continued""" + # set up the problem + bundle = dummy_operator.SCHEMES['predictor'] + operator = dummy_operator.DummyOperator() + + # initial depletion + bundle.solver(operator, [1.0, 2.0], [1.0, 2.0]).integrate() + + # set up continue run + prev_res = openmc.deplete.Results(operator.output_dir / "depletion_results.h5") + operator = dummy_operator.DummyOperator(prev_res) + + # first continue run + bundle.solver(operator, [1.0, 2.0, 3.0, 4.0], [1.0, 2.0, 3.0, 4.0], + continue_timesteps=True).integrate() + + prev_res = openmc.deplete.Results(operator.output_dir / "depletion_results.h5") + # second continue run + bundle.solver(operator, [1.0, 2.0, 3.0, 4.0, 5.0, 6.0], [1.0, 2.0, 3.0, 4.0, 5.0, 6.0], + continue_timesteps=True).integrate() + + final_res = openmc.deplete.Results(operator.output_dir / "depletion_results.h5") + + assert np.array_equal( + np.diff(final_res.get_times(time_units="s")), + [1.0, 2.0, 3.0, 4.0, 5.0, 6.0] + ) + def test_mismatched_initial_times(run_in_tmpdir): """Test to ensure that a continue run with different initial steps is properly caught"""