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

openmc-dev / openmc / 20898701121

11 Jan 2026 05:00PM UTC coverage: 82.202% (+0.004%) from 82.198%
20898701121

Pull #3720

github

web-flow
Merge 7c2b2cc86 into 37e2feb34
Pull Request #3720: Support cell densities in the random ray solver

17111 of 23671 branches covered (72.29%)

Branch coverage included in aggregate %.

44 of 49 new or added lines in 6 files covered. (89.8%)

1 existing line in 1 file now uncovered.

55279 of 64393 relevant lines covered (85.85%)

43679107.91 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)
38,407,400✔
13
  : negroups_(sr.scalar_flux_old_.size()), material_(&sr.material_),
38,407,400✔
14
    density_mult_(&sr.density_mult_), is_small_(&sr.is_small_),
38,407,400✔
15
    n_hits_(&sr.n_hits_), is_linear_(sr.source_gradients_.size() > 0),
76,814,800✔
16
    lock_(&sr.lock_), volume_(&sr.volume_), volume_t_(&sr.volume_t_),
38,407,400✔
17
    volume_sq_(&sr.volume_sq_), volume_sq_t_(&sr.volume_sq_t_),
38,407,400✔
18
    volume_naive_(&sr.volume_naive_),
38,407,400✔
19
    position_recorded_(&sr.position_recorded_),
38,407,400✔
20
    external_source_present_(&sr.external_source_present_),
38,407,400✔
21
    position_(&sr.position_), centroid_(&sr.centroid_),
38,407,400✔
22
    centroid_iteration_(&sr.centroid_iteration_), centroid_t_(&sr.centroid_t_),
38,407,400✔
23
    mom_matrix_(&sr.mom_matrix_), mom_matrix_t_(&sr.mom_matrix_t_),
38,407,400✔
24
    volume_task_(&sr.volume_task_), mesh_(&sr.mesh_),
38,407,400✔
25
    parent_sr_(&sr.parent_sr_), scalar_flux_old_(sr.scalar_flux_old_.data()),
38,407,400✔
26
    scalar_flux_new_(sr.scalar_flux_new_.data()), source_(sr.source_.data()),
38,407,400✔
27
    external_source_(sr.external_source_.data()),
38,407,400✔
28
    scalar_flux_final_(sr.scalar_flux_final_.data()),
38,407,400✔
29
    source_gradients_(sr.source_gradients_.data()),
38,407,400✔
30
    flux_moments_old_(sr.flux_moments_old_.data()),
38,407,400✔
31
    flux_moments_new_(sr.flux_moments_new_.data()),
38,407,400✔
32
    flux_moments_t_(sr.flux_moments_t_.data()),
38,407,400✔
33
    tally_task_(sr.tally_task_.data())
76,814,800✔
34
{}
38,407,400✔
35

36
//==============================================================================
37
// SourceRegion implementation
38
//==============================================================================
39
SourceRegion::SourceRegion(int negroups, bool is_linear)
2,362,777✔
40
{
41
  if (settings::run_mode == RunMode::EIGENVALUE) {
2,362,777✔
42
    // If in eigenvalue mode, set starting flux to guess of 1
43
    scalar_flux_old_.assign(negroups, 1.0);
52,019✔
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,362,777✔
52
  source_.assign(negroups, 0.0);
2,362,777✔
53
  scalar_flux_final_.assign(negroups, 0.0);
2,362,777✔
54

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

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

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

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

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

99
  // Energy-dependent fields
100
  for (int g = 0; g < negroups_; ++g) {
4,853,813✔
101
    scalar_flux_old_.push_back(sr.scalar_flux_old_[g]);
2,592,478✔
102
    scalar_flux_new_.push_back(sr.scalar_flux_new_[g]);
2,592,478✔
103
    scalar_flux_final_.push_back(sr.scalar_flux_final_[g]);
2,592,478✔
104
    source_.push_back(sr.source_[g]);
2,592,478✔
105
    if (settings::run_mode == RunMode::FIXED_SOURCE) {
2,592,478✔
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,592,478✔
111
      source_gradients_.push_back(sr.source_gradients_[g]);
856,284✔
112
      flux_moments_old_.push_back(sr.flux_moments_old_[g]);
856,284✔
113
      flux_moments_new_.push_back(sr.flux_moments_new_[g]);
856,284✔
114
      flux_moments_t_.push_back(sr.flux_moments_t_[g]);
856,284✔
115
    }
116

117
    // Tally tasks
118
    tally_task_.emplace_back(sr.tally_task_[g]);
2,592,478✔
119
  }
120
}
2,261,335✔
121

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

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

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

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

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

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

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

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

213
  if (handle.is_linear_) {
1,291,569,507✔
214
    handle.centroid_ = &centroid(sr);
649,737,011✔
215
    handle.centroid_iteration_ = &centroid_iteration(sr);
649,737,011✔
216
    handle.centroid_t_ = &centroid_t(sr);
649,737,011✔
217
    handle.mom_matrix_ = &mom_matrix(sr);
649,737,011✔
218
    handle.mom_matrix_t_ = &mom_matrix_t(sr);
649,737,011✔
219
    handle.source_gradients_ = &source_gradients(sr, 0);
649,737,011✔
220
    handle.flux_moments_old_ = &flux_moments_old(sr, 0);
649,737,011✔
221
    handle.flux_moments_new_ = &flux_moments_new(sr, 0);
649,737,011✔
222
    handle.flux_moments_t_ = &flux_moments_t(sr, 0);
649,737,011✔
223
  }
224

225
  return handle;
1,291,569,507✔
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