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

openmc-dev / openmc / 18537555145

15 Oct 2025 05:37PM UTC coverage: 81.983% (-3.2%) from 85.194%
18537555145

Pull #3417

github

web-flow
Merge 3615a1fcc into e9077b137
Pull Request #3417: Addition of a collision tracking feature

16802 of 23354 branches covered (71.94%)

Branch coverage included in aggregate %.

480 of 522 new or added lines in 13 files covered. (91.95%)

483 existing lines in 53 files now uncovered.

54134 of 63171 relevant lines covered (85.69%)

43199115.04 hits per line

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

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

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

50
  scalar_flux_new_.assign(negroups, 0.0);
2,340,557✔
51
  source_.assign(negroups, 0.0);
2,340,557✔
52
  scalar_flux_final_.assign(negroups, 0.0);
2,340,557✔
53

54
  tally_task_.resize(negroups);
2,340,557✔
55
  if (is_linear) {
2,340,557✔
56
    source_gradients_.resize(negroups);
820,534✔
57
    flux_moments_old_.resize(negroups);
820,534✔
58
    flux_moments_new_.resize(negroups);
820,534✔
59
    flux_moments_t_.resize(negroups);
820,534✔
60
  }
61
}
2,340,557✔
62

63
//==============================================================================
64
// SourceRegionContainer implementation
65
//==============================================================================
66

67
void SourceRegionContainer::push_back(const SourceRegion& sr)
2,239,115✔
68
{
69
  n_source_regions_++;
2,239,115✔
70

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

88
  // Only store these fields if is_linear_ is true
89
  if (is_linear_) {
2,239,115✔
90
    centroid_.push_back(sr.centroid_);
787,380✔
91
    centroid_iteration_.push_back(sr.centroid_iteration_);
787,380✔
92
    centroid_t_.push_back(sr.centroid_t_);
787,380✔
93
    mom_matrix_.push_back(sr.mom_matrix_);
787,380✔
94
    mom_matrix_t_.push_back(sr.mom_matrix_t_);
787,380✔
95
  }
96

97
  // Energy-dependent fields
98
  for (int g = 0; g < negroups_; ++g) {
4,789,573✔
99
    scalar_flux_old_.push_back(sr.scalar_flux_old_[g]);
2,550,458✔
100
    scalar_flux_new_.push_back(sr.scalar_flux_new_[g]);
2,550,458✔
101
    scalar_flux_final_.push_back(sr.scalar_flux_final_[g]);
2,550,458✔
102
    source_.push_back(sr.source_[g]);
2,550,458✔
103
    if (settings::run_mode == RunMode::FIXED_SOURCE) {
2,550,458✔
104
      external_source_.push_back(sr.external_source_[g]);
2,236,342✔
105
    }
106

107
    // Only store these fields if is_linear_ is true
108
    if (is_linear_) {
2,550,458✔
109
      source_gradients_.push_back(sr.source_gradients_[g]);
852,060✔
110
      flux_moments_old_.push_back(sr.flux_moments_old_[g]);
852,060✔
111
      flux_moments_new_.push_back(sr.flux_moments_new_[g]);
852,060✔
112
      flux_moments_t_.push_back(sr.flux_moments_t_[g]);
852,060✔
113
    }
114

115
    // Tally tasks
116
    tally_task_.emplace_back(sr.tally_task_[g]);
2,550,458✔
117
  }
118
}
2,239,115✔
119

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

140
  if (is_linear_) {
×
141
    centroid_.clear();
×
142
    centroid_iteration_.clear();
×
143
    centroid_t_.clear();
×
144
    mom_matrix_.clear();
×
145
    mom_matrix_t_.clear();
×
146
  }
147

148
  scalar_flux_old_.clear();
×
149
  scalar_flux_new_.clear();
×
150
  scalar_flux_final_.clear();
×
151
  source_.clear();
×
152
  external_source_.clear();
×
153

154
  if (is_linear_) {
×
155
    source_gradients_.clear();
×
156
    flux_moments_old_.clear();
×
157
    flux_moments_new_.clear();
×
158
    flux_moments_t_.clear();
×
159
  }
160

161
  tally_task_.clear();
×
162
  volume_task_.clear();
×
163

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

170
void SourceRegionContainer::flux_swap()
11,672✔
171
{
172
  scalar_flux_old_.swap(scalar_flux_new_);
11,672✔
173
  if (is_linear_) {
11,672✔
174
    flux_moments_old_.swap(flux_moments_new_);
6,435✔
175
  }
176
}
11,672✔
177

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

209
  if (handle.is_linear_) {
1,256,022,809✔
210
    handle.centroid_ = &centroid(sr);
626,358,183✔
211
    handle.centroid_iteration_ = &centroid_iteration(sr);
626,358,183✔
212
    handle.centroid_t_ = &centroid_t(sr);
626,358,183✔
213
    handle.mom_matrix_ = &mom_matrix(sr);
626,358,183✔
214
    handle.mom_matrix_t_ = &mom_matrix_t(sr);
626,358,183✔
215
    handle.source_gradients_ = &source_gradients(sr, 0);
626,358,183✔
216
    handle.flux_moments_old_ = &flux_moments_old(sr, 0);
626,358,183✔
217
    handle.flux_moments_new_ = &flux_moments_new(sr, 0);
626,358,183✔
218
    handle.flux_moments_t_ = &flux_moments_t(sr, 0);
626,358,183✔
219
  }
220

221
  return handle;
1,256,022,809✔
222
}
223

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

261
} // 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

© 2025 Coveralls, Inc