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

openmc-dev / openmc / 28808529044

06 Jul 2026 04:55PM UTC coverage: 81.286% (+0.005%) from 81.281%
28808529044

Pull #3969

github

web-flow
Merge 57b10d8a3 into 3fcb9692b
Pull Request #3969: Overlap detection for plotter

18195 of 26406 branches covered (68.9%)

Branch coverage included in aggregate %.

64 of 67 new or added lines in 5 files covered. (95.52%)

384 existing lines in 15 files now uncovered.

59364 of 69009 relevant lines covered (86.02%)

48649031.09 hits per line

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

95.76
/src/simulation.cpp
1
#include "openmc/simulation.h"
2

3
#include "openmc/bank.h"
4
#include "openmc/capi.h"
5
#include "openmc/collision_track.h"
6
#include "openmc/container_util.h"
7
#include "openmc/eigenvalue.h"
8
#include "openmc/error.h"
9
#include "openmc/event.h"
10
#include "openmc/geometry_aux.h"
11
#include "openmc/ifp.h"
12
#include "openmc/material.h"
13
#include "openmc/message_passing.h"
14
#include "openmc/nuclide.h"
15
#include "openmc/output.h"
16
#include "openmc/particle.h"
17
#include "openmc/photon.h"
18
#include "openmc/random_lcg.h"
19
#include "openmc/random_ray/flat_source_domain.h"
20
#include "openmc/settings.h"
21
#include "openmc/source.h"
22
#include "openmc/state_point.h"
23
#include "openmc/tallies/derivative.h"
24
#include "openmc/tallies/filter.h"
25
#include "openmc/tallies/tally.h"
26
#include "openmc/tallies/trigger.h"
27
#include "openmc/timer.h"
28
#include "openmc/track_output.h"
29
#include "openmc/weight_windows.h"
30

31
#ifdef _OPENMP
32
#include <omp.h>
33
#endif
34
#include "openmc/tensor.h"
35

36
#ifdef OPENMC_MPI
37
#include <mpi.h>
38
#endif
39

40
#include <fmt/format.h>
41

42
#include <algorithm>
43
#include <cmath>
44
#include <string>
45

46
//==============================================================================
47
// C API functions
48
//==============================================================================
49

50
// OPENMC_RUN encompasses all the main logic where iterations are performed
51
// over the batches, generations, and histories in a fixed source or
52
// k-eigenvalue calculation.
53

54
int openmc_run()
6,690✔
55
{
56
  openmc::simulation::time_total.start();
6,690✔
57
  openmc_simulation_init();
6,690✔
58

59
  // Ensure that a batch isn't executed in the case that the maximum number of
60
  // batches has already been run in a restart statepoint file
61
  int status = 0;
6,690✔
62
  if (openmc::simulation::current_batch >= openmc::settings::n_max_batches) {
6,690✔
63
    status = openmc::STATUS_EXIT_MAX_BATCH;
11✔
64
  }
65

66
  int err = 0;
67
  while (status == 0 && err == 0) {
147,930✔
68
    err = openmc_next_batch(&status);
141,253✔
69
  }
70

71
  openmc_simulation_finalize();
6,677✔
72
  openmc::simulation::time_total.stop();
6,677✔
73
  return err;
6,677✔
74
}
75

76
int openmc_simulation_init()
7,862✔
77
{
78
  using namespace openmc;
7,862✔
79

80
  // Skip if simulation has already been initialized
81
  if (simulation::initialized)
7,862✔
82
    return 0;
83

84
  // Initialize nuclear data (energy limits, log grid)
85
  if (settings::run_CE) {
7,840✔
86
    initialize_data();
6,429✔
87
  }
88

89
  // Determine how much work each process should do
90
  calculate_work(settings::n_particles);
7,840✔
91

92
  // Allocate source, fission and surface source banks.
93
  allocate_banks();
7,840✔
94

95
  // Create track file if needed
96
  if (!settings::track_identifiers.empty() || settings::write_all_tracks) {
7,840✔
97
    open_track_file();
90✔
98
  }
99

100
  // If doing an event-based simulation, intialize the particle buffer
101
  // and event queues
102
  if (settings::event_based) {
7,840✔
103
    int64_t event_buffer_length =
222!
104
      std::min(simulation::work_per_rank, settings::max_particles_in_flight);
222✔
105
    init_event_queues(event_buffer_length);
222✔
106
  }
107

108
  // Allocate tally results arrays if they're not allocated yet
109
  for (auto& t : model::tallies) {
35,421✔
110
    t->set_strides();
27,581✔
111
    t->init_results();
27,581✔
112
  }
113

114
  // Set up material nuclide index mapping
115
  for (auto& mat : model::materials) {
27,605✔
116
    mat->init_nuclide_index();
19,765✔
117
  }
118

119
  // Reset global variables -- this is done before loading state point (as that
120
  // will potentially populate k_generation and entropy)
121
  simulation::current_batch = 0;
7,840✔
122
  simulation::ct_current_file = 1;
7,840✔
123
  simulation::ssw_current_file = 1;
7,840✔
124
  simulation::k_generation.clear();
7,840✔
125
  simulation::entropy.clear();
7,840✔
126
  reset_source_rejection_counters();
7,840✔
127
  openmc_reset();
7,840✔
128

129
  // If this is a restart run, load the state point data and binary source
130
  // file
131
  if (settings::restart_run) {
7,840✔
132
    load_state_point();
63✔
133
    write_message("Resuming simulation...", 6);
126✔
134
  } else {
135
    // Only initialize primary source bank for eigenvalue simulations
136
    if (settings::run_mode == RunMode::EIGENVALUE &&
7,777✔
137
        settings::solver_type == SolverType::MONTE_CARLO) {
4,418✔
138
      initialize_source();
4,047✔
139
    }
140
  }
141

142
  // Display header
143
  if (mpi::master) {
7,840✔
144
    if (settings::run_mode == RunMode::FIXED_SOURCE) {
6,828✔
145
      if (settings::solver_type == SolverType::MONTE_CARLO) {
3,041✔
146
        header("FIXED SOURCE TRANSPORT SIMULATION", 3);
2,665✔
147
      } else if (settings::solver_type == SolverType::RANDOM_RAY) {
376!
148
        header("FIXED SOURCE TRANSPORT SIMULATION (RANDOM RAY SOLVER)", 3);
376✔
149
      }
150
    } else if (settings::run_mode == RunMode::EIGENVALUE) {
3,787!
151
      if (settings::solver_type == SolverType::MONTE_CARLO) {
3,787✔
152
        header("K EIGENVALUE SIMULATION", 3);
3,512✔
153
      } else if (settings::solver_type == SolverType::RANDOM_RAY) {
275!
154
        header("K EIGENVALUE SIMULATION (RANDOM RAY SOLVER)", 3);
275✔
155
      }
156
      if (settings::verbosity >= 7)
3,787✔
157
        print_columns();
3,407✔
158
    }
159
  }
160

161
  // load weight windows from file
162
  if (!settings::weight_windows_file.empty()) {
7,840!
UNCOV
163
    openmc_weight_windows_import(settings::weight_windows_file.c_str());
×
164
  }
165

166
  // Set flag indicating initialization is done
167
  simulation::initialized = true;
7,840✔
168
  return 0;
7,840✔
169
}
170

171
int openmc_simulation_finalize()
7,827✔
172
{
173
  using namespace openmc;
7,827✔
174

175
  // Skip if simulation was never run
176
  if (!simulation::initialized)
7,827!
177
    return 0;
178

179
  // Stop active batch timer and start finalization timer
180
  simulation::time_active.stop();
7,827✔
181
  simulation::time_finalize.start();
7,827✔
182

183
  // Clear material nuclide mapping
184
  for (auto& mat : model::materials) {
27,579✔
185
    mat->mat_nuclide_index_.clear();
39,504!
186
  }
187

188
  // Close track file if open
189
  if (!settings::track_identifiers.empty() || settings::write_all_tracks) {
7,827✔
190
    close_track_file();
90✔
191
  }
192

193
  // Increment total number of generations
194
  simulation::total_gen += simulation::current_batch * settings::gen_per_batch;
7,827✔
195

196
#ifdef OPENMC_MPI
197
  broadcast_results();
3,510✔
198
#endif
199

200
  // Write tally results to tallies.out
201
  if (settings::output_tallies && mpi::master)
7,827!
202
    write_tallies();
6,469✔
203

204
  // If weight window generators are present in this simulation, write a
205
  // weight windows file. This is skipped during the forward solve of an
206
  // adjoint (FW-CADIS) run, where only the adjoint-derived weight windows
207
  // are meaningful.
208
  if (variance_reduction::weight_windows_generators.size() > 0 &&
7,827✔
209
      FlatSourceDomain::solve_ != RandomRaySolve::FORWARD_FOR_ADJOINT) {
166✔
210
    openmc_weight_windows_export();
105✔
211
  }
212

213
  // Deactivate all tallies
214
  for (auto& t : model::tallies) {
35,408✔
215
    t->active_ = false;
27,581✔
216
  }
217

218
  // Stop timers and show timing statistics
219
  simulation::time_finalize.stop();
7,827✔
220
  simulation::time_total.stop();
7,827✔
221

222
#ifdef OPENMC_MPI
223
  // Reduce track count across ranks for correct reporting. In shared secondary
224
  // bank mode, all ranks already have the global count; in non-shared mode,
225
  // each rank only has its own count.
226
  if (settings::weight_windows_on && !settings::use_shared_secondary_bank) {
3,510✔
227
    int64_t total_tracks;
92✔
228
    MPI_Reduce(&simulation::simulation_tracks_completed, &total_tracks, 1,
92✔
229
      MPI_INT64_T, MPI_SUM, 0, mpi::intracomm);
230
    if (mpi::master)
92✔
231
      simulation::simulation_tracks_completed = total_tracks;
76✔
232
  }
233
#endif
234

235
  if (mpi::master) {
7,827✔
236
    if (settings::solver_type != SolverType::RANDOM_RAY) {
6,815✔
237
      if (settings::verbosity >= 6)
6,164✔
238
        print_runtime();
5,784✔
239
      if (settings::verbosity >= 4)
6,164✔
240
        print_results();
5,784✔
241
    }
242
  }
243
  if (settings::check_overlaps)
7,827!
UNCOV
244
    print_overlap_check();
×
245

246
  // Reset flags
247
  simulation::initialized = false;
7,827✔
248
  return 0;
7,827✔
249
}
250

251
int openmc_next_batch(int* status)
145,378✔
252
{
253
  using namespace openmc;
145,378✔
254
  using openmc::simulation::current_gen;
145,378✔
255

256
  // Make sure simulation has been initialized
257
  if (!simulation::initialized) {
145,378✔
258
    set_errmsg("Simulation has not been initialized yet.");
11✔
259
    return OPENMC_E_ALLOCATE;
11✔
260
  }
261

262
  initialize_batch();
145,367✔
263

264
  // =======================================================================
265
  // LOOP OVER GENERATIONS
266
  for (current_gen = 1; current_gen <= settings::gen_per_batch; ++current_gen) {
290,931✔
267

268
    initialize_generation();
145,577✔
269

270
    // Start timer for transport
271
    simulation::time_transport.start();
145,577✔
272

273
    // Transport loop
274
    if (settings::event_based) {
145,577✔
275
      if (settings::use_shared_secondary_bank) {
3,231✔
276
        transport_event_based_shared_secondary();
11✔
277
      } else {
278
        transport_event_based();
3,220✔
279
      }
280
    } else {
281
      if (settings::use_shared_secondary_bank) {
142,346✔
282
        transport_history_based_shared_secondary();
667✔
283
      } else {
284
        transport_history_based();
141,679✔
285
      }
286
    }
287

288
    // Accumulate time for transport
289
    simulation::time_transport.stop();
145,564✔
290

291
    finalize_generation();
145,564✔
292
  }
293

294
  finalize_batch();
145,354✔
295

296
  // Check simulation ending criteria
297
  if (status) {
145,354!
298
    if (simulation::current_batch >= settings::n_max_batches) {
145,354✔
299
      *status = STATUS_EXIT_MAX_BATCH;
6,870✔
300
    } else if (simulation::satisfy_triggers) {
138,484✔
301
      *status = STATUS_EXIT_ON_TRIGGER;
93✔
302
    } else {
303
      *status = STATUS_EXIT_NORMAL;
138,391✔
304
    }
305
  }
306
  return 0;
307
}
308

309
bool openmc_is_statepoint_batch()
3,135✔
310
{
311
  using namespace openmc;
3,135✔
312
  using openmc::simulation::current_gen;
3,135✔
313

314
  if (!simulation::initialized)
3,135!
315
    return false;
316
  else
317
    return contains(settings::statepoint_batch, simulation::current_batch);
6,270✔
318
}
319

320
namespace openmc {
321

322
//==============================================================================
323
// Global variables
324
//==============================================================================
325

326
namespace simulation {
327

328
int ct_current_file;
329
int current_batch;
330
int current_gen;
331
bool initialized {false};
332
double keff {1.0};
333
double keff_std;
334
double k_col_abs {0.0};
335
double k_col_tra {0.0};
336
double k_abs_tra {0.0};
337
double log_spacing;
338
int n_lost_particles {0};
339
bool need_depletion_rx {false};
340
int restart_batch;
341
bool satisfy_triggers {false};
342
int ssw_current_file;
343
int total_gen {0};
344
double total_weight;
345
int64_t work_per_rank;
346

347
const RegularMesh* entropy_mesh {nullptr};
348
const RegularMesh* ufs_mesh {nullptr};
349

350
vector<double> k_generation;
351
vector<int64_t> work_index;
352

353
int64_t simulation_tracks_completed {0};
354

355
} // namespace simulation
356

357
//==============================================================================
358
// Non-member functions
359
//==============================================================================
360

361
void allocate_banks()
7,840✔
362
{
363
  if (settings::run_mode == RunMode::EIGENVALUE &&
7,840✔
364
      settings::solver_type == SolverType::MONTE_CARLO) {
4,481✔
365
    // Allocate source bank
366
    simulation::source_bank.resize(simulation::work_per_rank);
4,110✔
367

368
    // Allocate fission bank
369
    init_fission_bank(3 * simulation::work_per_rank);
4,110✔
370

371
    // Allocate IFP bank
372
    if (settings::ifp_on) {
4,110✔
373
      resize_simulation_ifp_banks();
74✔
374
    }
375
  }
376

377
  if (settings::surf_source_write) {
7,840✔
378
    // Allocate surface source bank
379
    simulation::surf_source_bank.reserve(settings::ssw_max_particles);
1,154✔
380
  }
381

382
  if (settings::collision_track) {
7,840✔
383
    // Allocate collision track bank
384
    collision_track_reserve_bank();
160✔
385
  }
386
}
7,840✔
387

388
void initialize_batch()
166,329✔
389
{
390
  // Increment current batch
391
  ++simulation::current_batch;
166,329✔
392
  if (settings::run_mode == RunMode::FIXED_SOURCE) {
166,329✔
393
    if (settings::solver_type == SolverType::RANDOM_RAY &&
65,386✔
394
        simulation::current_batch < settings::n_inactive + 1) {
14,112✔
395
      write_message(
16,812✔
396
        6, "Simulating batch {:<4} (inactive)", simulation::current_batch);
397
    } else {
398
      write_message(6, "Simulating batch {}", simulation::current_batch);
113,960✔
399
    }
400
  }
401

402
  // Reset total starting particle weight used for normalizing tallies
403
  simulation::total_weight = 0.0;
166,329✔
404

405
  // Determine if this batch is the first inactive or active batch.
406
  bool first_inactive = false;
166,329✔
407
  bool first_active = false;
166,329✔
408
  if (!settings::restart_run) {
166,329✔
409
    first_inactive = settings::n_inactive > 0 && simulation::current_batch == 1;
166,166✔
410
    first_active = simulation::current_batch == settings::n_inactive + 1;
166,166✔
411
  } else if (simulation::current_batch == simulation::restart_batch + 1) {
163✔
412
    first_inactive = simulation::restart_batch < settings::n_inactive;
52✔
413
    first_active = !first_inactive;
52✔
414
  }
415

416
  // Manage active/inactive timers and activate tallies if necessary.
417
  if (first_inactive) {
166,218✔
418
    simulation::time_inactive.start();
3,865✔
419
  } else if (first_active) {
162,464✔
420
    simulation::time_inactive.stop();
7,793✔
421
    simulation::time_active.start();
7,793✔
422
    for (auto& t : model::tallies) {
35,352✔
423
      t->active_ = true;
27,559✔
424
    }
425
  }
426

427
  // Add user tallies to active tallies list
428
  setup_active_tallies();
166,329✔
429
}
166,329✔
430

431
void finalize_batch()
166,316✔
432
{
433
  // Reduce tallies onto master process and accumulate
434
  simulation::time_tallies.start();
166,316✔
435
  accumulate_tallies();
166,316✔
436
  simulation::time_tallies.stop();
166,316✔
437

438
  // update weight windows if needed
439
  for (const auto& wwg : variance_reduction::weight_windows_generators) {
168,948✔
440
    wwg->update();
2,632✔
441
  }
442

443
  // Reset global tally results
444
  if (simulation::current_batch <= settings::n_inactive) {
166,316✔
445
    simulation::global_tallies.fill(0.0);
32,603✔
446
    simulation::n_realizations = 0;
32,603✔
447
  }
448

449
  // Check_triggers
450
  if (mpi::master)
166,316✔
451
    check_triggers();
147,357✔
452
#ifdef OPENMC_MPI
453
  MPI_Bcast(&simulation::satisfy_triggers, 1, MPI_C_BOOL, 0, mpi::intracomm);
72,868✔
454
#endif
455
  if (simulation::satisfy_triggers ||
166,316✔
456
      (settings::trigger_on &&
2,567✔
457
        simulation::current_batch == settings::n_max_batches)) {
2,567✔
458
    settings::statepoint_batch.insert(simulation::current_batch);
141✔
459
  }
460

461
  // Write out state point if it's been specified for this batch and is not
462
  // a CMFD run instance
463
  if (contains(settings::statepoint_batch, simulation::current_batch) &&
332,632✔
464
      !settings::cmfd_run) {
8,095✔
465
    if (contains(settings::sourcepoint_batch, simulation::current_batch) &&
15,560✔
466
        settings::source_write && !settings::source_separate) {
14,677✔
467
      bool b = (settings::run_mode == RunMode::EIGENVALUE);
6,687✔
468
      openmc_statepoint_write(nullptr, &b);
6,687✔
469
    } else {
470
      bool b = false;
1,232✔
471
      openmc_statepoint_write(nullptr, &b);
1,232✔
472
    }
473
  }
474

475
  if (settings::run_mode == RunMode::EIGENVALUE) {
166,316✔
476
    // Write out a separate source point if it's been specified for this batch
477
    if (contains(settings::sourcepoint_batch, simulation::current_batch) &&
105,450✔
478
        settings::source_write && settings::source_separate) {
105,079✔
479

480
      // Determine width for zero padding
481
      int w = std::to_string(settings::n_max_batches).size();
71✔
482
      std::string source_point_filename = fmt::format("{0}source.{1:0{2}}",
71✔
483
        settings::path_output, simulation::current_batch, w);
71✔
484
      span<SourceSite> bankspan(simulation::source_bank);
71✔
485
      write_source_point(source_point_filename, bankspan,
142✔
486
        simulation::work_index, settings::source_mcpl_write);
487
    }
71✔
488

489
    // Write a continously-overwritten source point if requested.
490
    if (settings::source_latest) {
100,943✔
491
      auto filename = settings::path_output + "source";
150✔
492
      span<SourceSite> bankspan(simulation::source_bank);
150✔
493
      write_source_point(filename, bankspan, simulation::work_index,
300✔
494
        settings::source_mcpl_write);
495
    }
150✔
496
  }
497

498
  // Write out surface source if requested.
499
  if (settings::surf_source_write &&
166,316✔
500
      simulation::ssw_current_file <= settings::ssw_max_files) {
17,669✔
501
    bool last_batch = (simulation::current_batch == settings::n_batches);
1,976✔
502
    if (simulation::surf_source_bank.full() || last_batch) {
1,976✔
503
      // Determine appropriate filename
504
      auto filename = fmt::format("{}surface_source.{}", settings::path_output,
1,187✔
505
        simulation::current_batch);
1,187✔
506
      if (settings::ssw_max_files == 1 ||
1,187✔
507
          (simulation::ssw_current_file == 1 && last_batch)) {
55!
508
        filename = settings::path_output + "surface_source";
1,132✔
509
      }
510

511
      // Get span of source bank and calculate parallel index vector
512
      auto surf_work_index = mpi::calculate_parallel_index_vector(
1,187✔
513
        simulation::surf_source_bank.size());
1,187✔
514
      span<SourceSite> surfbankspan(simulation::surf_source_bank.begin(),
1,187✔
515
        simulation::surf_source_bank.size());
1,187✔
516

517
      // Write surface source file
518
      write_source_point(
1,187✔
519
        filename, surfbankspan, surf_work_index, settings::surf_mcpl_write);
520

521
      // Reset surface source bank and increment counter
522
      simulation::surf_source_bank.clear();
1,187✔
523
      if (!last_batch && settings::ssw_max_files >= 1) {
1,187!
524
        simulation::surf_source_bank.reserve(settings::ssw_max_particles);
1,005✔
525
      }
526
      ++simulation::ssw_current_file;
1,187✔
527
    }
1,187✔
528
  }
529
  // Write collision track file if requested
530
  if (settings::collision_track) {
166,316✔
531
    collision_track_flush_bank();
580✔
532
  }
533
}
166,316✔
534

535
void initialize_generation()
166,539✔
536
{
537
  if (settings::run_mode == RunMode::EIGENVALUE) {
166,539✔
538
    // Clear out the fission bank
539
    simulation::fission_bank.resize(0);
101,153✔
540

541
    // Count source sites if using uniform fission source weighting
542
    if (settings::ufs_on)
101,153✔
543
      ufs_count_sites();
150✔
544

545
    // Store current value of tracklength k
546
    simulation::keff_generation = simulation::global_tallies(
101,153✔
547
      GlobalTally::K_TRACKLENGTH, TallyResult::VALUE);
548
  }
549
}
166,539✔
550

551
void finalize_generation()
166,526✔
552
{
553
  auto& gt = simulation::global_tallies;
166,526✔
554

555
  // Update global tallies with the accumulation variables
556
  if (settings::run_mode == RunMode::EIGENVALUE) {
166,526✔
557
    gt(GlobalTally::K_COLLISION, TallyResult::VALUE) += global_tally_collision;
101,153✔
558
    gt(GlobalTally::K_ABSORPTION, TallyResult::VALUE) +=
101,153✔
559
      global_tally_absorption;
560
    gt(GlobalTally::K_TRACKLENGTH, TallyResult::VALUE) +=
101,153✔
561
      global_tally_tracklength;
562
  }
563
  gt(GlobalTally::LEAKAGE, TallyResult::VALUE) += global_tally_leakage;
166,526✔
564

565
  // reset tallies
566
  if (settings::run_mode == RunMode::EIGENVALUE) {
166,526✔
567
    global_tally_collision = 0.0;
101,153✔
568
    global_tally_absorption = 0.0;
101,153✔
569
    global_tally_tracklength = 0.0;
101,153✔
570
  }
571
  global_tally_leakage = 0.0;
166,526✔
572

573
  if (settings::run_mode == RunMode::EIGENVALUE &&
166,526✔
574
      settings::solver_type == SolverType::MONTE_CARLO) {
101,153✔
575
    // If using shared memory, stable sort the fission bank (by parent IDs)
576
    // so as to allow for reproducibility regardless of which order particles
577
    // are run in.
578
    sort_bank(simulation::fission_bank, true);
94,303✔
579

580
    // Distribute fission bank across processors evenly
581
    synchronize_bank();
94,303✔
582
  }
583

584
  if (settings::run_mode == RunMode::EIGENVALUE) {
166,526✔
585

586
    // Calculate shannon entropy
587
    if (settings::entropy_on &&
101,153✔
588
        settings::solver_type == SolverType::MONTE_CARLO)
14,535✔
589
      shannon_entropy();
7,685✔
590

591
    // Collect results and statistics
592
    calculate_generation_keff();
101,153✔
593
    calculate_average_keff();
101,153✔
594

595
    // Write generation output
596
    if (mpi::master && settings::verbosity >= 7) {
101,153✔
597
      print_generation();
76,088✔
598
    }
599
  }
600
}
166,526✔
601

602
void sample_source_particle(Particle& p, int64_t index_source)
178,008,577✔
603
{
604
  // Sample a particle from the source bank
605
  if (settings::run_mode == RunMode::EIGENVALUE) {
178,008,577✔
606
    p.from_source(&simulation::source_bank[index_source - 1]);
149,904,000✔
607
  } else if (settings::run_mode == RunMode::FIXED_SOURCE) {
28,104,577!
608
    // initialize random number seed
609
    int64_t id = compute_transport_seed(compute_particle_id(index_source));
28,104,577✔
610
    uint64_t seed = init_seed(id, STREAM_SOURCE);
28,104,577✔
611
    // sample from external source distribution or custom library then set
612
    auto site = sample_external_source(&seed);
28,104,577✔
613
    p.from_source(&site);
28,104,573✔
614
  }
615
}
178,008,573✔
616

617
void initialize_particle_track(
199,327,213✔
618
  Particle& p, int64_t index_source, bool is_secondary)
619
{
620
  // Note: index_source is 1-based (first particle = 1), but current_work() is
621
  // stored as 0-based for direct use as an array index into
622
  // progeny_per_particle, source_bank, ifp banks, etc.
623
  if (!is_secondary) {
199,327,213✔
624
    sample_source_particle(p, index_source);
178,008,577✔
625
  }
626

627
  p.current_work() = index_source - 1;
199,327,209✔
628

629
  // set identifier for particle
630
  p.id() = compute_particle_id(index_source);
199,327,209✔
631

632
  // set progeny count to zero
633
  p.n_progeny() = 0;
199,327,209✔
634

635
  // Reset particle event counter
636
  p.n_event() = 0;
199,327,209✔
637

638
  // Initialize track counter (1 for this primary/secondary track)
639
  p.n_tracks() = 1;
199,327,209✔
640

641
  // Reset split counter
642
  p.n_split() = 0;
199,327,209✔
643

644
  // Reset weight window ratio
645
  p.ww_factor() = 0.0;
199,327,209✔
646

647
  // set particle history start weight
648
  p.wgt_born() = p.wgt();
199,327,209✔
649

650
  // Reset pulse_height_storage
651
  std::fill(p.pht_storage().begin(), p.pht_storage().end(), 0);
199,327,209✔
652

653
  // set random number seed
654
  int64_t particle_seed = compute_transport_seed(p.id());
199,327,209✔
655
  init_particle_seeds(particle_seed, p.seeds());
199,327,209✔
656

657
  // set particle trace
658
  p.trace() = false;
199,327,209✔
659
  if (simulation::current_batch == settings::trace_batch &&
199,338,209✔
660
      simulation::current_gen == settings::trace_gen &&
199,327,209!
661
      p.id() == settings::trace_particle)
11,000✔
662
    p.trace() = true;
11✔
663

664
  // Set particle track.
665
  p.write_track() = check_track_criteria(p);
199,327,209✔
666

667
  // Set the particle's initial weight window value.
668
  if (!is_secondary) {
199,327,209✔
669
    p.wgt_ww_born() = -1.0;
178,008,573✔
670
    apply_weight_windows(p);
178,008,573✔
671
  }
672

673
  // Display message if high verbosity or trace is on
674
  if (settings::verbosity >= 9 || p.trace()) {
199,327,209!
675
    write_message("Simulating Particle {}", p.id());
22✔
676
  }
677

678
  // Add particle's starting weight to count for normalizing tallies later
679
  if (!is_secondary) {
199,327,209✔
680
#pragma omp atomic
97,360,796✔
681
    simulation::total_weight += p.wgt();
178,008,573✔
682
  }
683

684
  // Force calculation of cross-sections by setting last energy to zero
685
  if (settings::run_CE) {
199,327,209✔
686
    p.invalidate_neutron_xs();
84,778,665✔
687
  }
688

689
  // Prepare to write out particle track.
690
  if (p.write_track())
199,327,209✔
691
    add_particle_track(p);
999✔
692
}
199,327,209✔
693

694
int overall_generation()
204,815,977✔
695
{
696
  using namespace simulation;
204,815,977✔
697
  return settings::gen_per_batch * (current_batch - 1) + current_gen;
204,815,977✔
698
}
699

700
int64_t compute_particle_id(int64_t index_source)
227,432,061✔
701
{
702
  if (settings::use_shared_secondary_bank) {
227,432,061✔
703
    return simulation::work_index[mpi::rank] + index_source +
22,887,661✔
704
           simulation::simulation_tracks_completed;
22,887,661✔
705
  } else {
706
    return simulation::work_index[mpi::rank] + index_source;
204,544,400✔
707
  }
708
}
709

710
int64_t compute_transport_seed(int64_t particle_id)
227,432,105✔
711
{
712
  if (settings::use_shared_secondary_bank) {
227,432,105✔
713
    return particle_id;
714
  } else {
715
    return (simulation::total_gen + overall_generation() - 1) *
204,544,433✔
716
             settings::n_particles +
717
           particle_id;
204,544,433✔
718
  }
719
}
720

721
void calculate_work(int64_t n_particles)
17,170✔
722
{
723
  // Determine minimum amount of particles to simulate on each processor
724
  int64_t min_work = n_particles / mpi::n_procs;
17,170✔
725

726
  // Determine number of processors that have one extra particle
727
  int64_t remainder = n_particles % mpi::n_procs;
17,170✔
728

729
  int64_t i_bank = 0;
17,170✔
730
  simulation::work_index.resize(mpi::n_procs + 1);
17,170✔
731
  simulation::work_index[0] = 0;
17,170✔
732
  for (int i = 0; i < mpi::n_procs; ++i) {
39,891✔
733
    // Number of particles for rank i
734
    int64_t work_i = i < remainder ? min_work + 1 : min_work;
22,721✔
735

736
    // Set number of particles
737
    if (mpi::rank == i)
22,721✔
738
      simulation::work_per_rank = work_i;
17,170✔
739

740
    // Set index into source bank for rank i
741
    i_bank += work_i;
22,721✔
742
    simulation::work_index[i + 1] = i_bank;
22,721✔
743
  }
744
}
17,170✔
745

746
void initialize_data()
6,473✔
747
{
748
  // Determine minimum/maximum energy for incident neutron/photon data
749
  data::energy_max = {INFTY, INFTY, INFTY, INFTY};
6,473✔
750
  data::energy_min = {0.0, 0.0, 0.0, 0.0};
6,473✔
751

752
  for (const auto& nuc : data::nuclides) {
39,944✔
753
    if (nuc->grid_.size() >= 1) {
33,471!
754
      int neutron = ParticleType::neutron().transport_index();
33,471✔
755
      data::energy_min[neutron] =
33,471✔
756
        std::max(data::energy_min[neutron], nuc->grid_[0].energy.front());
39,412✔
757
      data::energy_max[neutron] =
33,471✔
758
        std::min(data::energy_max[neutron], nuc->grid_[0].energy.back());
40,976✔
759
    }
760
  }
761

762
  if (settings::photon_transport) {
6,473✔
763
    for (const auto& elem : data::elements) {
1,999✔
764
      if (elem->energy_.size() >= 1) {
1,465!
765
        int photon = ParticleType::photon().transport_index();
1,465✔
766
        int n = elem->energy_.size();
1,465✔
767
        data::energy_min[photon] =
2,930✔
768
          std::max(data::energy_min[photon], std::exp(elem->energy_(1)));
2,401✔
769
        data::energy_max[photon] =
1,465✔
770
          std::min(data::energy_max[photon], std::exp(elem->energy_(n - 1)));
1,999✔
771
      }
772
    }
773

774
    if (settings::electron_treatment == ElectronTreatment::TTB) {
534✔
775
      // Determine if minimum/maximum energy for bremsstrahlung is greater/less
776
      // than the current minimum/maximum
777
      if (data::ttb_e_grid.size() >= 1) {
475!
778
        int photon = ParticleType::photon().transport_index();
475✔
779
        int electron = ParticleType::electron().transport_index();
475✔
780
        int positron = ParticleType::positron().transport_index();
475✔
781
        int n_e = data::ttb_e_grid.size();
475✔
782

783
        const std::vector<int> charged = {electron, positron};
475✔
784
        for (auto t : charged) {
1,425✔
785
          data::energy_min[t] = std::exp(data::ttb_e_grid(1));
950✔
786
          data::energy_max[t] = std::exp(data::ttb_e_grid(n_e - 1));
950✔
787
        }
788

789
        data::energy_min[photon] =
950✔
790
          std::max(data::energy_min[photon], data::energy_min[electron]);
950!
791

792
        data::energy_max[photon] =
950✔
793
          std::min(data::energy_max[photon], data::energy_max[electron]);
950!
794
      }
475✔
795
    }
796
  }
797

798
  // Show which nuclide results in lowest energy for neutron transport
799
  for (const auto& nuc : data::nuclides) {
8,097✔
800
    // If a nuclide is present in a material that's not used in the model, its
801
    // grid has not been allocated
802
    if (nuc->grid_.size() > 0) {
7,565!
803
      double max_E = nuc->grid_[0].energy.back();
7,565✔
804
      int neutron = ParticleType::neutron().transport_index();
7,565✔
805
      if (max_E == data::energy_max[neutron]) {
7,565✔
806
        write_message(7, "Maximum neutron transport energy: {} eV for {}",
5,941✔
807
          data::energy_max[neutron], nuc->name_);
5,941✔
808
        if (mpi::master && data::energy_max[neutron] < 20.0e6) {
5,941!
UNCOV
809
          warning("Maximum neutron energy is below 20 MeV. This may bias "
×
810
                  "the results.");
811
        }
812
        break;
813
      }
814
    }
815
  }
816

817
  // Set up logarithmic grid for nuclides
818
  for (auto& nuc : data::nuclides) {
39,944✔
819
    nuc->init_grid();
33,471✔
820
  }
821
  int neutron = ParticleType::neutron().transport_index();
6,473✔
822
  simulation::log_spacing =
12,946✔
823
    std::log(data::energy_max[neutron] / data::energy_min[neutron]) /
6,473✔
824
    settings::n_log_bins;
825
}
6,473✔
826

827
#ifdef OPENMC_MPI
828
void broadcast_results()
3,510✔
829
{
830
  // Broadcast tally results so that each process has access to results
831
  for (auto& t : model::tallies) {
17,199✔
832
    // Create a new datatype that consists of all values for a given filter
833
    // bin and then use that to broadcast. This is done to minimize the
834
    // chance of the 'count' argument of MPI_BCAST exceeding 2**31
835
    auto& results = t->results_;
13,689✔
836

837
    auto shape = results.shape();
13,689✔
838
    int count_per_filter = shape[1] * shape[2];
13,689✔
839
    MPI_Datatype result_block;
13,689✔
840
    MPI_Type_contiguous(count_per_filter, MPI_DOUBLE, &result_block);
13,689✔
841
    MPI_Type_commit(&result_block);
13,689✔
842
    MPI_Bcast(results.data(), shape[0], result_block, 0, mpi::intracomm);
13,689✔
843
    MPI_Type_free(&result_block);
13,689✔
844
  }
13,689✔
845

846
  // Also broadcast global tally results
847
  auto& gt = simulation::global_tallies;
3,510✔
848
  MPI_Bcast(gt.data(), gt.size(), MPI_DOUBLE, 0, mpi::intracomm);
3,510✔
849

850
  // These guys are needed so that non-master processes can calculate the
851
  // combined estimate of k-effective
852
  double temp[] {
3,510✔
853
    simulation::k_col_abs, simulation::k_col_tra, simulation::k_abs_tra};
3,510✔
854
  MPI_Bcast(temp, 3, MPI_DOUBLE, 0, mpi::intracomm);
3,510✔
855
  simulation::k_col_abs = temp[0];
3,510✔
856
  simulation::k_col_tra = temp[1];
3,510✔
857
  simulation::k_abs_tra = temp[2];
3,510✔
858
}
3,510✔
859

860
#endif
861

862
void free_memory_simulation()
9,012✔
863
{
864
  simulation::k_generation.clear();
9,012✔
865
  simulation::entropy.clear();
9,012✔
866
}
9,012✔
867

868
void transport_history_based_single_particle(Particle& p)
186,981,443✔
869
{
870
  while (p.alive()) {
2,147,483,647✔
871
    p.event_calculate_xs();
2,147,483,647✔
872
    if (p.alive()) {
2,147,483,647!
873
      p.event_advance();
2,147,483,647✔
874
    }
875
    if (p.alive()) {
2,147,483,647✔
876
      if (p.collision_distance() > p.boundary().distance()) {
2,147,483,647✔
877
        p.event_cross_surface();
2,147,483,647✔
878
      } else if (p.alive()) {
2,147,483,647✔
879
        p.event_collide();
2,147,483,647✔
880
      }
881
    }
882
    p.event_check_limit_and_revive();
2,147,483,647✔
883
  }
884
  p.event_death();
186,981,434✔
885
}
186,981,434✔
886

887
void transport_history_based()
141,679✔
888
{
889
#pragma omp parallel for schedule(runtime)
78,939✔
890
  for (int64_t i_work = 1; i_work <= simulation::work_per_rank; ++i_work) {
80,538,565✔
891
    Particle p;
80,475,834✔
892
    initialize_particle_track(p, i_work, false);
80,475,834✔
893
    transport_history_based_single_particle(p);
80,475,830✔
894
  }
80,475,825✔
895
}
141,670✔
896

897
// The shared secondary bank transport algorithm works in two phases. In the
898
// first phase, all primary particles are sampled then transported, and their
899
// secondary particles are deposited into a shared secondary bank. The second
900
// phase occurs in a loop, where all secondary tracks in the shared secondary
901
// bank are transported. Any secondary particles generated during this phase are
902
// deposited back into the shared secondary bank. The shared secondary bank is
903
// sorted for consistent ordering and load balanced across MPI ranks. This loop
904
// continues until there are no more secondary tracks left to transport.
905
void transport_history_based_shared_secondary()
667✔
906
{
907
  // Clear shared secondary banks from any prior use
908
  simulation::shared_secondary_bank_read.clear();
667✔
909
  simulation::shared_secondary_bank_write.clear();
667✔
910

911
  if (mpi::master) {
667✔
912
    write_message(fmt::format(" Primary source          particles: {}",
1,150✔
913
                    settings::n_particles),
914
      6);
915
  }
916

917
  simulation::progeny_per_particle.resize(simulation::work_per_rank);
667✔
918
  std::fill(simulation::progeny_per_particle.begin(),
1,334✔
919
    simulation::progeny_per_particle.end(), 0);
667✔
920

921
  // Phase 1: Transport primary particles and deposit first generation of
922
  // secondaries in the shared secondary bank
923
#pragma omp parallel
384✔
924
  {
283✔
925
    vector<SourceSite> thread_bank;
283✔
926

927
#pragma omp for schedule(runtime)
928
    for (int64_t i = 1; i <= simulation::work_per_rank; i++) {
356,058✔
929
      Particle p;
355,775✔
930
      initialize_particle_track(p, i, false);
355,775✔
931
      transport_history_based_single_particle(p);
355,775✔
932
      for (auto& site : p.local_secondary_bank()) {
1,087,225✔
933
        thread_bank.push_back(site);
731,450✔
934
      }
935
    }
355,775✔
936

937
    // Drain thread-local bank into the shared secondary bank (once per thread)
938
#pragma omp critical(SharedSecondaryBank)
939
    {
283✔
940
      for (auto& site : thread_bank) {
731,733✔
941
        simulation::shared_secondary_bank_write.thread_unsafe_append(site);
731,450✔
942
      }
943
    }
944
  }
945

946
  simulation::simulation_tracks_completed += settings::n_particles;
667✔
947

948
  // Phase 2: Now that the secondary bank has been populated, enter loop over
949
  // all secondary generations
950
  int n_generation_depth = 1;
667✔
951
  int64_t alive_secondary = 1;
667✔
952
  while (alive_secondary) {
8,913✔
953

954
    // Sort the shared secondary bank by parent ID then progeny ID to
955
    // ensure reproducibility.
956
    sort_bank(simulation::shared_secondary_bank_write, false);
8,246✔
957

958
    // Synchronize the shared secondary bank amongst all MPI ranks, such
959
    // that each MPI rank has an approximately equal number of secondary
960
    // tracks. Also reports the total number of secondaries alive across
961
    // all MPI ranks.
962
    alive_secondary = synchronize_global_secondary_bank(
8,246✔
963
      simulation::shared_secondary_bank_write);
964

965
    // Recalculate work for each MPI rank based on number of alive secondary
966
    // tracks
967
    calculate_work(alive_secondary);
8,246✔
968

969
    // Display the number of secondary tracks in this generation. This
970
    // is useful for user monitoring so as to see if the secondary population is
971
    // exploding and to determine how many generations of secondaries are being
972
    // transported.
973
    if (mpi::master) {
8,246✔
974
      write_message(fmt::format(" Secondary generation {:<2}    tracks: {}",
13,148✔
975
                      n_generation_depth, alive_secondary),
976
        6);
977
    }
978

979
    simulation::shared_secondary_bank_read =
8,246✔
980
      std::move(simulation::shared_secondary_bank_write);
8,246✔
981
    simulation::shared_secondary_bank_write = SharedArray<SourceSite>();
8,246!
982
    simulation::progeny_per_particle.resize(
8,246✔
983
      simulation::shared_secondary_bank_read.size());
8,246✔
984
    std::fill(simulation::progeny_per_particle.begin(),
16,492✔
985
      simulation::progeny_per_particle.end(), 0);
8,246✔
986

987
    // Transport all secondary tracks from the shared secondary bank
988
#pragma omp parallel
4,653✔
989
    {
3,593✔
990
      vector<SourceSite> thread_bank;
3,593✔
991

992
#pragma omp for schedule(runtime)
993
      for (int64_t i = 1; i <= simulation::shared_secondary_bank_read.size();
9,727,253✔
994
           i++) {
995
        Particle p;
9,723,660✔
996
        initialize_particle_track(p, i, true);
9,723,660✔
997
        SourceSite& site = simulation::shared_secondary_bank_read[i - 1];
9,723,660✔
998
        p.event_revive_from_secondary(site);
9,723,660✔
999
        transport_history_based_single_particle(p);
9,723,660✔
1000
        for (auto& secondary_site : p.local_secondary_bank()) {
18,715,870✔
1001
          thread_bank.push_back(secondary_site);
8,992,210✔
1002
        }
1003
      }
9,723,660✔
1004

1005
      // Drain thread-local bank into the shared secondary bank (once per
1006
      // thread)
1007
#pragma omp critical(SharedSecondaryBank)
1008
      {
3,593✔
1009
        for (auto& secondary_site : thread_bank) {
8,995,803✔
1010
          simulation::shared_secondary_bank_write.thread_unsafe_append(
8,992,210✔
1011
            secondary_site);
1012
        }
1013
      }
1014
    } // End of transport loop over tracks in shared secondary bank
3,593✔
1015
    n_generation_depth++;
8,246✔
1016
    simulation::simulation_tracks_completed += alive_secondary;
8,246✔
1017
  } // End of loop over secondary generations
1018

1019
  // Reset work so that fission bank etc works correctly
1020
  calculate_work(settings::n_particles);
667✔
1021
}
667✔
1022

1023
void transport_event_based()
3,220✔
1024
{
1025
  int64_t remaining_work = simulation::work_per_rank;
3,220✔
1026
  int64_t source_offset = 0;
3,220✔
1027

1028
  // To cap the total amount of memory used to store particle object data, the
1029
  // number of particles in flight at any point in time can bet set. In the case
1030
  // that the maximum in flight particle count is lower than the total number
1031
  // of particles that need to be run this iteration, the event-based transport
1032
  // loop is executed multiple times until all particles have been completed.
1033
  while (remaining_work > 0) {
6,440✔
1034
    // Figure out # of particles to run for this subiteration
1035
    int64_t n_particles =
3,220!
1036
      std::min(remaining_work, settings::max_particles_in_flight);
3,220✔
1037

1038
    // Initialize all particle histories for this subiteration
1039
    process_init_events(n_particles, source_offset);
3,220✔
1040
    process_transport_events();
3,220✔
1041
    process_death_events(n_particles);
3,220✔
1042

1043
    // Adjust remaining work and source offset variables
1044
    remaining_work -= n_particles;
3,220✔
1045
    source_offset += n_particles;
3,220✔
1046
  }
1047
}
3,220✔
1048

1049
void transport_event_based_shared_secondary()
11✔
1050
{
1051
  // Clear shared secondary banks from any prior use
1052
  simulation::shared_secondary_bank_read.clear();
11✔
1053
  simulation::shared_secondary_bank_write.clear();
11✔
1054

1055
  if (mpi::master) {
11!
1056
    write_message(fmt::format(" Primary source          particles: {}",
22!
1057
                    settings::n_particles),
1058
      6);
1059
  }
1060

1061
  simulation::progeny_per_particle.resize(simulation::work_per_rank);
11✔
1062
  std::fill(simulation::progeny_per_particle.begin(),
22✔
1063
    simulation::progeny_per_particle.end(), 0);
11✔
1064

1065
  // Phase 1: Transport primary particles using event-based processing and
1066
  // deposit first generation of secondaries in the shared secondary bank
1067
  int64_t remaining_work = simulation::work_per_rank;
11✔
1068
  int64_t source_offset = 0;
11✔
1069

1070
  while (remaining_work > 0) {
22✔
1071
    int64_t n_particles =
11!
1072
      std::min(remaining_work, settings::max_particles_in_flight);
11✔
1073

1074
    process_init_events(n_particles, source_offset);
11✔
1075
    process_transport_events();
11✔
1076
    process_death_events(n_particles);
11✔
1077

1078
    // Collect secondaries from all particle buffers into shared bank
1079
    for (int64_t i = 0; i < n_particles; i++) {
1,661✔
1080
      for (auto& site : simulation::particles[i].local_secondary_bank()) {
6,132✔
1081
        simulation::shared_secondary_bank_write.thread_unsafe_append(site);
4,482✔
1082
      }
1083
      simulation::particles[i].local_secondary_bank().clear();
3,017✔
1084
    }
1085

1086
    remaining_work -= n_particles;
11✔
1087
    source_offset += n_particles;
11✔
1088
  }
1089

1090
  simulation::simulation_tracks_completed += settings::n_particles;
11✔
1091

1092
  // Phase 2: Now that the secondary bank has been populated, enter loop over
1093
  // all secondary generations
1094
  int n_generation_depth = 1;
11✔
1095
  int64_t alive_secondary = 1;
11✔
1096
  while (alive_secondary) {
417✔
1097

1098
    // Sort the shared secondary bank by parent ID then progeny ID to
1099
    // ensure reproducibility.
1100
    sort_bank(simulation::shared_secondary_bank_write, false);
406✔
1101

1102
    // Synchronize the shared secondary bank amongst all MPI ranks, such
1103
    // that each MPI rank has an approximately equal number of secondary
1104
    // tracks.
1105
    alive_secondary = synchronize_global_secondary_bank(
406✔
1106
      simulation::shared_secondary_bank_write);
1107

1108
    // Recalculate work for each MPI rank based on number of alive secondary
1109
    // tracks
1110
    calculate_work(alive_secondary);
406✔
1111

1112
    if (mpi::master) {
406!
1113
      write_message(fmt::format(" Secondary generation {:<2}    tracks: {}",
812!
1114
                      n_generation_depth, alive_secondary),
1115
        6);
1116
    }
1117

1118
    simulation::shared_secondary_bank_read =
406✔
1119
      std::move(simulation::shared_secondary_bank_write);
406✔
1120
    simulation::shared_secondary_bank_write = SharedArray<SourceSite>();
406!
1121
    simulation::progeny_per_particle.resize(
406✔
1122
      simulation::shared_secondary_bank_read.size());
406✔
1123
    std::fill(simulation::progeny_per_particle.begin(),
812✔
1124
      simulation::progeny_per_particle.end(), 0);
406✔
1125

1126
    // Ensure particle buffer is large enough for this secondary generation
1127
    int64_t sec_buffer_length = std::min(
406!
1128
      static_cast<int64_t>(simulation::shared_secondary_bank_read.size()),
406!
1129
      settings::max_particles_in_flight);
406✔
1130
    if (sec_buffer_length >
406✔
1131
        static_cast<int64_t>(simulation::particles.size())) {
406✔
1132
      init_event_queues(sec_buffer_length);
34✔
1133
    }
1134

1135
    // Transport secondary tracks using event-based processing
1136
    int64_t sec_remaining = simulation::shared_secondary_bank_read.size();
406✔
1137
    int64_t sec_offset = 0;
406✔
1138

1139
    while (sec_remaining > 0) {
801✔
1140
      int64_t n_particles =
395!
1141
        std::min(sec_remaining, settings::max_particles_in_flight);
395✔
1142

1143
      process_init_secondary_events(
395✔
1144
        n_particles, sec_offset, simulation::shared_secondary_bank_read);
1145
      process_transport_events();
395✔
1146
      process_death_events(n_particles);
395✔
1147

1148
      // Collect secondaries from all particle buffers into shared bank
1149
      for (int64_t i = 0; i < n_particles; i++) {
180,005✔
1150
        for (auto& site : simulation::particles[i].local_secondary_bank()) {
354,738✔
1151
          simulation::shared_secondary_bank_write.thread_unsafe_append(site);
175,128✔
1152
        }
1153
        simulation::particles[i].local_secondary_bank().clear();
226,133✔
1154
      }
1155

1156
      sec_remaining -= n_particles;
395✔
1157
      sec_offset += n_particles;
395✔
1158
    } // End of subiteration loop over secondary tracks
1159
    n_generation_depth++;
406✔
1160
    simulation::simulation_tracks_completed += alive_secondary;
406✔
1161
  } // End of loop over secondary generations
1162

1163
  // Reset work so that fission bank etc works correctly
1164
  calculate_work(settings::n_particles);
11✔
1165
}
11✔
1166

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