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

openmc-dev / openmc / 14178819009

31 Mar 2025 06:35PM UTC coverage: 85.21% (+0.08%) from 85.126%
14178819009

Pull #3351

github

web-flow
Merge e1e88c91a into 24655dfd5
Pull Request #3351: Random Ray AutoMagic Setup

263 of 278 new or added lines in 7 files covered. (94.6%)

101 existing lines in 4 files now uncovered.

51853 of 60853 relevant lines covered (85.21%)

38660801.39 hits per line

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

88.16
/src/random_ray/random_ray_simulation.cpp
1
#include "openmc/random_ray/random_ray_simulation.h"
2

3
#include "openmc/eigenvalue.h"
4
#include "openmc/geometry.h"
5
#include "openmc/message_passing.h"
6
#include "openmc/mgxs_interface.h"
7
#include "openmc/output.h"
8
#include "openmc/plot.h"
9
#include "openmc/random_ray/flat_source_domain.h"
10
#include "openmc/random_ray/random_ray.h"
11
#include "openmc/simulation.h"
12
#include "openmc/source.h"
13
#include "openmc/tallies/filter.h"
14
#include "openmc/tallies/tally.h"
15
#include "openmc/tallies/tally_scoring.h"
16
#include "openmc/timer.h"
17
#include "openmc/weight_windows.h"
18

19
namespace openmc {
20

21
//==============================================================================
22
// Non-member functions
23
//==============================================================================
24

25
void openmc_run_random_ray()
544✔
26
{
27
  //////////////////////////////////////////////////////////
28
  // Run forward simulation
29
  //////////////////////////////////////////////////////////
30

31
  // Check if adjoint calculation is needed. If it is, we will run the forward
32
  // calculation first and then the adjoint calculation later.
33
  bool adjoint_needed = FlatSourceDomain::adjoint_;
544✔
34

35
  // Configure the domain for forward simulation
36
  FlatSourceDomain::adjoint_ = false;
544✔
37

38
  // If we're going to do an adjoint simulation afterwards, report that this is
39
  // the initial forward flux solve.
40
  if (adjoint_needed && mpi::master)
544✔
41
    header("FORWARD FLUX SOLVE", 3);
55✔
42

43
  // Initialize OpenMC general data structures
44
  openmc_simulation_init();
544✔
45

46
  // Validate that inputs meet requirements for random ray mode
47
  if (mpi::master)
544✔
48
    validate_random_ray_inputs();
374✔
49

50
  // Declare forward flux so that it can be saved for later adjoint simulation
51
  vector<double> forward_flux;
544✔
52
  SourceRegionContainer forward_source_regions;
544✔
53
  SourceRegionContainer forward_base_source_regions;
544✔
54
  std::unordered_map<SourceRegionKey, int64_t, SourceRegionKey::HashFunctor>
55
    forward_source_region_map;
544✔
56

57
  {
58
    // Initialize Random Ray Simulation Object
59
    RandomRaySimulation sim;
544✔
60

61
    // Initialize fixed sources, if present
62
    sim.apply_fixed_sources_and_mesh_domains();
544✔
63

64
    // Begin main simulation timer
65
    simulation::time_total.start();
544✔
66

67
    // Execute random ray simulation
68
    sim.simulate();
544✔
69

70
    // End main simulation timer
71
    simulation::time_total.stop();
544✔
72

73
    // Normalize and save the final forward flux
74
    sim.domain()->serialize_final_fluxes(forward_flux);
544✔
75

76
    double source_normalization_factor =
77
      sim.domain()->compute_fixed_source_normalization_factor() /
544✔
78
      (settings::n_batches - settings::n_inactive);
544✔
79

80
#pragma omp parallel for
306✔
81
    for (uint64_t i = 0; i < forward_flux.size(); i++) {
1,021,834✔
82
      forward_flux[i] *= source_normalization_factor;
1,021,596✔
83
    }
84

85
    forward_source_regions = sim.domain()->source_regions_;
544✔
86
    forward_source_region_map = sim.domain()->source_region_map_;
544✔
87
    forward_base_source_regions = sim.domain()->base_source_regions_;
544✔
88

89
    // Finalize OpenMC
90
    openmc_simulation_finalize();
544✔
91

92
    // Output all simulation results
93
    sim.output_simulation_results();
544✔
94
  }
544✔
95

96
  //////////////////////////////////////////////////////////
97
  // Run adjoint simulation (if enabled)
98
  //////////////////////////////////////////////////////////
99

100
  if (adjoint_needed) {
544✔
101
    reset_timers();
80✔
102

103
    // Configure the domain for adjoint simulation
104
    FlatSourceDomain::adjoint_ = true;
80✔
105

106
    if (mpi::master)
80✔
107
      header("ADJOINT FLUX SOLVE", 3);
55✔
108

109
    // Initialize OpenMC general data structures
110
    openmc_simulation_init();
80✔
111

112
    // Initialize Random Ray Simulation Object
113
    RandomRaySimulation adjoint_sim;
80✔
114

115
    // Initialize adjoint fixed sources, if present
116
    adjoint_sim.prepare_fixed_sources_adjoint(forward_flux,
80✔
117
      forward_source_regions, forward_base_source_regions,
118
      forward_source_region_map);
119

120
    // Transpose scattering matrix
121
    adjoint_sim.domain()->transpose_scattering_matrix();
80✔
122

123
    // Swap nu_sigma_f and chi
124
    adjoint_sim.domain()->nu_sigma_f_.swap(adjoint_sim.domain()->chi_);
80✔
125

126
    // Begin main simulation timer
127
    simulation::time_total.start();
80✔
128

129
    // Execute random ray simulation
130
    adjoint_sim.simulate();
80✔
131

132
    // End main simulation timer
133
    simulation::time_total.stop();
80✔
134

135
    // Finalize OpenMC
136
    openmc_simulation_finalize();
80✔
137

138
    // Output all simulation results
139
    adjoint_sim.output_simulation_results();
80✔
140
  }
80✔
141
}
544✔
142

143
// Enforces restrictions on inputs in random ray mode.  While there are
144
// many features that don't make sense in random ray mode, and are therefore
145
// unsupported, we limit our testing/enforcement operations only to inputs
146
// that may cause erroneous/misleading output or crashes from the solver.
147
void validate_random_ray_inputs()
374✔
148
{
149
  // Validate tallies
150
  ///////////////////////////////////////////////////////////////////
151
  for (auto& tally : model::tallies) {
1,188✔
152

153
    // Validate score types
154
    for (auto score_bin : tally->scores_) {
1,804✔
155
      switch (score_bin) {
990✔
156
      case SCORE_FLUX:
990✔
157
      case SCORE_TOTAL:
158
      case SCORE_FISSION:
159
      case SCORE_NU_FISSION:
160
      case SCORE_EVENTS:
161
        break;
990✔
162
      default:
×
163
        fatal_error(
×
164
          "Invalid score specified. Only flux, total, fission, nu-fission, and "
165
          "event scores are supported in random ray mode.");
166
      }
167
    }
168

169
    // Validate filter types
170
    for (auto f : tally->filters()) {
1,782✔
171
      auto& filter = *model::tally_filters[f];
968✔
172

173
      switch (filter.type()) {
968✔
174
      case FilterType::CELL:
968✔
175
      case FilterType::CELL_INSTANCE:
176
      case FilterType::DISTRIBCELL:
177
      case FilterType::ENERGY:
178
      case FilterType::MATERIAL:
179
      case FilterType::MESH:
180
      case FilterType::UNIVERSE:
181
      case FilterType::PARTICLE:
182
        break;
968✔
183
      default:
×
184
        fatal_error("Invalid filter specified. Only cell, cell_instance, "
×
185
                    "distribcell, energy, material, mesh, and universe filters "
186
                    "are supported in random ray mode.");
187
      }
188
    }
189
  }
190

191
  // Validate MGXS data
192
  ///////////////////////////////////////////////////////////////////
193
  for (auto& material : data::mg.macro_xs_) {
1,386✔
194
    if (!material.is_isotropic) {
1,012✔
195
      fatal_error("Anisotropic MGXS detected. Only isotropic XS data sets "
×
196
                  "supported in random ray mode.");
197
    }
198
    if (material.get_xsdata().size() > 1) {
1,012✔
199
      fatal_error("Non-isothermal MGXS detected. Only isothermal XS data sets "
×
200
                  "supported in random ray mode.");
201
    }
202
    for (int g = 0; g < data::mg.num_energy_groups_; g++) {
5,456✔
203
      if (material.exists_in_model) {
4,444✔
204
        // Temperature and angle indices, if using multiple temperature
205
        // data sets and/or anisotropic data sets.
206
        // TODO: Currently assumes we are only using single temp/single angle
207
        // data.
208
        const int t = 0;
4,400✔
209
        const int a = 0;
4,400✔
210
        double sigma_t =
211
          material.get_xs(MgxsType::TOTAL, g, NULL, NULL, NULL, t, a);
4,400✔
212
        if (sigma_t <= 0.0) {
4,400✔
213
          fatal_error("No zero or negative total macroscopic cross sections "
×
214
                      "allowed in random ray mode. If the intention is to make "
215
                      "a void material, use a cell fill of 'None' instead.");
216
        }
217
      }
218
    }
219
  }
220

221
  // Validate ray source
222
  ///////////////////////////////////////////////////////////////////
223

224
  // Check for independent source
225
  IndependentSource* is =
226
    dynamic_cast<IndependentSource*>(RandomRay::ray_source_.get());
374✔
227
  if (!is) {
374✔
228
    fatal_error("Invalid ray source definition. Ray source must provided and "
×
229
                "be of type IndependentSource.");
230
  }
231

232
  // Check for box source
233
  SpatialDistribution* space_dist = is->space();
374✔
234
  SpatialBox* sb = dynamic_cast<SpatialBox*>(space_dist);
374✔
235
  if (!sb) {
374✔
236
    fatal_error(
×
237
      "Invalid ray source definition -- only box sources are allowed.");
238
  }
239

240
  // Check that box source is not restricted to fissionable areas
241
  if (sb->only_fissionable()) {
374✔
242
    fatal_error(
×
243
      "Invalid ray source definition -- fissionable spatial distribution "
244
      "not allowed.");
245
  }
246

247
  // Check for isotropic source
248
  UnitSphereDistribution* angle_dist = is->angle();
374✔
249
  Isotropic* id = dynamic_cast<Isotropic*>(angle_dist);
374✔
250
  if (!id) {
374✔
251
    fatal_error("Invalid ray source definition -- only isotropic sources are "
×
252
                "allowed.");
253
  }
254

255
  // Validate external sources
256
  ///////////////////////////////////////////////////////////////////
257
  if (settings::run_mode == RunMode::FIXED_SOURCE) {
374✔
258
    if (model::external_sources.size() < 1) {
253✔
259
      fatal_error("Must provide a particle source (in addition to ray source) "
×
260
                  "in fixed source random ray mode.");
261
    }
262

263
    for (int i = 0; i < model::external_sources.size(); i++) {
506✔
264
      Source* s = model::external_sources[i].get();
253✔
265

266
      // Check for independent source
267
      IndependentSource* is = dynamic_cast<IndependentSource*>(s);
253✔
268

269
      if (!is) {
253✔
270
        fatal_error(
×
271
          "Only IndependentSource external source types are allowed in "
272
          "random ray mode");
273
      }
274

275
      // Check for isotropic source
276
      UnitSphereDistribution* angle_dist = is->angle();
253✔
277
      Isotropic* id = dynamic_cast<Isotropic*>(angle_dist);
253✔
278
      if (!id) {
253✔
279
        fatal_error(
×
280
          "Invalid source definition -- only isotropic external sources are "
281
          "allowed in random ray mode.");
282
      }
283

284
      // Validate that a domain ID was specified
285
      if (is->domain_ids().size() == 0) {
253✔
286
        fatal_error("Fixed sources must be specified by domain "
×
287
                    "id (cell, material, or universe) in random ray mode.");
288
      }
289

290
      // Check that a discrete energy distribution was used
291
      Distribution* d = is->energy();
253✔
292
      Discrete* dd = dynamic_cast<Discrete*>(d);
253✔
293
      if (!dd) {
253✔
294
        fatal_error(
×
295
          "Only discrete (multigroup) energy distributions are allowed for "
296
          "external sources in random ray mode.");
297
      }
298
    }
299
  }
300

301
  // Validate plotting files
302
  ///////////////////////////////////////////////////////////////////
303
  for (int p = 0; p < model::plots.size(); p++) {
374✔
304

305
    // Get handle to OpenMC plot object
306
    const auto& openmc_plottable = model::plots[p];
×
UNCOV
307
    Plot* openmc_plot = dynamic_cast<Plot*>(openmc_plottable.get());
×
308

309
    // Random ray plots only support voxel plots
310
    if (!openmc_plot) {
×
UNCOV
311
      warning(fmt::format(
×
312
        "Plot {} will not be used for end of simulation data plotting -- only "
313
        "voxel plotting is allowed in random ray mode.",
314
        openmc_plottable->id()));
×
315
      continue;
×
316
    } else if (openmc_plot->type_ != Plot::PlotType::voxel) {
×
UNCOV
317
      warning(fmt::format(
×
318
        "Plot {} will not be used for end of simulation data plotting -- only "
319
        "voxel plotting is allowed in random ray mode.",
320
        openmc_plottable->id()));
×
UNCOV
321
      continue;
×
322
    }
323
  }
324

325
  // Warn about slow MPI domain replication, if detected
326
  ///////////////////////////////////////////////////////////////////
327
#ifdef OPENMC_MPI
328
  if (mpi::n_procs > 1) {
170✔
329
    warning(
170✔
330
      "MPI parallelism is not supported by the random ray solver. All work "
331
      "will be performed by rank 0. Domain decomposition may be implemented in "
332
      "the future to provide efficient MPI scaling.");
333
  }
334
#endif
335

336
  // Warn about instability resulting from linear sources in small regions
337
  // when generating weight windows with FW-CADIS and an overlaid mesh.
338
  ///////////////////////////////////////////////////////////////////
339
  if (RandomRay::source_shape_ == RandomRaySourceShape::LINEAR &&
132✔
340
      RandomRay::mesh_subdivision_enabled_ &&
506✔
341
      variance_reduction::weight_windows.size() > 0) {
66✔
342
    warning(
11✔
343
      "Linear sources may result in negative fluxes in small source regions "
344
      "generated by mesh subdivision. Negative sources may result in low "
345
      "quality FW-CADIS weight windows. We recommend you use flat source mode "
346
      "when generating weight windows with an overlaid mesh tally.");
347
  }
348
}
374✔
349

350
void openmc_reset_random_ray()
6,636✔
351
{
352
  FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::HYBRID;
6,636✔
353
  FlatSourceDomain::volume_normalized_flux_tallies_ = false;
6,636✔
354
  FlatSourceDomain::adjoint_ = false;
6,636✔
355
  FlatSourceDomain::mesh_domain_map_.clear();
6,636✔
356
  RandomRay::ray_source_.reset();
6,636✔
357
  RandomRay::source_shape_ = RandomRaySourceShape::FLAT;
6,636✔
358
  RandomRay::mesh_subdivision_enabled_ = false;
6,636✔
359
  RandomRay::sample_method_ = RandomRaySampleMethod::PRNG;
6,636✔
360
}
6,636✔
361

362
//==============================================================================
363
// RandomRaySimulation implementation
364
//==============================================================================
365

366
RandomRaySimulation::RandomRaySimulation()
624✔
367
  : negroups_(data::mg.num_energy_groups_)
624✔
368
{
369
  // There are no source sites in random ray mode, so be sure to disable to
370
  // ensure we don't attempt to write source sites to statepoint
371
  settings::source_write = false;
624✔
372

373
  // Random ray mode does not have an inner loop over generations within a
374
  // batch, so set the current gen to 1
375
  simulation::current_gen = 1;
624✔
376

377
  switch (RandomRay::source_shape_) {
624✔
378
  case RandomRaySourceShape::FLAT:
368✔
379
    domain_ = make_unique<FlatSourceDomain>();
368✔
380
    break;
368✔
381
  case RandomRaySourceShape::LINEAR:
256✔
382
  case RandomRaySourceShape::LINEAR_XY:
383
    domain_ = make_unique<LinearSourceDomain>();
256✔
384
    break;
256✔
385
  default:
×
UNCOV
386
    fatal_error("Unknown random ray source shape");
×
387
  }
388

389
  // Convert OpenMC native MGXS into a more efficient format
390
  // internal to the random ray solver
391
  domain_->flatten_xs();
624✔
392
}
624✔
393

394
void RandomRaySimulation::apply_fixed_sources_and_mesh_domains()
544✔
395
{
396
  if (settings::run_mode == RunMode::FIXED_SOURCE) {
544✔
397
    // Transfer external source user inputs onto random ray source regions
398
    domain_->convert_external_sources();
368✔
399
    domain_->count_external_source_regions();
368✔
400
  }
401
  domain_->apply_meshes();
544✔
402
}
544✔
403

404
void RandomRaySimulation::prepare_fixed_sources_adjoint(
80✔
405
  vector<double>& forward_flux, SourceRegionContainer& forward_source_regions,
406
  SourceRegionContainer& forward_base_source_regions,
407
  std::unordered_map<SourceRegionKey, int64_t, SourceRegionKey::HashFunctor>&
408
    forward_source_region_map)
409
{
410
  if (settings::run_mode == RunMode::FIXED_SOURCE) {
80✔
411
    if (RandomRay::mesh_subdivision_enabled_) {
64✔
412
      domain_->source_regions_ = forward_source_regions;
32✔
413
      domain_->source_region_map_ = forward_source_region_map;
32✔
414
      domain_->base_source_regions_ = forward_base_source_regions;
32✔
415
      domain_->source_regions_.adjoint_reset();
32✔
416
    }
417
    domain_->set_adjoint_sources(forward_flux);
64✔
418
  }
419
}
80✔
420

421
void RandomRaySimulation::simulate()
624✔
422
{
423
  // Random ray power iteration loop
424
  while (simulation::current_batch < settings::n_batches) {
16,944✔
425
    // Initialize the current batch
426
    initialize_batch();
16,320✔
427
    initialize_generation();
16,320✔
428

429
    // MPI not supported in random ray solver, so all work is done by rank 0
430
    // TODO: Implement domain decomposition for MPI parallelism
431
    if (mpi::master) {
16,320✔
432

433
      // Reset total starting particle weight used for normalizing tallies
434
      simulation::total_weight = 1.0;
11,220✔
435

436
      // Update source term (scattering + fission)
437
      domain_->update_neutron_source(k_eff_);
11,220✔
438

439
      // Reset scalar fluxes, iteration volume tallies, and region hit flags to
440
      // zero
441
      domain_->batch_reset();
11,220✔
442

443
      // At the beginning of the simulation, if mesh subvivision is in use, we
444
      // need to swap the main source region container into the base container,
445
      // as the main source region container will be used to hold the true
446
      // subdivided source regions. The base container will therefore only
447
      // contain the external source region information, the mesh indices,
448
      // material properties, and initial guess values for the flux/source.
449
      if (RandomRay::mesh_subdivision_enabled_ &&
11,220✔
450
          simulation::current_batch == 1 && !FlatSourceDomain::adjoint_) {
2,640✔
451
        domain_->prepare_base_source_regions();
99✔
452
      }
453

454
      // Start timer for transport
455
      simulation::time_transport.start();
11,220✔
456

457
// Transport sweep over all random rays for the iteration
458
#pragma omp parallel for schedule(dynamic)                                     \
6,120✔
459
  reduction(+ : total_geometric_intersections_)
6,120✔
460
      for (int i = 0; i < settings::n_particles; i++) {
835,600✔
461
        RandomRay ray(i, domain_.get());
830,500✔
462
        total_geometric_intersections_ +=
830,500✔
463
          ray.transport_history_based_single_ray();
830,500✔
464
      }
830,500✔
465

466
      simulation::time_transport.stop();
11,220✔
467

468
      // If using mesh subdivision, add any newly discovered source regions
469
      // to the main source region container.
470
      if (RandomRay::mesh_subdivision_enabled_) {
11,220✔
471
        domain_->finalize_discovered_source_regions();
2,640✔
472
      }
473

474
      // Normalize scalar flux and update volumes
475
      domain_->normalize_scalar_flux_and_volumes(
11,220✔
476
        settings::n_particles * RandomRay::distance_active_);
477

478
      // Add source to scalar flux, compute number of FSR hits
479
      int64_t n_hits = domain_->add_source_to_scalar_flux();
11,220✔
480

481
      // Apply transport stabilization factors
482
      domain_->apply_transport_stabilization();
11,220✔
483

484
      if (settings::run_mode == RunMode::EIGENVALUE) {
11,220✔
485
        // Compute random ray k-eff
486
        k_eff_ = domain_->compute_k_eff(k_eff_);
2,090✔
487

488
        // Store random ray k-eff into OpenMC's native k-eff variable
489
        global_tally_tracklength = k_eff_;
2,090✔
490
      }
491

492
      // Execute all tallying tasks, if this is an active batch
493
      if (simulation::current_batch > settings::n_inactive) {
11,220✔
494

495
        // Add this iteration's scalar flux estimate to final accumulated
496
        // estimate
497
        domain_->accumulate_iteration_flux();
4,510✔
498

499
        // Generate mapping between source regions and tallies
500
        if (!domain_->mapped_all_tallies_) {
4,510✔
501
          domain_->convert_source_regions_to_tallies();
429✔
502
        }
503

504
        // Use above mapping to contribute FSR flux data to appropriate
505
        // tallies
506
        domain_->random_ray_tally();
4,510✔
507
      }
508

509
      // Set phi_old = phi_new
510
      domain_->flux_swap();
11,220✔
511

512
      // Check for any obvious insabilities/nans/infs
513
      instability_check(n_hits, k_eff_, avg_miss_rate_);
11,220✔
514
    } // End MPI master work
515

516
    // Finalize the current batch
517
    finalize_generation();
16,320✔
518
    finalize_batch();
16,320✔
519
  } // End random ray power iteration loop
520
}
624✔
521

522
void RandomRaySimulation::output_simulation_results() const
624✔
523
{
524
  // Print random ray results
525
  if (mpi::master) {
624✔
526
    print_results_random_ray(total_geometric_intersections_,
429✔
527
      avg_miss_rate_ / settings::n_batches, negroups_,
429✔
528
      domain_->n_source_regions(), domain_->n_external_source_regions_);
429✔
529
    if (model::plots.size() > 0) {
429✔
UNCOV
530
      domain_->output_to_vtk();
×
531
    }
532
  }
533
}
624✔
534

535
// Apply a few sanity checks to catch obvious cases of numerical instability.
536
// Instability typically only occurs if ray density is extremely low.
537
void RandomRaySimulation::instability_check(
11,220✔
538
  int64_t n_hits, double k_eff, double& avg_miss_rate) const
539
{
540
  double percent_missed = ((domain_->n_source_regions() - n_hits) /
11,220✔
541
                            static_cast<double>(domain_->n_source_regions())) *
11,220✔
542
                          100.0;
11,220✔
543
  avg_miss_rate += percent_missed;
11,220✔
544

545
  if (mpi::master) {
11,220✔
546
    if (percent_missed > 10.0) {
11,220✔
547
      warning(fmt::format(
638✔
548
        "Very high FSR miss rate detected ({:.3f}%). Instability may occur. "
549
        "Increase ray density by adding more rays and/or active distance.",
550
        percent_missed));
551
    } else if (percent_missed > 1.0) {
10,582✔
552
      warning(
×
UNCOV
553
        fmt::format("Elevated FSR miss rate detected ({:.3f}%). Increasing "
×
554
                    "ray density by adding more rays and/or active "
555
                    "distance may improve simulation efficiency.",
556
          percent_missed));
557
    }
558

559
    if (k_eff > 10.0 || k_eff < 0.01 || !(std::isfinite(k_eff))) {
11,220✔
UNCOV
560
      fatal_error("Instability detected");
×
561
    }
562
  }
563
}
11,220✔
564

565
// Print random ray simulation results
566
void RandomRaySimulation::print_results_random_ray(
429✔
567
  uint64_t total_geometric_intersections, double avg_miss_rate, int negroups,
568
  int64_t n_source_regions, int64_t n_external_source_regions) const
569
{
570
  using namespace simulation;
571

572
  if (settings::verbosity >= 6) {
429✔
573
    double total_integrations = total_geometric_intersections * negroups;
429✔
574
    double time_per_integration =
575
      simulation::time_transport.elapsed() / total_integrations;
429✔
576
    double misc_time = time_total.elapsed() - time_update_src.elapsed() -
429✔
577
                       time_transport.elapsed() - time_tallies.elapsed() -
429✔
578
                       time_bank_sendrecv.elapsed();
429✔
579

580
    header("Simulation Statistics", 4);
429✔
581
    fmt::print(
429✔
582
      " Total Iterations                  = {}\n", settings::n_batches);
583
    fmt::print(
429✔
584
      " Number of Rays per Iteration      = {}\n", settings::n_particles);
585
    fmt::print(" Inactive Distance                 = {} cm\n",
429✔
586
      RandomRay::distance_inactive_);
587
    fmt::print(" Active Distance                   = {} cm\n",
429✔
588
      RandomRay::distance_active_);
589
    fmt::print(" Source Regions (SRs)              = {}\n", n_source_regions);
429✔
590
    fmt::print(
351✔
591
      " SRs Containing External Sources   = {}\n", n_external_source_regions);
592
    fmt::print(" Total Geometric Intersections     = {:.4e}\n",
351✔
593
      static_cast<double>(total_geometric_intersections));
429✔
594
    fmt::print("   Avg per Iteration               = {:.4e}\n",
351✔
595
      static_cast<double>(total_geometric_intersections) / settings::n_batches);
429✔
596
    fmt::print("   Avg per Iteration per SR        = {:.2f}\n",
351✔
597
      static_cast<double>(total_geometric_intersections) /
429✔
598
        static_cast<double>(settings::n_batches) / n_source_regions);
858✔
599
    fmt::print(" Avg SR Miss Rate per Iteration    = {:.4f}%\n", avg_miss_rate);
429✔
600
    fmt::print(" Energy Groups                     = {}\n", negroups);
429✔
601
    fmt::print(
351✔
602
      " Total Integrations                = {:.4e}\n", total_integrations);
603
    fmt::print("   Avg per Iteration               = {:.4e}\n",
351✔
604
      total_integrations / settings::n_batches);
429✔
605

606
    std::string estimator;
429✔
607
    switch (domain_->volume_estimator_) {
429✔
608
    case RandomRayVolumeEstimator::SIMULATION_AVERAGED:
22✔
609
      estimator = "Simulation Averaged";
22✔
610
      break;
22✔
611
    case RandomRayVolumeEstimator::NAIVE:
66✔
612
      estimator = "Naive";
66✔
613
      break;
66✔
614
    case RandomRayVolumeEstimator::HYBRID:
341✔
615
      estimator = "Hybrid";
341✔
616
      break;
341✔
617
    default:
×
UNCOV
618
      fatal_error("Invalid volume estimator type");
×
619
    }
620
    fmt::print(" Volume Estimator Type             = {}\n", estimator);
351✔
621

622
    std::string adjoint_true = (FlatSourceDomain::adjoint_) ? "ON" : "OFF";
1,287✔
623
    fmt::print(" Adjoint Flux Mode                 = {}\n", adjoint_true);
351✔
624

625
    std::string shape;
858✔
626
    switch (RandomRay::source_shape_) {
429✔
627
    case RandomRaySourceShape::FLAT:
253✔
628
      shape = "Flat";
253✔
629
      break;
253✔
630
    case RandomRaySourceShape::LINEAR:
143✔
631
      shape = "Linear";
143✔
632
      break;
143✔
633
    case RandomRaySourceShape::LINEAR_XY:
33✔
634
      shape = "Linear XY";
33✔
635
      break;
33✔
NEW
636
    default:
×
NEW
637
      fatal_error("Invalid random ray source shape");
×
638
    }
639
    fmt::print(" Source Shape                      = {}\n", shape);
351✔
640
    std::string sample_method =
641
      (RandomRay::sample_method_ == RandomRaySampleMethod::PRNG) ? "PRNG"
429✔
642
                                                                 : "Halton";
1,287✔
643
    fmt::print(" Sample Method                     = {}\n", sample_method);
351✔
644

645
    if (domain_->is_transport_stabilization_needed_) {
429✔
646
      fmt::print(" Transport XS Stabilization Used   = YES (rho = {:.3f})\n",
11✔
647
        FlatSourceDomain::diagonal_stabilization_rho_);
648
    } else {
649
      fmt::print(" Transport XS Stabilization Used   = NO\n");
418✔
650
    }
651

652
    header("Timing Statistics", 4);
429✔
653
    show_time("Total time for initialization", time_initialize.elapsed());
429✔
654
    show_time("Reading cross sections", time_read_xs.elapsed(), 1);
429✔
655
    show_time("Total simulation time", time_total.elapsed());
429✔
656
    show_time("Transport sweep only", time_transport.elapsed(), 1);
429✔
657
    show_time("Source update only", time_update_src.elapsed(), 1);
429✔
658
    show_time("Tally conversion only", time_tallies.elapsed(), 1);
429✔
659
    show_time("MPI source reductions only", time_bank_sendrecv.elapsed(), 1);
429✔
660
    show_time("Other iteration routines", misc_time, 1);
429✔
661
    if (settings::run_mode == RunMode::EIGENVALUE) {
429✔
662
      show_time("Time in inactive batches", time_inactive.elapsed());
132✔
663
    }
664
    show_time("Time in active batches", time_active.elapsed());
429✔
665
    show_time("Time writing statepoints", time_statepoint.elapsed());
429✔
666
    show_time("Total time for finalization", time_finalize.elapsed());
429✔
667
    show_time("Time per integration", time_per_integration);
429✔
668
  }
429✔
669

670
  if (settings::verbosity >= 4 && settings::run_mode == RunMode::EIGENVALUE) {
429✔
671
    header("Results", 4);
132✔
672
    fmt::print(" k-effective                       = {:.5f} +/- {:.5f}\n",
132✔
673
      simulation::keff, simulation::keff_std);
674
  }
675
}
429✔
676

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