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

openmc-dev / openmc / 27644425221

16 Jun 2026 08:00PM UTC coverage: 81.312% (+0.03%) from 81.281%
27644425221

Pull #3971

github

web-flow
Merge a0e499466 into 02eb999af
Pull Request #3971: Delta tracking

18506 of 26817 branches covered (69.01%)

Branch coverage included in aggregate %.

601 of 656 new or added lines in 20 files covered. (91.62%)

31 existing lines in 1 file now uncovered.

59814 of 69503 relevant lines covered (86.06%)

49436668.03 hits per line

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

85.13
/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:
88,233,080✔
75
  case PDG_POSITRON:
88,233,080✔
76
    return MASS_ELECTRON_EV;
88,233,080✔
77
  default:
40,568,757✔
78
    return this->type().mass() * AMU_EV;
40,568,757✔
79
  }
80
}
81

82
bool Particle::create_secondary(
503,998,249✔
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();
503,998,249✔
88
  if (idx == C_NONE) {
503,998,249!
89
    return false;
90
  }
91
  if (E < settings::energy_cutoff[idx]) {
503,998,249✔
92
    return false;
93
  }
94

95
  // Increment number of secondaries created (for ParticleProductionFilter)
96
  n_secondaries()++;
263,647,664✔
97

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

114
  local_secondary_bank().emplace_back(bank);
263,647,664✔
115
  return true;
116
}
117

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

128
  // Convert signed index to a signed surface ID
129
  if (surface() == SURFACE_NONE) {
10,313,846✔
130
    bank.surf_id = SURFACE_NONE;
10,309,974✔
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,313,846✔
137
  bank.wgt_ww_born = wgt_ww_born();
10,313,846✔
138
  bank.n_split = n_split();
10,313,846✔
139
  bank.parent_id = current_work();
10,313,846✔
140
  if (settings::use_shared_secondary_bank) {
10,313,846✔
141
    bank.progeny_id = n_progeny()++;
5,146,710✔
142
  }
143

144
  local_secondary_bank().emplace_back(bank);
10,313,846✔
145
}
10,313,846✔
146

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

163
  // Copy attributes from source bank site
164
  type() = src->particle;
462,968,974✔
165
  wgt() = src->wgt;
462,968,974✔
166
  wgt_last() = src->wgt;
462,968,974✔
167
  r() = src->r;
462,968,974✔
168
  u() = src->u;
462,968,974✔
169
  r_born() = src->r;
462,968,974✔
170
  r_last_current() = src->r;
462,968,974✔
171
  r_last() = src->r;
462,968,974✔
172
  u_last() = src->u;
462,968,974✔
173
  if (settings::run_CE) {
462,968,974✔
174
    E() = src->E;
346,103,110✔
175
    g() = 0;
346,103,110✔
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();
462,968,974✔
182
  time() = src->time;
462,968,974✔
183
  time_last() = src->time;
462,968,974✔
184
  parent_nuclide() = src->parent_nuclide;
462,968,974✔
185
  delayed_group() = src->delayed_group;
462,968,974✔
186

187
  // Convert signed surface ID to signed index
188
  if (src->surf_id != SURFACE_NONE) {
462,968,974✔
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;
462,968,974✔
194
  wgt_ww_born() = src->wgt_ww_born;
462,968,974✔
195
  n_split() = src->n_split;
462,968,974✔
196

197
  if (delta_tracking()) {
462,968,974✔
198
    update_majorant();
168,458,969✔
199
  }
200
}
462,968,974✔
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)) {
284,651,302!
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)
284,651,302!
231
      cell_born() = lowest_coord().cell();
284,651,302✔
232

233
    // Initialize last cells from current cell
234
    for (int j = 0; j < n_coord(); ++j) {
586,685,323✔
235
      cell_last(j) = coord(j).cell();
302,034,021✔
236
    }
237
    n_coord_last() = n_coord();
284,651,302✔
238
  }
239

240
  // Write particle track.
241
  if (write_track())
2,147,483,647✔
242
    write_particle_track(*this);
10,306✔
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,686,267✔
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,465✔
268
    macro_xs().absorption = 0.0;
111,961,465✔
269
    macro_xs().fission = 0.0;
111,961,465✔
270
    macro_xs().nu_fission = 0.0;
