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

openmc-dev / openmc / 34416149688

09 Sep 2026 11:15PM UTC coverage: 81.48% (+0.1%) from 81.347%
34416149688

Pull #4087

github

web-flow
Merge 93138e589 into 5260b9a0f
Pull Request #4087: Compute bounding boxes for general planes and tori in C++

18756 of 27197 branches covered (68.96%)

Branch coverage included in aggregate %.

43 of 46 new or added lines in 2 files covered. (93.48%)

959 existing lines in 29 files now uncovered.

60863 of 70519 relevant lines covered (86.31%)

49704801.91 hits per line

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

86.88
/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/material.h"
19
#include "openmc/message_passing.h"
20
#include "openmc/mgxs_interface.h"
21
#include "openmc/nuclide.h"
22
#include "openmc/particle_data.h"
23
#include "openmc/photon.h"
24
#include "openmc/physics.h"
25
#include "openmc/physics_mg.h"
26
#include "openmc/random_lcg.h"
27
#include "openmc/settings.h"
28
#include "openmc/simulation.h"
29
#include "openmc/source.h"
30
#include "openmc/surface.h"
31
#include "openmc/tallies/derivative.h"
32
#include "openmc/tallies/tally.h"
33
#include "openmc/tallies/tally_scoring.h"
34
#include "openmc/track_output.h"
35
#include "openmc/weight_windows.h"
36

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

41
namespace openmc {
42

43
//==============================================================================
44
// Particle implementation
45
//==============================================================================
46

47
double Particle::speed(double E) const
2,147,483,647 ✔
48
{
49
  // Determine mass in eV/c^2
50
  double mass = this->mass();
2,147,483,647 ✔
51
  // Equivalent to C * sqrt(1-(m/(m+E))^2) without problem at E<<m:
52
  return C_LIGHT * std::sqrt(E * (E + 2 * mass)) / (E + mass);
2,147,483,647 ✔
53
}
54

55
double Particle::speed() const
2,147,483,647 ✔
56
{
57
  if (settings::run_CE) {
2,147,483,647 ✔
58
    return speed(this->E());
2,147,483,647 ✔
59
  } else {
60
    auto mat = this->material();
2,082,832,565 ✔
61
    if (mat == MATERIAL_VOID)
2,082,832,565 !
62
      return 1.0 / data::mg.default_inverse_velocity_[this->g()];
×
63
    auto& macro_xs = data::mg.macro_xs_[mat];
2,082,832,565 ✔
64
    int macro_t = this->mg_xs_cache().t;
2,082,832,565 ✔
65
    int macro_a = macro_xs.get_angle_index(this->u());
2,082,832,565 ✔
66
    return 1.0 / macro_xs.get_xs(
2,147,483,647 ✔
67
                   MgxsType::INVERSE_VELOCITY, this->g(), macro_t, macro_a);
2,082,832,565 ✔
68
  }
69
}
70

71
double Particle::mass() const
2,147,483,647 ✔
72
{
73
  switch (type().pdg_number()) {
2,147,483,647 ✔
74
  case PDG_NEUTRON:
75
    return MASS_NEUTRON_EV;
76
  case PDG_ELECTRON:
110,000 ✔
77
  case PDG_POSITRON:
110,000 ✔
78
    return MASS_ELECTRON_EV;
110,000 ✔
79
  default:
39,164,395 ✔
80
    return this->type().mass() * AMU_EV;
39,164,395 ✔
81
  }
82
}
83

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

97
  // Increment number of secondaries created (for ParticleProductionFilter)
98
  n_secondaries()++;
7,819,407 ✔
99

100
  SourceSite bank;
7,819,407 ✔
101
  bank.particle = type;
7,819,407 ✔
102
  bank.wgt = wgt;
7,819,407 ✔
103
  bank.r = r();
7,819,407 !
104
  bank.u = u;
7,819,407 ✔
105
  bank.E = settings::run_CE ? E : g();
7,819,407 !
106
  bank.time = time();
7,819,407 ✔
107
  bank_second_E() += bank.E;
7,819,407 ✔
108
  bank.parent_id = current_work();
7,819,407 ✔
109
  if (settings::use_shared_secondary_bank) {
7,819,407 ✔
110
    bank.progeny_id = n_progeny()++;
932,756 ✔
111
  }
112
  bank.wgt_born = wgt_born();
7,819,407 ✔
113
  bank.wgt_ww_born = wgt_ww_born();
7,819,407 ✔
114
  bank.n_split = n_split();
7,819,407 ✔
115

116
  local_secondary_bank().emplace_back(bank);
7,819,407 ✔
117
  return true;
118
}
119

120
void Particle::split(double wgt)
19,031,916 ✔
121
{
122
  SourceSite bank;
19,031,916 ✔
123
  bank.particle = type();
19,031,916 ✔
124
  bank.wgt = wgt;
19,031,916 ✔
125
  bank.r = r();
19,031,916 ✔
126
  bank.u = u();
19,031,916 ✔
127
  bank.E = settings::run_CE ? E() : g();
19,031,916 ✔
128
  bank.time = time();
19,031,916 ✔
129

130
  // Convert signed index to a signed surface ID
131
  if (surface() == SURFACE_NONE) {
19,031,916 ✔
132
    bank.surf_id = SURFACE_NONE;
18,764,986 ✔
133
  } else {
134
    int surf_id = model::surfaces[surface_index()]->id_;
266,930 ✔
135
    bank.surf_id = (surface() > 0) ? surf_id : -surf_id;
266,930 ✔
136
  }
137

138
  bank.wgt_born = wgt_born();
19,031,916 ✔
139
  bank.wgt_ww_born = wgt_ww_born();
19,031,916 ✔
140
  bank.n_split = n_split();
19,031,916 ✔
141
  bank.n_collision = n_collision();
19,031,916 ✔
142
  bank.parent_id = current_work();
19,031,916 ✔
143
  if (settings::use_shared_secondary_bank) {
19,031,916 ✔
144
    bank.progeny_id = n_progeny()++;
13,713,295 ✔
145
  }
146

147
  local_secondary_bank().emplace_back(bank);
19,031,916 ✔
148
}
19,031,916 ✔
149

