From 2ff8eb4696f315f6f47a7d5b7a7e200a6647ea48 Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Tue, 7 Aug 2018 17:03:38 -0400 Subject: [PATCH] Add a C-API based restart test --- src/state_point.F90 | 3 ++- tests/unit_tests/test_capi.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/state_point.F90 b/src/state_point.F90 index 4d66a37aa5..3f1d5b3978 100644 --- a/src/state_point.F90 +++ b/src/state_point.F90 @@ -70,6 +70,7 @@ contains integer(HID_T) :: cmfd_group, tallies_group, tally_group, meshes_group, & filters_group, filter_group, derivs_group, & deriv_group, runtime_group + integer(C_INT) :: ignored_err real(C_DOUBLE) :: k_combined(2) character(MAX_WORD_LEN), allocatable :: str_array(:) character(C_CHAR), pointer :: string(:) @@ -151,7 +152,7 @@ contains call write_dataset(file_id, "k_col_abs", k_col_abs) call write_dataset(file_id, "k_col_tra", k_col_tra) call write_dataset(file_id, "k_abs_tra", k_abs_tra) - err = openmc_get_keff(k_combined) + ignored_err = openmc_get_keff(k_combined) call write_dataset(file_id, "k_combined", k_combined) ! Write out CMFD info diff --git a/tests/unit_tests/test_capi.py b/tests/unit_tests/test_capi.py index af013cbb5b..288676ff7a 100644 --- a/tests/unit_tests/test_capi.py +++ b/tests/unit_tests/test_capi.py @@ -311,3 +311,31 @@ def test_mesh(capi_init): msf = openmc.capi.MeshSurfaceFilter(mesh) assert msf.mesh == mesh + + +def test_restart(pincell_model): + # Run for 7 batches then write a statepoint. + openmc.capi.init() + openmc.capi.simulation_init() + for i in range(7): + openmc.capi.next_batch() + openmc.capi.statepoint_write('restart_test.h5', True) + + # Run 3 more batches and copy the keff. + for i in range(3): + openmc.capi.next_batch() + keff0 = openmc.capi.keff() + openmc.capi.simulation_finalize() + openmc.capi.finalize() + + # Restart the simulation and run all 10 batches. + openmc.capi.init(args=('-r', 'restart_test.h5')) + openmc.capi.simulation_init() + for i in range(10): + openmc.capi.next_batch() + keff1 = openmc.capi.keff() + openmc.capi.simulation_finalize() + openmc.capi.finalize() + + # Compare the keff values. + assert keff0 == pytest.approx(keff1)