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

openmc-dev / openmc / 24201667475

09 Apr 2026 04:34PM UTC coverage: 81.306% (-0.03%) from 81.337%
24201667475

Pull #3702

github

web-flow
Merge 85e3d3a8b into 1eb368bbd
Pull Request #3702: Random Ray Kinetic Simulation Mode

18160 of 26198 branches covered (69.32%)

Branch coverage included in aggregate %.

935 of 1075 new or added lines in 20 files covered. (86.98%)

74 existing lines in 8 files now uncovered.

58936 of 68624 relevant lines covered (85.88%)

52648244.8 hits per line

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

75.65
/src/settings.cpp
1
#include "openmc/settings.h"
2
#include "openmc/random_ray/flat_source_domain.h"
3

4
#include <cmath>  // for ceil, pow
5
#include <limits> // for numeric_limits
6
#include <string>
7

8
#include <fmt/core.h>
9
#ifdef _OPENMP
10
#include <omp.h>
11
#endif
12

13
#include "openmc/capi.h"
14
#include "openmc/collision_track.h"
15
#include "openmc/constants.h"
16
#include "openmc/container_util.h"
17
#include "openmc/distribution.h"
18
#include "openmc/distribution_multi.h"
19
#include "openmc/distribution_spatial.h"
20
#include "openmc/eigenvalue.h"
21
#include "openmc/error.h"
22
#include "openmc/file_utils.h"
23
#include "openmc/mcpl_interface.h"
24
#include "openmc/mesh.h"
25
#include "openmc/message_passing.h"
26
#include "openmc/output.h"
27
#include "openmc/plot.h"
28
#include "openmc/random_lcg.h"
29
#include "openmc/random_ray/random_ray.h"
30
#include "openmc/reaction.h"
31
#include "openmc/simulation.h"
32
#include "openmc/source.h"
33
#include "openmc/string_utils.h"
34
#include "openmc/tallies/trigger.h"
35
#include "openmc/volume_calc.h"
36
#include "openmc/weight_windows.h"
37
#include "openmc/xml_interface.h"
38

