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

openmc-dev / openmc / 33760503483

03 Sep 2026 01:19PM UTC coverage: 81.368% (+0.002%) from 81.366%
33760503483

Pull #4110

github

web-flow
Merge a3bd0787b into c106712e2
Pull Request #4110: Adaptive Volume Estimators

18821 of 27328 branches covered (68.87%)

Branch coverage included in aggregate %.

190 of 208 new or added lines in 7 files covered. (91.35%)

4 existing lines in 2 files now uncovered.

60536 of 70201 relevant lines covered (86.23%)

50117914.78 hits per line

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

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

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

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

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

114
ElectronTreatment electron_treatment {ElectronTreatment::TTB};
115
array<double, 4> energy_cutoff {0.0, 1000.0, 0.0, 0.0};
116
array<double, 4> time_cutoff {INFTY, INFTY, INFTY, INFTY};
117
int ifp_n_generation {-1};
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)
8,406 ✔
164
{
165
  using namespace settings;
8,406 ✔
166
  using namespace pugi;
8,406 ✔
167

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

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

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

215
  // Get number of inactive batches
216
  if (run_mode == RunMode::EIGENVALUE ||
8,406 ✔
217
      solver_type == SolverType::RANDOM_RAY) {
3,650 ✔
218
    if (check_for_node(node_base, "inactive")) {
5,356 ✔
219
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
5,101 ✔
220
    }
221
    if (check_for_node(node_base, "generations_per_batch")) {
5,356 ✔
222
      gen_per_batch =
30 ✔
223
        std::stoi(get_node_value(node_base, "generations_per_batch"));
15 ✔
224
    }
225

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

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

235
      if (check_for_node(node_keff_trigger, "type")) {
101 !
236
        auto temp = get_node_value(node_keff_trigger, "type", true, true);
101 ✔
237
        if (temp == "std_dev") {
101 !
238
          keff_trigger.metric = TriggerMetric::standard_deviation;
101 ✔
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")) {
101 !
251
        keff_trigger.threshold =
202 ✔
252
          std::stod(get_node_value(node_keff_trigger, "threshold"));
202 ✔
253
        if (keff_trigger.threshold <= 0) {
101 !
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) {
8,406 ✔
264
    xml_node random_ray_node = node_base.child("random_ray");
986 ✔
265
    if (check_for_node(random_ray_node, "distance_active")) {
986 !
266
      RandomRay::distance_active_ =
1,972 ✔
267
        std::stod(get_node_value(random_ray_node, "distance_active"));
1,972 ✔
268
      if (RandomRay::distance_active_ <= 0.0) {
986 !
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")) {
986 !
275
      RandomRay::distance_inactive_ =
1,972 ✔
276
        std::stod(get_node_value(random_ray_node, "distance_inactive"));
1,972 ✔
277
      if (RandomRay::distance_inactive_ < 0) {
986 !
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")) {
986 !
285
      xml_node ray_source_node = random_ray_node.child("ray_source");
986 ✔
286
      xml_node source_node = ray_source_node.child("source");
986 ✔
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);
1,972 ✔
290
    } else {
291
      fatal_error("Specify random ray source in settings XML");
×
292
    }
293
    if (check_for_node(random_ray_node, "volume_estimator")) {
986 ✔
294
      std::string temp_str =
589 ✔
295
        get_node_value(random_ray_node, "volume_estimator", true, true);
589 ✔
296
      if (temp_str == "simulation_averaged") {
589 ✔
297
        FlatSourceDomain::volume_estimator_ =
30 ✔
298
          RandomRayVolumeEstimator::SIMULATION_AVERAGED;
299
      } else if (temp_str == "naive") {
559 ✔
300
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::NAIVE;
102 ✔
301
      } else if (temp_str == "hybrid") {
457 ✔
302
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::HYBRID;
352 ✔
303
      } else if (temp_str == "adaptive") {
105 ✔
304
        FlatSourceDomain::volume_estimator_ =
75 ✔
305
          RandomRayVolumeEstimator::ADAPTIVE;
306
      } else if (temp_str == "strict_adaptive") {
30 !
307
        FlatSourceDomain::volume_estimator_ =
30 ✔
308
          RandomRayVolumeEstimator::STRICT_ADAPTIVE;
NEW
309
      } else if (temp_str == "auto") {
×
NEW
310
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::AUTO;
×
311
      } else {
312
        fatal_error("Unrecognized volume estimator: " + temp_str);
×
313
      }
314
    }
589 ✔
315
    if (check_for_node(random_ray_node, "source_shape")) {
986 ✔
316
      std::string temp_str =
517 ✔
317
        get_node_value(random_ray_node, "source_shape", true, true);
517 ✔
318
      if (temp_str == "flat") {
517 ✔
319
        RandomRay::source_shape_ = RandomRaySourceShape::FLAT;
97 ✔
320
      } else if (temp_str == "linear") {
420 ✔
321
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR;
375 ✔
322
      } else if (temp_str == "linear_xy") {
45 !
323
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR_XY;
45 ✔
324
      } else {
325
        fatal_error("Unrecognized source shape: " + temp_str);
×
326
      }
327
    }
517 ✔
328
    if (check_for_node(random_ray_node, "volume_normalized_flux_tallies")) {
986 ✔
329
      FlatSourceDomain::volume_normalized_flux_tallies_ =
708 ✔
330
        get_node_value_bool(random_ray_node, "volume_normalized_flux_tallies");
708 ✔
331
    }
332
    if (check_for_node(random_ray_node, "adjoint")) {
986 ✔
333
      FlatSourceDomain::adjoint_requested_ =
86 ✔
334
        get_node_value_bool(random_ray_node, "adjoint");
86 ✔
335
    }
336
    if (check_for_node(random_ray_node, "sample_method")) {
986 ✔
337
      std::string temp_str =
52 ✔
338
        get_node_value(random_ray_node, "sample_method", true, true);
52 ✔
339
      if (temp_str == "prng") {
52 !
340
        RandomRay::sample_method_ = RandomRaySampleMethod::PRNG;
×
341
      } else if (temp_str == "halton") {
52 ✔
342
        RandomRay::sample_method_ = RandomRaySampleMethod::HALTON;
37 ✔
343
      } else if (temp_str == "s2") {
15 !
344
        RandomRay::sample_method_ = RandomRaySampleMethod::S2;
15 ✔
345
      } else {
346
        fatal_error("Unrecognized sample method: " + temp_str);
×
347
      }
348
    }
52 ✔
349
    if (check_for_node(random_ray_node, "source_region_meshes")) {
986 ✔
350
      pugi::xml_node node_source_region_meshes =
398 ✔
351
        random_ray_node.child("source_region_meshes");
398 ✔
352
      for (pugi::xml_node node_mesh :
856 ✔
353
        node_source_region_meshes.children("mesh")) {
856 ✔
354
        int mesh_id = std::stoi(node_mesh.attribute("id").value());
916 ✔
355
        for (pugi::xml_node node_domain : node_mesh.children("domain")) {
916 ✔
356
          int domain_id = std::stoi(node_domain.attribute("id").value());
916 ✔
357
          std::string domain_type = node_domain.attribute("type").value();
458 ✔
358
          Source::DomainType type;
458 ✔
359
          if (domain_type == "material") {
458 ✔
360
            type = Source::DomainType::MATERIAL;
30 ✔
361
          } else if (domain_type == "cell") {
428 ✔
362
            type = Source::DomainType::CELL;
30 ✔
363
          } else if (domain_type == "universe") {
398 !
364
            type = Source::DomainType::UNIVERSE;
398 ✔
365
          } else {
366
            throw std::runtime_error("Unknown domain type: " + domain_type);
×
367
          }
368
          FlatSourceDomain::mesh_domain_map_[mesh_id].emplace_back(
458 ✔
369
            type, domain_id);
370
        }
458 ✔
371
      }
372
    }
373
    if (check_for_node(random_ray_node, "diagonal_stabilization_rho")) {
986 ✔
374
      FlatSourceDomain::diagonal_stabilization_rho_ = std::stod(
30 ✔
375
        get_node_value(random_ray_node, "diagonal_stabilization_rho"));
30 ✔
376
      if (FlatSourceDomain::diagonal_stabilization_rho_ < 0.0 ||
30 !
377
          FlatSourceDomain::diagonal_stabilization_rho_ > 1.0) {
378
        fatal_error("Random ray diagonal stabilization rho factor must be "
×
379
                    "between 0 and 1");
380
      }
381
    }
382
    if (check_for_node(random_ray_node, "adjoint_source")) {
986 ✔
383
      pugi::xml_node adj_source_node = random_ray_node.child("adjoint_source");
15 ✔
384
      for (pugi::xml_node source_node : adj_source_node.children("source")) {
30 ✔
385
        // Find any local adjoint sources
386
        model::adjoint_sources.push_back(Source::create(source_node));
30 ✔
387
      }
388
    }
389
  }
390
}
8,406 ✔
391

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

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

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

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

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

435
  write_message("Reading settings XML file...", 5);
1,401 ✔
436

437
  read_settings_xml(root);
1,401 ✔
438
}
1,413 ✔
439

440
void read_settings_xml(pugi::xml_node root)
9,424 ✔
441
{
442
  using namespace settings;
9,424 ✔
443
  using namespace pugi;
9,424 ✔
444

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

455
  // Check for user meshes and allocate
456
  read_meshes(root);
9,424 ✔
457

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

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

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

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

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

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

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

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

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

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

556
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
9,424 ✔
557
    // Read run parameters
558
    get_run_parameters(node_mode);
8,406 ✔
559

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

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

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

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

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

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

619
  // Check for photon transport
620
  if (check_for_node(root, "photon_transport")) {
9,415 ✔
621
    photon_transport = get_node_value_bool(root, "photon_transport");
486 ✔
622

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

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

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

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

651
  // ==========================================================================
652
  // EXTERNAL SOURCE
653

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

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

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

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

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

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

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

703
  if (check_for_node(root, "free_gas_threshold")) {
9,405 !
704
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
705
  }
706

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

715
  // Survival biasing
716
  if (check_for_node(root, "survival_biasing")) {
9,405 ✔
717
    survival_biasing = get_node_value_bool(root, "survival_biasing");
227 ✔
718
  }
719

720
  // Probability tables
721
  if (check_for_node(root, "ptables")) {
9,405 ✔
722
    urr_ptables_on = get_node_value_bool(root, "ptables");
15 ✔
723
  }
724

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

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

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

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

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

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

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

832
      // Turn on Shannon entropy calculation
833
      entropy_on = true;
334 ✔
834

835
    } else if (check_for_node(root, "entropy")) {
8,085 !
836
      fatal_error(
×
837
        "Specifying a Shannon entropy mesh via the <entropy> element "
838
        "is deprecated. Please create a mesh using <mesh> and then reference "
839
        "it by specifying its ID in an <entropy_mesh> element.");
840
    }
841
  }
842
  // Uniform fission source weighting mesh
843
  if (check_for_node(root, "ufs_mesh")) {
9,405 ✔
844
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
30 ✔
845
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
15 !
846
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
847
                              "method does not exist.",
848
        temp));
849
    }
850

851
    auto* m =
15 ✔
852
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
15 !
853
    if (!m)
15 !
854
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
855
    simulation::ufs_mesh = m;
15 ✔
856

857
    // Turn on uniform fission source weighting
858
    ufs_on = true;
15 ✔
859

860
  } else if (check_for_node(root, "uniform_fs")) {
9,390 !
861
    fatal_error(
×
862
      "Specifying a UFS mesh via the <uniform_fs> element "
863
      "is deprecated. Please create a mesh using <mesh> and then reference "
864
      "it by specifying its ID in a <ufs_mesh> element.");
865
  }
866

867
  // Check if the user has specified to write state points
868
  if (check_for_node(root, "state_point")) {
9,405 ✔
869

870
    // Get pointer to state_point node
871
    auto node_sp = root.child("state_point");
160 ✔
872

873
    // Determine number of batches at which to store state points
874
    if (check_for_node(node_sp, "batches")) {
160 !
875
      // User gave specific batches to write state points
876
      auto temp = get_node_array<int>(node_sp, "batches");
160 ✔
877
      for (const auto& b : temp) {
491 ✔
878
        statepoint_batch.insert(b);
331 ✔
879
      }
880
    } else {
160 ✔
881
      // If neither were specified, write state point at last batch
882
      statepoint_batch.insert(n_batches);
×
883
    }
884
  } else {
885
    // If no <state_point> tag was present, by default write state point at
886
    // last batch only
887
    statepoint_batch.insert(n_batches);
9,245 ✔
888
  }
889

890
  // Check if the user has specified to write source points
891
  if (check_for_node(root, "source_point")) {
9,405 ✔
892
    // Get source_point node
893
    xml_node node_sp = root.child("source_point");
101 ✔
894

895
    // Determine batches at which to store source points
896
    if (check_for_node(node_sp, "batches")) {
101 ✔
897
      // User gave specific batches to write source points
898
      auto temp = get_node_array<int>(node_sp, "batches");
45 ✔
899
      for (const auto& b : temp) {
120 ✔
900
        sourcepoint_batch.insert(b);
75 ✔
901
      }
902
    } else {
45 ✔
903
      // If neither were specified, write source points with state points
904
      sourcepoint_batch = statepoint_batch;
56 !
905
    }
906

907
    // Check if the user has specified to write binary source file
908
    if (check_for_node(node_sp, "separate")) {
101 ✔
909
      source_separate = get_node_value_bool(node_sp, "separate");
71 ✔
910
    }
911
    if (check_for_node(node_sp, "write")) {
101 !
912
      source_write = get_node_value_bool(node_sp, "write");
×
913
    }
914
    if (check_for_node(node_sp, "mcpl")) {
101 ✔
915
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
26 ✔
916
    }
917
    if (check_for_node(node_sp, "overwrite_latest")) {
101 ✔
918
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
15 ✔
919
      source_separate = source_latest;
15 ✔
920
    }
921
  } else {
922
    // If no <source_point> tag was present, by default we keep source bank in
923
    // statepoint file and write it out at statepoints intervals
924
    source_separate = false;
9,304 ✔
925
    sourcepoint_batch = statepoint_batch;
9,304 !
926
  }