111,961,465✔
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;
176,466,160!
283
  } else if (macro_xs().total == 0.0) {
2,147,483,647✔
284
    collision_distance() = INFINITY;
111,961,465✔
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,540,122✔
332
{
333
  if (E() != E_last()) {
264,540,122✔
334
    update_majorant();
23,503,689✔
335
  }
336

337
  // Sample distance to next position
338
  if (type() == ParticleType::electron() ||
264,540,122✔
339
      type() == ParticleType::positron()) {
111,897,830✔
340
    // Electrons/positrons don't move
341
    collision_distance() = 0.0;
152,779,429✔
342
  } else if (majorant() == 0.0) {
111,760,693!
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,760,693✔
349
  }
350

351
  // Update distance to problem boundary
352
  boundary() = distance_to_external_boundary(*this);
264,540,122✔
353

354
  // Move to the external boundary or delta tracking collision site. Particles
355
  // with large majorant cross sections will tunnel out of the domain if a
356
  // floating point tolerance is not specified on the boundary distance
357
  // calculation.
358
  double distance =
264,540,122✔
359
    std::min(collision_distance(), boundary().distance() - FP_REL_PRECISION);
264,540,122✔
360
  r() += distance * u();
264,540,122✔
361

362
  // Need to locate the particle at the collision site or boundary.
363
  for (int j = 0; j < n_coord(); ++j) {
624,361,397✔
364
    coord(j).reset();
359,821,275✔
365
  }
366
  if (!exhaustive_find_cell(*this)) {
264,540,122!
367
    // We've lost this particle.
NEW
368
    mark_as_lost(fmt::format(
×
NEW
369
      "Particle {} could not be located while running delta tracking!", id()));
×
NEW
370
    return;
×
371
  }
372

373
  // Force re-calculation of material properties at the collision site.
374
  material_last() = C_NONE;
264,540,122✔
375
}
376

377
void Particle::event_cross_surface()
2,147,483,647✔
378
{
379
  // Saving previous cell data
380
  for (int j = 0; j < n_coord(); ++j) {
2,147,483,647✔
381
    cell_last(j) = coord(j).cell();
2,147,483,647✔
382
  }
383
  n_coord_last() = n_coord();
2,147,483,647✔
384

385
  // Set surface that particle is on and adjust coordinate levels
386
  surface() = boundary().surface();
2,147,483,647✔
387
  n_coord() = boundary().coord_level();
2,147,483,647✔
388

389
  if (boundary().lattice_translation()[0] != 0 ||
2,147,483,647✔
390
      boundary().lattice_translation()[1] != 0 ||
2,147,483,647✔
391
      boundary().lattice_translation()[2] != 0) {
2,147,483,647✔
392
    // Particle crosses lattice boundary
393

394
    bool verbose = settings::verbosity >= 10 || trace();
801,265,687!
395
    cross_lattice(*this, boundary(), verbose);
801,265,687✔
396
    event() = TallyEvent::LATTICE;
801,265,687✔
397

398
    // Score cell to cell partial currents
399
    if (!model::active_surface_tallies.empty()) {
801,265,687!
UNCOV
400
      auto& lat {*model::lattices[lowest_coord().lattice()]};
×
UNCOV
401
      bool is_valid;
×
UNCOV
402
      Direction normal =
×
UNCOV
403
        lat.get_normal(boundary().lattice_translation(), is_valid);
×
UNCOV
404
      if (is_valid) {
×
UNCOV
405
        normal /= normal.norm();
×
UNCOV
406
        score_surface_tally(*this, model::active_surface_tallies, normal);
×
407
      }
408
    }
409

410
  } else {
411

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

414
    // Particle crosses surface
415
    // If BC, add particle to surface source before crossing surface
416
    if (surf.surf_source_ && surf.bc_) {
2,147,483,647✔
417
      add_surf_source_to_bank(*this, surf);
1,023,009,783✔
418
    }
419
    this->cross_surface(surf);
2,147,483,647✔
420
    // If no BC, add particle to surface source after crossing surface
421
    if (surf.surf_source_ && !surf.bc_) {
2,147,483,647✔
422
      add_surf_source_to_bank(*this, surf);
1,851,728,532✔
423
    }
424
    if (settings::weight_window_checkpoint_surface) {
2,147,483,647✔
425
      apply_weight_windows(*this);
173,985✔
426
    }
427
    event() = TallyEvent::SURFACE;
2,147,483,647✔
428

429
    // Score cell to cell partial currents
430
    if (!model::active_surface_tallies.empty()) {
2,147,483,647✔
431
      Direction normal = surf.normal(r());
34,931,567✔
432
      normal /= normal.norm();
34,931,567✔
433
      score_surface_tally(*this, model::active_surface_tallies, normal);
34,931,567✔
434
    }
435
  }
436
}
2,147,483,647✔
437

438
void Particle::event_collide()
2,147,483,647✔
439
{
440
  // Score collision estimate of keff
441
  if (settings::run_mode == RunMode::EIGENVALUE && type().is_neutron()) {
2,147,483,647✔
442
    keff_tally_collision() += wgt() * macro_xs().nu_fission / macro_xs().total;
2,147,483,647✔
443
  }
444

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

449
  if (!model::active_meshsurf_tallies.empty())
2,147,483,647✔
450
    score_meshsurface_tally(*this, model::active_meshsurf_tallies);
63,098,926✔
451

452
  // Clear surface component
453
  surface() = SURFACE_NONE;
2,147,483,647✔
454

455
  if (settings::run_CE) {
2,147,483,647✔
456
    collision(*this);
1,647,208,962✔
457
  } else {
458
    collision_mg(*this);
1,801,144,774✔
459
  }
460

461
  // Collision track feature to recording particle interaction
462
  if (settings::collision_track) {
2,147,483,647✔
463
    collision_track_record(*this);
728,673✔
464
  }
465

466
  // Score collision estimator tallies -- this is done after a collision
467
  // has occurred rather than before because we need information on the
468
  // outgoing energy for any tallies with an outgoing energy filter
469
  if (!model::active_collision_tallies.empty())
2,147,483,647✔
470
    score_collision_tally(*this);
202,494,657✔
471
  if (!model::active_analog_tallies.empty()) {
2,147,483,647✔
472
    if (settings::run_CE) {
406,229,898✔
473
      score_analog_tally_ce(*this);
405,021,636✔
474
    } else {
475
      score_analog_tally_mg(*this);
1,208,262✔
476
    }
477
  }
478

479
  if (!model::active_pulse_height_tallies.empty() && type().is_photon()) {
2,147,483,647✔
480
    pht_collision_energy();
8,668✔
481
  }
482

483
  // Reset banked weight during collision
484
  n_bank() = 0;
2,147,483,647✔
485
  bank_second_E() = 0.0;
2,147,483,647✔
486
  wgt_bank() = 0.0;
2,147,483,647✔
487

488
  // Clear number of secondaries in this collision. This is
489
  // distinct from the number of created neutrons n_bank() above!
490
  n_secondaries() = 0;
2,147,483,647✔
491

492
  zero_delayed_bank();
2,147,483,647✔
493

494
  // Reset fission logical
495
  fission() = false;
2,147,483,647✔
496

497
  // Save coordinates for tallying purposes
498
  r_last_current() = r();
2,147,483,647✔
499

500
  // Set last material to none since cross sections will need to be
501
  // re-evaluated
502
  material_last() = C_NONE;
2,147,483,647✔
503

504
  // Set all directions to base level -- right now, after a collision, only
505
  // the base level directions are changed
506
  for (int j = 0; j < n_coord() - 1; ++j) {
2,147,483,647✔
507
    if (coord(j + 1).rotated()) {
473,826,967✔
508
      // If next level is rotated, apply rotation matrix
509
      const auto& m {model::cells[coord(j).cell()]->rotation_};
11,724,229✔
510
      const auto& u {coord(j).u()};
11,724,229✔
511
      coord(j + 1).u() = u.rotate(m);
11,724,229✔
512
    } else {
513
      // Otherwise, copy this level's direction
514
      coord(j + 1).u() = coord(j).u();
462,102,738✔
515
    }
516
  }
517

518
  // Score flux derivative accumulators for differential tallies.
519
  if (!model::active_tallies.empty())
2,147,483,647✔
520
    score_collision_derivative(*this);
1,392,825,602✔
521

522
#ifdef OPENMC_DAGMC_ENABLED
523
  history().reset();
314,280,169✔
524
#endif
525
}
2,147,483,647✔
526

527
void Particle::event_revive_from_secondary(const SourceSite& site)
274,975,707✔
528
{
529
  // Write final position for the previous track (skip if this is a freshly
530
  // constructed particle with no prior track, e.g., Phase 2 of shared
531
  // secondary transport)
532
  if (write_track() && n_event() > 0) {
274,975,707!
533
    write_particle_track(*this);
5,232✔
534
  }
535

536
  from_source(&site);
274,975,707✔
537

538
  n_event() = 0;
274,975,707✔
539
  if (!settings::use_shared_secondary_bank) {
274,975,707✔
540
    n_tracks()++;
253,647,725✔
541
  }
542
  bank_second_E() = 0.0;
274,975,707✔
543

544
  // Subtract secondary particle energy from interim pulse-height results.
545
  // In shared secondary mode, this subtraction was already done on the parent
546
  // particle during create_secondary(), so skip it here.
547
  if (!settings::use_shared_secondary_bank &&
528,623,432✔
548
      !model::active_pulse_height_tallies.empty() && this->type().is_photon()) {
274,975,707✔
549
    // Since the birth cell of the particle has not been set we
550
    // have to determine it before the energy of the secondary particle can be
551
    // removed from the pulse-height of this cell.
552
    if (lowest_coord().cell() == C_NONE) {
3,168!
553
      bool verbose = settings::verbosity >= 10 || trace();
3,168!
554
      if (!exhaustive_find_cell(*this, verbose)) {
3,168!
UNCOV
555
        mark_as_lost("Could not find the cell containing particle " +
×
UNCOV
556
                     std::to_string(id()));
×
UNCOV
557
        return;
×
558
      }
559
      // Set birth cell attribute
560
      if (cell_born() == C_NONE)
3,168!
561
        cell_born() = lowest_coord().cell();
3,168✔
562

563
      // Initialize last cells from current cell
564
      for (int j = 0; j < n_coord(); ++j) {
6,336✔
565
        cell_last(j) = coord(j).cell();
3,168✔
566
      }
567
      n_coord_last() = n_coord();
3,168✔
568
    }
569
    pht_secondary_particles();
3,168✔
570
  }
571

572
  // Enter new particle in particle track file
573
  if (write_track())
274,975,707✔
574
    add_particle_track(*this);
5,232✔
575
}
576

577
void Particle::event_check_limit_and_revive()
2,147,483,647✔
578
{
579
  // If particle has too many events, display warning and kill it
580
  n_event()++;
2,147,483,647✔
581
  if (n_event() == settings::max_particle_events) {
2,147,483,647!
UNCOV
582
    warning("Particle " + std::to_string(id()) +
×
583
            " underwent maximum number of events.");
UNCOV
584
    wgt() = 0.0;
×
585
  }
586

587
  // In non-shared-secondary mode, revive from local secondary bank
588
  if (!alive() && !settings::use_shared_secondary_bank &&
2,147,483,647✔
589
      !local_secondary_bank().empty()) {
431,799,952✔
590
    SourceSite& site = local_secondary_bank().back();
253,647,725✔
591
    event_revive_from_secondary(site);
253,647,725✔
592
    local_secondary_bank().pop_back();
253,647,725✔
593
  }
594
}
2,147,483,647✔
595

596
void Particle::event_death()
200,265,705✔
597
{
598
#ifdef OPENMC_DAGMC_ENABLED
599
  history().reset();
18,259,068✔
600
#endif
601

602
  // Finish particle track output.
603
  if (write_track()) {
200,265,705✔
604
    write_particle_track(*this);
1,010✔
605
    finalize_particle_track(*this);
1,010✔
606
  }
607

608
// Contribute tally reduction variables to global accumulator
609
#pragma omp atomic
109,780,208✔
610
  global_tally_absorption += keff_tally_absorption();
200,265,705✔
611
#pragma omp atomic
109,356,689✔
612
  global_tally_collision += keff_tally_collision();
200,265,705✔
613
  if (!delta_tracking()) {
200,265,705✔
614
#pragma omp atomic
108,968,523✔
615
    global_tally_tracklength += keff_tally_tracklength();
199,165,705✔
616
  }
617
#pragma omp atomic
109,410,358✔
618
  global_tally_leakage += keff_tally_leakage();
200,265,705✔
619

620
  // Reset particle tallies once accumulated
621
  keff_tally_absorption() = 0.0;
200,265,705✔
622
  keff_tally_collision() = 0.0;
200,265,705✔
623
  keff_tally_tracklength() = 0.0;
200,265,705✔
624
  keff_tally_leakage() = 0.0;
200,265,705✔
625

626
  if (!model::active_pulse_height_tallies.empty()) {
200,265,705✔
627
    score_pulse_height_tally(*this, model::active_pulse_height_tallies);
33,000✔
628
  }
629

630
  // Accumulate track count for this particle history
631
  if (!settings::use_shared_secondary_bank) {
200,265,705✔
632
#pragma omp atomic
97,255,062✔
633
    simulation::simulation_tracks_completed += n_tracks();
178,153,227✔
634
  }
635

636
  // Record the number of progeny created by this particle.
637
  // This data will be used to efficiently sort the fission bank.
638
  if (settings::run_mode == RunMode::EIGENVALUE ||
200,265,705✔
639
      settings::use_shared_secondary_bank) {
640
    simulation::progeny_per_particle[current_work()] = n_progeny();
173,116,478✔
641
  }
642
}
200,265,705✔
643

644
void Particle::pht_collision_energy()
8,668✔
645
{
646
  // Adds the energy particles lose in a collision to the pulse-height
647

648
  // determine index of cell in pulse_height_cells
649
  auto it = std::find(model::pulse_height_cells.begin(),
8,668✔
650
    model::pulse_height_cells.end(), lowest_coord().cell());
8,668!
651

652
  if (it != model::pulse_height_cells.end()) {
8,668!
653
    int index = std::distance(model::pulse_height_cells.begin(), it);
8,668✔
654
    pht_storage()[index] += E_last() - E();
8,668✔
655

656
    // If the energy of the particle is below the cutoff, it will not be sampled
657
    // so its energy is added to the pulse-height in the cell
658
    int photon = ParticleType::photon().transport_index();
8,668✔
659
    if (E() < settings::energy_cutoff[photon]) {
8,668✔
660
      pht_storage()[index] += E();
3,740✔
661
    }
662
  }
663
}
8,668✔
664

665
void Particle::pht_secondary_particles()
3,168✔
666
{
667
  // Removes the energy of secondary produced particles from the pulse-height
668

669
  // determine index of cell in pulse_height_cells
670
  auto it = std::find(model::pulse_height_cells.begin(),
3,168✔
671
    model::pulse_height_cells.end(), cell_born());
3,168!
672

673
  if (it != model::pulse_height_cells.end()) {
3,168!
674
    int index = std::distance(model::pulse_height_cells.begin(), it);
3,168✔
675
    pht_storage()[index] -= E();
3,168✔
676
  }
677
}
3,168✔
678

679
void Particle::cross_surface(const Surface& surf)
2,147,483,647✔
680
{
681

682
  if (settings::verbosity >= 10 || trace()) {
2,147,483,647✔
683
    write_message(1, "    Crossing surface {}", surf.id_);
88✔
684
  }
685

686
// if we're crossing a CSG surface, make sure the DAG history is reset
687
#ifdef OPENMC_DAGMC_ENABLED
688
  if (surf.geom_type() == GeometryType::CSG)
262,270,887✔
689
    history().reset();
262,213,205✔
690
#endif
691

692
  // Handle any applicable boundary conditions.
693
  if (surf.bc_ && settings::run_mode != RunMode::PLOTTING &&
2,147,483,647!
694
      settings::run_mode != RunMode::VOLUME) {
695
    surf.bc_->handle_particle(*this, surf);
1,023,361,891✔
696
    return;
1,023,361,891✔
697
  }
698

699
  // ==========================================================================
700
  // SEARCH NEIGHBOR LISTS FOR NEXT CELL
701

702
#ifdef OPENMC_DAGMC_ENABLED
703
  // in DAGMC, we know what the next cell should be
704
  if (surf.geom_type() == GeometryType::DAG) {
168,810,544✔
705
    int32_t i_cell = next_cell(surface_index(), cell_last(n_coord() - 1),
46,742✔
706
                       lowest_coord().universe()) -
46,742✔
707
                     1;
46,742✔
708
    // save material, temperature, and density multiplier
709
    material_last() = material();
46,742✔
710
    sqrtkT_last() = sqrtkT();
46,742✔
711
    density_mult_last() = density_mult();
46,742✔
712
    // set new cell value
713
    lowest_coord().cell() = i_cell;
46,742✔
714
    auto& cell = model::cells[i_cell];
46,742✔
715

716
    cell_instance() = 0;
46,742✔
717
    if (cell->distribcell_index_ >= 0)
46,742✔
718
      cell_instance() = cell_instance_at_level(*this, n_coord() - 1);
45,718✔
719

720
    material() = cell->material(cell_instance());
46,742!
721
    sqrtkT() = cell->sqrtkT(cell_instance());
46,742!
722
    density_mult() = cell->density_mult(cell_instance());
46,742✔
723
    return;
46,742✔
724
  }
725
#endif
726

727
  bool verbose = settings::verbosity >= 10 || trace();
1,854,471,398!
728
  if (neighbor_list_find_cell(*this, verbose)) {
1,854,471,398✔
729
    return;
730
  }
731

732
  // ==========================================================================
733
  // COULDN'T FIND PARTICLE IN NEIGHBORING CELLS, SEARCH ALL CELLS
734

735
  // Remove lower coordinate levels
736
  n_coord() = 1;
29,977✔
737
  bool found = exhaustive_find_cell(*this, verbose);
29,977✔
738

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

745
    surface() = SURFACE_NONE;
5,865✔
746
    n_coord() = 1;
5,865✔
747
    r() += TINY_BIT * u();
5,865✔
748

749
    // Couldn't find next cell anywhere! This probably means there is an actual
750
    // undefined region in the geometry.
751

752
    if (!exhaustive_find_cell(*this, verbose)) {
5,865!
753
      mark_as_lost("After particle " + std::to_string(id()) +
17,586✔
754
                   " crossed surface " + std::to_string(surf.id_) +
17,586✔
755
                   " it could not be located in any cell and it did not leak.");
756
      return;
5,856✔
757
    }
758
  }
759
}
760

