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

openmc-dev / openmc / 28400627666

29 Jun 2026 08:29PM UTC coverage: 81.304% (+0.02%) from 81.281%
28400627666

Pull #3734

github

web-flow
Merge e517af4f6 into 4d6244d93
Pull Request #3734: Specify temperature from a field (structured mesh only)

18315 of 26537 branches covered (69.02%)

Branch coverage included in aggregate %.

285 of 318 new or added lines in 18 files covered. (89.62%)

14 existing lines in 2 files now uncovered.

59513 of 69188 relevant lines covered (86.02%)

49157606.49 hits per line

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

86.18
/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() const
2,147,483,647✔
48
{
49
  if (settings::run_CE) {
2,147,483,647✔
50
    // Determine mass in eV/c^2
51
    double mass = this->mass();
2,147,483,647✔
52

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

68
double Particle::mass() const
2,147,483,647✔
69
{
70
  switch (type().pdg_number()) {
2,147,483,647✔
71
  case PDG_NEUTRON:
72
    return MASS_NEUTRON_EV;
73
  case PDG_ELECTRON:
88,238,888✔
74
  case PDG_POSITRON:
88,238,888✔
75
    return MASS_ELECTRON_EV;
88,238,888✔
76
  default:
40,574,106✔
77
    return this->type().mass() * AMU_EV;
40,574,106✔
78
  }
79
}
80

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

94
  // Increment number of secondaries created (for ParticleProductionFilter)
95
  n_secondaries()++;
95,495,583✔
96

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

113
  local_secondary_bank().emplace_back(bank);
95,495,583✔
114
  return true;
115
}
116

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

127
  // Convert signed index to a signed surface ID
128
  if (surface() == SURFACE_NONE) {
10,327,202✔
129
    bank.surf_id = SURFACE_NONE;
10,322,318✔
130
  } else {
131
    int surf_id = model::surfaces[surface_index()]->id_;
4,884✔
132
    bank.surf_id = (surface() > 0) ? surf_id : -surf_id;
4,884✔
133
  }
134

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

143
  local_secondary_bank().emplace_back(bank);
10,327,202✔
144
}
10,327,202✔
145

146
void Particle::from_source(const SourceSite* src)
294,290,749✔
147
{
148
  // Reset some attributes
149
  clear();
294,290,749✔
150
  surface() = SURFACE_NONE;
294,290,749✔
151
  cell_born() = C_NONE;
294,290,749✔
152
  material() = C_NONE;
294,290,749✔
153
  n_collision() = 0;
294,290,749✔
154
  fission() = false;
294,290,749✔
155
  zero_flux_derivs();
294,290,749✔
156
  lifetime() = 0.0;
294,290,749✔
157
  if (settings::temperature_field_on) {
294,290,749✔
158
    tf_bin() = C_NONE;
544,577✔
159
    tf_bin_next() = C_NONE;
544,577✔
160
  }
161
#ifdef OPENMC_DAGMC_ENABLED
162
  history().reset();
26,943,360✔
163
#endif
164

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

189
  // Convert signed surface ID to signed index
190
  if (src->surf_id != SURFACE_NONE) {
294,290,749✔
191
    int index_plus_one = model::surface_map[std::abs(src->surf_id)] + 1;
114,884✔
192
    surface() = (src->surf_id > 0) ? index_plus_one : -index_plus_one;
114,884✔
193
  }
194

195
  wgt_born() = src->wgt_born;
294,290,749✔
196
  wgt_ww_born() = src->wgt_ww_born;
294,290,749✔
197
  n_split() = src->n_split;
294,290,749✔
198
}
294,290,749✔
199

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

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

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

217
  // If the cell hasn't been determined based on the particle's location,
218
  // initiate a search for the current cell. This generally happens at the
219
  // beginning of the history and again for any secondary particles
220
  if (lowest_coord().cell() == C_NONE) {
2,147,483,647✔
221

222
    // Define temperature field cell
223
    if (settings::temperature_field_on) {
285,232,046✔
224
      tf_bin() = simulation::temperature_field.get_bin(r());
544,577✔
225
    }
226

227
    if (!exhaustive_find_cell(*this)) {
285,232,046!
228
      mark_as_lost(
×
229
        "Could not find the cell containing particle " + std::to_string(id()));
×
230
      return;
×
231
    }
232

233
    // Set birth cell attribute
234
    if (cell_born() == C_NONE)
285,232,046!
235
      cell_born() = lowest_coord().cell();
285,232,046✔
236

237
    // Initialize last cells from current cell
238
    for (int j = 0; j < n_coord(); ++j) {
588,111,042✔
239
      cell_last(j) = coord(j).cell();
302,878,996✔
240
    }
241
    n_coord_last() = n_coord();
285,232,046✔
242
  }
243

244
  // Write particle track.
245
  if (write_track())
2,147,483,647✔
246
    write_particle_track(*this);
10,320✔
247

