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

openmc-dev / openmc / 21621852983

03 Feb 2026 07:56AM UTC coverage: 81.778% (+0.02%) from 81.763%
21621852983

Pull #3728

github

web-flow
Merge 303b029bb into b41e22f68
Pull Request #3728: Add delay to activation of IFP tallies.

17257 of 24175 branches covered (71.38%)

Branch coverage included in aggregate %.

78 of 83 new or added lines in 9 files covered. (93.98%)

119 existing lines in 5 files now uncovered.

55882 of 65261 relevant lines covered (85.63%)

44367469.2 hits per line

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

76.53
/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 legendre_to_tabular {true};
59
bool material_cell_offsets {true};
60
bool output_summary {true};
61
bool output_tallies {true};
62
bool particle_restart_run {false};
63
bool photon_transport {false};
64
bool reduce_tallies {true};
65
bool res_scat_on {false};
66
bool restart_run {false};
67
bool run_CE {true};
68
bool source_latest {false};
69
bool source_separate {false};
70
bool source_write {true};
71
bool source_mcpl_write {false};
72
bool surf_source_write {false};
73
bool surf_mcpl_write {false};
74
bool surf_source_read {false};
75
bool survival_biasing {false};
76
bool survival_normalization {false};
77
bool temperature_multipole {false};
78
bool trigger_on {false};
79
bool trigger_predict {false};
80
bool uniform_source_sampling {false};
81
bool ufs_on {false};
82
bool urr_ptables_on {true};
83
bool use_decay_photons {false};
84
bool weight_windows_on {false};
85
bool weight_window_checkpoint_surface {false};
86
bool weight_window_checkpoint_collision {true};
87
bool write_all_tracks {false};
88
bool write_initial_source {false};
89

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

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

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

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

150
} // namespace settings
151

152
//==============================================================================
153
// Functions
154
//==============================================================================
155

