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

openmc-dev / openmc / 29123958173

10 Jul 2026 09:12PM UTC coverage: 80.472% (-0.8%) from 81.292%
29123958173

Pull #3951

github

web-flow
Merge 62dca9136 into 7256d5046
Pull Request #3951: wwinp files: Fix MemoryError in WeightWindowsList.export_to_hdf5 and speed up from_wwinp. Alternative Approach

16757 of 24275 branches covered (69.03%)

Branch coverage included in aggregate %.

70 of 138 new or added lines in 10 files covered. (50.72%)

876 existing lines in 50 files now uncovered.

57507 of 68010 relevant lines covered (84.56%)

23274270.93 hits per line

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

81.71
/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()
1,611✔
55
{
56
  openmc::simulation::time_total.start();
1,611✔
57
  openmc_simulation_init();
1,611✔
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;
1,611✔
62
  if (openmc::simulation::current_batch >= openmc::settings::n_max_batches) {
1,611✔
63
    status = openmc::STATUS_EXIT_MAX_BATCH;
3✔
64
  }
65

66
  int err = 0;
67
  while (status == 0 && err == 0) {
36,204✔
68
    err = openmc_next_batch(&status);
34,599✔
69
  }
70

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

76
int openmc_simulation_init()
1,866✔
77
{
78
  using namespace openmc;
1,866✔
79

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

84
  // Initialize nuclear data (energy limits, log grid)
85
  if (settings::run_CE) {
1,860✔
86
    initialize_data();
1,575✔
87
  }
88

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

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

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

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

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

114
  // Set up material nuclide index mapping
115
  for (auto& mat : model::materials) {
6,966✔
116
    mat->init_nuclide_index();
5,106✔
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;
1,860✔
122
  simulation::ct_current_file = 1;
1,860✔
123
  simulation::ssw_current_file = 1;
1,860✔
124
  simulation::k_generation.clear();
1,860✔
125
  simulation::entropy.clear();
1,860✔
126
  reset_source_rejection_counters();
1,860✔
127
  openmc_reset();
1,860✔
128

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

142
  // Display header
143
  if (mpi::master) {
1,860!
144
    if (settings::run_mode == RunMode::FIXED_SOURCE) {
1,860✔
145
      if (settings::solver_type == SolverType::MONTE_CARLO) {
822✔
146
        header("FIXED SOURCE TRANSPORT SIMULATION", 3);
720✔
147
      } else if (settings::solver_type == SolverType::RANDOM_RAY) {
102!
148
        header("FIXED SOURCE TRANSPORT SIMULATION (RANDOM RAY SOLVER)", 3);
102✔
149
      }
150
    } else if (settings::run_mode == RunMode::EIGENVALUE) {
1,038!
151
      if (settings::solver_type == SolverType::MONTE_CARLO) {
1,038✔
152
        header("K EIGENVALUE SIMULATION", 3);
963✔
153
      } else if (settings::solver_type == SolverType::RANDOM_RAY) {
75!
154
        header("K EIGENVALUE SIMULATION (RANDOM RAY SOLVER)", 3);
75✔
155
      }
156
      if (settings::verbosity >= 7)
1,038✔
157
        print_columns();
930✔
158
    }
159
  }
160

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

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

171
int openmc_simulation_finalize()
1,854✔
172
{
173
  using namespace openmc;
1,854✔
174

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

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

183
  // Clear material nuclide mapping
184
  for (auto& mat : model::materials) {
6,954✔
185
    mat->mat_nuclide_index_.clear();
10,200!
186
  }
187

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

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

196
#ifdef OPENMC_MPI
197
  broadcast_results();
198
#endif
199

200
  // Write tally results to tallies.out
201
  if (settings::output_tallies && mpi::master)
1,854!
202
    write_tallies();
1,761✔
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 &&
1,854✔
209
      FlatSourceDomain::solve_ != RandomRaySolve::FORWARD_FOR_ADJOINT) {
36✔
210
    openmc_weight_windows_export();
24✔
211
  }
212

213
  // Deactivate all tallies
214
  for (auto& t : model::tallies) {
7,803✔
215
    t->active_ = false;
5,949✔
216
  }
217

218
  // Stop timers and show timing statistics
219
  simulation::time_finalize.stop();
1,854✔
220
  simulation::time_total.stop();
1,854✔
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) {
227
    int64_t total_tracks;
228
    MPI_Reduce(&simulation::simulation_tracks_completed, &total_tracks, 1,
229
      MPI_INT64_T, MPI_SUM, 0, mpi::intracomm);
230
    if (mpi::master)
231
      simulation::simulation_tracks_completed = total_tracks;
232
  }
233
#endif
234

235
  if (mpi::master) {
1,854!
236
    if (settings::solver_type != SolverType::RANDOM_RAY) {
1,854✔
237
      if (settings::verbosity >= 6)
1,677✔
238
        print_runtime();
1,569✔
239
      if (settings::verbosity >= 4)
1,677✔
240
        print_results();
1,569✔
241
    }
242
  }
243
  if (settings::check_overlaps)
1,854!
244
    print_overlap_check();
×
245

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

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

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

262
  initialize_batch();
35,721✔
263

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

268
    initialize_generation();
35,763✔
269

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

273
    // Transport loop
274
    if (settings::event_based) {
35,763!
UNCOV
275
      if (settings::use_shared_secondary_bank) {
×
UNCOV
276
        transport_event_based_shared_secondary();
×
277
      } else {
UNCOV
278
        transport_event_based();
×
279
      }
280
    } else {
281
      if (settings::use_shared_secondary_bank) {
35,763✔
282
        transport_history_based_shared_secondary();
156✔
283
      } else {
284
        transport_history_based();
35,607✔
285
      }
286
    }
287

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

291
    finalize_generation();
35,757✔
292
  }
293

294
  finalize_batch();
35,715✔
295

296
  // Check simulation ending criteria
297
  if (status) {
35,715!
298
    if (simulation::current_batch >= settings::n_max_batches) {
35,715✔
299
      *status = STATUS_EXIT_MAX_BATCH;
1,662✔
300
    } else if (simulation::satisfy_triggers) {
34,053✔
301
      *status = STATUS_EXIT_ON_TRIGGER;
21✔
302
    } else {
303
      *status = STATUS_EXIT_NORMAL;
34,032✔
304
    }
305
  }
306
  return 0;
307
}
308

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

314
  if (!simulation::initialized)
855!
315
    return false;
316
  else
317
    return contains(settings::statepoint_batch, simulation::current_batch);
1,710✔
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()
1,860✔
362
{
363
  if (settings::run_mode == RunMode::EIGENVALUE &&
1,860✔
364
      settings::solver_type == SolverType::MONTE_CARLO) {
1,038✔
365
    // Allocate source bank
366
    simulation::source_bank.resize(simulation::work_per_rank);
963✔
367

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

371
    // Allocate IFP bank
372
    if (settings::ifp_on) {
963✔
373
      resize_simulation_ifp_banks();
18✔
374
    }
375
  }
376

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

382
  if (settings::collision_track) {
1,860✔
383
    // Allocate collision track bank
384
    collision_track_reserve_bank();
36✔
385
  }
386
}
1,860✔
387

388
void initialize_batch()
40,071✔
389
{
390
  // Increment current batch
391
  ++simulation::current_batch;
40,071✔
392
  if (settings::run_mode == RunMode::FIXED_SOURCE) {
40,071✔
393
    if (settings::solver_type == SolverType::RANDOM_RAY &&
16,329✔
394
        simulation::current_batch < settings::n_inactive + 1) {
2,820✔
395
      write_message(
3,360✔
396
        6, "Simulating batch {:<4} (inactive)", simulation::current_batch);
397
    } else {
398
      write_message(6, "Simulating batch {}", simulation::current_batch);
29,298✔
399
    }
400
  }
401

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

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

416
  // Manage active/inactive timers and activate tallies if necessary.
417
  if (first_inactive) {
40,044✔
418
    simulation::time_inactive.start();
870✔
419
  } else if (first_active) {
39,201✔
420
    simulation::time_inactive.stop();
1,848✔
421
    simulation::time_active.start();
1,848✔
422
    for (auto& t : model::tallies) {
7,791✔
423
      t->active_ = true;
5,943✔
424
    }
425
  }
426

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

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

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

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

449
  // Check_triggers
450
  if (mpi::master)
40,065!
451
    check_triggers();
40,065✔
452
#ifdef OPENMC_MPI
453
  MPI_Bcast(&simulation::satisfy_triggers, 1, MPI_C_BOOL, 0, mpi::intracomm);
454
#endif
455
  if (simulation::satisfy_triggers ||
40,065✔
456
      (settings::trigger_on &&
615✔
457
        simulation::current_batch == settings::n_max_batches)) {
615✔
458
    settings::statepoint_batch.insert(simulation::current_batch);
33✔
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) &&
80,130✔
464
      !settings::cmfd_run) {
1,917✔
465
    if (contains(settings::sourcepoint_batch, simulation::current_batch) &&
3,672✔
466
        settings::source_write && !settings::source_separate) {
3,495✔
467
      bool b = (settings::run_mode == RunMode::EIGENVALUE);
1,611✔
468
      openmc_statepoint_write(nullptr, &b);
1,611✔
469
    } else {
470
      bool b = false;
258✔
471
      openmc_statepoint_write(nullptr, &b);
258✔
472
    }
473
  }
474

475
  if (settings::run_mode == RunMode::EIGENVALUE) {
40,065✔
476
    // Write out a separate source point if it's been specified for this batch
477
    if (contains(settings::sourcepoint_batch, simulation::current_batch) &&
24,786✔
478
        settings::source_write && settings::source_separate) {
24,711✔
479

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

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

498
  // Write out surface source if requested.
499
  if (settings::surf_source_write &&
40,065✔
500
      simulation::ssw_current_file <= settings::ssw_max_files) {
4,872✔
501
    bool last_batch = (simulation::current_batch == settings::n_batches);
552✔
502
    if (simulation::surf_source_bank.full() || last_batch) {
552✔
503
      // Determine appropriate filename
504
      auto filename = fmt::format("{}surface_source.{}", settings::path_output,
330✔
505
        simulation::current_batch);
330✔
506
      if (settings::ssw_max_files == 1 ||
330✔
507
          (simulation::ssw_current_file == 1 && last_batch)) {
15!
508
        filename = settings::path_output + "surface_source";
315✔
509
      }
510

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

517
      // Write surface source file
518
      write_source_point(
330✔
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();
330✔
523
      if (!last_batch && settings::ssw_max_files >= 1) {
330!
524
        simulation::surf_source_bank.reserve(settings::ssw_max_particles);
279✔
525
      }
526
      ++simulation::ssw_current_file;
330✔
527
    }
330✔
528
  }
529
  // Write collision track file if requested
530
  if (settings::collision_track) {
40,065✔
531
    collision_track_flush_bank();
120✔
532
  }
533
}
40,065✔
534

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

541
    // Count source sites if using uniform fission source weighting
542
    if (settings::ufs_on)
23,784✔
543
      ufs_count_sites();
30✔
544

545
    // Store current value of tracklength k
546
    simulation::keff_generation = simulation::global_tallies(
23,784✔
547
      GlobalTally::K_TRACKLENGTH, TallyResult::VALUE);
548
  }
549
}
40,113✔
550

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

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

565
  // reset tallies
566
  if (settings::run_mode == RunMode::EIGENVALUE) {
40,107✔
567
    global_tally_collision = 0.0;
23,784✔
568
    global_tally_absorption = 0.0;
23,784✔
569
    global_tally_tracklength = 0.0;
23,784✔
570
  }
571
  global_tally_leakage = 0.0;
40,107✔
572

573
  if (settings::run_mode == RunMode::EIGENVALUE &&
40,107✔
574
      settings::solver_type == SolverType::MONTE_CARLO) {
23,784✔
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);
22,254✔
579

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

584
  if (settings::run_mode == RunMode::EIGENVALUE) {
40,107✔
585

586
    // Calculate shannon entropy
587
    if (settings::entropy_on &&
23,784✔
588
        settings::solver_type == SolverType::MONTE_CARLO)
3,615✔
589
      shannon_entropy();
2,085✔
590

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

595
    // Write generation output
596
    if (mpi::master && settings::verbosity >= 7) {
23,784!
597
      print_generation();
20,754✔
598
    }
599
  }
600
}
40,107✔
601

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

617
void initialize_particle_track(
54,336,246✔
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) {
54,336,246✔
624
    sample_source_particle(p, index_source);
48,502,050✔
625
  }
626

627
  p.current_work() = index_source - 1;
54,336,243✔
628

629
  // set identifier for particle
630
  p.id() = compute_particle_id(index_source);
54,336,243✔
631

632
  // set progeny count to zero
633
  p.n_progeny() = 0;
54,336,243✔
634

635
  // Reset particle event counter
636
  p.n_event() = 0;
54,336,243✔
637

638
  // Initialize track counter (1 for this primary/secondary track)
639
  p.n_tracks() = 1;
54,336,243✔
640

641
  // Reset split counter
642
  p.n_split() = 0;
54,336,243✔
643

644
  // Reset weight window ratio
645
  p.ww_factor() = 0.0;
54,336,243✔
646

647
  // set particle history start weight
648
  p.wgt_born() = p.wgt();
54,336,243✔
649

650
  // Reset pulse_height_storage
651
  std::fill(p.pht_storage().begin(), p.pht_storage().end(), 0);
54,336,243✔
652

653
  // set random number seed
654
  int64_t particle_seed = compute_transport_seed(p.id());
54,336,243✔
655
  init_particle_seeds(particle_seed, p.seeds());
54,336,243✔
656

657
  // set particle trace
658
  p.trace() = false;
54,336,243✔
659
  if (simulation::current_batch == settings::trace_batch &&
54,339,243✔
660
      simulation::current_gen == settings::trace_gen &&
54,336,243!
661
      p.id() == settings::trace_particle)
3,000✔
662
    p.trace() = true;
3✔
663

664
  // Set particle track.
665
  p.write_track() = check_track_criteria(p);
54,336,243✔
666

667
  // Set the particle's initial weight window value.
668
  if (!is_secondary) {
54,336,243✔
669
    p.wgt_ww_born() = -1.0;
48,502,047✔
670
    apply_weight_windows(p);
48,502,047✔
671
  }
672

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

678
  // Add particle's starting weight to count for normalizing tallies later
679
  if (!is_secondary) {
54,336,243✔
680
#pragma omp atomic
681
    simulation::total_weight += p.wgt();
48,502,047✔
682
  }
683

684
  // Force calculation of cross-sections by setting last energy to zero
685
  if (settings::run_CE) {
54,336,243✔
686
    p.invalidate_neutron_xs();
23,095,731✔
687
  }
688

689
  // Prepare to write out particle track.
690
  if (p.write_track())
54,336,243✔
691
    add_particle_track(p);
207✔
692
}
54,336,243✔
693

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

700
int64_t compute_particle_id(int64_t index_source)
61,951,368✔
701
{
702
  if (settings::use_shared_secondary_bank) {
61,951,368✔
703
    return simulation::work_index[mpi::rank] + index_source +
6,261,141✔
704
           simulation::simulation_tracks_completed;
6,261,141✔
705
  } else {
706
    return simulation::work_index[mpi::rank] + index_source;
55,690,227✔
707
  }
708
}
709

710
int64_t compute_transport_seed(int64_t particle_id)
61,951,380✔
711
{
712
  if (settings::use_shared_secondary_bank) {
61,951,380✔
713
    return particle_id;
714
  } else {
715
    return (simulation::total_gen + overall_generation() - 1) *
55,690,236✔
716
             settings::n_particles +
717
           particle_id;
55,690,236✔
718
  }
719
}
720

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

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

729
  int64_t i_bank = 0;
3,921✔
730
  simulation::work_index.resize(mpi::n_procs + 1);
3,921✔
731
  simulation::work_index[0] = 0;
