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

openmc-dev / openmc / 22286612725

22 Feb 2026 10:21PM UTC coverage: 81.784% (+0.09%) from 81.69%
22286612725

Pull #3808

github

web-flow
Merge a62b545e2 into 83a30f686
Pull Request #3808: Add properties to settings w/ documentation, c++ loading of filename, and python round-trip test

17355 of 24476 branches covered (70.91%)

Branch coverage included in aggregate %.

83 of 100 new or added lines in 8 files covered. (83.0%)

721 existing lines in 14 files now uncovered.

57750 of 67357 relevant lines covered (85.74%)

42989222.51 hits per line

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

76.46
/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 legendre_to_tabular {true};
60
bool material_cell_offsets {true};
61
bool output_summary {true};
62
bool output_tallies {true};
63
bool particle_restart_run {false};
64
bool photon_transport {false};
65
bool reduce_tallies {true};
66
bool res_scat_on {false};
67
bool restart_run {false};
68
bool run_CE {true};
69
bool source_latest {false};
70
bool source_separate {false};
71
bool source_write {true};
72
bool source_mcpl_write {false};
73
bool surf_source_write {false};
74
bool surf_mcpl_write {false};
75
bool surf_source_read {false};
76
bool survival_biasing {false};
77
bool survival_normalization {false};
78
bool temperature_multipole {false};
79
bool trigger_on {false};
80
bool trigger_predict {false};
81
bool uniform_source_sampling {false};
82
bool ufs_on {false};
83
bool urr_ptables_on {true};
84
bool use_decay_photons {false};
85
bool weight_windows_on {false};
86
bool weight_window_checkpoint_surface {false};
87
bool weight_window_checkpoint_collision {true};
88
bool write_all_tracks {false};
89
bool write_initial_source {false};
90
bool read_temperatures_from_properties {true};
91
bool read_densities_from_properties {true};
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
TemperatureMethod temperature_method {TemperatureMethod::NEAREST};
143
double temperature_tolerance {10.0};
144
double temperature_default {293.6};
145
array<double, 2> temperature_range {0.0, 0.0};
146
int trace_batch;
147
int trace_gen;
148
int64_t trace_particle;
149
vector<array<int, 3>> track_identifiers;
150
int trigger_batch_interval {1};
151
int verbosity {-1};
152
double weight_cutoff {0.25};
153
double weight_survive {1.0};
154

155
} // namespace settings
156

157
//==============================================================================
158
// Functions
159
//==============================================================================
160

161
void get_run_parameters(pugi::xml_node node_base)
6,141✔
162
{
163
  using namespace settings;
164
  using namespace pugi;
165

166
  // Check number of particles
167
  if (!check_for_node(node_base, "particles")) {
6,141!
168
    fatal_error("Need to specify number of particles.");
×
169
  }
170

171
  // Get number of particles if it wasn't specified as a command-line argument
172
  if (n_particles == -1) {
6,141!
173
    n_particles = std::stoll(get_node_value(node_base, "particles"));
6,141✔
174
  }
175

176
  // Get maximum number of in flight particles for event-based mode
177
  if (check_for_node(node_base, "max_particles_in_flight")) {
6,141!
178
    max_particles_in_flight =
×
179
      std::stoll(get_node_value(node_base, "max_particles_in_flight"));
×
180
  }
181

182
  // Get maximum number of events allowed per particle
183
  if (check_for_node(node_base, "max_particle_events")) {
6,141!
184
    max_particle_events =
×
185
      std::stoll(get_node_value(node_base, "max_particle_events"));
×
186
  }
187

188
  // Get number of basic batches
189
  if (check_for_node(node_base, "batches")) {
6,141!
190
    n_batches = std::stoi(get_node_value(node_base, "batches"));
6,141✔
191
  }
192
  if (!trigger_on)
6,141✔
193
    n_max_batches = n_batches;
6,022✔
194

195
  // Get max number of lost particles
196
  if (check_for_node(node_base, "max_lost_particles")) {
6,141✔
197
    max_lost_particles =
40✔
198
      std::stoi(get_node_value(node_base, "max_lost_particles"));
40✔
199
  }
200

201
  // Get relative number of lost particles
202
  if (check_for_node(node_base, "rel_max_lost_particles")) {
6,141!
203
    rel_max_lost_particles =
×
204
      std::stod(get_node_value(node_base, "rel_max_lost_particles"));
×
205
  }
206

207
  // Get relative number of lost particles
208
  if (check_for_node(node_base, "max_write_lost_particles")) {
6,141✔
209
    max_write_lost_particles =
13✔
210
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
13✔
211
  }
212

213
  // Get number of inactive batches
214
  if (run_mode == RunMode::EIGENVALUE ||
6,141✔
215
      solver_type == SolverType::RANDOM_RAY) {
2,312✔
216
    if (check_for_node(node_base, "inactive")) {
4,181✔
217
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,017✔
218
    }
219
    if (check_for_node(node_base, "generations_per_batch")) {
4,181✔
220
      gen_per_batch =
13✔
221
        std::stoi(get_node_value(node_base, "generations_per_batch"));
13✔
222
    }
223

224
    // Preallocate space for keff and entropy by generation
225
    int m = settings::n_max_batches * settings::gen_per_batch;
4,181✔
226
    simulation::k_generation.reserve(m);
4,181✔
227
    simulation::entropy.reserve(m);
4,181✔
228

229
    // Get the trigger information for keff
230
    if (check_for_node(node_base, "keff_trigger")) {
4,181✔
231
      xml_node node_keff_trigger = node_base.child("keff_trigger");
87✔
232

233
      if (check_for_node(node_keff_trigger, "type")) {
87!
234
        auto temp = get_node_value(node_keff_trigger, "type", true, true);
87✔
235
        if (temp == "std_dev") {
87!
236
          keff_trigger.metric = TriggerMetric::standard_deviation;
87✔
237
        } else if (temp == "variance") {
×
238
          keff_trigger.metric = TriggerMetric::variance;
×
239
        } else if (temp == "rel_err") {
×
240
          keff_trigger.metric = TriggerMetric::relative_error;
×
241
        } else {
242
          fatal_error("Unrecognized keff trigger type " + temp);
×
243
        }
244
      } else {
87✔
245
        fatal_error("Specify keff trigger type in settings XML");
×
246
      }
247

248
      if (check_for_node(node_keff_trigger, "threshold")) {
87!
249
        keff_trigger.threshold =
87✔
250
          std::stod(get_node_value(node_keff_trigger, "threshold"));
87✔
251
        if (keff_trigger.threshold <= 0) {
87!
252
          fatal_error("keff trigger threshold must be positive");
×
253
        }
254
      } else {
255
        fatal_error("Specify keff trigger threshold in settings XML");
×
256
      }
257
    }
258
  }
259

260
  // Random ray variables
261
  if (solver_type == SolverType::RANDOM_RAY) {
6,141✔
262
    xml_node random_ray_node = node_base.child("random_ray");
660✔
263
    if (check_for_node(random_ray_node, "distance_active")) {
660!
264
      RandomRay::distance_active_ =
660✔
265
        std::stod(get_node_value(random_ray_node, "distance_active"));
660✔
266
      if (RandomRay::distance_active_ <= 0.0) {
660!
267
        fatal_error("Random ray active distance must be greater than 0");
×
268
      }
269
    } else {
270
      fatal_error("Specify random ray active distance in settings XML");
×
271
    }
272
    if (check_for_node(random_ray_node, "distance_inactive")) {
660!
273
      RandomRay::distance_inactive_ =
660✔
274
        std::stod(get_node_value(random_ray_node, "distance_inactive"));
660✔
275
      if (RandomRay::distance_inactive_ < 0) {
660!
276
        fatal_error(
×
277
          "Random ray inactive distance must be greater than or equal to 0");
278
      }
279
    } else {
280
      fatal_error("Specify random ray inactive distance in settings XML");
×
281
    }
282
    if (check_for_node(random_ray_node, "source")) {
660!
283
      xml_node source_node = random_ray_node.child("source");
660✔
284
      // Get point to list of <source> elements and make sure there is at least
285
      // one
286
      RandomRay::ray_source_ = Source::create(source_node);
660✔
287
    } else {
288
      fatal_error("Specify random ray source in settings XML");
×
289
    }
290
    if (check_for_node(random_ray_node, "volume_estimator")) {
660✔
291
      std::string temp_str =
292
        get_node_value(random_ray_node, "volume_estimator", true, true);
105✔
293
      if (temp_str == "simulation_averaged") {
105✔
294
        FlatSourceDomain::volume_estimator_ =
26✔
295
          RandomRayVolumeEstimator::SIMULATION_AVERAGED;
296
      } else if (temp_str == "naive") {
79✔
297
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::NAIVE;
53✔
298
      } else if (temp_str == "hybrid") {
26!
299
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::HYBRID;
26✔
300
      } else {
301
        fatal_error("Unrecognized volume estimator: " + temp_str);
×
302
      }
303
    }
105✔
304
    if (check_for_node(random_ray_node, "source_shape")) {
660✔
305
      std::string temp_str =
306
        get_node_value(random_ray_node, "source_shape", true, true);
390✔
307
      if (temp_str == "flat") {
390✔
308
        RandomRay::source_shape_ = RandomRaySourceShape::FLAT;
65✔
309
      } else if (temp_str == "linear") {
325✔
310
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR;
286✔
311
      } else if (temp_str == "linear_xy") {
39!
312
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR_XY;
39✔
313
      } else {
314
        fatal_error("Unrecognized source shape: " + temp_str);
×
315
      }
316
    }
390✔
317
    if (check_for_node(random_ray_node, "volume_normalized_flux_tallies")) {
660✔
318
      FlatSourceDomain::volume_normalized_flux_tallies_ =
451✔
319
        get_node_value_bool(random_ray_node, "volume_normalized_flux_tallies");
451✔
320
    }
321
    if (check_for_node(random_ray_node, "adjoint")) {
660✔
322
      FlatSourceDomain::adjoint_ =
26✔
323
        get_node_value_bool(random_ray_node, "adjoint");
26✔
324
    }
325
    if (check_for_node(random_ray_node, "sample_method")) {
660✔
326
      std::string temp_str =
327
        get_node_value(random_ray_node, "sample_method", true, true);
26✔
328
      if (temp_str == "prng") {
26!
329
        RandomRay::sample_method_ = RandomRaySampleMethod::PRNG;
×
330
      } else if (temp_str == "halton") {
26✔
331
        RandomRay::sample_method_ = RandomRaySampleMethod::HALTON;
13✔
332
      } else if (temp_str == "s2") {
13!
333
        RandomRay::sample_method_ = RandomRaySampleMethod::S2;
13✔
334
      } else {
UNCOV
335
        fatal_error("Unrecognized sample method: " + temp_str);
×
336
      }
337
    }
26✔
338
    if (check_for_node(random_ray_node, "source_region_meshes")) {
660✔
339
      pugi::xml_node node_source_region_meshes =
340
        random_ray_node.child("source_region_meshes");
274✔
341
      for (pugi::xml_node node_mesh :
274✔
342
        node_source_region_meshes.children("mesh")) {
874✔
343
        int mesh_id = std::stoi(node_mesh.attribute("id").value());
326✔
344
        for (pugi::xml_node node_domain : node_mesh.children("domain")) {
652✔
345
          int domain_id = std::stoi(node_domain.attribute("id").value());
326✔
346
          std::string domain_type = node_domain.attribute("type").value();
326✔
347
          Source::DomainType type;
348
          if (domain_type == "material") {
326✔
349
            type = Source::DomainType::MATERIAL;
26✔
350
          } else if (domain_type == "cell") {
300✔
351
            type = Source::DomainType::CELL;
26✔
352
          } else if (domain_type == "universe") {
274!
353
            type = Source::DomainType::UNIVERSE;
274✔
354
          } else {
UNCOV
355
            throw std::runtime_error("Unknown domain type: " + domain_type);
×
356
          }
357
          FlatSourceDomain::mesh_domain_map_[mesh_id].emplace_back(
326✔
358
            type, domain_id);
359
        }
326✔
360
      }
361
    }
362
    if (check_for_node(random_ray_node, "diagonal_stabilization_rho")) {
660✔
363
      FlatSourceDomain::diagonal_stabilization_rho_ = std::stod(
13✔
364
        get_node_value(random_ray_node, "diagonal_stabilization_rho"));
26✔
365
      if (FlatSourceDomain::diagonal_stabilization_rho_ < 0.0 ||
13!
366
          FlatSourceDomain::diagonal_stabilization_rho_ > 1.0) {
13!
UNCOV
367
        fatal_error("Random ray diagonal stabilization rho factor must be "
×
368
                    "between 0 and 1");
369
      }
370
    }
371
  }
372
}
6,141✔
373

374
void read_settings_xml()
1,140✔
375
{
376
  using namespace settings;
377
  using namespace pugi;
378
  // Check if settings.xml exists
379
  std::string filename = settings::path_input + "settings.xml";
1,140✔
380
  if (!file_exists(filename)) {
1,140✔
381
    if (run_mode != RunMode::PLOTTING) {
18!
UNCOV
382
      fatal_error("Could not find any XML input files! In order to run OpenMC, "
×
383
                  "you first need a set of input files; at a minimum, this "
384
                  "includes settings.xml, geometry.xml, and materials.xml or a "
385
                  "single model XML file. Please consult the user's guide at "
386
                  "https://docs.openmc.org for further information.");
387
    } else {
388
      // The settings.xml file is optional if we just want to make a plot.
389
      return;
18✔
390
    }
391
  }
392

393
  // Parse settings.xml file
394
  xml_document doc;
1,122✔
395
  auto result = doc.load_file(filename.c_str());
1,122✔
396
  if (!result) {
1,122!
UNCOV
397
    fatal_error("Error processing settings.xml file.");
×
398
  }
399

400
  // Get root element
401
  xml_node root = doc.document_element();
1,122✔
402

403
  // Verbosity
404
  if (check_for_node(root, "verbosity") && verbosity == -1) {
1,122!
405
    verbosity = std::stoi(get_node_value(root, "verbosity"));
149✔
406
  } else if (verbosity == -1) {
973!
407
    verbosity = 7;
973✔
408
  }
409

410
  // To this point, we haven't displayed any output since we didn't know what
411
  // the verbosity is. Now that we checked for it, show the title if necessary
412
  if (mpi::master) {
1,122✔
413
    if (verbosity >= 2)
942✔
414
      title();
801✔
415
  }
416

417
  write_message("Reading settings XML file...", 5);
1,122✔
418

419
  read_settings_xml(root);
1,122✔
420
}
1,132✔
421

422
void read_settings_xml(pugi::xml_node root)
6,803✔
423
{
424
  using namespace settings;
425
  using namespace pugi;
426

427
  // Find if a multi-group or continuous-energy simulation is desired
428
  if (check_for_node(root, "energy_mode")) {
6,803✔
429
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
1,112✔
430
    if (temp_str == "mg" || temp_str == "multi-group") {
1,112!
431
      run_CE = false;
1,112✔
UNCOV
432
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
UNCOV
433
      run_CE = true;
×
434
    }
435
  }
1,112✔
436

437
  // Check for user meshes and allocate
438
  read_meshes(root);
6,803✔
439

440
  // Look for deprecated cross_sections.xml file in settings.xml
441
  if (check_for_node(root, "cross_sections")) {
6,803!
UNCOV
442
    warning(
×
443
      "Setting cross_sections in settings.xml has been deprecated."
444
      " The cross_sections are now set in materials.xml and the "
445
      "cross_sections input to materials.xml and the OPENMC_CROSS_SECTIONS"
446
      " environment variable will take precendent over setting "
447
      "cross_sections in settings.xml.");
UNCOV
448
    path_cross_sections = get_node_value(root, "cross_sections");
×
449
  }
450

451
  if (!run_CE) {
6,803✔
452
    // Scattering Treatments
453
    if (check_for_node(root, "max_order")) {
1,112✔
454
      max_order = std::stoi(get_node_value(root, "max_order"));
13✔
455
    } else {
456
      // Set to default of largest int - 1, which means to use whatever is
457
      // contained in library. This is largest int - 1 because for legendre
458
      // scattering, a value of 1 is added to the order; adding 1 to the largest
459
      // int gets you the largest negative integer, which is not what we want.
460
      max_order = std::numeric_limits<int>::max() - 1;
1,099✔
461
    }
462
  }
463

464
  // Check for a trigger node and get trigger information
465
  if (check_for_node(root, "trigger")) {
6,803✔
466
    xml_node node_trigger = root.child("trigger");
132✔
467

468
    // Check if trigger(s) are to be turned on
469
    trigger_on = get_node_value_bool(node_trigger, "active");
132✔
470

471
    if (trigger_on) {
132✔
472
      if (check_for_node(node_trigger, "max_batches")) {
119!
473
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
119✔
474
      } else {
UNCOV
475
        fatal_error("<max_batches> must be specified with triggers");
×
476
      }
477

478
      // Get the batch interval to check triggers
479
      if (!check_for_node(node_trigger, "batch_interval")) {
119✔
480
        trigger_predict = true;
13✔
481
      } else {
482
        trigger_batch_interval =
106✔
483
          std::stoi(get_node_value(node_trigger, "batch_interval"));
106✔
484
        if (trigger_batch_interval <= 0) {
106!
UNCOV
485
          fatal_error("Trigger batch interval must be greater than zero");
×
486
        }
487
      }
488
    }
489
  }
490

491
  // Check run mode if it hasn't been set from the command line
492
  xml_node node_mode;
6,803✔
493
  if (run_mode == RunMode::UNSET) {
6,803✔
494
    if (check_for_node(root, "run_mode")) {
6,169✔
495
      std::string temp_str = get_node_value(root, "run_mode", true, true);
6,143✔
496
      if (temp_str == "eigenvalue") {
6,143✔
497
        run_mode = RunMode::EIGENVALUE;
3,803✔
498
      } else if (temp_str == "fixed source") {
2,340✔
499
        run_mode = RunMode::FIXED_SOURCE;
2,312✔
500
      } else if (temp_str == "plot") {
28!
501
        run_mode = RunMode::PLOTTING;
×
502
      } else if (temp_str == "particle restart") {
28!
UNCOV
503
        run_mode = RunMode::PARTICLE;
×
504
      } else if (temp_str == "volume") {
28!
505
        run_mode = RunMode::VOLUME;
28✔
506
      } else {
UNCOV
507
        fatal_error("Unrecognized run mode: " + temp_str);
×
508
      }
509

510
      // Assume XML specifies <particles>, <batches>, etc. directly
511
      node_mode = root;
6,143✔
512
    } else {
6,143✔
513
      warning("<run_mode> should be specified.");
26✔
514

515
      // Make sure that either eigenvalue or fixed source was specified
516
      node_mode = root.child("eigenvalue");
26✔
517
      if (node_mode) {
26!
518
        run_mode = RunMode::EIGENVALUE;
26✔
519
      } else {
520
        node_mode = root.child("fixed_source");
×
UNCOV
521
        if (node_mode) {
×
522
          run_mode = RunMode::FIXED_SOURCE;
×
523
        } else {
UNCOV
524
          fatal_error("<eigenvalue> or <fixed_source> not specified.");
×
525
        }
526
      }
527
    }
528
  }
529

530
  // Check solver type
531
  if (check_for_node(root, "random_ray")) {
6,803✔
532
    solver_type = SolverType::RANDOM_RAY;
660✔
533
    if (run_CE)
660!
UNCOV
534
      fatal_error("multi-group energy mode must be specified in settings XML "
×
535
                  "when using the random ray solver.");
536
  }
537

538
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
6,803✔
539
    // Read run parameters
540
    get_run_parameters(node_mode);
6,141✔
541

542
    // Check number of active batches, inactive batches, max lost particles and
543
    // particles
544
    if (n_batches <= n_inactive) {
6,141!
545
      fatal_error("Number of active batches must be greater than zero.");
×
546
    } else if (n_inactive < 0) {
6,141!
547
      fatal_error("Number of inactive batches must be non-negative.");
×
548
    } else if (n_particles <= 0) {
6,141!
549
      fatal_error("Number of particles must be greater than zero.");
×
550
    } else if (max_lost_particles <= 0) {
6,141!
551
      fatal_error("Number of max lost particles must be greater than zero.");
×
552
    } else if (rel_max_lost_particles <= 0.0 || rel_max_lost_particles >= 1.0) {
6,141!
UNCOV
553
      fatal_error("Relative max lost particles must be between zero and one.");
×
554
    }
555

556
    // Check for user value for the number of generation of the Iterated Fission
557
    // Probability (IFP) method
558
    if (check_for_node(root, "ifp_n_generation")) {
6,141✔
559
      ifp_n_generation = std::stoi(get_node_value(root, "ifp_n_generation"));
69✔
560
      if (ifp_n_generation <= 0) {
69!
UNCOV
561
        fatal_error("'ifp_n_generation' must be greater than 0.");
×
562
      }
563
      // Avoid tallying 0 if IFP logs are not complete when active cycles start
564
      if (ifp_n_generation > n_inactive) {
69✔
565
        fatal_error("'ifp_n_generation' must be lower than or equal to the "
7✔
566
                    "number of inactive cycles.");
567
      }
568
    }
569
  }
570

571
  // Copy plotting random number seed if specified
572
  if (check_for_node(root, "plot_seed")) {
6,796!
UNCOV
573
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
UNCOV
574
    model::plotter_seed = seed;
×
575
  }
576

577
  // Copy random number seed if specified
578
  if (check_for_node(root, "seed")) {
6,796✔
579
    auto seed = std::stoll(get_node_value(root, "seed"));
479✔
580
    openmc_set_seed(seed);
479✔
581
  }
582

583
  // Copy random number stride if specified
584
  if (check_for_node(root, "stride")) {
6,796✔
585
    auto stride = std::stoull(get_node_value(root, "stride"));
13✔
586
    openmc_set_stride(stride);
13✔
587
  }
588

589
  // Check for electron treatment
590
  if (check_for_node(root, "electron_treatment")) {
6,796✔
591
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
57✔
592
    if (temp_str == "led") {
57✔
593
      electron_treatment = ElectronTreatment::LED;
9✔
594
    } else if (temp_str == "ttb") {
48!
595
      electron_treatment = ElectronTreatment::TTB;
48✔
596
    } else {
UNCOV
597
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
598
    }
599
  }
57✔
600

601
  // Check for photon transport
602
  if (check_for_node(root, "photon_transport")) {
6,796✔
603
    photon_transport = get_node_value_bool(root, "photon_transport");
162✔
604

605
    if (!run_CE && photon_transport) {
162!
UNCOV
606
      fatal_error("Photon transport is not currently supported in "
×
607
                  "multigroup mode");
608
    }
609
  }
610

611
  // Number of bins for logarithmic grid
612
  if (check_for_node(root, "log_grid_bins")) {
6,796✔
613
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
13✔
614
    if (n_log_bins < 1) {
13!
UNCOV
615
      fatal_error("Number of bins for logarithmic grid must be greater "
×
616
                  "than zero.");
617
    }
618
  }
619

620
  // Number of OpenMP threads
621
  if (check_for_node(root, "threads")) {
6,796!
UNCOV
622
    if (mpi::master)
×
UNCOV
623
      warning("The <threads> element has been deprecated. Use "
×
624
              "the OMP_NUM_THREADS environment variable to set the number of "
625
              "threads.");
626
  }
627

628
  // ==========================================================================
629
  // EXTERNAL SOURCE
630

631
  // Get point to list of <source> elements and make sure there is at least one
632
  for (pugi::xml_node node : root.children("source")) {
13,159✔
633
    model::external_sources.push_back(Source::create(node));
6,371✔
634
  }
635

636
  // Check if the user has specified to read surface source
637
  if (check_for_node(root, "surf_source_read")) {
6,788✔
638
    surf_source_read = true;
26✔
639
    // Get surface source read node
640
    xml_node node_ssr = root.child("surf_source_read");
26✔
641

642
    std::string path = "surface_source.h5";
26✔
643
    // Check if the user has specified different file for surface source reading
644
    if (check_for_node(node_ssr, "path")) {
26!
645
      path = get_node_value(node_ssr, "path", false, true);
26✔
646
    }
647
    model::external_sources.push_back(make_unique<FileSource>(path));
26✔
648
  }
26✔
649

650
  // If no source specified, default to isotropic point source at origin with
651
  // Watt spectrum. No default source is needed in random ray mode.
652
  if (model::external_sources.empty() &&
8,602✔
653
      settings::solver_type != SolverType::RANDOM_RAY) {
1,814✔
654
    double T[] {0.0};
1,688✔
655
    double p[] {1.0};
1,688✔
656
    model::external_sources.push_back(make_unique<IndependentSource>(
1,688✔
657
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
3,376✔
658
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
3,376✔
659
      UPtrDist {new Discrete(T, p, 1)}));
3,376✔
660
  }
661

662
  // Build probability mass function for sampling external sources
663
  vector<double> source_strengths;
6,788✔
664
  for (auto& s : model::external_sources) {
14,865✔
665
    source_strengths.push_back(s->strength());
8,077✔
666
  }
667
  model::external_sources_probability.assign(source_strengths);
6,788✔
668

669
  // Check if we want to write out source
670
  if (check_for_node(root, "write_initial_source")) {
6,788!
UNCOV
671
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
672
  }
673

674
  // Get relative number of lost particles
675
  if (check_for_node(root, "source_rejection_fraction")) {
6,788✔
676
    source_rejection_fraction =
5✔
677
      std::stod(get_node_value(root, "source_rejection_fraction"));
5!
678
  }
679

680
  if (check_for_node(root, "free_gas_threshold")) {
6,788!
UNCOV
681
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
682
  }
683

684
  // Survival biasing
685
  if (check_for_node(root, "survival_biasing")) {
6,788✔
686
    survival_biasing = get_node_value_bool(root, "survival_biasing");
145✔
687
  }
688

689
  // Probability tables
690
  if (check_for_node(root, "ptables")) {
6,788✔
691
    urr_ptables_on = get_node_value_bool(root, "ptables");
13✔
692
  }
693

694
  // Cutoffs
695
  if (check_for_node(root, "cutoff")) {
6,788✔
696
    xml_node node_cutoff = root.child("cutoff");
118✔
697
    if (check_for_node(node_cutoff, "weight")) {
118✔
698
      weight_cutoff = std::stod(get_node_value(node_cutoff, "weight"));
13✔
699
    }
700
    if (check_for_node(node_cutoff, "weight_avg")) {
118✔
701
      weight_survive = std::stod(get_node_value(node_cutoff, "weight_avg"));
13✔
702
    }
703
    if (check_for_node(node_cutoff, "survival_normalization")) {
118!
UNCOV
704
      survival_normalization =
×
UNCOV
705
        get_node_value_bool(node_cutoff, "survival_normalization");
×
706
    }
707
    if (check_for_node(node_cutoff, "energy_neutron")) {
118✔
708
      energy_cutoff[0] =
26✔
709
        std::stod(get_node_value(node_cutoff, "energy_neutron"));
13✔
710
    } else if (check_for_node(node_cutoff, "energy")) {
105!
711
      warning("The use of an <energy> cutoff is deprecated and should "
×
712
              "be replaced by <energy_neutron>.");
UNCOV
713
      energy_cutoff[0] = std::stod(get_node_value(node_cutoff, "energy"));
×
714
    }
715
    if (check_for_node(node_cutoff, "energy_photon")) {
118✔
716
      energy_cutoff[1] =
140✔
717
        std::stod(get_node_value(node_cutoff, "energy_photon"));
70✔
718
    }
719
    if (check_for_node(node_cutoff, "energy_electron")) {
118!
UNCOV
720
      energy_cutoff[2] =
×
UNCOV
721
        std::stof(get_node_value(node_cutoff, "energy_electron"));
×
722
    }
723
    if (check_for_node(node_cutoff, "energy_positron")) {
118!
UNCOV
724
      energy_cutoff[3] =
×
UNCOV
725
        std::stod(get_node_value(node_cutoff, "energy_positron"));
×
726
    }
727
    if (check_for_node(node_cutoff, "time_neutron")) {
118✔
728
      time_cutoff[0] = std::stod(get_node_value(node_cutoff, "time_neutron"));
22✔
729
    }
730
    if (check_for_node(node_cutoff, "time_photon")) {
118!
UNCOV
731
      time_cutoff[1] = std::stod(get_node_value(node_cutoff, "time_photon"));
×
732
    }
733
    if (check_for_node(node_cutoff, "time_electron")) {
118!
UNCOV
734
      time_cutoff[2] = std::stod(get_node_value(node_cutoff, "time_electron"));
×
735
    }
736
    if (check_for_node(node_cutoff, "time_positron")) {
118!
UNCOV
737
      time_cutoff[3] = std::stod(get_node_value(node_cutoff, "time_positron"));
×
738
    }
739
  }
740

741
  // read properties from file
742
  if (check_for_node(root, "properties")) {
6,788!
743
    // Get pointer to properties node
NEW
744
    xml_node node_props = root.child("properties");
×
745

NEW
746
    properties_file = get_node_value(node_props, "filepath");
×
NEW
747
    if (!file_exists(properties_file)) {
×
NEW
748
      fatal_error(fmt::format("File '{}' does not exist.", properties_file));
×
749
    }
NEW
750
    read_temperatures_from_properties =
×
NEW
751
      get_node_value_bool(node_props, "temperatures");
×
NEW
752
    read_densities_from_properties =
×
NEW
753
      get_node_value_bool(node_props, "densities");
×
754
  }
755

756
  // Particle trace
757
  if (check_for_node(root, "trace")) {
6,788✔
758
    auto temp = get_node_array<int64_t>(root, "trace");
13✔
759
    if (temp.size() != 3) {
13!
UNCOV
760
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
761
                  "batch, generation, and particle number.");
762
    }
763
    trace_batch = temp.at(0);
13✔
764
    trace_gen = temp.at(1);
13✔
765
    trace_particle = temp.at(2);
13✔
766
  }
13✔
767

768
  // Particle tracks
769
  if (check_for_node(root, "track")) {
6,788✔
770
    // Get values and make sure there are three per particle
771
    auto temp = get_node_array<int>(root, "track");
39✔
772
    if (temp.size() % 3 != 0) {
39!
UNCOV
773
      fatal_error(
×
774
        "Number of integers specified in 'track' is not "
775
        "divisible by 3.  Please provide 3 integers per particle to be "
776
        "tracked.");
777
    }
778

779
    // Reshape into track_identifiers
780
    int n_tracks = temp.size() / 3;
39✔
781
    for (int i = 0; i < n_tracks; ++i) {
156✔
782
      track_identifiers.push_back(
117✔
783
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
117✔
784
    }
785
  }
39✔
786

787
  // Shannon entropy
788
  if (solver_type == SolverType::RANDOM_RAY) {
6,788✔
789
    if (check_for_node(root, "entropy_mesh")) {
660!
UNCOV
790
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
791
                  "No user-defined entropy mesh is supported.");
792
    }
793
    entropy_on = true;
660✔
794
  } else if (solver_type == SolverType::MONTE_CARLO) {
6,128!
795
    if (check_for_node(root, "entropy_mesh")) {
6,128✔
796
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
274✔
797
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
274!
UNCOV
798
        fatal_error(fmt::format(
×
799
          "Mesh {} specified for Shannon entropy does not exist.", temp));
800
      }
801

802
      auto* m = dynamic_cast<RegularMesh*>(
274!
803
        model::meshes[model::mesh_map.at(temp)].get());
274✔
804
      if (!m)
274!
UNCOV
805
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
806
      simulation::entropy_mesh = m;
274✔
807

808
      // Turn on Shannon entropy calculation
809
      entropy_on = true;
274✔
810

811
    } else if (check_for_node(root, "entropy")) {
5,854!
UNCOV
812
      fatal_error(
×
813
        "Specifying a Shannon entropy mesh via the <entropy> element "
814
        "is deprecated. Please create a mesh using <mesh> and then reference "
815
        "it by specifying its ID in an <entropy_mesh> element.");
816
    }
817
  }
818
  // Uniform fission source weighting mesh
819
  if (check_for_node(root, "ufs_mesh")) {
6,788✔
820
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
13✔
821
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
13!
UNCOV
822
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
823
                              "method does not exist.",
824
        temp));
825
    }
826

827
    auto* m =
828
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
13!
829
    if (!m)
13!
UNCOV
830
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
831
    simulation::ufs_mesh = m;
13✔
832

833
    // Turn on uniform fission source weighting
834
    ufs_on = true;
13✔
835

836
  } else if (check_for_node(root, "uniform_fs")) {
6,775!
UNCOV
837
    fatal_error(
×
838
      "Specifying a UFS mesh via the <uniform_fs> element "
839
      "is deprecated. Please create a mesh using <mesh> and then reference "
840
      "it by specifying its ID in a <ufs_mesh> element.");
841
  }
842

843
  // Check if the user has specified to write state points
844
  if (check_for_node(root, "state_point")) {
6,788✔
845

846
    // Get pointer to state_point node
847
    auto node_sp = root.child("state_point");
136✔
848

849
    // Determine number of batches at which to store state points
850
    if (check_for_node(node_sp, "batches")) {
136!
851
      // User gave specific batches to write state points
852
      auto temp = get_node_array<int>(node_sp, "batches");
136✔
853
      for (const auto& b : temp) {
417✔
854
        statepoint_batch.insert(b);
281✔
855
      }
856
    } else {
136✔
857
      // If neither were specified, write state point at last batch
UNCOV
858
      statepoint_batch.insert(n_batches);
×
859
    }
860
  } else {
861
    // If no <state_point> tag was present, by default write state point at
862
    // last batch only
863
    statepoint_batch.insert(n_batches);
6,652✔
864
  }
865

866
  // Check if the user has specified to write source points
867
  if (check_for_node(root, "source_point")) {
6,788✔
868
    // Get source_point node
869
    xml_node node_sp = root.child("source_point");
87✔
870

871
    // Determine batches at which to store source points
872
    if (check_for_node(node_sp, "batches")) {
87✔
873
      // User gave specific batches to write source points
874
      auto temp = get_node_array<int>(node_sp, "batches");
39✔
875
      for (const auto& b : temp) {
104✔
876
        sourcepoint_batch.insert(b);
65✔
877
      }
878
    } else {
39✔
879
      // If neither were specified, write source points with state points
880
      sourcepoint_batch = statepoint_batch;
48✔
881
    }
882

883
    // Check if the user has specified to write binary source file
884
    if (check_for_node(node_sp, "separate")) {
87✔
885
      source_separate = get_node_value_bool(node_sp, "separate");
61✔
886
    }
887
    if (check_for_node(node_sp, "write")) {
87!
UNCOV
888
      source_write = get_node_value_bool(node_sp, "write");
×
889
    }
890
    if (check_for_node(node_sp, "mcpl")) {
87✔
891
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
22✔
892
    }
893
    if (check_for_node(node_sp, "overwrite_latest")) {
87✔
894
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
13✔
895
      source_separate = source_latest;
13✔
896
    }
897
  } else {
898
    // If no <source_point> tag was present, by default we keep source bank in
899
    // statepoint file and write it out at statepoints intervals
900
    source_separate = false;
6,701✔
901
    sourcepoint_batch = statepoint_batch;
6,701✔
902
  }
903

904
  // Check is the user specified to convert strength to statistical weight
905
  if (check_for_node(root, "uniform_source_sampling")) {
6,788✔
906
    uniform_source_sampling =
45✔
907
      get_node_value_bool(root, "uniform_source_sampling");
45✔
908
  }
909

910
  // Check if the user has specified to write surface source
911
  if (check_for_node(root, "surf_source_write")) {
6,788✔
912
    surf_source_write = true;
334✔
913
    // Get surface source write node
914
    xml_node node_ssw = root.child("surf_source_write");
334✔
915

916
    // Determine surface ids at which crossing particles are to be banked.
917
    // If no surfaces are specified, all surfaces in the model will be used
918
    // to bank source points.
919
    if (check_for_node(node_ssw, "surface_ids")) {
334✔
920
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
164✔
921
      for (const auto& b : temp) {
804✔
922
        source_write_surf_id.insert(b);
640✔
923
      }
924
    }
164✔
925

926
    // Get maximum number of particles to be banked per surface
927
    if (check_for_node(node_ssw, "max_particles")) {
334✔
928
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
327✔
929
    } else {
930
      fatal_error("A maximum number of particles needs to be specified "
7✔
931
                  "using the 'max_particles' parameter to store surface "
932
                  "source points.");
933
    }
934

935
    // Get maximum number of surface source files to be created
936
    if (check_for_node(node_ssw, "max_source_files")) {
327✔
937
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
27✔
938
    } else {
939
      ssw_max_files = 1;
300✔
940
    }
941

942
    if (check_for_node(node_ssw, "mcpl")) {
327✔
943
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
9✔
944
    }
945
    // Get cell information
946
    if (check_for_node(node_ssw, "cell")) {
327✔
947
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
84✔
948
      ssw_cell_type = SSWCellType::Both;
84✔
949
    }
950
    if (check_for_node(node_ssw, "cellfrom")) {
327✔
951
      if (ssw_cell_id != C_NONE) {
72✔
952
        fatal_error(
14✔
953
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
954
      }
955
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
58✔
956
      ssw_cell_type = SSWCellType::From;
58✔
957
    }
958
    if (check_for_node(node_ssw, "cellto")) {
313✔
959
      if (ssw_cell_id != C_NONE) {
57✔
960
        fatal_error(
14✔
961
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
962
      }
963
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
43✔
964
      ssw_cell_type = SSWCellType::To;
43✔
965
    }
966
  }
967

968
  // Check if the user has specified to write specific collisions
969
  if (check_for_node(root, "collision_track")) {
6,753✔
970
    settings::collision_track = true;
126✔
971
    // Get collision track node
972
    xml_node node_ct = root.child("collision_track");
126✔
973
    collision_track_config = CollisionTrackConfig {};
126✔
974

975
    // Determine cell ids at which crossing particles are to be banked
976
    if (check_for_node(node_ct, "cell_ids")) {
126✔
977
      auto temp = get_node_array<int>(node_ct, "cell_ids");
66✔
978
      for (const auto& b : temp) {
172✔
979
        collision_track_config.cell_ids.insert(b);
106✔
980
      }
981
    }
66✔
982
    if (check_for_node(node_ct, "reactions")) {
126✔
983
      auto temp = get_node_array<std::string>(node_ct, "reactions");
53✔
984
      for (const auto& b : temp) {
145✔
985
        int reaction_int = reaction_mt(b);
92✔
986
        if (reaction_int > 0) {
92!
987
          collision_track_config.mt_numbers.insert(reaction_int);
92✔
988
        }
989
      }
990
    }
53✔
991
    if (check_for_node(node_ct, "universe_ids")) {
126✔
992
      auto temp = get_node_array<int>(node_ct, "universe_ids");
26✔
993
      for (const auto& b : temp) {
52✔
994
        collision_track_config.universe_ids.insert(b);
26✔
995
      }
996
    }
26✔
997
    if (check_for_node(node_ct, "material_ids")) {
126✔
998
      auto temp = get_node_array<int>(node_ct, "material_ids");
26✔
999
      for (const auto& b : temp) {
65✔
1000
        collision_track_config.material_ids.insert(b);
39✔
1001
      }
1002
    }
26✔
1003
    if (check_for_node(node_ct, "nuclides")) {
126✔
1004
      auto temp = get_node_array<std::string>(node_ct, "nuclides");
26✔
1005
      for (const auto& b : temp) {
104✔
1006
        collision_track_config.nuclides.insert(b);
78✔
1007
      }
1008
    }
26✔
1009
    if (check_for_node(node_ct, "deposited_E_threshold")) {
126✔
1010
      collision_track_config.deposited_energy_threshold =
26✔
1011
        std::stod(get_node_value(node_ct, "deposited_E_threshold"));
26✔
1012
    }
1013
    // Get maximum number of particles to be banked per collision
1014
    if (check_for_node(node_ct, "max_collisions")) {
126!
1015
      collision_track_config.max_collisions =
126✔
1016
        std::stoll(get_node_value(node_ct, "max_collisions"));
126✔
1017
    } else {
UNCOV
1018
      warning("A maximum number of collisions needs to be specified. "
×
1019
              "By default the code sets 'max_collisions' parameter equals to "
1020
              "1000.");
1021
    }
1022
    // Get maximum number of collision_track files to be created
1023
    if (check_for_node(node_ct, "max_collision_track_files")) {
126!
UNCOV
1024
      collision_track_config.max_files =
×
UNCOV
1025
        std::stoll(get_node_value(node_ct, "max_collision_track_files"));
×
1026
    }
1027
    if (check_for_node(node_ct, "mcpl")) {
126✔
1028
      collision_track_config.mcpl_write = get_node_value_bool(node_ct, "mcpl");
18✔
1029
    }
1030
  }
1031

1032
  // If source is not separate and is to be written out in the statepoint
1033
  // file, make sure that the sourcepoint batch numbers are contained in the
1034
  // statepoint list
1035
  if (!source_separate) {
6,753✔
1036
    for (const auto& b : sourcepoint_batch) {
13,464✔
1037
      if (!contains(statepoint_batch, b)) {
6,785!
UNCOV
1038
        fatal_error(
×
1039
          "Sourcepoint batches are not a subset of statepoint batches.");
1040
      }
1041
    }
1042
  }
1043

1044
  // Check if the user has specified to not reduce tallies at the end of every
1045
  // batch
1046
  if (check_for_node(root, "no_reduce")) {
6,753✔
1047
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
26✔
1048
  }
1049

1050
  // Check if the user has specified to use confidence intervals for
1051
  // uncertainties rather than standard deviations
1052
  if (check_for_node(root, "confidence_intervals")) {
6,753✔
1053
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
13✔
1054
  }
1055

1056
  // Check for output options
1057
  if (check_for_node(root, "output")) {
6,753✔
1058
    // Get pointer to output node
1059
    pugi::xml_node node_output = root.child("output");
632✔
1060

1061
    // Check for summary option
1062
    if (check_for_node(node_output, "summary")) {
632✔
1063
      output_summary = get_node_value_bool(node_output, "summary");
610✔
1064
    }
1065

1066
    // Check for ASCII tallies output option
1067
    if (check_for_node(node_output, "tallies")) {
632✔
1068
      output_tallies = get_node_value_bool(node_output, "tallies");
287✔
1069
    }
1070

1071
    // Set output directory if a path has been specified
1072
    if (check_for_node(node_output, "path")) {
632!
1073
      path_output = get_node_value(node_output, "path");
×
UNCOV
1074
      if (!ends_with(path_output, "/")) {
×
UNCOV
1075
        path_output += "/";
×
1076
      }
1077
    }
1078
  }
1079

1080
  // Resonance scattering parameters
1081
  if (check_for_node(root, "resonance_scattering")) {
6,753✔
1082
    xml_node node_res_scat = root.child("resonance_scattering");
13✔
1083

1084
    // See if resonance scattering is enabled
1085
    if (check_for_node(node_res_scat, "enable")) {
13!
1086
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
13✔
1087
    } else {
UNCOV
1088
      res_scat_on = true;
×
1089
    }
1090

1091
    // Determine what method is used
1092
    if (check_for_node(node_res_scat, "method")) {
13!
1093
      auto temp = get_node_value(node_res_scat, "method", true, true);
13✔
1094
      if (temp == "rvs") {
13!
1095
        res_scat_method = ResScatMethod::rvs;
13✔
UNCOV
1096
      } else if (temp == "dbrc") {
×
1097
        res_scat_method = ResScatMethod::dbrc;
×
1098
      } else {
UNCOV
1099
        fatal_error(
×
UNCOV
1100
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1101
      }
1102
    }
13✔
1103

1104
    // Minimum energy for resonance scattering
1105
    if (check_for_node(node_res_scat, "energy_min")) {
13!
1106
      res_scat_energy_min =
13✔
1107
        std::stod(get_node_value(node_res_scat, "energy_min"));
13✔
1108
    }
1109
    if (res_scat_energy_min < 0.0) {
13!
UNCOV
1110
      fatal_error("Lower resonance scattering energy bound is negative");
×
1111
    }
1112

1113
    // Maximum energy for resonance scattering
1114
    if (check_for_node(node_res_scat, "energy_max")) {
13!
1115
      res_scat_energy_max =
13✔
1116
        std::stod(get_node_value(node_res_scat, "energy_max"));
13✔
1117
    }
1118
    if (res_scat_energy_max < res_scat_energy_min) {
13!
UNCOV
1119
      fatal_error("Upper resonance scattering energy bound is below the "
×
1120
                  "lower resonance scattering energy bound.");
1121
    }
1122

1123
    // Get resonance scattering nuclides
1124
    if (check_for_node(node_res_scat, "nuclides")) {
13!
1125
      res_scat_nuclides =
1126
        get_node_array<std::string>(node_res_scat, "nuclides");
13✔
1127
    }
1128
  }
1129

1130
  // Get volume calculations
1131
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
7,021✔
1132
    model::volume_calcs.emplace_back(node_vol);
268✔
1133
  }
1134

1135
  // Get temperature settings
1136
  if (check_for_node(root, "temperature_default")) {
6,753✔
1137
    temperature_default =
141✔
1138
      std::stod(get_node_value(root, "temperature_default"));
141✔
1139
  }
1140
  if (check_for_node(root, "temperature_method")) {
6,753✔
1141
    auto temp = get_node_value(root, "temperature_method", true, true);
407✔
1142
    if (temp == "nearest") {
407✔
1143
      temperature_method = TemperatureMethod::NEAREST;
256✔
1144
    } else if (temp == "interpolation") {
151!
1145
      temperature_method = TemperatureMethod::INTERPOLATION;
151✔
1146
    } else {
UNCOV
1147
      fatal_error("Unknown temperature method: " + temp);
×
1148
    }
1149
  }
407✔
1150
  if (check_for_node(root, "temperature_tolerance")) {
6,753✔
1151
    temperature_tolerance =
282✔
1152
      std::stod(get_node_value(root, "temperature_tolerance"));
282✔
1153
  }
1154
  if (check_for_node(root, "temperature_multipole")) {
6,753✔
1155
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
155✔
1156

1157
    // Multipole currently doesn't work with photon transport
1158
    if (temperature_multipole && photon_transport) {
155!
UNCOV
1159
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1160
                  "photon transport.");
1161
    }
1162
  }
1163
  if (check_for_node(root, "temperature_range")) {
6,753✔
1164
    auto range = get_node_array<double>(root, "temperature_range");
142✔
1165
    temperature_range[0] = range.at(0);
142✔
1166
    temperature_range[1] = range.at(1);
142✔
1167
  }
142✔
1168

1169
  // Check for tabular_legendre options
1170
  if (check_for_node(root, "tabular_legendre")) {
6,753✔
1171
    // Get pointer to tabular_legendre node
1172
    xml_node node_tab_leg = root.child("tabular_legendre");
78✔
1173

1174
    // Check for enable option
1175
    if (check_for_node(node_tab_leg, "enable")) {
78!
1176
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
78✔
1177
    }
1178

1179
    // Check for the number of points
1180
    if (check_for_node(node_tab_leg, "num_points")) {
78!
1181
      legendre_to_tabular_points =
×
1182
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
UNCOV
1183
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
UNCOV
1184
        fatal_error(
×
1185
          "The 'num_points' subelement/attribute of the "
1186
          "<tabular_legendre> element must contain a value greater than 1");
1187
      }
1188
    }
1189
  }
1190

1191
  // Check whether create delayed neutrons in fission
1192
  if (check_for_node(root, "create_delayed_neutrons")) {
6,753!
UNCOV
1193
    create_delayed_neutrons =
×
UNCOV
1194
      get_node_value_bool(root, "create_delayed_neutrons");
×
1195
  }
1196

1197
  // Check whether create fission sites
1198
  if (run_mode == RunMode::FIXED_SOURCE) {
6,753✔
1199
    if (check_for_node(root, "create_fission_neutrons")) {
2,276✔
1200
      create_fission_neutrons =
230✔
1201
        get_node_value_bool(root, "create_fission_neutrons");
230✔
1202
    }
1203
  }
1204

1205
  // Check whether to scale fission photon yields
1206
  if (check_for_node(root, "delayed_photon_scaling")) {
6,753!
UNCOV
1207
    delayed_photon_scaling =
×
UNCOV
1208
      get_node_value_bool(root, "delayed_photon_scaling");
×
1209
  }
1210

1211
  // Check whether to use event-based parallelism
1212
  if (check_for_node(root, "event_based")) {
6,753!
UNCOV
1213
    event_based = get_node_value_bool(root, "event_based");
×
1214
  }
1215

1216
  // Check whether material cell offsets should be generated
1217
  if (check_for_node(root, "material_cell_offsets")) {
6,753!
UNCOV
1218
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1219
  }
1220

1221
  // Weight window information
1222
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
6,829✔
1223
    variance_reduction::weight_windows.emplace_back(
76✔
1224
      std::make_unique<WeightWindows>(node_ww));
152✔
1225
  }
1226

1227
  // Enable weight windows by default if one or more are present
1228
  if (variance_reduction::weight_windows.size() > 0)
6,753✔
1229
    settings::weight_windows_on = true;
54✔
1230

1231
  // read weight windows from file
1232
  if (check_for_node(root, "weight_windows_file")) {
6,753!
UNCOV
1233
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1234
  }
1235

1236
  // read settings for weight windows value, this will override
1237
  // the automatic setting even if weight windows are present
1238
  if (check_for_node(root, "weight_windows_on")) {
6,753✔
1239
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
32✔
1240
  }
1241

1242
  if (check_for_node(root, "max_secondaries")) {
6,753!
UNCOV
1243
    settings::max_secondaries =
×
UNCOV
1244
      std::stoi(get_node_value(root, "max_secondaries"));
×
1245
  }
1246

1247
  if (check_for_node(root, "max_history_splits")) {
6,753✔
1248
    settings::max_history_splits =
176✔
1249
      std::stoi(get_node_value(root, "max_history_splits"));
176✔
1250
  }
1251

1252
  if (check_for_node(root, "max_tracks")) {
6,753✔
1253
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
39✔
1254
  }
1255

1256
  // Create weight window generator objects
1257
  if (check_for_node(root, "weight_window_generators")) {
6,753✔
1258
    auto wwgs_node = root.child("weight_window_generators");
67✔
1259
    for (pugi::xml_node node_wwg :
67✔
1260
      wwgs_node.children("weight_windows_generator")) {
201✔
1261
      variance_reduction::weight_windows_generators.emplace_back(
67✔
1262
        std::make_unique<WeightWindowsGenerator>(node_wwg));
134✔
1263
    }
1264
    // if any of the weight windows are intended to be generated otf, make
1265
    // sure they're applied
1266
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
67!
1267
      if (wwg->on_the_fly_) {
67!
1268
        settings::weight_windows_on = true;
67✔
1269
        break;
67✔
1270
      }
1271
    }
1272
  }
1273

1274
  // Set up weight window checkpoints
1275
  if (check_for_node(root, "weight_window_checkpoints")) {
6,753✔
1276
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
15✔
1277
    if (check_for_node(ww_checkpoints, "collision")) {
15!
1278
      weight_window_checkpoint_collision =
15✔
1279
        get_node_value_bool(ww_checkpoints, "collision");
15✔
1280
    }
1281
    if (check_for_node(ww_checkpoints, "surface")) {
15!
1282
      weight_window_checkpoint_surface =
15✔
1283
        get_node_value_bool(ww_checkpoints, "surface");
15✔
1284
    }
1285
  }
1286

1287
  if (check_for_node(root, "use_decay_photons")) {
6,753✔
1288
    settings::use_decay_photons =
9✔
1289
      get_node_value_bool(root, "use_decay_photons");
9✔
1290
  }
1291
}
6,753✔
1292

1293
void free_memory_settings()
6,881✔
1294
{
1295
  settings::statepoint_batch.clear();
6,881✔
1296
  settings::sourcepoint_batch.clear();
6,881✔
1297
  settings::source_write_surf_id.clear();
6,881✔
1298
  settings::res_scat_nuclides.clear();
6,881✔
1299
}
6,881✔
1300

1301
//==============================================================================
1302
// C API functions
1303
//==============================================================================
1304

1305
extern "C" int openmc_set_n_batches(
36✔
1306
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1307
{
1308
  if (settings::n_inactive >= n_batches) {
36✔
1309
    set_errmsg("Number of active batches must be greater than zero.");
9✔
1310
    return OPENMC_E_INVALID_ARGUMENT;
9✔
1311
  }
1312

1313
  if (!settings::trigger_on) {
27✔
1314
    // Set n_batches and n_max_batches to same value
1315
    settings::n_batches = n_batches;
9✔
1316
    settings::n_max_batches = n_batches;
9✔
1317
  } else {
1318
    // Set n_batches and n_max_batches based on value of set_max_batches
1319
    if (set_max_batches) {
18✔
1320
      settings::n_max_batches = n_batches;
9✔
1321
    } else {
1322
      settings::n_batches = n_batches;
9✔
1323
    }
1324
  }
1325

1326
  // Update size of k_generation and entropy
1327
  int m = settings::n_max_batches * settings::gen_per_batch;
27✔
1328
  simulation::k_generation.reserve(m);
27✔
1329
  simulation::entropy.reserve(m);
27✔
1330

1331
  // Add value of n_batches to statepoint_batch
1332
  if (add_statepoint_batch &&
45✔
1333
      !(contains(settings::statepoint_batch, n_batches)))
18!
1334
    settings::statepoint_batch.insert(n_batches);
18✔
1335

1336
  return 0;
27✔
1337
}
1338

1339
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,070✔
1340
{
1341
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,070✔
1342

1343
  return 0;
2,070✔
1344
}
1345

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