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

openmc-dev / openmc / 10586562087

27 Aug 2024 10:05PM UTC coverage: 84.707% (-0.2%) from 84.9%
10586562087

Pull #3112

github

web-flow
Merge f7f32bf18 into 5bc04b5d7
Pull Request #3112: Revamp CI with dependency and Python caching for efficient installs

49553 of 58499 relevant lines covered (84.71%)

34324762.08 hits per line

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

96.14
/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)
300,169,308✔
24
{
25
  constexpr float c1n = -1.0000013559236386308f;
300,169,308✔
26
  constexpr float c2n = 0.23151368626911062025f;
300,169,308✔
27
  constexpr float c3n = -0.061481916409314966140f;
300,169,308✔
28
  constexpr float c4n = 0.0098619906458127653020f;
300,169,308✔
29
  constexpr float c5n = -0.0012629460503540849940f;
300,169,308✔
30
  constexpr float c6n = 0.00010360973791574984608f;
300,169,308✔
31
  constexpr float c7n = -0.000013276571933735820960f;
300,169,308✔
32

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

42
  float x = -tau;
300,169,308✔
43

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

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

62
  return num / den;
300,169,308✔
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()
512,400✔
188
  : angular_flux_(data::mg.num_energy_groups_),
512,400✔
189
    delta_psi_(data::mg.num_energy_groups_),
512,400✔
190
    negroups_(data::mg.num_energy_groups_)
1,537,200✔
191
{
192
  if (source_shape_ == RandomRaySourceShape::LINEAR ||
512,400✔
193
      source_shape_ == RandomRaySourceShape::LINEAR_XY) {
291,600✔
194
    delta_moments_.resize(negroups_);
357,000✔
195
  }
196
}
512,400✔
197

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

203
// Transports ray until termination criteria are met
204
uint64_t RandomRay::transport_history_based_single_ray()
512,400✔
205
{
206
  using namespace openmc;
207
  while (alive()) {
259,830,240✔
208
    event_advance_ray();
259,830,240✔
209
    if (!alive())
259,830,240✔
210
      break;
512,400✔
211
    event_cross_surface();
259,317,840✔
212
  }
213

214
  return n_event();
512,400✔
215
}
216

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

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

230
  if (is_active_) {
259,830,240✔
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_) {
197,720,928✔
236
      distance = distance_active_ - distance_travelled_;
512,400✔
237
      wgt() = 0.0;
512,400✔
238
    }
239

240
    distance_travelled_ += distance;
197,720,928✔
241
    attenuate_flux(distance, true);
197,720,928✔
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_) {
62,109,312✔
249
      is_active_ = true;
512,400✔
250
      double distance_dead = distance_inactive_ - distance_travelled_;
512,400✔
251
      attenuate_flux(distance_dead, false);
512,400✔
252

253
      double distance_alive = distance - distance_dead;
512,400✔
254

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

261
      attenuate_flux(distance_alive, true);
512,400✔
262
      distance_travelled_ = distance_alive;
512,400✔
263
    } else {
264
      distance_travelled_ += distance;
61,596,912✔
265
      attenuate_flux(distance, false);
61,596,912✔
266
    }
267
  }
268

269
  // Advance particle
270
  for (int j = 0; j < n_coord(); ++j) {
1,038,677,844✔
271
    coord(j).r += distance * coord(j).u;
778,847,604✔
272
  }
273
}
274

