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

openmc-dev / openmc / 22668999617

04 Mar 2026 12:17PM UTC coverage: 81.558% (+0.02%) from 81.539%
22668999617

push

github

web-flow
Implement surface flux tallies (#3742)

Co-authored-by: Paul Romano <paul.k.romano@gmail.com>

17538 of 25247 branches covered (69.47%)

Branch coverage included in aggregate %.

106 of 115 new or added lines in 7 files covered. (92.17%)

91 existing lines in 2 files now uncovered.

57928 of 67284 relevant lines covered (86.09%)

44833497.5 hits per line

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

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

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

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

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

39
namespace openmc {
40

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

45
namespace settings {
46

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

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
double surface_grazing_cutoff {0.001};
140
double surface_grazing_ratio {0.5};
141
TemperatureMethod temperature_method {TemperatureMethod::NEAREST};
142
double temperature_tolerance {10.0};
143
double temperature_default {293.6};
144
array<double, 2> temperature_range {0.0, 0.0};
145
int trace_batch;
146
int trace_gen;
147
int64_t trace_particle;
148
vector<array<int, 3>> track_identifiers;
149
int trigger_batch_interval {1};
150
int verbosity {-1};
151
double weight_cutoff {0.25};
152
double weight_survive {1.0};
153

154
} // namespace settings
155

156
//==============================================================================
157
// Functions
158
//==============================================================================
159

160
void get_run_parameters(pugi::xml_node node_base)
7,377✔
161
{
162
  using namespace settings;
7,377✔
163
  using namespace pugi;
7,377✔
164

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

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

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

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

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

194
  // Get max number of lost particles
195
  if (check_for_node(node_base, "max_lost_particles")) {
7,377✔
196
    max_lost_particles =
92✔
197
      std::stoi(get_node_value(node_base, "max_lost_particles"));
46✔
198
  }
199

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

206
  // Get relative number of lost particles
207
  if (check_for_node(node_base, "max_write_lost_particles")) {
7,377✔
208
    max_write_lost_particles =
30✔
209
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
15✔
210
  }
211

212
  // Get number of inactive batches
213
  if (run_mode == RunMode::EIGENVALUE ||
7,377✔
214
      solver_type == SolverType::RANDOM_RAY) {
2,829✔
215
    if (check_for_node(node_base, "inactive")) {
4,954✔
216
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,743✔
217
    }
218
    if (check_for_node(node_base, "generations_per_batch")) {
4,954✔
219
      gen_per_batch =
30✔
220
        std::stoi(get_node_value(node_base, "generations_per_batch"));
15✔
221
    }
222

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

228
    // Get the trigger information for keff
229
    if (check_for_node(node_base, "keff_trigger")) {
4,954✔
230
      xml_node node_keff_trigger = node_base.child("keff_trigger");
101✔
231

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

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

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

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

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

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

402
  // Verbosity
403
  if (check_for_node(root, "verbosity") && verbosity == -1) {
1,327!
404
    verbosity = std::stoi(get_node_value(root, "verbosity"));
362✔
405
  } else if (verbosity == -1) {
1,146!
406
    verbosity = 7;
1,146✔
407
  }
408

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

416
  write_message("Reading settings XML file...", 5);
1,327✔
417

418
  read_settings_xml(root);
1,327✔
419
}
1,339✔
420

421
void read_settings_xml(pugi::xml_node root)
8,185✔
422
{
423
  using namespace settings;
8,185✔
424
  using namespace pugi;
8,185✔
425

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

436
  // Check for user meshes and allocate
437
  read_meshes(root);
8,185✔
438

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

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

463
  // Check for a trigger node and get trigger information
464
  if (check_for_node(root, "trigger")) {
8,185✔
465
    xml_node node_trigger = root.child("trigger");
156✔
466

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

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

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

490
  // Check run mode if it hasn't been set from the command line
491
  xml_node node_mode;
8,185✔
492
  if (run_mode == RunMode::UNSET) {
8,185✔
493
    if (check_for_node(root, "run_mode")) {
7,409✔
494
      std::string temp_str = get_node_value(root, "run_mode", true, true);
7,379✔
495
      if (temp_str == "eigenvalue") {
7,379✔
496
        run_mode = RunMode::EIGENVALUE;
4,518✔
497
      } else if (temp_str == "fixed source") {
2,861✔
498
        run_mode = RunMode::FIXED_SOURCE;
2,829✔
499
      } else if (temp_str == "plot") {
32!
500
        run_mode = RunMode::PLOTTING;
×
501
      } else if (temp_str == "particle restart") {
32!
502
        run_mode = RunMode::PARTICLE;
×
503
      } else if (temp_str == "volume") {
32!
504
        run_mode = RunMode::VOLUME;
32✔
505
      } else {
506
        fatal_error("Unrecognized run mode: " + temp_str);
×
507
      }
508

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

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

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

537
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
8,185✔
538
    // Read run parameters
539
    get_run_parameters(node_mode);
7,377✔
540

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

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

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

576
  // Copy random number seed if specified
577
  if (check_for_node(root, "seed")) {
8,176✔
578
    auto seed = std::stoll(get_node_value(root, "seed"));
1,154✔
579
    openmc_set_seed(seed);
577✔
580
  }
581

582
  // Copy random number stride if specified
583
  if (check_for_node(root, "stride")) {
8,176✔
584
    auto stride = std::stoull(get_node_value(root, "stride"));
30✔
585
    openmc_set_stride(stride);
15✔
586
  }
587

588
  // Check for electron treatment
589
  if (check_for_node(root, "electron_treatment")) {
8,176✔
590
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
67✔
591
    if (temp_str == "led") {
67✔
592
      electron_treatment = ElectronTreatment::LED;
11✔
593
    } else if (temp_str == "ttb") {
56!
594
      electron_treatment = ElectronTreatment::TTB;
56✔
595
    } else {
596
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
597
    }
598
  }
67✔
599

600
  // Check for photon transport
601
  if (check_for_node(root, "photon_transport")) {
8,176✔
602
    photon_transport = get_node_value_bool(root, "photon_transport");
190✔
603

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

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

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

627
  // ==========================================================================
628
  // EXTERNAL SOURCE
629

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

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

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

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

661
  // Build probability mass function for sampling external sources
662
  vector<double> source_strengths;
8,166✔
663
  for (auto& s : model::external_sources) {
17,909✔
664
    source_strengths.push_back(s->strength());
9,743✔
665
  }
666
  model::external_sources_probability.assign(source_strengths);
8,166✔
667

668
  // Check if we want to write out source
669
  if (check_for_node(root, "write_initial_source")) {
8,166!
670
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
671
  }
672

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

679
  if (check_for_node(root, "free_gas_threshold")) {
8,166!
680
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
681
  }
682

683
  // Surface grazing
684
  if (check_for_node(root, "surface_grazing_cutoff"))
8,166!
NEW
685
    surface_grazing_cutoff =
×
NEW
686
      std::stod(get_node_value(root, "surface_grazing_cutoff"));
×
687
  if (check_for_node(root, "surface_grazing_ratio"))
8,166!
NEW
688
    surface_grazing_ratio =
×
NEW
689
      std::stod(get_node_value(root, "surface_grazing_ratio"));
×
690

691
  // Survival biasing
692
  if (check_for_node(root, "survival_biasing")) {
8,166✔
693
    survival_biasing = get_node_value_bool(root, "survival_biasing");
190✔
694
  }
695

696
  // Probability tables
697
  if (check_for_node(root, "ptables")) {
8,166✔
698
    urr_ptables_on = get_node_value_bool(root, "ptables");
15✔
699
  }
700

701
  // Cutoffs
702
  if (check_for_node(root, "cutoff")) {
8,166✔
703
    xml_node node_cutoff = root.child("cutoff");
138✔
704
    if (check_for_node(node_cutoff, "weight")) {
138✔
705
      weight_cutoff = std::stod(get_node_value(node_cutoff, "weight"));
30✔
706
    }
707
    if (check_for_node(node_cutoff, "weight_avg")) {
138✔
708
      weight_survive = std::stod(get_node_value(node_cutoff, "weight_avg"));
30✔
709
    }
710
    if (check_for_node(node_cutoff, "survival_normalization")) {
138!
711
      survival_normalization =
×
712
        get_node_value_bool(node_cutoff, "survival_normalization");
×
713
    }
714
    if (check_for_node(node_cutoff, "energy_neutron")) {
138✔
715
      energy_cutoff[0] =
15✔
716
        std::stod(get_node_value(node_cutoff, "energy_neutron"));
30✔
717
    } else if (check_for_node(node_cutoff, "energy")) {
123!
718
      warning("The use of an <energy> cutoff is deprecated and should "
×
719
              "be replaced by <energy_neutron>.");
720
      energy_cutoff[0] = std::stod(get_node_value(node_cutoff, "energy"));
×
721
    }
722
    if (check_for_node(node_cutoff, "energy_photon")) {
138✔
723
      energy_cutoff[1] =
82✔
724
        std::stod(get_node_value(node_cutoff, "energy_photon"));
164✔
725
    }
726
    if (check_for_node(node_cutoff, "energy_electron")) {
138!
727
      energy_cutoff[2] =
×
728
        std::stof(get_node_value(node_cutoff, "energy_electron"));
×
729
    }
730
    if (check_for_node(node_cutoff, "energy_positron")) {
138!
731
      energy_cutoff[3] =
×
732
        std::stod(get_node_value(node_cutoff, "energy_positron"));
×
733
    }
734
    if (check_for_node(node_cutoff, "time_neutron")) {
138✔
735
      time_cutoff[0] = std::stod(get_node_value(node_cutoff, "time_neutron"));
26✔
736
    }
737
    if (check_for_node(node_cutoff, "time_photon")) {
138!
738
      time_cutoff[1] = std::stod(get_node_value(node_cutoff, "time_photon"));
×
739
    }
740
    if (check_for_node(node_cutoff, "time_electron")) {
138!
741
      time_cutoff[2] = std::stod(get_node_value(node_cutoff, "time_electron"));
×
742
    }
743
    if (check_for_node(node_cutoff, "time_positron")) {
138!
744
      time_cutoff[3] = std::stod(get_node_value(node_cutoff, "time_positron"));
×
745
    }
746
  }
747

748
  // Particle trace
749
  if (check_for_node(root, "trace")) {
8,166✔
750
    auto temp = get_node_array<int64_t>(root, "trace");
15✔
751
    if (temp.size() != 3) {
15!
752
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
753
                  "batch, generation, and particle number.");
754
    }
755
    trace_batch = temp.at(0);
15✔
756
    trace_gen = temp.at(1);
15✔
757
    trace_particle = temp.at(2);
15✔
758
  }
15✔
759

760
  // Particle tracks
761
  if (check_for_node(root, "track")) {
8,166✔
762
    // Get values and make sure there are three per particle
763
    auto temp = get_node_array<int>(root, "track");
45✔
764
    if (temp.size() % 3 != 0) {
45!
765
      fatal_error(
×
766
        "Number of integers specified in 'track' is not "
767
        "divisible by 3.  Please provide 3 integers per particle to be "
768
        "tracked.");
769
    }
770

771
    // Reshape into track_identifiers
772
    int n_tracks = temp.size() / 3;
45✔
773
    for (int i = 0; i < n_tracks; ++i) {
180✔
774
      track_identifiers.push_back(
135✔
775
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
135✔
776
    }
777
  }
45✔
778

779
  // Shannon entropy
780
  if (solver_type == SolverType::RANDOM_RAY) {
8,166✔
781
    if (check_for_node(root, "entropy_mesh")) {
762!
782
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
783
                  "No user-defined entropy mesh is supported.");
784
    }
785
    entropy_on = true;
762✔
786
  } else if (solver_type == SolverType::MONTE_CARLO) {
7,404!
787
    if (check_for_node(root, "entropy_mesh")) {
7,404✔
788
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
668✔
789
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
334!
790
        fatal_error(fmt::format(
×
791
          "Mesh {} specified for Shannon entropy does not exist.", temp));
792
      }
793

794
      auto* m = dynamic_cast<RegularMesh*>(
334!
795
        model::meshes[model::mesh_map.at(temp)].get());
334!
796
      if (!m)
334!
797
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
798
      simulation::entropy_mesh = m;
334✔
799

800
      // Turn on Shannon entropy calculation
801
      entropy_on = true;
334✔
802

803
    } else if (check_for_node(root, "entropy")) {
7,070!
804
      fatal_error(
×
805
        "Specifying a Shannon entropy mesh via the <entropy> element "
806
        "is deprecated. Please create a mesh using <mesh> and then reference "
807
        "it by specifying its ID in an <entropy_mesh> element.");
808
    }
809
  }
810
  // Uniform fission source weighting mesh
811
  if (check_for_node(root, "ufs_mesh")) {
8,166✔
812
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
30✔
813
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
15!
814
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
815
                              "method does not exist.",
816
        temp));
817
    }
818

819
    auto* m =
15✔
820
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
15!
821
    if (!m)
15!
822
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
823
    simulation::ufs_mesh = m;
15✔
824

825
    // Turn on uniform fission source weighting
826
    ufs_on = true;
15✔
827

828
  } else if (check_for_node(root, "uniform_fs")) {
8,151!
829
    fatal_error(
×
830
      "Specifying a UFS mesh via the <uniform_fs> element "
831
      "is deprecated. Please create a mesh using <mesh> and then reference "
832
      "it by specifying its ID in a <ufs_mesh> element.");
833
  }
834

835
  // Check if the user has specified to write state points
836
  if (check_for_node(root, "state_point")) {
8,166✔
837

838
    // Get pointer to state_point node
839
    auto node_sp = root.child("state_point");
160✔
840

841
    // Determine number of batches at which to store state points
842
    if (check_for_node(node_sp, "batches")) {
160!
843
      // User gave specific batches to write state points
844
      auto temp = get_node_array<int>(node_sp, "batches");
160✔
845
      for (const auto& b : temp) {
491✔
846
        statepoint_batch.insert(b);
331✔
847
      }
848
    } else {
160✔
849
      // If neither were specified, write state point at last batch
850
      statepoint_batch.insert(n_batches);
×
851
    }
852
  } else {
853
    // If no <state_point> tag was present, by default write state point at
854
    // last batch only
855
    statepoint_batch.insert(n_batches);
8,006✔
856
  }
857

858
  // Check if the user has specified to write source points
859
  if (check_for_node(root, "source_point")) {
8,166✔
860
    // Get source_point node
861
    xml_node node_sp = root.child("source_point");
101✔
862

863
    // Determine batches at which to store source points
864
    if (check_for_node(node_sp, "batches")) {
101✔
865
      // User gave specific batches to write source points
866
      auto temp = get_node_array<int>(node_sp, "batches");
45✔
867
      for (const auto& b : temp) {
120✔
868
        sourcepoint_batch.insert(b);
75✔
869
      }
870
    } else {
45✔
871
      // If neither were specified, write source points with state points
872
      sourcepoint_batch = statepoint_batch;
56!
873
    }
874

875
    // Check if the user has specified to write binary source file
876
    if (check_for_node(node_sp, "separate")) {
101✔
877
      source_separate = get_node_value_bool(node_sp, "separate");
71✔
878
    }
879
    if (check_for_node(node_sp, "write")) {
101!
880
      source_write = get_node_value_bool(node_sp, "write");
×
881
    }
882
    if (check_for_node(node_sp, "mcpl")) {
101✔
883
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
26✔
884
    }
885
    if (check_for_node(node_sp, "overwrite_latest")) {
101✔
886
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
15✔
887
      source_separate = source_latest;
15✔
888
    }
889
  } else {
890
    // If no <source_point> tag was present, by default we keep source bank in
891
    // statepoint file and write it out at statepoints intervals
892
    source_separate = false;
8,065✔
893
    sourcepoint_batch = statepoint_batch;
8,065!
894
  }
895

896
  // Check is the user specified to convert strength to statistical weight
897
  if (check_for_node(root, "uniform_source_sampling")) {
8,166✔
898
    uniform_source_sampling =
55✔
899
      get_node_value_bool(root, "uniform_source_sampling");
55✔
900
  }
901

902
  // Check if the user has specified to write surface source
903
  if (check_for_node(root, "surf_source_write")) {
8,166✔
904
    surf_source_write = true;
412✔
905
    // Get surface source write node
906
    xml_node node_ssw = root.child("surf_source_write");
412✔
907

908
    // Determine surface ids at which crossing particles are to be banked.
909
    // If no surfaces are specified, all surfaces in the model will be used
910
    // to bank source points.
911
    if (check_for_node(node_ssw, "surface_ids")) {
412✔
912
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
202✔
913
      for (const auto& b : temp) {
994✔
914
        source_write_surf_id.insert(b);
792✔
915
      }
916
    }
202✔
917

918
    // Get maximum number of particles to be banked per surface
919
    if (check_for_node(node_ssw, "max_particles")) {
412✔
920
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
806✔
921
    } else {
922
      fatal_error("A maximum number of particles needs to be specified "
9✔
923
                  "using the 'max_particles' parameter to store surface "
924
                  "source points.");
925
    }
926

927
    // Get maximum number of surface source files to be created
928
    if (check_for_node(node_ssw, "max_source_files")) {
403✔
929
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
66✔
930
    } else {
931
      ssw_max_files = 1;
370✔
932
    }
933

934
    if (check_for_node(node_ssw, "mcpl")) {
403✔
935
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
11✔
936
    }
937
    // Get cell information
938
    if (check_for_node(node_ssw, "cell")) {
403✔
939
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
208✔
940
      ssw_cell_type = SSWCellType::Both;
104✔
941
    }
942
    if (check_for_node(node_ssw, "cellfrom")) {
403✔
943
      if (ssw_cell_id != C_NONE) {
90✔
944
        fatal_error(
18✔
945
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
946
      }
947
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
144✔
948
      ssw_cell_type = SSWCellType::From;
72✔
949
    }
950
    if (check_for_node(node_ssw, "cellto")) {
385✔
951
      if (ssw_cell_id != C_NONE) {
71✔
952
        fatal_error(
18✔
953
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
954
      }
955
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
106✔
956
      ssw_cell_type = SSWCellType::To;
53✔
957
    }
958
  }
959

960
  // Check if the user has specified to write specific collisions
961
  if (check_for_node(root, "collision_track")) {
8,121✔
962
    settings::collision_track = true;
148✔
963
    // Get collision track node
964
    xml_node node_ct = root.child("collision_track");
148✔
965
    collision_track_config = CollisionTrackConfig {};
148✔
966

967
    // Determine cell ids at which crossing particles are to be banked
968
    if (check_for_node(node_ct, "cell_ids")) {
148✔
969
      auto temp = get_node_array<int>(node_ct, "cell_ids");
78✔
970
      for (const auto& b : temp) {
204✔
971
        collision_track_config.cell_ids.insert(b);
126✔
972
      }
973
    }
78✔
974
    if (check_for_node(node_ct, "reactions")) {
148✔
975
      auto temp = get_node_array<std::string>(node_ct, "reactions");
63✔
976
      for (const auto& b : temp) {
171✔
977
        int reaction_int = reaction_mt(b);
108✔
978
        if (reaction_int > 0) {
108!
979
          collision_track_config.mt_numbers.insert(reaction_int);
108✔
980
        }
981
      }
982
    }
63✔
983
    if (check_for_node(node_ct, "universe_ids")) {
148✔
984
      auto temp = get_node_array<int>(node_ct, "universe_ids");
30✔
985
      for (const auto& b : temp) {
60✔
986
        collision_track_config.universe_ids.insert(b);
30✔
987
      }
988
    }
30✔
989
    if (check_for_node(node_ct, "material_ids")) {
148✔
990
      auto temp = get_node_array<int>(node_ct, "material_ids");
30✔
991
      for (const auto& b : temp) {
75✔
992
        collision_track_config.material_ids.insert(b);
45✔
993
      }
994
    }
30✔
995
    if (check_for_node(node_ct, "nuclides")) {
148✔
996
      auto temp = get_node_array<std::string>(node_ct, "nuclides");
30✔
997
      for (const auto& b : temp) {
120✔
998
        collision_track_config.nuclides.insert(b);
90✔
999
      }
1000
    }
30✔
1001
    if (check_for_node(node_ct, "deposited_E_threshold")) {
148✔
1002
      collision_track_config.deposited_energy_threshold =
60✔
1003
        std::stod(get_node_value(node_ct, "deposited_E_threshold"));
60✔
1004
    }
1005
    // Get maximum number of particles to be banked per collision
1006
    if (check_for_node(node_ct, "max_collisions")) {
148!
1007
      collision_track_config.max_collisions =
296✔
1008
        std::stoll(get_node_value(node_ct, "max_collisions"));
296✔
1009
    } else {
1010
      warning("A maximum number of collisions needs to be specified. "
×
1011
              "By default the code sets 'max_collisions' parameter equals to "
1012
              "1000.");
1013
    }
1014
    // Get maximum number of collision_track files to be created
1015
    if (check_for_node(node_ct, "max_collision_track_files")) {
148!
1016
      collision_track_config.max_files =
×
1017
        std::stoll(get_node_value(node_ct, "max_collision_track_files"));
×
1018
    }
1019
    if (check_for_node(node_ct, "mcpl")) {
148✔
1020
      collision_track_config.mcpl_write = get_node_value_bool(node_ct, "mcpl");
22✔
1021
    }
1022
  }
1023

1024
  // If source is not separate and is to be written out in the statepoint
1025
  // file, make sure that the sourcepoint batch numbers are contained in the
1026
  // statepoint list
1027
  if (!source_separate) {
8,121✔
1028
    for (const auto& b : sourcepoint_batch) {
16,196✔
1029
      if (!contains(statepoint_batch, b)) {
16,322!
1030
        fatal_error(
×
1031
          "Sourcepoint batches are not a subset of statepoint batches.");
1032
      }
1033
    }
1034
  }
1035

1036
  // Check if the user has specified to not reduce tallies at the end of every
1037
  // batch
1038
  if (check_for_node(root, "no_reduce")) {
8,121✔
1039
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
30✔
1040
  }
1041

1042
  // Check if the user has specified to use confidence intervals for
1043
  // uncertainties rather than standard deviations
1044
  if (check_for_node(root, "confidence_intervals")) {
8,121✔
1045
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
15✔
1046
  }
1047

1048
  // Check for output options
1049
  if (check_for_node(root, "output")) {
8,121✔
1050
    // Get pointer to output node
1051
    pugi::xml_node node_output = root.child("output");
764✔
1052

1053
    // Check for summary option
1054
    if (check_for_node(node_output, "summary")) {
764✔
1055
      output_summary = get_node_value_bool(node_output, "summary");
738✔
1056
    }
1057

1058
    // Check for ASCII tallies output option
1059
    if (check_for_node(node_output, "tallies")) {
764✔
1060
      output_tallies = get_node_value_bool(node_output, "tallies");
349✔
1061
    }
1062

1063
    // Set output directory if a path has been specified
1064
    if (check_for_node(node_output, "path")) {
764!
1065
      path_output = get_node_value(node_output, "path");
×
1066
      if (!ends_with(path_output, "/")) {
×
1067
        path_output += "/";
764!
1068
      }
1069
    }
1070
  }
1071

1072
  // Resonance scattering parameters
1073
  if (check_for_node(root, "resonance_scattering")) {
8,121✔
1074
    xml_node node_res_scat = root.child("resonance_scattering");
15✔
1075

1076
    // See if resonance scattering is enabled
1077
    if (check_for_node(node_res_scat, "enable")) {
15!
1078
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
15✔
1079
    } else {
1080
      res_scat_on = true;
×
1081
    }
1082

1083
    // Determine what method is used
1084
    if (check_for_node(node_res_scat, "method")) {
15!
1085
      auto temp = get_node_value(node_res_scat, "method", true, true);
15✔
1086
      if (temp == "rvs") {
15!
1087
        res_scat_method = ResScatMethod::rvs;
15✔
1088
      } else if (temp == "dbrc") {
×
1089
        res_scat_method = ResScatMethod::dbrc;
×
1090
      } else {
1091
        fatal_error(
×
1092
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1093
      }
1094
    }
15✔
1095

1096
    // Minimum energy for resonance scattering
1097
    if (check_for_node(node_res_scat, "energy_min")) {
15!
1098
      res_scat_energy_min =
30✔
1099
        std::stod(get_node_value(node_res_scat, "energy_min"));
30✔
1100
    }
1101
    if (res_scat_energy_min < 0.0) {
15!
1102
      fatal_error("Lower resonance scattering energy bound is negative");
×
1103
    }
1104

1105
    // Maximum energy for resonance scattering
1106
    if (check_for_node(node_res_scat, "energy_max")) {
15!
1107
      res_scat_energy_max =
30✔
1108
        std::stod(get_node_value(node_res_scat, "energy_max"));
30✔
1109
    }
1110
    if (res_scat_energy_max < res_scat_energy_min) {
15!
1111
      fatal_error("Upper resonance scattering energy bound is below the "
×
1112
                  "lower resonance scattering energy bound.");
1113
    }
1114

1115
    // Get resonance scattering nuclides
1116
    if (check_for_node(node_res_scat, "nuclides")) {
15!
1117
      res_scat_nuclides =
15✔
1118
        get_node_array<std::string>(node_res_scat, "nuclides");
30✔
1119
    }
1120
  }
1121

1122
  // Get volume calculations
1123
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
8,435✔
1124
    model::volume_calcs.emplace_back(node_vol);
314✔
1125
  }
1126

1127
  // Get temperature settings
1128
  if (check_for_node(root, "temperature_default")) {
8,121✔
1129
    temperature_default =
342✔
1130
      std::stod(get_node_value(root, "temperature_default"));
342✔
1131
  }
1132
  if (check_for_node(root, "temperature_method")) {
8,121✔
1133
    auto temp = get_node_value(root, "temperature_method", true, true);
485✔
1134
    if (temp == "nearest") {
485✔
1135
      temperature_method = TemperatureMethod::NEAREST;
304✔
1136
    } else if (temp == "interpolation") {
181!
1137
      temperature_method = TemperatureMethod::INTERPOLATION;
181✔
1138
    } else {
1139
      fatal_error("Unknown temperature method: " + temp);
×
1140
    }
1141
  }
485✔
1142
  if (check_for_node(root, "temperature_tolerance")) {
8,121✔
1143
    temperature_tolerance =
680✔
1144
      std::stod(get_node_value(root, "temperature_tolerance"));
680✔
1145
  }
1146
  if (check_for_node(root, "temperature_multipole")) {
8,121✔
1147
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
185✔
1148

1149
    // Multipole currently doesn't work with photon transport
1150
    if (temperature_multipole && photon_transport) {
185!
1151
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1152
                  "photon transport.");
1153
    }
1154
  }
1155
  if (check_for_node(root, "temperature_range")) {
8,121✔
1156
    auto range = get_node_array<double>(root, "temperature_range");
170✔
1157
    temperature_range[0] = range.at(0);
170✔
1158
    temperature_range[1] = range.at(1);
170✔
1159
  }
170✔
1160

1161
  // Check for tabular_legendre options
1162
  if (check_for_node(root, "tabular_legendre")) {
8,121✔
1163
    // Get pointer to tabular_legendre node
1164
    xml_node node_tab_leg = root.child("tabular_legendre");
90✔
1165

1166
    // Check for enable option
1167
    if (check_for_node(node_tab_leg, "enable")) {
90!
1168
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
90✔
1169
    }
1170

1171
    // Check for the number of points
1172
    if (check_for_node(node_tab_leg, "num_points")) {
90!
1173
      legendre_to_tabular_points =
×
1174
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
1175
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
1176
        fatal_error(
×
1177
          "The 'num_points' subelement/attribute of the "
1178
          "<tabular_legendre> element must contain a value greater than 1");
1179
      }
1180
    }
1181
  }
1182

1183
  // Check whether create delayed neutrons in fission
1184
  if (check_for_node(root, "create_delayed_neutrons")) {
8,121!
1185
    create_delayed_neutrons =
×
1186
      get_node_value_bool(root, "create_delayed_neutrons");
×
1187
  }
1188

1189
  // Check whether create fission sites
1190
  if (run_mode == RunMode::FIXED_SOURCE) {
8,121✔
1191
    if (check_for_node(root, "create_fission_neutrons")) {
2,783✔
1192
      create_fission_neutrons =
280✔
1193
        get_node_value_bool(root, "create_fission_neutrons");
280✔
1194
    }
1195
  }
1196

1197
  // Check whether to scale fission photon yields
1198
  if (check_for_node(root, "delayed_photon_scaling")) {
8,121!
1199
    delayed_photon_scaling =
×
1200
      get_node_value_bool(root, "delayed_photon_scaling");
×
1201
  }
1202

1203
  // Check whether to use event-based parallelism
1204
  if (check_for_node(root, "event_based")) {
8,121!
1205
    event_based = get_node_value_bool(root, "event_based");
×
1206
  }
1207

1208
  // Check whether material cell offsets should be generated
1209
  if (check_for_node(root, "material_cell_offsets")) {
8,121!
1210
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1211
  }
1212

1213
  // Weight window information
1214
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
8,226✔
1215
    variance_reduction::weight_windows.emplace_back(
105✔
1216
      std::make_unique<WeightWindows>(node_ww));
210✔
1217
  }
1218

1219
  // Enable weight windows by default if one or more are present
1220
  if (variance_reduction::weight_windows.size() > 0)
8,121✔
1221
    settings::weight_windows_on = true;
79✔
1222

1223
  // read weight windows from file
1224
  if (check_for_node(root, "weight_windows_file")) {
8,121!
1225
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1226
  }
1227

1228
  // read settings for weight windows value, this will override
1229
  // the automatic setting even if weight windows are present
1230
  if (check_for_node(root, "weight_windows_on")) {
8,121✔
1231
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
38✔
1232
  }
1233

1234
  if (check_for_node(root, "max_secondaries")) {
8,121!
1235
    settings::max_secondaries =
×
1236
      std::stoi(get_node_value(root, "max_secondaries"));
×
1237
  }
1238

1239
  if (check_for_node(root, "max_history_splits")) {
8,121✔
1240
    settings::max_history_splits =
428✔
1241
      std::stoi(get_node_value(root, "max_history_splits"));
428✔
1242
  }
1243

1244
  if (check_for_node(root, "max_tracks")) {
8,121✔
1245
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
90✔
1246
  }
1247

1248
  // Create weight window generator objects
1249
  if (check_for_node(root, "weight_window_generators")) {
8,121✔
1250
    auto wwgs_node = root.child("weight_window_generators");
79✔
1251
    for (pugi::xml_node node_wwg :
158✔
1252
      wwgs_node.children("weight_windows_generator")) {
158✔
1253
      variance_reduction::weight_windows_generators.emplace_back(
79✔
1254
        std::make_unique<WeightWindowsGenerator>(node_wwg));
158✔
1255
    }
1256
    // if any of the weight windows are intended to be generated otf, make
1257
    // sure they're applied
1258
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
79!
1259
      if (wwg->on_the_fly_) {
79!
1260
        settings::weight_windows_on = true;
79✔
1261
        break;
79✔
1262
      }
1263
    }
1264
  }
1265

1266
  // Set up weight window checkpoints
1267
  if (check_for_node(root, "weight_window_checkpoints")) {
8,121✔
1268
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
32✔
1269
    if (check_for_node(ww_checkpoints, "collision")) {
32!
1270
      weight_window_checkpoint_collision =
32✔
1271
        get_node_value_bool(ww_checkpoints, "collision");
32✔
1272
    }
1273
    if (check_for_node(ww_checkpoints, "surface")) {
32!
1274
      weight_window_checkpoint_surface =
32✔
1275
        get_node_value_bool(ww_checkpoints, "surface");
32✔
1276
    }
1277
  }
1278

1279
  if (weight_windows_on) {
8,121✔
1280
    if (!weight_window_checkpoint_surface &&
158✔
1281
        !weight_window_checkpoint_collision)
126!
1282
      fatal_error(
×
1283
        "Weight Windows are enabled but there are no valid checkpoints.");
1284
  }
1285

1286
  if (check_for_node(root, "use_decay_photons")) {
8,121✔
1287
    settings::use_decay_photons =
11✔
1288
      get_node_value_bool(root, "use_decay_photons");
11✔
1289
  }
1290
}
8,121✔
1291

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

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

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

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

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

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

1335
  return 0;
1336
}
1337

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

1342
  return 0;
2,530✔
1343
}
1344

1345
} // namespace openmc
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc