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

openmc-dev / openmc / 33522630326

01 Sep 2026 02:56PM UTC coverage: 81.412% (+0.08%) from 81.333%
33522630326

Pull #3944

github

web-flow
Merge 5e48e56ec into c6f91874b
Pull Request #3944: DNP drift (regular mesh only)

19142 of 27702 branches covered (69.1%)

Branch coverage included in aggregate %.

716 of 821 new or added lines in 22 files covered. (87.21%)

697 existing lines in 15 files now uncovered.

61072 of 70827 relevant lines covered (86.23%)

50626537.29 hits per line

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

77.08
/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/field.h"
23
#include "openmc/file_utils.h"
24
#include "openmc/mcpl_interface.h"
25
#include "openmc/mesh.h"
26
#include "openmc/message_passing.h"
27
#include "openmc/output.h"
28
#include "openmc/plot.h"
29
#include "openmc/random_lcg.h"
30
#include "openmc/random_ray/random_ray.h"
31
#include "openmc/reaction.h"
32
#include "openmc/simulation.h"
33
#include "openmc/source.h"
34
#include "openmc/string_utils.h"
35
#include "openmc/tallies/trigger.h"
36
#include "openmc/volume_calc.h"
37
#include "openmc/weight_windows.h"
38
#include "openmc/xml_interface.h"
39

40
namespace openmc {
41

42
//==============================================================================
43
// Global variables
44
//==============================================================================
45

46
namespace settings {
47

48
// Default values for boolean flags
49
bool assume_separate {false};
50
bool check_overlaps {false};
51
bool collision_track {false};
52
bool cmfd_run {false};
53
bool confidence_intervals {false};
54
bool create_delayed_neutrons {true};
55
bool create_fission_neutrons {true};
56
bool delayed_photon_scaling {true};
57
bool dnp_drift_on {false};
58
bool entropy_on {false};
59
bool event_based {false};
60
bool ifp_on {false};
61
bool legendre_to_tabular {true};
62
bool material_cell_offsets {true};
63
bool output_summary {true};
64
bool output_tallies {true};
65
bool particle_restart_run {false};
66
bool photon_transport {false};
67
bool atomic_relaxation {true};
68
bool reduce_tallies {true};
69
bool res_scat_on {false};
70
bool restart_run {false};
71
bool run_CE {true};
72
bool source_latest {false};
73
bool source_separate {false};
74
bool source_write {true};
75
bool source_mcpl_write {false};
76
bool surf_source_write {false};
77
bool surf_mcpl_write {false};
78
bool surf_source_read {false};
79
bool survival_biasing {false};
80
bool survival_normalization {false};
81
bool temperature_field_on {false};
82
bool temperature_multipole {false};
83
bool trigger_on {false};
84
bool trigger_predict {false};
85
bool uniform_source_sampling {false};
86
bool ufs_on {false};
87
bool urr_ptables_on {true};
88
bool use_decay_photons {false};
89
bool use_shared_secondary_bank {false};
90
bool weight_windows_on {false};
91
bool weight_window_checkpoint_surface {false};
92
bool weight_window_checkpoint_collision {true};
93
bool write_all_tracks {false};
94
bool write_initial_source {false};
95

96
std::string path_cross_sections;
97
std::string path_input;
98
std::string path_output;
99
std::string path_particle_restart;
100
std::string path_sourcepoint;
101
std::string path_statepoint;
102
const char* path_statepoint_c {path_statepoint.c_str()};
103
std::string weight_windows_file;
104
std::string properties_file;
105

106
int32_t n_inactive {0};
107
int32_t max_lost_particles {10};
108
double rel_max_lost_particles {1.0e-6};
109
int32_t max_write_lost_particles {-1};
110
int32_t gen_per_batch {1};
111
int64_t n_particles {-1};
112

113
int64_t max_particles_in_flight {100000};
114
int max_particle_events {1000000};
115

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

160
double dnp_drift_external_travel_time {0.0};
161
bool dnp_drift_recycling_on {false};
162

163
} // namespace settings
164

165
//==============================================================================
166
// Functions
167
//==============================================================================
168

169
void get_run_parameters(pugi::xml_node node_base)
8,496 ✔
170
{
171
  using namespace settings;
8,496 ✔
172
  using namespace pugi;
8,496 ✔
173

174
  // Check number of particles
175
  if (!check_for_node(node_base, "particles")) {
8,496 !
176
    fatal_error("Need to specify number of particles.");
×
177
  }
178

179
  // Get number of particles if it wasn't specified as a command-line argument
180
  if (n_particles == -1) {
8,496 ✔
181
    n_particles = std::stoll(get_node_value(node_base, "particles"));
8,452 ✔
182
  }
183

184
  // Get maximum number of in flight particles for event-based mode
185
  if (check_for_node(node_base, "max_particles_in_flight")) {
8,496 !
186
    max_particles_in_flight =
×
187
      std::stoll(get_node_value(node_base, "max_particles_in_flight"));
×
188
  }
189

190
  // Get maximum number of events allowed per particle
191
  if (check_for_node(node_base, "max_particle_events")) {
8,496 !
192
    max_particle_events =
×
193
      std::stoll(get_node_value(node_base, "max_particle_events"));
×
194
  }
195

196
  // Get number of basic batches
197
  if (check_for_node(node_base, "batches")) {
8,496 !
198
    n_batches = std::stoi(get_node_value(node_base, "batches"));
8,496 ✔
199
  }
200
  if (!trigger_on)
8,496 ✔
201
    n_max_batches = n_batches;
8,355 ✔
202

203
  // Get max number of lost particles
204
  if (check_for_node(node_base, "max_lost_particles")) {
8,496 ✔
205
    max_lost_particles =
92 ✔
206
      std::stoi(get_node_value(node_base, "max_lost_particles"));
46 ✔
207
  }
208

209
  // Get relative number of lost particles
210
  if (check_for_node(node_base, "rel_max_lost_particles")) {
8,496 !
211
    rel_max_lost_particles =
×
212
      std::stod(get_node_value(node_base, "rel_max_lost_particles"));
×
213
  }
214

215
  // Get relative number of lost particles
216
  if (check_for_node(node_base, "max_write_lost_particles")) {
8,496 ✔
217
    max_write_lost_particles =
30 ✔
218
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
15 ✔
219
  }
220

221
  // Get number of inactive batches
222
  if (run_mode == RunMode::EIGENVALUE ||
8,496 ✔
223
      solver_type == SolverType::RANDOM_RAY) {
3,519 ✔
224
    if (check_for_node(node_base, "inactive")) {
5,435 ✔
225
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,948 ✔
226
    }
227
    if (check_for_node(node_base, "generations_per_batch")) {
5,435 ✔
228
      gen_per_batch =
30 ✔
229
        std::stoi(get_node_value(node_base, "generations_per_batch"));
15 ✔
230
    }
231

232
    // Preallocate space for keff and entropy by generation
233
    int m = settings::n_max_batches * settings::gen_per_batch;
5,435 ✔
234
    simulation::k_generation.reserve(m);
5,435 ✔
235
    simulation::entropy.reserve(m);
5,435 ✔
236

237
    // Get the trigger information for keff
238
    if (check_for_node(node_base, "keff_trigger")) {
5,435 ✔
239
      xml_node node_keff_trigger = node_base.child("keff_trigger");
101 ✔
240

241
      if (check_for_node(node_keff_trigger, "type")) {
101 !
242
        auto temp = get_node_value(node_keff_trigger, "type", true, true);
101 ✔
243
        if (temp == "std_dev") {
101 !
244
          keff_trigger.metric = TriggerMetric::standard_deviation;
101 ✔
245
        } else if (temp == "variance") {
×
246
          keff_trigger.metric = TriggerMetric::variance;
×
247
        } else if (temp == "rel_err") {
×
248
          keff_trigger.metric = TriggerMetric::relative_error;
×
249
        } else {
250
          fatal_error("Unrecognized keff trigger type " + temp);
×
251
        }
252
      } else {
×
253
        fatal_error("Specify keff trigger type in settings XML");
×
254
      }
255

256
      if (check_for_node(node_keff_trigger, "threshold")) {
101 !
257
        keff_trigger.threshold =
202 ✔
258
          std::stod(get_node_value(node_keff_trigger, "threshold"));
202 ✔
259
        if (keff_trigger.threshold <= 0) {
101 !
260
          fatal_error("keff trigger threshold must be positive");
×
261
        }
262
      } else {
263
        fatal_error("Specify keff trigger threshold in settings XML");
×
264
      }
265
    }
266
  }
267

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

390
void read_settings_xml()
1,423 ✔
391
{
392
  using namespace settings;
1,423 ✔
393
  using namespace pugi;
1,423 ✔
394
  // Check if settings.xml exists
395
  std::string filename = settings::path_input + "settings.xml";
1,423 ✔
396
  if (!file_exists(filename)) {
1,423 ✔
397
    if (run_mode != RunMode::PLOTTING) {
22 !
398
      fatal_error("Could not find any XML input files! In order to run OpenMC, "
×
399
                  "you first need a set of input files; at a minimum, this "
400
                  "includes settings.xml, geometry.xml, and materials.xml or a "
401
                  "single model XML file. Please consult the user's guide at "
402
                  "https://docs.openmc.org for further information.");
403
    } else {
404
      // The settings.xml file is optional if we just want to make a plot.
405
      return;
22 ✔
406
    }
407
  }
408

409
  // Parse settings.xml file
410
  xml_document doc;
1,401 ✔
411
  auto result = doc.load_file(filename.c_str());
1,401 ✔
412
  if (!result) {
1,401 !
413
    fatal_error("Error processing settings.xml file.");
×
414
  }
415

416
  // Get root element
417
  xml_node root = doc.document_element();
1,401 ✔
418

419
  // Verbosity
420
  if (check_for_node(root, "verbosity") && verbosity == -1) {
1,401 !
421
    verbosity = std::stoi(get_node_value(root, "verbosity"));
428 ✔
422
  } else if (verbosity == -1) {
1,187 !
423
    verbosity = 7;
1,187 ✔
424
  }
425

426
  // To this point, we haven't displayed any output since we didn't know what
427
  // the verbosity is. Now that we checked for it, show the title if necessary
428
  if (mpi::master) {
1,401 ✔
429
    if (verbosity >= 2)
1,213 ✔
430
      title();
1,007 ✔
431
  }
432

433
  write_message("Reading settings XML file...", 5);
1,401 ✔
434

435
  read_settings_xml(root);
1,401 ✔
436
}
1,413 ✔
437

438
void read_settings_xml(pugi::xml_node root)
9,514 ✔
439
{
440
  using namespace settings;
9,514 ✔
441
  using namespace pugi;
9,514 ✔
442

443
  // Find if a multi-group or continuous-energy simulation is desired
444
  if (check_for_node(root, "energy_mode")) {
9,514 ✔
445
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
1,379 ✔
446
    if (temp_str == "mg" || temp_str == "multi-group") {
2,758 !
447
      run_CE = false;
1,379 ✔
448
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
449
      run_CE = true;
×
450
    }
451
  }
1,379 ✔
452

453
  // Check for user meshes and allocate
454
  read_meshes(root);
9,514 ✔
455

456
  // Look for deprecated cross_sections.xml file in settings.xml
457
  if (check_for_node(root, "cross_sections")) {
9,514 !
458
    warning(
×
459
      "Setting cross_sections in settings.xml has been deprecated."
460
      " The cross_sections are now set in materials.xml and the "
461
      "cross_sections input to materials.xml and the OPENMC_CROSS_SECTIONS"
462
      " environment variable will take precendent over setting "
463
      "cross_sections in settings.xml.");
464
    path_cross_sections = get_node_value(root, "cross_sections");
×
465
  }
466

467
  if (!run_CE) {
9,514 ✔
468
    // Scattering Treatments
469
    if (check_for_node(root, "max_order")) {
1,379 ✔
470
      max_order = std::stoi(get_node_value(root, "max_order"));
30 ✔
471
    } else {
472
      // Set to default of largest int - 1, which means to use whatever is
473
      // contained in library. This is largest int - 1 because for legendre
474
      // scattering, a value of 1 is added to the order; adding 1 to the largest
475
      // int gets you the largest negative integer, which is not what we want.
476
      max_order = std::numeric_limits<int>::max() - 1;
1,364 ✔
477
    }
478
  }
479

480
  // Check for a trigger node and get trigger information
481
  if (check_for_node(root, "trigger")) {
9,514 ✔
482
    xml_node node_trigger = root.child("trigger");
156 ✔
483

484
    // Check if trigger(s) are to be turned on
485
    trigger_on = get_node_value_bool(node_trigger, "active");
156 ✔
486

487
    if (trigger_on) {
156 ✔
488
      if (check_for_node(node_trigger, "max_batches")) {
141 !
489
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
282 ✔
490
      } else {
491
        fatal_error("<max_batches> must be specified with triggers");
×
492
      }
493

494
      // Get the batch interval to check triggers
495
      if (!check_for_node(node_trigger, "batch_interval")) {
141 ✔
496
        trigger_predict = true;
15 ✔
497
      } else {
498
        trigger_batch_interval =
252 ✔
499
          std::stoi(get_node_value(node_trigger, "batch_interval"));
252 ✔
500
        if (trigger_batch_interval <= 0) {
126 !
501
          fatal_error("Trigger batch interval must be greater than zero");
×
502
        }
503
      }
504
    }
505
  }
506

507
  // Check run mode if it hasn't been set from the command line
508
  xml_node node_mode;
9,514 ✔
509
  if (run_mode == RunMode::UNSET) {
9,514 ✔
510
    if (check_for_node(root, "run_mode")) {
8,528 ✔
511
      std::string temp_str = get_node_value(root, "run_mode", true, true);
8,498 ✔
512
      if (temp_str == "eigenvalue") {
8,498 ✔
513
        run_mode = RunMode::EIGENVALUE;
4,947 ✔
514
      } else if (temp_str == "fixed source") {
3,551 ✔
515
        run_mode = RunMode::FIXED_SOURCE;
3,519 ✔
516
      } else if (temp_str == "plot") {
32 !
517
        run_mode = RunMode::PLOTTING;
×
518
      } else if (temp_str == "particle restart") {
32 !
519
        run_mode = RunMode::PARTICLE;
×
520
      } else if (temp_str == "volume") {
32 !
521
        run_mode = RunMode::VOLUME;
32 ✔
522
      } else {
523
        fatal_error("Unrecognized run mode: " + temp_str);
×
524
      }
525

526
      // Assume XML specifies <particles>, <batches>, etc. directly
527
      node_mode = root;
8,498 ✔
528
    } else {
8,498 ✔
529
      warning("<run_mode> should be specified.");
30 ✔
530

531
      // Make sure that either eigenvalue or fixed source was specified
532
      node_mode = root.child("eigenvalue");
30 ✔
533
      if (node_mode) {
30 !
534
        run_mode = RunMode::EIGENVALUE;
30 ✔
535
      } else {
536
        node_mode = root.child("fixed_source");
×
537
        if (node_mode) {
×
538
          run_mode = RunMode::FIXED_SOURCE;
×
539
        } else {
540
          fatal_error("<eigenvalue> or <fixed_source> not specified.");
×
541
        }
542
      }
543
    }
544
  }
545

546
  // Check solver type
547
  if (check_for_node(root, "random_ray")) {
9,514 ✔
548
    solver_type = SolverType::RANDOM_RAY;
814 ✔
549
    if (run_CE)
814 !
550
      fatal_error("multi-group energy mode must be specified in settings XML "
×
551
                  "when using the random ray solver.");
552
  }
553

554
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
9,514 ✔
555
    // Read run parameters
556
    get_run_parameters(node_mode);
8,496 ✔
557

558
    // Check number of active batches, inactive batches, max lost particles and
559
    // particles
560
    if (n_batches <= n_inactive) {
8,496 !
561
      fatal_error("Number of active batches must be greater than zero.");
×
562
    } else if (n_inactive < 0) {
8,496 !
563
      fatal_error("Number of inactive batches must be non-negative.");
×
564
    } else if (n_particles <= 0) {
8,496 !
565
      fatal_error("Number of particles must be greater than zero.");
×
566
    } else if (max_lost_particles <= 0) {
8,496 !
567
      fatal_error("Number of max lost particles must be greater than zero.");
×
568
    } else if (rel_max_lost_particles <= 0.0 || rel_max_lost_particles >= 1.0) {
8,496 !
569
      fatal_error("Relative max lost particles must be between zero and one.");
×
570
    }
571

572
    // Check for user value for the number of generation of the Iterated Fission
573
    // Probability (IFP) method
574
    if (check_for_node(root, "ifp_n_generation")) {
8,496 ✔
575
      ifp_n_generation = std::stoi(get_node_value(root, "ifp_n_generation"));
210 ✔
576
      if (ifp_n_generation <= 0) {
105 !
577
        fatal_error("'ifp_n_generation' must be greater than 0.");
×
578
      }
579
      // Avoid tallying 0 if IFP logs are not complete when active cycles start
580
      if (ifp_n_generation > n_inactive) {
105 ✔
581
        fatal_error("'ifp_n_generation' must be lower than or equal to the "
9 ✔
582
                    "number of inactive cycles.");
583
      }
584
    }
585
  }
586

587
  // Copy plotting random number seed if specified
588
  if (check_for_node(root, "plot_seed")) {
9,505 !
589
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
590
    model::plotter_seed = seed;
×
591
  }
592

593
  // Copy random number seed if specified
594
  if (check_for_node(root, "seed")) {
9,505 ✔
595
    auto seed = std::stoll(get_node_value(root, "seed"));
1,200 ✔
596
    openmc_set_seed(seed);
600 ✔
597
  }
598

599
  // Copy random number stride if specified
600
  if (check_for_node(root, "stride")) {
9,505 ✔
601
    auto stride = std::stoull(get_node_value(root, "stride"));
30 ✔
602
    openmc_set_stride(stride);
15 ✔
603
  }
604

605
  // Check for electron treatment
606
  if (check_for_node(root, "electron_treatment")) {
9,505 ✔
607
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
108 ✔
608
    if (temp_str == "led") {
108 ✔
609
      electron_treatment = ElectronTreatment::LED;
41 ✔
610
    } else if (temp_str == "ttb") {
67 !
611
      electron_treatment = ElectronTreatment::TTB;
67 ✔
612
    } else {
613
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
614
    }
615
  }
108 ✔
616

617
  // Check for photon transport
618
  if (check_for_node(root, "photon_transport")) {
9,505 ✔
619
    photon_transport = get_node_value_bool(root, "photon_transport");
486 ✔
620

621
    if (!run_CE && photon_transport) {
486 !
622
      fatal_error("Photon transport is not currently supported in "
×
623
                  "multigroup mode");
624
    }
625
  }
626

627
  // Check for atomic relaxation
628
  if (check_for_node(root, "atomic_relaxation")) {
9,505 ✔
629
    atomic_relaxation = get_node_value_bool(root, "atomic_relaxation");
30 ✔
630
  }
631

632
  // Number of bins for logarithmic grid
633
  if (check_for_node(root, "log_grid_bins")) {
9,505 ✔
634
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
30 ✔
635
    if (n_log_bins < 1) {
15 !
636
      fatal_error("Number of bins for logarithmic grid must be greater "
×
637
                  "than zero.");
638
    }
639
  }
640

641
  // Number of OpenMP threads
642
  if (check_for_node(root, "threads")) {
9,505 !
643
    if (mpi::master)
×
644
      warning("The <threads> element has been deprecated. Use "
×
645
              "the OMP_NUM_THREADS environment variable to set the number of "
646
              "threads.");
647
  }
648

649
  // ==========================================================================
650
  // EXTERNAL SOURCE
651

652
  // Get point to list of <source> elements and make sure there is at least one
653
  for (pugi::xml_node node : root.children("source")) {
18,261 ✔
654
    model::external_sources.push_back(Source::create(node));
17,522 ✔
655
  }
656

657
  // Check if the user has specified to read surface source
658
  if (check_for_node(root, "surf_source_read")) {
9,495 ✔
659
    surf_source_read = true;
30 ✔
660
    // Get surface source read node
661
    xml_node node_ssr = root.child("surf_source_read");
30 ✔
662

663
    std::string path = "surface_source.h5";
30 ✔
664
    // Check if the user has specified different file for surface source reading
665
    if (check_for_node(node_ssr, "path")) {
30 !
666
      path = get_node_value(node_ssr, "path", false, true);
30 ✔
667
    }
668
    model::external_sources.push_back(make_unique<FileSource>(path));
30 ✔
669
  }
30 ✔
670

671
  // If no source specified, default to isotropic point source at origin with
672
  // Watt spectrum. No default source is needed in random ray mode.
673
  if (model::external_sources.empty() &&
9,495 ✔
674
      settings::solver_type != SolverType::RANDOM_RAY) {
2,465 ✔
675
    double T[] {0.0};
2,319 ✔
676
    double p[] {1.0};
2,319 ✔
677
    model::external_sources.push_back(make_unique<IndependentSource>(
2,319 ✔
678
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
4,638 ✔
679
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
4,638 ✔
680
      UPtrDist {new Discrete(T, p, 1)}));
4,638 ✔
681
  }
682

683
  // Build probability mass function for sampling external sources
684
  vector<double> source_strengths;
9,495 ✔
685
  for (auto& s : model::external_sources) {
20,633 ✔
686
    source_strengths.push_back(s->strength());
11,138 ✔
687
  }
688
  model::external_sources_probability.assign(source_strengths);
9,495 ✔
689

690
  // Check if we want to write out source
691
  if (check_for_node(root, "write_initial_source")) {
9,495 !
692
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
693
  }
694

695
  // Get relative number of lost particles
696
  if (check_for_node(root, "source_rejection_fraction")) {
9,495 ✔
697
    source_rejection_fraction =
14 ✔
698
      std::stod(get_node_value(root, "source_rejection_fraction"));
14 !
699
  }
700

701
  if (check_for_node(root, "free_gas_threshold")) {
9,495 !
702
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
703
  }
704

705
  // Surface grazing
706
  if (check_for_node(root, "surface_grazing_cutoff"))
9,495 !
707
    surface_grazing_cutoff =
×
708
      std::stod(get_node_value(root, "surface_grazing_cutoff"));
×
709
  if (check_for_node(root, "surface_grazing_ratio"))
9,495 !
710
    surface_grazing_ratio =
×
711
      std::stod(get_node_value(root, "surface_grazing_ratio"));
×
712

713
  // Survival biasing
714
  if (check_for_node(root, "survival_biasing")) {
9,495 ✔
715
    survival_biasing = get_node_value_bool(root, "survival_biasing");
227 ✔
716
  }
717

718
  // Probability tables
719
  if (check_for_node(root, "ptables")) {
9,495 ✔
720
    urr_ptables_on = get_node_value_bool(root, "ptables");
15 ✔
721
  }
722

723
  // Cutoffs
724
  if (check_for_node(root, "cutoff")) {
9,495 ✔
725
    xml_node node_cutoff = root.child("cutoff");
138 ✔
726
    if (check_for_node(node_cutoff, "weight")) {
138 ✔
727
      weight_cutoff = std::stod(get_node_value(node_cutoff, "weight"));
30 ✔
728
    }
729
    if (check_for_node(node_cutoff, "weight_avg")) {
138 ✔
730
      weight_survive = std::stod(get_node_value(node_cutoff, "weight_avg"));
30 ✔
731
    }
732
    if (check_for_node(node_cutoff, "survival_normalization")) {
138 !
733
      survival_normalization =
×
734
        get_node_value_bool(node_cutoff, "survival_normalization");
×
735
    }
736
    if (check_for_node(node_cutoff, "energy_neutron")) {
138 ✔
737
      energy_cutoff[0] =
15 ✔
738
        std::stod(get_node_value(node_cutoff, "energy_neutron"));
30 ✔
739
    } else if (check_for_node(node_cutoff, "energy")) {
123 !
740
      warning("The use of an <energy> cutoff is deprecated and should "
×
741
              "be replaced by <energy_neutron>.");
742
      energy_cutoff[0] = std::stod(get_node_value(node_cutoff, "energy"));
×
743
    }
744
    if (check_for_node(node_cutoff, "energy_photon")) {
138 ✔
745
      energy_cutoff[1] =
82 ✔
746
        std::stod(get_node_value(node_cutoff, "energy_photon"));
164 ✔
747
    }
748
    if (check_for_node(node_cutoff, "energy_electron")) {
138 !
749
      energy_cutoff[2] =
×
750
        std::stof(get_node_value(node_cutoff, "energy_electron"));
×
751
    }
752
    if (check_for_node(node_cutoff, "energy_positron")) {
138 !
753
      energy_cutoff[3] =
×
754
        std::stod(get_node_value(node_cutoff, "energy_positron"));
×
755
    }
756
    if (check_for_node(node_cutoff, "time_neutron")) {
138 ✔
757
      time_cutoff[0] = std::stod(get_node_value(node_cutoff, "time_neutron"));
26 ✔
758
    }
759
    if (check_for_node(node_cutoff, "time_photon")) {
138 !
760
      time_cutoff[1] = std::stod(get_node_value(node_cutoff, "time_photon"));
×
761
    }
762
    if (check_for_node(node_cutoff, "time_electron")) {
138 !
763
      time_cutoff[2] = std::stod(get_node_value(node_cutoff, "time_electron"));
×
764
    }
765
    if (check_for_node(node_cutoff, "time_positron")) {
138 !
766
      time_cutoff[3] = std::stod(get_node_value(node_cutoff, "time_positron"));
×
767
    }
768
  }
769

770
  // read properties from file
771
  if (check_for_node(root, "properties_file")) {
9,495 ✔
772
    properties_file = get_node_value(root, "properties_file");
11 ✔
773
    if (!file_exists(properties_file)) {
11 !
774
      fatal_error(fmt::format("File '{}' does not exist.", properties_file));
×
775
    }
776
  }
777

778
  // Particle trace
779
  if (check_for_node(root, "trace")) {
9,495 ✔
780
    auto temp = get_node_array<int64_t>(root, "trace");
15 ✔
781
    if (temp.size() != 3) {
15 !
782
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
783
                  "batch, generation, and particle number.");
784
    }
785
    trace_batch = temp.at(0);
15 ✔
786
    trace_gen = temp.at(1);
15 ✔
787
    trace_particle = temp.at(2);
15 ✔
788
  }
15 ✔
789

790
  // Particle tracks
791
  if (check_for_node(root, "track")) {
9,495 ✔
792
    // Get values and make sure there are three per particle
793
    auto temp = get_node_array<int>(root, "track");
45 ✔
794
    if (temp.size() % 3 != 0) {
45 !
795
      fatal_error(
×
796
        "Number of integers specified in 'track' is not "
797
        "divisible by 3.  Please provide 3 integers per particle to be "
798
        "tracked.");
799
    }
800

801
    // Reshape into track_identifiers
802
    int n_tracks = temp.size() / 3;
45 ✔
803
    for (int i = 0; i < n_tracks; ++i) {
180 ✔
804
      track_identifiers.push_back(
135 ✔
805
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
135 ✔
806
    }
807
  }
45 ✔
808

809
  // Shannon entropy
810
  if (solver_type == SolverType::RANDOM_RAY) {
9,495 ✔
811
    if (check_for_node(root, "entropy_mesh")) {
814 !
812
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
813
                  "No user-defined entropy mesh is supported.");
814
    }
815
    entropy_on = true;
814 ✔
816
  } else if (solver_type == SolverType::MONTE_CARLO) {
8,681 !
817
    if (check_for_node(root, "entropy_mesh")) {
8,681 ✔
818
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
668 ✔
819
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
334 !
820
        fatal_error(fmt::format(
×
821
          "Mesh {} specified for Shannon entropy does not exist.", temp));
822
      }
823

824
      auto* m = dynamic_cast<RegularMesh*>(
334 !
825
        model::meshes[model::mesh_map.at(temp)].get());
334 !
826
      if (!m)
334 !
827
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
828
      simulation::entropy_mesh = m;
334 ✔
829

830
      // Turn on Shannon entropy calculation
831
      entropy_on = true;
334 ✔
832

833
    } else if (check_for_node(root, "entropy")) {
8,347 !
834
      fatal_error(
×
835
        "Specifying a Shannon entropy mesh via the <entropy> element "
836
        "is deprecated. Please create a mesh using <mesh> and then reference "
837
        "it by specifying its ID in an <entropy_mesh> element.");
838
    }
839
  }