761
void Particle::cross_vacuum_bc(const Surface& surf)
37,353,730✔
762
{
763
  // Score any surface current tallies -- note that the particle is moved
764
  // forward slightly so that if the mesh boundary is on the surface, it is
765
  // still processed
766

767
  if (!model::active_meshsurf_tallies.empty()) {
37,353,730✔
768
    // TODO: Find a better solution to score surface currents than
769
    // physically moving the particle forward slightly
770

771
    r() += TINY_BIT * u();
937,222✔
772
    score_meshsurface_tally(*this, model::active_meshsurf_tallies);
937,222✔
773
  }
774

775
  // Score to global leakage tally
776
  keff_tally_leakage() += wgt();
37,353,730✔
777

778
  // Kill the particle
779
  wgt() = 0.0;
37,353,730✔
780

781
  // Display message
782
  if (settings::verbosity >= 10 || trace()) {
37,353,730!
783
    write_message(1, "    Leaked out of surface {}", surf.id_);
22✔
784
  }
785
}
37,353,730✔
786

787
void Particle::cross_reflective_bc(const Surface& surf, Direction new_u)
983,857,421✔
788
{
789
  // Do not handle reflective boundary conditions on lower universes
790
  if (n_coord() != 1) {
983,857,421!
UNCOV
791
    mark_as_lost("Cannot reflect particle " + std::to_string(id()) +
×
792
                 " off surface in a lower universe.");
UNCOV
793
    return;
×
794
  }
795

796
  // Score surface currents since reflection causes the direction of the
797
  // particle to change. For surface filters, we need to score the tallies
798
  // twice, once before the particle's surface attribute has changed and
799
  // once after. For mesh surface filters, we need to artificially move
800
  // the particle slightly back in case the surface crossing is coincident
801
  // with a mesh boundary
802

803
  if (!model::active_surface_tallies.empty()) {
983,857,421✔
804
    Direction normal = surf.normal(r());
285,021✔
805
    normal /= normal.norm();
285,021✔
806
    score_surface_tally(*this, model::active_surface_tallies, normal);
285,021✔
807
  }
808

809
  if (!model::active_meshsurf_tallies.empty()) {
983,857,421✔
810
    Position r {this->r()};
46,885,487✔
811
    this->r() -= TINY_BIT * u();
46,885,487✔
812
    score_meshsurface_tally(*this, model::active_meshsurf_tallies);
46,885,487✔
813
    this->r() = r;
46,885,487✔
814
  }
815

816
  // Set the new particle direction
817
  u() = new_u;
983,857,421✔
818

819
  // Reassign particle's cell and surface
820
  coord(0).cell() = cell_last(0);
983,857,421✔
821
  surface() = -surface();
983,857,421✔
822

823
  // If a reflective surface is coincident with a lattice or universe
824
  // boundary, it is necessary to redetermine the particle's coordinates in
825
  // the lower universes.
826
  // (unless we're using a dagmc model, which has exactly one universe)
827
  n_coord() = 1;
983,857,421✔
828
  if (surf.geom_type() != GeometryType::DAG &&
1,967,712,084!
829
      !neighbor_list_find_cell(*this)) {
983,854,663✔
UNCOV
830
    mark_as_lost("Couldn't find particle after reflecting from surface " +
×
UNCOV
831
                 std::to_string(surf.id_) + ".");
×
UNCOV
832
    return;
×
833
  }
834

835
  // Set previous coordinate going slightly past surface crossing
836
  r_last_current() = r() + TINY_BIT * u();
983,857,421✔
837

838
  // Diagnostic message
839
  if (settings::verbosity >= 10 || trace()) {
983,857,421!
UNCOV
840
    write_message(1, "    Reflected from surface {}", surf.id_);
×
841
  }
842
}
843

