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

openmc-dev / openmc / 26767292096

01 Jun 2026 04:17PM UTC coverage: 81.157% (-0.2%) from 81.356%
26767292096

Pull #3874

github

web-flow
Merge de5087f00 into 111eb7706
Pull Request #3874: Fix a bug in compton scattering shell selection

17392 of 24989 branches covered (69.6%)

Branch coverage included in aggregate %.

22 of 23 new or added lines in 1 file covered. (95.65%)

366 existing lines in 29 files now uncovered.

58181 of 68131 relevant lines covered (85.4%)

40636250.11 hits per line

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

83.42
/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/settings.h"
20
#include "openmc/source.h"
21
#include "openmc/state_point.h"
22
#include "openmc/tallies/derivative.h"
23
#include "openmc/tallies/filter.h"
24
#include "openmc/tallies/tally.h"
25
#include "openmc/tallies/trigger.h"
26
#include "openmc/timer.h"
27
#include "openmc/track_output.h"
28
#include "openmc/weight_windows.h"
29

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

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

39
#include <fmt/format.h>
40

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

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

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

53
int openmc_run()
3,871✔
54
{
55
  openmc::simulation::time_total.start();
3,871✔
56
  openmc_simulation_init();
3,871✔
57

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

65
  int err = 0;
66
  while (status == 0 && err == 0) {
87,803✔
67
    err = openmc_next_batch(&status);
83,942✔
68
  }
69

70
  openmc_simulation_finalize();
3,861✔
71
  openmc::simulation::time_total.stop();
3,861✔
72
  return err;
3,861✔
73
}
74

75
int openmc_simulation_init()
4,525✔
76
{
77
  using namespace openmc;
4,525✔
78

79
  // Skip if simulation has already been initialized
80
  if (simulation::initialized)
4,525✔
81
    return 0;
82

83
  // Initialize nuclear data (energy limits, log grid)
84
  if (settings::run_CE) {
4,511✔
85
    initialize_data();
3,755✔
86
  }
87

88
  // Determine how much work each process should do
89
  calculate_work(settings::n_particles);
4,511✔
90

91
  // Allocate source, fission and surface source banks.
92
  allocate_banks();
4,511✔
93

94
  // Create track file if needed
95
  if (!settings::track_identifiers.empty() || settings::write_all_tracks) {
4,511✔
96
    open_track_file();
48✔
97
  }
98

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

107
  // Allocate tally results arrays if they're not allocated yet
108
  for (auto& t : model::tallies) {
19,744✔
109
    t->set_strides();
15,233✔
110
    t->init_results();
15,233✔
111
  }
112

113
  // Set up material nuclide index mapping
114
  for (auto& mat : model::materials) {
16,600✔
115
    mat->init_nuclide_index();
12,089✔
116
  }
117

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

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

141
  // Display header
142
  if (mpi::master) {
4,511✔
143
    if (settings::run_mode == RunMode::FIXED_SOURCE) {
4,264✔
144
      if (settings::solver_type == SolverType::MONTE_CARLO) {
1,839✔
145
        header("FIXED SOURCE TRANSPORT SIMULATION", 3);
1,601✔
146
      } else if (settings::solver_type == SolverType::RANDOM_RAY) {
238!
147
        header("FIXED SOURCE TRANSPORT SIMULATION (RANDOM RAY SOLVER)", 3);
238✔
148
      }
149
    } else if (settings::run_mode == RunMode::EIGENVALUE) {
2,425!
150
      if (settings::solver_type == SolverType::MONTE_CARLO) {
2,425✔
151
        header("K EIGENVALUE SIMULATION", 3);
2,250✔
152
      } else if (settings::solver_type == SolverType::RANDOM_RAY) {
175!
153
        header("K EIGENVALUE SIMULATION (RANDOM RAY SOLVER)", 3);
175✔
154
      }
155
      if (settings::verbosity >= 7)
2,425✔
156
        print_columns();
2,177✔
157
    }
158
  }
159

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

165
  // Set flag indicating initialization is done
166
  simulation::initialized = true;
4,511✔
167
  return 0;
4,511✔
168
}
169

170
int openmc_simulation_finalize()
4,501✔
171
{
172
  using namespace openmc;
4,501✔
173

174
  // Skip if simulation was never run
175
  if (!simulation::initialized)
4,501!
176
    return 0;
177

178
  // Stop active batch timer and start finalization timer
179
  simulation::time_active.stop();
4,501✔
180
  simulation::time_finalize.start();
4,501✔
181

182
  // Clear material nuclide mapping
183
  for (auto& mat : model::materials) {
16,580✔
184
    mat->mat_nuclide_index_.clear();
24,158!
185
  }
186

187
  // Close track file if open
188
  if (!settings::track_identifiers.empty() || settings::write_all_tracks) {
4,501✔
189
    close_track_file();
48✔
190
  }
191

192
  // Increment total number of generations
193
  simulation::total_gen += simulation::current_batch * settings::gen_per_batch;
4,501✔
194

195
#ifdef OPENMC_MPI
196
  broadcast_results();
849✔
197
#endif
198

199
  // Write tally results to tallies.out
200
  if (settings::output_tallies && mpi::master)
4,501!
201
    write_tallies();
4,037✔
202

203
  // If weight window generators are present in this simulation,
204
  // write a weight windows file
205
  if (variance_reduction::weight_windows_generators.size() > 0) {
4,501✔
206
    openmc_weight_windows_export();
92✔
207
  }
208

209
  // Deactivate all tallies
210
  for (auto& t : model::tallies) {
19,734✔
211
    t->active_ = false;
15,233✔
212
  }
213

214
  // Stop timers and show timing statistics
215
  simulation::time_finalize.stop();
4,501✔
216
  simulation::time_total.stop();
4,501✔
217

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

231
  if (mpi::master) {
4,501✔
232
    if (settings::solver_type != SolverType::RANDOM_RAY) {
4,254✔
233
      if (settings::verbosity >= 6)
3,841✔
234
        print_runtime();
3,593✔
235
      if (settings::verbosity >= 4)
3,841✔
236
        print_results();
3,593✔
237
    }
238
  }
239
  if (settings::check_overlaps)
4,501!
240
    print_overlap_check();
×
241

242
  // Reset flags
243
  simulation::initialized = false;
4,501✔
244
  return 0;
4,501✔
245
}
246