927

928
  // Check is the user specified to convert strength to statistical weight
929
  if (check_for_node(root, "uniform_source_sampling")) {
9,405 ✔
930
    uniform_source_sampling =
55 ✔
931
      get_node_value_bool(root, "uniform_source_sampling");
55 ✔
932
  }
933

934
  // Check if the user has specified to write surface source
935
  if (check_for_node(root, "surf_source_write")) {
9,405 ✔
936
    surf_source_write = true;
412 ✔
937
    // Get surface source write node
938
    xml_node node_ssw = root.child("surf_source_write");
412 ✔
939

940
    // Determine surface ids at which crossing particles are to be banked.
941
    // If no surfaces are specified, all surfaces in the model will be used
942
    // to bank source points.
943
    if (check_for_node(node_ssw, "surface_ids")) {
412 ✔
944
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
202 ✔
945
      for (const auto& b : temp) {
994 ✔
946
        source_write_surf_id.insert(b);
792 ✔
947
      }
948
    }
202 ✔
949

950
    // Get maximum number of particles to be banked per surface
951
    if (check_for_node(node_ssw, "max_particles")) {
412 ✔
952
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
806 ✔
953
    } else {
954
      fatal_error("A maximum number of particles needs to be specified "
9 ✔
955
                  "using the 'max_particles' parameter to store surface "
956
                  "source points.");
957
    }
958

959
    // Get maximum number of surface source files to be created
960
    if (check_for_node(node_ssw, "max_source_files")) {
403 ✔
961
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
66 ✔
962
    } else {
963
      ssw_max_files = 1;
370 ✔
964
    }
965

966
    if (check_for_node(node_ssw, "mcpl")) {
403 ✔
967
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
11 ✔
968
    }
969
    // Get cell information
970
    if (check_for_node(node_ssw, "cell")) {
403 ✔
971
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
208 ✔
972
      ssw_cell_type = SSWCellType::Both;
104 ✔
973
    }
974
    if (check_for_node(node_ssw, "cellfrom")) {
403 ✔
975
      if (ssw_cell_id != C_NONE) {
90 ✔
976
        fatal_error(
18 ✔
977
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
978
      }
979
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
144 ✔
980
      ssw_cell_type = SSWCellType::From;
72 ✔
981
    }
982
    if (check_for_node(node_ssw, "cellto")) {
385 ✔
983
      if (ssw_cell_id != C_NONE) {
71 ✔
984
        fatal_error(
18 ✔
985
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
986
      }
987
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
106 ✔
988
      ssw_cell_type = SSWCellType::To;
53 ✔
989
    }
990
  }
991

992
  // Check if the user has specified to write specific collisions
993
  if (check_for_node(root, "collision_track")) {
9,360 ✔
994
    settings::collision_track = true;
160 ✔
995
    // Get collision track node
996
    xml_node node_ct = root.child("collision_track");
160 ✔
997
    collision_track_config = CollisionTrackConfig {};
160 ✔
998

999
    // Determine cell ids at which crossing particles are to be banked
1000
    if (check_for_node(node_ct, "cell_ids")) {
160 ✔
1001
      auto temp = get_node_array<int>(node_ct, "cell_ids");
89 ✔
1002
      for (const auto& b : temp) {
237 ✔
1003
        collision_track_config.cell_ids.insert(b);
148 ✔
1004
      }
1005
    }
89 ✔
1006
    if (check_for_node(node_ct, "reactions")) {
160 ✔
1007
      auto temp = get_node_array<std::string>(node_ct, "reactions");
63 ✔
1008
      for (const auto& b : temp) {
171 ✔
1009
        int reaction_int = reaction_mt(b);
108 ✔
1010
        if (reaction_int > 0) {
108 !
1011
          collision_track_config.mt_numbers.insert(reaction_int);
108 ✔
1012
        }
1013
      }
1014
    }
63 ✔
1015
    if (check_for_node(node_ct, "universe_ids")) {
160 ✔
1016
      auto temp = get_node_array<int>(node_ct, "universe_ids");
30 ✔
1017
      for (const auto& b : temp) {
60 ✔
1018
        collision_track_config.universe_ids.insert(b);
30 ✔
1019
      }
1020
    }
30 ✔
1021
    if (check_for_node(node_ct, "material_ids")) {
160 ✔
1022
      auto temp = get_node_array<int>(node_ct, "material_ids");
30 ✔
1023
      for (const auto& b : temp) {
75 ✔
1024
        collision_track_config.material_ids.insert(b);
45 ✔
1025
      }
1026
    }
30 ✔
1027
    if (check_for_node(node_ct, "nuclides")) {
160 ✔
1028
      auto temp = get_node_array<std::string>(node_ct, "nuclides");
30 ✔
1029
      for (const auto& b : temp) {
120 ✔
1030
        collision_track_config.nuclides.insert(b);
90 ✔
1031
      }
1032
    }
30 ✔
1033
    if (check_for_node(node_ct, "deposited_E_threshold")) {
160 ✔
1034
      collision_track_config.deposited_energy_threshold =
60 ✔
1035
        std::stod(get_node_value(node_ct, "deposited_E_threshold"));
60 ✔
1036
    }
1037
    // Get maximum number of particles to be banked per collision
1038
    if (check_for_node(node_ct, "max_collisions")) {
160 !
1039
      collision_track_config.max_collisions =
320 ✔
1040
        std::stoll(get_node_value(node_ct, "max_collisions"));
320 ✔
1041
    } else {
1042
      warning("A maximum number of collisions needs to be specified. "
×
1043
              "By default the code sets 'max_collisions' parameter equals to "
1044
              "1000.");
1045
    }
1046
    // Get maximum number of collision_track files to be created
1047
    if (check_for_node(node_ct, "max_collision_track_files")) {
160 !
1048
      collision_track_config.max_files =
×
1049
        std::stoll(get_node_value(node_ct, "max_collision_track_files"));
×
1050
    }
1051
    if (check_for_node(node_ct, "mcpl")) {
160 ✔
1052
      collision_track_config.mcpl_write = get_node_value_bool(node_ct, "mcpl");
22 ✔
1053
    }
1054
  }
1055

1056
  // If source is not separate and is to be written out in the statepoint
1057
  // file, make sure that the sourcepoint batch numbers are contained in the
1058
  // statepoint list
1059
  if (!source_separate) {
9,360 ✔
1060
    for (const auto& b : sourcepoint_batch) {
18,674 ✔
1061
      if (!contains(statepoint_batch, b)) {
18,800 !
1062
        fatal_error(
×
1063
          "Sourcepoint batches are not a subset of statepoint batches.");
1064
      }
1065
    }
1066
  }
1067

1068
  // Check if the user has specified to not reduce tallies at the end of every
1069
  // batch
1070
  if (check_for_node(root, "no_reduce")) {
9,360 ✔
1071
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
30 ✔
1072
  }
1073

1074
  // Check if the user has specified to use confidence intervals for
1075
  // uncertainties rather than standard deviations
1076
  if (check_for_node(root, "confidence_intervals")) {
9,360 ✔
1077
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
15 ✔
1078
  }
1079

1080
  // Check for output options
1081
  if (check_for_node(root, "output")) {
9,360 ✔
1082
    // Get pointer to output node
1083
    pugi::xml_node node_output = root.child("output");
856 ✔
1084

1085
    // Check for summary option
1086
    if (check_for_node(node_output, "summary")) {
856 ✔
1087
      output_summary = get_node_value_bool(node_output, "summary");
830 ✔
1088
    }
1089

1090
    // Check for ASCII tallies output option
1091
    if (check_for_node(node_output, "tallies")) {
856 ✔
1092
      output_tallies = get_node_value_bool(node_output, "tallies");
382 ✔
1093
    }
1094

1095
    // Set output directory if a path has been specified
1096
    if (check_for_node(node_output, "path")) {
856 !
1097
      path_output = get_node_value(node_output, "path");
×
1098
      if (!ends_with(path_output, "/")) {
×
1099
        path_output += "/";
856 !
1100
      }
1101
    }
1102
  }
1103

1104
  // Resonance scattering parameters
1105
  if (check_for_node(root, "resonance_scattering")) {
9,360 ✔
1106
    xml_node node_res_scat = root.child("resonance_scattering");
15 ✔
1107

1108
    // See if resonance scattering is enabled
1109
    if (check_for_node(node_res_scat, "enable")) {
15 !
1110
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
15 ✔
1111
    } else {
1112
      res_scat_on = true;
×
1113
    }
1114

1115
    // Determine what method is used
1116
    if (check_for_node(node_res_scat, "method")) {
15 !
1117
      auto temp = get_node_value(node_res_scat, "method", true, true);
15 ✔
1118
      if (temp == "rvs") {
15 !
1119
        res_scat_method = ResScatMethod::rvs;
15 ✔
1120
      } else if (temp == "dbrc") {
×
1121
        res_scat_method = ResScatMethod::dbrc;
×
1122
      } else {
1123
        fatal_error(
×
1124
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1125
      }
1126
    }
15 ✔
1127

1128
    // Minimum energy for resonance scattering
1129
    if (check_for_node(node_res_scat, "energy_min")) {
15 !
1130
      res_scat_energy_min =
30 ✔
1131
        std::stod(get_node_value(node_res_scat, "energy_min"));
30 ✔
1132
    }
1133
    if (res_scat_energy_min < 0.0) {
15 !
1134
      fatal_error("Lower resonance scattering energy bound is negative");
×
1135
    }
1136

1137
    // Maximum energy for resonance scattering
1138
    if (check_for_node(node_res_scat, "energy_max")) {
15 !
1139
      res_scat_energy_max =
30 ✔
1140
        std::stod(get_node_value(node_res_scat, "energy_max"));
30 ✔
1141
    }
1142
    if (res_scat_energy_max < res_scat_energy_min) {
15 !
1143
      fatal_error("Upper resonance scattering energy bound is below the "
×
1144
                  "lower resonance scattering energy bound.");
1145
    }
1146

1147
    // Get resonance scattering nuclides
1148
    if (check_for_node(node_res_scat, "nuclides")) {
15 !
1149
      res_scat_nuclides =
15 ✔
1150
        get_node_array<std::string>(node_res_scat, "nuclides");
30 ✔
1151
    }
1152
  }
1153

1154
  // Get volume calculations
1155
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
9,670 ✔
1156
    model::volume_calcs.emplace_back(node_vol);
310 ✔
1157
  }
1158

1159
  // Get temperature settings
1160
  if (check_for_node(root, "temperature_default")) {
9,360 ✔
1161
    temperature_default =
342 ✔
1162
      std::stod(get_node_value(root, "temperature_default"));
342 ✔
1163
  }
1164
  if (check_for_node(root, "temperature_method")) {
9,360 ✔
1165
    auto temp = get_node_value(root, "temperature_method", true, true);
485 ✔
1166
    if (temp == "nearest") {
485 ✔
1167
      temperature_method = TemperatureMethod::NEAREST;
304 ✔
1168
    } else if (temp == "interpolation") {
181 !
1169
      temperature_method = TemperatureMethod::INTERPOLATION;
181 ✔
1170
    } else {
1171
      fatal_error("Unknown temperature method: " + temp);
×
1172
    }
1173
  }
485 ✔
1174
  if (check_for_node(root, "temperature_tolerance")) {
9,360 ✔
1175
    temperature_tolerance =
680 ✔
1176
      std::stod(get_node_value(root, "temperature_tolerance"));
680 ✔
1177
  }
1178
  if (check_for_node(root, "temperature_multipole")) {
9,360 ✔
1179
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
185 ✔
1180

1181
    // Multipole currently doesn't work with photon transport
1182
    if (temperature_multipole && photon_transport) {
185 !
1183
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1184
                  "photon transport.");
1185
    }
1186
  }
1187
  if (check_for_node(root, "temperature_range")) {
9,360 ✔
1188
    auto range = get_node_array<double>(root, "temperature_range");
170 ✔
1189
    temperature_range[0] = range.at(0);
170 ✔
1190
    temperature_range[1] = range.at(1);
170 ✔
1191
  }
170 ✔
1192

1193
  // Check for tabular_legendre options
1194
  if (check_for_node(root, "tabular_legendre")) {
9,360 ✔
1195
    // Get pointer to tabular_legendre node
1196
    xml_node node_tab_leg = root.child("tabular_legendre");
105 ✔
1197

1198
    // Check for enable option
1199
    if (check_for_node(node_tab_leg, "enable")) {
105 !
1200
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
105 ✔
1201
    }
1202

1203
    // Check for the number of points
1204
    if (check_for_node(node_tab_leg, "num_points")) {
105 !
1205
      legendre_to_tabular_points =
×
1206
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
1207
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
1208
        fatal_error(
×
1209
          "The 'num_points' subelement/attribute of the "
1210
          "<tabular_legendre> element must contain a value greater than 1");
1211
      }
1212
    }
1213
  }
1214

1215
  // Check whether create delayed neutrons in fission
1216
  if (check_for_node(root, "create_delayed_neutrons")) {
9,360 !
1217
    create_delayed_neutrons =
×
1218
      get_node_value_bool(root, "create_delayed_neutrons");
×
1219
  }
1220

1221
  // Check whether create fission sites
1222
  if (run_mode == RunMode::FIXED_SOURCE) {
9,360 ✔
1223
    if (check_for_node(root, "create_fission_neutrons")) {
3,604 ✔
1224
      create_fission_neutrons =
336 ✔
1225
        get_node_value_bool(root, "create_fission_neutrons");
336 ✔
1226
    }
1227
  }
1228

1229
  // Check whether to scale fission photon yields
1230
  if (check_for_node(root, "delayed_photon_scaling")) {
9,360 !
1231
    delayed_photon_scaling =
×
1232
      get_node_value_bool(root, "delayed_photon_scaling");
×
1233
  }
1234

1235
  // Check whether to use event-based parallelism
1236
  if (check_for_node(root, "event_based")) {
9,360 !
1237
    event_based = get_node_value_bool(root, "event_based");
×
1238
  }
1239

1240
  // Check whether material cell offsets should be generated
1241
  if (check_for_node(root, "material_cell_offsets")) {
9,360 !
1242
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1243
  }
1244

1245
  // Weight window information
1246
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
9,676 ✔
1247
    variance_reduction::weight_windows.emplace_back(
316 ✔
1248
      std::make_unique<WeightWindows>(node_ww));
632 ✔
1249
  }
1250

1251
  // Enable weight windows by default if one or more are present
1252
  if (variance_reduction::weight_windows.size() > 0)
9,360 ✔
1253
    settings::weight_windows_on = true;
220 ✔
1254

1255
  // read weight windows from file
1256
  if (check_for_node(root, "weight_windows_file")) {
9,360 ✔
1257
    weight_windows_file = get_node_value(root, "weight_windows_file");
26 ✔
1258
    weight_windows_on = true;
26 ✔
1259
  }
1260

1261
  // read settings for weight windows value, this will override
1262
  // the automatic setting even if weight windows are present
1263
  if (check_for_node(root, "weight_windows_on")) {
9,360 ✔
1264
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
93 ✔
1265
  }
1266

1267
  if (check_for_node(root, "max_secondaries")) {
9,360 !
1268
    settings::max_secondaries =
×
1269
      std::stoi(get_node_value(root, "max_secondaries"));
×
1270
  }
1271

1272
  if (check_for_node(root, "max_history_splits")) {
9,360 ✔
1273
    settings::max_history_splits =
798 ✔
1274
      std::stoi(get_node_value(root, "max_history_splits"));
798 ✔
1275
  }
1276

1277
  if (check_for_node(root, "max_tracks")) {
9,360 ✔
1278
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
90 ✔
1279
  }
1280

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

1309
  // Set up weight window checkpoints
1310
  if (check_for_node(root, "weight_window_checkpoints")) {
9,360 ✔
1311
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
184 ✔
1312
    if (check_for_node(ww_checkpoints, "collision")) {
184 !
1313
      weight_window_checkpoint_collision =
184 ✔
1314
        get_node_value_bool(ww_checkpoints, "collision");
184 ✔
1315
    }
1316
    if (check_for_node(ww_checkpoints, "surface")) {
184 !
1317
      weight_window_checkpoint_surface =
184 ✔
1318
        get_node_value_bool(ww_checkpoints, "surface");
184 ✔
1319
    }
1320
  }
1321

1322
  if (weight_windows_on) {
9,360 ✔
1323
    if (!weight_window_checkpoint_surface &&
377 ✔
1324
        !weight_window_checkpoint_collision)
204 !
1325
      fatal_error(
×
1326
        "Weight Windows are enabled but there are no valid checkpoints.");
1327
  }
1328

1329
  if (check_for_node(root, "use_decay_photons")) {
9,360 ✔
1330
    settings::use_decay_photons =
11 ✔
1331
      get_node_value_bool(root, "use_decay_photons");
11 ✔
1332
  }
1333

1334
  // If weight windows are on, also enable shared secondary bank (unless
1335
  // explicitly disabled by user).
1336
  if (check_for_node(root, "shared_secondary_bank")) {
9,360 ✔
1337
    bool val = get_node_value_bool(root, "shared_secondary_bank");
335 ✔
1338
    if (val && run_mode == RunMode::EIGENVALUE) {
335 !
1339
      warning(
×
1340
        "Shared secondary bank is not supported in eigenvalue calculations. "
1341
        "Setting will be ignored.");
1342
    } else {
1343
      settings::use_shared_secondary_bank = val;
335 ✔
1344
    }
1345
  } else if (settings::weight_windows_on) {
9,025 ✔
1346
    if (run_mode == RunMode::EIGENVALUE) {
195 ✔
1347
      warning(
22 ✔
1348
        "Shared secondary bank is not supported in eigenvalue calculations. "
1349
        "Particle local secondary banks will be used instead.");
1350
    } else if (run_mode == RunMode::FIXED_SOURCE) {
184 !
1351
      settings::use_shared_secondary_bank = true;
184 ✔
1352
    }
1353
  }
1354
}
9,360 ✔
1355

1356
void free_memory_settings()
9,511 ✔
1357
{
1358
  settings::statepoint_batch.clear();
9,511 ✔
1359
  settings::sourcepoint_batch.clear();
9,511 ✔
1360
  settings::source_write_surf_id.clear();
9,511 ✔
1361
  settings::res_scat_nuclides.clear();
9,511 ✔
1362
  settings::ifp_delayed_group_on = false;
9,511 ✔
1363
  settings::ifp_lifetime_on = false;
9,511 ✔
1364
}
9,511 ✔
1365

1366
//==============================================================================
1367
// C API functions
1368
//==============================================================================
1369

1370
extern "C" int openmc_set_n_batches(
220 ✔
1371
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1372
{
1373
  if (settings::n_inactive >= n_batches) {
220 ✔
1374
    set_errmsg("Number of active batches must be greater than zero.");
11 ✔
1375
    return OPENMC_E_INVALID_ARGUMENT;
11 ✔
1376
  }
1377

1378
  if (!settings::trigger_on) {
209 ✔
1379
    // Set n_batches and n_max_batches to same value
1380
    settings::n_batches = n_batches;
187 ✔
1381
    settings::n_max_batches = n_batches;
187 ✔
1382
  } else {
1383
    // Set n_batches and n_max_batches based on value of set_max_batches
1384
    if (set_max_batches) {
22 ✔
1385
      settings::n_max_batches = n_batches;
11 ✔
1386
    } else {
1387
      settings::n_batches = n_batches;
11 ✔
1388
    }
1389
  }
1390

1391
  // Update size of k_generation and entropy
1392
  int m = settings::n_max_batches * settings::gen_per_batch;
209 ✔
1393
  simulation::k_generation.reserve(m);
209 ✔
1394
  simulation::entropy.reserve(m);
209 ✔
1395

1396
  // Add value of n_batches to statepoint_batch
1397
  if (add_statepoint_batch &&
209 ✔
1398
      !(contains(settings::statepoint_batch, n_batches)))
198 ✔
1399
    settings::statepoint_batch.insert(n_batches);
33 ✔
1400

1401
  return 0;
1402
}
1403

1404
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,530 ✔
1405
{
1406
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,530 ✔
1407

1408
  return 0;
2,530 ✔
1409
}
1410

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

© 2026 Coveralls, Inc