150
void Particle::from_source(const SourceSite* src)
218,229,293 ✔
151
{
152
  // Reset some attributes
153
  clear();
218,229,293 ✔
154
  surface() = SURFACE_NONE;
218,229,293 ✔
155
  cell_born() = C_NONE;
218,229,293 ✔
156
  material() = C_NONE;
218,229,293 ✔
157
  n_collision() = src->n_collision;
218,229,293 ✔
158
  fission() = false;
218,229,293 ✔
159
  zero_flux_derivs();
218,229,293 ✔
160
  lifetime() = 0.0;
218,229,293 ✔
161
#ifdef OPENMC_DAGMC_ENABLED
162
  history().reset();
20,001,487 ✔
163
#endif
164

165
  // Copy attributes from source bank site
166
  type() = src->particle;
218,229,293 ✔
167
  wgt() = src->wgt;
218,229,293 ✔
168
  wgt_last() = src->wgt;
218,229,293 ✔
169
  r() = src->r;
218,229,293 ✔
170
  u() = src->u;
218,229,293 ✔
171
  r_born() = src->r;
218,229,293 ✔
172
  r_last_current() = src->r;
218,229,293 ✔
173
  r_last() = src->r;
218,229,293 ✔
174
  u_last() = src->u;
218,229,293 ✔
175
  if (settings::run_CE) {
218,229,293 ✔
176
    E() = src->E;
100,483,429 ✔
177
    g() = 0;
100,483,429 ✔
178
  } else {
179
    g() = static_cast<int>(src->E);
117,745,864 ✔
180
    g_last() = static_cast<int>(src->E);
117,745,864 ✔
181
    E() = data::mg.energy_bin_avg_[g()];
117,745,864 ✔
182
  }
183
  E_last() = E();
218,229,293 ✔
184
  time() = src->time;
218,229,293 ✔
185
  time_last() = src->time;
218,229,293 ✔
186
  parent_nuclide() = src->parent_nuclide;
218,229,293 ✔
187
  delayed_group() = src->delayed_group;
218,229,293 ✔
188

189
  // Convert signed surface ID to signed index
190
  if (src->surf_id != SURFACE_NONE) {
218,229,293 ✔
191
    auto it = model::surface_map.find(std::abs(src->surf_id));
380,725 !
192
    if (it != model::surface_map.end()) {
380,725 !
193
      int index_plus_one = it->second + 1;
380,725 ✔
194
      surface() = (src->surf_id > 0) ? index_plus_one : -index_plus_one;
380,725 ✔
195
    }
196
  }
197

198
  wgt_born() = src->wgt_born;
218,229,293 ✔
199
  wgt_ww_born() = src->wgt_ww_born;
218,229,293 ✔
200
  n_split() = src->n_split;
218,229,293 ✔
201
}
218,229,293 ✔
202

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

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

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

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

230
    // Set birth cell attribute
231
    if (cell_born() == C_NONE)
208,233,881 !
232
      cell_born() = lowest_coord().cell();
208,233,881 ✔
233

234
    // Initialize last cells from current cell
235
    for (int j = 0; j < n_coord(); ++j) {
434,070,748 ✔
236
      cell_last(j) = coord(j).cell();
225,836,867 ✔
237
    }
238
    n_coord_last() = n_coord();
208,233,881 ✔
239
  }
240

241
  // Write particle track.
242
  if (write_track())
2,147,483,647 ✔
243
    write_particle_track(*this);
5,630 ✔
244

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

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

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

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

280
  // Sample a distance to collision
281
  if (type() == ParticleType::electron() ||
2,147,483,647 !
282
      type() == ParticleType::positron()) {
2,147,483,647 !
283
    collision_distance() = material() == MATERIAL_VOID ? INFINITY : 0.0;
220,000 !
284
  } else if (macro_xs().total == 0.0) {
2,147,483,647 ✔
285
    collision_distance() = INFINITY;
113,932,795 ✔
286
  } else {
287
    collision_distance() = -std::log(prn(current_seed())) / macro_xs().total;
2,147,483,647 ✔
288
  }
289

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

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

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

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

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

315
  // Score track-length estimate of k-eff
316
  if (settings::run_mode == RunMode::EIGENVALUE && type().is_neutron()) {
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

330
  // Clear surface component if distance is long enough
331
  if (distance > TINY_BIT)
2,147,483,647 ✔
332
    surface() = SURFACE_NONE;
2,147,483,647 ✔
333
}
2,147,483,647 ✔
334

335
void Particle::event_cross_surface()
2,147,483,647 ✔
336
{
337
  // Saving previous cell data
338
  for (int j = 0; j < n_coord(); ++j) {
2,147,483,647 ✔
339
    cell_last(j) = coord(j).cell();
2,147,483,647 ✔
340
  }
341
  n_coord_last() = n_coord();
2,147,483,647 ✔
342

343
  // Set surface that particle is on and adjust coordinate levels
344
  surface() = boundary().surface();
2,147,483,647 ✔
345
  n_coord() = boundary().coord_level();
2,147,483,647 ✔
346

347
  if (boundary().lattice_translation()[0] != 0 ||
2,147,483,647 ✔
348
      boundary().lattice_translation()[1] != 0 ||
2,147,483,647 ✔
349
      boundary().lattice_translation()[2] != 0) {
2,147,483,647 ✔
350
    // Particle crosses lattice boundary
351

352
    int i_lattice = coord(boundary().coord_level() - 1).lattice();
813,765,123 !
353
    bool verbose = settings::verbosity >= 10 || trace();
813,765,123 !
354
    cross_lattice(*this, boundary(), verbose);
813,765,123 ✔
355
    event() = TallyEvent::LATTICE;
813,765,123 ✔
356

357
    // Score cell to cell partial currents
358
    if (!model::active_surface_tallies.empty()) {
813,765,123 ✔
359
      auto& lat {*model::lattices[i_lattice]};
55 ✔
360
      bool is_valid;
55 ✔
361
      Direction normal =
55 ✔
362
        lat.get_normal(boundary().lattice_translation(), is_valid);
55 ✔
363
      if (is_valid) {
55 !
364
        normal /= normal.norm();
55 ✔
365
        score_surface_tally(*this, model::active_surface_tallies, normal);
55 ✔
366
      }
367
    }
368

369
  } else {
370

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

373
    // Particle crosses surface
374
    // If BC, add particle to surface source before crossing surface
375
    if (surf.surf_source_ && surf.bc_) {
2,147,483,647 ✔
376
      add_surf_source_to_bank(*this, surf);
1,017,856,681 ✔
377
    }
378
    this->cross_surface(surf);
2,147,483,647 ✔
379
    // If no BC, add particle to surface source after crossing surface
380
    if (surf.surf_source_ && !surf.bc_) {
2,147,483,647 ✔
381
      add_surf_source_to_bank(*this, surf);
1,855,425,325 ✔
382
    }
383
    if (settings::weight_window_checkpoint_surface) {
2,147,483,647 ✔
384
      apply_weight_windows(*this);
13,175,293 ✔
385
    }
386
    event() = TallyEvent::SURFACE;
2,147,483,647 ✔
387

388
    // Score cell to cell partial currents
389
    if (!model::active_surface_tallies.empty()) {
2,147,483,647 ✔
390
      Direction normal = surf.normal(r());
34,933,558 ✔
391
      normal /= normal.norm();
34,933,558 ✔
392
      score_surface_tally(*this, model::active_surface_tallies, normal);
34,933,558 ✔
393
    }
394
  }
395
}
2,147,483,647 ✔
396

397
void Particle::event_collide()
2,147,483,647 ✔
398
{
399

400
  // Score collision estimate of keff
401
  if (settings::run_mode == RunMode::EIGENVALUE && type().is_neutron()) {
2,147,483,647 ✔
402
    keff_tally_collision() += wgt() * macro_xs().nu_fission / macro_xs().total;
2,147,483,647 ✔
403
  }
404

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

409
  if (!model::active_meshsurf_tallies.empty())
2,147,483,647 ✔
410
    score_meshsurface_tally(*this, model::active_meshsurf_tallies);
63,095,989 ✔
411

412
  // Preserve whether the particle is still associated with a recently crossed
413
  // surface so that a direction change during a near-surface collision can be
414
  // reconciled afterward. The surface marker is no longer needed during the
415
  // collision itself.
416
  const bool near_surface = surface() != SURFACE_NONE;
2,147,483,647 ✔
417
  surface() = SURFACE_NONE;
2,147,483,647 ✔
418

419
  if (settings::run_CE) {
2,147,483,647 ✔
420
    collision(*this);
1,593,021,606 ✔
421
  } else {
422
    collision_mg(*this);
1,801,144,774 ✔
423
  }
424

425
  // Collision track feature to recording particle interaction
426
  if (settings::collision_track) {
2,147,483,647 ✔
427
    collision_track_record(*this);
712,734 ✔
428
  }
429

430
  // Score collision estimator tallies -- this is done after a collision
431
  // has occurred rather than before because we need information on the
432
  // outgoing energy for any tallies with an outgoing energy filter
433
  if (!model::active_collision_tallies.empty())
2,147,483,647 ✔
434
    score_collision_tally(*this);
75,093,829 ✔
435
  if (!model::active_analog_tallies.empty()) {
2,147,483,647 ✔
436
    if (settings::run_CE) {
511,009,925 ✔
437
      score_analog_tally_ce(*this);
509,801,663 ✔
438
    } else {
439
      score_analog_tally_mg(*this);
1,208,262 ✔
440
    }
441
  }
442

443
  if (!model::active_pulse_height_tallies.empty() && type().is_photon()) {
2,147,483,647 ✔
444
    pht_collision_energy();
102,509 ✔
445
  }
446

447
  // Reset banked weight during collision
448
  n_bank() = 0;
2,147,483,647 ✔
449
  bank_second_E() = 0.0;
2,147,483,647 ✔
450
  wgt_bank() = 0.0;
2,147,483,647 ✔
451

452
  // Clear number of secondaries in this collision. This is
453
  // distinct from the number of created neutrons n_bank() above!
454
  n_secondaries() = 0;
2,147,483,647 ✔
455

456
  zero_delayed_bank();
2,147,483,647 ✔
457

458
  // Reset fission logical
459
  fission() = false;
2,147,483,647 ✔
460

461
  // Save coordinates for tallying purposes
462
  r_last_current() = r();
2,147,483,647 ✔
463

464
  // Set last material to none since cross sections will need to be
465
  // re-evaluated
466
  material_last() = C_NONE;
2,147,483,647 ✔
467

468
  // Set all directions to base level -- right now, after a collision, only
469
  // the base level directions are changed
470
  for (int j = 0; j < n_coord() - 1; ++j) {
2,147,483,647 ✔
471
    if (coord(j + 1).rotated()) {
298,231,813 ✔
472
      // If next level is rotated, apply rotation matrix
473
      const auto& m {model::cells[coord(j).cell()]->rotation_};
11,724,229 ✔
474
      const auto& u {coord(j).u()};
11,724,229 ✔
475
      coord(j + 1).u() = u.rotate(m);
11,724,229 ✔
476
    } else {
477
      // Otherwise, copy this level's direction
478
      coord(j + 1).u() = coord(j).u();
286,507,584 ✔
479
    }
480
  }
481

482
  // Score flux derivative accumulators for differential tallies.
483
  if (!model::active_tallies.empty())
2,147,483,647 ✔
484
    score_collision_derivative(*this);
1,446,676,052 ✔
485

486
#ifdef OPENMC_DAGMC_ENABLED
487
  history().reset();
310,599,651 ✔
488
#endif
489

490
  if (near_surface && alive())
2,147,483,647 !
491
    reconcile_cell_after_collision(*this);
55 ✔
492
}
2,147,483,647 ✔
493

494
void Particle::event_revive_from_secondary(const SourceSite& site)
27,866,072 ✔
495
{
496
  // Write final position for the previous track (skip if this is a freshly
497
  // constructed particle with no prior track, e.g., Phase 2 of shared
498
  // secondary transport)
499
  if (write_track() && n_event() > 0) {
27,866,072 !
500
    write_particle_track(*this);
513 ✔
501
  }
502

503
  from_source(&site);
27,866,072 ✔
504

505
  n_event() = 0;
27,866,072 ✔
506
  if (!settings::use_shared_secondary_bank) {
27,866,072 ✔
507
    n_tracks()++;
12,414,359 ✔
508
  }
509
  bank_second_E() = 0.0;
27,866,072 ✔
510

511
  // Subtract secondary particle energy from interim pulse-height results.
512
  // In shared secondary mode, this subtraction was already done on the parent
513
  // particle during create_secondary(), so skip it here.
514
  if (!settings::use_shared_secondary_bank &&
40,280,431 ✔
515
      !model::active_pulse_height_tallies.empty() && this->type().is_photon()) {
27,866,072 !
516
    // Since the birth cell of the particle has not been set we
517
    // have to determine it before the energy of the secondary particle can be
518
    // removed from the pulse-height of this cell.
519
    if (lowest_coord().cell() == C_NONE) {
33,429 !
520
      bool verbose = settings::verbosity >= 10 || trace();
33,429 !
521
      if (!exhaustive_find_cell(*this, verbose)) {
33,429 !
522
        mark_as_lost("Could not find the cell containing particle " +
×
523
                     std::to_string(id()));
×
524
        return;
×
525
      }
526
      // Set birth cell attribute
527
      if (cell_born() == C_NONE)
33,429 !
528
        cell_born() = lowest_coord().cell();
33,429 ✔
529

530
      // Initialize last cells from current cell
531
      for (int j = 0; j < n_coord(); ++j) {
66,858 ✔
532
        cell_last(j) = coord(j).cell();
33,429 ✔
533
      }
534
      n_coord_last() = n_coord();
33,429 ✔
535
    }
536
    pht_secondary_particles();
33,429 ✔
537
  }
538

539
  // Enter new particle in particle track file
540
  if (write_track())
27,866,072 ✔
541
    add_particle_track(*this);
513 ✔
542
}
543

544
void Particle::event_check_limit_and_revive()
2,147,483,647 ✔
545
{
546
  // If particle has too many events, display warning and kill it
547
  n_event()++;
2,147,483,647 ✔
548
  if (n_event() == settings::max_particle_events) {
2,147,483,647 !
549
    warning("Particle " + std::to_string(id()) +
×
550
            " underwent maximum number of events.");
551
    wgt() = 0.0;
×
552
  }
553

554
  // In non-shared-secondary mode, revive from local secondary bank
555
  if (!alive() && !settings::use_shared_secondary_bank &&
2,147,483,647 ✔
556
      !local_secondary_bank().empty()) {
191,915,747 ✔
557
    SourceSite& site = local_secondary_bank().back();
12,414,359 ✔
558
    event_revive_from_secondary(site);
12,414,359 ✔
559
    local_secondary_bank().pop_back();
12,414,359 ✔
560
  }
561
}
2,147,483,647 ✔
562