844
void Particle::cross_periodic_bc(
3,156,206✔
845
  const Surface& surf, Position new_r, Direction new_u, int new_surface)
846
{
847
  // Do not handle periodic boundary conditions on lower universes
848
  if (n_coord() != 1) {
3,156,206!
UNCOV
849
    mark_as_lost(
×
UNCOV
850
      "Cannot transfer particle " + std::to_string(id()) +
×
851
      " across surface in a lower universe. Boundary conditions must be "
852
      "applied to root universe.");
UNCOV
853
    return;
×
854
  }
855

856
  // Score surface currents since reflection causes the direction of the
857
  // particle to change -- artificially move the particle slightly back in
858
  // case the surface crossing is coincident with a mesh boundary
859
  if (!model::active_meshsurf_tallies.empty()) {
3,156,206!
UNCOV
860
    Position r {this->r()};
×
UNCOV
861
    this->r() -= TINY_BIT * u();
×
UNCOV
862
    score_meshsurface_tally(*this, model::active_meshsurf_tallies);
×
UNCOV
863
    this->r() = r;
×
864
  }
865

866
  // Adjust the particle's location and direction.
867
  r() = new_r;
3,156,206✔
868
  u() = new_u;
3,156,206✔
869

870
  // Reassign particle's surface
871
  surface() = new_surface;
3,156,206✔
872

873
  // Figure out what cell particle is in now
874
  n_coord() = 1;
3,156,206✔
875

876
  if (!neighbor_list_find_cell(*this)) {
3,156,206!
877
    mark_as_lost("Couldn't find particle after hitting periodic "
×
878
                 "boundary on surface " +
×
879
                 std::to_string(surf.id_) + ".");
×
UNCOV
880
    return;
×
881
  }
882

883
  // Set previous coordinate going slightly past surface crossing
884
  r_last_current() = r() + TINY_BIT * u();
3,156,206✔
885

886
  // Diagnostic message
887
  if (settings::verbosity >= 10 || trace()) {
3,156,206!
UNCOV
888
    write_message(1, "    Hit periodic boundary on surface {}", surf.id_);
×
889
  }
890
}
891

