Merge pull request #1044 from smharper/openmc_reset

Don't deactivate tallies in openmc_reset
This commit is contained in:
Paul Romano 2018-08-16 11:56:45 -05:00 committed by GitHub
commit c56b91bc77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 83 additions and 26 deletions

View file

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

View file

@ -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
!===============================================================================

View file

@ -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, &
@ -438,6 +438,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()
@ -580,6 +583,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()

View file

@ -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
@ -236,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):