248
  if (settings::check_overlaps)
2,147,483,647!
249
    check_cell_overlap(*this);
×
250

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

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

278
void Particle::event_advance()
2,147,483,647✔
279
{
280
  // Find the distance to the nearest geometry boundary
281
  boundary() = distance_to_boundary(*this);
2,147,483,647✔
282

283
  // Sample a distance to collision
284
  if (type() == ParticleType::electron() ||
2,147,483,647✔
285
      type() == ParticleType::positron()) {
2,147,483,647✔
286
    collision_distance() = material() == MATERIAL_VOID ? INFINITY : 0.0;
176,477,776!
287
  } else if (macro_xs().total == 0.0) {
2,147,483,647✔
288
    collision_distance() = INFINITY;
111,961,468✔
289
  } else {
290
    collision_distance() = -std::log(prn(current_seed())) / macro_xs().total;
2,147,483,647✔
291
  }
292

293
  // Find the distance to the nearest temperature mesh cell surface
294
  double distance_tmesh = INFTY;
2,147,483,647✔
295
  if (settings::temperature_field_on) {
2,147,483,647✔
296
    distance_tmesh = simulation::temperature_field.distance_to_next_boundary(
11,669,832✔
297
      tf_bin(), r(), u(), tf_bin_next());
11,669,832✔
298
  }
299

300
  // Calculate the distance corresponding to the time cutoff
301
  double speed = this->speed();
2,147,483,647✔
302
  double time_cutoff = settings::time_cutoff[type().transport_index()];
2,147,483,647✔
303
  double distance_cutoff =
2,147,483,647✔
304
    (time_cutoff < INFTY) ? (time_cutoff - time()) * speed : INFTY;
2,147,483,647✔
305

306
  // Determine minimal distance for cross surface events
307
  double distance_cross_surface =
2,147,483,647✔
308
    std::min({boundary().distance(), distance_tmesh});
2,147,483,647✔
309

310
  // Determine minimal distance of all events
311
  double distance =
2,147,483,647✔
312
    std::min({distance_cross_surface, collision_distance(), distance_cutoff});
2,147,483,647✔
313

314
  // Determine next event
315
  next_event().clear();
2,147,483,647✔
316
  if (distance == distance_cutoff) {
2,147,483,647✔
317
    next_event().event_type = EVENT_TIME_CUTOFF;
224,928✔
318
  } else {
319
    if (collision_distance() > distance_cross_surface) {
2,147,483,647✔
320
      next_event().event_type = EVENT_CROSS_SURFACE;
2,147,483,647✔
321
      next_event().cross_surface_geometry =
2,147,483,647✔
322
        (std::abs(distance - boundary().distance()) <= FP_COINCIDENT);
2,147,483,647✔
323
      next_event().cross_surface_temperature_field =
2,147,483,647✔
324
        (std::abs(distance - distance_tmesh) <= FP_COINCIDENT);
2,147,483,647✔
325
    } else {
326
      next_event().event_type = EVENT_COLLIDE;
2,147,483,647✔
327
    }
328
  }
329

330
  // Advance particle in space and time
331
  this->move_distance(distance);
2,147,483,647✔
332
  double dt = distance / speed;
2,147,483,647✔
333
  this->time() += dt;
2,147,483,647✔
334
  this->lifetime() += dt;
2,147,483,647✔
335

336
  // Score timed track-length tallies
337
  if (!model::active_timed_tracklength_tallies.empty()) {
2,147,483,647✔
338
    score_timed_tracklength_tally(*this, distance);
3,628,317✔
339
  }
340

341
  // Score track-length tallies
342
  if (!model::active_tracklength_tallies.empty()) {
2,147,483,647✔
343
    score_tracklength_tally(*this, distance);
2,147,483,647✔
344
  }
345

346
  // Score track-length estimate of k-eff
347
  if (settings::run_mode == RunMode::EIGENVALUE && type().is_neutron()) {
2,147,483,647✔
348
    keff_tally_tracklength() += wgt() * distance * macro_xs().nu_fission;
2,147,483,647✔
349
  }
350

351
  // Score flux derivative accumulators for differential tallies.
352
  if (!model::active_tallies.empty()) {
2,147,483,647✔
353
    score_track_derivative(*this, distance);
2,147,483,647✔
354
  }
355
}
2,147,483,647✔
356

