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

openmc-dev / openmc / 23084721708

14 Mar 2026 08:56AM UTC coverage: 81.599% (-0.5%) from 82.058%
23084721708

Pull #2693

github

web-flow
Merge 0ed23ee59 into bc9c31e0f
Pull Request #2693: Add reactivity control to coupled transport-depletion analyses

17575 of 25275 branches covered (69.54%)

Branch coverage included in aggregate %.

74 of 85 new or added lines in 4 files covered. (87.06%)

3755 existing lines in 99 files now uncovered.

58074 of 67433 relevant lines covered (86.12%)

47252067.37 hits per line

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

76.63
/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 atomic_relaxation {true};
66
bool reduce_tallies {true};
67
bool res_scat_on {false};
68
bool restart_run {false};
69
bool run_CE {true};
70
bool source_latest {false};
71
bool source_separate {false};
72
bool source_write {true};
73
bool source_mcpl_write {false};
74
bool surf_source_write {false};
75
bool surf_mcpl_write {false};
76
bool surf_source_read {false};
77
bool survival_biasing {false};
78
bool survival_normalization {false};
79
bool temperature_multipole {false};
80
bool trigger_on {false};
81
bool trigger_predict {false};
82
bool uniform_source_sampling {false};
83
bool ufs_on {false};
84
bool urr_ptables_on {true};
85
bool use_decay_photons {false};
86
bool weight_windows_on {false};
87
bool weight_window_checkpoint_surface {false};
88
bool weight_window_checkpoint_collision {true};
89
bool write_all_tracks {false};
90
bool write_initial_source {false};
91

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

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

109
int64_t max_particles_in_flight {100000};
110
int max_particle_events {1000000};
111

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

156
} // namespace settings
157

158
//==============================================================================
159
// Functions
160
//==============================================================================
161

162
void get_run_parameters(pugi::xml_node node_base)
7,447✔
163
{
164
  using namespace settings;
7,447✔
165
  using namespace pugi;
7,447✔
166

167
  // Check number of particles
168
  if (!check_for_node(node_base, "particles")) {
7,447!
UNCOV
169
    fatal_error("Need to specify number of particles.");
×
170
  }
171

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

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

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

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

196
  // Get max number of lost particles
197
  if (check_for_node(node_base, "max_lost_particles")) {
7,447✔
198
    max_lost_particles =
92✔
199
      std::stoi(get_node_value(node_base, "max_lost_particles"));
46✔
200
  }
201

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

208
  // Get relative number of lost particles
209
  if (check_for_node(node_base, "max_write_lost_particles")) {
7,447✔
210
    max_write_lost_particles =
30✔
211
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
15✔
212
  }
213

214
  // Get number of inactive batches
215
  if (run_mode == RunMode::EIGENVALUE ||
7,447✔
216
      solver_type == SolverType::RANDOM_RAY) {
2,844✔
217
    if (check_for_node(node_base, "inactive")) {
5,009✔
218
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,798✔
219
    }
220
    if (check_for_node(node_base, "generations_per_batch")) {
5,009✔
221
      gen_per_batch =
30✔
222
        std::stoi(get_node_value(node_base, "generations_per_batch"));
15✔
223
    }
224

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

230
    // Get the trigger information for keff
231
    if (check_for_node(node_base, "keff_trigger")) {
5,009✔
232
      xml_node node_keff_trigger = node_base.child("keff_trigger");
101✔
233

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

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

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

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

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

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

404
  // Verbosity
405
  if (check_for_node(root, "verbosity") && verbosity == -1) {
1,360!
406
    verbosity = std::stoi(get_node_value(root, "verbosity"));
428✔
407
  } else if (verbosity == -1) {
1,146!
408
    verbosity = 7;
1,146✔
409
  }
410

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

418
  write_message("Reading settings XML file...", 5);
1,360✔
419

420
  read_settings_xml(root);
1,360✔
421
}
1,372✔
422

423
void read_settings_xml(pugi::xml_node root)
8,255✔
424
{
425
  using namespace settings;
8,255✔
426
  using namespace pugi;
8,255✔
427

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

438
  // Check for user meshes and allocate
439
  read_meshes(root);
8,255✔
440

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

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

465
  // Check for a trigger node and get trigger information
466
  if (check_for_node(root, "trigger")) {
8,255✔
467
    xml_node node_trigger = root.child("trigger");
156✔
468

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

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

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

492
  // Check run mode if it hasn't been set from the command line
493
  xml_node node_mode;
8,255✔
494
  if (run_mode == RunMode::UNSET) {
8,255✔
495
    if (check_for_node(root, "run_mode")) {
7,479✔
496
      std::string temp_str = get_node_value(root, "run_mode", true, true);
7,449✔
497
      if (temp_str == "eigenvalue") {
7,449✔
498
        run_mode = RunMode::EIGENVALUE;
4,573✔
499
      } else if (temp_str == "fixed source") {
2,876✔
500
        run_mode = RunMode::FIXED_SOURCE;
2,844✔
501
      } else if (temp_str == "plot") {
32!
502
        run_mode = RunMode::PLOTTING;
×
503
      } else if (temp_str == "particle restart") {
32!
UNCOV
504
        run_mode = RunMode::PARTICLE;
×
505
      } else if (temp_str == "volume") {
32!
506
        run_mode = RunMode::VOLUME;
32✔
507
      } else {
UNCOV
508
        fatal_error("Unrecognized run mode: " + temp_str);
×
509
      }
510

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

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

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

539
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
8,255✔
540
    // Read run parameters
541
    get_run_parameters(node_mode);
7,447✔
542

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

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

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

578
  // Copy random number seed if specified
579
  if (check_for_node(root, "seed")) {
8,246✔
580
    auto seed = std::stoll(get_node_value(root, "seed"));
1,154✔
581
    openmc_set_seed(seed);
577✔
582
  }
583

584
  // Copy random number stride if specified
585
  if (check_for_node(root, "stride")) {
8,246✔
586
    auto stride = std::stoull(get_node_value(root, "stride"));
30✔
587
    openmc_set_stride(stride);
15✔
588
  }
589

590
  // Check for electron treatment
591
  if (check_for_node(root, "electron_treatment")) {
8,246✔
592
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
82✔
593
    if (temp_str == "led") {
82✔
594
      electron_treatment = ElectronTreatment::LED;
26✔
595
    } else if (temp_str == "ttb") {
56!
596
      electron_treatment = ElectronTreatment::TTB;
56✔
597
    } else {
UNCOV
598
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
599
    }
600
  }
82✔
601

602
  // Check for photon transport
603
  if (check_for_node(root, "photon_transport")) {
8,246✔
604
    photon_transport = get_node_value_bool(root, "photon_transport");
205✔
605

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

612
  // Check for atomic relaxation
613
  if (check_for_node(root, "atomic_relaxation")) {
8,246✔
614
    atomic_relaxation = get_node_value_bool(root, "atomic_relaxation");
15✔
615
  }
616

617
  // Number of bins for logarithmic grid
618
  if (check_for_node(root, "log_grid_bins")) {
8,246✔
619
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
30✔
620
    if (n_log_bins < 1) {
15!
UNCOV
621
      fatal_error("Number of bins for logarithmic grid must be greater "
×
622
                  "than zero.");
623
    }
624
  }
625

626
  // Number of OpenMP threads
627
  if (check_for_node(root, "threads")) {
8,246!
UNCOV
628
    if (mpi::master)
×
UNCOV
629
      warning("The <threads> element has been deprecated. Use "
×
630
              "the OMP_NUM_THREADS environment variable to set the number of "
631
              "threads.");
632
  }
633

634
  // ==========================================================================
635
  // EXTERNAL SOURCE
636

637
  // Get point to list of <source> elements and make sure there is at least one
638
  for (pugi::xml_node node : root.children("source")) {
15,937✔
639
    model::external_sources.push_back(Source::create(node));
15,392✔
640
  }
641

642
  // Check if the user has specified to read surface source
643
  if (check_for_node(root, "surf_source_read")) {
8,236✔
644
    surf_source_read = true;
30✔
645
    // Get surface source read node
646
    xml_node node_ssr = root.child("surf_source_read");
30✔
647

648
    std::string path = "surface_source.h5";
30✔
649
    // Check if the user has specified different file for surface source reading
650
    if (check_for_node(node_ssr, "path")) {
30!
651
      path = get_node_value(node_ssr, "path", false, true);
30✔
652
    }
653
    model::external_sources.push_back(make_unique<FileSource>(path));
30✔
654
  }
30✔
655

656
  // If no source specified, default to isotropic point source at origin with
657
  // Watt spectrum. No default source is needed in random ray mode.
658
  if (model::external_sources.empty() &&
8,236✔
659
      settings::solver_type != SolverType::RANDOM_RAY) {
2,238✔
660
    double T[] {0.0};
2,092✔
661
    double p[] {1.0};
2,092✔
662
    model::external_sources.push_back(make_unique<IndependentSource>(
2,092✔
663
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
4,184✔
664
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
4,184✔
665
      UPtrDist {new Discrete(T, p, 1)}));
4,184✔
666
  }
667

668
  // Build probability mass function for sampling external sources
669
  vector<double> source_strengths;
8,236✔
670
  for (auto& s : model::external_sources) {
18,049✔
671
    source_strengths.push_back(s->strength());
9,813✔
672
  }
673
  model::external_sources_probability.assign(source_strengths);
8,236✔
674

675
  // Check if we want to write out source
676
  if (check_for_node(root, "write_initial_source")) {
8,236!
UNCOV
677
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
678
  }
679

680
  // Get relative number of lost particles
681
  if (check_for_node(root, "source_rejection_fraction")) {
8,236✔
682
    source_rejection_fraction =
14✔
683
      std::stod(get_node_value(root, "source_rejection_fraction"));
14!
684
  }
685

686
  if (check_for_node(root, "free_gas_threshold")) {
8,236!
UNCOV
687
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
688
  }
689

690
  // Surface grazing
691
  if (check_for_node(root, "surface_grazing_cutoff"))
8,236!
UNCOV
692
    surface_grazing_cutoff =
×
UNCOV
693
      std::stod(get_node_value(root, "surface_grazing_cutoff"));
×
694
  if (check_for_node(root, "surface_grazing_ratio"))
8,236!
UNCOV
695
    surface_grazing_ratio =
×
UNCOV
696
      std::stod(get_node_value(root, "surface_grazing_ratio"));
×
697

698
  // Survival biasing
699
  if (check_for_node(root, "survival_biasing")) {
8,236✔
700
    survival_biasing = get_node_value_bool(root, "survival_biasing");
190✔
701
  }
702

703
  // Probability tables
704
  if (check_for_node(root, "ptables")) {
8,236✔
705
    urr_ptables_on = get_node_value_bool(root, "ptables");
15✔
706
  }
707

708
  // Cutoffs
709
  if (check_for_node(root, "cutoff")) {
8,236✔
710
    xml_node node_cutoff = root.child("cutoff");
138✔
711
    if (check_for_node(node_cutoff, "weight")) {
138✔
712
      weight_cutoff = std::stod(get_node_value(node_cutoff, "weight"));
30✔
713
    }
714
    if (check_for_node(node_cutoff, "weight_avg")) {
138✔
715
      weight_survive = std::stod(get_node_value(node_cutoff, "weight_avg"));
30✔
716
    }
717
    if (check_for_node(node_cutoff, "survival_normalization")) {
138!
UNCOV
718
      survival_normalization =
×
719
        get_node_value_bool(node_cutoff, "survival_normalization");
×
720
    }
721
    if (check_for_node(node_cutoff, "energy_neutron")) {
138✔
722
      energy_cutoff[0] =
15✔
723
        std::stod(get_node_value(node_cutoff, "energy_neutron"));
30✔
724
    } else if (check_for_node(node_cutoff, "energy")) {
123!
UNCOV
725
      warning("The use of an <energy> cutoff is deprecated and should "
×
726
              "be replaced by <energy_neutron>.");
UNCOV
727
      energy_cutoff[0] = std::stod(get_node_value(node_cutoff, "energy"));
×
728
    }
729
    if (check_for_node(node_cutoff, "energy_photon")) {
138✔
730
      energy_cutoff[1] =
82✔
731
        std::stod(get_node_value(node_cutoff, "energy_photon"));
164✔
732
    }
733
    if (check_for_node(node_cutoff, "energy_electron")) {
138!
UNCOV
734
      energy_cutoff[2] =
×
UNCOV
735
        std::stof(get_node_value(node_cutoff, "energy_electron"));
×
736
    }
737
    if (check_for_node(node_cutoff, "energy_positron")) {
138!
UNCOV
738
      energy_cutoff[3] =
×
UNCOV
739
        std::stod(get_node_value(node_cutoff, "energy_positron"));
×
740
    }
741
    if (check_for_node(node_cutoff, "time_neutron")) {
138✔
742
      time_cutoff[0] = std::stod(get_node_value(node_cutoff, "time_neutron"));
26✔
743
    }
744
    if (check_for_node(node_cutoff, "time_photon")) {
138!
UNCOV
745
      time_cutoff[1] = std::stod(get_node_value(node_cutoff, "time_photon"));
×
746
    }
747
    if (check_for_node(node_cutoff, "time_electron")) {
138!
UNCOV
748
      time_cutoff[2] = std::stod(get_node_value(node_cutoff, "time_electron"));
×
749
    }
750
    if (check_for_node(node_cutoff, "time_positron")) {
138!
UNCOV
751
      time_cutoff[3] = std::stod(get_node_value(node_cutoff, "time_positron"));
×
752
    }
753
  }
754

755
  // read properties from file
756
  if (check_for_node(root, "properties_file")) {
8,236✔
757
    properties_file = get_node_value(root, "properties_file");
11✔
758
    if (!file_exists(properties_file)) {
11!
UNCOV
759
      fatal_error(fmt::format("File '{}' does not exist.", properties_file));
×
760
    }
761
  }
762

763
  // Particle trace
764
  if (check_for_node(root, "trace")) {
8,236✔
765
    auto temp = get_node_array<int64_t>(root, "trace");
15✔
766
    if (temp.size() != 3) {
15!
UNCOV
767
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
768
                  "batch, generation, and particle number.");
769
    }
770
    trace_batch = temp.at(0);
15✔
771
    trace_gen = temp.at(1);
15✔
772
    trace_particle = temp.at(2);
15✔
773
  }
15✔
774

775
  // Particle tracks
776
  if (check_for_node(root, "track")) {
8,236✔
777
    // Get values and make sure there are three per particle
778
    auto temp = get_node_array<int>(root, "track");
45✔
779
    if (temp.size() % 3 != 0) {
45!
UNCOV
780
      fatal_error(
×
781
        "Number of integers specified in 'track' is not "
782
        "divisible by 3.  Please provide 3 integers per particle to be "
783
        "tracked.");
784
    }
785

786
    // Reshape into track_identifiers
787
    int n_tracks = temp.size() / 3;
45✔
788
    for (int i = 0; i < n_tracks; ++i) {
180✔
789
      track_identifiers.push_back(
135✔
790
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
135✔
791
    }
792
  }
45✔
793

794
  // Shannon entropy
795
  if (solver_type == SolverType::RANDOM_RAY) {
8,236✔
796
    if (check_for_node(root, "entropy_mesh")) {
762!
UNCOV
797
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
798
                  "No user-defined entropy mesh is supported.");
799
    }
800
    entropy_on = true;
762✔
801
  } else if (solver_type == SolverType::MONTE_CARLO) {
7,474!
802
    if (check_for_node(root, "entropy_mesh")) {
7,474✔
803
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
668✔
804
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
334!
UNCOV
805
        fatal_error(fmt::format(
×
806
          "Mesh {} specified for Shannon entropy does not exist.", temp));
807
      }
808

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

815
      // Turn on Shannon entropy calculation
816
      entropy_on = true;
334✔
817

818
    } else if (check_for_node(root, "entropy")) {
7,140!
UNCOV
819
      fatal_error(
×
820
        "Specifying a Shannon entropy mesh via the <entropy> element "
821
        "is deprecated. Please create a mesh using <mesh> and then reference "
822
        "it by specifying its ID in an <entropy_mesh> element.");
823
    }
824
  }
825
  // Uniform fission source weighting mesh
826
  if (check_for_node(root, "ufs_mesh")) {
8,236✔
827
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
30✔
828
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
15!
UNCOV
829
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
830
                              "method does not exist.",
831
        temp));
832
    }
833

834
    auto* m =
15✔
835
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
15!
836
    if (!m)
15!
UNCOV
837
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
838
    simulation::ufs_mesh = m;
15✔
839

840
    // Turn on uniform fission source weighting
841
    ufs_on = true;
15✔
842

843
  } else if (check_for_node(root, "uniform_fs")) {
8,221!
UNCOV
844
    fatal_error(
×
845
      "Specifying a UFS mesh via the <uniform_fs> element "
846
      "is deprecated. Please create a mesh using <mesh> and then reference "
847
      "it by specifying its ID in a <ufs_mesh> element.");
848
  }
849

850
  // Check if the user has specified to write state points
851
  if (check_for_node(root, "state_point")) {
8,236✔
852

853
    // Get pointer to state_point node
854
    auto node_sp = root.child("state_point");
160✔
855

856
    // Determine number of batches at which to store state points
857
    if (check_for_node(node_sp, "batches")) {
160!
858
      // User gave specific batches to write state points
859
      auto temp = get_node_array<int>(node_sp, "batches");
160✔
860
      for (const auto& b : temp) {
491✔
861
        statepoint_batch.insert(b);
331✔
862
      }
863
    } else {
160✔
864
      // If neither were specified, write state point at last batch
UNCOV
865
      statepoint_batch.insert(n_batches);
×
866
    }
867
  } else {
868
    // If no <state_point> tag was present, by default write state point at
869
    // last batch only
870
    statepoint_batch.insert(n_batches);
8,076✔
871
  }
872

873
  // Check if the user has specified to write source points
874
  if (check_for_node(root, "source_point")) {
8,236✔
875
    // Get source_point node
876
    xml_node node_sp = root.child("source_point");
101✔
877

878
    // Determine batches at which to store source points
879
    if (check_for_node(node_sp, "batches")) {
101✔
880
      // User gave specific batches to write source points
881
      auto temp = get_node_array<int>(node_sp, "batches");
45✔
882
      for (const auto& b : temp) {
120✔
883
        sourcepoint_batch.insert(b);
75✔
884
      }
885
    } else {
45✔
886
      // If neither were specified, write source points with state points
887
      sourcepoint_batch = statepoint_batch;
56!
888
    }
889

890
    // Check if the user has specified to write binary source file
891
    if (check_for_node(node_sp, "separate")) {
101✔
892
      source_separate = get_node_value_bool(node_sp, "separate");
71✔
893
    }
894
    if (check_for_node(node_sp, "write")) {
101!
UNCOV
895
      source_write = get_node_value_bool(node_sp, "write");
×
896
    }
897
    if (check_for_node(node_sp, "mcpl")) {
101✔
898
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
26✔
899
    }
900
    if (check_for_node(node_sp, "overwrite_latest")) {
101✔
901
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
15✔
902
      source_separate = source_latest;
15✔
903
    }
904
  } else {
905
    // If no <source_point> tag was present, by default we keep source bank in
906
    // statepoint file and write it out at statepoints intervals
907
    source_separate = false;
8,135✔
908
    sourcepoint_batch = statepoint_batch;
8,135!
909
  }
910

911
  // Check is the user specified to convert strength to statistical weight
912
  if (check_for_node(root, "uniform_source_sampling")) {
8,236✔
913
    uniform_source_sampling =
55✔
914
      get_node_value_bool(root, "uniform_source_sampling");
55✔
915
  }
916

917
  // Check if the user has specified to write surface source
918
  if (check_for_node(root, "surf_source_write")) {
8,236✔
919
    surf_source_write = true;
412✔
920
    // Get surface source write node
921
    xml_node node_ssw = root.child("surf_source_write");
412✔
922

923
    // Determine surface ids at which crossing particles are to be banked.
924
    // If no surfaces are specified, all surfaces in the model will be used
925
    // to bank source points.
926
    if (check_for_node(node_ssw, "surface_ids")) {
412✔
927
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
202✔
928
      for (const auto& b : temp) {
994✔
929
        source_write_surf_id.insert(b);
792✔
930
      }
931
    }
202✔
932

933
    // Get maximum number of particles to be banked per surface
934
    if (check_for_node(node_ssw, "max_particles")) {
412✔
935
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
806✔
936
    } else {
937
      fatal_error("A maximum number of particles needs to be specified "
9✔
938
                  "using the 'max_particles' parameter to store surface "
939
                  "source points.");
940
    }
941

942
    // Get maximum number of surface source files to be created
943
    if (check_for_node(node_ssw, "max_source_files")) {
403✔
944
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
66✔
945
    } else {
946
      ssw_max_files = 1;
370✔
947
    }
948

949
    if (check_for_node(node_ssw, "mcpl")) {
403✔
950
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
11✔
951
    }
952
    // Get cell information
953
    if (check_for_node(node_ssw, "cell")) {
403✔
954
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
208✔
955
      ssw_cell_type = SSWCellType::Both;
104✔
956
    }
957
    if (check_for_node(node_ssw, "cellfrom")) {
403✔
958
      if (ssw_cell_id != C_NONE) {
90✔
959
        fatal_error(
18✔
960
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
961
      }
962
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
144✔
963
      ssw_cell_type = SSWCellType::From;
72✔
964
    }
965
    if (check_for_node(node_ssw, "cellto")) {
385✔
966
      if (ssw_cell_id != C_NONE) {
71✔
967
        fatal_error(
18✔
968
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
969
      }
970
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
106✔
971
      ssw_cell_type = SSWCellType::To;
53✔
972
    }
973
  }
974

975
  // Check if the user has specified to write specific collisions
976
  if (check_for_node(root, "collision_track")) {
8,191✔
977
    settings::collision_track = true;
148✔
978
    // Get collision track node
979
    xml_node node_ct = root.child("collision_track");
148✔
980
    collision_track_config = CollisionTrackConfig {};
148✔
981

982
    // Determine cell ids at which crossing particles are to be banked
983
    if (check_for_node(node_ct, "cell_ids")) {
148✔
984
      auto temp = get_node_array<int>(node_ct, "cell_ids");
78✔
985
      for (const auto& b : temp) {
204✔
986
        collision_track_config.cell_ids.insert(b);
126✔
987
      }
988
    }
78✔
989
    if (check_for_node(node_ct, "reactions")) {
148✔
990
      auto temp = get_node_array<std::string>(node_ct, "reactions");
63✔
991
      for (const auto& b : temp) {
171✔
992
        int reaction_int = reaction_mt(b);
108✔
993
        if (reaction_int > 0) {
108!
994
          collision_track_config.mt_numbers.insert(reaction_int);
108✔
995
        }
996
      }
997
    }
63✔
998
    if (check_for_node(node_ct, "universe_ids")) {
148✔
999
      auto temp = get_node_array<int>(node_ct, "universe_ids");
30✔
1000
      for (const auto& b : temp) {
60✔
1001
        collision_track_config.universe_ids.insert(b);
30✔
1002
      }
1003
    }
30✔
1004
    if (check_for_node(node_ct, "material_ids")) {
148✔
1005
      auto temp = get_node_array<int>(node_ct, "material_ids");
30✔
1006
      for (const auto& b : temp) {
75✔
1007
        collision_track_config.material_ids.insert(b);
45✔
1008
      }
1009
    }
30✔
1010
    if (check_for_node(node_ct, "nuclides")) {
148✔
1011
      auto temp = get_node_array<std::string>(node_ct, "nuclides");
30✔
1012
      for (const auto& b : temp) {
120✔
1013
        collision_track_config.nuclides.insert(b);
90✔
1014
      }
1015
    }
30✔
1016
    if (check_for_node(node_ct, "deposited_E_threshold")) {
148✔
1017
      collision_track_config.deposited_energy_threshold =
60✔
1018
        std::stod(get_node_value(node_ct, "deposited_E_threshold"));
60✔
1019
    }
1020
    // Get maximum number of particles to be banked per collision
1021
    if (check_for_node(node_ct, "max_collisions")) {
148!
1022
      collision_track_config.max_collisions =
296✔
1023
        std::stoll(get_node_value(node_ct, "max_collisions"));
296✔
1024
    } else {
UNCOV
1025
      warning("A maximum number of collisions needs to be specified. "
×
1026
              "By default the code sets 'max_collisions' parameter equals to "
1027
              "1000.");
1028
    }
1029
    // Get maximum number of collision_track files to be created
1030
    if (check_for_node(node_ct, "max_collision_track_files")) {
148!
UNCOV
1031
      collision_track_config.max_files =
×
UNCOV
1032
        std::stoll(get_node_value(node_ct, "max_collision_track_files"));
×
1033
    }
1034
    if (check_for_node(node_ct, "mcpl")) {
148✔
1035
      collision_track_config.mcpl_write = get_node_value_bool(node_ct, "mcpl");
22✔
1036
    }
1037
  }
1038

1039
  // If source is not separate and is to be written out in the statepoint
1040
  // file, make sure that the sourcepoint batch numbers are contained in the
1041
  // statepoint list
1042
  if (!source_separate) {
8,191✔
1043
    for (const auto& b : sourcepoint_batch) {
16,336✔
1044
      if (!contains(statepoint_batch, b)) {
16,462!
UNCOV
1045
        fatal_error(
×
1046
          "Sourcepoint batches are not a subset of statepoint batches.");
1047
      }
1048
    }
1049
  }
1050

1051
  // Check if the user has specified to not reduce tallies at the end of every
1052
  // batch
1053
  if (check_for_node(root, "no_reduce")) {
8,191✔
1054
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
30✔
1055
  }
1056

1057
  // Check if the user has specified to use confidence intervals for
1058
  // uncertainties rather than standard deviations
1059
  if (check_for_node(root, "confidence_intervals")) {
8,191✔
1060
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
15✔
1061
  }
1062

1063
  // Check for output options
1064
  if (check_for_node(root, "output")) {
8,191✔
1065
    // Get pointer to output node
1066
    pugi::xml_node node_output = root.child("output");
764✔
1067

1068
    // Check for summary option
1069
    if (check_for_node(node_output, "summary")) {
764✔
1070
      output_summary = get_node_value_bool(node_output, "summary");
738✔
1071
    }
1072

1073
    // Check for ASCII tallies output option
1074
    if (check_for_node(node_output, "tallies")) {
764✔
1075
      output_tallies = get_node_value_bool(node_output, "tallies");
349✔
1076
    }
1077

1078
    // Set output directory if a path has been specified
1079
    if (check_for_node(node_output, "path")) {
764!
1080
      path_output = get_node_value(node_output, "path");
×
UNCOV
1081
      if (!ends_with(path_output, "/")) {
×
1082
        path_output += "/";
764!
1083
      }
1084
    }
1085
  }
1086

1087
  // Resonance scattering parameters
1088
  if (check_for_node(root, "resonance_scattering")) {
8,191✔
1089
    xml_node node_res_scat = root.child("resonance_scattering");
15✔
1090

1091
    // See if resonance scattering is enabled
1092
    if (check_for_node(node_res_scat, "enable")) {
15!
1093
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
15✔
1094
    } else {
UNCOV
1095
      res_scat_on = true;
×
1096
    }
1097

1098
    // Determine what method is used
1099
    if (check_for_node(node_res_scat, "method")) {
15!
1100
      auto temp = get_node_value(node_res_scat, "method", true, true);
15✔
1101
      if (temp == "rvs") {
15!
1102
        res_scat_method = ResScatMethod::rvs;
15✔
UNCOV
1103
      } else if (temp == "dbrc") {
×
UNCOV
1104
        res_scat_method = ResScatMethod::dbrc;
×
1105
      } else {
UNCOV
1106
        fatal_error(
×
UNCOV
1107
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1108
      }
1109
    }
15✔
1110

1111
    // Minimum energy for resonance scattering
1112
    if (check_for_node(node_res_scat, "energy_min")) {
15!
1113
      res_scat_energy_min =
30✔
1114
        std::stod(get_node_value(node_res_scat, "energy_min"));
30✔
1115
    }
1116
    if (res_scat_energy_min < 0.0) {
15!
UNCOV
1117
      fatal_error("Lower resonance scattering energy bound is negative");
×
1118
    }
1119

1120
    // Maximum energy for resonance scattering
1121
    if (check_for_node(node_res_scat, "energy_max")) {
15!
1122
      res_scat_energy_max =
30✔
1123
        std::stod(get_node_value(node_res_scat, "energy_max"));
30✔
1124
    }
1125
    if (res_scat_energy_max < res_scat_energy_min) {
15!
UNCOV
1126
      fatal_error("Upper resonance scattering energy bound is below the "
×
1127
                  "lower resonance scattering energy bound.");
1128
    }
1129

1130
    // Get resonance scattering nuclides
1131
    if (check_for_node(node_res_scat, "nuclides")) {
15!
1132
      res_scat_nuclides =
15✔
1133
        get_node_array<std::string>(node_res_scat, "nuclides");
30✔
1134
    }
1135
  }
1136

1137
  // Get volume calculations
1138
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
8,505✔
1139
    model::volume_calcs.emplace_back(node_vol);
314✔
1140
  }
1141

1142
  // Get temperature settings
1143
  if (check_for_node(root, "temperature_default")) {
8,191✔
1144
    temperature_default =
342✔
1145
      std::stod(get_node_value(root, "temperature_default"));
342✔
1146
  }
1147
  if (check_for_node(root, "temperature_method")) {
8,191✔
1148
    auto temp = get_node_value(root, "temperature_method", true, true);
485✔
1149
    if (temp == "nearest") {
485✔
1150
      temperature_method = TemperatureMethod::NEAREST;
304✔
1151
    } else if (temp == "interpolation") {
181!
1152
      temperature_method = TemperatureMethod::INTERPOLATION;
181✔
1153
    } else {
UNCOV
1154
      fatal_error("Unknown temperature method: " + temp);
×
1155
    }
1156
  }
485✔
1157
  if (check_for_node(root, "temperature_tolerance")) {
8,191✔
1158
    temperature_tolerance =
680✔
1159
      std::stod(get_node_value(root, "temperature_tolerance"));
680✔
1160
  }
1161
  if (check_for_node(root, "temperature_multipole")) {
8,191✔
1162
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
185✔
1163

1164
    // Multipole currently doesn't work with photon transport
1165
    if (temperature_multipole && photon_transport) {
185!
UNCOV
1166
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1167
                  "photon transport.");
1168
    }
1169
  }
1170
  if (check_for_node(root, "temperature_range")) {
8,191✔
1171
    auto range = get_node_array<double>(root, "temperature_range");
170✔
1172
    temperature_range[0] = range.at(0);
170✔
1173
    temperature_range[1] = range.at(1);
170✔
1174
  }
170✔
1175

1176
  // Check for tabular_legendre options
1177
  if (check_for_node(root, "tabular_legendre")) {
8,191✔
1178
    // Get pointer to tabular_legendre node
1179
    xml_node node_tab_leg = root.child("tabular_legendre");
90✔
1180

1181
    // Check for enable option
1182
    if (check_for_node(node_tab_leg, "enable")) {
90!
1183
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
90✔
1184
    }
1185

1186
    // Check for the number of points
1187
    if (check_for_node(node_tab_leg, "num_points")) {
90!
1188
      legendre_to_tabular_points =
×
UNCOV
1189
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
UNCOV
1190
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
UNCOV
1191
        fatal_error(
×
1192
          "The 'num_points' subelement/attribute of the "
1193
          "<tabular_legendre> element must contain a value greater than 1");
1194
      }
1195
    }
1196
  }
1197

1198
  // Check whether create delayed neutrons in fission
1199
  if (check_for_node(root, "create_delayed_neutrons")) {
8,191!
UNCOV
1200
    create_delayed_neutrons =
×
UNCOV
1201
      get_node_value_bool(root, "create_delayed_neutrons");
×
1202
  }
1203

1204
  // Check whether create fission sites
1205
  if (run_mode == RunMode::FIXED_SOURCE) {
8,191✔
1206
    if (check_for_node(root, "create_fission_neutrons")) {
2,798✔
1207
      create_fission_neutrons =
280✔
1208
        get_node_value_bool(root, "create_fission_neutrons");
280✔
1209
    }
1210
  }
1211

1212
  // Check whether to scale fission photon yields
1213
  if (check_for_node(root, "delayed_photon_scaling")) {
8,191!
UNCOV
1214
    delayed_photon_scaling =
×
UNCOV
1215
      get_node_value_bool(root, "delayed_photon_scaling");
×
1216
  }
1217

1218
  // Check whether to use event-based parallelism
1219
  if (check_for_node(root, "event_based")) {
8,191!
UNCOV
1220
    event_based = get_node_value_bool(root, "event_based");
×
1221
  }
1222

1223
  // Check whether material cell offsets should be generated
1224
  if (check_for_node(root, "material_cell_offsets")) {
8,191!
UNCOV
1225
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1226
  }
1227

1228
  // Weight window information
1229
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
8,296✔
1230
    variance_reduction::weight_windows.emplace_back(
105✔
1231
      std::make_unique<WeightWindows>(node_ww));
210✔
1232
  }
1233

1234
  // Enable weight windows by default if one or more are present
1235
  if (variance_reduction::weight_windows.size() > 0)
8,191✔
1236
    settings::weight_windows_on = true;
79✔
1237

1238
  // read weight windows from file
1239
  if (check_for_node(root, "weight_windows_file")) {
8,191!
UNCOV
1240
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1241
  }
1242

1243
  // read settings for weight windows value, this will override
1244
  // the automatic setting even if weight windows are present
1245
  if (check_for_node(root, "weight_windows_on")) {
8,191✔
1246
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
38✔
1247
  }
1248

1249
  if (check_for_node(root, "max_secondaries")) {
8,191!
UNCOV
1250
    settings::max_secondaries =
×
UNCOV
1251
      std::stoi(get_node_value(root, "max_secondaries"));
×
1252
  }
1253

1254
  if (check_for_node(root, "max_history_splits")) {
8,191✔
1255
    settings::max_history_splits =
428✔
1256
      std::stoi(get_node_value(root, "max_history_splits"));
428✔
1257
  }
1258

1259
  if (check_for_node(root, "max_tracks")) {
8,191✔
1260
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
90✔
1261
  }
1262

1263
  // Create weight window generator objects
1264
  if (check_for_node(root, "weight_window_generators")) {
8,191✔
1265
    auto wwgs_node = root.child("weight_window_generators");
79✔
1266
    for (pugi::xml_node node_wwg :
158✔
1267
      wwgs_node.children("weight_windows_generator")) {
158✔
1268
      variance_reduction::weight_windows_generators.emplace_back(
79✔
1269
        std::make_unique<WeightWindowsGenerator>(node_wwg));
158✔
1270
    }
1271
    // if any of the weight windows are intended to be generated otf, make
1272
    // sure they're applied
1273
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
79!
1274
      if (wwg->on_the_fly_) {
79!
1275
        settings::weight_windows_on = true;
79✔
1276
        break;
79✔
1277
      }
1278
    }
1279
  }
1280

1281
  // Set up weight window checkpoints
1282
  if (check_for_node(root, "weight_window_checkpoints")) {
8,191✔
1283
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
32✔
1284
    if (check_for_node(ww_checkpoints, "collision")) {
32!
1285
      weight_window_checkpoint_collision =
32✔
1286
        get_node_value_bool(ww_checkpoints, "collision");
32✔
1287
    }
1288
    if (check_for_node(ww_checkpoints, "surface")) {
32!
1289
      weight_window_checkpoint_surface =
32✔
1290
        get_node_value_bool(ww_checkpoints, "surface");
32✔
1291
    }
1292
  }
1293

1294
  if (weight_windows_on) {
8,191✔
1295
    if (!weight_window_checkpoint_surface &&
158✔
1296
        !weight_window_checkpoint_collision)
126!
UNCOV
1297
      fatal_error(
×
1298
        "Weight Windows are enabled but there are no valid checkpoints.");
1299
  }
1300

1301
  if (check_for_node(root, "use_decay_photons")) {
8,191✔
1302
    settings::use_decay_photons =
11✔
1303
      get_node_value_bool(root, "use_decay_photons");
11✔
1304
  }
1305
}
8,191✔
1306

1307
void free_memory_settings()
8,342✔
1308
{
1309
  settings::statepoint_batch.clear();
8,342✔
1310
  settings::sourcepoint_batch.clear();
8,342✔
1311
  settings::source_write_surf_id.clear();
8,342✔
1312
  settings::res_scat_nuclides.clear();
8,342✔
1313
}
8,342✔
1314

1315
//==============================================================================
1316
// C API functions
1317
//==============================================================================
1318

1319
extern "C" int openmc_set_n_batches(
220✔
1320
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1321
{
1322
  if (settings::n_inactive >= n_batches) {
220✔
1323
    set_errmsg("Number of active batches must be greater than zero.");
11✔
1324
    return OPENMC_E_INVALID_ARGUMENT;
11✔
1325
  }
1326

1327
  if (!settings::trigger_on) {
209✔
1328
    // Set n_batches and n_max_batches to same value
1329
    settings::n_batches = n_batches;
187✔
1330
    settings::n_max_batches = n_batches;
187✔
1331
  } else {
1332
    // Set n_batches and n_max_batches based on value of set_max_batches
1333
    if (set_max_batches) {
22✔
1334
      settings::n_max_batches = n_batches;
11✔
1335
    } else {
1336
      settings::n_batches = n_batches;
11✔
1337
    }
1338
  }
1339

1340
  // Update size of k_generation and entropy
1341
  int m = settings::n_max_batches * settings::gen_per_batch;
209✔
1342
  simulation::k_generation.reserve(m);
209✔
1343
  simulation::entropy.reserve(m);
209✔
1344

1345
  // Add value of n_batches to statepoint_batch
1346
  if (add_statepoint_batch &&
209✔
1347
      !(contains(settings::statepoint_batch, n_batches)))
198✔
1348
    settings::statepoint_batch.insert(n_batches);
33✔
1349

1350
  return 0;
1351
}
1352

1353
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,530✔
1354
{
1355
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,530✔
1356

1357
  return 0;
2,530✔
1358
}
1359

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