Skip to content

Commit a6db05a

Browse files
authored
Optimize Mapping of Random Ray Source Regions to Tallies (#3465)
1 parent 15dfe7e commit a6db05a

4 files changed

Lines changed: 17 additions & 17 deletions

File tree

include/openmc/random_ray/flat_source_domain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class FlatSourceDomain {
3434

3535
int64_t add_source_to_scalar_flux();
3636
virtual void batch_reset();
37-
void convert_source_regions_to_tallies();
37+
void convert_source_regions_to_tallies(int64_t start_sr_id);
3838
void reset_tally_volumes();
3939
void random_ray_tally();
4040
virtual void accumulate_iteration_flux();

src/random_ray/flat_source_domain.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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();

src/random_ray/random_ray_simulation.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,9 @@ void RandomRaySimulation::simulate()
508508
domain_->accumulate_iteration_flux();
509509

510510
// Generate mapping between source regions and tallies
511-
if (!domain_->mapped_all_tallies_) {
512-
domain_->convert_source_regions_to_tallies();
511+
if (!domain_->mapped_all_tallies_ &&
512+
!RandomRay::mesh_subdivision_enabled_) {
513+
domain_->convert_source_regions_to_tallies(0);
513514
}
514515

515516
// Use above mapping to contribute FSR flux data to appropriate

src/random_ray/source_region.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,11 @@ void SourceRegionContainer::adjoint_reset()
259259
MomentMatrix {0.0, 0.0, 0.0, 0.0, 0.0, 0.0});
260260
std::fill(mom_matrix_t_.begin(), mom_matrix_t_.end(),
261261
MomentMatrix {0.0, 0.0, 0.0, 0.0, 0.0, 0.0});
262-
for (auto& task_set : volume_task_) {
263-
task_set.clear();
264-
}
265262
std::fill(scalar_flux_old_.begin(), scalar_flux_old_.end(), 0.0);
266263
std::fill(scalar_flux_new_.begin(), scalar_flux_new_.end(), 0.0);
267264
std::fill(scalar_flux_final_.begin(), scalar_flux_final_.end(), 0.0);
268265
std::fill(source_.begin(), source_.end(), 0.0f);
269266
std::fill(external_source_.begin(), external_source_.end(), 0.0f);
270-
271267
std::fill(source_gradients_.begin(), source_gradients_.end(),
272268
MomentArray {0.0, 0.0, 0.0});
273269
std::fill(flux_moments_old_.begin(), flux_moments_old_.end(),
@@ -276,10 +272,6 @@ void SourceRegionContainer::adjoint_reset()
276272
MomentArray {0.0, 0.0, 0.0});
277273
std::fill(flux_moments_t_.begin(), flux_moments_t_.end(),
278274
MomentArray {0.0, 0.0, 0.0});
279-
280-
for (auto& task_set : tally_task_) {
281-
task_set.clear();
282-
}
283275
}
284276

285277
} // namespace openmc

0 commit comments

Comments
 (0)