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

openmc-dev / openmc / 22313563243

23 Feb 2026 03:48PM UTC coverage: 81.668% (-0.02%) from 81.688%
22313563243

Pull #3817

github

web-flow
Merge 57700522b into 83a30f686
Pull Request #3817: Fix MeshFilter.get_pandas_dataframe to handle all mesh types

16814 of 23454 branches covered (71.69%)

Branch coverage included in aggregate %.

23 of 25 new or added lines in 4 files covered. (92.0%)

744 existing lines in 15 files now uncovered.

56855 of 66751 relevant lines covered (85.17%)

43165405.27 hits per line

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

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

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

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

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

39
namespace openmc {
40

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

45
namespace settings {
46

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

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

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

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

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

152
} // namespace settings
153

154
//==============================================================================
155
// Functions
156
//==============================================================================
157

158
void get_run_parameters(pugi::xml_node node_base)
5,851✔
159
{
160
  using namespace settings;
161
  using namespace pugi;
162

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

414
  write_message("Reading settings XML file...", 5);
1,061✔
415

416
  read_settings_xml(root);
1,061✔
417
}
1,072✔
418

419
void read_settings_xml(pugi::xml_node root)
6,506✔
420
{
421
  using namespace settings;
422
  using namespace pugi;
423

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

434
  // Check for user meshes and allocate
435
  read_meshes(root);
6,506✔
436

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

598
  // Check for photon transport
599
  if (check_for_node(root, "photon_transport")) {
6,499✔
600
    photon_transport = get_node_value_bool(root, "photon_transport");
153✔
601

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

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

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

625
  // ==========================================================================
626
  // EXTERNAL SOURCE
627

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

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

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

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

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

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

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

677
  if (check_for_node(root, "free_gas_threshold")) {
6,492!
UNCOV
678
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
679
  }
680

681
  // Survival biasing
682
  if (check_for_node(root, "survival_biasing")) {
6,492✔
683
    survival_biasing = get_node_value_bool(root, "survival_biasing");
141✔
684
  }
685

686
  // Probability tables
687
  if (check_for_node(root, "ptables")) {
6,492✔
688
    urr_ptables_on = get_node_value_bool(root, "ptables");
12✔
689
  }
690

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

738
  // Particle trace
739
  if (check_for_node(root, "trace")) {
6,492✔
740
    auto temp = get_node_array<int64_t>(root, "trace");
12✔
741
    if (temp.size() != 3) {
12!
UNCOV
742
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
743
                  "batch, generation, and particle number.");
744
    }
745
    trace_batch = temp.at(0);
12✔
746
    trace_gen = temp.at(1);
12✔
747
    trace_particle = temp.at(2);
12✔
748
  }
12✔
749

750
  // Particle tracks
751
  if (check_for_node(root, "track")) {
6,492✔
752
    // Get values and make sure there are three per particle
753
    auto temp = get_node_array<int>(root, "track");
36✔
754
    if (temp.size() % 3 != 0) {
36!
UNCOV
755
      fatal_error(
×
756
        "Number of integers specified in 'track' is not "
757
        "divisible by 3.  Please provide 3 integers per particle to be "
758
        "tracked.");
759
    }
760

761
    // Reshape into track_identifiers
762
    int n_tracks = temp.size() / 3;
36✔
763
    for (int i = 0; i < n_tracks; ++i) {
144✔
764
      track_identifiers.push_back(
108✔
765
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
108✔
766
    }
767
  }
36✔
768

769
  // Shannon entropy
770
  if (solver_type == SolverType::RANDOM_RAY) {
6,492✔
771
    if (check_for_node(root, "entropy_mesh")) {
609!
UNCOV
772
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
773
                  "No user-defined entropy mesh is supported.");
774
    }
775
    entropy_on = true;
609✔
776
  } else if (solver_type == SolverType::MONTE_CARLO) {
5,883!
777
    if (check_for_node(root, "entropy_mesh")) {
5,883✔
778
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
273✔
779
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
273!
UNCOV
780
        fatal_error(fmt::format(
×
781
          "Mesh {} specified for Shannon entropy does not exist.", temp));
782
      }
783

784
      auto* m = dynamic_cast<RegularMesh*>(
273!
785
        model::meshes[model::mesh_map.at(temp)].get());
273✔
786
      if (!m)
273!
UNCOV
787
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
788
      simulation::entropy_mesh = m;
273✔
789

790
      // Turn on Shannon entropy calculation
791
      entropy_on = true;
273✔
792

793
    } else if (check_for_node(root, "entropy")) {
5,610!
UNCOV
794
      fatal_error(
×
795
        "Specifying a Shannon entropy mesh via the <entropy> element "
796
        "is deprecated. Please create a mesh using <mesh> and then reference "
797
        "it by specifying its ID in an <entropy_mesh> element.");
798
    }
799
  }
800
  // Uniform fission source weighting mesh
801
  if (check_for_node(root, "ufs_mesh")) {
6,492✔
802
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
12✔
803
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
12!
UNCOV
804
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
805
                              "method does not exist.",
806
        temp));
807
    }
808

809
    auto* m =
810
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
12!
811
    if (!m)
12!
UNCOV
812
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
813
    simulation::ufs_mesh = m;
12✔
814

815
    // Turn on uniform fission source weighting
816
    ufs_on = true;
12✔
817

818
  } else if (check_for_node(root, "uniform_fs")) {
6,480!
UNCOV
819
    fatal_error(
×
820
      "Specifying a UFS mesh via the <uniform_fs> element "
821
      "is deprecated. Please create a mesh using <mesh> and then reference "
822
      "it by specifying its ID in a <ufs_mesh> element.");
823
  }
824

825
  // Check if the user has specified to write state points
826
  if (check_for_node(root, "state_point")) {
6,492✔
827

828
    // Get pointer to state_point node
829
    auto node_sp = root.child("state_point");
129✔
830

831
    // Determine number of batches at which to store state points
832
    if (check_for_node(node_sp, "batches")) {
129!
833
      // User gave specific batches to write state points
834
      auto temp = get_node_array<int>(node_sp, "batches");
129✔
835
      for (const auto& b : temp) {
396✔
836
        statepoint_batch.insert(b);
267✔
837
      }
838
    } else {
129✔
839
      // If neither were specified, write state point at last batch
UNCOV
840
      statepoint_batch.insert(n_batches);
×
841
    }
842
  } else {
843
    // If no <state_point> tag was present, by default write state point at
844
    // last batch only
845
    statepoint_batch.insert(n_batches);
6,363✔
846
  }
847

848
  // Check if the user has specified to write source points
849
  if (check_for_node(root, "source_point")) {
6,492✔
850
    // Get source_point node
851
    xml_node node_sp = root.child("source_point");
81✔
852

853
    // Determine batches at which to store source points
854
    if (check_for_node(node_sp, "batches")) {
81✔
855
      // User gave specific batches to write source points
856
      auto temp = get_node_array<int>(node_sp, "batches");
36✔
857
      for (const auto& b : temp) {
96✔
858
        sourcepoint_batch.insert(b);
60✔
859
      }
860
    } else {
36✔
861
      // If neither were specified, write source points with state points
862
      sourcepoint_batch = statepoint_batch;
45✔
863
    }
864

865
    // Check if the user has specified to write binary source file
866
    if (check_for_node(node_sp, "separate")) {
81✔
867
      source_separate = get_node_value_bool(node_sp, "separate");
57✔
868
    }
869
    if (check_for_node(node_sp, "write")) {
81!
UNCOV
870
      source_write = get_node_value_bool(node_sp, "write");
×
871
    }
872
    if (check_for_node(node_sp, "mcpl")) {
81✔
873
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
21✔
874
    }
875
    if (check_for_node(node_sp, "overwrite_latest")) {
81✔
876
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
12✔
877
      source_separate = source_latest;
12✔
878
    }
879
  } else {
880
    // If no <source_point> tag was present, by default we keep source bank in
881
    // statepoint file and write it out at statepoints intervals
882
    source_separate = false;
6,411✔
883
    sourcepoint_batch = statepoint_batch;
6,411✔
884
  }
