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

openmc-dev / openmc / 23494067097

24 Mar 2026 02:14PM UTC coverage: 81.299% (-0.03%) from 81.326%
23494067097

Pull #3863

github

web-flow
Merge fc121e706 into 6cd39073b
Pull Request #3863: Shared Secondary Particle Bank

17806 of 25682 branches covered (69.33%)

Branch coverage included in aggregate %.

418 of 435 new or added lines in 17 files covered. (96.09%)

130 existing lines in 4 files now uncovered.

58438 of 68100 relevant lines covered (85.81%)

46091568.19 hits per line

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

76.56
/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
std::string properties_file;
101

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

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

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

157
} // namespace settings
158

159
//==============================================================================
160
// Functions
161
//==============================================================================
162

163
void get_run_parameters(pugi::xml_node node_base)
7,597✔
164
{
165
  using namespace settings;
7,597✔
166
  using namespace pugi;
7,597✔
167

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

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

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

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

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

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

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

209
  // Get relative number of lost particles
210
  if (check_for_node(node_base, "max_write_lost_particles")) {
7,597✔
211
    max_write_lost_particles =
30✔
212
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
15✔
213
  }
214

215
  // Get number of inactive batches
216
  if (run_mode == RunMode::EIGENVALUE ||
7,597✔
217
      solver_type == SolverType::RANDOM_RAY) {
3,027✔
218
    if (check_for_node(node_base, "inactive")) {
4,976✔
219
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,765✔
220
    }
221
    if (check_for_node(node_base, "generations_per_batch")) {
4,976✔
222
      gen_per_batch =
30✔
223
        std::stoi(get_node_value(node_base, "generations_per_batch"));
15✔
224
    }
225

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

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

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

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

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

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

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

402
  // Get root element
403
  xml_node root = doc.document_element();
1,357✔
404

405
  // Verbosity
406
  if (check_for_node(root, "verbosity") && verbosity == -1) {
1,357!
407
    verbosity = std::stoi(get_node_value(root, "verbosity"));
362✔
408
  } else if (verbosity == -1) {
1,176!
409
    verbosity = 7;
1,176✔
410
  }
411

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

419
  write_message("Reading settings XML file...", 5);
1,357✔
420

421
  read_settings_xml(root);
1,357✔
422
}
1,369✔
423

424
void read_settings_xml(pugi::xml_node root)
8,405✔
425
{
426
  using namespace settings;
8,405✔
427
  using namespace pugi;
8,405✔
428

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

439
  // Check for user meshes and allocate
440
  read_meshes(root);
8,405✔
441

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

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

466
  // Check for a trigger node and get trigger information
467
  if (check_for_node(root, "trigger")) {
8,405✔
468
    xml_node node_trigger = root.child("trigger");
156✔
469

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

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

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

493
  // Check run mode if it hasn't been set from the command line
494
  xml_node node_mode;
8,405✔
495
  if (run_mode == RunMode::UNSET) {
8,405✔
496
    if (check_for_node(root, "run_mode")) {
7,629✔
497
      std::string temp_str = get_node_value(root, "run_mode", true, true);
7,599✔
498
      if (temp_str == "eigenvalue") {
7,599✔
499
        run_mode = RunMode::EIGENVALUE;
4,540✔
500
      } else if (temp_str == "fixed source") {
3,059✔
501
        run_mode = RunMode::FIXED_SOURCE;
3,027✔
502
      } else if (temp_str == "plot") {
32!
503
        run_mode = RunMode::PLOTTING;
×
504
      } else if (temp_str == "particle restart") {
32!
505
        run_mode = RunMode::PARTICLE;
×
506
      } else if (temp_str == "volume") {
32!
507
        run_mode = RunMode::VOLUME;
32✔
508
      } else {
509
        fatal_error("Unrecognized run mode: " + temp_str);
×
510
      }
511

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

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

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

540
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
8,405✔
541
    // Read run parameters
542
    get_run_parameters(node_mode);
7,597✔
543

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

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

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

579
  // Copy random number seed if specified
580
  if (check_for_node(root, "seed")) {
8,396✔
581
    auto seed = std::stoll(get_node_value(root, "seed"));
1,154✔
582
    openmc_set_seed(seed);
577✔
583
  }
584

585
  // Copy random number stride if specified
586
  if (check_for_node(root, "stride")) {
8,396✔
587
    auto stride = std::stoull(get_node_value(root, "stride"));
30✔
588
    openmc_set_stride(stride);
15✔
589
  }
590

591
  // Check for electron treatment
592
  if (check_for_node(root, "electron_treatment")) {
8,396✔
593
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
82✔
594
    if (temp_str == "led") {
82✔
595
      electron_treatment = ElectronTreatment::LED;
26✔
596
    } else if (temp_str == "ttb") {
56!
597
      electron_treatment = ElectronTreatment::TTB;
56✔
598
    } else {
599
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
600
    }
601
  }
82✔
602

603
  // Check for photon transport
604
  if (check_for_node(root, "photon_transport")) {
8,396✔
605
    photon_transport = get_node_value_bool(root, "photon_transport");
287✔
606

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

613
  // Check for atomic relaxation
614
  if (check_for_node(root, "atomic_relaxation")) {
8,396✔
615
    atomic_relaxation = get_node_value_bool(root, "atomic_relaxation");
15✔
616
  }
617

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

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

635
  // ==========================================================================
636
  // EXTERNAL SOURCE
637

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

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

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

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

669
  // Build probability mass function for sampling external sources
670
  vector<double> source_strengths;
8,386✔
671
  for (auto& s : model::external_sources) {
18,349✔
672
    source_strengths.push_back(s->strength());
9,963✔
673
  }
674
  model::external_sources_probability.assign(source_strengths);
8,386✔
675

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

681
  // Get relative number of lost particles
682
  if (check_for_node(root, "source_rejection_fraction")) {
8,386✔
683
    source_rejection_fraction =
14✔
684
      std::stod(get_node_value(root, "source_rejection_fraction"));
14!
685
  }
686

687
  if (check_for_node(root, "free_gas_threshold")) {
8,386!
688
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
689
  }
690

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

699
  // Survival biasing
700
  if (check_for_node(root, "survival_biasing")) {
8,386✔
701
    survival_biasing = get_node_value_bool(root, "survival_biasing");
205✔
702
  }
703

704
  // Probability tables
705
  if (check_for_node(root, "ptables")) {
8,386✔
706
    urr_ptables_on = get_node_value_bool(root, "ptables");
15✔
707
  }
708

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

756
  // read properties from file
757
  if (check_for_node(root, "properties_file")) {
8,386✔
758
    properties_file = get_node_value(root, "properties_file");
11✔
759
    if (!file_exists(properties_file)) {
11!
760
      fatal_error(fmt::format("File '{}' does not exist.", properties_file));
×
761
    }
762
  }
763

764
  // Particle trace
765
  if (check_for_node(root, "trace")) {
8,386✔
766
    auto temp = get_node_array<int64_t>(root, "trace");
15✔
767
    if (temp.size() != 3) {
15!
768
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
769
                  "batch, generation, and particle number.");
770
    }
771
    trace_batch = temp.at(0);
15✔
772
    trace_gen = temp.at(1);
15✔
773
    trace_particle = temp.at(2);
15✔
774
  }
15✔
775

776
  // Particle tracks
777
  if (check_for_node(root, "track")) {
8,386✔
778
    // Get values and make sure there are three per particle
779
    auto temp = get_node_array<int>(root, "track");
45✔
780
    if (temp.size() % 3 != 0) {
45!
781
      fatal_error(
×
782
        "Number of integers specified in 'track' is not "
783
        "divisible by 3.  Please provide 3 integers per particle to be "
784
        "tracked.");
785
    }
786

787
    // Reshape into track_identifiers
788
    int n_tracks = temp.size() / 3;
45✔
789
    for (int i = 0; i < n_tracks; ++i) {
180✔
790
      track_identifiers.push_back(
135✔
791
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
135✔
792
    }
793
  }
45✔
794

795
  // Shannon entropy
796
  if (solver_type == SolverType::RANDOM_RAY) {
8,386✔
797
    if (check_for_node(root, "entropy_mesh")) {
762!
798
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
799
                  "No user-defined entropy mesh is supported.");
800
    }
801
    entropy_on = true;
762✔
802
  } else if (solver_type == SolverType::MONTE_CARLO) {
7,624!
803
    if (check_for_node(root, "entropy_mesh")) {
7,624✔
804
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
668✔
805
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
334!
806
        fatal_error(fmt::format(
×
807
          "Mesh {} specified for Shannon entropy does not exist.", temp));
808
      }
809

810
      auto* m = dynamic_cast<RegularMesh*>(
334!
811
        model::meshes[model::mesh_map.at(temp)].get());
334!
812
      if (!m)
334!
813
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
814
      simulation::entropy_mesh = m;
334✔
815

816
      // Turn on Shannon entropy calculation
817
      entropy_on = true;
334✔
818

819
    } else if (check_for_node(root, "entropy")) {
7,290!
820
      fatal_error(
×
821
        "Specifying a Shannon entropy mesh via the <entropy> element "
822
        "is deprecated. Please create a mesh using <mesh> and then reference "
823
        "it by specifying its ID in an <entropy_mesh> element.");
824
    }
825
  }
826
  // Uniform fission source weighting mesh
827
  if (check_for_node(root, "ufs_mesh")) {
8,386✔
828
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
30✔
829
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
15!
830
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
831
                              "method does not exist.",
832
        temp));
833
    }
834

835
    auto* m =
15✔
836
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
15!
837
    if (!m)
15!
838
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
839
    simulation::ufs_mesh = m;
15✔
840

841
    // Turn on uniform fission source weighting
842
    ufs_on = true;
15✔
843

844
  } else if (check_for_node(root, "uniform_fs")) {
8,371!
845
    fatal_error(
×
846
      "Specifying a UFS mesh via the <uniform_fs> element "
847
      "is deprecated. Please create a mesh using <mesh> and then reference "
848
      "it by specifying its ID in a <ufs_mesh> element.");
849
  }
850

851
  // Check if the user has specified to write state points
852
  if (check_for_node(root, "state_point")) {
8,386✔
853

854
    // Get pointer to state_point node
855
    auto node_sp = root.child("state_point");
160✔
856

857
    // Determine number of batches at which to store state points
858
    if (check_for_node(node_sp, "batches")) {
160!
859
      // User gave specific batches to write state points
860
      auto temp = get_node_array<int>(node_sp, "batches");
160✔
861
      for (const auto& b : temp) {
491✔
862
        statepoint_batch.insert(b);
331✔
863
      }
864
    } else {
160✔
865
      // If neither were specified, write state point at last batch
866
      statepoint_batch.insert(n_batches);
×
867
    }
868
  } else {
869
    // If no <state_point> tag was present, by default write state point at
870
    // last batch only
871
    statepoint_batch.insert(n_batches);
8,226✔
872
  }
873

874
  // Check if the user has specified to write source points
875
  if (check_for_node(root, "source_point")) {
8,386✔
876
    // Get source_point node
877
    xml_node node_sp = root.child("source_point");
101✔
878

879
    // Determine batches at which to store source points
880
    if (check_for_node(node_sp, "batches")) {
101✔
881
      // User gave specific batches to write source points
882
      auto temp = get_node_array<int>(node_sp, "batches");
45✔
883
      for (const auto& b : temp) {
120✔
884
        sourcepoint_batch.insert(b);
75✔
885
      }
886
    } else {
45✔
887
      // If neither were specified, write source points with state points
888
      sourcepoint_batch = statepoint_batch;
56!
889
    }
890

891
    // Check if the user has specified to write binary source file
892
    if (check_for_node(node_sp, "separate")) {
101✔
893
      source_separate = get_node_value_bool(node_sp, "separate");
71✔
894
    }
895
    if (check_for_node(node_sp, "write")) {
101!
896
      source_write = get_node_value_bool(node_sp, "write");
×
897
    }
898
    if (check_for_node(node_sp, "mcpl")) {
101✔
899
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
26✔
900
    }
901
    if (check_for_node(node_sp, "overwrite_latest")) {
101✔
902
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
15✔
903
      source_separate = source_latest;
15✔
904
    }
905
  } else {
906
    // If no <source_point> tag was present, by default we keep source bank in
907
    // statepoint file and write it out at statepoints intervals
908
    source_separate = false;
8,285✔
909
    sourcepoint_batch = statepoint_batch;
8,285!
910
  }
911

912
  // Check is the user specified to convert strength to statistical weight
913
  if (check_for_node(root, "uniform_source_sampling")) {
8,386✔
914
    uniform_source_sampling =
55✔
915
      get_node_value_bool(root, "uniform_source_sampling");
55✔
916
  }
917

918
  // Check if the user has specified to write surface source
919
  if (check_for_node(root, "surf_source_write")) {
8,386✔
920
    surf_source_write = true;
412✔
921
    // Get surface source write node
922
    xml_node node_ssw = root.child("surf_source_write");
412✔
923

924
    // Determine surface ids at which crossing particles are to be banked.
925
    // If no surfaces are specified, all surfaces in the model will be used
926
    // to bank source points.
927
    if (check_for_node(node_ssw, "surface_ids")) {
412✔
928
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
202✔
929
      for (const auto& b : temp) {
994✔
930
        source_write_surf_id.insert(b);
792✔
931
      }
932
    }
202✔
933

934
    // Get maximum number of particles to be banked per surface
935
    if (check_for_node(node_ssw, "max_particles")) {
412✔
936
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
806✔
937
    } else {
938
      fatal_error("A maximum number of particles needs to be specified "
9✔
939
                  "using the 'max_particles' parameter to store surface "
940
                  "source points.");
941
    }
942

943
    // Get maximum number of surface source files to be created
944
    if (check_for_node(node_ssw, "max_source_files")) {
403✔
945
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
66✔
946
    } else {
947
      ssw_max_files = 1;
370✔
948
    }
949

950
    if (check_for_node(node_ssw, "mcpl")) {
403✔
951
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
11✔
952
    }
953
    // Get cell information
954
    if (check_for_node(node_ssw, "cell")) {
403✔
955
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
208✔
956
      ssw_cell_type = SSWCellType::Both;
104✔
957
    }
958
    if (check_for_node(node_ssw, "cellfrom")) {
403✔
959
      if (ssw_cell_id != C_NONE) {
90✔
960
        fatal_error(
18✔
961
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
962
      }
963
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
144✔
964
      ssw_cell_type = SSWCellType::From;
72✔
965
    }
966
    if (check_for_node(node_ssw, "cellto")) {
385✔
967
      if (ssw_cell_id != C_NONE) {
71✔
968
        fatal_error(
18✔
969
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
970
      }
971
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
106✔
972
      ssw_cell_type = SSWCellType::To;
53✔
973
    }
974
  }
975

976
  // Check if the user has specified to write specific collisions
977
  if (check_for_node(root, "collision_track")) {
8,341✔
978
    settings::collision_track = true;
148✔
979
    // Get collision track node
980
    xml_node node_ct = root.child("collision_track");
148✔
981
    collision_track_config = CollisionTrackConfig {};
148✔
982

983
    // Determine cell ids at which crossing particles are to be banked
984
    if (check_for_node(node_ct, "cell_ids")) {
148✔
985
      auto temp = get_node_array<int>(node_ct, "cell_ids");
78✔
986
      for (const auto& b : temp) {
204✔
987
        collision_track_config.cell_ids.insert(b);
126✔
988
      }
989
    }
78✔
990
    if (check_for_node(node_ct, "reactions")) {
148✔
991
      auto temp = get_node_array<std::string>(node_ct, "reactions");
63✔
992
      for (const auto& b : temp) {
171✔
993
        int reaction_int = reaction_mt(b);
108✔
994
        if (reaction_int > 0) {
108!
995
          collision_track_config.mt_numbers.insert(reaction_int);
108✔
996
        }
997
      }
998
    }
63✔
999
    if (check_for_node(node_ct, "universe_ids")) {
148✔
1000
      auto temp = get_node_array<int>(node_ct, "universe_ids");
30✔
1001
      for (const auto& b : temp) {
60✔
1002
        collision_track_config.universe_ids.insert(b);
30✔
1003
      }
1004
    }
30✔
1005
    if (check_for_node(node_ct, "material_ids")) {
148✔
1006
      auto temp = get_node_array<int>(node_ct, "material_ids");
30✔
1007
      for (const auto& b : temp) {
75✔
1008
        collision_track_config.material_ids.insert(b);
45✔
1009
      }
1010
    }
30✔
1011
    if (check_for_node(node_ct, "nuclides")) {
148✔
1012
      auto temp = get_node_array<std::string>(node_ct, "nuclides");
30✔
1013
      for (const auto& b : temp) {
120✔
1014
        collision_track_config.nuclides.insert(b);
90✔
1015
      }
1016
    }
30✔
1017
    if (check_for_node(node_ct, "deposited_E_threshold")) {
148✔
1018
      collision_track_config.deposited_energy_threshold =
60✔
1019
        std::stod(get_node_value(node_ct, "deposited_E_threshold"));
60✔
1020
    }
1021
    // Get maximum number of particles to be banked per collision
1022
    if (check_for_node(node_ct, "max_collisions")) {
148!
1023
      collision_track_config.max_collisions =
296✔
1024
        std::stoll(get_node_value(node_ct, "max_collisions"));
296✔
1025
    } else {
1026
      warning("A maximum number of collisions needs to be specified. "
×
1027
              "By default the code sets 'max_collisions' parameter equals to "
1028
              "1000.");
1029
    }
1030
    // Get maximum number of collision_track files to be created
1031
    if (check_for_node(node_ct, "max_collision_track_files")) {
148!
1032
      collision_track_config.max_files =
×
1033
        std::stoll(get_node_value(node_ct, "max_collision_track_files"));
×
1034
    }
1035
    if (check_for_node(node_ct, "mcpl")) {
148✔
1036
      collision_track_config.mcpl_write = get_node_value_bool(node_ct, "mcpl");
22✔
1037
    }
1038
  }
1039

1040
  // If source is not separate and is to be written out in the statepoint
1041
  // file, make sure that the sourcepoint batch numbers are contained in the
1042
  // statepoint list
1043
  if (!source_separate) {
8,341✔
1044
    for (const auto& b : sourcepoint_batch) {
16,636✔
1045
      if (!contains(statepoint_batch, b)) {
16,762!
1046
        fatal_error(
×
1047
          "Sourcepoint batches are not a subset of statepoint batches.");
1048
      }
1049
    }
1050
  }
1051

1052
  // Check if the user has specified to not reduce tallies at the end of every
1053
  // batch
1054
  if (check_for_node(root, "no_reduce")) {
8,341✔
1055
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
30✔
1056
  }
1057

1058
  // Check if the user has specified to use confidence intervals for
1059
  // uncertainties rather than standard deviations
1060
  if (check_for_node(root, "confidence_intervals")) {
8,341✔
1061
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
15✔
1062
  }
1063

1064
  // Check for output options
1065
  if (check_for_node(root, "output")) {
8,341✔
1066
    // Get pointer to output node
1067
    pugi::xml_node node_output = root.child("output");
779✔
1068

1069
    // Check for summary option
1070
    if (check_for_node(node_output, "summary")) {
779✔
1071
      output_summary = get_node_value_bool(node_output, "summary");
753✔
1072
    }
1073

1074
    // Check for ASCII tallies output option
1075
    if (check_for_node(node_output, "tallies")) {
779✔
1076
      output_tallies = get_node_value_bool(node_output, "tallies");
349✔
1077
    }
1078

1079
    // Set output directory if a path has been specified
1080
    if (check_for_node(node_output, "path")) {
779!
1081
      path_output = get_node_value(node_output, "path");
×
1082
      if (!ends_with(path_output, "/")) {
×
1083
        path_output += "/";
779!
1084
      }
1085
    }
1086
  }
1087

1088
  // Resonance scattering parameters
1089
  if (check_for_node(root, "resonance_scattering")) {
8,341✔
1090
    xml_node node_res_scat = root.child("resonance_scattering");
15✔
1091

1092
    // See if resonance scattering is enabled
1093
    if (check_for_node(node_res_scat, "enable")) {
15!
1094
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
15✔
1095
    } else {
1096
      res_scat_on = true;
×
1097
    }
1098

1099
    // Determine what method is used
1100
    if (check_for_node(node_res_scat, "method")) {
15!
1101
      auto temp = get_node_value(node_res_scat, "method", true, true);
15✔
1102
      if (temp == "rvs") {
15!
1103
        res_scat_method = ResScatMethod::rvs;
15✔
1104
      } else if (temp == "dbrc") {
×
1105
        res_scat_method = ResScatMethod::dbrc;
×
1106
      } else {
1107
        fatal_error(
×
1108
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1109
      }
1110
    }
15✔
1111

1112
    // Minimum energy for resonance scattering
1113
    if (check_for_node(node_res_scat, "energy_min")) {
15!
1114
      res_scat_energy_min =
30✔
1115
        std::stod(get_node_value(node_res_scat, "energy_min"));
30✔
1116
    }
1117
    if (res_scat_energy_min < 0.0) {
15!
1118
      fatal_error("Lower resonance scattering energy bound is negative");
×
1119
    }
1120

1121
    // Maximum energy for resonance scattering
1122
    if (check_for_node(node_res_scat, "energy_max")) {
15!
1123
      res_scat_energy_max =
30✔
1124
        std::stod(get_node_value(node_res_scat, "energy_max"));
30✔
1125
    }
1126
    if (res_scat_energy_max < res_scat_energy_min) {
15!
1127
      fatal_error("Upper resonance scattering energy bound is below the "
×
1128
                  "lower resonance scattering energy bound.");
1129
    }
1130

1131
    // Get resonance scattering nuclides
1132
    if (check_for_node(node_res_scat, "nuclides")) {
15!
1133
      res_scat_nuclides =
15✔
1134
        get_node_array<std::string>(node_res_scat, "nuclides");
30✔
1135
    }
1136
  }
1137

1138
  // Get volume calculations
1139
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
8,655✔
1140
    model::volume_calcs.emplace_back(node_vol);
314✔
1141
  }
1142

1143
  // Get temperature settings
1144
  if (check_for_node(root, "temperature_default")) {
8,341✔
1145
    temperature_default =
342✔
1146
      std::stod(get_node_value(root, "temperature_default"));
342✔
1147
  }
1148
  if (check_for_node(root, "temperature_method")) {
8,341✔
1149
    auto temp = get_node_value(root, "temperature_method", true, true);
485✔
1150
    if (temp == "nearest") {
485✔
1151
      temperature_method = TemperatureMethod::NEAREST;
304✔
1152
    } else if (temp == "interpolation") {
181!
1153
      temperature_method = TemperatureMethod::INTERPOLATION;
181✔
1154
    } else {
1155
      fatal_error("Unknown temperature method: " + temp);
×
1156
    }
1157
  }
485✔
1158
  if (check_for_node(root, "temperature_tolerance")) {
8,341✔
1159
    temperature_tolerance =
680✔
1160
      std::stod(get_node_value(root, "temperature_tolerance"));
680✔
1161
  }
1162
  if (check_for_node(root, "temperature_multipole")) {
8,341✔
1163
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
185✔
1164

1165
    // Multipole currently doesn't work with photon transport
1166
    if (temperature_multipole && photon_transport) {
185!
1167
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1168
                  "photon transport.");
1169
    }
1170
  }
1171
  if (check_for_node(root, "temperature_range")) {
8,341✔
1172
    auto range = get_node_array<double>(root, "temperature_range");
170✔
1173
    temperature_range[0] = range.at(0);
170✔
1174
    temperature_range[1] = range.at(1);
170✔
1175
  }
170✔
1176

1177
  // Check for tabular_legendre options
1178
  if (check_for_node(root, "tabular_legendre")) {
8,341✔
1179
    // Get pointer to tabular_legendre node
1180
    xml_node node_tab_leg = root.child("tabular_legendre");
105✔
1181

1182
    // Check for enable option
1183
    if (check_for_node(node_tab_leg, "enable")) {
105!
1184
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
105✔
1185
    }
1186

1187
    // Check for the number of points
1188
    if (check_for_node(node_tab_leg, "num_points")) {
105!
1189
      legendre_to_tabular_points =
×
1190
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
1191
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
1192
        fatal_error(
×
1193
          "The 'num_points' subelement/attribute of the "
1194
          "<tabular_legendre> element must contain a value greater than 1");
1195
      }
1196
    }
1197
  }
1198

1199
  // Check whether create delayed neutrons in fission
1200
  if (check_for_node(root, "create_delayed_neutrons")) {
8,341!
1201
    create_delayed_neutrons =
×
1202
      get_node_value_bool(root, "create_delayed_neutrons");
×
1203
  }
1204

1205
  // Check whether create fission sites
1206
  if (run_mode == RunMode::FIXED_SOURCE) {
8,341✔
1207
    if (check_for_node(root, "create_fission_neutrons")) {
2,981✔
1208
      create_fission_neutrons =
325✔
1209
        get_node_value_bool(root, "create_fission_neutrons");
325✔
1210
    }
1211
  }
1212

1213
  // Check whether to scale fission photon yields
1214
  if (check_for_node(root, "delayed_photon_scaling")) {
8,341!
1215
    delayed_photon_scaling =
×
1216
      get_node_value_bool(root, "delayed_photon_scaling");
×
1217
  }
1218

1219
  // Check whether to use event-based parallelism
1220
  if (check_for_node(root, "event_based")) {
8,341!
1221
    event_based = get_node_value_bool(root, "event_based");
×
1222
  }
1223

1224
  // Check whether material cell offsets should be generated
1225
  if (check_for_node(root, "material_cell_offsets")) {
8,341!
1226
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1227
  }
1228

1229
  // Weight window information
1230
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
8,558✔
1231
    variance_reduction::weight_windows.emplace_back(
217✔
1232
      std::make_unique<WeightWindows>(node_ww));
434✔
1233
  }
1234

1235
  // Enable weight windows by default if one or more are present
1236
  if (variance_reduction::weight_windows.size() > 0)
8,341✔
1237
    settings::weight_windows_on = true;
165✔
1238

1239
  // read weight windows from file
1240
  if (check_for_node(root, "weight_windows_file")) {
8,341!
1241
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1242
  }
1243

1244
  // read settings for weight windows value, this will override
1245
  // the automatic setting even if weight windows are present
1246
  if (check_for_node(root, "weight_windows_on")) {
8,341✔
1247
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
60✔
1248
  }
1249

1250
  if (check_for_node(root, "max_secondaries")) {
8,341!
1251
    settings::max_secondaries =
×
1252
      std::stoi(get_node_value(root, "max_secondaries"));
×
1253
  }
1254

1255
  if (check_for_node(root, "max_history_splits")) {
8,341✔
1256
    settings::max_history_splits =
592✔
1257
      std::stoi(get_node_value(root, "max_history_splits"));
592✔
1258
  }
1259

1260
  if (check_for_node(root, "max_tracks")) {
8,341✔
1261
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
90✔
1262
  }
1263

1264
  // Create weight window generator objects
1265
  if (check_for_node(root, "weight_window_generators")) {
8,341✔
1266
    auto wwgs_node = root.child("weight_window_generators");
90✔
1267
    for (pugi::xml_node node_wwg :
180✔
1268
      wwgs_node.children("weight_windows_generator")) {
180✔
1269
      variance_reduction::weight_windows_generators.emplace_back(
90✔
1270
        std::make_unique<WeightWindowsGenerator>(node_wwg));
180✔
1271
    }
1272
    // if any of the weight windows are intended to be generated otf, make
1273
    // sure they're applied
1274
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
90!
1275
      if (wwg->on_the_fly_) {
90!
1276
        settings::weight_windows_on = true;
90✔
1277
        break;
90✔
1278
      }
1279
    }
1280
  }
1281

1282
  // Set up weight window checkpoints
1283
  if (check_for_node(root, "weight_window_checkpoints")) {
8,341✔
1284
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
92✔
1285
    if (check_for_node(ww_checkpoints, "collision")) {
92!
1286
      weight_window_checkpoint_collision =
92✔
1287
        get_node_value_bool(ww_checkpoints, "collision");
92✔
1288
    }
1289
    if (check_for_node(ww_checkpoints, "surface")) {
92!
1290
      weight_window_checkpoint_surface =
92✔
1291
        get_node_value_bool(ww_checkpoints, "surface");
92✔
1292
    }
1293
  }
1294

1295
  if (weight_windows_on) {
8,341✔
1296
    if (!weight_window_checkpoint_surface &&
255✔
1297
        !weight_window_checkpoint_collision)
163!
1298
      fatal_error(
×
1299
        "Weight Windows are enabled but there are no valid checkpoints.");
1300
  }
1301

1302
  if (check_for_node(root, "use_decay_photons")) {
8,341✔
1303
    settings::use_decay_photons =
11✔
1304
      get_node_value_bool(root, "use_decay_photons");
11✔
1305
  }
1306

1307
  // If weight windows are on, also enable shared secondary bank (unless
1308
  // explicitly disabled by user).
1309
  if (check_for_node(root, "shared_secondary_bank")) {
8,341✔
1310
    bool val = get_node_value_bool(root, "shared_secondary_bank");
261✔
1311
    if (val && run_mode == RunMode::EIGENVALUE) {
261!
NEW
1312
      warning(
×
1313
        "Shared secondary bank is not supported in eigenvalue calculations. "
1314
        "Setting will be ignored.");
1315
    } else {
1316
      settings::use_shared_secondary_bank = val;
261✔
1317
    }
1318
  } else if (settings::weight_windows_on) {
8,080✔
1319
    if (run_mode == RunMode::EIGENVALUE) {
106✔
1320
      warning(
22✔
1321
        "Shared secondary bank is not supported in eigenvalue calculations. "
1322
        "Particle local secondary banks will be used instead.");
1323
    } else if (run_mode == RunMode::FIXED_SOURCE) {
95!
1324
      settings::use_shared_secondary_bank = true;
95✔
1325
    }
1326
  }
1327
}
8,341✔
1328

1329
void free_memory_settings()
8,492✔
1330
{
1331
  settings::statepoint_batch.clear();
8,492✔
1332
  settings::sourcepoint_batch.clear();
8,492✔
1333
  settings::source_write_surf_id.clear();
8,492✔
1334
  settings::res_scat_nuclides.clear();
8,492✔
1335
}
8,492✔
1336

1337
//==============================================================================
1338
// C API functions
1339
//==============================================================================
1340

1341
extern "C" int openmc_set_n_batches(
44✔
1342
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1343
{
1344
  if (settings::n_inactive >= n_batches) {
44✔
1345
    set_errmsg("Number of active batches must be greater than zero.");
11✔
1346
    return OPENMC_E_INVALID_ARGUMENT;
11✔
1347
  }
1348

1349
  if (!settings::trigger_on) {
33✔
1350
    // Set n_batches and n_max_batches to same value
1351
    settings::n_batches = n_batches;
11✔
1352
    settings::n_max_batches = n_batches;
11✔
1353
  } else {
1354
    // Set n_batches and n_max_batches based on value of set_max_batches
1355
    if (set_max_batches) {
22✔
1356
      settings::n_max_batches = n_batches;
11✔
1357
    } else {
1358
      settings::n_batches = n_batches;
11✔
1359
    }
1360
  }
1361

1362
  // Update size of k_generation and entropy
1363
  int m = settings::n_max_batches * settings::gen_per_batch;
33✔
1364
  simulation::k_generation.reserve(m);
33✔
1365
  simulation::entropy.reserve(m);
33✔
1366

1367
  // Add value of n_batches to statepoint_batch
1368
  if (add_statepoint_batch &&
33✔
1369
      !(contains(settings::statepoint_batch, n_batches)))
22!
1370
    settings::statepoint_batch.insert(n_batches);
22✔
1371

1372
  return 0;
1373
}
1374

1375
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,530✔
1376
{
1377
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,530✔
1378

1379
  return 0;
2,530✔
1380
}
1381

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