892
void Particle::update_majorant()
193,062,658✔
893
{
894
  if (type().is_neutron()) {
193,062,658✔
895
    majorant() = NeutronMajorant::safety_factor_ *
20,620,806✔
896
                 data::n_majorant->calculate_neutron_xs(E());
20,620,806✔
897
  } else if (type().is_photon()) {
172,441,852✔
898
    majorant() = PhotonMajorant::safety_factor_ *
19,662,423✔
899
                 data::p_majorant->calculate_photon_xs(E());
19,662,423✔
900
  }
901
}
193,062,658✔
902

903
bool Particle::kill_invalid_maj()
97,232,234✔
904
{
905
  if (alive() && (macro_xs().total / majorant() > 1.0)) {
97,232,234!
NEW
UNCOV
906
    mark_as_lost(
×
NEW
UNCOV
907
      fmt::format("Ratio of the total cross section ({}) to the majorant "
×
908
                  "cross section ({}) for particle {} ({}) with energy {} is "
909
                  "greater than unity!",
NEW
910
        macro_xs().total, majorant(), id(), type().str(), E()));
×
NEW
911
    return true;
×
912
  }
913
  return false;
914
}
915

916
void Particle::mark_as_lost(const char* message)
5,865✔
917
{
918
  // Print warning and write lost particle file
919
  warning(message);
5,865✔
920
  if (settings::max_write_lost_particles < 0 ||
5,865✔
921
      simulation::n_lost_particles < settings::max_write_lost_particles) {
5,500✔
922
    write_restart();
440✔
923
  }
924
  // Increment number of lost particles
925
  wgt() = 0.0;
5,865✔
926
#pragma omp atomic
3,190✔
927
  simulation::n_lost_particles += 1;
2,675✔
928

929
  // Count the total number of simulated particles (on this processor)
930
  auto n = simulation::current_batch * settings::gen_per_batch *
5,865✔
931
           simulation::work_per_rank;
932

933
  // Abort the simulation if the maximum number of lost particles has been
934
  // reached
935
  if (simulation::n_lost_particles >= settings::max_lost_particles &&
5,865✔
936
      simulation::n_lost_particles >= settings::rel_max_lost_particles * n) {
9!
937
    fatal_error("Maximum number of lost particles has been reached.");
9✔
938
  }
939
}
5,856✔
940

