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

openmc-dev / openmc / 15799682238

21 Jun 2025 09:11PM UTC coverage: 85.197% (-0.04%) from 85.239%
15799682238

Pull #3452

github

web-flow
Merge 2b25fb3f3 into 3d16d4b10
Pull Request #3452: relaxed random ray constraints

237 of 306 new or added lines in 8 files covered. (77.45%)

2 existing lines in 1 file now uncovered.

52706 of 61864 relevant lines covered (85.2%)

36699485.74 hits per line

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

88.49
/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()
576✔
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_;
576✔
34

35
  // Configure the domain for forward simulation
36
  FlatSourceDomain::adjoint_ = false;
576✔
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)
576✔
41
    header("FORWARD FLUX SOLVE", 3);
55✔
42

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

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

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

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

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

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

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

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

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

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

80
#pragma omp parallel for
324✔
81
    for (uint64_t i = 0; i < forward_flux.size(); i++) {
1,258,605✔
82
      forward_flux[i] *= source_normalization_factor;
1,258,353✔
83
    }
84

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

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

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

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

100
  if (adjoint_needed) {
576✔
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
}
576✔
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()
396✔
148
{
149
  // Validate tallies
150
  ///////////////////////////////////////////////////////////////////
151
  for (auto& tally : model::tallies) {
1,276✔
152

153
    // Validate score types
154
    for (auto score_bin : tally->scores_) {
1,936✔
155
      switch (score_bin) {
1,056✔
156
      case SCORE_FLUX:
1,056✔
157
      case SCORE_TOTAL:
158
      case SCORE_FISSION:
159
      case SCORE_NU_FISSION:
160
      case SCORE_EVENTS:
161
        break;
1,056✔
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,914✔
171
      auto& filter = *model::tally_filters[f];
1,034✔
172

173
      switch (filter.type()) {
1,034✔
174
      case FilterType::CELL:
1,034✔
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;
1,034✔
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,474✔
194
    if (!material.is_isotropic) {
1,078✔
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,078✔
199
      warning("Non-isothermal MGXS detected. Only isothermal XS data sets "
×
200
              "supported in random ray mode. Using lowest temperature.");
201
    }
202
    for (int g = 0; g < data::mg.num_energy_groups_; g++) {
5,588✔
203
      if (material.exists_in_model) {
4,510✔
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,466✔
209
        const int a = 0;
4,466✔
210
        double sigma_t =
211
          material.get_xs(MgxsType::TOTAL, g, NULL, NULL, NULL, t, a);
4,466✔
212
        if (sigma_t <= 0.0) {
4,466✔
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());
396✔
227
  if (!is) {
396✔
228
    fatal_error("Invalid ray source definition. Ray source must provided and "
×
229
                "be of type IndependentSource.");
230
  }
231

232
  // Check for computable volume
233
  auto* space_dist = dynamic_cast<FixedSpatialDistribution*>(is->space());
396✔
234
  if (!space_dist || !(space_dist->volume() > 0)) {
396✔
NEW
235
    fatal_error("Invalid ray source definition -- only volumetric sources with "
×
236
                "defined volume are allowed.");
237
  }
238
  // Check for fixed dimensional source
239
  if (!(space_dist->dims() > 0)) {
396✔
NEW
240
    fatal_error("Invalid ray source definition -- only fixed dimensional "
×
241
                "sources are allowed.");
242
  }
243

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

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

260
    for (int i = 0; i < model::external_sources.size(); i++) {
550✔
261
      Source* s = model::external_sources[i].get();
275✔
262

263
      // Check for independent source
264
      IndependentSource* is = dynamic_cast<IndependentSource*>(s);
275✔
265

266
      if (!is) {
275✔
267
        fatal_error(
×
268
          "Only IndependentSource external source types are allowed in "
269
          "random ray mode");
270
      }
271

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

281
      // Validate that a domain ID was specified OR that it is a point source
282
      auto sp = dynamic_cast<SpatialPoint*>(is->space());
275✔
283
      if (is->domain_ids().size() == 0 && !sp) {
275✔
284
        fatal_error("Fixed sources must be point source or spatially "
×
285
                    "constrained by domain id (cell, material, or universe) in "
286
                    "random ray mode.");
287
      } else if (is->domain_ids().size() > 0 && sp) {
275✔
288
        // If both a domain constraint and a non-default point source location
289
        // are specified, notify user that domain constraint takes precedence.
290
        if (sp->r().x == 0.0 && sp->r().y == 0.0 && sp->r().z == 0.0) {
242✔
291
          warning("Fixed source has both a domain constraint and a point "
242✔
292
                  "type spatial distribution. The domain constraint takes "
293
                  "precedence in random ray mode -- point source coordinate "
294
                  "will be ignored.");
295
        }
296
      }
297
    }
298
  }
299

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

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

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

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

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

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

361
//==============================================================================
362
// RandomRaySimulation implementation
363
//==============================================================================
364

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

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

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

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

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

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

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

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

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

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

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

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

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

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

465
      simulation::time_transport.stop();
11,660✔
466

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

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

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

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

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

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

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

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

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

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

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

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

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

520
  domain_->count_external_source_regions();
656✔
521
}
656✔
522

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© 2025 Coveralls, Inc