275
void RandomRay::attenuate_flux(double distance, bool is_active)
260,342,640✔
276
{
277
  switch (source_shape_) {
260,342,640✔
278
  case RandomRaySourceShape::FLAT:
70,192,956✔
279
    attenuate_flux_flat_source(distance, is_active);
70,192,956✔
280
    break;
70,192,956✔
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
}
260,342,640✔
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)
70,192,956✔
304
{
305
  // The number of geometric intersections is counted for reporting purposes
306
  n_event()++;
70,192,956✔
307

308
  // Determine source region index etc.
309
  int i_cell = lowest_coord().cell;
70,192,956✔
310

311
  // The source region is the spatial region index
312
  int64_t source_region =
313
    domain_->source_region_offsets_[i_cell] + cell_instance();
70,192,956✔
314

315
  // The source element is the energy-specific region index
316
  int64_t source_element = source_region * negroups_;
70,192,956✔
317
  int material = this->material();
70,192,956✔
318

319
  // Temperature and angle indices, if using multiple temperature
320
  // data sets and/or anisotropic data sets.
321
  // TODO: Currently assumes we are only using single temp/single
322
  // angle data.
323
  const int t = 0;
70,192,956✔
324
  const int a = 0;
70,192,956✔
325

326
  // MOC incoming flux attenuation + source contribution/attenuation equation
327
  for (int g = 0; g < negroups_; g++) {
370,362,264✔
328
    float sigma_t = data::mg.macro_xs_[material].get_xs(
300,169,308✔
329
      MgxsType::TOTAL, g, NULL, NULL, NULL, t, a);
300,169,308✔
330
    float tau = sigma_t * distance;
300,169,308✔
331
    float exponential = cjosey_exponential(tau); // exponential = 1 - exp(-tau)
300,169,308✔
332
    float new_delta_psi =
333
      (angular_flux_[g] - domain_->source_[source_element + g]) * exponential;
300,169,308✔
334
    delta_psi_[g] = new_delta_psi;
300,169,308✔
335
    angular_flux_[g] -= new_delta_psi;
300,169,308✔
336
  }
337

338
  // If ray is in the active phase (not in dead zone), make contributions to
339
  // source region bookkeeping
340
  if (is_active) {
70,192,956✔
341

342
    // Aquire lock for source region
343
    domain_->lock_[source_region].lock();
49,225,908✔
344

345
    // Accumulate delta psi into new estimate of source region flux for
346
    // this iteration
347
    for (int g = 0; g < negroups_; g++) {
234,583,872✔
348
      domain_->scalar_flux_new_[source_element + g] += delta_psi_[g];
185,357,964✔
349
    }
350

351
    // Accomulate volume (ray distance) into this iteration's estimate
352
    // of the source region's volume
353
    domain_->volume_[source_region] += distance;
49,225,908✔
354

355
    // Tally valid position inside the source region (e.g., midpoint of
356
    // the ray) if not done already
357
    if (!domain_->position_recorded_[source_region]) {
49,225,908✔
358
      Position midpoint = r() + u() * (distance / 2.0);
253,611✔
359
      domain_->position_[source_region] = midpoint;
253,611✔
360
      domain_->position_recorded_[source_region] = 1;
253,611✔
361
    }
362

363
    // Release lock
364
    domain_->lock_[source_region].unlock();
49,225,908✔
365
  }
366
}
70,192,956✔
367

368
void RandomRay::attenuate_flux_linear_source(double distance, bool is_active)
190,149,684✔
369
{
370
  // Cast domain to LinearSourceDomain
371
  LinearSourceDomain* domain = dynamic_cast<LinearSourceDomain*>(domain_);
190,149,684✔
372
  if (!domain) {
190,149,684✔
373
    fatal_error("RandomRay::attenuate_flux_linear_source() called with "
×
374
                "non-LinearSourceDomain domain.");
375
  }
376

377
  // The number of geometric intersections is counted for reporting purposes
378
  n_event()++;
190,149,684✔
379

380
  // Determine source region index etc.
381
  int i_cell = lowest_coord().cell;
190,149,684✔
382

383
  // The source region is the spatial region index
384
  int64_t source_region =
385
    domain_->source_region_offsets_[i_cell] + cell_instance();
190,149,684✔
386

387
  // The source element is the energy-specific region index
388
  int64_t source_element = source_region * negroups_;
190,149,684✔
389
  int material = this->material();
190,149,684✔
390

391
  // Temperature and angle indices, if using multiple temperature
392
  // data sets and/or anisotropic data sets.
393
  // TODO: Currently assumes we are only using single temp/single
394
  // angle data.
395
  const int t = 0;
190,149,684✔
396
  const int a = 0;
190,149,684✔
397

398
  Position& centroid = domain->centroid_[source_region];
190,149,684✔
399
  Position midpoint = r() + u() * (distance / 2.0);
190,149,684✔
400

401
  // Determine the local position of the midpoint and the ray origin
402
  // relative to the source region's centroid
403
  Position rm_local;
190,149,684✔
404
  Position r0_local;
190,149,684✔
405

406
  // In the first few iterations of the simulation, the source region
407
  // may not yet have had any ray crossings, in which case there will
408
  // be no estimate of its centroid. We detect this by checking if it has
409
  // any accumulated volume. If its volume is zero, just use the midpoint
410
  // of the ray as the region's centroid.
411
  if (domain->volume_t_[source_region]) {
190,149,684✔
412
    rm_local = midpoint - centroid;
185,861,784✔
413
    r0_local = r() - centroid;
185,861,784✔
414
  } else {
415
    rm_local = {0.0, 0.0, 0.0};
4,287,900✔
416
    r0_local = -u() * 0.5 * distance;
4,287,900✔
417
  }
418
  double distance_2 = distance * distance;
190,149,684✔
419

420
  // Linear Source MOC incoming flux attenuation + source
421
  // contribution/attenuation equation
422
  for (int g = 0; g < negroups_; g++) {
1,051,429,512✔
423

424
    // Compute tau, the optical thickness of the ray segment
425
    float sigma_t = data::mg.macro_xs_[material].get_xs(
861,279,828✔
426
      MgxsType::TOTAL, g, NULL, NULL, NULL, t, a);
861,279,828✔
427
    float tau = sigma_t * distance;
861,279,828✔
428

429
    // If tau is very small, set it to zero to avoid numerical issues.
430
    // The following computations will still work with tau = 0.
431
    if (tau < 1.0e-8f) {
861,279,828✔
432
      tau = 0.0f;
300✔
433
    }
434

435
    // Compute linear source terms, spatial and directional (dir),
436
    // calculated from the source gradients dot product with local centroid
437
    // and direction, respectively.
438
    float spatial_source =
439
      domain_->source_[source_element + g] +
861,279,828✔
440
      rm_local.dot(domain->source_gradients_[source_element + g]);
861,279,828✔
441
    float dir_source = u().dot(domain->source_gradients_[source_element + g]);
861,279,828✔
442

443
    float gn = exponentialG(tau);
861,279,828✔
444
    float f1 = 1.0f - tau * gn;
861,279,828✔
445
    float f2 = (2.0f * gn - f1) * distance_2;
861,279,828✔
446
    float new_delta_psi = (angular_flux_[g] - spatial_source) * f1 * distance -
861,279,828✔
447
                          0.5 * dir_source * f2;
861,279,828✔
448

449
    float h1 = f1 - gn;
861,279,828✔
450
    float g1 = 0.5f - h1;
861,279,828✔
451
    float g2 = exponentialG2(tau);
861,279,828✔
452
    g1 = g1 * spatial_source;
861,279,828✔
453
    g2 = g2 * dir_source * distance * 0.5f;
861,279,828✔
454
    h1 = h1 * angular_flux_[g];
861,279,828✔
455
    h1 = (g1 + g2 + h1) * distance_2;
861,279,828✔
456
    spatial_source = spatial_source * distance + new_delta_psi;
861,279,828✔
457

458
    // Store contributions for this group into arrays, so that they can
459
    // be accumulated into the source region's estimates inside of the locked
460
    // region.
461
    delta_psi_[g] = new_delta_psi;
861,279,828✔
462
    delta_moments_[g] = r0_local * spatial_source + u() * h1;
861,279,828✔
463

464
    // Update the angular flux for this group
465
    angular_flux_[g] -= new_delta_psi * sigma_t;
861,279,828✔
466

467
    // If 2D mode is enabled, the z-component of the flux moments is forced
468
    // to zero
469
    if (source_shape_ == RandomRaySourceShape::LINEAR_XY) {
861,279,828✔
470
      delta_moments_[g].z = 0.0;
504,226,956✔
471
    }
472
  }
473

474
  // If ray is in the active phase (not in dead zone), make contributions to
475
  // source region bookkeeping
476
  if (is_active) {
190,149,684✔
477
    // Compute an estimate of the spatial moments matrix for the source
478
    // region based on parameters from this ray's crossing
479
    MomentMatrix moment_matrix_estimate;
480
    moment_matrix_estimate.compute_spatial_moments_matrix(
149,007,420✔
481
      rm_local, u(), distance);
149,007,420✔
482

483
    // Aquire lock for source region
484
    domain_->lock_[source_region].lock();
149,007,420✔
485

486
    // Accumulate deltas into the new estimate of source region flux for this
487
    // iteration
488
    for (int g = 0; g < negroups_; g++) {
801,449,280✔
489
      domain_->scalar_flux_new_[source_element + g] += delta_psi_[g];
652,441,860✔
490
      domain->flux_moments_new_[source_element + g] += delta_moments_[g];
652,441,860✔
491
    }
492

493
    // Accumulate the volume (ray segment distance), centroid, and spatial
494
    // momement estimates into the running totals for the iteration for this
495
    // source region. The centroid and spatial momements estimates are scaled by
496
    // the ray segment length as part of length averaging of the estimates.
497
    domain_->volume_[source_region] += distance;
149,007,420✔
498
    domain->centroid_iteration_[source_region] += midpoint * distance;
149,007,420✔
499
    moment_matrix_estimate *= distance;
149,007,420✔
500
    domain->mom_matrix_[source_region] += moment_matrix_estimate;
149,007,420✔
501

502
    // Tally valid position inside the source region (e.g., midpoint of
503
    // the ray) if not done already
504
    if (!domain_->position_recorded_[source_region]) {
149,007,420✔
505
      domain_->position_[source_region] = midpoint;
161,067✔
506
      domain_->position_recorded_[source_region] = 1;
161,067✔
507
    }
508

509
    // Release lock
510
    domain_->lock_[source_region].unlock();
149,007,420✔
511
  }
512
}
190,149,684✔
513

514
void RandomRay::initialize_ray(uint64_t ray_id, FlatSourceDomain* domain)
512,400✔
515
{
516
  domain_ = domain;
512,400✔
517

518
  // Reset particle event counter
519
  n_event() = 0;
512,400✔
520

521
  is_active_ = (distance_inactive_ <= 0.0);
512,400✔
522

523
  wgt() = 1.0;
512,400✔
524

525
  // set identifier for particle
526
  id() = simulation::work_index[mpi::rank] + ray_id;
512,400✔
527

528
  // set random number seed
529
  int64_t particle_seed =
530
    (simulation::current_batch - 1) * settings::n_particles + id();
512,400✔
531
  init_particle_seeds(particle_seed, seeds());
512,400✔
532
  stream() = STREAM_TRACKING;
512,400✔
533

534
  // Sample from ray source distribution
535
  SourceSite site {ray_source_->sample(current_seed())};
512,400✔
536
  site.E = lower_bound_index(
512,400✔
537
    data::mg.rev_energy_bins_.begin(), data::mg.rev_energy_bins_.end(), site.E);
538
  site.E = negroups_ - site.E - 1.;
512,400✔
539
  this->from_source(&site);
512,400✔
540

541
  // Locate ray
542
  if (lowest_coord().cell == C_NONE) {
512,400✔
543
    if (!exhaustive_find_cell(*this)) {
512,400✔
544
      this->mark_as_lost(
×
545
        "Could not find the cell containing particle " + std::to_string(id()));
×
546
    }
547

548
    // Set birth cell attribute
549
    if (cell_born() == C_NONE)
512,400✔
550
      cell_born() = lowest_coord().cell;
512,400✔
551
  }
552

553
  // Initialize ray's starting angular flux to starting location's isotropic
554
  // source
555
  int i_cell = lowest_coord().cell;
512,400✔
556
  int64_t source_region_idx =
557
    domain_->source_region_offsets_[i_cell] + cell_instance();
512,400✔
558

559
  for (int g = 0; g < negroups_; g++) {
2,212,800✔
560
    angular_flux_[g] = domain_->source_[source_region_idx * negroups_ + g];
1,700,400✔
561
  }
562
}
512,400✔
563

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