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

openmc-dev / openmc / 29109839871

10 Jul 2026 05:07PM UTC coverage: 81.355% (+0.06%) from 81.295%
29109839871

Pull #3971

github

web-flow
Merge b03e8c77b into 7256d5046
Pull Request #3971: Delta tracking

18567 of 26880 branches covered (69.07%)

Branch coverage included in aggregate %.

604 of 650 new or added lines in 20 files covered. (92.92%)

59962 of 69646 relevant lines covered (86.1%)

49564145.57 hits per line

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

76.41
/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 delta_tracking {false};
57
bool entropy_on {false};
58
bool event_based {false};
59
bool ifp_on {false};
60
bool legendre_to_tabular {true};
61
bool material_cell_offsets {true};
62
bool output_summary {true};
63
bool output_tallies {true};
64
bool particle_restart_run {false};
65
bool photon_transport {false};
66
bool atomic_relaxation {true};
67
bool reduce_tallies {true};
68
bool res_scat_on {false};
69
bool restart_run {false};
70
bool run_CE {true};
71
bool source_latest {false};
72
bool source_separate {false};
73
bool source_write {true};
74
bool source_mcpl_write {false};
75
bool surf_source_write {false};
76
bool surf_mcpl_write {false};
77
bool surf_source_read {false};
78
bool survival_biasing {false};
79
bool survival_normalization {false};
80
bool temperature_multipole {false};
81
bool trigger_on {false};
82
bool trigger_predict {false};
83
bool uniform_source_sampling {false};
84
bool ufs_on {false};
85
bool urr_ptables_on {true};
86
bool use_decay_photons {false};
87
bool use_shared_secondary_bank {false};
88
bool weight_windows_on {false};
89
bool weight_window_checkpoint_surface {false};
90
bool weight_window_checkpoint_collision {true};
91
bool write_all_tracks {false};
92
bool write_initial_source {false};
93

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

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

111
int64_t max_particles_in_flight {100000};
112
int max_particle_events {1000000};
113

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

158
} // namespace settings
159

160
//==============================================================================
161
// Functions
162
//==============================================================================
163

164
void get_run_parameters(pugi::xml_node node_base)
8,127✔
165
{
166
  using namespace settings;
8,127✔
167
  using namespace pugi;
8,127✔
168

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

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

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

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

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

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

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

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

216
  // Get number of inactive batches
217
  if (run_mode == RunMode::EIGENVALUE ||
8,127✔
218
      solver_type == SolverType::RANDOM_RAY) {
3,313✔
219
    if (check_for_node(node_base, "inactive")) {
5,250✔
220
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,995✔
221
    }
222
    if (check_for_node(node_base, "generations_per_batch")) {
5,250✔
223
      gen_per_batch =
30✔
224
        std::stoi(get_node_value(node_base, "generations_per_batch"));
15✔
225
    }
226

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

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

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

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

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

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

404
  // Parse settings.xml file
405
  xml_document doc;
1,387✔
406
  auto result = doc.load_file(filename.c_str());
1,387✔
407
  if (!result) {
1,387!
408
    fatal_error("Error processing settings.xml file.");
×
409
  }
410

411
  // Get root element
412
  xml_node root = doc.document_element();
1,387✔
413

414
  // Verbosity
415
  if (check_for_node(root, "verbosity") && verbosity == -1) {
1,387!
416
    verbosity = std::stoi(get_node_value(root, "verbosity"));
428✔
417
  } else if (verbosity == -1) {
1,173!
418
    verbosity = 7;
1,173✔
419
  }
420

421
  // To this point, we haven't displayed any output since we didn't know what
422
  // the verbosity is. Now that we checked for it, show the title if necessary
423
  if (mpi::master) {
1,387✔
424
    if (verbosity >= 2)
1,199✔
425
      title();
993✔
426
  }
427

428
  write_message("Reading settings XML file...", 5);
1,387✔
429

430
  read_settings_xml(root);
1,387✔
431
}
1,399✔
432

433
void read_settings_xml(pugi::xml_node root)
9,078✔
434
{
435
  using namespace settings;
9,078✔
436
  using namespace pugi;
9,078✔
437

438
  // Find if a multi-group or continuous-energy simulation is desired
439
  if (check_for_node(root, "energy_mode")) {
9,078✔
440
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
1,357✔
441
    if (temp_str == "mg" || temp_str == "multi-group") {
2,714!
442
      run_CE = false;
1,357✔
443
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
444
      run_CE = true;
×
445
    }
446
  }
1,357✔
447

448
  // Check for user meshes and allocate
449
  read_meshes(root);
9,078✔
450

451
  // Look for deprecated cross_sections.xml file in settings.xml
452
  if (check_for_node(root, "cross_sections")) {
9,078!
453
    warning(
×
454
      "Setting cross_sections in settings.xml has been deprecated."
455
      " The cross_sections are now set in materials.xml and the "
456
      "cross_sections input to materials.xml and the OPENMC_CROSS_SECTIONS"
457
      " environment variable will take precendent over setting "
458
      "cross_sections in settings.xml.");
459
    path_cross_sections = get_node_value(root, "cross_sections");
×
460
  }
461

462
  if (!run_CE) {
9,078✔
463
    // Scattering Treatments
464
    if (check_for_node(root, "max_order")) {
1,357✔
465
      max_order = std::stoi(get_node_value(root, "max_order"));
30✔
466
    } else {
467
      // Set to default of largest int - 1, which means to use whatever is
468
      // contained in library. This is largest int - 1 because for legendre
469
      // scattering, a value of 1 is added to the order; adding 1 to the largest
470
      // int gets you the largest negative integer, which is not what we want.
471
      max_order = std::numeric_limits<int>::max() - 1;
1,342✔
472
    }
473
  }
474

475
  // Check for a trigger node and get trigger information
476
  if (check_for_node(root, "trigger")) {
9,078✔
477
    xml_node node_trigger = root.child("trigger");
156✔
478

479
    // Check if trigger(s) are to be turned on
480
    trigger_on = get_node_value_bool(node_trigger, "active");
156✔
481

482
    if (trigger_on) {
156✔
483
      if (check_for_node(node_trigger, "max_batches")) {
141!
484
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
282✔
485
      } else {
486
        fatal_error("<max_batches> must be specified with triggers");
×
487
      }
488

489
      // Get the batch interval to check triggers
490
      if (!check_for_node(node_trigger, "batch_interval")) {
141✔
491
        trigger_predict = true;
15✔
492
      } else {
493
        trigger_batch_interval =
252✔
494
          std::stoi(get_node_value(node_trigger, "batch_interval"));
252✔
495
        if (trigger_batch_interval <= 0) {
126!
496
          fatal_error("Trigger batch interval must be greater than zero");
×
497
        }
498
      }
499
    }
500
  }
501

502
  // Check run mode if it hasn't been set from the command line
503
  xml_node node_mode;
9,078✔
504
  if (run_mode == RunMode::UNSET) {
9,078✔
505
    if (check_for_node(root, "run_mode")) {
8,159✔
506
      std::string temp_str = get_node_value(root, "run_mode", true, true);
8,129✔
507
      if (temp_str == "eigenvalue") {
8,129✔
508
        run_mode = RunMode::EIGENVALUE;
4,784✔
509
      } else if (temp_str == "fixed source") {
3,345✔
510
        run_mode = RunMode::FIXED_SOURCE;
3,313✔
511
      } else if (temp_str == "plot") {
32!
512
        run_mode = RunMode::PLOTTING;
×
513
      } else if (temp_str == "particle restart") {
32!
514
        run_mode = RunMode::PARTICLE;
×
515
      } else if (temp_str == "volume") {
32!
516
        run_mode = RunMode::VOLUME;
32✔
517
      } else {
518
        fatal_error("Unrecognized run mode: " + temp_str);
×
519
      }
520

521
      // Assume XML specifies <particles>, <batches>, etc. directly
522
      node_mode = root;
8,129✔
523
    } else {
8,129✔
524
      warning("<run_mode> should be specified.");
30✔
525

526
      // Make sure that either eigenvalue or fixed source was specified
527
      node_mode = root.child("eigenvalue");
30✔
528
      if (node_mode) {
30!
529
        run_mode = RunMode::EIGENVALUE;
30✔
530
      } else {
531
        node_mode = root.child("fixed_source");
×
532
        if (node_mode) {
×
533
          run_mode = RunMode::FIXED_SOURCE;
×
534
        } else {
535
          fatal_error("<eigenvalue> or <fixed_source> not specified.");
×
536
        }
537
      }
538
    }
539
  }
540

541
  // Check solver type
542
  if (check_for_node(root, "random_ray")) {
9,078✔
543
    solver_type = SolverType::RANDOM_RAY;
792✔
544
    if (run_CE)
792!
545
      fatal_error("multi-group energy mode must be specified in settings XML "
×
546
                  "when using the random ray solver.");
547
  }
548

549
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
9,078✔
550
    // Read run parameters
551
    get_run_parameters(node_mode);
8,127✔
552

553
    // Check number of active batches, inactive batches, max lost particles and
554
    // particles
555
    if (n_batches <= n_inactive) {
8,127!
556
      fatal_error("Number of active batches must be greater than zero.");
×
557
    } else if (n_inactive < 0) {
8,127!
558
      fatal_error("Number of inactive batches must be non-negative.");
×
559
    } else if (n_particles <= 0) {
8,127!
560
      fatal_error("Number of particles must be greater than zero.");
×
561
    } else if (max_lost_particles <= 0) {
8,127!
562
      fatal_error("Number of max lost particles must be greater than zero.");
×
563
    } else if (rel_max_lost_particles <= 0.0 || rel_max_lost_particles >= 1.0) {
8,127!
564
      fatal_error("Relative max lost particles must be between zero and one.");
×
565
    }
566

567
    // Check for user value for the number of generation of the Iterated Fission
568
    // Probability (IFP) method
569
    if (check_for_node(root, "ifp_n_generation")) {
8,127✔
570
      ifp_n_generation = std::stoi(get_node_value(root, "ifp_n_generation"));
166✔
571
      if (ifp_n_generation <= 0) {
83!
572
        fatal_error("'ifp_n_generation' must be greater than 0.");
×
573
      }
574
      // Avoid tallying 0 if IFP logs are not complete when active cycles start
575
      if (ifp_n_generation > n_inactive) {
83✔
576
        fatal_error("'ifp_n_generation' must be lower than or equal to the "
9✔
577
                    "number of inactive cycles.");
578
      }
579
    }
580
  }
581

582
  // Copy plotting random number seed if specified
583
  if (check_for_node(root, "plot_seed")) {
9,069!
584
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
585
    model::plotter_seed = seed;
×
586
  }
587

588
  // Copy random number seed if specified
589
  if (check_for_node(root, "seed")) {
9,069✔
590
    auto seed = std::stoll(get_node_value(root, "seed"));
1,178✔
591
    openmc_set_seed(seed);
589✔
592
  }
593

594
  // Copy random number stride if specified
595
  if (check_for_node(root, "stride")) {
9,069✔
596
    auto stride = std::stoull(get_node_value(root, "stride"));
30✔
597
    openmc_set_stride(stride);
15✔
598
  }
599

600
  // Check for electron treatment
601
  if (check_for_node(root, "electron_treatment")) {
9,069✔
602
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
82✔
603
    if (temp_str == "led") {
82✔
604
      electron_treatment = ElectronTreatment::LED;
26✔
605
    } else if (temp_str == "ttb") {
56!
606
      electron_treatment = ElectronTreatment::TTB;
56✔
607
    } else {
608
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
609
    }
610
  }
82✔
611

612
  // Check for photon transport
613
  if (check_for_node(root, "photon_transport")) {
9,069✔
614
    photon_transport = get_node_value_bool(root, "photon_transport");
566✔
615

616
    if (!run_CE && photon_transport) {
566!
617
      fatal_error("Photon transport is not currently supported in "
×
618
                  "multigroup mode");
619
    }
620
  }
621

622
  // Check for atomic relaxation
623
  if (check_for_node(root, "atomic_relaxation")) {
9,069✔
624
    atomic_relaxation = get_node_value_bool(root, "atomic_relaxation");
15✔
625
  }
626

627
  // Number of bins for logarithmic grid
628
  if (check_for_node(root, "log_grid_bins")) {
9,069✔
629
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
30✔
630
    if (n_log_bins < 1) {
15!
631
      fatal_error("Number of bins for logarithmic grid must be greater "
×
632
                  "than zero.");
633
    }
634
  }
635

636
  // Number of OpenMP threads
637
  if (check_for_node(root, "threads")) {
9,069!
638
    if (mpi::master)
×
639
      warning("The <threads> element has been deprecated. Use "
×
640
              "the OMP_NUM_THREADS environment variable to set the number of "
641
              "threads.");
642
  }
643

644
  // ==========================================================================
645
  // EXTERNAL SOURCE
646

647
  // Get point to list of <source> elements and make sure there is at least one
648
  for (pugi::xml_node node : root.children("source")) {
17,320✔
649
    model::external_sources.push_back(Source::create(node));
16,512✔
650
  }
651

652
  // Check if the user has specified to read surface source
653
  if (check_for_node(root, "surf_source_read")) {
9,059✔
654
    surf_source_read = true;
30✔
655
    // Get surface source read node
656
    xml_node node_ssr = root.child("surf_source_read");
30✔
657

658
    std::string path = "surface_source.h5";
30✔
659
    // Check if the user has specified different file for surface source reading
660
    if (check_for_node(node_ssr, "path")) {
30!
661
      path = get_node_value(node_ssr, "path", false, true);
30✔
662
    }
663
    model::external_sources.push_back(make_unique<FileSource>(path));
30✔
664
  }
30✔
665

666
  // If no source specified, default to isotropic point source at origin with
667
  // Watt spectrum. No default source is needed in random ray mode.
668
  if (model::external_sources.empty() &&
9,059✔
669
      settings::solver_type != SolverType::RANDOM_RAY) {
2,501✔
670
    double T[] {0.0};
2,355✔
671
    double p[] {1.0};
2,355✔
672
    model::external_sources.push_back(make_unique<IndependentSource>(
2,355✔
673
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
4,710✔
674
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
4,710✔
675
      UPtrDist {new Discrete(T, p, 1)}));
4,710✔
676
  }
677

678
  // Build probability mass function for sampling external sources
679
  vector<double> source_strengths;
9,059✔
680
  for (auto& s : model::external_sources) {
19,695✔
681
    source_strengths.push_back(s->strength());
10,636✔
682
  }
683
  model::external_sources_probability.assign(source_strengths);
9,059✔
684

685
  // Check if we want to write out source
686
  if (check_for_node(root, "write_initial_source")) {
9,059!
687
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
688
  }
689

690
  // Get relative number of lost particles
691
  if (check_for_node(root, "source_rejection_fraction")) {
9,059✔
692
    source_rejection_fraction =
14✔
693
      std::stod(get_node_value(root, "source_rejection_fraction"));
14!
694
  }
695

696
  if (check_for_node(root, "free_gas_threshold")) {
9,059!
697
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
698
  }
699

700
  // Surface grazing
701
  if (check_for_node(root, "surface_grazing_cutoff"))
9,059!
702
    surface_grazing_cutoff =
×
703
      std::stod(get_node_value(root, "surface_grazing_cutoff"));
×
704
  if (check_for_node(root, "surface_grazing_ratio"))
9,059!
705
    surface_grazing_ratio =
×
706
      std::stod(get_node_value(root, "surface_grazing_ratio"));
×
707

708
  // Survival biasing
709
  if (check_for_node(root, "survival_biasing")) {
9,059✔
710
    survival_biasing = get_node_value_bool(root, "survival_biasing");
205✔
711
  }
712

713
  // Probability tables
714
  if (check_for_node(root, "ptables")) {
9,059✔
715
    urr_ptables_on = get_node_value_bool(root, "ptables");
15✔
716
  }
717

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

765
  // read properties from file
766
  if (check_for_node(root, "properties_file")) {
9,059✔
767
    properties_file = get_node_value(root, "properties_file");
11✔
768
    if (!file_exists(properties_file)) {
11!
769
      fatal_error(fmt::format("File '{}' does not exist.", properties_file));
×
770
    }
771
  }
772

773
  // Particle trace
774
  if (check_for_node(root, "trace")) {
9,059✔
775
    auto temp = get_node_array<int64_t>(root, "trace");
15✔
776
    if (temp.size() != 3) {
15!
777
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
778
                  "batch, generation, and particle number.");
779
    }
780
    trace_batch = temp.at(0);
15✔
781
    trace_gen = temp.at(1);
15✔
782
    trace_particle = temp.at(2);
15✔
783
  }
15✔
784

785
  // Particle tracks
786
  if (check_for_node(root, "track")) {
9,059✔
787
    // Get values and make sure there are three per particle
788
    auto temp = get_node_array<int>(root, "track");
45✔
789
    if (temp.size() % 3 != 0) {
45!
790
      fatal_error(
×
791
        "Number of integers specified in 'track' is not "
792
        "divisible by 3.  Please provide 3 integers per particle to be "
793
        "tracked.");
794
    }
795

796
    // Reshape into track_identifiers
797
    int n_tracks = temp.size() / 3;
45✔
798
    for (int i = 0; i < n_tracks; ++i) {
180✔
799
      track_identifiers.push_back(
135✔
800
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
135✔
801
    }
802
  }
45✔
803

804
  // Shannon entropy
805
  if (solver_type == SolverType::RANDOM_RAY) {
9,059✔
806
    if (check_for_node(root, "entropy_mesh")) {
792!
807
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
808
                  "No user-defined entropy mesh is supported.");
809
    }
810
    entropy_on = true;
792✔
811
  } else if (solver_type == SolverType::MONTE_CARLO) {
8,267!
812
    if (check_for_node(root, "entropy_mesh")) {
8,267✔
813
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
668✔
814
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
334!
815
        fatal_error(fmt::format(
×
816
          "Mesh {} specified for Shannon entropy does not exist.", temp));
817
      }
818

819
      auto* m = dynamic_cast<RegularMesh*>(
334!
820
        model::meshes[model::mesh_map.at(temp)].get());
334!
821
      if (!m)
334!
822
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
823
      simulation::entropy_mesh = m;
334✔
824

825
      // Turn on Shannon entropy calculation
826
      entropy_on = true;
334✔
827

828
    } else if (check_for_node(root, "entropy")) {
7,933!
829
      fatal_error(
×
830
        "Specifying a Shannon entropy mesh via the <entropy> element "
831
        "is deprecated. Please create a mesh using <mesh> and then reference "
832
        "it by specifying its ID in an <entropy_mesh> element.");
833
    }
834
  }
835
  // Uniform fission source weighting mesh
836
  if (check_for_node(root, "ufs_mesh")) {
9,059✔
837
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
30✔
838
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
15!
839
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
840
                              "method does not exist.",
841
        temp));
842
    }
843

844
    auto* m =
15✔
845
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
15!
846
    if (!m)
15!
847
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
848
    simulation::ufs_mesh = m;
15✔
849

850
    // Turn on uniform fission source weighting
851
    ufs_on = true;
15✔
852

853
  } else if (check_for_node(root, "uniform_fs")) {
9,044!
854
    fatal_error(
×
855
      "Specifying a UFS mesh via the <uniform_fs> element "
856
      "is deprecated. Please create a mesh using <mesh> and then reference "
857
      "it by specifying its ID in a <ufs_mesh> element.");
858
  }
859

860
  // Check if the user has specified to write state points
861
  if (check_for_node(root, "state_point")) {
9,059✔
862

863
    // Get pointer to state_point node
864
    auto node_sp = root.child("state_point");
160✔
865

866
    // Determine number of batches at which to store state points
867
    if (check_for_node(node_sp, "batches")) {
160!
868
      // User gave specific batches to write state points
869
      auto temp = get_node_array<int>(node_sp, "batches");
160✔
870
      for (const auto& b : temp) {
491✔
871
        statepoint_batch.insert(b);
331✔
872
      }
873
    } else {
160✔
874
      // If neither were specified, write state point at last batch
875
      statepoint_batch.insert(n_batches);
×
876
    }
877
  } else {
878
    // If no <state_point> tag was present, by default write state point at
879
    // last batch only
880
    statepoint_batch.insert(n_batches);
8,899✔
881
  }
882

883
  // Check if the user has specified to write source points
884
  if (check_for_node(root, "source_point")) {
9,059✔
885
    // Get source_point node
886
    xml_node node_sp = root.child("source_point");
101✔
887

888
    // Determine batches at which to store source points
889
    if (check_for_node(node_sp, "batches")) {
101✔
890
      // User gave specific batches to write source points
891
      auto temp = get_node_array<int>(node_sp, "batches");
45✔
892
      for (const auto& b : temp) {
120✔
893
        sourcepoint_batch.insert(b);
75✔
894
      }
895
    } else {
45✔
896
      // If neither were specified, write source points with state points
897
      sourcepoint_batch = statepoint_batch;
56!
898
    }
899

900
    // Check if the user has specified to write binary source file
901
    if (check_for_node(node_sp, "separate")) {
101✔
902
      source_separate = get_node_value_bool(node_sp, "separate");
71✔
903
    }
904
    if (check_for_node(node_sp, "write")) {
101!
905
      source_write = get_node_value_bool(node_sp, "write");
×
906
    }
907
    if (check_for_node(node_sp, "mcpl")) {
101✔
908
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
26✔
909
    }
910
    if (check_for_node(node_sp, "overwrite_latest")) {
101✔
911
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
15✔
912
      source_separate = source_latest;
15✔
913
    }
914
  } else {
915
    // If no <source_point> tag was present, by default we keep source bank in
916
    // statepoint file and write it out at statepoints intervals
917
    source_separate = false;
8,958✔
918
    sourcepoint_batch = statepoint_batch;
8,958!
919
  }
920

921
  // Check is the user specified to convert strength to statistical weight
922
  if (check_for_node(root, "uniform_source_sampling")) {
9,059✔
923
    uniform_source_sampling =
55✔
924
      get_node_value_bool(root, "uniform_source_sampling");
55✔
925
  }
926

927
  // Check if the user has specified to write surface source
928
  if (check_for_node(root, "surf_source_write")) {
9,059✔
929
    surf_source_write = true;
412✔
930
    // Get surface source write node
931
    xml_node node_ssw = root.child("surf_source_write");
412✔
932

933
    // Determine surface ids at which crossing particles are to be banked.
934
    // If no surfaces are specified, all surfaces in the model will be used
935
    // to bank source points.
936
    if (check_for_node(node_ssw, "surface_ids")) {
412✔
937
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
202✔
938
      for (const auto& b : temp) {
994✔
939
        source_write_surf_id.insert(b);
792✔
940
      }
941
    }
202✔
942

943
    // Get maximum number of particles to be banked per surface
944
    if (check_for_node(node_ssw, "max_particles")) {
412✔
945
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
806✔
946
    } else {
947
      fatal_error("A maximum number of particles needs to be specified "
9✔
948
                  "using the 'max_particles' parameter to store surface "
949
                  "source points.");
950
    }
951

952
    // Get maximum number of surface source files to be created
953
    if (check_for_node(node_ssw, "max_source_files")) {
403✔
954
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
66✔
955
    } else {
956
      ssw_max_files = 1;
370✔
957
    }
958

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

985
  // Check if the user has specified to write specific collisions
986
  if (check_for_node(root, "collision_track")) {
9,014✔
987
    settings::collision_track = true;
160✔
988
    // Get collision track node
989
    xml_node node_ct = root.child("collision_track");
160✔
990
    collision_track_config = CollisionTrackConfig {};
160✔
991

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

1049
  // If source is not separate and is to be written out in the statepoint
1050
  // file, make sure that the sourcepoint batch numbers are contained in the
1051
  // statepoint list
1052
  if (!source_separate) {
9,014✔
1053
    for (const auto& b : sourcepoint_batch) {
17,982✔
1054
      if (!contains(statepoint_batch, b)) {
18,108!
1055
        fatal_error(
×
1056
          "Sourcepoint batches are not a subset of statepoint batches.");
1057
      }
1058
    }
1059
  }
1060

1061
  // Check if the user has specified to not reduce tallies at the end of every
1062
  // batch
1063
  if (check_for_node(root, "no_reduce")) {
9,014✔
1064
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
30✔
1065
  }
1066

1067
  // Check if the user has specified to use confidence intervals for
1068
  // uncertainties rather than standard deviations
1069
  if (check_for_node(root, "confidence_intervals")) {
9,014✔
1070
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
15✔
1071
  }
1072

1073
  // Check for output options
1074
  if (check_for_node(root, "output")) {
9,014✔
1075
    // Get pointer to output node
1076
    pugi::xml_node node_output = root.child("output");
823✔
1077

1078
    // Check for summary option
1079
    if (check_for_node(node_output, "summary")) {
823✔
1080
      output_summary = get_node_value_bool(node_output, "summary");
797✔
1081
    }
1082

1083
    // Check for ASCII tallies output option
1084
    if (check_for_node(node_output, "tallies")) {
823✔
1085
      output_tallies = get_node_value_bool(node_output, "tallies");
349✔
1086
    }
1087

1088
    // Set output directory if a path has been specified
1089
    if (check_for_node(node_output, "path")) {
823!
1090
      path_output = get_node_value(node_output, "path");
×
1091
      if (!ends_with(path_output, "/")) {
×
1092
        path_output += "/";
823!
1093
      }
1094
    }
1095
  }
1096

1097
  // Resonance scattering parameters
1098
  if (check_for_node(root, "resonance_scattering")) {
9,014✔
1099
    xml_node node_res_scat = root.child("resonance_scattering");
15✔
1100

1101
    // See if resonance scattering is enabled
1102
    if (check_for_node(node_res_scat, "enable")) {
15!
1103
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
15✔
1104
    } else {
1105
      res_scat_on = true;
×
1106
    }
1107

1108
    // Determine what method is used
1109
    if (check_for_node(node_res_scat, "method")) {
15!
1110
      auto temp = get_node_value(node_res_scat, "method", true, true);
15✔
1111
      if (temp == "rvs") {
15!
1112
        res_scat_method = ResScatMethod::rvs;
15✔
1113
      } else if (temp == "dbrc") {
×
1114
        res_scat_method = ResScatMethod::dbrc;
×
1115
      } else {
1116
        fatal_error(
×
1117
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1118
      }
1119
    }
15✔
1120

1121
    // Minimum energy for resonance scattering
1122
    if (check_for_node(node_res_scat, "energy_min")) {
15!
1123
      res_scat_energy_min =
30✔
1124
        std::stod(get_node_value(node_res_scat, "energy_min"));
30✔
1125
    }
1126
    if (res_scat_energy_min < 0.0) {
15!
1127
      fatal_error("Lower resonance scattering energy bound is negative");
×
1128
    }
1129

1130
    // Maximum energy for resonance scattering
1131
    if (check_for_node(node_res_scat, "energy_max")) {
15!
1132
      res_scat_energy_max =
30✔
1133
        std::stod(get_node_value(node_res_scat, "energy_max"));
30✔
1134
    }
1135
    if (res_scat_energy_max < res_scat_energy_min) {
15!
1136
      fatal_error("Upper resonance scattering energy bound is below the "
×
1137
                  "lower resonance scattering energy bound.");
1138
    }
1139

1140
    // Get resonance scattering nuclides
1141
    if (check_for_node(node_res_scat, "nuclides")) {
15!
1142
      res_scat_nuclides =
15✔
1143
        get_node_array<std::string>(node_res_scat, "nuclides");
30✔
1144
    }
1145
  }
1146

1147
  // Get volume calculations
1148
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
9,322✔
1149
    model::volume_calcs.emplace_back(node_vol);
308✔
1150
  }
1151

1152
  // Get temperature settings
1153
  if (check_for_node(root, "temperature_default")) {
9,014✔
1154
    temperature_default =
342✔
1155
      std::stod(get_node_value(root, "temperature_default"));
342✔
1156
  }
1157
  if (check_for_node(root, "temperature_method")) {
9,014✔
1158
    auto temp = get_node_value(root, "temperature_method", true, true);
485✔
1159
    if (temp == "nearest") {
485✔
1160
      temperature_method = TemperatureMethod::NEAREST;
304✔
1161
    } else if (temp == "interpolation") {
181!
1162
      temperature_method = TemperatureMethod::INTERPOLATION;
181✔
1163
    } else {
1164
      fatal_error("Unknown temperature method: " + temp);
×
1165
    }
1166
  }
485✔
1167
  if (check_for_node(root, "temperature_tolerance")) {
9,014✔
1168
    temperature_tolerance =
680✔
1169
      std::stod(get_node_value(root, "temperature_tolerance"));
680✔
1170
  }
1171
  if (check_for_node(root, "temperature_multipole")) {
9,014✔
1172
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
185✔
1173

1174
    // Multipole currently doesn't work with photon transport
1175
    if (temperature_multipole && photon_transport) {
185!
1176
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1177
                  "photon transport.");
1178
    }
1179
  }
1180
  if (check_for_node(root, "temperature_range")) {
9,014✔
1181
    auto range = get_node_array<double>(root, "temperature_range");
170✔
1182
    temperature_range[0] = range.at(0);
170✔
1183
    temperature_range[1] = range.at(1);
170✔
1184
  }
170✔
1185

1186
  // Check for tabular_legendre options
1187
  if (check_for_node(root, "tabular_legendre")) {
9,014✔
1188
    // Get pointer to tabular_legendre node
1189
    xml_node node_tab_leg = root.child("tabular_legendre");
105✔
1190

1191
    // Check for enable option
1192
    if (check_for_node(node_tab_leg, "enable")) {
105!
1193
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
105✔
1194
    }
1195

1196
    // Check for the number of points
1197
    if (check_for_node(node_tab_leg, "num_points")) {
105!
1198
      legendre_to_tabular_points =
×
1199
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
1200
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
1201
        fatal_error(
×
1202
          "The 'num_points' subelement/attribute of the "
1203
          "<tabular_legendre> element must contain a value greater than 1");
1204
      }
1205
    }
1206
  }
1207

1208
  // Check whether create delayed neutrons in fission
1209
  if (check_for_node(root, "create_delayed_neutrons")) {
9,014!
1210
    create_delayed_neutrons =
×
1211
      get_node_value_bool(root, "create_delayed_neutrons");
×
1212
  }
1213

1214
  // Check whether create fission sites
1215
  if (run_mode == RunMode::FIXED_SOURCE) {
9,014✔
1216
    if (check_for_node(root, "create_fission_neutrons")) {
3,267✔
1217
      create_fission_neutrons =
325✔
1218
        get_node_value_bool(root, "create_fission_neutrons");
325✔
1219
    }
1220
  }
1221

1222
  // Check whether to scale fission photon yields
1223
  if (check_for_node(root, "delayed_photon_scaling")) {
9,014!
1224
    delayed_photon_scaling =
×
1225
      get_node_value_bool(root, "delayed_photon_scaling");
×
1226
  }
1227

1228
  // Check whether to use event-based parallelism
1229
  if (check_for_node(root, "event_based")) {
9,014✔
1230
    event_based = get_node_value_bool(root, "event_based");
30✔
1231
  }
1232

1233
  // Check whether or not to use delta tracking
1234
  if (check_for_node(root, "delta_tracking")) {
9,014✔
1235
    delta_tracking = get_node_value_bool(root, "delta_tracking");
150✔
1236

1237
    if (temperature_multipole && delta_tracking) {
150!
NEW
1238
      fatal_error(
×
1239
        "At present, delta tracking cannot be used with a windowed multipole "
1240
        "temperature treatment.");
1241
    }
1242

1243
    if (!run_CE && delta_tracking) {
150!
NEW
1244
      fatal_error("At present, delta tracking can only be used in continuous "
×
1245
                  "energy simulations.");
1246
    }
1247
  }
1248

1249
  // Check whether material cell offsets should be generated
1250
  if (check_for_node(root, "material_cell_offsets")) {
9,014!
1251
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1252
  }
1253

1254
  // Weight window information
1255
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
9,319✔
1256
    variance_reduction::weight_windows.emplace_back(
305✔
1257
      std::make_unique<WeightWindows>(node_ww));
610✔
1258
  }
1259

1260
  // Enable weight windows by default if one or more are present
1261
  if (variance_reduction::weight_windows.size() > 0)
9,014✔
1262
    settings::weight_windows_on = true;
209✔
1263

1264
  // read weight windows from file
1265
  if (check_for_node(root, "weight_windows_file")) {
9,014!
1266
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1267
    weight_windows_on = true;
×
1268
  }
1269

1270
  // read settings for weight windows value, this will override
1271
  // the automatic setting even if weight windows are present
1272
  if (check_for_node(root, "weight_windows_on")) {
9,014✔
1273
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
71✔
1274
  }
1275

1276
  if (check_for_node(root, "max_secondaries")) {
9,014!
1277
    settings::max_secondaries =
×
1278
      std::stoi(get_node_value(root, "max_secondaries"));
×
1279
  }
1280

1281
  if (check_for_node(root, "max_history_splits")) {
9,014✔
1282
    settings::max_history_splits =
680✔
1283
      std::stoi(get_node_value(root, "max_history_splits"));
680✔
1284
  }
1285

1286
  if (check_for_node(root, "max_tracks")) {
9,014✔
1287
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
90✔
1288
  }
1289

1290
  // Create weight window generator objects
1291
  if (check_for_node(root, "weight_window_generators")) {
9,014✔
1292
    auto wwgs_node = root.child("weight_window_generators");
105✔
1293
    for (pugi::xml_node node_wwg :
210✔
1294
      wwgs_node.children("weight_windows_generator")) {
210✔
1295
      variance_reduction::weight_windows_generators.emplace_back(
105✔
1296
        std::make_unique<WeightWindowsGenerator>(node_wwg));
210✔
1297
    }
1298
    // if any of the weight windows are intended to be generated otf, make
1299
    // sure they're applied
1300
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
105!
1301
      if (wwg->on_the_fly_) {
105!
1302
        settings::weight_windows_on = true;
105✔
1303
        break;
105✔
1304
      }
1305
    }
1306
    // If any weight window generators have local FW-CADIS target tallies,
1307
    // user-defined adjoint sources cannot be used at the same time.
1308
    if (!model::adjoint_sources.empty()) {
105!
1309
      for (const auto& wwg : variance_reduction::weight_windows_generators) {
×
1310
        if (!wwg->targets_.empty()) {
×
1311
          fatal_error("Cannot use both user-defined adjoint sources and "
×
1312
                      "FW-CADIS target tallies at the same time.");
1313
        }
1314
      }
1315
    }
1316
  }
1317

1318
  // Set up weight window checkpoints
1319
  if (check_for_node(root, "weight_window_checkpoints")) {
9,014✔
1320
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
136✔
1321
    if (check_for_node(ww_checkpoints, "collision")) {
136!
1322
      weight_window_checkpoint_collision =
136✔
1323
        get_node_value_bool(ww_checkpoints, "collision");
136✔
1324
    }
1325
    if (check_for_node(ww_checkpoints, "surface")) {
136!
1326
      weight_window_checkpoint_surface =
136✔
1327
        get_node_value_bool(ww_checkpoints, "surface");
136✔
1328
    }
1329
  }
1330

1331
  if (weight_windows_on) {
9,014✔
1332
    if (!weight_window_checkpoint_surface &&
303✔
1333
        !weight_window_checkpoint_collision)
178!
1334
      fatal_error(
×
1335
        "Weight Windows are enabled but there are no valid checkpoints.");
1336
  }
1337

1338
  if (check_for_node(root, "use_decay_photons")) {
9,014✔
1339
    settings::use_decay_photons =
11✔
1340
      get_node_value_bool(root, "use_decay_photons");
11✔
1341
  }
1342

1343
  // If weight windows are on, also enable shared secondary bank (unless
1344
  // explicitly disabled by user).
1345
  if (check_for_node(root, "shared_secondary_bank")) {
9,014✔
1346
    bool val = get_node_value_bool(root, "shared_secondary_bank");
335✔
1347
    if (val && run_mode == RunMode::EIGENVALUE) {
335!
1348
      warning(
×
1349
        "Shared secondary bank is not supported in eigenvalue calculations. "
1350
        "Setting will be ignored.");
1351
    } else {
1352
      settings::use_shared_secondary_bank = val;
335✔
1353
    }
1354
  } else if (settings::weight_windows_on) {
8,679✔
1355
    if (run_mode == RunMode::EIGENVALUE) {
121✔
1356
      warning(
22✔
1357
        "Shared secondary bank is not supported in eigenvalue calculations. "
1358
        "Particle local secondary banks will be used instead.");
1359
    } else if (run_mode == RunMode::FIXED_SOURCE) {
110!
1360
      settings::use_shared_secondary_bank = true;
110✔
1361
    }
1362
  }
1363
}
9,014✔
1364

1365
void free_memory_settings()
9,162✔
1366
{
1367
  settings::statepoint_batch.clear();
9,162✔
1368
  settings::sourcepoint_batch.clear();
9,162✔
1369
  settings::source_write_surf_id.clear();
9,162✔
1370
  settings::res_scat_nuclides.clear();
9,162✔
1371
}
9,162✔
1372

1373
//==============================================================================
1374
// C API functions
1375
//==============================================================================
1376

1377
extern "C" int openmc_set_n_batches(
220✔
1378
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1379
{
1380
  if (settings::n_inactive >= n_batches) {
220✔
1381
    set_errmsg("Number of active batches must be greater than zero.");
11✔
1382
    return OPENMC_E_INVALID_ARGUMENT;
11✔
1383
  }
1384

1385
  if (!settings::trigger_on) {
209✔
1386
    // Set n_batches and n_max_batches to same value
1387
    settings::n_batches = n_batches;
187✔
1388
    settings::n_max_batches = n_batches;
187✔
1389
  } else {
1390
    // Set n_batches and n_max_batches based on value of set_max_batches
1391
    if (set_max_batches) {
22✔
1392
      settings::n_max_batches = n_batches;
11✔
1393
    } else {
1394
      settings::n_batches = n_batches;
11✔
1395
    }
1396
  }
1397

1398
  // Update size of k_generation and entropy
1399
  int m = settings::n_max_batches * settings::gen_per_batch;
209✔
1400
  simulation::k_generation.reserve(m);
209✔
1401
  simulation::entropy.reserve(m);
209✔
1402

1403
  // Add value of n_batches to statepoint_batch
1404
  if (add_statepoint_batch &&
209✔
1405
      !(contains(settings::statepoint_batch, n_batches)))
198✔
1406
    settings::statepoint_batch.insert(n_batches);
33✔
1407

1408
  return 0;
1409
}
1410

1411
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,530✔
1412
{
1413
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,530✔
1414

1415
  return 0;
2,530✔
1416
}
1417

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