247
int openmc_next_batch(int* status)
86,567✔
248
{
249
  using namespace openmc;
86,567✔
250
  using openmc::simulation::current_gen;
86,567✔
251

252
  // Make sure simulation has been initialized
253
  if (!simulation::initialized) {
86,567✔
254
    set_errmsg("Simulation has not been initialized yet.");
7✔
255
    return OPENMC_E_ALLOCATE;
7✔
256
  }
257

258
  initialize_batch();
86,560✔
259

260
  // =======================================================================
261
  // LOOP OVER GENERATIONS
262
  for (current_gen = 1; current_gen <= settings::gen_per_batch; ++current_gen) {
173,222✔
263

264
    initialize_generation();
86,672✔
265

266
    // Start timer for transport
267
    simulation::time_transport.start();
86,672✔
268

269
    // Transport loop
270
    if (settings::event_based) {
86,672!
UNCOV
271
      if (settings::use_shared_secondary_bank) {
×
UNCOV
272
        transport_event_based_shared_secondary();
×
273
      } else {
UNCOV
274
        transport_event_based();
×
275
      }
276
    } else {
277
      if (settings::use_shared_secondary_bank) {
86,672✔
278
        transport_history_based_shared_secondary();
389✔
279
      } else {
280
        transport_history_based();
86,283✔
281
      }
282
    }
283

284
    // Accumulate time for transport
285
    simulation::time_transport.stop();
86,662✔
286

287
    finalize_generation();
86,662✔
288
  }
289

290
  finalize_batch();
86,550✔
291

292
  // Check simulation ending criteria
293
  if (status) {
86,550!
294
    if (simulation::current_batch >= settings::n_max_batches) {
86,550✔
295
      *status = STATUS_EXIT_MAX_BATCH;
3,990✔
296
    } else if (simulation::satisfy_triggers) {
82,560✔
297
      *status = STATUS_EXIT_ON_TRIGGER;
53✔
298
    } else {
299
      *status = STATUS_EXIT_NORMAL;
82,507✔
300
    }
301
  }
302
  return 0;
303
}
304

305
bool openmc_is_statepoint_batch()
1,995✔
306
{
307
  using namespace openmc;
1,995✔
308
  using openmc::simulation::current_gen;
1,995✔
309

310
  if (!simulation::initialized)
1,995!
311
    return false;
312
  else
313
    return contains(settings::statepoint_batch, simulation::current_batch);
3,990✔
314
}
315

316
namespace openmc {
317

318
//==============================================================================
319
// Global variables
320
//==============================================================================
321

322
namespace simulation {
323

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

343
const RegularMesh* entropy_mesh {nullptr};
344
const RegularMesh* ufs_mesh {nullptr};
345

346
vector<double> k_generation;
347
vector<int64_t> work_index;
348

349
int64_t simulation_tracks_completed {0};
350

351
} // namespace simulation
352

353
//==============================================================================
354
// Non-member functions
355
//==============================================================================
356

357
void allocate_banks()
4,511✔
358
{
359
  if (settings::run_mode == RunMode::EIGENVALUE &&
4,511✔
360
      settings::solver_type == SolverType::MONTE_CARLO) {
2,597✔
361
    // Allocate source bank
362
    simulation::source_bank.resize(simulation::work_per_rank);
2,398✔
363

364
    // Allocate fission bank
365
    init_fission_bank(3 * simulation::work_per_rank);
2,398✔
366

367
    // Allocate IFP bank
368
    if (settings::ifp_on) {
2,398✔
369
      resize_simulation_ifp_banks();
44✔
370
    }
371
  }
372

373
  if (settings::surf_source_write) {
4,511✔
374
    // Allocate surface source bank
375
    simulation::surf_source_bank.reserve(settings::ssw_max_particles);
745✔
376
  }
377

378
  if (settings::collision_track) {
4,511✔
379
    // Allocate collision track bank
380
    collision_track_reserve_bank();
84✔
381
  }
382
}
4,511✔
383

384
void initialize_batch()
97,960✔
385
{
386
  // Increment current batch
387
  ++simulation::current_batch;
97,960✔
388
  if (settings::run_mode == RunMode::FIXED_SOURCE) {
97,960✔
389
    if (settings::solver_type == SolverType::RANDOM_RAY &&
39,061✔
390
        simulation::current_batch < settings::n_inactive + 1) {
7,520✔
391
      write_message(
8,960✔
392
        6, "Simulating batch {:<4} (inactive)", simulation::current_batch);
393
    } else {
394
      write_message(6, "Simulating batch {}", simulation::current_batch);
69,162✔
395
    }
396
  }
397

398
  // Reset total starting particle weight used for normalizing tallies
399
  simulation::total_weight = 0.0;
97,960✔
400

401
  // Determine if this batch is the first inactive or active batch.
402
  bool first_inactive = false;
97,960✔
403
  bool first_active = false;
97,960✔
404
  if (!settings::restart_run) {
97,960✔
405
    first_inactive = settings::n_inactive > 0 && simulation::current_batch == 1;
97,864✔
406
    first_active = simulation::current_batch == settings::n_inactive + 1;
97,864✔
407
  } else if (simulation::current_batch == simulation::restart_batch + 1) {
96✔
408
    first_inactive = simulation::restart_batch < settings::n_inactive;
30✔
409
    first_active = !first_inactive;
30✔
410
  }
411

412
  // Manage active/inactive timers and activate tallies if necessary.
413
  if (first_inactive) {
97,894✔
414
    simulation::time_inactive.start();
2,207✔
415
  } else if (first_active) {
95,753✔
416
    simulation::time_inactive.stop();
4,482✔
417
    simulation::time_active.start();
4,482✔
418
    for (auto& t : model::tallies) {
19,701✔
419
      t->active_ = true;
15,219✔
420
    }
421
  }
422

423
  // Add user tallies to active tallies list
424
  setup_active_tallies();
97,960✔
425
}
97,960✔
426

427
void finalize_batch()
97,950✔
428
{
429
  // Reduce tallies onto master process and accumulate
430
  simulation::time_tallies.start();
97,950✔
431
  accumulate_tallies();
97,950✔
432
  simulation::time_tallies.stop();
97,950✔
433

434
  // update weight windows if needed
435
  for (const auto& wwg : variance_reduction::weight_windows_generators) {
99,370✔
436
    wwg->update();
1,420✔
437
  }
438

439
  // Reset global tally results
440
  if (simulation::current_batch <= settings::n_inactive) {
97,950✔
441
    simulation::global_tallies.fill(0.0);
18,630✔
442
    simulation::n_realizations = 0;
18,630✔
443
  }
444

445
  // Check_triggers
446
  if (mpi::master)
97,950✔
447
    check_triggers();
93,264✔
448
#ifdef OPENMC_MPI
449
  MPI_Bcast(&simulation::satisfy_triggers, 1, MPI_C_BOOL, 0, mpi::intracomm);
17,966✔
450
#endif
451
  if (simulation::satisfy_triggers ||
97,950✔
452
      (settings::trigger_on &&
1,513✔
453
        simulation::current_batch == settings::n_max_batches)) {
1,513✔
454
    settings::statepoint_batch.insert(simulation::current_batch);
82✔
455
  }
456

457
  // Write out state point if it's been specified for this batch and is not
458
  // a CMFD run instance
459
  if (contains(settings::statepoint_batch, simulation::current_batch) &&
195,900✔
460
      !settings::cmfd_run) {
4,657✔
461
    if (contains(settings::sourcepoint_batch, simulation::current_batch) &&
8,927✔
462
        settings::source_write && !settings::source_separate) {
8,456✔
463
      bool b = (settings::run_mode == RunMode::EIGENVALUE);
3,872✔
464
      openmc_statepoint_write(nullptr, &b);
3,872✔
465
    } else {
466
      bool b = false;
673✔
467
      openmc_statepoint_write(nullptr, &b);
673✔
468
    }
469
  }
470

471
  if (settings::run_mode == RunMode::EIGENVALUE) {
97,950✔
472
    // Write out a separate source point if it's been specified for this batch
473
    if (contains(settings::sourcepoint_batch, simulation::current_batch) &&
61,511✔
474
        settings::source_write && settings::source_separate) {
61,312✔
475

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

485
    // Write a continously-overwritten source point if requested.
486
    if (settings::source_latest) {
58,899✔
487
      auto filename = settings::path_output + "source";
80✔
488
      span<SourceSite> bankspan(simulation::source_bank);
80✔
489
      write_source_point(filename, bankspan, simulation::work_index,
160✔
490
        settings::source_mcpl_write);
491
    }
80✔
492
  }
493

494
  // Write out surface source if requested.
495
  if (settings::surf_source_write &&
97,950✔
496
      simulation::ssw_current_file <= settings::ssw_max_files) {
11,328✔
497
    bool last_batch = (simulation::current_batch == settings::n_batches);
1,284✔
498
    if (simulation::surf_source_bank.full() || last_batch) {
1,284✔
499
      // Determine appropriate filename
500
      auto filename = fmt::format("{}surface_source.{}", settings::path_output,
766✔
501
        simulation::current_batch);
766✔
502
      if (settings::ssw_max_files == 1 ||
766✔
503
          (simulation::ssw_current_file == 1 && last_batch)) {
35!
504
        filename = settings::path_output + "surface_source";
731✔
505
      }
506

507
      // Get span of source bank and calculate parallel index vector
508
      auto surf_work_index = mpi::calculate_parallel_index_vector(
766✔
509
        simulation::surf_source_bank.size());
766✔
510
      span<SourceSite> surfbankspan(simulation::surf_source_bank.begin(),
766✔
511
        simulation::surf_source_bank.size());
766✔
512

513
      // Write surface source file
514
      write_source_point(
766✔
515
        filename, surfbankspan, surf_work_index, settings::surf_mcpl_write);
516

517
      // Reset surface source bank and increment counter
518
      simulation::surf_source_bank.clear();
766✔
519
      if (!last_batch && settings::ssw_max_files >= 1) {
766!
520
        simulation::surf_source_bank.reserve(settings::ssw_max_particles);
647✔
521
      }
522
      ++simulation::ssw_current_file;
766✔
523
    }
766✔
524
  }
525
  // Write collision track file if requested
526
  if (settings::collision_track) {
97,950✔
527
    collision_track_flush_bank();
336✔
528
  }
529
}
97,950✔
530

531
void initialize_generation()
98,072✔
532
{
533
  if (settings::run_mode == RunMode::EIGENVALUE) {
98,072✔
534
    // Clear out the fission bank
535
    simulation::fission_bank.resize(0);
59,011✔
536

537
    // Count source sites if using uniform fission source weighting
538
    if (settings::ufs_on)
59,011✔
539
      ufs_count_sites();
80✔
540

541
    // Store current value of tracklength k
542
    simulation::keff_generation = simulation::global_tallies(
59,011✔
543
      GlobalTally::K_TRACKLENGTH, TallyResult::VALUE);
544
  }
545
}
98,072✔
546

547
void finalize_generation()
98,062✔
548
{
549
  auto& gt = simulation::global_tallies;
98,062✔
550

551
  // Update global tallies with the accumulation variables
552
  if (settings::run_mode == RunMode::EIGENVALUE) {
98,062✔
553
    gt(GlobalTally::K_COLLISION, TallyResult::VALUE) += global_tally_collision;
59,011✔
554
    gt(GlobalTally::K_ABSORPTION, TallyResult::VALUE) +=
59,011✔
555
      global_tally_absorption;
556
    gt(GlobalTally::K_TRACKLENGTH, TallyResult::VALUE) +=
59,011✔
557
      global_tally_tracklength;
558
  }
559
  gt(GlobalTally::LEAKAGE, TallyResult::VALUE) += global_tally_leakage;
98,062✔
560

561
  // reset tallies
562
  if (settings::run_mode == RunMode::EIGENVALUE) {
98,062✔
563
    global_tally_collision = 0.0;
59,011✔
564
    global_tally_absorption = 0.0;
59,011✔
565
    global_tally_tracklength = 0.0;
59,011✔
566
  }
567
  global_tally_leakage = 0.0;
98,062✔
568

569
  if (settings::run_mode == RunMode::EIGENVALUE &&
98,062✔
570
      settings::solver_type == SolverType::MONTE_CARLO) {
59,011✔
571
    // If using shared memory, stable sort the fission bank (by parent IDs)
572
    // so as to allow for reproducibility regardless of which order particles
573
    // are run in.
574
    sort_bank(simulation::fission_bank, true);
55,131✔
575

576
    // Distribute fission bank across processors evenly
577
    synchronize_bank();
55,131✔
578
  }
579

580
  if (settings::run_mode == RunMode::EIGENVALUE) {
98,062✔
581

582
    // Calculate shannon entropy
583
    if (settings::entropy_on &&
59,011✔
584
        settings::solver_type == SolverType::MONTE_CARLO)
8,755✔
585
      shannon_entropy();
4,875✔
586

587
    // Collect results and statistics
588
    calculate_generation_keff();
59,011✔
589
    calculate_average_keff();
59,011✔
590

591
    // Write generation output
592
    if (mpi::master && settings::verbosity >= 7) {
59,011✔
593
      print_generation();
48,461✔
594
    }
595
  }
596
}
98,062✔
597

598
void sample_source_particle(Particle& p, int64_t index_source)
113,203,712✔
599
{
600
  // Sample a particle from the source bank
601
  if (settings::run_mode == RunMode::EIGENVALUE) {
113,203,712✔
602
    p.from_source(&simulation::source_bank[index_source - 1]);
95,407,400✔
603
  } else if (settings::run_mode == RunMode::FIXED_SOURCE) {
17,796,312!
604
    // initialize random number seed
605
    int64_t id = compute_transport_seed(compute_particle_id(index_source));
17,796,312✔
606
    uint64_t seed = init_seed(id, STREAM_SOURCE);
17,796,312✔
607
    // sample from external source distribution or custom library then set
608
    auto site = sample_external_source(&seed);
17,796,312✔
609
    p.from_source(&site);
17,796,308✔
610
  }
611
}
113,203,708✔
612

613
void initialize_particle_track(
175,483,119✔
614
  Particle& p, int64_t index_source, bool is_secondary)
615
{
616
  // Note: index_source is 1-based (first particle = 1), but current_work() is
617
  // stored as 0-based for direct use as an array index into
618
  // progeny_per_particle, source_bank, ifp banks, etc.
619
  if (!is_secondary) {
175,483,119✔
620
    sample_source_particle(p, index_source);
113,203,712✔
621
  }
622

623
  p.current_work() = index_source - 1;
175,483,115✔
624

625
  // set identifier for particle
626
  p.id() = compute_particle_id(index_source);
175,483,115✔
627

628
  // set progeny count to zero
629
  p.n_progeny() = 0;
175,483,115✔
630

631
  // Reset particle event counter
632
  p.n_event() = 0;
175,483,115✔
633

634
  // Initialize track counter (1 for this primary/secondary track)
635
  p.n_tracks() = 1;
175,483,115✔
636

637
  // Reset split counter
638
  p.n_split() = 0;
175,483,115✔
639

640
  // Reset weight window ratio
641
  p.ww_factor() = 0.0;
175,483,115✔
642

643
  // set particle history start weight
644
  p.wgt_born() = p.wgt();
175,483,115✔
645

646
  // Reset pulse_height_storage
647
  std::fill(p.pht_storage().begin(), p.pht_storage().end(), 0);
175,483,115✔
648

649
  // set random number seed
650
  int64_t particle_seed = compute_transport_seed(p.id());
175,483,115✔
651
  init_particle_seeds(particle_seed, p.seeds());
175,483,115✔
652

653
  // set particle trace
654
  p.trace() = false;
175,483,115✔
655
  if (simulation::current_batch == settings::trace_batch &&
175,490,115✔
656
      simulation::current_gen == settings::trace_gen &&
175,483,115!
657
      p.id() == settings::trace_particle)
7,000✔
658
    p.trace() = true;
7✔
659

660
  // Set particle track.
661
  p.write_track() = check_track_criteria(p);
175,483,115✔
662

663
  // Set the particle's initial weight window value.
664
  if (!is_secondary) {
175,483,115✔
665
    p.wgt_ww_born() = -1.0;
113,203,708✔
666
    apply_weight_windows(p);
113,203,708✔
667
  }
668

669
  // Display message if high verbosity or trace is on
670
  if (settings::verbosity >= 9 || p.trace()) {
175,483,115!
671
    write_message("Simulating Particle {}", p.id());
14✔
672
  }
673

674
  // Add particle's starting weight to count for normalizing tallies later
675
  if (!is_secondary) {
175,483,115✔
676
#pragma omp atomic
32,408,861✔
677
    simulation::total_weight += p.wgt();
113,203,708✔
678
  }
679

680
  // Force calculation of cross-sections by setting last energy to zero
681
  if (settings::run_CE) {
175,483,115✔
682
    p.invalidate_neutron_xs();
102,588,587✔
683
  }
684

685
  // Prepare to write out particle track.
686
  if (p.write_track())
175,483,115✔
687
    add_particle_track(p);
543✔
688
}
175,483,115✔
689

690
int overall_generation()
130,075,279✔
691
{
692
  using namespace simulation;
130,075,279✔
693
  return settings::gen_per_batch * (current_batch - 1) + current_gen;
130,075,279✔
694
}
695

696
int64_t compute_particle_id(int64_t index_source)
193,279,597✔
697
{
698
  if (settings::use_shared_secondary_bank) {
193,279,597✔
699
    return simulation::work_index[mpi::rank] + index_source +
63,366,942✔
700
           simulation::simulation_tracks_completed;
63,366,942✔
701
  } else {
702
    return simulation::work_index[mpi::rank] + index_source;
129,912,655✔
703
  }
704
}
705

706
int64_t compute_transport_seed(int64_t particle_id)
193,279,625✔
707
{
708
  if (settings::use_shared_secondary_bank) {
193,279,625✔
709
    return particle_id;
710
  } else {
711
    return (simulation::total_gen + overall_generation() - 1) *
129,912,676✔
712
             settings::n_particles +
713
           particle_id;
129,912,676✔
714
  }
715
}
716

717
void calculate_work(int64_t n_particles)
9,865✔
718
{
719
  // Determine minimum amount of particles to simulate on each processor
720
  int64_t min_work = n_particles / mpi::n_procs;
9,865✔
721

722
  // Determine number of processors that have one extra particle
723
  int64_t remainder = n_particles % mpi::n_procs;
9,865✔
724

725
  int64_t i_bank = 0;
9,865✔
726
  simulation::work_index.resize(mpi::n_procs + 1);
9,865✔
727
  simulation::work_index[0] = 0;
9,865✔
728
  for (int i = 0; i < mpi::n_procs; ++i) {
21,096✔
729
    // Number of particles for rank i
730
    int64_t work_i = i < remainder ? min_work + 1 : min_work;
11,231✔
731

732
    // Set number of particles
733
    if (mpi::rank == i)
11,231✔
734
      simulation::work_per_rank = work_i;
9,865✔
735

736
    // Set index into source bank for rank i
737
    i_bank += work_i;
11,231✔
738
    simulation::work_index[i + 1] = i_bank;
11,231✔
739
  }
740
}
9,865✔
741

742
void initialize_data()
3,783✔
743
{
744
  // Determine minimum/maximum energy for incident neutron/photon data
745
  data::energy_max = {INFTY, INFTY, INFTY, INFTY};
3,783✔
746
  data::energy_min = {0.0, 0.0, 0.0, 0.0};
3,783✔
747

748
  for (const auto& nuc : data::nuclides) {
23,727✔
749
    if (nuc->grid_.size() >= 1) {
19,944!
750
      int neutron = ParticleType::neutron().transport_index();
19,944✔
751
      data::energy_min[neutron] =
19,944✔
752
        std::max(data::energy_min[neutron], nuc->grid_[0].energy.front());
23,405✔
753
      data::energy_max[neutron] =
19,944✔
754
        std::min(data::energy_max[neutron], nuc->grid_[0].energy.back());
24,364✔
755
    }
756
  }
757

758
  if (settings::photon_transport) {
3,783✔
759
    for (const auto& elem : data::elements) {
932✔
760
      if (elem->energy_.size() >= 1) {
662!
761
        int photon = ParticleType::photon().transport_index();
662✔
762
        int n = elem->energy_.size();
662✔
763
        data::energy_min[photon] =
1,324✔
764
          std::max(data::energy_min[photon], std::exp(elem->energy_(1)));
1,093✔
765
        data::energy_max[photon] =
662✔
766
          std::min(data::energy_max[photon], std::exp(elem->energy_(n - 1)));
932✔
767
      }
768
    }
769

770
    if (settings::electron_treatment == ElectronTreatment::TTB) {
270✔
771
      // Determine if minimum/maximum energy for bremsstrahlung is greater/less
772
      // than the current minimum/maximum
773
      if (data::ttb_e_grid.size() >= 1) {
234!
774
        int photon = ParticleType::photon().transport_index();
234✔
775
        int electron = ParticleType::electron().transport_index();
234✔
776
        int positron = ParticleType::positron().transport_index();
234✔
777
        int n_e = data::ttb_e_grid.size();
234✔
778

779
        const std::vector<int> charged = {electron, positron};
234✔
780
        for (auto t : charged) {
702✔
781
          data::energy_min[t] = std::exp(data::ttb_e_grid(1));
468✔
782
          data::energy_max[t] = std::exp(data::ttb_e_grid(n_e - 1));
468✔
783
        }
784

785
        data::energy_min[photon] =
468✔
786
          std::max(data::energy_min[photon], data::energy_min[electron]);
468!
787

788
        data::energy_max[photon] =
468✔
789
          std::min(data::energy_max[photon], data::energy_max[electron]);
468!
790
      }
234✔
791
    }
792
  }
793

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

813
  // Set up logarithmic grid for nuclides
814
  for (auto& nuc : data::nuclides) {
23,727✔
815
    nuc->init_grid();
19,944✔
816
  }
817
  int neutron = ParticleType::neutron().transport_index();
3,783✔
818
  simulation::log_spacing =
7,566✔
819
    std::log(data::energy_max[neutron] / data::energy_min[neutron]) /
3,783✔
820
    settings::n_log_bins;
821
}
3,783✔
822

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

833
    auto shape = results.shape();
3,390✔
834
    int count_per_filter = shape[1] * shape[2];
3,390✔
835
    MPI_Datatype result_block;
3,390✔
836
    MPI_Type_contiguous(count_per_filter, MPI_DOUBLE, &result_block);
3,390✔
837
    MPI_Type_commit(&result_block);
3,390✔
838
    MPI_Bcast(results.data(), shape[0], result_block, 0, mpi::intracomm);
3,390✔
839
    MPI_Type_free(&result_block);
3,390✔
840
  }
3,390✔
841

842
  // Also broadcast global tally results
843
  auto& gt = simulation::global_tallies;
849✔
844
  MPI_Bcast(gt.data(), gt.size(), MPI_DOUBLE, 0, mpi::intracomm);
849✔
845

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

856
#endif
857

858
void free_memory_simulation()
5,133✔
859
{
860
  simulation::k_generation.clear();
5,133✔
861
  simulation::entropy.clear();
5,133✔
862
}
5,133✔
863

864
void transport_history_based_single_particle(Particle& p)
175,483,143✔
865
{
866
  while (p.alive()) {
2,147,483,647✔
867
    p.event_calculate_xs();
2,147,483,647✔
868
    if (p.alive()) {
2,147,483,647!
869
      p.event_advance();
2,147,483,647✔
870
    }
871
    if (p.alive()) {
2,147,483,647✔
872
      if (p.collision_distance() > p.boundary().distance()) {
2,147,483,647✔
873
        p.event_cross_surface();
1,686,961,650✔
874
      } else if (p.alive()) {
2,147,483,647✔
875
        p.event_collide();
2,147,483,647✔
876
      }
877
    }
878
    p.event_check_limit_and_revive();
2,147,483,647✔
879
  }
880
  p.event_death();
175,483,137✔
881
}
175,483,137✔
882

883
void transport_history_based()
86,283✔
884
{
885
#pragma omp parallel for schedule(runtime)
23,723✔
886
  for (int64_t i_work = 1; i_work <= simulation::work_per_rank; ++i_work) {
80,496,680✔
887
    Particle p;
80,434,129✔
888
    initialize_particle_track(p, i_work, false);
80,434,129✔
889
    transport_history_based_single_particle(p);
80,434,125✔
890
  }
80,434,120✔
891
}
86,274✔
892

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

907
  if (mpi::master) {
389✔
908
    write_message(fmt::format(" Primary source          particles: {}",
732✔
909
                    settings::n_particles),
910
      6);
911
  }
912

913
  simulation::progeny_per_particle.resize(simulation::work_per_rank);
389✔
914
  std::fill(simulation::progeny_per_particle.begin(),
778✔
915
    simulation::progeny_per_particle.end(), 0);
389✔
916

917
  // Phase 1: Transport primary particles and deposit first generation of
918
  // secondaries in the shared secondary bank
919
#pragma omp parallel
106✔
920
  {
283✔
921
    vector<SourceSite> thread_bank;
283✔
922

923
#pragma omp for schedule(runtime)
924
    for (int64_t i = 1; i <= simulation::work_per_rank; i++) {
388,533✔
925
      Particle p;
388,250✔
926
      initialize_particle_track(p, i, false);
388,250✔
927
      transport_history_based_single_particle(p);
388,250✔
928
      for (auto& site : p.local_secondary_bank()) {
1,593,065✔
929
        thread_bank.push_back(site);
1,204,815✔
930
      }
931
    }
388,250✔
932

933
    // Drain thread-local bank into the shared secondary bank (once per thread)
934
#pragma omp critical(SharedSecondaryBank)
935
    {
283✔
936
      for (auto& site : thread_bank) {
1,205,098✔
937
        simulation::shared_secondary_bank_write.thread_unsafe_append(site);
1,204,815✔
938
      }
939
    }
940
  }
941

942
  simulation::simulation_tracks_completed += settings::n_particles;
389✔
943

944
  // Phase 2: Now that the secondary bank has been populated, enter loop over
945
  // all secondary generations
946
  int n_generation_depth = 1;
389✔
947
  int64_t alive_secondary = 1;
389✔
948
  while (alive_secondary) {
5,354✔
949

950
    // Sort the shared secondary bank by parent ID then progeny ID to
951
    // ensure reproducibility.
952
    sort_bank(simulation::shared_secondary_bank_write, false);
4,965✔
953

954
    // Synchronize the shared secondary bank amongst all MPI ranks, such
955
    // that each MPI rank has an approximately equal number of secondary
956
    // tracks. Also reports the total number of secondaries alive across
957
    // all MPI ranks.
958
    alive_secondary = synchronize_global_secondary_bank(
4,965✔
959
      simulation::shared_secondary_bank_write);
960

961
    // Recalculate work for each MPI rank based on number of alive secondary
962
    // tracks
963
    calculate_work(alive_secondary);
4,965✔
964

965
    // Display the number of secondary tracks in this generation. This
966
    // is useful for user monitoring so as to see if the secondary population is
967
    // exploding and to determine how many generations of secondaries are being
968
    // transported.
969
    if (mpi::master) {
4,965✔
970
      write_message(fmt::format(" Secondary generation {:<2}    tracks: {}",
9,104✔
971
                      n_generation_depth, alive_secondary),
972
        6);
973
    }
974

975
    simulation::shared_secondary_bank_read =
4,965✔
976
      std::move(simulation::shared_secondary_bank_write);
4,965✔
977
    simulation::shared_secondary_bank_write = SharedArray<SourceSite>();
4,965!
978
    simulation::progeny_per_particle.resize(
4,965✔
979
      simulation::shared_secondary_bank_read.size());
4,965✔
980
    std::fill(simulation::progeny_per_particle.begin(),
9,930✔
981
      simulation::progeny_per_particle.end(), 0);
4,965✔
982

983
    // Transport all secondary tracks from the shared secondary bank
984
#pragma omp parallel
1,297✔
985
    {
3,668✔
986
      vector<SourceSite> thread_bank;
3,668✔
987

988
#pragma omp for schedule(runtime)
989
      for (int64_t i = 1; i <= simulation::shared_secondary_bank_read.size();
44,599,708✔
990
           i++) {
991
        Particle p;
44,596,040✔
992
        initialize_particle_track(p, i, true);
44,596,040✔
993
        SourceSite& site = simulation::shared_secondary_bank_read[i - 1];
44,596,040✔
994
        p.event_revive_from_secondary(site);
44,596,040✔
995
        transport_history_based_single_particle(p);
44,596,040✔
996
        for (auto& secondary_site : p.local_secondary_bank()) {
87,987,265✔
997
          thread_bank.push_back(secondary_site);
43,391,225✔
998
        }
999
      }
44,596,040✔
1000

1001
      // Drain thread-local bank into the shared secondary bank (once per
1002
      // thread)
1003
#pragma omp critical(SharedSecondaryBank)
1004
      {
3,668✔
1005
        for (auto& secondary_site : thread_bank) {
43,394,893✔
1006
          simulation::shared_secondary_bank_write.thread_unsafe_append(
43,391,225✔
1007
            secondary_site);
1008
        }
1009
      }
1010
    } // End of transport loop over tracks in shared secondary bank
3,668✔
1011
    n_generation_depth++;
4,965✔
1012
    simulation::simulation_tracks_completed += alive_secondary;
4,965✔
1013
  } // End of loop over secondary generations
1014

1015
  // Reset work so that fission bank etc works correctly
1016
  calculate_work(settings::n_particles);
389✔
1017
}
389✔
1018