357
void Particle::event_cross_surface()
2,147,483,647✔
358
{
359
  if (next_event().cross_surface_geometry) {
2,147,483,647✔
360

361
    // Saving previous cell data
362
    for (int j = 0; j < n_coord(); ++j) {
2,147,483,647✔
363
      cell_last(j) = coord(j).cell();
2,147,483,647✔
364
    }
365
    n_coord_last() = n_coord();
2,147,483,647✔
366

367
    // Set surface that particle is on and adjust coordinate levels
368
    surface() = boundary().surface();
2,147,483,647✔
369
    n_coord() = boundary().coord_level();
2,147,483,647✔
370

371
    if (boundary().lattice_translation()[0] != 0 ||
2,147,483,647✔
372
        boundary().lattice_translation()[1] != 0 ||
2,147,483,647✔
373
        boundary().lattice_translation()[2] != 0) {
2,147,483,647✔
374
      // Particle crosses lattice boundary
375

376
      // Update temperature field bin
377
      if (settings::temperature_field_on) {
803,167,678✔
378
        if (next_event().cross_surface_temperature_field) {
1,901,988✔
379
          tf_bin() = tf_bin_next();
748,792✔
380
        }
381
      }
382

383
      bool verbose = settings::verbosity >= 10 || trace();
803,167,678!
384
      cross_lattice(*this, boundary(), verbose);
803,167,678✔
385
      event() = TallyEvent::LATTICE;
803,167,678✔
386

387
      // Score cell to cell partial currents
388
      if (!model::active_surface_tallies.empty()) {
803,167,678!
NEW
389
        auto& lat {*model::lattices[lowest_coord().lattice()]};
×
NEW
390
        bool is_valid;
×
NEW
391
        Direction normal =
×
NEW
392
          lat.get_normal(boundary().lattice_translation(), is_valid);
×
NEW
393
        if (is_valid) {
×
NEW
394
          normal /= normal.norm();
×
NEW
395
          score_surface_tally(*this, model::active_surface_tallies, normal);
×
396
        }
397
      }
398

399
    } else {
400

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

403
      // Particle crosses surface
404
      // If BC, add particle to surface source before crossing surface
405
      if (surf.surf_source_ && surf.bc_) {
2,147,483,647✔
406
        add_surf_source_to_bank(*this, surf);
1,010,316,681✔
407
      }
408
      this->cross_surface(surf);
2,147,483,647✔
409
      // If no BC, add particle to surface source after crossing surface
410
      if (surf.surf_source_ && !surf.bc_) {
2,147,483,647✔
411
        add_surf_source_to_bank(*this, surf);
1,852,237,553✔
412
      }
413
      if (settings::weight_window_checkpoint_surface) {
2,147,483,647✔
414
        apply_weight_windows(*this);
170,718✔
415
      }
416
      event() = TallyEvent::SURFACE;
2,147,483,647✔
417

418
      // Score cell to cell partial currents
419
      if (!model::active_surface_tallies.empty()) {
2,147,483,647✔
420
        Direction normal = surf.normal(r());
34,931,567✔
421
        normal /= normal.norm();
34,931,567✔
422
        score_surface_tally(*this, model::active_surface_tallies, normal);
34,931,567✔
423
      }
424
    }
425

426
    // Update particle temperature from the temperature field
427
  } else if (next_event().cross_surface_temperature_field) {
723,867!
428

429
    sqrtkT_last() = sqrtkT();
723,867✔
430

431
    tf_bin() = tf_bin_next();
723,867✔
432

433
    if (tf_bin() != C_NONE) {
723,867!
434
      sqrtkT() = simulation::temperature_field.get_sqrtkT(tf_bin());
723,867✔
435
    } else {
NEW
436
      int i_cell = lowest_coord().cell();
×
NEW
437
      Cell& c {*model::cells[i_cell]};
×
NEW
438
      sqrtkT() = c.sqrtkT(cell_instance());
×
439
    }
440

441
#ifdef OPENMC_DAGMC_ENABLED
442
    history().reset();
96,447✔
443
#endif
444
  }
445
}
2,147,483,647✔
446

447
void Particle::event_collide()
2,147,483,647✔
448
{
449

450
  // Score collision estimate of keff
451
  if (settings::run_mode == RunMode::EIGENVALUE && type().is_neutron()) {
2,147,483,647✔
452
    keff_tally_collision() += wgt() * macro_xs().nu_fission / macro_xs().total;
2,147,483,647✔
453
  }
454

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

459
  if (!model::active_meshsurf_tallies.empty())
2,147,483,647✔
460
    score_meshsurface_tally(*this, model::active_meshsurf_tallies);
63,098,926✔
461

462
  // Clear surface component
463
  surface() = SURFACE_NONE;
2,147,483,647✔
464

465
  if (settings::run_CE) {
2,147,483,647✔
466
    collision(*this);
1,468,342,670✔
467
  } else {
468
    collision_mg(*this);
1,801,144,774✔
469
  }
470

471
  // Collision track feature to recording particle interaction
472
  if (settings::collision_track) {
2,147,483,647✔
473
    collision_track_record(*this);
728,673✔
474
  }
475

476
  // Score collision estimator tallies -- this is done after a collision
477
  // has occurred rather than before because we need information on the
478
  // outgoing energy for any tallies with an outgoing energy filter
479
  if (!model::active_collision_tallies.empty())
2,147,483,647✔
480
    score_collision_tally(*this);
108,987,466✔
481
  if (!model::active_analog_tallies.empty()) {
2,147,483,647✔
482
    if (settings::run_CE) {
406,229,898✔
483
      score_analog_tally_ce(*this);
405,021,636✔
484
    } else {
485
      score_analog_tally_mg(*this);
1,208,262✔
486
    }
487
  }
488

489
  if (!model::active_pulse_height_tallies.empty() && type().is_photon()) {
2,147,483,647✔
490
    pht_collision_energy();
8,668✔
491
  }
492

493
  // Reset banked weight during collision
494
  n_bank() = 0;
2,147,483,647✔
495
  bank_second_E() = 0.0;
2,147,483,647✔
496
  wgt_bank() = 0.0;
2,147,483,647✔
497

498
  // Clear number of secondaries in this collision. This is
499
  // distinct from the number of created neutrons n_bank() above!
500
  n_secondaries() = 0;
2,147,483,647✔
501

502
  zero_delayed_bank();
2,147,483,647✔
503

504
  // Reset fission logical
505
  fission() = false;
2,147,483,647✔
506

507
  // Save coordinates for tallying purposes
508
  r_last_current() = r();
2,147,483,647✔
509

510
  // Set last material to none since cross sections will need to be
511
  // re-evaluated
512
  material_last() = C_NONE;
2,147,483,647✔
513

514
  // Set all directions to base level -- right now, after a collision, only
515
  // the base level directions are changed
516
  for (int j = 0; j < n_coord() - 1; ++j) {
2,147,483,647✔
517
    if (coord(j + 1).rotated()) {
289,429,325✔
518
      // If next level is rotated, apply rotation matrix
519
      const auto& m {model::cells[coord(j).cell()]->rotation_};
11,724,229✔
520
      const auto& u {coord(j).u()};
11,724,229✔
521
      coord(j + 1).u() = u.rotate(m);
11,724,229✔
522
    } else {
523
      // Otherwise, copy this level's direction
524
      coord(j + 1).u() = coord(j).u();
277,705,096✔
525
    }
526
  }
527

528
  // Score flux derivative accumulators for differential tallies.
529
  if (!model::active_tallies.empty())
2,147,483,647✔
530
    score_collision_derivative(*this);
1,308,094,471✔
531

532
#ifdef OPENMC_DAGMC_ENABLED
533
  history().reset();
299,663,221✔
534
#endif
535
}
2,147,483,647✔
536

537
void Particle::event_revive_from_secondary(const SourceSite& site)
106,836,982✔
538
{
539
  // Write final position for the previous track (skip if this is a freshly
540
  // constructed particle with no prior track, e.g., Phase 2 of shared
541
  // secondary transport)
542
  if (write_track() && n_event() > 0) {
106,836,982!
543
    write_particle_track(*this);
5,234✔
544
  }
545

546
  from_source(&site);
106,836,982✔
547

548
  n_event() = 0;
106,836,982✔
549
  if (!settings::use_shared_secondary_bank) {
106,836,982✔
550
    n_tracks()++;
85,496,421✔
551
  }
552
  bank_second_E() = 0.0;
106,836,982✔
553

554
  // Subtract secondary particle energy from interim pulse-height results.
555
  // In shared secondary mode, this subtraction was already done on the parent
556
  // particle during create_secondary(), so skip it here.
557
  if (!settings::use_shared_secondary_bank &&
192,333,403✔
558
      !model::active_pulse_height_tallies.empty() && this->type().is_photon()) {
106,836,982✔
559
    // Since the birth cell of the particle has not been set we
560
    // have to determine it before the energy of the secondary particle can be
561
    // removed from the pulse-height of this cell.
562
    if (lowest_coord().cell() == C_NONE) {
3,168!
563
      bool verbose = settings::verbosity >= 10 || trace();
3,168!
564

565
      // Define temperature field cell
566
      if (settings::temperature_field_on) {
3,168!
NEW
567
        tf_bin() = simulation::temperature_field.get_bin(r());
×
568
      }
569

570
      if (!exhaustive_find_cell(*this, verbose)) {
3,168!
571
        mark_as_lost("Could not find the cell containing particle " +
×
572
                     std::to_string(id()));
×
573
        return;
×
574
      }
575
      // Set birth cell attribute
576
      if (cell_born() == C_NONE)
3,168!
577
        cell_born() = lowest_coord().cell();
3,168✔
578

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

588
  // Enter new particle in particle track file
589
  if (write_track())
106,836,982✔
590
    add_particle_track(*this);
5,234✔
591
}
592

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

603
  // In non-shared-secondary mode, revive from local secondary bank
604
  if (!alive() && !settings::use_shared_secondary_bank &&
2,147,483,647✔
605
      !local_secondary_bank().empty()) {
263,109,148✔
606
    SourceSite& site = local_secondary_bank().back();
85,496,421✔
607
    event_revive_from_secondary(site);
85,496,421✔
608
    local_secondary_bank().pop_back();
85,496,421✔
609
  }
610
}
2,147,483,647✔
611

612
void Particle::event_death()
199,738,784✔
613
{
614
#ifdef OPENMC_DAGMC_ENABLED
615
  history().reset();
18,266,344✔
616
#endif
617

618
  // Finish particle track output.
619
  if (write_track()) {
199,738,784✔
620
    write_particle_track(*this);
1,010✔
621
    finalize_particle_track(*this);
1,010✔
622
  }
623

624
// Contribute tally reduction variables to global accumulator
625
#pragma omp atomic
109,743,617✔
626
  global_tally_absorption += keff_tally_absorption();
199,738,784✔
627
#pragma omp atomic
109,906,755✔
628
  global_tally_collision += keff_tally_collision();
199,738,784✔
629
#pragma omp atomic
109,673,705✔
630
  global_tally_tracklength += keff_tally_tracklength();
199,738,784✔
631
#pragma omp atomic
109,219,155✔
632
  global_tally_leakage += keff_tally_leakage();
199,738,784✔
633

634
  // Reset particle tallies once accumulated
635
  keff_tally_absorption() = 0.0;
199,738,784✔
636
  keff_tally_collision() = 0.0;
199,738,784✔
637
  keff_tally_tracklength() = 0.0;
199,738,784✔
638
  keff_tally_leakage() = 0.0;
199,738,784✔
639

640
  if (!model::active_pulse_height_tallies.empty()) {
199,738,784✔
641
    score_pulse_height_tally(*this, model::active_pulse_height_tallies);
33,000✔
642
  }
643

644
  // Accumulate track count for this particle history
645
  if (!settings::use_shared_secondary_bank) {
199,738,784✔
646
#pragma omp atomic
96,968,062✔
647
    simulation::simulation_tracks_completed += n_tracks();
177,613,727✔
648
  }
649

650
  // Record the number of progeny created by this particle.
651
  // This data will be used to efficiently sort the fission bank.
652
  if (settings::run_mode == RunMode::EIGENVALUE ||
199,738,784✔
653
      settings::use_shared_secondary_bank) {
654
    simulation::progeny_per_particle[current_work()] = n_progeny();
172,573,057✔
655
  }
656
}
199,738,784✔
657

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

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

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

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

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

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

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

693
void Particle::cross_surface(const Surface& surf)
2,147,483,647✔
694
{
695

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

700
// if we're crossing a CSG surface, make sure the DAG history is reset
701
#ifdef OPENMC_DAGMC_ENABLED
702
  if (surf.geom_type() == GeometryType::CSG)
261,364,418✔
703
    history().reset();
261,258,567✔
704
#endif
705

706
  // Handle any applicable boundary conditions.
707
  if (surf.bc_ && settings::run_mode != RunMode::PLOTTING &&
2,147,483,647!
708
      settings::run_mode != RunMode::VOLUME) {
709
    surf.bc_->handle_particle(*this, surf);
1,010,668,789✔
710
    return;
1,010,668,789✔
711
  }
712

713
  // Update temperature field bin after handling boundary conditions
714
  if (settings::temperature_field_on) {
1,855,001,553✔
715
    if (next_event().cross_surface_temperature_field) {
512,344✔
716
      tf_bin() = tf_bin_next();
67,207✔
717
    }
718
  }
719

720
  // ==========================================================================
721
  // SEARCH NEIGHBOR LISTS FOR NEXT CELL
722

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

737
    cell_instance() = 0;
50,369✔
738
    if (cell->distribcell_index_ >= 0)
50,369✔
739
      cell_instance() = cell_instance_at_level(*this, n_coord() - 1);
49,345✔
740

741
    material() = cell->material(cell_instance());
50,369!
742
    if (settings::temperature_field_on && tf_bin() != C_NONE) {
50,369✔
743
      sqrtkT() = simulation::temperature_field.get_sqrtkT(tf_bin());
1,693✔
744
    } else {
745
      sqrtkT() = cell->sqrtkT(cell_instance());
97,352!
746
    }
747
    density_mult() = cell->density_mult(cell_instance());
50,369✔
748
    return;
50,369✔
749
  }
750
#endif
751

752
  bool verbose = settings::verbosity >= 10 || trace();
1,854,951,184!
753
  if (neighbor_list_find_cell(*this, verbose)) {
1,854,951,184✔
754
    return;
755
  }
756

757
  // ==========================================================================
758
  // COULDN'T FIND PARTICLE IN NEIGHBORING CELLS, SEARCH ALL CELLS
759

760
  // Remove lower coordinate levels
761
  n_coord() = 1;
29,977✔
762
  bool found = exhaustive_find_cell(*this, verbose);
29,977✔
763

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

770
    surface() = SURFACE_NONE;
5,865✔
771
    n_coord() = 1;
5,865✔
772
    r() += TINY_BIT * u();
5,865✔
773

774
    // Couldn't find next cell anywhere! This probably means there is an actual
775
    // undefined region in the geometry.
776

777
    if (!exhaustive_find_cell(*this, verbose)) {
5,865!
778
      mark_as_lost("After particle " + std::to_string(id()) +
17,586✔
779
                   " crossed surface " + std::to_string(surf.id_) +
17,586✔
780
                   " it could not be located in any cell and it did not leak.");
781
      return;
5,856✔
782
    }
783
  }
