From 6ea533a61fb642e19f9baa0ad4b47e94b2f55f76 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Wed, 25 Jul 2018 14:58:55 -0500 Subject: [PATCH] Add C API function for resetting tally individually --- include/openmc.h | 1 + src/tallies/tally_header.F90 | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/openmc.h b/include/openmc.h index 5f778397e6..f211b4930f 100644 --- a/include/openmc.h +++ b/include/openmc.h @@ -97,6 +97,7 @@ extern "C" { int openmc_tally_get_n_realizations(int32_t index, int32_t* n); int openmc_tally_get_nuclides(int32_t index, int** nuclides, int* n); int openmc_tally_get_scores(int32_t index, int** scores, int* n); + int openmc_tally_reset(int32_t index); int openmc_tally_results(int32_t index, double** ptr, int shape_[3]); int openmc_tally_set_active(int32_t index, bool active); int openmc_tally_set_filters(int32_t index, int n, const int32_t* indices); diff --git a/src/tallies/tally_header.F90 b/src/tallies/tally_header.F90 index 16c5a87b8c..6442d58009 100644 --- a/src/tallies/tally_header.F90 +++ b/src/tallies/tally_header.F90 @@ -29,6 +29,7 @@ module tally_header public :: openmc_tally_get_n_realizations public :: openmc_tally_get_nuclides public :: openmc_tally_get_scores + public :: openmc_tally_reset public :: openmc_tally_results public :: openmc_tally_set_active public :: openmc_tally_set_filters @@ -608,6 +609,24 @@ contains end function openmc_tally_get_scores + function openmc_tally_reset(index) result(err) bind(C) + ! Reset tally results and number of realizations + integer(C_INT32_T), intent(in), value :: index + integer(C_INT) :: err + + if (index >= 1 .and. index <= size(tallies)) then + associate (t => tallies(index) % obj) + t % n_realizations = 0 + if (allocated(t % results)) t % results(:, :, :) = ZERO + err = 0 + end associate + else + err = E_OUT_OF_BOUNDS + call set_errmsg('Index in tallies array is out of bounds.') + end if + end function openmc_tally_reset + + function openmc_tally_results(index, ptr, shape_) result(err) bind(C) ! Returns a pointer to a tally results array along with its shape. This ! allows a user to obtain in-memory tally results from Python directly.