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

openmc-dev / openmc / 14600711877

22 Apr 2025 05:17PM UTC coverage: 85.203% (-0.2%) from 85.414%
14600711877

push

github

web-flow
Small Fixes to Allow Random Ray to Work with DAGMC (#3374)

Co-authored-by: Patrick Shriwise <pshriwise@gmail.com>

29 of 38 new or added lines in 3 files covered. (76.32%)

134 existing lines in 25 files now uncovered.

52230 of 61301 relevant lines covered (85.2%)

37375331.69 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()
560✔
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_;
560✔
34

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

173
      switch (filter.type()) {
1,001✔
174
      case FilterType::CELL:
1,001✔
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,001✔
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,430✔
194
    if (!material.is_isotropic) {
1,045✔
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,045✔
NEW
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,522✔
203
      if (material.exists_in_model) {
4,477✔
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,433✔
209
        const int a = 0;
4,433✔
210
        double sigma_t =
211
          material.get_xs(MgxsType::TOTAL, g, NULL, NULL, NULL, t, a);
4,433✔
212
        if (sigma_t <= 0.0) {
4,433✔
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());
385✔
227
  if (!is) {
385✔
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();
385✔
234
  SpatialBox* sb = dynamic_cast<SpatialBox*>(space_dist);
385✔
235
  if (!sb) {
385✔
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()) {
385✔
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();
385✔
249
  Isotropic* id = dynamic_cast<Isotropic*>(angle_dist);
385✔
250
  if (!id) {
385✔
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) {
385✔
258
    if (model::external_sources.size() < 1) {
264✔
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++) {
528✔
264
      Source* s = model::external_sources[i].get();
264✔
265

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

269
      if (!is) {
264✔
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();
264✔
277
      Isotropic* id = dynamic_cast<Isotropic*>(angle_dist);
264✔
278
      if (!id) {
264✔
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());
264✔
286
      if (is->domain_ids().size() == 0 && !sp) {
264✔
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) {
264✔
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) {
231✔
294
          warning("Fixed source has both a domain constraint and a point "
231✔
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();
264✔
303
      Discrete* dd = dynamic_cast<Discrete*>(d);
264✔
304
      if (!dd) {
264✔
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++) {
385✔
315

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

320
    // Random ray plots only support voxel plots
321
    if (!openmc_plot) {
×
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.",
325
        openmc_plottable->id()));
×
326
      continue;
×
327
    } else if (openmc_plot->type_ != Plot::PlotType::voxel) {
×
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.",
331
        openmc_plottable->id()));
×
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) {
175✔
340
    warning(
175✔
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 &&
132✔
351
      RandomRay::mesh_subdivision_enabled_ &&
517✔
352
      variance_reduction::weight_windows.size() > 0) {
66✔
353
    warning(
11✔
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
}
385✔
360

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

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

377
RandomRaySimulation::RandomRaySimulation()
640✔
378
  : negroups_(data::mg.num_energy_groups_)
640✔
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;
640✔
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;
640✔
387

388
  switch (RandomRay::source_shape_) {
640✔
389
  case RandomRaySourceShape::FLAT:
384✔
390
    domain_ = make_unique<FlatSourceDomain>();
384✔
391
    break;
384✔
392
  case RandomRaySourceShape::LINEAR:
256✔
393
  case RandomRaySourceShape::LINEAR_XY:
394
    domain_ = make_unique<LinearSourceDomain>();
256✔
395
    break;
256✔
396
  default:
×
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();
640✔
403
}
640✔
404

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

415
void RandomRaySimulation::prepare_fixed_sources_adjoint(
80✔
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) {
80✔
422
    if (RandomRay::mesh_subdivision_enabled_) {
64✔
423
      domain_->source_regions_ = forward_source_regions;
32✔
424
      domain_->source_region_map_ = forward_source_region_map;
32✔
425
      domain_->base_source_regions_ = forward_base_source_regions;
32✔
426
      domain_->source_regions_.adjoint_reset();
32✔
427
    }
428
    domain_->set_adjoint_sources(forward_flux);
64✔
429
  }
430
}
80✔
431

432
void RandomRaySimulation::simulate()
640✔
433
{
434
  // Random ray power iteration loop
435
  while (simulation::current_batch < settings::n_batches) {
17,440✔
436
    // Initialize the current batch
437
    initialize_batch();
16,800✔
438
    initialize_generation();
16,800✔
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) {
16,800✔
443

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

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

450
      // Reset scalar fluxes, iteration volume tallies, and region hit flags to
451
      // zero
452
      domain_->batch_reset();
11,550✔
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_ &&
11,550✔
461
          simulation::current_batch == 1 && !FlatSourceDomain::adjoint_) {
2,970✔
462
        domain_->prepare_base_source_regions();
110✔
463
      }
464

465
      // Start timer for transport
466
      simulation::time_transport.start();
11,550✔
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++) {
849,250✔
472
        RandomRay ray(i, domain_.get());
844,000✔
473
        total_geometric_intersections_ +=
844,000✔
474
          ray.transport_history_based_single_ray();
844,000✔
475
      }
844,000✔
476

477
      simulation::time_transport.stop();
11,550✔
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_) {
11,550✔
482
        domain_->finalize_discovered_source_regions();
2,970✔
483
      }
484

485
      // Normalize scalar flux and update volumes
486
      domain_->normalize_scalar_flux_and_volumes(
11,550✔
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();
11,550✔
491

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

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

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

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

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

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

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

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

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

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

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

535
void RandomRaySimulation::output_simulation_results() const
640✔
536
{
537
  // Print random ray results
538
  if (mpi::master) {
640✔
539
    print_results_random_ray(total_geometric_intersections_,
440✔
540
      avg_miss_rate_ / settings::n_batches, negroups_,
440✔
541
      domain_->n_source_regions(), domain_->n_external_source_regions_);
440✔
542
    if (model::plots.size() > 0) {
440✔
543
      domain_->output_to_vtk();
×
544
    }
545
  }
546
}
640✔
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(
11,550✔
551
  int64_t n_hits, double k_eff, double& avg_miss_rate) const
552
{
553
  double percent_missed = ((domain_->n_source_regions() - n_hits) /
11,550✔
554
                            static_cast<double>(domain_->n_source_regions())) *
11,550✔
555
                          100.0;
11,550✔
556
  avg_miss_rate += percent_missed;
11,550✔
557

558
  if (mpi::master) {
11,550✔
559
    if (percent_missed > 10.0) {
11,550✔
560
      warning(fmt::format(
957✔
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) {
10,593✔
565
      warning(
×
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))) {
11,550✔
573
      fatal_error("Instability detected");
×
574
    }
575
  }
576
}
11,550✔
577

578
// Print random ray simulation results
579
void RandomRaySimulation::print_results_random_ray(
440✔
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) {
440✔
586
    double total_integrations = total_geometric_intersections * negroups;
440✔
587
    double time_per_integration =
588
      simulation::time_transport.elapsed() / total_integrations;
440✔
589
    double misc_time = time_total.elapsed() - time_update_src.elapsed() -
440✔
590
                       time_transport.elapsed() - time_tallies.elapsed() -
440✔
591
                       time_bank_sendrecv.elapsed();
440✔
592

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

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

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

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

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

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

683
  if (settings::verbosity >= 4 && settings::run_mode == RunMode::EIGENVALUE) {
440✔
684
    header("Results", 4);
132✔
685
    fmt::print(" k-effective                       = {:.5f} +/- {:.5f}\n",
132✔
686
      simulation::keff, simulation::keff_std);
687
  }
688
}
440✔
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

© 2025 Coveralls, Inc