784
}
785

786
void Particle::cross_vacuum_bc(const Surface& surf)
37,405,405✔
787
{
788
  // Score any surface current tallies -- note that the particle is moved
789
  // forward slightly so that if the mesh boundary is on the surface, it is
790
  // still processed
791

792
  if (!model::active_meshsurf_tallies.empty()) {
37,405,405✔
793
    // TODO: Find a better solution to score surface currents than
794
    // physically moving the particle forward slightly
795

796
    r() += TINY_BIT * u();
937,222✔
797
    score_meshsurface_tally(*this, model::active_meshsurf_tallies);
937,222✔
798
  }
799

800
  // Score to global leakage tally
801
  keff_tally_leakage() += wgt();
37,405,405✔
802

803
  // Kill the particle
804
  wgt() = 0.0;
37,405,405✔
805

806
  // Display message
807
  if (settings::verbosity >= 10 || trace()) {
37,405,405!
808
    write_message(1, "    Leaked out of surface {}", surf.id_);
22✔
809
  }
810
}
37,405,405✔
811

812
void Particle::cross_reflective_bc(const Surface& surf, Direction new_u)
971,200,674✔
813
{
814
  // Do not handle reflective boundary conditions on lower universes
815
  if (n_coord() != 1) {
971,200,674!
816
    mark_as_lost("Cannot reflect particle " + std::to_string(id()) +
×
817
                 " off surface in a lower universe.");
818
    return;
×
819
  }
820

821
  // Score surface currents since reflection causes the direction of the
822
  // particle to change. For surface filters, we need to score the tallies
823
  // twice, once before the particle's surface attribute has changed and
824
  // once after. For mesh surface filters, we need to artificially move
825
  // the particle slightly back in case the surface crossing is coincident
826
  // with a mesh boundary
827

828
  if (!model::active_surface_tallies.empty()) {
971,200,674✔
829
    Direction normal = surf.normal(r());
285,021✔
830
    normal /= normal.norm();
285,021✔
831
    score_surface_tally(*this, model::active_surface_tallies, normal);
285,021✔
832
  }
833

834
  if (!model::active_meshsurf_tallies.empty()) {
971,200,674✔
835
    Position r {this->r()};
46,885,487✔
836
    this->r() -= TINY_BIT * u();
46,885,487✔
837
    score_meshsurface_tally(*this, model::active_meshsurf_tallies);
46,885,487✔
838
    this->r() = r;
46,885,487✔
839
  }
840

841
  // Set the new particle direction
842
  u() = new_u;
971,200,674✔
843

844
  // Reassign particle's cell and surface
845
  coord(0).cell() = cell_last(0);
971,200,674✔
846
  surface() = -surface();
971,200,674✔
847

848
  // Particle's temperature field bin is unchanged
849

850
  // If a reflective surface is coincident with a lattice or universe
851
  // boundary, it is necessary to redetermine the particle's coordinates in
852
  // the lower universes.
853
  // (unless we're using a dagmc model, which has exactly one universe)
854
  n_coord() = 1;
971,200,674✔
855
  if (surf.geom_type() != GeometryType::DAG &&
1,942,361,027!
856
      !neighbor_list_find_cell(*this)) {
971,160,353✔
857
    mark_as_lost("Couldn't find particle after reflecting from surface " +
×
858
                 std::to_string(surf.id_) + ".");
×
859
    return;
×
860
  }
861

862
  // Set previous coordinate going slightly past surface crossing
863
  r_last_current() = r() + TINY_BIT * u();
971,200,674✔
864

865
  // Diagnostic message
866
  if (settings::verbosity >= 10 || trace()) {
971,200,674!
867
    write_message(1, "    Reflected from surface {}", surf.id_);
×
868
  }
869
}
870

871
void Particle::cross_periodic_bc(
3,068,176✔
872
  const Surface& surf, Position new_r, Direction new_u, int new_surface)
