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

openmc-dev / openmc / 23010841626

12 Mar 2026 03:50PM UTC coverage: 81.015% (-0.6%) from 81.566%
23010841626

Pull #3863

github

web-flow
Merge 954a87042 into ba94c5823
Pull Request #3863: Shared Secondary Particle Bank

16912 of 24191 branches covered (69.91%)

Branch coverage included in aggregate %.

323 of 429 new or added lines in 17 files covered. (75.29%)

577 existing lines in 39 files now uncovered.

56865 of 66875 relevant lines covered (85.03%)

32719674.03 hits per line

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

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

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

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

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

39
namespace openmc {
40

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

45
namespace settings {
46

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

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

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

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

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

156
} // namespace settings
157

158
//==============================================================================
159
// Functions
160
//==============================================================================
161

162
void get_run_parameters(pugi::xml_node node_base)
3,828✔
163
{
164
  using namespace settings;
3,828✔
165
  using namespace pugi;
3,828✔
166

167
  // Check number of particles
168
  if (!check_for_node(node_base, "particles")) {
3,828!
169
    fatal_error("Need to specify number of particles.");
×
170
  }
171

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

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

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

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

196
  // Get max number of lost particles
197
  if (check_for_node(node_base, "max_lost_particles")) {
3,828✔
198
    max_lost_particles =
42✔
199
      std::stoi(get_node_value(node_base, "max_lost_particles"));
21✔
200
  }
201

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

208
  // Get relative number of lost particles
209
  if (check_for_node(node_base, "max_write_lost_particles")) {
3,828✔
210
    max_write_lost_particles =
14✔
211
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
7✔
212
  }
213

214
  // Get number of inactive batches
215
  if (run_mode == RunMode::EIGENVALUE ||
3,828✔
216
      solver_type == SolverType::RANDOM_RAY) {
1,553✔
217
    if (check_for_node(node_base, "inactive")) {
2,464✔
218
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
2,349✔
219
    }
220
    if (check_for_node(node_base, "generations_per_batch")) {
2,464✔
221
      gen_per_batch =
14✔
222
        std::stoi(get_node_value(node_base, "generations_per_batch"));
7✔
223
    }
224

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

230
    // Get the trigger information for keff
231
    if (check_for_node(node_base, "keff_trigger")) {
2,464✔
232
      xml_node node_keff_trigger = node_base.child("keff_trigger");
48✔
233

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

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

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

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

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

401
  // Get root element
402
  xml_node root = doc.document_element();
676✔
403

404
  // Verbosity
405
  if (check_for_node(root, "verbosity") && verbosity == -1) {
676!
406
    verbosity = std::stoi(get_node_value(root, "verbosity"));
194✔
407
  } else if (verbosity == -1) {
579!
408
    verbosity = 7;
579✔
409
  }
410

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

418
  write_message("Reading settings XML file...", 5);
676✔
419

420
  read_settings_xml(root);
676✔
421
}
682✔
422

423
void read_settings_xml(pugi::xml_node root)
4,268✔
424
{
425
  using namespace settings;
4,268✔
426
  using namespace pugi;
4,268✔
427

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

438
  // Check for user meshes and allocate
439
  read_meshes(root);
4,268✔
440

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

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

465
  // Check for a trigger node and get trigger information
466
  if (check_for_node(root, "trigger")) {
4,268✔
467
    xml_node node_trigger = root.child("trigger");
78✔
468

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

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

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

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

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

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

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

539
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
4,268✔
540
    // Read run parameters
541
    get_run_parameters(node_mode);
3,828✔
542

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

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

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

578
  // Copy random number seed if specified
579
  if (check_for_node(root, "seed")) {
4,262✔
580
    auto seed = std::stoll(get_node_value(root, "seed"));
612✔
581
    openmc_set_seed(seed);
306✔
582
  }
583

584
  // Copy random number stride if specified
585
  if (check_for_node(root, "stride")) {
4,262✔
586
    auto stride = std::stoull(get_node_value(root, "stride"));
14✔
587
    openmc_set_stride(stride);
7✔
588
  }
589

590
  // Check for electron treatment
591
  if (check_for_node(root, "electron_treatment")) {
4,262✔
592
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
40✔
593
    if (temp_str == "led") {
40✔
594
      electron_treatment = ElectronTreatment::LED;
13✔
595
    } else if (temp_str == "ttb") {
27!
596
      electron_treatment = ElectronTreatment::TTB;
27✔
597
    } else {
598
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
599
    }
600
  }
40✔
601

602
  // Check for photon transport
603
  if (check_for_node(root, "photon_transport")) {
4,262✔
604
    photon_transport = get_node_value_bool(root, "photon_transport");
140✔
605

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

612
  // Check for atomic relaxation
613
  if (check_for_node(root, "atomic_relaxation")) {
4,262✔
614
    atomic_relaxation = get_node_value_bool(root, "atomic_relaxation");
7✔
615
  }
616

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

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

634
  // ==========================================================================
635
  // EXTERNAL SOURCE
636

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

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

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

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

668
  // Build probability mass function for sampling external sources
669
  vector<double> source_strengths;
4,256✔
670
  for (auto& s : model::external_sources) {
9,374✔
671
    source_strengths.push_back(s->strength());
5,118✔
672
  }
673
  model::external_sources_probability.assign(source_strengths);
4,256✔
674

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

680
  // Get relative number of lost particles
681
  if (check_for_node(root, "source_rejection_fraction")) {
4,256✔
682
    source_rejection_fraction =
10✔
683
      std::stod(get_node_value(root, "source_rejection_fraction"));
10!
684
  }
685

686
  if (check_for_node(root, "free_gas_threshold")) {
4,256!
687
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
688
  }
689

690
  // Surface grazing
691
  if (check_for_node(root, "surface_grazing_cutoff"))
4,256!
692
    surface_grazing_cutoff =
×
693
      std::stod(get_node_value(root, "surface_grazing_cutoff"));
×
694
  if (check_for_node(root, "surface_grazing_ratio"))
4,256!
695
    surface_grazing_ratio =
×
696
      std::stod(get_node_value(root, "surface_grazing_ratio"));
×
697

698
  // Survival biasing
699
  if (check_for_node(root, "survival_biasing")) {
4,256✔
700
    survival_biasing = get_node_value_bool(root, "survival_biasing");
106✔
701
  }
702

703
  // Probability tables
704
  if (check_for_node(root, "ptables")) {
4,256✔
705
    urr_ptables_on = get_node_value_bool(root, "ptables");
7✔
706
  }
707

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

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

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

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

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

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

807
      // Turn on Shannon entropy calculation
808
      entropy_on = true;
181✔
809

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

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

832
    // Turn on uniform fission source weighting
833
    ufs_on = true;
7✔
834

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

842
  // Check if the user has specified to write state points
843
  if (check_for_node(root, "state_point")) {
4,256✔
844

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

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

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

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

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

903
  // Check is the user specified to convert strength to statistical weight
904
  if (check_for_node(root, "uniform_source_sampling")) {
4,256✔
905
    uniform_source_sampling =
30✔
906
      get_node_value_bool(root, "uniform_source_sampling");
30✔
907
  }
908

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

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

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

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

941
    if (check_for_node(node_ssw, "mcpl")) {
228✔
942
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
6✔
943
    }
944
    // Get cell information
945
    if (check_for_node(node_ssw, "cell")) {
228✔
946
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
120✔
947
      ssw_cell_type = SSWCellType::Both;
60✔
948
    }
949
    if (check_for_node(node_ssw, "cellfrom")) {
228✔
950
      if (ssw_cell_id != C_NONE) {
54✔
951
        fatal_error(
12✔
952
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
953
      }
954
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
84✔
955
      ssw_cell_type = SSWCellType::From;
42✔
956
    }
957
    if (check_for_node(node_ssw, "cellto")) {
216✔
958
      if (ssw_cell_id != C_NONE) {
42✔
959
        fatal_error(
12✔
960
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
961
      }
962
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
60✔
963
      ssw_cell_type = SSWCellType::To;
30✔
964
    }
965
  }
966

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

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

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

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

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

1055
  // Check for output options
1056
  if (check_for_node(root, "output")) {
4,226✔
1057
    // Get pointer to output node
1058
    pugi::xml_node node_output = root.child("output");
398✔
1059

1060
    // Check for summary option
1061
    if (check_for_node(node_output, "summary")) {
398✔
1062
      output_summary = get_node_value_bool(node_output, "summary");
385✔
1063
    }
1064

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

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

1079
  // Resonance scattering parameters
1080
  if (check_for_node(root, "resonance_scattering")) {
4,226✔
1081
    xml_node node_res_scat = root.child("resonance_scattering");
7✔
1082

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

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

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

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

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

1129
  // Get volume calculations
1130
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
4,376✔
1131
    model::volume_calcs.emplace_back(node_vol);
150✔
1132
  }
1133

1134
  // Get temperature settings
1135
  if (check_for_node(root, "temperature_default")) {
4,226✔
1136
    temperature_default =
182✔
1137
      std::stod(get_node_value(root, "temperature_default"));
182✔
1138
  }
1139
  if (check_for_node(root, "temperature_method")) {
4,226✔
1140
    auto temp = get_node_value(root, "temperature_method", true, true);
248✔
1141
    if (temp == "nearest") {
248✔
1142
      temperature_method = TemperatureMethod::NEAREST;
154✔
1143
    } else if (temp == "interpolation") {
94!
1144
      temperature_method = TemperatureMethod::INTERPOLATION;
94✔
1145
    } else {
1146
      fatal_error("Unknown temperature method: " + temp);
×
1147
    }
1148
  }
248✔
1149
  if (check_for_node(root, "temperature_tolerance")) {
4,226✔
1150
    temperature_tolerance =
358✔
1151
      std::stod(get_node_value(root, "temperature_tolerance"));
358✔
1152
  }
1153
  if (check_for_node(root, "temperature_multipole")) {
4,226✔
1154
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
95✔
1155

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

1168
  // Check for tabular_legendre options
1169
  if (check_for_node(root, "tabular_legendre")) {
4,226✔
1170
    // Get pointer to tabular_legendre node
1171
    xml_node node_tab_leg = root.child("tabular_legendre");
49✔
1172

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

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

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

1196
  // Check whether create fission sites
1197
  if (run_mode == RunMode::FIXED_SOURCE) {
4,226✔
1198
    if (check_for_node(root, "create_fission_neutrons")) {
1,523✔
1199
      create_fission_neutrons =
172✔
1200
        get_node_value_bool(root, "create_fission_neutrons");
172✔
1201
    }
1202
  }
1203

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

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

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

1220
  // Weight window information
1221
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
4,331✔
1222
    variance_reduction::weight_windows.emplace_back(
105✔
1223
      std::make_unique<WeightWindows>(node_ww));
210✔
1224
  }
1225

1226
  // Enable weight windows by default if one or more are present
1227
  if (variance_reduction::weight_windows.size() > 0)
4,226✔
1228
    settings::weight_windows_on = true;
79✔
1229

1230
  // read weight windows from file
1231
  if (check_for_node(root, "weight_windows_file")) {
4,226!
1232
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1233
  }
1234

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

1241
  if (check_for_node(root, "max_secondaries")) {
4,226!
1242
    settings::max_secondaries =
×
1243
      std::stoi(get_node_value(root, "max_secondaries"));
×
1244
  }
1245

1246
  if (check_for_node(root, "max_history_splits")) {
4,226✔
1247
    settings::max_history_splits =
310✔
1248
      std::stoi(get_node_value(root, "max_history_splits"));
310✔
1249
  }
1250

1251
  if (check_for_node(root, "max_tracks")) {
4,226✔
1252
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
42✔
1253
  }
1254

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

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

1286
  if (weight_windows_on) {
4,226✔
1287
    if (!weight_window_checkpoint_surface &&
124✔
1288
        !weight_window_checkpoint_collision)
82!
1289
      fatal_error(
×
1290
        "Weight Windows are enabled but there are no valid checkpoints.");
1291
  }
1292

1293
  if (check_for_node(root, "use_decay_photons")) {
4,226✔
1294
    settings::use_decay_photons =
6✔
1295
      get_node_value_bool(root, "use_decay_photons");
6✔
1296
  }
1297

1298
  // If weight windows are on, also enable shared secondary bank (unless
1299
  // explicitly disabled by user).
1300
  if (check_for_node(root, "shared_secondary_bank")) {
4,226✔
1301
    bool val = get_node_value_bool(root, "shared_secondary_bank");
127✔
1302
    if (val && run_mode == RunMode::EIGENVALUE) {
127!
NEW
1303
      warning(
×
1304
        "Shared secondary bank is not supported in eigenvalue calculations. "
1305
        "Setting will be ignored.");
1306
    } else {
1307
      settings::use_shared_secondary_bank = val;
127✔
1308
    }
1309
  } else if (settings::weight_windows_on) {
4,099✔
1310
    if (run_mode == RunMode::EIGENVALUE) {
51✔
1311
      warning(
12✔
1312
        "Shared secondary bank is not supported in eigenvalue calculations. "
1313
        "Particle local secondary banks will be used instead.");
1314
    } else if (run_mode == RunMode::FIXED_SOURCE) {
45!
1315
      settings::use_shared_secondary_bank = true;
45✔
1316
    }
1317
  }
1318
}
4,226✔
1319

1320
void free_memory_settings()
4,294✔
1321
{
1322
  settings::statepoint_batch.clear();
4,294✔
1323
  settings::sourcepoint_batch.clear();
4,294✔
1324
  settings::source_write_surf_id.clear();
4,294✔
1325
  settings::res_scat_nuclides.clear();
4,294✔
1326
}
4,294✔
1327

1328
//==============================================================================
1329
// C API functions
1330
//==============================================================================
1331

1332
extern "C" int openmc_set_n_batches(
24✔
1333
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1334
{
1335
  if (settings::n_inactive >= n_batches) {
24✔
1336
    set_errmsg("Number of active batches must be greater than zero.");
6✔
1337
    return OPENMC_E_INVALID_ARGUMENT;
6✔
1338
  }
1339

1340
  if (!settings::trigger_on) {
18✔
1341
    // Set n_batches and n_max_batches to same value
1342
    settings::n_batches = n_batches;
6✔
1343
    settings::n_max_batches = n_batches;
6✔
1344
  } else {
1345
    // Set n_batches and n_max_batches based on value of set_max_batches
1346
    if (set_max_batches) {
12✔
1347
      settings::n_max_batches = n_batches;
6✔
1348
    } else {
1349
      settings::n_batches = n_batches;
6✔
1350
    }
1351
  }
1352

1353
  // Update size of k_generation and entropy
1354
  int m = settings::n_max_batches * settings::gen_per_batch;
18✔
1355
  simulation::k_generation.reserve(m);
18✔
1356
  simulation::entropy.reserve(m);
18✔
1357

1358
  // Add value of n_batches to statepoint_batch
1359
  if (add_statepoint_batch &&
18✔
1360
      !(contains(settings::statepoint_batch, n_batches)))
12!
1361
    settings::statepoint_batch.insert(n_batches);
12✔
1362

1363
  return 0;
1364
}
1365

1366
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
1,380✔
1367
{
1368
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
1,380✔
1369

1370
  return 0;
1,380✔
1371
}
1372

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