840

841
  // Temperature field
842
  if (check_for_node(root, "temperature_field")) {
9,495 ✔
843
    temperature_field_on = true;
232 ✔
844

845
    // Get pointer to temperature_field node
846
    auto node_tf = root.child("temperature_field");
232 ✔
847

848
    // Mesh parameter
849
    Mesh* tf_mesh_ptr;
232 ✔
850
    if (check_for_node(node_tf, "mesh")) {
232 ✔
851
      int temp = std::stoi(get_node_value(node_tf, "mesh"));
442 ✔
852
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
221 ✔
853
        throw std::runtime_error(fmt::format(
11 ✔
854
          "Mesh {} specified for the temperature field does not exist.", temp));
22 ✔
855
      }
856
      tf_mesh_ptr = model::meshes[model::mesh_map.at(temp)].get();
210 ✔
857
    } else {
858
      throw std::runtime_error(
11 ✔
859
        "A mesh must be given for the temperature field.");
22 ✔
860
    }
861

862
    // Values parameter
863
    vector<double> tf_values;
210 ✔
864
    if (check_for_node(node_tf, "values")) {
210 ✔
865
      auto temp = get_node_array<double>(node_tf, "values");
199 ✔
866
      if (temp.size() != tf_mesh_ptr->n_bins()) {
199 ✔
867
        throw std::runtime_error(
11 ✔
868
          "Inconsistency in the temperature field: the number of "
869
          "values must be equal to the number of bins in the mesh.");
22 ✔
870
      }
871
      for (const auto& b : temp) {
1,692 ✔
872
        tf_values.push_back(b);
1,504 ✔
873
      }
874
    } else {
11 ✔
875
      throw std::runtime_error(
11 ✔
876
        "Temperature values must be given for the temperature field.");
22 ✔
877
    }
878

879
    // Mapping representation
880
    std::string mapping;
188 ✔
881
    if (check_for_node(node_tf, "mapping")) {
188 !
NEW
882
      mapping = get_node_value(node_tf, "mapping");
×
883
    } else {
884
      mapping = "cell";
188 ✔
885
    }
886

887
    // Instantiate the temperature field
888
    simulation::temperature_field =
188 ✔
889
      TemperatureField(tf_mesh_ptr, tf_values, mapping);
376 ✔
890
  }
210 ✔
891

892
  // Uniform fission source weighting mesh
893
  if (check_for_node(root, "ufs_mesh")) {
9,451 ✔
894
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
30 ✔
895
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
15 !
896
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
897
                              "method does not exist.",
898
        temp));
899
    }
900

901
    auto* m =
15 ✔
902
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
15 !
903
    if (!m)
15 !
904
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
905
    simulation::ufs_mesh = m;
15 ✔
906

907
    // Turn on uniform fission source weighting
908
    ufs_on = true;
15 ✔
909

910
  } else if (check_for_node(root, "uniform_fs")) {
9,436 !
911
    fatal_error(
×
912
      "Specifying a UFS mesh via the <uniform_fs> element "
913
      "is deprecated. Please create a mesh using <mesh> and then reference "
914
      "it by specifying its ID in a <ufs_mesh> element.");
915
  }
916

917
  // Check if the user has specified to write state points
918
  if (check_for_node(root, "state_point")) {
9,451 ✔
919

920
    // Get pointer to state_point node
921
    auto node_sp = root.child("state_point");
160 ✔
922

923
    // Determine number of batches at which to store state points
924
    if (check_for_node(node_sp, "batches")) {
160 !
925
      // User gave specific batches to write state points
926
      auto temp = get_node_array<int>(node_sp, "batches");
160 ✔
927
      for (const auto& b : temp) {
491 ✔
928
        statepoint_batch.insert(b);
331 ✔
929
      }
930
    } else {
160 ✔
931
      // If neither were specified, write state point at last batch
932
      statepoint_batch.insert(n_batches);
×
933
    }
934
  } else {
935
    // If no <state_point> tag was present, by default write state point at
936
    // last batch only
937
    statepoint_batch.insert(n_batches);
9,291 ✔
938
  }
939

940
  // Check if the user has specified to write source points
941
  if (check_for_node(root, "source_point")) {
9,451 ✔
942
    // Get source_point node
943
    xml_node node_sp = root.child("source_point");
101 ✔
944

945
    // Determine batches at which to store source points
946
    if (check_for_node(node_sp, "batches")) {
101 ✔
947
      // User gave specific batches to write source points
948
      auto temp = get_node_array<int>(node_sp, "batches");
45 ✔
949
      for (const auto& b : temp) {
120 ✔
950
        sourcepoint_batch.insert(b);
75 ✔
951
      }
952
    } else {
45 ✔
953
      // If neither were specified, write source points with state points
954
      sourcepoint_batch = statepoint_batch;
56 !
955
    }
956

957
    // Check if the user has specified to write binary source file
958
    if (check_for_node(node_sp, "separate")) {
101 ✔
959
      source_separate = get_node_value_bool(node_sp, "separate");
71 ✔
960
    }
961
    if (check_for_node(node_sp, "write")) {
101 !
962
      source_write = get_node_value_bool(node_sp, "write");
×
963
    }
964
    if (check_for_node(node_sp, "mcpl")) {
101 ✔
965
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
26 ✔
966
    }
967
    if (check_for_node(node_sp, "overwrite_latest")) {
101 ✔
968
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
15 ✔
969
      source_separate = source_latest;
15 ✔
970
    }
971
  } else {
972
    // If no <source_point> tag was present, by default we keep source bank in
973
    // statepoint file and write it out at statepoints intervals
974
    source_separate = false;
9,350 ✔
975
    sourcepoint_batch = statepoint_batch;
9,350 !
976
  }
977

978
  // Check is the user specified to convert strength to statistical weight
979
  if (check_for_node(root, "uniform_source_sampling")) {
9,451 ✔
980
    uniform_source_sampling =
55 ✔
981
      get_node_value_bool(root, "uniform_source_sampling");
55 ✔
982
  }
983

984
  // Check if the user has specified to write surface source
985
  if (check_for_node(root, "surf_source_write")) {
9,451 ✔
986
    surf_source_write = true;
412 ✔
987
    // Get surface source write node
988
    xml_node node_ssw = root.child("surf_source_write");
412 ✔
989

990
    // Determine surface ids at which crossing particles are to be banked.
991
    // If no surfaces are specified, all surfaces in the model will be used
992
    // to bank source points.
993
    if (check_for_node(node_ssw, "surface_ids")) {
412 ✔
994
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
202 ✔
995
      for (const auto& b : temp) {
994 ✔
996
        source_write_surf_id.insert(b);
792 ✔
997
      }
998
    }
202 ✔
999

1000
    // Get maximum number of particles to be banked per surface
1001
    if (check_for_node(node_ssw, "max_particles")) {
412 ✔
1002
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
806 ✔
1003
    } else {
1004
      fatal_error("A maximum number of particles needs to be specified "
9 ✔
1005
                  "using the 'max_particles' parameter to store surface "
1006
                  "source points.");
1007
    }
1008

1009
    // Get maximum number of surface source files to be created
1010
    if (check_for_node(node_ssw, "max_source_files")) {
403 ✔
1011
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
66 ✔
1012
    } else {
1013
      ssw_max_files = 1;
370 ✔
1014
    }
1015

1016
    if (check_for_node(node_ssw, "mcpl")) {
403 ✔
1017
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
11 ✔
1018
    }
1019
    // Get cell information
1020
    if (check_for_node(node_ssw, "cell")) {
403 ✔
1021
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
208 ✔
1022
      ssw_cell_type = SSWCellType::Both;
104 ✔
1023
    }
1024
    if (check_for_node(node_ssw, "cellfrom")) {
403 ✔
1025
      if (ssw_cell_id != C_NONE) {
90 ✔
1026
        fatal_error(
18 ✔
1027
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
1028
      }
1029
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
144 ✔
1030
      ssw_cell_type = SSWCellType::From;
72 ✔
1031
    }
1032
    if (check_for_node(node_ssw, "cellto")) {
385 ✔
1033
      if (ssw_cell_id != C_NONE) {
71 ✔
1034
        fatal_error(
18 ✔
1035
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
1036
      }
1037
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
106 ✔
1038
      ssw_cell_type = SSWCellType::To;
53 ✔
1039
    }
1040
  }
1041

1042
  // Check if the user has specified to write specific collisions
1043
  if (check_for_node(root, "collision_track")) {
9,406 ✔
1044
    settings::collision_track = true;
160 ✔
1045
    // Get collision track node
1046
    xml_node node_ct = root.child("collision_track");
160 ✔
1047
    collision_track_config = CollisionTrackConfig {};
160 ✔
1048

1049
    // Determine cell ids at which crossing particles are to be banked
1050
    if (check_for_node(node_ct, "cell_ids")) {
160 ✔
1051
      auto temp = get_node_array<int>(node_ct, "cell_ids");
89 ✔
1052
      for (const auto& b : temp) {
237 ✔
1053
        collision_track_config.cell_ids.insert(b);
148 ✔
1054
      }
1055
    }
89 ✔
1056
    if (check_for_node(node_ct, "reactions")) {
160 ✔
1057
      auto temp = get_node_array<std::string>(node_ct, "reactions");
63 ✔
1058
      for (const auto& b : temp) {
171 ✔
1059
        int reaction_int = reaction_mt(b);
108 ✔
1060
        if (reaction_int > 0) {
108 !
1061
          collision_track_config.mt_numbers.insert(reaction_int);
108 ✔
1062
        }
1063
      }
1064
    }
63 ✔
1065
    if (check_for_node(node_ct, "universe_ids")) {
160 ✔
1066
      auto temp = get_node_array<int>(node_ct, "universe_ids");
30 ✔
1067
      for (const auto& b : temp) {
60 ✔
1068
        collision_track_config.universe_ids.insert(b);
30 ✔
1069
      }
1070
    }
30 ✔
1071
    if (check_for_node(node_ct, "material_ids")) {
160 ✔
1072
      auto temp = get_node_array<int>(node_ct, "material_ids");
30 ✔
1073
      for (const auto& b : temp) {
75 ✔
1074
        collision_track_config.material_ids.insert(b);
45 ✔
1075
      }
1076
    }
30 ✔
1077
    if (check_for_node(node_ct, "nuclides")) {
160 ✔
1078
      auto temp = get_node_array<std::string>(node_ct, "nuclides");
30 ✔
1079
      for (const auto& b : temp) {
120 ✔
1080
        collision_track_config.nuclides.insert(b);
90 ✔
1081
      }
1082
    }
30 ✔
1083
    if (check_for_node(node_ct, "deposited_E_threshold")) {
160 ✔
1084
      collision_track_config.deposited_energy_threshold =
60 ✔
1085
        std::stod(get_node_value(node_ct, "deposited_E_threshold"));
60 ✔
1086
    }
1087
    // Get maximum number of particles to be banked per collision
1088
    if (check_for_node(node_ct, "max_collisions")) {
160 !
1089
      collision_track_config.max_collisions =
320 ✔
1090
        std::stoll(get_node_value(node_ct, "max_collisions"));
320 ✔
1091
    } else {
1092
      warning("A maximum number of collisions needs to be specified. "
×
1093
              "By default the code sets 'max_collisions' parameter equals to "
1094
              "1000.");
1095
    }
1096
    // Get maximum number of collision_track files to be created
1097
    if (check_for_node(node_ct, "max_collision_track_files")) {
160 !
1098
      collision_track_config.max_files =
×
1099
        std::stoll(get_node_value(node_ct, "max_collision_track_files"));
×
1100
    }
1101
    if (check_for_node(node_ct, "mcpl")) {
160 ✔
1102
      collision_track_config.mcpl_write = get_node_value_bool(node_ct, "mcpl");
22 ✔
1103
    }
1104
  }
1105

1106
  // If source is not separate and is to be written out in the statepoint
1107
  // file, make sure that the sourcepoint batch numbers are contained in the
1108
  // statepoint list
1109
  if (!source_separate) {
9,406 ✔
1110
    for (const auto& b : sourcepoint_batch) {
18,766 ✔
1111
      if (!contains(statepoint_batch, b)) {
18,892 !
1112
        fatal_error(
×
1113
          "Sourcepoint batches are not a subset of statepoint batches.");
1114
      }
1115
    }
1116
  }
1117

1118
  // Check if the user has specified to not reduce tallies at the end of every
1119
  // batch
1120
  if (check_for_node(root, "no_reduce")) {
9,406 ✔
1121
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
30 ✔
1122
  }
1123

1124
  // Check if the user has specified to use confidence intervals for
1125
  // uncertainties rather than standard deviations
1126
  if (check_for_node(root, "confidence_intervals")) {
9,406 ✔
1127
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
15 ✔
1128
  }
1129

1130
  // Check for output options
1131
  if (check_for_node(root, "output")) {
9,406 ✔
1132
    // Get pointer to output node
1133
    pugi::xml_node node_output = root.child("output");
845 ✔
1134

1135
    // Check for summary option
1136
    if (check_for_node(node_output, "summary")) {
845 ✔
1137
      output_summary = get_node_value_bool(node_output, "summary");
819 ✔
1138
    }
1139

1140
    // Check for ASCII tallies output option
1141
    if (check_for_node(node_output, "tallies")) {
845 ✔
1142
      output_tallies = get_node_value_bool(node_output, "tallies");
371 ✔
1143
    }
1144

1145
    // Set output directory if a path has been specified
1146
    if (check_for_node(node_output, "path")) {
845 !
1147
      path_output = get_node_value(node_output, "path");
×
1148
      if (!ends_with(path_output, "/")) {
×
1149
        path_output += "/";
845 !
1150
      }
1151
    }
1152
  }
1153

1154
  // Resonance scattering parameters
1155
  if (check_for_node(root, "resonance_scattering")) {
9,406 ✔
1156
    xml_node node_res_scat = root.child("resonance_scattering");
15 ✔
1157

1158
    // See if resonance scattering is enabled
1159
    if (check_for_node(node_res_scat, "enable")) {
15 !
1160
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
15 ✔
1161
    } else {
1162
      res_scat_on = true;
×
1163
    }
1164

1165
    // Determine what method is used
1166
    if (check_for_node(node_res_scat, "method")) {
15 !
1167
      auto temp = get_node_value(node_res_scat, "method", true, true);
15 ✔
1168
      if (temp == "rvs") {
15 !
1169
        res_scat_method = ResScatMethod::rvs;
15 ✔
1170
      } else if (temp == "dbrc") {
×
1171
        res_scat_method = ResScatMethod::dbrc;
×
1172
      } else {
1173
        fatal_error(
×
1174
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1175
      }
1176
    }
15 ✔
1177

1178
    // Minimum energy for resonance scattering
1179
    if (check_for_node(node_res_scat, "energy_min")) {
15 !
1180
      res_scat_energy_min =
30 ✔
1181
        std::stod(get_node_value(node_res_scat, "energy_min"));
30 ✔
1182
    }
1183
    if (res_scat_energy_min < 0.0) {
15 !
1184
      fatal_error("Lower resonance scattering energy bound is negative");
×
1185
    }
1186

1187
    // Maximum energy for resonance scattering
1188
    if (check_for_node(node_res_scat, "energy_max")) {
15 !
1189
      res_scat_energy_max =
30 ✔
1190
        std::stod(get_node_value(node_res_scat, "energy_max"));
30 ✔
1191
    }
1192
    if (res_scat_energy_max < res_scat_energy_min) {
15 !
1193
      fatal_error("Upper resonance scattering energy bound is below the "
×
1194
                  "lower resonance scattering energy bound.");
1195
    }
1196

1197
    // Get resonance scattering nuclides
1198
    if (check_for_node(node_res_scat, "nuclides")) {
15 !
1199
      res_scat_nuclides =
15 ✔
1200
        get_node_array<std::string>(node_res_scat, "nuclides");
30 ✔
1201
    }
1202
  }
1203

1204
  // Get volume calculations
1205
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
9,716 ✔
1206
    model::volume_calcs.emplace_back(node_vol);
310 ✔
1207
  }
1208

1209
  // Get temperature settings
1210
  if (check_for_node(root, "temperature_default")) {
9,406 ✔
1211
    temperature_default =
342 ✔
1212
      std::stod(get_node_value(root, "temperature_default"));
342 ✔
1213
  }
1214
  if (check_for_node(root, "temperature_method")) {
9,406 ✔
1215
    auto temp = get_node_value(root, "temperature_method", true, true);
515 ✔
1216
    if (temp == "nearest") {
515 ✔
1217
      temperature_method = TemperatureMethod::NEAREST;
304 ✔
1218
    } else if (temp == "interpolation") {
211 !
1219
      temperature_method = TemperatureMethod::INTERPOLATION;
211 ✔
1220
    } else {
1221
      fatal_error("Unknown temperature method: " + temp);
×
1222
    }
1223
  }
515 ✔
1224
  if (check_for_node(root, "temperature_tolerance")) {
9,406 ✔
1225
    temperature_tolerance =
1,056 ✔
1226
      std::stod(get_node_value(root, "temperature_tolerance"));
1,056 ✔
1227
  }
1228
  if (check_for_node(root, "temperature_multipole")) {
9,406 ✔
1229
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
373 ✔
1230

1231
    // Multipole currently doesn't work with photon transport
1232
    if (temperature_multipole && photon_transport) {
373 !
1233
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1234
                  "photon transport.");
1235
    }
1236
  }
1237
  if (check_for_node(root, "temperature_range")) {
9,406 ✔
1238
    auto range = get_node_array<double>(root, "temperature_range");
170 ✔
1239
    temperature_range[0] = range.at(0);
170 ✔
1240
    temperature_range[1] = range.at(1);
170 ✔
1241
  }
170 ✔
1242

1243
  // Explicit transport of Delayed Neutron Precursor (DNP)
1244
  if (check_for_node(root, "dnp_drift")) {
9,406 ✔
1245
    dnp_drift_on = true;
30 ✔
1246
    auto node_dnp_drift = root.child("dnp_drift");
30 ✔
1247

1248
    // Mesh
1249
    Mesh* mesh_ptr;
30 ✔
1250
    if (check_for_node(node_dnp_drift, "field_mesh")) {
30 !
1251
      int temp = std::stoi(get_node_value(node_dnp_drift, "field_mesh"));
60 ✔
1252
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
30 !
NEW
1253
        fatal_error(fmt::format(
×
1254
          "Mesh {} specified for the velocity field does not exist.", temp));
1255
      }
1256
      mesh_ptr = model::meshes[model::mesh_map.at(temp)].get();
30 ✔
1257
    } else {
NEW
1258
      fatal_error("A mesh must be given for the velocity field.");
×
1259
    }
1260

1261
    // Values
1262
    vector<Direction> vf_values;
30 ✔
1263
    if (check_for_node(node_dnp_drift, "field_values")) {
30 !
1264
      auto temp = get_node_array<double>(node_dnp_drift, "field_values");
30 ✔
1265
      if (temp.size() % 3 != 0) {
30 !
NEW
1266
        fatal_error("The number of values must be a multiple of 3.");
×
1267
      }
1268
      for (size_t i = 0; i + 2 < temp.size(); i += 3) {
555 ✔
1269
        Direction d = Direction(temp[i], temp[i + 1], temp[i + 2]);
525 ✔
1270
        vf_values.push_back(d);
525 ✔
1271
      }
NEW
1272
    } else {
×
NEW
1273
      fatal_error("Values must be given for the velocity field.");
×
1274
    }
1275

1276
    // Mapping representation
1277
    std::string field_mapping;
30 ✔
1278
    if (check_for_node(node_dnp_drift, "field_mapping")) {
30 !
1279
      field_mapping = get_node_value(node_dnp_drift, "field_mapping");
30 ✔
1280
    } else {
NEW
1281
      fatal_error(
×
1282
        "A mapping representation must be given for the velocity field.");
1283
    }
1284

1285
    // Velocity field
1286
    simulation::velocity_field =
30 ✔
1287
      VelocityField(mesh_ptr, vf_values, field_mapping);
30 ✔
1288

1289
    // Boundary conditions map
1290
    if (check_for_node(node_dnp_drift, "boundary_map")) {
30 !
1291
      BCMap bc_map;
30 ✔
1292
      auto node_boundary = node_dnp_drift.child("boundary_map");
30 ✔
1293

1294
      if (check_for_node(node_boundary, "inlet")) {
30 !
1295
        bc_map[BCType::INLET] = get_node_array<int>(node_boundary, "inlet");
30 ✔
1296
      } else {
NEW
1297
        fatal_error("Inlet boundary conditions must be declared.");
×
1298
      }
1299

1300
      if (check_for_node(node_boundary, "outlet")) {
30 !
1301
        bc_map[BCType::OUTLET] = get_node_array<int>(node_boundary, "outlet");
30 ✔
1302
      } else {
NEW
1303
        fatal_error("Outlet boundary conditions must be declared.");
×
1304
      }
1305

1306
      if (check_for_node(node_boundary, "wall")) {
30 !
1307
        bc_map[BCType::WALL] = get_node_array<int>(node_boundary, "wall");
30 ✔
1308
      } else {
NEW
1309
        fatal_error("Wall boundary conditions must be declared.");
×
1310
      }
1311

1312
      simulation::velocity_field.bc_map() = bc_map;
60 ✔
1313

NEW
1314
    } else {
×
NEW
1315
      fatal_error("Boundary conditions must be declared.");
×
1316
    }
1317

1318
    // Integrator
1319
    if (check_for_node(node_dnp_drift, "integrator")) {
30 !
1320
      std::string integration_method =
30 ✔
1321
        get_node_value(node_dnp_drift, "integrator");
30 ✔
1322

1323
      // Runge Kutta 4
1324
      if (integration_method == "RK4") {
30 !
1325

1326
        // Time step
1327
        double dt;
30 ✔
1328
        if (!check_for_node(node_dnp_drift, "integrator_dt")) {
30 !
NEW
1329
          fatal_error("The attribute 'integrator_dt' is not declared in the "
×
1330
                      "DNP drift settings.");
1331
        } else {
1332
          dt = std::stod(get_node_value(node_dnp_drift, "integrator_dt"));
60 ✔
1333
        }
1334

1335
        // Instantiate integrator
1336
        simulation::streamline_integrator =
30 ✔
1337
          std::make_unique<RK4StreamlineIntegrator>(dt);
30 ✔
1338

1339
        // Undefined integration method
1340
      } else {
NEW
1341
        fatal_error(
×
NEW
1342
          fmt::format("Integrator '{}' not implemented", integration_method));
×
1343
      }
NEW
1344
    } else {
×
NEW
1345
      fatal_error("An integrator should be defined in the DNP drift settings.");
×
1346
    }
1347

1348
    // Recycle precursor when reaching an outlet?
1349
    if (check_for_node(node_dnp_drift, "recycling")) {
30 !
1350
      dnp_drift_recycling_on = get_node_value_bool(node_dnp_drift, "recycling");
30 ✔
1351
      if (dnp_drift_recycling_on) {
30 !
1352
        if (!check_for_node(node_dnp_drift, "external_travel_time")) {
30 !
NEW
1353
          fatal_error("The external travel time is not declared in "
×
1354
                      "the DNP drift settings.");
1355
        } else {
1356
          dnp_drift_external_travel_time =
60 ✔
1357
            std::stod(get_node_value(node_dnp_drift, "external_travel_time"));
60 ✔
1358
        }
1359
      }
1360
    }
1361
  }
30 ✔
1362

1363
  // Add physical group information to mesh
1364
  if (check_for_node(root, "mesh_physical_group")) {
9,406 ✔
1365

1366
    auto node_physical_group = root.child("mesh_physical_group");
30 ✔
1367

1368
    // Mesh pointer
1369
    Mesh* mesh_ptr;
30 ✔
1370
    if (check_for_node(node_physical_group, "mesh")) {
30 !
1371
      int temp = std::stoi(get_node_value(node_physical_group, "mesh"));
60 ✔
1372
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
30 !
NEW
1373
        fatal_error(fmt::format(
×
1374
          "Mesh {} specified for the physical groups does not exist.", temp));
1375
      }
1376
      mesh_ptr = model::meshes[model::mesh_map.at(temp)].get();
30 ✔
1377
    } else {
NEW
1378
      fatal_error("A mesh must be given for the velocity field.");
×
1379
    }
1380

1381
    // Face IDs
1382
    vector<int> face_ids;
30 ✔
1383
    if (check_for_node(node_physical_group, "face_ids")) {
30 !
1384
      face_ids = get_node_array<int>(node_physical_group, "face_ids");
60 ✔
1385
    } else {
NEW
1386
      fatal_error("Surface IDs must be declared.");
×
1387
    }
1388

1389
    // Check for duplicate face IDs
1390
    std::set<int> unique_face_ids(face_ids.begin(), face_ids.end());
30 ✔
1391
    if (unique_face_ids.size() != face_ids.size()) {
30 !
NEW
1392
      fatal_error("Duplicate face IDs found in physical groups definition!");
×
1393
    }
1394

1395
    // Physical groups
1396
    vector<int> physical_groups;
30 ✔
1397
    if (check_for_node(node_physical_group, "physical_groups")) {
30 !
1398
      physical_groups =
30 ✔
1399
        get_node_array<int>(node_physical_group, "physical_groups");
60 ✔
1400
    } else {
NEW
1401
      fatal_error("Physical_groups must be declared.");
×
1402
    }
1403

1404
    // Check for consistency
1405
    if (face_ids.size() != physical_groups.size()) {
30 !
NEW
1406
      fatal_error(
×
1407
        "The lists of face IDs and physical groups must have the same size!");
1408
    }
1409

1410
    // Create the physical group map
1411
    PGMap pg_map;
30 ✔
1412
    for (size_t i = 0; i < face_ids.size(); i++) {
750 ✔
1413
      pg_map[physical_groups[i]].push_back(face_ids[i]);
720 ✔
1414
    }
1415

1416
    // Save the map in the mesh
1417
    mesh_ptr->pg_map() = pg_map;
60 !
1418
  }
30 ✔
1419

1420
  // Check for tabular_legendre options
1421
  if (check_for_node(root, "tabular_legendre")) {
9,406 ✔
1422
    // Get pointer to tabular_legendre node
1423
    xml_node node_tab_leg = root.child("tabular_legendre");
105 ✔
1424

1425
    // Check for enable option
1426
    if (check_for_node(node_tab_leg, "enable")) {
105 !
1427
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
105 ✔
1428
    }
1429

1430
    // Check for the number of points
1431
    if (check_for_node(node_tab_leg, "num_points")) {
105 !
1432
      legendre_to_tabular_points =
×
1433
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
1434
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
1435
        fatal_error(
×
1436
          "The 'num_points' subelement/attribute of the "
1437
          "<tabular_legendre> element must contain a value greater than 1");
1438
      }
1439
    }
1440
  }
1441

1442
  // Check whether create delayed neutrons in fission
1443
  if (check_for_node(root, "create_delayed_neutrons")) {
9,406 !
1444
    create_delayed_neutrons =
×
1445
      get_node_value_bool(root, "create_delayed_neutrons");
×
1446
  }
1447

1448
  // Check whether create fission sites
1449
  if (run_mode == RunMode::FIXED_SOURCE) {
9,406 ✔
1450
    if (check_for_node(root, "create_fission_neutrons")) {
3,473 ✔
1451
      create_fission_neutrons =
336 ✔
1452
        get_node_value_bool(root, "create_fission_neutrons");
336 ✔
1453
    }
1454
  }
1455

1456
  // Check whether to scale fission photon yields
1457
  if (check_for_node(root, "delayed_photon_scaling")) {
9,406 !
1458
    delayed_photon_scaling =
×
1459
      get_node_value_bool(root, "delayed_photon_scaling");
×
1460
  }
1461

1462
  // Check whether to use event-based parallelism
1463
  if (check_for_node(root, "event_based")) {
9,406 !
1464
    event_based = get_node_value_bool(root, "event_based");
×
1465
  }
1466

1467
  // Check whether material cell offsets should be generated
1468
  if (check_for_node(root, "material_cell_offsets")) {
9,406 !
1469
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1470
  }
1471

1472
  // Weight window information
1473
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
9,722 ✔
1474
    variance_reduction::weight_windows.emplace_back(
316 ✔
1475
      std::make_unique<WeightWindows>(node_ww));
632 ✔
1476
  }
1477

1478
  // Enable weight windows by default if one or more are present
1479
  if (variance_reduction::weight_windows.size() > 0)
9,406 ✔
1480
    settings::weight_windows_on = true;
220 ✔
1481

1482
  // read weight windows from file
1483
  if (check_for_node(root, "weight_windows_file")) {
9,406 ✔
1484
    weight_windows_file = get_node_value(root, "weight_windows_file");
26 ✔
1485
    weight_windows_on = true;
26 ✔
1486
  }
1487

1488
  // read settings for weight windows value, this will override
1489
  // the automatic setting even if weight windows are present
1490
  if (check_for_node(root, "weight_windows_on")) {
9,406 ✔
1491
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
93 ✔
1492
  }
1493

1494
  if (check_for_node(root, "max_secondaries")) {
9,406 !
1495
    settings::max_secondaries =
×
1496
      std::stoi(get_node_value(root, "max_secondaries"));
×
1497
  }
1498

1499
  if (check_for_node(root, "max_history_splits")) {
9,406 ✔
1500
    settings::max_history_splits =
798 ✔
1501
      std::stoi(get_node_value(root, "max_history_splits"));
798 ✔
1502
  }
1503

1504
  if (check_for_node(root, "max_tracks")) {
9,406 ✔
1505
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
90 ✔
1506
  }
1507

1508
  // Create weight window generator objects
1509
  if (check_for_node(root, "weight_window_generators")) {
9,406 ✔
1510
    auto wwgs_node = root.child("weight_window_generators");
127 ✔
1511
    for (pugi::xml_node node_wwg :
254 ✔
1512
      wwgs_node.children("weight_windows_generator")) {
254 ✔
1513
      variance_reduction::weight_windows_generators.emplace_back(
127 ✔
1514
        std::make_unique<WeightWindowsGenerator>(node_wwg));
254 ✔
1515
    }
1516
    // if any of the weight windows are intended to be generated otf, make
1517
    // sure they're applied
1518
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
127 !
1519
      if (wwg->on_the_fly_) {
127 !
1520
        settings::weight_windows_on = true;
127 ✔
1521
        break;
127 ✔
1522
      }
1523
    }
1524
    // If any weight window generators have local FW-CADIS target tallies,
1525
    // user-defined adjoint sources cannot be used at the same time.
1526
    if (!model::adjoint_sources.empty()) {
127 !
1527
      for (const auto& wwg : variance_reduction::weight_windows_generators) {
×
1528
        if (!wwg->targets_.empty()) {
×
1529
          fatal_error("Cannot use both user-defined adjoint sources and "
×
1530
                      "FW-CADIS target tallies at the same time.");
1531
        }
1532
      }
1533
    }
1534
  }
1535

1536
  // Set up weight window checkpoints
1537
  if (check_for_node(root, "weight_window_checkpoints")) {
9,406 ✔
1538
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
184 ✔
1539
    if (check_for_node(ww_checkpoints, "collision")) {
184 !
1540
      weight_window_checkpoint_collision =
184 ✔
1541
        get_node_value_bool(ww_checkpoints, "collision");
184 ✔
1542
    }
1543
    if (check_for_node(ww_checkpoints, "surface")) {
184 !
1544
      weight_window_checkpoint_surface =
184 ✔
1545
        get_node_value_bool(ww_checkpoints, "surface");
184 ✔
1546
    }
1547
  }
1548

1549
  if (weight_windows_on) {
9,406 ✔
1550
    if (!weight_window_checkpoint_surface &&
362 ✔
1551
        !weight_window_checkpoint_collision)
189 !
1552
      fatal_error(
×
1553
        "Weight Windows are enabled but there are no valid checkpoints.");
1554
  }
1555

1556
  if (check_for_node(root, "use_decay_photons")) {
9,406 ✔
1557
    settings::use_decay_photons =
11 ✔
1558
      get_node_value_bool(root, "use_decay_photons");
11 ✔
1559
  }
1560

1561
  // If weight windows are on, also enable shared secondary bank (unless
1562
  // explicitly disabled by user).
1563
  if (check_for_node(root, "shared_secondary_bank")) {
9,406 ✔
1564
    bool val = get_node_value_bool(root, "shared_secondary_bank");
335 ✔
1565
    if (val && run_mode == RunMode::EIGENVALUE) {
335 !
1566
      warning(
×
1567
        "Shared secondary bank is not supported in eigenvalue calculations. "
1568
        "Setting will be ignored.");
1569
    } else {
1570
      settings::use_shared_secondary_bank = val;
335 ✔
1571
    }
1572
  } else if (settings::weight_windows_on) {
9,071 ✔
1573
    if (run_mode == RunMode::EIGENVALUE) {
180 ✔
1574
      warning(
66 ✔
1575
        "Shared secondary bank is not supported in eigenvalue calculations. "
1576
        "Particle local secondary banks will be used instead.");
1577
    } else if (run_mode == RunMode::FIXED_SOURCE) {
169 !
1578
      settings::use_shared_secondary_bank = true;
169 ✔
1579
    }
1580
  }
1581
}
9,406 ✔
1582

1583
void free_memory_settings()
9,601 ✔
1584
{
1585
  settings::statepoint_batch.clear();
9,601 ✔
1586
  settings::sourcepoint_batch.clear();
9,601 ✔
1587
  settings::source_write_surf_id.clear();
9,601 ✔
1588
  settings::res_scat_nuclides.clear();
9,601 ✔
1589
}
9,601 ✔
1590

1591
//==============================================================================
1592
// C API functions
1593
//==============================================================================
1594

1595
extern "C" int openmc_set_n_batches(
220 ✔
1596
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1597
{
1598
  if (settings::n_inactive >= n_batches) {
220 ✔
1599
    set_errmsg("Number of active batches must be greater than zero.");
11 ✔
1600
    return OPENMC_E_INVALID_ARGUMENT;
11 ✔
1601
  }
1602

1603
  if (!settings::trigger_on) {
209 ✔
1604
    // Set n_batches and n_max_batches to same value
1605
    settings::n_batches = n_batches;
187 ✔
1606
    settings::n_max_batches = n_batches;
187 ✔
1607
  } else {
1608
    // Set n_batches and n_max_batches based on value of set_max_batches
1609
    if (set_max_batches) {
22 ✔
1610
      settings::n_max_batches = n_batches;
11 ✔
1611
    } else {
1612
      settings::n_batches = n_batches;
11 ✔
1613
    }
1614
  }
1615

1616
  // Update size of k_generation and entropy
1617
  int m = settings::n_max_batches * settings::gen_per_batch;
209 ✔
1618
  simulation::k_generation.reserve(m);
209 ✔
1619
  simulation::entropy.reserve(m);
209 ✔
1620

1621
  // Add value of n_batches to statepoint_batch
1622
  if (add_statepoint_batch &&
209 ✔
1623
      !(contains(settings::statepoint_batch, n_batches)))
198 ✔
1624
    settings::statepoint_batch.insert(n_batches);
33 ✔
1625

1626
  return 0;
1627
}
1628

1629
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,530 ✔
1630
{
1631
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,530 ✔
1632

1633
  return 0;
2,530 ✔
1634
}
1635

1636
} // namespace openmc
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc