Skip to content
Merged
Show file tree
Hide file tree
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
moved volume tasks into the SourceRegion object.
  • Loading branch information
jtramm committed Jan 30, 2025
commit 8d1cd79c42a7fed492801f9d5c58a120e25f305d
6 changes: 0 additions & 6 deletions include/openmc/random_ray/flat_source_domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,6 @@ class FlatSourceDomain {
// groups x energy groups
vector<double> sigma_s_;

// A 1D array over all source regions, with each source region having a set of
// volume tally tasks. This more complicated data structure is convenient for
// ensuring that volumes are only tallied once per source region, regardless
// of how many energy groups are used for tallying.
vector<std::unordered_set<TallyTask, TallyTask::HashFunctor>> volume_task_;

// The abstract container holding all source region-specific data
SourceRegionContainer source_regions_;

Expand Down
22 changes: 21 additions & 1 deletion include/openmc/random_ray/source_region.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ class SourceRegion {
// tasks
vector<vector<TallyTask>> tally_task_;

// A set of volume tally tasks. This more complicated data structure is
// convenient for ensuring that volumes are only tallied once per source
// region, regardless of how many energy groups are used for tallying.
std::unordered_set<TallyTask, TallyTask::HashFunctor> volume_task_;

}; // class SourceRegion

class SourceRegionContainer {
Expand Down Expand Up @@ -168,7 +173,6 @@ class SourceRegionContainer {
Position& position(int64_t sr) { return position_[sr]; }
const Position& position(int64_t sr) const { return position_[sr]; }

// Conditional field accessors (only if is_linear_)
Position& centroid(int64_t sr) { return centroid_[sr]; }
const Position& centroid(int64_t sr) const { return centroid_[sr]; }

Expand Down Expand Up @@ -321,6 +325,16 @@ class SourceRegionContainer {
return tally_task_[se];
}

std::unordered_set<TallyTask, TallyTask::HashFunctor>& volume_task(int64_t sr)
{
return volume_task_[sr];
}
const std::unordered_set<TallyTask, TallyTask::HashFunctor>& volume_task(
int64_t sr) const
{
return volume_task_[sr];
}

//----------------------------------------------------------------------------
// Public Methods

Expand Down Expand Up @@ -365,6 +379,12 @@ class SourceRegionContainer {
// Tally tasks
vector<vector<TallyTask>> tally_task_;

// A 1D array over all source regions, with each source region having a set of
// volume tally tasks. This more complicated data structure is convenient for
// ensuring that volumes are only tallied once per source region, regardless
// of how many energy groups are used for tallying.
vector<std::unordered_set<TallyTask, TallyTask::HashFunctor>> volume_task_;

//----------------------------------------------------------------------------
// Private Methods

Expand Down
5 changes: 2 additions & 3 deletions src/random_ray/flat_source_domain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ FlatSourceDomain::FlatSourceDomain() : negroups_(data::mg.num_energy_groups_)
}

// Initialize cell-wise arrays
volume_task_.resize(n_source_regions_);
bool is_linear = RandomRay::source_shape_ != RandomRaySourceShape::FLAT;
source_regions_ = SourceRegionContainer(negroups_, is_linear);
source_regions_.assign(n_source_regions_, SourceRegion(negroups_, is_linear));
Expand Down Expand Up @@ -465,7 +464,7 @@ void FlatSourceDomain::convert_source_regions_to_tallies()

// Also add this task to the list of volume tasks for this source
// region.
volume_task_[sr].insert(task);
source_regions_.volume_task(sr).insert(task);
}
}
}
Expand Down Expand Up @@ -619,7 +618,7 @@ void FlatSourceDomain::random_ray_tally()
// for normalizing the flux. We store this volume in a separate tensor.
// We only contribute to each volume tally bin once per FSR.
if (volume_normalized_flux_tallies_) {
for (const auto& task : volume_task_[sr]) {
for (const auto& task : source_regions_.volume_task(sr)) {
if (task.score_type == SCORE_FLUX) {
#pragma omp atomic
tally_volumes_[task.tally_idx](task.filter_idx, task.score_idx) +=
Expand Down
2 changes: 2 additions & 0 deletions src/random_ray/source_region.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void SourceRegionContainer::push_back(const SourceRegion& sr)
position_recorded_.push_back(sr.position_recorded_);
external_source_present_.push_back(sr.external_source_present_);
position_.push_back(sr.position_);
volume_task_.push_back(sr.volume_task_);

// Only store these fields if is_linear_ is true
if (is_linear_) {
Expand Down Expand Up @@ -119,6 +120,7 @@ void SourceRegionContainer::assign(
}

tally_task_.clear();
volume_task_.clear();

// Fill with copies of source_region
for (int i = 0; i < n_source_regions; ++i) {
Expand Down