39
namespace openmc {
40

41
//==============================================================================
42
// Global variables
43
//==============================================================================
44

45
namespace settings {
46

47
// Default values for boolean flags
48
bool assume_separate {false};
49
bool check_overlaps {false};
50
bool collision_track {false};
51
bool cmfd_run {false};
52
bool confidence_intervals {false};
53
bool create_delayed_neutrons {true};
54
bool create_fission_neutrons {true};
55
bool delayed_photon_scaling {true};
56
bool entropy_on {false};
57
bool event_based {false};
58
bool ifp_on {false};
59
bool kinetic_simulation {false};
60
bool legendre_to_tabular {true};
61
bool material_cell_offsets {true};
62
bool output_summary {true};
63
bool output_tallies {true};
64
bool particle_restart_run {false};
65
bool photon_transport {false};
66
bool atomic_relaxation {true};
67
bool reduce_tallies {true};
68
bool res_scat_on {false};
69
bool restart_run {false};
70
bool run_CE {true};
71
bool source_latest {false};
72
bool source_separate {false};
73
bool source_write {true};
74
bool source_mcpl_write {false};
75
bool surf_source_write {false};
76
bool surf_mcpl_write {false};
77
bool surf_source_read {false};
78
bool survival_biasing {false};
79
bool survival_normalization {false};
80
bool temperature_multipole {false};
81
bool trigger_on {false};
82
bool trigger_predict {false};
83
bool uniform_source_sampling {false};
84
bool ufs_on {false};
85
bool urr_ptables_on {true};
86
bool use_decay_photons {false};
87
bool weight_windows_on {false};
88
bool weight_window_checkpoint_surface {false};
89
bool weight_window_checkpoint_collision {true};
90
bool write_all_tracks {false};
91
bool write_initial_source {false};
92

93
std::string path_cross_sections;
94
std::string path_input;
95
std::string path_output;
96
std::string path_particle_restart;
97
std::string path_sourcepoint;
98
std::string path_statepoint;
99
const char* path_statepoint_c {path_statepoint.c_str()};
100
std::string weight_windows_file;
101
std::string properties_file;
102

103
int32_t n_inactive {0};
104
int32_t max_lost_particles {10};
105
double rel_max_lost_particles {1.0e-6};
106
int32_t max_write_lost_particles {-1};
107
int32_t gen_per_batch {1};
108
int64_t n_particles {-1};
109

110
int64_t max_particles_in_flight {100000};
111
int max_particle_events {1000000};
112

113
ElectronTreatment electron_treatment {ElectronTreatment::TTB};
114
array<double, 4> energy_cutoff {0.0, 1000.0, 0.0, 0.0};
115
array<double, 4> time_cutoff {INFTY, INFTY, INFTY, INFTY};
116
int ifp_n_generation {-1};
117
IFPParameter ifp_parameter {IFPParameter::None};
118
int legendre_to_tabular_points {C_NONE};
119
int max_order {0};
120
int n_log_bins {8000};
121
int n_batches;
122
int n_max_batches;
123
int max_secondaries {10000};
124
int max_history_splits {10'000'000};
125
int max_tracks {1000};
126
ResScatMethod res_scat_method {ResScatMethod::rvs};
127
double res_scat_energy_min {0.01};
128
double res_scat_energy_max {1000.0};
129
vector<std::string> res_scat_nuclides;
130
RunMode run_mode {RunMode::UNSET};
131
SolverType solver_type {SolverType::MONTE_CARLO};
132
std::unordered_set<int> sourcepoint_batch;
133
std::unordered_set<int> statepoint_batch;
134
double source_rejection_fraction {0.05};
135
double free_gas_threshold {400.0};
136
std::unordered_set<int> source_write_surf_id;
137
CollisionTrackConfig collision_track_config {};
138
int64_t ssw_max_particles;
139
int64_t ssw_max_files;
140
int64_t ssw_cell_id {C_NONE};
141
SSWCellType ssw_cell_type {SSWCellType::None};
142
double surface_grazing_cutoff {0.001};
143
double surface_grazing_ratio {0.5};
144
TemperatureMethod temperature_method {TemperatureMethod::NEAREST};
145
double temperature_tolerance {10.0};
146
double temperature_default {293.6};
147
array<double, 2> temperature_range {0.0, 0.0};
148
int trace_batch;
149
int trace_gen;
150
int64_t trace_particle;
151
vector<array<int, 3>> track_identifiers;
152
int trigger_batch_interval {1};
153
int verbosity {-1};
154
double weight_cutoff {0.25};
155
double weight_survive {1.0};
156

157
// Timestep variables for kinetic simulation
158
int n_timesteps;
159
double dt;
160

161
} // namespace settings
162

163
//==============================================================================
164
// Functions
165
//==============================================================================
166

167
void get_run_parameters(pugi::xml_node node_base)
7,759✔
168
{
169
  using namespace settings;
7,759✔
170
  using namespace pugi;
7,759✔
171

172
  // Check number of particles
173
  if (!check_for_node(node_base, "particles")) {
7,759!
174
    fatal_error("Need to specify number of particles.");
×
175
  }
176

177
  // Get number of particles if it wasn't specified as a command-line argument
178
  if (n_particles == -1) {
7,759!
179
    n_particles = std::stoll(get_node_value(node_base, "particles"));
7,759✔
180
  }
181

182
  // Get maximum number of in flight particles for event-based mode
183
  if (check_for_node(node_base, "max_particles_in_flight")) {
7,759!
184
    max_particles_in_flight =
×
185
      std::stoll(get_node_value(node_base, "max_particles_in_flight"));
×
186
  }
187

188
  // Get maximum number of events allowed per particle
189
  if (check_for_node(node_base, "max_particle_events")) {
7,759!
190
    max_particle_events =
×
191
      std::stoll(get_node_value(node_base, "max_particle_events"));
×
192
  }
193

194
  // Get number of basic batches
195
  if (check_for_node(node_base, "batches")) {
7,759!
196
    n_batches = std::stoi(get_node_value(node_base, "batches"));
7,759✔
197
  }
198
  if (!trigger_on)
7,759✔
199
    n_max_batches = n_batches;
7,618✔
200

201
  // Get max number of lost particles
202
  if (check_for_node(node_base, "max_lost_particles")) {
7,759✔
203
    max_lost_particles =
92✔
204
      std::stoi(get_node_value(node_base, "max_lost_particles"));
46✔
205
  }
206

207
  // Get relative number of lost particles
208
  if (check_for_node(node_base, "rel_max_lost_particles")) {
7,759!
209
    rel_max_lost_particles =
×
210
      std::stod(get_node_value(node_base, "rel_max_lost_particles"));
×
211
  }
212

213
  // Get relative number of lost particles
214
  if (check_for_node(node_base, "max_write_lost_particles")) {
7,759✔
215
    max_write_lost_particles =
30✔
216
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
15✔
217
  }
218

219
  // Get number of inactive batches
220
  if (run_mode == RunMode::EIGENVALUE ||
7,759✔
221
      solver_type == SolverType::RANDOM_RAY) {
2,965✔
222
    if (check_for_node(node_base, "inactive")) {
5,200✔
223
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,989✔
224
    }
225
    if (check_for_node(node_base, "generations_per_batch")) {
5,200✔
226
      gen_per_batch =
30✔
227
        std::stoi(get_node_value(node_base, "generations_per_batch"));
15✔
228
    }
229

230
    // Preallocate space for keff and entropy by generation
231
    int m = settings::n_max_batches * settings::gen_per_batch;
5,200✔
232
    simulation::k_generation.reserve(m);
5,200✔
233
    simulation::entropy.reserve(m);
5,200✔
234

235
    // Get the trigger information for keff
236
    if (check_for_node(node_base, "keff_trigger")) {
5,200✔
237
      xml_node node_keff_trigger = node_base.child("keff_trigger");
101✔
238

239
      if (check_for_node(node_keff_trigger, "type")) {
101!
240
        auto temp = get_node_value(node_keff_trigger, "type", true, true);
101✔
241
        if (temp == "std_dev") {
101!
242
          keff_trigger.metric = TriggerMetric::standard_deviation;
101✔
243
        } else if (temp == "variance") {
×
244
          keff_trigger.metric = TriggerMetric::variance;
×
245
        } else if (temp == "rel_err") {
×
246
          keff_trigger.metric = TriggerMetric::relative_error;
×
247
        } else {
248
          fatal_error("Unrecognized keff trigger type " + temp);
×
249
        }
250
      } else {
×
251
        fatal_error("Specify keff trigger type in settings XML");
×
252
      }
253

254
      if (check_for_node(node_keff_trigger, "threshold")) {
101!
255
        keff_trigger.threshold =
202✔
256
          std::stod(get_node_value(node_keff_trigger, "threshold"));
202✔
257
        if (keff_trigger.threshold <= 0) {
101!
258
          fatal_error("keff trigger threshold must be positive");
×
259
        }
260
      } else {
261
        fatal_error("Specify keff trigger threshold in settings XML");
×
262
      }
263
    }
264
  }
265

266
  // Kinetic variables
267
  if (check_for_node(node_base, "kinetic_simulation")) {
7,759✔
268
    kinetic_simulation = get_node_value_bool(node_base, "kinetic_simulation");
180✔
269
    if (solver_type != SolverType::RANDOM_RAY) {
180!
NEW
270
      fatal_error("Unsupported solver selected for kinetic simulation. Kinetic "
×
271
                  "simulations currently only support the random ray solver.");
272
    }
273
    if (run_mode != RunMode::EIGENVALUE) {
180!
NEW
274
      fatal_error(
×
275
        "Unsupported run mode selected for kinetic simulation. Kinetic "
276
        "simulations currently only support run mode based on an eigenvalue "
277
        "simulation establishing an initial condition.");
278
    }
279
  }
280

281
  // Get timestep parameters for kinetic simulations
282
  if (kinetic_simulation) {
7,759✔
283
    xml_node ts_node = node_base.child("timestep_parameters");
180✔
284
    if (check_for_node(ts_node, "n_timesteps")) {
180!
285
      n_timesteps = std::stoi(get_node_value(ts_node, "n_timesteps"));
360✔
286
    } else {
NEW
287
      fatal_error("Specify number of timesteps in settings XML");
×
288
    }
289
    if (check_for_node(ts_node, "timestep_units")) {
180!
290
      std::string units = get_node_value(ts_node, "timestep_units");
180✔
291
      if (check_for_node(ts_node, "dt")) {
180!
292
        dt = std::stod(get_node_value(ts_node, "dt"));
360✔
293
        double factor_to_seconds;
180✔
294
        if (units == "ms") {
180!
295
          factor_to_seconds = 1e-3;
296
        } else if (units == "s") {
180!
297
          factor_to_seconds = 1.0;
NEW
298
        } else if (units == "min") {
×
299
          factor_to_seconds = 1 / 60;
300
        } else {
NEW
301
          fatal_error("Invalid timestep unit, " + units);
×
302
        }
303
        dt *= factor_to_seconds;
180✔
304
      } else {
NEW
305
        fatal_error("Specify dt in settings XML");
×
306
      }
307
    } else {
180✔
NEW
308
      fatal_error("Specify timestep units in settings XML");
×
309
    }
310
  }
311

312
  // Random ray variables
313
  if (solver_type == SolverType::RANDOM_RAY) {
7,759✔
314
    xml_node random_ray_node = node_base.child("random_ray");
942✔
315
    if (check_for_node(random_ray_node, "distance_active")) {
942!
316
      RandomRay::distance_active_ =
1,884✔
317
        std::stod(get_node_value(random_ray_node, "distance_active"));
1,884✔
318
      if (RandomRay::distance_active_ <= 0.0) {
942!
319
        fatal_error("Random ray active distance must be greater than 0");
×
320
      }
321
    } else {
322
      fatal_error("Specify random ray active distance in settings XML");
×
323
    }
324
    if (check_for_node(random_ray_node, "distance_inactive")) {
942!
325
      RandomRay::distance_inactive_ =
1,884✔
326
        std::stod(get_node_value(random_ray_node, "distance_inactive"));
1,884✔
327
      if (RandomRay::distance_inactive_ < 0) {
942!
328
        fatal_error(
×
329
          "Random ray inactive distance must be greater than or equal to 0");
330
      }
331
    } else {
332
      fatal_error("Specify random ray inactive distance in settings XML");
×
333
    }
334
    if (check_for_node(random_ray_node, "source")) {
942!
335
      xml_node source_node = random_ray_node.child("source");
942✔
336
      // Get point to list of <source> elements and make sure there is at least
337
      // one
338
      RandomRay::ray_source_ = Source::create(source_node);
1,884✔
339
    } else {
340
      fatal_error("Specify random ray source in settings XML");
×
341
    }
342
    if (check_for_node(random_ray_node, "volume_estimator")) {
942✔
343
      std::string temp_str =
121✔
344
        get_node_value(random_ray_node, "volume_estimator", true, true);
121✔
345
      if (temp_str == "simulation_averaged") {
121✔
346
        FlatSourceDomain::volume_estimator_ =
30✔
347
          RandomRayVolumeEstimator::SIMULATION_AVERAGED;
348
      } else if (temp_str == "naive") {
91✔
349
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::NAIVE;
61✔
350
      } else if (temp_str == "hybrid") {
30!
351
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::HYBRID;
30✔
352
      } else {
353
        fatal_error("Unrecognized volume estimator: " + temp_str);
×
354
      }
355
    }
121✔
356
    if (check_for_node(random_ray_node, "source_shape")) {
942✔
357
      std::string temp_str =
450✔
358
        get_node_value(random_ray_node, "source_shape", true, true);
450✔
359
      if (temp_str == "flat") {
450✔
360
        RandomRay::source_shape_ = RandomRaySourceShape::FLAT;
75✔
361
      } else if (temp_str == "linear") {
375✔
362
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR;
330✔
363
        if (settings::kinetic_simulation) {
330!
NEW
364
          fatal_error(
×
365
            "linear source shapes unimplemented for kinetic simulations.");
366
        }
367
      } else if (temp_str == "linear_xy") {
45!
368
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR_XY;
45✔
369
        if (settings::kinetic_simulation) {
45!
NEW
370
          fatal_error(
×
371
            "linear_xy source shapes unimplemented for kinetic simulations.");
372
        }
373
      } else {
374
        fatal_error("Unrecognized source shape: " + temp_str);
×
375
      }
376
    }
450✔
377
    if (check_for_node(random_ray_node, "volume_normalized_flux_tallies")) {
942✔
378
      FlatSourceDomain::volume_normalized_flux_tallies_ =
581✔
379
        get_node_value_bool(random_ray_node, "volume_normalized_flux_tallies");
581✔
380
    }
381
    if (check_for_node(random_ray_node, "adjoint")) {
942✔
382
      FlatSourceDomain::adjoint_ =
60✔
383
        get_node_value_bool(random_ray_node, "adjoint");
30✔
384
      if (FlatSourceDomain::adjoint_ && kinetic_simulation) {
30!
NEW
385
        fatal_error("Adjoint kinetic simulations are currently unsupported .");
×
386
      }
387
    }
388
    if (check_for_node(random_ray_node, "sample_method")) {
942✔
389
      std::string temp_str =
30✔
390
        get_node_value(random_ray_node, "sample_method", true, true);
30✔
391
      if (temp_str == "prng") {
30!
392
        RandomRay::sample_method_ = RandomRaySampleMethod::PRNG;
×
393
      } else if (temp_str == "halton") {
30✔
394
        RandomRay::sample_method_ = RandomRaySampleMethod::HALTON;
15✔
395
      } else if (temp_str == "s2") {
15!
396
        RandomRay::sample_method_ = RandomRaySampleMethod::S2;
15✔
397
      } else {
398
        fatal_error("Unrecognized sample method: " + temp_str);
×
399
      }
400
    }
30✔
401
    if (check_for_node(random_ray_node, "source_region_meshes")) {
942✔
402
      pugi::xml_node node_source_region_meshes =
466✔
403
        random_ray_node.child("source_region_meshes");
466✔
404
      for (pugi::xml_node node_mesh :
992✔
405
        node_source_region_meshes.children("mesh")) {
992✔
406
        int mesh_id = std::stoi(node_mesh.attribute("id").value());
1,052✔
407
        for (pugi::xml_node node_domain : node_mesh.children("domain")) {
1,052✔
408
          int domain_id = std::stoi(node_domain.attribute("id").value());
1,052✔
409
          std::string domain_type = node_domain.attribute("type").value();
526✔
410
          Source::DomainType type;
526✔
411
          if (domain_type == "material") {
526✔
412
            type = Source::DomainType::MATERIAL;
30✔
413
          } else if (domain_type == "cell") {
496✔
414
            type = Source::DomainType::CELL;
30✔
415
          } else if (domain_type == "universe") {
466!
416
            type = Source::DomainType::UNIVERSE;
466✔
417
          } else {
418
            throw std::runtime_error("Unknown domain type: " + domain_type);
×
419
          }
420
          FlatSourceDomain::mesh_domain_map_[mesh_id].emplace_back(
526✔
421
            type, domain_id);
422
        }
526✔
423
      }
424
    }
425
    if (check_for_node(random_ray_node, "diagonal_stabilization_rho")) {
942✔
426
      FlatSourceDomain::diagonal_stabilization_rho_ = std::stod(
45✔
427
        get_node_value(random_ray_node, "diagonal_stabilization_rho"));
45✔
428
      if (FlatSourceDomain::diagonal_stabilization_rho_ < 0.0 ||
45!
429
          FlatSourceDomain::diagonal_stabilization_rho_ > 1.0) {
430
        fatal_error("Random ray diagonal stabilization rho factor must be "
×
431
                    "between 0 and 1");
432
      }
433
    }
434
    if (kinetic_simulation) {
942✔
435
      if (check_for_node(random_ray_node, "bd_order")) {
180✔
436
        static int n = std::stod(get_node_value(random_ray_node, "bd_order"));
120!
437
        if (n < 1 || n > 6) {
60!
NEW
438
          fatal_error("Specified BD order of " + std::to_string(n) +
×
439
                      ". BD order must be between 1 and 6");
440
        } else {
441
          RandomRay::bd_order_ = n;
60✔
442
        }
443
      }
444
      if (check_for_node(random_ray_node, "time_derivative_method")) {
180✔
445
        std::string temp_str =
120✔
446
          get_node_value(random_ray_node, "time_derivative_method", true, true);
120✔
447
        if (temp_str == "isotropic") {
120✔
448
          RandomRay::time_method_ = RandomRayTimeMethod::ISOTROPIC;
60✔
449
        } else if (temp_str == "propagation") {
60!
450
          RandomRay::time_method_ = RandomRayTimeMethod::PROPAGATION;
60✔
451
        } else {
NEW
452
          fatal_error("Unrecognized time derivative method: " + temp_str);
×
453
        }
454
      }
120✔
455
    }
456
  }
457
}
7,759✔
458

459
void read_settings_xml()
1,349✔
460
{
461
  using namespace settings;
1,349✔
462
  using namespace pugi;
1,349✔
463
  // Check if settings.xml exists
464
  std::string filename = settings::path_input + "settings.xml";
1,349✔
465
  if (!file_exists(filename)) {
1,349✔
466
    if (run_mode != RunMode::PLOTTING) {
22!
467
      fatal_error("Could not find any XML input files! In order to run OpenMC, "
×
468
                  "you first need a set of input files; at a minimum, this "
469
                  "includes settings.xml, geometry.xml, and materials.xml or a "
470
                  "single model XML file. Please consult the user's guide at "
471
                  "https://docs.openmc.org for further information.");
472
    } else {
473
      // The settings.xml file is optional if we just want to make a plot.
474
      return;
22✔
475
    }
476
  }
477

478
  // Parse settings.xml file
479
  xml_document doc;
1,327✔
480
  auto result = doc.load_file(filename.c_str());
1,327✔
481
  if (!result) {
1,327!
482
    fatal_error("Error processing settings.xml file.");
×
483
  }
484

485
  // Get root element
486
  xml_node root = doc.document_element();
1,327✔
487

488
  // Verbosity
489
  if (check_for_node(root, "verbosity") && verbosity == -1) {
1,327!
490
    verbosity = std::stoi(get_node_value(root, "verbosity"));
362✔
491
  } else if (verbosity == -1) {
1,146!
492
    verbosity = 7;
1,146✔
493
  }
494

495
  // To this point, we haven't displayed any output since we didn't know what
496
  // the verbosity is. Now that we checked for it, show the title if necessary
497
  if (mpi::master) {
1,327✔
498
    if (verbosity >= 2)
1,147✔
499
      title();
974✔
500
  }
501

502
  write_message("Reading settings XML file...", 5);
1,327✔
503

504
  read_settings_xml(root);
1,327✔
505
}
1,339✔
506

507
void read_settings_xml(pugi::xml_node root)
8,567✔
508
{
509
  using namespace settings;
8,567✔
510
  using namespace pugi;
8,567✔
511

512
  // Find if a multi-group or continuous-energy simulation is desired
513
  if (check_for_node(root, "energy_mode")) {
8,567✔
514
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
1,477✔
515
    if (temp_str == "mg" || temp_str == "multi-group") {
2,954!
516
      run_CE = false;
1,477✔
517
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
518
      run_CE = true;
×
519
    }
520
  }
1,477✔
521

522
  // Check for user meshes and allocate
523
  read_meshes(root);
8,567✔
524

525
  // Look for deprecated cross_sections.xml file in settings.xml
526
  if (check_for_node(root, "cross_sections")) {
8,567!
527
    warning(
×
528
      "Setting cross_sections in settings.xml has been deprecated."
529
      " The cross_sections are now set in materials.xml and the "
530
      "cross_sections input to materials.xml and the OPENMC_CROSS_SECTIONS"
531
      " environment variable will take precendent over setting "
532
      "cross_sections in settings.xml.");
533
    path_cross_sections = get_node_value(root, "cross_sections");
×
534
  }
535

536
  if (!run_CE) {
8,567✔
537
    // Scattering Treatments
538
    if (check_for_node(root, "max_order")) {
1,477✔
539
      max_order = std::stoi(get_node_value(root, "max_order"));
30✔
540
    } else {
541
      // Set to default of largest int - 1, which means to use whatever is
542
      // contained in library. This is largest int - 1 because for legendre
543
      // scattering, a value of 1 is added to the order; adding 1 to the largest
544
      // int gets you the largest negative integer, which is not what we want.
545
      max_order = std::numeric_limits<int>::max() - 1;
1,462✔
546
    }
547
  }
548

549
  // Check for a trigger node and get trigger information
550
  if (check_for_node(root, "trigger")) {
8,567✔
551
    xml_node node_trigger = root.child("trigger");
156✔
552

553
    // Check if trigger(s) are to be turned on
554
    trigger_on = get_node_value_bool(node_trigger, "active");
156✔
555

556
    if (trigger_on) {
156✔
557
      if (check_for_node(node_trigger, "max_batches")) {
141!
558
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
282✔
559
      } else {
560
        fatal_error("<max_batches> must be specified with triggers");
×
561
      }
562

563
      // Get the batch interval to check triggers
564
      if (!check_for_node(node_trigger, "batch_interval")) {
141✔
565
        trigger_predict = true;
15✔
566
      } else {
567
        trigger_batch_interval =
252✔
568
          std::stoi(get_node_value(node_trigger, "batch_interval"));
252✔
569
        if (trigger_batch_interval <= 0) {
126!
570
          fatal_error("Trigger batch interval must be greater than zero");
×
571
        }
572
      }
573
    }
574
  }
575

576
  // Check run mode if it hasn't been set from the command line
577
  xml_node node_mode;
8,567✔
578
  if (run_mode == RunMode::UNSET) {
8,567✔
579
    if (check_for_node(root, "run_mode")) {
7,791✔
580
      std::string temp_str = get_node_value(root, "run_mode", true, true);
7,761✔
581
      if (temp_str == "eigenvalue") {
7,761✔
582
        run_mode = RunMode::EIGENVALUE;
4,764✔
583
      } else if (temp_str == "fixed source") {
2,997✔
584
        run_mode = RunMode::FIXED_SOURCE;
2,965✔
585
      } else if (temp_str == "plot") {
32!
586
        run_mode = RunMode::PLOTTING;
×
587
      } else if (temp_str == "particle restart") {
32!
588
        run_mode = RunMode::PARTICLE;
×
589
      } else if (temp_str == "volume") {
32!
590
        run_mode = RunMode::VOLUME;
32✔
591
      } else {
592
        fatal_error("Unrecognized run mode: " + temp_str);
×
593
      }
594

595
      // Assume XML specifies <particles>, <batches>, etc. directly
596
      node_mode = root;
7,761✔
597
    } else {
7,761✔
598
      warning("<run_mode> should be specified.");
30✔
599

600
      // Make sure that either eigenvalue or fixed source was specified
601
      node_mode = root.child("eigenvalue");
30✔
602
      if (node_mode) {
30!
603
        run_mode = RunMode::EIGENVALUE;
30✔
604
      } else {
605
        node_mode = root.child("fixed_source");
×
606
        if (node_mode) {
×
607
          run_mode = RunMode::FIXED_SOURCE;
×
608
        } else {
609
          fatal_error("<eigenvalue> or <fixed_source> not specified.");
×
610
        }
611
      }
612
    }
613
  }
614

615
  // Check solver type
616
  if (check_for_node(root, "random_ray")) {
8,567✔
617
    solver_type = SolverType::RANDOM_RAY;
942✔
618
    if (run_CE)
942!
619
      fatal_error("multi-group energy mode must be specified in settings XML "
×
620
                  "when using the random ray solver.");
621
  }
622

623
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
8,567✔
624
    // Read run parameters
625
    get_run_parameters(node_mode);
7,759✔
626

627
    // Check number of active batches, inactive batches, max lost particles and
628
    // particles
629
    if (n_batches <= n_inactive) {
7,759!
630
      fatal_error("Number of active batches must be greater than zero.");
×
631
    } else if (n_inactive < 0) {
7,759!
632
      fatal_error("Number of inactive batches must be non-negative.");
×
633
    } else if (n_particles <= 0) {
7,759!
634
      fatal_error("Number of particles must be greater than zero.");
×
635
    } else if (max_lost_particles <= 0) {
7,759!
636
      fatal_error("Number of max lost particles must be greater than zero.");
×
637
    } else if (rel_max_lost_particles <= 0.0 || rel_max_lost_particles >= 1.0) {
7,759!
638
      fatal_error("Relative max lost particles must be between zero and one.");
×
639
    }
640

641
    // Check for user value for the number of generation of the Iterated Fission
642
    // Probability (IFP) method
643
    if (check_for_node(root, "ifp_n_generation")) {
7,759✔
644
      ifp_n_generation = std::stoi(get_node_value(root, "ifp_n_generation"));
166✔
645
      if (ifp_n_generation <= 0) {
83!
646
        fatal_error("'ifp_n_generation' must be greater than 0.");
×
647
      }
648
      // Avoid tallying 0 if IFP logs are not complete when active cycles start
649
      if (ifp_n_generation > n_inactive) {
83✔
650
        fatal_error("'ifp_n_generation' must be lower than or equal to the "
9✔
651
                    "number of inactive cycles.");
652
      }
653
    }
654
  }
655

656
  // Copy plotting random number seed if specified
657
  if (check_for_node(root, "plot_seed")) {
8,558!
658
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
659
    model::plotter_seed = seed;
×
660
  }
661

662
  // Copy random number seed if specified
663
  if (check_for_node(root, "seed")) {
8,558✔
664
    auto seed = std::stoll(get_node_value(root, "seed"));
1,154✔
665
    openmc_set_seed(seed);
577✔
666
  }
667

668
  // Copy random number stride if specified
669
  if (check_for_node(root, "stride")) {
8,558✔
670
    auto stride = std::stoull(get_node_value(root, "stride"));
30✔
671
    openmc_set_stride(stride);
15✔
672
  }
673

674
  // Check for electron treatment
675
  if (check_for_node(root, "electron_treatment")) {
8,558✔
676
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
82✔
677
    if (temp_str == "led") {
82✔
678
      electron_treatment = ElectronTreatment::LED;
26✔
679
    } else if (temp_str == "ttb") {
56!
680
      electron_treatment = ElectronTreatment::TTB;
56✔
681
    } else {
682
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
683
    }
684
  }
82✔
685

686
  // Check for photon transport
687
  if (check_for_node(root, "photon_transport")) {
8,558✔
688
    photon_transport = get_node_value_bool(root, "photon_transport");
205✔
689

690
    if (!run_CE && photon_transport) {
205!
691
      fatal_error("Photon transport is not currently supported in "
×
692
                  "multigroup mode");
693
    }
694
  }
695

696
  // Check for atomic relaxation
697
  if (check_for_node(root, "atomic_relaxation")) {
8,558✔
698
    atomic_relaxation = get_node_value_bool(root, "atomic_relaxation");
15✔
699
  }
700

701
  // Number of bins for logarithmic grid
702
  if (check_for_node(root, "log_grid_bins")) {
8,558✔
703
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
30✔
704
    if (n_log_bins < 1) {
15!
705
      fatal_error("Number of bins for logarithmic grid must be greater "
×
706
                  "than zero.");
707
    }
708
  }
709

710
  // Number of OpenMP threads
711
  if (check_for_node(root, "threads")) {
8,558!
712
    if (mpi::master)
×
713
      warning("The <threads> element has been deprecated. Use "
×
714
              "the OMP_NUM_THREADS environment variable to set the number of "
715
              "threads.");
716
  }
717

718
  // ==========================================================================
719
  // EXTERNAL SOURCE
720

721
  // Get point to list of <source> elements and make sure there is at least one
722
  for (pugi::xml_node node : root.children("source")) {
16,600✔
723
    model::external_sources.push_back(Source::create(node));
16,094✔
724
  }
725

726
  // Check if the user has specified to read surface source
727
  if (check_for_node(root, "surf_source_read")) {
8,548✔
728
    surf_source_read = true;
30✔
729
    // Get surface source read node
730
    xml_node node_ssr = root.child("surf_source_read");
30✔
731

732
    std::string path = "surface_source.h5";
30✔
733
    // Check if the user has specified different file for surface source reading
734
    if (check_for_node(node_ssr, "path")) {
30!
735
      path = get_node_value(node_ssr, "path", false, true);
30✔
736
    }
737
    model::external_sources.push_back(make_unique<FileSource>(path));
30✔
738
  }
30✔
739

740
  // If no source specified, default to isotropic point source at origin with
741
  // Watt spectrum. No default source is needed in random ray mode.
742
  if (model::external_sources.empty() &&
8,548✔
743
      settings::solver_type != SolverType::RANDOM_RAY) {
2,287✔
744
    double T[] {0.0};
2,081✔
745
    double p[] {1.0};
2,081✔
746
    model::external_sources.push_back(make_unique<IndependentSource>(
2,081✔
747
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
4,162✔
748
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
4,162✔
749
      UPtrDist {new Discrete(T, p, 1)}));
4,162✔
750
  }
751

752
  // Build probability mass function for sampling external sources
753
  vector<double> source_strengths;
8,548✔
754
  for (auto& s : model::external_sources) {
18,701✔
755
    source_strengths.push_back(s->strength());
10,153✔
756
  }
757
  model::external_sources_probability.assign(source_strengths);
8,548✔
758

759
  // Check if we want to write out source
760
  if (check_for_node(root, "write_initial_source")) {
8,548!
761
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
762
  }
763

764
  // Get relative number of lost particles
765
  if (check_for_node(root, "source_rejection_fraction")) {
8,548✔
766
    source_rejection_fraction =
14✔
767
      std::stod(get_node_value(root, "source_rejection_fraction"));
14!
768
  }
769

770
  if (check_for_node(root, "free_gas_threshold")) {
8,548!
771
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
772
  }
773

774
  // Surface grazing
775
  if (check_for_node(root, "surface_grazing_cutoff"))
8,548!
776
    surface_grazing_cutoff =
×
777
      std::stod(get_node_value(root, "surface_grazing_cutoff"));
×
778
  if (check_for_node(root, "surface_grazing_ratio"))
8,548!
779
    surface_grazing_ratio =
×
780
      std::stod(get_node_value(root, "surface_grazing_ratio"));
×
781

782
  // Survival biasing
783
  if (check_for_node(root, "survival_biasing")) {
8,548✔
784
    survival_biasing = get_node_value_bool(root, "survival_biasing");
190✔
785
  }
786

787
  // Probability tables
788
  if (check_for_node(root, "ptables")) {
8,548✔
789
    urr_ptables_on = get_node_value_bool(root, "ptables");
15✔
790
  }
791

792
  // Cutoffs
793
  if (check_for_node(root, "cutoff")) {
8,548✔
794
    xml_node node_cutoff = root.child("cutoff");
138✔
795
    if (check_for_node(node_cutoff, "weight")) {
138✔
796
      weight_cutoff = std::stod(get_node_value(node_cutoff, "weight"));
30✔
797
    }
798
    if (check_for_node(node_cutoff, "weight_avg")) {
138✔
799
      weight_survive = std::stod(get_node_value(node_cutoff, "weight_avg"));
30✔
800
    }
801
    if (check_for_node(node_cutoff, "survival_normalization")) {
138!
802
      survival_normalization =
×
803
        get_node_value_bool(node_cutoff, "survival_normalization");
×
804
    }
805
    if (check_for_node(node_cutoff, "energy_neutron")) {
138✔
806
      energy_cutoff[0] =
15✔
807
        std::stod(get_node_value(node_cutoff, "energy_neutron"));
30✔
808
    } else if (check_for_node(node_cutoff, "energy")) {
123!
809
      warning("The use of an <energy> cutoff is deprecated and should "
×
810
              "be replaced by <energy_neutron>.");
811
      energy_cutoff[0] = std::stod(get_node_value(node_cutoff, "energy"));
×
812
    }
813
    if (check_for_node(node_cutoff, "energy_photon")) {
138✔
814
      energy_cutoff[1] =
82✔
815
        std::stod(get_node_value(node_cutoff, "energy_photon"));
164✔
816
    }
817
    if (check_for_node(node_cutoff, "energy_electron")) {
138!
818
      energy_cutoff[2] =
×
819
        std::stof(get_node_value(node_cutoff, "energy_electron"));
×
820
    }
821
    if (check_for_node(node_cutoff, "energy_positron")) {
138!
822
      energy_cutoff[3] =
×
823
        std::stod(get_node_value(node_cutoff, "energy_positron"));
×
824
    }
825
    if (check_for_node(node_cutoff, "time_neutron")) {
138✔
826
      time_cutoff[0] = std::stod(get_node_value(node_cutoff, "time_neutron"));
26✔
827
    }
828
    if (check_for_node(node_cutoff, "time_photon")) {
138!
829
      time_cutoff[1] = std::stod(get_node_value(node_cutoff, "time_photon"));
×
830
    }
831
    if (check_for_node(node_cutoff, "time_electron")) {
138!
832
      time_cutoff[2] = std::stod(get_node_value(node_cutoff, "time_electron"));
×
833
    }
834
    if (check_for_node(node_cutoff, "time_positron")) {
138!
835
      time_cutoff[3] = std::stod(get_node_value(node_cutoff, "time_positron"));
×
836
    }
837
  }
838

839
  // read properties from file
840
  if (check_for_node(root, "properties_file")) {
8,548✔
841
    properties_file = get_node_value(root, "properties_file");
11✔
842
    if (!file_exists(properties_file)) {
11!
843
      fatal_error(fmt::format("File '{}' does not exist.", properties_file));
×
844
    }
845
  }
846

847
  // Particle trace
848
  if (check_for_node(root, "trace")) {
8,548✔
849
    auto temp = get_node_array<int64_t>(root, "trace");
15✔
850
    if (temp.size() != 3) {
15!
851
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
852
                  "batch, generation, and particle number.");
853
    }
854
    trace_batch = temp.at(0);
15✔
855
    trace_gen = temp.at(1);
15✔
856
    trace_particle = temp.at(2);
15✔
857
  }