941
void Particle::write_restart() const
440✔
942
{
943
  // Dont write another restart file if in particle restart mode
944
  if (settings::run_mode == RunMode::PARTICLE)
440✔
945
    return;
33✔
946

947
  // Set up file name
948
  auto filename = fmt::format("{}particle_{}_{}.h5", settings::path_output,
407✔
949
    simulation::current_batch, id());
407✔
950

951
#pragma omp critical(WriteParticleRestart)
217✔
952
  {
407✔
953
    // Create file
954
    hid_t file_id = file_open(filename, 'w');
407✔
955

956
    // Write filetype and version info
957
    write_attribute(file_id, "filetype", "particle restart");
407✔
958
    write_attribute(file_id, "version", VERSION_PARTICLE_RESTART);
407✔
959
    write_attribute(file_id, "openmc_version", VERSION);
407✔
960
#ifdef GIT_SHA1
961
    write_attr_string(file_id, "git_sha1", GIT_SHA1);
962
#endif
963

964
    // Write data to file
965
    write_dataset(file_id, "current_batch", simulation::current_batch);
407✔
966
    write_dataset(file_id, "generations_per_batch", settings::gen_per_batch);
407✔
967
    write_dataset(file_id, "current_generation", simulation::current_gen);
407✔
968
    write_dataset(file_id, "n_particles", settings::n_particles);
407✔
969
    switch (settings::run_mode) {
407!
970
    case RunMode::FIXED_SOURCE:
275✔
971
      write_dataset(file_id, "run_mode", "fixed source");
275✔
972
      break;
145✔
973
    case RunMode::EIGENVALUE:
132✔
974
      write_dataset(file_id, "run_mode", "eigenvalue");
132✔
975
      break;
72✔
UNCOV
976
    case RunMode::PARTICLE:
×
UNCOV
977
      write_dataset(file_id, "run_mode", "particle restart");
×
978
      break;
979
    default:
980
      break;
981
    }
982
    write_dataset(file_id, "id", id());
407✔
983
    write_dataset(file_id, "type", type().pdg_number());
407✔
984

985
    // Get source site data for the particle that got lost
986
    int64_t i = current_work();
407✔
987
    SourceSite site;
407✔
988
    if (settings::run_mode == RunMode::EIGENVALUE) {
407✔
989
      site = simulation::source_bank[i];
132✔
990
    } else if (settings::run_mode == RunMode::FIXED_SOURCE &&
275✔
991
               settings::use_shared_secondary_bank &&
275!
992
               i < simulation::shared_secondary_bank_read.size()) {
55!
993
      site = simulation::shared_secondary_bank_read[i];
×
994
    } else if (settings::run_mode == RunMode::FIXED_SOURCE) {
275!
995
      // Re-sample using the same seed used to generate the source particle.
996
      // current_work() is 0-indexed, compute_particle_id expects 1-indexed.
997
      int64_t id = compute_transport_seed(compute_particle_id(i + 1));
275✔
998
      uint64_t seed = init_seed(id, STREAM_SOURCE);
275✔
999
      site = sample_external_source(&seed);
275✔
1000
    }
1001
    write_dataset(file_id, "weight", site.wgt);
407✔
1002
    write_dataset(file_id, "energy", site.E);
407✔
1003
    write_dataset(file_id, "xyz", site.r);
407✔
1004
    write_dataset(file_id, "uvw", site.u);
407✔
1005
    write_dataset(file_id, "time", site.time);
407✔
1006

1007
    // Close file
1008
    file_close(file_id);
407✔
1009
  } // #pragma omp critical
1010
}
407✔
1011

1012
void Particle::update_neutron_xs(
2,147,483,647✔
1013
  int i_nuclide, int i_grid, int i_sab, double sab_frac, double ncrystal_xs)
1014
{
1015
  // Get microscopic cross section cache
1016
  auto& micro = this->neutron_xs(i_nuclide);
2,147,483,647✔
1017

1018
  // If the cache doesn't match, recalculate micro xs
1019
  if (this->E() != micro.last_E || this->sqrtkT() != micro.last_sqrtkT ||
2,147,483,647✔
1020
      i_sab != micro.index_sab || sab_frac != micro.sab_frac ||
2,147,483,647✔
1021
      ncrystal_xs != micro.ncrystal_xs) {
2,147,483,647!
1022
    data::nuclides[i_nuclide]->calculate_xs(i_sab, i_grid, sab_frac, *this);
2,147,483,647✔
1023

1024
    // If NCrystal is being used, update micro cross section cache
1025
    micro.ncrystal_xs = ncrystal_xs;
2,147,483,647✔
1026
    if (ncrystal_xs >= 0.0) {
2,147,483,647✔
1027
      data::nuclides[i_nuclide]->calculate_elastic_xs(*this);
11,018,953✔
1028
      ncrystal_update_micro(ncrystal_xs, micro);
11,018,953✔
1029
    }
1030
  }
1031
}
2,147,483,647✔
1032