873
{
874
  // Do not handle periodic boundary conditions on lower universes
875
  if (n_coord() != 1) {
3,068,176!
876
    mark_as_lost(
×
877
      "Cannot transfer particle " + std::to_string(id()) +
×
878
      " across surface in a lower universe. Boundary conditions must be "
879
      "applied to root universe.");
880
    return;
×
881
  }
882

883
  // Score surface currents since reflection causes the direction of the
884
  // particle to change -- artificially move the particle slightly back in
885
  // case the surface crossing is coincident with a mesh boundary
886
  if (!model::active_meshsurf_tallies.empty()) {
3,068,176!
887
    Position r {this->r()};
×
888
    this->r() -= TINY_BIT * u();
×
889
    score_meshsurface_tally(*this, model::active_meshsurf_tallies);
×
890
    this->r() = r;
×
891
  }
892

893
  // Adjust the particle's location and direction.
894
  r() = new_r;
3,068,176✔
895
  u() = new_u;
3,068,176✔
896

897
  // Reassign particle's surface
898
  surface() = new_surface;
3,068,176✔
899

900
  // Reassign particle's temperature field bin
901
  if (settings::temperature_field_on) {
3,068,176✔
902
    tf_bin() = simulation::temperature_field.get_bin(r());
821,502✔
903
  }
904

905
  // Figure out what cell particle is in now
906
  n_coord() = 1;
3,068,176✔
907

908
  if (!neighbor_list_find_cell(*this)) {
3,068,176!
909
    mark_as_lost("Couldn't find particle after hitting periodic "
×
910
                 "boundary on surface " +
×
911
                 std::to_string(surf.id_) + ".");
×
912
    return;
×
913
  }
914

915
  // Set previous coordinate going slightly past surface crossing
916
  r_last_current() = r() + TINY_BIT * u();
3,068,176✔
917

918
  // Diagnostic message
919
  if (settings::verbosity >= 10 || trace()) {
3,068,176!
920
    write_message(1, "    Hit periodic boundary on surface {}", surf.id_);
×
921
  }
922
}
923

924
void Particle::mark_as_lost(const char* message)
5,865✔
925
{
926
  // Print warning and write lost particle file
927
  warning(message);
5,865✔
928
  if (settings::max_write_lost_particles < 0 ||
5,865✔
929
      simulation::n_lost_particles < settings::max_write_lost_particles) {
5,500✔
930
    write_restart();
440✔
931
  }
932
  // Increment number of lost particles
933
  wgt() = 0.0;
5,865✔
934
#pragma omp atomic
3,190✔
935
  simulation::n_lost_particles += 1;
2,675✔
936

937
  // Count the total number of simulated particles (on this processor)
938
  auto n = simulation::current_batch * settings::gen_per_batch *
5,865✔
939
           simulation::work_per_rank;
940

941
  // Abort the simulation if the maximum number of lost particles has been
942
  // reached
943
  if (simulation::n_lost_particles >= settings::max_lost_particles &&
5,865✔
944
      simulation::n_lost_particles >= settings::rel_max_lost_particles * n) {
9!
945
    fatal_error("Maximum number of lost particles has been reached.");
9✔
946
  }
947
}
5,856✔
948

949
void Particle::write_restart() const
440✔
950
{
951
  // Dont write another restart file if in particle restart mode
952
  if (settings::run_mode == RunMode::PARTICLE)
440✔
953
    return;
33✔
954

955
  // Set up file name
956
  auto filename = fmt::format("{}particle_{}_{}.h5", settings::path_output,
407✔
957
    simulation::current_batch, id());
407✔
958

959
#pragma omp critical(WriteParticleRestart)
217✔
960
  {
407✔
961
    // Create file
962
    hid_t file_id = file_open(filename, 'w');
407✔
963

964
    // Write filetype and version info
965
    write_attribute(file_id, "filetype", "particle restart");
407✔
966
    write_attribute(file_id, "version", VERSION_PARTICLE_RESTART);
407✔
967
    write_attribute(file_id, "openmc_version", VERSION);
407✔
968
#ifdef GIT_SHA1
969
    write_attr_string(file_id, "git_sha1", GIT_SHA1);
970
#endif
971

972
    // Write data to file
973
    write_dataset(file_id, "current_batch", simulation::current_batch);
407✔
974
    write_dataset(file_id, "generations_per_batch", settings::gen_per_batch);
407✔
975
    write_dataset(file_id, "current_generation", simulation::current_gen);
407✔
976
    write_dataset(file_id, "n_particles", settings::n_particles);
407✔
977
    switch (settings::run_mode) {
407!
978
    case RunMode::FIXED_SOURCE:
275✔
979
      write_dataset(file_id, "run_mode", "fixed source");
275✔
980
      break;
145✔
981
    case RunMode::EIGENVALUE:
132✔
982
      write_dataset(file_id, "run_mode", "eigenvalue");
132✔
983
      break;
72✔
984
    case RunMode::PARTICLE:
×
985
      write_dataset(file_id, "run_mode", "particle restart");
×
986
      break;
987
    default:
988
      break;
989
    }
990
    write_dataset(file_id, "id", id());
407✔
991
    write_dataset(file_id, "type", type().pdg_number());
407✔
992

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

1015
    // Close file
1016
    file_close(file_id);
407✔
1017
  } // #pragma omp critical
1018
}
407✔
1019

