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

openmc-dev / openmc / 29123958173

10 Jul 2026 09:12PM UTC coverage: 80.472% (-0.8%) from 81.292%
29123958173

Pull #3951

github

web-flow
Merge 62dca9136 into 7256d5046
Pull Request #3951: wwinp files: Fix MemoryError in WeightWindowsList.export_to_hdf5 and speed up from_wwinp. Alternative Approach

16757 of 24275 branches covered (69.03%)

Branch coverage included in aggregate %.

70 of 138 new or added lines in 10 files covered. (50.72%)

876 existing lines in 50 files now uncovered.

57507 of 68010 relevant lines covered (84.56%)

23274270.93 hits per line

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

76.04
/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 use_shared_secondary_bank {false};
87
bool weight_windows_on {false};
88
bool weight_window_checkpoint_surface {false};
89
bool weight_window_checkpoint_collision {true};
90
bool write_all_tracks {false};
91
bool write_initial_source {false};
92

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

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

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

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

157
} // namespace settings
158

159
//==============================================================================
160
// Functions
161
//==============================================================================
162

163
void get_run_parameters(pugi::xml_node node_base)
1,896✔
164
{
165
  using namespace settings;
1,896✔
166
  using namespace pugi;
1,896✔
167

168
  // Check number of particles
169
  if (!check_for_node(node_base, "particles")) {
1,896!
170
    fatal_error("Need to specify number of particles.");
×
171
  }
172

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

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

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

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

197
  // Get max number of lost particles
198
  if (check_for_node(node_base, "max_lost_particles")) {
1,896✔
199
    max_lost_particles =
18✔
200
      std::stoi(get_node_value(node_base, "max_lost_particles"));
9✔
201
  }
202

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

209
  // Get relative number of lost particles
210
  if (check_for_node(node_base, "max_write_lost_particles")) {
1,896✔
211
    max_write_lost_particles =
6✔
212
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
3✔
213
  }
214

215
  // Get number of inactive batches
216
  if (run_mode == RunMode::EIGENVALUE ||
1,896✔
217
      solver_type == SolverType::RANDOM_RAY) {
816✔
218
    if (check_for_node(node_base, "inactive")) {
1,167✔
219
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
1,101✔
220
    }
221
    if (check_for_node(node_base, "generations_per_batch")) {
1,167✔
222
      gen_per_batch =
6✔
223
        std::stoi(get_node_value(node_base, "generations_per_batch"));
3✔
224
    }
225

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

231
    // Get the trigger information for keff
232
    if (check_for_node(node_base, "keff_trigger")) {
1,167✔
233
      xml_node node_keff_trigger = node_base.child("keff_trigger");
21✔
234

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

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

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

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

403
  // Parse settings.xml file
404
  xml_document doc;
324✔
405
  auto result = doc.load_file(filename.c_str());
324✔
406
  if (!result) {
324!
407
    fatal_error("Error processing settings.xml file.");
×
408
  }
409

410
  // Get root element
411
  xml_node root = doc.document_element();
324✔
412

413
  // Verbosity
414
  if (check_for_node(root, "verbosity") && verbosity == -1) {
324!
415
    verbosity = std::stoi(get_node_value(root, "verbosity"));
114✔
416
  } else if (verbosity == -1) {
267!
417
    verbosity = 7;
267✔
418
  }
419

420
  // To this point, we haven't displayed any output since we didn't know what
421
  // the verbosity is. Now that we checked for it, show the title if necessary
422
  if (mpi::master) {
324!
423
    if (verbosity >= 2)
324✔
424
      title();
267✔
425
  }
426

427
  write_message("Reading settings XML file...", 5);
324✔
428

429
  read_settings_xml(root);
324✔
430
}
327✔
431

432
void read_settings_xml(pugi::xml_node root)
2,154✔
433
{
434
  using namespace settings;
2,154✔
435
  using namespace pugi;
2,154✔
436

437
  // Find if a multi-group or continuous-energy simulation is desired
438
  if (check_for_node(root, "energy_mode")) {
2,154✔
439
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
276✔
440
    if (temp_str == "mg" || temp_str == "multi-group") {
552!
441
      run_CE = false;
276✔
442
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
443
      run_CE = true;
×
444
    }
445
  }
276✔
446

447
  // Check for user meshes and allocate
448
  read_meshes(root);
2,154✔
449

450
  // Look for deprecated cross_sections.xml file in settings.xml
451
  if (check_for_node(root, "cross_sections")) {
2,154!
452
    warning(
×
453
      "Setting cross_sections in settings.xml has been deprecated."
454
      " The cross_sections are now set in materials.xml and the "
455
      "cross_sections input to materials.xml and the OPENMC_CROSS_SECTIONS"
456
      " environment variable will take precendent over setting "
457
      "cross_sections in settings.xml.");
458
    path_cross_sections = get_node_value(root, "cross_sections");
×
459
  }
460

461
  if (!run_CE) {
2,154✔
462
    // Scattering Treatments
463
    if (check_for_node(root, "max_order")) {
276✔
464
      max_order = std::stoi(get_node_value(root, "max_order"));
6✔
465
    } else {
466
      // Set to default of largest int - 1, which means to use whatever is
467
      // contained in library. This is largest int - 1 because for legendre
468
      // scattering, a value of 1 is added to the order; adding 1 to the largest
469
      // int gets you the largest negative integer, which is not what we want.
470
      max_order = std::numeric_limits<int>::max() - 1;
273✔
471
    }
472
  }
473

474
  // Check for a trigger node and get trigger information
475
  if (check_for_node(root, "trigger")) {
2,154✔
476
    xml_node node_trigger = root.child("trigger");
36✔
477

478
    // Check if trigger(s) are to be turned on
479
    trigger_on = get_node_value_bool(node_trigger, "active");
36✔
480

481
    if (trigger_on) {
36✔
482
      if (check_for_node(node_trigger, "max_batches")) {
33!
483
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
66✔
484
      } else {
485
        fatal_error("<max_batches> must be specified with triggers");
×
486
      }
487

488
      // Get the batch interval to check triggers
489
      if (!check_for_node(node_trigger, "batch_interval")) {
33✔
490
        trigger_predict = true;
3✔
491
      } else {
492
        trigger_batch_interval =
60✔
493
          std::stoi(get_node_value(node_trigger, "batch_interval"));
60✔
494
        if (trigger_batch_interval <= 0) {
30!
495
          fatal_error("Trigger batch interval must be greater than zero");
×
496
        }
497
      }
498
    }
499
  }
500

501
  // Check run mode if it hasn't been set from the command line
502
  xml_node node_mode;
2,154✔
503
  if (run_mode == RunMode::UNSET) {
2,154✔
504
    if (check_for_node(root, "run_mode")) {
1,902✔
505
      std::string temp_str = get_node_value(root, "run_mode", true, true);
1,896✔
506
      if (temp_str == "eigenvalue") {
1,896✔
507
        run_mode = RunMode::EIGENVALUE;
1,074✔
508
      } else if (temp_str == "fixed source") {
822✔
509
        run_mode = RunMode::FIXED_SOURCE;
816✔
510
      } else if (temp_str == "plot") {
6!
511
        run_mode = RunMode::PLOTTING;
×
512
      } else if (temp_str == "particle restart") {
6!
513
        run_mode = RunMode::PARTICLE;
×
514
      } else if (temp_str == "volume") {
6!
515
        run_mode = RunMode::VOLUME;
6✔
516
      } else {
517
        fatal_error("Unrecognized run mode: " + temp_str);
×
518
      }
519

520
      // Assume XML specifies <particles>, <batches>, etc. directly
521
      node_mode = root;
1,896✔
522
    } else {
1,896✔
523
      warning("<run_mode> should be specified.");
6✔
524

525
      // Make sure that either eigenvalue or fixed source was specified
526
      node_mode = root.child("eigenvalue");
6✔
527
      if (node_mode) {
6!
528
        run_mode = RunMode::EIGENVALUE;
6✔
529
      } else {
530
        node_mode = root.child("fixed_source");
×
531
        if (node_mode) {
×
532
          run_mode = RunMode::FIXED_SOURCE;
×
533
        } else {
534
          fatal_error("<eigenvalue> or <fixed_source> not specified.");
×
535
        }
536
      }
537
    }
538
  }
539

540
  // Check solver type
541
  if (check_for_node(root, "random_ray")) {
2,154✔
542
    solver_type = SolverType::RANDOM_RAY;
159✔
543
    if (run_CE)
159!
544
      fatal_error("multi-group energy mode must be specified in settings XML "
×
545
                  "when using the random ray solver.");
546
  }
547

548
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
2,154✔
549
    // Read run parameters
550
    get_run_parameters(node_mode);
1,896✔
551

552
    // Check number of active batches, inactive batches, max lost particles and
553
    // particles
554
    if (n_batches <= n_inactive) {
1,896!
555
      fatal_error("Number of active batches must be greater than zero.");
×
556
    } else if (n_inactive < 0) {
1,896!
557
      fatal_error("Number of inactive batches must be non-negative.");
×
558
    } else if (n_particles <= 0) {
1,896!
559
      fatal_error("Number of particles must be greater than zero.");
×
560
    } else if (max_lost_particles <= 0) {
1,896!
561
      fatal_error("Number of max lost particles must be greater than zero.");
×
562
    } else if (rel_max_lost_particles <= 0.0 || rel_max_lost_particles >= 1.0) {
1,896!
563
      fatal_error("Relative max lost particles must be between zero and one.");
×
564
    }
565

566
    // Check for user value for the number of generation of the Iterated Fission
567
    // Probability (IFP) method
568
    if (check_for_node(root, "ifp_n_generation")) {
1,896✔
569
      ifp_n_generation = std::stoi(get_node_value(root, "ifp_n_generation"));
42✔
570
      if (ifp_n_generation <= 0) {
21!
571
        fatal_error("'ifp_n_generation' must be greater than 0.");
×
572
      }
573
      // Avoid tallying 0 if IFP logs are not complete when active cycles start
574
      if (ifp_n_generation > n_inactive) {
21✔
575
        fatal_error("'ifp_n_generation' must be lower than or equal to the "
3✔
576
                    "number of inactive cycles.");
577
      }
578
    }
579
  }
580

581
  // Copy plotting random number seed if specified
582
  if (check_for_node(root, "plot_seed")) {
2,151!
583
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
584
    model::plotter_seed = seed;
×
585
  }
586

587
  // Copy random number seed if specified
588
  if (check_for_node(root, "seed")) {
2,151✔
589
    auto seed = std::stoll(get_node_value(root, "seed"));
300✔
590
    openmc_set_seed(seed);
150✔
591
  }
592

593
  // Copy random number stride if specified
594
  if (check_for_node(root, "stride")) {
2,151✔
595
    auto stride = std::stoull(get_node_value(root, "stride"));
6✔
596
    openmc_set_stride(stride);
3✔
597
  }
598

599
  // Check for electron treatment
600
  if (check_for_node(root, "electron_treatment")) {
2,151✔
601
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
18✔
602
    if (temp_str == "led") {
18✔
603
      electron_treatment = ElectronTreatment::LED;
6✔
604
    } else if (temp_str == "ttb") {
12!
605
      electron_treatment = ElectronTreatment::TTB;
12✔
606
    } else {
607
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
608
    }
609
  }
18✔
610

611
  // Check for photon transport
612
  if (check_for_node(root, "photon_transport")) {
2,151✔
613
    photon_transport = get_node_value_bool(root, "photon_transport");
96✔
614

615
    if (!run_CE && photon_transport) {
96!
616
      fatal_error("Photon transport is not currently supported in "
×
617
                  "multigroup mode");
618
    }
619
  }
620

621
  // Check for atomic relaxation
622
  if (check_for_node(root, "atomic_relaxation")) {
2,151✔
623
    atomic_relaxation = get_node_value_bool(root, "atomic_relaxation");
3✔
624
  }
625

626
  // Number of bins for logarithmic grid
627
  if (check_for_node(root, "log_grid_bins")) {
2,151✔
628
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
6✔
629
    if (n_log_bins < 1) {
3!
630
      fatal_error("Number of bins for logarithmic grid must be greater "
×
631
                  "than zero.");
632
    }
633
  }
634

635
  // Number of OpenMP threads
636
  if (check_for_node(root, "threads")) {
2,151!
637
    if (mpi::master)
×
638
      warning("The <threads> element has been deprecated. Use "
×
639
              "the OMP_NUM_THREADS environment variable to set the number of "
640
              "threads.");
641
  }
642

643
  // ==========================================================================
644
  // EXTERNAL SOURCE
645

646
  // Get point to list of <source> elements and make sure there is at least one
647
  for (pugi::xml_node node : root.children("source")) {
4,158✔
648
    model::external_sources.push_back(Source::create(node));
4,017✔
649
  }
650

651
  // Check if the user has specified to read surface source
652
  if (check_for_node(root, "surf_source_read")) {
2,148✔
653
    surf_source_read = true;
6✔
654
    // Get surface source read node
655
    xml_node node_ssr = root.child("surf_source_read");
6✔
656

657
    std::string path = "surface_source.h5";
6✔
658
    // Check if the user has specified different file for surface source reading
659
    if (check_for_node(node_ssr, "path")) {
6!
660
      path = get_node_value(node_ssr, "path", false, true);
6✔
661
    }
662
    model::external_sources.push_back(make_unique<FileSource>(path));
6✔
663
  }
6✔
664

665
  // If no source specified, default to isotropic point source at origin with
666
  // Watt spectrum. No default source is needed in random ray mode.
667
  if (model::external_sources.empty() &&
2,148✔
668
      settings::solver_type != SolverType::RANDOM_RAY) {
597✔
669
    double T[] {0.0};
567✔
670
    double p[] {1.0};
567✔
671
    model::external_sources.push_back(make_unique<IndependentSource>(
567✔
672
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
1,134✔
673
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
1,134✔
674
      UPtrDist {new Discrete(T, p, 1)}));
1,134✔
675
  }
676

677
  // Build probability mass function for sampling external sources
678
  vector<double> source_strengths;
2,148✔
679
  for (auto& s : model::external_sources) {
4,728✔
680
    source_strengths.push_back(s->strength());
2,580✔
681
  }
682
  model::external_sources_probability.assign(source_strengths);
2,148✔
683

684
  // Check if we want to write out source
685
  if (check_for_node(root, "write_initial_source")) {
2,148!
686
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
687
  }
688

689
  // Get relative number of lost particles
690
  if (check_for_node(root, "source_rejection_fraction")) {
2,148✔
691
    source_rejection_fraction =
6✔
692
      std::stod(get_node_value(root, "source_rejection_fraction"));
6✔
693
  }
694

695
  if (check_for_node(root, "free_gas_threshold")) {
2,148!
696
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
697
  }
698

699
  // Surface grazing
700
  if (check_for_node(root, "surface_grazing_cutoff"))
2,148!
701
    surface_grazing_cutoff =
×
702
      std::stod(get_node_value(root, "surface_grazing_cutoff"));
×
703
  if (check_for_node(root, "surface_grazing_ratio"))
2,148!
704
    surface_grazing_ratio =
×
705
      std::stod(get_node_value(root, "surface_grazing_ratio"));
×
706

707
  // Survival biasing
708
  if (check_for_node(root, "survival_biasing")) {
2,148✔
709
    survival_biasing = get_node_value_bool(root, "survival_biasing");
51✔
710
  }
711

712
  // Probability tables
713
  if (check_for_node(root, "ptables")) {
2,148✔
714
    urr_ptables_on = get_node_value_bool(root, "ptables");
3✔
715
  }
716

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

764
  // read properties from file
765
  if (check_for_node(root, "properties_file")) {
2,148✔
766
    properties_file = get_node_value(root, "properties_file");
3✔
767
    if (!file_exists(properties_file)) {
3!
768
      fatal_error(fmt::format("File '{}' does not exist.", properties_file));
×
769
    }
770
  }
771

772
  // Particle trace
773
  if (check_for_node(root, "trace")) {
2,148✔
774
    auto temp = get_node_array<int64_t>(root, "trace");
3✔
775
    if (temp.size() != 3) {
3!
776
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
777
                  "batch, generation, and particle number.");
778
    }
779
    trace_batch = temp.at(0);
3✔
780
    trace_gen = temp.at(1);
3✔
781
    trace_particle = temp.at(2);
3✔
782
  }
3✔
783

784
  // Particle tracks
785
  if (check_for_node(root, "track")) {
2,148✔
786
    // Get values and make sure there are three per particle
787
    auto temp = get_node_array<int>(root, "track");
9✔
788
    if (temp.size() % 3 != 0) {
9!
789
      fatal_error(
×
790
        "Number of integers specified in 'track' is not "
791
        "divisible by 3.  Please provide 3 integers per particle to be "
792
        "tracked.");
793
    }
794

795
    // Reshape into track_identifiers
796
    int n_tracks = temp.size() / 3;
9✔
797
    for (int i = 0; i < n_tracks; ++i) {
36✔
798
      track_identifiers.push_back(
27✔
799
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
27✔
800
    }
801
  }
9✔
802

803
  // Shannon entropy
804
  if (solver_type == SolverType::RANDOM_RAY) {
2,148✔
805
    if (check_for_node(root, "entropy_mesh")) {
159!
806
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
807
                  "No user-defined entropy mesh is supported.");
808
    }
809
    entropy_on = true;
159✔
810
  } else if (solver_type == SolverType::MONTE_CARLO) {
1,989!
811
    if (check_for_node(root, "entropy_mesh")) {
1,989✔
812
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
180✔
813
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
90!
814
        fatal_error(fmt::format(
×
815
          "Mesh {} specified for Shannon entropy does not exist.", temp));
816
      }
817

818
      auto* m = dynamic_cast<RegularMesh*>(
90!
819
        model::meshes[model::mesh_map.at(temp)].get());
90!
820
      if (!m)
90!
821
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
822
      simulation::entropy_mesh = m;
90✔
823

824
      // Turn on Shannon entropy calculation
825
      entropy_on = true;
90✔
826

827
    } else if (check_for_node(root, "entropy")) {
1,899!
828
      fatal_error(
×
829
        "Specifying a Shannon entropy mesh via the <entropy> element "
830
        "is deprecated. Please create a mesh using <mesh> and then reference "
831
        "it by specifying its ID in an <entropy_mesh> element.");
832
    }
833
  }