1033
//==============================================================================
1034
// Non-method functions
1035
//==============================================================================
1036
void add_surf_source_to_bank(Particle& p, const Surface& surf)
2,147,483,647✔
1037
{
1038
  if (simulation::current_batch <= settings::n_inactive ||
2,147,483,647✔
1039
      simulation::surf_source_bank.full()) {
2,147,483,647✔
1040
    return;
2,147,483,647✔
1041
  }
1042

1043
  // If a cell/cellfrom/cellto parameter is defined
1044
  if (settings::ssw_cell_id != C_NONE) {
337,076✔
1045

1046
    // Retrieve cell index and storage type
1047
    int cell_idx = model::cell_map[settings::ssw_cell_id];
254,431✔
1048

1049
    if (surf.bc_) {
254,431✔
1050
      // Leave if cellto with vacuum boundary condition
1051
      if (surf.bc_->type() == "vacuum" &&
298,914✔
1052
          settings::ssw_cell_type == SSWCellType::To) {
33,097✔
1053
        return;
1054
      }
1055

1056
      // Leave if other boundary condition than vacuum
1057
      if (surf.bc_->type() != "vacuum") {
274,644✔
1058
        return;
1059
      }
1060
    }
1061

1062
    // Check if the cell of interest has been exited
1063
    bool exited = false;
1064
    for (int i = 0; i < p.n_coord_last(); ++i) {
333,661✔
1065
      if (p.cell_last(i) == cell_idx) {
207,725✔
1066
        exited = true;
73,763✔
1067
      }
1068
    }
1069

1070
    // Check if the cell of interest has been entered
1071
    bool entered = false;
1072
    for (int i = 0; i < p.n_coord(); ++i) {
297,963✔
1073
      if (p.coord(i).cell() == cell_idx) {
172,027✔
1074
        entered = true;
57,516✔
1075
      }
1076
    }
1077

1078
    // Vacuum boundary conditions: return if cell is not exited
1079
    if (surf.bc_) {
125,936✔
1080
      if (surf.bc_->type() == "vacuum" && !exited) {
41,924!
1081
        return;
1082
      }
1083
    } else {
1084

1085
      // If we both enter and exit the cell of interest
1086
      if (entered && exited) {
104,974✔
1087
        return;
1088
      }
1089

1090
      // If we did not enter nor exit the cell of interest
1091
      if (!entered && !exited) {
77,771✔
1092
        return;
1093
      }
1094

1095
      // If cellfrom and the cell before crossing is not the cell of
1096
      // interest
1097
      if (settings::ssw_cell_type == SSWCellType::From && !exited) {
64,273✔
1098
        return;
1099
      }
1100

1101
      // If cellto and the cell after crossing is not the cell of interest
1102
      if (settings::ssw_cell_type == SSWCellType::To && !entered) {
52,731✔
1103
        return;
1104
      }
1105
    }
1106
  }
1107

1108
  SourceSite site;
129,653✔
1109
  site.r = p.r();
129,653✔
1110
  site.u = p.u();
129,653✔
1111
  site.E = p.E();
129,653✔
1112
  site.time = p.time();
129,653✔
1113
  site.wgt = p.wgt();
129,653✔
1114
  site.delayed_group = p.delayed_group();
129,653✔
1115
  site.surf_id = surf.id_;
129,653✔
1116
  site.particle = p.type();
129,653✔
1117
  site.parent_id = p.id();
129,653✔
1118
  site.progeny_id = p.n_progeny();
129,653✔
1119
  int64_t idx = simulation::surf_source_bank.thread_safe_append(site);
129,653✔
1120
}
1121

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

© 2026 Coveralls, Inc