156
void get_run_parameters(pugi::xml_node node_base)
7,284✔
157
{
158
  using namespace settings;
159
  using namespace pugi;
160

161
  // Check number of particles
162
  if (!check_for_node(node_base, "particles")) {
7,284!
163
    fatal_error("Need to specify number of particles.");
×
164
  }
165

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

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

177
  // Get maximum number of events allowed per particle
178
  if (check_for_node(node_base, "max_particle_events")) {
7,284!
179
    max_particle_events =
×
180
      std::stoll(get_node_value(node_base, "max_particle_events"));
×
181
  }
182

183
  // Get number of basic batches
184
  if (check_for_node(node_base, "batches")) {
7,284!
185
    n_batches = std::stoi(get_node_value(node_base, "batches"));
7,284✔
186
  }
187
  if (!trigger_on)
7,284✔
188
    n_max_batches = n_batches;
7,138✔
189

190
  // Get max number of lost particles
191
  if (check_for_node(node_base, "max_lost_particles")) {
7,284✔
192
    max_lost_particles =
49✔
193
      std::stoi(get_node_value(node_base, "max_lost_particles"));
49✔
194
  }
195

196
  // Get relative number of lost particles
197
  if (check_for_node(node_base, "rel_max_lost_particles")) {
7,284!
198
    rel_max_lost_particles =
×
199
      std::stod(get_node_value(node_base, "rel_max_lost_particles"));
×
200
  }
201

202
  // Get relative number of lost particles
203
  if (check_for_node(node_base, "max_write_lost_particles")) {
7,284✔
204
    max_write_lost_particles =
16✔
205
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
16✔
206
  }
207

208
  // Get number of inactive batches
209
  if (run_mode == RunMode::EIGENVALUE ||
7,284✔
210
      solver_type == SolverType::RANDOM_RAY) {
2,720✔
211
    if (check_for_node(node_base, "inactive")) {
4,981✔
212
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,796✔
213
    }
214
    if (check_for_node(node_base, "generations_per_batch")) {
4,981✔
215
      gen_per_batch =
16✔
216
        std::stoi(get_node_value(node_base, "generations_per_batch"));
16✔
217
    }
218

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

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

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

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

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

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

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

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

396
  // Verbosity
397
  if (check_for_node(root, "verbosity") && verbosity == -1) {
1,359!
398
    verbosity = std::stoi(get_node_value(root, "verbosity"));
182✔
399
  } else if (verbosity == -1) {
1,177!
400
    verbosity = 7;
1,177✔
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)
8,092✔
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")) {
8,092✔
422
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
1,277✔
423
    if (temp_str == "mg" || temp_str == "multi-group") {
1,277!
424
      run_CE = false;
1,277✔
425
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
426
      run_CE = true;
×
427
    }
428
  }
1,277✔
429

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

433
  // Look for deprecated cross_sections.xml file in settings.xml
434
  if (check_for_node(root, "cross_sections")) {
8,092!
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.");
441
    path_cross_sections = get_node_value(root, "cross_sections");
×
442
  }
443

444
  if (!run_CE) {
8,092✔
445
    // Scattering Treatments
446
    if (check_for_node(root, "max_order")) {
1,277✔
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,261✔
454
    }
455
  }
456

457
  // Check for a trigger node and get trigger information
458
  if (check_for_node(root, "trigger")) {
8,092✔
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 {
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!
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;
8,092✔
486
  if (run_mode == RunMode::UNSET) {
8,092✔
487
    if (check_for_node(root, "run_mode")) {
7,316✔
488
      std::string temp_str = get_node_value(root, "run_mode", true, true);
7,284✔
489
      if (temp_str == "eigenvalue") {
7,284✔
490
        run_mode = RunMode::EIGENVALUE;
4,532✔
491
      } else if (temp_str == "fixed source") {
2,752✔
492
        run_mode = RunMode::FIXED_SOURCE;
2,720✔
493
      } else if (temp_str == "plot") {
32!
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 {
500
        fatal_error("Unrecognized run mode: " + temp_str);
×
501
      }
502

503
      // Assume XML specifies <particles>, <batches>, etc. directly
504
      node_mode = root;
7,284✔
505
    } else {
7,284✔
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");
×
514
        if (node_mode) {
×
515
          run_mode = RunMode::FIXED_SOURCE;
×
516
        } else {
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")) {
8,092✔
525
    solver_type = SolverType::RANDOM_RAY;
721✔
526
    if (run_CE)
721!
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) {
8,092✔
532
    // Read run parameters
533
    get_run_parameters(node_mode);
7,284✔
534

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

549
    // Check for user value for the number of generation of the Iterated Fission
550
    // Probability (IFP) method
551
    if (check_for_node(root, "ifp_n_generation")) {
7,284✔
552
      ifp_n_generation = std::stoi(get_node_value(root, "ifp_n_generation"));
76✔
553
      if (ifp_n_generation <= 0)
76!
554
        fatal_error("'ifp_n_generation' must be greater than 0.");
×
555
    }
556
  }
557

558
  // Copy plotting random number seed if specified
559
  if (check_for_node(root, "plot_seed")) {
8,092!
UNCOV
560
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
UNCOV
561
    model::plotter_seed = seed;
×
562
  }
563

564
  // Copy random number seed if specified
565
  if (check_for_node(root, "seed")) {
8,092✔
566
    auto seed = std::stoll(get_node_value(root, "seed"));
589✔
567
    openmc_set_seed(seed);
589✔
568
  }
569

570
  // Copy random number stride if specified
571
  if (check_for_node(root, "stride")) {
8,092✔
572
    auto stride = std::stoull(get_node_value(root, "stride"));
16✔
573
    openmc_set_stride(stride);
16✔
574
  }
575

576
  // Check for electron treatment
577
  if (check_for_node(root, "electron_treatment")) {
8,092✔
578
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
70✔
579
    if (temp_str == "led") {
70✔
580
      electron_treatment = ElectronTreatment::LED;
11✔
581
    } else if (temp_str == "ttb") {
59!
582
      electron_treatment = ElectronTreatment::TTB;
59✔
583
    } else {
584
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
585
    }
586
  }
70✔
587

588
  // Check for photon transport
589
  if (check_for_node(root, "photon_transport")) {
8,092✔
590
    photon_transport = get_node_value_bool(root, "photon_transport");
199✔
591

592
    if (!run_CE && photon_transport) {
199!
593
      fatal_error("Photon transport is not currently supported in "
×
594
                  "multigroup mode");
595
    }
596
  }
597

598
  // Number of bins for logarithmic grid
599
  if (check_for_node(root, "log_grid_bins")) {
8,092✔
600
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
16✔
601
    if (n_log_bins < 1) {
16!
602
      fatal_error("Number of bins for logarithmic grid must be greater "
×
603
                  "than zero.");
604
    }
605
  }
606

607
  // Number of OpenMP threads
608
  if (check_for_node(root, "threads")) {
8,092!
609
    if (mpi::master)
×
610
      warning("The <threads> element has been deprecated. Use "
×
611
              "the OMP_NUM_THREADS environment variable to set the number of "
612
              "threads.");
613
  }
614

615
  // ==========================================================================
616
  // EXTERNAL SOURCE
617

618
  // Get point to list of <source> elements and make sure there is at least one
619
  for (pugi::xml_node node : root.children("source")) {
15,615✔
620
    model::external_sources.push_back(Source::create(node));
7,533✔
621
  }
622

623
  // Check if the user has specified to read surface source
624
  if (check_for_node(root, "surf_source_read")) {
8,082✔
625
    surf_source_read = true;
32✔
626
    // Get surface source read node
627
    xml_node node_ssr = root.child("surf_source_read");
32✔
628

629
    std::string path = "surface_source.h5";
32✔
630
    // Check if the user has specified different file for surface source reading
631
    if (check_for_node(node_ssr, "path")) {
32!
632
      path = get_node_value(node_ssr, "path", false, true);
32✔
633
    }
634
    model::external_sources.push_back(make_unique<FileSource>(path));
32✔
635
  }
32✔
636

637
  // If no source specified, default to isotropic point source at origin with
638
  // Watt spectrum. No default source is needed in random ray mode.
639
  if (model::external_sources.empty() &&
10,251✔
640
      settings::solver_type != SolverType::RANDOM_RAY) {
2,169✔
641
    double T[] {0.0};
2,041✔
642
    double p[] {1.0};
2,041✔
643
    model::external_sources.push_back(make_unique<IndependentSource>(
2,041✔
644
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
4,082✔
645
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
4,082✔
646
      UPtrDist {new Discrete(T, p, 1)}));
4,082✔
647
  }
648

649
  // Build probability mass function for sampling external sources
650
  vector<double> source_strengths;
8,082✔
651
  for (auto& s : model::external_sources) {
17,678✔
652
    source_strengths.push_back(s->strength());
9,596✔
653
  }
654
  model::external_sources_probability.assign(source_strengths);
8,082✔
655

656
  // Check if we want to write out source
657
  if (check_for_node(root, "write_initial_source")) {
8,082!
658
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
659
  }
660

661
  // Get relative number of lost particles
662
  if (check_for_node(root, "source_rejection_fraction")) {
8,082✔
663
    source_rejection_fraction =
6✔
664
      std::stod(get_node_value(root, "source_rejection_fraction"));
6!
665
  }
666

667
  if (check_for_node(root, "free_gas_threshold")) {
8,082!
668
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
669
  }
670

671
  // Survival biasing
672
  if (check_for_node(root, "survival_biasing")) {
8,082✔
673
    survival_biasing = get_node_value_bool(root, "survival_biasing");
177✔
674
  }
675

676
  // Probability tables
677
  if (check_for_node(root, "ptables")) {
8,082✔
678
    urr_ptables_on = get_node_value_bool(root, "ptables");
16✔
679
  }
680

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

728
  // Particle trace
729
  if (check_for_node(root, "trace")) {
8,082✔
730
    auto temp = get_node_array<int64_t>(root, "trace");
16✔
731
    if (temp.size() != 3) {
16!
732
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
733
                  "batch, generation, and particle number.");
734
    }
735
    trace_batch = temp.at(0);
16✔
736
    trace_gen = temp.at(1);
16✔
737
    trace_particle = temp.at(2);
16✔
738
  }
16✔
739

740
  // Particle tracks
741
  if (check_for_node(root, "track")) {
8,082✔
742
    // Get values and make sure there are three per particle
743
    auto temp = get_node_array<int>(root, "track");
48✔
744
    if (temp.size() % 3 != 0) {
48!
745
      fatal_error(
×
746
        "Number of integers specified in 'track' is not "
747
        "divisible by 3.  Please provide 3 integers per particle to be "
748
        "tracked.");
749
    }
750

751
    // Reshape into track_identifiers
752
    int n_tracks = temp.size() / 3;
48✔
753
    for (int i = 0; i < n_tracks; ++i) {
192✔
754
      track_identifiers.push_back(
144✔
755
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
144✔
756
    }
757
  }
48✔
758

759
  // Shannon entropy
760
  if (solver_type == SolverType::RANDOM_RAY) {
8,082✔
761
    if (check_for_node(root, "entropy_mesh")) {
721!
762
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
763
                  "No user-defined entropy mesh is supported.");
764
    }
765
    entropy_on = true;
721✔
766
  } else if (solver_type == SolverType::MONTE_CARLO) {
7,361!
767
    if (check_for_node(root, "entropy_mesh")) {
7,361✔
768
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
335✔
769
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
335!
770
        fatal_error(fmt::format(
×
771
          "Mesh {} specified for Shannon entropy does not exist.", temp));
772
      }
773

774
      auto* m = dynamic_cast<RegularMesh*>(
335!
775
        model::meshes[model::mesh_map.at(temp)].get());
335✔
776
      if (!m)
335!
777
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
778
      simulation::entropy_mesh = m;
335✔
779

780
      // Turn on Shannon entropy calculation
781
      entropy_on = true;
335✔
782

783
    } else if (check_for_node(root, "entropy")) {
7,026!
784
      fatal_error(
×
785
        "Specifying a Shannon entropy mesh via the <entropy> element "
786
        "is deprecated. Please create a mesh using <mesh> and then reference "
787
        "it by specifying its ID in an <entropy_mesh> element.");
788
    }
789
  }
790
  // Uniform fission source weighting mesh
791
  if (check_for_node(root, "ufs_mesh")) {
8,082✔
792
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
16✔
793
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
16!
794
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
795
                              "method does not exist.",
796
        temp));
797
    }
798

799
    auto* m =
800
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
16!
801
    if (!m)
16!
802
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
803
    simulation::ufs_mesh = m;
16✔
804

805
    // Turn on uniform fission source weighting
806
    ufs_on = true;
16✔
807

808
  } else if (check_for_node(root, "uniform_fs")) {
8,066!
809
    fatal_error(
×
810
      "Specifying a UFS mesh via the <uniform_fs> element "
811
      "is deprecated. Please create a mesh using <mesh> and then reference "
812
      "it by specifying its ID in a <ufs_mesh> element.");
813
  }
814

815
  // Check if the user has specified to write state points
816
  if (check_for_node(root, "state_point")) {
8,082✔
817

818
    // Get pointer to state_point node
819
    auto node_sp = root.child("state_point");
167✔
820

821
    // Determine number of batches at which to store state points
822
    if (check_for_node(node_sp, "batches")) {
167!
823
      // User gave specific batches to write state points
824
      auto temp = get_node_array<int>(node_sp, "batches");
167✔
825
      for (const auto& b : temp) {
512✔
826
        statepoint_batch.insert(b);
345✔
827
      }
828
    } else {
167✔
829
      // If neither were specified, write state point at last batch
830
      statepoint_batch.insert(n_batches);
×
831
    }
832
  } else {
833
    // If no <state_point> tag was present, by default write state point at
834
    // last batch only
835
    statepoint_batch.insert(n_batches);
7,915✔
836
  }
837

838
  // Check if the user has specified to write source points
839
  if (check_for_node(root, "source_point")) {
8,082✔
840
    // Get source_point node
841
    xml_node node_sp = root.child("source_point");
107✔
842

843
    // Determine batches at which to store source points
844
    if (check_for_node(node_sp, "batches")) {
107✔
845
      // User gave specific batches to write source points
846
      auto temp = get_node_array<int>(node_sp, "batches");
48✔
847
      for (const auto& b : temp) {
128✔
848
        sourcepoint_batch.insert(b);
80✔
849
      }
850
    } else {
48✔
851
      // If neither were specified, write source points with state points
852
      sourcepoint_batch = statepoint_batch;
59✔
853
    }
854

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

876
  // Check is the user specified to convert strength to statistical weight
877
  if (check_for_node(root, "uniform_source_sampling")) {
8,082✔
878
    uniform_source_sampling =
55✔
879
      get_node_value_bool(root, "uniform_source_sampling");
55✔
880
  }
881

882
  // Check if the user has specified to write surface source
883
  if (check_for_node(root, "surf_source_write")) {
8,082✔
884
    surf_source_write = true;
412✔
885
    // Get surface source write node
886
    xml_node node_ssw = root.child("surf_source_write");
412✔
887

888
    // Determine surface ids at which crossing particles are to be banked.
889
    // If no surfaces are specified, all surfaces in the model will be used
890
    // to bank source points.
891
    if (check_for_node(node_ssw, "surface_ids")) {
412✔
892
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
202✔
893
      for (const auto& b : temp) {
994✔
894
        source_write_surf_id.insert(b);
792✔
895
      }
896
    }
202✔
897

898
    // Get maximum number of particles to be banked per surface
899
    if (check_for_node(node_ssw, "max_particles")) {
412✔
900
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
403✔
901
    } else {
902
      fatal_error("A maximum number of particles needs to be specified "
9✔
903
                  "using the 'max_particles' parameter to store surface "
904
                  "source points.");
905
    }
906

907
    // Get maximum number of surface source files to be created
908
    if (check_for_node(node_ssw, "max_source_files")) {
403✔
909
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
33✔
910
    } else {
911
      ssw_max_files = 1;
370✔
912
    }
913

914
    if (check_for_node(node_ssw, "mcpl")) {
403✔
915
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
11✔
916
    }
917
    // Get cell information
918
    if (check_for_node(node_ssw, "cell")) {
403✔
919
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
104✔
920
      ssw_cell_type = SSWCellType::Both;
104✔
921
    }
922
    if (check_for_node(node_ssw, "cellfrom")) {
403✔
923
      if (ssw_cell_id != C_NONE) {
90✔
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, "cellfrom"));
72✔
928
      ssw_cell_type = SSWCellType::From;
72✔
929
    }
930
    if (check_for_node(node_ssw, "cellto")) {
385✔
931
      if (ssw_cell_id != C_NONE) {
71✔
932
        fatal_error(
18✔
933
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
934
      }
935
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
53✔
936
      ssw_cell_type = SSWCellType::To;
53✔
937
    }
938
  }
939

940
  // Check if the user has specified to write specific collisions
941
  if (check_for_node(root, "collision_track")) {
8,037✔
942
    settings::collision_track = true;
155✔
943
    // Get collision track node
944
    xml_node node_ct = root.child("collision_track");
155✔
945
    collision_track_config = CollisionTrackConfig {};
155✔
946

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

1004
  // If source is not separate and is to be written out in the statepoint
1005
  // file, make sure that the sourcepoint batch numbers are contained in the
1006
  // statepoint list
1007
  if (!source_separate) {
8,037✔
1008
    for (const auto& b : sourcepoint_batch) {
16,022✔
1009
      if (!contains(statepoint_batch, b)) {
8,076!
1010
        fatal_error(
×
1011
          "Sourcepoint batches are not a subset of statepoint batches.");
1012
      }
1013
    }
1014
  }
1015

1016
  // Check if the user has specified to not reduce tallies at the end of every
1017
  // batch
1018
  if (check_for_node(root, "no_reduce")) {
8,037✔
1019
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
32✔
1020
  }
1021

1022
  // Check if the user has specified to use confidence intervals for
1023
  // uncertainties rather than standard deviations
1024
  if (check_for_node(root, "confidence_intervals")) {
8,037✔
1025
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
16✔
1026
  }
1027

1028
  // Check for output options
1029
  if (check_for_node(root, "output")) {
8,037✔
1030
    // Get pointer to output node
1031
    pugi::xml_node node_output = root.child("output");
661✔
1032

1033
    // Check for summary option
1034
    if (check_for_node(node_output, "summary")) {
661✔
1035
      output_summary = get_node_value_bool(node_output, "summary");
634✔
1036
    }
1037

1038
    // Check for ASCII tallies output option
1039
    if (check_for_node(node_output, "tallies")) {
661✔
1040
      output_tallies = get_node_value_bool(node_output, "tallies");
239✔
1041
    }
1042

1043
    // Set output directory if a path has been specified
1044
    if (check_for_node(node_output, "path")) {
661!
1045
      path_output = get_node_value(node_output, "path");
×
1046
      if (!ends_with(path_output, "/")) {
×
1047
        path_output += "/";
×
1048
      }
1049
    }
1050
  }
1051

1052
  // Resonance scattering parameters
1053
  if (check_for_node(root, "resonance_scattering")) {
8,037✔
1054
    xml_node node_res_scat = root.child("resonance_scattering");
16✔
1055

1056
    // See if resonance scattering is enabled
1057
    if (check_for_node(node_res_scat, "enable")) {
16!
1058
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
16✔
1059
    } else {
1060
      res_scat_on = true;
×
1061
    }
1062

1063
    // Determine what method is used
1064
    if (check_for_node(node_res_scat, "method")) {
16!
1065
      auto temp = get_node_value(node_res_scat, "method", true, true);
16✔
1066
      if (temp == "rvs") {
16!
1067
        res_scat_method = ResScatMethod::rvs;
16✔
1068
      } else if (temp == "dbrc") {
×
1069
        res_scat_method = ResScatMethod::dbrc;
×
1070
      } else {
1071
        fatal_error(
×
1072
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1073
      }
1074
    }
16✔
1075

1076
    // Minimum energy for resonance scattering
1077
    if (check_for_node(node_res_scat, "energy_min")) {
16!
1078
      res_scat_energy_min =
16✔
1079
        std::stod(get_node_value(node_res_scat, "energy_min"));
16✔
1080
    }
1081
    if (res_scat_energy_min < 0.0) {
16!
1082
      fatal_error("Lower resonance scattering energy bound is negative");
×
1083
    }
1084

1085
    // Maximum energy for resonance scattering
1086
    if (check_for_node(node_res_scat, "energy_max")) {
16!
1087
      res_scat_energy_max =
16✔
1088
        std::stod(get_node_value(node_res_scat, "energy_max"));
16✔
1089
    }
1090
    if (res_scat_energy_max < res_scat_energy_min) {
16!
1091
      fatal_error("Upper resonance scattering energy bound is below the "
×
1092
                  "lower resonance scattering energy bound.");
1093
    }
1094

1095
    // Get resonance scattering nuclides
1096
    if (check_for_node(node_res_scat, "nuclides")) {
16!
1097
      res_scat_nuclides =
1098
        get_node_array<std::string>(node_res_scat, "nuclides");
16✔
1099
    }
1100
  }
1101

1102
  // Get volume calculations
1103
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
8,363✔
1104
    model::volume_calcs.emplace_back(node_vol);
326✔
1105
  }
1106

1107
  // Get temperature settings
1108
  if (check_for_node(root, "temperature_default")) {
8,037✔
1109
    temperature_default =
172✔
1110
      std::stod(get_node_value(root, "temperature_default"));
172✔
1111
  }
1112
  if (check_for_node(root, "temperature_method")) {
8,037✔
1113
    auto temp = get_node_value(root, "temperature_method", true, true);
325✔
1114
    if (temp == "nearest") {
325✔
1115
      temperature_method = TemperatureMethod::NEAREST;
140✔
1116
    } else if (temp == "interpolation") {
185!
1117
      temperature_method = TemperatureMethod::INTERPOLATION;
185✔
1118
    } else {
1119
      fatal_error("Unknown temperature method: " + temp);
×
1120
    }
1121
  }
325✔
1122
  if (check_for_node(root, "temperature_tolerance")) {
8,037✔
1123
    temperature_tolerance =
171✔
1124
      std::stod(get_node_value(root, "temperature_tolerance"));
171✔
1125
  }
1126
  if (check_for_node(root, "temperature_multipole")) {
8,037✔
1127
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
32✔
1128

1129
    // Multipole currently doesn't work with photon transport
1130
    if (temperature_multipole && photon_transport) {
32!
1131
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1132
                  "photon transport.");
1133
    }
1134
  }
1135
  if (check_for_node(root, "temperature_range")) {
8,037!
1136
    auto range = get_node_array<double>(root, "temperature_range");
×
1137
    temperature_range[0] = range.at(0);
×
1138
    temperature_range[1] = range.at(1);
×
1139
  }
×
1140

1141
  // Check for tabular_legendre options
1142
  if (check_for_node(root, "tabular_legendre")) {
8,037✔
1143
    // Get pointer to tabular_legendre node
1144
    xml_node node_tab_leg = root.child("tabular_legendre");
96✔
1145

1146
    // Check for enable option
1147
    if (check_for_node(node_tab_leg, "enable")) {
96!
1148
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
96✔
1149
    }
1150

1151
    // Check for the number of points
1152
    if (check_for_node(node_tab_leg, "num_points")) {
96!
1153
      legendre_to_tabular_points =
×
1154
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
1155
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
1156
        fatal_error(
×
1157
          "The 'num_points' subelement/attribute of the "
1158
          "<tabular_legendre> element must contain a value greater than 1");
1159
      }
1160
    }
1161
  }
1162

1163
  // Check whether create delayed neutrons in fission
1164
  if (check_for_node(root, "create_delayed_neutrons")) {
8,037!
1165
    create_delayed_neutrons =
×
1166
      get_node_value_bool(root, "create_delayed_neutrons");
×
1167
  }
1168

1169
  // Check whether create fission sites
1170
  if (run_mode == RunMode::FIXED_SOURCE) {
8,037✔
1171
    if (check_for_node(root, "create_fission_neutrons")) {
2,674✔
1172
      create_fission_neutrons =
193✔
1173
        get_node_value_bool(root, "create_fission_neutrons");
193✔
1174
    }
1175
  }
1176

1177
  // Check whether to scale fission photon yields
1178
  if (check_for_node(root, "delayed_photon_scaling")) {
8,037!
1179
    delayed_photon_scaling =
×
1180
      get_node_value_bool(root, "delayed_photon_scaling");
×
1181
  }
1182

1183
  // Check whether to use event-based parallelism
1184
  if (check_for_node(root, "event_based")) {
8,037!
1185
    event_based = get_node_value_bool(root, "event_based");
×
1186
  }
1187

1188
  // Check whether material cell offsets should be generated
1189
  if (check_for_node(root, "material_cell_offsets")) {
8,037!
1190
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1191
  }
1192

1193
  // Weight window information
1194
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
8,129✔
1195
    variance_reduction::weight_windows.emplace_back(
92✔
1196
      std::make_unique<WeightWindows>(node_ww));
184✔
1197
  }
1198

1199
  // Enable weight windows by default if one or more are present
1200
  if (variance_reduction::weight_windows.size() > 0)
8,037✔
1201
    settings::weight_windows_on = true;
65✔
1202

1203
  // read weight windows from file
1204
  if (check_for_node(root, "weight_windows_file")) {
8,037!
1205
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1206
  }
1207

1208
  // read settings for weight windows value, this will override
1209
  // the automatic setting even if weight windows are present
1210
  if (check_for_node(root, "weight_windows_on")) {
8,037✔
1211
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
38✔
1212
  }
1213

1214
  if (check_for_node(root, "max_secondaries")) {
8,037!
1215
    settings::max_secondaries =
×
1216
      std::stoi(get_node_value(root, "max_secondaries"));
×
1217
  }
1218

1219
  if (check_for_node(root, "max_history_splits")) {
8,037✔
1220
    settings::max_history_splits =
215✔
1221
      std::stoi(get_node_value(root, "max_history_splits"));
215✔
1222
  }
1223

1224
  if (check_for_node(root, "max_tracks")) {
8,037✔
1225
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
48✔
1226
  }
1227

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

1246
  // Set up weight window checkpoints
1247
  if (check_for_node(root, "weight_window_checkpoints")) {
8,037✔
1248
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
2!
1249
    if (check_for_node(ww_checkpoints, "collision")) {
2!
1250
      weight_window_checkpoint_collision =
2✔
1251
        get_node_value_bool(ww_checkpoints, "collision");
2!
1252
    }
1253
    if (check_for_node(ww_checkpoints, "surface")) {
2!
1254
      weight_window_checkpoint_surface =
2✔
1255
        get_node_value_bool(ww_checkpoints, "surface");
2!
1256
    }
1257
  }
1258

1259
  if (check_for_node(root, "use_decay_photons")) {
8,037✔
1260
    settings::use_decay_photons =
11✔
1261
      get_node_value_bool(root, "use_decay_photons");
11✔
1262
  }
1263
}
8,037✔
1264

1265
void free_memory_settings()
8,186✔
1266
{
1267
  settings::statepoint_batch.clear();
8,186✔
1268
  settings::sourcepoint_batch.clear();
8,186✔
1269
  settings::source_write_surf_id.clear();
8,186✔
1270
  settings::res_scat_nuclides.clear();
8,186✔
1271
}
8,186✔
1272

1273
//==============================================================================
1274
// C API functions
1275
//==============================================================================
1276

1277
extern "C" int openmc_set_n_batches(
44✔
1278
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1279
{
1280
  if (settings::n_inactive >= n_batches) {
44✔
1281
    set_errmsg("Number of active batches must be greater than zero.");
11✔
1282
    return OPENMC_E_INVALID_ARGUMENT;
11✔
1283
  }
1284

1285
  if (!settings::trigger_on) {
33✔
1286
    // Set n_batches and n_max_batches to same value
1287
    settings::n_batches = n_batches;
11✔
1288
    settings::n_max_batches = n_batches;
11✔
1289
  } else {
1290
    // Set n_batches and n_max_batches based on value of set_max_batches
1291
    if (set_max_batches) {
22✔
1292
      settings::n_max_batches = n_batches;
11✔
1293
    } else {
1294
      settings::n_batches = n_batches;
11✔
1295
    }
1296
  }
1297

1298
  // Update size of k_generation and entropy
1299
  int m = settings::n_max_batches * settings::gen_per_batch;
33✔
1300
  simulation::k_generation.reserve(m);
33✔
1301
  simulation::entropy.reserve(m);
33✔
1302

1303
  // Add value of n_batches to statepoint_batch
1304
  if (add_statepoint_batch &&
55✔
1305
      !(contains(settings::statepoint_batch, n_batches)))
22!
1306
    settings::statepoint_batch.insert(n_batches);
22✔
1307

1308
  return 0;
33✔
1309
}
1310

1311
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,530✔
1312
{
1313
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,530✔
1314

1315
  return 0;
2,530✔
1316
}
1317

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