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

openmc-dev / openmc / 20113241616

10 Dec 2025 09:05PM UTC coverage: 82.165% (+0.07%) from 82.1%
20113241616

Pull #3674

github

web-flow
Merge 589cc1264 into d09fbc61b
Pull Request #3674: Add user documentation for DAGMCUniverse synchronization

16996 of 23543 branches covered (72.19%)

Branch coverage included in aggregate %.

55087 of 64187 relevant lines covered (85.82%)

43499274.33 hits per line

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

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

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

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

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

39
namespace openmc {
40

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

45
namespace settings {
46

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

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

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

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

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

152
} // namespace settings
153

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

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

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

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

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

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

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

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

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

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

210
  // Get number of inactive batches
211
  if (run_mode == RunMode::EIGENVALUE ||
7,032✔
212
      solver_type == SolverType::RANDOM_RAY) {
2,644✔
213
    if (check_for_node(node_base, "inactive")) {
4,789✔
214
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,604✔
215
    }
216
    if (check_for_node(node_base, "generations_per_batch")) {
4,789✔
217
      gen_per_batch =
16✔
218
        std::stoi(get_node_value(node_base, "generations_per_batch"));
16✔
219
    }
220

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

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

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

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

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

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

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

395
  // Get root element
396
  xml_node root = doc.document_element();
1,359✔
397

398
  // Verbosity
399
  if (check_for_node(root, "verbosity")) {
1,359✔
400
    verbosity = std::stoi(get_node_value(root, "verbosity"));
182✔
401
  }
402

403
  // To this point, we haven't displayed any output since we didn't know what
404
  // the verbosity is. Now that we checked for it, show the title if necessary
405
  if (mpi::master) {
1,359✔
406
    if (verbosity >= 2)
1,134✔
407
      title();
962✔
408
  }
409

410
  write_message("Reading settings XML file...", 5);
1,359✔
411

412
  read_settings_xml(root);
1,359✔
413
}
1,371✔
414

415
void read_settings_xml(pugi::xml_node root)
7,631✔
416
{
417
  using namespace settings;
418
  using namespace pugi;
419

420
  // Find if a multi-group or continuous-energy simulation is desired
421
  if (check_for_node(root, "energy_mode")) {
7,631✔
422
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
1,175✔
423
    if (temp_str == "mg" || temp_str == "multi-group") {
1,175!
424
      run_CE = false;
1,175✔
425
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
426
      run_CE = true;
×
427
    }
428
  }
1,175✔
429

430
  // Check for user meshes and allocate
431
  read_meshes(root);
7,631✔
432

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

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

457
  // Check for a trigger node and get trigger information
458
  if (check_for_node(root, "trigger")) {
7,631✔
459
    xml_node node_trigger = root.child("trigger");
162✔
460

461
    // Check if trigger(s) are to be turned on
462
    trigger_on = get_node_value_bool(node_trigger, "active");
162✔
463

464
    if (trigger_on) {
162✔
465
      if (check_for_node(node_trigger, "max_batches")) {
146!
466
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
146✔
467
      } else {
468
        fatal_error("<max_batches> must be specified with triggers");
×
469
      }
470

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

484
  // Check run mode if it hasn't been set from the command line
485
  xml_node node_mode;
7,631✔
486
  if (run_mode == RunMode::UNSET) {
7,631✔
487
    if (check_for_node(root, "run_mode")) {
7,064✔
488
      std::string temp_str = get_node_value(root, "run_mode", true, true);
7,032✔
489
      if (temp_str == "eigenvalue") {
7,032✔
490
        run_mode = RunMode::EIGENVALUE;
4,356✔
491
      } else if (temp_str == "fixed source") {
2,676✔
492
        run_mode = RunMode::FIXED_SOURCE;
2,644✔
493
      } else if (temp_str == "plot") {
32!
494
        run_mode = RunMode::PLOTTING;
×
495
      } else if (temp_str == "particle restart") {
32!
496
        run_mode = RunMode::PARTICLE;
×
497
      } else if (temp_str == "volume") {
32!
498
        run_mode = RunMode::VOLUME;
32✔
499
      } else {
500
        fatal_error("Unrecognized run mode: " + temp_str);
×
501
      }
502

503
      // Assume XML specifies <particles>, <batches>, etc. directly
504
      node_mode = root;
7,032✔
505
    } else {
7,032✔
506
      warning("<run_mode> should be specified.");
32✔
507

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

523
  // Check solver type
524
  if (check_for_node(root, "random_ray")) {
7,631✔
525
    solver_type = SolverType::RANDOM_RAY;
641✔
526
    if (run_CE)
641!
527
      fatal_error("multi-group energy mode must be specified in settings XML "
×
528
                  "when using the random ray solver.");
529
  }
530

531
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
7,631✔
532
    // Read run parameters
533
    get_run_parameters(node_mode);
7,032✔
534

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

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

564
  // Copy plotting random number seed if specified
565
  if (check_for_node(root, "plot_seed")) {
7,622!
566
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
567
    model::plotter_seed = seed;
×
568
  }
569

570
  // Copy random number seed if specified
571
  if (check_for_node(root, "seed")) {
7,622✔
572
    auto seed = std::stoll(get_node_value(root, "seed"));
589✔
573
    openmc_set_seed(seed);
589✔
574
  }
575

576
  // Copy random number stride if specified
577
  if (check_for_node(root, "stride")) {
7,622✔
578
    auto stride = std::stoull(get_node_value(root, "stride"));
16✔
579
    openmc_set_stride(stride);
16✔
580
  }
581

582
  // Check for electron treatment
583
  if (check_for_node(root, "electron_treatment")) {
7,622✔
584
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
70✔
585
    if (temp_str == "led") {
70✔
586
      electron_treatment = ElectronTreatment::LED;
11✔
587
    } else if (temp_str == "ttb") {
59!
588
      electron_treatment = ElectronTreatment::TTB;
59✔
589
    } else {
590
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
591
    }
592
  }
70✔
593

594
  // Check for photon transport
595
  if (check_for_node(root, "photon_transport")) {
7,622✔
596
    photon_transport = get_node_value_bool(root, "photon_transport");
199✔
597

598
    if (!run_CE && photon_transport) {
199!
599
      fatal_error("Photon transport is not currently supported in "
×
600
                  "multigroup mode");
601
    }
602
  }
603

604
  // Number of bins for logarithmic grid
605
  if (check_for_node(root, "log_grid_bins")) {
7,622✔
606
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
16✔
607
    if (n_log_bins < 1) {
16!
608
      fatal_error("Number of bins for logarithmic grid must be greater "
×
609
                  "than zero.");
610
    }
611
  }
612

613
  // Number of OpenMP threads
614
  if (check_for_node(root, "threads")) {
7,622!
615
    if (mpi::master)
×
616
      warning("The <threads> element has been deprecated. Use "
×
617
              "the OMP_NUM_THREADS environment variable to set the number of "
618
              "threads.");
619
  }
620

621
  // ==========================================================================
622
  // EXTERNAL SOURCE
623

624
  // Get point to list of <source> elements and make sure there is at least one
625
  for (pugi::xml_node node : root.children("source")) {
14,709✔
626
    model::external_sources.push_back(Source::create(node));
7,097✔
627
  }
628

629
  // Check if the user has specified to read surface source
630
  if (check_for_node(root, "surf_source_read")) {
7,612✔
631
    surf_source_read = true;
32✔
632
    // Get surface source read node
633
    xml_node node_ssr = root.child("surf_source_read");
32✔
634

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

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

655
  // Build probability mass function for sampling external sources
656
  vector<double> source_strengths;
7,612✔
657
  for (auto& s : model::external_sources) {
16,721✔
658
    source_strengths.push_back(s->strength());
9,109✔
659
  }
660
  model::external_sources_probability.assign(source_strengths);
7,612✔
661

662
  // Check if we want to write out source
663
  if (check_for_node(root, "write_initial_source")) {
7,612!
664
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
665
  }
666

667
  // Get relative number of lost particles
668
  if (check_for_node(root, "source_rejection_fraction")) {
7,612✔
669
    source_rejection_fraction =
6✔
670
      std::stod(get_node_value(root, "source_rejection_fraction"));
6!
671
  }
672

673
  if (check_for_node(root, "free_gas_threshold")) {
7,612!
674
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
675
  }
676

677
  // Survival biasing
678
  if (check_for_node(root, "survival_biasing")) {
7,612✔
679
    survival_biasing = get_node_value_bool(root, "survival_biasing");
177✔
680
  }
681

682
  // Probability tables
683
  if (check_for_node(root, "ptables")) {
7,612✔
684
    urr_ptables_on = get_node_value_bool(root, "ptables");
16✔
685
  }
686

687
  // Cutoffs
688
  if (check_for_node(root, "cutoff")) {
7,612✔
689
    xml_node node_cutoff = root.child("cutoff");
145✔
690
    if (check_for_node(node_cutoff, "weight")) {
145✔
691
      weight_cutoff = std::stod(get_node_value(node_cutoff, "weight"));
16✔
692
    }
693
    if (check_for_node(node_cutoff, "weight_avg")) {
145✔
694
      weight_survive = std::stod(get_node_value(node_cutoff, "weight_avg"));
16✔
695
    }
696
    if (check_for_node(node_cutoff, "survival_normalization")) {
145!
697
      survival_normalization =
×
698
        get_node_value_bool(node_cutoff, "survival_normalization");
×
699
    }
700
    if (check_for_node(node_cutoff, "energy_neutron")) {
145✔
701
      energy_cutoff[0] =
32✔
702
        std::stod(get_node_value(node_cutoff, "energy_neutron"));
16✔
703
    } else if (check_for_node(node_cutoff, "energy")) {
129!
704
      warning("The use of an <energy> cutoff is deprecated and should "
×
705
              "be replaced by <energy_neutron>.");
706
      energy_cutoff[0] = std::stod(get_node_value(node_cutoff, "energy"));
×
707
    }
708
    if (check_for_node(node_cutoff, "energy_photon")) {
145✔
709
      energy_cutoff[1] =
172✔
710
        std::stod(get_node_value(node_cutoff, "energy_photon"));
86✔
711
    }
712
    if (check_for_node(node_cutoff, "energy_electron")) {
145!
713
      energy_cutoff[2] =
×
714
        std::stof(get_node_value(node_cutoff, "energy_electron"));
×
715
    }
716
    if (check_for_node(node_cutoff, "energy_positron")) {
145!
717
      energy_cutoff[3] =
×
718
        std::stod(get_node_value(node_cutoff, "energy_positron"));
×
719
    }
720
    if (check_for_node(node_cutoff, "time_neutron")) {
145✔
721
      time_cutoff[0] = std::stod(get_node_value(node_cutoff, "time_neutron"));
27✔
722
    }
723
    if (check_for_node(node_cutoff, "time_photon")) {
145!
724
      time_cutoff[1] = std::stod(get_node_value(node_cutoff, "time_photon"));
×
725
    }
726
    if (check_for_node(node_cutoff, "time_electron")) {
145!
727
      time_cutoff[2] = std::stod(get_node_value(node_cutoff, "time_electron"));
×
728
    }
729
    if (check_for_node(node_cutoff, "time_positron")) {
145!
730
      time_cutoff[3] = std::stod(get_node_value(node_cutoff, "time_positron"));
×
731
    }
732
  }
733

734
  // Particle trace
735
  if (check_for_node(root, "trace")) {
7,612✔
736
    auto temp = get_node_array<int64_t>(root, "trace");
16✔
737
    if (temp.size() != 3) {
16!
738
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
739
                  "batch, generation, and particle number.");
740
    }
741
    trace_batch = temp.at(0);
16✔
742
    trace_gen = temp.at(1);
16✔
743
    trace_particle = temp.at(2);
16✔
744
  }
16✔
745

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

757
    // Reshape into track_identifiers
758
    int n_tracks = temp.size() / 3;
48✔
759
    for (int i = 0; i < n_tracks; ++i) {
192✔
760
      track_identifiers.push_back(
144✔
761
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
144✔
762
    }
763
  }
48✔
764

765
  // Shannon entropy
766
  if (solver_type == SolverType::RANDOM_RAY) {
7,612✔
767
    if (check_for_node(root, "entropy_mesh")) {
641!
768
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
769
                  "No user-defined entropy mesh is supported.");
770
    }
771
    entropy_on = true;
641✔
772
  } else if (solver_type == SolverType::MONTE_CARLO) {
6,971!
773
    if (check_for_node(root, "entropy_mesh")) {
6,971✔
774
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
335✔
775
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
335!
776
        fatal_error(fmt::format(
×
777
          "Mesh {} specified for Shannon entropy does not exist.", temp));
778
      }
779

780
      auto* m = dynamic_cast<RegularMesh*>(
335!
781
        model::meshes[model::mesh_map.at(temp)].get());
335✔
782
      if (!m)
335!
783
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
784
      simulation::entropy_mesh = m;
335✔
785

786
      // Turn on Shannon entropy calculation
787
      entropy_on = true;
335✔
788

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

805
    auto* m =
806
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
16!
807
    if (!m)
16!
808
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
809
    simulation::ufs_mesh = m;
16✔
810

811
    // Turn on uniform fission source weighting
812
    ufs_on = true;
16✔
813

814
  } else if (check_for_node(root, "uniform_fs")) {
7,596!
815
    fatal_error(
×
816
      "Specifying a UFS mesh via the <uniform_fs> element "
817
      "is deprecated. Please create a mesh using <mesh> and then reference "
818
      "it by specifying its ID in a <ufs_mesh> element.");
819
  }
820

821
  // Check if the user has specified to write state points
822
  if (check_for_node(root, "state_point")) {
7,612✔
823

824
    // Get pointer to state_point node
825
    auto node_sp = root.child("state_point");
167✔
826

827
    // Determine number of batches at which to store state points
828
    if (check_for_node(node_sp, "batches")) {
167!
829
      // User gave specific batches to write state points
830
      auto temp = get_node_array<int>(node_sp, "batches");
167✔
831
      for (const auto& b : temp) {
512✔
832
        statepoint_batch.insert(b);
345✔
833
      }
834
    } else {
167✔
835
      // If neither were specified, write state point at last batch
836
      statepoint_batch.insert(n_batches);
×
837
    }
838
  } else {
839
    // If no <state_point> tag was present, by default write state point at
840
    // last batch only
841
    statepoint_batch.insert(n_batches);
7,445✔
842
  }
843

844
  // Check if the user has specified to write source points
845
  if (check_for_node(root, "source_point")) {
7,612✔
846
    // Get source_point node
847
    xml_node node_sp = root.child("source_point");
107✔
848

849
    // Determine batches at which to store source points
850
    if (check_for_node(node_sp, "batches")) {
107✔
851
      // User gave specific batches to write source points
852
      auto temp = get_node_array<int>(node_sp, "batches");
48✔
853
      for (const auto& b : temp) {
128✔
854
        sourcepoint_batch.insert(b);
80✔
855
      }
856
    } else {
48✔
857
      // If neither were specified, write source points with state points
858
      sourcepoint_batch = statepoint_batch;
59✔
859
    }
860

861
    // Check if the user has specified to write binary source file
862
    if (check_for_node(node_sp, "separate")) {
107✔
863
      source_separate = get_node_value_bool(node_sp, "separate");
75✔
864
    }
865
    if (check_for_node(node_sp, "write")) {
107!
866
      source_write = get_node_value_bool(node_sp, "write");
×
867
    }
868
    if (check_for_node(node_sp, "mcpl")) {
107✔
869
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
27✔
870
    }
871
    if (check_for_node(node_sp, "overwrite_latest")) {
107✔
872
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
16✔
873
      source_separate = source_latest;
16✔
874
    }
875
  } else {
876
    // If no <source_point> tag was present, by default we keep source bank in
877
    // statepoint file and write it out at statepoints intervals
878
    source_separate = false;
7,505✔
879
    sourcepoint_batch = statepoint_batch;
7,505✔
880
  }
881

882
  // Check is the user specified to convert strength to statistical weight
883
  if (check_for_node(root, "uniform_source_sampling")) {
7,612✔
884
    uniform_source_sampling =
55✔
885
      get_node_value_bool(root, "uniform_source_sampling");
55✔
886
  }
887

888
  // Check if the user has specified to write surface source
889
  if (check_for_node(root, "surf_source_write")) {
7,612✔
890
    surf_source_write = true;
412✔
891
    // Get surface source write node
892
    xml_node node_ssw = root.child("surf_source_write");
412✔
893

894
    // Determine surface ids at which crossing particles are to be banked.
895
    // If no surfaces are specified, all surfaces in the model will be used
896
    // to bank source points.
897
    if (check_for_node(node_ssw, "surface_ids")) {
412✔
898
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
202✔
899
      for (const auto& b : temp) {
994✔
900
        source_write_surf_id.insert(b);
792✔
901
      }
902
    }
202✔
903

904
    // Get maximum number of particles to be banked per surface
905
    if (check_for_node(node_ssw, "max_particles")) {
412✔
906
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
403✔
907
    } else {
908
      fatal_error("A maximum number of particles needs to be specified "
9✔
909
                  "using the 'max_particles' parameter to store surface "
910
                  "source points.");
911
    }
912

913
    // Get maximum number of surface source files to be created
914
    if (check_for_node(node_ssw, "max_source_files")) {
403✔
915
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
33✔
916
    } else {
917
      ssw_max_files = 1;
370✔
918
    }
919

920
    if (check_for_node(node_ssw, "mcpl")) {
403✔
921
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
11✔
922
    }
923
    // Get cell information
924
    if (check_for_node(node_ssw, "cell")) {
403✔
925
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
104✔
926
      ssw_cell_type = SSWCellType::Both;
104✔
927
    }
928
    if (check_for_node(node_ssw, "cellfrom")) {
403✔
929
      if (ssw_cell_id != C_NONE) {
90✔
930
        fatal_error(
18✔
931
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
932
      }
933
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
72✔
934
      ssw_cell_type = SSWCellType::From;
72✔
935
    }
936
    if (check_for_node(node_ssw, "cellto")) {
385✔
937
      if (ssw_cell_id != C_NONE) {
71✔
938
        fatal_error(
18✔
939
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
940
      }
941
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
53✔
942
      ssw_cell_type = SSWCellType::To;
53✔
943
    }
944
  }
945

946
  // Check if the user has specified to write specific collisions
947
  if (check_for_node(root, "collision_track")) {
7,567✔
948
    settings::collision_track = true;
155✔
949
    // Get collision track node
950
    xml_node node_ct = root.child("collision_track");
155✔
951
    collision_track_config = CollisionTrackConfig {};
155✔
952

953
    // Determine cell ids at which crossing particles are to be banked
954
    if (check_for_node(node_ct, "cell_ids")) {
155✔
955
      auto temp = get_node_array<int>(node_ct, "cell_ids");
81✔
956
      for (const auto& b : temp) {
211✔
957
        collision_track_config.cell_ids.insert(b);
130✔
958
      }
959
    }
81✔
960
    if (check_for_node(node_ct, "reactions")) {
155✔
961
      auto temp = get_node_array<std::string>(node_ct, "reactions");
65✔
962
      for (const auto& b : temp) {
178✔
963
        int reaction_int = reaction_type(b);
113✔
964
        if (reaction_int > 0) {
113!
965
          collision_track_config.mt_numbers.insert(reaction_int);
113✔
966
        }
967
      }
968
    }
65✔
969
    if (check_for_node(node_ct, "universe_ids")) {
155✔
970
      auto temp = get_node_array<int>(node_ct, "universe_ids");
32✔
971
      for (const auto& b : temp) {
64✔
972
        collision_track_config.universe_ids.insert(b);
32✔
973
      }
974
    }
32✔
975
    if (check_for_node(node_ct, "material_ids")) {
155✔
976
      auto temp = get_node_array<int>(node_ct, "material_ids");
32✔
977
      for (const auto& b : temp) {
80✔
978
        collision_track_config.material_ids.insert(b);
48✔
979
      }
980
    }
32✔
981
    if (check_for_node(node_ct, "nuclides")) {
155✔
982
      auto temp = get_node_array<std::string>(node_ct, "nuclides");
32✔
983
      for (const auto& b : temp) {
128✔
984
        collision_track_config.nuclides.insert(b);
96✔
985
      }
986
    }
32✔
987
    if (check_for_node(node_ct, "deposited_E_threshold")) {
155✔
988
      collision_track_config.deposited_energy_threshold =
32✔
989
        std::stod(get_node_value(node_ct, "deposited_E_threshold"));
32✔
990
    }
991
    // Get maximum number of particles to be banked per collision
992
    if (check_for_node(node_ct, "max_collisions")) {
155!
993
      collision_track_config.max_collisions =
155✔
994
        std::stoll(get_node_value(node_ct, "max_collisions"));
155✔
995
    } else {
996
      warning("A maximum number of collisions needs to be specified. "
×
997
              "By default the code sets 'max_collisions' parameter equals to "
998
              "1000.");
999
    }
1000
    // Get maximum number of collision_track files to be created
1001
    if (check_for_node(node_ct, "max_collision_track_files")) {
155!
1002
      collision_track_config.max_files =
×
1003
        std::stoll(get_node_value(node_ct, "max_collision_track_files"));
×
1004
    }
1005
    if (check_for_node(node_ct, "mcpl")) {
155✔
1006
      collision_track_config.mcpl_write = get_node_value_bool(node_ct, "mcpl");
22✔
1007
    }
1008
  }
1009

1010
  // If source is not separate and is to be written out in the statepoint
1011
  // file, make sure that the sourcepoint batch numbers are contained in the
1012
  // statepoint list
1013
  if (!source_separate) {
7,567✔
1014
    for (const auto& b : sourcepoint_batch) {
15,082✔
1015
      if (!contains(statepoint_batch, b)) {
7,606!
1016
        fatal_error(
×
1017
          "Sourcepoint batches are not a subset of statepoint batches.");
1018
      }
1019
    }
1020
  }
1021

1022
  // Check if the user has specified to not reduce tallies at the end of every
1023
  // batch
1024
  if (check_for_node(root, "no_reduce")) {
7,567✔
1025
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
32✔
1026
  }
1027

1028
  // Check if the user has specified to use confidence intervals for
1029
  // uncertainties rather than standard deviations
1030
  if (check_for_node(root, "confidence_intervals")) {
7,567✔
1031
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
16✔
1032
  }
1033

1034
  // Check for output options
1035
  if (check_for_node(root, "output")) {
7,567✔
1036
    // Get pointer to output node
1037
    pugi::xml_node node_output = root.child("output");
606✔
1038

1039
    // Check for summary option
1040
    if (check_for_node(node_output, "summary")) {
606✔
1041
      output_summary = get_node_value_bool(node_output, "summary");
579✔
1042
    }
1043

1044
    // Check for ASCII tallies output option
1045
    if (check_for_node(node_output, "tallies")) {
606✔
1046
      output_tallies = get_node_value_bool(node_output, "tallies");
184✔
1047
    }
1048

1049
    // Set output directory if a path has been specified
1050
    if (check_for_node(node_output, "path")) {
606!
1051
      path_output = get_node_value(node_output, "path");
×
1052
      if (!ends_with(path_output, "/")) {
×
1053
        path_output += "/";
×
1054
      }
1055
    }
1056
  }
1057

1058
  // Resonance scattering parameters
1059
  if (check_for_node(root, "resonance_scattering")) {
7,567✔
1060
    xml_node node_res_scat = root.child("resonance_scattering");
16✔
1061

1062
    // See if resonance scattering is enabled
1063
    if (check_for_node(node_res_scat, "enable")) {
16!
1064
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
16✔
1065
    } else {
1066
      res_scat_on = true;
×
1067
    }
1068

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

1082
    // Minimum energy for resonance scattering
1083
    if (check_for_node(node_res_scat, "energy_min")) {
16!
1084
      res_scat_energy_min =
16✔
1085
        std::stod(get_node_value(node_res_scat, "energy_min"));
16✔
1086
    }
1087
    if (res_scat_energy_min < 0.0) {
16!
1088
      fatal_error("Lower resonance scattering energy bound is negative");
×
1089
    }
1090

1091
    // Maximum energy for resonance scattering
1092
    if (check_for_node(node_res_scat, "energy_max")) {
16!
1093
      res_scat_energy_max =
16✔
1094
        std::stod(get_node_value(node_res_scat, "energy_max"));
16✔
1095
    }
1096
    if (res_scat_energy_max < res_scat_energy_min) {
16!
1097
      fatal_error("Upper resonance scattering energy bound is below the "
×
1098
                  "lower resonance scattering energy bound.");
1099
    }
1100

1101
    // Get resonance scattering nuclides
1102
    if (check_for_node(node_res_scat, "nuclides")) {
16!
1103
      res_scat_nuclides =
1104
        get_node_array<std::string>(node_res_scat, "nuclides");
16✔
1105
    }
1106
  }
1107

1108
  // Get volume calculations
1109
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
7,893✔
1110
    model::volume_calcs.emplace_back(node_vol);
326✔
1111
  }
1112

1113
  // Get temperature settings
1114
  if (check_for_node(root, "temperature_default")) {
7,567✔
1115
    temperature_default =
172✔
1116
      std::stod(get_node_value(root, "temperature_default"));
172✔
1117
  }
1118
  if (check_for_node(root, "temperature_method")) {
7,567✔
1119
    auto temp = get_node_value(root, "temperature_method", true, true);
325✔
1120
    if (temp == "nearest") {
325✔
1121
      temperature_method = TemperatureMethod::NEAREST;
140✔
1122
    } else if (temp == "interpolation") {
185!
1123
      temperature_method = TemperatureMethod::INTERPOLATION;
185✔
1124
    } else {
1125
      fatal_error("Unknown temperature method: " + temp);
×
1126
    }
1127
  }
325✔
1128
  if (check_for_node(root, "temperature_tolerance")) {
7,567✔
1129
    temperature_tolerance =
171✔
1130
      std::stod(get_node_value(root, "temperature_tolerance"));
171✔
1131
  }
1132
  if (check_for_node(root, "temperature_multipole")) {
7,567✔
1133
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
32✔
1134

1135
    // Multipole currently doesn't work with photon transport
1136
    if (temperature_multipole && photon_transport) {
32!
1137
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1138
                  "photon transport.");
1139
    }
1140
  }
1141
  if (check_for_node(root, "temperature_range")) {
7,567!
1142
    auto range = get_node_array<double>(root, "temperature_range");
×
1143
    temperature_range[0] = range.at(0);
×
1144
    temperature_range[1] = range.at(1);
×
1145
  }
×
1146

1147
  // Check for tabular_legendre options
1148
  if (check_for_node(root, "tabular_legendre")) {
7,567✔
1149
    // Get pointer to tabular_legendre node
1150
    xml_node node_tab_leg = root.child("tabular_legendre");
96✔
1151

1152
    // Check for enable option
1153
    if (check_for_node(node_tab_leg, "enable")) {
96!
1154
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
96✔
1155
    }
1156

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

1169
  // Check whether create delayed neutrons in fission
1170
  if (check_for_node(root, "create_delayed_neutrons")) {
7,567!
1171
    create_delayed_neutrons =
×
1172
      get_node_value_bool(root, "create_delayed_neutrons");
×
1173
  }
1174

1175
  // Check whether create fission sites
1176
  if (run_mode == RunMode::FIXED_SOURCE) {
7,567✔
1177
    if (check_for_node(root, "create_fission_neutrons")) {
2,598✔
1178
      create_fission_neutrons =
149✔
1179
        get_node_value_bool(root, "create_fission_neutrons");
149✔
1180
    }
1181
  }
1182

1183
  // Check whether to scale fission photon yields
1184
  if (check_for_node(root, "delayed_photon_scaling")) {
7,567!
1185
    delayed_photon_scaling =
×
1186
      get_node_value_bool(root, "delayed_photon_scaling");
×
1187
  }
1188

1189
  // Check whether to use event-based parallelism
1190
  if (check_for_node(root, "event_based")) {
7,567!
1191
    event_based = get_node_value_bool(root, "event_based");
×
1192
  }
1193

1194
  // Check whether material cell offsets should be generated
1195
  if (check_for_node(root, "material_cell_offsets")) {
7,567!
1196
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1197
  }
1198

1199
  // Weight window information
1200
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
7,659✔
1201
    variance_reduction::weight_windows.emplace_back(
92✔
1202
      std::make_unique<WeightWindows>(node_ww));
184✔
1203
  }
1204

1205
  // Enable weight windows by default if one or more are present
1206
  if (variance_reduction::weight_windows.size() > 0)
7,567✔
1207
    settings::weight_windows_on = true;
65✔
1208

1209
  // read weight windows from file
1210
  if (check_for_node(root, "weight_windows_file")) {
7,567!
1211
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1212
  }
1213

1214
  // read settings for weight windows value, this will override
1215
  // the automatic setting even if weight windows are present
1216
  if (check_for_node(root, "weight_windows_on")) {
7,567✔
1217
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
38✔
1218
  }
1219

1220
  if (check_for_node(root, "max_secondaries")) {
7,567!
1221
    settings::max_secondaries =
×
1222
      std::stoi(get_node_value(root, "max_secondaries"));
×
1223
  }
1224

1225
  if (check_for_node(root, "max_history_splits")) {
7,567✔
1226
    settings::max_history_splits =
215✔
1227
      std::stoi(get_node_value(root, "max_history_splits"));
215✔
1228
  }
1229

1230
  if (check_for_node(root, "max_tracks")) {
7,567✔
1231
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
48✔
1232
  }
1233

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

1252
  // Set up weight window checkpoints
1253
  if (check_for_node(root, "weight_window_checkpoints")) {
7,567✔
1254
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
2!
1255
    if (check_for_node(ww_checkpoints, "collision")) {
2!
1256
      weight_window_checkpoint_collision =
2✔
1257
        get_node_value_bool(ww_checkpoints, "collision");
2!
1258
    }
1259
    if (check_for_node(ww_checkpoints, "surface")) {
2!
1260
      weight_window_checkpoint_surface =
2✔
1261
        get_node_value_bool(ww_checkpoints, "surface");
2!
1262
    }
1263
  }
1264

1265
  if (check_for_node(root, "use_decay_photons")) {
7,567✔
1266
    settings::use_decay_photons =
11✔
1267
      get_node_value_bool(root, "use_decay_photons");
11✔
1268
  }
1269
}
7,567✔
1270

1271
void free_memory_settings()
7,707✔
1272
{
1273
  settings::statepoint_batch.clear();
7,707✔
1274
  settings::sourcepoint_batch.clear();
7,707✔
1275
  settings::source_write_surf_id.clear();
7,707✔
1276
  settings::res_scat_nuclides.clear();
7,707✔
1277
}
7,707✔
1278

1279
//==============================================================================
1280
// C API functions
1281
//==============================================================================
1282

1283
extern "C" int openmc_set_n_batches(
44✔
1284
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1285
{
1286
  if (settings::n_inactive >= n_batches) {
44✔
1287
    set_errmsg("Number of active batches must be greater than zero.");
11✔
1288
    return OPENMC_E_INVALID_ARGUMENT;
11✔
1289
  }
1290

1291
  if (!settings::trigger_on) {
33✔
1292
    // Set n_batches and n_max_batches to same value
1293
    settings::n_batches = n_batches;
11✔
1294
    settings::n_max_batches = n_batches;
11✔
1295
  } else {
1296
    // Set n_batches and n_max_batches based on value of set_max_batches
1297
    if (set_max_batches) {
22✔
1298
      settings::n_max_batches = n_batches;
11✔
1299
    } else {
1300
      settings::n_batches = n_batches;
11✔
1301
    }
1302
  }
1303

1304
  // Update size of k_generation and entropy
1305
  int m = settings::n_max_batches * settings::gen_per_batch;
33✔
1306
  simulation::k_generation.reserve(m);
33✔
1307
  simulation::entropy.reserve(m);
33✔
1308

1309
  // Add value of n_batches to statepoint_batch
1310
  if (add_statepoint_batch &&
55✔
1311
      !(contains(settings::statepoint_batch, n_batches)))
22!
1312
    settings::statepoint_batch.insert(n_batches);
22✔
1313

1314
  return 0;
33✔
1315
}
1316

1317
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,530✔
1318
{
1319
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,530✔
1320

1321
  return 0;
2,530✔
1322
}
1323

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