563
void Particle::event_death()
195,852,942 ✔
564
{
565
#ifdef OPENMC_DAGMC_ENABLED
566
  history().reset();
17,887,606 ✔
567
#endif
568

569
  // Finish particle track output.
570
  if (write_track()) {
195,852,942 ✔
571
    write_particle_track(*this);
1,010 ✔
572
    finalize_particle_track(*this);
1,010 ✔
573
  }
574

575
  // Contribute tally reduction variables to global accumulator
576
  const auto k_absorption = keff_tally_absorption();
195,852,942 ✔
577
  const auto k_collision = keff_tally_collision();
195,852,942 ✔
578
  const auto k_tracklength = keff_tally_tracklength();
195,852,942 ✔
579
  const auto leakage = keff_tally_leakage();
195,852,942 ✔
580

581
  if (settings::run_mode == RunMode::EIGENVALUE) {
195,852,942 ✔
582
    if (k_absorption != 0.0) {
152,357,000 ✔
583
#pragma omp atomic
74,036,046 ✔
584
      global_tally_absorption += k_absorption;
61,152,513 ✔
585
    }
586
    if (k_collision != 0.0) {
152,357,000 ✔
587
#pragma omp atomic
79,588,579 ✔
588
      global_tally_collision += k_collision;
65,951,336 ✔
589
    }
590
    if (k_tracklength != 0.0) {
152,357,000 ✔
591
#pragma omp atomic
83,690,631 ✔
592
      global_tally_tracklength += k_tracklength;
69,209,415 ✔
593
    }
594
  }
595
  if (leakage != 0.0) {
195,852,942 ✔
596
#pragma omp atomic
21,864,419 ✔
597
    global_tally_leakage += leakage;
17,683,940 ✔
598
  }
599

600
  // Reset particle tallies once accumulated
601
  keff_tally_absorption() = 0.0;
195,852,942 ✔
602
  keff_tally_collision() = 0.0;
195,852,942 ✔
603
  keff_tally_tracklength() = 0.0;
195,852,942 ✔
604
  keff_tally_leakage() = 0.0;
195,852,942 ✔
605

606
  if (!model::active_pulse_height_tallies.empty()) {
195,852,942 ✔
607
    score_pulse_height_tally(*this, model::active_pulse_height_tallies);
143,000 ✔
608
  }
609

610
  // Accumulate track count for this particle history
611
  if (!settings::use_shared_secondary_bank) {
195,852,942 ✔
612
#pragma omp atomic
97,990,968 ✔
613
    simulation::simulation_tracks_completed += n_tracks();
179,502,388 ✔
614
  }
615

616
  // Record the number of progeny created by this particle.
617
  // This data will be used to efficiently sort the fission bank.
618
  if (settings::run_mode == RunMode::EIGENVALUE ||
195,852,942 ✔
619
      settings::use_shared_secondary_bank) {
620
    simulation::progeny_per_particle[current_work()] = n_progeny();
168,707,554 ✔
621
  }
622
}
195,852,942 ✔
623

624
void Particle::pht_collision_energy()
102,509 ✔
625
{
626
  // Adds the energy particles lose in a collision to the pulse-height
627

628
  // determine index of cell in pulse_height_cells
629
  auto it = std::find(model::pulse_height_cells.begin(),
102,509 ✔
630
    model::pulse_height_cells.end(), lowest_coord().cell());
102,509 !
631

632
  if (it != model::pulse_height_cells.end()) {
102,509 !
633
    int index = std::distance(model::pulse_height_cells.begin(), it);
102,509 ✔
634
    pht_storage()[index] += E_last() - E();
102,509 ✔
635

636
    // If the energy of the particle is below the cutoff, it will not be sampled
637
    // so its energy is added to the pulse-height in the cell
638
    int photon = ParticleType::photon().transport_index();
102,509 ✔
639
    if (E() < settings::energy_cutoff[photon]) {
102,509 ✔
640
      pht_storage()[index] += E();
45,375 ✔
641
    }
642
  }
643
}
102,509 ✔
644

645
void Particle::pht_secondary_particles()
33,429 ✔
646
{
647
  // Removes the energy of secondary produced particles from the pulse-height
648

649
  // determine index of cell in pulse_height_cells
650
  auto it = std::find(model::pulse_height_cells.begin(),
33,429 ✔
651
    model::pulse_height_cells.end(), cell_born());
33,429 !
652

653
  if (it != model::pulse_height_cells.end()) {
33,429 !
654
    int index = std::distance(model::pulse_height_cells.begin(), it);
33,429 ✔
655
    pht_storage()[index] -= E();
33,429 ✔
656
  }
657
}
33,429 ✔
658

659
void Particle::cross_surface(const Surface& surf)
2,147,483,647 ✔
660
{
661

662
  if (settings::verbosity >= 10 || trace()) {
2,147,483,647 ✔
663
    write_message(1, "    Crossing surface {}", surf.id_);
88 ✔
664
  }
665

666
  // Handle any applicable boundary conditions.
667
  if (surf.bc_ && settings::run_mode != RunMode::PLOTTING &&
2,147,483,647 !
668
      settings::run_mode != RunMode::VOLUME) {
669
    surf.bc_->handle_particle(*this, surf);
1,018,203,678 ✔
670
    return;
1,018,203,678 ✔
671
  }
672

673
  // ==========================================================================
674
  // SEARCH NEIGHBOR LISTS FOR NEXT CELL
675

676
#ifdef OPENMC_DAGMC_ENABLED
677
  // in DAGMC, we know what the next cell should be
678
  if (surf.geom_type() == GeometryType::DAG) {
168,725,414 ✔
679
    int32_t i_cell = next_cell(surface_index(), cell_last(n_coord() - 1),
46,716 ✔
680
                       lowest_coord().universe()) -
46,716 ✔
681
                     1;
46,716 ✔
682
    // save material, temperature, and density multiplier
683
    material_last() = material();
46,716 ✔
684
    sqrtkT_last() = sqrtkT();
46,716 ✔
685
    density_mult_last() = density_mult();
46,716 ✔
686
    // set new cell value
687
    lowest_coord().cell() = i_cell;
46,716 ✔
688
    auto& cell = model::cells[i_cell];
46,716 ✔
689

690
    cell_instance() = 0;
46,716 ✔
691
    if (cell->distribcell_index_ >= 0)
46,716 ✔
692
      cell_instance() = cell_instance_at_level(*this, n_coord() - 1);
45,692 ✔
693

694
    material() = cell->material(cell_instance());
46,716 !
695
    sqrtkT() = cell->sqrtkT(cell_instance());
46,716 !
696
    density_mult() = cell->density_mult(cell_instance());
46,716 ✔
697
    return;
46,716 ✔
698
  }
699
#endif
700

701
  bool verbose = settings::verbosity >= 10 || trace();
1,856,056,591 !
702
  if (neighbor_list_find_cell(*this, verbose)) {
1,856,056,591 ✔
703
    return;
704
  }
705

706
  // ==========================================================================
707
  // COULDN'T FIND PARTICLE IN NEIGHBORING CELLS, SEARCH ALL CELLS
708

709
  // Remove lower coordinate levels
710
  n_coord() = 1;
29,977 ✔
711
  bool found = exhaustive_find_cell(*this, verbose);
29,977 ✔
712

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

719
    surface() = SURFACE_NONE;
5,865 ✔
720
    n_coord() = 1;
5,865 ✔
721
    r() += TINY_BIT * u();
5,865 ✔
722

723
    // Couldn't find next cell anywhere! This probably means there is an actual
724
    // undefined region in the geometry.
725

726
    if (!exhaustive_find_cell(*this, verbose)) {
5,865 !
727
      mark_as_lost("After particle " + std::to_string(id()) +
17,586 ✔
728
                   " crossed surface " + std::to_string(surf.id_) +
17,586 ✔
729
                   " it could not be located in any cell and it did not leak.");
730
      return;
5,856 ✔
731
    }
732
  }
733
}
734

735
void Particle::cross_vacuum_bc(const Surface& surf)
40,365,477 ✔
736
{
737
  // Score any surface current tallies -- note that the particle is moved
738
  // forward slightly so that if the mesh boundary is on the surface, it is
739
  // still processed
740

741
  if (!model::active_meshsurf_tallies.empty()) {
40,365,477 ✔
742
    // TODO: Find a better solution to score surface currents than
743
    // physically moving the particle forward slightly
744

745
    r() += TINY_BIT * u();
936,210 ✔
746
    score_meshsurface_tally(*this, model::active_meshsurf_tallies);
936,210 ✔
747
  }
748

749
  // Score to global leakage tally
750
  keff_tally_leakage() += wgt();
40,365,477 ✔
751

752
  // Kill the particle
753
  wgt() = 0.0;
40,365,477 ✔
754

755
  // Display message
756
  if (settings::verbosity >= 10 || trace()) {
40,365,477 !
757
    write_message(1, "    Leaked out of surface {}", surf.id_);
22 ✔
758
  }
759
}
40,365,477 ✔
760

761
void Particle::cross_reflective_bc(const Surface& surf, Direction new_u)
976,599,985 ✔
762
{
763
  // Do not handle reflective boundary conditions on lower universes
764
  if (n_coord() != 1) {
976,599,985 !
UNCOV
765
    mark_as_lost("Cannot reflect particle " + std::to_string(id()) +
×
766
                 " off surface in a lower universe.");
UNCOV
767
    return;
×
768
  }
769

770
  // Score surface currents since reflection causes the direction of the
771
  // particle to change. For surface filters, we need to score the tallies
772
  // twice, once before the particle's surface attribute has changed and
773
  // once after. For mesh surface filters, we need to artificially move
774
  // the particle slightly back in case the surface crossing is coincident
775
  // with a mesh boundary
776

777
  if (!model::active_surface_tallies.empty()) {
976,599,985 ✔
778
    Direction normal = surf.normal(r());
285,021 ✔
779
    normal /= normal.norm();
285,021 ✔
780
    score_surface_tally(*this, model::active_surface_tallies, normal);
285,021 ✔
781
  }
782

783
  if (!model::active_meshsurf_tallies.empty()) {
976,599,985 ✔
784
    Position r {this->r()};
46,882,979 ✔
785
    this->r() -= TINY_BIT * u();
46,882,979 ✔
786
    score_meshsurface_tally(*this, model::active_meshsurf_tallies);
46,882,979 ✔
787
    this->r() = r;
46,882,979 ✔
788
  }
789

790
  // Set the new particle direction
791
  u() = new_u;
976,599,985 ✔
792

793
  // Reassign particle's cell and surface
794
  coord(0).cell() = cell_last(0);
976,599,985 ✔
795
  surface() = -surface();
976,599,985 ✔
796

797
  // If a reflective surface is coincident with a lattice or universe
798
  // boundary, it is necessary to redetermine the particle's coordinates in
799
  // the lower universes.
800
  // (unless we're using a dagmc model, which has exactly one universe)
801
  n_coord() = 1;
976,599,985 ✔
802
  if (surf.geom_type() != GeometryType::DAG &&
1,953,197,212 !
803
      !neighbor_list_find_cell(*this)) {
976,597,227 ✔
UNCOV
804
    mark_as_lost("Couldn't find particle after reflecting from surface " +
×
UNCOV
805
                 std::to_string(surf.id_) + ".");
×
UNCOV
806
    return;
×
807
  }
808

809
  // Set previous coordinate going slightly past surface crossing
810
  r_last_current() = r() + TINY_BIT * u();
976,599,985 ✔
811

812
  // Diagnostic message
813
  if (settings::verbosity >= 10 || trace()) {
976,599,985 !
UNCOV
814
    write_message(1, "    Reflected from surface {}", surf.id_);
×
815
  }
816
}
817

818
void Particle::cross_periodic_bc(
2,243,682 ✔
819
  const Surface& surf, Position new_r, Direction new_u, int new_surface)
820
{
821
  // Do not handle periodic boundary conditions on lower universes
822
  if (n_coord() != 1) {
2,243,682 !
UNCOV
823
    mark_as_lost(
×
UNCOV
824
      "Cannot transfer particle " + std::to_string(id()) +
×
825
      " across surface in a lower universe. Boundary conditions must be "
826
      "applied to root universe.");
UNCOV
827
    return;
×
828
  }
829

830
  // Score surface currents since reflection causes the direction of the
831
  // particle to change -- artificially move the particle slightly back in
832
  // case the surface crossing is coincident with a mesh boundary
833
  if (!model::active_meshsurf_tallies.empty()) {
2,243,682 !
UNCOV
834
    Position r {this->r()};
×
UNCOV
835
    this->r() -= TINY_BIT * u();
×
UNCOV
836
    score_meshsurface_tally(*this, model::active_meshsurf_tallies);
×
UNCOV
837
    this->r() = r;
×
838
  }
839

840
  // Adjust the particle's location and direction.
841
  r() = new_r;
2,243,682 ✔
842
  u() = new_u;
2,243,682 ✔
843

844
  // Reassign particle's surface
845
  surface() = new_surface;
2,243,682 ✔
846

847
  // Figure out what cell particle is in now
848
  n_coord() = 1;
2,243,682 ✔
849

850
  if (!neighbor_list_find_cell(*this)) {
2,243,682 !
UNCOV
851
    mark_as_lost("Couldn't find particle after hitting periodic "
×
UNCOV
852
                 "boundary on surface " +
×
UNCOV
853
                 std::to_string(surf.id_) + ".");
×
UNCOV
854
    return;
×
855
  }
856

857
  // Set previous coordinate going slightly past surface crossing
858
  r_last_current() = r() + TINY_BIT * u();
2,243,682 ✔
859

860
  // Diagnostic message
861
  if (settings::verbosity >= 10 || trace()) {
2,243,682 !
UNCOV
862
    write_message(1, "    Hit periodic boundary on surface {}", surf.id_);
×
863
  }
864
}
865

866
void Particle::mark_as_lost(const char* message)
5,865 ✔
867
{
868
  // Print warning and write lost particle file
869
  warning(message);
5,865 ✔
870
  if (settings::max_write_lost_particles < 0 ||
5,865 ✔
871
      simulation::n_lost_particles < settings::max_write_lost_particles) {
5,500 ✔
872
    write_restart();
440 ✔
873
  }
874
  // Increment number of lost particles
875
  wgt() = 0.0;
5,865 ✔
876
#pragma omp atomic
3,190 ✔
877
  simulation::n_lost_particles += 1;
2,675 ✔
878

879
  // Count the total number of simulated particles (on this processor)
880
  auto n = simulation::current_batch * settings::gen_per_batch *
5,865 ✔
881
           simulation::work_per_rank;
882

883
  // Abort the simulation if the maximum number of lost particles has been
884
  // reached
885
  if (simulation::n_lost_particles >= settings::max_lost_particles &&
5,865 ✔
886
      simulation::n_lost_particles >= settings::rel_max_lost_particles * n) {
9 !
887
    fatal_error("Maximum number of lost particles has been reached.");
9 ✔
888
  }
889
}
5,856 ✔
890

891
void Particle::write_restart() const
440 ✔
892
{
893
  // Dont write another restart file if in particle restart mode
894
  if (settings::run_mode == RunMode::PARTICLE)
440 ✔
895
    return;
33 ✔
896

897
  // Set up file name
898
  auto filename = fmt::format("{}particle_{}_{}.h5", settings::path_output,
407 ✔
899
    simulation::current_batch, id());
407 ✔
900

901
#pragma omp critical(WriteParticleRestart)
217 ✔
902
  {
407 ✔
903
    // Create file
904
    hid_t file_id = file_open(filename, 'w');
407 ✔
905

906
    // Write filetype and version info
907
    write_attribute(file_id, "filetype", "particle restart");
407 ✔
908
    write_attribute(file_id, "version", VERSION_PARTICLE_RESTART);
407 ✔
909
    write_attribute(file_id, "openmc_version", VERSION);
407 ✔
910
#ifdef GIT_SHA1
911
    write_attr_string(file_id, "git_sha1", GIT_SHA1);
912
#endif
913

914
    // Write data to file
915
    write_dataset(file_id, "current_batch", simulation::current_batch);
407 ✔
916
    write_dataset(file_id, "generations_per_batch", settings::gen_per_batch);
407 ✔
917
    write_dataset(file_id, "current_generation", simulation::current_gen);
407 ✔
918
    write_dataset(file_id, "n_particles", settings::n_particles);
407 ✔
919
    switch (settings::run_mode) {
407 !
920
    case RunMode::FIXED_SOURCE:
275 ✔
921
      write_dataset(file_id, "run_mode", "fixed source");
275 ✔
922
      break;
145 ✔
923
    case RunMode::EIGENVALUE:
132 ✔
924
      write_dataset(file_id, "run_mode", "eigenvalue");
132 ✔
925
      break;
72 ✔
UNCOV
926
    case RunMode::PARTICLE:
×
UNCOV
927
      write_dataset(file_id, "run_mode", "particle restart");
×
928
      break;
929
    default:
930
      break;
931
    }
932
    write_dataset(file_id, "id", id());
407 ✔
933
    write_dataset(file_id, "type", type().pdg_number());
407 ✔
934

935
    // Get source site data for the particle that got lost
936
    int64_t i = current_work();
407 ✔
937
    SourceSite site;
407 ✔
938
    if (settings::run_mode == RunMode::EIGENVALUE) {
407 ✔
939
      site = simulation::source_bank[i];
132 ✔
940
    } else if (settings::run_mode == RunMode::FIXED_SOURCE &&
275 ✔
941
               settings::use_shared_secondary_bank &&
275 !
942
               i < simulation::shared_secondary_bank_read.size()) {
55 !
UNCOV
943
      site = simulation::shared_secondary_bank_read[i];
×
944
    } else if (settings::run_mode == RunMode::FIXED_SOURCE) {
275 !
945
      // Re-sample using the same seed used to generate the source particle.
946
      // current_work() is 0-indexed, compute_particle_id expects 1-indexed.
947
      int64_t id = compute_transport_seed(compute_particle_id(i + 1));
275 ✔
948
      uint64_t seed = init_seed(id, STREAM_SOURCE);
275 ✔
949
      site = sample_external_source(&seed);
275 ✔
950
    }
951
    write_dataset(file_id, "weight", site.wgt);
407 ✔
952
    write_dataset(file_id, "energy", site.E);
407 ✔
953
    write_dataset(file_id, "xyz", site.r);
407 ✔
954
    write_dataset(file_id, "uvw", site.u);
407 ✔
955
    write_dataset(file_id, "time", site.time);
407 ✔
956

957
    // Close file
958
    file_close(file_id);
407 ✔
959
  } // #pragma omp critical
960
}
407 ✔
961

