From 0ae1077a39a146fa6c4bb65bdd901d203076a0a5 Mon Sep 17 00:00:00 2001 From: davidjohnlong Date: Thu, 5 Mar 2020 10:48:36 +0000 Subject: [PATCH] Implement the new fixed source bank model. For a fixed source calcultion the primary source bank is not allocated memory and source particles can not be read/written to files. The source particles for each history are now sampled at the start of initialize_history() through call to sample_external_source() with the appropriate seed. The timing stats for sampling has been removed from the output since this processing is now part of the transport timer --- include/openmc/particle.h | 11 ++++++++ src/output.cpp | 2 -- src/particle.cpp | 16 +++++++---- src/simulation.cpp | 58 +++++++++++++++++++++++---------------- src/source.cpp | 17 ------------ src/state_point.cpp | 8 ++++-- 6 files changed, 62 insertions(+), 50 deletions(-) diff --git a/include/openmc/particle.h b/include/openmc/particle.h index 2917b45e4..f5f43affb 100644 --- a/include/openmc/particle.h +++ b/include/openmc/particle.h @@ -181,6 +181,15 @@ public: int delayed_group; //!< particle delayed group }; + //! Saved ("banked") state of primary source particle, for particle restart + struct RestartBank { + Position r; + Direction u; + double E; + double wgt; + }; + + //========================================================================== // Constructors @@ -361,6 +370,8 @@ public: #endif int64_t n_progeny_ {0}; // Number of progeny produced by this particle + + RestartBank primary_source_; // primary source particle data }; } // namespace openmc diff --git a/src/output.cpp b/src/output.cpp index 18b94be9b..8da32de55 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -441,8 +441,6 @@ void print_runtime() show_time("Time synchronizing fission bank", time_bank.elapsed(), 1); show_time("Sampling source sites", time_bank_sample.elapsed(), 2); show_time("SEND/RECV source sites", time_bank_sendrecv.elapsed(), 2); - } else { - show_time("Time sampling source", time_sample_source.elapsed(), 1); } show_time("Time accumulating tallies", time_tallies.elapsed(), 1); show_time("Total time for finalization", time_finalize.elapsed()); diff --git a/src/particle.cpp b/src/particle.cpp index 5f9713941..376ee35cd 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -128,6 +128,13 @@ Particle::from_source(const Bank* src) E_ = data::mg.energy_bin_avg_[g_]; } E_last_ = E_; + + // Saved copy of primary source attributes + primary_source_.r = src->r; + primary_source_.u = src->u; + primary_source_.E = E_last_; + primary_source_.wgt = wgt_; + } void @@ -681,11 +688,10 @@ Particle::write_restart() const write_dataset(file_id, "id", id_); write_dataset(file_id, "type", static_cast(type_)); - int64_t i = current_work_; - write_dataset(file_id, "weight", simulation::source_bank[i-1].wgt); - write_dataset(file_id, "energy", simulation::source_bank[i-1].E); - write_dataset(file_id, "xyz", simulation::source_bank[i-1].r); - write_dataset(file_id, "uvw", simulation::source_bank[i-1].u); + write_dataset(file_id, "weight", primary_source_.wgt); + write_dataset(file_id, "energy", primary_source_.E); + write_dataset(file_id, "xyz", primary_source_.r); + write_dataset(file_id, "uvw", primary_source_.u); // Close file file_close(file_id); diff --git a/src/simulation.cpp b/src/simulation.cpp index 086d74059..2176e7d5c 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -69,9 +69,10 @@ int openmc_simulation_init() // Determine how much work each process should do calculate_work(); - // Allocate source bank, and for eigenvalue simulations also allocate the - // fission bank - allocate_banks(); + // Allocate source and fission banks for eigenvalue simulations + if (settings::run_mode == RunMode::EIGENVALUE) { + allocate_banks(); + } // If doing an event-based simulation, intialize the particle buffer // and event queues @@ -105,7 +106,10 @@ int openmc_simulation_init() load_state_point(); write_message("Resuming simulation...", 6); } else { - initialize_source(); + //Only initialize primary source bank for eigenvalue simulations + if (settings::run_mode == RunMode::EIGENVALUE) { + initialize_source(); + } } // Display header @@ -271,10 +275,8 @@ void allocate_banks() { // Allocate source bank simulation::source_bank.resize(simulation::work_per_rank); - - if (settings::run_mode == RunMode::EIGENVALUE) { - init_fission_bank(3*simulation::work_per_rank); - } + // Allocate fission bank + init_fission_bank(3*simulation::work_per_rank); } void initialize_batch() @@ -350,7 +352,7 @@ void finalize_batch() && !settings::cmfd_run) { if (contains(settings::sourcepoint_batch, simulation::current_batch) && settings::source_write && !settings::source_separate) { - bool b = true; + bool b = (settings::run_mode == RunMode::EIGENVALUE) ? true : false; openmc_statepoint_write(nullptr, &b); } else { bool b = false; @@ -358,16 +360,18 @@ void finalize_batch() } } - // Write out a separate source point if it's been specified for this batch - if (contains(settings::sourcepoint_batch, simulation::current_batch) - && settings::source_write && settings::source_separate) { - write_source_point(nullptr); - } + if (settings::run_mode == RunMode::EIGENVALUE) { + // Write out a separate source point if it's been specified for this batch + if (contains(settings::sourcepoint_batch, simulation::current_batch) + && settings::source_write && settings::source_separate) { + write_source_point(nullptr); + } - // Write a continously-overwritten source point if requested. - if (settings::source_latest) { - auto filename = settings::path_output + "source.h5"; - write_source_point(filename.c_str()); + // Write a continously-overwritten source point if requested. + if (settings::source_latest) { + auto filename = settings::path_output + "source.h5"; + write_source_point(filename.c_str()); + } } } @@ -429,18 +433,24 @@ void finalize_generation() } } - } else if (settings::run_mode == RunMode::FIXED_SOURCE) { - // For fixed-source mode, we need to sample the external source - simulation::time_sample_source.start(); - fill_source_bank_fixedsource(); - simulation::time_sample_source.stop(); } } void initialize_history(Particle* p, int64_t index_source) { // set defaults - p->from_source(&simulation::source_bank[index_source - 1]); + if(settings::run_mode == RunMode::FIXED_SOURCE) { + // initialize random number seed + int64_t id = (simulation::total_gen + overall_generation() - 1)*settings::n_particles + + simulation::work_index[mpi::rank] + index_source; + uint64_t seed = init_seed(id, STREAM_SOURCE); + // sample external source distribution then set + Particle::Bank site = sample_external_source(&seed); + p->from_source(&site); + } else if (settings::run_mode == RunMode::EIGENVALUE) { + // set defaults for eigenvalue simulations from primary bank + p->from_source(&simulation::source_bank[index_source - 1]); + } p->current_work_ = index_source; // set identifier for particle diff --git a/src/source.cpp b/src/source.cpp index 96175804c..c0ee6a853 100644 --- a/src/source.cpp +++ b/src/source.cpp @@ -396,21 +396,4 @@ void fill_source_bank_custom_source() #endif } -void fill_source_bank_fixedsource() -{ - if (settings::path_source.empty() && settings::path_source_library.empty()) { - for (int64_t i = 0; i < simulation::work_per_rank; ++i) { - // initialize random number seed - int64_t id = (simulation::total_gen + overall_generation()) * - settings::n_particles + simulation::work_index[mpi::rank] + i + 1; - uint64_t seed = init_seed(id, STREAM_SOURCE); - - // sample external source distribution - simulation::source_bank[i] = sample_external_source(&seed); - } - } else if (settings::path_source.empty() && !settings::path_source_library.empty()) { - fill_source_bank_custom_source(); - } -} - } // namespace openmc diff --git a/src/state_point.cpp b/src/state_point.cpp index 011581768..a3a05197e 100644 --- a/src/state_point.cpp +++ b/src/state_point.cpp @@ -387,6 +387,7 @@ void load_state_point() // Logical flag for source present in statepoint file bool source_present; + read_attribute(file_id, "source_present", source_present); // Read information specific to eigenvalue run if (settings::run_mode == RunMode::EIGENVALUE) { @@ -397,7 +398,6 @@ void load_state_point() settings::n_inactive = std::max(settings::n_inactive, temp); // Check to make sure source bank is present - read_attribute(file_id, "source_present", source_present); if (settings::path_sourcepoint == settings::path_statepoint && !source_present) { fatal_error("Source bank must be contained in statepoint restart file"); @@ -409,7 +409,11 @@ void load_state_point() // Set k_sum, keff, and current_batch based on whether restart file is part // of active cycle or inactive cycle - restart_set_keff(); + if (settings::run_mode == RunMode::EIGENVALUE) { + restart_set_keff(); + } + + // Set current batch number simulation::current_batch = simulation::restart_batch; // Read tallies to master. If we are using Parallel HDF5, all processes