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

openmc-dev / openmc / 29081469495

10 Jul 2026 08:58AM UTC coverage: 80.468% (-0.8%) from 81.292%
29081469495

Pull #3951

github

web-flow
Merge c00210fb3 into 7c408f6a1
Pull Request #3951: wwinp files: Fix MemoryError in WeightWindowsList.export_to_hdf5 and speed up from_wwinp. Alternative Approach

16740 of 24259 branches covered (69.01%)

Branch coverage included in aggregate %.

70 of 133 new or added lines in 10 files covered. (52.63%)

787 existing lines in 49 files now uncovered.

57490 of 67989 relevant lines covered (84.56%)

17347023.23 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,264✔
164
{
165
  using namespace settings;
1,264✔
166
  using namespace pugi;
1,264✔
167

168
  // Check number of particles
169
  if (!check_for_node(node_base, "particles")) {
1,264!
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,264✔
175
    n_particles = std::stoll(get_node_value(node_base, "particles"));
1,262✔
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,264!
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,264!
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,264!
192
    n_batches = std::stoi(get_node_value(node_base, "batches"));
1,264✔
193
  }
194
  if (!trigger_on)
1,264✔
195
    n_max_batches = n_batches;
1,242✔
196

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

203
  // Get relative number of lost particles
204
  if (check_for_node(node_base, "rel_max_lost_particles")) {
1,264!
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,264✔
211
    max_write_lost_particles =
4✔
212
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
2✔
213
  }
214

215
  // Get number of inactive batches
216
  if (run_mode == RunMode::EIGENVALUE ||
1,264✔
217
      solver_type == SolverType::RANDOM_RAY) {
544✔
218
    if (check_for_node(node_base, "inactive")) {
778✔
219
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
734✔
220
    }
221
    if (check_for_node(node_base, "generations_per_batch")) {
778✔
222
      gen_per_batch =
4✔
223
        std::stoi(get_node_value(node_base, "generations_per_batch"));
2✔
224
    }
225

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

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

235
      if (check_for_node(node_keff_trigger, "type")) {
14!
236
        auto temp = get_node_value(node_keff_trigger, "type", true, true);
14✔
237
        if (temp == "std_dev") {
14!
238
          keff_trigger.metric = TriggerMetric::standard_deviation;
14✔
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")) {
14!
251
        keff_trigger.threshold =
28✔
252
          std::stod(get_node_value(node_keff_trigger, "threshold"));
28✔
253
        if (keff_trigger.threshold <= 0) {
14!
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,264✔
264
    xml_node random_ray_node = node_base.child("random_ray");
106✔
265
    if (check_for_node(random_ray_node, "distance_active")) {
106!
266
      RandomRay::distance_active_ =
212✔
267
        std::stod(get_node_value(random_ray_node, "distance_active"));
212✔
268
      if (RandomRay::distance_active_ <= 0.0) {
106!
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")) {
106!
275
      RandomRay::distance_inactive_ =
212✔
276
        std::stod(get_node_value(random_ray_node, "distance_inactive"));
212✔
277
      if (RandomRay::distance_inactive_ < 0) {
106!
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")) {
106!
285
      xml_node ray_source_node = random_ray_node.child("ray_source");
106✔
286
      xml_node source_node = ray_source_node.child("source");
106✔
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);
212✔
290
    } else {
291
      fatal_error("Specify random ray source in settings XML");
×
292
    }
293
    if (check_for_node(random_ray_node, "volume_estimator")) {
106✔
294
      std::string temp_str =
20✔
295
        get_node_value(random_ray_node, "volume_estimator", true, true);
20✔
296
      if (temp_str == "simulation_averaged") {
20✔
297
        FlatSourceDomain::volume_estimator_ =
4✔
298
          RandomRayVolumeEstimator::SIMULATION_AVERAGED;
299
      } else if (temp_str == "naive") {
16✔
300
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::NAIVE;
12✔
301
      } else if (temp_str == "hybrid") {
4!
302
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::HYBRID;
4✔
303
      } else {
304
        fatal_error("Unrecognized volume estimator: " + temp_str);
×
305
      }
306
    }
20✔
307
    if (check_for_node(random_ray_node, "source_shape")) {
106✔
308
      std::string temp_str =
60✔
309
        get_node_value(random_ray_node, "source_shape", true, true);
60✔
310
      if (temp_str == "flat") {
60✔
311
        RandomRay::source_shape_ = RandomRaySourceShape::FLAT;
10✔
312
      } else if (temp_str == "linear") {
50✔
313
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR;
44✔
314
      } else if (temp_str == "linear_xy") {
6!
315
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR_XY;
6✔
316
      } else {
317
        fatal_error("Unrecognized source shape: " + temp_str);
×
318
      }
319
    }
60✔
320
    if (check_for_node(random_ray_node, "volume_normalized_flux_tallies")) {
106✔
321
      FlatSourceDomain::volume_normalized_flux_tallies_ =
74✔
322
        get_node_value_bool(random_ray_node, "volume_normalized_flux_tallies");
74✔
323
    }
324
    if (check_for_node(random_ray_node, "adjoint")) {
106✔
325
      FlatSourceDomain::adjoint_requested_ =
6✔
326
        get_node_value_bool(random_ray_node, "adjoint");
6✔
327
    }
328
    if (check_for_node(random_ray_node, "sample_method")) {
106✔
329
      std::string temp_str =
4✔
330
        get_node_value(random_ray_node, "sample_method", true, true);
4✔
331
      if (temp_str == "prng") {
4!
332
        RandomRay::sample_method_ = RandomRaySampleMethod::PRNG;
×
333
      } else if (temp_str == "halton") {
4✔
334
        RandomRay::sample_method_ = RandomRaySampleMethod::HALTON;
2✔
335
      } else if (temp_str == "s2") {
2!
336
        RandomRay::sample_method_ = RandomRaySampleMethod::S2;
2✔
337
      } else {
338
        fatal_error("Unrecognized sample method: " + temp_str);
×
339
      }
340
    }
4✔
341
    if (check_for_node(random_ray_node, "source_region_meshes")) {
106✔
342
      pugi::xml_node node_source_region_meshes =
46✔
343
        random_ray_node.child("source_region_meshes");
46✔
344
      for (pugi::xml_node node_mesh :
100✔
345
        node_source_region_meshes.children("mesh")) {
100✔
346
        int mesh_id = std::stoi(node_mesh.attribute("id").value());
108✔
347
        for (pugi::xml_node node_domain : node_mesh.children("domain")) {
108✔
348
          int domain_id = std::stoi(node_domain.attribute("id").value());
108✔
349
          std::string domain_type = node_domain.attribute("type").value();
54✔
350
          Source::DomainType type;
54✔
351
          if (domain_type == "material") {
54✔
352
            type = Source::DomainType::MATERIAL;
4✔
353
          } else if (domain_type == "cell") {
50✔
354
            type = Source::DomainType::CELL;
4✔
355
          } else if (domain_type == "universe") {
46!
356
            type = Source::DomainType::UNIVERSE;
46✔
357
          } else {
358
            throw std::runtime_error("Unknown domain type: " + domain_type);
×
359
          }
360
          FlatSourceDomain::mesh_domain_map_[mesh_id].emplace_back(
54✔
361
            type, domain_id);
362
        }
54✔
363
      }
364
    }
365
    if (check_for_node(random_ray_node, "diagonal_stabilization_rho")) {
106✔
366
      FlatSourceDomain::diagonal_stabilization_rho_ = std::stod(
2✔
367
        get_node_value(random_ray_node, "diagonal_stabilization_rho"));
2✔
368
      if (FlatSourceDomain::diagonal_stabilization_rho_ < 0.0 ||
2!
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")) {
106✔
375
      pugi::xml_node adj_source_node = random_ray_node.child("adjoint_source");
2✔
376
      for (pugi::xml_node source_node : adj_source_node.children("source")) {
4✔
377
        // Find any local adjoint sources
378
        model::adjoint_sources.push_back(Source::create(source_node));
4✔
379
      }
380
    }
381
  }
382
}
1,264✔
383

384
void read_settings_xml()
220✔
385
{
386
  using namespace settings;
220✔
387
  using namespace pugi;
220✔
388
  // Check if settings.xml exists
389
  std::string filename = settings::path_input + "settings.xml";
220✔
390
  if (!file_exists(filename)) {
220✔
391
    if (run_mode != RunMode::PLOTTING) {
4!
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;
4✔
400
    }
401
  }
402

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

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

413
  // Verbosity
414
  if (check_for_node(root, "verbosity") && verbosity == -1) {
216!
415
    verbosity = std::stoi(get_node_value(root, "verbosity"));
76✔
416
  } else if (verbosity == -1) {
178!
417
    verbosity = 7;
178✔
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) {
216!
423
    if (verbosity >= 2)
216✔
424
      title();
178✔
425
  }
426

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

429
  read_settings_xml(root);
216✔
430
}
218✔
431

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

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

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

450
  // Look for deprecated cross_sections.xml file in settings.xml
451
  if (check_for_node(root, "cross_sections")) {
1,436!
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) {
1,436✔
462
    // Scattering Treatments
463
    if (check_for_node(root, "max_order")) {
184✔
464
      max_order = std::stoi(get_node_value(root, "max_order"));
4✔
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;
182✔
471
    }
472
  }
473

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

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

481
    if (trigger_on) {
24✔
482
      if (check_for_node(node_trigger, "max_batches")) {
22!
483
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
44✔
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")) {
22✔
490
        trigger_predict = true;
2✔
491
      } else {
492
        trigger_batch_interval =
40✔
493
          std::stoi(get_node_value(node_trigger, "batch_interval"));
40✔
494
        if (trigger_batch_interval <= 0) {
20!
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;
1,436✔
503
  if (run_mode == RunMode::UNSET) {
1,436✔
504
    if (check_for_node(root, "run_mode")) {
1,268✔
505
      std::string temp_str = get_node_value(root, "run_mode", true, true);
1,264✔
506
      if (temp_str == "eigenvalue") {
1,264✔
507
        run_mode = RunMode::EIGENVALUE;
716✔
508
      } else if (temp_str == "fixed source") {
548✔
509
        run_mode = RunMode::FIXED_SOURCE;
544✔
510
      } else if (temp_str == "plot") {
4!
511
        run_mode = RunMode::PLOTTING;
×
512
      } else if (temp_str == "particle restart") {
4!
513
        run_mode = RunMode::PARTICLE;
×
514
      } else if (temp_str == "volume") {
4!
515
        run_mode = RunMode::VOLUME;
4✔
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,264✔
522
    } else {
1,264✔
523
      warning("<run_mode> should be specified.");
4✔
524

525
      // Make sure that either eigenvalue or fixed source was specified
526
      node_mode = root.child("eigenvalue");
4✔
527
      if (node_mode) {
4!
528
        run_mode = RunMode::EIGENVALUE;
4✔
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")) {
1,436✔
542
    solver_type = SolverType::RANDOM_RAY;
106✔
543
    if (run_CE)
106!
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) {
1,436✔
549
    // Read run parameters
550
    get_run_parameters(node_mode);
1,264✔
551

552
    // Check number of active batches, inactive batches, max lost particles and
553
    // particles
554
    if (n_batches <= n_inactive) {
1,264!
555
      fatal_error("Number of active batches must be greater than zero.");
×
556
    } else if (n_inactive < 0) {
1,264!
557
      fatal_error("Number of inactive batches must be non-negative.");
×
558
    } else if (n_particles <= 0) {
1,264!
559
      fatal_error("Number of particles must be greater than zero.");
×
560
    } else if (max_lost_particles <= 0) {
1,264!
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,264!
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,264✔
569
      ifp_n_generation = std::stoi(get_node_value(root, "ifp_n_generation"));
28✔
570
      if (ifp_n_generation <= 0) {
14!
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) {
14✔
575
        fatal_error("'ifp_n_generation' must be lower than or equal to the "
2✔
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")) {
1,434!
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")) {
1,434✔
589
    auto seed = std::stoll(get_node_value(root, "seed"));
200✔
590
    openmc_set_seed(seed);
100✔
591
  }
592

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

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

611
  // Check for photon transport
612
  if (check_for_node(root, "photon_transport")) {
1,434✔
613
    photon_transport = get_node_value_bool(root, "photon_transport");
64✔
614

615
    if (!run_CE && photon_transport) {
64!
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")) {
1,434✔
623
    atomic_relaxation = get_node_value_bool(root, "atomic_relaxation");
2✔
624
  }
625

626
  // Number of bins for logarithmic grid
627
  if (check_for_node(root, "log_grid_bins")) {
1,434✔
628
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
4✔
629
    if (n_log_bins < 1) {
2!
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")) {
1,434!
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")) {
2,772✔
648
    model::external_sources.push_back(Source::create(node));
2,678✔
649
  }
650

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

657
    std::string path = "surface_source.h5";
4✔
658
    // Check if the user has specified different file for surface source reading
659
    if (check_for_node(node_ssr, "path")) {
4!
660
      path = get_node_value(node_ssr, "path", false, true);
4✔
661
    }
662
    model::external_sources.push_back(make_unique<FileSource>(path));
4✔
663
  }
4✔
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() &&
1,432✔
668
      settings::solver_type != SolverType::RANDOM_RAY) {
398✔
669
    double T[] {0.0};
378✔
670
    double p[] {1.0};
378✔
671
    model::external_sources.push_back(make_unique<IndependentSource>(
378✔
672
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
756✔
673
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
756✔
674
      UPtrDist {new Discrete(T, p, 1)}));
756✔
675
  }
676

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

684
  // Check if we want to write out source
685
  if (check_for_node(root, "write_initial_source")) {
1,432!
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")) {
1,432✔
691
    source_rejection_fraction =
4✔
692
      std::stod(get_node_value(root, "source_rejection_fraction"));
4✔
693
  }
694

695
  if (check_for_node(root, "free_gas_threshold")) {
1,432!
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"))
1,432!
701
    surface_grazing_cutoff =
×
702
      std::stod(get_node_value(root, "surface_grazing_cutoff"));
×
703
  if (check_for_node(root, "surface_grazing_ratio"))
1,432!
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")) {
1,432✔
709
    survival_biasing = get_node_value_bool(root, "survival_biasing");
34✔
710
  }
711

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

717
  // Cutoffs
718
  if (check_for_node(root, "cutoff")) {
1,432✔
719
    xml_node node_cutoff = root.child("cutoff");
20✔
720
    if (check_for_node(node_cutoff, "weight")) {
20✔
721
      weight_cutoff = std::stod(get_node_value(node_cutoff, "weight"));
4✔
722
    }
723
    if (check_for_node(node_cutoff, "weight_avg")) {
20✔
724
      weight_survive = std::stod(get_node_value(node_cutoff, "weight_avg"));
4✔
725
    }
726
    if (check_for_node(node_cutoff, "survival_normalization")) {
20!
727
      survival_normalization =
×
728
        get_node_value_bool(node_cutoff, "survival_normalization");
×
729
    }
730
    if (check_for_node(node_cutoff, "energy_neutron")) {
20✔
731
      energy_cutoff[0] =
2✔
732
        std::stod(get_node_value(node_cutoff, "energy_neutron"));
4✔
733
    } else if (check_for_node(node_cutoff, "energy")) {
18!
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")) {
20✔
739
      energy_cutoff[1] =
12✔
740
        std::stod(get_node_value(node_cutoff, "energy_photon"));
24✔
741
    }
742
    if (check_for_node(node_cutoff, "energy_electron")) {
20!
743
      energy_cutoff[2] =
×
744
        std::stof(get_node_value(node_cutoff, "energy_electron"));
×
745
    }
746
    if (check_for_node(node_cutoff, "energy_positron")) {
20!
747
      energy_cutoff[3] =
×
748
        std::stod(get_node_value(node_cutoff, "energy_positron"));
×
749
    }
750
    if (check_for_node(node_cutoff, "time_neutron")) {
20✔
751
      time_cutoff[0] = std::stod(get_node_value(node_cutoff, "time_neutron"));
4✔
752
    }
753
    if (check_for_node(node_cutoff, "time_photon")) {
20!
754
      time_cutoff[1] = std::stod(get_node_value(node_cutoff, "time_photon"));
×
755
    }
756
    if (check_for_node(node_cutoff, "time_electron")) {
20!
757
      time_cutoff[2] = std::stod(get_node_value(node_cutoff, "time_electron"));
×
758
    }
759
    if (check_for_node(node_cutoff, "time_positron")) {
20!
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")) {
1,432✔
766
    properties_file = get_node_value(root, "properties_file");
2✔
767
    if (!file_exists(properties_file)) {
2!
768
      fatal_error(fmt::format("File '{}' does not exist.", properties_file));
×
769
    }
770
  }
771

772
  // Particle trace
773
  if (check_for_node(root, "trace")) {
1,432✔
774
    auto temp = get_node_array<int64_t>(root, "trace");
2✔
775
    if (temp.size() != 3) {
2!
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);
2✔
780
    trace_gen = temp.at(1);
2✔
781
    trace_particle = temp.at(2);
2✔
782
  }
2✔
783

784
  // Particle tracks
785
  if (check_for_node(root, "track")) {
1,432✔
786
    // Get values and make sure there are three per particle
787
    auto temp = get_node_array<int>(root, "track");
6✔
788
    if (temp.size() % 3 != 0) {
6!
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;
6✔
797
    for (int i = 0; i < n_tracks; ++i) {
24✔
798
      track_identifiers.push_back(
18✔
799
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
18✔
800
    }
801
  }
6✔
802

803
  // Shannon entropy
804
  if (solver_type == SolverType::RANDOM_RAY) {
1,432✔
805
    if (check_for_node(root, "entropy_mesh")) {
106!
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;
106✔
810
  } else if (solver_type == SolverType::MONTE_CARLO) {
1,326!
811
    if (check_for_node(root, "entropy_mesh")) {
1,326✔
812
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
120✔
813
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
60!
814
        fatal_error(fmt::format(
×
815
          "Mesh {} specified for Shannon entropy does not exist.", temp));
816
      }
817

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

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

827
    } else if (check_for_node(root, "entropy")) {
1,266!
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")) {
1,432✔
836
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
4✔
837
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
2!
838
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
839
                              "method does not exist.",
840
        temp));
841
    }
842

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

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

852
  } else if (check_for_node(root, "uniform_fs")) {
1,430!
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")) {
1,432✔
861

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

865
    // Determine number of batches at which to store state points
866
    if (check_for_node(node_sp, "batches")) {
24!
867
      // User gave specific batches to write state points
868
      auto temp = get_node_array<int>(node_sp, "batches");
24✔
869
      for (const auto& b : temp) {
74✔
870
        statepoint_batch.insert(b);
50✔
871
      }
872
    } else {
24✔
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);
1,408✔
880
  }
881

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

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

899
    // Check if the user has specified to write binary source file
900
    if (check_for_node(node_sp, "separate")) {
14✔
901
      source_separate = get_node_value_bool(node_sp, "separate");
10✔
902
    }
903
    if (check_for_node(node_sp, "write")) {
14!
904
      source_write = get_node_value_bool(node_sp, "write");
×
905
    }
906
    if (check_for_node(node_sp, "mcpl")) {
14✔
907
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
4✔
908
    }
909
    if (check_for_node(node_sp, "overwrite_latest")) {
14✔
910
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
2✔
911
      source_separate = source_latest;
2✔
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;
1,418✔
917
    sourcepoint_batch = statepoint_batch;
1,418!
918
  }
919

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

926
  // Check if the user has specified to write surface source
927
  if (check_for_node(root, "surf_source_write")) {
1,432✔
928
    surf_source_write = true;
78✔
929
    // Get surface source write node
930
    xml_node node_ssw = root.child("surf_source_write");
78✔
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")) {
78✔
936
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
38✔
937
      for (const auto& b : temp) {
190✔
938
        source_write_surf_id.insert(b);
152✔
939
      }
940
    }
38✔
941

942
    // Get maximum number of particles to be banked per surface
943
    if (check_for_node(node_ssw, "max_particles")) {
78✔
944
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
152✔
945
    } else {
946
      fatal_error("A maximum number of particles needs to be specified "
2✔
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")) {
76✔
953
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
12✔
954
    } else {
955
      ssw_max_files = 1;
70✔
956
    }
957

958
    if (check_for_node(node_ssw, "mcpl")) {
76✔
959
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
2✔
960
    }
961
    // Get cell information
962
    if (check_for_node(node_ssw, "cell")) {
76✔
963
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
40✔
964
      ssw_cell_type = SSWCellType::Both;
20✔
965
    }
966
    if (check_for_node(node_ssw, "cellfrom")) {
76✔
967
      if (ssw_cell_id != C_NONE) {
18✔
968
        fatal_error(
4✔
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"));
28✔
972
      ssw_cell_type = SSWCellType::From;
14✔
973
    }
974
    if (check_for_node(node_ssw, "cellto")) {
72✔
975
      if (ssw_cell_id != C_NONE) {
14✔
976
        fatal_error(
4✔
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"));
20✔
980
      ssw_cell_type = SSWCellType::To;
10✔
981
    }
982
  }
983

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

991
    // Determine cell ids at which crossing particles are to be banked
992
    if (check_for_node(node_ct, "cell_ids")) {
24✔
993
      auto temp = get_node_array<int>(node_ct, "cell_ids");
14✔
994
      for (const auto& b : temp) {
38✔
995
        collision_track_config.cell_ids.insert(b);
24✔
996
      }
997
    }
14✔
998
    if (check_for_node(node_ct, "reactions")) {
24✔
999
      auto temp = get_node_array<std::string>(node_ct, "reactions");
10✔
1000
      for (const auto& b : temp) {
26✔
1001
        int reaction_int = reaction_mt(b);
16✔
1002
        if (reaction_int > 0) {
16!
1003
          collision_track_config.mt_numbers.insert(reaction_int);
16✔
1004
        }
1005
      }
1006
    }
10✔
1007
    if (check_for_node(node_ct, "universe_ids")) {
24✔
1008
      auto temp = get_node_array<int>(node_ct, "universe_ids");
4✔
1009
      for (const auto& b : temp) {
8✔
1010
        collision_track_config.universe_ids.insert(b);
4✔
1011
      }
1012
    }
4✔
1013
    if (check_for_node(node_ct, "material_ids")) {
24✔
1014
      auto temp = get_node_array<int>(node_ct, "material_ids");
4✔
1015
      for (const auto& b : temp) {
10✔
1016
        collision_track_config.material_ids.insert(b);
6✔
1017
      }
1018
    }
4✔
1019
    if (check_for_node(node_ct, "nuclides")) {
24✔
1020
      auto temp = get_node_array<std::string>(node_ct, "nuclides");
4✔
1021
      for (const auto& b : temp) {
16✔
1022
        collision_track_config.nuclides.insert(b);
12✔
1023
      }
1024
    }
4✔
1025
    if (check_for_node(node_ct, "deposited_E_threshold")) {
24✔
1026
      collision_track_config.deposited_energy_threshold =
8✔
1027
        std::stod(get_node_value(node_ct, "deposited_E_threshold"));
8✔
1028
    }
1029
    // Get maximum number of particles to be banked per collision
1030
    if (check_for_node(node_ct, "max_collisions")) {
24!
1031
      collision_track_config.max_collisions =
48✔
1032
        std::stoll(get_node_value(node_ct, "max_collisions"));
48✔
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")) {
24!
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")) {
24✔
1044
      collision_track_config.mcpl_write = get_node_value_bool(node_ct, "mcpl");
4✔
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) {
1,422✔
1052
    for (const auto& b : sourcepoint_batch) {
2,840✔
1053
      if (!contains(statepoint_batch, b)) {
2,860!
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")) {
1,422✔
1063
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
4✔
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")) {
1,422✔
1069
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
2✔
1070
  }
1071

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

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

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

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

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

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

1107
    // Determine what method is used
1108
    if (check_for_node(node_res_scat, "method")) {
2!
1109
      auto temp = get_node_value(node_res_scat, "method", true, true);
2✔
1110
      if (temp == "rvs") {
2!
1111
        res_scat_method = ResScatMethod::rvs;
2✔
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
    }
2✔
1119

1120
    // Minimum energy for resonance scattering
1121
    if (check_for_node(node_res_scat, "energy_min")) {
2!
1122
      res_scat_energy_min =
4✔
1123
        std::stod(get_node_value(node_res_scat, "energy_min"));
4✔
1124
    }
1125
    if (res_scat_energy_min < 0.0) {
2!
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")) {
2!
1131
      res_scat_energy_max =
4✔
1132
        std::stod(get_node_value(node_res_scat, "energy_max"));
4✔
1133
    }
1134
    if (res_scat_energy_max < res_scat_energy_min) {
2!
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")) {
2!
1141
      res_scat_nuclides =
2✔
1142
        get_node_array<std::string>(node_res_scat, "nuclides");
4✔
1143
    }
1144
  }
1145

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

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

1173
    // Multipole currently doesn't work with photon transport
1174
    if (temperature_multipole && photon_transport) {
30!
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")) {
1,422✔
1180
    auto range = get_node_array<double>(root, "temperature_range");
28✔
1181
    temperature_range[0] = range.at(0);
28✔
1182
    temperature_range[1] = range.at(1);
28✔
1183
  }
28✔
1184

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

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

1195
    // Check for the number of points
1196
    if (check_for_node(node_tab_leg, "num_points")) {
14!
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")) {
1,422!
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) {
1,422✔
1215
    if (check_for_node(root, "create_fission_neutrons")) {
534✔
1216
      create_fission_neutrons =
56✔
1217
        get_node_value_bool(root, "create_fission_neutrons");
56✔
1218
    }
1219
  }
1220

1221
  // Check whether to scale fission photon yields
1222
  if (check_for_node(root, "delayed_photon_scaling")) {
1,422!
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")) {
1,422!
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")) {
1,422!
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")) {
1,468✔
1239
    variance_reduction::weight_windows.emplace_back(
46✔
1240
      std::make_unique<WeightWindows>(node_ww));
92✔
1241
  }
1242

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

1247
  // read weight windows from file
1248
  if (check_for_node(root, "weight_windows_file")) {
1,422!
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")) {
1,422✔
1256
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
12✔
1257
  }
1258

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

1264
  if (check_for_node(root, "max_history_splits")) {
1,422✔
1265
    settings::max_history_splits =
116✔
1266
      std::stoi(get_node_value(root, "max_history_splits"));
116✔
1267
  }
1268

1269
  if (check_for_node(root, "max_tracks")) {
1,422✔
1270
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
12✔
1271
  }
1272

1273
  // Create weight window generator objects
1274
  if (check_for_node(root, "weight_window_generators")) {
1,422✔
1275
    auto wwgs_node = root.child("weight_window_generators");
16✔
1276
    for (pugi::xml_node node_wwg :
32✔
1277
      wwgs_node.children("weight_windows_generator")) {
32✔
1278
      variance_reduction::weight_windows_generators.emplace_back(
16✔
1279
        std::make_unique<WeightWindowsGenerator>(node_wwg));
32✔
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) {
16!
1284
      if (wwg->on_the_fly_) {
16!
1285
        settings::weight_windows_on = true;
16✔
1286
        break;
16✔
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()) {
16!
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")) {
1,422✔
1303
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
20✔
1304
    if (check_for_node(ww_checkpoints, "collision")) {
20!
1305
      weight_window_checkpoint_collision =
20✔
1306
        get_node_value_bool(ww_checkpoints, "collision");
20✔
1307
    }
1308
    if (check_for_node(ww_checkpoints, "surface")) {
20!
1309
      weight_window_checkpoint_surface =
20✔
1310
        get_node_value_bool(ww_checkpoints, "surface");
20✔
1311
    }
1312
  }
1313

1314
  if (weight_windows_on) {
1,422✔
1315
    if (!weight_window_checkpoint_surface &&
44✔
1316
        !weight_window_checkpoint_collision)
26!
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")) {
1,422✔
1322
    settings::use_decay_photons =
2✔
1323
      get_node_value_bool(root, "use_decay_photons");
2✔
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")) {
1,422✔
1329
    bool val = get_node_value_bool(root, "shared_secondary_bank");
50✔
1330
    if (val && run_mode == RunMode::EIGENVALUE) {
50!
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;
50✔
1336
    }
1337
  } else if (settings::weight_windows_on) {
1,372✔
1338
    if (run_mode == RunMode::EIGENVALUE) {
16!
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) {
16!
1343
      settings::use_shared_secondary_bank = true;
16✔
1344
    }
1345
  }
1346
}
1,422✔
1347

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

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

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

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

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

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

1391
  return 0;
1392
}
1393

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

1398
  return 0;
460✔
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