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

openmc-dev / openmc / 21806470376

08 Feb 2026 10:22PM UTC coverage: 81.817% (+0.05%) from 81.769%
21806470376

push

github

web-flow
Install parallel h5py with no build isolation (#3782)

17330 of 24289 branches covered (71.35%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

265 existing lines in 7 files now uncovered.

56082 of 65438 relevant lines covered (85.7%)

45167148.53 hits per line

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

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

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

20
namespace openmc {
21

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

26
// Enforces restrictions on inputs in random ray mode.  While there are
27
// many features that don't make sense in random ray mode, and are therefore
28
// unsupported, we limit our testing/enforcement operations only to inputs
29
// that may cause erroneous/misleading output or crashes from the solver.
30
void validate_random_ray_inputs()
507✔
31
{
32
  // Validate tallies
33
  ///////////////////////////////////////////////////////////////////
34
  for (auto& tally : model::tallies) {
1,476✔
35

36
    // Validate score types
37
    for (auto score_bin : tally->scores_) {
2,158✔
38
      switch (score_bin) {
1,189!
39
      case SCORE_FLUX:
1,189✔
40
      case SCORE_TOTAL:
41
      case SCORE_FISSION:
42
      case SCORE_NU_FISSION:
43
      case SCORE_EVENTS:
44
      case SCORE_KAPPA_FISSION:
45
        break;
1,189✔
UNCOV
46
      default:
×
UNCOV
47
        fatal_error(
×
48
          "Invalid score specified. Only flux, total, fission, nu-fission, "
49
          "kappa-fission, and event scores are supported in random ray mode.");
50
      }
51
    }
52

53
    // Validate filter types
54
    for (auto f : tally->filters()) {
2,094✔
55
      auto& filter = *model::tally_filters[f];
1,125✔
56

57
      switch (filter.type()) {
1,125!
58
      case FilterType::CELL:
1,125✔
59
      case FilterType::CELL_INSTANCE:
60
      case FilterType::DISTRIBCELL:
61
      case FilterType::ENERGY:
62
      case FilterType::MATERIAL:
63
      case FilterType::MESH:
64
      case FilterType::UNIVERSE:
65
      case FilterType::PARTICLE:
66
        break;
1,125✔
UNCOV
67
      default:
×
UNCOV
68
        fatal_error("Invalid filter specified. Only cell, cell_instance, "
×
69
                    "distribcell, energy, material, mesh, and universe filters "
70
                    "are supported in random ray mode.");
71
      }
72
    }
73
  }
74

75
  // Validate MGXS data
76
  ///////////////////////////////////////////////////////////////////
77
  for (auto& material : data::mg.macro_xs_) {
1,894✔
78
    if (!material.is_isotropic) {
1,387!
UNCOV
79
      fatal_error("Anisotropic MGXS detected. Only isotropic XS data sets "
×
80
                  "supported in random ray mode.");
81
    }
82
    if (material.get_xsdata().size() > 1) {
1,387!
UNCOV
83
      warning("Non-isothermal MGXS detected. Only isothermal XS data sets "
×
84
              "supported in random ray mode. Using lowest temperature.");
85
    }
86
    for (int g = 0; g < data::mg.num_energy_groups_; g++) {
7,494✔
87
      if (material.exists_in_model) {
6,107✔
88
        // Temperature and angle indices, if using multiple temperature
89
        // data sets and/or anisotropic data sets.
90
        // TODO: Currently assumes we are only using single temp/single angle
91
        // data.
92
        const int t = 0;
6,063✔
93
        const int a = 0;
6,063✔
94
        double sigma_t =
95
          material.get_xs(MgxsType::TOTAL, g, NULL, NULL, NULL, t, a);
6,063✔
96
        if (sigma_t <= 0.0) {
6,063!
UNCOV
97
          fatal_error("No zero or negative total macroscopic cross sections "
×
98
                      "allowed in random ray mode. If the intention is to make "
99
                      "a void material, use a cell fill of 'None' instead.");
100
        }
101
      }
102
    }
103
  }
104

105
  // Validate ray source
106
  ///////////////////////////////////////////////////////////////////
107

108
  // Check for independent source
109
  IndependentSource* is =
110
    dynamic_cast<IndependentSource*>(RandomRay::ray_source_.get());
507!
111
  if (!is) {
507!
UNCOV
112
    fatal_error("Invalid ray source definition. Ray source must provided and "
×
113
                "be of type IndependentSource.");
114
  }
115

116
  // Check for box source
117
  SpatialDistribution* space_dist = is->space();
507✔
118
  SpatialBox* sb = dynamic_cast<SpatialBox*>(space_dist);
507!
119
  if (!sb) {
507!
UNCOV
120
    fatal_error(
×
121
      "Invalid ray source definition -- only box sources are allowed.");
122
  }
123

124
  // Check that box source is not restricted to fissionable areas
125
  if (sb->only_fissionable()) {
507!
UNCOV
126
    fatal_error(
×
127
      "Invalid ray source definition -- fissionable spatial distribution "
128
      "not allowed.");
129
  }
130

131
  // Check for isotropic source
132
  UnitSphereDistribution* angle_dist = is->angle();
507✔
133
  Isotropic* id = dynamic_cast<Isotropic*>(angle_dist);
507!
134
  if (!id) {
507!
UNCOV
135
    fatal_error("Invalid ray source definition -- only isotropic sources are "
×
136
                "allowed.");
137
  }
138

139
  // Validate external sources
140
  ///////////////////////////////////////////////////////////////////
141
  if (settings::run_mode == RunMode::FIXED_SOURCE) {
507✔
142
    if (model::external_sources.size() < 1) {
287!
UNCOV
143
      fatal_error("Must provide a particle source (in addition to ray source) "
×
144
                  "in fixed source random ray mode.");
145
    }
146

147
    for (int i = 0; i < model::external_sources.size(); i++) {
574✔
148
      Source* s = model::external_sources[i].get();
287✔
149

150
      // Check for independent source
151
      IndependentSource* is = dynamic_cast<IndependentSource*>(s);
287!
152

153
      if (!is) {
287!
154
        fatal_error(
×
155
          "Only IndependentSource external source types are allowed in "
156
          "random ray mode");
157
      }
158

159
      // Check for isotropic source
160
      UnitSphereDistribution* angle_dist = is->angle();
287✔
161
      Isotropic* id = dynamic_cast<Isotropic*>(angle_dist);
287!
162
      if (!id) {
287!
UNCOV
163
        fatal_error(
×
164
          "Invalid source definition -- only isotropic external sources are "
165
          "allowed in random ray mode.");
166
      }
167

168
      // Validate that a domain ID was specified OR that it is a point source
169
      auto sp = dynamic_cast<SpatialPoint*>(is->space());
287!
170
      if (is->domain_ids().size() == 0 && !sp) {
287!
UNCOV
171
        fatal_error("Fixed sources must be point source or spatially "
×
172
                    "constrained by domain id (cell, material, or universe) in "
173
                    "random ray mode.");
174
      } else if (is->domain_ids().size() > 0 && sp) {
287✔
175
        // If both a domain constraint and a non-default point source location
176
        // are specified, notify user that domain constraint takes precedence.
177
        if (sp->r().x == 0.0 && sp->r().y == 0.0 && sp->r().z == 0.0) {
253!
178
          warning("Fixed source has both a domain constraint and a point "
253✔
179
                  "type spatial distribution. The domain constraint takes "
180
                  "precedence in random ray mode -- point source coordinate "
181
                  "will be ignored.");
182
        }
183
      }
184

185
      // Check that a discrete energy distribution was used
186
      Distribution* d = is->energy();
287✔
187
      Discrete* dd = dynamic_cast<Discrete*>(d);
287!
188
      if (!dd) {
287!
UNCOV
189
        fatal_error(
×
190
          "Only discrete (multigroup) energy distributions are allowed for "
191
          "external sources in random ray mode.");
192
      }
193
    }
194
  }
195

196
  // Validate plotting files
197
  ///////////////////////////////////////////////////////////////////
198
  for (int p = 0; p < model::plots.size(); p++) {
507!
199

200
    // Get handle to OpenMC plot object
UNCOV
201
    const auto& openmc_plottable = model::plots[p];
×
UNCOV
202
    Plot* openmc_plot = dynamic_cast<Plot*>(openmc_plottable.get());
×
203

204
    // Random ray plots only support voxel plots
205
    if (!openmc_plot) {
×
UNCOV
206
      warning(fmt::format(
×
207
        "Plot {} will not be used for end of simulation data plotting -- only "
208
        "voxel plotting is allowed in random ray mode.",
UNCOV
209
        openmc_plottable->id()));
×
UNCOV
210
      continue;
×
UNCOV
211
    } else if (openmc_plot->type_ != Plot::PlotType::voxel) {
×
UNCOV
212
      warning(fmt::format(
×
213
        "Plot {} will not be used for end of simulation data plotting -- only "
214
        "voxel plotting is allowed in random ray mode.",
UNCOV
215
        openmc_plottable->id()));
×
UNCOV
216
      continue;
×
217
    }
218
  }
219

220
  // Warn about slow MPI domain replication, if detected
221
  ///////////////////////////////////////////////////////////////////
222
#ifdef OPENMC_MPI
223
  if (mpi::n_procs > 1) {
231✔
224
    warning(
225✔
225
      "MPI parallelism is not supported by the random ray solver. All work "
226
      "will be performed by rank 0. Domain decomposition may be implemented in "
227
      "the future to provide efficient MPI scaling.");
228
  }
229
#endif
230

231
  // Warn about instability resulting from linear sources in small regions
232
  // when generating weight windows with FW-CADIS and an overlaid mesh.
233
  ///////////////////////////////////////////////////////////////////
234
  if (RandomRay::source_shape_ == RandomRaySourceShape::LINEAR &&
716✔
235
      variance_reduction::weight_windows.size() > 0) {
209✔
236
    warning(
11✔
237
      "Linear sources may result in negative fluxes in small source regions "
238
      "generated by mesh subdivision. Negative sources may result in low "
239
      "quality FW-CADIS weight windows. We recommend you use flat source mode "
240
      "when generating weight windows with an overlaid mesh tally.");
241
  }
242
}
507✔
243

244
void print_adjoint_header()
112✔
245
{
246
  if (!FlatSourceDomain::adjoint_)
112✔
247
    // If we're going to do an adjoint simulation afterwards, report that this
248
    // is the initial forward flux solve.
249
    header("FORWARD FLUX SOLVE", 3);
56✔
250
  else
251
    // Otherwise report that we are doing the adjoint simulation
252
    header("ADJOINT FLUX SOLVE", 3);
56✔
253
}
112✔
254

255
//==============================================================================
256
// RandomRaySimulation implementation
257
//==============================================================================
258

259
RandomRaySimulation::RandomRaySimulation()
732✔
260
  : negroups_(data::mg.num_energy_groups_)
732✔
261
{
262
  // There are no source sites in random ray mode, so be sure to disable to
263
  // ensure we don't attempt to write source sites to statepoint
264
  settings::source_write = false;
732✔
265

266
  // Random ray mode does not have an inner loop over generations within a
267
  // batch, so set the current gen to 1
268
  simulation::current_gen = 1;
732✔
269

270
  switch (RandomRay::source_shape_) {
732!
271
  case RandomRaySourceShape::FLAT:
380✔
272
    domain_ = make_unique<FlatSourceDomain>();
380✔
273
    break;
380✔
274
  case RandomRaySourceShape::LINEAR:
352✔
275
  case RandomRaySourceShape::LINEAR_XY:
276
    domain_ = make_unique<LinearSourceDomain>();
352✔
277
    break;
352✔
UNCOV
278
  default:
×
UNCOV
279
    fatal_error("Unknown random ray source shape");
×
280
  }
281

282
  // Convert OpenMC native MGXS into a more efficient format
283
  // internal to the random ray solver
284
  domain_->flatten_xs();
732✔
285

286
  // Check if adjoint calculation is needed. If it is, we will run the forward
287
  // calculation first and then the adjoint calculation later.
288
  adjoint_needed_ = FlatSourceDomain::adjoint_;
732✔
289

290
  // Adjoint is always false for the forward calculation
291
  FlatSourceDomain::adjoint_ = false;
732✔
292

293
  // The first simulation is run after initialization
294
  is_first_simulation_ = true;
732✔
295
}
732✔
296

297
void RandomRaySimulation::apply_fixed_sources_and_mesh_domains()
732✔
298
{
299
  domain_->apply_meshes();
732✔
300
  if (settings::run_mode == RunMode::FIXED_SOURCE) {
732✔
301
    // Transfer external source user inputs onto random ray source regions
302
    domain_->convert_external_sources();
417✔
303
    domain_->count_external_source_regions();
417✔
304
  }
305
}
732✔
306

307
void RandomRaySimulation::prepare_fixed_sources_adjoint()
81✔
308
{
309
  domain_->source_regions_.adjoint_reset();
81✔
310
  if (settings::run_mode == RunMode::FIXED_SOURCE) {
81✔
311
    domain_->set_adjoint_sources();
65✔
312
  }
313
}
81✔
314

315
void RandomRaySimulation::prepare_adjoint_simulation()
81✔
316
{
317
  // Configure the domain for adjoint simulation
318
  FlatSourceDomain::adjoint_ = true;
81✔
319

320
  // Reset k-eff
321
  domain_->k_eff_ = 1.0;
81✔
322

323
  // Initialize adjoint fixed sources, if present
324
  prepare_fixed_sources_adjoint();
81✔
325

326
  // Transpose scattering matrix
327
  domain_->transpose_scattering_matrix();
81✔
328

329
  // Swap nu_sigma_f and chi
330
  domain_->nu_sigma_f_.swap(domain_->chi_);
81✔
331
}
81✔
332

333
void RandomRaySimulation::simulate()
813✔
334
{
335
  if (!is_first_simulation_) {
813✔
336
    if (mpi::master && adjoint_needed_)
81!
337
      openmc::print_adjoint_header();
56✔
338

339
    // Reset the timers and reinitialize the general OpenMC datastructures if
340
    // this is after the first simulation
341
    reset_timers();
81✔
342

343
    // Initialize OpenMC general data structures
344
    openmc_simulation_init();
81✔
345
  }
346

347
  // Begin main simulation timer
348
  simulation::time_total.start();
813✔
349

350
  // Random ray power iteration loop
351
  while (simulation::current_batch < settings::n_batches) {
21,425✔
352
    // Initialize the current batch
353
    initialize_batch();
20,612✔
354
    initialize_generation();
20,612✔
355

356
    // MPI not supported in random ray solver, so all work is done by rank 0
357
    // TODO: Implement domain decomposition for MPI parallelism
358
    if (mpi::master) {
20,612✔
359

360
      // Reset total starting particle weight used for normalizing tallies
361
      simulation::total_weight = 1.0;
14,862✔
362

363
      // Update source term (scattering + fission)
364
      domain_->update_all_neutron_sources();
14,862✔
365

366
      // Reset scalar fluxes, iteration volume tallies, and region hit flags
367
      // to zero
368
      domain_->batch_reset();
14,862✔
369

370
      // At the beginning of the simulation, if mesh subdivision is in use, we
371
      // need to swap the main source region container into the base container,
372
      // as the main source region container will be used to hold the true
373
      // subdivided source regions. The base container will therefore only
374
      // contain the external source region information, the mesh indices,
375
      // material properties, and initial guess values for the flux/source.
376

377
      // Start timer for transport
378
      simulation::time_transport.start();
14,862✔
379

380
// Transport sweep over all random rays for the iteration
381
#pragma omp parallel for schedule(dynamic)                                     \
8,112✔
382
  reduction(+ : total_geometric_intersections_)
8,112✔
383
      for (int i = 0; i < settings::n_particles; i++) {
949,750✔
384
        RandomRay ray(i, domain_.get());
943,000✔
385
        total_geometric_intersections_ +=
943,000✔
386
          ray.transport_history_based_single_ray();
943,000✔
387
      }
943,000✔
388

389
      simulation::time_transport.stop();
14,862✔
390

391
      // Add any newly discovered source regions to the main source region
392
      // container.
393
      domain_->finalize_discovered_source_regions();
14,862✔
394

395
      // Normalize scalar flux and update volumes
396
      domain_->normalize_scalar_flux_and_volumes(
14,862✔
397
        settings::n_particles * RandomRay::distance_active_);
398

399
      // Add source to scalar flux, compute number of FSR hits
400
      int64_t n_hits = domain_->add_source_to_scalar_flux();
14,862✔
401

402
      // Apply transport stabilization factors
403
      domain_->apply_transport_stabilization();
14,862✔
404

405
      if (settings::run_mode == RunMode::EIGENVALUE) {
14,862✔
406
        // Compute random ray k-eff
407
        domain_->compute_k_eff();
5,170✔
408

409
        // Store random ray k-eff into OpenMC's native k-eff variable
410
        global_tally_tracklength = domain_->k_eff_;
5,170✔
411
      }
412

413
      // Execute all tallying tasks, if this is an active batch
414
      if (simulation::current_batch > settings::n_inactive) {
14,862✔
415

416
        // Add this iteration's scalar flux estimate to final accumulated
417
        // estimate
418
        domain_->accumulate_iteration_flux();
6,881✔
419

420
        // Use above mapping to contribute FSR flux data to appropriate
421
        // tallies
422
        domain_->random_ray_tally();
6,881✔
423
      }
424

425
      // Set phi_old = phi_new
426
      domain_->flux_swap();
14,862✔
427

428
      // Check for any obvious insabilities/nans/infs
429
      instability_check(n_hits, domain_->k_eff_, avg_miss_rate_);
14,862✔
430
    } // End MPI master work
431

432
    // Finalize the current batch
433
    finalize_generation();
20,612✔
434
    finalize_batch();
20,612✔
435
  } // End random ray power iteration loop
436

437
  domain_->count_external_source_regions();
813✔
438

439
  // End main simulation timer
440
  simulation::time_total.stop();
813✔
441

442
  // Normalize and save the final flux
443
  double source_normalization_factor =
444
    domain_->compute_fixed_source_normalization_factor() /
813✔
445
    (settings::n_batches - settings::n_inactive);
813✔
446

447
#pragma omp parallel for
458✔
448
  for (uint64_t se = 0; se < domain_->n_source_elements(); se++) {
1,344,775✔
449
    domain_->source_regions_.scalar_flux_final(se) *=
1,344,420✔
450
      source_normalization_factor;
451
  }
452

453
  // Finalize OpenMC
454
  openmc_simulation_finalize();
813✔
455

456
  // Output all simulation results
457
  output_simulation_results();
813✔
458

459
  // Toggle that the simulation object has been initialized after the first
460
  // simulation
461
  if (is_first_simulation_)
813✔
462
    is_first_simulation_ = false;
732✔
463
}
813✔
464

465
void RandomRaySimulation::output_simulation_results() const
813✔
466
{
467
  // Print random ray results
468
  if (mpi::master) {
813✔
469
    print_results_random_ray(total_geometric_intersections_,
563✔
470
      avg_miss_rate_ / settings::n_batches, negroups_,
563✔
471
      domain_->n_source_regions(), domain_->n_external_source_regions_);
563✔
472
    if (model::plots.size() > 0) {
563!
UNCOV
473
      domain_->output_to_vtk();
×
474
    }
475
  }
476
}
813✔
477

478
// Apply a few sanity checks to catch obvious cases of numerical instability.
479
// Instability typically only occurs if ray density is extremely low.
480
void RandomRaySimulation::instability_check(
14,862✔
481
  int64_t n_hits, double k_eff, double& avg_miss_rate) const
482
{
483
  double percent_missed = ((domain_->n_source_regions() - n_hits) /
14,862✔
484
                            static_cast<double>(domain_->n_source_regions())) *
14,862✔
485
                          100.0;
14,862✔
486
  avg_miss_rate += percent_missed;
14,862✔
487

488
  if (mpi::master) {
14,862!
489
    if (percent_missed > 10.0) {
14,862✔
490
      warning(fmt::format(
957✔
491
        "Very high FSR miss rate detected ({:.3f}%). Instability may occur. "
492
        "Increase ray density by adding more rays and/or active distance.",
493
        percent_missed));
494
    } else if (percent_missed > 1.0) {
13,905✔
495
      warning(
2!
496
        fmt::format("Elevated FSR miss rate detected ({:.3f}%). Increasing "
4!
497
                    "ray density by adding more rays and/or active "
498
                    "distance may improve simulation efficiency.",
499
          percent_missed));
500
    }
501

502
    if (k_eff > 10.0 || k_eff < 0.01 || !(std::isfinite(k_eff))) {
14,862!
UNCOV
503
      fatal_error(fmt::format("Instability detected: k-eff = {:.5f}", k_eff));
×
504
    }
505
  }
506
}
14,862✔
507

508
// Print random ray simulation results
509
void RandomRaySimulation::print_results_random_ray(
563✔
510
  uint64_t total_geometric_intersections, double avg_miss_rate, int negroups,
511
  int64_t n_source_regions, int64_t n_external_source_regions) const
512
{
513
  using namespace simulation;
514

515
  if (settings::verbosity >= 6) {
563!
516
    double total_integrations = total_geometric_intersections * negroups;
563✔
517
    double time_per_integration =
518
      simulation::time_transport.elapsed() / total_integrations;
563✔
519
    double misc_time = time_total.elapsed() - time_update_src.elapsed() -
563✔
520
                       time_transport.elapsed() - time_tallies.elapsed() -
563✔
521
                       time_bank_sendrecv.elapsed();
563✔
522

523
    header("Simulation Statistics", 4);
563✔
524
    fmt::print(
563✔
525
      " Total Iterations                  = {}\n", settings::n_batches);
526
    fmt::print(
563✔
527
      " Number of Rays per Iteration      = {}\n", settings::n_particles);
528
    fmt::print(" Inactive Distance                 = {} cm\n",
563✔
529
      RandomRay::distance_inactive_);
530
    fmt::print(" Active Distance                   = {} cm\n",
563✔
531
      RandomRay::distance_active_);
532
    fmt::print(" Source Regions (SRs)              = {}\n", n_source_regions);
563✔
533
    fmt::print(
461✔
534
      " SRs Containing External Sources   = {}\n", n_external_source_regions);
535
    fmt::print(" Total Geometric Intersections     = {:.4e}\n",
461✔
536
      static_cast<double>(total_geometric_intersections));
563✔
537
    fmt::print("   Avg per Iteration               = {:.4e}\n",
461✔
538
      static_cast<double>(total_geometric_intersections) / settings::n_batches);
563✔
539
    fmt::print("   Avg per Iteration per SR        = {:.2f}\n",
461✔
540
      static_cast<double>(total_geometric_intersections) /
563✔
541
        static_cast<double>(settings::n_batches) / n_source_regions);
1,126✔
542
    fmt::print(" Avg SR Miss Rate per Iteration    = {:.4f}%\n", avg_miss_rate);
563✔
543
    fmt::print(" Energy Groups                     = {}\n", negroups);
563✔
544
    fmt::print(
461✔
545
      " Total Integrations                = {:.4e}\n", total_integrations);
546
    fmt::print("   Avg per Iteration               = {:.4e}\n",
461✔
547
      total_integrations / settings::n_batches);
563✔
548

549
    std::string estimator;
563✔
550
    switch (domain_->volume_estimator_) {
563!
551
    case RandomRayVolumeEstimator::SIMULATION_AVERAGED:
22✔
552
      estimator = "Simulation Averaged";
22✔
553
      break;
22✔
554
    case RandomRayVolumeEstimator::NAIVE:
68✔
555
      estimator = "Naive";
68✔
556
      break;
68✔
557
    case RandomRayVolumeEstimator::HYBRID:
473✔
558
      estimator = "Hybrid";
473✔
559
      break;
473✔
UNCOV
560
    default:
×
UNCOV
561
      fatal_error("Invalid volume estimator type");
×
562
    }
563
    fmt::print(" Volume Estimator Type             = {}\n", estimator);
461✔
564

565
    std::string adjoint_true = (FlatSourceDomain::adjoint_) ? "ON" : "OFF";
1,689✔
566
    fmt::print(" Adjoint Flux Mode                 = {}\n", adjoint_true);
461✔
567

568
    std::string shape;
1,126✔
569
    switch (RandomRay::source_shape_) {
563!
570
    case RandomRaySourceShape::FLAT:
310✔
571
      shape = "Flat";
310✔
572
      break;
310✔
573
    case RandomRaySourceShape::LINEAR:
220✔
574
      shape = "Linear";
220✔
575
      break;
220✔
576
    case RandomRaySourceShape::LINEAR_XY:
33✔
577
      shape = "Linear XY";
33✔
578
      break;
33✔
UNCOV
579
    default:
×
UNCOV
580
      fatal_error("Invalid random ray source shape");
×
581
    }
582
    fmt::print(" Source Shape                      = {}\n", shape);
461✔
583
    std::string sample_method =
584
      (RandomRay::sample_method_ == RandomRaySampleMethod::PRNG) ? "PRNG"
563✔
585
                                                                 : "Halton";
1,689✔
586
    fmt::print(" Sample Method                     = {}\n", sample_method);
461✔
587

588
    if (domain_->is_transport_stabilization_needed_) {
563✔
589
      fmt::print(" Transport XS Stabilization Used   = YES (rho = {:.3f})\n",
11✔
590
        FlatSourceDomain::diagonal_stabilization_rho_);
591
    } else {
592
      fmt::print(" Transport XS Stabilization Used   = NO\n");
552✔
593
    }
594

595
    header("Timing Statistics", 4);
563✔
596
    show_time("Total time for initialization", time_initialize.elapsed());
563✔
597
    show_time("Reading cross sections", time_read_xs.elapsed(), 1);
563✔
598
    show_time("Total simulation time", time_total.elapsed());
563✔
599
    show_time("Transport sweep only", time_transport.elapsed(), 1);
563✔
600
    show_time("Source update only", time_update_src.elapsed(), 1);
563✔
601
    show_time("Tally conversion only", time_tallies.elapsed(), 1);
563✔
602
    show_time("MPI source reductions only", time_bank_sendrecv.elapsed(), 1);
563✔
603
    show_time("Other iteration routines", misc_time, 1);
563✔
604
    if (settings::run_mode == RunMode::EIGENVALUE) {
563✔
605
      show_time("Time in inactive batches", time_inactive.elapsed());
231✔
606
    }
607
    show_time("Time in active batches", time_active.elapsed());
563✔
608
    show_time("Time writing statepoints", time_statepoint.elapsed());
563✔
609
    show_time("Total time for finalization", time_finalize.elapsed());
563✔
610
    show_time("Time per integration", time_per_integration);
563✔
611
  }
563✔
612

613
  if (settings::verbosity >= 4 && settings::run_mode == RunMode::EIGENVALUE) {
563!
614
    header("Results", 4);
231✔
615
    fmt::print(" k-effective                       = {:.5f} +/- {:.5f}\n",
231✔
616
      simulation::keff, simulation::keff_std);
617
  }
618
}
563✔
619

620
void openmc_finalize_random_ray()
8,210✔
621
{
622
  FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::HYBRID;
8,210✔
623
  FlatSourceDomain::volume_normalized_flux_tallies_ = false;
8,210✔
624
  FlatSourceDomain::adjoint_ = false;
8,210✔
625
  FlatSourceDomain::mesh_domain_map_.clear();
8,210✔
626
  RandomRay::ray_source_.reset();
8,210✔
627
  RandomRay::source_shape_ = RandomRaySourceShape::FLAT;
8,210✔
628
  RandomRay::sample_method_ = RandomRaySampleMethod::PRNG;
8,210✔
629
}
8,210✔
630

631
} // namespace openmc
632

633
//==============================================================================
634
// C API functions
635
//==============================================================================
636

637
void openmc_run_random_ray()
732✔
638
{
639
  //////////////////////////////////////////////////////////
640
  // Run forward simulation
641
  //////////////////////////////////////////////////////////
642

643
  if (openmc::mpi::master) {
732✔
644
    if (openmc::FlatSourceDomain::adjoint_) {
507✔
645
      openmc::FlatSourceDomain::adjoint_ = false;
56✔
646
      openmc::print_adjoint_header();
56✔
647
      openmc::FlatSourceDomain::adjoint_ = true;
56✔
648
    }
649
  }
650

651
  // Initialize OpenMC general data structures
652
  openmc_simulation_init();
732✔
653

654
  // Validate that inputs meet requirements for random ray mode
655
  if (openmc::mpi::master)
732✔
656
    openmc::validate_random_ray_inputs();
507✔
657

658
  // Initialize Random Ray Simulation Object
659
  openmc::RandomRaySimulation sim;
732✔
660

661
  // Initialize fixed sources, if present
662
  sim.apply_fixed_sources_and_mesh_domains();
732✔
663

664
  // Run initial random ray simulation
665
  sim.simulate();
732✔
666

667
  //////////////////////////////////////////////////////////
668
  // Run adjoint simulation (if enabled)
669
  //////////////////////////////////////////////////////////
670

671
  if (sim.adjoint_needed_) {
732✔
672
    // Setup for adjoint simulation
673
    sim.prepare_adjoint_simulation();
81✔
674

675
    // Run adjoint simulation
676
    sim.simulate();
81✔
677
  }
678
}
732✔
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