Merge pull request #2302 from yardasol/depletion-statepoints-fix

Fix zero-valued `runtime` attribute in depletion statepoints.
This commit is contained in:
Paul Romano 2022-11-23 05:07:12 -08:00 committed by GitHub
commit 33ead74209
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View file

@ -460,7 +460,6 @@ class CoupledOperator(OpenMCOperator):
# Run OpenMC
openmc.lib.run()
openmc.lib.reset_timers()
# Extract results
rates = self._calculate_reaction_rates(source_rate)
@ -529,6 +528,8 @@ class CoupledOperator(OpenMCOperator):
"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:

View file

@ -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
@ -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)
@ -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"""