From 25b8dcd7a37563b0fdc4cb26013decaa150240c5 Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Mon, 13 Aug 2018 15:27:35 -0400 Subject: [PATCH 1/5] Don't deactive tallies in openmc_reset --- src/api.F90 | 9 --------- src/tallies/tally_header.F90 | 1 + 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/api.F90 b/src/api.F90 index cc9120c7b9..f7e896b7c8 100644 --- a/src/api.F90 +++ b/src/api.F90 @@ -259,7 +259,6 @@ contains if (allocated(tallies)) then do i = 1, size(tallies) associate (t => tallies(i) % obj) - t % active = .false. t % n_realizations = 0 if (allocated(t % results)) then t % results(:, :, :) = ZERO @@ -278,14 +277,6 @@ contains k_abs_tra = ZERO k_sum(:) = ZERO - ! Clear active tally lists - call active_analog_tallies % clear() - call active_tracklength_tallies % clear() - call active_meshsurf_tallies % clear() - call active_collision_tallies % clear() - call active_surface_tallies % clear() - call active_tallies % clear() - ! Reset timers call time_total % reset() call time_total % reset() diff --git a/src/tallies/tally_header.F90 b/src/tallies/tally_header.F90 index 6442d58009..4c78fd6da7 100644 --- a/src/tallies/tally_header.F90 +++ b/src/tallies/tally_header.F90 @@ -388,6 +388,7 @@ contains do i = 1, n_tallies call tallies(i) % obj % allocate_results() + tallies(i) % obj % active = .false. end do end subroutine configure_tallies From 3c727f7364cb0f0cc6978ce12fc017b76c0d4943 Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Tue, 14 Aug 2018 12:25:58 -0400 Subject: [PATCH 2/5] Make sure CMFD tallies are activated --- src/cmfd_execute.F90 | 15 ++++++++++++++- src/simulation.F90 | 5 ++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/cmfd_execute.F90 b/src/cmfd_execute.F90 index af8d57a807..7fe153d273 100644 --- a/src/cmfd_execute.F90 +++ b/src/cmfd_execute.F90 @@ -11,7 +11,7 @@ module cmfd_execute implicit none private - public :: execute_cmfd, cmfd_init_batch + public :: execute_cmfd, cmfd_init_batch, cmfd_tally_init contains @@ -360,6 +360,19 @@ contains end function get_matrix_idx +!=============================================================================== +! CMFD_TALLY_INIT +!=============================================================================== + + subroutine cmfd_tally_init() + integer :: i + if (cmfd_run) then + do i = 1, size(cmfd_tallies) + cmfd_tallies(i) % obj % active = .true. + end do + end if + end subroutine cmfd_tally_init + !=============================================================================== ! CMFD_TALLY_RESET resets all cmfd tallies !=============================================================================== diff --git a/src/simulation.F90 b/src/simulation.F90 index 00d558d140..41af5b2bab 100644 --- a/src/simulation.F90 +++ b/src/simulation.F90 @@ -7,7 +7,7 @@ module simulation #endif use bank_header, only: source_bank - use cmfd_execute, only: cmfd_init_batch, execute_cmfd + use cmfd_execute, only: cmfd_init_batch, cmfd_tally_init, execute_cmfd use cmfd_header, only: cmfd_on use constants, only: ZERO use eigenvalue, only: count_source_for_ufs, calculate_average_keff, & @@ -428,6 +428,9 @@ contains ! Allocate tally results arrays if they're not allocated yet call configure_tallies() + ! Activate the CMFD tallies + call cmfd_tally_init() + ! Set up material nuclide index mapping do i = 1, n_materials call materials(i) % init_nuclide_index() From 3aa4a6f6daa8c56bc5d1ced6b1e0545aea5b0ed5 Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Tue, 14 Aug 2018 13:46:42 -0400 Subject: [PATCH 3/5] Update capi tally activation test --- tests/unit_tests/test_capi.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/unit_tests/test_capi.py b/tests/unit_tests/test_capi.py index af013cbb5b..d6b59423ff 100644 --- a/tests/unit_tests/test_capi.py +++ b/tests/unit_tests/test_capi.py @@ -49,7 +49,13 @@ def capi_init(pincell_model): @pytest.fixture(scope='module') -def capi_run(capi_init): +def capi_simulation_init(pincell_model): + openmc.capi.simulation_init() + yield + + +@pytest.fixture(scope='module') +def capi_run(capi_simulation_init): openmc.capi.run() @@ -173,10 +179,6 @@ def test_tally(capi_init): t.scores = new_scores assert t.scores == new_scores - assert not t.active - t.active = True - assert t.active - t2 = openmc.capi.tallies[2] t2.id = 2 assert len(t2.filters) == 2 @@ -196,6 +198,13 @@ def test_new_tally(capi_init): assert len(openmc.capi.tallies) == 4 +def test_tally_activate(capi_simulation_init): + t = openmc.capi.tallies[1] + assert not t.active + t.active = True + assert t.active + + def test_tally_results(capi_run): t = openmc.capi.tallies[1] assert t.num_realizations == 10 # t was made active in test_tally From a10737cf113c36e74ee0e978e313cc5b41d1fa75 Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Thu, 16 Aug 2018 10:46:00 -0400 Subject: [PATCH 4/5] Add a test for openmc.capi.reset --- tests/unit_tests/test_capi.py | 54 ++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/tests/unit_tests/test_capi.py b/tests/unit_tests/test_capi.py index d6b59423ff..c56771a7a3 100644 --- a/tests/unit_tests/test_capi.py +++ b/tests/unit_tests/test_capi.py @@ -245,17 +245,51 @@ def test_by_batch(capi_run): openmc.capi.next_batch() openmc.capi.simulation_init() - for _ in openmc.capi.iter_batches(): - # Make sure we can get k-effective during inactive/active batches - mean, std_dev = openmc.capi.keff() - assert 0.0 < mean < 2.5 - assert std_dev > 0.0 - assert openmc.capi.num_realizations() == 5 + try: + for _ in openmc.capi.iter_batches(): + # Make sure we can get k-effective during inactive/active batches + mean, std_dev = openmc.capi.keff() + assert 0.0 < mean < 2.5 + assert std_dev > 0.0 + assert openmc.capi.num_realizations() == 5 - for i in range(3): - openmc.capi.next_batch() - assert openmc.capi.num_realizations() == 8 - openmc.capi.simulation_finalize() + for i in range(3): + openmc.capi.next_batch() + assert openmc.capi.num_realizations() == 8 + + finally: + openmc.capi.simulation_finalize() + + +def test_reset(capi_run): + # Init and run 10 batches. + openmc.capi.hard_reset() + openmc.capi.simulation_init() + try: + for i in range(10): + openmc.capi.next_batch() + + # Make sure there are 5 realizations for the 5 active batches. + assert openmc.capi.num_realizations() == 5 + assert openmc.capi.tallies[2].num_realizations == 5 + _, keff_sd1 = openmc.capi.keff() + tally_sd1 = openmc.capi.tallies[2].std_dev[0] + + # Reset and run 3 more batches. Check the number of realizations. + openmc.capi.reset() + for i in range(3): + openmc.capi.next_batch() + assert openmc.capi.num_realizations() == 3 + assert openmc.capi.tallies[2].num_realizations == 3 + + # Check the tally std devs to make sure results were cleared. + _, keff_sd2 = openmc.capi.keff() + tally_sd2 = openmc.capi.tallies[2].std_dev[0] + assert keff_sd2 > keff_sd1 + assert tally_sd2 > tally_sd1 + + finally: + openmc.capi.simulation_finalize() def test_reproduce_keff(capi_init): From 2e660bd89f1a2e0f25fb39016753fed0e7217338 Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Thu, 16 Aug 2018 10:52:05 -0400 Subject: [PATCH 5/5] Move tally deactivation to simulation_finalize --- src/simulation.F90 | 7 +++++++ src/tallies/tally_header.F90 | 1 - 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/simulation.F90 b/src/simulation.F90 index 41af5b2bab..89c7b1f68e 100644 --- a/src/simulation.F90 +++ b/src/simulation.F90 @@ -573,6 +573,13 @@ contains ! Write tally results to tallies.out if (output_tallies .and. master) call write_tallies() + ! Deactivate all tallies + if (allocated(tallies)) then + do i = 1, n_tallies + tallies(i) % obj % active = .false. + end do + end if + ! Stop timers and show timing statistics call time_finalize%stop() call time_total%stop() diff --git a/src/tallies/tally_header.F90 b/src/tallies/tally_header.F90 index 4c78fd6da7..6442d58009 100644 --- a/src/tallies/tally_header.F90 +++ b/src/tallies/tally_header.F90 @@ -388,7 +388,6 @@ contains do i = 1, n_tallies call tallies(i) % obj % allocate_results() - tallies(i) % obj % active = .false. end do end subroutine configure_tallies