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

openmc-dev / openmc / 21266930580

22 Jan 2026 10:19PM UTC coverage: 82.119% (+0.1%) from 82.009%
21266930580

Pull #3737

github

web-flow
Merge 0bb4bb40f into 049a852e5
Pull Request #3737: Temperature feedback support in the random ray solver.

17250 of 23966 branches covered (71.98%)

Branch coverage included in aggregate %.

330 of 357 new or added lines in 11 files covered. (92.44%)

5 existing lines in 3 files now uncovered.

55870 of 65076 relevant lines covered (85.85%)

45069371.1 hits per line

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

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

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

55
  tally_task_.resize(negroups);
2,365,857✔
56
  if (is_linear) {
2,365,857✔
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,365,857✔
63

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

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

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

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

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

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

118
    // Tally tasks
119
    tally_task_.emplace_back(sr.tally_task_[g]);
2,612,058✔
120
  }
121
}
2,264,415✔
122

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

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

153
  scalar_flux_old_.clear();
×
154
  scalar_flux_new_.clear();
×
155
  scalar_flux_final_.clear();
×
156
  source_.clear();
×
157
  external_source_.clear();
×
158

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

166
  tally_task_.clear();
×
167
  volume_task_.clear();
×
168

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

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

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

216
  if (handle.is_linear_) {
1,317,873,004✔
217
    handle.centroid_ = &centroid(sr);
667,271,132✔
218
    handle.centroid_iteration_ = &centroid_iteration(sr);
667,271,132✔
219
    handle.centroid_t_ = &centroid_t(sr);
667,271,132✔
220
    handle.mom_matrix_ = &mom_matrix(sr);
667,271,132✔
221
    handle.mom_matrix_t_ = &mom_matrix_t(sr);
667,271,132✔
222
    handle.source_gradients_ = &source_gradients(sr, 0);
667,271,132✔
223
    handle.flux_moments_old_ = &flux_moments_old(sr, 0);
667,271,132✔
224
    handle.flux_moments_new_ = &flux_moments_new(sr, 0);
667,271,132✔
225
    handle.flux_moments_t_ = &flux_moments_t(sr, 0);
667,271,132✔
226
  }
227

228
  return handle;
1,317,873,004✔
229
}
230

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

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