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

This commit is contained in:
davidjohnlong 2020-03-05 10:48:36 +00:00
parent 50a9a0ac3b
commit 0ae1077a39
6 changed files with 62 additions and 50 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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