@@ -421,7 +421,12 @@ double FlatSourceDomain::compute_k_eff(double k_eff_old) const
421421// be passed back to the caller to alert them that this function doesn't
422422// need to be called for the remainder of the simulation.
423423
424- void FlatSourceDomain::convert_source_regions_to_tallies ()
424+ // It takes as an argument the starting index in the source region array,
425+ // and it will operate from that index until the end of the array. This
426+ // is useful as it can be called for both explicit user source regions or
427+ // when a source region mesh is overlaid.
428+
429+ void FlatSourceDomain::convert_source_regions_to_tallies (int64_t start_sr_id)
425430{
426431 openmc::simulation::time_tallies.start ();
427432
@@ -430,7 +435,7 @@ void FlatSourceDomain::convert_source_regions_to_tallies()
430435
431436// Attempt to generate mapping for all source regions
432437#pragma omp parallel for
433- for (int64_t sr = 0 ; sr < n_source_regions (); sr++) {
438+ for (int64_t sr = start_sr_id ; sr < n_source_regions (); sr++) {
434439
435440 // If this source region has not been hit by a ray yet, then
436441 // we aren't going to be able to map it, so skip it.
@@ -468,7 +473,7 @@ void FlatSourceDomain::convert_source_regions_to_tallies()
468473 // Loop over all active tallies. This logic is essentially identical
469474 // to what happens when scanning for applicable tallies during
470475 // MC transport.
471- for (auto i_tally : model::active_tallies ) {
476+ for (int i_tally = 0 ; i_tally < model::tallies. size (); i_tally++ ) {
472477 Tally& tally {*model::tallies[i_tally]};
473478
474479 // Initialize an iterator over valid filter bin combinations.
@@ -1525,16 +1530,18 @@ void FlatSourceDomain::finalize_discovered_source_regions()
15251530 // order due to shared memory threading.
15261531 std::sort (keys.begin (), keys.end ());
15271532
1533+ // Remember the index of the first new source region
1534+ int64_t start_sr_id = source_regions_.n_source_regions ();
1535+
15281536 // Append the source regions in the sorted key order.
15291537 for (const auto & key : keys) {
15301538 const SourceRegion& sr = discovered_source_regions_[key];
15311539 source_region_map_[key] = source_regions_.n_source_regions ();
15321540 source_regions_.push_back (sr);
15331541 }
15341542
1535- // If any new source regions were discovered, we need to update the
1536- // tally mapping between source regions and tally bins.
1537- mapped_all_tallies_ = false ;
1543+ // Map all new source regions to tallies
1544+ convert_source_regions_to_tallies (start_sr_id);
15381545 }
15391546
15401547 discovered_source_regions_.clear ();
0 commit comments