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

openmc-dev / openmc / 23560024828

25 Mar 2026 07:28PM UTC coverage: 80.336% (-1.0%) from 81.326%
23560024828

Pull #3702

github

web-flow
Merge 0f768b2d1 into 6cd39073b
Pull Request #3702: Random Ray Kinetic Simulation Mode

17625 of 25263 branches covered (69.77%)

Branch coverage included in aggregate %.

926 of 1957 new or added lines in 21 files covered. (47.32%)

461 existing lines in 28 files now uncovered.

57995 of 68867 relevant lines covered (84.21%)

50654337.8 hits per line

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

75.81
/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)
6,811✔
168
{
169
  using namespace settings;
6,811✔
170
  using namespace pugi;
6,811✔
171

172
  // Check number of particles
173
  if (!check_for_node(node_base, "particles")) {
6,811!
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) {
6,811!
179
    n_particles = std::stoll(get_node_value(node_base, "particles"));
6,811✔
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")) {
6,811!
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")) {
6,811!
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")) {
6,811!
196
    n_batches = std::stoi(get_node_value(node_base, "batches"));
6,811✔
197
  }
198
  if (!trigger_on)
6,811✔
199
    n_max_batches = n_batches;
6,686✔
200

201
  // Get max number of lost particles
202
  if (check_for_node(node_base, "max_lost_particles")) {
6,811✔
203
    max_lost_particles =
78✔
204
      std::stoi(get_node_value(node_base, "max_lost_particles"));
39✔
205
  }
206

207
  // Get relative number of lost particles
208
  if (check_for_node(node_base, "rel_max_lost_particles")) {
6,811!
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")) {
6,811✔
215
    max_write_lost_particles =
26✔
216
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
13✔
217
  }
218

219
  // Get number of inactive batches
220
  if (run_mode == RunMode::EIGENVALUE ||
6,811✔
221
      solver_type == SolverType::RANDOM_RAY) {
2,604✔
222
    if (check_for_node(node_base, "inactive")) {
4,558✔
223
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,367✔
224
    }
225
    if (check_for_node(node_base, "generations_per_batch")) {
4,558✔
226
      gen_per_batch =
26✔
227
        std::stoi(get_node_value(node_base, "generations_per_batch"));
13✔
228
    }
229

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

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

239
      if (check_for_node(node_keff_trigger, "type")) {
88!
240
        auto temp = get_node_value(node_keff_trigger, "type", true, true);
88✔
241
        if (temp == "std_dev") {
88!
242
          keff_trigger.metric = TriggerMetric::standard_deviation;
88✔
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")) {
88!
255
        keff_trigger.threshold =
176✔
256
          std::stod(get_node_value(node_keff_trigger, "threshold"));
176✔
257
        if (keff_trigger.threshold <= 0) {
88!
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")) {
6,811✔
268
    kinetic_simulation = get_node_value_bool(node_base, "kinetic_simulation");
156✔
269
    if (solver_type != SolverType::RANDOM_RAY) {
156!
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) {
156!
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) {
6,811✔
283
    xml_node ts_node = node_base.child("timestep_parameters");
156✔
284
    if (check_for_node(ts_node, "n_timesteps")) {
156!
285
      n_timesteps = std::stoi(get_node_value(ts_node, "n_timesteps"));
312✔
286
    } else {
NEW
287
      fatal_error("Specify number of timesteps in settings XML");
×
288
    }
289
    if (check_for_node(ts_node, "timestep_units")) {
156!
290
      std::string units = get_node_value(ts_node, "timestep_units");
156✔
291
      if (check_for_node(ts_node, "dt")) {
156!
292
        dt = std::stod(get_node_value(ts_node, "dt"));
312✔
293
        double factor_to_seconds;
156✔
294
        if (units == "ms") {
156!
295
          factor_to_seconds = 1e-3;
296
        } else if (units == "s") {
156!
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;
156✔
304
      } else {
NEW
305
        fatal_error("Specify dt in settings XML");
×
306
      }
307
    } else {
156✔
NEW
308
      fatal_error("Specify timestep units in settings XML");
×
309
    }
310
  }
311

312
  // Random ray variables
313
  if (solver_type == SolverType::RANDOM_RAY) {
6,811✔
314
    xml_node random_ray_node = node_base.child("random_ray");
816✔
315
    if (check_for_node(random_ray_node, "distance_active")) {
816!
316
      RandomRay::distance_active_ =
1,632✔
317
        std::stod(get_node_value(random_ray_node, "distance_active"));
1,632✔
318
      if (RandomRay::distance_active_ <= 0.0) {
816!
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")) {
816!
325
      RandomRay::distance_inactive_ =
1,632✔
326
        std::stod(get_node_value(random_ray_node, "distance_inactive"));
1,632✔
327
      if (RandomRay::distance_inactive_ < 0) {
816!
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")) {
816!
335
      xml_node source_node = random_ray_node.child("source");
816✔
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,632✔
339
    } else {
340
      fatal_error("Specify random ray source in settings XML");
×
341
    }
342
    if (check_for_node(random_ray_node, "volume_estimator")) {
816✔
343
      std::string temp_str =
104✔
344
        get_node_value(random_ray_node, "volume_estimator", true, true);
104✔
345
      if (temp_str == "simulation_averaged") {
104✔
346
        FlatSourceDomain::volume_estimator_ =
26✔
347
          RandomRayVolumeEstimator::SIMULATION_AVERAGED;
348
      } else if (temp_str == "naive") {
78✔
349
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::NAIVE;
52✔
350
      } else if (temp_str == "hybrid") {
26!
351
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::HYBRID;
26✔
352
      } else {
353
        fatal_error("Unrecognized volume estimator: " + temp_str);
×
354
      }
355
    }
104✔
356
    if (check_for_node(random_ray_node, "source_shape")) {
816✔
357
      std::string temp_str =
390✔
358
        get_node_value(random_ray_node, "source_shape", true, true);
390✔
359
      if (temp_str == "flat") {
390✔
360
        RandomRay::source_shape_ = RandomRaySourceShape::FLAT;
65✔
361
      } else if (temp_str == "linear") {
325✔
362
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR;
286✔
363
        if (settings::kinetic_simulation) {
286!
NEW
364
          fatal_error(
×
365
            "linear source shapes unimplemented for kinetic simulations.");
366
        }
367
      } else if (temp_str == "linear_xy") {
39!
368
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR_XY;
39✔
369
        if (settings::kinetic_simulation) {
39!
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
    }
390✔
377
    if (check_for_node(random_ray_node, "volume_normalized_flux_tallies")) {
816✔
378
      FlatSourceDomain::volume_normalized_flux_tallies_ =
504✔
379
        get_node_value_bool(random_ray_node, "volume_normalized_flux_tallies");
504✔
380
    }
381
    if (check_for_node(random_ray_node, "adjoint")) {
816✔
382
      FlatSourceDomain::adjoint_ =
26✔
383
        get_node_value_bool(random_ray_node, "adjoint");
26✔
384
    }
385
    if (check_for_node(random_ray_node, "sample_method")) {
816✔
386
      std::string temp_str =
26✔
387
        get_node_value(random_ray_node, "sample_method", true, true);
26✔
388
      if (temp_str == "prng") {
26!
UNCOV
389
        RandomRay::sample_method_ = RandomRaySampleMethod::PRNG;
×
390
      } else if (temp_str == "halton") {
26✔
391
        RandomRay::sample_method_ = RandomRaySampleMethod::HALTON;
13✔
392
      } else if (temp_str == "s2") {
13!
393
        RandomRay::sample_method_ = RandomRaySampleMethod::S2;
13✔
394
      } else {
UNCOV
395
        fatal_error("Unrecognized sample method: " + temp_str);
×
396
      }
397
    }
26✔
398
    if (check_for_node(random_ray_node, "source_region_meshes")) {
816✔
399
      pugi::xml_node node_source_region_meshes =
403✔
400
        random_ray_node.child("source_region_meshes");
403✔
401
      for (pugi::xml_node node_mesh :
858✔
402
        node_source_region_meshes.children("mesh")) {
858✔
403
        int mesh_id = std::stoi(node_mesh.attribute("id").value());
910✔
404
        for (pugi::xml_node node_domain : node_mesh.children("domain")) {
910✔
405
          int domain_id = std::stoi(node_domain.attribute("id").value());
910✔
406
          std::string domain_type = node_domain.attribute("type").value();
455✔
407
          Source::DomainType type;
455✔
408
          if (domain_type == "material") {
455✔
409
            type = Source::DomainType::MATERIAL;
26✔
410
          } else if (domain_type == "cell") {
429✔
411
            type = Source::DomainType::CELL;
26✔
412
          } else if (domain_type == "universe") {
403!
413
            type = Source::DomainType::UNIVERSE;
403✔
414
          } else {
UNCOV
415
            throw std::runtime_error("Unknown domain type: " + domain_type);
×
416
          }
417
          FlatSourceDomain::mesh_domain_map_[mesh_id].emplace_back(
455✔
418
            type, domain_id);
419
        }
455✔
420
      }
421
    }
422
    if (check_for_node(random_ray_node, "diagonal_stabilization_rho")) {
816✔
423
      FlatSourceDomain::diagonal_stabilization_rho_ = std::stod(
39✔
424
        get_node_value(random_ray_node, "diagonal_stabilization_rho"));
39✔
425
      if (FlatSourceDomain::diagonal_stabilization_rho_ < 0.0 ||
39!
426
          FlatSourceDomain::diagonal_stabilization_rho_ > 1.0) {
UNCOV
427
        fatal_error("Random ray diagonal stabilization rho factor must be "
×
428
                    "between 0 and 1");
429
      }
430
    }
431
    if (kinetic_simulation) {
816✔
432
      if (check_for_node(random_ray_node, "bd_order")) {
156✔
433
        static int n = std::stod(get_node_value(random_ray_node, "bd_order"));
104!
434
        if (n < 1 || n > 6) {
52!
NEW
435
          fatal_error("Specified BD order of " + std::to_string(n) +
×
436
                      ". BD order must be between 1 and 6");
437
        } else {
438
          RandomRay::bd_order_ = n;
52✔
439
        }
440
      }
441
      if (check_for_node(random_ray_node, "time_derivative_method")) {
156✔
442
        std::string temp_str =
104✔
443
          get_node_value(random_ray_node, "time_derivative_method", true, true);
104✔
444
        if (temp_str == "isotropic") {
104✔
445
          RandomRay::time_method_ = RandomRayTimeMethod::ISOTROPIC;
52✔
446
        } else if (temp_str == "propagation") {
52!
447
          RandomRay::time_method_ = RandomRayTimeMethod::PROPAGATION;
52✔
448
        } else {
NEW
449
          fatal_error("Unrecognized time derivative method: " + temp_str);
×
450
        }
451
      }
104✔
452
    }
453
  }
454
}
6,811✔
455

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

475
  // Parse settings.xml file
476
  xml_document doc;
1,164✔
477
  auto result = doc.load_file(filename.c_str());
1,164✔
478
  if (!result) {
1,164!
UNCOV
479
    fatal_error("Error processing settings.xml file.");
×
480
  }
481

482
  // Get root element
483
  xml_node root = doc.document_element();
1,164✔
484

485
  // Verbosity
486
  if (check_for_node(root, "verbosity") && verbosity == -1) {
1,164!
487
    verbosity = std::stoi(get_node_value(root, "verbosity"));
326✔
488
  } else if (verbosity == -1) {
1,001!
489
    verbosity = 7;
1,001✔
490
  }
491

492
  // To this point, we haven't displayed any output since we didn't know what
493
  // the verbosity is. Now that we checked for it, show the title if necessary
494
  if (mpi::master) {
1,164✔
495
    if (verbosity >= 2)
1,029✔
496
      title();
872✔
497
  }
498

499
  write_message("Reading settings XML file...", 5);
1,164✔
500

501
  read_settings_xml(root);
1,164✔
502
}
1,176✔
503

504
void read_settings_xml(pugi::xml_node root)
7,539✔
505
{
506
  using namespace settings;
7,539✔
507
  using namespace pugi;
7,539✔
508

509
  // Find if a multi-group or continuous-energy simulation is desired
510
  if (check_for_node(root, "energy_mode")) {
7,539✔
511
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
1,272✔
512
    if (temp_str == "mg" || temp_str == "multi-group") {
2,544!
513
      run_CE = false;
1,272✔
UNCOV
514
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
UNCOV
515
      run_CE = true;
×
516
    }
517
  }
1,272✔
518

519
  // Check for user meshes and allocate
520
  read_meshes(root);
7,539✔
521

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

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

546
  // Check for a trigger node and get trigger information
547
  if (check_for_node(root, "trigger")) {
7,539✔
548
    xml_node node_trigger = root.child("trigger");
138✔
549

550
    // Check if trigger(s) are to be turned on
551
    trigger_on = get_node_value_bool(node_trigger, "active");
138✔
552

553
    if (trigger_on) {
138✔
554
      if (check_for_node(node_trigger, "max_batches")) {
125!
555
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
250✔
556
      } else {
UNCOV
557
        fatal_error("<max_batches> must be specified with triggers");
×
558
      }
559

560
      // Get the batch interval to check triggers
561
      if (!check_for_node(node_trigger, "batch_interval")) {
125✔
562
        trigger_predict = true;
13✔
563
      } else {
564
        trigger_batch_interval =
224✔
565
          std::stoi(get_node_value(node_trigger, "batch_interval"));
224✔
566
        if (trigger_batch_interval <= 0) {
112!
UNCOV
567
          fatal_error("Trigger batch interval must be greater than zero");
×
568
        }
569
      }
570
    }
571
  }
572

573
  // Check run mode if it hasn't been set from the command line
574
  xml_node node_mode;
7,539✔
575
  if (run_mode == RunMode::UNSET) {
7,539✔
576
    if (check_for_node(root, "run_mode")) {
6,837✔
577
      std::string temp_str = get_node_value(root, "run_mode", true, true);
6,811✔
578
      if (temp_str == "eigenvalue") {
6,811✔
579
        run_mode = RunMode::EIGENVALUE;
4,181✔
580
      } else if (temp_str == "fixed source") {
2,630✔
581
        run_mode = RunMode::FIXED_SOURCE;
2,604✔
582
      } else if (temp_str == "plot") {
26!
UNCOV
583
        run_mode = RunMode::PLOTTING;
×
584
      } else if (temp_str == "particle restart") {
26!
UNCOV
585
        run_mode = RunMode::PARTICLE;
×
586
      } else if (temp_str == "volume") {
26!
587
        run_mode = RunMode::VOLUME;
26✔
588
      } else {
UNCOV
589
        fatal_error("Unrecognized run mode: " + temp_str);
×
590
      }
591

592
      // Assume XML specifies <particles>, <batches>, etc. directly
593
      node_mode = root;
6,811✔
594
    } else {
6,811✔
595
      warning("<run_mode> should be specified.");
26✔
596

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

612
  // Check solver type
613
  if (check_for_node(root, "random_ray")) {
7,539✔
614
    solver_type = SolverType::RANDOM_RAY;
816✔
615
    if (run_CE)
816!
UNCOV
616
      fatal_error("multi-group energy mode must be specified in settings XML "
×
617
                  "when using the random ray solver.");
618
  }
619

620
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
7,539✔
621
    // Read run parameters
622
    get_run_parameters(node_mode);
6,811✔
623

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

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

653
  // Copy plotting random number seed if specified
654
  if (check_for_node(root, "plot_seed")) {
7,531!
UNCOV
655
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
UNCOV
656
    model::plotter_seed = seed;
×
657
  }
658

659
  // Copy random number seed if specified
660
  if (check_for_node(root, "seed")) {
7,531✔
661
    auto seed = std::stoll(get_node_value(root, "seed"));
1,012✔
662
    openmc_set_seed(seed);
506✔
663
  }
664

665
  // Copy random number stride if specified
666
  if (check_for_node(root, "stride")) {
7,531✔
667
    auto stride = std::stoull(get_node_value(root, "stride"));
26✔
668
    openmc_set_stride(stride);
13✔
669
  }
670

671
  // Check for electron treatment
672
  if (check_for_node(root, "electron_treatment")) {
7,531✔
673
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
72✔
674
    if (temp_str == "led") {
72✔
675
      electron_treatment = ElectronTreatment::LED;
23✔
676
    } else if (temp_str == "ttb") {
49!
677
      electron_treatment = ElectronTreatment::TTB;
49✔
678
    } else {
UNCOV
679
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
680
    }
681
  }
72✔
682

683
  // Check for photon transport
684
  if (check_for_node(root, "photon_transport")) {
7,531✔
685
    photon_transport = get_node_value_bool(root, "photon_transport");
180✔
686

687
    if (!run_CE && photon_transport) {
180!
UNCOV
688
      fatal_error("Photon transport is not currently supported in "
×
689
                  "multigroup mode");
690
    }
691
  }
692

693
  // Check for atomic relaxation
694
  if (check_for_node(root, "atomic_relaxation")) {
7,531✔
695
    atomic_relaxation = get_node_value_bool(root, "atomic_relaxation");
13✔
696
  }
697

698
  // Number of bins for logarithmic grid
699
  if (check_for_node(root, "log_grid_bins")) {
7,531✔
700
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
26✔
701
    if (n_log_bins < 1) {
13!
UNCOV
702
      fatal_error("Number of bins for logarithmic grid must be greater "
×
703
                  "than zero.");
704
    }
705
  }
706

707
  // Number of OpenMP threads
708
  if (check_for_node(root, "threads")) {
7,531!
UNCOV
709
    if (mpi::master)
×
UNCOV
710
      warning("The <threads> element has been deprecated. Use "
×
711
              "the OMP_NUM_THREADS environment variable to set the number of "
712
              "threads.");
713
  }
714

715
  // ==========================================================================
716
  // EXTERNAL SOURCE
717

718
  // Get point to list of <source> elements and make sure there is at least one
719
  for (pugi::xml_node node : root.children("source")) {
14,653✔
720
    model::external_sources.push_back(Source::create(node));
14,252✔
721
  }
722

723
  // Check if the user has specified to read surface source
724
  if (check_for_node(root, "surf_source_read")) {
7,523✔
725
    surf_source_read = true;
26✔
726
    // Get surface source read node
727
    xml_node node_ssr = root.child("surf_source_read");
26✔
728

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

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

749
  // Build probability mass function for sampling external sources
750
  vector<double> source_strengths;
7,523✔
751
  for (auto& s : model::external_sources) {
16,508✔
752
    source_strengths.push_back(s->strength());
8,985✔
753
  }
754
  model::external_sources_probability.assign(source_strengths);
7,523✔
755

756
  // Check if we want to write out source
757
  if (check_for_node(root, "write_initial_source")) {
7,523!
UNCOV
758
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
759
  }
760

761
  // Get relative number of lost particles
762
  if (check_for_node(root, "source_rejection_fraction")) {
7,523✔
763
    source_rejection_fraction =
14✔
764
      std::stod(get_node_value(root, "source_rejection_fraction"));
14!
765
  }
766

767
  if (check_for_node(root, "free_gas_threshold")) {
7,523!
UNCOV
768
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
769
  }
770

771
  // Surface grazing
772
  if (check_for_node(root, "surface_grazing_cutoff"))
7,523!
UNCOV
773
    surface_grazing_cutoff =
×
UNCOV
774
      std::stod(get_node_value(root, "surface_grazing_cutoff"));
×
775
  if (check_for_node(root, "surface_grazing_ratio"))
7,523!
776
    surface_grazing_ratio =
×
777
      std::stod(get_node_value(root, "surface_grazing_ratio"));
×
778

779
  // Survival biasing
780
  if (check_for_node(root, "survival_biasing")) {
7,523✔
781
    survival_biasing = get_node_value_bool(root, "survival_biasing");
169✔
782
  }
783

784
  // Probability tables
785
  if (check_for_node(root, "ptables")) {
7,523✔
786
    urr_ptables_on = get_node_value_bool(root, "ptables");
13✔
787
  }
788

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

836
  // read properties from file
837
  if (check_for_node(root, "properties_file")) {
7,523✔
838
    properties_file = get_node_value(root, "properties_file");
10✔
839
    if (!file_exists(properties_file)) {
10!
UNCOV
840
      fatal_error(fmt::format("File '{}' does not exist.", properties_file));
×
841
    }
842
  }
843

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

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

867
    // Reshape into track_identifiers
868
    int n_tracks = temp.size() / 3;
39✔
869
    for (int i = 0; i < n_tracks; ++i) {
156✔
870
      track_identifiers.push_back(
117✔
871
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
117✔
872
    }
873
  }
39✔
874

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

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

896
      // Turn on Shannon entropy calculation
897
      entropy_on = true;
303✔
898

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

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

921
    // Turn on uniform fission source weighting
922
    ufs_on = true;
13✔
923

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

931
  // Check if the user has specified to write state points
932
  if (check_for_node(root, "state_point")) {
7,523✔
933

934
    // Get pointer to state_point node
935
    auto node_sp = root.child("state_point");
141✔
936

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

954
  // Check if the user has specified to write source points
955
  if (check_for_node(root, "source_point")) {
7,523✔
956
    // Get source_point node
957
    xml_node node_sp = root.child("source_point");
88✔
958

959
    // Determine batches at which to store source points
960
    if (check_for_node(node_sp, "batches")) {
88✔
961
      // User gave specific batches to write source points
962
      auto temp = get_node_array<int>(node_sp, "batches");
39✔
963
      for (const auto& b : temp) {
104✔
964
        sourcepoint_batch.insert(b);
65✔
965
      }
966
    } else {
39✔
967
      // If neither were specified, write source points with state points
968
      sourcepoint_batch = statepoint_batch;
49!
969
    }
970

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

992
  // Check is the user specified to convert strength to statistical weight
993
  if (check_for_node(root, "uniform_source_sampling")) {
7,523✔
994
    uniform_source_sampling =
50✔
995
      get_node_value_bool(root, "uniform_source_sampling");
50✔
996
  }
997

998
  // Check if the user has specified to write surface source
999
  if (check_for_node(root, "surf_source_write")) {
7,523✔
1000
    surf_source_write = true;
361✔
1001
    // Get surface source write node
1002
    xml_node node_ssw = root.child("surf_source_write");
361✔
1003

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

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

1023
    // Get maximum number of surface source files to be created
1024
    if (check_for_node(node_ssw, "max_source_files")) {
353✔
1025
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
60✔
1026
    } else {
1027
      ssw_max_files = 1;
323✔
1028
    }
1029

1030
    if (check_for_node(node_ssw, "mcpl")) {
353✔
1031
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
10✔
1032
    }
1033
    // Get cell information
1034
    if (check_for_node(node_ssw, "cell")) {
353✔
1035
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
180✔
1036
      ssw_cell_type = SSWCellType::Both;
90✔
1037
    }
1038
    if (check_for_node(node_ssw, "cellfrom")) {
353✔
1039
      if (ssw_cell_id != C_NONE) {
79✔
1040
        fatal_error(
16✔
1041
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
1042
      }
1043
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
126✔
1044
      ssw_cell_type = SSWCellType::From;
63✔
1045
    }
1046
    if (check_for_node(node_ssw, "cellto")) {
337✔
1047
      if (ssw_cell_id != C_NONE) {
62✔
1048
        fatal_error(
16✔
1049
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
1050
      }
1051
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
92✔
1052
      ssw_cell_type = SSWCellType::To;
46✔
1053
    }
1054
  }
1055

1056
  // Check if the user has specified to write specific collisions
1057
  if (check_for_node(root, "collision_track")) {
7,483✔
1058
    settings::collision_track = true;
130✔
1059
    // Get collision track node
1060
    xml_node node_ct = root.child("collision_track");
130✔
1061
    collision_track_config = CollisionTrackConfig {};
130✔
1062

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

1120
  // If source is not separate and is to be written out in the statepoint
1121
  // file, make sure that the sourcepoint batch numbers are contained in the
1122
  // statepoint list
1123
  if (!source_separate) {
7,483✔
1124
    for (const auto& b : sourcepoint_batch) {
14,928✔
1125
      if (!contains(statepoint_batch, b)) {
15,040!
UNCOV
1126
        fatal_error(
×
1127
          "Sourcepoint batches are not a subset of statepoint batches.");
1128
      }
1129
    }
1130
  }
1131

1132
  // Check if the user has specified to not reduce tallies at the end of every
1133
  // batch
1134
  if (check_for_node(root, "no_reduce")) {
7,483✔
1135
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
26✔
1136
  }
1137

1138
  // Check if the user has specified to use confidence intervals for
1139
  // uncertainties rather than standard deviations
1140
  if (check_for_node(root, "confidence_intervals")) {
7,483✔
1141
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
13✔
1142
  }
1143

1144
  // Check for output options
1145
  if (check_for_node(root, "output")) {
7,483✔
1146
    // Get pointer to output node
1147
    pugi::xml_node node_output = root.child("output");
797✔
1148

1149
    // Check for summary option
1150
    if (check_for_node(node_output, "summary")) {
797✔
1151
      output_summary = get_node_value_bool(node_output, "summary");
774✔
1152
    }
1153

1154
    // Check for ASCII tallies output option
1155
    if (check_for_node(node_output, "tallies")) {
797✔
1156
      output_tallies = get_node_value_bool(node_output, "tallies");
433✔
1157
    }
1158

1159
    // Set output directory if a path has been specified
1160
    if (check_for_node(node_output, "path")) {
797!
UNCOV
1161
      path_output = get_node_value(node_output, "path");
×
UNCOV
1162
      if (!ends_with(path_output, "/")) {
×
1163
        path_output += "/";
797!
1164
      }
1165
    }
1166
  }
1167

1168
  // Resonance scattering parameters
1169
  if (check_for_node(root, "resonance_scattering")) {
7,483✔
1170
    xml_node node_res_scat = root.child("resonance_scattering");
13✔
1171

1172
    // See if resonance scattering is enabled
1173
    if (check_for_node(node_res_scat, "enable")) {
13!
1174
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
13✔
1175
    } else {
UNCOV
1176
      res_scat_on = true;
×
1177
    }
1178

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

1192
    // Minimum energy for resonance scattering
1193
    if (check_for_node(node_res_scat, "energy_min")) {
13!
1194
      res_scat_energy_min =
26✔
1195
        std::stod(get_node_value(node_res_scat, "energy_min"));
26✔
1196
    }
1197
    if (res_scat_energy_min < 0.0) {
13!
UNCOV
1198
      fatal_error("Lower resonance scattering energy bound is negative");
×
1199
    }
1200

1201
    // Maximum energy for resonance scattering
1202
    if (check_for_node(node_res_scat, "energy_max")) {
13!
1203
      res_scat_energy_max =
26✔
1204
        std::stod(get_node_value(node_res_scat, "energy_max"));
26✔
1205
    }
1206
    if (res_scat_energy_max < res_scat_energy_min) {
13!
UNCOV
1207
      fatal_error("Upper resonance scattering energy bound is below the "
×
1208
                  "lower resonance scattering energy bound.");
1209
    }
1210

1211
    // Get resonance scattering nuclides
1212
    if (check_for_node(node_res_scat, "nuclides")) {
13!
1213
      res_scat_nuclides =
13✔
1214
        get_node_array<std::string>(node_res_scat, "nuclides");
26✔
1215
    }
1216
  }
1217

1218
  // Get volume calculations
1219
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
7,743✔
1220
    model::volume_calcs.emplace_back(node_vol);
260✔
1221
  }
1222

1223
  // Get temperature settings
1224
  if (check_for_node(root, "temperature_default")) {
7,483✔
1225
    temperature_default =
306✔
1226
      std::stod(get_node_value(root, "temperature_default"));
306✔
1227
  }
1228
  if (check_for_node(root, "temperature_method")) {
7,483✔
1229
    auto temp = get_node_value(root, "temperature_method", true, true);
432✔
1230
    if (temp == "nearest") {
432✔
1231
      temperature_method = TemperatureMethod::NEAREST;
270✔
1232
    } else if (temp == "interpolation") {
162!
1233
      temperature_method = TemperatureMethod::INTERPOLATION;
162✔
1234
    } else {
UNCOV
1235
      fatal_error("Unknown temperature method: " + temp);
×
1236
    }
1237
  }
432✔
1238
  if (check_for_node(root, "temperature_tolerance")) {
7,483✔
1239
    temperature_tolerance =
610✔
1240
      std::stod(get_node_value(root, "temperature_tolerance"));
610✔
1241
  }
1242
  if (check_for_node(root, "temperature_multipole")) {
7,483✔
1243
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
165✔
1244

1245
    // Multipole currently doesn't work with photon transport
1246
    if (temperature_multipole && photon_transport) {
165!
UNCOV
1247
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1248
                  "photon transport.");
1249
    }
1250
  }
1251
  if (check_for_node(root, "temperature_range")) {
7,483✔
1252
    auto range = get_node_array<double>(root, "temperature_range");
152✔
1253
    temperature_range[0] = range.at(0);
152✔
1254
    temperature_range[1] = range.at(1);
152✔
1255
  }
152✔
1256

1257
  // Check for tabular_legendre options
1258
  if (check_for_node(root, "tabular_legendre")) {
7,483✔
1259
    // Get pointer to tabular_legendre node
1260
    xml_node node_tab_leg = root.child("tabular_legendre");
78✔
1261

1262
    // Check for enable option
1263
    if (check_for_node(node_tab_leg, "enable")) {
78!
1264
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
78✔
1265
    }
1266

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

1279
  // Check whether create delayed neutrons in fission
1280
  if (check_for_node(root, "create_delayed_neutrons")) {
7,483!
UNCOV
1281
    create_delayed_neutrons =
×
UNCOV
1282
      get_node_value_bool(root, "create_delayed_neutrons");
×
1283
  }
1284

1285
  // Check whether create fission sites
1286
  if (run_mode == RunMode::FIXED_SOURCE) {
7,483✔
1287
    if (check_for_node(root, "create_fission_neutrons")) {
2,564✔
1288
      create_fission_neutrons =
333✔
1289
        get_node_value_bool(root, "create_fission_neutrons");
333✔
1290
    }
1291
  }
1292

1293
  // Check whether to scale fission photon yields
1294
  if (check_for_node(root, "delayed_photon_scaling")) {
7,483!
UNCOV
1295
    delayed_photon_scaling =
×
UNCOV
1296
      get_node_value_bool(root, "delayed_photon_scaling");
×
1297
  }
1298

1299
  // Check whether to use event-based parallelism
1300
  if (check_for_node(root, "event_based")) {
7,483!
UNCOV
1301
    event_based = get_node_value_bool(root, "event_based");
×
1302
  }
1303

1304
  // Check whether material cell offsets should be generated
1305
  if (check_for_node(root, "material_cell_offsets")) {
7,483!
UNCOV
1306
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1307
  }
1308

1309
  // Weight window information
1310
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
7,574✔
1311
    variance_reduction::weight_windows.emplace_back(
91✔
1312
      std::make_unique<WeightWindows>(node_ww));
182✔
1313
  }
1314

1315
  // Enable weight windows by default if one or more are present
1316
  if (variance_reduction::weight_windows.size() > 0)
7,483✔
1317
    settings::weight_windows_on = true;
68✔
1318

1319
  // read weight windows from file
1320
  if (check_for_node(root, "weight_windows_file")) {
7,483!
UNCOV
1321
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1322
  }
1323

1324
  // read settings for weight windows value, this will override
1325
  // the automatic setting even if weight windows are present
1326
  if (check_for_node(root, "weight_windows_on")) {
7,483✔
1327
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
32✔
1328
  }
1329

1330
  if (check_for_node(root, "max_secondaries")) {
7,483!
UNCOV
1331
    settings::max_secondaries =
×
UNCOV
1332
      std::stoi(get_node_value(root, "max_secondaries"));
×
1333
  }
1334

1335
  if (check_for_node(root, "max_history_splits")) {
7,483✔
1336
    settings::max_history_splits =
386✔
1337
      std::stoi(get_node_value(root, "max_history_splits"));
386✔
1338
  }
1339

1340
  if (check_for_node(root, "max_tracks")) {
7,483✔
1341
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
78✔
1342
  }
1343

1344
  // Create weight window generator objects
1345
  if (check_for_node(root, "weight_window_generators")) {
7,483✔
1346
    auto wwgs_node = root.child("weight_window_generators");
69✔
1347
    for (pugi::xml_node node_wwg :
138✔
1348
      wwgs_node.children("weight_windows_generator")) {
138✔
1349
      variance_reduction::weight_windows_generators.emplace_back(
69✔
1350
        std::make_unique<WeightWindowsGenerator>(node_wwg));
138✔
1351
    }
1352
    // if any of the weight windows are intended to be generated otf, make
1353
    // sure they're applied
1354
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
69!
1355
      if (wwg->on_the_fly_) {
69!
1356
        settings::weight_windows_on = true;
69✔
1357
        break;
69✔
1358
      }
1359
    }
1360
  }
1361

1362
  // Set up weight window checkpoints
1363
  if (check_for_node(root, "weight_window_checkpoints")) {
7,483✔
1364
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
26✔
1365
    if (check_for_node(ww_checkpoints, "collision")) {
26!
1366
      weight_window_checkpoint_collision =
26✔
1367
        get_node_value_bool(ww_checkpoints, "collision");
26✔
1368
    }
1369
    if (check_for_node(ww_checkpoints, "surface")) {
26!
1370
      weight_window_checkpoint_surface =
26✔
1371
        get_node_value_bool(ww_checkpoints, "surface");
26✔
1372
    }
1373
  }
1374

1375
  if (weight_windows_on) {
7,483✔
1376
    if (!weight_window_checkpoint_surface &&
137✔
1377
        !weight_window_checkpoint_collision)
111!
UNCOV
1378
      fatal_error(
×
1379
        "Weight Windows are enabled but there are no valid checkpoints.");
1380
  }
1381

1382
  if (check_for_node(root, "use_decay_photons")) {
7,483✔
1383
    settings::use_decay_photons =
10✔
1384
      get_node_value_bool(root, "use_decay_photons");
10✔
1385
  }
1386
}
7,483✔
1387

1388
void free_memory_settings()
7,613✔
1389
{
1390
  settings::statepoint_batch.clear();
7,613✔
1391
  settings::sourcepoint_batch.clear();
7,613✔
1392
  settings::source_write_surf_id.clear();
7,613✔
1393
  settings::res_scat_nuclides.clear();
7,613✔
1394
}
7,613✔
1395

1396
//==============================================================================
1397
// C API functions
1398
//==============================================================================
1399

1400
extern "C" int openmc_set_n_batches(
40✔
1401
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1402
{
1403
  if (settings::n_inactive >= n_batches) {
40✔
1404
    set_errmsg("Number of active batches must be greater than zero.");
10✔
1405
    return OPENMC_E_INVALID_ARGUMENT;
10✔
1406
  }
1407

1408
  if (!settings::trigger_on) {
30✔
1409
    // Set n_batches and n_max_batches to same value
1410
    settings::n_batches = n_batches;
10✔
1411
    settings::n_max_batches = n_batches;
10✔
1412
  } else {
1413
    // Set n_batches and n_max_batches based on value of set_max_batches
1414
    if (set_max_batches) {
20✔
1415
      settings::n_max_batches = n_batches;
10✔
1416
    } else {
1417
      settings::n_batches = n_batches;
10✔
1418
    }
1419
  }
1420

1421
  // Update size of k_generation and entropy
1422
  int m = settings::n_max_batches * settings::gen_per_batch;
30✔
1423
  simulation::k_generation.reserve(m);
30✔
1424
  simulation::entropy.reserve(m);
30✔
1425

1426
  // Add value of n_batches to statepoint_batch
1427
  if (add_statepoint_batch &&
30✔
1428
      !(contains(settings::statepoint_batch, n_batches)))
20!
1429
    settings::statepoint_batch.insert(n_batches);
20✔
1430

1431
  return 0;
1432
}
1433

1434
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,300✔
1435
{
1436
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,300✔
1437

1438
  return 0;
2,300✔
1439
}
1440

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