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

openmc-dev / openmc / 18299973882

07 Oct 2025 02:14AM UTC coverage: 81.92% (-3.3%) from 85.194%
18299973882

push

github

web-flow
Switch to using coveralls github action for reporting (#3594)

16586 of 23090 branches covered (71.83%)

Branch coverage included in aggregate %.

53703 of 62712 relevant lines covered (85.63%)

43428488.21 hits per line

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

75.63
/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
double free_gas_threshold {400.0};
130
std::unordered_set<int> source_write_surf_id;
131
int64_t ssw_max_particles;
132
int64_t ssw_max_files;
133
int64_t ssw_cell_id {C_NONE};
134
SSWCellType ssw_cell_type {SSWCellType::None};
135
TemperatureMethod temperature_method {TemperatureMethod::NEAREST};
136
double temperature_tolerance {10.0};
137
double temperature_default {293.6};
138
array<double, 2> temperature_range {0.0, 0.0};
139
int trace_batch;
140
int trace_gen;
141
int64_t trace_particle;
142
vector<array<int, 3>> track_identifiers;
143
int trigger_batch_interval {1};
144
int verbosity {7};
145
double weight_cutoff {0.25};
146
double weight_survive {1.0};
147

148
} // namespace settings
149

150
//==============================================================================
151
// Functions
152
//==============================================================================
153

154
void get_run_parameters(pugi::xml_node node_base)
7,184✔
155
{
156
  using namespace settings;
157
  using namespace pugi;
158

159
  // Check number of particles
160
  if (!check_for_node(node_base, "particles")) {
7,184!
161
    fatal_error("Need to specify number of particles.");
×
162
  }
163

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

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

175
  // Get maximum number of events allowed per particle
176
  if (check_for_node(node_base, "max_particle_events")) {
7,184!
177
    max_particle_events =
×
178
      std::stoll(get_node_value(node_base, "max_particle_events"));
×
179
  }
180

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

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

194
  // Get relative number of lost particles
195
  if (check_for_node(node_base, "rel_max_lost_particles")) {
7,184!
196
    rel_max_lost_particles =
×
197
      std::stod(get_node_value(node_base, "rel_max_lost_particles"));
×
198
  }
199

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

206
  // Get number of inactive batches
207
  if (run_mode == RunMode::EIGENVALUE ||
7,184✔
208
      solver_type == SolverType::RANDOM_RAY) {
2,617✔
209
    if (check_for_node(node_base, "inactive")) {
4,968✔
210
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,718✔
211
    }
212
    if (check_for_node(node_base, "generations_per_batch")) {
4,968✔
213
      gen_per_batch =
16✔
214
        std::stoi(get_node_value(node_base, "generations_per_batch"));
16✔
215
    }
216

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

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

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

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

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

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

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

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

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

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

406
  write_message("Reading settings XML file...", 5);
1,774✔
407

408
  read_settings_xml(root);
1,774✔
409
}
1,786✔
410

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

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

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

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

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

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

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

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

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

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

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

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

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

527
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
7,790✔
528
    // Read run parameters
529
    get_run_parameters(node_mode);
7,184✔
530

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

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

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

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

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

576
  // Check for photon transport
577
  if (check_for_node(root, "photon_transport")) {
7,790✔
578
    photon_transport = get_node_value_bool(root, "photon_transport");
201✔
579

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

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

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

603
  // ==========================================================================
604
  // EXTERNAL SOURCE
605

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

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

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

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

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

644
  // Check if we want to write out source
645
  if (check_for_node(root, "write_initial_source")) {
7,780!
646
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
647
  }
648

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

655
  if (check_for_node(root, "free_gas_threshold")) {
7,780!
656
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
657
  }
658

659
  // Survival biasing
660
  if (check_for_node(root, "survival_biasing")) {
7,780✔
661
    survival_biasing = get_node_value_bool(root, "survival_biasing");
202✔
662
  }
663

664
  // Probability tables
665
  if (check_for_node(root, "ptables")) {
7,780✔
666
    urr_ptables_on = get_node_value_bool(root, "ptables");
16✔
667
  }
668

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

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

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

739
    // Reshape into track_identifiers
740
    int n_tracks = temp.size() / 3;
48✔
741
    for (int i = 0; i < n_tracks; ++i) {
192✔
742
      track_identifiers.push_back(
144✔
743
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
144✔
744
    }
745
  }
48✔
746

747
  // Shannon entropy
748
  if (solver_type == SolverType::RANDOM_RAY) {
7,780✔
749
    if (check_for_node(root, "entropy_mesh")) {
577!
750
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
751
                  "No user-defined entropy mesh is supported.");
752
    }
753
    entropy_on = true;
577✔
754
  } else if (solver_type == SolverType::MONTE_CARLO) {
7,203!
755
    if (check_for_node(root, "entropy_mesh")) {
7,203✔
756
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
379✔
757
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
379!
758
        fatal_error(fmt::format(
×
759
          "Mesh {} specified for Shannon entropy does not exist.", temp));
760
      }
761

762
      auto* m = dynamic_cast<RegularMesh*>(
379!
763
        model::meshes[model::mesh_map.at(temp)].get());
379✔
764
      if (!m)
379!
765
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
766
      simulation::entropy_mesh = m;
379✔
767

768
      // Turn on Shannon entropy calculation
769
      entropy_on = true;
379✔
770

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

787
    auto* m =
788
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
16!
789
    if (!m)
16!
790
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
791
    simulation::ufs_mesh = m;
16✔
792

793
    // Turn on uniform fission source weighting
794
    ufs_on = true;
16✔
795

796
  } else if (check_for_node(root, "uniform_fs")) {
7,764!
797
    fatal_error(
×
798
      "Specifying a UFS mesh via the <uniform_fs> element "
799
      "is deprecated. Please create a mesh using <mesh> and then reference "
800
      "it by specifying its ID in a <ufs_mesh> element.");
801
  }
802

803
  // Check if the user has specified to write state points
804
  if (check_for_node(root, "state_point")) {
7,780✔
805

806
    // Get pointer to state_point node
807
    auto node_sp = root.child("state_point");
171✔
808

809
    // Determine number of batches at which to store state points
810
    if (check_for_node(node_sp, "batches")) {
171!
811
      // User gave specific batches to write state points
812
      auto temp = get_node_array<int>(node_sp, "batches");
171✔
813
      for (const auto& b : temp) {
524✔
814
        statepoint_batch.insert(b);
353✔
815
      }
816
    } else {
171✔
817
      // If neither were specified, write state point at last batch
818
      statepoint_batch.insert(n_batches);
×
819
    }
820
  } else {
821
    // If no <state_point> tag was present, by default write state point at
822
    // last batch only
823
    statepoint_batch.insert(n_batches);
7,609✔
824
  }
825

826
  // Check if the user has specified to write source points
827
  if (check_for_node(root, "source_point")) {
7,780✔
828
    // Get source_point node
829
    xml_node node_sp = root.child("source_point");
107✔
830

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

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

864
  // Check is the user specified to convert strength to statistical weight
865
  if (check_for_node(root, "uniform_source_sampling")) {
7,780✔
866
    uniform_source_sampling =
57✔
867
      get_node_value_bool(root, "uniform_source_sampling");
57✔
868
  }
869

870
  // Check if the user has specified to write surface source
871
  if (check_for_node(root, "surf_source_write")) {
7,780✔
872
    surf_source_write = true;
414✔
873
    // Get surface source write node
874
    xml_node node_ssw = root.child("surf_source_write");
414✔
875

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

886
    // Get maximum number of particles to be banked per surface
887
    if (check_for_node(node_ssw, "max_particles")) {
414✔
888
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
405✔
889
    } else {
890
      fatal_error("A maximum number of particles needs to be specified "
9✔
891
                  "using the 'max_particles' parameter to store surface "
892
                  "source points.");
893
    }
894

895
    // Get maximum number of surface source files to be created
896
    if (check_for_node(node_ssw, "max_source_files")) {
405✔
897
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
33✔
898
    } else {
899
      ssw_max_files = 1;
372✔
900
    }
901

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

928
  // If source is not separate and is to be written out in the statepoint file,
929
  // make sure that the sourcepoint batch numbers are contained in the
930
  // statepoint list
931
  if (!source_separate) {
7,735✔
932
    for (const auto& b : sourcepoint_batch) {
15,422✔
933
      if (!contains(statepoint_batch, b)) {
7,778!
934
        fatal_error(
×
935
          "Sourcepoint batches are not a subset of statepoint batches.");
936
      }
937
    }
938
  }
939

940
  // Check if the user has specified to not reduce tallies at the end of every
941
  // batch
942
  if (check_for_node(root, "no_reduce")) {
7,735!
943
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
×
944
  }
945

946
  // Check if the user has specified to use confidence intervals for
947
  // uncertainties rather than standard deviations
948
  if (check_for_node(root, "confidence_intervals")) {
7,735✔
949
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
16✔
950
  }
951

952
  // Check for output options
953
  if (check_for_node(root, "output")) {
7,735✔
954
    // Get pointer to output node
955
    pugi::xml_node node_output = root.child("output");
585✔
956

957
    // Check for summary option
958
    if (check_for_node(node_output, "summary")) {
585✔
959
      output_summary = get_node_value_bool(node_output, "summary");
558✔
960
    }
961

962
    // Check for ASCII tallies output option
963
    if (check_for_node(node_output, "tallies")) {
585✔
964
      output_tallies = get_node_value_bool(node_output, "tallies");
95✔
965
    }
966

967
    // Set output directory if a path has been specified
968
    if (check_for_node(node_output, "path")) {
585!
969
      path_output = get_node_value(node_output, "path");
×
970
      if (!ends_with(path_output, "/")) {
×
971
        path_output += "/";
×
972
      }
973
    }
974
  }
975

976
  // Resonance scattering parameters
977
  if (check_for_node(root, "resonance_scattering")) {
7,735✔
978
    xml_node node_res_scat = root.child("resonance_scattering");
16✔
979

980
    // See if resonance scattering is enabled
981
    if (check_for_node(node_res_scat, "enable")) {
16!
982
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
16✔
983
    } else {
984
      res_scat_on = true;
×
985
    }
986

987
    // Determine what method is used
988
    if (check_for_node(node_res_scat, "method")) {
16!
989
      auto temp = get_node_value(node_res_scat, "method", true, true);
16✔
990
      if (temp == "rvs") {
16!
991
        res_scat_method = ResScatMethod::rvs;
16✔
992
      } else if (temp == "dbrc") {
×
993
        res_scat_method = ResScatMethod::dbrc;
×
994
      } else {
995
        fatal_error(
×
996
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
997
      }
998
    }
16✔
999

1000
    // Minimum energy for resonance scattering
1001
    if (check_for_node(node_res_scat, "energy_min")) {
16!
1002
      res_scat_energy_min =
16✔
1003
        std::stod(get_node_value(node_res_scat, "energy_min"));
16✔
1004
    }
1005
    if (res_scat_energy_min < 0.0) {
16!
1006
      fatal_error("Lower resonance scattering energy bound is negative");
×
1007
    }
1008

1009
    // Maximum energy for resonance scattering
1010
    if (check_for_node(node_res_scat, "energy_max")) {
16!
1011
      res_scat_energy_max =
16✔
1012
        std::stod(get_node_value(node_res_scat, "energy_max"));
16✔
1013
    }
1014
    if (res_scat_energy_max < res_scat_energy_min) {
16!
1015
      fatal_error("Upper resonance scattering energy bound is below the "
×
1016
                  "lower resonance scattering energy bound.");
1017
    }
1018

1019
    // Get resonance scattering nuclides
1020
    if (check_for_node(node_res_scat, "nuclides")) {
16!
1021
      res_scat_nuclides =
1022
        get_node_array<std::string>(node_res_scat, "nuclides");
16✔
1023
    }
1024
  }
1025

1026
  // Get volume calculations
1027
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
8,179✔
1028
    model::volume_calcs.emplace_back(node_vol);
444✔
1029
  }
1030

1031
  // Get temperature settings
1032
  if (check_for_node(root, "temperature_default")) {
7,735✔
1033
    temperature_default =
172✔
1034
      std::stod(get_node_value(root, "temperature_default"));
172✔
1035
  }
1036
  if (check_for_node(root, "temperature_method")) {
7,735✔
1037
    auto temp = get_node_value(root, "temperature_method", true, true);
325✔
1038
    if (temp == "nearest") {
325✔
1039
      temperature_method = TemperatureMethod::NEAREST;
140✔
1040
    } else if (temp == "interpolation") {
185!
1041
      temperature_method = TemperatureMethod::INTERPOLATION;
185✔
1042
    } else {
1043
      fatal_error("Unknown temperature method: " + temp);
×
1044
    }
1045
  }
325✔
1046
  if (check_for_node(root, "temperature_tolerance")) {
7,735✔
1047
    temperature_tolerance =
177✔
1048
      std::stod(get_node_value(root, "temperature_tolerance"));
177✔
1049
  }
1050
  if (check_for_node(root, "temperature_multipole")) {
7,735✔
1051
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
32✔
1052

1053
    // Multipole currently doesn't work with photon transport
1054
    if (temperature_multipole && photon_transport) {
32!
1055
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1056
                  "photon transport.");
1057
    }
1058
  }
1059
  if (check_for_node(root, "temperature_range")) {
7,735!
1060
    auto range = get_node_array<double>(root, "temperature_range");
×
1061
    temperature_range[0] = range.at(0);
×
1062
    temperature_range[1] = range.at(1);
×
1063
  }
×
1064

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

1079
  // Check for tabular_legendre options
1080
  if (check_for_node(root, "tabular_legendre")) {
7,726✔
1081
    // Get pointer to tabular_legendre node
1082
    xml_node node_tab_leg = root.child("tabular_legendre");
96✔
1083

1084
    // Check for enable option
1085
    if (check_for_node(node_tab_leg, "enable")) {
96!
1086
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
96✔
1087
    }
1088

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

1101
  // Check whether create delayed neutrons in fission
1102
  if (check_for_node(root, "create_delayed_neutrons")) {
7,726!
1103
    create_delayed_neutrons =
×
1104
      get_node_value_bool(root, "create_delayed_neutrons");
×
1105
  }
1106

1107
  // Check whether create fission sites
1108
  if (run_mode == RunMode::FIXED_SOURCE) {
7,726✔
1109
    if (check_for_node(root, "create_fission_neutrons")) {
2,571✔
1110
      create_fission_neutrons =
16✔
1111
        get_node_value_bool(root, "create_fission_neutrons");
16✔
1112
    }
1113
  }
1114

1115
  // Check whether to scale fission photon yields
1116
  if (check_for_node(root, "delayed_photon_scaling")) {
7,726!
1117
    delayed_photon_scaling =
×
1118
      get_node_value_bool(root, "delayed_photon_scaling");
×
1119
  }
1120

1121
  // Check whether to use event-based parallelism
1122
  if (check_for_node(root, "event_based")) {
7,726!
1123
    event_based = get_node_value_bool(root, "event_based");
×
1124
  }
1125

1126
  // Check whether material cell offsets should be generated
1127
  if (check_for_node(root, "material_cell_offsets")) {
7,726!
1128
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1129
  }
1130

1131
  // Weight window information
1132
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
7,821✔
1133
    variance_reduction::weight_windows.emplace_back(
95✔
1134
      std::make_unique<WeightWindows>(node_ww));
190✔
1135
  }
1136

1137
  // Enable weight windows by default if one or more are present
1138
  if (variance_reduction::weight_windows.size() > 0)
7,726✔
1139
    settings::weight_windows_on = true;
68✔
1140

1141
  // read weight windows from file
1142
  if (check_for_node(root, "weight_windows_file")) {
7,726!
1143
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1144
  }
1145

1146
  // read settings for weight windows value, this will override
1147
  // the automatic setting even if weight windows are present
1148
  if (check_for_node(root, "weight_windows_on")) {
7,726✔
1149
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
37✔
1150
  }
1151

1152
  if (check_for_node(root, "max_secondaries")) {
7,726!
1153
    settings::max_secondaries =
×
1154
      std::stoi(get_node_value(root, "max_secondaries"));
×
1155
  }
1156

1157
  if (check_for_node(root, "max_history_splits")) {
7,726✔
1158
    settings::max_history_splits =
242✔
1159
      std::stoi(get_node_value(root, "max_history_splits"));
242✔
1160
  }
1161

1162
  if (check_for_node(root, "max_tracks")) {
7,726✔
1163
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
48✔
1164
  }
1165

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

1184
  // Set up weight window checkpoints
1185
  if (check_for_node(root, "weight_window_checkpoints")) {
7,726✔
1186
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
1!
1187
    if (check_for_node(ww_checkpoints, "collision")) {
1!
1188
      weight_window_checkpoint_collision =
1✔
1189
        get_node_value_bool(ww_checkpoints, "collision");
1!
1190
    }
1191
    if (check_for_node(ww_checkpoints, "surface")) {
1!
1192
      weight_window_checkpoint_surface =
1✔
1193
        get_node_value_bool(ww_checkpoints, "surface");
1!
1194
    }
1195
  }
1196

1197
  if (check_for_node(root, "use_decay_photons")) {
7,726✔
1198
    settings::use_decay_photons =
11✔
1199
      get_node_value_bool(root, "use_decay_photons");
11✔
1200
  }
1201
}
7,726✔
1202

1203
void free_memory_settings()
8,084✔
1204
{
1205
  settings::statepoint_batch.clear();
8,084✔
1206
  settings::sourcepoint_batch.clear();
8,084✔
1207
  settings::source_write_surf_id.clear();
8,084✔
1208
  settings::res_scat_nuclides.clear();
8,084✔
1209
}
8,084✔
1210

1211
//==============================================================================
1212
// C API functions
1213
//==============================================================================
1214

1215
extern "C" int openmc_set_n_batches(
75✔
1216
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1217
{
1218
  if (settings::n_inactive >= n_batches) {
75✔
1219
    set_errmsg("Number of active batches must be greater than zero.");
15✔
1220
    return OPENMC_E_INVALID_ARGUMENT;
15✔
1221
  }
1222

1223
  if (simulation::current_batch >= n_batches) {
60✔
1224
    set_errmsg("Number of batches must be greater than current batch.");
15✔
1225
    return OPENMC_E_INVALID_ARGUMENT;
15✔
1226
  }
1227

1228
  if (!settings::trigger_on) {
45✔
1229
    // Set n_batches and n_max_batches to same value
1230
    settings::n_batches = n_batches;
15✔
1231
    settings::n_max_batches = n_batches;
15✔
1232
  } else {
1233
    // Set n_batches and n_max_batches based on value of set_max_batches
1234
    if (set_max_batches) {
30✔
1235
      settings::n_max_batches = n_batches;
15✔
1236
    } else {
1237
      settings::n_batches = n_batches;
15✔
1238
    }
1239
  }
1240

1241
  // Update size of k_generation and entropy
1242
  int m = settings::n_max_batches * settings::gen_per_batch;
45✔
1243
  simulation::k_generation.reserve(m);
45✔
1244
  simulation::entropy.reserve(m);
45✔
1245

1246
  // Add value of n_batches to statepoint_batch
1247
  if (add_statepoint_batch &&
75✔
1248
      !(contains(settings::statepoint_batch, n_batches)))
30!
1249
    settings::statepoint_batch.insert(n_batches);
30✔
1250

1251
  return 0;
45✔
1252
}
1253

1254
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
3,000✔
1255
{
1256
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
3,000✔
1257

1258
  return 0;
3,000✔
1259
}
1260

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

© 2025 Coveralls, Inc