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

openmc-dev / openmc / 26473127945

26 May 2026 08:25PM UTC coverage: 80.855% (-0.5%) from 81.333%
26473127945

Pull #3877

github

web-flow
Merge e16d17e3a into dfb6c5699
Pull Request #3877: Add VTKHDF output support for all structured mesh types (#3620)

17109 of 24582 branches covered (69.6%)

Branch coverage included in aggregate %.

109 of 119 new or added lines in 1 file covered. (91.6%)

652 existing lines in 38 files now uncovered.

57802 of 68066 relevant lines covered (84.92%)

38696905.68 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()
4,005✔
54
{
55
  openmc::simulation::time_total.start();
4,005✔
56
  openmc_simulation_init();
4,005✔
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;
4,005✔
61
  if (openmc::simulation::current_batch >= openmc::settings::n_max_batches) {
4,005✔
62
    status = openmc::STATUS_EXIT_MAX_BATCH;
7✔
63
  }
64

65
  int err = 0;
66
  while (status == 0 && err == 0) {
91,027✔
67
    err = openmc_next_batch(&status);
87,033✔
68
  }
69

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

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

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

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

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

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

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

99
  // If doing an event-based simulation, intialize the particle buffer
100
  // and event queues
101
  if (settings::event_based) {
4,702!
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) {
21,095✔
109
    t->set_strides();
16,393✔
110
    t->init_results();
16,393✔
111
  }
112

113
  // Set up material nuclide index mapping
114
  for (auto& mat : model::materials) {
16,929✔
115
    mat->init_nuclide_index();
12,227✔
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,702✔
121
  simulation::ct_current_file = 1;
4,702✔
122
  simulation::ssw_current_file = 1;
4,702✔
123
  simulation::k_generation.clear();
4,702✔
124
  simulation::entropy.clear();
4,702✔
125
  reset_source_rejection_counters();
4,702✔
126
  openmc_reset();
4,702✔
127

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

141
  // Display header
142
  if (mpi::master) {
4,702✔
143
    if (settings::run_mode == RunMode::FIXED_SOURCE) {
4,216✔
144
      if (settings::solver_type == SolverType::MONTE_CARLO) {
1,808✔
145
        header("FIXED SOURCE TRANSPORT SIMULATION", 3);
1,570✔
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,408!
150
      if (settings::solver_type == SolverType::MONTE_CARLO) {
2,408✔
151
        header("K EIGENVALUE SIMULATION", 3);
2,233✔
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,408✔
156
        print_columns();
2,163✔
157
    }
158
  }
159

160
  // load weight windows from file
161
  if (!settings::weight_windows_file.empty()) {
4,702!
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,702✔
167
  return 0;
4,702✔
168
}
169

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

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

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

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

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

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

195
#ifdef OPENMC_MPI
196
  broadcast_results();
1,680✔
197
#endif
198

199
  // Write tally results to tallies.out
200
  if (settings::output_tallies && mpi::master)
4,691!
201
    write_tallies();
3,988✔
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,691✔
206
    openmc_weight_windows_export();
100✔
207
  }
208

209
  // Deactivate all tallies
210
  for (auto& t : model::tallies) {
21,084✔
211
    t->active_ = false;
16,393✔
212
  }
213

214
  // Stop timers and show timing statistics
215
  simulation::time_finalize.stop();
4,691✔
216
  simulation::time_total.stop();
4,691✔
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) {
1,680✔
223
    int64_t total_tracks;
40✔
224
    MPI_Reduce(&simulation::simulation_tracks_completed, &total_tracks, 1,
40✔
225
      MPI_INT64_T, MPI_SUM, 0, mpi::intracomm);
226
    if (mpi::master)
40✔
227
      simulation::simulation_tracks_completed = total_tracks;
32✔
228
  }
229
#endif
230

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

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

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

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

258
  initialize_batch();
89,651✔
259

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

264
    initialize_generation();
89,777✔
265

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

269
    // Transport loop
270
    if (settings::event_based) {
89,777!
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) {
89,777✔
278
        transport_history_based_shared_secondary();
410✔
279
      } else {
280
        transport_history_based();
89,367✔
281
      }
282
    }
283

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

287
    finalize_generation();
89,766✔
288
  }
289

290
  finalize_batch();
89,640✔
291

292
  // Check simulation ending criteria
293
  if (status) {
89,640!
294
    if (simulation::current_batch >= settings::n_max_batches) {
89,640✔
295
      *status = STATUS_EXIT_MAX_BATCH;
4,119✔
296
    } else if (simulation::satisfy_triggers) {
85,521✔
297
      *status = STATUS_EXIT_ON_TRIGGER;
57✔
298
    } else {
299
      *status = STATUS_EXIT_NORMAL;
85,464✔
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,702✔
358
{
359
  if (settings::run_mode == RunMode::EIGENVALUE &&
4,702✔
360
      settings::solver_type == SolverType::MONTE_CARLO) {
2,748✔
361
    // Allocate source bank
362
    simulation::source_bank.resize(simulation::work_per_rank);
2,525✔
363

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

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

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

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

384
void initialize_batch()
102,301✔
385
{
386
  // Increment current batch
387
  ++simulation::current_batch;
102,301✔
388
  if (settings::run_mode == RunMode::FIXED_SOURCE) {
102,301✔
389
    if (settings::solver_type == SolverType::RANDOM_RAY &&
40,086✔
390
        simulation::current_batch < settings::n_inactive + 1) {
8,460✔
391
      write_message(
10,080✔
392
        6, "Simulating batch {:<4} (inactive)", simulation::current_batch);
393
    } else {
394
      write_message(6, "Simulating batch {}", simulation::current_batch);
70,092✔
395
    }
396
  }
397

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

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

412
  // Manage active/inactive timers and activate tallies if necessary.
413
  if (first_inactive) {
102,232✔
414
    simulation::time_inactive.start();
2,360✔
415
  } else if (first_active) {
99,941✔
416
    simulation::time_inactive.stop();
4,674✔
417
    simulation::time_active.start();
4,674✔
418
    for (auto& t : model::tallies) {
21,053✔
419
      t->active_ = true;
16,379✔
420
    }
421
  }
422

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

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

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

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

445
  // Check_triggers
446
  if (mpi::master)
102,290✔
447
    check_triggers();
92,978✔
448
#ifdef OPENMC_MPI
449
  MPI_Bcast(&simulation::satisfy_triggers, 1, MPI_C_BOOL, 0, mpi::intracomm);
35,810✔
450
#endif
451
  if (simulation::satisfy_triggers ||
102,290✔
452
      (settings::trigger_on &&
1,591✔
453
        simulation::current_batch == settings::n_max_batches)) {
1,591✔
454
    settings::statepoint_batch.insert(simulation::current_batch);
87✔
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) &&
204,580✔
460
      !settings::cmfd_run) {
4,858✔
461
    if (contains(settings::sourcepoint_batch, simulation::current_batch) &&
9,319✔
462
        settings::source_write && !settings::source_separate) {
8,790✔
463
      bool b = (settings::run_mode == RunMode::EIGENVALUE);
4,001✔
464
      openmc_statepoint_write(nullptr, &b);
4,001✔
465
    } else {
466
      bool b = false;
745✔
467
      openmc_statepoint_write(nullptr, &b);
745✔
468
    }
469
  }
470

471
  if (settings::run_mode == RunMode::EIGENVALUE) {
102,290✔
472
    // Write out a separate source point if it's been specified for this batch
473
    if (contains(settings::sourcepoint_batch, simulation::current_batch) &&
64,978✔
474
        settings::source_write && settings::source_separate) {
64,755✔
475

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

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

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

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

513
      // Write surface source file
514
      write_source_point(
763✔
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();
763✔
519
      if (!last_batch && settings::ssw_max_files >= 1) {
763!
520
        simulation::surf_source_bank.reserve(settings::ssw_max_particles);
644✔
521
      }
522
      ++simulation::ssw_current_file;
763✔
523
    }
763✔
524
  }
525
  // Write collision track file if requested
526
  if (settings::collision_track) {
102,290✔
527
    collision_track_flush_bank();
371✔
528
  }
529
}
102,290✔
530

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

537
    // Count source sites if using uniform fission source weighting
538
    if (settings::ufs_on)
62,341✔
539
      ufs_count_sites();
90✔
540

541
    // Store current value of tracklength k
542
    simulation::keff_generation = simulation::global_tallies(
62,341✔
543
      GlobalTally::K_TRACKLENGTH, TallyResult::VALUE);
544
  }
545
}
102,427✔
546

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

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

561
  // reset tallies
562
  if (settings::run_mode == RunMode::EIGENVALUE) {
102,416✔
563
    global_tally_collision = 0.0;
62,341✔
564
    global_tally_absorption = 0.0;
62,341✔
565
    global_tally_tracklength = 0.0;
62,341✔
566
  }
567
  global_tally_leakage = 0.0;
102,416✔
568

569
  if (settings::run_mode == RunMode::EIGENVALUE &&
102,416✔
570
      settings::solver_type == SolverType::MONTE_CARLO) {
62,341✔
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);
58,151✔
575

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

580
  if (settings::run_mode == RunMode::EIGENVALUE) {
102,416✔
581

582
    // Calculate shannon entropy
583
    if (settings::entropy_on &&
62,341✔
584
        settings::solver_type == SolverType::MONTE_CARLO)
9,075✔
585
      shannon_entropy();
4,885✔
586

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

591
    // Write generation output
592
    if (mpi::master && settings::verbosity >= 7) {
62,341✔
593
      print_generation();
48,321✔
594
    }
595
  }
596
}
102,416✔
597

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

613
void initialize_particle_track(
126,651,347✔
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) {
126,651,347✔
620
    sample_source_particle(p, index_source);
113,065,475✔
621
  }
622

623
  p.current_work() = index_source - 1;
126,651,343✔
624

625
  // set identifier for particle
626
  p.id() = compute_particle_id(index_source);
126,651,343✔
627

628
  // set progeny count to zero
629
  p.n_progeny() = 0;
126,651,343✔
630

631
  // Reset particle event counter
632
  p.n_event() = 0;
126,651,343✔
633

634
  // Initialize track counter (1 for this primary/secondary track)
635
  p.n_tracks() = 1;
126,651,343✔
636

637
  // Reset split counter
638
  p.n_split() = 0;
126,651,343✔
639

640
  // Reset weight window ratio
641
  p.ww_factor() = 0.0;
126,651,343✔
642

643
  // set particle history start weight
644
  p.wgt_born() = p.wgt();
126,651,343✔
645

646
  // Reset pulse_height_storage
647
  std::fill(p.pht_storage().begin(), p.pht_storage().end(), 0);
126,651,343✔
648

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

653
  // set particle trace
654
  p.trace() = false;
126,651,343✔
655
  if (simulation::current_batch == settings::trace_batch &&
126,658,343✔
656
      simulation::current_gen == settings::trace_gen &&
126,651,343!
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);
126,651,343✔
662

663
  // Set the particle's initial weight window value.
664
  if (!is_secondary) {
126,651,343✔
665
    p.wgt_ww_born() = -1.0;
113,065,471✔
666
    apply_weight_windows(p);
113,065,471✔
667
  }
668

669
  // Display message if high verbosity or trace is on
670
  if (settings::verbosity >= 9 || p.trace()) {
126,651,343!
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) {
126,651,343✔
676
#pragma omp atomic
32,755,011✔
677
    simulation::total_weight += p.wgt();
113,065,471✔
678
  }
679

680
  // Force calculation of cross-sections by setting last energy to zero
681
  if (settings::run_CE) {
126,651,343✔
682
    p.invalidate_neutron_xs();
53,763,815✔
683
  }
684

685
  // Prepare to write out particle track.
686
  if (p.write_track())
126,651,343✔
687
    add_particle_track(p);
603✔
688
}
126,651,343✔
689

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

696
int64_t compute_particle_id(int64_t index_source)
144,297,603✔
697
{
698
  if (settings::use_shared_secondary_bank) {
144,297,603✔
699
    return simulation::work_index[mpi::rank] + index_source +
14,582,077✔
700
           simulation::simulation_tracks_completed;
14,582,077✔
701
  } else {
702
    return simulation::work_index[mpi::rank] + index_source;
129,715,526✔
703
  }
704
}
705

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

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

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

725
  int64_t i_bank = 0;
10,382✔
726
  simulation::work_index.resize(mpi::n_procs + 1);
10,382✔
727
  simulation::work_index[0] = 0;
10,382✔
728
  for (int i = 0; i < mpi::n_procs; ++i) {
23,500✔
729
    // Number of particles for rank i
730
    int64_t work_i = i < remainder ? min_work + 1 : min_work;
13,118✔
731

732
    // Set number of particles
733
    if (mpi::rank == i)
13,118✔
734
      simulation::work_per_rank = work_i;
10,382✔
735

736
    // Set index into source bank for rank i
737
    i_bank += work_i;
13,118✔
738
    simulation::work_index[i + 1] = i_bank;
13,118✔
739
  }
740
}
10,382✔
741

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

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

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

770
    if (settings::electron_treatment == ElectronTreatment::TTB) {
263✔
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) {
226!
774
        int photon = ParticleType::photon().transport_index();
226✔
775
        int electron = ParticleType::electron().transport_index();
226✔
776
        int positron = ParticleType::positron().transport_index();
226✔
777
        int n_e = data::ttb_e_grid.size();
226✔
778

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

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

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

794
  // Show which nuclide results in lowest energy for neutron transport
795
  for (const auto& nuc : data::nuclides) {
4,914✔
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,589!
799
      double max_E = nuc->grid_[0].energy.back();
4,589✔
800
      int neutron = ParticleType::neutron().transport_index();
4,589✔
801
      if (max_E == data::energy_max[neutron]) {
4,589✔
802
        write_message(7, "Maximum neutron transport energy: {} eV for {}",
3,567✔
803
          data::energy_max[neutron], nuc->name_);
3,567✔
804
        if (mpi::master && data::energy_max[neutron] < 20.0e6) {
3,567!
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) {
24,183✔
815
    nuc->init_grid();
20,291✔
816
  }
817
  int neutron = ParticleType::neutron().transport_index();
3,892✔
818
  simulation::log_spacing =
7,784✔
819
    std::log(data::energy_max[neutron] / data::energy_min[neutron]) /
3,892✔
820
    settings::n_log_bins;
821
}
3,892✔
822

823
#ifdef OPENMC_MPI
824
void broadcast_results()
1,680✔
825
{
826
  // Broadcast tally results so that each process has access to results
827
  for (auto& t : model::tallies) {
8,352✔
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_;
6,672✔
832

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

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

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

856
#endif
857

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

864
void transport_history_based_single_particle(Particle& p)
126,651,371✔
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,688,302,466✔
874
      } else if (p.alive()) {
2,071,908,490✔
875
        p.event_collide();
2,071,908,490✔
876
      }
877
    }
878
    p.event_check_limit_and_revive();
2,147,483,647✔
879
  }
880
  p.event_death();
126,651,364✔
881
}
126,651,364✔
882

883
void transport_history_based()
89,367✔
884
{
885
#pragma omp parallel for schedule(runtime)
26,992✔
886
  for (int64_t i_work = 1; i_work <= simulation::work_per_rank; ++i_work) {
80,448,520✔
887
    Particle p;
80,386,154✔
888
    initialize_particle_track(p, i_work, false);
80,386,154✔
889
    transport_history_based_single_particle(p);
80,386,150✔
890
  }
80,386,145✔
891
}
89,358✔
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()
410✔
902
{
903
  // Clear shared secondary banks from any prior use
904
  simulation::shared_secondary_bank_read.clear();
410✔
905
  simulation::shared_secondary_bank_write.clear();
410✔
906

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

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

917
  // Phase 1: Transport primary particles and deposit first generation of
918
  // secondaries in the shared secondary bank
919
#pragma omp parallel
127✔
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++) {
356,058✔
925
      Particle p;
355,775✔
926
      initialize_particle_track(p, i, false);
355,775✔
927
      transport_history_based_single_particle(p);
355,775✔
928
      for (auto& site : p.local_secondary_bank()) {
1,087,225✔
929
        thread_bank.push_back(site);
731,450✔
930
      }
931
    }
355,775✔
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) {
731,733✔
937
        simulation::shared_secondary_bank_write.thread_unsafe_append(site);
731,450✔
938
      }
939
    }
940
  }
941

942
  simulation::simulation_tracks_completed += settings::n_particles;
410✔
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;
410✔
947
  int64_t alive_secondary = 1;
410✔
948
  while (alive_secondary) {
5,680✔
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);
5,270✔
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(
5,270✔
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);
5,270✔
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) {
5,270✔
970
      write_message(fmt::format(" Secondary generation {:<2}    tracks: {}",
8,868✔
971
                      n_generation_depth, alive_secondary),
972
        6);
973
    }
974

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

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

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

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

1015
  // Reset work so that fission bank etc works correctly
1016
  calculate_work(settings::n_particles);
410✔
1017
}
410✔
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