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

openmc-dev / openmc / 28975504630

08 Jul 2026 09:02PM UTC coverage: 81.341% (+0.07%) from 81.267%
28975504630

Pull #3971

github

web-flow
Merge af2ecaf51 into 8b15ee391
Pull Request #3971: Delta tracking

18549 of 26870 branches covered (69.03%)

Branch coverage included in aggregate %.

614 of 661 new or added lines in 20 files covered. (92.89%)

545 existing lines in 20 files now uncovered.

59935 of 69618 relevant lines covered (86.09%)

49705850.0 hits per line

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

85.76
/src/particle.cpp
1
#include "openmc/particle.h"
2

3
#include <algorithm> // copy, min
4
#include <cmath>     // log, abs
5

6
#include <fmt/core.h>
7

8
#include "openmc/bank.h"
9
#include "openmc/capi.h"
10
#include "openmc/cell.h"
11
#include "openmc/collision_track.h"
12
#include "openmc/constants.h"
13
#include "openmc/dagmc.h"
14
#include "openmc/error.h"
15
#include "openmc/geometry.h"
16
#include "openmc/hdf5_interface.h"
17
#include "openmc/lattice.h"
18
#include "openmc/majorant.h"
19
#include "openmc/material.h"
20
#include "openmc/message_passing.h"
21
#include "openmc/mgxs_interface.h"
22
#include "openmc/nuclide.h"
23
#include "openmc/particle_data.h"
24
#include "openmc/photon.h"
25
#include "openmc/physics.h"
26
#include "openmc/physics_mg.h"
27
#include "openmc/random_lcg.h"
28
#include "openmc/settings.h"
29
#include "openmc/simulation.h"
30
#include "openmc/source.h"
31
#include "openmc/surface.h"
32
#include "openmc/tallies/derivative.h"
33
#include "openmc/tallies/tally.h"
34
#include "openmc/tallies/tally_scoring.h"
35
#include "openmc/track_output.h"
36
#include "openmc/weight_windows.h"
37

38
#ifdef OPENMC_DAGMC_ENABLED
39
#include "DagMC.hpp"
40
#endif
41

42
namespace openmc {
43

44
//==============================================================================
45
// Particle implementation
46
//==============================================================================
47

48
double Particle::speed() const
2,147,483,647✔
49
{
50
  if (settings::run_CE) {
2,147,483,647✔
51
    // Determine mass in eV/c^2
52
    double mass = this->mass();
2,147,483,647✔
53

54
    // Equivalent to C * sqrt(1-(m/(m+E))^2) without problem at E<<m:
55
    return C_LIGHT * std::sqrt(this->E() * (this->E() + 2 * mass)) /
2,147,483,647✔
56
           (this->E() + mass);
2,147,483,647✔
57
  } else {
58
    auto mat = this->material();
2,082,832,565✔
59
    if (mat == MATERIAL_VOID)
2,082,832,565!
60
      return 1.0 / data::mg.default_inverse_velocity_[this->g()];
×
61
    auto& macro_xs = data::mg.macro_xs_[mat];
2,082,832,565✔
62
    int macro_t = this->mg_xs_cache().t;
2,082,832,565✔
63
    int macro_a = macro_xs.get_angle_index(this->u());
2,082,832,565✔
64
    return 1.0 / macro_xs.get_xs(
2,147,483,647✔
65
                   MgxsType::INVERSE_VELOCITY, this->g(), macro_t, macro_a);
2,082,832,565✔
66
  }
67
}
68

69
double Particle::mass() const
2,147,483,647✔
70
{
71
  switch (type().pdg_number()) {
2,147,483,647✔
72
  case PDG_NEUTRON:
73
    return MASS_NEUTRON_EV;
74
  case PDG_ELECTRON:
248,312,828✔
75
  case PDG_POSITRON:
248,312,828✔
76
    return MASS_ELECTRON_EV;
248,312,828✔
77
  default:
127,282,718✔
78
    return this->type().mass() * AMU_EV;
127,282,718✔
79
  }
80
}
81

82
bool Particle::create_secondary(
519,051,947✔
83
  double wgt, Direction u, double E, ParticleType type)
84
{
85
  // If energy is below cutoff for this particle, don't create secondary
86
  // particle
87
  int idx = type.transport_index();
519,051,947✔
88
  if (idx == C_NONE) {
519,051,947!
89
    return false;
90
  }
91
  if (E < settings::energy_cutoff[idx]) {
519,051,947✔
92
    return false;
93
  }
94

95
  // Increment number of secondaries created (for ParticleProductionFilter)
96
  n_secondaries()++;
271,413,890✔
97

98
  SourceSite bank;
271,413,890✔
99
  bank.particle = type;
271,413,890✔
100
  bank.wgt = wgt;
271,413,890✔
101
  bank.r = r();
271,413,890!
102
  bank.u = u;
271,413,890✔
103
  bank.E = settings::run_CE ? E : g();
271,413,890!
104
  bank.time = time();
271,413,890✔
105
  bank_second_E() += bank.E;
271,413,890✔
106
  bank.parent_id = current_work();
271,413,890✔
107
  if (settings::use_shared_secondary_bank) {
271,413,890✔
108
    bank.progeny_id = n_progeny()++;
15,375,610✔
109
  }
110
  bank.wgt_born = wgt_born();
271,413,890✔
111
  bank.wgt_ww_born = wgt_ww_born();
271,413,890✔
112
  bank.n_split = n_split();
271,413,890✔
113

114
  local_secondary_bank().emplace_back(bank);
271,413,890✔
115
  return true;
116
}
117

118
void Particle::split(double wgt)
10,780,381✔
119
{
120
  SourceSite bank;
10,780,381✔
121
  bank.particle = type();
10,780,381✔
122
  bank.wgt = wgt;
10,780,381✔
123
  bank.r = r();
10,780,381✔
124
  bank.u = u();
10,780,381✔
125
  bank.E = settings::run_CE ? E() : g();
10,780,381✔
126
  bank.time = time();
10,780,381✔
127

128
  // Convert signed index to a signed surface ID
129
  if (surface() == SURFACE_NONE) {
10,780,381✔
130
    bank.surf_id = SURFACE_NONE;
10,776,509✔
131
  } else {
132
    int surf_id = model::surfaces[surface_index()]->id_;
3,872✔
133
    bank.surf_id = (surface() > 0) ? surf_id : -surf_id;
3,872✔
134
  }
135

136
  bank.wgt_born = wgt_born();
10,780,381✔
137
  bank.wgt_ww_born = wgt_ww_born();
10,780,381✔
138
  bank.n_split = n_split();
10,780,381✔
139
  bank.parent_id = current_work();
10,780,381✔
140
  if (settings::use_shared_secondary_bank) {
10,780,381✔
141
    bank.progeny_id = n_progeny()++;
5,135,441✔
142
  }
143

144
  local_secondary_bank().emplace_back(bank);
10,780,381✔
145
}
10,780,381✔
146

147
void Particle::from_source(const SourceSite* src)
471,372,620✔
148
{
149
  // Reset some attributes
150
  clear();
471,372,620✔
151
  surface() = SURFACE_NONE;
471,372,620✔
152
  cell_born() = C_NONE;
471,372,620✔
153
  material() = C_NONE;
471,372,620✔
154
  n_collision() = 0;
471,372,620✔
155
  fission() = false;
471,372,620✔
156
  majorant() = 0.0;
471,372,620✔
157
  zero_flux_derivs();
471,372,620✔
158
  lifetime() = 0.0;
471,372,620✔
159
#ifdef OPENMC_DAGMC_ENABLED
160
  history().reset();
43,022,302✔
161
#endif
162

163
  // Copy attributes from source bank site
164
  type() = src->particle;
471,372,620✔
165
  wgt() = src->wgt;
471,372,620✔
166
  wgt_last() = src->wgt;
471,372,620✔
167
  r() = src->r;
471,372,620✔
168
  u() = src->u;
471,372,620✔
169
  r_born() = src->r;
471,372,620✔
170
  r_last_current() = src->r;
471,372,620✔
171
  r_last() = src->r;
471,372,620✔
172
  u_last() = src->u;
471,372,620✔
173
  if (settings::run_CE) {
471,372,620✔
174
    E() = src->E;
354,506,756✔
175
    g() = 0;
354,506,756✔
176
  } else {
177
    g() = static_cast<int>(src->E);
116,865,864✔
178
    g_last() = static_cast<int>(src->E);
116,865,864✔
179
    E() = data::mg.energy_bin_avg_[g()];
116,865,864✔
180
  }
181
  E_last() = E();
471,372,620✔
182
  time() = src->time;
471,372,620✔
183
  time_last() = src->time;
471,372,620✔
184
  parent_nuclide() = src->parent_nuclide;
471,372,620✔
185
  delayed_group() = src->delayed_group;
471,372,620✔
186

187
  // Convert signed surface ID to signed index
188
  if (src->surf_id != SURFACE_NONE) {
471,372,620✔
189
    int index_plus_one = model::surface_map[std::abs(src->surf_id)] + 1;
113,872✔
190
    surface() = (src->surf_id > 0) ? index_plus_one : -index_plus_one;
113,872✔
191
  }
192

193
  wgt_born() = src->wgt_born;
471,372,620✔
194
  wgt_ww_born() = src->wgt_ww_born;
471,372,620✔
195
  n_split() = src->n_split;
471,372,620✔
196

197
  if (delta_tracking()) {
471,372,620✔
198
    update_majorant();
168,145,865✔
199
  }
200
}
471,372,620✔
201

202
void Particle::event_calculate_xs()
2,147,483,647✔
203
{
204
  // Set the random number stream
205
  stream() = STREAM_TRACKING;
2,147,483,647✔
206

207
  // Store pre-collision particle properties
208
  wgt_last() = wgt();
2,147,483,647✔
209
  E_last() = E();
2,147,483,647✔
210
  u_last() = u();
2,147,483,647✔
211
  r_last() = r();
2,147,483,647✔
212
  time_last() = time();
2,147,483,647✔
213

214
  // Reset event variables
215
  event() = TallyEvent::KILL;
2,147,483,647✔
216
  event_nuclide() = NUCLIDE_NONE;
2,147,483,647✔
217
  event_mt() = REACTION_NONE;
2,147,483,647✔
218

219
  // If the cell hasn't been determined based on the particle's location,
220
  // initiate a search for the current cell. This generally happens at the
221
  // beginning of the history and again for any secondary particles
222
  if (lowest_coord().cell() == C_NONE) {
2,147,483,647✔
223
    if (!exhaustive_find_cell(*this)) {
293,368,052!
224
      mark_as_lost(
×
225
        "Could not find the cell containing particle " + std::to_string(id()));
×
226
      return;
×
227
    }
228

229
    // Set birth cell attribute
230
    if (cell_born() == C_NONE)
293,368,052!
231
      cell_born() = lowest_coord().cell();
293,368,052✔
232

233
    // Initialize last cells from current cell
234
    for (int j = 0; j < n_coord(); ++j) {
604,228,944✔
235
      cell_last(j) = coord(j).cell();
310,860,892✔
236
    }
237
    n_coord_last() = n_coord();
293,368,052✔
238
  }
239

240
  // Write particle track.
241
  if (write_track())
2,147,483,647✔
242
    write_particle_track(*this);
10,319✔
243

244
  if (settings::check_overlaps)
2,147,483,647!
245
    check_cell_overlap(*this);
×
246

247
  // Calculate microscopic and macroscopic cross sections
248
  if (material() != MATERIAL_VOID) {
2,147,483,647✔
249
    if (settings::run_CE) {
2,147,483,647✔
250
      if (material() != material_last() || sqrtkT() != sqrtkT_last() ||
2,147,483,647✔
251
          density_mult() != density_mult_last()) {
902,532,080✔
252
        // If the material is the same as the last material and the
253
        // temperature hasn't changed, we don't need to lookup cross
254
        // sections again.
255
        model::materials[material()]->calculate_xs(*this);
2,147,483,647✔
256
      }
257
    } else {
258
      // Get the MG data; unlike the CE case above, we have to re-calculate
259
      // cross sections for every collision since the cross sections may
260
      // be angle-dependent
261
      data::mg.macro_xs_[material()].calculate_xs(*this);
2,082,832,565✔
262

263
      // Update the particle's group while we know we are multi-group
264
      g_last() = g();
2,082,832,565✔
265
    }
266
  } else {
267
    macro_xs().total = 0.0;
111,961,605✔
268
    macro_xs().absorption = 0.0;
111,961,605✔
269
    macro_xs().fission = 0.0;
111,961,605✔
270
    macro_xs().nu_fission = 0.0;
111,961,605✔
271
  }
272
}
273

274
void Particle::event_advance()
2,147,483,647✔
275
{
276
  // Find the distance to the nearest boundary
277
  boundary() = distance_to_boundary(*this);
2,147,483,647✔
278

279
  // Sample a distance to collision
280
  if (type() == ParticleType::electron() ||
2,147,483,647✔
281
      type() == ParticleType::positron()) {
2,147,483,647✔
282
    collision_distance() = material() == MATERIAL_VOID ? INFINITY : 0.0;
191,639,304!
283
  } else if (macro_xs().total == 0.0) {
2,147,483,647✔
284
    collision_distance() = INFINITY;
111,961,605✔
285
  } else {
286
    collision_distance() = -std::log(prn(current_seed())) / macro_xs().total;
2,147,483,647✔
287
  }
288

289
  double speed = this->speed();
2,147,483,647✔
290
  double time_cutoff = settings::time_cutoff[type().transport_index()];
2,147,483,647✔
291
  double distance_cutoff =
2,147,483,647✔
292
    (time_cutoff < INFTY) ? (time_cutoff - time()) * speed : INFTY;
2,147,483,647✔
293

294
  // Select smaller of the three distances
295
  double distance =
2,147,483,647✔
296
    std::min({boundary().distance(), collision_distance(), distance_cutoff});
2,147,483,647✔
297

298
  // Advance particle in space and time
299
  this->move_distance(distance);
2,147,483,647✔
300
  double dt = distance / speed;
2,147,483,647✔
301
  this->time() += dt;
2,147,483,647✔
302
  this->lifetime() += dt;
2,147,483,647✔
303

304
  // Score timed track-length tallies
305
  if (!model::active_timed_tracklength_tallies.empty()) {
2,147,483,647✔
306
    score_timed_tracklength_tally(*this, distance);
3,628,317✔
307
  }
308

309
  // Score track-length tallies
310
  if (!model::active_tracklength_tallies.empty()) {
2,147,483,647✔
311
    score_tracklength_tally(*this, distance);
2,147,483,647✔
312
  }
313

314
  // Score track-length estimate of k-eff
315
  if (settings::run_mode == RunMode::EIGENVALUE && type().is_neutron() &&
2,147,483,647✔
316
      !delta_tracking()) {
2,147,483,647!
317
    keff_tally_tracklength() += wgt() * distance * macro_xs().nu_fission;
2,147,483,647✔
318
  }
319

320
  // Score flux derivative accumulators for differential tallies.
321
  if (!model::active_tallies.empty()) {
2,147,483,647✔
322
    score_track_derivative(*this, distance);
2,147,483,647✔
323
  }
324

325
  // Set particle weight to zero if it hit the time boundary
326
  if (distance == distance_cutoff) {
2,147,483,647✔
327
    wgt() = 0.0;
224,928✔
328
  }
329
}
2,147,483,647✔
330

331
void Particle::event_delta_advance()
264,250,987✔
332
{
333
  if (E() != E_last()) {
264,250,987✔
334
    update_majorant();
23,478,048✔
335
  }
336

337
  // Sample distance to next position
338
  if (type() == ParticleType::electron() ||
264,250,987✔
339
      type() == ParticleType::positron()) {
111,895,432✔
340
    // Electrons/positrons don't move
341
    collision_distance() = 0.0;
152,493,176✔
342
  } else if (majorant() == 0.0) {
111,757,811!
343
    // For a void majorant (rare but possible for a source in a void),
344
    // the collision distance is infinity.
NEW
345
    collision_distance() = INFINITY;
×
346
  } else {
347
    // Sample collision distance based on the majorant for this energy.
348
    collision_distance() = -std::log(prn(current_seed())) / majorant();
111,757,811✔
349
  }
350

351
  // Update distance to problem boundary. Particles with large majorant
352
  // cross sections will tunnel out of the domain if a floating point
353
  // tolerance is not specified on the boundary distance calculation.
354
  boundary() = distance_to_external_boundary(*this);
264,250,987✔
355
  boundary().distance() -= FP_REL_PRECISION;
264,250,987✔
356

357
  double speed = this->speed();
264,250,987✔
358
  double time_cutoff = settings::time_cutoff[type().transport_index()];
264,250,987!
359
  double distance_cutoff =
264,250,987✔
360
    (time_cutoff < INFTY) ? (time_cutoff - time()) * speed : INFTY;
264,250,987!
361

362
  // Move to the external boundary, delta tracking collision site, or time
363
  // cutoff distance.
364
  double distance =
264,250,987✔
365
    std::min({collision_distance(), boundary().distance(), distance_cutoff});
264,250,987✔
366
  move_distance(distance);
264,250,987✔
367

368
  // Advance particle in time.
369
  double dt = distance / speed;
264,250,987✔
370
  time() += dt;
264,250,987✔
371
  lifetime() += dt;
264,250,987✔
372

373
  // Need to locate the particle at the collision site or boundary.
374
  for (int j = 0; j < n_coord(); ++j) {
623,807,096✔
375
    coord(j).reset();
359,556,109✔
376
  }
377
  if (!exhaustive_find_cell(*this)) {
264,250,987!
378
    // We've lost this particle.
NEW
379
    mark_as_lost(fmt::format(
×
NEW
380
      "Particle {} could not be located while running delta tracking!", id()));
×
NEW
381
    return;
×
382
  }
383

384
  // Force re-calculation of material properties at the collision site.
385
  material_last() = C_NONE;
264,250,987✔
386

387
  // Set particle weight to zero if it hit the time boundary
388
  if (distance == distance_cutoff) {
264,250,987!
NEW
389
    wgt() = 0.0;
×
390
  }
391
}
392

393
void Particle::event_cross_surface()
2,147,483,647✔
394
{
395
  // Saving previous cell data
396
  for (int j = 0; j < n_coord(); ++j) {
2,147,483,647✔
397
    cell_last(j) = coord(j).cell();
2,147,483,647✔
398
  }
399
  n_coord_last() = n_coord();
2,147,483,647✔
400

401
  // Set surface that particle is on and adjust coordinate levels
402
  surface() = boundary().surface();
2,147,483,647✔
403
  n_coord() = boundary().coord_level();
2,147,483,647✔
404

405
  if (boundary().lattice_translation()[0] != 0 ||
2,147,483,647✔
406
      boundary().lattice_translation()[1] != 0 ||
2,147,483,647✔
407
      boundary().lattice_translation()[2] != 0) {
2,147,483,647✔
408
    // Particle crosses lattice boundary
409

410
    int i_lattice = coord(boundary().coord_level() - 1).lattice();
801,517,771!
411
    bool verbose = settings::verbosity >= 10 || trace();
801,517,771!
412
    cross_lattice(*this, boundary(), verbose);
801,517,771✔
413
    event() = TallyEvent::LATTICE;
801,517,771✔
414

415
    // Score cell to cell partial currents
416
    if (!model::active_surface_tallies.empty()) {
801,517,771✔
417
      auto& lat {*model::lattices[i_lattice]};
55✔
418
      bool is_valid;
55✔
419
      Direction normal =
55✔
420
        lat.get_normal(boundary().lattice_translation(), is_valid);
55✔
421
      if (is_valid) {
55!
422
        normal /= normal.norm();
55✔
423
        score_surface_tally(*this, model::active_surface_tallies, normal);
55✔
424
      }
425
    }
426

427
  } else {
428

429
    const auto& surf {*model::surfaces[surface_index()].get()};
2,147,483,647✔
430

431
    // Particle crosses surface
432
    // If BC, add particle to surface source before crossing surface
433
    if (surf.surf_source_ && surf.bc_) {
2,147,483,647✔
434
      add_surf_source_to_bank(*this, surf);
1,023,162,132✔
435
    }
436
    this->cross_surface(surf);
2,147,483,647✔
437
    // If no BC, add particle to surface source after crossing surface
438
    if (surf.surf_source_ && !surf.bc_) {
2,147,483,647✔
439
      add_surf_source_to_bank(*this, surf);
1,851,429,240✔
440
    }
441
    if (settings::weight_window_checkpoint_surface) {
2,147,483,647✔
442
      apply_weight_windows(*this);
174,249✔
443
    }
444
    event() = TallyEvent::SURFACE;
2,147,483,647✔
445

446
    // Score cell to cell partial currents
447
    if (!model::active_surface_tallies.empty()) {
2,147,483,647✔
448
      Direction normal = surf.normal(r());
34,931,622✔
449
      normal /= normal.norm();
34,931,622✔
450
      score_surface_tally(*this, model::active_surface_tallies, normal);
34,931,622✔
451
    }
452
  }
453
}
2,147,483,647✔
454

455
void Particle::event_collide()
2,147,483,647✔
456
{
457
  // Score collision estimate of keff
458
  if (settings::run_mode == RunMode::EIGENVALUE && type().is_neutron()) {
2,147,483,647✔
459
    keff_tally_collision() += wgt() * macro_xs().nu_fission / macro_xs().total;
2,147,483,647✔
460
  }
461

462
  // Score surface current tallies -- this has to be done before the collision
463
  // since the direction of the particle will change and we need to use the
464
  // pre-collision direction to figure out what mesh surfaces were crossed
465

466
  if (!model::active_meshsurf_tallies.empty())
2,147,483,647✔
467
    score_meshsurface_tally(*this, model::active_meshsurf_tallies);
63,098,926✔
468

469
  // Clear surface component
470
  surface() = SURFACE_NONE;
2,147,483,647✔
471

472
  if (settings::run_CE) {
2,147,483,647✔
473
    collision(*this);
1,673,528,621✔
474
  } else {
475
    collision_mg(*this);
1,801,144,774✔
476
  }
477

478
  // Collision track feature to recording particle interaction
479
  if (settings::collision_track) {
2,147,483,647✔
480
    collision_track_record(*this);
728,673✔
481
  }
482

483
  // Score collision estimator tallies -- this is done after a collision
484
  // has occurred rather than before because we need information on the
485
  // outgoing energy for any tallies with an outgoing energy filter
486
  if (!model::active_collision_tallies.empty())
2,147,483,647✔
487
    score_collision_tally(*this);
201,993,703✔
488
  if (!model::active_analog_tallies.empty()) {
2,147,483,647✔
489
    if (settings::run_CE) {
406,229,898✔
490
      score_analog_tally_ce(*this);
405,021,636✔
491
    } else {
492
      score_analog_tally_mg(*this);
1,208,262✔
493
    }
494
  }
495

496
  if (!model::active_pulse_height_tallies.empty() && type().is_photon()) {
2,147,483,647✔
497
    pht_collision_energy();
8,668✔
498
  }
499

500
  // Reset banked weight during collision
501
  n_bank() = 0;
2,147,483,647✔
502
  bank_second_E() = 0.0;
2,147,483,647✔
503
  wgt_bank() = 0.0;
2,147,483,647✔
504

505
  // Clear number of secondaries in this collision. This is
506
  // distinct from the number of created neutrons n_bank() above!
507
  n_secondaries() = 0;
2,147,483,647✔
508

509
  zero_delayed_bank();
2,147,483,647✔
510

511
  // Reset fission logical
512
  fission() = false;
2,147,483,647✔
513

514
  // Save coordinates for tallying purposes
515
  r_last_current() = r();
2,147,483,647✔
516

517
  // Set last material to none since cross sections will need to be
518
  // re-evaluated
519
  material_last() = C_NONE;
2,147,483,647✔
520

521
  // Set all directions to base level -- right now, after a collision, only
522
  // the base level directions are changed
523
  for (int j = 0; j < n_coord() - 1; ++j) {
2,147,483,647✔
524
    if (coord(j + 1).rotated()) {
477,842,159✔
525
      // If next level is rotated, apply rotation matrix
526
      const auto& m {model::cells[coord(j).cell()]->rotation_};
11,724,229✔
527
      const auto& u {coord(j).u()};
11,724,229✔
528
      coord(j + 1).u() = u.rotate(m);
11,724,229✔
529
    } else {
530
      // Otherwise, copy this level's direction
531
      coord(j + 1).u() = coord(j).u();
466,117,930✔
532
    }
533
  }
534

535
  // Score flux derivative accumulators for differential tallies.
536
  if (!model::active_tallies.empty())
2,147,483,647✔
537
    score_collision_derivative(*this);
1,418,935,459✔
538

539
#ifdef OPENMC_DAGMC_ENABLED
540
  history().reset();
317,724,023✔
541
#endif
542
}
2,147,483,647✔
543

544
void Particle::event_revive_from_secondary(const SourceSite& site)
283,208,468✔
545
{
546
  // Write final position for the previous track (skip if this is a freshly
547
  // constructed particle with no prior track, e.g., Phase 2 of shared
548
  // secondary transport)
549
  if (write_track() && n_event() > 0) {
283,208,468!
550
    write_particle_track(*this);
5,234✔
551
  }
552

553
  from_source(&site);
283,208,468✔
554

555
  n_event() = 0;
283,208,468✔
556
  if (!settings::use_shared_secondary_bank) {
283,208,468✔
557
    n_tracks()++;
261,891,755✔
558
  }
559
  bank_second_E() = 0.0;
283,208,468✔
560

561
  // Subtract secondary particle energy from interim pulse-height results.
562
  // In shared secondary mode, this subtraction was already done on the parent
563
  // particle during create_secondary(), so skip it here.
564
  if (!settings::use_shared_secondary_bank &&
545,100,223✔
565
      !model::active_pulse_height_tallies.empty() && this->type().is_photon()) {
283,208,468✔
566
    // Since the birth cell of the particle has not been set we
567
    // have to determine it before the energy of the secondary particle can be
568
    // removed from the pulse-height of this cell.
569
    if (lowest_coord().cell() == C_NONE) {
3,168!
570
      bool verbose = settings::verbosity >= 10 || trace();
3,168!
571
      if (!exhaustive_find_cell(*this, verbose)) {
3,168!
572
        mark_as_lost("Could not find the cell containing particle " +
×
573
                     std::to_string(id()));
×
UNCOV
574
        return;
×
575
      }
576
      // Set birth cell attribute
577
      if (cell_born() == C_NONE)
3,168!
578
        cell_born() = lowest_coord().cell();
3,168✔
579

580
      // Initialize last cells from current cell
581
      for (int j = 0; j < n_coord(); ++j) {
6,336✔
582
        cell_last(j) = coord(j).cell();
3,168✔
583
      }
584
      n_coord_last() = n_coord();
3,168✔
585
    }
586
    pht_secondary_particles();
3,168✔
587
  }
588

589
  // Enter new particle in particle track file
590
  if (write_track())
283,208,468✔
591
    add_particle_track(*this);
5,234✔
592
}
593

594
void Particle::event_check_limit_and_revive()
2,147,483,647✔
595
{
596
  // If particle has too many events, display warning and kill it
597
  n_event()++;
2,147,483,647✔
598
  if (n_event() == settings::max_particle_events) {
2,147,483,647!
UNCOV
599
    warning("Particle " + std::to_string(id()) +
×
600
            " underwent maximum number of events.");
UNCOV
601
    wgt() = 0.0;
×
602
  }
603

604
  // In non-shared-secondary mode, revive from local secondary bank
605
  if (!alive() && !settings::use_shared_secondary_bank &&
2,147,483,647✔
606
      !local_secondary_bank().empty()) {
440,214,867✔
607
    SourceSite& site = local_secondary_bank().back();
261,891,755✔
608
    event_revive_from_secondary(site);
261,891,755✔
609
    local_secondary_bank().pop_back();
261,891,755✔
610
  }
611
}
2,147,483,647✔
612

613
void Particle::event_death()
200,425,321✔
614
{
615
#ifdef OPENMC_DAGMC_ENABLED
616
  history().reset();
18,292,279✔
617
#endif
618

619
  // Finish particle track output.
620
  if (write_track()) {
200,425,321✔
621
    write_particle_track(*this);
1,010✔
622
    finalize_particle_track(*this);
1,010✔
623
  }
624

625
// Contribute tally reduction variables to global accumulator
626
#pragma omp atomic
109,725,422✔
627
  global_tally_absorption += keff_tally_absorption();
200,425,321✔
628
#pragma omp atomic
109,459,750✔
629
  global_tally_collision += keff_tally_collision();
200,425,321✔
630
  if (!delta_tracking()) {
200,425,321✔
631
#pragma omp atomic
109,026,517✔
632
    global_tally_tracklength += keff_tally_tracklength();
199,325,321✔
633
  }
634
#pragma omp atomic
109,548,057✔
635
  global_tally_leakage += keff_tally_leakage();
200,425,321✔
636

637
  // Reset particle tallies once accumulated
638
  keff_tally_absorption() = 0.0;
200,425,321✔
639
  keff_tally_collision() = 0.0;
200,425,321✔
640
  keff_tally_tracklength() = 0.0;
200,425,321✔
641
  keff_tally_leakage() = 0.0;
200,425,321✔
642

643
  if (!model::active_pulse_height_tallies.empty()) {
200,425,321✔
644
    score_pulse_height_tally(*this, model::active_pulse_height_tallies);
33,000✔
645
  }
646

647
  // Accumulate track count for this particle history
648
  if (!settings::use_shared_secondary_bank) {
200,425,321✔
649
#pragma omp atomic
97,348,272✔
650
    simulation::simulation_tracks_completed += n_tracks();
178,324,112✔
651
  }
652

653
  // Record the number of progeny created by this particle.
654
  // This data will be used to efficiently sort the fission bank.
655
  if (settings::run_mode == RunMode::EIGENVALUE ||
200,425,321✔
656
      settings::use_shared_secondary_bank) {
657
    simulation::progeny_per_particle[current_work()] = n_progeny();
173,105,209✔
658
  }
659
}
200,425,321✔
660

661
void Particle::pht_collision_energy()
8,668✔
662
{
663
  // Adds the energy particles lose in a collision to the pulse-height
664

665
  // determine index of cell in pulse_height_cells
666
  auto it = std::find(model::pulse_height_cells.begin(),
8,668✔
667
    model::pulse_height_cells.end(), lowest_coord().cell());
8,668!
668

669
  if (it != model::pulse_height_cells.end()) {
8,668!
670
    int index = std::distance(model::pulse_height_cells.begin(), it);
8,668✔
671
    pht_storage()[index] += E_last() - E();
8,668✔
672

673
    // If the energy of the particle is below the cutoff, it will not be sampled
674
    // so its energy is added to the pulse-height in the cell
675
    int photon = ParticleType::photon().transport_index();
8,668✔
676
    if (E() < settings::energy_cutoff[photon]) {
8,668✔
677
      pht_storage()[index] += E();
3,740✔
678
    }
679
  }
680
}
8,668✔
681

682
void Particle::pht_secondary_particles()
3,168✔
683
{
684
  // Removes the energy of secondary produced particles from the pulse-height
685

686
  // determine index of cell in pulse_height_cells
687
  auto it = std::find(model::pulse_height_cells.begin(),
3,168✔
688
    model::pulse_height_cells.end(), cell_born());
3,168!
689

690
  if (it != model::pulse_height_cells.end()) {
3,168!
691
    int index = std::distance(model::pulse_height_cells.begin(), it);
3,168✔
692
    pht_storage()[index] -= E();
3,168✔
693
  }
694
}
3,168✔
695

696
void Particle::cross_surface(const Surface& surf)
2,147,483,647✔
697
{
698

699
  if (settings::verbosity >= 10 || trace()) {
2,147,483,647✔
700
    write_message(1, "    Crossing surface {}", surf.id_);
88✔
701
  }
702

703
// if we're crossing a CSG surface, make sure the DAG history is reset
704
#ifdef OPENMC_DAGMC_ENABLED
705
  if (surf.geom_type() == GeometryType::CSG)
262,294,007✔
706
    history().reset();
262,236,325✔
707
#endif
708

709
  // Handle any applicable boundary conditions.
710
  if (surf.bc_ && settings::run_mode != RunMode::PLOTTING &&
2,147,483,647!
711
      settings::run_mode != RunMode::VOLUME) {
712
    surf.bc_->handle_particle(*this, surf);
1,023,514,240✔
713
    return;
1,023,514,240✔
714
  }
715

716
  // ==========================================================================
717
  // SEARCH NEIGHBOR LISTS FOR NEXT CELL
718

719
#ifdef OPENMC_DAGMC_ENABLED
720
  // in DAGMC, we know what the next cell should be
721
  if (surf.geom_type() == GeometryType::DAG) {
168,803,648✔
722
    int32_t i_cell = next_cell(surface_index(), cell_last(n_coord() - 1),
46,742✔
723
                       lowest_coord().universe()) -
46,742✔
724
                     1;
46,742✔
725
    // save material, temperature, and density multiplier
726
    material_last() = material();
46,742✔
727
    sqrtkT_last() = sqrtkT();
46,742✔
728
    density_mult_last() = density_mult();
46,742✔
729
    // set new cell value
730
    lowest_coord().cell() = i_cell;
46,742✔
731
    auto& cell = model::cells[i_cell];
46,742✔
732

733
    cell_instance() = 0;
46,742✔
734
    if (cell->distribcell_index_ >= 0)
46,742✔
735
      cell_instance() = cell_instance_at_level(*this, n_coord() - 1);
45,718✔
736

737
    material() = cell->material(cell_instance());
46,742!
738
    sqrtkT() = cell->sqrtkT(cell_instance());
46,742!
739
    density_mult() = cell->density_mult(cell_instance());
46,742✔
740
    return;
46,742✔
741
  }
742
#endif
743

744
  bool verbose = settings::verbosity >= 10 || trace();
1,854,222,650!
745
  if (neighbor_list_find_cell(*this, verbose)) {
1,854,222,650✔
746
    return;
747
  }
748

749
  // ==========================================================================
750
  // COULDN'T FIND PARTICLE IN NEIGHBORING CELLS, SEARCH ALL CELLS
751

752
  // Remove lower coordinate levels
753
  n_coord() = 1;
29,977✔
754
  bool found = exhaustive_find_cell(*this, verbose);
29,977✔
755

756
  if (settings::run_mode != RunMode::PLOTTING && (!found)) {
29,977!
757
    // If a cell is still not found, there are two possible causes: 1) there is
758
    // a void in the model, and 2) the particle hit a surface at a tangent. If
759
    // the particle is really traveling tangent to a surface, if we move it
760
    // forward a tiny bit it should fix the problem.
761

762
    surface() = SURFACE_NONE;
5,865✔
763
    n_coord() = 1;
5,865✔
764
    r() += TINY_BIT * u();
5,865✔
765

766
    // Couldn't find next cell anywhere! This probably means there is an actual
767
    // undefined region in the geometry.
768

769
    if (!exhaustive_find_cell(*this, verbose)) {
5,865!
770
      mark_as_lost("After particle " + std::to_string(id()) +
17,586✔
771
                   " crossed surface " + std::to_string(surf.id_) +
17,586✔
772
                   " it could not be located in any cell and it did not leak.");
773
      return;
5,856✔
774
    }
775
  }
776
}
777

778
void Particle::cross_vacuum_bc(const Surface& surf)
37,459,199✔
779
{
780
  // Score any surface current tallies -- note that the particle is moved
781
  // forward slightly so that if the mesh boundary is on the surface, it is
782
  // still processed
783

784
  if (!model::active_meshsurf_tallies.empty()) {
37,459,199✔
785
    // TODO: Find a better solution to score surface currents than
786
    // physically moving the particle forward slightly
787

788
    r() += TINY_BIT * u();
937,222✔
789
    score_meshsurface_tally(*this, model::active_meshsurf_tallies);
937,222✔
790
  }
791

792
  // Score to global leakage tally
793
  keff_tally_leakage() += wgt();
37,459,199✔
794

795
  // Kill the particle
796
  wgt() = 0.0;
37,459,199✔
797

798
  // Display message
799
  if (settings::verbosity >= 10 || trace()) {
37,459,199!
800
    write_message(1, "    Leaked out of surface {}", surf.id_);
22✔
801
  }
802
}
37,459,199✔
803

804
void Particle::cross_reflective_bc(const Surface& surf, Direction new_u)
983,889,625✔
805
{
806
  // Do not handle reflective boundary conditions on lower universes
807
  if (n_coord() != 1) {
983,889,625!
UNCOV
808
    mark_as_lost("Cannot reflect particle " + std::to_string(id()) +
×
809
                 " off surface in a lower universe.");
UNCOV
810
    return;
×
811
  }
812

813
  // Score surface currents since reflection causes the direction of the
814
  // particle to change. For surface filters, we need to score the tallies
815
  // twice, once before the particle's surface attribute has changed and
816
  // once after. For mesh surface filters, we need to artificially move
817
  // the particle slightly back in case the surface crossing is coincident
818
  // with a mesh boundary
819

820
  if (!model::active_surface_tallies.empty()) {
983,889,625✔
821
    Direction normal = surf.normal(r());
285,021✔
822
    normal /= normal.norm();
285,021✔
823
    score_surface_tally(*this, model::active_surface_tallies, normal);
285,021✔
824
  }
825

826
  if (!model::active_meshsurf_tallies.empty()) {
983,889,625✔
827
    Position r {this->r()};
46,885,487✔
828
    this->r() -= TINY_BIT * u();
46,885,487✔
829
    score_meshsurface_tally(*this, model::active_meshsurf_tallies);
46,885,487✔
830
    this->r() = r;
46,885,487✔
831
  }
832

833
  // Set the new particle direction
834
  u() = new_u;
983,889,625✔
835

836
  // Reassign particle's cell and surface
837
  coord(0).cell() = cell_last(0);
983,889,625✔
838
  surface() = -surface();
983,889,625✔
839

840
  // If a reflective surface is coincident with a lattice or universe
841
  // boundary, it is necessary to redetermine the particle's coordinates in
842
  // the lower universes.
843
  // (unless we're using a dagmc model, which has exactly one universe)
844
  n_coord() = 1;
983,889,625✔
845
  if (surf.geom_type() != GeometryType::DAG &&
1,967,776,492!
846
      !neighbor_list_find_cell(*this)) {
983,886,867✔
847
    mark_as_lost("Couldn't find particle after reflecting from surface " +
×
848
                 std::to_string(surf.id_) + ".");
×
UNCOV
849
    return;
×
850
  }
851

852
  // Set previous coordinate going slightly past surface crossing
853
  r_last_current() = r() + TINY_BIT * u();
983,889,625✔
854

855
  // Diagnostic message
856
  if (settings::verbosity >= 10 || trace()) {
983,889,625!
UNCOV
857
    write_message(1, "    Reflected from surface {}", surf.id_);
×
858
  }
859
}
860

861
void Particle::cross_periodic_bc(
3,170,882✔
862
  const Surface& surf, Position new_r, Direction new_u, int new_surface)
863
{
864
  // Do not handle periodic boundary conditions on lower universes
865
  if (n_coord() != 1) {
3,170,882!
866
    mark_as_lost(
×
UNCOV
867
      "Cannot transfer particle " + std::to_string(id()) +
×
868
      " across surface in a lower universe. Boundary conditions must be "
869
      "applied to root universe.");
UNCOV
870
    return;
×
871
  }
872

873
  // Score surface currents since reflection causes the direction of the
874
  // particle to change -- artificially move the particle slightly back in
875
  // case the surface crossing is coincident with a mesh boundary
876
  if (!model::active_meshsurf_tallies.empty()) {
3,170,882!
877
    Position r {this->r()};
×
878
    this->r() -= TINY_BIT * u();
×
879
    score_meshsurface_tally(*this, model::active_meshsurf_tallies);
×
UNCOV
880
    this->r() = r;
×
881
  }
882

883
  // Adjust the particle's location and direction.
884
  r() = new_r;
3,170,882✔
885
  u() = new_u;
3,170,882✔
886

887
  // Reassign particle's surface
888
  surface() = new_surface;
3,170,882✔
889

890
  // Figure out what cell particle is in now
891
  n_coord() = 1;
3,170,882✔
892

893
  if (!neighbor_list_find_cell(*this)) {
3,170,882!
894
    mark_as_lost("Couldn't find particle after hitting periodic "
×
895
                 "boundary on surface " +
×
896
                 std::to_string(surf.id_) + ".");
×
UNCOV
897
    return;
×
898
  }
899

900
  // Set previous coordinate going slightly past surface crossing
901
  r_last_current() = r() + TINY_BIT * u();
3,170,882✔
902

903
  // Diagnostic message
904
  if (settings::verbosity >= 10 || trace()) {
3,170,882!
UNCOV
905
    write_message(1, "    Hit periodic boundary on surface {}", surf.id_);
×
906
  }
907
}
908

909
void Particle::update_majorant()
192,723,913✔
910
{
911
  if (type().is_neutron()) {
192,723,913✔
912
    majorant() = NeutronMajorant::safety_factor_ *
20,604,834✔
913
                 data::n_majorant->calculate_neutron_xs(E());
20,604,834✔
914
  } else if (type().is_photon()) {
172,119,079✔
915
    majorant() = PhotonMajorant::safety_factor_ *
19,625,903✔
916
                 data::p_majorant->calculate_photon_xs(E());
19,625,903✔
917
  }
918
}
192,723,913✔
919

920
bool Particle::kill_invalid_maj()
97,273,869✔
921
{
922
  if (alive() && (macro_xs().total > majorant())) {
97,273,869!
NEW
923
    mark_as_lost(
×
NEW
924
      fmt::format("Ratio of the total cross section ({}) to the majorant "
×
925
                  "cross section ({}) for particle {} ({}) with energy {} is "
926
                  "greater than unity!",
NEW
927
        macro_xs().total, majorant(), id(), type().str(), E()));
×
NEW
928
    return true;
×
929
  }
930
  return false;
931
}
932

933
void Particle::mark_as_lost(const char* message)
5,865✔
934
{
935
  // Print warning and write lost particle file
936
  warning(message);
5,865✔
937
  if (settings::max_write_lost_particles < 0 ||
5,865✔
938
      simulation::n_lost_particles < settings::max_write_lost_particles) {
5,500✔
939
    write_restart();
440✔
940
  }
941
  // Increment number of lost particles
942
  wgt() = 0.0;
5,865✔
943
#pragma omp atomic
3,190✔
944
  simulation::n_lost_particles += 1;
2,675✔
945

946
  // Count the total number of simulated particles (on this processor)
947
  auto n = simulation::current_batch * settings::gen_per_batch *
5,865✔
948
           simulation::work_per_rank;
949

950
  // Abort the simulation if the maximum number of lost particles has been
951
  // reached
952
  if (simulation::n_lost_particles >= settings::max_lost_particles &&
5,865✔
953
      simulation::n_lost_particles >= settings::rel_max_lost_particles * n) {
9!
954
    fatal_error("Maximum number of lost particles has been reached.");
9✔
955
  }
956
}
5,856✔
957

958
void Particle::write_restart() const
440✔
959
{
960
  // Dont write another restart file if in particle restart mode
961
  if (settings::run_mode == RunMode::PARTICLE)
440✔
962
    return;
33✔
963

964
  // Set up file name
965
  auto filename = fmt::format("{}particle_{}_{}.h5", settings::path_output,
407✔
966
    simulation::current_batch, id());
407✔
967

968
#pragma omp critical(WriteParticleRestart)
217✔
969
  {
407✔
970
    // Create file
971
    hid_t file_id = file_open(filename, 'w');
407✔
972

973
    // Write filetype and version info
974
    write_attribute(file_id, "filetype", "particle restart");
407✔
975
    write_attribute(file_id, "version", VERSION_PARTICLE_RESTART);
407✔
976
    write_attribute(file_id, "openmc_version", VERSION);
407✔
977
#ifdef GIT_SHA1
978
    write_attr_string(file_id, "git_sha1", GIT_SHA1);
979
#endif
980

981
    // Write data to file
982
    write_dataset(file_id, "current_batch", simulation::current_batch);
407✔
983
    write_dataset(file_id, "generations_per_batch", settings::gen_per_batch);
407✔
984
    write_dataset(file_id, "current_generation", simulation::current_gen);
407✔
985
    write_dataset(file_id, "n_particles", settings::n_particles);
407✔
986
    switch (settings::run_mode) {
407!
987
    case RunMode::FIXED_SOURCE:
275✔
988
      write_dataset(file_id, "run_mode", "fixed source");
275✔
989
      break;
145✔
990
    case RunMode::EIGENVALUE:
132✔
991
      write_dataset(file_id, "run_mode", "eigenvalue");
132✔
992
      break;
72✔
993
    case RunMode::PARTICLE:
×
UNCOV
994
      write_dataset(file_id, "run_mode", "particle restart");
×
995
      break;
996
    default:
997
      break;
998
    }
999
    write_dataset(file_id, "id", id());
407✔
1000
    write_dataset(file_id, "type", type().pdg_number());
407✔
1001

1002
    // Get source site data for the particle that got lost
1003
    int64_t i = current_work();
407✔
1004
    SourceSite site;
407✔
1005
    if (settings::run_mode == RunMode::EIGENVALUE) {
407✔
1006
      site = simulation::source_bank[i];
132✔
1007
    } else if (settings::run_mode == RunMode::FIXED_SOURCE &&
275✔
1008
               settings::use_shared_secondary_bank &&
275!
1009
               i < simulation::shared_secondary_bank_read.size()) {
55!
UNCOV
1010
      site = simulation::shared_secondary_bank_read[i];
×
1011
    } else if (settings::run_mode == RunMode::FIXED_SOURCE) {
275!
1012
      // Re-sample using the same seed used to generate the source particle.
1013
      // current_work() is 0-indexed, compute_particle_id expects 1-indexed.
1014
      int64_t id = compute_transport_seed(compute_particle_id(i + 1));
275✔
1015
      uint64_t seed = init_seed(id, STREAM_SOURCE);
275✔
1016
      site = sample_external_source(&seed);
275✔
1017
    }
1018
    write_dataset(file_id, "weight", site.wgt);
407✔
1019
    write_dataset(file_id, "energy", site.E);
407✔
1020
    write_dataset(file_id, "xyz", site.r);
407✔
1021
    write_dataset(file_id, "uvw", site.u);
407✔
1022
    write_dataset(file_id, "time", site.time);
407✔
1023

1024
    // Close file
1025
    file_close(file_id);
407✔
1026
  } // #pragma omp critical
1027
}
407✔
1028

1029
void Particle::update_neutron_xs(
2,147,483,647✔
1030
  int i_nuclide, int i_grid, int i_sab, double sab_frac, double ncrystal_xs)
1031
{
1032
  // Get microscopic cross section cache
1033
  auto& micro = this->neutron_xs(i_nuclide);
2,147,483,647✔
1034

1035
  // If the cache doesn't match, recalculate micro xs
1036
  if (this->E() != micro.last_E || this->sqrtkT() != micro.last_sqrtkT ||
2,147,483,647✔
1037
      i_sab != micro.index_sab || sab_frac != micro.sab_frac ||
2,147,483,647✔
1038
      ncrystal_xs != micro.ncrystal_xs) {
2,147,483,647!
1039
    data::nuclides[i_nuclide]->calculate_xs(i_sab, i_grid, sab_frac, *this);
2,147,483,647✔
1040

1041
    // If NCrystal is being used, update micro cross section cache
1042
    micro.ncrystal_xs = ncrystal_xs;
2,147,483,647✔
1043
    if (ncrystal_xs >= 0.0) {
2,147,483,647✔
1044
      data::nuclides[i_nuclide]->calculate_elastic_xs(*this);
11,018,953✔
1045
      ncrystal_update_micro(ncrystal_xs, micro);
11,018,953✔
1046
    }
1047
  }
1048
}
2,147,483,647✔
1049

1050
//==============================================================================
1051
// Non-method functions
1052
//==============================================================================
1053
void add_surf_source_to_bank(Particle& p, const Surface& surf)
2,147,483,647✔
1054
{
1055
  if (simulation::current_batch <= settings::n_inactive ||
2,147,483,647✔
1056
      simulation::surf_source_bank.full()) {
2,147,483,647✔
1057
    return;
2,147,483,647✔
1058
  }
1059

1060
  // If a cell/cellfrom/cellto parameter is defined
1061
  if (settings::ssw_cell_id != C_NONE) {
337,079✔
1062

1063
    // Retrieve cell index and storage type
1064
    int cell_idx = model::cell_map[settings::ssw_cell_id];
254,434✔
1065

1066
    if (surf.bc_) {
254,434✔
1067
      // Leave if cellto with vacuum boundary condition
1068
      if (surf.bc_->type() == "vacuum" &&
298,916✔
1069
          settings::ssw_cell_type == SSWCellType::To) {
33,098✔
1070
        return;
1071
      }
1072

1073
      // Leave if other boundary condition than vacuum
1074
      if (surf.bc_->type() != "vacuum") {
274,646✔
1075
        return;
1076
      }
1077
    }
1078

1079
    // Check if the cell of interest has been exited
1080
    bool exited = false;
1081
    for (int i = 0; i < p.n_coord_last(); ++i) {
333,667✔
1082
      if (p.cell_last(i) == cell_idx) {
207,728✔
1083
        exited = true;
73,763✔
1084
      }
1085
    }
1086

1087
    // Check if the cell of interest has been entered
1088
    bool entered = false;
1089
    for (int i = 0; i < p.n_coord(); ++i) {
297,969✔
1090
      if (p.coord(i).cell() == cell_idx) {
172,030✔
1091
        entered = true;
57,517✔
1092
      }
1093
    }
1094

1095
    // Vacuum boundary conditions: return if cell is not exited
1096
    if (surf.bc_) {
125,939✔
1097
      if (surf.bc_->type() == "vacuum" && !exited) {
41,926!
1098
        return;
1099
      }
1100
    } else {
1101

1102
      // If we both enter and exit the cell of interest
1103
      if (entered && exited) {
104,976✔
1104
        return;
1105
      }
1106

1107
      // If we did not enter nor exit the cell of interest
1108
      if (!entered && !exited) {
77,773✔
1109
        return;
1110
      }
1111

1112
      // If cellfrom and the cell before crossing is not the cell of
1113
      // interest
1114
      if (settings::ssw_cell_type == SSWCellType::From && !exited) {
64,274✔
1115
        return;
1116
      }
1117

1118
      // If cellto and the cell after crossing is not the cell of interest
1119
      if (settings::ssw_cell_type == SSWCellType::To && !entered) {
52,731✔
1120
        return;
1121
      }
1122
    }
1123
  }
1124

1125
  SourceSite site;
129,653✔
1126
  site.r = p.r();
129,653✔
1127
  site.u = p.u();
129,653✔
1128
  site.E = p.E();
129,653✔
1129
  site.time = p.time();
129,653✔
1130
  site.wgt = p.wgt();
129,653✔
1131
  site.delayed_group = p.delayed_group();
129,653✔
1132
  site.surf_id = surf.id_;
129,653✔
1133
  site.particle = p.type();
129,653✔
1134
  site.parent_id = p.id();
129,653✔
1135
  site.progeny_id = p.n_progeny();
129,653✔
1136
  int64_t idx = simulation::surf_source_bank.thread_safe_append(site);
129,653✔
1137
}
1138

1139
} // namespace openmc
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc