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

openmc-dev / openmc / 19851502091

02 Dec 2025 08:05AM UTC coverage: 82.016% (+0.1%) from 81.872%
19851502091

Pull #3413

github

web-flow
Merge d7a168452 into ef22558f4
Pull Request #3413: More interpolation types in Tabular.

16946 of 23531 branches covered (72.02%)

Branch coverage included in aggregate %.

68 of 107 new or added lines in 3 files covered. (63.55%)

1391 existing lines in 31 files now uncovered.

54939 of 64116 relevant lines covered (85.69%)

42115001.1 hits per line

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

76.6
/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 {7};
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,837✔
159
{
160
  using namespace settings;
161
  using namespace pugi;
162

163
  // Check number of particles
164
  if (!check_for_node(node_base, "particles")) {
6,837!
UNCOV
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,837!
170
    n_particles = std::stoll(get_node_value(node_base, "particles"));
6,837✔
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,837!
UNCOV
175
    max_particles_in_flight =
×
UNCOV
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,837!
UNCOV
181
    max_particle_events =
×
UNCOV
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,837!
187
    n_batches = std::stoi(get_node_value(node_base, "batches"));
6,837✔
188
  }
189
  if (!trigger_on)
6,837✔
190
    n_max_batches = n_batches;
6,691✔
191

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

198
  // Get relative number of lost particles
199
  if (check_for_node(node_base, "rel_max_lost_particles")) {
6,837!
UNCOV
200
    rel_max_lost_particles =
×
UNCOV
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,837✔
206
    max_write_lost_particles =
16✔
207
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
16✔
208
  }
209

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

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

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

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

245
      if (check_for_node(node_keff_trigger, "threshold")) {
107!
246
        keff_trigger.threshold =
107✔
247
          std::stod(get_node_value(node_keff_trigger, "threshold"));
107✔
248
        if (keff_trigger.threshold <= 0) {
107!
UNCOV
249
          fatal_error("keff trigger threshold must be positive");
×
250
        }
251
      } else {
UNCOV
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,837✔
259
    xml_node random_ray_node = node_base.child("random_ray");
577✔
260
    if (check_for_node(random_ray_node, "distance_active")) {
577!
261
      RandomRay::distance_active_ =
577✔
262
        std::stod(get_node_value(random_ray_node, "distance_active"));
577✔
263
      if (RandomRay::distance_active_ <= 0.0) {
577!
UNCOV
264
        fatal_error("Random ray active distance must be greater than 0");
×
265
      }
266
    } else {
UNCOV
267
      fatal_error("Specify random ray active distance in settings XML");
×
268
    }
269
    if (check_for_node(random_ray_node, "distance_inactive")) {
577!
270
      RandomRay::distance_inactive_ =
577✔
271
        std::stod(get_node_value(random_ray_node, "distance_inactive"));
577✔
272
      if (RandomRay::distance_inactive_ < 0) {
577!
273
        fatal_error(
×
274
          "Random ray inactive distance must be greater than or equal to 0");
275
      }
276
    } else {
UNCOV
277
      fatal_error("Specify random ray inactive distance in settings XML");
×
278
    }
279
    if (check_for_node(random_ray_node, "source")) {
577!
280
      xml_node source_node = random_ray_node.child("source");
577✔
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);
577✔
284
    } else {
UNCOV
285
      fatal_error("Specify random ray source in settings XML");
×
286
    }
287
    if (check_for_node(random_ray_node, "volume_estimator")) {
577✔
288
      std::string temp_str =
289
        get_node_value(random_ray_node, "volume_estimator", true, true);
129✔
290
      if (temp_str == "simulation_averaged") {
129✔
291
        FlatSourceDomain::volume_estimator_ =
32✔
292
          RandomRayVolumeEstimator::SIMULATION_AVERAGED;
293
      } else if (temp_str == "naive") {
97✔
294
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::NAIVE;
65✔
295
      } else if (temp_str == "hybrid") {
32!
296
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::HYBRID;
32✔
297
      } else {
UNCOV
298
        fatal_error("Unrecognized volume estimator: " + temp_str);
×
299
      }
300
    }
129✔
301
    if (check_for_node(random_ray_node, "source_shape")) {
577✔
302
      std::string temp_str =
303
        get_node_value(random_ray_node, "source_shape", true, true);
304✔
304
      if (temp_str == "flat") {
304✔
305
        RandomRay::source_shape_ = RandomRaySourceShape::FLAT;
64✔
306
      } else if (temp_str == "linear") {
240✔
307
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR;
192✔
308
      } else if (temp_str == "linear_xy") {
48!
309
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR_XY;
48✔
310
      } else {
UNCOV
311
        fatal_error("Unrecognized source shape: " + temp_str);
×
312
      }
313
    }
304✔
314
    if (check_for_node(random_ray_node, "volume_normalized_flux_tallies")) {
577✔
315
      FlatSourceDomain::volume_normalized_flux_tallies_ =
496✔
316
        get_node_value_bool(random_ray_node, "volume_normalized_flux_tallies");
496✔
317
    }
318
    if (check_for_node(random_ray_node, "adjoint")) {
577✔
319
      FlatSourceDomain::adjoint_ =
32✔
320
        get_node_value_bool(random_ray_node, "adjoint");
32✔
321
    }
322
    if (check_for_node(random_ray_node, "sample_method")) {
577✔
323
      std::string temp_str =
324
        get_node_value(random_ray_node, "sample_method", true, true);
16✔
325
      if (temp_str == "prng") {
16!
326
        RandomRay::sample_method_ = RandomRaySampleMethod::PRNG;
×
327
      } else if (temp_str == "halton") {
16!
328
        RandomRay::sample_method_ = RandomRaySampleMethod::HALTON;
16✔
329
      } else {
UNCOV
330
        fatal_error("Unrecognized sample method: " + temp_str);
×
331
      }
332
    }
16✔
333
    if (check_for_node(random_ray_node, "source_region_meshes")) {
577✔
334
      pugi::xml_node node_source_region_meshes =
335
        random_ray_node.child("source_region_meshes");
161✔
336
      for (pugi::xml_node node_mesh :
161✔
337
        node_source_region_meshes.children("mesh")) {
547✔
338
        int mesh_id = std::stoi(node_mesh.attribute("id").value());
225✔
339
        for (pugi::xml_node node_domain : node_mesh.children("domain")) {
450✔
340
          int domain_id = std::stoi(node_domain.attribute("id").value());
225✔
341
          std::string domain_type = node_domain.attribute("type").value();
225✔
342
          Source::DomainType type;
343
          if (domain_type == "material") {
225✔
344
            type = Source::DomainType::MATERIAL;
32✔
345
          } else if (domain_type == "cell") {
193✔
346
            type = Source::DomainType::CELL;
32✔
347
          } else if (domain_type == "universe") {
161!
348
            type = Source::DomainType::UNIVERSE;
161✔
349
          } else {
UNCOV
350
            throw std::runtime_error("Unknown domain type: " + domain_type);
×
351
          }
352
          FlatSourceDomain::mesh_domain_map_[mesh_id].emplace_back(
225✔
353
            type, domain_id);
354
        }
225✔
355
      }
356
    }
357
    if (check_for_node(random_ray_node, "diagonal_stabilization_rho")) {
577✔
358
      FlatSourceDomain::diagonal_stabilization_rho_ = std::stod(
16✔
359
        get_node_value(random_ray_node, "diagonal_stabilization_rho"));
32✔
360
      if (FlatSourceDomain::diagonal_stabilization_rho_ < 0.0 ||
16!
361
          FlatSourceDomain::diagonal_stabilization_rho_ > 1.0) {
16!
UNCOV
362
        fatal_error("Random ray diagonal stabilization rho factor must be "
×
363
                    "between 0 and 1");
364
      }
365
    }
366
  }
367
}
6,837✔
368

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

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

395
  // Get root element
396
  xml_node root = doc.document_element();
1,359✔
397

398
  // Verbosity
399
  if (check_for_node(root, "verbosity")) {
1,359✔
400
    verbosity = std::stoi(get_node_value(root, "verbosity"));
182✔
401
  }
402

403
  // To this point, we haven't displayed any output since we didn't know what
404
  // the verbosity is. Now that we checked for it, show the title if necessary
405
  if (mpi::master) {
1,359✔
406
    if (verbosity >= 2)
1,134✔
407
      title();
962✔
408
  }
409

410
  write_message("Reading settings XML file...", 5);
1,359✔
411

412
  read_settings_xml(root);
1,359✔
413
}
1,371✔
414

415
void read_settings_xml(pugi::xml_node root)
7,414✔
416
{
417
  using namespace settings;
418
  using namespace pugi;
419

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

430
  // Check for user meshes and allocate
431
  read_meshes(root);
7,414✔
432

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

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

457
  // Check for a trigger node and get trigger information
458
  if (check_for_node(root, "trigger")) {
7,414✔
459
    xml_node node_trigger = root.child("trigger");
162✔
460

461
    // Check if trigger(s) are to be turned on
462
    trigger_on = get_node_value_bool(node_trigger, "active");
162✔
463

464
    if (trigger_on) {
162✔
465
      if (check_for_node(node_trigger, "max_batches")) {
146!
466
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
146✔
467
      } else {
UNCOV
468
        fatal_error("<max_batches> must be specified with triggers");
×
469
      }
470

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

484
  // Check run mode if it hasn't been set from the command line
485
  xml_node node_mode;
7,414✔
486
  if (run_mode == RunMode::UNSET) {
7,414✔
487
    if (check_for_node(root, "run_mode")) {
6,869✔
488
      std::string temp_str = get_node_value(root, "run_mode", true, true);
6,837✔
489
      if (temp_str == "eigenvalue") {
6,837✔
490
        run_mode = RunMode::EIGENVALUE;
4,260✔
491
      } else if (temp_str == "fixed source") {
2,577✔
492
        run_mode = RunMode::FIXED_SOURCE;
2,545✔
493
      } else if (temp_str == "plot") {
32!
UNCOV
494
        run_mode = RunMode::PLOTTING;
×
495
      } else if (temp_str == "particle restart") {
32!
496
        run_mode = RunMode::PARTICLE;
×
497
      } else if (temp_str == "volume") {
32!
498
        run_mode = RunMode::VOLUME;
32✔
499
      } else {
UNCOV
500
        fatal_error("Unrecognized run mode: " + temp_str);
×
501
      }
502

503
      // Assume XML specifies <particles>, <batches>, etc. directly
504
      node_mode = root;
6,837✔
505
    } else {
6,837✔
506
      warning("<run_mode> should be specified.");
32✔
507

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

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

531
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
7,414✔
532
    // Read run parameters
533
    get_run_parameters(node_mode);
6,837✔
534

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

550
  // Copy plotting random number seed if specified
551
  if (check_for_node(root, "plot_seed")) {
7,414!
UNCOV
552
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
UNCOV
553
    model::plotter_seed = seed;
×
554
  }
555

556
  // Copy random number seed if specified
557
  if (check_for_node(root, "seed")) {
7,414✔
558
    auto seed = std::stoll(get_node_value(root, "seed"));
589✔
559
    openmc_set_seed(seed);
589✔
560
  }
561

562
  // Copy random number stride if specified
563
  if (check_for_node(root, "stride")) {
7,414✔
564
    auto stride = std::stoull(get_node_value(root, "stride"));
16✔
565
    openmc_set_stride(stride);
16✔
566
  }
567

568
  // Check for electron treatment
569
  if (check_for_node(root, "electron_treatment")) {
7,414✔
570
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
70✔
571
    if (temp_str == "led") {
70✔
572
      electron_treatment = ElectronTreatment::LED;
11✔
573
    } else if (temp_str == "ttb") {
59!
574
      electron_treatment = ElectronTreatment::TTB;
59✔
575
    } else {
UNCOV
576
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
577
    }
578
  }
70✔
579

580
  // Check for photon transport
581
  if (check_for_node(root, "photon_transport")) {
7,414✔
582
    photon_transport = get_node_value_bool(root, "photon_transport");
199✔
583

584
    if (!run_CE && photon_transport) {
199!
UNCOV
585
      fatal_error("Photon transport is not currently supported in "
×
586
                  "multigroup mode");
587
    }
588
  }
589

590
  // Number of bins for logarithmic grid
591
  if (check_for_node(root, "log_grid_bins")) {
7,414✔
592
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
16✔
593
    if (n_log_bins < 1) {
16!
UNCOV
594
      fatal_error("Number of bins for logarithmic grid must be greater "
×
595
                  "than zero.");
596
    }
597
  }
598

599
  // Number of OpenMP threads
600
  if (check_for_node(root, "threads")) {
7,414!
UNCOV
601
    if (mpi::master)
×
UNCOV
602
      warning("The <threads> element has been deprecated. Use "
×
603
              "the OMP_NUM_THREADS environment variable to set the number of "
604
              "threads.");
605
  }
606

607
  // ==========================================================================
608
  // EXTERNAL SOURCE
609

610
  // Get point to list of <source> elements and make sure there is at least one
611
  for (pugi::xml_node node : root.children("source")) {
14,184✔
612
    model::external_sources.push_back(Source::create(node));
6,780✔
613
  }
614

615
  // Check if the user has specified to read surface source
616
  if (check_for_node(root, "surf_source_read")) {
7,404✔
617
    surf_source_read = true;
32✔
618
    // Get surface source read node
619
    xml_node node_ssr = root.child("surf_source_read");
32✔
620

621
    std::string path = "surface_source.h5";
32✔
622
    // Check if the user has specified different file for surface source reading
623
    if (check_for_node(node_ssr, "path")) {
32!
624
      path = get_node_value(node_ssr, "path", false, true);
32✔
625
    }
626
    model::external_sources.push_back(make_unique<FileSource>(path));
32✔
627
  }
32✔
628

629
  // If no source specified, default to isotropic point source at origin with
630
  // Watt spectrum. No default source is needed in random ray mode.
631
  if (model::external_sources.empty() &&
9,482✔
632
      settings::solver_type != SolverType::RANDOM_RAY) {
2,078✔
633
    double T[] {0.0};
1,966✔
634
    double p[] {1.0};
1,966✔
635
    model::external_sources.push_back(make_unique<IndependentSource>(
1,966✔
636
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
3,932✔
637
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
3,932✔
638
      UPtrDist {new Discrete(T, p, 1)}));
3,932✔
639
  }
640

641
  // Build probability mass function for sampling external sources
642
  vector<double> source_strengths;
7,404✔
643
  for (auto& s : model::external_sources) {
16,172✔
644
    source_strengths.push_back(s->strength());
8,768✔
645
  }
646
  model::external_sources_probability.assign(source_strengths);
7,404✔
647

648
  // Check if we want to write out source
649
  if (check_for_node(root, "write_initial_source")) {
7,404!
UNCOV
650
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
651
  }
652

653
  // Get relative number of lost particles
654
  if (check_for_node(root, "source_rejection_fraction")) {
7,404✔
655
    source_rejection_fraction =
6✔
656
      std::stod(get_node_value(root, "source_rejection_fraction"));
6!
657
  }
658

659
  if (check_for_node(root, "free_gas_threshold")) {
7,404!
UNCOV
660
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
661
  }
662

663
  // Survival biasing
664
  if (check_for_node(root, "survival_biasing")) {
7,404✔
665
    survival_biasing = get_node_value_bool(root, "survival_biasing");
177✔
666
  }
667

668
  // Probability tables
669
  if (check_for_node(root, "ptables")) {
7,404✔
670
    urr_ptables_on = get_node_value_bool(root, "ptables");
16✔
671
  }
672

673
  // Cutoffs
674
  if (check_for_node(root, "cutoff")) {
7,404✔
675
    xml_node node_cutoff = root.child("cutoff");
145✔
676
    if (check_for_node(node_cutoff, "weight")) {
145✔
677
      weight_cutoff = std::stod(get_node_value(node_cutoff, "weight"));
16✔
678
    }
679
    if (check_for_node(node_cutoff, "weight_avg")) {
145✔
680
      weight_survive = std::stod(get_node_value(node_cutoff, "weight_avg"));
16✔
681
    }
682
    if (check_for_node(node_cutoff, "survival_normalization")) {
145!
UNCOV
683
      survival_normalization =
×
UNCOV
684
        get_node_value_bool(node_cutoff, "survival_normalization");
×
685
    }
686
    if (check_for_node(node_cutoff, "energy_neutron")) {
145✔
687
      energy_cutoff[0] =
32✔
688
        std::stod(get_node_value(node_cutoff, "energy_neutron"));
16✔
689
    } else if (check_for_node(node_cutoff, "energy")) {
129!
UNCOV
690
      warning("The use of an <energy> cutoff is deprecated and should "
×
691
              "be replaced by <energy_neutron>.");
UNCOV
692
      energy_cutoff[0] = std::stod(get_node_value(node_cutoff, "energy"));
×
693
    }
694
    if (check_for_node(node_cutoff, "energy_photon")) {
145✔
695
      energy_cutoff[1] =
172✔
696
        std::stod(get_node_value(node_cutoff, "energy_photon"));
86✔
697
    }
698
    if (check_for_node(node_cutoff, "energy_electron")) {
145!
699
      energy_cutoff[2] =
×
700
        std::stof(get_node_value(node_cutoff, "energy_electron"));
×
701
    }
702
    if (check_for_node(node_cutoff, "energy_positron")) {
145!
UNCOV
703
      energy_cutoff[3] =
×
UNCOV
704
        std::stod(get_node_value(node_cutoff, "energy_positron"));
×
705
    }
706
    if (check_for_node(node_cutoff, "time_neutron")) {
145✔
707
      time_cutoff[0] = std::stod(get_node_value(node_cutoff, "time_neutron"));
27✔
708
    }
709
    if (check_for_node(node_cutoff, "time_photon")) {
145!
UNCOV
710
      time_cutoff[1] = std::stod(get_node_value(node_cutoff, "time_photon"));
×
711
    }
712
    if (check_for_node(node_cutoff, "time_electron")) {
145!
UNCOV
713
      time_cutoff[2] = std::stod(get_node_value(node_cutoff, "time_electron"));
×
714
    }
715
    if (check_for_node(node_cutoff, "time_positron")) {
145!
UNCOV
716
      time_cutoff[3] = std::stod(get_node_value(node_cutoff, "time_positron"));
×
717
    }
718
  }
719

720
  // Particle trace
721
  if (check_for_node(root, "trace")) {
7,404✔
722
    auto temp = get_node_array<int64_t>(root, "trace");
16✔
723
    if (temp.size() != 3) {
16!
UNCOV
724
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
725
                  "batch, generation, and particle number.");
726
    }
727
    trace_batch = temp.at(0);
16✔
728
    trace_gen = temp.at(1);
16✔
729
    trace_particle = temp.at(2);
16✔
730
  }
16✔
731

732
  // Particle tracks
733
  if (check_for_node(root, "track")) {
7,404✔
734
    // Get values and make sure there are three per particle
735
    auto temp = get_node_array<int>(root, "track");
48✔
736
    if (temp.size() % 3 != 0) {
48!
UNCOV
737
      fatal_error(
×
738
        "Number of integers specified in 'track' is not "
739
        "divisible by 3.  Please provide 3 integers per particle to be "
740
        "tracked.");
741
    }
742

743
    // Reshape into track_identifiers
744
    int n_tracks = temp.size() / 3;
48✔
745
    for (int i = 0; i < n_tracks; ++i) {
192✔
746
      track_identifiers.push_back(
144✔
747
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
144✔
748
    }
749
  }
48✔
750

751
  // Shannon entropy
752
  if (solver_type == SolverType::RANDOM_RAY) {
7,404✔
753
    if (check_for_node(root, "entropy_mesh")) {
577!
UNCOV
754
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
755
                  "No user-defined entropy mesh is supported.");
756
    }
757
    entropy_on = true;
577✔
758
  } else if (solver_type == SolverType::MONTE_CARLO) {
6,827!
759
    if (check_for_node(root, "entropy_mesh")) {
6,827✔
760
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
335✔
761
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
335!
UNCOV
762
        fatal_error(fmt::format(
×
763
          "Mesh {} specified for Shannon entropy does not exist.", temp));
764
      }
765

766
      auto* m = dynamic_cast<RegularMesh*>(
335!
767
        model::meshes[model::mesh_map.at(temp)].get());
335✔
768
      if (!m)
335!
UNCOV
769
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
770
      simulation::entropy_mesh = m;
335✔
771

772
      // Turn on Shannon entropy calculation
773
      entropy_on = true;
335✔
774

775
    } else if (check_for_node(root, "entropy")) {
6,492!
UNCOV
776
      fatal_error(
×
777
        "Specifying a Shannon entropy mesh via the <entropy> element "
778
        "is deprecated. Please create a mesh using <mesh> and then reference "
779
        "it by specifying its ID in an <entropy_mesh> element.");
780
    }
781
  }
782
  // Uniform fission source weighting mesh
783
  if (check_for_node(root, "ufs_mesh")) {
7,404✔
784
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
16✔
785
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
16!
UNCOV
786
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
787
                              "method does not exist.",
788
        temp));
789
    }
790

791
    auto* m =
792
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
16!
793
    if (!m)
16!
UNCOV
794
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
795
    simulation::ufs_mesh = m;
16✔
796

797
    // Turn on uniform fission source weighting
798
    ufs_on = true;
16✔
799

800
  } else if (check_for_node(root, "uniform_fs")) {
7,388!
UNCOV
801
    fatal_error(
×
802
      "Specifying a UFS mesh via the <uniform_fs> element "
803
      "is deprecated. Please create a mesh using <mesh> and then reference "
804
      "it by specifying its ID in a <ufs_mesh> element.");
805
  }
806

807
  // Check if the user has specified to write state points
808
  if (check_for_node(root, "state_point")) {
7,404✔
809

810
    // Get pointer to state_point node
811
    auto node_sp = root.child("state_point");
167✔
812

813
    // Determine number of batches at which to store state points
814
    if (check_for_node(node_sp, "batches")) {
167!
815
      // User gave specific batches to write state points
816
      auto temp = get_node_array<int>(node_sp, "batches");
167✔
817
      for (const auto& b : temp) {
512✔
818
        statepoint_batch.insert(b);
345✔
819
      }
820
    } else {
167✔
821
      // If neither were specified, write state point at last batch
UNCOV
822
      statepoint_batch.insert(n_batches);
×
823
    }
824
  } else {
825
    // If no <state_point> tag was present, by default write state point at
826
    // last batch only
827
    statepoint_batch.insert(n_batches);
7,237✔
828
  }
829

830
  // Check if the user has specified to write source points
831
  if (check_for_node(root, "source_point")) {
7,404✔
832
    // Get source_point node
833
    xml_node node_sp = root.child("source_point");
107✔
834

835
    // Determine batches at which to store source points
836
    if (check_for_node(node_sp, "batches")) {
107✔
837
      // User gave specific batches to write source points
838
      auto temp = get_node_array<int>(node_sp, "batches");
48✔
839
      for (const auto& b : temp) {
128✔
840
        sourcepoint_batch.insert(b);
80✔
841
      }
842
    } else {
48✔
843
      // If neither were specified, write source points with state points
844
      sourcepoint_batch = statepoint_batch;
59✔
845
    }
846

847
    // Check if the user has specified to write binary source file
848
    if (check_for_node(node_sp, "separate")) {
107✔
849
      source_separate = get_node_value_bool(node_sp, "separate");
75✔
850
    }
851
    if (check_for_node(node_sp, "write")) {
107!
UNCOV
852
      source_write = get_node_value_bool(node_sp, "write");
×
853
    }
854
    if (check_for_node(node_sp, "mcpl")) {
107✔
855
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
27✔
856
    }
857
    if (check_for_node(node_sp, "overwrite_latest")) {
107✔
858
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
16✔
859
      source_separate = source_latest;
16✔
860
    }
861
  } else {
862
    // If no <source_point> tag was present, by default we keep source bank in
863
    // statepoint file and write it out at statepoints intervals
864
    source_separate = false;
7,297✔
865
    sourcepoint_batch = statepoint_batch;
7,297✔
866
  }
867

868
  // Check is the user specified to convert strength to statistical weight
869
  if (check_for_node(root, "uniform_source_sampling")) {
7,404✔
870
    uniform_source_sampling =
55✔
871
      get_node_value_bool(root, "uniform_source_sampling");
55✔
872
  }
873

874
  // Check if the user has specified to write surface source
875
  if (check_for_node(root, "surf_source_write")) {
7,404✔
876
    surf_source_write = true;
412✔
877
    // Get surface source write node
878
    xml_node node_ssw = root.child("surf_source_write");
412✔
879

880
    // Determine surface ids at which crossing particles are to be banked.
881
    // If no surfaces are specified, all surfaces in the model will be used
882
    // to bank source points.
883
    if (check_for_node(node_ssw, "surface_ids")) {
412✔
884
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
202✔
885
      for (const auto& b : temp) {
994✔
886
        source_write_surf_id.insert(b);
792✔
887
      }
888
    }
202✔
889

890
    // Get maximum number of particles to be banked per surface
891
    if (check_for_node(node_ssw, "max_particles")) {
412✔
892
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
403✔
893
    } else {
894
      fatal_error("A maximum number of particles needs to be specified "
9✔
895
                  "using the 'max_particles' parameter to store surface "
896
                  "source points.");
897
    }
898

899
    // Get maximum number of surface source files to be created
900
    if (check_for_node(node_ssw, "max_source_files")) {
403✔
901
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
33✔
902
    } else {
903
      ssw_max_files = 1;
370✔
904
    }
905

906
    if (check_for_node(node_ssw, "mcpl")) {
403✔
907
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
11✔
908
    }
909
    // Get cell information
910
    if (check_for_node(node_ssw, "cell")) {
403✔
911
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
104✔
912
      ssw_cell_type = SSWCellType::Both;
104✔
913
    }
914
    if (check_for_node(node_ssw, "cellfrom")) {
403✔
915
      if (ssw_cell_id != C_NONE) {
90✔
916
        fatal_error(
18✔
917
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
918
      }
919
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
72✔
920
      ssw_cell_type = SSWCellType::From;
72✔
921
    }
922
    if (check_for_node(node_ssw, "cellto")) {
385✔
923
      if (ssw_cell_id != C_NONE) {
71✔
924
        fatal_error(
18✔
925
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
926
      }
927
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
53✔
928
      ssw_cell_type = SSWCellType::To;
53✔
929
    }
930
  }
931

932
  // Check if the user has specified to write specific collisions
933
  if (check_for_node(root, "collision_track")) {
7,359✔
934
    settings::collision_track = true;
155✔
935
    // Get collision track node
936
    xml_node node_ct = root.child("collision_track");
155✔
937
    collision_track_config = CollisionTrackConfig {};
155✔
938

939
    // Determine cell ids at which crossing particles are to be banked
940
    if (check_for_node(node_ct, "cell_ids")) {
155✔
941
      auto temp = get_node_array<int>(node_ct, "cell_ids");
81✔
942
      for (const auto& b : temp) {
211✔
943
        collision_track_config.cell_ids.insert(b);
130✔
944
      }
945
    }
81✔
946
    if (check_for_node(node_ct, "reactions")) {
155✔
947
      auto temp = get_node_array<std::string>(node_ct, "reactions");
65✔
948
      for (const auto& b : temp) {
178✔
949
        int reaction_int = reaction_type(b);
113✔
950
        if (reaction_int > 0) {
113!
951
          collision_track_config.mt_numbers.insert(reaction_int);
113✔
952
        }
953
      }
954
    }
65✔
955
    if (check_for_node(node_ct, "universe_ids")) {
155✔
956
      auto temp = get_node_array<int>(node_ct, "universe_ids");
32✔
957
      for (const auto& b : temp) {
64✔
958
        collision_track_config.universe_ids.insert(b);
32✔
959
      }
960
    }
32✔
961
    if (check_for_node(node_ct, "material_ids")) {
155✔
962
      auto temp = get_node_array<int>(node_ct, "material_ids");
32✔
963
      for (const auto& b : temp) {
80✔
964
        collision_track_config.material_ids.insert(b);
48✔
965
      }
966
    }
32✔
967
    if (check_for_node(node_ct, "nuclides")) {
155✔
968
      auto temp = get_node_array<std::string>(node_ct, "nuclides");
32✔
969
      for (const auto& b : temp) {
128✔
970
        collision_track_config.nuclides.insert(b);
96✔
971
      }
972
    }
32✔
973
    if (check_for_node(node_ct, "deposited_E_threshold")) {
155✔
974
      collision_track_config.deposited_energy_threshold =
32✔
975
        std::stod(get_node_value(node_ct, "deposited_E_threshold"));
32✔
976
    }
977
    // Get maximum number of particles to be banked per collision
978
    if (check_for_node(node_ct, "max_collisions")) {
155!
979
      collision_track_config.max_collisions =
155✔
980
        std::stoll(get_node_value(node_ct, "max_collisions"));
155✔
981
    } else {
UNCOV
982
      warning("A maximum number of collisions needs to be specified. "
×
983
              "By default the code sets 'max_collisions' parameter equals to "
984
              "1000.");
985
    }
986
    // Get maximum number of collision_track files to be created
987
    if (check_for_node(node_ct, "max_collision_track_files")) {
155!
UNCOV
988
      collision_track_config.max_files =
×
UNCOV
989
        std::stoll(get_node_value(node_ct, "max_collision_track_files"));
×
990
    }
991
    if (check_for_node(node_ct, "mcpl")) {
155✔
992
      collision_track_config.mcpl_write = get_node_value_bool(node_ct, "mcpl");
22✔
993
    }
994
  }
995

996
  // If source is not separate and is to be written out in the statepoint
997
  // file, make sure that the sourcepoint batch numbers are contained in the
998
  // statepoint list
999
  if (!source_separate) {
7,359✔
1000
    for (const auto& b : sourcepoint_batch) {
14,666✔
1001
      if (!contains(statepoint_batch, b)) {
7,398!
UNCOV
1002
        fatal_error(
×
1003
          "Sourcepoint batches are not a subset of statepoint batches.");
1004
      }
1005
    }
1006
  }
1007

1008
  // Check if the user has specified to not reduce tallies at the end of every
1009
  // batch
1010
  if (check_for_node(root, "no_reduce")) {
7,359✔
1011
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
32✔
1012
  }
1013

1014
  // Check if the user has specified to use confidence intervals for
1015
  // uncertainties rather than standard deviations
1016
  if (check_for_node(root, "confidence_intervals")) {
7,359✔
1017
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
16✔
1018
  }
1019

1020
  // Check for output options
1021
  if (check_for_node(root, "output")) {
7,359✔
1022
    // Get pointer to output node
1023
    pugi::xml_node node_output = root.child("output");
518✔
1024

1025
    // Check for summary option
1026
    if (check_for_node(node_output, "summary")) {
518✔
1027
      output_summary = get_node_value_bool(node_output, "summary");
491✔
1028
    }
1029

1030
    // Check for ASCII tallies output option
1031
    if (check_for_node(node_output, "tallies")) {
518✔
1032
      output_tallies = get_node_value_bool(node_output, "tallies");
96✔
1033
    }
1034

1035
    // Set output directory if a path has been specified
1036
    if (check_for_node(node_output, "path")) {
518!
UNCOV
1037
      path_output = get_node_value(node_output, "path");
×
UNCOV
1038
      if (!ends_with(path_output, "/")) {
×
UNCOV
1039
        path_output += "/";
×
1040
      }
1041
    }
1042
  }
1043

1044
  // Resonance scattering parameters
1045
  if (check_for_node(root, "resonance_scattering")) {
7,359✔
1046
    xml_node node_res_scat = root.child("resonance_scattering");
16✔
1047

1048
    // See if resonance scattering is enabled
1049
    if (check_for_node(node_res_scat, "enable")) {
16!
1050
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
16✔
1051
    } else {
UNCOV
1052
      res_scat_on = true;
×
1053
    }
1054

1055
    // Determine what method is used
1056
    if (check_for_node(node_res_scat, "method")) {
16!
1057
      auto temp = get_node_value(node_res_scat, "method", true, true);
16✔
1058
      if (temp == "rvs") {
16!
1059
        res_scat_method = ResScatMethod::rvs;
16✔
1060
      } else if (temp == "dbrc") {
×
1061
        res_scat_method = ResScatMethod::dbrc;
×
1062
      } else {
1063
        fatal_error(
×
UNCOV
1064
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1065
      }
1066
    }
16✔
1067

1068
    // Minimum energy for resonance scattering
1069
    if (check_for_node(node_res_scat, "energy_min")) {
16!
1070
      res_scat_energy_min =
16✔
1071
        std::stod(get_node_value(node_res_scat, "energy_min"));
16✔
1072
    }
1073
    if (res_scat_energy_min < 0.0) {
16!
UNCOV
1074
      fatal_error("Lower resonance scattering energy bound is negative");
×
1075
    }
1076

1077
    // Maximum energy for resonance scattering
1078
    if (check_for_node(node_res_scat, "energy_max")) {
16!
1079
      res_scat_energy_max =
16✔
1080
        std::stod(get_node_value(node_res_scat, "energy_max"));
16✔
1081
    }
1082
    if (res_scat_energy_max < res_scat_energy_min) {
16!
UNCOV
1083
      fatal_error("Upper resonance scattering energy bound is below the "
×
1084
                  "lower resonance scattering energy bound.");
1085
    }
1086

1087
    // Get resonance scattering nuclides
1088
    if (check_for_node(node_res_scat, "nuclides")) {
16!
1089
      res_scat_nuclides =
1090
        get_node_array<std::string>(node_res_scat, "nuclides");
16✔
1091
    }
1092
  }
1093

1094
  // Get volume calculations
1095
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
7,685✔
1096
    model::volume_calcs.emplace_back(node_vol);
326✔
1097
  }
1098

1099
  // Get temperature settings
1100
  if (check_for_node(root, "temperature_default")) {
7,359✔
1101
    temperature_default =
172✔
1102
      std::stod(get_node_value(root, "temperature_default"));
172✔
1103
  }
1104
  if (check_for_node(root, "temperature_method")) {
7,359✔
1105
    auto temp = get_node_value(root, "temperature_method", true, true);
325✔
1106
    if (temp == "nearest") {
325✔
1107
      temperature_method = TemperatureMethod::NEAREST;
140✔
1108
    } else if (temp == "interpolation") {
185!
1109
      temperature_method = TemperatureMethod::INTERPOLATION;
185✔
1110
    } else {
UNCOV
1111
      fatal_error("Unknown temperature method: " + temp);
×
1112
    }
1113
  }
325✔
1114
  if (check_for_node(root, "temperature_tolerance")) {
7,359✔
1115
    temperature_tolerance =
171✔
1116
      std::stod(get_node_value(root, "temperature_tolerance"));
171✔
1117
  }
1118
  if (check_for_node(root, "temperature_multipole")) {
7,359✔
1119
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
32✔
1120

1121
    // Multipole currently doesn't work with photon transport
1122
    if (temperature_multipole && photon_transport) {
32!
1123
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1124
                  "photon transport.");
1125
    }
1126
  }
1127
  if (check_for_node(root, "temperature_range")) {
7,359!
1128
    auto range = get_node_array<double>(root, "temperature_range");
×
UNCOV
1129
    temperature_range[0] = range.at(0);
×
UNCOV
1130
    temperature_range[1] = range.at(1);
×
UNCOV
1131
  }
×
1132

1133
  // Check for user value for the number of generation of the Iterated Fission
1134
  // Probability (IFP) method
1135
  if (check_for_node(root, "ifp_n_generation")) {
7,359✔
1136
    ifp_n_generation = std::stoi(get_node_value(root, "ifp_n_generation"));
85✔
1137
    if (ifp_n_generation <= 0) {
85!
UNCOV
1138
      fatal_error("'ifp_n_generation' must be greater than 0.");
×
1139
    }
1140
    // Avoid tallying 0 if IFP logs are not complete when active cycles start
1141
    if (ifp_n_generation > n_inactive) {
85✔
1142
      fatal_error("'ifp_n_generation' must be lower than or equal to the "
9✔
1143
                  "number of inactive cycles.");
1144
    }
1145
  }
1146

1147
  // Check for tabular_legendre options
1148
  if (check_for_node(root, "tabular_legendre")) {
7,350✔
1149
    // Get pointer to tabular_legendre node
1150
    xml_node node_tab_leg = root.child("tabular_legendre");
96✔
1151

1152
    // Check for enable option
1153
    if (check_for_node(node_tab_leg, "enable")) {
96!
1154
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
96✔
1155
    }
1156

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

1169
  // Check whether create delayed neutrons in fission
1170
  if (check_for_node(root, "create_delayed_neutrons")) {
7,350!
UNCOV
1171
    create_delayed_neutrons =
×
UNCOV
1172
      get_node_value_bool(root, "create_delayed_neutrons");
×
1173
  }
1174

1175
  // Check whether create fission sites
1176
  if (run_mode == RunMode::FIXED_SOURCE) {
7,350✔
1177
    if (check_for_node(root, "create_fission_neutrons")) {
2,499✔
1178
      create_fission_neutrons =
16✔
1179
        get_node_value_bool(root, "create_fission_neutrons");
16✔
1180
    }
1181
  }
1182

1183
  // Check whether to scale fission photon yields
1184
  if (check_for_node(root, "delayed_photon_scaling")) {
7,350!
UNCOV
1185
    delayed_photon_scaling =
×
UNCOV
1186
      get_node_value_bool(root, "delayed_photon_scaling");
×
1187
  }
1188

1189
  // Check whether to use event-based parallelism
1190
  if (check_for_node(root, "event_based")) {
7,350!
UNCOV
1191
    event_based = get_node_value_bool(root, "event_based");
×
1192
  }
1193

1194
  // Check whether material cell offsets should be generated
1195
  if (check_for_node(root, "material_cell_offsets")) {
7,350!
UNCOV
1196
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1197
  }
1198

1199
  // Weight window information
1200
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
7,442✔
1201
    variance_reduction::weight_windows.emplace_back(
92✔
1202
      std::make_unique<WeightWindows>(node_ww));
184✔
1203
  }
1204

1205
  // Enable weight windows by default if one or more are present
1206
  if (variance_reduction::weight_windows.size() > 0)
7,350✔
1207
    settings::weight_windows_on = true;
65✔
1208

1209
  // read weight windows from file
1210
  if (check_for_node(root, "weight_windows_file")) {
7,350!
UNCOV
1211
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1212
  }
1213

1214
  // read settings for weight windows value, this will override
1215
  // the automatic setting even if weight windows are present
1216
  if (check_for_node(root, "weight_windows_on")) {
7,350✔
1217
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
38✔
1218
  }
1219

1220
  if (check_for_node(root, "max_secondaries")) {
7,350!
UNCOV
1221
    settings::max_secondaries =
×
UNCOV
1222
      std::stoi(get_node_value(root, "max_secondaries"));
×
1223
  }
1224

1225
  if (check_for_node(root, "max_history_splits")) {
7,350✔
1226
    settings::max_history_splits =
215✔
1227
      std::stoi(get_node_value(root, "max_history_splits"));
215✔
1228
  }
1229

1230
  if (check_for_node(root, "max_tracks")) {
7,350✔
1231
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
48✔
1232
  }
1233

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

1252
  // Set up weight window checkpoints
1253
  if (check_for_node(root, "weight_window_checkpoints")) {
7,350✔
1254
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
2!
1255
    if (check_for_node(ww_checkpoints, "collision")) {
2!
1256
      weight_window_checkpoint_collision =
2✔
1257
        get_node_value_bool(ww_checkpoints, "collision");
2!
1258
    }
1259
    if (check_for_node(ww_checkpoints, "surface")) {
2!
1260
      weight_window_checkpoint_surface =
2✔
1261
        get_node_value_bool(ww_checkpoints, "surface");
2!
1262
    }
1263
  }
1264

1265
  if (check_for_node(root, "use_decay_photons")) {
7,350✔
1266
    settings::use_decay_photons =
11✔
1267
      get_node_value_bool(root, "use_decay_photons");
11✔
1268
  }
1269
}
7,350✔
1270

1271
void free_memory_settings()
7,490✔
1272
{
1273
  settings::statepoint_batch.clear();
7,490✔
1274
  settings::sourcepoint_batch.clear();
7,490✔
1275
  settings::source_write_surf_id.clear();
7,490✔
1276
  settings::res_scat_nuclides.clear();
7,490✔
1277
}
7,490✔
1278

1279
//==============================================================================
1280
// C API functions
1281
//==============================================================================
1282

1283
extern "C" int openmc_set_n_batches(
44✔
1284
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1285
{
1286
  if (settings::n_inactive >= n_batches) {
44✔
1287
    set_errmsg("Number of active batches must be greater than zero.");
11✔
1288
    return OPENMC_E_INVALID_ARGUMENT;
11✔
1289
  }
1290

1291
  if (!settings::trigger_on) {
33✔
1292
    // Set n_batches and n_max_batches to same value
1293
    settings::n_batches = n_batches;
11✔
1294
    settings::n_max_batches = n_batches;
11✔
1295
  } else {
1296
    // Set n_batches and n_max_batches based on value of set_max_batches
1297
    if (set_max_batches) {
22✔
1298
      settings::n_max_batches = n_batches;
11✔
1299
    } else {
1300
      settings::n_batches = n_batches;
11✔
1301
    }
1302
  }
1303

1304
  // Update size of k_generation and entropy
1305
  int m = settings::n_max_batches * settings::gen_per_batch;
33✔
1306
  simulation::k_generation.reserve(m);
33✔
1307
  simulation::entropy.reserve(m);
33✔
1308

1309
  // Add value of n_batches to statepoint_batch
1310
  if (add_statepoint_batch &&
55✔
1311
      !(contains(settings::statepoint_batch, n_batches)))
22!
1312
    settings::statepoint_batch.insert(n_batches);
22✔
1313

1314
  return 0;
33✔
1315
}
1316

1317
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,530✔
1318
{
1319
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,530✔
1320

1321
  return 0;
2,530✔
1322
}
1323

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