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

openmc-dev / openmc / 22920521397

10 Mar 2026 07:28PM UTC coverage: 81.221% (-0.5%) from 81.721%
22920521397

Pull #3810

github

web-flow
Merge c81063b52 into 1dc4aa988
Pull Request #3810: Implementation of migration area score

17031 of 24387 branches covered (69.84%)

Branch coverage included in aggregate %.

37 of 52 new or added lines in 5 files covered. (71.15%)

2537 existing lines in 86 files now uncovered.

57019 of 66784 relevant lines covered (85.38%)

35780397.68 hits per line

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

76.62
/src/settings.cpp
1
#include "openmc/settings.h"
2
#include "openmc/random_ray/flat_source_domain.h"
3

4
#include <cmath>  // for ceil, pow
5
#include <limits> // for numeric_limits
6
#include <string>
7

8
#include <fmt/core.h>
9
#ifdef _OPENMP
10
#include <omp.h>
11
#endif
12

13
#include "openmc/capi.h"
14
#include "openmc/collision_track.h"
15
#include "openmc/constants.h"
16
#include "openmc/container_util.h"
17
#include "openmc/distribution.h"
18
#include "openmc/distribution_multi.h"
19
#include "openmc/distribution_spatial.h"
20
#include "openmc/eigenvalue.h"
21
#include "openmc/error.h"
22
#include "openmc/file_utils.h"
23
#include "openmc/mcpl_interface.h"
24
#include "openmc/mesh.h"
25
#include "openmc/message_passing.h"
26
#include "openmc/output.h"
27
#include "openmc/plot.h"
28
#include "openmc/random_lcg.h"
29
#include "openmc/random_ray/random_ray.h"
30
#include "openmc/reaction.h"
31
#include "openmc/simulation.h"
32
#include "openmc/source.h"
33
#include "openmc/string_utils.h"
34
#include "openmc/tallies/trigger.h"
35
#include "openmc/volume_calc.h"
36
#include "openmc/weight_windows.h"
37
#include "openmc/xml_interface.h"
38

39
namespace openmc {
40

41
//==============================================================================
42
// Global variables
43
//==============================================================================
44

45
namespace settings {
46

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

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

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

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

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

155
} // namespace settings
156

157
//==============================================================================
158
// Functions
159
//==============================================================================
160

161
void get_run_parameters(pugi::xml_node node_base)
4,789✔
162
{
163
  using namespace settings;
4,789✔
164
  using namespace pugi;
4,789✔
165

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

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

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

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

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

195
  // Get max number of lost particles
196
  if (check_for_node(node_base, "max_lost_particles")) {
4,789✔
197
    max_lost_particles =
60✔
198
      std::stoi(get_node_value(node_base, "max_lost_particles"));
30✔
199
  }
200

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

207
  // Get relative number of lost particles
208
  if (check_for_node(node_base, "max_write_lost_particles")) {
4,789✔
209
    max_write_lost_particles =
20✔
210
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
10✔
211
  }
212

213
  // Get number of inactive batches
214
  if (run_mode == RunMode::EIGENVALUE ||
4,789✔
215
      solver_type == SolverType::RANDOM_RAY) {
1,831✔
216
    if (check_for_node(node_base, "inactive")) {
3,228✔
217
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
3,094✔
218
    }
219
    if (check_for_node(node_base, "generations_per_batch")) {
3,228✔
220
      gen_per_batch =
20✔
221
        std::stoi(get_node_value(node_base, "generations_per_batch"));
10✔
222
    }
223

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

229
    // Get the trigger information for keff
230
    if (check_for_node(node_base, "keff_trigger")) {
3,228✔
231
      xml_node node_keff_trigger = node_base.child("keff_trigger");
67✔
232

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

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

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

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

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

400
  // Get root element
401
  xml_node root = doc.document_element();
855✔
402

403
  // Verbosity
404
  if (check_for_node(root, "verbosity") && verbosity == -1) {
855!
405
    verbosity = std::stoi(get_node_value(root, "verbosity"));
230✔
406
  } else if (verbosity == -1) {
740!
407
    verbosity = 7;
740✔
408
  }
409

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

417
  write_message("Reading settings XML file...", 5);
855✔
418

419
  read_settings_xml(root);
855✔
420
}
864✔
421

422
void read_settings_xml(pugi::xml_node root)
5,298✔
423
{
424
  using namespace settings;
5,298✔
425
  using namespace pugi;
5,298✔
426

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

437
  // Check for user meshes and allocate
438
  read_meshes(root);
5,298✔
439

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

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

464
  // Check for a trigger node and get trigger information
465
  if (check_for_node(root, "trigger")) {
5,298✔
466
    xml_node node_trigger = root.child("trigger");
102✔
467

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

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

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

491
  // Check run mode if it hasn't been set from the command line
492
  xml_node node_mode;
5,298✔
493
  if (run_mode == RunMode::UNSET) {
5,298✔
494
    if (check_for_node(root, "run_mode")) {
4,809✔
495
      std::string temp_str = get_node_value(root, "run_mode", true, true);
4,789✔
496
      if (temp_str == "eigenvalue") {
4,789✔
497
        run_mode = RunMode::EIGENVALUE;
2,938✔
498
      } else if (temp_str == "fixed source") {
1,851✔
499
        run_mode = RunMode::FIXED_SOURCE;
1,831✔
500
      } else if (temp_str == "plot") {
20!
UNCOV
501
        run_mode = RunMode::PLOTTING;
×
502
      } else if (temp_str == "particle restart") {
20!
UNCOV
503
        run_mode = RunMode::PARTICLE;
×
504
      } else if (temp_str == "volume") {
20!
505
        run_mode = RunMode::VOLUME;
20✔
506
      } else {
UNCOV
507
        fatal_error("Unrecognized run mode: " + temp_str);
×
508
      }
509

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

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

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

538
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
5,298✔
539
    // Read run parameters
540
    get_run_parameters(node_mode);
4,789✔
541

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

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

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

577
  // Copy random number seed if specified
578
  if (check_for_node(root, "seed")) {
5,293✔
579
    auto seed = std::stoll(get_node_value(root, "seed"));
758✔
580
    openmc_set_seed(seed);
379✔
581
  }
582

583
  // Copy random number stride if specified
584
  if (check_for_node(root, "stride")) {
5,293✔
585
    auto stride = std::stoull(get_node_value(root, "stride"));
20✔
586
    openmc_set_stride(stride);
10✔
587
  }
588

589
  // Check for electron treatment
590
  if (check_for_node(root, "electron_treatment")) {
5,293✔
591
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
54✔
592
    if (temp_str == "led") {
54✔
593
      electron_treatment = ElectronTreatment::LED;
17✔
594
    } else if (temp_str == "ttb") {
37!
595
      electron_treatment = ElectronTreatment::TTB;
37✔
596
    } else {
UNCOV
597
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
598
    }
599
  }
54✔
600

601
  // Check for photon transport
602
  if (check_for_node(root, "photon_transport")) {
5,293✔
603
    photon_transport = get_node_value_bool(root, "photon_transport");
135✔
604

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

611
  // Check for atomic relaxation
612
  if (check_for_node(root, "atomic_relaxation")) {
5,293✔
613
    atomic_relaxation = get_node_value_bool(root, "atomic_relaxation");
10✔
614
  }
615

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

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

633
  // ==========================================================================
634
  // EXTERNAL SOURCE
635

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

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

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

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

667
  // Build probability mass function for sampling external sources
668
  vector<double> source_strengths;
5,288✔
669
  for (auto& s : model::external_sources) {
11,578✔
670
    source_strengths.push_back(s->strength());
6,290✔
671
  }
672
  model::external_sources_probability.assign(source_strengths);
5,288✔
673

674
  // Check if we want to write out source
675
  if (check_for_node(root, "write_initial_source")) {
5,288!
676
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
677
  }
678

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

685
  if (check_for_node(root, "free_gas_threshold")) {
5,288!
UNCOV
686
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
687
  }
688

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

697
  // Survival biasing
698
  if (check_for_node(root, "survival_biasing")) {
5,288✔
699
    survival_biasing = get_node_value_bool(root, "survival_biasing");
121✔
700
  }
701

702
  // Probability tables
703
  if (check_for_node(root, "ptables")) {
5,288✔
704
    urr_ptables_on = get_node_value_bool(root, "ptables");
10✔
705
  }
706

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

754
  // Particle trace
755
  if (check_for_node(root, "trace")) {
5,288✔
756
    auto temp = get_node_array<int64_t>(root, "trace");
10✔
757
    if (temp.size() != 3) {
10!
UNCOV
758
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
759
                  "batch, generation, and particle number.");
760
    }
761
    trace_batch = temp.at(0);
10✔
762
    trace_gen = temp.at(1);
10✔
763
    trace_particle = temp.at(2);
10✔
764
  }
10✔
765

766
  // Particle tracks
767
  if (check_for_node(root, "track")) {
5,288✔
768
    // Get values and make sure there are three per particle
769
    auto temp = get_node_array<int>(root, "track");
30✔
770
    if (temp.size() % 3 != 0) {
30!
UNCOV
771
      fatal_error(
×
772
        "Number of integers specified in 'track' is not "
773
        "divisible by 3.  Please provide 3 integers per particle to be "
774
        "tracked.");
775
    }
776

777
    // Reshape into track_identifiers
778
    int n_tracks = temp.size() / 3;
30✔
779
    for (int i = 0; i < n_tracks; ++i) {
120✔
780
      track_identifiers.push_back(
90✔
781
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
90✔
782
    }
783
  }
30✔
784

785
  // Shannon entropy
786
  if (solver_type == SolverType::RANDOM_RAY) {
5,288✔
787
    if (check_for_node(root, "entropy_mesh")) {
507!
UNCOV
788
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
789
                  "No user-defined entropy mesh is supported.");
790
    }
791
    entropy_on = true;
507✔
792
  } else if (solver_type == SolverType::MONTE_CARLO) {
4,781!
793
    if (check_for_node(root, "entropy_mesh")) {
4,781✔
794
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
426✔
795
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
213!
UNCOV
796
        fatal_error(fmt::format(
×
797
          "Mesh {} specified for Shannon entropy does not exist.", temp));
798
      }
799

800
      auto* m = dynamic_cast<RegularMesh*>(
213!
801
        model::meshes[model::mesh_map.at(temp)].get());
213!
802
      if (!m)
213!
UNCOV
803
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
804
      simulation::entropy_mesh = m;
213✔
805

806
      // Turn on Shannon entropy calculation
807
      entropy_on = true;
213✔
808

809
    } else if (check_for_node(root, "entropy")) {
4,568!
810
      fatal_error(
×
811
        "Specifying a Shannon entropy mesh via the <entropy> element "
812
        "is deprecated. Please create a mesh using <mesh> and then reference "
813
        "it by specifying its ID in an <entropy_mesh> element.");
814
    }
815
  }
816
  // Uniform fission source weighting mesh
817
  if (check_for_node(root, "ufs_mesh")) {
5,288✔
818
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
20✔
819
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
10!
UNCOV
820
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
821
                              "method does not exist.",
822
        temp));
823
    }
824

825
    auto* m =
10✔
826
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
10!
827
    if (!m)
10!
UNCOV
828
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
829
    simulation::ufs_mesh = m;
10✔
830

831
    // Turn on uniform fission source weighting
832
    ufs_on = true;
10✔
833

834
  } else if (check_for_node(root, "uniform_fs")) {
5,278!
UNCOV
835
    fatal_error(
×
836
      "Specifying a UFS mesh via the <uniform_fs> element "
837
      "is deprecated. Please create a mesh using <mesh> and then reference "
838
      "it by specifying its ID in a <ufs_mesh> element.");
839
  }
840

841
  // Check if the user has specified to write state points
842
  if (check_for_node(root, "state_point")) {
5,288✔
843

844
    // Get pointer to state_point node
845
    auto node_sp = root.child("state_point");
105✔
846

847
    // Determine number of batches at which to store state points
848
    if (check_for_node(node_sp, "batches")) {
105!
849
      // User gave specific batches to write state points
850
      auto temp = get_node_array<int>(node_sp, "batches");
105✔
851
      for (const auto& b : temp) {
322✔
852
        statepoint_batch.insert(b);
217✔
853
      }
854
    } else {
105✔
855
      // If neither were specified, write state point at last batch
UNCOV
856
      statepoint_batch.insert(n_batches);
×
857
    }
858
  } else {
859
    // If no <state_point> tag was present, by default write state point at
860
    // last batch only
861
    statepoint_batch.insert(n_batches);
5,183✔
862
  }
863

864
  // Check if the user has specified to write source points
865
  if (check_for_node(root, "source_point")) {
5,288✔
866
    // Get source_point node
867
    xml_node node_sp = root.child("source_point");
67✔
868

869
    // Determine batches at which to store source points
870
    if (check_for_node(node_sp, "batches")) {
67✔
871
      // User gave specific batches to write source points
872
      auto temp = get_node_array<int>(node_sp, "batches");
30✔
873
      for (const auto& b : temp) {
80✔
874
        sourcepoint_batch.insert(b);
50✔
875
      }
876
    } else {
30✔
877
      // If neither were specified, write source points with state points
878
      sourcepoint_batch = statepoint_batch;
37!
879
    }
880

881
    // Check if the user has specified to write binary source file
882
    if (check_for_node(node_sp, "separate")) {
67✔
883
      source_separate = get_node_value_bool(node_sp, "separate");
47✔
884
    }
885
    if (check_for_node(node_sp, "write")) {
67!
UNCOV
886
      source_write = get_node_value_bool(node_sp, "write");
×
887
    }
888
    if (check_for_node(node_sp, "mcpl")) {
67✔
889
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
17✔
890
    }
891
    if (check_for_node(node_sp, "overwrite_latest")) {
67✔
892
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
10✔
893
      source_separate = source_latest;
10✔
894
    }
895
  } else {
896
    // If no <source_point> tag was present, by default we keep source bank in
897
    // statepoint file and write it out at statepoints intervals
898
    source_separate = false;
5,221✔
899
    sourcepoint_batch = statepoint_batch;
5,221!
900
  }
901

902
  // Check is the user specified to convert strength to statistical weight
903
  if (check_for_node(root, "uniform_source_sampling")) {
5,288✔
904
    uniform_source_sampling =
35✔
905
      get_node_value_bool(root, "uniform_source_sampling");
35✔
906
  }
907

908
  // Check if the user has specified to write surface source
909
  if (check_for_node(root, "surf_source_write")) {
5,288✔
910
    surf_source_write = true;
263✔
911
    // Get surface source write node
912
    xml_node node_ssw = root.child("surf_source_write");
263✔
913

914
    // Determine surface ids at which crossing particles are to be banked.
915
    // If no surfaces are specified, all surfaces in the model will be used
916
    // to bank source points.
917
    if (check_for_node(node_ssw, "surface_ids")) {
263✔
918
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
133✔
919
      for (const auto& b : temp) {
665✔
920
        source_write_surf_id.insert(b);
532✔
921
      }
922
    }
133✔
923

924
    // Get maximum number of particles to be banked per surface
925
    if (check_for_node(node_ssw, "max_particles")) {
263✔
926
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
516✔
927
    } else {
928
      fatal_error("A maximum number of particles needs to be specified "
5✔
929
                  "using the 'max_particles' parameter to store surface "
930
                  "source points.");
931
    }
932

933
    // Get maximum number of surface source files to be created
934
    if (check_for_node(node_ssw, "max_source_files")) {
258✔
935
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
42✔
936
    } else {
937
      ssw_max_files = 1;
237✔
938
    }
939

940
    if (check_for_node(node_ssw, "mcpl")) {
258✔
941
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
7✔
942
    }
943
    // Get cell information
944
    if (check_for_node(node_ssw, "cell")) {
258✔
945
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
128✔
946
      ssw_cell_type = SSWCellType::Both;
64✔
947
    }
948
    if (check_for_node(node_ssw, "cellfrom")) {
258✔
949
      if (ssw_cell_id != C_NONE) {
57✔
950
        fatal_error(
10✔
951
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
952
      }
953
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
94✔
954
      ssw_cell_type = SSWCellType::From;
47✔
955
    }
956
    if (check_for_node(node_ssw, "cellto")) {
248✔
957
      if (ssw_cell_id != C_NONE) {
45✔
958
        fatal_error(
10✔
959
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
960
      }
961
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
70✔
962
      ssw_cell_type = SSWCellType::To;
35✔
963
    }
964
  }
965

966
  // Check if the user has specified to write specific collisions
967
  if (check_for_node(root, "collision_track")) {
5,263✔
968
    settings::collision_track = true;
98✔
969
    // Get collision track node
970
    xml_node node_ct = root.child("collision_track");
98✔
971
    collision_track_config = CollisionTrackConfig {};
98✔
972

973
    // Determine cell ids at which crossing particles are to be banked
974
    if (check_for_node(node_ct, "cell_ids")) {
98✔
975
      auto temp = get_node_array<int>(node_ct, "cell_ids");
51✔
976
      for (const auto& b : temp) {
133✔
977
        collision_track_config.cell_ids.insert(b);
82✔
978
      }
979
    }
51✔
980
    if (check_for_node(node_ct, "reactions")) {
98✔
981
      auto temp = get_node_array<std::string>(node_ct, "reactions");
41✔
982
      for (const auto& b : temp) {
112✔
983
        int reaction_int = reaction_mt(b);
71✔
984
        if (reaction_int > 0) {
71!
985
          collision_track_config.mt_numbers.insert(reaction_int);
71✔
986
        }
987
      }
988
    }
41✔
989
    if (check_for_node(node_ct, "universe_ids")) {
98✔
990
      auto temp = get_node_array<int>(node_ct, "universe_ids");
20✔
991
      for (const auto& b : temp) {
40✔
992
        collision_track_config.universe_ids.insert(b);
20✔
993
      }
994
    }
20✔
995
    if (check_for_node(node_ct, "material_ids")) {
98✔
996
      auto temp = get_node_array<int>(node_ct, "material_ids");
20✔
997
      for (const auto& b : temp) {
50✔
998
        collision_track_config.material_ids.insert(b);
30✔
999
      }
1000
    }
20✔
1001
    if (check_for_node(node_ct, "nuclides")) {
98✔
1002
      auto temp = get_node_array<std::string>(node_ct, "nuclides");
20✔
1003
      for (const auto& b : temp) {
80✔
1004
        collision_track_config.nuclides.insert(b);
60✔
1005
      }
1006
    }
20✔
1007
    if (check_for_node(node_ct, "deposited_E_threshold")) {
98✔
1008
      collision_track_config.deposited_energy_threshold =
40✔
1009
        std::stod(get_node_value(node_ct, "deposited_E_threshold"));
40✔
1010
    }
1011
    // Get maximum number of particles to be banked per collision
1012
    if (check_for_node(node_ct, "max_collisions")) {
98!
1013
      collision_track_config.max_collisions =
196✔
1014
        std::stoll(get_node_value(node_ct, "max_collisions"));
196✔
1015
    } else {
UNCOV
1016
      warning("A maximum number of collisions needs to be specified. "
×
1017
              "By default the code sets 'max_collisions' parameter equals to "
1018
              "1000.");
1019
    }
1020
    // Get maximum number of collision_track files to be created
1021
    if (check_for_node(node_ct, "max_collision_track_files")) {
98!
UNCOV
1022
      collision_track_config.max_files =
×
UNCOV
1023
        std::stoll(get_node_value(node_ct, "max_collision_track_files"));
×
1024
    }
1025
    if (check_for_node(node_ct, "mcpl")) {
98✔
1026
      collision_track_config.mcpl_write = get_node_value_bool(node_ct, "mcpl");
14✔
1027
    }
1028
  }
1029

1030
  // If source is not separate and is to be written out in the statepoint
1031
  // file, make sure that the sourcepoint batch numbers are contained in the
1032
  // statepoint list
1033
  if (!source_separate) {
5,263✔
1034
    for (const auto& b : sourcepoint_batch) {
10,494✔
1035
      if (!contains(statepoint_batch, b)) {
10,576!
UNCOV
1036
        fatal_error(
×
1037
          "Sourcepoint batches are not a subset of statepoint batches.");
1038
      }
1039
    }
1040
  }
1041

1042
  // Check if the user has specified to not reduce tallies at the end of every
1043
  // batch
1044
  if (check_for_node(root, "no_reduce")) {
5,263✔
1045
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
20✔
1046
  }
1047

1048
  // Check if the user has specified to use confidence intervals for
1049
  // uncertainties rather than standard deviations
1050
  if (check_for_node(root, "confidence_intervals")) {
5,263✔
1051
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
10✔
1052
  }
1053

1054
  // Check for output options
1055
  if (check_for_node(root, "output")) {
5,263✔
1056
    // Get pointer to output node
1057
    pugi::xml_node node_output = root.child("output");
491✔
1058

1059
    // Check for summary option
1060
    if (check_for_node(node_output, "summary")) {
491✔
1061
      output_summary = get_node_value_bool(node_output, "summary");
474✔
1062
    }
1063

1064
    // Check for ASCII tallies output option
1065
    if (check_for_node(node_output, "tallies")) {
491✔
1066
      output_tallies = get_node_value_bool(node_output, "tallies");
220✔
1067
    }
1068

1069
    // Set output directory if a path has been specified
1070
    if (check_for_node(node_output, "path")) {
491!
UNCOV
1071
      path_output = get_node_value(node_output, "path");
×
UNCOV
1072
      if (!ends_with(path_output, "/")) {
×
1073
        path_output += "/";
491!
1074
      }
1075
    }
1076
  }
1077

1078
  // Resonance scattering parameters
1079
  if (check_for_node(root, "resonance_scattering")) {
5,263✔
1080
    xml_node node_res_scat = root.child("resonance_scattering");
10✔
1081

1082
    // See if resonance scattering is enabled
1083
    if (check_for_node(node_res_scat, "enable")) {
10!
1084
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
10✔
1085
    } else {
UNCOV
1086
      res_scat_on = true;
×
1087
    }
1088

1089
    // Determine what method is used
1090
    if (check_for_node(node_res_scat, "method")) {
10!
1091
      auto temp = get_node_value(node_res_scat, "method", true, true);
10✔
1092
      if (temp == "rvs") {
10!
1093
        res_scat_method = ResScatMethod::rvs;
10✔
UNCOV
1094
      } else if (temp == "dbrc") {
×
UNCOV
1095
        res_scat_method = ResScatMethod::dbrc;
×
1096
      } else {
UNCOV
1097
        fatal_error(
×
UNCOV
1098
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1099
      }
1100
    }
10✔
1101

1102
    // Minimum energy for resonance scattering
1103
    if (check_for_node(node_res_scat, "energy_min")) {
10!
1104
      res_scat_energy_min =
20✔
1105
        std::stod(get_node_value(node_res_scat, "energy_min"));
20✔
1106
    }
1107
    if (res_scat_energy_min < 0.0) {
10!
UNCOV
1108
      fatal_error("Lower resonance scattering energy bound is negative");
×
1109
    }
1110

1111
    // Maximum energy for resonance scattering
1112
    if (check_for_node(node_res_scat, "energy_max")) {
10!
1113
      res_scat_energy_max =
20✔
1114
        std::stod(get_node_value(node_res_scat, "energy_max"));
20✔
1115
    }
1116
    if (res_scat_energy_max < res_scat_energy_min) {
10!
UNCOV
1117
      fatal_error("Upper resonance scattering energy bound is below the "
×
1118
                  "lower resonance scattering energy bound.");
1119
    }
1120

1121
    // Get resonance scattering nuclides
1122
    if (check_for_node(node_res_scat, "nuclides")) {
10!
1123
      res_scat_nuclides =
10✔
1124
        get_node_array<std::string>(node_res_scat, "nuclides");
20✔
1125
    }
1126
  }
1127

1128
  // Get volume calculations
1129
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
5,454✔
1130
    model::volume_calcs.emplace_back(node_vol);
191✔
1131
  }
1132

1133
  // Get temperature settings
1134
  if (check_for_node(root, "temperature_default")) {
5,263✔
1135
    temperature_default =
216✔
1136
      std::stod(get_node_value(root, "temperature_default"));
216✔
1137
  }
1138
  if (check_for_node(root, "temperature_method")) {
5,263✔
1139
    auto temp = get_node_value(root, "temperature_method", true, true);
315✔
1140
    if (temp == "nearest") {
315✔
1141
      temperature_method = TemperatureMethod::NEAREST;
198✔
1142
    } else if (temp == "interpolation") {
117!
1143
      temperature_method = TemperatureMethod::INTERPOLATION;
117✔
1144
    } else {
UNCOV
1145
      fatal_error("Unknown temperature method: " + temp);
×
1146
    }
1147
  }
315✔
1148
  if (check_for_node(root, "temperature_tolerance")) {
5,263✔
1149
    temperature_tolerance =
436✔
1150
      std::stod(get_node_value(root, "temperature_tolerance"));
436✔
1151
  }
1152
  if (check_for_node(root, "temperature_multipole")) {
5,263✔
1153
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
120✔
1154

1155
    // Multipole currently doesn't work with photon transport
1156
    if (temperature_multipole && photon_transport) {
120!
UNCOV
1157
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1158
                  "photon transport.");
1159
    }
1160
  }
1161
  if (check_for_node(root, "temperature_range")) {
5,263✔
1162
    auto range = get_node_array<double>(root, "temperature_range");
110✔
1163
    temperature_range[0] = range.at(0);
110✔
1164
    temperature_range[1] = range.at(1);
110✔
1165
  }
110✔
1166

1167
  // Check for tabular_legendre options
1168
  if (check_for_node(root, "tabular_legendre")) {
5,263✔
1169
    // Get pointer to tabular_legendre node
1170
    xml_node node_tab_leg = root.child("tabular_legendre");
60✔
1171

1172
    // Check for enable option
1173
    if (check_for_node(node_tab_leg, "enable")) {
60!
1174
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
60✔
1175
    }
1176

1177
    // Check for the number of points
1178
    if (check_for_node(node_tab_leg, "num_points")) {
60!
UNCOV
1179
      legendre_to_tabular_points =
×
UNCOV
1180
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
UNCOV
1181
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
UNCOV
1182
        fatal_error(
×
1183
          "The 'num_points' subelement/attribute of the "
1184
          "<tabular_legendre> element must contain a value greater than 1");
1185
      }
1186
    }
1187
  }
1188

1189
  // Check whether create delayed neutrons in fission
1190
  if (check_for_node(root, "create_delayed_neutrons")) {
5,263!
UNCOV
1191
    create_delayed_neutrons =
×
UNCOV
1192
      get_node_value_bool(root, "create_delayed_neutrons");
×
1193
  }
1194

1195
  // Check whether create fission sites
1196
  if (run_mode == RunMode::FIXED_SOURCE) {
5,263✔
1197
    if (check_for_node(root, "create_fission_neutrons")) {
1,806✔
1198
      create_fission_neutrons =
178✔
1199
        get_node_value_bool(root, "create_fission_neutrons");
178✔
1200
    }
1201
  }
1202

1203
  // Check whether to scale fission photon yields
1204
  if (check_for_node(root, "delayed_photon_scaling")) {
5,263!
UNCOV
1205
    delayed_photon_scaling =
×
UNCOV
1206
      get_node_value_bool(root, "delayed_photon_scaling");
×
1207
  }
1208

1209
  // Check whether to use event-based parallelism
1210
  if (check_for_node(root, "event_based")) {
5,263!
UNCOV
1211
    event_based = get_node_value_bool(root, "event_based");
×
1212
  }
1213

1214
  // Check whether material cell offsets should be generated
1215
  if (check_for_node(root, "material_cell_offsets")) {
5,263!
UNCOV
1216
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1217
  }
1218

1219
  // Weight window information
1220
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
5,330✔
1221
    variance_reduction::weight_windows.emplace_back(
67✔
1222
      std::make_unique<WeightWindows>(node_ww));
134✔
1223
  }
1224

1225
  // Enable weight windows by default if one or more are present
1226
  if (variance_reduction::weight_windows.size() > 0)
5,263✔
1227
    settings::weight_windows_on = true;
50✔
1228

1229
  // read weight windows from file
1230
  if (check_for_node(root, "weight_windows_file")) {
5,263!
UNCOV
1231
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1232
  }
1233

1234
  // read settings for weight windows value, this will override
1235
  // the automatic setting even if weight windows are present
1236
  if (check_for_node(root, "weight_windows_on")) {
5,263✔
1237
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
23✔
1238
  }
1239

1240
  if (check_for_node(root, "max_secondaries")) {
5,263!
UNCOV
1241
    settings::max_secondaries =
×
UNCOV
1242
      std::stoi(get_node_value(root, "max_secondaries"));
×
1243
  }
1244

1245
  if (check_for_node(root, "max_history_splits")) {
5,263✔
1246
    settings::max_history_splits =
272✔
1247
      std::stoi(get_node_value(root, "max_history_splits"));
272✔
1248
  }
1249

1250
  if (check_for_node(root, "max_tracks")) {
5,263✔
1251
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
60✔
1252
  }
1253

1254
  // Create weight window generator objects
1255
  if (check_for_node(root, "weight_window_generators")) {
5,263✔
1256
    auto wwgs_node = root.child("weight_window_generators");
51✔
1257
    for (pugi::xml_node node_wwg :
102✔
1258
      wwgs_node.children("weight_windows_generator")) {
102✔
1259
      variance_reduction::weight_windows_generators.emplace_back(
51✔
1260
        std::make_unique<WeightWindowsGenerator>(node_wwg));
102✔
1261
    }
1262
    // if any of the weight windows are intended to be generated otf, make
1263
    // sure they're applied
1264
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
51!
1265
      if (wwg->on_the_fly_) {
51!
1266
        settings::weight_windows_on = true;
51✔
1267
        break;
51✔
1268
      }
1269
    }
1270
  }
1271

1272
  // Set up weight window checkpoints
1273
  if (check_for_node(root, "weight_window_checkpoints")) {
5,263✔
1274
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
20✔
1275
    if (check_for_node(ww_checkpoints, "collision")) {
20!
1276
      weight_window_checkpoint_collision =
20✔
1277
        get_node_value_bool(ww_checkpoints, "collision");
20✔
1278
    }
1279
    if (check_for_node(ww_checkpoints, "surface")) {
20!
1280
      weight_window_checkpoint_surface =
20✔
1281
        get_node_value_bool(ww_checkpoints, "surface");
20✔
1282
    }
1283
  }
1284

1285
  if (weight_windows_on) {
5,263✔
1286
    if (!weight_window_checkpoint_surface &&
101✔
1287
        !weight_window_checkpoint_collision)
81!
UNCOV
1288
      fatal_error(
×
1289
        "Weight Windows are enabled but there are no valid checkpoints.");
1290
  }
1291

1292
  if (check_for_node(root, "use_decay_photons")) {
5,263✔
1293
    settings::use_decay_photons =
7✔
1294
      get_node_value_bool(root, "use_decay_photons");
7✔
1295
  }
1296
}
5,263✔
1297

1298
void free_memory_settings()
5,358✔
1299
{
1300
  settings::statepoint_batch.clear();
5,358✔
1301
  settings::sourcepoint_batch.clear();
5,358✔
1302
  settings::source_write_surf_id.clear();
5,358✔
1303
  settings::res_scat_nuclides.clear();
5,358✔
1304
}
5,358✔
1305

1306
//==============================================================================
1307
// C API functions
1308
//==============================================================================
1309

1310
extern "C" int openmc_set_n_batches(
28✔
1311
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1312
{
1313
  if (settings::n_inactive >= n_batches) {
28✔
1314
    set_errmsg("Number of active batches must be greater than zero.");
7✔
1315
    return OPENMC_E_INVALID_ARGUMENT;
7✔
1316
  }
1317

1318
  if (!settings::trigger_on) {
21✔
1319
    // Set n_batches and n_max_batches to same value
1320
    settings::n_batches = n_batches;
7✔
1321
    settings::n_max_batches = n_batches;
7✔
1322
  } else {
1323
    // Set n_batches and n_max_batches based on value of set_max_batches
1324
    if (set_max_batches) {
14✔
1325
      settings::n_max_batches = n_batches;
7✔
1326
    } else {
1327
      settings::n_batches = n_batches;
7✔
1328
    }
1329
  }
1330

1331
  // Update size of k_generation and entropy
1332
  int m = settings::n_max_batches * settings::gen_per_batch;
21✔
1333
  simulation::k_generation.reserve(m);
21✔
1334
  simulation::entropy.reserve(m);
21✔
1335

1336
  // Add value of n_batches to statepoint_batch
1337
  if (add_statepoint_batch &&
21✔
1338
      !(contains(settings::statepoint_batch, n_batches)))
14!
1339
    settings::statepoint_batch.insert(n_batches);
14✔
1340

1341
  return 0;
1342
}
1343

1344
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
1,610✔
1345
{
1346
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
1,610✔
1347

1348
  return 0;
1,610✔
1349
}
1350

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