834
  // Uniform fission source weighting mesh
835
  if (check_for_node(root, "ufs_mesh")) {
2,148✔
836
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
6✔
837
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
3!
838
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
839
                              "method does not exist.",
840
        temp));
841
    }
842

843
    auto* m =
3✔
844
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
3!
845
    if (!m)
3!
846
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
847
    simulation::ufs_mesh = m;
3✔
848

849
    // Turn on uniform fission source weighting
850
    ufs_on = true;
3✔
851

852
  } else if (check_for_node(root, "uniform_fs")) {
2,145!
853
    fatal_error(
×
854
      "Specifying a UFS mesh via the <uniform_fs> element "
855
      "is deprecated. Please create a mesh using <mesh> and then reference "
856
      "it by specifying its ID in a <ufs_mesh> element.");
857
  }
858

859
  // Check if the user has specified to write state points
860
  if (check_for_node(root, "state_point")) {
2,148✔
861

862
    // Get pointer to state_point node
863
    auto node_sp = root.child("state_point");
36✔
864

865
    // Determine number of batches at which to store state points
866
    if (check_for_node(node_sp, "batches")) {
36!
867
      // User gave specific batches to write state points
868
      auto temp = get_node_array<int>(node_sp, "batches");
36✔
869
      for (const auto& b : temp) {
111✔
870
        statepoint_batch.insert(b);
75✔
871
      }
872
    } else {
36✔
873
      // If neither were specified, write state point at last batch
874
      statepoint_batch.insert(n_batches);
×
875
    }
876
  } else {
877
    // If no <state_point> tag was present, by default write state point at
878
    // last batch only
879
    statepoint_batch.insert(n_batches);
2,112✔
880
  }
881

882
  // Check if the user has specified to write source points
883
  if (check_for_node(root, "source_point")) {
2,148✔
884
    // Get source_point node
885
    xml_node node_sp = root.child("source_point");
21✔
886

887
    // Determine batches at which to store source points
888
    if (check_for_node(node_sp, "batches")) {
21✔
889
      // User gave specific batches to write source points
890
      auto temp = get_node_array<int>(node_sp, "batches");
9✔
891
      for (const auto& b : temp) {
24✔
892
        sourcepoint_batch.insert(b);
15✔
893
      }
894
    } else {
9✔
895
      // If neither were specified, write source points with state points
896
      sourcepoint_batch = statepoint_batch;
12!
897
    }
898

899
    // Check if the user has specified to write binary source file
900
    if (check_for_node(node_sp, "separate")) {
21✔
901
      source_separate = get_node_value_bool(node_sp, "separate");
15✔
902
    }
903
    if (check_for_node(node_sp, "write")) {
21!
904
      source_write = get_node_value_bool(node_sp, "write");
×
905
    }
906
    if (check_for_node(node_sp, "mcpl")) {
21✔
907
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
6✔
908
    }
909
    if (check_for_node(node_sp, "overwrite_latest")) {
21✔
910
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
3✔
911
      source_separate = source_latest;
3✔
912
    }
913
  } else {
914
    // If no <source_point> tag was present, by default we keep source bank in
915
    // statepoint file and write it out at statepoints intervals
916
    source_separate = false;
2,127✔
917
    sourcepoint_batch = statepoint_batch;
2,127!
918
  }
919

920
  // Check is the user specified to convert strength to statistical weight
921
  if (check_for_node(root, "uniform_source_sampling")) {
2,148✔
922
    uniform_source_sampling =
15✔
923
      get_node_value_bool(root, "uniform_source_sampling");
15✔
924
  }
925

926
  // Check if the user has specified to write surface source
927
  if (check_for_node(root, "surf_source_write")) {
2,148✔
928
    surf_source_write = true;
117✔
929
    // Get surface source write node
930
    xml_node node_ssw = root.child("surf_source_write");
117✔
931

932
    // Determine surface ids at which crossing particles are to be banked.
933
    // If no surfaces are specified, all surfaces in the model will be used
934
    // to bank source points.
935
    if (check_for_node(node_ssw, "surface_ids")) {
117✔
936
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
57✔
937
      for (const auto& b : temp) {
285✔
938
        source_write_surf_id.insert(b);
228✔
939
      }
940
    }
57✔
941

942
    // Get maximum number of particles to be banked per surface
943
    if (check_for_node(node_ssw, "max_particles")) {
117✔
944
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
228✔
945
    } else {
946
      fatal_error("A maximum number of particles needs to be specified "
3✔
947
                  "using the 'max_particles' parameter to store surface "
948
                  "source points.");
949
    }
950

951
    // Get maximum number of surface source files to be created
952
    if (check_for_node(node_ssw, "max_source_files")) {
114✔
953
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
18✔
954
    } else {
955
      ssw_max_files = 1;
105✔
956
    }
957

958
    if (check_for_node(node_ssw, "mcpl")) {
114✔
959
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
3✔
960
    }
961
    // Get cell information
962
    if (check_for_node(node_ssw, "cell")) {
114✔
963
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
60✔
964
      ssw_cell_type = SSWCellType::Both;
30✔
965
    }
966
    if (check_for_node(node_ssw, "cellfrom")) {
114✔
967
      if (ssw_cell_id != C_NONE) {
27✔
968
        fatal_error(
6✔
969
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
970
      }
971
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
42✔
972
      ssw_cell_type = SSWCellType::From;
21✔
973
    }
974
    if (check_for_node(node_ssw, "cellto")) {
108✔
975
      if (ssw_cell_id != C_NONE) {
21✔
976
        fatal_error(
6✔
977
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
978
      }
979
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
30✔
980
      ssw_cell_type = SSWCellType::To;
15✔
981
    }
982
  }
983

984
  // Check if the user has specified to write specific collisions
985
  if (check_for_node(root, "collision_track")) {
2,133✔
986
    settings::collision_track = true;
36✔
987
    // Get collision track node
988
    xml_node node_ct = root.child("collision_track");
36✔
989
    collision_track_config = CollisionTrackConfig {};
36✔
990

991
    // Determine cell ids at which crossing particles are to be banked
992
    if (check_for_node(node_ct, "cell_ids")) {
36✔
993
      auto temp = get_node_array<int>(node_ct, "cell_ids");
21✔
994
      for (const auto& b : temp) {
57✔
995
        collision_track_config.cell_ids.insert(b);
36✔
996
      }
997
    }
21✔
998
    if (check_for_node(node_ct, "reactions")) {
36✔
999
      auto temp = get_node_array<std::string>(node_ct, "reactions");
15✔
1000
      for (const auto& b : temp) {
39✔
1001
        int reaction_int = reaction_mt(b);
24✔
1002
        if (reaction_int > 0) {
24!
1003
          collision_track_config.mt_numbers.insert(reaction_int);
24✔
1004
        }
1005
      }
1006
    }
15✔
1007
    if (check_for_node(node_ct, "universe_ids")) {
36✔
1008
      auto temp = get_node_array<int>(node_ct, "universe_ids");
6✔
1009
      for (const auto& b : temp) {
12✔
1010
        collision_track_config.universe_ids.insert(b);
6✔
1011
      }
1012
    }
6✔
1013
    if (check_for_node(node_ct, "material_ids")) {
36✔
1014
      auto temp = get_node_array<int>(node_ct, "material_ids");
6✔
1015
      for (const auto& b : temp) {
15✔
1016
        collision_track_config.material_ids.insert(b);
9✔
1017
      }
1018
    }
6✔
1019
    if (check_for_node(node_ct, "nuclides")) {
36✔
1020
      auto temp = get_node_array<std::string>(node_ct, "nuclides");
6✔
1021
      for (const auto& b : temp) {
24✔
1022
        collision_track_config.nuclides.insert(b);
18✔
1023
      }
1024
    }
6✔
1025
    if (check_for_node(node_ct, "deposited_E_threshold")) {
36✔
1026
      collision_track_config.deposited_energy_threshold =
12✔
1027
        std::stod(get_node_value(node_ct, "deposited_E_threshold"));
12✔
1028
    }
1029
    // Get maximum number of particles to be banked per collision
1030
    if (check_for_node(node_ct, "max_collisions")) {
36!
1031
      collision_track_config.max_collisions =
72✔
1032
        std::stoll(get_node_value(node_ct, "max_collisions"));
72✔
1033
    } else {
1034
      warning("A maximum number of collisions needs to be specified. "
×
1035
              "By default the code sets 'max_collisions' parameter equals to "
1036
              "1000.");
1037
    }
1038
    // Get maximum number of collision_track files to be created
1039
    if (check_for_node(node_ct, "max_collision_track_files")) {
36!
1040
      collision_track_config.max_files =
×
1041
        std::stoll(get_node_value(node_ct, "max_collision_track_files"));
×
1042
    }
1043
    if (check_for_node(node_ct, "mcpl")) {
36✔
1044
      collision_track_config.mcpl_write = get_node_value_bool(node_ct, "mcpl");
6✔
1045
    }
1046
  }
1047

1048
  // If source is not separate and is to be written out in the statepoint
1049
  // file, make sure that the sourcepoint batch numbers are contained in the
1050
  // statepoint list
1051
  if (!source_separate) {
2,133✔
1052
    for (const auto& b : sourcepoint_batch) {
4,260✔
1053
      if (!contains(statepoint_batch, b)) {
4,290!
1054
        fatal_error(
×
1055
          "Sourcepoint batches are not a subset of statepoint batches.");
1056
      }
1057
    }
1058
  }
1059

1060
  // Check if the user has specified to not reduce tallies at the end of every
1061
  // batch
1062
  if (check_for_node(root, "no_reduce")) {
2,133✔
1063
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
6✔
1064
  }
1065

1066
  // Check if the user has specified to use confidence intervals for
1067
  // uncertainties rather than standard deviations
1068
  if (check_for_node(root, "confidence_intervals")) {
2,133✔
1069
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
3✔
1070
  }
1071

1072
  // Check for output options
1073
  if (check_for_node(root, "output")) {
2,133✔
1074
    // Get pointer to output node
1075
    pugi::xml_node node_output = root.child("output");
201✔
1076

1077
    // Check for summary option
1078
    if (check_for_node(node_output, "summary")) {
201✔
1079
      output_summary = get_node_value_bool(node_output, "summary");
195✔
1080
    }
1081

1082
    // Check for ASCII tallies output option
1083
    if (check_for_node(node_output, "tallies")) {
201✔
1084
      output_tallies = get_node_value_bool(node_output, "tallies");
93✔
1085
    }
1086

1087
    // Set output directory if a path has been specified
1088
    if (check_for_node(node_output, "path")) {
201!
1089
      path_output = get_node_value(node_output, "path");
×
1090
      if (!ends_with(path_output, "/")) {
×
1091
        path_output += "/";
201!
1092
      }
1093
    }
1094
  }
1095

1096
  // Resonance scattering parameters
1097
  if (check_for_node(root, "resonance_scattering")) {
2,133✔
1098
    xml_node node_res_scat = root.child("resonance_scattering");
3✔
1099

1100
    // See if resonance scattering is enabled
1101
    if (check_for_node(node_res_scat, "enable")) {
3!
1102
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
3✔
1103
    } else {
1104
      res_scat_on = true;
×
1105
    }
1106

1107
    // Determine what method is used
1108
    if (check_for_node(node_res_scat, "method")) {
3!
1109
      auto temp = get_node_value(node_res_scat, "method", true, true);
3✔
1110
      if (temp == "rvs") {
3!
1111
        res_scat_method = ResScatMethod::rvs;
3✔
1112
      } else if (temp == "dbrc") {
×
1113
        res_scat_method = ResScatMethod::dbrc;
×
1114
      } else {
1115
        fatal_error(
×
1116
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1117
      }
1118
    }
3✔
1119

1120
    // Minimum energy for resonance scattering
1121
    if (check_for_node(node_res_scat, "energy_min")) {
3!
1122
      res_scat_energy_min =
6✔
1123
        std::stod(get_node_value(node_res_scat, "energy_min"));
6✔
1124
    }
1125
    if (res_scat_energy_min < 0.0) {
3!
1126
      fatal_error("Lower resonance scattering energy bound is negative");
×
1127
    }
1128

1129
    // Maximum energy for resonance scattering
1130
    if (check_for_node(node_res_scat, "energy_max")) {
3!
1131
      res_scat_energy_max =
6✔
1132
        std::stod(get_node_value(node_res_scat, "energy_max"));
6✔
1133
    }
1134
    if (res_scat_energy_max < res_scat_energy_min) {
3!
1135
      fatal_error("Upper resonance scattering energy bound is below the "
×
1136
                  "lower resonance scattering energy bound.");
1137
    }
1138

1139
    // Get resonance scattering nuclides
1140
    if (check_for_node(node_res_scat, "nuclides")) {
3!
1141
      res_scat_nuclides =
3✔
1142
        get_node_array<std::string>(node_res_scat, "nuclides");
6✔
1143
    }
1144
  }
1145

1146
  // Get volume calculations
1147
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
2,202✔
1148
    model::volume_calcs.emplace_back(node_vol);
69✔
1149
  }
1150

1151
  // Get temperature settings
1152
  if (check_for_node(root, "temperature_default")) {
2,133✔
1153
    temperature_default =
90✔
1154
      std::stod(get_node_value(root, "temperature_default"));
90✔
1155
  }
1156
  if (check_for_node(root, "temperature_method")) {
2,133✔
1157
    auto temp = get_node_value(root, "temperature_method", true, true);
117✔
1158
    if (temp == "nearest") {
117✔
1159
      temperature_method = TemperatureMethod::NEAREST;
72✔
1160
    } else if (temp == "interpolation") {
45!
1161
      temperature_method = TemperatureMethod::INTERPOLATION;
45✔
1162
    } else {
1163
      fatal_error("Unknown temperature method: " + temp);
×
1164
    }
1165
  }
117✔
1166
  if (check_for_node(root, "temperature_tolerance")) {
2,133✔
1167
    temperature_tolerance =
174✔
1168
      std::stod(get_node_value(root, "temperature_tolerance"));
174✔
1169
  }
1170
  if (check_for_node(root, "temperature_multipole")) {
2,133✔
1171
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
45✔
1172

1173
    // Multipole currently doesn't work with photon transport
1174
    if (temperature_multipole && photon_transport) {
45!
1175
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1176
                  "photon transport.");
1177
    }
1178
  }
1179
  if (check_for_node(root, "temperature_range")) {
2,133✔
1180
    auto range = get_node_array<double>(root, "temperature_range");
42✔
1181
    temperature_range[0] = range.at(0);
42✔
1182
    temperature_range[1] = range.at(1);
42✔
1183
  }
42✔
1184

1185
  // Check for tabular_legendre options
1186
  if (check_for_node(root, "tabular_legendre")) {
2,133✔
1187
    // Get pointer to tabular_legendre node
1188
    xml_node node_tab_leg = root.child("tabular_legendre");
21✔
1189

1190
    // Check for enable option
1191
    if (check_for_node(node_tab_leg, "enable")) {
21!
1192
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
21✔
1193
    }
1194

1195
    // Check for the number of points
1196
    if (check_for_node(node_tab_leg, "num_points")) {
21!
1197
      legendre_to_tabular_points =
×
1198
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
1199
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
1200
        fatal_error(
×
1201
          "The 'num_points' subelement/attribute of the "
1202
          "<tabular_legendre> element must contain a value greater than 1");
1203
      }
1204
    }
1205
  }
1206

1207
  // Check whether create delayed neutrons in fission
1208
  if (check_for_node(root, "create_delayed_neutrons")) {
2,133!
1209
    create_delayed_neutrons =
×
1210
      get_node_value_bool(root, "create_delayed_neutrons");
×
1211
  }
1212

1213
  // Check whether create fission sites
1214
  if (run_mode == RunMode::FIXED_SOURCE) {
2,133✔
1215
    if (check_for_node(root, "create_fission_neutrons")) {
801✔
1216
      create_fission_neutrons =
84✔
1217
        get_node_value_bool(root, "create_fission_neutrons");
84✔
1218
    }
1219
  }
1220

1221
  // Check whether to scale fission photon yields
1222
  if (check_for_node(root, "delayed_photon_scaling")) {
2,133!
1223
    delayed_photon_scaling =
×
1224
      get_node_value_bool(root, "delayed_photon_scaling");
×
1225
  }
1226

1227
  // Check whether to use event-based parallelism
1228
  if (check_for_node(root, "event_based")) {
2,133!
1229
    event_based = get_node_value_bool(root, "event_based");
×
1230
  }
1231

1232
  // Check whether material cell offsets should be generated
1233
  if (check_for_node(root, "material_cell_offsets")) {
2,133!
1234
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1235
  }