962
void Particle::update_neutron_xs(
2,147,483,647 ✔
963
  int i_nuclide, int i_grid, int i_sab, double sab_frac, double ncrystal_xs)
964
{
965
  // Get microscopic cross section cache
966
  auto& micro = this->neutron_xs(i_nuclide);
2,147,483,647 ✔
967

968
  // If the cache doesn't match, recalculate micro xs
969
  if (this->E() != micro.last_E || this->sqrtkT() != micro.last_sqrtkT ||
2,147,483,647 ✔
970
      i_sab != micro.index_sab || sab_frac != micro.sab_frac ||
2,147,483,647 ✔
971
      ncrystal_xs != micro.ncrystal_xs) {
2,147,483,647 !
972
    data::nuclides[i_nuclide]->calculate_xs(i_sab, i_grid, sab_frac, *this);
2,147,483,647 ✔
973

974
    // If NCrystal is being used, update micro cross section cache
975
    micro.ncrystal_xs = ncrystal_xs;
2,147,483,647 ✔
976
    if (ncrystal_xs >= 0.0) {
2,147,483,647 ✔
977
      data::nuclides[i_nuclide]->calculate_elastic_xs(*this);
11,018,953 ✔
978
      ncrystal_update_micro(ncrystal_xs, micro);
11,018,953 ✔
979
    }
980
  }
981
}
2,147,483,647 ✔
982

983
//==============================================================================
984
// Non-method functions
985
//==============================================================================
986
void add_surf_source_to_bank(Particle& p, const Surface& surf)
2,147,483,647 ✔
987
{
988
  if (simulation::current_batch <= settings::n_inactive ||
2,147,483,647 ✔
989
      simulation::surf_source_bank.full()) {
2,147,483,647 ✔
990
    return;
2,147,483,647 ✔
991
  }
992

993
  // If a cell/cellfrom/cellto parameter is defined
994
  if (settings::ssw_cell_id != C_NONE) {
304,421 ✔
995

996
    // Retrieve cell index and storage type
997
    int cell_idx = model::cell_map[settings::ssw_cell_id];
222,356 ✔
998

999
    if (surf.bc_) {
222,356 ✔
1000
      // Leave if cellto with vacuum boundary condition
1001
      if (surf.bc_->type() == "vacuum" &&
284,578 ✔
1002
          settings::ssw_cell_type == SSWCellType::To) {
32,879 ✔
1003
        return;
1004
      }
1005

1006
      // Leave if other boundary condition than vacuum
1007
      if (surf.bc_->type() != "vacuum") {
260,248 ✔
1008
        return;
1009
      }
1010
    }
1011

1012
    // Check if the cell of interest has been exited
1013
    bool exited = false;
1014
    for (int i = 0; i < p.n_coord_last(); ++i) {
268,745 ✔
1015
      if (p.cell_last(i) == cell_idx) {
167,964 ✔
1016
        exited = true;
59,527 ✔
1017
      }
1018
    }
1019

1020
    // Check if the cell of interest has been entered
1021
    bool entered = false;
1022
    for (int i = 0; i < p.n_coord(); ++i) {
233,629 ✔
1023
      if (p.coord(i).cell() == cell_idx) {
132,848 ✔
1024
        entered = true;
43,893 ✔
1025
      }
1026
    }
1027

1028
    // Vacuum boundary conditions: return if cell is not exited
1029
    if (surf.bc_) {
100,781 ✔
1030
      if (surf.bc_->type() == "vacuum" && !exited) {
41,428 !
1031
        return;
1032
      }
1033
    } else {
1034

1035
      // If we both enter and exit the cell of interest
1036
      if (entered && exited) {
80,067 ✔
1037
        return;
1038
      }
1039

1040
      // If we did not enter nor exit the cell of interest
1041
      if (!entered && !exited) {
66,550 ✔
1042
        return;
1043
      }
1044

1045
      // If cellfrom and the cell before crossing is not the cell of
1046
      // interest
1047
      if (settings::ssw_cell_type == SSWCellType::From && !exited) {
63,786 ✔
1048
        return;
1049
      }
1050

1051
      // If cellto and the cell after crossing is not the cell of interest
1052
      if (settings::ssw_cell_type == SSWCellType::To && !entered) {
52,313 ✔
1053
        return;
1054
      }
1055
    }
1056
  }
1057

1058
  SourceSite site;
128,645 ✔
1059
  site.r = p.r();
128,645 ✔
1060
  site.u = p.u();
128,645 ✔
1061
  site.E = p.E();
128,645 ✔
1062
  site.time = p.time();
128,645 ✔
1063
  site.wgt = p.wgt();
128,645 ✔
1064
  site.delayed_group = p.delayed_group();
128,645 ✔
1065
  site.surf_id = surf.id_;
128,645 ✔
1066
  site.particle = p.type();
128,645 ✔
1067
  site.parent_id = p.id();
128,645 ✔
1068
  site.progeny_id = p.n_progeny();
128,645 ✔
1069
  int64_t idx = simulation::surf_source_bank.thread_safe_append(site);
128,645 ✔
1070
}
1071

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