Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix stat:sum to use total source particles, not file particle count
Per issue #3514 requirements, stat:sum should contain the original number
of source particles in the simulation, not the number written to the file.

Changed implementation to calculate:
  (n_batches - n_inactive) * n_particles
instead of using bank_index.back()

This ensures proper weight normalization when merging MCPL files.
  • Loading branch information
bpolania committed Aug 6, 2025
commit a255618c4b4387bc0714fe7a204169a0689f1062
12 changes: 8 additions & 4 deletions src/mcpl_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,13 +527,17 @@ void write_mcpl_source_point(const char* filename, span<SourceSite> source_bank,
if (file_id) {
// Update stat:sum with actual particle count before closing (issue #3514)
// This represents the original number of source particles in the
// simulation
// simulation (not the number of particles in the file)
if (g_mcpl_api->hdr_add_stat_sum) {
// If bank_index is empty, statistics are unavailable, use -1
int64_t total_particles = bank_index.empty() ? -1 : bank_index.back();
// Calculate total source particles from active batches
// Per issue #3514: this should be the original number of source particles,
// not the number written to the file
int64_t total_source_particles =
static_cast<int64_t>(settings::n_batches - settings::n_inactive) *
settings::n_particles;
// Update with actual count - this overwrites the initial -1 value
g_mcpl_api->hdr_add_stat_sum(
file_id, "openmc_np1", static_cast<double>(total_particles));
file_id, "openmc_np1", static_cast<double>(total_source_particles));
}

g_mcpl_api->close_outfile(file_id);
Expand Down