diff --git a/src/settings.F90 b/src/settings.F90 index dfe4afbe3..710a87e1e 100644 --- a/src/settings.F90 +++ b/src/settings.F90 @@ -121,7 +121,6 @@ module settings 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_multipole ! Path to wmp library - character(MAX_FILE_LEN) :: path_source = '' ! Path to binary source character(MAX_FILE_LEN) :: path_state_point ! Path to binary state point character(MAX_FILE_LEN) :: path_source_point ! Path to binary source point character(MAX_FILE_LEN) :: path_particle_restart ! Path to particle restart diff --git a/src/simulation.F90 b/src/simulation.F90 index b5d24180c..d5ca165b5 100644 --- a/src/simulation.F90 +++ b/src/simulation.F90 @@ -253,7 +253,10 @@ contains subroutine finalize_generation() - integer(8) :: i + interface + subroutine fill_source_bank_fixedsource() bind(C) + end subroutine + end interface ! Update global tallies with the omp private accumulation variables !$omp parallel @@ -306,13 +309,7 @@ contains elseif (run_mode == MODE_FIXEDSOURCE) then ! For fixed-source mode, we need to sample the external source - if (path_source == '') then - do i = 1, work - call set_particle_seed((total_gen + overall_generation()) * & - n_particles + work_index(rank) + i) - source_bank(i) = sample_external_source() - end do - end if + call fill_source_bank_fixedsource() end if end subroutine finalize_generation diff --git a/src/simulation_header.F90 b/src/simulation_header.F90 index 7addf9b2c..d7040b8d5 100644 --- a/src/simulation_header.F90 +++ b/src/simulation_header.F90 @@ -80,8 +80,8 @@ contains ! OVERALL_GENERATION determines the overall generation number !=============================================================================== - pure function overall_generation() result(gen) - integer :: gen + pure function overall_generation() result(gen) bind(C) + integer(C_INT) :: gen gen = gen_per_batch*(current_batch - 1) + current_gen end function overall_generation diff --git a/src/source.cpp b/src/source.cpp index e01c9795e..c3869fcf4 100644 --- a/src/source.cpp +++ b/src/source.cpp @@ -352,4 +352,28 @@ extern "C" double total_source_strength() return strength; } +// Needed in fill_source_bank_fixedsource +extern "C" int overall_generation(); + +//! Fill source bank at end of generation for fixed source simulations +extern "C" void fill_source_bank_fixedsource() +{ + if (path_source.empty()) { + // Get pointer to source bank + Bank* source_bank; + int64_t n; + openmc_source_bank(&source_bank, &n); + + for (int64_t i = 0; i < openmc_work; ++i) { + // initialize random number seed + int64_t id = (openmc_total_gen + overall_generation())*n_particles + + work_index[openmc::mpi::rank] + i + 1; + set_particle_seed(id); + + // sample external source distribution + source_bank[i] = sample_external_source(); + } + } +} + } // namespace openmc