Update _get_start_data to always grab the beginning of timestep time (#3414)

Co-authored-by: Paul Wilson <paul.wilson@wisc.edu>
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
This commit is contained in:
Lewis Gross 2025-06-04 18:40:55 -05:00 committed by GitHub
parent ace73ab5de
commit e14bb884eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 65 additions and 2 deletions

View file

@ -818,10 +818,35 @@ class Integrator(ABC):
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(

View file

@ -4,6 +4,7 @@ These tests run in two steps: first a normal run and then a continue run using t
"""
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"""