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

openmc-dev / openmc / 29060094959

10 Jul 2026 12:29AM UTC coverage: 80.472% (-0.8%) from 81.292%
29060094959

Pull #3951

github

web-flow
Merge dfc4a1991 into 3c3ebba98
Pull Request #3951: wwinp files: Fix MemoryError in WeightWindowsList.export_to_hdf5 and speed up from_wwinp. Alternative Approach

16740 of 24259 branches covered (69.01%)

Branch coverage included in aggregate %.

70 of 128 new or added lines in 10 files covered. (54.69%)

787 existing lines in 49 files now uncovered.

57490 of 67984 relevant lines covered (84.56%)

17348614.33 hits per line

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

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

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

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

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

40
#include <fmt/format.h>
41

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

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

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

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

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

66
  int err = 0;
67
  while (status == 0 && err == 0) {
24,136✔
68
    err = openmc_next_batch(&status);
23,066✔
69
  }
70

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

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

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

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

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

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

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

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

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

114
  // Set up material nuclide index mapping
115
  for (auto& mat : model::materials) {
4,644✔
116
    mat->init_nuclide_index();
3,404✔
117
  }
118

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

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

142
  // Display header
143
  if (mpi::master) {
1,240!
144
    if (settings::run_mode == RunMode::FIXED_SOURCE) {
1,240✔
145
      if (settings::solver_type == SolverType::MONTE_CARLO) {
548✔
146
        header("FIXED SOURCE TRANSPORT SIMULATION", 3);
480✔
147
      } else if (settings::solver_type == SolverType::RANDOM_RAY) {
68!
148
        header("FIXED SOURCE TRANSPORT SIMULATION (RANDOM RAY SOLVER)", 3);
68✔
149
      }
150
    } else if (settings::run_mode == RunMode::EIGENVALUE) {
692!
151
      if (settings::solver_type == SolverType::MONTE_CARLO) {
692✔
152
        header("K EIGENVALUE SIMULATION", 3);
642✔
153
      } else if (settings::solver_type == SolverType::RANDOM_RAY) {
50!
154
        header("K EIGENVALUE SIMULATION (RANDOM RAY SOLVER)", 3);
50✔
155
      }
156
      if (settings::verbosity >= 7)
692✔
157
        print_columns();
620✔
158
    }
159
  }
160

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

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

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

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

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

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

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

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

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

200
  // Write tally results to tallies.out
201
  if (settings::output_tallies && mpi::master)
1,236!
202
    write_tallies();
1,174✔
203

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

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

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

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

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

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

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

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

262
  initialize_batch();
23,814✔
263

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

268
    initialize_generation();
23,842✔
269

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

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

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

291
    finalize_generation();
23,838✔
292
  }
293

294
  finalize_batch();
23,810✔
295

296
  // Check simulation ending criteria
297
  if (status) {
23,810!
298
    if (simulation::current_batch >= settings::n_max_batches) {
23,810✔
299
      *status = STATUS_EXIT_MAX_BATCH;
1,108✔
300
    } else if (simulation::satisfy_triggers) {
22,702✔
301
      *status = STATUS_EXIT_ON_TRIGGER;
14✔
302
    } else {
303
      *status = STATUS_EXIT_NORMAL;
22,688✔
304
    }
305
  }
306
  return 0;
307
}
308

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

314
  if (!simulation::initialized)
570!
315
    return false;
316
  else
317
    return contains(settings::statepoint_batch, simulation::current_batch);
1,140✔
318
}
319

320
namespace openmc {
321

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

326
namespace simulation {
327

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

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

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

353
int64_t simulation_tracks_completed {0};
354

355
} // namespace simulation
356

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

361
void allocate_banks()
1,240✔
362
{
363
  if (settings::run_mode == RunMode::EIGENVALUE &&
1,240✔
364
      settings::solver_type == SolverType::MONTE_CARLO) {
692✔
365
    // Allocate source bank
366
    simulation::source_bank.resize(simulation::work_per_rank);
642✔
367

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

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

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

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

388
void initialize_batch()
26,714✔
389
{
390
  // Increment current batch
391
  ++simulation::current_batch;
26,714✔
392
  if (settings::run_mode == RunMode::FIXED_SOURCE) {
26,714✔
393
    if (settings::solver_type == SolverType::RANDOM_RAY &&
10,886✔
394
        simulation::current_batch < settings::n_inactive + 1) {
1,880✔
395
      write_message(
2,240✔
396
        6, "Simulating batch {:<4} (inactive)", simulation::current_batch);
397
    } else {
398
      write_message(6, "Simulating batch {}", simulation::current_batch);
19,532✔
399
    }
400
  }
401

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

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

416
  // Manage active/inactive timers and activate tallies if necessary.
417
  if (first_inactive) {
26,696✔
418
    simulation::time_inactive.start();
580✔
419
  } else if (first_active) {
26,134✔
420
    simulation::time_inactive.stop();
1,232✔
421
    simulation::time_active.start();
1,232✔
422
    for (auto& t : model::tallies) {
5,194✔
423
      t->active_ = true;
3,962✔
424
    }
425
  }
426

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

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

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

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

449
  // Check_triggers
450
  if (mpi::master)
26,710!
451
    check_triggers();
26,710✔
452
#ifdef OPENMC_MPI
453
  MPI_Bcast(&simulation::satisfy_triggers, 1, MPI_C_BOOL, 0, mpi::intracomm);
454
#endif
455
  if (simulation::satisfy_triggers ||
26,710✔
456
      (settings::trigger_on &&
410✔
457
        simulation::current_batch == settings::n_max_batches)) {
410✔
458
    settings::statepoint_batch.insert(simulation::current_batch);
22✔
459
  }
460

461
  // Write out state point if it's been specified for this batch and is not
462
  // a CMFD run instance
463
  if (contains(settings::statepoint_batch, simulation::current_batch) &&
53,420✔
464
      !settings::cmfd_run) {
1,278✔
465
    if (contains(settings::sourcepoint_batch, simulation::current_batch) &&
2,448✔
466
        settings::source_write && !settings::source_separate) {
2,330✔
467
      bool b = (settings::run_mode == RunMode::EIGENVALUE);
1,074✔
468
      openmc_statepoint_write(nullptr, &b);
1,074✔
469
    } else {
470
      bool b = false;
172✔
471
      openmc_statepoint_write(nullptr, &b);
172✔
472
    }
473
  }
474

475
  if (settings::run_mode == RunMode::EIGENVALUE) {
26,710✔
476
    // Write out a separate source point if it's been specified for this batch
477
    if (contains(settings::sourcepoint_batch, simulation::current_batch) &&
16,524✔
478
        settings::source_write && settings::source_separate) {
16,474✔
479

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

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

498
  // Write out surface source if requested.
499
  if (settings::surf_source_write &&
26,710✔
500
      simulation::ssw_current_file <= settings::ssw_max_files) {
3,248✔
501
    bool last_batch = (simulation::current_batch == settings::n_batches);
368✔
502
    if (simulation::surf_source_bank.full() || last_batch) {
368✔
503
      // Determine appropriate filename
504
      auto filename = fmt::format("{}surface_source.{}", settings::path_output,
220✔
505
        simulation::current_batch);
220✔
506
      if (settings::ssw_max_files == 1 ||
220✔
507
          (simulation::ssw_current_file == 1 && last_batch)) {
10!
508
        filename = settings::path_output + "surface_source";
210✔
509
      }
510

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

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

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

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

541
    // Count source sites if using uniform fission source weighting
542
    if (settings::ufs_on)
15,856✔
543
      ufs_count_sites();
20✔
544

545
    // Store current value of tracklength k
546
    simulation::keff_generation = simulation::global_tallies(
15,856✔
547
      GlobalTally::K_TRACKLENGTH, TallyResult::VALUE);
548
  }
549
}
26,742✔
550

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

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

565
  // reset tallies
566
  if (settings::run_mode == RunMode::EIGENVALUE) {
26,738✔
567
    global_tally_collision = 0.0;
15,856✔
568
    global_tally_absorption = 0.0;
15,856✔
569
    global_tally_tracklength = 0.0;
15,856✔
570
  }
571
  global_tally_leakage = 0.0;
26,738✔
572

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

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

584
  if (settings::run_mode == RunMode::EIGENVALUE) {
26,738✔
585

586
    // Calculate shannon entropy
587
    if (settings::entropy_on &&
15,856✔
588
        settings::solver_type == SolverType::MONTE_CARLO)
2,410✔
589
      shannon_entropy();
1,390✔
590

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

595
    // Write generation output
596
    if (mpi::master && settings::verbosity >= 7) {
15,856!
597
      print_generation();
13,836✔
598
    }
599
  }
600
}
26,738✔
601

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

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

627
  p.current_work() = index_source - 1;
36,224,162✔
628

629
  // set identifier for particle
630
  p.id() = compute_particle_id(index_source);
36,224,162✔
631

632
  // set progeny count to zero
633
  p.n_progeny() = 0;
36,224,162✔
634

635
  // Reset particle event counter
636
  p.n_event() = 0;
36,224,162✔
637

638
  // Initialize track counter (1 for this primary/secondary track)
639
  p.n_tracks() = 1;
36,224,162✔
640

641
  // Reset split counter
642
  p.n_split() = 0;
36,224,162✔
643

644
  // Reset weight window ratio
645
  p.ww_factor() = 0.0;
36,224,162✔
646

647
  // set particle history start weight
648
  p.wgt_born() = p.wgt();
36,224,162✔
649

650
  // Reset pulse_height_storage
651
  std::fill(p.pht_storage().begin(), p.pht_storage().end(), 0);
36,224,162✔
652

653
  // set random number seed
654
  int64_t particle_seed = compute_transport_seed(p.id());
36,224,162✔
655
  init_particle_seeds(particle_seed, p.seeds());
36,224,162✔
656

657
  // set particle trace
658
  p.trace() = false;
36,224,162✔
659
  if (simulation::current_batch == settings::trace_batch &&
36,226,162✔
660
      simulation::current_gen == settings::trace_gen &&
36,224,162!
661
      p.id() == settings::trace_particle)
2,000✔
662
    p.trace() = true;
2✔
663

664
  // Set particle track.
665
  p.write_track() = check_track_criteria(p);
36,224,162✔
666

667
  // Set the particle's initial weight window value.
668
  if (!is_secondary) {
36,224,162✔
669
    p.wgt_ww_born() = -1.0;
32,334,698✔
670
    apply_weight_windows(p);
32,334,698✔
671
  }
672

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

678
  // Add particle's starting weight to count for normalizing tallies later
679
  if (!is_secondary) {
36,224,162✔
680
#pragma omp atomic
681
    simulation::total_weight += p.wgt();
32,334,698✔
682
  }
683

684
  // Force calculation of cross-sections by setting last energy to zero
685
  if (settings::run_CE) {
36,224,162✔
686
    p.invalidate_neutron_xs();
15,397,154✔
687
  }
688

689
  // Prepare to write out particle track.
690
  if (p.write_track())
36,224,162✔
691
    add_particle_track(p);
138✔
692
}
36,224,162✔
693

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

700
int64_t compute_particle_id(int64_t index_source)
41,300,912✔
701
{
702
  if (settings::use_shared_secondary_bank) {
41,300,912✔
703
    return simulation::work_index[mpi::rank] + index_source +
4,174,094✔
704
           simulation::simulation_tracks_completed;
4,174,094✔
705
  } else {
706
    return simulation::work_index[mpi::rank] + index_source;
37,126,818✔
707
  }
708
}
709

710
int64_t compute_transport_seed(int64_t particle_id)
41,300,920✔
711
{
712
  if (settings::use_shared_secondary_bank) {
41,300,920✔
713
    return particle_id;
714
  } else {
715
    return (simulation::total_gen + overall_generation() - 1) *
37,126,824✔
716
             settings::n_particles +
717
           particle_id;
37,126,824✔
718
  }
719
}
720

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

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

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

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

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

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

752
  for (const auto& nuc : data::nuclides) {
6,710✔
753
    if (nuc->grid_.size() >= 1) {
5,652!
754
      int neutron = ParticleType::neutron().transport_index();
5,652✔
755
      data::energy_min[neutron] =
5,652✔
756
        std::max(data::energy_min[neutron], nuc->grid_[0].energy.front());
6,618✔
757
      data::energy_max[neutron] =
5,652✔
758
        std::min(data::energy_max[neutron], nuc->grid_[0].energy.back());
6,880✔
759
    }
760
  }
761

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

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

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

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

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

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

817
  // Set up logarithmic grid for nuclides
818
  for (auto& nuc : data::nuclides) {
6,710✔
819
    nuc->init_grid();
5,652✔
820
  }
821
  int neutron = ParticleType::neutron().transport_index();
1,058✔
822
  simulation::log_spacing =
2,116✔
823
    std::log(data::energy_max[neutron] / data::energy_min[neutron]) /
1,058✔
824
    settings::n_log_bins;
825
}
1,058✔
826

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

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

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

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

860
#endif
861

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

868
void transport_history_based_single_particle(Particle& p)
36,224,170✔
869
{
870
  while (p.alive()) {
1,115,772,959✔
871
    p.event_calculate_xs();
1,079,548,791✔
872
    if (p.alive()) {
1,079,548,791!
873
      p.event_advance();
1,079,548,791✔
874
    }
875
    if (p.alive()) {
1,079,548,791✔
876
      if (p.collision_distance() > p.boundary().distance()) {
1,079,507,895✔
877
        p.event_cross_surface();
482,122,860✔
878
      } else if (p.alive()) {
597,385,035✔
879
        p.event_collide();
597,385,035✔
880
      }
881
    }
882
    p.event_check_limit_and_revive();
1,079,548,789✔
883
  }
884
  p.event_death();
36,224,168✔
885
}
36,224,168✔
886

887
void transport_history_based()
23,738✔
888
{
889
#pragma omp parallel for schedule(runtime)
890
  for (int64_t i_work = 1; i_work <= simulation::work_per_rank; ++i_work) {
32,216,124✔
891
    Particle p;
32,192,390✔
892
    initialize_particle_track(p, i_work, false);
32,192,390✔
893
    transport_history_based_single_particle(p);
32,192,388✔
894
  }
32,192,386✔
895
}
23,734✔
896

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

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

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

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

927
#pragma omp for schedule(runtime)
928
    for (int64_t i = 1; i <= simulation::work_per_rank; i++) {
142,414✔
929
      Particle p;
142,310✔
930
      initialize_particle_track(p, i, false);
142,310✔
931
      transport_history_based_single_particle(p);
142,310✔
932
      for (auto& site : p.local_secondary_bank()) {
434,890✔
933
        thread_bank.push_back(site);
292,580✔
934
      }
935
    }
142,310✔
936

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

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

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

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

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

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

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

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

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

992
#pragma omp for schedule(runtime)
993
      for (int64_t i = 1; i <= simulation::shared_secondary_bank_read.size();
3,890,734✔
994
           i++) {
995
        Particle p;
3,889,464✔
996
        initialize_particle_track(p, i, true);
3,889,464✔
997
        SourceSite& site = simulation::shared_secondary_bank_read[i - 1];
3,889,464✔
998
        p.event_revive_from_secondary(site);
3,889,464✔
999
        transport_history_based_single_particle(p);
3,889,464✔
1000
        for (auto& secondary_site : p.local_secondary_bank()) {
7,486,348✔
1001
          thread_bank.push_back(secondary_site);
3,596,884✔
1002
        }
1003
      }
3,889,464✔
1004

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

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

UNCOV
1023
void transport_event_based()
×
1024
{
UNCOV
1025
  int64_t remaining_work = simulation::work_per_rank;
×
UNCOV
1026
  int64_t source_offset = 0;
×
1027

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

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

1043
    // Adjust remaining work and source offset variables
UNCOV
1044
    remaining_work -= n_particles;
×
UNCOV
1045
    source_offset += n_particles;
×
1046
  }
UNCOV
1047
}
×
1048

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

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

UNCOV
1061
  simulation::progeny_per_particle.resize(simulation::work_per_rank);
×
UNCOV
1062
  std::fill(simulation::progeny_per_particle.begin(),
×
UNCOV
1063
    simulation::progeny_per_particle.end(), 0);
×
1064

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

UNCOV
1070
  while (remaining_work > 0) {
×
UNCOV
1071
    int64_t n_particles =
×
UNCOV
1072
      std::min(remaining_work, settings::max_particles_in_flight);
×
1073

UNCOV
1074
    process_init_events(n_particles, source_offset);
×
UNCOV
1075
    process_transport_events();
×
UNCOV
1076
    process_death_events(n_particles);
×
1077

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

UNCOV
1086
    remaining_work -= n_particles;
×
UNCOV
1087
    source_offset += n_particles;
×
1088
  }
1089

UNCOV
1090
  simulation::simulation_tracks_completed += settings::n_particles;
×
1091

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

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

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

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

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

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

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

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

UNCOV
1139
    while (sec_remaining > 0) {
×
UNCOV
1140
      int64_t n_particles =
×
UNCOV
1141
        std::min(sec_remaining, settings::max_particles_in_flight);
×
1142

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

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

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

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

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