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

openmc-dev / openmc / 21899763772

11 Feb 2026 09:34AM UTC coverage: 81.695% (-0.2%) from 81.905%
21899763772

Pull #3795

github

web-flow
Merge ee5b4c070 into 3f20a5e22
Pull Request #3795: Source activity

16830 of 23342 branches covered (72.1%)

Branch coverage included in aggregate %.

27 of 59 new or added lines in 3 files covered. (45.76%)

308 existing lines in 25 files now uncovered.

55334 of 64991 relevant lines covered (85.14%)

44935365.75 hits per line

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

76.16
/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 reduce_tallies {true};
66
bool res_scat_on {false};
67
bool restart_run {false};
68
bool run_CE {true};
69
bool source_latest {false};
70
bool source_separate {false};
71
bool source_write {true};
72
bool source_mcpl_write {false};
73
bool surf_source_write {false};
74
bool surf_mcpl_write {false};
75
bool surf_source_read {false};
76
bool survival_biasing {false};
77
bool survival_normalization {false};
78
bool temperature_multipole {false};
79
bool trigger_on {false};
80
bool trigger_predict {false};
81
bool uniform_source_sampling {false};
82
bool ufs_on {false};
83
bool urr_ptables_on {true};
84
bool use_decay_photons {false};
85
bool weight_windows_on {false};
86
bool weight_window_checkpoint_surface {false};
87
bool weight_window_checkpoint_collision {true};
88
bool write_all_tracks {false};
89
bool write_initial_source {false};
90
bool activity_based_timing {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
TemperatureMethod temperature_method {TemperatureMethod::NEAREST};
141
double temperature_tolerance {10.0};
142
double temperature_default {293.6};
143
array<double, 2> temperature_range {0.0, 0.0};
144
int trace_batch;
145
int trace_gen;
146
int64_t trace_particle;
147
vector<array<int, 3>> track_identifiers;
148
int trigger_batch_interval {1};
149
int verbosity {-1};
150
double weight_cutoff {0.25};
151
double weight_survive {1.0};
152

153
} // namespace settings
154

155
//==============================================================================
156
// Functions
157
//==============================================================================
158

159
void get_run_parameters(pugi::xml_node node_base)
6,624✔
160
{
161
  using namespace settings;
162
  using namespace pugi;
163

164
  // Check number of particles
165
  if (!check_for_node(node_base, "particles")) {
6,624!
166
    fatal_error("Need to specify number of particles.");
×
167
  }
168

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

174
  // Get maximum number of in flight particles for event-based mode
175
  if (check_for_node(node_base, "max_particles_in_flight")) {
6,624!
176
    max_particles_in_flight =
×
177
      std::stoll(get_node_value(node_base, "max_particles_in_flight"));
×
178
  }
179

180
  // Get maximum number of events allowed per particle
181
  if (check_for_node(node_base, "max_particle_events")) {
6,624!
182
    max_particle_events =
×
183
      std::stoll(get_node_value(node_base, "max_particle_events"));
×
184
  }
185

186
  // Get number of basic batches
187
  if (check_for_node(node_base, "batches")) {
6,624!
188
    n_batches = std::stoi(get_node_value(node_base, "batches"));
6,624✔
189
  }
190
  if (!trigger_on)
6,624✔
191
    n_max_batches = n_batches;
6,494✔
192

193
  // Get max number of lost particles
194
  if (check_for_node(node_base, "max_lost_particles")) {
6,624✔
195
    max_lost_particles =
42✔
196
      std::stoi(get_node_value(node_base, "max_lost_particles"));
42✔
197
  }
198

199
  // Get relative number of lost particles
200
  if (check_for_node(node_base, "rel_max_lost_particles")) {
6,624!
201
    rel_max_lost_particles =
×
202
      std::stod(get_node_value(node_base, "rel_max_lost_particles"));
×
203
  }
204

205
  // Get relative number of lost particles
206
  if (check_for_node(node_base, "max_write_lost_particles")) {
6,624✔
207
    max_write_lost_particles =
14✔
208
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
14✔
209
  }
210

211
  // Get number of inactive batches
212
  if (run_mode == RunMode::EIGENVALUE ||
6,624✔
213
      solver_type == SolverType::RANDOM_RAY) {
2,498✔
214
    if (check_for_node(node_base, "inactive")) {
4,490✔
215
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,322✔
216
    }
217
    if (check_for_node(node_base, "generations_per_batch")) {
4,490✔
218
      gen_per_batch =
14✔
219
        std::stoi(get_node_value(node_base, "generations_per_batch"));
14✔
220
    }
221

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

227
    // Get the trigger information for keff
228
    if (check_for_node(node_base, "keff_trigger")) {
4,490✔
229
      xml_node node_keff_trigger = node_base.child("keff_trigger");
94✔
230

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

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

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

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

389
  // Parse settings.xml file
390
  xml_document doc;
1,208✔
391
  auto result = doc.load_file(filename.c_str());
1,208✔
392
  if (!result) {
1,208!
393
    fatal_error("Error processing settings.xml file.");
×
394
  }
395

396
  // Get root element
397
  xml_node root = doc.document_element();
1,208✔
398

399
  // Verbosity
400
  if (check_for_node(root, "verbosity") && verbosity == -1) {
1,208!
401
    verbosity = std::stoi(get_node_value(root, "verbosity"));
164✔
402
  } else if (verbosity == -1) {
1,044!
403
    verbosity = 7;
1,044✔
404
  }
405

406
  // To this point, we haven't displayed any output since we didn't know what
407
  // the verbosity is. Now that we checked for it, show the title if necessary
408
  if (mpi::master) {
1,208✔
409
    if (verbosity >= 2)
1,028✔
410
      title();
872✔
411
  }
412

413
  write_message("Reading settings XML file...", 5);
1,208✔
414

415
  read_settings_xml(root);
1,208✔
416
}
1,220✔
417

418
void read_settings_xml(pugi::xml_node root)
7,354✔
419
{
420
  using namespace settings;
421
  using namespace pugi;
422

423
  // Find if a multi-group or continuous-energy simulation is desired
424
  if (check_for_node(root, "energy_mode")) {
7,354✔
425
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
1,184✔
426
    if (temp_str == "mg" || temp_str == "multi-group") {
1,184!
427
      run_CE = false;
1,184✔
428
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
429
      run_CE = true;
×
430
    }
431
  }
1,184✔
432

433
  // Check for user meshes and allocate
434
  read_meshes(root);
7,354✔
435

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

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

460
  // Check for a trigger node and get trigger information
461
  if (check_for_node(root, "trigger")) {
7,354✔
462
    xml_node node_trigger = root.child("trigger");
144✔
463

464
    // Check if trigger(s) are to be turned on
465
    trigger_on = get_node_value_bool(node_trigger, "active");
144✔
466

467
    if (trigger_on) {
144✔
468
      if (check_for_node(node_trigger, "max_batches")) {
130!
469
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
130✔
470
      } else {
471
        fatal_error("<max_batches> must be specified with triggers");
×
472
      }
473

474
      // Get the batch interval to check triggers
475
      if (!check_for_node(node_trigger, "batch_interval")) {
130✔
476
        trigger_predict = true;
14✔
477
      } else {
478
        trigger_batch_interval =
116✔
479
          std::stoi(get_node_value(node_trigger, "batch_interval"));
116✔
480
        if (trigger_batch_interval <= 0) {
116!
481
          fatal_error("Trigger batch interval must be greater than zero");
×
482
        }
483
      }
484
    }
485
  }
486

487
  // Check run mode if it hasn't been set from the command line
488
  xml_node node_mode;
7,354✔
489
  if (run_mode == RunMode::UNSET) {
7,354✔
490
    if (check_for_node(root, "run_mode")) {
6,652✔
491
      std::string temp_str = get_node_value(root, "run_mode", true, true);
6,624✔
492
      if (temp_str == "eigenvalue") {
6,624✔
493
        run_mode = RunMode::EIGENVALUE;
4,098✔
494
      } else if (temp_str == "fixed source") {
2,526✔
495
        run_mode = RunMode::FIXED_SOURCE;
2,498✔
496
      } else if (temp_str == "plot") {
28!
497
        run_mode = RunMode::PLOTTING;
×
498
      } else if (temp_str == "particle restart") {
28!
499
        run_mode = RunMode::PARTICLE;
×
500
      } else if (temp_str == "volume") {
28!
501
        run_mode = RunMode::VOLUME;
28✔
502
      } else {
503
        fatal_error("Unrecognized run mode: " + temp_str);
×
504
      }
505

506
      // Assume XML specifies <particles>, <batches>, etc. directly
507
      node_mode = root;
6,624✔
508
    } else {
6,624✔
509
      warning("<run_mode> should be specified.");
28✔
510

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

526
  // Check solver type
527
  if (check_for_node(root, "random_ray")) {
7,354✔
528
    solver_type = SolverType::RANDOM_RAY;
696✔
529
    if (run_CE)
696!
530
      fatal_error("multi-group energy mode must be specified in settings XML "
×
531
                  "when using the random ray solver.");
532
  }
533

534
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
7,354✔
535
    // Read run parameters
536
    get_run_parameters(node_mode);
6,624✔
537

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

552
    // Check for user value for the number of generation of the Iterated Fission
553
    // Probability (IFP) method
554
    if (check_for_node(root, "ifp_n_generation")) {
6,624✔
555
      ifp_n_generation = std::stoi(get_node_value(root, "ifp_n_generation"));
76✔
556
      if (ifp_n_generation <= 0) {
76!
557
        fatal_error("'ifp_n_generation' must be greater than 0.");
×
558
      }
559
      // Avoid tallying 0 if IFP logs are not complete when active cycles start
560
      if (ifp_n_generation > n_inactive) {
76✔
561
        fatal_error("'ifp_n_generation' must be lower than or equal to the "
8✔
562
                    "number of inactive cycles.");
563
      }
564
    }
565
  }
566

567
  // Copy plotting random number seed if specified
568
  if (check_for_node(root, "plot_seed")) {
7,346!
569
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
570
    model::plotter_seed = seed;
×
571
  }
572

573
  // Copy random number seed if specified
574
  if (check_for_node(root, "seed")) {
7,346✔
575
    auto seed = std::stoll(get_node_value(root, "seed"));
518✔
576
    openmc_set_seed(seed);
518✔
577
  }
578

579
  // Copy random number stride if specified
580
  if (check_for_node(root, "stride")) {
7,346✔
581
    auto stride = std::stoull(get_node_value(root, "stride"));
14✔
582
    openmc_set_stride(stride);
14✔
583
  }
584

585
  // Check for electron treatment
586
  if (check_for_node(root, "electron_treatment")) {
7,346✔
587
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
62✔
588
    if (temp_str == "led") {
62✔
589
      electron_treatment = ElectronTreatment::LED;
10✔
590
    } else if (temp_str == "ttb") {
52!
591
      electron_treatment = ElectronTreatment::TTB;
52✔
592
    } else {
593
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
594
    }
595
  }
62✔
596

597
  // Check for photon transport
598
  if (check_for_node(root, "photon_transport")) {
7,346✔
599
    photon_transport = get_node_value_bool(root, "photon_transport");
176✔
600

601
    if (!run_CE && photon_transport) {
176!
602
      fatal_error("Photon transport is not currently supported in "
×
603
                  "multigroup mode");
604
    }
605
  }
606

607
  // Number of bins for logarithmic grid
608
  if (check_for_node(root, "log_grid_bins")) {
7,346✔
609
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
14✔
610
    if (n_log_bins < 1) {
14!
611
      fatal_error("Number of bins for logarithmic grid must be greater "
×
612
                  "than zero.");
613
    }
614
  }
615

616
  // Number of OpenMP threads
617
  if (check_for_node(root, "threads")) {
7,346!
618
    if (mpi::master)
×
619
      warning("The <threads> element has been deprecated. Use "
×
620
              "the OMP_NUM_THREADS environment variable to set the number of "
621
              "threads.");
622
  }
623

624
  // ==========================================================================
625
  // EXTERNAL SOURCE
626

627
  // Get point to list of <source> elements and make sure there is at least one
628
  for (pugi::xml_node node : root.children("source")) {
14,256✔
629
    model::external_sources.push_back(Source::create(node));
6,918✔
630
  }
631

632
  // Check if the user has specified to read surface source
633
  if (check_for_node(root, "surf_source_read")) {
7,338✔
634
    surf_source_read = true;
28✔
635
    // Get surface source read node
636
    xml_node node_ssr = root.child("surf_source_read");
28✔
637

638
    std::string path = "surface_source.h5";
28✔
639
    // Check if the user has specified different file for surface source reading
640
    if (check_for_node(node_ssr, "path")) {
28!
641
      path = get_node_value(node_ssr, "path", false, true);
28✔
642
    }
643
    model::external_sources.push_back(make_unique<FileSource>(path));
28✔
644
  }
28✔
645

646
  // If no source specified, default to isotropic point source at origin with
647
  // Watt spectrum. No default source is needed in random ray mode.
648
  if (model::external_sources.empty() &&
9,306✔
649
      settings::solver_type != SolverType::RANDOM_RAY) {
1,968✔
650
    double T[] {0.0};
1,832✔
651
    double p[] {1.0};
1,832✔
652
    model::external_sources.push_back(make_unique<IndependentSource>(
1,832✔
653
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
3,664✔
654
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
3,664✔
655
      UPtrDist {new Discrete(T, p, 1)}));
3,664✔
656
  }
657

658
  // Build probability mass function for sampling external sources
659
  vector<double> source_strengths;
7,338✔
660
  for (auto& s : model::external_sources) {
16,108✔
661
    source_strengths.push_back(s->strength());
8,770✔
662
  }
663
  model::external_sources_probability.assign(source_strengths);
7,338✔
664

665
  // Check if we want to write out source
666
  if (check_for_node(root, "write_initial_source")) {
7,338!
667
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
668
  }
669

670
  // Get relative number of lost particles
671
  if (check_for_node(root, "source_rejection_fraction")) {
7,338✔
672
    source_rejection_fraction =
6✔
673
      std::stod(get_node_value(root, "source_rejection_fraction"));
6!
674
  }
675

676
  if (check_for_node(root, "free_gas_threshold")) {
7,338!
677
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
678
  }
679

680
  // Survival biasing
681
  if (check_for_node(root, "survival_biasing")) {
7,338✔
682
    survival_biasing = get_node_value_bool(root, "survival_biasing");
158✔
683
  }
684

685
  // Probability tables
686
  if (check_for_node(root, "ptables")) {
7,338✔
687
    urr_ptables_on = get_node_value_bool(root, "ptables");
14✔
688
  }
689

690
  // Cutoffs
691
  if (check_for_node(root, "cutoff")) {
7,338✔
692
    xml_node node_cutoff = root.child("cutoff");
128✔
693
    if (check_for_node(node_cutoff, "weight")) {
128✔
694
      weight_cutoff = std::stod(get_node_value(node_cutoff, "weight"));
14✔
695
    }
696
    if (check_for_node(node_cutoff, "weight_avg")) {
128✔
697
      weight_survive = std::stod(get_node_value(node_cutoff, "weight_avg"));
14✔
698
    }
699
    if (check_for_node(node_cutoff, "survival_normalization")) {
128!
700
      survival_normalization =
×
701
        get_node_value_bool(node_cutoff, "survival_normalization");
×
702
    }
703
    if (check_for_node(node_cutoff, "energy_neutron")) {
128✔
704
      energy_cutoff[0] =
28✔
705
        std::stod(get_node_value(node_cutoff, "energy_neutron"));
14✔
706
    } else if (check_for_node(node_cutoff, "energy")) {
114!
707
      warning("The use of an <energy> cutoff is deprecated and should "
×
708
              "be replaced by <energy_neutron>.");
709
      energy_cutoff[0] = std::stod(get_node_value(node_cutoff, "energy"));
×
710
    }
711
    if (check_for_node(node_cutoff, "energy_photon")) {
128✔
712
      energy_cutoff[1] =
152✔
713
        std::stod(get_node_value(node_cutoff, "energy_photon"));
76✔
714
    }
715
    if (check_for_node(node_cutoff, "energy_electron")) {
128!
716
      energy_cutoff[2] =
×
717
        std::stof(get_node_value(node_cutoff, "energy_electron"));
×
718
    }
719
    if (check_for_node(node_cutoff, "energy_positron")) {
128!
720
      energy_cutoff[3] =
×
721
        std::stod(get_node_value(node_cutoff, "energy_positron"));
×
722
    }
723
    if (check_for_node(node_cutoff, "time_neutron")) {
128✔
724
      time_cutoff[0] = std::stod(get_node_value(node_cutoff, "time_neutron"));
24✔
725
    }
726
    if (check_for_node(node_cutoff, "time_photon")) {
128!
727
      time_cutoff[1] = std::stod(get_node_value(node_cutoff, "time_photon"));
×
728
    }
729
    if (check_for_node(node_cutoff, "time_electron")) {
128!
730
      time_cutoff[2] = std::stod(get_node_value(node_cutoff, "time_electron"));
×
731
    }
732
    if (check_for_node(node_cutoff, "time_positron")) {
128!
733
      time_cutoff[3] = std::stod(get_node_value(node_cutoff, "time_positron"));
×
734
    }
735
  }
736

737
  // Particle trace
738
  if (check_for_node(root, "trace")) {
7,338✔
739
    auto temp = get_node_array<int64_t>(root, "trace");
14✔
740
    if (temp.size() != 3) {
14!
741
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
742
                  "batch, generation, and particle number.");
743
    }
744
    trace_batch = temp.at(0);
14✔
745
    trace_gen = temp.at(1);
14✔
746
    trace_particle = temp.at(2);
14✔
747
  }
14✔
748

749
  // Particle tracks
750
  if (check_for_node(root, "track")) {
7,338✔
751
    // Get values and make sure there are three per particle
752
    auto temp = get_node_array<int>(root, "track");
42✔
753
    if (temp.size() % 3 != 0) {
42!
754
      fatal_error(
×
755
        "Number of integers specified in 'track' is not "
756
        "divisible by 3.  Please provide 3 integers per particle to be "
757
        "tracked.");
758
    }
759

760
    // Reshape into track_identifiers
761
    int n_tracks = temp.size() / 3;
42✔
762
    for (int i = 0; i < n_tracks; ++i) {
168✔
763
      track_identifiers.push_back(
126✔
764
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
126✔
765
    }
766
  }
42✔
767

768
  // Shannon entropy
769
  if (solver_type == SolverType::RANDOM_RAY) {
7,338✔
770
    if (check_for_node(root, "entropy_mesh")) {
696!
771
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
772
                  "No user-defined entropy mesh is supported.");
773
    }
774
    entropy_on = true;
696✔
775
  } else if (solver_type == SolverType::MONTE_CARLO) {
6,642!
776
    if (check_for_node(root, "entropy_mesh")) {
6,642✔
777
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
304✔
778
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
304!
779
        fatal_error(fmt::format(
×
780
          "Mesh {} specified for Shannon entropy does not exist.", temp));
781
      }
782

783
      auto* m = dynamic_cast<RegularMesh*>(
304!
784
        model::meshes[model::mesh_map.at(temp)].get());
304✔
785
      if (!m)
304!
786
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
787
      simulation::entropy_mesh = m;
304✔
788

789
      // Turn on Shannon entropy calculation
790
      entropy_on = true;
304✔
791

792
    } else if (check_for_node(root, "entropy")) {
6,338!
793
      fatal_error(
×
794
        "Specifying a Shannon entropy mesh via the <entropy> element "
795
        "is deprecated. Please create a mesh using <mesh> and then reference "
796
        "it by specifying its ID in an <entropy_mesh> element.");
797
    }
798
  }
799
  // Uniform fission source weighting mesh
800
  if (check_for_node(root, "ufs_mesh")) {
7,338✔
801
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
14✔
802
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
14!
803
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
804
                              "method does not exist.",
805
        temp));
806
    }
807

808
    auto* m =
809
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
14!
810
    if (!m)
14!
811
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
812
    simulation::ufs_mesh = m;
14✔
813

814
    // Turn on uniform fission source weighting
815
    ufs_on = true;
14✔
816

817
  } else if (check_for_node(root, "uniform_fs")) {
7,324!
818
    fatal_error(
×
819
      "Specifying a UFS mesh via the <uniform_fs> element "
820
      "is deprecated. Please create a mesh using <mesh> and then reference "
821
      "it by specifying its ID in a <ufs_mesh> element.");
822
  }
823

824
  // Check if the user has specified to write state points
825
  if (check_for_node(root, "state_point")) {
7,338✔
826

827
    // Get pointer to state_point node
828
    auto node_sp = root.child("state_point");
148✔
829

830
    // Determine number of batches at which to store state points
831
    if (check_for_node(node_sp, "batches")) {
148!
832
      // User gave specific batches to write state points
833
      auto temp = get_node_array<int>(node_sp, "batches");
148✔
834
      for (const auto& b : temp) {
454✔
835
        statepoint_batch.insert(b);
306✔
836
      }
837
    } else {
148✔
838
      // If neither were specified, write state point at last batch
839
      statepoint_batch.insert(n_batches);
×
840
    }
841
  } else {
842
    // If no <state_point> tag was present, by default write state point at
843
    // last batch only
844
    statepoint_batch.insert(n_batches);
7,190✔
845
  }
846

847
  // Check if the user has specified to write source points
848
  if (check_for_node(root, "source_point")) {
7,338✔
849
    // Get source_point node
850
    xml_node node_sp = root.child("source_point");
94✔
851

852
    // Determine batches at which to store source points
853
    if (check_for_node(node_sp, "batches")) {
94✔
854
      // User gave specific batches to write source points
855
      auto temp = get_node_array<int>(node_sp, "batches");
42✔
856
      for (const auto& b : temp) {
112✔
857
        sourcepoint_batch.insert(b);
70✔
858
      }
859
    } else {
42✔
860
      // If neither were specified, write source points with state points
861
      sourcepoint_batch = statepoint_batch;
52✔
862
    }
863

864
    // Check if the user has specified to write binary source file
865
    if (check_for_node(node_sp, "separate")) {
94✔
866
      source_separate = get_node_value_bool(node_sp, "separate");
66✔
867
    }
868
    if (check_for_node(node_sp, "write")) {
94!
869
      source_write = get_node_value_bool(node_sp, "write");
×
870
    }
871
    if (check_for_node(node_sp, "mcpl")) {
94✔
872
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
24✔
873
    }
874
    if (check_for_node(node_sp, "overwrite_latest")) {
94✔
875
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
14✔
876
      source_separate = source_latest;
14✔
877
    }
878
  } else {
879
    // If no <source_point> tag was present, by default we keep source bank in
880
    // statepoint file and write it out at statepoints intervals
881
    source_separate = false;
7,244✔
882
    sourcepoint_batch = statepoint_batch;
7,244✔
883
  }
884

885
  // Check is the user specified to convert strength to statistical weight
886
  if (check_for_node(root, "uniform_source_sampling")) {
7,338✔
887
    uniform_source_sampling =
50✔
888
      get_node_value_bool(root, "uniform_source_sampling");
50✔
889
  }
890

891
  // Check if the user wants activity-based timing (per-source Poisson
892
  // timestamps using strength as activity rate in Bq)
893
  if (check_for_node(root, "activity_based_timing")) {
7,338!
NEW
894
    activity_based_timing = get_node_value_bool(root, "activity_based_timing");
×
895
  }
896

897
  // Check if the user has specified to write surface source
898
  if (check_for_node(root, "surf_source_write")) {
7,338✔
899
    surf_source_write = true;
361✔
900
    // Get surface source write node
901
    xml_node node_ssw = root.child("surf_source_write");
361✔
902

903
    // Determine surface ids at which crossing particles are to be banked.
904
    // If no surfaces are specified, all surfaces in the model will be used
905
    // to bank source points.
906
    if (check_for_node(node_ssw, "surface_ids")) {
361✔
907
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
177✔
908
      for (const auto& b : temp) {
877✔
909
        source_write_surf_id.insert(b);
700✔
910
      }
911
    }
177✔
912

913
    // Get maximum number of particles to be banked per surface
914
    if (check_for_node(node_ssw, "max_particles")) {
361✔
915
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
353✔
916
    } else {
917
      fatal_error("A maximum number of particles needs to be specified "
8✔
918
                  "using the 'max_particles' parameter to store surface "
919
                  "source points.");
920
    }
921

922
    // Get maximum number of surface source files to be created
923
    if (check_for_node(node_ssw, "max_source_files")) {
353✔
924
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
30✔
925
    } else {
926
      ssw_max_files = 1;
323✔
927
    }
928

929
    if (check_for_node(node_ssw, "mcpl")) {
353✔
930
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
10✔
931
    }
932
    // Get cell information
933
    if (check_for_node(node_ssw, "cell")) {
353✔
934
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
90✔
935
      ssw_cell_type = SSWCellType::Both;
90✔
936
    }
937
    if (check_for_node(node_ssw, "cellfrom")) {
353✔
938
      if (ssw_cell_id != C_NONE) {
79✔
939
        fatal_error(
16✔
940
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
941
      }
942
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
63✔
943
      ssw_cell_type = SSWCellType::From;
63✔
944
    }
945
    if (check_for_node(node_ssw, "cellto")) {
337✔
946
      if (ssw_cell_id != C_NONE) {
62✔
947
        fatal_error(
16✔
948
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
949
      }
950
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
46✔
951
      ssw_cell_type = SSWCellType::To;
46✔
952
    }
953
  }
954

955
  // Check if the user has specified to write specific collisions
956
  if (check_for_node(root, "collision_track")) {
7,298✔
957
    settings::collision_track = true;
137✔
958
    // Get collision track node
959
    xml_node node_ct = root.child("collision_track");
137✔
960
    collision_track_config = CollisionTrackConfig {};
137✔
961

962
    // Determine cell ids at which crossing particles are to be banked
963
    if (check_for_node(node_ct, "cell_ids")) {
137✔
964
      auto temp = get_node_array<int>(node_ct, "cell_ids");
72✔
965
      for (const auto& b : temp) {
188✔
966
        collision_track_config.cell_ids.insert(b);
116✔
967
      }
968
    }
72✔
969
    if (check_for_node(node_ct, "reactions")) {
137✔
970
      auto temp = get_node_array<std::string>(node_ct, "reactions");
58✔
971
      for (const auto& b : temp) {
158✔
972
        int reaction_int = reaction_type(b);
100✔
973
        if (reaction_int > 0) {
100!
974
          collision_track_config.mt_numbers.insert(reaction_int);
100✔
975
        }
976
      }
977
    }
58✔
978
    if (check_for_node(node_ct, "universe_ids")) {
137✔
979
      auto temp = get_node_array<int>(node_ct, "universe_ids");
28✔
980
      for (const auto& b : temp) {
56✔
981
        collision_track_config.universe_ids.insert(b);
28✔
982
      }
983
    }
28✔
984
    if (check_for_node(node_ct, "material_ids")) {
137✔
985
      auto temp = get_node_array<int>(node_ct, "material_ids");
28✔
986
      for (const auto& b : temp) {
70✔
987
        collision_track_config.material_ids.insert(b);
42✔
988
      }
989
    }
28✔
990
    if (check_for_node(node_ct, "nuclides")) {
137✔
991
      auto temp = get_node_array<std::string>(node_ct, "nuclides");
28✔
992
      for (const auto& b : temp) {
112✔
993
        collision_track_config.nuclides.insert(b);
84✔
994
      }
995
    }
28✔
996
    if (check_for_node(node_ct, "deposited_E_threshold")) {
137✔
997
      collision_track_config.deposited_energy_threshold =
28✔
998
        std::stod(get_node_value(node_ct, "deposited_E_threshold"));
28✔
999
    }
1000
    // Get maximum number of particles to be banked per collision
1001
    if (check_for_node(node_ct, "max_collisions")) {
137!
1002
      collision_track_config.max_collisions =
137✔
1003
        std::stoll(get_node_value(node_ct, "max_collisions"));
137✔
1004
    } else {
1005
      warning("A maximum number of collisions needs to be specified. "
×
1006
              "By default the code sets 'max_collisions' parameter equals to "
1007
              "1000.");
1008
    }
1009
    // Get maximum number of collision_track files to be created
1010
    if (check_for_node(node_ct, "max_collision_track_files")) {
137!
1011
      collision_track_config.max_files =
×
1012
        std::stoll(get_node_value(node_ct, "max_collision_track_files"));
×
1013
    }
1014
    if (check_for_node(node_ct, "mcpl")) {
137✔
1015
      collision_track_config.mcpl_write = get_node_value_bool(node_ct, "mcpl");
20✔
1016
    }
1017
  }
1018

1019
  // If source is not separate and is to be written out in the statepoint
1020
  // file, make sure that the sourcepoint batch numbers are contained in the
1021
  // statepoint list
1022
  if (!source_separate) {
7,298✔
1023
    for (const auto& b : sourcepoint_batch) {
14,552✔
1024
      if (!contains(statepoint_batch, b)) {
7,334!
1025
        fatal_error(
×
1026
          "Sourcepoint batches are not a subset of statepoint batches.");
1027
      }
1028
    }
1029
  }
1030

1031
  // Check if the user has specified to not reduce tallies at the end of every
1032
  // batch
1033
  if (check_for_node(root, "no_reduce")) {
7,298✔
1034
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
28✔
1035
  }
1036

1037
  // Check if the user has specified to use confidence intervals for
1038
  // uncertainties rather than standard deviations
1039
  if (check_for_node(root, "confidence_intervals")) {
7,298✔
1040
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
14✔
1041
  }
1042

1043
  // Check for output options
1044
  if (check_for_node(root, "output")) {
7,298✔
1045
    // Get pointer to output node
1046
    pugi::xml_node node_output = root.child("output");
686✔
1047

1048
    // Check for summary option
1049
    if (check_for_node(node_output, "summary")) {
686✔
1050
      output_summary = get_node_value_bool(node_output, "summary");
662✔
1051
    }
1052

1053
    // Check for ASCII tallies output option
1054
    if (check_for_node(node_output, "tallies")) {
686✔
1055
      output_tallies = get_node_value_bool(node_output, "tallies");
314✔
1056
    }
1057

1058
    // Set output directory if a path has been specified
1059
    if (check_for_node(node_output, "path")) {
686!
1060
      path_output = get_node_value(node_output, "path");
×
1061
      if (!ends_with(path_output, "/")) {
×
1062
        path_output += "/";
×
1063
      }
1064
    }
1065
  }
1066

1067
  // Resonance scattering parameters
1068
  if (check_for_node(root, "resonance_scattering")) {
7,298✔
1069
    xml_node node_res_scat = root.child("resonance_scattering");
14✔
1070

1071
    // See if resonance scattering is enabled
1072
    if (check_for_node(node_res_scat, "enable")) {
14!
1073
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
14✔
1074
    } else {
1075
      res_scat_on = true;
×
1076
    }
1077

1078
    // Determine what method is used
1079
    if (check_for_node(node_res_scat, "method")) {
14!
1080
      auto temp = get_node_value(node_res_scat, "method", true, true);
14✔
1081
      if (temp == "rvs") {
14!
1082
        res_scat_method = ResScatMethod::rvs;
14✔
1083
      } else if (temp == "dbrc") {
×
1084
        res_scat_method = ResScatMethod::dbrc;
×
1085
      } else {
1086
        fatal_error(
×
1087
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1088
      }
1089
    }
14✔
1090

1091
    // Minimum energy for resonance scattering
1092
    if (check_for_node(node_res_scat, "energy_min")) {
14!
1093
      res_scat_energy_min =
14✔
1094
        std::stod(get_node_value(node_res_scat, "energy_min"));
14✔
1095
    }
1096
    if (res_scat_energy_min < 0.0) {
14!
1097
      fatal_error("Lower resonance scattering energy bound is negative");
×
1098
    }
1099

1100
    // Maximum energy for resonance scattering
1101
    if (check_for_node(node_res_scat, "energy_max")) {
14!
1102
      res_scat_energy_max =
14✔
1103
        std::stod(get_node_value(node_res_scat, "energy_max"));
14✔
1104
    }
1105
    if (res_scat_energy_max < res_scat_energy_min) {
14!
1106
      fatal_error("Upper resonance scattering energy bound is below the "
×
1107
                  "lower resonance scattering energy bound.");
1108
    }
1109

1110
    // Get resonance scattering nuclides
1111
    if (check_for_node(node_res_scat, "nuclides")) {
14!
1112
      res_scat_nuclides =
1113
        get_node_array<std::string>(node_res_scat, "nuclides");
14✔
1114
    }
1115
  }
1116

1117
  // Get volume calculations
1118
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
7,570✔
1119
    model::volume_calcs.emplace_back(node_vol);
272✔
1120
  }
1121

1122
  // Get temperature settings
1123
  if (check_for_node(root, "temperature_default")) {
7,298✔
1124
    temperature_default =
154✔
1125
      std::stod(get_node_value(root, "temperature_default"));
154✔
1126
  }
1127
  if (check_for_node(root, "temperature_method")) {
7,298✔
1128
    auto temp = get_node_value(root, "temperature_method", true, true);
446✔
1129
    if (temp == "nearest") {
446✔
1130
      temperature_method = TemperatureMethod::NEAREST;
280✔
1131
    } else if (temp == "interpolation") {
166!
1132
      temperature_method = TemperatureMethod::INTERPOLATION;
166✔
1133
    } else {
1134
      fatal_error("Unknown temperature method: " + temp);
×
1135
    }
1136
  }
446✔
1137
  if (check_for_node(root, "temperature_tolerance")) {
7,298✔
1138
    temperature_tolerance =
310✔
1139
      std::stod(get_node_value(root, "temperature_tolerance"));
310✔
1140
  }
1141
  if (check_for_node(root, "temperature_multipole")) {
7,298✔
1142
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
170✔
1143

1144
    // Multipole currently doesn't work with photon transport
1145
    if (temperature_multipole && photon_transport) {
170!
1146
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1147
                  "photon transport.");
1148
    }
1149
  }
1150
  if (check_for_node(root, "temperature_range")) {
7,298✔
1151
    auto range = get_node_array<double>(root, "temperature_range");
156✔
1152
    temperature_range[0] = range.at(0);
156✔
1153
    temperature_range[1] = range.at(1);
156✔
1154
  }
156✔
1155

1156
  // Check for tabular_legendre options
1157
  if (check_for_node(root, "tabular_legendre")) {
7,298✔
1158
    // Get pointer to tabular_legendre node
1159
    xml_node node_tab_leg = root.child("tabular_legendre");
84✔
1160

1161
    // Check for enable option
1162
    if (check_for_node(node_tab_leg, "enable")) {
84!
1163
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
84✔
1164
    }
1165

1166
    // Check for the number of points
1167
    if (check_for_node(node_tab_leg, "num_points")) {
84!
1168
      legendre_to_tabular_points =
×
1169
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
1170
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
1171
        fatal_error(
×
1172
          "The 'num_points' subelement/attribute of the "
1173
          "<tabular_legendre> element must contain a value greater than 1");
1174
      }
1175
    }
1176
  }
1177

1178
  // Check whether create delayed neutrons in fission
1179
  if (check_for_node(root, "create_delayed_neutrons")) {
7,298!
1180
    create_delayed_neutrons =
×
1181
      get_node_value_bool(root, "create_delayed_neutrons");
×
1182
  }
1183

1184
  // Check whether create fission sites
1185
  if (run_mode == RunMode::FIXED_SOURCE) {
7,298✔
1186
    if (check_for_node(root, "create_fission_neutrons")) {
2,458✔
1187
      create_fission_neutrons =
254✔
1188
        get_node_value_bool(root, "create_fission_neutrons");
254✔
1189
    }
1190
  }
1191

1192
  // Check whether to scale fission photon yields
1193
  if (check_for_node(root, "delayed_photon_scaling")) {
7,298!
1194
    delayed_photon_scaling =
×
1195
      get_node_value_bool(root, "delayed_photon_scaling");
×
1196
  }
1197

1198
  // Check whether to use event-based parallelism
1199
  if (check_for_node(root, "event_based")) {
7,298!
1200
    event_based = get_node_value_bool(root, "event_based");
×
1201
  }
1202

1203
  // Check whether material cell offsets should be generated
1204
  if (check_for_node(root, "material_cell_offsets")) {
7,298!
1205
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1206
  }
1207

1208
  // Weight window information
1209
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
7,378✔
1210
    variance_reduction::weight_windows.emplace_back(
80✔
1211
      std::make_unique<WeightWindows>(node_ww));
160✔
1212
  }
1213

1214
  // Enable weight windows by default if one or more are present
1215
  if (variance_reduction::weight_windows.size() > 0)
7,298✔
1216
    settings::weight_windows_on = true;
56✔
1217

1218
  // read weight windows from file
1219
  if (check_for_node(root, "weight_windows_file")) {
7,298!
1220
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1221
  }
1222

1223
  // read settings for weight windows value, this will override
1224
  // the automatic setting even if weight windows are present
1225
  if (check_for_node(root, "weight_windows_on")) {
7,298✔
1226
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
32✔
1227
  }
1228

1229
  if (check_for_node(root, "max_secondaries")) {
7,298!
1230
    settings::max_secondaries =
×
1231
      std::stoi(get_node_value(root, "max_secondaries"));
×
1232
  }
1233

1234
  if (check_for_node(root, "max_history_splits")) {
7,298✔
1235
    settings::max_history_splits =
194✔
1236
      std::stoi(get_node_value(root, "max_history_splits"));
194✔
1237
  }
1238

1239
  if (check_for_node(root, "max_tracks")) {
7,298✔
1240
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
42✔
1241
  }
1242

1243
  // Create weight window generator objects
1244
  if (check_for_node(root, "weight_window_generators")) {
7,298✔
1245
    auto wwgs_node = root.child("weight_window_generators");
72✔
1246
    for (pugi::xml_node node_wwg :
72✔
1247
      wwgs_node.children("weight_windows_generator")) {
216✔
1248
      variance_reduction::weight_windows_generators.emplace_back(
72✔
1249
        std::make_unique<WeightWindowsGenerator>(node_wwg));
144✔
1250
    }
1251
    // if any of the weight windows are intended to be generated otf, make
1252
    // sure they're applied
1253
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
72!
1254
      if (wwg->on_the_fly_) {
72!
1255
        settings::weight_windows_on = true;
72✔
1256
        break;
72✔
1257
      }
1258
    }
1259
  }
1260

1261
  // Set up weight window checkpoints
1262
  if (check_for_node(root, "weight_window_checkpoints")) {
7,298!
UNCOV
1263
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
×
UNCOV
1264
    if (check_for_node(ww_checkpoints, "collision")) {
×
UNCOV
1265
      weight_window_checkpoint_collision =
×
UNCOV
1266
        get_node_value_bool(ww_checkpoints, "collision");
×
1267
    }
UNCOV
1268
    if (check_for_node(ww_checkpoints, "surface")) {
×
UNCOV
1269
      weight_window_checkpoint_surface =
×
UNCOV
1270
        get_node_value_bool(ww_checkpoints, "surface");
×
1271
    }
1272
  }
1273

1274
  if (check_for_node(root, "use_decay_photons")) {
7,298✔
1275
    settings::use_decay_photons =
10✔
1276
      get_node_value_bool(root, "use_decay_photons");
10✔
1277
  }
1278
}
7,298✔
1279

1280
void free_memory_settings()
7,429✔
1281
{
1282
  settings::statepoint_batch.clear();
7,429✔
1283
  settings::sourcepoint_batch.clear();
7,429✔
1284
  settings::source_write_surf_id.clear();
7,429✔
1285
  settings::res_scat_nuclides.clear();
7,429✔
1286
}
7,429✔
1287

1288
//==============================================================================
1289
// C API functions
1290
//==============================================================================
1291

1292
extern "C" int openmc_set_n_batches(
40✔
1293
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1294
{
1295
  if (settings::n_inactive >= n_batches) {
40✔
1296
    set_errmsg("Number of active batches must be greater than zero.");
10✔
1297
    return OPENMC_E_INVALID_ARGUMENT;
10✔
1298
  }
1299

1300
  if (!settings::trigger_on) {
30✔
1301
    // Set n_batches and n_max_batches to same value
1302
    settings::n_batches = n_batches;
10✔
1303
    settings::n_max_batches = n_batches;
10✔
1304
  } else {
1305
    // Set n_batches and n_max_batches based on value of set_max_batches
1306
    if (set_max_batches) {
20✔
1307
      settings::n_max_batches = n_batches;
10✔
1308
    } else {
1309
      settings::n_batches = n_batches;
10✔
1310
    }
1311
  }
1312

1313
  // Update size of k_generation and entropy
1314
  int m = settings::n_max_batches * settings::gen_per_batch;
30✔
1315
  simulation::k_generation.reserve(m);
30✔
1316
  simulation::entropy.reserve(m);
30✔
1317

1318
  // Add value of n_batches to statepoint_batch
1319
  if (add_statepoint_batch &&
50✔
1320
      !(contains(settings::statepoint_batch, n_batches)))
20!
1321
    settings::statepoint_batch.insert(n_batches);
20✔
1322

1323
  return 0;
30✔
1324
}
1325

1326
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,300✔
1327
{
1328
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,300✔
1329

1330
  return 0;
2,300✔
1331
}
1332

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