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

openmc-dev / openmc / 13341039720

15 Feb 2025 02:46AM UTC coverage: 85.006% (+0.1%) from 84.867%
13341039720

Pull #2655

github

web-flow
Merge 1b7b4ad1e into be4396c12
Pull Request #2655: Raytrace plots

402 of 453 new or added lines in 5 files covered. (88.74%)

1175 existing lines in 53 files now uncovered.

50436 of 59332 relevant lines covered (85.01%)

35668719.75 hits per line

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

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

3
#include "openmc/constants.h"
4
#include "openmc/geometry.h"
5
#include "openmc/message_passing.h"
6
#include "openmc/mgxs_interface.h"
7
#include "openmc/random_ray/flat_source_domain.h"
8
#include "openmc/random_ray/linear_source_domain.h"
9
#include "openmc/search.h"
10
#include "openmc/settings.h"
11
#include "openmc/simulation.h"
12
#include "openmc/source.h"
13

14
namespace openmc {
15

16
//==============================================================================
17
// Non-method functions
18
//==============================================================================
19

20
// returns 1 - exp(-tau)
21
// Equivalent to -(_expm1f(-tau)), but faster
22
// Written by Colin Josey.
23
float cjosey_exponential(float tau)
464,083,260✔
24
{
25
  constexpr float c1n = -1.0000013559236386308f;
464,083,260✔
26
  constexpr float c2n = 0.23151368626911062025f;
464,083,260✔
27
  constexpr float c3n = -0.061481916409314966140f;
464,083,260✔
28
  constexpr float c4n = 0.0098619906458127653020f;
464,083,260✔
29
  constexpr float c5n = -0.0012629460503540849940f;
464,083,260✔
30
  constexpr float c6n = 0.00010360973791574984608f;
464,083,260✔
31
  constexpr float c7n = -0.000013276571933735820960f;
464,083,260✔
32

33
  constexpr float c0d = 1.0f;
464,083,260✔
34
  constexpr float c1d = -0.73151337729389001396f;
464,083,260✔
35
  constexpr float c2d = 0.26058381273536471371f;
464,083,260✔
36
  constexpr float c3d = -0.059892419041316836940f;
464,083,260✔
37
  constexpr float c4d = 0.0099070188241094279067f;
464,083,260✔
38
  constexpr float c5d = -0.0012623388962473160860f;
464,083,260✔
39
  constexpr float c6d = 0.00010361277635498731388f;
464,083,260✔
40
  constexpr float c7d = -0.000013276569500666698498f;
464,083,260✔
41

42
  float x = -tau;
464,083,260✔
43

44
  float den = c7d;
464,083,260✔
45
  den = den * x + c6d;
464,083,260✔
46
  den = den * x + c5d;
464,083,260✔
47
  den = den * x + c4d;
464,083,260✔
48
  den = den * x + c3d;
464,083,260✔
49
  den = den * x + c2d;
464,083,260✔
50
  den = den * x + c1d;
464,083,260✔
51
  den = den * x + c0d;
464,083,260✔
52

53
  float num = c7n;
464,083,260✔
54
  num = num * x + c6n;
464,083,260✔
55
  num = num * x + c5n;
464,083,260✔
56
  num = num * x + c4n;
464,083,260✔
57
  num = num * x + c3n;
464,083,260✔
58
  num = num * x + c2n;
464,083,260✔
59
  num = num * x + c1n;
464,083,260✔
60
  num = num * x;
464,083,260✔
61

62
  return num / den;
464,083,260✔
63
}
64

65
// The below two functions (exponentialG and exponentialG2) were developed
66
// by Colin Josey. The implementation of these functions is closely based
67
// on the OpenMOC versions of these functions. The OpenMOC license is given
68
// below:
69

70
// Copyright (C) 2012-2023 Massachusetts Institute of Technology and OpenMOC
71
// contributors
72
//
73
// Permission is hereby granted, free of charge, to any person obtaining a copy
74
// of this software and associated documentation files (the "Software"), to deal
75
// in the Software without restriction, including without limitation the rights
76
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
77
// copies of the Software, and to permit persons to whom the Software is
78
// furnished to do so, subject to the following conditions:
79
//
80
// The above copyright notice and this permission notice shall be included in
81
// all copies or substantial portions of the Software.
82
//
83
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
84
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
85
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
86
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
87
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
88
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
89
// SOFTWARE.
90

91
// Computes y = 1/x-(1-exp(-x))/x**2 using a 5/6th order rational
92
// approximation. It is accurate to 2e-7 over [0, 1e5]. Developed by Colin
93
// Josey using Remez's algorithm, with original implementation in OpenMOC at:
94
// https://github.com/mit-crpg/OpenMOC/blob/develop/src/exponentials.h
95
float exponentialG(float tau)
861,279,828✔
96
{
97
  // Numerator coefficients in rational approximation for 1/x - (1 - exp(-x)) /
98
  // x^2
99
  constexpr float d0n = 0.5f;
861,279,828✔
100
  constexpr float d1n = 0.176558112351595f;
861,279,828✔
101
  constexpr float d2n = 0.04041584305811143f;
861,279,828✔
102
  constexpr float d3n = 0.006178333902037397f;
861,279,828✔
103
  constexpr float d4n = 0.0006429894635552992f;
861,279,828✔
104
  constexpr float d5n = 0.00006064409107557148f;
861,279,828✔
105

106
  // Denominator coefficients in rational approximation for 1/x - (1 - exp(-x))
107
  // / x^2
108
  constexpr float d0d = 1.0f;
861,279,828✔
109
  constexpr float d1d = 0.6864462055546078f;
861,279,828✔
110
  constexpr float d2d = 0.2263358514260129f;
861,279,828✔
111
  constexpr float d3d = 0.04721469893686252f;
861,279,828✔
112
  constexpr float d4d = 0.006883236664917246f;
861,279,828✔
113
  constexpr float d5d = 0.0007036272419147752f;
861,279,828✔
114
  constexpr float d6d = 0.00006064409107557148f;
861,279,828✔
115

116
  float x = tau;
861,279,828✔
117

118
  float num = d5n;
861,279,828✔
119
  num = num * x + d4n;
861,279,828✔
120
  num = num * x + d3n;
861,279,828✔
121
  num = num * x + d2n;
861,279,828✔
122
  num = num * x + d1n;
861,279,828✔
123
  num = num * x + d0n;
861,279,828✔
124

125
  float den = d6d;
861,279,828✔
126
  den = den * x + d5d;
861,279,828✔
127
  den = den * x + d4d;
861,279,828✔
128
  den = den * x + d3d;
861,279,828✔
129
  den = den * x + d2d;
861,279,828✔
130
  den = den * x + d1d;
861,279,828✔
131
  den = den * x + d0d;
861,279,828✔
132

133
  return num / den;
861,279,828✔
134
}
135

136
// Computes G2 : y = 2/3 - (1 + 2/x) * (1/x + 0.5 - (1 + 1/x) * (1-exp(-x)) /
137
// x) using a 5/5th order rational approximation. It is accurate to 1e-6 over
138
// [0, 1e6]. Developed by Colin Josey using Remez's algorithm, with original
139
// implementation in OpenMOC at:
140
// https://github.com/mit-crpg/OpenMOC/blob/develop/src/exponentials.h
141
float exponentialG2(float tau)
861,279,828✔
142
{
143

144
  // Coefficients for numerator in rational approximation
145
  constexpr float g1n = -0.08335775885589858f;
861,279,828✔
146
  constexpr float g2n = -0.003603942303847604f;
861,279,828✔
147
  constexpr float g3n = 0.0037673183263550827f;
861,279,828✔
148
  constexpr float g4n = 0.00001124183494990467f;
861,279,828✔
149
  constexpr float g5n = 0.00016837426505799449f;
861,279,828✔
150

151
  // Coefficients for denominator in rational approximation
152
  constexpr float g1d = 0.7454048371823628f;
861,279,828✔
153
  constexpr float g2d = 0.23794300531408347f;
861,279,828✔
154
  constexpr float g3d = 0.05367250964303789f;
861,279,828✔
155
  constexpr float g4d = 0.006125197988351906f;
861,279,828✔
156
  constexpr float g5d = 0.0010102514456857377f;
861,279,828✔
157

158
  float x = tau;
861,279,828✔
159

160
  float num = g5n;
861,279,828✔
161
  num = num * x + g4n;
861,279,828✔
162
  num = num * x + g3n;
861,279,828✔
163
  num = num * x + g2n;
861,279,828✔
164
  num = num * x + g1n;
861,279,828✔
165
  num = num * x;
861,279,828✔
166

167
  float den = g5d;
861,279,828✔
168
  den = den * x + g4d;
861,279,828✔
169
  den = den * x + g3d;
861,279,828✔
170
  den = den * x + g2d;
861,279,828✔
171
  den = den * x + g1d;
861,279,828✔
172
  den = den * x + 1.0f;
861,279,828✔
173

174
  return num / den;
861,279,828✔
175
}
176

177
//==============================================================================
178
// RandomRay implementation
179
//==============================================================================
180

181
// Static Variable Declarations
182
double RandomRay::distance_inactive_;
183
double RandomRay::distance_active_;
184
unique_ptr<Source> RandomRay::ray_source_;
185
RandomRaySourceShape RandomRay::source_shape_ {RandomRaySourceShape::FLAT};
186

187
RandomRay::RandomRay()
579,600✔
188
  : angular_flux_(data::mg.num_energy_groups_),
579,600✔
189
    delta_psi_(data::mg.num_energy_groups_),
579,600✔
190
    negroups_(data::mg.num_energy_groups_)
1,738,800✔
191
{
192
  if (source_shape_ == RandomRaySourceShape::LINEAR ||
579,600✔
193
      source_shape_ == RandomRaySourceShape::LINEAR_XY) {
358,800✔
194
    delta_moments_.resize(negroups_);
357,000✔
195
  }
196
}
579,600✔
197

198
RandomRay::RandomRay(uint64_t ray_id, FlatSourceDomain* domain) : RandomRay()
579,600✔
199
{
200
  initialize_ray(ray_id, domain);
579,600✔
201
}
579,600✔
202

203
// Transports ray until termination criteria are met
204
uint64_t RandomRay::transport_history_based_single_ray()
579,600✔
205
{
206
  using namespace openmc;
207
  while (alive()) {
296,554,368✔
208
    event_advance_ray();
296,554,368✔
209
    if (!alive())
296,554,368✔
210
      break;
579,600✔
211
    event_cross_surface();
295,974,768✔
212
  }
213

214
  return n_event();
579,600✔
215
}
216

217
// Transports ray across a single source region
218
void RandomRay::event_advance_ray()
296,554,368✔
219
{
220
  // Find the distance to the nearest boundary
221
  boundary() = distance_to_boundary(*this);
296,554,368✔
222
  double distance = boundary().distance;
296,554,368✔
223

224
  if (distance <= 0.0) {
296,554,368✔
225
    mark_as_lost("Negative transport distance detected for particle " +
×
226
                 std::to_string(id()));
×
227
    return;
×
228
  }
229

230
  if (is_active_) {
296,554,368✔
231
    // If the ray is in the active length, need to check if it has
232
    // reached its maximum termination distance. If so, reduce
233
    // the ray traced length so that the ray does not overrun the
234
    // maximum numerical length (so as to avoid numerical bias).
235
    if (distance_travelled_ + distance >= distance_active_) {
228,276,240✔
236
      distance = distance_active_ - distance_travelled_;
579,600✔
237
      wgt() = 0.0;
579,600✔
238
    }
239

240
    distance_travelled_ += distance;
228,276,240✔
241
    attenuate_flux(distance, true);
228,276,240✔
242
  } else {
243
    // If the ray is still in the dead zone, need to check if it
244
    // has entered the active phase. If so, split into two segments (one
245
    // representing the final part of the dead zone, the other representing the
246
    // first part of the active length) and attenuate each. Otherwise, if the
247
    // full length of the segment is within the dead zone, attenuate as normal.
248
    if (distance_travelled_ + distance >= distance_inactive_) {
68,278,128✔
249
      is_active_ = true;
579,600✔
250
      double distance_dead = distance_inactive_ - distance_travelled_;
579,600✔
251
      attenuate_flux(distance_dead, false);
579,600✔
252

253
      double distance_alive = distance - distance_dead;
579,600✔
254

255
      // Ensure we haven't travelled past the active phase as well
256
      if (distance_alive > distance_active_) {
579,600✔
257
        distance_alive = distance_active_;
×
258
        wgt() = 0.0;
×
259
      }
260

261
      attenuate_flux(distance_alive, true);
579,600✔
262
      distance_travelled_ = distance_alive;
579,600✔
263
    } else {
264
      distance_travelled_ += distance;
67,698,528✔
265
      attenuate_flux(distance, false);
67,698,528✔
266
    }
267
  }
268

269
  // Advance particle
270
  for (int j = 0; j < n_coord(); ++j) {
1,185,574,356✔
271
    coord(j).r += distance * coord(j).u;
889,019,988✔
272
  }
273
}
274

275
void RandomRay::attenuate_flux(double distance, bool is_active)
297,133,968✔
276
{
277
  switch (source_shape_) {
297,133,968✔
278
  case RandomRaySourceShape::FLAT:
106,984,284✔
279
    attenuate_flux_flat_source(distance, is_active);
106,984,284✔
280
    break;
106,984,284✔
281
  case RandomRaySourceShape::LINEAR:
190,149,684✔
282
  case RandomRaySourceShape::LINEAR_XY:
283
    attenuate_flux_linear_source(distance, is_active);
190,149,684✔
284
    break;
190,149,684✔
285
  default:
×
286
    fatal_error("Unknown source shape for random ray transport.");
×
287
  }
288
}
297,133,968✔
289

290
// This function forms the inner loop of the random ray transport process.
291
// It is responsible for several tasks. Based on the incoming angular flux
292
// of the ray and the source term in the region, the outgoing angular flux
293
// is computed. The delta psi between the incoming and outgoing fluxes is
294
// contributed to the estimate of the total scalar flux in the source region.
295
// Additionally, the contribution of the ray path to the stochastically
296
// estimated volume is also kept track of. All tasks involving writing
297
// to the data for the source region are done with a lock over the entire
298
// source region.  Locks are used instead of atomics as all energy groups
299
// must be written, such that locking once is typically much more efficient
300
// than use of many atomic operations corresponding to each energy group
301
// individually (at least on CPU). Several other bookkeeping tasks are also
302
// performed when inside the lock.
303
void RandomRay::attenuate_flux_flat_source(double distance, bool is_active)
106,984,284✔
304
{
305
  // The number of geometric intersections is counted for reporting purposes
306
  n_event()++;
106,984,284✔
307

308
  // Determine source region index etc.
309
  int i_cell = lowest_coord().cell;
106,984,284✔
310

311
  // The source region is the spatial region index
312
  int64_t sr = domain_->source_region_offsets_[i_cell] + cell_instance();
106,984,284✔
313

314
  // The source element is the energy-specific region index
315
  int material = this->material();
106,984,284✔
316

317
  // MOC incoming flux attenuation + source contribution/attenuation equation
318
  for (int g = 0; g < negroups_; g++) {
571,067,544✔
319
    float sigma_t = domain_->sigma_t_[material * negroups_ + g];
464,083,260✔
320
    float tau = sigma_t * distance;
464,083,260✔
321
    float exponential = cjosey_exponential(tau); // exponential = 1 - exp(-tau)
464,083,260✔
322
    float new_delta_psi =
323
      (angular_flux_[g] - domain_->source_regions_.source(sr, g)) * exponential;
464,083,260✔
324
    delta_psi_[g] = new_delta_psi;
464,083,260✔
325
    angular_flux_[g] -= new_delta_psi;
464,083,260✔
326
  }
327

328
  // If ray is in the active phase (not in dead zone), make contributions to
329
  // source region bookkeeping
330
  if (is_active) {
106,984,284✔
331

332
    // Aquire lock for source region
333
    domain_->source_regions_.lock(sr).lock();
79,848,420✔
334

335
    // Accumulate delta psi into new estimate of source region flux for
336
    // this iteration
337
    for (int g = 0; g < negroups_; g++) {
401,709,792✔
338
      domain_->source_regions_.scalar_flux_new(sr, g) += delta_psi_[g];
321,861,372✔
339
    }
340

341
    // Accomulate volume (ray distance) into this iteration's estimate
342
    // of the source region's volume
343
    domain_->source_regions_.volume(sr) += distance;
79,848,420✔
344

345
    // Tally valid position inside the source region (e.g., midpoint of
346
    // the ray) if not done already
347
    if (!domain_->source_regions_.position_recorded(sr)) {
79,848,420✔
348
      Position midpoint = r() + u() * (distance / 2.0);
379,576✔
349
      domain_->source_regions_.position(sr) = midpoint;
379,576✔
350
      domain_->source_regions_.position_recorded(sr) = 1;
379,576✔
351
    }
352

353
    // Release lock
354
    domain_->source_regions_.lock(sr).unlock();
79,848,420✔
355
  }
356
}
106,984,284✔
357

358
void RandomRay::attenuate_flux_linear_source(double distance, bool is_active)
190,149,684✔
359
{
360
  // Cast domain to LinearSourceDomain
361
  LinearSourceDomain* domain = dynamic_cast<LinearSourceDomain*>(domain_);
190,149,684✔
362
  if (!domain) {
190,149,684✔
UNCOV
363
    fatal_error("RandomRay::attenuate_flux_linear_source() called with "
×
364
                "non-LinearSourceDomain domain.");
365
  }
366

367
  // The number of geometric intersections is counted for reporting purposes
368
  n_event()++;
190,149,684✔
369

370
  // Determine source region index etc.
371
  int i_cell = lowest_coord().cell;
190,149,684✔
372

373
  // The source region is the spatial region index
374
  int64_t sr = domain_->source_region_offsets_[i_cell] + cell_instance();
190,149,684✔
375

376
  // The source element is the energy-specific region index
377
  int material = this->material();
190,149,684✔
378

379
  Position& centroid = domain_->source_regions_.centroid(sr);
190,149,684✔
380
  Position midpoint = r() + u() * (distance / 2.0);
190,149,684✔
381

382
  // Determine the local position of the midpoint and the ray origin
383
  // relative to the source region's centroid
384
  Position rm_local;
190,149,684✔
385
  Position r0_local;
190,149,684✔
386

387
  // In the first few iterations of the simulation, the source region
388
  // may not yet have had any ray crossings, in which case there will
389
  // be no estimate of its centroid. We detect this by checking if it has
390
  // any accumulated volume. If its volume is zero, just use the midpoint
391
  // of the ray as the region's centroid.
392
  if (domain_->source_regions_.volume_t(sr)) {
190,149,684✔
393
    rm_local = midpoint - centroid;
185,861,784✔
394
    r0_local = r() - centroid;
185,861,784✔
395
  } else {
396
    rm_local = {0.0, 0.0, 0.0};
4,287,900✔
397
    r0_local = -u() * 0.5 * distance;
4,287,900✔
398
  }
399
  double distance_2 = distance * distance;
190,149,684✔
400

401
  // Linear Source MOC incoming flux attenuation + source
402
  // contribution/attenuation equation
403
  for (int g = 0; g < negroups_; g++) {
1,051,429,512✔
404

405
    // Compute tau, the optical thickness of the ray segment
406
    float sigma_t = domain_->sigma_t_[material * negroups_ + g];
861,279,828✔
407
    float tau = sigma_t * distance;
861,279,828✔
408

409
    // If tau is very small, set it to zero to avoid numerical issues.
410
    // The following computations will still work with tau = 0.
411
    if (tau < 1.0e-8f) {
861,279,828✔
412
      tau = 0.0f;
300✔
413
    }
414

415
    // Compute linear source terms, spatial and directional (dir),
416
    // calculated from the source gradients dot product with local centroid
417
    // and direction, respectively.
418
    float spatial_source =
419
      domain_->source_regions_.source(sr, g) +
861,279,828✔
420
      rm_local.dot(domain_->source_regions_.source_gradients(sr, g));
861,279,828✔
421
    float dir_source =
422
      u().dot(domain_->source_regions_.source_gradients(sr, g));
861,279,828✔
423

424
    float gn = exponentialG(tau);
861,279,828✔
425
    float f1 = 1.0f - tau * gn;
861,279,828✔
426
    float f2 = (2.0f * gn - f1) * distance_2;
861,279,828✔
427
    float new_delta_psi = (angular_flux_[g] - spatial_source) * f1 * distance -
861,279,828✔
428
                          0.5 * dir_source * f2;
861,279,828✔
429

430
    float h1 = f1 - gn;
861,279,828✔
431
    float g1 = 0.5f - h1;
861,279,828✔
432
    float g2 = exponentialG2(tau);
861,279,828✔
433
    g1 = g1 * spatial_source;
861,279,828✔
434
    g2 = g2 * dir_source * distance * 0.5f;
861,279,828✔
435
    h1 = h1 * angular_flux_[g];
861,279,828✔
436
    h1 = (g1 + g2 + h1) * distance_2;
861,279,828✔
437
    spatial_source = spatial_source * distance + new_delta_psi;
861,279,828✔
438

439
    // Store contributions for this group into arrays, so that they can
440
    // be accumulated into the source region's estimates inside of the locked
441
    // region.
442
    delta_psi_[g] = new_delta_psi;
861,279,828✔
443
    delta_moments_[g] = r0_local * spatial_source + u() * h1;
861,279,828✔
444

445
    // Update the angular flux for this group
446
    angular_flux_[g] -= new_delta_psi * sigma_t;
861,279,828✔
447

448
    // If 2D mode is enabled, the z-component of the flux moments is forced
449
    // to zero
450
    if (source_shape_ == RandomRaySourceShape::LINEAR_XY) {
861,279,828✔
451
      delta_moments_[g].z = 0.0;
504,226,956✔
452
    }
453
  }
454

455
  // If ray is in the active phase (not in dead zone), make contributions to
456
  // source region bookkeeping
457
  if (is_active) {
190,149,684✔
458
    // Compute an estimate of the spatial moments matrix for the source
459
    // region based on parameters from this ray's crossing
460
    MomentMatrix moment_matrix_estimate;
461
    moment_matrix_estimate.compute_spatial_moments_matrix(
149,007,420✔
462
      rm_local, u(), distance);
149,007,420✔
463

464
    // Aquire lock for source region
465
    domain_->source_regions_.lock(sr).lock();
149,007,420✔
466

467
    // Accumulate deltas into the new estimate of source region flux for this
468
    // iteration
469
    for (int g = 0; g < negroups_; g++) {
801,449,280✔
470
      domain_->source_regions_.scalar_flux_new(sr, g) += delta_psi_[g];
652,441,860✔
471
      domain_->source_regions_.flux_moments_new(sr, g) += delta_moments_[g];
652,441,860✔
472
    }
473

474
    // Accumulate the volume (ray segment distance), centroid, and spatial
475
    // momement estimates into the running totals for the iteration for this
476
    // source region. The centroid and spatial momements estimates are scaled by
477
    // the ray segment length as part of length averaging of the estimates.
478
    domain_->source_regions_.volume(sr) += distance;
149,007,420✔
479
    domain_->source_regions_.centroid_iteration(sr) += midpoint * distance;
149,007,420✔
480
    moment_matrix_estimate *= distance;
149,007,420✔
481
    domain_->source_regions_.mom_matrix(sr) += moment_matrix_estimate;
149,007,420✔
482

483
    // Tally valid position inside the source region (e.g., midpoint of
484
    // the ray) if not done already
485
    if (!domain_->source_regions_.position_recorded(sr)) {
149,007,420✔
486
      domain_->source_regions_.position(sr) = midpoint;
161,092✔
487
      domain_->source_regions_.position_recorded(sr) = 1;
161,092✔
488
    }
489

490
    // Release lock
491
    domain_->source_regions_.lock(sr).unlock();
149,007,420✔
492
  }
493
}
190,149,684✔
494

495
void RandomRay::initialize_ray(uint64_t ray_id, FlatSourceDomain* domain)
579,600✔
496
{
497
  domain_ = domain;
579,600✔
498

499
  // Reset particle event counter
500
  n_event() = 0;
579,600✔
501

502
  is_active_ = (distance_inactive_ <= 0.0);
579,600✔
503

504
  wgt() = 1.0;
579,600✔
505

506
  // set identifier for particle
507
  id() = simulation::work_index[mpi::rank] + ray_id;
579,600✔
508

509
  // set random number seed
510
  int64_t particle_seed =
511
    (simulation::current_batch - 1) * settings::n_particles + id();
579,600✔
512
  init_particle_seeds(particle_seed, seeds());
579,600✔
513
  stream() = STREAM_TRACKING;
579,600✔
514

515
  // Sample from ray source distribution
516
  SourceSite site {ray_source_->sample(current_seed())};
579,600✔
517
  site.E = lower_bound_index(
579,600✔
518
    data::mg.rev_energy_bins_.begin(), data::mg.rev_energy_bins_.end(), site.E);
519
  site.E = negroups_ - site.E - 1.;
579,600✔
520
  this->from_source(&site);
579,600✔
521

522
  // Locate ray
523
  if (lowest_coord().cell == C_NONE) {
579,600✔
524
    if (!exhaustive_find_cell(*this)) {
579,600✔
UNCOV
525
      this->mark_as_lost(
×
UNCOV
526
        "Could not find the cell containing particle " + std::to_string(id()));
×
527
    }
528

529
    // Set birth cell attribute
530
    if (cell_born() == C_NONE)
579,600✔
531
      cell_born() = lowest_coord().cell;
579,600✔
532
  }
533

534
  // Initialize ray's starting angular flux to starting location's isotropic
535
  // source
536
  int i_cell = lowest_coord().cell;
579,600✔
537
  int64_t sr = domain_->source_region_offsets_[i_cell] + cell_instance();
579,600✔
538

539
  for (int g = 0; g < negroups_; g++) {
2,491,200✔
540
    angular_flux_[g] = domain_->source_regions_.source(sr, g);
1,911,600✔
541
  }
542
}
579,600✔
543

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