diff --git a/openmc/deplete/coupled_operator.py b/openmc/deplete/coupled_operator.py index 287a4e0d37b..d591e956f5f 100644 --- a/openmc/deplete/coupled_operator.py +++ b/openmc/deplete/coupled_operator.py @@ -265,6 +265,9 @@ def __init__(self, model, chain_file=None, prev_results=None, 'fission_yield_opts': fission_yield_opts } + # Records how many times the operator has been called + self._n_calls = 0 + super().__init__( materials=model.materials, cross_sections=cross_sections, @@ -429,6 +432,16 @@ def __call__(self, vec, source_rate): # Reset results in OpenMC openmc.lib.reset() + # The timers are reset only if the operator has been called before. + # This is because we call this method after loading cross sections, and + # no transport has taken place yet. As a result, we only reset the + # timers after the first step so as to correctly report the time spent + # reading cross sections in the first depletion step, and from there + # correctly report all particle tracking rates in multistep depletion + # solvers. + if self._n_calls > 0: + openmc.lib.reset_timers() + self._update_materials_and_nuclides(vec) # If the source rate is zero, return zero reaction rates without running @@ -449,6 +462,8 @@ def __call__(self, vec, source_rate): op_result = OperatorResult(keff, rates) + self._n_calls += 1 + return copy.deepcopy(op_result) def _update_materials(self): @@ -508,8 +523,6 @@ def write_bos_data(step): "openmc_simulation_n{}.h5".format(step), write_source=False) - openmc.lib.reset_timers() - def finalize(self): """Finalize a depletion simulation and release resources.""" if self.cleanup_when_done: