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

openmc-dev / openmc / 22322317452

pending completion
22322317452

Pull #3808

github

web-flow
Merge 0e9eea39a into 83a30f686
Pull Request #3808: Add properties to settings w/ documentation, c++ loading of filename, and python round-trip test

16820 of 23482 branches covered (71.63%)

Branch coverage included in aggregate %.

76 of 92 new or added lines in 8 files covered. (82.61%)

724 existing lines in 14 files now uncovered.

56900 of 66807 relevant lines covered (85.17%)

43125827.06 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 reduce_tallies {true};
66
bool res_scat_on {false};
67
bool restart_run {false};
68
bool run_CE {true};
69
bool source_latest {false};
70
bool source_separate {false};
71
bool source_write {true};
72
bool source_mcpl_write {false};
73
bool surf_source_write {false};
74
bool surf_mcpl_write {false};
75
bool surf_source_read {false};
76
bool survival_biasing {false};
77
bool survival_normalization {false};
78
bool temperature_multipole {false};
79
bool trigger_on {false};
80
bool trigger_predict {false};
81
bool uniform_source_sampling {false};
82
bool ufs_on {false};
83
bool urr_ptables_on {true};
84
bool use_decay_photons {false};
85
bool weight_windows_on {false};
86
bool weight_window_checkpoint_surface {false};
87
bool weight_window_checkpoint_collision {true};
88
bool write_all_tracks {false};
89
bool write_initial_source {false};
90
bool read_temperatures {true};
91
bool read_densities {true};
92

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

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

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

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

155
} // namespace settings
156

157
//==============================================================================
158
// Functions
159
//==============================================================================
160