1020
void Particle::update_neutron_xs(
2,147,483,647✔
1021
  int i_nuclide, int i_grid, int i_sab, double sab_frac, double ncrystal_xs)
1022
{
1023
  // Get microscopic cross section cache
1024
  auto& micro = this->neutron_xs(i_nuclide);
2,147,483,647✔
1025

1026
  // If the cache doesn't match, recalculate micro xs
1027
  if (this->E() != micro.last_E || this->sqrtkT() != micro.last_sqrtkT ||
2,147,483,647✔
1028
      i_sab != micro.index_sab || sab_frac != micro.sab_frac ||
2,147,483,647✔
1029
      ncrystal_xs != micro.ncrystal_xs) {
2,147,483,647!
1030
    data::nuclides[i_nuclide]->calculate_xs(i_sab, i_grid, sab_frac, *this);
2,147,483,647✔
1031

1032
    // If NCrystal is being used, update micro cross section cache
1033
    micro.ncrystal_xs = ncrystal_xs;
2,147,483,647✔
1034
    if (ncrystal_xs >= 0.0) {
2,147,483,647✔
1035
      data::nuclides[i_nuclide]->calculate_elastic_xs(*this);
11,018,953✔
1036
      ncrystal_update_micro(ncrystal_xs, micro);
11,018,953✔
1037
    }
1038
  }
1039
}
2,147,483,647✔
1040

1041
//==============================================================================
1042
// Non-method functions
1043
//==============================================================================
1044
void add_surf_source_to_bank(Particle& p, const Surface& surf)
2,147,483,647✔
1045
{
1046
  if (simulation::current_batch <= settings::n_inactive ||
2,147,483,647✔
1047
      simulation::surf_source_bank.full()) {
2,147,483,647✔
1048
    return;
2,147,483,647✔
1049
  }
1050

1051
  // If a cell/cellfrom/cellto parameter is defined
1052
  if (settings::ssw_cell_id != C_NONE) {
337,076✔
1053

1054
    // Retrieve cell index and storage type
1055
    int cell_idx = model::cell_map[settings::ssw_cell_id];
254,431✔
1056

1057
    if (surf.bc_) {
254,431✔
1058
      // Leave if cellto with vacuum boundary condition
1059
      if (surf.bc_->type() == "vacuum" &&
298,916✔
1060
          settings::ssw_cell_type == SSWCellType::To) {
33,098✔
1061
        return;
1062
      }
1063

1064
      // Leave if other boundary condition than vacuum
1065
      if (surf.bc_->type() != "vacuum") {
274,646✔
1066
        return;
1067
      }
1068
    }
1069

1070
    // Check if the cell of interest has been exited
1071
    bool exited = false;
1072
    for (int i = 0; i < p.n_coord_last(); ++i) {
333,661✔
1073
      if (p.cell_last(i) == cell_idx) {
207,725✔
1074
        exited = true;
73,764✔
1075
      }
1076
    }
1077

1078
    // Check if the cell of interest has been entered
1079
    bool entered = false;
1080
    for (int i = 0; i < p.n_coord(); ++i) {
297,963✔
1081
      if (p.coord(i).cell() == cell_idx) {
172,027✔
1082
        entered = true;
57,514✔
1083
      }
1084
    }
1085

1086
    // Vacuum boundary conditions: return if cell is not exited
1087
    if (surf.bc_) {
125,936✔
1088
      if (surf.bc_->type() == "vacuum" && !exited) {
41,926!
1089
        return;
1090
      }
1091
    } else {
1092

1093
      // If we both enter and exit the cell of interest
1094
      if (entered && exited) {
104,973✔
1095
        return;
1096
      }
1097

1098
      // If we did not enter nor exit the cell of interest
1099
      if (!entered && !exited) {
77,770✔
1100
        return;
1101
      }
1102

1103
      // If cellfrom and the cell before crossing is not the cell of
1104
      // interest
1105
      if (settings::ssw_cell_type == SSWCellType::From && !exited) {
64,272✔
1106
        return;
1107
      }
1108

1109
      // If cellto and the cell after crossing is not the cell of interest
1110
      if (settings::ssw_cell_type == SSWCellType::To && !entered) {
52,732✔
1111
        return;
1112
      }
1113
    }
1114
  }
1115

1116
  SourceSite site;
129,653✔
1117
  site.r = p.r();
129,653✔
1118
  site.u = p.u();
129,653✔
1119
  site.E = p.E();
129,653✔
1120
  site.time = p.time();
129,653✔
1121
  site.wgt = p.wgt();
129,653✔
1122
  site.delayed_group = p.delayed_group();
129,653✔
1123
  site.surf_id = surf.id_;
129,653✔
1124
  site.particle = p.type();
129,653✔
1125
  site.parent_id = p.id();
129,653✔
1126
  site.progeny_id = p.n_progeny();
129,653✔
1127
  int64_t idx = simulation::surf_source_bank.thread_safe_append(site);
129,653✔
1128
}
1129

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