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

openmc-dev / openmc / 28400627666

29 Jun 2026 08:29PM UTC coverage: 81.304% (+0.02%) from 81.281%
28400627666

Pull #3734

github

web-flow
Merge e517af4f6 into 4d6244d93
Pull Request #3734: Specify temperature from a field (structured mesh only)

18315 of 26537 branches covered (69.02%)

Branch coverage included in aggregate %.

285 of 318 new or added lines in 18 files covered. (89.62%)

14 existing lines in 2 files now uncovered.

59513 of 69188 relevant lines covered (86.02%)

49157606.49 hits per line

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

95.19
/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/constants.h"
7
#include "openmc/container_util.h"
8
#include "openmc/eigenvalue.h"
9
#include "openmc/error.h"
10
#include "openmc/event.h"
11
#include "openmc/field.h"
12
#include "openmc/geometry_aux.h"
13
#include "openmc/ifp.h"
14
#include "openmc/material.h"
15
#include "openmc/message_passing.h"
16
#include "openmc/nuclide.h"
17
#include "openmc/output.h"
18
#include "openmc/particle.h"
19
#include "openmc/photon.h"
20
#include "openmc/random_lcg.h"
21
#include "openmc/settings.h"
22
#include "openmc/source.h"
23
#include "openmc/state_point.h"
24
#include "openmc/tallies/derivative.h"
25
#include "openmc/tallies/filter.h"
26
#include "openmc/tallies/tally.h"
27
#include "openmc/tallies/trigger.h"
28
#include "openmc/timer.h"
29
#include "openmc/track_output.h"
30
#include "openmc/weight_windows.h"
31

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

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

41
#include <fmt/format.h>
42

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

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

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

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

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

67
  int err = 0;
68
  while (status == 0 && err == 0) {
151,515✔
69
    err = openmc_next_batch(&status);
144,731✔
70
  }
71

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

77
int openmc_simulation_init()
7,969✔
78
{
79
  using namespace openmc;
7,969✔
80

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

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

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

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

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

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

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

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

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

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

143
  // Display header
144
  if (mpi::master) {
7,947✔
145
    if (settings::run_mode == RunMode::FIXED_SOURCE) {
6,887✔
146
      if (settings::solver_type == SolverType::MONTE_CARLO) {
2,964✔
147
        header("FIXED SOURCE TRANSPORT SIMULATION", 3);
2,588✔
148
      } else if (settings::solver_type == SolverType::RANDOM_RAY) {
376!
149
        header("FIXED SOURCE TRANSPORT SIMULATION (RANDOM RAY SOLVER)", 3);
376✔
150
      }
151
    } else if (settings::run_mode == RunMode::EIGENVALUE) {
3,923!
152
      if (settings::solver_type == SolverType::MONTE_CARLO) {
3,923✔
153
        header("K EIGENVALUE SIMULATION", 3);
3,648✔
154
      } else if (settings::solver_type == SolverType::RANDOM_RAY) {
275!
155
        header("K EIGENVALUE SIMULATION (RANDOM RAY SOLVER)", 3);
275✔
156
      }
157
      if (settings::verbosity >= 7)
3,923✔
158
        print_columns();
3,543✔
159
    }
160
  }
161

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

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

172
int openmc_simulation_finalize()
7,934✔
173
{
174
  using namespace openmc;
7,934✔
175

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

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

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

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

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

197
#ifdef OPENMC_MPI
198
  broadcast_results();
3,582✔
199
#endif
200

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

205
  // If weight window generators are present in this simulation,
206
  // write a weight windows file
207
  if (variance_reduction::weight_windows_generators.size() > 0) {
7,934✔
208
    openmc_weight_windows_export();
166✔
209
  }
210

211
  // Deactivate all tallies
212
  for (auto& t : model::tallies) {
35,633✔
213
    t->active_ = false;
27,699✔
214
  }
215

216
  // Stop timers and show timing statistics
217
  simulation::time_finalize.stop();
7,934✔
218
  simulation::time_total.stop();
7,934✔
219

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

233
  if (mpi::master) {
7,934✔
234
    if (settings::solver_type != SolverType::RANDOM_RAY) {
6,874✔
235
      if (settings::verbosity >= 6)
6,223✔
236
        print_runtime();
5,843✔
237
      if (settings::verbosity >= 4)
6,223✔
238
        print_results();
5,843✔
239
    }
240
  }
241
  if (settings::check_overlaps)
7,934!
242
    print_overlap_check();
×
243

244
  // Reset flags
245
  simulation::initialized = false;
7,934✔
246
  return 0;
7,934✔
247
}
248

249
int openmc_next_batch(int* status)
148,856✔
250
{
251
  using namespace openmc;
148,856✔
252
  using openmc::simulation::current_gen;
148,856✔
253

254
  // Make sure simulation has been initialized
255
  if (!simulation::initialized) {
148,856✔
256
    set_errmsg("Simulation has not been initialized yet.");
11✔
257
    return OPENMC_E_ALLOCATE;
11✔
258
  }
259

260
  initialize_batch();
148,845✔
261

262
  // =======================================================================
263
  // LOOP OVER GENERATIONS
264
  for (current_gen = 1; current_gen <= settings::gen_per_batch; ++current_gen) {
297,887✔
265

266
    initialize_generation();
149,055✔
267

268
    // Start timer for transport
269
    simulation::time_transport.start();
149,055✔
270

271
    // Transport loop
272
    if (settings::event_based) {
149,055✔
273
      if (settings::use_shared_secondary_bank) {
3,461✔
274
        transport_event_based_shared_secondary();
11✔
275
      } else {
276
        transport_event_based();
3,450✔
277
      }
278
    } else {
279
      if (settings::use_shared_secondary_bank) {
145,594✔
280
        transport_history_based_shared_secondary();
667✔
281
      } else {
282
        transport_history_based();
144,927✔
283
      }
284
    }
285

286
    // Accumulate time for transport
287
    simulation::time_transport.stop();
149,042✔
288

289
    finalize_generation();
149,042✔
290
  }
291

292
  finalize_batch();
148,832✔
293

294
  // Check simulation ending criteria
295
  if (status) {
148,832!
296
    if (simulation::current_batch >= settings::n_max_batches) {
148,832✔
297
      *status = STATUS_EXIT_MAX_BATCH;
6,977✔
298
    } else if (simulation::satisfy_triggers) {
141,855✔
299
      *status = STATUS_EXIT_ON_TRIGGER;
93✔
300
    } else {
301
      *status = STATUS_EXIT_NORMAL;
141,762✔
302
    }
303
  }
304
  return 0;
305
}
306

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

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

318
namespace openmc {
319

320
//==============================================================================
321
// Global variables
322
//==============================================================================
323

324
namespace simulation {
325

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

345
const RegularMesh* entropy_mesh {nullptr};
346
const RegularMesh* ufs_mesh {nullptr};
347

348
TemperatureField temperature_field;
349

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

353
int64_t simulation_tracks_completed {0};
354

355
} // namespace simulation
356

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

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

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

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

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

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

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

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

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

416
  // Manage active/inactive timers and activate tallies if necessary.
417
  if (first_inactive) {
169,696✔
418
    simulation::time_inactive.start();
3,865✔
419
  } else if (first_active) {
165,942✔
420
    simulation::time_inactive.stop();
7,900✔
421
    simulation::time_active.start();
7,900✔
422
    for (auto& t : model::tallies) {
35,577✔
423
      t->active_ = true;
27,677✔
424
    }
425
  }
426

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

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

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

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

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

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

475
  if (settings::run_mode == RunMode::EIGENVALUE) {
169,794✔
476
    // Write out a separate source point if it's been specified for this batch
477
    if (contains(settings::sourcepoint_batch, simulation::current_batch) &&
109,398✔
478
        settings::source_write && settings::source_separate) {
109,027✔
479

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

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

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

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

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

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

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

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

545
    // Store current value of tracklength k
546
    simulation::keff_generation = simulation::global_tallies(
104,913✔
547
      GlobalTally::K_TRACKLENGTH, TallyResult::VALUE);
548
  }
549
}
170,017✔
550

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

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

565
  // reset tallies
566
  if (settings::run_mode == RunMode::EIGENVALUE) {
170,004✔
567
    global_tally_collision = 0.0;
104,913✔
568
    global_tally_absorption = 0.0;
104,913✔
569
    global_tally_tracklength = 0.0;
104,913✔
570
  }
571
  global_tally_leakage = 0.0;
170,004✔
572

573
  if (settings::run_mode == RunMode::EIGENVALUE &&
170,004✔
574
      settings::solver_type == SolverType::MONTE_CARLO) {
104,913✔
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);
98,063✔
579

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

584
  if (settings::run_mode == RunMode::EIGENVALUE) {
170,004✔
585

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

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

595
    // Write generation output
596
    if (mpi::master && settings::verbosity >= 7) {
104,913✔
597
      print_generation();
78,808✔
598
    }
599
  }
600
}
170,004✔
601

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

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

627
  p.current_work() = index_source - 1;
199,738,749✔
628

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

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

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

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

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

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

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

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

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

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

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

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

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

678
  // Add particle's starting weight to count for normalizing tallies later
679
  if (!is_secondary) {
199,738,749✔
680
#pragma omp atomic
97,695,629✔
681
    simulation::total_weight += p.wgt();
178,398,188✔
682
  }
683

684
  // Force calculation of cross-sections by setting last energy to zero
685
  if (settings::run_CE) {
199,738,749✔
686
    p.invalidate_neutron_xs();
85,190,205✔
687
  }
688

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

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

700
int64_t compute_particle_id(int64_t index_source)
227,689,216✔
701
{
702
  if (settings::use_shared_secondary_bank) {
227,689,216✔
703
    return simulation::work_index[mpi::rank] + index_source +
22,909,586✔
704
           simulation::simulation_tracks_completed;
22,909,586✔
705
  } else {
706
    return simulation::work_index[mpi::rank] + index_source;
204,779,630✔
707
  }
708
}
709

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

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

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

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

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

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

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

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

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

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

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

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

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

798
  // Show which nuclide results in lowest energy for neutron transport
799
  for (const auto& nuc : data::nuclides) {
8,204✔
800
    // If a nuclide is present in a material that's not used in the model, its
801
    // grid has not been allocated
802
    if (nuc->grid_.size() > 0) {
7,683!
803
      double max_E = nuc->grid_[0].energy.back();
7,683✔
804
      int neutron = ParticleType::neutron().transport_index();
7,683✔
805
      if (max_E == data::energy_max[neutron]) {
7,683✔
806
        write_message(7, "Maximum neutron transport energy: {} eV for {}",
6,059✔
807
          data::energy_max[neutron], nuc->name_);
6,059✔
808
        if (mpi::master && data::energy_max[neutron] < 20.0e6) {
6,059!
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) {
40,566✔
819
    nuc->init_grid();
33,986✔
820
  }
821
  int neutron = ParticleType::neutron().transport_index();
6,580✔
822
  simulation::log_spacing =
13,160✔
823
    std::log(data::energy_max[neutron] / data::energy_min[neutron]) /
6,580✔
824
    settings::n_log_bins;
825
}
6,580✔
826

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

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

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

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

860
#endif
861

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

868
void transport_history_based_single_particle(Particle& p)
187,354,696✔
869
{
870
  while (p.alive()) {
2,147,483,647✔
871
    p.event_calculate_xs();
2,147,483,647✔
872
    if (p.alive()) {
2,147,483,647!
873
      p.event_advance();
2,147,483,647✔
874
    }
875
    if (p.alive()) {
2,147,483,647!
876
      switch (p.next_event().event_type) {
2,147,483,647!
877
      case EVENT_CROSS_SURFACE:
2,147,483,647✔
878
        p.event_cross_surface();
2,147,483,647✔
879
        break;
2,147,483,647✔
880
      case EVENT_COLLIDE:
2,147,483,647✔
881
        p.event_collide();
2,147,483,647✔
882
        break;
2,147,483,647✔
883
      case EVENT_TIME_CUTOFF:
223,928✔
884
        p.wgt() = 0.0;
223,928✔
885
        break;
223,928✔
NEW
886
      default:
×
NEW
887
        fatal_error(
×
NEW
888
          fmt::format("Unknown event '{}' in history-based transport!",
×
NEW
889
            p.next_event().event_type));
×
890
        break;
891
      }
892
    }
893
    p.event_check_limit_and_revive();
2,147,483,647✔
894
  }
895
  p.event_death();
187,354,687✔
896
}
187,354,687✔
897

898
void transport_history_based()
144,927✔
899
{
900
#pragma omp parallel for schedule(runtime)
80,867✔
901
  for (int64_t i_work = 1; i_work <= simulation::work_per_rank; ++i_work) {
80,709,710✔
902
    Particle p;
80,645,659✔
903
    initialize_particle_track(p, i_work, false);
80,645,659✔
904
    transport_history_based_single_particle(p);
80,645,655✔
905
  }
80,645,650✔
906
}
144,918✔
907

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

922
  if (mpi::master) {
667✔
923
    write_message(fmt::format(" Primary source          particles: {}",
1,150✔
924
                    settings::n_particles),
925
      6);
926
  }
927

928
  simulation::progeny_per_particle.resize(simulation::work_per_rank);
667✔
929
  std::fill(simulation::progeny_per_particle.begin(),
1,334✔
930
    simulation::progeny_per_particle.end(), 0);
667✔
931

932
  // Phase 1: Transport primary particles and deposit first generation of
933
  // secondaries in the shared secondary bank
934
#pragma omp parallel
384✔
935
  {
283✔
936
    vector<SourceSite> thread_bank;
283✔
937

938
#pragma omp for schedule(runtime)
939
    for (int64_t i = 1; i <= simulation::work_per_rank; i++) {
356,058✔
940
      Particle p;
355,775✔
941
      initialize_particle_track(p, i, false);
355,775✔
942
      transport_history_based_single_particle(p);
355,775✔
943
      for (auto& site : p.local_secondary_bank()) {
1,087,360✔
944
        thread_bank.push_back(site);
731,585✔
945
      }
946
    }
355,775✔
947

948
    // Drain thread-local bank into the shared secondary bank (once per thread)
949
#pragma omp critical(SharedSecondaryBank)
950
    {
283✔
951
      for (auto& site : thread_bank) {
731,868✔
952
        simulation::shared_secondary_bank_write.thread_unsafe_append(site);
731,585✔
953
      }
954
    }
955
  }
956

957
  simulation::simulation_tracks_completed += settings::n_particles;
667✔
958

959
  // Phase 2: Now that the secondary bank has been populated, enter loop over
960
  // all secondary generations
961
  int n_generation_depth = 1;
667✔
962
  int64_t alive_secondary = 1;
667✔
963
  while (alive_secondary) {
8,891✔
964

965
    // Sort the shared secondary bank by parent ID then progeny ID to
966
    // ensure reproducibility.
967
    sort_bank(simulation::shared_secondary_bank_write, false);
8,224✔
968

969
    // Synchronize the shared secondary bank amongst all MPI ranks, such
970
    // that each MPI rank has an approximately equal number of secondary
971
    // tracks. Also reports the total number of secondaries alive across
972
    // all MPI ranks.
973
    alive_secondary = synchronize_global_secondary_bank(
8,224✔
974
      simulation::shared_secondary_bank_write);
975

976
    // Recalculate work for each MPI rank based on number of alive secondary
977
    // tracks
978
    calculate_work(alive_secondary);
8,224✔
979

980
    // Display the number of secondary tracks in this generation. This
981
    // is useful for user monitoring so as to see if the secondary population is
982
    // exploding and to determine how many generations of secondaries are being
983
    // transported.
984
    if (mpi::master) {
8,224✔
985
      write_message(fmt::format(" Secondary generation {:<2}    tracks: {}",
13,120✔
986
                      n_generation_depth, alive_secondary),
987
        6);
988
    }
989

990
    simulation::shared_secondary_bank_read =
8,224✔
991
      std::move(simulation::shared_secondary_bank_write);
8,224✔
992
    simulation::shared_secondary_bank_write = SharedArray<SourceSite>();
8,224!
993
    simulation::progeny_per_particle.resize(
8,224✔
994
      simulation::shared_secondary_bank_read.size());
8,224✔
995
    std::fill(simulation::progeny_per_particle.begin(),
16,448✔
996
      simulation::progeny_per_particle.end(), 0);
8,224✔
997

998
    // Transport all secondary tracks from the shared secondary bank
999
#pragma omp parallel
4,643✔
1000
    {
3,581✔
1001
      vector<SourceSite> thread_bank;
3,581✔
1002

1003
#pragma omp for schedule(runtime)
1004
      for (int64_t i = 1; i <= simulation::shared_secondary_bank_read.size();
9,728,676✔
1005
           i++) {
1006
        Particle p;
9,725,095✔
1007
        initialize_particle_track(p, i, true);
9,725,095✔
1008
        SourceSite& site = simulation::shared_secondary_bank_read[i - 1];
9,725,095✔
1009
        p.event_revive_from_secondary(site);
9,725,095✔
1010
        transport_history_based_single_particle(p);
9,725,095✔
1011
        for (auto& secondary_site : p.local_secondary_bank()) {
18,718,605✔
1012
          thread_bank.push_back(secondary_site);
8,993,510✔
1013
        }
1014
      }
9,725,095✔
1015

1016
      // Drain thread-local bank into the shared secondary bank (once per
1017
      // thread)
1018
#pragma omp critical(SharedSecondaryBank)
1019
      {
3,581✔
1020
        for (auto& secondary_site : thread_bank) {
8,997,091✔
1021
          simulation::shared_secondary_bank_write.thread_unsafe_append(
8,993,510✔
1022
            secondary_site);
1023
        }
1024
      }
1025
    } // End of transport loop over tracks in shared secondary bank
3,581✔
1026
    n_generation_depth++;
8,224✔
1027
    simulation::simulation_tracks_completed += alive_secondary;
8,224✔
1028
  } // End of loop over secondary generations
1029

1030
  // Reset work so that fission bank etc works correctly
1031
  calculate_work(settings::n_particles);
667✔
1032
}
667✔
1033

1034
void transport_event_based()
3,450✔
1035
{
1036
  int64_t remaining_work = simulation::work_per_rank;
3,450✔
1037
  int64_t source_offset = 0;
3,450✔
1038

1039
  // To cap the total amount of memory used to store particle object data, the
1040
  // number of particles in flight at any point in time can bet set. In the case
1041
  // that the maximum in flight particle count is lower than the total number
1042
  // of particles that need to be run this iteration, the event-based transport
1043
  // loop is executed multiple times until all particles have been completed.
1044
  while (remaining_work > 0) {
6,900✔
1045
    // Figure out # of particles to run for this subiteration
1046
    int64_t n_particles =
3,450!
1047
      std::min(remaining_work, settings::max_particles_in_flight);
3,450✔
1048

1049
    // Initialize all particle histories for this subiteration
1050
    process_init_events(n_particles, source_offset);
3,450✔
1051
    process_transport_events();
3,450✔
1052
    process_death_events(n_particles);
3,450✔
1053

1054
    // Adjust remaining work and source offset variables
1055
    remaining_work -= n_particles;
3,450✔
1056
    source_offset += n_particles;
3,450✔
1057
  }
1058
}
3,450✔
1059

1060
void transport_event_based_shared_secondary()
11✔
1061
{
1062
  // Clear shared secondary banks from any prior use
1063
  simulation::shared_secondary_bank_read.clear();
11✔
1064
  simulation::shared_secondary_bank_write.clear();
11✔
1065

1066
  if (mpi::master) {
11!
1067
    write_message(fmt::format(" Primary source          particles: {}",
22!
1068
                    settings::n_particles),
1069
      6);
1070
  }
1071

1072
  simulation::progeny_per_particle.resize(simulation::work_per_rank);
11✔
1073
  std::fill(simulation::progeny_per_particle.begin(),
22✔
1074
    simulation::progeny_per_particle.end(), 0);
11✔
1075

1076
  // Phase 1: Transport primary particles using event-based processing and
1077
  // deposit first generation of secondaries in the shared secondary bank
1078
  int64_t remaining_work = simulation::work_per_rank;
11✔
1079
  int64_t source_offset = 0;
11✔
1080

1081
  while (remaining_work > 0) {
22✔
1082
    int64_t n_particles =
11!
1083
      std::min(remaining_work, settings::max_particles_in_flight);
11✔
1084

1085
    process_init_events(n_particles, source_offset);
11✔
1086
    process_transport_events();
11✔
1087
    process_death_events(n_particles);
11✔
1088

1089
    // Collect secondaries from all particle buffers into shared bank
1090
    for (int64_t i = 0; i < n_particles; i++) {
1,661✔
1091
      for (auto& site : simulation::particles[i].local_secondary_bank()) {
6,159✔
1092
        simulation::shared_secondary_bank_write.thread_unsafe_append(site);
4,509✔
1093
      }
1094
      simulation::particles[i].local_secondary_bank().clear();
3,016✔
1095
    }
1096

1097
    remaining_work -= n_particles;
11✔
1098
    source_offset += n_particles;
11✔
1099
  }
1100

1101
  simulation::simulation_tracks_completed += settings::n_particles;
11✔
1102

1103
  // Phase 2: Now that the secondary bank has been populated, enter loop over
1104
  // all secondary generations
1105
  int n_generation_depth = 1;
11✔
1106
  int64_t alive_secondary = 1;
11✔
1107
  while (alive_secondary) {
415✔
1108

1109
    // Sort the shared secondary bank by parent ID then progeny ID to
1110
    // ensure reproducibility.
1111
    sort_bank(simulation::shared_secondary_bank_write, false);
404✔
1112

1113
    // Synchronize the shared secondary bank amongst all MPI ranks, such
1114
    // that each MPI rank has an approximately equal number of secondary
1115
    // tracks.
1116
    alive_secondary = synchronize_global_secondary_bank(
404✔
1117
      simulation::shared_secondary_bank_write);
1118

1119
    // Recalculate work for each MPI rank based on number of alive secondary
1120
    // tracks
1121
    calculate_work(alive_secondary);
404✔
1122

1123
    if (mpi::master) {
404!
1124
      write_message(fmt::format(" Secondary generation {:<2}    tracks: {}",
808!
1125
                      n_generation_depth, alive_secondary),
1126
        6);
1127
    }
1128

1129
    simulation::shared_secondary_bank_read =
404✔
1130
      std::move(simulation::shared_secondary_bank_write);
404✔
1131
    simulation::shared_secondary_bank_write = SharedArray<SourceSite>();
404!
1132
    simulation::progeny_per_particle.resize(
404✔
1133
      simulation::shared_secondary_bank_read.size());
404✔
1134
    std::fill(simulation::progeny_per_particle.begin(),
808✔
1135
      simulation::progeny_per_particle.end(), 0);
404✔
1136

1137
    // Ensure particle buffer is large enough for this secondary generation
1138
    int64_t sec_buffer_length = std::min(
404!
1139
      static_cast<int64_t>(simulation::shared_secondary_bank_read.size()),
404!
1140
      settings::max_particles_in_flight);
404✔
1141
    if (sec_buffer_length >
404✔
1142
        static_cast<int64_t>(simulation::particles.size())) {
404✔
1143
      init_event_queues(sec_buffer_length);
35✔
1144
    }
1145

1146
    // Transport secondary tracks using event-based processing
1147
    int64_t sec_remaining = simulation::shared_secondary_bank_read.size();
404✔
1148
    int64_t sec_offset = 0;
404✔
1149

1150
    while (sec_remaining > 0) {
797✔
1151
      int64_t n_particles =
393!
1152
        std::min(sec_remaining, settings::max_particles_in_flight);
393✔
1153

1154
      process_init_secondary_events(
393✔
1155
        n_particles, sec_offset, simulation::shared_secondary_bank_read);
1156
      process_transport_events();
393✔
1157
      process_death_events(n_particles);
393✔
1158

1159
      // Collect secondaries from all particle buffers into shared bank
1160
      for (int64_t i = 0; i < n_particles; i++) {
180,290✔
1161
        for (auto& site : simulation::particles[i].local_secondary_bank()) {
355,285✔
1162
          simulation::shared_secondary_bank_write.thread_unsafe_append(site);
175,388✔
1163
        }
1164
        simulation::particles[i].local_secondary_bank().clear();
226,415✔
1165
      }
1166

1167
      sec_remaining -= n_particles;
393✔
1168
      sec_offset += n_particles;
393✔
1169
    } // End of subiteration loop over secondary tracks
1170
    n_generation_depth++;
404✔
1171
    simulation::simulation_tracks_completed += alive_secondary;
404✔
1172
  } // End of loop over secondary generations
1173

1174
  // Reset work so that fission bank etc works correctly
1175
  calculate_work(settings::n_particles);
11✔
1176
}
11✔
1177

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