Skip to content

Commit

Permalink
Merge pull request #2302 from yardasol/depletion-statepoints-fix
Browse files Browse the repository at this point in the history
Fix zero-valued `runtime` attribute in depletion statepoints.
  • Loading branch information
paulromano committed Nov 23, 2022
2 parents da7e06d + 8163d7a commit 33ead74
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion openmc/deplete/coupled_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,6 @@ def __call__(self, vec, source_rate):

# Run OpenMC
openmc.lib.run()
openmc.lib.reset_timers()

# Extract results
rates = self._calculate_reaction_rates(source_rate)
Expand Down Expand Up @@ -529,6 +528,8 @@ 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
19 changes: 19 additions & 0 deletions tests/regression_tests/deplete_with_transport/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from math import floor
import shutil
from pathlib import Path
from collections import defaultdict

from difflib import unified_diff
import numpy as np
Expand Down Expand Up @@ -122,8 +123,11 @@ def test_full(run_in_tmpdir, problem, multiproc):
n_tallies = np.empty(N + 1, dtype=int)

# Get statepoint files for all BOS points and EOL
runtimes = defaultdict(list)
for n in range(N + 1):
statepoint = openmc.StatePoint(f"openmc_simulation_n{n}.h5")
for measure, time in statepoint.runtime.items():
runtimes[measure].append(time)
k_n = statepoint.keff
k_state[n] = [k_n.nominal_value, k_n.std_dev]
n_tallies[n] = len(statepoint.tallies)
Expand All @@ -134,6 +138,21 @@ def test_full(run_in_tmpdir, problem, multiproc):
# Check that no additional tallies are loaded from the files
assert np.all(n_tallies == 0)

# Convert values in runtimes to arrays
runtimes = {k: np.array(v) for k, v in runtimes.items()}

# Check that runtimes are qualitatively correct
assert runtimes['reading cross sections'][0] != 0
assert runtimes['total initialization'][0] != 0
assert np.all(runtimes['reading cross sections'][1:] == 0)
assert np.all(runtimes['total initialization'][1:] == 0)
assert np.all(runtimes['inactive batches'] == 0)
del runtimes['reading cross sections']
del runtimes['total initialization']
del runtimes['inactive batches']
for measure, times in runtimes.items():
assert np.all(times != 0)


def test_depletion_results_to_material(run_in_tmpdir, problem):
"""Checks openmc.Materials objects can be created from depletion results"""
Expand Down

0 comments on commit 33ead74

Please sign in to comment.