Skip to content

Commit

Permalink
Reset timers at correct place in deplete (#2821)
Browse files Browse the repository at this point in the history
  • Loading branch information
gridley committed Jan 11, 2024
1 parent cc15f5e commit d8e9d58
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions openmc/deplete/coupled_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit d8e9d58

Please sign in to comment.