161
void get_run_parameters(pugi::xml_node node_base)
5,851✔
162
{
163
  using namespace settings;
164
  using namespace pugi;
165

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

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

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

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

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

195
  // Get max number of lost particles
196
  if (check_for_node(node_base, "max_lost_particles")) {
5,851✔
197
    max_lost_particles =
36✔
198
      std::stoi(get_node_value(node_base, "max_lost_particles"));
36✔
199
  }
200

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

207
  // Get relative number of lost particles
208
  if (check_for_node(node_base, "max_write_lost_particles")) {
5,851✔
209
    max_write_lost_particles =
12✔
210
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
12✔
211
  }
212

213
  // Get number of inactive batches
214
  if (run_mode == RunMode::EIGENVALUE ||
5,851✔
215
      solver_type == SolverType::RANDOM_RAY) {
2,229✔
216
    if (check_for_node(node_base, "inactive")) {
3,946✔
217
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
3,783✔
218
    }
219
    if (check_for_node(node_base, "generations_per_batch")) {
3,946✔
220
      gen_per_batch =
12✔
221
        std::stoi(get_node_value(node_base, "generations_per_batch"));
12✔
222
    }
223

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

229
    // Get the trigger information for keff
230
    if (check_for_node(node_base, "keff_trigger")) {
3,946✔
231
      xml_node node_keff_trigger = node_base.child("keff_trigger");
81✔
232

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

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

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

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

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

400
  // Get root element
401
  xml_node root = doc.document_element();
1,061✔
402

403
  // Verbosity
404
  if (check_for_node(root, "verbosity") && verbosity == -1) {
1,061!
405
    verbosity = std::stoi(get_node_value(root, "verbosity"));
147✔
406
  } else if (verbosity == -1) {
914!
407
    verbosity = 7;
914✔
408
  }
409

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

417
  write_message("Reading settings XML file...", 5);
1,061✔
418

419
  read_settings_xml(root);
1,061✔
420
}
1,072✔
421

422
void read_settings_xml(pugi::xml_node root)
6,506✔
423
{
424
  using namespace settings;
425
  using namespace pugi;
426

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

437
  // Check for user meshes and allocate
438
  read_meshes(root);
6,506✔
439

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

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

464
  // Check for a trigger node and get trigger information
465
  if (check_for_node(root, "trigger")) {
6,506✔
466
    xml_node node_trigger = root.child("trigger");
126✔
467

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

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

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

491
  // Check run mode if it hasn't been set from the command line
492
  xml_node node_mode;
6,506✔
493
  if (run_mode == RunMode::UNSET) {
6,506✔
494
    if (check_for_node(root, "run_mode")) {
5,875✔
495
      std::string temp_str = get_node_value(root, "run_mode", true, true);
5,851✔
496
      if (temp_str == "eigenvalue") {
5,851✔
497
        run_mode = RunMode::EIGENVALUE;
3,598✔
498
      } else if (temp_str == "fixed source") {
2,253✔
499
        run_mode = RunMode::FIXED_SOURCE;
2,229✔
500
      } else if (temp_str == "plot") {
24!
501
        run_mode = RunMode::PLOTTING;
×
502
      } else if (temp_str == "particle restart") {
24!
UNCOV
503
        run_mode = RunMode::PARTICLE;
×
504
      } else if (temp_str == "volume") {
24!
505
        run_mode = RunMode::VOLUME;
24✔
506
      } else {
UNCOV
507
        fatal_error("Unrecognized run mode: " + temp_str);
×
508
      }
509

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

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

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

538
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
6,506✔
539
    // Read run parameters
540
    get_run_parameters(node_mode);
5,851✔
541

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

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

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

577
  // Copy random number seed if specified
578
  if (check_for_node(root, "seed")) {
6,499✔
579
    auto seed = std::stoll(get_node_value(root, "seed"));
457✔
580
    openmc_set_seed(seed);
457✔
581
  }
582

583
  // Copy random number stride if specified
584
  if (check_for_node(root, "stride")) {
6,499✔
585
    auto stride = std::stoull(get_node_value(root, "stride"));
12✔
586
    openmc_set_stride(stride);
12✔
587
  }
588

589
  // Check for electron treatment
590
  if (check_for_node(root, "electron_treatment")) {
6,499✔
591
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
54✔
592
    if (temp_str == "led") {
54✔
593
      electron_treatment = ElectronTreatment::LED;
9✔
594
    } else if (temp_str == "ttb") {
45!
595
      electron_treatment = ElectronTreatment::TTB;
45✔
596
    } else {
UNCOV
597
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
598
    }
599
  }
54✔
600

601
  // Check for photon transport
602
  if (check_for_node(root, "photon_transport")) {
6,499✔
603
    photon_transport = get_node_value_bool(root, "photon_transport");
153✔
604

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

611
  // Number of bins for logarithmic grid
612
  if (check_for_node(root, "log_grid_bins")) {
6,499✔
613
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
12✔
614
    if (n_log_bins < 1) {
12!
UNCOV
615
      fatal_error("Number of bins for logarithmic grid must be greater "
×
616
                  "than zero.");
617
    }
618
  }
619

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

628
  // ==========================================================================
629
  // EXTERNAL SOURCE
630

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

636
  // Check if the user has specified to read surface source
637
  if (check_for_node(root, "surf_source_read")) {
6,492✔
638
    surf_source_read = true;
24✔
639
    // Get surface source read node
640
    xml_node node_ssr = root.child("surf_source_read");
24✔
641

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

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

662
  // Build probability mass function for sampling external sources
663
  vector<double> source_strengths;
6,492✔
664
  for (auto& s : model::external_sources) {
14,274✔
665
    source_strengths.push_back(s->strength());
7,782✔
666
  }
667
  model::external_sources_probability.assign(source_strengths);
6,492✔
668

669
  // Check if we want to write out source
670
  if (check_for_node(root, "write_initial_source")) {
6,492!
UNCOV
671
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
672
  }
673

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

680
  if (check_for_node(root, "free_gas_threshold")) {
6,492!
UNCOV
681
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
682
  }
683

684
  // Survival biasing
685
  if (check_for_node(root, "survival_biasing")) {
6,492✔
686
    survival_biasing = get_node_value_bool(root, "survival_biasing");
141✔
687
  }
688

689
  // Probability tables
690
  if (check_for_node(root, "ptables")) {
6,492✔
691
    urr_ptables_on = get_node_value_bool(root, "ptables");
12✔
692
  }
693

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

741
  // read properties from file
742
  if (check_for_node(root, "properties")) {
6,492!
743
    // Get pointer to properties node
NEW
744
    xml_node node_props = root.child("properties");
×
745

NEW
746
    properties_file = get_node_value(node_props, "filepath");
×
NEW
747
    if (!file_exists(properties_file)) {
×
NEW
748
      fatal_error(fmt::format("File '{}' does not exist.", properties_file));
×
749
    }
NEW
750
    read_temperatures = get_node_value_bool(node_props, "temperatures");
×
NEW
751
    read_densities = get_node_value_bool(node_props, "densities");
×
752
  }
753

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

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

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

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

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

806
      // Turn on Shannon entropy calculation
807
      entropy_on = true;
273✔
808

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

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

831
    // Turn on uniform fission source weighting
832
    ufs_on = true;
12✔
833

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

841
  // Check if the user has specified to write state points
842
  if (check_for_node(root, "state_point")) {
6,492✔
843

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

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

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

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

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

902
  // Check is the user specified to convert strength to statistical weight
903
  if (check_for_node(root, "uniform_source_sampling")) {
6,492✔
904
    uniform_source_sampling =
45✔
905
      get_node_value_bool(root, "uniform_source_sampling");
45✔
906
  }
907

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

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

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

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

940
    if (check_for_node(node_ssw, "mcpl")) {
315✔
941
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
9✔
942
    }
943
    // Get cell information
944
    if (check_for_node(node_ssw, "cell")) {
315✔
945
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
80✔
946
      ssw_cell_type = SSWCellType::Both;
80✔
947
    }
948
    if (check_for_node(node_ssw, "cellfrom")) {
315✔
949
      if (ssw_cell_id != C_NONE) {
70✔
950
        fatal_error(
14✔
951
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
952
      }
953
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
56✔
954
      ssw_cell_type = SSWCellType::From;
56✔
955
    }
956
    if (check_for_node(node_ssw, "cellto")) {
301✔
957
      if (ssw_cell_id != C_NONE) {
55✔
958
        fatal_error(
14✔
959
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
960
      }
961
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
41✔
962
      ssw_cell_type = SSWCellType::To;
41✔
963
    }
964
  }
965

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

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

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

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

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

1054
  // Check for output options
1055
  if (check_for_node(root, "output")) {
6,457✔
1056
    // Get pointer to output node
1057
    pugi::xml_node node_output = root.child("output");
606✔
1058

1059
    // Check for summary option
1060
    if (check_for_node(node_output, "summary")) {
606✔
1061
      output_summary = get_node_value_bool(node_output, "summary");
585✔
1062
    }
1063

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

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

1078
  // Resonance scattering parameters
1079
  if (check_for_node(root, "resonance_scattering")) {
6,457✔
1080
    xml_node node_res_scat = root.child("resonance_scattering");
12✔
1081

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

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

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

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

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

1128
  // Get volume calculations
1129
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
6,694✔
1130
    model::volume_calcs.emplace_back(node_vol);
237✔
1131
  }
1132

1133
  // Get temperature settings
1134
  if (check_for_node(root, "temperature_default")) {
6,457✔
1135
    temperature_default =
138✔
1136
      std::stod(get_node_value(root, "temperature_default"));
138✔
1137
  }
1138
  if (check_for_node(root, "temperature_method")) {
6,457✔
1139
    auto temp = get_node_value(root, "temperature_method", true, true);
393✔
1140
    if (temp == "nearest") {
393✔
1141
      temperature_method = TemperatureMethod::NEAREST;
246✔
1142
    } else if (temp == "interpolation") {
147!
1143
      temperature_method = TemperatureMethod::INTERPOLATION;
147✔
1144
    } else {
UNCOV
1145
      fatal_error("Unknown temperature method: " + temp);
×
1146
    }
1147
  }
393✔
1148
  if (check_for_node(root, "temperature_tolerance")) {
6,457✔
1149
    temperature_tolerance =
276✔
1150
      std::stod(get_node_value(root, "temperature_tolerance"));
276✔
1151
  }
1152
  if (check_for_node(root, "temperature_multipole")) {
6,457✔
1153
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
150✔
1154

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

1167
  // Check for tabular_legendre options
1168
  if (check_for_node(root, "tabular_legendre")) {
6,457✔
1169
    // Get pointer to tabular_legendre node
1170
    xml_node node_tab_leg = root.child("tabular_legendre");
72✔
1171

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

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

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

1195
  // Check whether create fission sites
1196
  if (run_mode == RunMode::FIXED_SOURCE) {
6,457✔
1197
    if (check_for_node(root, "create_fission_neutrons")) {
2,194✔
1198
      create_fission_neutrons =
228✔
1199
        get_node_value_bool(root, "create_fission_neutrons");
228✔
1200
    }
1201
  }
1202

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

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

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

1219
  // Weight window information
1220
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
6,528✔
1221
    variance_reduction::weight_windows.emplace_back(
71✔
1222
      std::make_unique<WeightWindows>(node_ww));
142✔
1223
  }
1224

1225
  // Enable weight windows by default if one or more are present
1226
  if (variance_reduction::weight_windows.size() > 0)
6,457✔
1227
    settings::weight_windows_on = true;
50✔
1228

1229
  // read weight windows from file
1230
  if (check_for_node(root, "weight_windows_file")) {
6,457!
UNCOV
1231
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1232
  }
1233

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

1240
  if (check_for_node(root, "max_secondaries")) {
6,457!
UNCOV
1241
    settings::max_secondaries =
×
UNCOV
1242
      std::stoi(get_node_value(root, "max_secondaries"));
×
1243
  }
1244

1245
  if (check_for_node(root, "max_history_splits")) {
6,457✔
1246
    settings::max_history_splits =
174✔
1247
      std::stoi(get_node_value(root, "max_history_splits"));
174✔
1248
  }
1249

1250
  if (check_for_node(root, "max_tracks")) {
6,457✔
1251
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
36✔
1252
  }
1253

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

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

1285
  if (check_for_node(root, "use_decay_photons")) {
6,457✔
1286
    settings::use_decay_photons =
9✔
1287
      get_node_value_bool(root, "use_decay_photons");
9✔
1288
  }
1289
}
6,457✔
1290

1291
void free_memory_settings()
6,576✔
1292
{
1293
  settings::statepoint_batch.clear();
6,576✔
1294
  settings::sourcepoint_batch.clear();
6,576✔
1295
  settings::source_write_surf_id.clear();
6,576✔
1296
  settings::res_scat_nuclides.clear();
6,576✔
1297
}
6,576✔
1298

1299
//==============================================================================
1300
// C API functions
1301
//==============================================================================
1302

1303
extern "C" int openmc_set_n_batches(
36✔
1304
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1305
{
1306
  if (settings::n_inactive >= n_batches) {
36✔
1307
    set_errmsg("Number of active batches must be greater than zero.");
9✔
1308
    return OPENMC_E_INVALID_ARGUMENT;
9✔
1309
  }
1310

1311
  if (!settings::trigger_on) {
27✔
1312
    // Set n_batches and n_max_batches to same value
1313
    settings::n_batches = n_batches;
9✔
1314
    settings::n_max_batches = n_batches;
9✔
1315
  } else {
1316
    // Set n_batches and n_max_batches based on value of set_max_batches
1317
    if (set_max_batches) {
18✔
1318
      settings::n_max_batches = n_batches;
9✔
1319
    } else {
1320
      settings::n_batches = n_batches;
9✔
1321
    }
1322
  }
1323

1324
  // Update size of k_generation and entropy
1325
  int m = settings::n_max_batches * settings::gen_per_batch;
27✔
1326
  simulation::k_generation.reserve(m);
27✔
1327
  simulation::entropy.reserve(m);
27✔
1328

1329
  // Add value of n_batches to statepoint_batch
1330
  if (add_statepoint_batch &&
45✔
1331
      !(contains(settings::statepoint_batch, n_batches)))
18!
1332
    settings::statepoint_batch.insert(n_batches);
18✔
1333

1334
  return 0;
27✔
1335
}
1336

1337
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,070✔
1338
{
1339
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,070✔
1340

1341
  return 0;
2,070✔
1342
}
1343

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