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

openmc-dev / openmc / 22231282333

20 Feb 2026 04:04PM UTC coverage: 81.861% (-0.2%) from 82.058%
22231282333

Pull #2693

github

web-flow
Merge e5188d202 into 53ce1910f
Pull Request #2693: Add reactivity control to coupled transport-depletion analyses

17278 of 24307 branches covered (71.08%)

Branch coverage included in aggregate %.

75 of 80 new or added lines in 4 files covered. (93.75%)

3462 existing lines in 80 files now uncovered.

57630 of 67199 relevant lines covered (85.76%)

49119197.82 hits per line

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

77.59
/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

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

100
int32_t n_inactive {0};
101
int32_t max_lost_particles {10};
102
double rel_max_lost_particles {1.0e-6};
103
int32_t max_write_lost_particles {-1};
104
int32_t gen_per_batch {1};
105
int64_t n_particles {-1};
106

107
int64_t max_particles_in_flight {100000};
108
int max_particle_events {1000000};
109

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

152
} // namespace settings
153

154
//==============================================================================
155
// Functions
156
//==============================================================================
157

158
void get_run_parameters(pugi::xml_node node_base)
6,765✔
159
{
160
  using namespace settings;
161
  using namespace pugi;
162

163
  // Check number of particles
164
  if (!check_for_node(node_base, "particles")) {
6,765!
165
    fatal_error("Need to specify number of particles.");
×
166
  }
167

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

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

179
  // Get maximum number of events allowed per particle
180
  if (check_for_node(node_base, "max_particle_events")) {
6,765!
181
    max_particle_events =
×
182
      std::stoll(get_node_value(node_base, "max_particle_events"));
×
183
  }
184

185
  // Get number of basic batches
186
  if (check_for_node(node_base, "batches")) {
6,765!
187
    n_batches = std::stoi(get_node_value(node_base, "batches"));
6,765✔
188
  }
189
  if (!trigger_on)
6,765✔
190
    n_max_batches = n_batches;
6,635✔
191

192
  // Get max number of lost particles
193
  if (check_for_node(node_base, "max_lost_particles")) {
6,765✔
194
    max_lost_particles =
43✔
195
      std::stoi(get_node_value(node_base, "max_lost_particles"));
43✔
196
  }
197

198
  // Get relative number of lost particles
199
  if (check_for_node(node_base, "rel_max_lost_particles")) {
6,765!
200
    rel_max_lost_particles =
×
201
      std::stod(get_node_value(node_base, "rel_max_lost_particles"));
×
202
  }
203

204
  // Get relative number of lost particles
205
  if (check_for_node(node_base, "max_write_lost_particles")) {
6,765✔
206
    max_write_lost_particles =
14✔
207
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
14✔
208
  }
209

210
  // Get number of inactive batches
211
  if (run_mode == RunMode::EIGENVALUE ||
6,765✔
212
      solver_type == SolverType::RANDOM_RAY) {
2,541✔
213
    if (check_for_node(node_base, "inactive")) {
4,603✔
214
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,435✔
215
    }
216
    if (check_for_node(node_base, "generations_per_batch")) {
4,603✔
217
      gen_per_batch =
14✔
218
        std::stoi(get_node_value(node_base, "generations_per_batch"));
14✔
219
    }
220

221
    // Preallocate space for keff and entropy by generation
222
    int m = settings::n_max_batches * settings::gen_per_batch;
4,603✔
223
    simulation::k_generation.reserve(m);
4,603✔
224
    simulation::entropy.reserve(m);
4,603✔
225

226
    // Get the trigger information for keff
227
    if (check_for_node(node_base, "keff_trigger")) {
4,603✔
228
      xml_node node_keff_trigger = node_base.child("keff_trigger");
94✔
229

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

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

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

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

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

397
  // Get root element
398
  xml_node root = doc.document_element();
1,285✔
399

400
  // Verbosity
401
  if (check_for_node(root, "verbosity") && verbosity == -1) {
1,285!
402
    verbosity = std::stoi(get_node_value(root, "verbosity"));
165✔
403
  } else if (verbosity == -1) {
1,120!
404
    verbosity = 7;
1,120✔
405
  }
406

407
  // To this point, we haven't displayed any output since we didn't know what
408
  // the verbosity is. Now that we checked for it, show the title if necessary
409
  if (mpi::master) {
1,285✔
410
    if (verbosity >= 2)
1,105✔
411
      title();
948✔
412
  }
413

414
  write_message("Reading settings XML file...", 5);
1,285✔
415

416
  read_settings_xml(root);
1,285✔
417
}
1,296✔
418

419
void read_settings_xml(pugi::xml_node root)
7,500✔
420
{
421
  using namespace settings;
422
  using namespace pugi;
423

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

434
  // Check for user meshes and allocate
435
  read_meshes(root);
7,500✔
436

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

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

461
  // Check for a trigger node and get trigger information
462
  if (check_for_node(root, "trigger")) {
7,500✔
463
    xml_node node_trigger = root.child("trigger");
144✔
464

465
    // Check if trigger(s) are to be turned on
466
    trigger_on = get_node_value_bool(node_trigger, "active");
144✔
467

468
    if (trigger_on) {
144✔
469
      if (check_for_node(node_trigger, "max_batches")) {
130!
470
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
130✔
471
      } else {
UNCOV
472
        fatal_error("<max_batches> must be specified with triggers");
×
473
      }
474

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

488
  // Check run mode if it hasn't been set from the command line
489
  xml_node node_mode;
7,500✔
490
  if (run_mode == RunMode::UNSET) {
7,500✔
491
    if (check_for_node(root, "run_mode")) {
6,795✔
492
      std::string temp_str = get_node_value(root, "run_mode", true, true);
6,767✔
493
      if (temp_str == "eigenvalue") {
6,767✔
494
        run_mode = RunMode::EIGENVALUE;
4,196✔
495
      } else if (temp_str == "fixed source") {
2,571✔
496
        run_mode = RunMode::FIXED_SOURCE;
2,541✔
497
      } else if (temp_str == "plot") {
30!
498
        run_mode = RunMode::PLOTTING;
×
499
      } else if (temp_str == "particle restart") {
30!
UNCOV
500
        run_mode = RunMode::PARTICLE;
×
501
      } else if (temp_str == "volume") {
30!
502
        run_mode = RunMode::VOLUME;
30✔
503
      } else {
UNCOV
504
        fatal_error("Unrecognized run mode: " + temp_str);
×
505
      }
506

507
      // Assume XML specifies <particles>, <batches>, etc. directly
508
      node_mode = root;
6,767✔
509
    } else {
6,767✔
510
      warning("<run_mode> should be specified.");
28✔
511

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

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

535
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
7,500✔
536
    // Read run parameters
537
    get_run_parameters(node_mode);
6,765✔
538

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

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

568
  // Copy plotting random number seed if specified
569
  if (check_for_node(root, "plot_seed")) {
7,492!
UNCOV
570
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
UNCOV
571
    model::plotter_seed = seed;
×
572
  }
573

574
  // Copy random number seed if specified
575
  if (check_for_node(root, "seed")) {
7,492✔
576
    auto seed = std::stoll(get_node_value(root, "seed"));
528✔
577
    openmc_set_seed(seed);
528✔
578
  }
579

580
  // Copy random number stride if specified
581
  if (check_for_node(root, "stride")) {
7,492✔
582
    auto stride = std::stoull(get_node_value(root, "stride"));
14✔
583
    openmc_set_stride(stride);
14✔
584
  }
585

586
  // Check for electron treatment
587
  if (check_for_node(root, "electron_treatment")) {
7,492✔
588
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
62✔
589
    if (temp_str == "led") {
62✔
590
      electron_treatment = ElectronTreatment::LED;
10✔
591
    } else if (temp_str == "ttb") {
52!
592
      electron_treatment = ElectronTreatment::TTB;
52✔
593
    } else {
UNCOV
594
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
595
    }
596
  }
62✔
597

598
  // Check for photon transport
599
  if (check_for_node(root, "photon_transport")) {
7,492✔
600
    photon_transport = get_node_value_bool(root, "photon_transport");
176✔
601

602
    if (!run_CE && photon_transport) {
176!
UNCOV
603
      fatal_error("Photon transport is not currently supported in "
×
604
                  "multigroup mode");
605
    }
606
  }
607

608
  // Number of bins for logarithmic grid
609
  if (check_for_node(root, "log_grid_bins")) {
7,492✔
610
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
14✔
611
    if (n_log_bins < 1) {
14!
UNCOV
612
      fatal_error("Number of bins for logarithmic grid must be greater "
×
613
                  "than zero.");
614
    }
615
  }
616

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

625
  // ==========================================================================
626
  // EXTERNAL SOURCE
627

628
  // Get point to list of <source> elements and make sure there is at least one
629
  for (pugi::xml_node node : root.children("source")) {
14,471✔
630
    model::external_sources.push_back(Source::create(node));
6,988✔
631
  }
632

633
  // Check if the user has specified to read surface source
634
  if (check_for_node(root, "surf_source_read")) {
7,483✔
635
    surf_source_read = true;
28✔
636
    // Get surface source read node
637
    xml_node node_ssr = root.child("surf_source_read");
28✔
638

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

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

659
  // Build probability mass function for sampling external sources
660
  vector<double> source_strengths;
7,483✔
661
  for (auto& s : model::external_sources) {
16,399✔
662
    source_strengths.push_back(s->strength());
8,916✔
663
  }
664
  model::external_sources_probability.assign(source_strengths);
7,483✔
665

666
  // Check if we want to write out source
667
  if (check_for_node(root, "write_initial_source")) {
7,483!
UNCOV
668
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
669
  }
670

671
  // Get relative number of lost particles
672
  if (check_for_node(root, "source_rejection_fraction")) {
7,483✔
673
    source_rejection_fraction =
6✔
674
      std::stod(get_node_value(root, "source_rejection_fraction"));
6!
675
  }
676

677
  if (check_for_node(root, "free_gas_threshold")) {
7,483!
UNCOV
678
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
679
  }
680

681
  // Survival biasing
682
  if (check_for_node(root, "survival_biasing")) {
7,483✔
683
    survival_biasing = get_node_value_bool(root, "survival_biasing");
160✔
684
  }
685

686
  // Probability tables
687
  if (check_for_node(root, "ptables")) {
7,483✔
688
    urr_ptables_on = get_node_value_bool(root, "ptables");
14✔
689
  }
690

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

738
  // Particle trace
739
  if (check_for_node(root, "trace")) {
7,483✔
740
    auto temp = get_node_array<int64_t>(root, "trace");
14✔
741
    if (temp.size() != 3) {
14!
UNCOV
742
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
743
                  "batch, generation, and particle number.");
744
    }
745
    trace_batch = temp.at(0);
14✔
746
    trace_gen = temp.at(1);
14✔
747
    trace_particle = temp.at(2);
14✔
748
  }
14✔
749

750
  // Particle tracks
751
  if (check_for_node(root, "track")) {
7,483✔
752
    // Get values and make sure there are three per particle
753
    auto temp = get_node_array<int>(root, "track");
42✔
754
    if (temp.size() % 3 != 0) {
42!
UNCOV
755
      fatal_error(
×
756
        "Number of integers specified in 'track' is not "
757
        "divisible by 3.  Please provide 3 integers per particle to be "
758
        "tracked.");
759
    }
760

761
    // Reshape into track_identifiers
762
    int n_tracks = temp.size() / 3;
42✔
763
    for (int i = 0; i < n_tracks; ++i) {
168✔
764
      track_identifiers.push_back(
126✔
765
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
126✔
766
    }
767
  }
42✔
768

769
  // Shannon entropy
770
  if (solver_type == SolverType::RANDOM_RAY) {
7,483✔
771
    if (check_for_node(root, "entropy_mesh")) {
711!
UNCOV
772
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
773
                  "No user-defined entropy mesh is supported.");
774
    }
775
    entropy_on = true;
711✔
776
  } else if (solver_type == SolverType::MONTE_CARLO) {
6,772!
777
    if (check_for_node(root, "entropy_mesh")) {
6,772✔
778
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
304✔
779
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
304!
UNCOV
780
        fatal_error(fmt::format(
×
781
          "Mesh {} specified for Shannon entropy does not exist.", temp));
782
      }
783

784
      auto* m = dynamic_cast<RegularMesh*>(
304!
785
        model::meshes[model::mesh_map.at(temp)].get());
304✔
786
      if (!m)
304!
UNCOV
787
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
788
      simulation::entropy_mesh = m;
304✔
789

790
      // Turn on Shannon entropy calculation
791
      entropy_on = true;
304✔
792

793
    } else if (check_for_node(root, "entropy")) {
6,468!
UNCOV
794
      fatal_error(
×
795
        "Specifying a Shannon entropy mesh via the <entropy> element "
796
        "is deprecated. Please create a mesh using <mesh> and then reference "
797
        "it by specifying its ID in an <entropy_mesh> element.");
798
    }
799
  }
800
  // Uniform fission source weighting mesh
801
  if (check_for_node(root, "ufs_mesh")) {
7,483✔
802
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
14✔
803
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
14!
UNCOV
804
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
805
                              "method does not exist.",
806
        temp));
807
    }
808

809
    auto* m =
810
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
14!
811
    if (!m)
14!
UNCOV
812
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
813
    simulation::ufs_mesh = m;
14✔
814

815
    // Turn on uniform fission source weighting
816
    ufs_on = true;
14✔
817

818
  } else if (check_for_node(root, "uniform_fs")) {
7,469!
UNCOV
819
    fatal_error(
×
820
      "Specifying a UFS mesh via the <uniform_fs> element "
821
      "is deprecated. Please create a mesh using <mesh> and then reference "
822
      "it by specifying its ID in a <ufs_mesh> element.");
823
  }
824

825
  // Check if the user has specified to write state points
826
  if (check_for_node(root, "state_point")) {
7,483✔
827

828
    // Get pointer to state_point node
829
    auto node_sp = root.child("state_point");
148✔
830

831
    // Determine number of batches at which to store state points
832
    if (check_for_node(node_sp, "batches")) {
148!
833
      // User gave specific batches to write state points
834
      auto temp = get_node_array<int>(node_sp, "batches");
148✔
835
      for (const auto& b : temp) {
454✔
836
        statepoint_batch.insert(b);
306✔
837
      }
838
    } else {
148✔
839
      // If neither were specified, write state point at last batch
UNCOV
840
      statepoint_batch.insert(n_batches);
×
841
    }
842
  } else {
843
    // If no <state_point> tag was present, by default write state point at
844
    // last batch only
845
    statepoint_batch.insert(n_batches);
7,335✔
846
  }
847

848
  // Check if the user has specified to write source points
849
  if (check_for_node(root, "source_point")) {
7,483✔
850
    // Get source_point node
851
    xml_node node_sp = root.child("source_point");
94✔
852

853
    // Determine batches at which to store source points
854
    if (check_for_node(node_sp, "batches")) {
94✔
855
      // User gave specific batches to write source points
856
      auto temp = get_node_array<int>(node_sp, "batches");
42✔
857
      for (const auto& b : temp) {
112✔
858
        sourcepoint_batch.insert(b);
70✔
859
      }
860
    } else {
42✔
861
      // If neither were specified, write source points with state points
862
      sourcepoint_batch = statepoint_batch;
52✔
863
    }
864

865
    // Check if the user has specified to write binary source file
866
    if (check_for_node(node_sp, "separate")) {
94✔
867
      source_separate = get_node_value_bool(node_sp, "separate");
66✔
868
    }
869
    if (check_for_node(node_sp, "write")) {
94!
UNCOV
870
      source_write = get_node_value_bool(node_sp, "write");
×
871
    }
872
    if (check_for_node(node_sp, "mcpl")) {
94✔
873
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
24✔
874
    }
875
    if (check_for_node(node_sp, "overwrite_latest")) {
94✔
876
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
14✔
877
      source_separate = source_latest;
14✔
878
    }
879
  } else {
880
    // If no <source_point> tag was present, by default we keep source bank in
881
    // statepoint file and write it out at statepoints intervals
882
    source_separate = false;
7,389✔
883
    sourcepoint_batch = statepoint_batch;
7,389✔
884
  }
885

886
  // Check is the user specified to convert strength to statistical weight
887
  if (check_for_node(root, "uniform_source_sampling")) {
7,483✔
888
    uniform_source_sampling =
50✔
889
      get_node_value_bool(root, "uniform_source_sampling");
50✔
890
  }
891

892
  // Check if the user has specified to write surface source
893
  if (check_for_node(root, "surf_source_write")) {
7,483✔
894
    surf_source_write = true;
373✔
895
    // Get surface source write node
896
    xml_node node_ssw = root.child("surf_source_write");
373✔
897

898
    // Determine surface ids at which crossing particles are to be banked.
899
    // If no surfaces are specified, all surfaces in the model will be used
900
    // to bank source points.
901
    if (check_for_node(node_ssw, "surface_ids")) {
373✔
902
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
183✔
903
      for (const auto& b : temp) {
899✔
904
        source_write_surf_id.insert(b);
716✔
905
      }
906
    }
183✔
907

908
    // Get maximum number of particles to be banked per surface
909
    if (check_for_node(node_ssw, "max_particles")) {
373✔
910
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
365✔
911
    } else {
912
      fatal_error("A maximum number of particles needs to be specified "
8✔
913
                  "using the 'max_particles' parameter to store surface "
914
                  "source points.");
915
    }
916

917
    // Get maximum number of surface source files to be created
918
    if (check_for_node(node_ssw, "max_source_files")) {
365✔
919
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
30✔
920
    } else {
921
      ssw_max_files = 1;
335✔
922
    }
923

924
    if (check_for_node(node_ssw, "mcpl")) {
365✔
925
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
10✔
926
    }
927
    // Get cell information
928
    if (check_for_node(node_ssw, "cell")) {
365✔
929
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
94✔
930
      ssw_cell_type = SSWCellType::Both;
94✔
931
    }
932
    if (check_for_node(node_ssw, "cellfrom")) {
365✔
933
      if (ssw_cell_id != C_NONE) {
81✔
934
        fatal_error(
16✔
935
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
936
      }
937
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
65✔
938
      ssw_cell_type = SSWCellType::From;
65✔
939
    }
940
    if (check_for_node(node_ssw, "cellto")) {
349✔
941
      if (ssw_cell_id != C_NONE) {
64✔
942
        fatal_error(
16✔
943
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
944
      }
945
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
48✔
946
      ssw_cell_type = SSWCellType::To;
48✔
947
    }
948
  }
949

950
  // Check if the user has specified to write specific collisions
951
  if (check_for_node(root, "collision_track")) {
7,443✔
952
    settings::collision_track = true;
137✔
953
    // Get collision track node
954
    xml_node node_ct = root.child("collision_track");
137✔
955
    collision_track_config = CollisionTrackConfig {};
137✔
956

957
    // Determine cell ids at which crossing particles are to be banked
958
    if (check_for_node(node_ct, "cell_ids")) {
137✔
959
      auto temp = get_node_array<int>(node_ct, "cell_ids");
72✔
960
      for (const auto& b : temp) {
188✔
961
        collision_track_config.cell_ids.insert(b);
116✔
962
      }
963
    }
72✔
964
    if (check_for_node(node_ct, "reactions")) {
137✔
965
      auto temp = get_node_array<std::string>(node_ct, "reactions");
58✔
966
      for (const auto& b : temp) {
158✔
967
        int reaction_int = reaction_type(b);
100✔
968
        if (reaction_int > 0) {
100!
969
          collision_track_config.mt_numbers.insert(reaction_int);
100✔
970
        }
971
      }
972
    }
58✔
973
    if (check_for_node(node_ct, "universe_ids")) {
137✔
974
      auto temp = get_node_array<int>(node_ct, "universe_ids");
28✔
975
      for (const auto& b : temp) {
56✔
976
        collision_track_config.universe_ids.insert(b);
28✔
977
      }
978
    }
28✔
979
    if (check_for_node(node_ct, "material_ids")) {
137✔
980
      auto temp = get_node_array<int>(node_ct, "material_ids");
28✔
981
      for (const auto& b : temp) {
70✔
982
        collision_track_config.material_ids.insert(b);
42✔
983
      }
984
    }
28✔
985
    if (check_for_node(node_ct, "nuclides")) {
137✔
986
      auto temp = get_node_array<std::string>(node_ct, "nuclides");
28✔
987
      for (const auto& b : temp) {
112✔
988
        collision_track_config.nuclides.insert(b);
84✔
989
      }
990
    }
28✔
991
    if (check_for_node(node_ct, "deposited_E_threshold")) {
137✔
992
      collision_track_config.deposited_energy_threshold =
28✔
993
        std::stod(get_node_value(node_ct, "deposited_E_threshold"));
28✔
994
    }
995
    // Get maximum number of particles to be banked per collision
996
    if (check_for_node(node_ct, "max_collisions")) {
137!
997
      collision_track_config.max_collisions =
137✔
998
        std::stoll(get_node_value(node_ct, "max_collisions"));
137✔
999
    } else {
UNCOV
1000
      warning("A maximum number of collisions needs to be specified. "
×
1001
              "By default the code sets 'max_collisions' parameter equals to "
1002
              "1000.");
1003
    }
1004
    // Get maximum number of collision_track files to be created
1005
    if (check_for_node(node_ct, "max_collision_track_files")) {
137!
UNCOV
1006
      collision_track_config.max_files =
×
UNCOV
1007
        std::stoll(get_node_value(node_ct, "max_collision_track_files"));
×
1008
    }
1009
    if (check_for_node(node_ct, "mcpl")) {
137✔
1010
      collision_track_config.mcpl_write = get_node_value_bool(node_ct, "mcpl");
20✔
1011
    }
1012
  }
1013

1014
  // If source is not separate and is to be written out in the statepoint
1015
  // file, make sure that the sourcepoint batch numbers are contained in the
1016
  // statepoint list
1017
  if (!source_separate) {
7,443✔
1018
    for (const auto& b : sourcepoint_batch) {
14,842✔
1019
      if (!contains(statepoint_batch, b)) {
7,479!
UNCOV
1020
        fatal_error(
×
1021
          "Sourcepoint batches are not a subset of statepoint batches.");
1022
      }
1023
    }
1024
  }
1025

1026
  // Check if the user has specified to not reduce tallies at the end of every
1027
  // batch
1028
  if (check_for_node(root, "no_reduce")) {
7,443✔
1029
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
28✔
1030
  }
1031

1032
  // Check if the user has specified to use confidence intervals for
1033
  // uncertainties rather than standard deviations
1034
  if (check_for_node(root, "confidence_intervals")) {
7,443✔
1035
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
14✔
1036
  }
1037

1038
  // Check for output options
1039
  if (check_for_node(root, "output")) {
7,443✔
1040
    // Get pointer to output node
1041
    pugi::xml_node node_output = root.child("output");
693✔
1042

1043
    // Check for summary option
1044
    if (check_for_node(node_output, "summary")) {
693✔
1045
      output_summary = get_node_value_bool(node_output, "summary");
669✔
1046
    }
1047

1048
    // Check for ASCII tallies output option
1049
    if (check_for_node(node_output, "tallies")) {
693✔
1050
      output_tallies = get_node_value_bool(node_output, "tallies");
318✔
1051
    }
1052

1053
    // Set output directory if a path has been specified
1054
    if (check_for_node(node_output, "path")) {
693!
1055
      path_output = get_node_value(node_output, "path");
×
UNCOV
1056
      if (!ends_with(path_output, "/")) {
×
UNCOV
1057
        path_output += "/";
×
1058
      }
1059
    }
1060
  }
1061

1062
  // Resonance scattering parameters
1063
  if (check_for_node(root, "resonance_scattering")) {
7,443✔
1064
    xml_node node_res_scat = root.child("resonance_scattering");
14✔
1065

1066
    // See if resonance scattering is enabled
1067
    if (check_for_node(node_res_scat, "enable")) {
14!
1068
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
14✔
1069
    } else {
UNCOV
1070
      res_scat_on = true;
×
1071
    }
1072

1073
    // Determine what method is used
1074
    if (check_for_node(node_res_scat, "method")) {
14!
1075
      auto temp = get_node_value(node_res_scat, "method", true, true);
14✔
1076
      if (temp == "rvs") {
14!
1077
        res_scat_method = ResScatMethod::rvs;
14✔
UNCOV
1078
      } else if (temp == "dbrc") {
×
1079
        res_scat_method = ResScatMethod::dbrc;
×
1080
      } else {
UNCOV
1081
        fatal_error(
×
UNCOV
1082
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1083
      }
1084
    }
14✔
1085

1086
    // Minimum energy for resonance scattering
1087
    if (check_for_node(node_res_scat, "energy_min")) {
14!
1088
      res_scat_energy_min =
14✔
1089
        std::stod(get_node_value(node_res_scat, "energy_min"));
14✔
1090
    }
1091
    if (res_scat_energy_min < 0.0) {
14!
UNCOV
1092
      fatal_error("Lower resonance scattering energy bound is negative");
×
1093
    }
1094

1095
    // Maximum energy for resonance scattering
1096
    if (check_for_node(node_res_scat, "energy_max")) {
14!
1097
      res_scat_energy_max =
14✔
1098
        std::stod(get_node_value(node_res_scat, "energy_max"));
14✔
1099
    }
1100
    if (res_scat_energy_max < res_scat_energy_min) {
14!
UNCOV
1101
      fatal_error("Upper resonance scattering energy bound is below the "
×
1102
                  "lower resonance scattering energy bound.");
1103
    }
1104

1105
    // Get resonance scattering nuclides
1106
    if (check_for_node(node_res_scat, "nuclides")) {
14!
1107
      res_scat_nuclides =
1108
        get_node_array<std::string>(node_res_scat, "nuclides");
14✔
1109
    }
1110
  }
1111

1112
  // Get volume calculations
1113
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
7,734✔
1114
    model::volume_calcs.emplace_back(node_vol);
291✔
1115
  }
1116

1117
  // Get temperature settings
1118
  if (check_for_node(root, "temperature_default")) {
7,443✔
1119
    temperature_default =
156✔
1120
      std::stod(get_node_value(root, "temperature_default"));
156✔
1121
  }
1122
  if (check_for_node(root, "temperature_method")) {
7,443✔
1123
    auto temp = get_node_value(root, "temperature_method", true, true);
446✔
1124
    if (temp == "nearest") {
446✔
1125
      temperature_method = TemperatureMethod::NEAREST;
280✔
1126
    } else if (temp == "interpolation") {
166!
1127
      temperature_method = TemperatureMethod::INTERPOLATION;
166✔
1128
    } else {
UNCOV
1129
      fatal_error("Unknown temperature method: " + temp);
×
1130
    }
1131
  }
446✔
1132
  if (check_for_node(root, "temperature_tolerance")) {
7,443✔
1133
    temperature_tolerance =
311✔
1134
      std::stod(get_node_value(root, "temperature_tolerance"));
311✔
1135
  }
1136
  if (check_for_node(root, "temperature_multipole")) {
7,443✔
1137
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
170✔
1138

1139
    // Multipole currently doesn't work with photon transport
1140
    if (temperature_multipole && photon_transport) {
170!
UNCOV
1141
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1142
                  "photon transport.");
1143
    }
1144
  }
1145
  if (check_for_node(root, "temperature_range")) {
7,443✔
1146
    auto range = get_node_array<double>(root, "temperature_range");
156✔
1147
    temperature_range[0] = range.at(0);
156✔
1148
    temperature_range[1] = range.at(1);
156✔
1149
  }
156✔
1150

1151
  // Check for tabular_legendre options
1152
  if (check_for_node(root, "tabular_legendre")) {
7,443✔
1153
    // Get pointer to tabular_legendre node
1154
    xml_node node_tab_leg = root.child("tabular_legendre");
84✔
1155

1156
    // Check for enable option
1157
    if (check_for_node(node_tab_leg, "enable")) {
84!
1158
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
84✔
1159
    }
1160

1161
    // Check for the number of points
1162
    if (check_for_node(node_tab_leg, "num_points")) {
84!
1163
      legendre_to_tabular_points =
×
1164
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
UNCOV
1165
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
UNCOV
1166
        fatal_error(
×
1167
          "The 'num_points' subelement/attribute of the "
1168
          "<tabular_legendre> element must contain a value greater than 1");
1169
      }
1170
    }
1171
  }
1172

1173
  // Check whether create delayed neutrons in fission
1174
  if (check_for_node(root, "create_delayed_neutrons")) {
7,443!
UNCOV
1175
    create_delayed_neutrons =
×
UNCOV
1176
      get_node_value_bool(root, "create_delayed_neutrons");
×
1177
  }
1178

1179
  // Check whether create fission sites
1180
  if (run_mode == RunMode::FIXED_SOURCE) {
7,443✔
1181
    if (check_for_node(root, "create_fission_neutrons")) {
2,500✔
1182
      create_fission_neutrons =
255✔
1183
        get_node_value_bool(root, "create_fission_neutrons");
255✔
1184
    }
1185
  }
1186

1187
  // Check whether to scale fission photon yields
1188
  if (check_for_node(root, "delayed_photon_scaling")) {
7,443!
UNCOV
1189
    delayed_photon_scaling =
×
UNCOV
1190
      get_node_value_bool(root, "delayed_photon_scaling");
×
1191
  }
1192

1193
  // Check whether to use event-based parallelism
1194
  if (check_for_node(root, "event_based")) {
7,443!
UNCOV
1195
    event_based = get_node_value_bool(root, "event_based");
×
1196
  }
1197

1198
  // Check whether material cell offsets should be generated
1199
  if (check_for_node(root, "material_cell_offsets")) {
7,443!
UNCOV
1200
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1201
  }
1202

1203
  // Weight window information
1204
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
7,526✔
1205
    variance_reduction::weight_windows.emplace_back(
83✔
1206
      std::make_unique<WeightWindows>(node_ww));
166✔
1207
  }
1208

1209
  // Enable weight windows by default if one or more are present
1210
  if (variance_reduction::weight_windows.size() > 0)
7,443✔
1211
    settings::weight_windows_on = true;
59✔
1212

1213
  // read weight windows from file
1214
  if (check_for_node(root, "weight_windows_file")) {
7,443!
UNCOV
1215
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1216
  }
1217

1218
  // read settings for weight windows value, this will override
1219
  // the automatic setting even if weight windows are present
1220
  if (check_for_node(root, "weight_windows_on")) {
7,443✔
1221
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
35✔
1222
  }
1223

1224
  if (check_for_node(root, "max_secondaries")) {
7,443!
UNCOV
1225
    settings::max_secondaries =
×
UNCOV
1226
      std::stoi(get_node_value(root, "max_secondaries"));
×
1227
  }
1228

1229
  if (check_for_node(root, "max_history_splits")) {
7,443✔
1230
    settings::max_history_splits =
195✔
1231
      std::stoi(get_node_value(root, "max_history_splits"));
195✔
1232
  }
1233

1234
  if (check_for_node(root, "max_tracks")) {
7,443✔
1235
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
42✔
1236
  }
1237

1238
  // Create weight window generator objects
1239
  if (check_for_node(root, "weight_window_generators")) {
7,443✔
1240
    auto wwgs_node = root.child("weight_window_generators");
73✔
1241
    for (pugi::xml_node node_wwg :
73✔
1242
      wwgs_node.children("weight_windows_generator")) {
219✔
1243
      variance_reduction::weight_windows_generators.emplace_back(
73✔
1244
        std::make_unique<WeightWindowsGenerator>(node_wwg));
146✔
1245
    }
1246
    // if any of the weight windows are intended to be generated otf, make
1247
    // sure they're applied
1248
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
73!
1249
      if (wwg->on_the_fly_) {
73!
1250
        settings::weight_windows_on = true;
73✔
1251
        break;
73✔
1252
      }
1253
    }
1254
  }
1255

1256
  // Set up weight window checkpoints
1257
  if (check_for_node(root, "weight_window_checkpoints")) {
7,443✔
1258
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
16✔
1259
    if (check_for_node(ww_checkpoints, "collision")) {
16!
1260
      weight_window_checkpoint_collision =
16✔
1261
        get_node_value_bool(ww_checkpoints, "collision");
16✔
1262
    }
1263
    if (check_for_node(ww_checkpoints, "surface")) {
16!
1264
      weight_window_checkpoint_surface =
16✔
1265
        get_node_value_bool(ww_checkpoints, "surface");
16✔
1266
    }
1267
  }
1268

1269
  if (check_for_node(root, "use_decay_photons")) {
7,443✔
1270
    settings::use_decay_photons =
10✔
1271
      get_node_value_bool(root, "use_decay_photons");
10✔
1272
  }
1273
}
7,443✔
1274

1275
void free_memory_settings()
7,582✔
1276
{
1277
  settings::statepoint_batch.clear();
7,582✔
1278
  settings::sourcepoint_batch.clear();
7,582✔
1279
  settings::source_write_surf_id.clear();
7,582✔
1280
  settings::res_scat_nuclides.clear();
7,582✔
1281
}
7,582✔
1282

1283
//==============================================================================
1284
// C API functions
1285
//==============================================================================
1286

1287
extern "C" int openmc_set_n_batches(
274✔
1288
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1289
{
1290
  if (settings::n_inactive >= n_batches) {
274✔
1291
    set_errmsg("Number of active batches must be greater than zero.");
10✔
1292
    return OPENMC_E_INVALID_ARGUMENT;
10✔
1293
  }
1294

1295
  if (!settings::trigger_on) {
264✔
1296
    // Set n_batches and n_max_batches to same value
1297
    settings::n_batches = n_batches;
244✔
1298
    settings::n_max_batches = n_batches;
244✔
1299
  } else {
1300
    // Set n_batches and n_max_batches based on value of set_max_batches
1301
    if (set_max_batches) {
20✔
1302
      settings::n_max_batches = n_batches;
10✔
1303
    } else {
1304
      settings::n_batches = n_batches;
10✔
1305
    }
1306
  }
1307

1308
  // Update size of k_generation and entropy
1309
  int m = settings::n_max_batches * settings::gen_per_batch;
264✔
1310
  simulation::k_generation.reserve(m);
264✔
1311
  simulation::entropy.reserve(m);
264✔
1312

1313
  // Add value of n_batches to statepoint_batch
1314
  if (add_statepoint_batch &&
518✔
1315
      !(contains(settings::statepoint_batch, n_batches)))
254✔
1316
    settings::statepoint_batch.insert(n_batches);
75✔
1317

1318
  return 0;
264✔
1319
}
1320

1321
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,300✔
1322
{
1323
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,300✔
1324

1325
  return 0;
2,300✔
1326
}
1327

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