1236

1237
  // Weight window information
1238
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
2,202✔
1239
    variance_reduction::weight_windows.emplace_back(
69✔
1240
      std::make_unique<WeightWindows>(node_ww));
138✔
1241
  }
1242

1243
  // Enable weight windows by default if one or more are present
1244
  if (variance_reduction::weight_windows.size() > 0)
2,133✔
1245
    settings::weight_windows_on = true;
45✔
1246

1247
  // read weight windows from file
1248
  if (check_for_node(root, "weight_windows_file")) {
2,133!
1249
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1250
    weight_windows_on = true;
×
1251
  }
1252

1253
  // read settings for weight windows value, this will override
1254
  // the automatic setting even if weight windows are present
1255
  if (check_for_node(root, "weight_windows_on")) {
2,133✔
1256
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
18✔
1257
  }
1258

1259
  if (check_for_node(root, "max_secondaries")) {
2,133!
1260
    settings::max_secondaries =
×
1261
      std::stoi(get_node_value(root, "max_secondaries"));
×
1262
  }
1263

1264
  if (check_for_node(root, "max_history_splits")) {
2,133✔
1265
    settings::max_history_splits =
174✔
1266
      std::stoi(get_node_value(root, "max_history_splits"));
174✔
1267
  }
1268

1269
  if (check_for_node(root, "max_tracks")) {
2,133✔
1270
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
18✔
1271
  }
1272

1273
  // Create weight window generator objects
1274
  if (check_for_node(root, "weight_window_generators")) {
2,133✔
1275
    auto wwgs_node = root.child("weight_window_generators");
24✔
1276
    for (pugi::xml_node node_wwg :
48✔
1277
      wwgs_node.children("weight_windows_generator")) {
48✔
1278
      variance_reduction::weight_windows_generators.emplace_back(
24✔
1279
        std::make_unique<WeightWindowsGenerator>(node_wwg));
48✔
1280
    }
1281
    // if any of the weight windows are intended to be generated otf, make
1282
    // sure they're applied
1283
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
24!
1284
      if (wwg->on_the_fly_) {
24!
1285
        settings::weight_windows_on = true;
24✔
1286
        break;
24✔
1287
      }
1288
    }
1289
    // If any weight window generators have local FW-CADIS target tallies,
1290
    // user-defined adjoint sources cannot be used at the same time.
1291
    if (!model::adjoint_sources.empty()) {
24!
1292
      for (const auto& wwg : variance_reduction::weight_windows_generators) {
×
1293
        if (!wwg->targets_.empty()) {
×
1294
          fatal_error("Cannot use both user-defined adjoint sources and "
×
1295
                      "FW-CADIS target tallies at the same time.");
1296
        }
1297
      }
1298
    }
1299
  }
1300

1301
  // Set up weight window checkpoints
1302
  if (check_for_node(root, "weight_window_checkpoints")) {
2,133✔
1303
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
30✔
1304
    if (check_for_node(ww_checkpoints, "collision")) {
30!
1305
      weight_window_checkpoint_collision =
30✔
1306
        get_node_value_bool(ww_checkpoints, "collision");
30✔
1307
    }
1308
    if (check_for_node(ww_checkpoints, "surface")) {
30!
1309
      weight_window_checkpoint_surface =
30✔
1310
        get_node_value_bool(ww_checkpoints, "surface");
30✔
1311
    }
1312
  }
1313

1314
  if (weight_windows_on) {
2,133✔
1315
    if (!weight_window_checkpoint_surface &&
66✔
1316
        !weight_window_checkpoint_collision)
39!
1317
      fatal_error(
×
1318
        "Weight Windows are enabled but there are no valid checkpoints.");
1319
  }
1320

1321
  if (check_for_node(root, "use_decay_photons")) {
2,133✔
1322
    settings::use_decay_photons =
3✔
1323
      get_node_value_bool(root, "use_decay_photons");
3✔
1324
  }
1325

1326
  // If weight windows are on, also enable shared secondary bank (unless
1327
  // explicitly disabled by user).
1328
  if (check_for_node(root, "shared_secondary_bank")) {
2,133✔
1329
    bool val = get_node_value_bool(root, "shared_secondary_bank");
75✔
1330
    if (val && run_mode == RunMode::EIGENVALUE) {
75!
1331
      warning(
×
1332
        "Shared secondary bank is not supported in eigenvalue calculations. "
1333
        "Setting will be ignored.");
1334
    } else {
1335
      settings::use_shared_secondary_bank = val;
75✔
1336
    }
1337
  } else if (settings::weight_windows_on) {
2,058✔
1338
    if (run_mode == RunMode::EIGENVALUE) {
24!
UNCOV
1339
      warning(
×
1340
        "Shared secondary bank is not supported in eigenvalue calculations. "
1341
        "Particle local secondary banks will be used instead.");
1342
    } else if (run_mode == RunMode::FIXED_SOURCE) {
24!
1343
      settings::use_shared_secondary_bank = true;
24✔
1344
    }
1345
  }
1346
}
2,133✔
1347

1348
void free_memory_settings()
2,166✔
1349
{
1350
  settings::statepoint_batch.clear();
2,166✔
1351
  settings::sourcepoint_batch.clear();
2,166✔
1352
  settings::source_write_surf_id.clear();
2,166✔
1353
  settings::res_scat_nuclides.clear();
2,166✔
1354
}
2,166✔
1355

1356
//==============================================================================
1357
// C API functions
1358
//==============================================================================
1359

1360
extern "C" int openmc_set_n_batches(
60✔
1361
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1362
{
1363
  if (settings::n_inactive >= n_batches) {
60✔
1364
    set_errmsg("Number of active batches must be greater than zero.");
3✔
1365
    return OPENMC_E_INVALID_ARGUMENT;
3✔
1366
  }
1367

1368
  if (!settings::trigger_on) {
57✔
1369
    // Set n_batches and n_max_batches to same value
1370
    settings::n_batches = n_batches;
51✔
1371
    settings::n_max_batches = n_batches;
51✔
1372
  } else {
1373
    // Set n_batches and n_max_batches based on value of set_max_batches
1374
    if (set_max_batches) {
6✔
1375
      settings::n_max_batches = n_batches;
3✔
1376
    } else {
1377
      settings::n_batches = n_batches;
3✔
1378
    }
1379
  }
1380

1381
  // Update size of k_generation and entropy
1382
  int m = settings::n_max_batches * settings::gen_per_batch;
57✔
1383
  simulation::k_generation.reserve(m);
57✔
1384
  simulation::entropy.reserve(m);
57✔
1385

1386
  // Add value of n_batches to statepoint_batch
1387
  if (add_statepoint_batch &&
57✔
1388
      !(contains(settings::statepoint_batch, n_batches)))
54✔
1389
    settings::statepoint_batch.insert(n_batches);
9✔
1390

1391
  return 0;
1392
}
1393

1394
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
690✔
1395
{
1396
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
690✔
1397

1398
  return 0;
690✔
1399
}
1400

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