3,921✔
732
  for (int i = 0; i < mpi::n_procs; ++i) {
7,842✔
733
    // Number of particles for rank i
734
    int64_t work_i = i < remainder ? min_work + 1 : min_work;
3,921!
735

736
    // Set number of particles
737
    if (mpi::rank == i)
3,921!
738
      simulation::work_per_rank = work_i;
3,921✔
739

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

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

752
  for (const auto& nuc : data::nuclides) {
10,065✔
753
    if (nuc->grid_.size() >= 1) {
8,478!
754
      int neutron = ParticleType::neutron().transport_index();
8,478✔
755
      data::energy_min[neutron] =
8,478✔
756
        std::max(data::energy_min[neutron], nuc->grid_[0].energy.front());
9,927✔
757
      data::energy_max[neutron] =
8,478✔
758
        std::min(data::energy_max[neutron], nuc->grid_[0].energy.back());
10,320✔
759
    }
760
  }
761

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

774
    if (settings::electron_treatment == ElectronTreatment::TTB) {
126✔
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) {
111!
778
        int photon = ParticleType::photon().transport_index();
111✔
779
        int electron = ParticleType::electron().transport_index();
111✔
780
        int positron = ParticleType::positron().transport_index();
111✔
781
        int n_e = data::ttb_e_grid.size();
111✔
782

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

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

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

798
  // Show which nuclide results in lowest energy for neutron transport
799
  for (const auto& nuc : data::nuclides) {
1,992✔
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) {
1,854!
803
      double max_E = nuc->grid_[0].energy.back();
1,854✔
804
      int neutron = ParticleType::neutron().transport_index();
1,854✔
805
      if (max_E == data::energy_max[neutron]) {
1,854✔
806
        write_message(7, "Maximum neutron transport energy: {} eV for {}",
1,449✔
807
          data::energy_max[neutron], nuc->name_);
1,449✔
808
        if (mpi::master && data::energy_max[neutron] < 20.0e6) {
1,449!
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) {
10,065✔
819
    nuc->init_grid();
8,478✔
820
  }
821
  int neutron = ParticleType::neutron().transport_index();
1,587✔
822
  simulation::log_spacing =
3,174✔
823
    std::log(data::energy_max[neutron] / data::energy_min[neutron]) /
1,587✔
824
    settings::n_log_bins;
825
}
1,587✔
826

827
#ifdef OPENMC_MPI
828
void broadcast_results()
829
{
830
  // Broadcast tally results so that each process has access to results
831
  for (auto& t : model::tallies) {
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_;
836

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

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

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

860
#endif
861

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

868
void transport_history_based_single_particle(Particle& p)
54,336,255✔
869
{
870
  while (p.alive()) {
1,673,886,316✔
871
    p.event_calculate_xs();
1,619,550,064✔
872
    if (p.alive()) {
1,619,550,064!
873
      p.event_advance();
1,619,550,064✔
874
    }
875
    if (p.alive()) {
1,619,550,064✔
876
      if (p.collision_distance() > p.boundary().distance()) {
1,619,488,720✔
877
        p.event_cross_surface();
723,181,243✔
878
      } else if (p.alive()) {
896,307,477✔
879
        p.event_collide();
896,307,477✔
880
      }
881
    }
882
    p.event_check_limit_and_revive();
1,619,550,061✔
883
  }
884
  p.event_death();
54,336,252✔
885
}
54,336,252✔
886

887
void transport_history_based()
35,607✔
888
{
889
#pragma omp parallel
890
  {
35,607✔
891
    Particle p;
35,607✔
892
#pragma omp for schedule(runtime)
893
    for (int64_t i_work = 1; i_work <= simulation::work_per_rank; ++i_work) {
48,324,186✔
894
      initialize_particle_track(p, i_work, false);
48,288,585✔
895
      transport_history_based_single_particle(p);
48,288,582✔
896
    }
897
  }
35,601✔
898
}
35,601✔
899

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

914
  if (mpi::master) {
156!
915
    write_message(fmt::format(" Primary source          particles: {}",
312✔
916
                    settings::n_particles),
917
      6);
918
  }
919

920
  simulation::progeny_per_particle.resize(simulation::work_per_rank);
156✔
921
  std::fill(simulation::progeny_per_particle.begin(),
312✔
922
    simulation::progeny_per_particle.end(), 0);
156✔
923

924
  // Phase 1: Transport primary particles and deposit first generation of
925
  // secondaries in the shared secondary bank
926
#pragma omp parallel
927
  {
156✔
928
    vector<SourceSite> thread_bank;
156✔
929
    Particle p;
156✔
930

931
#pragma omp for schedule(runtime)
932
    for (int64_t i = 1; i <= simulation::work_per_rank; i++) {
213,621✔
933
      initialize_particle_track(p, i, false);
213,465✔
934
      transport_history_based_single_particle(p);
213,465✔
935
      for (auto& site : p.local_secondary_bank()) {
652,335✔
936
        thread_bank.push_back(site);
438,870✔
937
      }
938
      p.local_secondary_bank().clear();
266,700✔
939
    }
940

941
    // Drain thread-local bank into the shared secondary bank (once per thread)
942
#pragma omp critical(SharedSecondaryBank)
943
    {
156✔
944
      for (auto& site : thread_bank) {
439,026✔
945
        simulation::shared_secondary_bank_write.thread_unsafe_append(site);
438,870✔
946
      }
947
    }
948
  }
156✔
949

950
  simulation::simulation_tracks_completed += settings::n_particles;
156✔
951

952
  // Phase 2: Now that the secondary bank has been populated, enter loop over
953
  // all secondary generations
954
  int n_generation_depth = 1;
156✔
955
  int64_t alive_secondary = 1;
156✔
956
  while (alive_secondary) {
2,061✔
957

958
    // Sort the shared secondary bank by parent ID then progeny ID to
959
    // ensure reproducibility.
960
    sort_bank(simulation::shared_secondary_bank_write, false);
1,905✔
961

962
    // Synchronize the shared secondary bank amongst all MPI ranks, such
963
    // that each MPI rank has an approximately equal number of secondary
964
    // tracks. Also reports the total number of secondaries alive across
965
    // all MPI ranks.
966
    alive_secondary = synchronize_global_secondary_bank(
1,905✔
967
      simulation::shared_secondary_bank_write);
968

969
    // Recalculate work for each MPI rank based on number of alive secondary
970
    // tracks
971
    calculate_work(alive_secondary);
1,905✔
972

973
    // Display the number of secondary tracks in this generation. This
974
    // is useful for user monitoring so as to see if the secondary population is
975
    // exploding and to determine how many generations of secondaries are being
976
    // transported.
977
    if (mpi::master) {
1,905!
978
      write_message(fmt::format(" Secondary generation {:<2}    tracks: {}",
3,810✔
979
                      n_generation_depth, alive_secondary),
980
        6);
981
    }
982

983
    simulation::shared_secondary_bank_read =
1,905✔
984
      std::move(simulation::shared_secondary_bank_write);
1,905✔
985
    simulation::shared_secondary_bank_write = SharedArray<SourceSite>();
1,905!
986
    simulation::progeny_per_particle.resize(
1,905✔
987
      simulation::shared_secondary_bank_read.size());
1,905✔
988
    std::fill(simulation::progeny_per_particle.begin(),
3,810✔
989
      simulation::progeny_per_particle.end(), 0);
1,905✔
990

991
    // Transport all secondary tracks from the shared secondary bank
992
#pragma omp parallel
993
    {
1,905✔
994
      vector<SourceSite> thread_bank;
1,905✔
995
      Particle p;
1,905✔
996

997
#pragma omp for schedule(runtime)
998
      for (int64_t i = 1; i <= simulation::shared_secondary_bank_read.size();
5,836,101✔
999
           i++) {
1000
        initialize_particle_track(p, i, true);
5,834,196✔
1001
        SourceSite& site = simulation::shared_secondary_bank_read[i - 1];
5,834,196✔
1002
        p.event_revive_from_secondary(site);
5,834,196✔
1003
        transport_history_based_single_particle(p);
5,834,196✔
1004
        for (auto& secondary_site : p.local_secondary_bank()) {
11,229,522✔
1005
          thread_bank.push_back(secondary_site);
5,395,326✔
1006
        }
1007
        p.local_secondary_bank().clear();
6,713,514✔
1008
      }
1009

1010
      // Drain thread-local bank into the shared secondary bank (once per
1011
      // thread)
1012
#pragma omp critical(SharedSecondaryBank)
1013
      {
1,905✔
1014
        for (auto& secondary_site : thread_bank) {
5,397,231✔
1015
          simulation::shared_secondary_bank_write.thread_unsafe_append(
5,395,326✔
1016
            secondary_site);
1017
        }
1018
      }
1019
    } // End of transport loop over tracks in shared secondary bank
1,905✔
1020
    n_generation_depth++;
1,905✔
1021
    simulation::simulation_tracks_completed += alive_secondary;
1,905✔
1022
  } // End of loop over secondary generations
1023

1024
  // Reset work so that fission bank etc works correctly
1025
  calculate_work(settings::n_particles);
156✔
1026
}
156✔
1027

UNCOV
1028
void transport_event_based()
×
1029
{
UNCOV
1030
  int64_t remaining_work = simulation::work_per_rank;
×
UNCOV
1031
  int64_t source_offset = 0;
×
1032

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

1043
    // Initialize all particle histories for this subiteration
UNCOV
1044
    process_init_events(n_particles, source_offset);
×
UNCOV
1045
    process_transport_events();
×
UNCOV
1046
    process_death_events(n_particles);
×
1047

1048
    // Adjust remaining work and source offset variables
UNCOV
1049
    remaining_work -= n_particles;
×
UNCOV
1050
    source_offset += n_particles;
×
1051
  }
UNCOV
1052
}
×
1053

UNCOV
1054
void transport_event_based_shared_secondary()
×
1055
{
1056
  // Clear shared secondary banks from any prior use
UNCOV
1057
  simulation::shared_secondary_bank_read.clear();
×
UNCOV
1058
  simulation::shared_secondary_bank_write.clear();
×
1059

UNCOV
1060
  if (mpi::master) {
×
UNCOV
1061
    write_message(fmt::format(" Primary source          particles: {}",
×
1062
                    settings::n_particles),
1063
      6);
1064
  }
1065

UNCOV
1066
  simulation::progeny_per_particle.resize(simulation::work_per_rank);
×
UNCOV
1067
  std::fill(simulation::progeny_per_particle.begin(),
×
UNCOV
1068
    simulation::progeny_per_particle.end(), 0);
×
1069

1070
  // Phase 1: Transport primary particles using event-based processing and
1071
  // deposit first generation of secondaries in the shared secondary bank
UNCOV
1072
  int64_t remaining_work = simulation::work_per_rank;
×
UNCOV
1073
  int64_t source_offset = 0;
×
1074

UNCOV
1075
  while (remaining_work > 0) {
×
UNCOV
1076
    int64_t n_particles =
×
UNCOV
1077
      std::min(remaining_work, settings::max_particles_in_flight);
×
1078

UNCOV
1079
    process_init_events(n_particles, source_offset);
×
UNCOV
1080
    process_transport_events();
×
UNCOV
1081
    process_death_events(n_particles);
×
1082

1083
    // Collect secondaries from all particle buffers into shared bank
UNCOV
1084
    for (int64_t i = 0; i < n_particles; i++) {
×
UNCOV
1085
      for (auto& site : simulation::particles[i].local_secondary_bank()) {
×
UNCOV
1086
        simulation::shared_secondary_bank_write.thread_unsafe_append(site);
×
1087
      }
UNCOV
1088
      simulation::particles[i].local_secondary_bank().clear();
×
1089
    }
1090

UNCOV
1091
    remaining_work -= n_particles;
×
UNCOV
1092
    source_offset += n_particles;
×
1093
  }
1094

UNCOV
1095
  simulation::simulation_tracks_completed += settings::n_particles;
×
1096

1097
  // Phase 2: Now that the secondary bank has been populated, enter loop over
1098
  // all secondary generations
UNCOV
1099
  int n_generation_depth = 1;
×
UNCOV
1100
  int64_t alive_secondary = 1;
×
UNCOV
1101
  while (alive_secondary) {
×
1102

1103
    // Sort the shared secondary bank by parent ID then progeny ID to
1104
    // ensure reproducibility.
UNCOV
1105
    sort_bank(simulation::shared_secondary_bank_write, false);
×
1106

1107
    // Synchronize the shared secondary bank amongst all MPI ranks, such
1108
    // that each MPI rank has an approximately equal number of secondary
1109
    // tracks.
UNCOV
1110
    alive_secondary = synchronize_global_secondary_bank(
×
1111
      simulation::shared_secondary_bank_write);
1112

1113
    // Recalculate work for each MPI rank based on number of alive secondary
1114
    // tracks
UNCOV
1115
    calculate_work(alive_secondary);
×
1116

UNCOV
1117
    if (mpi::master) {
×
UNCOV
1118
      write_message(fmt::format(" Secondary generation {:<2}    tracks: {}",
×
1119
                      n_generation_depth, alive_secondary),
1120
        6);
1121
    }
1122

UNCOV
1123
    simulation::shared_secondary_bank_read =
×
UNCOV
1124
      std::move(simulation::shared_secondary_bank_write);
×
UNCOV
1125
    simulation::shared_secondary_bank_write = SharedArray<SourceSite>();
×
UNCOV
1126
    simulation::progeny_per_particle.resize(
×
UNCOV
1127
      simulation::shared_secondary_bank_read.size());
×
UNCOV
1128
    std::fill(simulation::progeny_per_particle.begin(),
×
UNCOV
1129
      simulation::progeny_per_particle.end(), 0);
×
1130

1131
    // Ensure particle buffer is large enough for this secondary generation
UNCOV
1132
    int64_t sec_buffer_length = std::min(
×
UNCOV
1133
      static_cast<int64_t>(simulation::shared_secondary_bank_read.size()),
×
UNCOV
1134
      settings::max_particles_in_flight);
×
UNCOV
1135
    if (sec_buffer_length >
×
UNCOV
1136
        static_cast<int64_t>(simulation::particles.size())) {
×
UNCOV
1137
      init_event_queues(sec_buffer_length);
×
1138
    }
1139

1140
    // Transport secondary tracks using event-based processing
UNCOV
1141
    int64_t sec_remaining = simulation::shared_secondary_bank_read.size();
×
UNCOV
1142
    int64_t sec_offset = 0;
×
1143

UNCOV
1144
    while (sec_remaining > 0) {
×
UNCOV
1145
      int64_t n_particles =
×
UNCOV
1146
        std::min(sec_remaining, settings::max_particles_in_flight);
×
1147

UNCOV
1148
      process_init_secondary_events(
×
1149
        n_particles, sec_offset, simulation::shared_secondary_bank_read);
UNCOV
1150
      process_transport_events();
×
UNCOV
1151
      process_death_events(n_particles);
×
1152

1153
      // Collect secondaries from all particle buffers into shared bank
UNCOV
1154
      for (int64_t i = 0; i < n_particles; i++) {
×
UNCOV
1155
        for (auto& site : simulation::particles[i].local_secondary_bank()) {
×
UNCOV
1156
          simulation::shared_secondary_bank_write.thread_unsafe_append(site);
×
1157
        }
UNCOV
1158
        simulation::particles[i].local_secondary_bank().clear();
×
1159
      }
1160

UNCOV
1161
      sec_remaining -= n_particles;
×
UNCOV
1162
      sec_offset += n_particles;
×
1163
    } // End of subiteration loop over secondary tracks
UNCOV
1164
    n_generation_depth++;
×
UNCOV
1165
    simulation::simulation_tracks_completed += alive_secondary;
×
1166
  } // End of loop over secondary generations
1167

1168
  // Reset work so that fission bank etc works correctly
UNCOV
1169
  calculate_work(settings::n_particles);
×
UNCOV
1170
}
×
1171

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