From e4281408f674ce795f237d8b568396793b159206 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 18 Nov 2022 10:31:58 -0600 Subject: [PATCH 1/3] reset timers after writing statepoint file --- openmc/deplete/coupled_operator.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openmc/deplete/coupled_operator.py b/openmc/deplete/coupled_operator.py index a8c1fa156c4..669e98ddac3 100644 --- a/openmc/deplete/coupled_operator.py +++ b/openmc/deplete/coupled_operator.py @@ -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) @@ -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: From d45c37b20619154db60c48d5a18a750152fbeb48 Mon Sep 17 00:00:00 2001 From: yardasol Date: Fri, 18 Nov 2022 10:54:41 -0600 Subject: [PATCH 2/3] Add test for runtime attribute on depletion statepoints --- .../deplete_with_transport/test.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/regression_tests/deplete_with_transport/test.py b/tests/regression_tests/deplete_with_transport/test.py index 9b37e43510e..97724164425 100644 --- a/tests/regression_tests/deplete_with_transport/test.py +++ b/tests/regression_tests/deplete_with_transport/test.py @@ -122,8 +122,18 @@ 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 = {} for n in range(N + 1): statepoint = openmc.StatePoint(f"openmc_simulation_n{n}.h5") + runtime = statepoint.runtime + if n == 0: + for measure, time in runtime.items(): + runtimes.update({measure: np.array([time])}) + else: + for measure, time in runtime.items(): + current = runtimes[measure] + updated = np.append(current, time) + runtimes.update({measure: updated}) k_n = statepoint.keff k_state[n] = [k_n.nominal_value, k_n.std_dev] n_tallies[n] = len(statepoint.tallies) @@ -134,6 +144,18 @@ def test_full(run_in_tmpdir, problem, multiproc): # Check that no additional tallies are loaded from the files assert np.all(n_tallies == 0) + # 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""" From 8163d7a759d4212d1e8ca76471ce0a8f887a6c90 Mon Sep 17 00:00:00 2001 From: Olek <45364492+yardasol@users.noreply.github.com> Date: Mon, 21 Nov 2022 15:33:54 -0600 Subject: [PATCH 3/3] use defaultdict Co-authored-by: Paul Romano --- .../deplete_with_transport/test.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/tests/regression_tests/deplete_with_transport/test.py b/tests/regression_tests/deplete_with_transport/test.py index 97724164425..477959d1cb1 100644 --- a/tests/regression_tests/deplete_with_transport/test.py +++ b/tests/regression_tests/deplete_with_transport/test.py @@ -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,18 +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 = {} + runtimes = defaultdict(list) for n in range(N + 1): statepoint = openmc.StatePoint(f"openmc_simulation_n{n}.h5") - runtime = statepoint.runtime - if n == 0: - for measure, time in runtime.items(): - runtimes.update({measure: np.array([time])}) - else: - for measure, time in runtime.items(): - current = runtimes[measure] - updated = np.append(current, time) - runtimes.update({measure: updated}) + 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) @@ -144,6 +138,9 @@ 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