• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

openmc-dev / openmc / 21533365354

30 Jan 2026 10:48PM UTC coverage: 81.979% (-3.2%) from 85.162%
21533365354

Pull #3453

github

web-flow
Merge de22ee16c into 7b4617aff
Pull Request #3453: Secondary energy filter

17272 of 24046 branches covered (71.83%)

Branch coverage included in aggregate %.

50 of 52 new or added lines in 8 files covered. (96.15%)

4544 existing lines in 133 files now uncovered.

55847 of 65146 relevant lines covered (85.73%)

44003337.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.4
/src/random_ray/source_region.cpp
1
#include "openmc/random_ray/source_region.h"
2

3
#include "openmc/error.h"
4
#include "openmc/message_passing.h"
5
#include "openmc/simulation.h"
6

7
namespace openmc {
8

9
//==============================================================================
10
// SourceRegionHandle implementation
11
//==============================================================================
12
SourceRegionHandle::SourceRegionHandle(SourceRegion& sr)
40,352,057✔
13
  : negroups_(sr.scalar_flux_old_.size()), material_(&sr.material_),
40,352,057✔
14
    density_mult_(&sr.density_mult_), is_small_(&sr.is_small_),
40,352,057✔
15
    n_hits_(&sr.n_hits_), is_linear_(sr.source_gradients_.size() > 0),
80,704,114✔
16
    lock_(&sr.lock_), volume_(&sr.volume_), volume_t_(&sr.volume_t_),
40,352,057✔
17
    volume_sq_(&sr.volume_sq_), volume_sq_t_(&sr.volume_sq_t_),
40,352,057✔
18
    volume_naive_(&sr.volume_naive_),
40,352,057✔
19
    position_recorded_(&sr.position_recorded_),
40,352,057✔
20
    external_source_present_(&sr.external_source_present_),
40,352,057✔
21
    position_(&sr.position_), centroid_(&sr.centroid_),
40,352,057✔
22
    centroid_iteration_(&sr.centroid_iteration_), centroid_t_(&sr.centroid_t_),
40,352,057✔
23
    mom_matrix_(&sr.mom_matrix_), mom_matrix_t_(&sr.mom_matrix_t_),
40,352,057✔
24
    volume_task_(&sr.volume_task_), mesh_(&sr.mesh_),
40,352,057✔
25
    parent_sr_(&sr.parent_sr_), scalar_flux_old_(sr.scalar_flux_old_.data()),
40,352,057✔
26
    scalar_flux_new_(sr.scalar_flux_new_.data()), source_(sr.source_.data()),
40,352,057✔
27
    external_source_(sr.external_source_.data()),
40,352,057✔
28
    scalar_flux_final_(sr.scalar_flux_final_.data()),
40,352,057✔
29
    source_gradients_(sr.source_gradients_.data()),
40,352,057✔
30
    flux_moments_old_(sr.flux_moments_old_.data()),
40,352,057✔
31
    flux_moments_new_(sr.flux_moments_new_.data()),
40,352,057✔
32
    flux_moments_t_(sr.flux_moments_t_.data()),
40,352,057✔
33
    tally_task_(sr.tally_task_.data())
80,704,114✔
34
{}
40,352,057✔
35

36
//==============================================================================
37
// SourceRegion implementation
38
//==============================================================================
39
SourceRegion::SourceRegion(int negroups, bool is_linear)
2,363,173✔
40
{
41
  if (settings::run_mode == RunMode::EIGENVALUE) {
2,363,173✔
42
    // If in eigenvalue mode, set starting flux to guess of 1
43
    scalar_flux_old_.assign(negroups, 1.0);
52,415✔
44
  } else {
45
    // If in fixed source mode, set starting flux to guess of zero
46
    // and initialize external source arrays
47
    scalar_flux_old_.assign(negroups, 0.0);
2,310,758✔
48
    external_source_.assign(negroups, 0.0);
2,310,758✔
49
  }
50

51
  scalar_flux_new_.assign(negroups, 0.0);
2,363,173✔
52
  source_.assign(negroups, 0.0);
2,363,173✔
53
  scalar_flux_final_.assign(negroups, 0.0);
2,363,173✔
54

55
  tally_task_.resize(negroups);
2,363,173✔
56
  if (is_linear) {
2,363,173✔
57
    source_gradients_.resize(negroups);
821,458✔
58
    flux_moments_old_.resize(negroups);
821,458✔
59
    flux_moments_new_.resize(negroups);
821,458✔
60
    flux_moments_t_.resize(negroups);
821,458✔
61
  }
62
}
2,363,173✔
63

64
//==============================================================================
65
// SourceRegionContainer implementation
66
//==============================================================================
67

68
void SourceRegionContainer::push_back(const SourceRegion& sr)
2,261,731✔
69
{
70
  n_source_regions_++;
2,261,731✔
71

72
  // Scalar fields
73
  material_.push_back(sr.material_);
2,261,731✔
74
  density_mult_.push_back(sr.density_mult_);
2,261,731✔
75
  is_small_.push_back(sr.is_small_);
2,261,731✔
76
  n_hits_.push_back(sr.n_hits_);
2,261,731✔
77
  lock_.push_back(sr.lock_);
2,261,731✔
78
  volume_.push_back(sr.volume_);
2,261,731✔
79
  volume_t_.push_back(sr.volume_t_);
2,261,731✔
80
  volume_sq_.push_back(sr.volume_sq_);
2,261,731✔
81
  volume_sq_t_.push_back(sr.volume_sq_t_);
2,261,731✔
82
  volume_naive_.push_back(sr.volume_naive_);
2,261,731✔
83
  position_recorded_.push_back(sr.position_recorded_);
2,261,731✔
84
  external_source_present_.push_back(sr.external_source_present_);
2,261,731✔
85
  position_.push_back(sr.position_);
2,261,731✔
86
  volume_task_.push_back(sr.volume_task_);
2,261,731✔
87
  mesh_.push_back(sr.mesh_);
2,261,731✔
88
  parent_sr_.push_back(sr.parent_sr_);
2,261,731✔
89

90
  // Only store these fields if is_linear_ is true
91
  if (is_linear_) {
2,261,731✔
92
    centroid_.push_back(sr.centroid_);
788,304✔
93
    centroid_iteration_.push_back(sr.centroid_iteration_);
788,304✔
94
    centroid_t_.push_back(sr.centroid_t_);
788,304✔
95
    mom_matrix_.push_back(sr.mom_matrix_);
788,304✔
96
    mom_matrix_t_.push_back(sr.mom_matrix_t_);
788,304✔
97
  }
98

99
  // Energy-dependent fields
100
  for (int g = 0; g < negroups_; ++g) {
4,855,001✔
101
    scalar_flux_old_.push_back(sr.scalar_flux_old_[g]);
2,593,270✔
102
    scalar_flux_new_.push_back(sr.scalar_flux_new_[g]);
2,593,270✔
103
    scalar_flux_final_.push_back(sr.scalar_flux_final_[g]);
2,593,270✔
104
    source_.push_back(sr.source_[g]);
2,593,270✔
105
    if (settings::run_mode == RunMode::FIXED_SOURCE) {
2,593,270✔
106
      external_source_.push_back(sr.external_source_[g]);
2,255,350✔
107
    }
108

109
    // Only store these fields if is_linear_ is true
110
    if (is_linear_) {
2,593,270✔
111
      source_gradients_.push_back(sr.source_gradients_[g]);
857,076✔
112
      flux_moments_old_.push_back(sr.flux_moments_old_[g]);
857,076✔
113
      flux_moments_new_.push_back(sr.flux_moments_new_[g]);
857,076✔
114
      flux_moments_t_.push_back(sr.flux_moments_t_[g]);
857,076✔
115
    }
116

117
    // Tally tasks
118
    tally_task_.emplace_back(sr.tally_task_[g]);
2,593,270✔
119
  }
120
}
2,261,731✔
121

UNCOV
122
void SourceRegionContainer::assign(
×
123
  int n_source_regions, const SourceRegion& source_region)
124
{
125
  // Clear existing data
UNCOV
126
  n_source_regions_ = 0;
×
UNCOV
127
  material_.clear();
×
UNCOV
128
  density_mult_.clear();
×
UNCOV
129
  is_small_.clear();
×
UNCOV
130
  n_hits_.clear();
×
UNCOV
131
  lock_.clear();
×
UNCOV
132
  volume_.clear();
×
UNCOV
133
  volume_t_.clear();
×
UNCOV
134
  volume_sq_.clear();
×
UNCOV
135
  volume_sq_t_.clear();
×
UNCOV
136
  volume_naive_.clear();
×
UNCOV
137
  position_recorded_.clear();
×
UNCOV
138
  external_source_present_.clear();
×
UNCOV
139
  position_.clear();
×
UNCOV
140
  mesh_.clear();
×
UNCOV
141
  parent_sr_.clear();
×
142

UNCOV
143
  if (is_linear_) {
×
UNCOV
144
    centroid_.clear();
×
UNCOV
145
    centroid_iteration_.clear();
×
UNCOV
146
    centroid_t_.clear();
×
UNCOV
147
    mom_matrix_.clear();
×
UNCOV
148
    mom_matrix_t_.clear();
×
149
  }
150

UNCOV
151
  scalar_flux_old_.clear();
×
UNCOV
152
  scalar_flux_new_.clear();
×
UNCOV
153
  scalar_flux_final_.clear();
×
UNCOV
154
  source_.clear();
×
UNCOV
155
  external_source_.clear();
×
156

UNCOV
157
  if (is_linear_) {
×
UNCOV
158
    source_gradients_.clear();
×
UNCOV
159
    flux_moments_old_.clear();
×
UNCOV
160
    flux_moments_new_.clear();
×
UNCOV
161
    flux_moments_t_.clear();
×
162
  }
163

UNCOV
164
  tally_task_.clear();
×
UNCOV
165
  volume_task_.clear();
×
166

167
  // Fill with copies of source_region
UNCOV
168
  for (int i = 0; i < n_source_regions; ++i) {
×
UNCOV
169
    push_back(source_region);
×
170
  }
UNCOV
171
}
×
172

173
void SourceRegionContainer::flux_swap()
12,662✔
174
{
175
  scalar_flux_old_.swap(scalar_flux_new_);
12,662✔
176
  if (is_linear_) {
12,662✔
177
    flux_moments_old_.swap(flux_moments_new_);
7,205✔
178
  }
179
}
12,662✔
180

181
SourceRegionHandle SourceRegionContainer::get_source_region_handle(int64_t sr)
1,309,103,628✔
182
{
183
  SourceRegionHandle handle;
1,309,103,628✔
184
  handle.negroups_ = negroups();
1,309,103,628✔
185
  handle.material_ = &material(sr);
1,309,103,628✔
186
  handle.density_mult_ = &density_mult(sr);
1,309,103,628✔
187
  handle.is_small_ = &is_small(sr);
1,309,103,628✔
188
  handle.n_hits_ = &n_hits(sr);
1,309,103,628✔
189
  handle.is_linear_ = is_linear();
1,309,103,628✔
190
  handle.lock_ = &lock(sr);
1,309,103,628✔
191
  handle.volume_ = &volume(sr);
1,309,103,628✔
192
  handle.volume_t_ = &volume_t(sr);
1,309,103,628✔
193
  handle.volume_sq_ = &volume_sq(sr);
1,309,103,628✔
194
  handle.volume_sq_t_ = &volume_sq_t(sr);
1,309,103,628✔
195
  handle.volume_naive_ = &volume_naive(sr);
1,309,103,628✔
196
  handle.position_recorded_ = &position_recorded(sr);
1,309,103,628✔
197
  handle.external_source_present_ = &external_source_present(sr);
1,309,103,628✔
198
  handle.position_ = &position(sr);
1,309,103,628✔
199
  handle.volume_task_ = &volume_task(sr);
1,309,103,628✔
200
  handle.mesh_ = &mesh(sr);
1,309,103,628✔
201
  handle.parent_sr_ = &parent_sr(sr);
1,309,103,628✔
202
  handle.scalar_flux_old_ = &scalar_flux_old(sr, 0);
1,309,103,628✔
203
  handle.scalar_flux_new_ = &scalar_flux_new(sr, 0);
1,309,103,628✔
204
  handle.source_ = &source(sr, 0);
1,309,103,628✔
205
  if (settings::run_mode == RunMode::FIXED_SOURCE) {
1,309,103,628✔
206
    handle.external_source_ = &external_source(sr, 0);
1,093,381,231✔
207
  } else {
208
    handle.external_source_ = nullptr;
215,722,397✔
209
  }
210
  handle.scalar_flux_final_ = &scalar_flux_final(sr, 0);
1,309,103,628✔
211
  handle.tally_task_ = &tally_task(sr, 0);
1,309,103,628✔
212

213
  if (handle.is_linear_) {
1,309,103,628✔
214
    handle.centroid_ = &centroid(sr);
667,271,132✔
215
    handle.centroid_iteration_ = &centroid_iteration(sr);
667,271,132✔
216
    handle.centroid_t_ = &centroid_t(sr);
667,271,132✔
217
    handle.mom_matrix_ = &mom_matrix(sr);
667,271,132✔
218
    handle.mom_matrix_t_ = &mom_matrix_t(sr);
667,271,132✔
219
    handle.source_gradients_ = &source_gradients(sr, 0);
667,271,132✔
220
    handle.flux_moments_old_ = &flux_moments_old(sr, 0);
667,271,132✔
221
    handle.flux_moments_new_ = &flux_moments_new(sr, 0);
667,271,132✔
222
    handle.flux_moments_t_ = &flux_moments_t(sr, 0);
667,271,132✔
223
  }
224

225
  return handle;
1,309,103,628✔
226
}
227

228
void SourceRegionContainer::adjoint_reset()
81✔
229
{
230
  std::fill(n_hits_.begin(), n_hits_.end(), 0);
81✔
231
  std::fill(volume_.begin(), volume_.end(), 0.0);
81✔
232
  std::fill(volume_t_.begin(), volume_t_.end(), 0.0);
81✔
233
  std::fill(volume_sq_.begin(), volume_sq_.end(), 0.0);
81✔
234
  std::fill(volume_sq_t_.begin(), volume_sq_t_.end(), 0.0);
81✔
235
  std::fill(volume_naive_.begin(), volume_naive_.end(), 0.0);
81✔
236
  std::fill(
81✔
237
    external_source_present_.begin(), external_source_present_.end(), 0);
81✔
238
  std::fill(external_source_.begin(), external_source_.end(), 0.0);
81✔
239
  std::fill(centroid_.begin(), centroid_.end(), Position {0.0, 0.0, 0.0});
81✔
240
  std::fill(centroid_iteration_.begin(), centroid_iteration_.end(),
81✔
241
    Position {0.0, 0.0, 0.0});
81✔
242
  std::fill(centroid_t_.begin(), centroid_t_.end(), Position {0.0, 0.0, 0.0});
81✔
243
  std::fill(mom_matrix_.begin(), mom_matrix_.end(),
81✔
244
    MomentMatrix {0.0, 0.0, 0.0, 0.0, 0.0, 0.0});
81✔
245
  std::fill(mom_matrix_t_.begin(), mom_matrix_t_.end(),
81✔
246
    MomentMatrix {0.0, 0.0, 0.0, 0.0, 0.0, 0.0});
81✔
247
  if (settings::run_mode == RunMode::FIXED_SOURCE) {
81✔
248
    std::fill(scalar_flux_old_.begin(), scalar_flux_old_.end(), 0.0);
65✔
249
  } else {
250
    std::fill(scalar_flux_old_.begin(), scalar_flux_old_.end(), 1.0);
16✔
251
  }
252
  std::fill(scalar_flux_new_.begin(), scalar_flux_new_.end(), 0.0);
81✔
253
  std::fill(source_.begin(), source_.end(), 0.0f);
81✔
254
  std::fill(external_source_.begin(), external_source_.end(), 0.0f);
81✔
255
  std::fill(source_gradients_.begin(), source_gradients_.end(),
81✔
256
    MomentArray {0.0, 0.0, 0.0});
81✔
257
  std::fill(flux_moments_old_.begin(), flux_moments_old_.end(),
81✔
258
    MomentArray {0.0, 0.0, 0.0});
81✔
259
  std::fill(flux_moments_new_.begin(), flux_moments_new_.end(),
81✔
260
    MomentArray {0.0, 0.0, 0.0});
81✔
261
  std::fill(flux_moments_t_.begin(), flux_moments_t_.end(),
81✔
262
    MomentArray {0.0, 0.0, 0.0});
81✔
263
}
81✔
264

265
} // namespace openmc
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc