From 013df94b2e8701c2e367ca88ab923adb32751925 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Tue, 31 Jul 2012 14:49:05 -0400 Subject: [PATCH] Ability to restart from state point. Works in serial. --- src/DEPENDENCIES | 2 + src/criticality.F90 | 7 ++++ src/fixed_source.F90 | 6 +++ src/global.F90 | 6 ++- src/initialize.F90 | 13 ++++++ src/input_xml.F90 | 3 -- src/output.F90 | 1 + src/state_point.F90 | 94 ++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 128 insertions(+), 4 deletions(-) diff --git a/src/DEPENDENCIES b/src/DEPENDENCIES index 514be1d02..487b06129 100644 --- a/src/DEPENDENCIES +++ b/src/DEPENDENCIES @@ -120,6 +120,7 @@ initialize.o: input_xml.o initialize.o: output.o initialize.o: random_lcg.o initialize.o: source.o +initialize.o: state_point.o initialize.o: string.o initialize.o: tally.o initialize.o: tally_header.o @@ -233,6 +234,7 @@ source.o: physics.o source.o: random_lcg.o source.o: string.o +state_point.o: error.o state_point.o: global.o state_point.o: output.o state_point.o: string.o diff --git a/src/criticality.F90 b/src/criticality.F90 index 686c36153..4d7b1ee31 100644 --- a/src/criticality.F90 +++ b/src/criticality.F90 @@ -38,6 +38,13 @@ contains ! LOOP OVER BATCHES BATCH_LOOP: do current_batch = 1, n_batches + ! In a restart run, skip any batches that have already been simulated + if (restart_run .and. current_batch <= restart_batch) then + if (current_batch == n_inactive) tallies_on = .true. + if (current_batch > n_inactive) n_realizations = n_realizations + 1 + cycle BATCH_LOOP + end if + call initialize_batch() ! ======================================================================= diff --git a/src/fixed_source.F90 b/src/fixed_source.F90 index a650aa384..ead8676e6 100644 --- a/src/fixed_source.F90 +++ b/src/fixed_source.F90 @@ -34,6 +34,12 @@ contains ! LOOP OVER BATCHES BATCH_LOOP: do current_batch = 1, n_batches + ! In a restart run, skip any batches that have already been simulated + if (restart_run .and. current_batch <= restart_batch) then + if (current_batch > n_inactive) n_realizations = n_realizations + 1 + cycle BATCH_LOOP + end if + call initialize_batch() ! Start timer for transport diff --git a/src/global.F90 b/src/global.F90 index c2bf819bb..60c59c47a 100644 --- a/src/global.F90 +++ b/src/global.F90 @@ -222,9 +222,13 @@ module global ! Mode to run in (fixed source, criticality, plotting, etc) integer :: run_mode = MODE_CRITICALITY + ! Restart run + logical :: restart_run = .false. + integer :: restart_batch + character(MAX_FILE_LEN) :: path_input ! Path to input file character(MAX_FILE_LEN) :: path_cross_sections ! Path to cross_sections.xml - character(MAX_FILE_LEN) :: path_source ! Path to binary source + character(MAX_FILE_LEN) :: path_source = '' ! Path to binary source character(MAX_FILE_LEN) :: path_state_point ! Path to binary state point ! Message used in message/warning/fatal_error diff --git a/src/initialize.F90 b/src/initialize.F90 index 60c080621..8f1fb7996 100644 --- a/src/initialize.F90 +++ b/src/initialize.F90 @@ -18,6 +18,7 @@ module initialize create_xs_summary_file, print_version use random_lcg, only: initialize_prng use source, only: initialize_source + use state_point, only: load_state_point use string, only: to_str, str_to_int, starts_with, ends_with, & lower_case use tally, only: create_tally_map @@ -125,6 +126,10 @@ contains call allocate_banks() call initialize_source() end if + + ! If this is a restart run, load the state point data and binary source + ! file + if (restart_run) call load_state_point() end if ! stop timer for initialization @@ -260,6 +265,14 @@ contains " command-line flag." call fatal_error() end if + case ('-r', '-restart', '--restart') + i = i + 1 + ! Read path for state point + path_state_point = argv(i) + restart_run = .true. + + ! Set path for binary source file + path_source = 'source.' // path_state_point(9:10) // '.binary' case ('-?', '-help', '--help') call print_usage() stop diff --git a/src/input_xml.F90 b/src/input_xml.F90 index 8be4080fd..f1f98c322 100644 --- a/src/input_xml.F90 +++ b/src/input_xml.F90 @@ -327,9 +327,6 @@ contains allocate(external_source % params_energy(2)) external_source % params_energy = (/ 0.988_8, 2.249_8 /) end if - - ! Set null path for source file - path_source = "" end if ! Survival biasing diff --git a/src/output.F90 b/src/output.F90 index b46349d98..4d8afc104 100644 --- a/src/output.F90 +++ b/src/output.F90 @@ -167,6 +167,7 @@ contains write(OUTPUT_UNIT,*) write(OUTPUT_UNIT,*) 'Options:' write(OUTPUT_UNIT,*) ' -p, --plot Run in plotting mode' + write(OUTPUT_UNIT,*) ' -r, --restart Restart a previous run' write(OUTPUT_UNIT,*) ' -v, --version Show version information' write(OUTPUT_UNIT,*) ' -?, --help Show this message' end if diff --git a/src/state_point.F90 b/src/state_point.F90 index 88ec1e409..9cf950ace 100644 --- a/src/state_point.F90 +++ b/src/state_point.F90 @@ -1,5 +1,6 @@ module state_point + use error, only: warning, fatal_error use global use output, only: write_message use string, only: to_str @@ -44,6 +45,9 @@ contains ! Write out random number seed write(UNIT_STATE) seed + ! Write out keff information + write(UNIT_STATE) keff, keff_std + ! Write out global tallies sum and sum_sq write(UNIT_STATE) N_GLOBAL_TALLIES write(UNIT_STATE) global_tallies(:) % sum @@ -65,4 +69,94 @@ contains end subroutine create_state_point +!=============================================================================== +! LOAD_STATE_POINT +!=============================================================================== + + subroutine load_state_point() + + integer :: i ! loop index + integer :: temp(3) ! temporary variable + + ! Write message + message = "Loading state point " // trim(path_state_point) // "..." + call write_message() + + ! Open binary state point file for writing + open(UNIT=UNIT_STATE, FILE=path_state_point, STATUS='old', & + ACCESS='stream') + + ! Raad revision number for state point file and make sure it matches with + ! current version + read(UNIT_STATE) temp(1) + if (temp(1) /= REVISION_STATEPOINT) then + message = "State point binary version does not match current version " & + // "in OpenMC." + call fatal_error() + end if + + ! Read OpenMC version + read(UNIT_STATE) temp(1:3) + if (temp(1) /= VERSION_MAJOR .or. temp(2) /= VERSION_MINOR & + .or. temp(3) /= VERSION_RELEASE) then + message = "State point file was created with a different version " // & + "of OpenMC." + call warning() + end if + + ! Read and overwrite run information + read(UNIT_STATE) run_mode, n_particles, n_batches, & + n_inactive, gen_per_batch + + ! Read batch number to restart at + read(UNIT_STATE) restart_batch + + ! Read and overwrite random number seed + read(UNIT_STATE) seed + + ! Write out keff information + read(UNIT_STATE) keff, keff_std + + if (master) then + ! Read number of global tallies and make sure it matches + read(UNIT_STATE) temp(1) + if (temp(1) /= N_GLOBAL_TALLIES) then + message = "Number of global tallies does not match in state point." + call fatal_error() + end if + + ! Read global tally data + read(UNIT_STATE) global_tallies(:) % sum + read(UNIT_STATE) global_tallies(:) % sum_sq + + ! Read tally data + if (current_batch > n_inactive) then + ! Read number of tallies and make sure it matches + read(UNIT_STATE) temp(1) + if (temp(1) /= n_tallies) then + message = "Number of tallies does not match in state point." + call fatal_error() + end if + + do i = 1, n_tallies + ! Make sure dimensions match for tally filters and scores + read(UNIT_STATE) temp(1:2) + if (temp(1) /= size(tallies(i) % scores, 1) .or. & + temp(2) /= size(tallies(i) % scores, 2)) then + message = "Tally dimensions do not match in state point." + call fatal_error() + end if + + ! Read sum and sum squared + read(UNIT_STATE) tallies(i) % scores(:,:) % sum + read(UNIT_STATE) tallies(i) % scores(:,:) % sum_sq + end do + end if + end if + + ! Close binary state point file + close(UNIT_STATE) + + end subroutine load_state_point + end module state_point