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

openmc-dev / openmc / 18199783194

02 Oct 2025 04:51PM UTC coverage: 85.122% (-0.08%) from 85.199%
18199783194

Pull #3587

github

web-flow
Merge 775bbd9ec into 1dacf4fd2
Pull Request #3587: Ensure weight_windows_file information is read from XML

8 of 9 new or added lines in 1 file covered. (88.89%)

263 existing lines in 10 files now uncovered.

53128 of 62414 relevant lines covered (85.12%)

38859371.13 hits per line

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

81.35
/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/constants.h"
15
#include "openmc/container_util.h"
16
#include "openmc/distribution.h"
17
#include "openmc/distribution_multi.h"
18
#include "openmc/distribution_spatial.h"
19
#include "openmc/eigenvalue.h"
20
#include "openmc/error.h"
21
#include "openmc/file_utils.h"
22
#include "openmc/mcpl_interface.h"
23
#include "openmc/mesh.h"
24
#include "openmc/message_passing.h"
25
#include "openmc/output.h"
26
#include "openmc/plot.h"
27
#include "openmc/random_lcg.h"
28
#include "openmc/random_ray/random_ray.h"
29
#include "openmc/simulation.h"
30
#include "openmc/source.h"
31
#include "openmc/string_utils.h"
32
#include "openmc/tallies/trigger.h"
33
#include "openmc/volume_calc.h"
34
#include "openmc/weight_windows.h"
35
#include "openmc/xml_interface.h"
36

37
namespace openmc {
38

39
//==============================================================================
40
// Global variables
41
//==============================================================================
42

43
namespace settings {
44

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

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

97
int32_t n_inactive {0};
98
int32_t max_lost_particles {10};
99
double rel_max_lost_particles {1.0e-6};
100
int32_t max_write_lost_particles {-1};
101
int32_t gen_per_batch {1};
102
int64_t n_particles {-1};
103

104
int64_t max_particles_in_flight {100000};
105
int max_particle_events {1000000};
106

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

147
} // namespace settings
148

149
//==============================================================================
150
// Functions
151
//==============================================================================
152

153
void get_run_parameters(pugi::xml_node node_base)
6,767✔
154
{
155
  using namespace settings;
156
  using namespace pugi;
157

158
  // Check number of particles
159
  if (!check_for_node(node_base, "particles")) {
6,767✔
160
    fatal_error("Need to specify number of particles.");
×
161
  }
162

163
  // Get number of particles if it wasn't specified as a command-line argument
164
  if (n_particles == -1) {
6,767✔
165
    n_particles = std::stoll(get_node_value(node_base, "particles"));
6,767✔
166
  }
167

168
  // Get maximum number of in flight particles for event-based mode
169
  if (check_for_node(node_base, "max_particles_in_flight")) {
6,767✔
170
    max_particles_in_flight =
×
171
      std::stoll(get_node_value(node_base, "max_particles_in_flight"));
×
172
  }
173

174
  // Get maximum number of events allowed per particle
175
  if (check_for_node(node_base, "max_particle_events")) {
6,767✔
176
    max_particle_events =
×
177
      std::stoll(get_node_value(node_base, "max_particle_events"));
×
178
  }
179

180
  // Get number of basic batches
181
  if (check_for_node(node_base, "batches")) {
6,767✔
182
    n_batches = std::stoi(get_node_value(node_base, "batches"));
6,767✔
183
  }
184
  if (!trigger_on)
6,767✔
185
    n_max_batches = n_batches;
6,619✔
186

187
  // Get max number of lost particles
188
  if (check_for_node(node_base, "max_lost_particles")) {
6,767✔
189
    max_lost_particles =
48✔
190
      std::stoi(get_node_value(node_base, "max_lost_particles"));
48✔
191
  }
192

193
  // Get relative number of lost particles
194
  if (check_for_node(node_base, "rel_max_lost_particles")) {
6,767✔
195
    rel_max_lost_particles =
×
196
      std::stod(get_node_value(node_base, "rel_max_lost_particles"));
×
197
  }
198

199
  // Get relative number of lost particles
200
  if (check_for_node(node_base, "max_write_lost_particles")) {
6,767✔
201
    max_write_lost_particles =
16✔
202
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
16✔
203
  }
204

205
  // Get number of inactive batches
206
  if (run_mode == RunMode::EIGENVALUE ||
6,767✔
207
      solver_type == SolverType::RANDOM_RAY) {
2,502✔
208
    if (check_for_node(node_base, "inactive")) {
4,666✔
209
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,464✔
210
    }
211
    if (check_for_node(node_base, "generations_per_batch")) {
4,666✔
212
      gen_per_batch =
16✔
213
        std::stoi(get_node_value(node_base, "generations_per_batch"));
16✔
214
    }
215

216
    // Preallocate space for keff and entropy by generation
217
    int m = settings::n_max_batches * settings::gen_per_batch;
4,666✔
218
    simulation::k_generation.reserve(m);
4,666✔
219
    simulation::entropy.reserve(m);
4,666✔
220

221
    // Get the trigger information for keff
222
    if (check_for_node(node_base, "keff_trigger")) {
4,666✔
223
      xml_node node_keff_trigger = node_base.child("keff_trigger");
109✔
224

225
      if (check_for_node(node_keff_trigger, "type")) {
109✔
226
        auto temp = get_node_value(node_keff_trigger, "type", true, true);
109✔
227
        if (temp == "std_dev") {
109✔
228
          keff_trigger.metric = TriggerMetric::standard_deviation;
109✔
229
        } else if (temp == "variance") {
×
230
          keff_trigger.metric = TriggerMetric::variance;
×
231
        } else if (temp == "rel_err") {
×
232
          keff_trigger.metric = TriggerMetric::relative_error;
×
233
        } else {
234
          fatal_error("Unrecognized keff trigger type " + temp);
×
235
        }
236
      } else {
109✔
237
        fatal_error("Specify keff trigger type in settings XML");
×
238
      }
239

240
      if (check_for_node(node_keff_trigger, "threshold")) {
109✔
241
        keff_trigger.threshold =
109✔
242
          std::stod(get_node_value(node_keff_trigger, "threshold"));
109✔
243
        if (keff_trigger.threshold <= 0) {
109✔
244
          fatal_error("keff trigger threshold must be positive");
×
245
        }
246
      } else {
247
        fatal_error("Specify keff trigger threshold in settings XML");
×
248
      }
249
    }
250
  }
251

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

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

383
  // Parse settings.xml file
384
  xml_document doc;
1,506✔
385
  auto result = doc.load_file(filename.c_str());
1,506✔
386
  if (!result) {
1,506✔
UNCOV
387
    fatal_error("Error processing settings.xml file.");
×
388
  }
389

390
  // Get root element
391
  xml_node root = doc.document_element();
1,506✔
392

393
  // Verbosity
394
  if (check_for_node(root, "verbosity")) {
1,506✔
395
    verbosity = std::stoi(get_node_value(root, "verbosity"));
276✔
396
  }
397

398
  // To this point, we haven't displayed any output since we didn't know what
399
  // the verbosity is. Now that we checked for it, show the title if necessary
400
  if (mpi::master) {
1,506✔
401
    if (verbosity >= 2)
1,281✔
402
      title();
1,015✔
403
  }
404

405
  write_message("Reading settings XML file...", 5);
1,506✔
406

407
  read_settings_xml(root);
1,506✔
408
}
1,518✔
409

410
void read_settings_xml(pugi::xml_node root)
7,362✔
411
{
412
  using namespace settings;
413
  using namespace pugi;
414

415
  // Find if a multi-group or continuous-energy simulation is desired
416
  if (check_for_node(root, "energy_mode")) {
7,362✔
417
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
1,111✔
418
    if (temp_str == "mg" || temp_str == "multi-group") {
1,111✔
419
      run_CE = false;
1,111✔
UNCOV
420
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
421
      run_CE = true;
×
422
    }
423
  }
1,111✔
424

425
  // Check for user meshes and allocate
426
  read_meshes(root);
7,362✔
427

428
  // Look for deprecated cross_sections.xml file in settings.xml
429
  if (check_for_node(root, "cross_sections")) {
7,362✔
UNCOV
430
    warning(
×
431
      "Setting cross_sections in settings.xml has been deprecated."
432
      " The cross_sections are now set in materials.xml and the "
433
      "cross_sections input to materials.xml and the OPENMC_CROSS_SECTIONS"
434
      " environment variable will take precendent over setting "
435
      "cross_sections in settings.xml.");
UNCOV
436
    path_cross_sections = get_node_value(root, "cross_sections");
×
437
  }
438

439
  if (!run_CE) {
7,362✔
440
    // Scattering Treatments
441
    if (check_for_node(root, "max_order")) {
1,111✔
442
      max_order = std::stoi(get_node_value(root, "max_order"));
16✔
443
    } else {
444
      // Set to default of largest int - 1, which means to use whatever is
445
      // contained in library. This is largest int - 1 because for legendre
446
      // scattering, a value of 1 is added to the order; adding 1 to the largest
447
      // int gets you the largest negative integer, which is not what we want.
448
      max_order = std::numeric_limits<int>::max() - 1;
1,095✔
449
    }
450
  }
451

452
  // Check for a trigger node and get trigger information
453
  if (check_for_node(root, "trigger")) {
7,362✔
454
    xml_node node_trigger = root.child("trigger");
164✔
455

456
    // Check if trigger(s) are to be turned on
457
    trigger_on = get_node_value_bool(node_trigger, "active");
164✔
458

459
    if (trigger_on) {
164✔
460
      if (check_for_node(node_trigger, "max_batches")) {
148✔
461
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
148✔
462
      } else {
UNCOV
463
        fatal_error("<max_batches> must be specified with triggers");
×
464
      }
465

466
      // Get the batch interval to check triggers
467
      if (!check_for_node(node_trigger, "batch_interval")) {
148✔
468
        trigger_predict = true;
16✔
469
      } else {
470
        trigger_batch_interval =
132✔
471
          std::stoi(get_node_value(node_trigger, "batch_interval"));
132✔
472
        if (trigger_batch_interval <= 0) {
132✔
UNCOV
473
          fatal_error("Trigger batch interval must be greater than zero");
×
474
        }
475
      }
476
    }
477
  }
478

479
  // Check run mode if it hasn't been set from the command line
480
  xml_node node_mode;
7,362✔
481
  if (run_mode == RunMode::UNSET) {
7,362✔
482
    if (check_for_node(root, "run_mode")) {
6,799✔
483
      std::string temp_str = get_node_value(root, "run_mode", true, true);
6,767✔
484
      if (temp_str == "eigenvalue") {
6,767✔
485
        run_mode = RunMode::EIGENVALUE;
4,233✔
486
      } else if (temp_str == "fixed source") {
2,534✔
487
        run_mode = RunMode::FIXED_SOURCE;
2,502✔
488
      } else if (temp_str == "plot") {
32✔
UNCOV
489
        run_mode = RunMode::PLOTTING;
×
490
      } else if (temp_str == "particle restart") {
32✔
UNCOV
491
        run_mode = RunMode::PARTICLE;
×
492
      } else if (temp_str == "volume") {
32✔
493
        run_mode = RunMode::VOLUME;
32✔
494
      } else {
UNCOV
495
        fatal_error("Unrecognized run mode: " + temp_str);
×
496
      }
497

498
      // Assume XML specifies <particles>, <batches>, etc. directly
499
      node_mode = root;
6,767✔
500
    } else {
6,767✔
501
      warning("<run_mode> should be specified.");
32✔
502

503
      // Make sure that either eigenvalue or fixed source was specified
504
      node_mode = root.child("eigenvalue");
32✔
505
      if (node_mode) {
32✔
506
        run_mode = RunMode::EIGENVALUE;
32✔
507
      } else {
UNCOV
508
        node_mode = root.child("fixed_source");
×
509
        if (node_mode) {
×
510
          run_mode = RunMode::FIXED_SOURCE;
×
511
        } else {
UNCOV
512
          fatal_error("<eigenvalue> or <fixed_source> not specified.");
×
513
        }
514
      }
515
    }
516
  }
517

518
  // Check solver type
519
  if (check_for_node(root, "random_ray")) {
7,362✔
520
    solver_type = SolverType::RANDOM_RAY;
577✔
521
    if (run_CE)
577✔
UNCOV
522
      fatal_error("multi-group energy mode must be specified in settings XML "
×
523
                  "when using the random ray solver.");
524
  }
525

526
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
7,362✔
527
    // Read run parameters
528
    get_run_parameters(node_mode);
6,767✔
529

530
    // Check number of active batches, inactive batches, max lost particles and
531
    // particles
532
    if (n_batches <= n_inactive) {
6,767✔
UNCOV
533
      fatal_error("Number of active batches must be greater than zero.");
×
534
    } else if (n_inactive < 0) {
6,767✔
UNCOV
535
      fatal_error("Number of inactive batches must be non-negative.");
×
536
    } else if (n_particles <= 0) {
6,767✔
UNCOV
537
      fatal_error("Number of particles must be greater than zero.");
×
538
    } else if (max_lost_particles <= 0) {
6,767✔
UNCOV
539
      fatal_error("Number of max lost particles must be greater than zero.");
×
540
    } else if (rel_max_lost_particles <= 0.0 || rel_max_lost_particles >= 1.0) {
6,767✔
UNCOV
541
      fatal_error("Relative max lost particles must be between zero and one.");
×
542
    }
543
  }
544

545
  // Copy plotting random number seed if specified
546
  if (check_for_node(root, "plot_seed")) {
7,362✔
UNCOV
547
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
548
    model::plotter_seed = seed;
×
549
  }
550

551
  // Copy random number seed if specified
552
  if (check_for_node(root, "seed")) {
7,362✔
553
    auto seed = std::stoll(get_node_value(root, "seed"));
439✔
554
    openmc_set_seed(seed);
439✔
555
  }
556

557
  // Copy random number stride if specified
558
  if (check_for_node(root, "stride")) {
7,362✔
559
    auto stride = std::stoull(get_node_value(root, "stride"));
16✔
560
    openmc_set_stride(stride);
16✔
561
  }
562

563
  // Check for electron treatment
564
  if (check_for_node(root, "electron_treatment")) {
7,362✔
565
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
70✔
566
    if (temp_str == "led") {
70✔
567
      electron_treatment = ElectronTreatment::LED;
11✔
568
    } else if (temp_str == "ttb") {
59✔
569
      electron_treatment = ElectronTreatment::TTB;
59✔
570
    } else {
UNCOV
571
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
572
    }
573
  }
70✔
574

575
  // Check for photon transport
576
  if (check_for_node(root, "photon_transport")) {
7,362✔
577
    photon_transport = get_node_value_bool(root, "photon_transport");
200✔
578

579
    if (!run_CE && photon_transport) {
200✔
UNCOV
580
      fatal_error("Photon transport is not currently supported in "
×
581
                  "multigroup mode");
582
    }
583
  }
584

585
  // Number of bins for logarithmic grid
586
  if (check_for_node(root, "log_grid_bins")) {
7,362✔
587
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
16✔
588
    if (n_log_bins < 1) {
16✔
UNCOV
589
      fatal_error("Number of bins for logarithmic grid must be greater "
×
590
                  "than zero.");
591
    }
592
  }
593

594
  // Number of OpenMP threads
595
  if (check_for_node(root, "threads")) {
7,362✔
UNCOV
596
    if (mpi::master)
×
597
      warning("The <threads> element has been deprecated. Use "
×
598
              "the OMP_NUM_THREADS environment variable to set the number of "
599
              "threads.");
600
  }
601

602
  // ==========================================================================
603
  // EXTERNAL SOURCE
604

605
  // Get point to list of <source> elements and make sure there is at least one
606
  for (pugi::xml_node node : root.children("source")) {
14,075✔
607
    model::external_sources.push_back(Source::create(node));
6,723✔
608
  }
609

610
  // Check if the user has specified to read surface source
611
  if (check_for_node(root, "surf_source_read")) {
7,352✔
612
    surf_source_read = true;
32✔
613
    // Get surface source read node
614
    xml_node node_ssr = root.child("surf_source_read");
32✔
615

616
    std::string path = "surface_source.h5";
32✔
617
    // Check if the user has specified different file for surface source reading
618
    if (check_for_node(node_ssr, "path")) {
32✔
619
      path = get_node_value(node_ssr, "path", false, true);
32✔
620
    }
621
    model::external_sources.push_back(make_unique<FileSource>(path));
32✔
622
  }
32✔
623

624
  // If no source specified, default to isotropic point source at origin with
625
  // Watt spectrum. No default source is needed in random ray mode.
626
  if (model::external_sources.empty() &&
9,415✔
627
      settings::solver_type != SolverType::RANDOM_RAY) {
2,063✔
628
    double T[] {0.0};
1,951✔
629
    double p[] {1.0};
1,951✔
630
    model::external_sources.push_back(make_unique<IndependentSource>(
1,951✔
631
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
3,902✔
632
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
3,902✔
633
      UPtrDist {new Discrete(T, p, 1)}));
3,902✔
634
  }
635

636
  // Build probability mass function for sampling external sources
637
  vector<double> source_strengths;
7,352✔
638
  for (auto& s : model::external_sources) {
16,048✔
639
    source_strengths.push_back(s->strength());
8,696✔
640
  }
641
  model::external_sources_probability.assign(source_strengths);
7,352✔
642

643
  // Check if we want to write out source
644
  if (check_for_node(root, "write_initial_source")) {
7,352✔
UNCOV
645
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
646
  }
647

648
  // Get relative number of lost particles
649
  if (check_for_node(root, "source_rejection_fraction")) {
7,352✔
650
    source_rejection_fraction =
6✔
651
      std::stod(get_node_value(root, "source_rejection_fraction"));
6✔
652
  }
653

654
  // Survival biasing
655
  if (check_for_node(root, "survival_biasing")) {
7,352✔
656
    survival_biasing = get_node_value_bool(root, "survival_biasing");
189✔
657
  }
658

659
  // Probability tables
660
  if (check_for_node(root, "ptables")) {
7,352✔
661
    urr_ptables_on = get_node_value_bool(root, "ptables");
16✔
662
  }
663

664
  // Cutoffs
665
  if (check_for_node(root, "cutoff")) {
7,352✔
666
    xml_node node_cutoff = root.child("cutoff");
129✔
667
    if (check_for_node(node_cutoff, "weight")) {
129✔
668
      weight_cutoff = std::stod(get_node_value(node_cutoff, "weight"));
16✔
669
    }
670
    if (check_for_node(node_cutoff, "weight_avg")) {
129✔
671
      weight_survive = std::stod(get_node_value(node_cutoff, "weight_avg"));
16✔
672
    }
673
    if (check_for_node(node_cutoff, "survival_normalization")) {
129✔
UNCOV
674
      survival_normalization =
×
675
        get_node_value_bool(node_cutoff, "survival_normalization");
×
676
    }
677
    if (check_for_node(node_cutoff, "energy_neutron")) {
129✔
678
      energy_cutoff[0] =
32✔
679
        std::stod(get_node_value(node_cutoff, "energy_neutron"));
16✔
680
    } else if (check_for_node(node_cutoff, "energy")) {
113✔
UNCOV
681
      warning("The use of an <energy> cutoff is deprecated and should "
×
682
              "be replaced by <energy_neutron>.");
UNCOV
683
      energy_cutoff[0] = std::stod(get_node_value(node_cutoff, "energy"));
×
684
    }
685
    if (check_for_node(node_cutoff, "energy_photon")) {
129✔
686
      energy_cutoff[1] =
140✔
687
        std::stod(get_node_value(node_cutoff, "energy_photon"));
70✔
688
    }
689
    if (check_for_node(node_cutoff, "energy_electron")) {
129✔
UNCOV
690
      energy_cutoff[2] =
×
691
        std::stof(get_node_value(node_cutoff, "energy_electron"));
×
692
    }
693
    if (check_for_node(node_cutoff, "energy_positron")) {
129✔
UNCOV
694
      energy_cutoff[3] =
×
695
        std::stod(get_node_value(node_cutoff, "energy_positron"));
×
696
    }
697
    if (check_for_node(node_cutoff, "time_neutron")) {
129✔
698
      time_cutoff[0] = std::stod(get_node_value(node_cutoff, "time_neutron"));
27✔
699
    }
700
    if (check_for_node(node_cutoff, "time_photon")) {
129✔
UNCOV
701
      time_cutoff[1] = std::stod(get_node_value(node_cutoff, "time_photon"));
×
702
    }
703
    if (check_for_node(node_cutoff, "time_electron")) {
129✔
UNCOV
704
      time_cutoff[2] = std::stod(get_node_value(node_cutoff, "time_electron"));
×
705
    }
706
    if (check_for_node(node_cutoff, "time_positron")) {
129✔
UNCOV
707
      time_cutoff[3] = std::stod(get_node_value(node_cutoff, "time_positron"));
×
708
    }
709
  }
710

711
  // Particle trace
712
  if (check_for_node(root, "trace")) {
7,352✔
713
    auto temp = get_node_array<int64_t>(root, "trace");
16✔
714
    if (temp.size() != 3) {
16✔
UNCOV
715
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
716
                  "batch, generation, and particle number.");
717
    }
718
    trace_batch = temp.at(0);
16✔
719
    trace_gen = temp.at(1);
16✔
720
    trace_particle = temp.at(2);
16✔
721
  }
16✔
722

723
  // Particle tracks
724
  if (check_for_node(root, "track")) {
7,352✔
725
    // Get values and make sure there are three per particle
726
    auto temp = get_node_array<int>(root, "track");
48✔
727
    if (temp.size() % 3 != 0) {
48✔
UNCOV
728
      fatal_error(
×
729
        "Number of integers specified in 'track' is not "
730
        "divisible by 3.  Please provide 3 integers per particle to be "
731
        "tracked.");
732
    }
733

734
    // Reshape into track_identifiers
735
    int n_tracks = temp.size() / 3;
48✔
736
    for (int i = 0; i < n_tracks; ++i) {
192✔
737
      track_identifiers.push_back(
144✔
738
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
144✔
739
    }
740
  }
48✔
741

742
  // Shannon entropy
743
  if (solver_type == SolverType::RANDOM_RAY) {
7,352✔
744
    if (check_for_node(root, "entropy_mesh")) {
577✔
UNCOV
745
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
746
                  "No user-defined entropy mesh is supported.");
747
    }
748
    entropy_on = true;
577✔
749
  } else if (solver_type == SolverType::MONTE_CARLO) {
6,775✔
750
    if (check_for_node(root, "entropy_mesh")) {
6,775✔
751
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
363✔
752
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
363✔
UNCOV
753
        fatal_error(fmt::format(
×
754
          "Mesh {} specified for Shannon entropy does not exist.", temp));
755
      }
756

757
      auto* m = dynamic_cast<RegularMesh*>(
363✔
758
        model::meshes[model::mesh_map.at(temp)].get());
363✔
759
      if (!m)
363✔
UNCOV
760
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
761
      simulation::entropy_mesh = m;
363✔
762

763
      // Turn on Shannon entropy calculation
764
      entropy_on = true;
363✔
765

766
    } else if (check_for_node(root, "entropy")) {
6,412✔
UNCOV
767
      fatal_error(
×
768
        "Specifying a Shannon entropy mesh via the <entropy> element "
769
        "is deprecated. Please create a mesh using <mesh> and then reference "
770
        "it by specifying its ID in an <entropy_mesh> element.");
771
    }
772
  }
773
  // Uniform fission source weighting mesh
774
  if (check_for_node(root, "ufs_mesh")) {
7,352✔
775
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
16✔
776
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
16✔
UNCOV
777
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
778
                              "method does not exist.",
779
        temp));
780
    }
781

782
    auto* m =
783
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
16✔
784
    if (!m)
16✔
UNCOV
785
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
786
    simulation::ufs_mesh = m;
16✔
787

788
    // Turn on uniform fission source weighting
789
    ufs_on = true;
16✔
790

791
  } else if (check_for_node(root, "uniform_fs")) {
7,336✔
UNCOV
792
    fatal_error(
×
793
      "Specifying a UFS mesh via the <uniform_fs> element "
794
      "is deprecated. Please create a mesh using <mesh> and then reference "
795
      "it by specifying its ID in a <ufs_mesh> element.");
796
  }
797

798
  // Check if the user has specified to write state points
799
  if (check_for_node(root, "state_point")) {
7,352✔
800

801
    // Get pointer to state_point node
802
    auto node_sp = root.child("state_point");
169✔
803

804
    // Determine number of batches at which to store state points
805
    if (check_for_node(node_sp, "batches")) {
169✔
806
      // User gave specific batches to write state points
807
      auto temp = get_node_array<int>(node_sp, "batches");
169✔
808
      for (const auto& b : temp) {
518✔
809
        statepoint_batch.insert(b);
349✔
810
      }
811
    } else {
169✔
812
      // If neither were specified, write state point at last batch
UNCOV
813
      statepoint_batch.insert(n_batches);
×
814
    }
815
  } else {
816
    // If no <state_point> tag was present, by default write state point at
817
    // last batch only
818
    statepoint_batch.insert(n_batches);
7,183✔
819
  }
820

821
  // Check if the user has specified to write source points
822
  if (check_for_node(root, "source_point")) {
7,352✔
823
    // Get source_point node
824
    xml_node node_sp = root.child("source_point");
107✔
825

826
    // Determine batches at which to store source points
827
    if (check_for_node(node_sp, "batches")) {
107✔
828
      // User gave specific batches to write source points
829
      auto temp = get_node_array<int>(node_sp, "batches");
48✔
830
      for (const auto& b : temp) {
128✔
831
        sourcepoint_batch.insert(b);
80✔
832
      }
833
    } else {
48✔
834
      // If neither were specified, write source points with state points
835
      sourcepoint_batch = statepoint_batch;
59✔
836
    }
837

838
    // Check if the user has specified to write binary source file
839
    if (check_for_node(node_sp, "separate")) {
107✔
840
      source_separate = get_node_value_bool(node_sp, "separate");
75✔
841
    }
842
    if (check_for_node(node_sp, "write")) {
107✔
UNCOV
843
      source_write = get_node_value_bool(node_sp, "write");
×
844
    }
845
    if (check_for_node(node_sp, "mcpl")) {
107✔
846
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
27✔
847
    }
848
    if (check_for_node(node_sp, "overwrite_latest")) {
107✔
849
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
16✔
850
      source_separate = source_latest;
16✔
851
    }
852
  } else {
853
    // If no <source_point> tag was present, by default we keep source bank in
854
    // statepoint file and write it out at statepoints intervals
855
    source_separate = false;
7,245✔
856
    sourcepoint_batch = statepoint_batch;
7,245✔
857
  }
858

859
  // Check is the user specified to convert strength to statistical weight
860
  if (check_for_node(root, "uniform_source_sampling")) {
7,352✔
861
    uniform_source_sampling =
56✔
862
      get_node_value_bool(root, "uniform_source_sampling");
56✔
863
  }
864

865
  // Check if the user has specified to write surface source
866
  if (check_for_node(root, "surf_source_write")) {
7,352✔
867
    surf_source_write = true;
413✔
868
    // Get surface source write node
869
    xml_node node_ssw = root.child("surf_source_write");
413✔
870

871
    // Determine surface ids at which crossing particles are to be banked.
872
    // If no surfaces are specified, all surfaces in the model will be used
873
    // to bank source points.
874
    if (check_for_node(node_ssw, "surface_ids")) {
413✔
875
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
202✔
876
      for (const auto& b : temp) {
994✔
877
        source_write_surf_id.insert(b);
792✔
878
      }
879
    }
202✔
880

881
    // Get maximum number of particles to be banked per surface
882
    if (check_for_node(node_ssw, "max_particles")) {
413✔
883
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
404✔
884
    } else {
885
      fatal_error("A maximum number of particles needs to be specified "
9✔
886
                  "using the 'max_particles' parameter to store surface "
887
                  "source points.");
888
    }
889

890
    // Get maximum number of surface source files to be created
891
    if (check_for_node(node_ssw, "max_source_files")) {
404✔
892
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
33✔
893
    } else {
894
      ssw_max_files = 1;
371✔
895
    }
896

897
    if (check_for_node(node_ssw, "mcpl")) {
404✔
898
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
11✔
899
    }
900
    // Get cell information
901
    if (check_for_node(node_ssw, "cell")) {
404✔
902
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
104✔
903
      ssw_cell_type = SSWCellType::Both;
104✔
904
    }
905
    if (check_for_node(node_ssw, "cellfrom")) {
404✔
906
      if (ssw_cell_id != C_NONE) {
90✔
907
        fatal_error(
18✔
908
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
909
      }
910
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
72✔
911
      ssw_cell_type = SSWCellType::From;
72✔
912
    }
913
    if (check_for_node(node_ssw, "cellto")) {
386✔
914
      if (ssw_cell_id != C_NONE) {
71✔
915
        fatal_error(
18✔
916
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
917
      }
918
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
53✔
919
      ssw_cell_type = SSWCellType::To;
53✔
920
    }
921
  }
922

923
  // If source is not separate and is to be written out in the statepoint file,
924
  // make sure that the sourcepoint batch numbers are contained in the
925
  // statepoint list
926
  if (!source_separate) {
7,307✔
927
    for (const auto& b : sourcepoint_batch) {
14,564✔
928
      if (!contains(statepoint_batch, b)) {
7,348✔
UNCOV
929
        fatal_error(
×
930
          "Sourcepoint batches are not a subset of statepoint batches.");
931
      }
932
    }
933
  }
934

935
  // Check if the user has specified to not reduce tallies at the end of every
936
  // batch
937
  if (check_for_node(root, "no_reduce")) {
7,307✔
UNCOV
938
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
×
939
  }
940

941
  // Check if the user has specified to use confidence intervals for
942
  // uncertainties rather than standard deviations
943
  if (check_for_node(root, "confidence_intervals")) {
7,307✔
944
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
16✔
945
  }
946

947
  // Check for output options
948
  if (check_for_node(root, "output")) {
7,307✔
949
    // Get pointer to output node
950
    pugi::xml_node node_output = root.child("output");
541✔
951

952
    // Check for summary option
953
    if (check_for_node(node_output, "summary")) {
541✔
954
      output_summary = get_node_value_bool(node_output, "summary");
514✔
955
    }
956

957
    // Check for ASCII tallies output option
958
    if (check_for_node(node_output, "tallies")) {
541✔
959
      output_tallies = get_node_value_bool(node_output, "tallies");
95✔
960
    }
961

962
    // Set output directory if a path has been specified
963
    if (check_for_node(node_output, "path")) {
541✔
UNCOV
964
      path_output = get_node_value(node_output, "path");
×
965
      if (!ends_with(path_output, "/")) {
×
966
        path_output += "/";
×
967
      }
968
    }
969
  }
970

971
  // Resonance scattering parameters
972
  if (check_for_node(root, "resonance_scattering")) {
7,307✔
973
    xml_node node_res_scat = root.child("resonance_scattering");
16✔
974

975
    // See if resonance scattering is enabled
976
    if (check_for_node(node_res_scat, "enable")) {
16✔
977
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
16✔
978
    } else {
UNCOV
979
      res_scat_on = true;
×
980
    }
981

982
    // Determine what method is used
983
    if (check_for_node(node_res_scat, "method")) {
16✔
984
      auto temp = get_node_value(node_res_scat, "method", true, true);
16✔
985
      if (temp == "rvs") {
16✔
986
        res_scat_method = ResScatMethod::rvs;
16✔
UNCOV
987
      } else if (temp == "dbrc") {
×
988
        res_scat_method = ResScatMethod::dbrc;
×
989
      } else {
UNCOV
990
        fatal_error(
×
991
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
992
      }
993
    }
16✔
994

995
    // Minimum energy for resonance scattering
996
    if (check_for_node(node_res_scat, "energy_min")) {
16✔
997
      res_scat_energy_min =
16✔
998
        std::stod(get_node_value(node_res_scat, "energy_min"));
16✔
999
    }
1000
    if (res_scat_energy_min < 0.0) {
16✔
UNCOV
1001
      fatal_error("Lower resonance scattering energy bound is negative");
×
1002
    }
1003

1004
    // Maximum energy for resonance scattering
1005
    if (check_for_node(node_res_scat, "energy_max")) {
16✔
1006
      res_scat_energy_max =
16✔
1007
        std::stod(get_node_value(node_res_scat, "energy_max"));
16✔
1008
    }
1009
    if (res_scat_energy_max < res_scat_energy_min) {
16✔
UNCOV
1010
      fatal_error("Upper resonance scattering energy bound is below the "
×
1011
                  "lower resonance scattering energy bound.");
1012
    }
1013

1014
    // Get resonance scattering nuclides
1015
    if (check_for_node(node_res_scat, "nuclides")) {
16✔
1016
      res_scat_nuclides =
1017
        get_node_array<std::string>(node_res_scat, "nuclides");
16✔
1018
    }
1019
  }
1020

1021
  // Get volume calculations
1022
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
7,635✔
1023
    model::volume_calcs.emplace_back(node_vol);
328✔
1024
  }
1025

1026
  // Get temperature settings
1027
  if (check_for_node(root, "temperature_default")) {
7,307✔
1028
    temperature_default =
172✔
1029
      std::stod(get_node_value(root, "temperature_default"));
172✔
1030
  }
1031
  if (check_for_node(root, "temperature_method")) {
7,307✔
1032
    auto temp = get_node_value(root, "temperature_method", true, true);
325✔
1033
    if (temp == "nearest") {
325✔
1034
      temperature_method = TemperatureMethod::NEAREST;
140✔
1035
    } else if (temp == "interpolation") {
185✔
1036
      temperature_method = TemperatureMethod::INTERPOLATION;
185✔
1037
    } else {
UNCOV
1038
      fatal_error("Unknown temperature method: " + temp);
×
1039
    }
1040
  }
325✔
1041
  if (check_for_node(root, "temperature_tolerance")) {
7,307✔
1042
    temperature_tolerance =
171✔
1043
      std::stod(get_node_value(root, "temperature_tolerance"));
171✔
1044
  }
1045
  if (check_for_node(root, "temperature_multipole")) {
7,307✔
1046
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
32✔
1047

1048
    // Multipole currently doesn't work with photon transport
1049
    if (temperature_multipole && photon_transport) {
32✔
UNCOV
1050
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1051
                  "photon transport.");
1052
    }
1053
  }
1054
  if (check_for_node(root, "temperature_range")) {
7,307✔
UNCOV
1055
    auto range = get_node_array<double>(root, "temperature_range");
×
1056
    temperature_range[0] = range.at(0);
×
1057
    temperature_range[1] = range.at(1);
×
1058
  }
1059

1060
  // Check for user value for the number of generation of the Iterated Fission
1061
  // Probability (IFP) method
1062
  if (check_for_node(root, "ifp_n_generation")) {
7,307✔
1063
    ifp_n_generation = std::stoi(get_node_value(root, "ifp_n_generation"));
85✔
1064
    if (ifp_n_generation <= 0) {
85✔
UNCOV
1065
      fatal_error("'ifp_n_generation' must be greater than 0.");
×
1066
    }
1067
    // Avoid tallying 0 if IFP logs are not complete when active cycles start
1068
    if (ifp_n_generation > n_inactive) {
85✔
1069
      fatal_error("'ifp_n_generation' must be lower than or equal to the "
9✔
1070
                  "number of inactive cycles.");
1071
    }
1072
  }
1073

1074
  // Check for tabular_legendre options
1075
  if (check_for_node(root, "tabular_legendre")) {
7,298✔
1076
    // Get pointer to tabular_legendre node
1077
    xml_node node_tab_leg = root.child("tabular_legendre");
96✔
1078

1079
    // Check for enable option
1080
    if (check_for_node(node_tab_leg, "enable")) {
96✔
1081
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
96✔
1082
    }
1083

1084
    // Check for the number of points
1085
    if (check_for_node(node_tab_leg, "num_points")) {
96✔
UNCOV
1086
      legendre_to_tabular_points =
×
1087
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
1088
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
1089
        fatal_error(
×
1090
          "The 'num_points' subelement/attribute of the "
1091
          "<tabular_legendre> element must contain a value greater than 1");
1092
      }
1093
    }
1094
  }
1095

1096
  // Check whether create delayed neutrons in fission
1097
  if (check_for_node(root, "create_delayed_neutrons")) {
7,298✔
UNCOV
1098
    create_delayed_neutrons =
×
1099
      get_node_value_bool(root, "create_delayed_neutrons");
×
1100
  }
1101

1102
  // Check whether create fission sites
1103
  if (run_mode == RunMode::FIXED_SOURCE) {
7,298✔
1104
    if (check_for_node(root, "create_fission_neutrons")) {
2,456✔
1105
      create_fission_neutrons =
16✔
1106
        get_node_value_bool(root, "create_fission_neutrons");
16✔
1107
    }
1108
  }
1109

1110
  // Check whether to scale fission photon yields
1111
  if (check_for_node(root, "delayed_photon_scaling")) {
7,298✔
UNCOV
1112
    delayed_photon_scaling =
×
1113
      get_node_value_bool(root, "delayed_photon_scaling");
×
1114
  }
1115

1116
  // Check whether to use event-based parallelism
1117
  if (check_for_node(root, "event_based")) {
7,298✔
UNCOV
1118
    event_based = get_node_value_bool(root, "event_based");
×
1119
  }
1120

1121
  // Check whether material cell offsets should be generated
1122
  if (check_for_node(root, "material_cell_offsets")) {
7,298✔
UNCOV
1123
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1124
  }
1125

1126
  // Weight window information
1127
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
7,391✔
1128
    variance_reduction::weight_windows.emplace_back(
93✔
1129
      std::make_unique<WeightWindows>(node_ww));
186✔
1130
  }
1131

1132
  // Enable weight windows by default if one or more are present
1133
  if (variance_reduction::weight_windows.size() > 0)
7,298✔
1134
    settings::weight_windows_on = true;
66✔
1135

1136
  // read weight windows from file
1137
  if (check_for_node(root, "weight_windows_file")) {
7,298✔
UNCOV
1138
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1139
  }
1140

1141
  // read settings for weight windows value, this will override
1142
  // the automatic setting even if weight windows are present
1143
  if (check_for_node(root, "weight_windows_on")) {
7,298✔
1144
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
37✔
1145
  }
1146

1147
  if (check_for_node(root, "max_secondaries")) {
7,298✔
UNCOV
1148
    settings::max_secondaries =
×
1149
      std::stoi(get_node_value(root, "max_secondaries"));
×
1150
  }
1151

1152
  if (check_for_node(root, "max_history_splits")) {
7,298✔
1153
    settings::max_history_splits =
228✔
1154
      std::stoi(get_node_value(root, "max_history_splits"));
228✔
1155
  }
1156

1157
  if (check_for_node(root, "max_tracks")) {
7,298✔
1158
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
48✔
1159
  }
1160

1161
  // Create weight window generator objects
1162
  if (check_for_node(root, "weight_window_generators")) {
7,298✔
1163
    auto wwgs_node = root.child("weight_window_generators");
82✔
1164
    for (pugi::xml_node node_wwg :
82✔
1165
      wwgs_node.children("weight_windows_generator")) {
246✔
1166
      variance_reduction::weight_windows_generators.emplace_back(
82✔
1167
        std::make_unique<WeightWindowsGenerator>(node_wwg));
164✔
1168
    }
1169
    // if any of the weight windows are intended to be generated otf, make sure
1170
    // they're applied
1171
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
82✔
1172
      if (wwg->on_the_fly_) {
82✔
1173
        settings::weight_windows_on = true;
82✔
1174
        break;
82✔
1175
      }
1176
    }
1177
  }
1178

1179
  // Set up weight window checkpoints
1180
  if (check_for_node(root, "weight_window_checkpoints")) {
7,298✔
1181
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
1✔
1182
    if (check_for_node(ww_checkpoints, "collision")) {
1✔
1183
      weight_window_checkpoint_collision =
1✔
1184
        get_node_value_bool(ww_checkpoints, "collision");
1✔
1185
    }
1186
    if (check_for_node(ww_checkpoints, "surface")) {
1✔
1187
      weight_window_checkpoint_surface =
1✔
1188
        get_node_value_bool(ww_checkpoints, "surface");
1✔
1189
    }
1190
  }
1191

1192
  if (check_for_node(root, "use_decay_photons")) {
7,298✔
1193
    settings::use_decay_photons =
11✔
1194
      get_node_value_bool(root, "use_decay_photons");
11✔
1195
  }
1196
}
7,298✔
1197

1198
void free_memory_settings()
7,519✔
1199
{
1200
  settings::statepoint_batch.clear();
7,519✔
1201
  settings::sourcepoint_batch.clear();
7,519✔
1202
  settings::source_write_surf_id.clear();
7,519✔
1203
  settings::res_scat_nuclides.clear();
7,519✔
1204
}
7,519✔
1205

1206
//==============================================================================
1207
// C API functions
1208
//==============================================================================
1209

1210
extern "C" int openmc_set_n_batches(
65✔
1211
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1212
{
1213
  if (settings::n_inactive >= n_batches) {
65✔
1214
    set_errmsg("Number of active batches must be greater than zero.");
13✔
1215
    return OPENMC_E_INVALID_ARGUMENT;
13✔
1216
  }
1217

1218
  if (simulation::current_batch >= n_batches) {
52✔
1219
    set_errmsg("Number of batches must be greater than current batch.");
13✔
1220
    return OPENMC_E_INVALID_ARGUMENT;
13✔
1221
  }
1222

1223
  if (!settings::trigger_on) {
39✔
1224
    // Set n_batches and n_max_batches to same value
1225
    settings::n_batches = n_batches;
13✔
1226
    settings::n_max_batches = n_batches;
13✔
1227
  } else {
1228
    // Set n_batches and n_max_batches based on value of set_max_batches
1229
    if (set_max_batches) {
26✔
1230
      settings::n_max_batches = n_batches;
13✔
1231
    } else {
1232
      settings::n_batches = n_batches;
13✔
1233
    }
1234
  }
1235

1236
  // Update size of k_generation and entropy
1237
  int m = settings::n_max_batches * settings::gen_per_batch;
39✔
1238
  simulation::k_generation.reserve(m);
39✔
1239
  simulation::entropy.reserve(m);
39✔
1240

1241
  // Add value of n_batches to statepoint_batch
1242
  if (add_statepoint_batch &&
65✔
1243
      !(contains(settings::statepoint_batch, n_batches)))
26✔
1244
    settings::statepoint_batch.insert(n_batches);
26✔
1245

1246
  return 0;
39✔
1247
}
1248

1249
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,765✔
1250
{
1251
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,765✔
1252

1253
  return 0;
2,765✔
1254
}
1255

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