885

886
  // Check is the user specified to convert strength to statistical weight
887
  if (check_for_node(root, "uniform_source_sampling")) {
6,492✔
888
    uniform_source_sampling =
45✔
889
      get_node_value_bool(root, "uniform_source_sampling");
45✔
890
  }
891

892
  // Check if the user has specified to write surface source
893
  if (check_for_node(root, "surf_source_write")) {
6,492✔
894
    surf_source_write = true;
322✔
895
    // Get surface source write node
896
    xml_node node_ssw = root.child("surf_source_write");
322✔
897

898
    // Determine surface ids at which crossing particles are to be banked.
899
    // If no surfaces are specified, all surfaces in the model will be used
900
    // to bank source points.
901
    if (check_for_node(node_ssw, "surface_ids")) {
322✔
902
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
158✔
903
      for (const auto& b : temp) {
782✔
904
        source_write_surf_id.insert(b);
624✔
905
      }
906
    }
158✔
907

908
    // Get maximum number of particles to be banked per surface
909
    if (check_for_node(node_ssw, "max_particles")) {
322✔
910
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
315✔
911
    } else {
912
      fatal_error("A maximum number of particles needs to be specified "
7✔
913
                  "using the 'max_particles' parameter to store surface "
914
                  "source points.");
915
    }
916

917
    // Get maximum number of surface source files to be created
918
    if (check_for_node(node_ssw, "max_source_files")) {
315✔
919
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
27✔
920
    } else {
921
      ssw_max_files = 1;
288✔
922
    }
923

924
    if (check_for_node(node_ssw, "mcpl")) {
315✔
925
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
9✔
926
    }
927
    // Get cell information
928
    if (check_for_node(node_ssw, "cell")) {
315✔
929
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
80✔
930
      ssw_cell_type = SSWCellType::Both;
80✔
931
    }
932
    if (check_for_node(node_ssw, "cellfrom")) {
315✔
933
      if (ssw_cell_id != C_NONE) {
70✔
934
        fatal_error(
14✔
935
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
936
      }
937
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
56✔
938
      ssw_cell_type = SSWCellType::From;
56✔
939
    }
940
    if (check_for_node(node_ssw, "cellto")) {
301✔
941
      if (ssw_cell_id != C_NONE) {
55✔
942
        fatal_error(
14✔
943
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
944
      }
945
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
41✔
946
      ssw_cell_type = SSWCellType::To;
41✔
947
    }
948
  }
949

950
  // Check if the user has specified to write specific collisions
951
  if (check_for_node(root, "collision_track")) {
6,457✔
952
    settings::collision_track = true;
119✔
953
    // Get collision track node
954
    xml_node node_ct = root.child("collision_track");
119✔
955
    collision_track_config = CollisionTrackConfig {};
119✔
956

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

1014
  // If source is not separate and is to be written out in the statepoint
1015
  // file, make sure that the sourcepoint batch numbers are contained in the
1016
  // statepoint list
1017
  if (!source_separate) {
6,457✔
1018
    for (const auto& b : sourcepoint_batch) {
12,878✔
1019
      if (!contains(statepoint_batch, b)) {
6,490!
UNCOV
1020
        fatal_error(
×
1021
          "Sourcepoint batches are not a subset of statepoint batches.");
1022
      }
1023
    }
1024
  }
1025

1026
  // Check if the user has specified to not reduce tallies at the end of every
1027
  // batch
1028
  if (check_for_node(root, "no_reduce")) {
6,457✔
1029
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
24✔
1030
  }
1031

1032
  // Check if the user has specified to use confidence intervals for
1033
  // uncertainties rather than standard deviations
1034
  if (check_for_node(root, "confidence_intervals")) {
6,457✔
1035
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
12✔
1036
  }
1037

1038
  // Check for output options
1039
  if (check_for_node(root, "output")) {
6,457✔
1040
    // Get pointer to output node
1041
    pugi::xml_node node_output = root.child("output");
606✔
1042

1043
    // Check for summary option
1044
    if (check_for_node(node_output, "summary")) {
606✔
1045
      output_summary = get_node_value_bool(node_output, "summary");
585✔
1046
    }
1047

1048
    // Check for ASCII tallies output option
1049
    if (check_for_node(node_output, "tallies")) {
606✔
1050
      output_tallies = get_node_value_bool(node_output, "tallies");
282✔
1051
    }
1052

1053
    // Set output directory if a path has been specified
1054
    if (check_for_node(node_output, "path")) {
606!
1055
      path_output = get_node_value(node_output, "path");
×
UNCOV
1056
      if (!ends_with(path_output, "/")) {
×
UNCOV
1057
        path_output += "/";
×
1058
      }
1059
    }
1060
  }
1061

1062
  // Resonance scattering parameters
1063
  if (check_for_node(root, "resonance_scattering")) {
6,457✔
1064
    xml_node node_res_scat = root.child("resonance_scattering");
12✔
1065

1066
    // See if resonance scattering is enabled
1067
    if (check_for_node(node_res_scat, "enable")) {
12!
1068
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
12✔
1069
    } else {
UNCOV
1070
      res_scat_on = true;
×
1071
    }
1072

1073
    // Determine what method is used
1074
    if (check_for_node(node_res_scat, "method")) {
12!
1075
      auto temp = get_node_value(node_res_scat, "method", true, true);
12✔
1076
      if (temp == "rvs") {
12!
1077
        res_scat_method = ResScatMethod::rvs;
12✔
UNCOV
1078
      } else if (temp == "dbrc") {
×
1079
        res_scat_method = ResScatMethod::dbrc;
×
1080
      } else {
UNCOV
1081
        fatal_error(
×
UNCOV
1082
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1083
      }
1084
    }
12✔
1085

1086
    // Minimum energy for resonance scattering
1087
    if (check_for_node(node_res_scat, "energy_min")) {
12!
1088
      res_scat_energy_min =
12✔
1089
        std::stod(get_node_value(node_res_scat, "energy_min"));
12✔
1090
    }
1091
    if (res_scat_energy_min < 0.0) {
12!
UNCOV
1092
      fatal_error("Lower resonance scattering energy bound is negative");
×
1093
    }
1094

1095
    // Maximum energy for resonance scattering
1096
    if (check_for_node(node_res_scat, "energy_max")) {
12!
1097
      res_scat_energy_max =
12✔
1098
        std::stod(get_node_value(node_res_scat, "energy_max"));
12✔
1099
    }
1100
    if (res_scat_energy_max < res_scat_energy_min) {
12!
UNCOV
1101
      fatal_error("Upper resonance scattering energy bound is below the "
×
1102
                  "lower resonance scattering energy bound.");
1103
    }
1104

1105
    // Get resonance scattering nuclides
1106
    if (check_for_node(node_res_scat, "nuclides")) {
12!
1107
      res_scat_nuclides =
1108
        get_node_array<std::string>(node_res_scat, "nuclides");
12✔
1109
    }
1110
  }
1111

1112
  // Get volume calculations
1113
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
6,694✔
1114
    model::volume_calcs.emplace_back(node_vol);
237✔
1115
  }
1116

1117
  // Get temperature settings
1118
  if (check_for_node(root, "temperature_default")) {
6,457✔
1119
    temperature_default =
138✔
1120
      std::stod(get_node_value(root, "temperature_default"));
138✔
1121
  }
1122
  if (check_for_node(root, "temperature_method")) {
6,457✔
1123
    auto temp = get_node_value(root, "temperature_method", true, true);
393✔
1124
    if (temp == "nearest") {
393✔
1125
      temperature_method = TemperatureMethod::NEAREST;
246✔
1126
    } else if (temp == "interpolation") {
147!
1127
      temperature_method = TemperatureMethod::INTERPOLATION;
147✔
1128
    } else {
UNCOV
1129
      fatal_error("Unknown temperature method: " + temp);
×
1130
    }
1131
  }
393✔
1132
  if (check_for_node(root, "temperature_tolerance")) {
6,457✔
1133
    temperature_tolerance =
276✔
1134
      std::stod(get_node_value(root, "temperature_tolerance"));
276✔
1135
  }
1136
  if (check_for_node(root, "temperature_multipole")) {
6,457✔
1137
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
150✔
1138

1139
    // Multipole currently doesn't work with photon transport
1140
    if (temperature_multipole && photon_transport) {
150!
UNCOV
1141
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1142
                  "photon transport.");
1143
    }
1144
  }
1145
  if (check_for_node(root, "temperature_range")) {
6,457✔
1146
    auto range = get_node_array<double>(root, "temperature_range");
138✔
1147
    temperature_range[0] = range.at(0);
138✔
1148
    temperature_range[1] = range.at(1);
138✔
1149
  }
138✔
1150

1151
  // Check for tabular_legendre options
1152
  if (check_for_node(root, "tabular_legendre")) {
6,457✔
1153
    // Get pointer to tabular_legendre node
1154
    xml_node node_tab_leg = root.child("tabular_legendre");
72✔
1155

1156
    // Check for enable option
1157
    if (check_for_node(node_tab_leg, "enable")) {
72!
1158
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
72✔
1159
    }
1160

1161
    // Check for the number of points
1162
    if (check_for_node(node_tab_leg, "num_points")) {
72!
1163
      legendre_to_tabular_points =
×
1164
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
UNCOV
1165
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
UNCOV
1166
        fatal_error(
×
1167
          "The 'num_points' subelement/attribute of the "
1168
          "<tabular_legendre> element must contain a value greater than 1");
1169
      }
1170
    }
1171
  }
1172

1173
  // Check whether create delayed neutrons in fission
1174
  if (check_for_node(root, "create_delayed_neutrons")) {
6,457!
UNCOV
1175
    create_delayed_neutrons =
×
UNCOV
1176
      get_node_value_bool(root, "create_delayed_neutrons");
×
1177
  }
1178

1179
  // Check whether create fission sites
1180
  if (run_mode == RunMode::FIXED_SOURCE) {
6,457✔
1181
    if (check_for_node(root, "create_fission_neutrons")) {
2,194✔
1182
      create_fission_neutrons =
228✔
1183
        get_node_value_bool(root, "create_fission_neutrons");
228✔
1184
    }
1185
  }
1186

1187
  // Check whether to scale fission photon yields
1188
  if (check_for_node(root, "delayed_photon_scaling")) {
6,457!
UNCOV
1189
    delayed_photon_scaling =
×
UNCOV
1190
      get_node_value_bool(root, "delayed_photon_scaling");
×
1191
  }
1192

1193
  // Check whether to use event-based parallelism
1194
  if (check_for_node(root, "event_based")) {
6,457!
UNCOV
1195
    event_based = get_node_value_bool(root, "event_based");
×
1196
  }
1197

1198
  // Check whether material cell offsets should be generated
1199
  if (check_for_node(root, "material_cell_offsets")) {
6,457!
UNCOV
1200
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1201
  }
1202

1203
  // Weight window information
1204
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
6,528✔
1205
    variance_reduction::weight_windows.emplace_back(
71✔
1206
      std::make_unique<WeightWindows>(node_ww));
142✔
1207
  }
1208

1209
  // Enable weight windows by default if one or more are present
1210
  if (variance_reduction::weight_windows.size() > 0)
6,457✔
1211
    settings::weight_windows_on = true;
50✔
1212

1213
  // read weight windows from file
1214
  if (check_for_node(root, "weight_windows_file")) {
6,457!
UNCOV
1215
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1216
  }
1217

1218
  // read settings for weight windows value, this will override
1219
  // the automatic setting even if weight windows are present
1220
  if (check_for_node(root, "weight_windows_on")) {
6,457✔
1221
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
29✔
1222
  }
1223

1224
  if (check_for_node(root, "max_secondaries")) {
6,457!
UNCOV
1225
    settings::max_secondaries =
×
UNCOV
1226
      std::stoi(get_node_value(root, "max_secondaries"));
×
1227
  }
1228

1229
  if (check_for_node(root, "max_history_splits")) {
6,457✔
1230
    settings::max_history_splits =
174✔
1231
      std::stoi(get_node_value(root, "max_history_splits"));
174✔
1232
  }
1233

1234
  if (check_for_node(root, "max_tracks")) {
6,457✔
1235
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
36✔
1236
  }
1237

1238
  // Create weight window generator objects
1239
  if (check_for_node(root, "weight_window_generators")) {
6,457✔
1240
    auto wwgs_node = root.child("weight_window_generators");
63✔
1241
    for (pugi::xml_node node_wwg :
63✔
1242
      wwgs_node.children("weight_windows_generator")) {
189✔
1243
      variance_reduction::weight_windows_generators.emplace_back(
63✔
1244
        std::make_unique<WeightWindowsGenerator>(node_wwg));
126✔
1245
    }
1246
    // if any of the weight windows are intended to be generated otf, make
1247
    // sure they're applied
1248
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
63!
1249
      if (wwg->on_the_fly_) {
63!
1250
        settings::weight_windows_on = true;
63✔
1251
        break;
63✔
1252
      }
1253
    }
1254
  }
1255

1256
  // Set up weight window checkpoints
1257
  if (check_for_node(root, "weight_window_checkpoints")) {
6,457✔
1258
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
12✔
1259
    if (check_for_node(ww_checkpoints, "collision")) {
12!
1260
      weight_window_checkpoint_collision =
12✔
1261
        get_node_value_bool(ww_checkpoints, "collision");
12✔
1262
    }
1263
    if (check_for_node(ww_checkpoints, "surface")) {
12!
1264
      weight_window_checkpoint_surface =
12✔
1265
        get_node_value_bool(ww_checkpoints, "surface");
12✔
1266
    }
1267
  }
1268

1269
  if (check_for_node(root, "use_decay_photons")) {
6,457✔
1270
    settings::use_decay_photons =
9✔
1271
      get_node_value_bool(root, "use_decay_photons");
9✔
1272
  }
1273
}
6,457✔
1274

1275
void free_memory_settings()
6,576✔
1276
{
1277
  settings::statepoint_batch.clear();
6,576✔
1278
  settings::sourcepoint_batch.clear();
6,576✔
1279
  settings::source_write_surf_id.clear();
6,576✔
1280
  settings::res_scat_nuclides.clear();
6,576✔
1281
}
6,576✔
1282

1283
//==============================================================================
1284
// C API functions
1285
//==============================================================================
1286

1287
extern "C" int openmc_set_n_batches(
36✔
1288
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1289
{
1290
  if (settings::n_inactive >= n_batches) {
36✔
1291
    set_errmsg("Number of active batches must be greater than zero.");
9✔
1292
    return OPENMC_E_INVALID_ARGUMENT;
9✔
1293
  }
1294

1295
  if (!settings::trigger_on) {
27✔
1296
    // Set n_batches and n_max_batches to same value
1297
    settings::n_batches = n_batches;
9✔
1298
    settings::n_max_batches = n_batches;
9✔
1299
  } else {
1300
    // Set n_batches and n_max_batches based on value of set_max_batches
1301
    if (set_max_batches) {
18✔
1302
      settings::n_max_batches = n_batches;
9✔
1303
    } else {
1304
      settings::n_batches = n_batches;
9✔
1305
    }
1306
  }
1307

1308
  // Update size of k_generation and entropy
1309
  int m = settings::n_max_batches * settings::gen_per_batch;
27✔
1310
  simulation::k_generation.reserve(m);
27✔
1311
  simulation::entropy.reserve(m);
27✔
1312

1313
  // Add value of n_batches to statepoint_batch
1314
  if (add_statepoint_batch &&
45✔
1315
      !(contains(settings::statepoint_batch, n_batches)))
18!
1316
    settings::statepoint_batch.insert(n_batches);
18✔
1317

1318
  return 0;
27✔
1319
}
1320

1321
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,070✔
1322
{
1323
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,070✔
1324

1325
  return 0;
2,070✔
1326
}
1327

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