15✔
858

859
  // Particle tracks
860
  if (check_for_node(root, "track")) {
8,548✔
861
    // Get values and make sure there are three per particle
862
    auto temp = get_node_array<int>(root, "track");
45✔
863
    if (temp.size() % 3 != 0) {
45!
864
      fatal_error(
×
865
        "Number of integers specified in 'track' is not "
866
        "divisible by 3.  Please provide 3 integers per particle to be "
867
        "tracked.");
868
    }
869

870
    // Reshape into track_identifiers
871
    int n_tracks = temp.size() / 3;
45✔
872
    for (int i = 0; i < n_tracks; ++i) {
180✔
873
      track_identifiers.push_back(
135✔
874
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
135✔
875
    }
876
  }
45✔
877

878
  // Shannon entropy
879
  if (solver_type == SolverType::RANDOM_RAY) {
8,548✔
880
    if (check_for_node(root, "entropy_mesh")) {
942!
881
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
882
                  "No user-defined entropy mesh is supported.");
883
    }
884
    entropy_on = true;
942✔
885
  } else if (solver_type == SolverType::MONTE_CARLO) {
7,606!
886
    if (check_for_node(root, "entropy_mesh")) {
7,606✔
887
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
668✔
888
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
334!
889
        fatal_error(fmt::format(
×
890
          "Mesh {} specified for Shannon entropy does not exist.", temp));
891
      }
892

893
      auto* m = dynamic_cast<RegularMesh*>(
334!
894
        model::meshes[model::mesh_map.at(temp)].get());
334!
895
      if (!m)
334!
896
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
897
      simulation::entropy_mesh = m;
334✔
898

899
      // Turn on Shannon entropy calculation
900
      entropy_on = true;
334✔
901

902
    } else if (check_for_node(root, "entropy")) {
7,272!
903
      fatal_error(
×
904
        "Specifying a Shannon entropy mesh via the <entropy> element "
905
        "is deprecated. Please create a mesh using <mesh> and then reference "
906
        "it by specifying its ID in an <entropy_mesh> element.");
907
    }
908
  }
909
  // Uniform fission source weighting mesh
910
  if (check_for_node(root, "ufs_mesh")) {
8,548✔
911
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
30✔
912
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
15!
913
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
914
                              "method does not exist.",
915
        temp));
916
    }
917

918
    auto* m =
15✔
919
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
15!
920
    if (!m)
15!
921
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
922
    simulation::ufs_mesh = m;
15✔
923

924
    // Turn on uniform fission source weighting
925
    ufs_on = true;
15✔
926

927
  } else if (check_for_node(root, "uniform_fs")) {
8,533!
928
    fatal_error(
×
929
      "Specifying a UFS mesh via the <uniform_fs> element "
930
      "is deprecated. Please create a mesh using <mesh> and then reference "
931
      "it by specifying its ID in a <ufs_mesh> element.");
932
  }
933

934
  // Check if the user has specified to write state points
935
  if (check_for_node(root, "state_point")) {
8,548✔
936

937
    // Get pointer to state_point node
938
    auto node_sp = root.child("state_point");
160✔
939

940
    // Determine number of batches at which to store state points
941
    if (check_for_node(node_sp, "batches")) {
160!
942
      // User gave specific batches to write state points
943
      auto temp = get_node_array<int>(node_sp, "batches");
160✔
944
      for (const auto& b : temp) {
491✔
945
        statepoint_batch.insert(b);
331✔
946
      }
947
    } else {
160✔
948
      // If neither were specified, write state point at last batch
949
      statepoint_batch.insert(n_batches);
×
950
    }
951
  } else {
952
    // If no <state_point> tag was present, by default write state point at
953
    // last batch only
954
    statepoint_batch.insert(n_batches);
8,388✔
955
  }
956

957
  // Check if the user has specified to write source points
958
  if (check_for_node(root, "source_point")) {
8,548✔
959
    // Get source_point node
960
    xml_node node_sp = root.child("source_point");
101✔
961

962
    // Determine batches at which to store source points
963
    if (check_for_node(node_sp, "batches")) {
101✔
964
      // User gave specific batches to write source points
965
      auto temp = get_node_array<int>(node_sp, "batches");
45✔
966
      for (const auto& b : temp) {
120✔
967
        sourcepoint_batch.insert(b);
75✔
968
      }
969
    } else {
45✔
970
      // If neither were specified, write source points with state points
971
      sourcepoint_batch = statepoint_batch;
56!
972
    }
973

974
    // Check if the user has specified to write binary source file
975
    if (check_for_node(node_sp, "separate")) {
101✔
976
      source_separate = get_node_value_bool(node_sp, "separate");
71✔
977
    }
978
    if (check_for_node(node_sp, "write")) {
101!
979
      source_write = get_node_value_bool(node_sp, "write");
×
980
    }
981
    if (check_for_node(node_sp, "mcpl")) {
101✔
982
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
26✔
983
    }
984
    if (check_for_node(node_sp, "overwrite_latest")) {
101✔
985
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
15✔
986
      source_separate = source_latest;
15✔
987
    }
988
  } else {
989
    // If no <source_point> tag was present, by default we keep source bank in
990
    // statepoint file and write it out at statepoints intervals
991
    source_separate = false;
8,447✔
992
    sourcepoint_batch = statepoint_batch;
8,447!
993
  }
994

995
  // Check is the user specified to convert strength to statistical weight
996
  if (check_for_node(root, "uniform_source_sampling")) {
8,548✔
997
    uniform_source_sampling =
55✔
998
      get_node_value_bool(root, "uniform_source_sampling");
55✔
999
  }
1000

1001
  // Check if the user has specified to write surface source
1002
  if (check_for_node(root, "surf_source_write")) {
8,548✔
1003
    surf_source_write = true;
412✔
1004
    // Get surface source write node
1005
    xml_node node_ssw = root.child("surf_source_write");
412✔
1006

1007
    // Determine surface ids at which crossing particles are to be banked.
1008
    // If no surfaces are specified, all surfaces in the model will be used
1009
    // to bank source points.
1010
    if (check_for_node(node_ssw, "surface_ids")) {
412✔
1011
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
202✔
1012
      for (const auto& b : temp) {
994✔
1013
        source_write_surf_id.insert(b);
792✔
1014
      }
1015
    }
202✔
1016

1017
    // Get maximum number of particles to be banked per surface
1018
    if (check_for_node(node_ssw, "max_particles")) {
412✔
1019
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
806✔
1020
    } else {
1021
      fatal_error("A maximum number of particles needs to be specified "
9✔
1022
                  "using the 'max_particles' parameter to store surface "
1023
                  "source points.");
1024
    }
1025

1026
    // Get maximum number of surface source files to be created
1027
    if (check_for_node(node_ssw, "max_source_files")) {
403✔
1028
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
66✔
1029
    } else {
1030
      ssw_max_files = 1;
370✔
1031
    }
1032

1033
    if (check_for_node(node_ssw, "mcpl")) {
403✔
1034
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
11✔
1035
    }
1036
    // Get cell information
1037
    if (check_for_node(node_ssw, "cell")) {
403✔
1038
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
208✔
1039
      ssw_cell_type = SSWCellType::Both;
104✔
1040
    }
1041
    if (check_for_node(node_ssw, "cellfrom")) {
403✔
1042
      if (ssw_cell_id != C_NONE) {
90✔
1043
        fatal_error(
18✔
1044
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
1045
      }
1046
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
144✔
1047
      ssw_cell_type = SSWCellType::From;
72✔
1048
    }
1049
    if (check_for_node(node_ssw, "cellto")) {
385✔
1050
      if (ssw_cell_id != C_NONE) {
71✔
1051
        fatal_error(
18✔
1052
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
1053
      }
1054
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
106✔
1055
      ssw_cell_type = SSWCellType::To;
53✔
1056
    }
1057
  }
1058

1059
  // Check if the user has specified to write specific collisions
1060
  if (check_for_node(root, "collision_track")) {
8,503✔
1061
    settings::collision_track = true;
148✔
1062
    // Get collision track node
1063
    xml_node node_ct = root.child("collision_track");
148✔
1064
    collision_track_config = CollisionTrackConfig {};
148✔
1065

1066
    // Determine cell ids at which crossing particles are to be banked
1067
    if (check_for_node(node_ct, "cell_ids")) {
148✔
1068
      auto temp = get_node_array<int>(node_ct, "cell_ids");
78✔
1069
      for (const auto& b : temp) {
204✔
1070
        collision_track_config.cell_ids.insert(b);
126✔
1071
      }
1072
    }
78✔
1073
    if (check_for_node(node_ct, "reactions")) {
148✔
1074
      auto temp = get_node_array<std::string>(node_ct, "reactions");
63✔
1075
      for (const auto& b : temp) {
171✔
1076
        int reaction_int = reaction_mt(b);
108✔
1077
        if (reaction_int > 0) {
108!
1078
          collision_track_config.mt_numbers.insert(reaction_int);
108✔
1079
        }
1080
      }
1081
    }
63✔
1082
    if (check_for_node(node_ct, "universe_ids")) {
148✔
1083
      auto temp = get_node_array<int>(node_ct, "universe_ids");
30✔
1084
      for (const auto& b : temp) {
60✔
1085
        collision_track_config.universe_ids.insert(b);
30✔
1086
      }
1087
    }
30✔
1088
    if (check_for_node(node_ct, "material_ids")) {
148✔
1089
      auto temp = get_node_array<int>(node_ct, "material_ids");
30✔
1090
      for (const auto& b : temp) {
75✔
1091
        collision_track_config.material_ids.insert(b);
45✔
1092
      }
1093
    }
30✔
1094
    if (check_for_node(node_ct, "nuclides")) {
148✔
1095
      auto temp = get_node_array<std::string>(node_ct, "nuclides");
30✔
1096
      for (const auto& b : temp) {
120✔
1097
        collision_track_config.nuclides.insert(b);
90✔
1098
      }
1099
    }
30✔
1100
    if (check_for_node(node_ct, "deposited_E_threshold")) {
148✔
1101
      collision_track_config.deposited_energy_threshold =
60✔
1102
        std::stod(get_node_value(node_ct, "deposited_E_threshold"));
60✔
1103
    }
1104
    // Get maximum number of particles to be banked per collision
1105
    if (check_for_node(node_ct, "max_collisions")) {
148!
1106
      collision_track_config.max_collisions =
296✔
1107
        std::stoll(get_node_value(node_ct, "max_collisions"));
296✔
1108
    } else {
1109
      warning("A maximum number of collisions needs to be specified. "
×
1110
              "By default the code sets 'max_collisions' parameter equals to "
1111
              "1000.");
1112
    }
1113
    // Get maximum number of collision_track files to be created
1114
    if (check_for_node(node_ct, "max_collision_track_files")) {
148!
1115
      collision_track_config.max_files =
×
1116
        std::stoll(get_node_value(node_ct, "max_collision_track_files"));
×
1117
    }
1118
    if (check_for_node(node_ct, "mcpl")) {
148✔
1119
      collision_track_config.mcpl_write = get_node_value_bool(node_ct, "mcpl");
22✔
1120
    }
1121
  }
1122

1123
  // If source is not separate and is to be written out in the statepoint
1124
  // file, make sure that the sourcepoint batch numbers are contained in the
1125
  // statepoint list
1126
  if (!source_separate) {
8,503✔
1127
    for (const auto& b : sourcepoint_batch) {
16,960✔
1128
      if (!contains(statepoint_batch, b)) {
17,086!
1129
        fatal_error(
×
1130
          "Sourcepoint batches are not a subset of statepoint batches.");
1131
      }
1132
    }
1133
  }
1134

1135
  // Check if the user has specified to not reduce tallies at the end of every
1136
  // batch
1137
  if (check_for_node(root, "no_reduce")) {
8,503✔
1138
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
30✔
1139
  }
1140

1141
  // Check if the user has specified to use confidence intervals for
1142
  // uncertainties rather than standard deviations
1143
  if (check_for_node(root, "confidence_intervals")) {
8,503✔
1144
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
15✔
1145
  }
1146

1147
  // Check for output options
1148
  if (check_for_node(root, "output")) {
8,503✔
1149
    // Get pointer to output node
1150
    pugi::xml_node node_output = root.child("output");
896✔
1151

1152
    // Check for summary option
1153
    if (check_for_node(node_output, "summary")) {
896✔
1154
      output_summary = get_node_value_bool(node_output, "summary");
870✔
1155
    }
1156

1157
    // Check for ASCII tallies output option
1158
    if (check_for_node(node_output, "tallies")) {
896✔
1159
      output_tallies = get_node_value_bool(node_output, "tallies");
481✔
1160
    }
1161

1162
    // Set output directory if a path has been specified
1163
    if (check_for_node(node_output, "path")) {
896!
1164
      path_output = get_node_value(node_output, "path");
×
1165
      if (!ends_with(path_output, "/")) {
×
1166
        path_output += "/";
896!
1167
      }
1168
    }
1169
  }
1170

1171
  // Resonance scattering parameters
1172
  if (check_for_node(root, "resonance_scattering")) {
8,503✔
1173
    xml_node node_res_scat = root.child("resonance_scattering");
15✔
1174

1175
    // See if resonance scattering is enabled
1176
    if (check_for_node(node_res_scat, "enable")) {
15!
1177
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
15✔
1178
    } else {
1179
      res_scat_on = true;
×
1180
    }
1181

1182
    // Determine what method is used
1183
    if (check_for_node(node_res_scat, "method")) {
15!
1184
      auto temp = get_node_value(node_res_scat, "method", true, true);
15✔
1185
      if (temp == "rvs") {
15!
1186
        res_scat_method = ResScatMethod::rvs;
15✔
1187
      } else if (temp == "dbrc") {
×
1188
        res_scat_method = ResScatMethod::dbrc;
×
1189
      } else {
1190
        fatal_error(
×
1191
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1192
      }
1193
    }
15✔
1194

1195
    // Minimum energy for resonance scattering
1196
    if (check_for_node(node_res_scat, "energy_min")) {
15!
1197
      res_scat_energy_min =
30✔
1198
        std::stod(get_node_value(node_res_scat, "energy_min"));
30✔
1199
    }
1200
    if (res_scat_energy_min < 0.0) {
15!
1201
      fatal_error("Lower resonance scattering energy bound is negative");
×
1202
    }
1203

1204
    // Maximum energy for resonance scattering
1205
    if (check_for_node(node_res_scat, "energy_max")) {
15!
1206
      res_scat_energy_max =
30✔
1207
        std::stod(get_node_value(node_res_scat, "energy_max"));
30✔
1208
    }
1209
    if (res_scat_energy_max < res_scat_energy_min) {
15!
1210
      fatal_error("Upper resonance scattering energy bound is below the "
×
1211
                  "lower resonance scattering energy bound.");
1212
    }
1213

1214
    // Get resonance scattering nuclides
1215
    if (check_for_node(node_res_scat, "nuclides")) {
15!
1216
      res_scat_nuclides =
15✔
1217
        get_node_array<std::string>(node_res_scat, "nuclides");
30✔
1218
    }
1219
  }
1220

1221
  // Get volume calculations
1222
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
8,817✔
1223
    model::volume_calcs.emplace_back(node_vol);
314✔
1224
  }
1225

1226
  // Get temperature settings
1227
  if (check_for_node(root, "temperature_default")) {
8,503✔
1228
    temperature_default =
342✔
1229
      std::stod(get_node_value(root, "temperature_default"));
342✔
1230
  }
1231
  if (check_for_node(root, "temperature_method")) {
8,503✔
1232
    auto temp = get_node_value(root, "temperature_method", true, true);
485✔
1233
    if (temp == "nearest") {
485✔
1234
      temperature_method = TemperatureMethod::NEAREST;
304✔
1235
    } else if (temp == "interpolation") {
181!
1236
      temperature_method = TemperatureMethod::INTERPOLATION;
181✔
1237
    } else {
1238
      fatal_error("Unknown temperature method: " + temp);
×
1239
    }
1240
  }
485✔
1241
  if (check_for_node(root, "temperature_tolerance")) {
8,503✔
1242
    temperature_tolerance =
680✔
1243
      std::stod(get_node_value(root, "temperature_tolerance"));
680✔
1244
  }
1245
  if (check_for_node(root, "temperature_multipole")) {
8,503✔
1246
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
185✔
1247

1248
    // Multipole currently doesn't work with photon transport
1249
    if (temperature_multipole && photon_transport) {
185!
1250
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1251
                  "photon transport.");
1252
    }
1253
  }
1254
  if (check_for_node(root, "temperature_range")) {
8,503✔
1255
    auto range = get_node_array<double>(root, "temperature_range");
170✔
1256
    temperature_range[0] = range.at(0);
170✔
1257
    temperature_range[1] = range.at(1);
170✔
1258
  }
170✔
1259

1260
  // Check for tabular_legendre options
1261
  if (check_for_node(root, "tabular_legendre")) {
8,503✔
1262
    // Get pointer to tabular_legendre node
1263
    xml_node node_tab_leg = root.child("tabular_legendre");
90✔
1264

1265
    // Check for enable option
1266
    if (check_for_node(node_tab_leg, "enable")) {
90!
1267
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
90✔
1268
    }
1269

1270
    // Check for the number of points
1271
    if (check_for_node(node_tab_leg, "num_points")) {
90!
1272
      legendre_to_tabular_points =
×
1273
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
1274
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
1275
        fatal_error(
×
1276
          "The 'num_points' subelement/attribute of the "
1277
          "<tabular_legendre> element must contain a value greater than 1");
1278
      }
1279
    }
1280
  }
1281

1282
  // Check whether create delayed neutrons in fission
1283
  if (check_for_node(root, "create_delayed_neutrons")) {
8,503!
1284
    create_delayed_neutrons =
×
1285
      get_node_value_bool(root, "create_delayed_neutrons");
×
1286
  }
1287

1288
  // Check whether create fission sites
1289
  if (run_mode == RunMode::FIXED_SOURCE) {
8,503✔
1290
    if (check_for_node(root, "create_fission_neutrons")) {
2,919✔
1291
      create_fission_neutrons =
368✔
1292
        get_node_value_bool(root, "create_fission_neutrons");
368✔
1293
    }
1294
  }
1295

1296
  // Check whether to scale fission photon yields
1297
  if (check_for_node(root, "delayed_photon_scaling")) {
8,503!
1298
    delayed_photon_scaling =
×
1299
      get_node_value_bool(root, "delayed_photon_scaling");
×
1300
  }
1301

1302
  // Check whether to use event-based parallelism
1303
  if (check_for_node(root, "event_based")) {
8,503!
1304
    event_based = get_node_value_bool(root, "event_based");
×
1305
  }
1306

1307
  // Check whether material cell offsets should be generated
1308
  if (check_for_node(root, "material_cell_offsets")) {
8,503!
1309
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1310
  }
1311

1312
  // Weight window information
1313
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
8,608✔
1314
    variance_reduction::weight_windows.emplace_back(
105✔
1315
      std::make_unique<WeightWindows>(node_ww));
210✔
1316
  }
1317

1318
  // Enable weight windows by default if one or more are present
1319
  if (variance_reduction::weight_windows.size() > 0)
8,503✔
1320
    settings::weight_windows_on = true;
79✔
1321

1322
  // read weight windows from file
1323
  if (check_for_node(root, "weight_windows_file")) {
8,503!
1324
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1325
  }
1326

1327
  // read settings for weight windows value, this will override
1328
  // the automatic setting even if weight windows are present
1329
  if (check_for_node(root, "weight_windows_on")) {
8,503✔
1330
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
38✔
1331
  }
1332

1333
  if (check_for_node(root, "max_secondaries")) {
8,503!
1334
    settings::max_secondaries =
×
1335
      std::stoi(get_node_value(root, "max_secondaries"));
×
1336
  }
1337

1338
  if (check_for_node(root, "max_history_splits")) {
8,503✔
1339
    settings::max_history_splits =
428✔
1340
      std::stoi(get_node_value(root, "max_history_splits"));
428✔
1341
  }
1342

1343
  if (check_for_node(root, "max_tracks")) {
8,503✔
1344
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
90✔
1345
  }
1346

1347
  // Create weight window generator objects
1348
  if (check_for_node(root, "weight_window_generators")) {
8,503✔
1349
    if (kinetic_simulation) {
79!
NEW
1350
      fatal_error("Weight window generation is currently unsupported in kinetic"
×
1351
                  " random ray solver mode.");
1352
    }
1353
    auto wwgs_node = root.child("weight_window_generators");
79✔
1354
    for (pugi::xml_node node_wwg :
158✔
1355
      wwgs_node.children("weight_windows_generator")) {
158✔
1356
      variance_reduction::weight_windows_generators.emplace_back(
79✔
1357
        std::make_unique<WeightWindowsGenerator>(node_wwg));
158✔
1358
    }
1359
    // if any of the weight windows are intended to be generated otf, make
1360
    // sure they're applied
1361
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
79!
1362
      if (wwg->on_the_fly_) {
79!
1363
        settings::weight_windows_on = true;
79✔
1364
        break;
79✔
1365
      }
1366
    }
1367
  }
1368

1369
  // Set up weight window checkpoints
1370
  if (check_for_node(root, "weight_window_checkpoints")) {
8,503✔
1371
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
32✔
1372
    if (check_for_node(ww_checkpoints, "collision")) {
32!
1373
      weight_window_checkpoint_collision =
32✔
1374
        get_node_value_bool(ww_checkpoints, "collision");
32✔
1375
    }
1376
    if (check_for_node(ww_checkpoints, "surface")) {
32!
1377
      weight_window_checkpoint_surface =
32✔
1378
        get_node_value_bool(ww_checkpoints, "surface");
32✔
1379
    }
1380
  }
1381

1382
  if (weight_windows_on) {
8,503✔
1383
    if (!weight_window_checkpoint_surface &&
158✔
1384
        !weight_window_checkpoint_collision)
126!
1385
      fatal_error(
×
1386
        "Weight Windows are enabled but there are no valid checkpoints.");
1387
  }
1388

1389
  if (check_for_node(root, "use_decay_photons")) {
8,503✔
1390
    settings::use_decay_photons =
11✔
1391
      get_node_value_bool(root, "use_decay_photons");
11✔
1392
  }
1393
}
8,503✔
1394

1395
void free_memory_settings()
8,654✔
1396
{
1397
  settings::statepoint_batch.clear();
8,654✔
1398
  settings::sourcepoint_batch.clear();
8,654✔
1399
  settings::source_write_surf_id.clear();
8,654✔
1400
  settings::res_scat_nuclides.clear();
8,654✔
1401
}
8,654✔
1402

1403
//==============================================================================
1404
// C API functions
1405
//==============================================================================
1406

1407
extern "C" int openmc_set_n_batches(
44✔
1408
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1409
{
1410
  if (settings::n_inactive >= n_batches) {
44✔
1411
    set_errmsg("Number of active batches must be greater than zero.");
11✔
1412
    return OPENMC_E_INVALID_ARGUMENT;
11✔
1413
  }
1414

1415
  if (!settings::trigger_on) {
33✔
1416
    // Set n_batches and n_max_batches to same value
1417
    settings::n_batches = n_batches;
11✔
1418
    settings::n_max_batches = n_batches;
11✔
1419
  } else {
1420
    // Set n_batches and n_max_batches based on value of set_max_batches
1421
    if (set_max_batches) {
22✔
1422
      settings::n_max_batches = n_batches;
11✔
1423
    } else {
1424
      settings::n_batches = n_batches;
11✔
1425
    }
1426
  }
1427

1428
  // Update size of k_generation and entropy
1429
  int m = settings::n_max_batches * settings::gen_per_batch;
33✔
1430
  simulation::k_generation.reserve(m);
33✔
1431
  simulation::entropy.reserve(m);
33✔
1432

1433
  // Add value of n_batches to statepoint_batch
1434
  if (add_statepoint_batch &&
33✔
1435
      !(contains(settings::statepoint_batch, n_batches)))
22!
1436
    settings::statepoint_batch.insert(n_batches);
22✔
1437

1438
  return 0;
1439
}
1440

1441
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,530✔
1442
{
1443
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,530✔
1444

1445
  return 0;
2,530✔
1446
}
1447

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