mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-26 05:05:30 -04:00
Write surface source files per batch (#3124)
Co-authored-by: Patrick Shriwise <pshriwise@gmail.com> Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
This commit is contained in:
parent
b54de4d761
commit
9686851e7a
14 changed files with 167 additions and 48 deletions
|
|
@ -117,6 +117,7 @@ int openmc_simulation_init()
|
|||
// Reset global variables -- this is done before loading state point (as that
|
||||
// will potentially populate k_generation and entropy)
|
||||
simulation::current_batch = 0;
|
||||
simulation::ssw_current_file = 1;
|
||||
simulation::k_generation.clear();
|
||||
simulation::entropy.clear();
|
||||
openmc_reset();
|
||||
|
|
@ -308,6 +309,7 @@ int n_lost_particles {0};
|
|||
bool need_depletion_rx {false};
|
||||
int restart_batch;
|
||||
bool satisfy_triggers {false};
|
||||
int ssw_current_file;
|
||||
int total_gen {0};
|
||||
double total_weight;
|
||||
int64_t work_per_rank;
|
||||
|
|
@ -337,7 +339,7 @@ void allocate_banks()
|
|||
|
||||
if (settings::surf_source_write) {
|
||||
// Allocate surface source bank
|
||||
simulation::surf_source_bank.reserve(settings::max_surface_particles);
|
||||
simulation::surf_source_bank.reserve(settings::ssw_max_particles);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -345,7 +347,6 @@ void initialize_batch()
|
|||
{
|
||||
// Increment current batch
|
||||
++simulation::current_batch;
|
||||
|
||||
if (settings::run_mode == RunMode::FIXED_SOURCE) {
|
||||
if (settings::solver_type == SolverType::RANDOM_RAY &&
|
||||
simulation::current_batch < settings::n_inactive + 1) {
|
||||
|
|
@ -439,42 +440,49 @@ void finalize_batch()
|
|||
std::string source_point_filename = fmt::format("{0}source.{1:0{2}}",
|
||||
settings::path_output, simulation::current_batch, w);
|
||||
gsl::span<SourceSite> bankspan(simulation::source_bank);
|
||||
if (settings::source_mcpl_write) {
|
||||
write_mcpl_source_point(
|
||||
source_point_filename.c_str(), bankspan, simulation::work_index);
|
||||
} else {
|
||||
write_source_point(
|
||||
source_point_filename.c_str(), bankspan, simulation::work_index);
|
||||
}
|
||||
write_source_point(source_point_filename, bankspan,
|
||||
simulation::work_index, settings::source_mcpl_write);
|
||||
}
|
||||
|
||||
// Write a continously-overwritten source point if requested.
|
||||
if (settings::source_latest) {
|
||||
|
||||
// note: correct file extension appended automatically
|
||||
auto filename = settings::path_output + "source";
|
||||
gsl::span<SourceSite> bankspan(simulation::source_bank);
|
||||
if (settings::source_mcpl_write) {
|
||||
write_mcpl_source_point(
|
||||
filename.c_str(), bankspan, simulation::work_index);
|
||||
} else {
|
||||
write_source_point(filename.c_str(), bankspan, simulation::work_index);
|
||||
}
|
||||
write_source_point(filename.c_str(), bankspan, simulation::work_index,
|
||||
settings::source_mcpl_write);
|
||||
}
|
||||
}
|
||||
|
||||
// Write out surface source if requested.
|
||||
if (settings::surf_source_write &&
|
||||
simulation::current_batch == settings::n_batches) {
|
||||
auto filename = settings::path_output + "surface_source";
|
||||
auto surf_work_index =
|
||||
mpi::calculate_parallel_index_vector(simulation::surf_source_bank.size());
|
||||
gsl::span<SourceSite> surfbankspan(simulation::surf_source_bank.begin(),
|
||||
simulation::surf_source_bank.size());
|
||||
if (settings::surf_mcpl_write) {
|
||||
write_mcpl_source_point(filename.c_str(), surfbankspan, surf_work_index);
|
||||
} else {
|
||||
write_source_point(filename.c_str(), surfbankspan, surf_work_index);
|
||||
simulation::ssw_current_file <= settings::ssw_max_files) {
|
||||
bool last_batch = (simulation::current_batch == settings::n_batches);
|
||||
if (simulation::surf_source_bank.full() || last_batch) {
|
||||
// Determine appropriate filename
|
||||
auto filename = fmt::format("{}surface_source.{}", settings::path_output,
|
||||
simulation::current_batch);
|
||||
if (settings::ssw_max_files == 1 ||
|
||||
(simulation::ssw_current_file == 1 && last_batch)) {
|
||||
filename = settings::path_output + "surface_source";
|
||||
}
|
||||
|
||||
// Get span of source bank and calculate parallel index vector
|
||||
auto surf_work_index = mpi::calculate_parallel_index_vector(
|
||||
simulation::surf_source_bank.size());
|
||||
gsl::span<SourceSite> surfbankspan(simulation::surf_source_bank.begin(),
|
||||
simulation::surf_source_bank.size());
|
||||
|
||||
// Write surface source file
|
||||
write_source_point(
|
||||
filename, surfbankspan, surf_work_index, settings::surf_mcpl_write);
|
||||
|
||||
// Reset surface source bank and increment counter
|
||||
simulation::surf_source_bank.clear();
|
||||
if (!last_batch && settings::ssw_max_files >= 1) {
|
||||
simulation::surf_source_bank.reserve(settings::ssw_max_particles);
|
||||
}
|
||||
++simulation::ssw_current_file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue