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

openmc-dev / openmc / 15371300071

01 Jun 2025 05:04AM UTC coverage: 85.143% (+0.3%) from 84.827%
15371300071

Pull #3176

github

web-flow
Merge 4f739184a into cb95c784b
Pull Request #3176: MeshFilter rotation - solution to issue #3166

86 of 99 new or added lines in 4 files covered. (86.87%)

3707 existing lines in 117 files now uncovered.

52212 of 61323 relevant lines covered (85.14%)

42831974.38 hits per line

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

88.35
/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()
770✔
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_;
770✔
34

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

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

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

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

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

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

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

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

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

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

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

80
#pragma omp parallel for
315✔
81
    for (uint64_t i = 0; i < forward_flux.size(); i++) {
2,287,003✔
82
      forward_flux[i] *= source_normalization_factor;
2,286,548✔
83
    }
84

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

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

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

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

100
  if (adjoint_needed) {
770✔
101
    reset_timers();
110✔
102

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

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

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

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

115
    // Initialize adjoint fixed sources, if present
116
    adjoint_sim.prepare_fixed_sources_adjoint(forward_flux,
110✔
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();
110✔
122

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

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

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

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

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

138
    // Output all simulation results
139
    adjoint_sim.output_simulation_results();
110✔
140
  }
110✔
141
}
770✔
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()
525✔
148
{
149
  // Validate tallies
150
  ///////////////////////////////////////////////////////////////////
151
  for (auto& tally : model::tallies) {
1,680✔
152

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

173
      switch (filter.type()) {
1,365✔
174
      case FilterType::CELL:
1,365✔
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,365✔
UNCOV
183
      default:
×
UNCOV
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,950✔
194
    if (!material.is_isotropic) {
1,425✔
UNCOV
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,425✔
UNCOV
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++) {
7,530✔
203
      if (material.exists_in_model) {
6,105✔
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;
6,045✔
209
        const int a = 0;
6,045✔
210
        double sigma_t =
211
          material.get_xs(MgxsType::TOTAL, g, NULL, NULL, NULL, t, a);
6,045✔
212
        if (sigma_t <= 0.0) {
6,045✔
UNCOV
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());
525✔
227
  if (!is) {
525✔
UNCOV
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();
525✔
234
  SpatialBox* sb = dynamic_cast<SpatialBox*>(space_dist);
525✔
235
  if (!sb) {
525✔
UNCOV
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()) {
525✔
UNCOV
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();
525✔
249
  Isotropic* id = dynamic_cast<Isotropic*>(angle_dist);
525✔
250
  if (!id) {
525✔
UNCOV
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) {
525✔
258
    if (model::external_sources.size() < 1) {
360✔
UNCOV
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++) {
720✔
264
      Source* s = model::external_sources[i].get();
360✔
265

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

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

301
      // Check that a discrete energy distribution was used
302
      Distribution* d = is->energy();
360✔
303
      Discrete* dd = dynamic_cast<Discrete*>(d);
360✔
304
      if (!dd) {
360✔
UNCOV
305
        fatal_error(
×
306
          "Only discrete (multigroup) energy distributions are allowed for "
307
          "external sources in random ray mode.");
308
      }
309
    }
310
  }
311

312
  // Validate plotting files
313
  ///////////////////////////////////////////////////////////////////
314
  for (int p = 0; p < model::plots.size(); p++) {
525✔
315

316
    // Get handle to OpenMC plot object
UNCOV
317
    const auto& openmc_plottable = model::plots[p];
×
UNCOV
318
    Plot* openmc_plot = dynamic_cast<Plot*>(openmc_plottable.get());
×
319

320
    // Random ray plots only support voxel plots
UNCOV
321
    if (!openmc_plot) {
×
UNCOV
322
      warning(fmt::format(
×
323
        "Plot {} will not be used for end of simulation data plotting -- only "
324
        "voxel plotting is allowed in random ray mode.",
UNCOV
325
        openmc_plottable->id()));
×
UNCOV
326
      continue;
×
UNCOV
327
    } else if (openmc_plot->type_ != Plot::PlotType::voxel) {
×
UNCOV
328
      warning(fmt::format(
×
329
        "Plot {} will not be used for end of simulation data plotting -- only "
330
        "voxel plotting is allowed in random ray mode.",
UNCOV
331
        openmc_plottable->id()));
×
UNCOV
332
      continue;
×
333
    }
334
  }
335

336
  // Warn about slow MPI domain replication, if detected
337
  ///////////////////////////////////////////////////////////////////
338
#ifdef OPENMC_MPI
339
  if (mpi::n_procs > 1) {
245✔
340
    warning(
245✔
341
      "MPI parallelism is not supported by the random ray solver. All work "
342
      "will be performed by rank 0. Domain decomposition may be implemented in "
343
      "the future to provide efficient MPI scaling.");
344
  }
345
#endif
346

347
  // Warn about instability resulting from linear sources in small regions
348
  // when generating weight windows with FW-CADIS and an overlaid mesh.
349
  ///////////////////////////////////////////////////////////////////
350
  if (RandomRay::source_shape_ == RandomRaySourceShape::LINEAR &&
180✔
351
      RandomRay::mesh_subdivision_enabled_ &&
705✔
352
      variance_reduction::weight_windows.size() > 0) {
90✔
353
    warning(
15✔
354
      "Linear sources may result in negative fluxes in small source regions "
355
      "generated by mesh subdivision. Negative sources may result in low "
356
      "quality FW-CADIS weight windows. We recommend you use flat source mode "
357
      "when generating weight windows with an overlaid mesh tally.");
358
  }
359
}
525✔
360

361
void openmc_reset_random_ray()
9,188✔
362
{
363
  FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::HYBRID;
9,188✔
364
  FlatSourceDomain::volume_normalized_flux_tallies_ = false;
9,188✔
365
  FlatSourceDomain::adjoint_ = false;
9,188✔
366
  FlatSourceDomain::mesh_domain_map_.clear();
9,188✔
367
  RandomRay::ray_source_.reset();
9,188✔
368
  RandomRay::source_shape_ = RandomRaySourceShape::FLAT;
9,188✔
369
  RandomRay::mesh_subdivision_enabled_ = false;
9,188✔
370
  RandomRay::sample_method_ = RandomRaySampleMethod::PRNG;
9,188✔
371
}
9,188✔
372

373
//==============================================================================
374
// RandomRaySimulation implementation
375
//==============================================================================
376

377
RandomRaySimulation::RandomRaySimulation()
880✔
378
  : negroups_(data::mg.num_energy_groups_)
880✔
379
{
380
  // There are no source sites in random ray mode, so be sure to disable to
381
  // ensure we don't attempt to write source sites to statepoint
382
  settings::source_write = false;
880✔
383

384
  // Random ray mode does not have an inner loop over generations within a
385
  // batch, so set the current gen to 1
386
  simulation::current_gen = 1;
880✔
387

388
  switch (RandomRay::source_shape_) {
880✔
389
  case RandomRaySourceShape::FLAT:
528✔
390
    domain_ = make_unique<FlatSourceDomain>();
528✔
391
    break;
528✔
392
  case RandomRaySourceShape::LINEAR:
352✔
393
  case RandomRaySourceShape::LINEAR_XY:
394
    domain_ = make_unique<LinearSourceDomain>();
352✔
395
    break;
352✔
UNCOV
396
  default:
×
UNCOV
397
    fatal_error("Unknown random ray source shape");
×
398
  }
399

400
  // Convert OpenMC native MGXS into a more efficient format
401
  // internal to the random ray solver
402
  domain_->flatten_xs();
880✔
403
}
880✔
404

405
void RandomRaySimulation::apply_fixed_sources_and_mesh_domains()
770✔
406
{
407
  domain_->apply_meshes();
770✔
408
  if (settings::run_mode == RunMode::FIXED_SOURCE) {
770✔
409
    // Transfer external source user inputs onto random ray source regions
410
    domain_->convert_external_sources();
528✔
411
    domain_->count_external_source_regions();
528✔
412
  }
413
}
770✔
414

415
void RandomRaySimulation::prepare_fixed_sources_adjoint(
110✔
416
  vector<double>& forward_flux, SourceRegionContainer& forward_source_regions,
417
  SourceRegionContainer& forward_base_source_regions,
418
  std::unordered_map<SourceRegionKey, int64_t, SourceRegionKey::HashFunctor>&
419
    forward_source_region_map)
420
{
421
  if (settings::run_mode == RunMode::FIXED_SOURCE) {
110✔
422
    if (RandomRay::mesh_subdivision_enabled_) {
88✔
423
      domain_->source_regions_ = forward_source_regions;
44✔
424
      domain_->source_region_map_ = forward_source_region_map;
44✔
425
      domain_->base_source_regions_ = forward_base_source_regions;
44✔
426
      domain_->source_regions_.adjoint_reset();
44✔
427
    }
428
    domain_->set_adjoint_sources(forward_flux);
88✔
429
  }
430
}
110✔
431

432
void RandomRaySimulation::simulate()
880✔
433
{
434
  // Random ray power iteration loop
435
  while (simulation::current_batch < settings::n_batches) {
23,980✔
436
    // Initialize the current batch
437
    initialize_batch();
23,100✔
438
    initialize_generation();
23,100✔
439

440
    // MPI not supported in random ray solver, so all work is done by rank 0
441
    // TODO: Implement domain decomposition for MPI parallelism
442
    if (mpi::master) {
23,100✔
443

444
      // Reset total starting particle weight used for normalizing tallies
445
      simulation::total_weight = 1.0;
15,750✔
446

447
      // Update source term (scattering + fission)
448
      domain_->update_neutron_source(k_eff_);
15,750✔
449

450
      // Reset scalar fluxes, iteration volume tallies, and region hit flags to
451
      // zero
452
      domain_->batch_reset();
15,750✔
453

454
      // At the beginning of the simulation, if mesh subvivision is in use, we
455
      // need to swap the main source region container into the base container,
456
      // as the main source region container will be used to hold the true
457
      // subdivided source regions. The base container will therefore only
458
      // contain the external source region information, the mesh indices,
459
      // material properties, and initial guess values for the flux/source.
460
      if (RandomRay::mesh_subdivision_enabled_ &&
15,750✔
461
          simulation::current_batch == 1 && !FlatSourceDomain::adjoint_) {
4,050✔
462
        domain_->prepare_base_source_regions();
150✔
463
      }
464

465
      // Start timer for transport
466
      simulation::time_transport.start();
15,750✔
467

468
// Transport sweep over all random rays for the iteration
469
#pragma omp parallel for schedule(dynamic)                                     \
6,300✔
470
  reduction(+ : total_geometric_intersections_)
6,300✔
471
      for (int i = 0; i < settings::n_particles; i++) {
1,528,650✔
472
        RandomRay ray(i, domain_.get());
1,519,200✔
473
        total_geometric_intersections_ +=
1,519,200✔
474
          ray.transport_history_based_single_ray();
1,519,200✔
475
      }
1,519,200✔
476

477
      simulation::time_transport.stop();
15,750✔
478

479
      // If using mesh subdivision, add any newly discovered source regions
480
      // to the main source region container.
481
      if (RandomRay::mesh_subdivision_enabled_) {
15,750✔
482
        domain_->finalize_discovered_source_regions();
4,050✔
483
      }
484

485
      // Normalize scalar flux and update volumes
486
      domain_->normalize_scalar_flux_and_volumes(
15,750✔
487
        settings::n_particles * RandomRay::distance_active_);
488

489
      // Add source to scalar flux, compute number of FSR hits
490
      int64_t n_hits = domain_->add_source_to_scalar_flux();
15,750✔
491

492
      // Apply transport stabilization factors
493
      domain_->apply_transport_stabilization();
15,750✔
494

495
      if (settings::run_mode == RunMode::EIGENVALUE) {
15,750✔
496
        // Compute random ray k-eff
497
        k_eff_ = domain_->compute_k_eff(k_eff_);
2,850✔
498

499
        // Store random ray k-eff into OpenMC's native k-eff variable
500
        global_tally_tracklength = k_eff_;
2,850✔
501
      }
502

503
      // Execute all tallying tasks, if this is an active batch
504
      if (simulation::current_batch > settings::n_inactive) {
15,750✔
505

506
        // Add this iteration's scalar flux estimate to final accumulated
507
        // estimate
508
        domain_->accumulate_iteration_flux();
6,375✔
509

510
        // Generate mapping between source regions and tallies
511
        if (!domain_->mapped_all_tallies_) {
6,375✔
512
          domain_->convert_source_regions_to_tallies();
600✔
513
        }
514

515
        // Use above mapping to contribute FSR flux data to appropriate
516
        // tallies
517
        domain_->random_ray_tally();
6,375✔
518
      }
519

520
      // Set phi_old = phi_new
521
      domain_->flux_swap();
15,750✔
522

523
      // Check for any obvious insabilities/nans/infs
524
      instability_check(n_hits, k_eff_, avg_miss_rate_);
15,750✔
525
    } // End MPI master work
526

527
    // Finalize the current batch
528
    finalize_generation();
23,100✔
529
    finalize_batch();
23,100✔
530
  } // End random ray power iteration loop
531

532
  domain_->count_external_source_regions();
880✔
533
}
880✔
534

535
void RandomRaySimulation::output_simulation_results() const
880✔
536
{
537
  // Print random ray results
538
  if (mpi::master) {
880✔
539
    print_results_random_ray(total_geometric_intersections_,
600✔
540
      avg_miss_rate_ / settings::n_batches, negroups_,
600✔
541
      domain_->n_source_regions(), domain_->n_external_source_regions_);
600✔
542
    if (model::plots.size() > 0) {
600✔
UNCOV
543
      domain_->output_to_vtk();
×
544
    }
545
  }
546
}
880✔
547

548
// Apply a few sanity checks to catch obvious cases of numerical instability.
549
// Instability typically only occurs if ray density is extremely low.
550
void RandomRaySimulation::instability_check(
15,750✔
551
  int64_t n_hits, double k_eff, double& avg_miss_rate) const
552
{
553
  double percent_missed = ((domain_->n_source_regions() - n_hits) /
15,750✔
554
                            static_cast<double>(domain_->n_source_regions())) *
15,750✔
555
                          100.0;
15,750✔
556
  avg_miss_rate += percent_missed;
15,750✔
557

558
  if (mpi::master) {
15,750✔
559
    if (percent_missed > 10.0) {
15,750✔
560
      warning(fmt::format(
1,305✔
561
        "Very high FSR miss rate detected ({:.3f}%). Instability may occur. "
562
        "Increase ray density by adding more rays and/or active distance.",
563
        percent_missed));
564
    } else if (percent_missed > 1.0) {
14,445✔
UNCOV
565
      warning(
×
UNCOV
566
        fmt::format("Elevated FSR miss rate detected ({:.3f}%). Increasing "
×
567
                    "ray density by adding more rays and/or active "
568
                    "distance may improve simulation efficiency.",
569
          percent_missed));
570
    }
571

572
    if (k_eff > 10.0 || k_eff < 0.01 || !(std::isfinite(k_eff))) {
15,750✔
UNCOV
573
      fatal_error("Instability detected");
×
574
    }
575
  }
576
}
15,750✔
577

578
// Print random ray simulation results
579
void RandomRaySimulation::print_results_random_ray(
600✔
580
  uint64_t total_geometric_intersections, double avg_miss_rate, int negroups,
581
  int64_t n_source_regions, int64_t n_external_source_regions) const
582
{
583
  using namespace simulation;
584

585
  if (settings::verbosity >= 6) {
600✔
586
    double total_integrations = total_geometric_intersections * negroups;
600✔
587
    double time_per_integration =
588
      simulation::time_transport.elapsed() / total_integrations;
600✔
589
    double misc_time = time_total.elapsed() - time_update_src.elapsed() -
600✔
590
                       time_transport.elapsed() - time_tallies.elapsed() -
600✔
591
                       time_bank_sendrecv.elapsed();
600✔
592

593
    header("Simulation Statistics", 4);
600✔
594
    fmt::print(
600✔
595
      " Total Iterations                  = {}\n", settings::n_batches);
596
    fmt::print(
600✔
597
      " Number of Rays per Iteration      = {}\n", settings::n_particles);
598
    fmt::print(" Inactive Distance                 = {} cm\n",
600✔
599
      RandomRay::distance_inactive_);
600
    fmt::print(" Active Distance                   = {} cm\n",
600✔
601
      RandomRay::distance_active_);
602
    fmt::print(" Source Regions (SRs)              = {}\n", n_source_regions);
600✔
603
    fmt::print(
520✔
604
      " SRs Containing External Sources   = {}\n", n_external_source_regions);
605
    fmt::print(" Total Geometric Intersections     = {:.4e}\n",
520✔
606
      static_cast<double>(total_geometric_intersections));
600✔
607
    fmt::print("   Avg per Iteration               = {:.4e}\n",
520✔
608
      static_cast<double>(total_geometric_intersections) / settings::n_batches);
600✔
609
    fmt::print("   Avg per Iteration per SR        = {:.2f}\n",
520✔
610
      static_cast<double>(total_geometric_intersections) /
600✔
611
        static_cast<double>(settings::n_batches) / n_source_regions);
1,200✔
612
    fmt::print(" Avg SR Miss Rate per Iteration    = {:.4f}%\n", avg_miss_rate);
600✔
613
    fmt::print(" Energy Groups                     = {}\n", negroups);
600✔
614
    fmt::print(
520✔
615
      " Total Integrations                = {:.4e}\n", total_integrations);
616
    fmt::print("   Avg per Iteration               = {:.4e}\n",
520✔
617
      total_integrations / settings::n_batches);
600✔
618

619
    std::string estimator;
600✔
620
    switch (domain_->volume_estimator_) {
600✔
621
    case RandomRayVolumeEstimator::SIMULATION_AVERAGED:
30✔
622
      estimator = "Simulation Averaged";
30✔
623
      break;
30✔
624
    case RandomRayVolumeEstimator::NAIVE:
90✔
625
      estimator = "Naive";
90✔
626
      break;
90✔
627
    case RandomRayVolumeEstimator::HYBRID:
480✔
628
      estimator = "Hybrid";
480✔
629
      break;
480✔
UNCOV
630
    default:
×
UNCOV
631
      fatal_error("Invalid volume estimator type");
×
632
    }
633
    fmt::print(" Volume Estimator Type             = {}\n", estimator);
520✔
634

635
    std::string adjoint_true = (FlatSourceDomain::adjoint_) ? "ON" : "OFF";
1,800✔
636
    fmt::print(" Adjoint Flux Mode                 = {}\n", adjoint_true);
520✔
637

638
    std::string shape;
1,200✔
639
    switch (RandomRay::source_shape_) {
600✔
640
    case RandomRaySourceShape::FLAT:
360✔
641
      shape = "Flat";
360✔
642
      break;
360✔
643
    case RandomRaySourceShape::LINEAR:
195✔
644
      shape = "Linear";
195✔
645
      break;
195✔
646
    case RandomRaySourceShape::LINEAR_XY:
45✔
647
      shape = "Linear XY";
45✔
648
      break;
45✔
UNCOV
649
    default:
×
UNCOV
650
      fatal_error("Invalid random ray source shape");
×
651
    }
652
    fmt::print(" Source Shape                      = {}\n", shape);
520✔
653
    std::string sample_method =
654
      (RandomRay::sample_method_ == RandomRaySampleMethod::PRNG) ? "PRNG"
600✔
655
                                                                 : "Halton";
1,800✔
656
    fmt::print(" Sample Method                     = {}\n", sample_method);
520✔
657

658
    if (domain_->is_transport_stabilization_needed_) {
600✔
659
      fmt::print(" Transport XS Stabilization Used   = YES (rho = {:.3f})\n",
15✔
660
        FlatSourceDomain::diagonal_stabilization_rho_);
661
    } else {
662
      fmt::print(" Transport XS Stabilization Used   = NO\n");
585✔
663
    }
664

665
    header("Timing Statistics", 4);
600✔
666
    show_time("Total time for initialization", time_initialize.elapsed());
600✔
667
    show_time("Reading cross sections", time_read_xs.elapsed(), 1);
600✔
668
    show_time("Total simulation time", time_total.elapsed());
600✔
669
    show_time("Transport sweep only", time_transport.elapsed(), 1);
600✔
670
    show_time("Source update only", time_update_src.elapsed(), 1);
600✔
671
    show_time("Tally conversion only", time_tallies.elapsed(), 1);
600✔
672
    show_time("MPI source reductions only", time_bank_sendrecv.elapsed(), 1);
600✔
673
    show_time("Other iteration routines", misc_time, 1);
600✔
674
    if (settings::run_mode == RunMode::EIGENVALUE) {
600✔
675
      show_time("Time in inactive batches", time_inactive.elapsed());
180✔
676
    }
677
    show_time("Time in active batches", time_active.elapsed());
600✔
678
    show_time("Time writing statepoints", time_statepoint.elapsed());
600✔
679
    show_time("Total time for finalization", time_finalize.elapsed());
600✔
680
    show_time("Time per integration", time_per_integration);
600✔
681
  }
600✔
682

683
  if (settings::verbosity >= 4 && settings::run_mode == RunMode::EIGENVALUE) {
600✔
684
    header("Results", 4);
180✔
685
    fmt::print(" k-effective                       = {:.5f} +/- {:.5f}\n",
180✔
686
      simulation::keff, simulation::keff_std);
687
  }
688
}
600✔
689

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