UNCOV
1019
void transport_event_based()
×
1020
{
UNCOV
1021
  int64_t remaining_work = simulation::work_per_rank;
×
UNCOV
1022
  int64_t source_offset = 0;
×
1023

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

1034
    // Initialize all particle histories for this subiteration
UNCOV
1035
    process_init_events(n_particles, source_offset);
×
UNCOV
1036
    process_transport_events();
×
UNCOV
1037
    process_death_events(n_particles);
×
1038

1039
    // Adjust remaining work and source offset variables
UNCOV
1040
    remaining_work -= n_particles;
×
UNCOV
1041
    source_offset += n_particles;
×
1042
  }
UNCOV
1043
}
×
1044

UNCOV
1045
void transport_event_based_shared_secondary()
×
1046
{
1047
  // Clear shared secondary banks from any prior use
UNCOV
1048
  simulation::shared_secondary_bank_read.clear();
×
UNCOV
1049
  simulation::shared_secondary_bank_write.clear();
×
1050

UNCOV
1051
  if (mpi::master) {
×
UNCOV
1052
    write_message(fmt::format(" Primary source          particles: {}",
×
1053
                    settings::n_particles),
1054
      6);
1055
  }
1056

UNCOV
1057
  simulation::progeny_per_particle.resize(simulation::work_per_rank);
×
UNCOV
1058
  std::fill(simulation::progeny_per_particle.begin(),
×
UNCOV
1059
    simulation::progeny_per_particle.end(), 0);
×
1060

1061
  // Phase 1: Transport primary particles using event-based processing and
1062
  // deposit first generation of secondaries in the shared secondary bank
UNCOV
1063
  int64_t remaining_work = simulation::work_per_rank;
×
UNCOV
1064
  int64_t source_offset = 0;
×
1065

UNCOV
1066
  while (remaining_work > 0) {
×
UNCOV
1067
    int64_t n_particles =
×
UNCOV
1068
      std::min(remaining_work, settings::max_particles_in_flight);
×
1069

UNCOV
1070
    process_init_events(n_particles, source_offset);
×
UNCOV
1071
    process_transport_events();
×
UNCOV
1072
    process_death_events(n_particles);
×
1073

1074
    // Collect secondaries from all particle buffers into shared bank
UNCOV
1075
    for (int64_t i = 0; i < n_particles; i++) {
×
UNCOV
1076
      for (auto& site : simulation::particles[i].local_secondary_bank()) {
×
UNCOV
1077
        simulation::shared_secondary_bank_write.thread_unsafe_append(site);
×
1078
      }
UNCOV
1079
      simulation::particles[i].local_secondary_bank().clear();
×
1080
    }
1081

UNCOV
1082
    remaining_work -= n_particles;
×
UNCOV
1083
    source_offset += n_particles;
×
1084
  }
1085

UNCOV
1086
  simulation::simulation_tracks_completed += settings::n_particles;
×
1087

1088
  // Phase 2: Now that the secondary bank has been populated, enter loop over
1089
  // all secondary generations
UNCOV
1090
  int n_generation_depth = 1;
×
UNCOV
1091
  int64_t alive_secondary = 1;
×
UNCOV
1092
  while (alive_secondary) {
×
1093

1094
    // Sort the shared secondary bank by parent ID then progeny ID to
1095
    // ensure reproducibility.
UNCOV
1096
    sort_bank(simulation::shared_secondary_bank_write, false);
×
1097

1098
    // Synchronize the shared secondary bank amongst all MPI ranks, such
1099
    // that each MPI rank has an approximately equal number of secondary
1100
    // tracks.
UNCOV
1101
    alive_secondary = synchronize_global_secondary_bank(
×
1102
      simulation::shared_secondary_bank_write);
1103

1104
    // Recalculate work for each MPI rank based on number of alive secondary
1105
    // tracks
UNCOV
1106
    calculate_work(alive_secondary);
×
1107

UNCOV
1108
    if (mpi::master) {
×
UNCOV
1109
      write_message(fmt::format(" Secondary generation {:<2}    tracks: {}",
×
1110
                      n_generation_depth, alive_secondary),
1111
        6);
1112
    }
1113

UNCOV
1114
    simulation::shared_secondary_bank_read =
×
UNCOV
1115
      std::move(simulation::shared_secondary_bank_write);
×
UNCOV
1116
    simulation::shared_secondary_bank_write = SharedArray<SourceSite>();
×
UNCOV
1117
    simulation::progeny_per_particle.resize(
×
UNCOV
1118
      simulation::shared_secondary_bank_read.size());
×
UNCOV
1119
    std::fill(simulation::progeny_per_particle.begin(),
×
UNCOV
1120
      simulation::progeny_per_particle.end(), 0);
×
1121

1122
    // Ensure particle buffer is large enough for this secondary generation
UNCOV
1123
    int64_t sec_buffer_length = std::min(
×
UNCOV
1124
      static_cast<int64_t>(simulation::shared_secondary_bank_read.size()),
×
UNCOV
1125
      settings::max_particles_in_flight);
×
UNCOV
1126
    if (sec_buffer_length >
×
UNCOV
1127
        static_cast<int64_t>(simulation::particles.size())) {
×
UNCOV
1128
      init_event_queues(sec_buffer_length);
×
1129
    }
1130

1131
    // Transport secondary tracks using event-based processing
UNCOV
1132
    int64_t sec_remaining = simulation::shared_secondary_bank_read.size();
×
UNCOV
1133
    int64_t sec_offset = 0;
×
1134

UNCOV
1135
    while (sec_remaining > 0) {
×
UNCOV
1136
      int64_t n_particles =
×
UNCOV
1137
        std::min(sec_remaining, settings::max_particles_in_flight);
×
1138

UNCOV
1139
      process_init_secondary_events(
×
1140
        n_particles, sec_offset, simulation::shared_secondary_bank_read);
UNCOV
1141
      process_transport_events();
×
UNCOV
1142
      process_death_events(n_particles);
×
1143

1144
      // Collect secondaries from all particle buffers into shared bank
UNCOV
1145
      for (int64_t i = 0; i < n_particles; i++) {
×
UNCOV
1146
        for (auto& site : simulation::particles[i].local_secondary_bank()) {
×
UNCOV
1147
          simulation::shared_secondary_bank_write.thread_unsafe_append(site);
×
1148
        }
UNCOV
1149
        simulation::particles[i].local_secondary_bank().clear();
×
1150
      }
1151

UNCOV
1152
      sec_remaining -= n_particles;
×
UNCOV
1153
      sec_offset += n_particles;
×
1154
    } // End of subiteration loop over secondary tracks
UNCOV
1155
    n_generation_depth++;
×
UNCOV
1156
    simulation::simulation_tracks_completed += alive_secondary;
×
1157
  } // End of loop over secondary generations
1158

1159
  // Reset work so that fission bank etc works correctly
UNCOV
1160
  calculate_work(settings::n_particles);
×
UNCOV
1161
}
×
1162

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