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

openmc-dev / openmc / 22249465565

21 Feb 2026 03:27AM UTC coverage: 81.839% (+0.01%) from 81.826%
22249465565

Pull #3830

github

web-flow
Merge 62bae4829 into 53ce1910f
Pull Request #3830: Parallelize sampling external sources and threadsafe rejection counters

17287 of 24326 branches covered (71.06%)

Branch coverage included in aggregate %.

65 of 73 new or added lines in 5 files covered. (89.04%)

3 existing lines in 2 files now uncovered.

57597 of 67176 relevant lines covered (85.74%)

45560552.21 hits per line

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

77.23
/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

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

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

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

110
ElectronTreatment electron_treatment {ElectronTreatment::TTB};
111
array<double, 4> energy_cutoff {0.0, 1000.0, 0.0, 0.0};
112
array<double, 4> time_cutoff {INFTY, INFTY, INFTY, INFTY};
113
int ifp_n_generation {-1};
114
IFPParameter ifp_parameter {IFPParameter::None};
115
int legendre_to_tabular_points {C_NONE};
116
int max_order {0};
117
int n_log_bins {8000};
118
int n_batches;
119
int n_max_batches;
120
int max_secondaries {10000};
121
int max_history_splits {10'000'000};
122
int max_tracks {1000};
123
ResScatMethod res_scat_method {ResScatMethod::rvs};
124
double res_scat_energy_min {0.01};
125
double res_scat_energy_max {1000.0};
126
vector<std::string> res_scat_nuclides;
127
RunMode run_mode {RunMode::UNSET};
128
SolverType solver_type {SolverType::MONTE_CARLO};
129
std::unordered_set<int> sourcepoint_batch;
130
std::unordered_set<int> statepoint_batch;
131
double source_rejection_fraction {0.05};
132
int64_t max_source_rejections_per_sample {1'000'000};
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,705✔
160
{
161
  using namespace settings;
162
  using namespace pugi;
163

164
  // Check number of particles
165
  if (!check_for_node(node_base, "particles")) {
6,705!
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,705!
171
    n_particles = std::stoll(get_node_value(node_base, "particles"));
6,705✔
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,705!
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,705!
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,705!
188
    n_batches = std::stoi(get_node_value(node_base, "batches"));
6,705✔
189
  }
190
  if (!trigger_on)
6,705✔
191
    n_max_batches = n_batches;
6,575✔
192

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

199
  // Get relative number of lost particles
200
  if (check_for_node(node_base, "rel_max_lost_particles")) {
6,705!
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,705✔
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,705✔
213
      solver_type == SolverType::RANDOM_RAY) {
2,541✔
214
    if (check_for_node(node_base, "inactive")) {
4,543✔
215
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,375✔
216
    }
217
    if (check_for_node(node_base, "generations_per_batch")) {
4,543✔
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,543✔
224
    simulation::k_generation.reserve(m);
4,543✔
225
    simulation::entropy.reserve(m);
4,543✔
226

227
    // Get the trigger information for keff
228
    if (check_for_node(node_base, "keff_trigger")) {
4,543✔
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,705✔
260
    xml_node random_ray_node = node_base.child("random_ray");
711✔
261
    if (check_for_node(random_ray_node, "distance_active")) {
711!
262
      RandomRay::distance_active_ =
711✔
263
        std::stod(get_node_value(random_ray_node, "distance_active"));
711✔
264
      if (RandomRay::distance_active_ <= 0.0) {
711!
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")) {
711!
271
      RandomRay::distance_inactive_ =
711✔
272
        std::stod(get_node_value(random_ray_node, "distance_inactive"));
711✔
273
      if (RandomRay::distance_inactive_ < 0) {
711!
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")) {
711!
281
      xml_node source_node = random_ray_node.child("source");
711✔
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);
711✔
285
    } else {
286
      fatal_error("Specify random ray source in settings XML");
×
287
    }
288
    if (check_for_node(random_ray_node, "volume_estimator")) {
711✔
289
      std::string temp_str =
290
        get_node_value(random_ray_node, "volume_estimator", true, true);
113✔
291
      if (temp_str == "simulation_averaged") {
113✔
292
        FlatSourceDomain::volume_estimator_ =
28✔
293
          RandomRayVolumeEstimator::SIMULATION_AVERAGED;
294
      } else if (temp_str == "naive") {
85✔
295
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::NAIVE;
57✔
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
    }
113✔
302
    if (check_for_node(random_ray_node, "source_shape")) {
711✔
303
      std::string temp_str =
304
        get_node_value(random_ray_node, "source_shape", true, true);
420✔
305
      if (temp_str == "flat") {
420✔
306
        RandomRay::source_shape_ = RandomRaySourceShape::FLAT;
70✔
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
    }
420✔
315
    if (check_for_node(random_ray_node, "volume_normalized_flux_tallies")) {
711✔
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")) {
711✔
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")) {
711✔
324
      std::string temp_str =
325
        get_node_value(random_ray_node, "sample_method", true, true);
28✔
326
      if (temp_str == "prng") {
28!
327
        RandomRay::sample_method_ = RandomRaySampleMethod::PRNG;
×
328
      } else if (temp_str == "halton") {
28✔
329
        RandomRay::sample_method_ = RandomRaySampleMethod::HALTON;
14✔
330
      } else if (temp_str == "s2") {
14!
331
        RandomRay::sample_method_ = RandomRaySampleMethod::S2;
14✔
332
      } else {
333
        fatal_error("Unrecognized sample method: " + temp_str);
×
334
      }
335
    }
28✔
336
    if (check_for_node(random_ray_node, "source_region_meshes")) {
711✔
337
      pugi::xml_node node_source_region_meshes =
338
        random_ray_node.child("source_region_meshes");
295✔
339
      for (pugi::xml_node node_mesh :
295✔
340
        node_source_region_meshes.children("mesh")) {
941✔
341
        int mesh_id = std::stoi(node_mesh.attribute("id").value());
351✔
342
        for (pugi::xml_node node_domain : node_mesh.children("domain")) {
702✔
343
          int domain_id = std::stoi(node_domain.attribute("id").value());
351✔
344
          std::string domain_type = node_domain.attribute("type").value();
351✔
345
          Source::DomainType type;
346
          if (domain_type == "material") {
351✔
347
            type = Source::DomainType::MATERIAL;
28✔
348
          } else if (domain_type == "cell") {
323✔
349
            type = Source::DomainType::CELL;
28✔
350
          } else if (domain_type == "universe") {
295!
351
            type = Source::DomainType::UNIVERSE;
295✔
352
          } else {
353
            throw std::runtime_error("Unknown domain type: " + domain_type);
×
354
          }
355
          FlatSourceDomain::mesh_domain_map_[mesh_id].emplace_back(
351✔
356
            type, domain_id);
357
        }
351✔
358
      }
359
    }
360
    if (check_for_node(random_ray_node, "diagonal_stabilization_rho")) {
711✔
361
      FlatSourceDomain::diagonal_stabilization_rho_ = std::stod(
14✔
362
        get_node_value(random_ray_node, "diagonal_stabilization_rho"));
28✔
363
      if (FlatSourceDomain::diagonal_stabilization_rho_ < 0.0 ||
14!
364
          FlatSourceDomain::diagonal_stabilization_rho_ > 1.0) {
14!
365
        fatal_error("Random ray diagonal stabilization rho factor must be "
×
366
                    "between 0 and 1");
367
      }
368
    }
369
  }
370
}
6,705✔
371

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

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

398
  // Get root element
399
  xml_node root = doc.document_element();
1,225✔
400

401
  // Verbosity
402
  if (check_for_node(root, "verbosity") && verbosity == -1) {
1,225!
403
    verbosity = std::stoi(get_node_value(root, "verbosity"));
165✔
404
  } else if (verbosity == -1) {
1,060!
405
    verbosity = 7;
1,060✔
406
  }
407

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

415
  write_message("Reading settings XML file...", 5);
1,225✔
416

417
  read_settings_xml(root);
1,225✔
418
}
1,236✔
419

420
void read_settings_xml(pugi::xml_node root)
7,440✔
421
{
422
  using namespace settings;
423
  using namespace pugi;
424

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

435
  // Check for user meshes and allocate
436
  read_meshes(root);
7,440✔
437

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

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

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

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

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

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

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

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

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

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

536
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
7,440✔
537
    // Read run parameters
538
    get_run_parameters(node_mode);
6,705✔
539

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

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

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

575
  // Copy random number seed if specified
576
  if (check_for_node(root, "seed")) {
7,432✔
577
    auto seed = std::stoll(get_node_value(root, "seed"));
528✔
578
    openmc_set_seed(seed);
528✔
579
  }
580

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

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

599
  // Check for photon transport
600
  if (check_for_node(root, "photon_transport")) {
7,432✔
601
    photon_transport = get_node_value_bool(root, "photon_transport");
176✔
602

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

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

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

626
  // ==========================================================================
627
  // EXTERNAL SOURCE
628

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

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

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

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

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

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

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

678
  if (check_for_node(root, "max_source_rejections_per_sample")) {
7,423!
NEW
679
    max_source_rejections_per_sample =
×
NEW
680
      std::stoll(get_node_value(root, "max_source_rejections_per_sample"));
×
681
  }
682

683
  if (check_for_node(root, "free_gas_threshold")) {
7,423!
684
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
685
  }
686

687
  // Survival biasing
688
  if (check_for_node(root, "survival_biasing")) {
7,423✔
689
    survival_biasing = get_node_value_bool(root, "survival_biasing");
160✔
690
  }
691

692
  // Probability tables
693
  if (check_for_node(root, "ptables")) {
7,423✔
694
    urr_ptables_on = get_node_value_bool(root, "ptables");
14✔
695
  }
696

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

744
  // Particle trace
745
  if (check_for_node(root, "trace")) {
7,423✔
746
    auto temp = get_node_array<int64_t>(root, "trace");
14✔
747
    if (temp.size() != 3) {
14!
748
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
749
                  "batch, generation, and particle number.");
750
    }
751
    trace_batch = temp.at(0);
14✔
752
    trace_gen = temp.at(1);
14✔
753
    trace_particle = temp.at(2);
14✔
754
  }
14✔
755

756
  // Particle tracks
757
  if (check_for_node(root, "track")) {
7,423✔
758
    // Get values and make sure there are three per particle
759
    auto temp = get_node_array<int>(root, "track");
42✔
760
    if (temp.size() % 3 != 0) {
42!
761
      fatal_error(
×
762
        "Number of integers specified in 'track' is not "
763
        "divisible by 3.  Please provide 3 integers per particle to be "
764
        "tracked.");
765
    }
766

767
    // Reshape into track_identifiers
768
    int n_tracks = temp.size() / 3;
42✔
769
    for (int i = 0; i < n_tracks; ++i) {
168✔
770
      track_identifiers.push_back(
126✔
771
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
126✔
772
    }
773
  }
42✔
774

775
  // Shannon entropy
776
  if (solver_type == SolverType::RANDOM_RAY) {
7,423✔
777
    if (check_for_node(root, "entropy_mesh")) {
711!
778
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
779
                  "No user-defined entropy mesh is supported.");
780
    }
781
    entropy_on = true;
711✔
782
  } else if (solver_type == SolverType::MONTE_CARLO) {
6,712!
783
    if (check_for_node(root, "entropy_mesh")) {
6,712✔
784
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
304✔
785
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
304!
786
        fatal_error(fmt::format(
×
787
          "Mesh {} specified for Shannon entropy does not exist.", temp));
788
      }
789

790
      auto* m = dynamic_cast<RegularMesh*>(
304!
791
        model::meshes[model::mesh_map.at(temp)].get());
304✔
792
      if (!m)
304!
793
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
794
      simulation::entropy_mesh = m;
304✔
795

796
      // Turn on Shannon entropy calculation
797
      entropy_on = true;
304✔
798

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

815
    auto* m =
816
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
14!
817
    if (!m)
14!
818
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
819
    simulation::ufs_mesh = m;
14✔
820

821
    // Turn on uniform fission source weighting
822
    ufs_on = true;
14✔
823

824
  } else if (check_for_node(root, "uniform_fs")) {
7,409!
825
    fatal_error(
×
826
      "Specifying a UFS mesh via the <uniform_fs> element "
827
      "is deprecated. Please create a mesh using <mesh> and then reference "
828
      "it by specifying its ID in a <ufs_mesh> element.");
829
  }
830

831
  // Check if the user has specified to write state points
832
  if (check_for_node(root, "state_point")) {
7,423✔
833

834
    // Get pointer to state_point node
835
    auto node_sp = root.child("state_point");
148✔
836

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

854
  // Check if the user has specified to write source points
855
  if (check_for_node(root, "source_point")) {
7,423✔
856
    // Get source_point node
857
    xml_node node_sp = root.child("source_point");
94✔
858

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

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

892
  // Check is the user specified to convert strength to statistical weight
893
  if (check_for_node(root, "uniform_source_sampling")) {
7,423✔
894
    uniform_source_sampling =
50✔
895
      get_node_value_bool(root, "uniform_source_sampling");
50✔
896
  }
897

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

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

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

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

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

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

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

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

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

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

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

1049
    // Check for summary option
1050
    if (check_for_node(node_output, "summary")) {
693✔
1051
      output_summary = get_node_value_bool(node_output, "summary");
669✔
1052
    }
1053

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1235
  if (check_for_node(root, "max_history_splits")) {
7,383✔
1236
    settings::max_history_splits =
195✔
1237
      std::stoi(get_node_value(root, "max_history_splits"));
195✔
1238
  }
1239

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

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

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

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

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

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

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

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

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

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

1324
  return 0;
30✔
1325
}
1326

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

1331
  return 0;
2,300✔
1332
}
1333

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