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

openmc-dev / openmc / 23049805565

13 Mar 2026 11:59AM UTC coverage: 81.582% (-0.5%) from 82.058%
23049805565

Pull #2693

github

web-flow
Merge a9d814ea7 into 4bda85f17
Pull Request #2693: Add reactivity control to coupled transport-depletion analyses

17557 of 25264 branches covered (69.49%)

Branch coverage included in aggregate %.

75 of 86 new or added lines in 4 files covered. (87.21%)

3737 existing lines in 99 files now uncovered.

58038 of 67397 relevant lines covered (86.11%)

47274599.15 hits per line

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

76.69
/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 atomic_relaxation {true};
66
bool reduce_tallies {true};
67
bool res_scat_on {false};
68
bool restart_run {false};
69
bool run_CE {true};
70
bool source_latest {false};
71
bool source_separate {false};
72
bool source_write {true};
73
bool source_mcpl_write {false};
74
bool surf_source_write {false};
75
bool surf_mcpl_write {false};
76
bool surf_source_read {false};
77
bool survival_biasing {false};
78
bool survival_normalization {false};
79
bool temperature_multipole {false};
80
bool trigger_on {false};
81
bool trigger_predict {false};
82
bool uniform_source_sampling {false};
83
bool ufs_on {false};
84
bool urr_ptables_on {true};
85
bool use_decay_photons {false};
86
bool weight_windows_on {false};
87
bool weight_window_checkpoint_surface {false};
88
bool weight_window_checkpoint_collision {true};
89
bool write_all_tracks {false};
90
bool write_initial_source {false};
91

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

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

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

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

155
} // namespace settings
156

157
//==============================================================================
158
// Functions
159
//==============================================================================
160

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

417
  write_message("Reading settings XML file...", 5);
1,360✔
418

419
  read_settings_xml(root);
1,360✔
420
}
1,372✔
421

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

601
  // Check for photon transport
602
  if (check_for_node(root, "photon_transport")) {
8,224✔
603
    photon_transport = get_node_value_bool(root, "photon_transport");
205✔
604

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

611
  // Check for atomic relaxation
612
  if (check_for_node(root, "atomic_relaxation")) {
8,224✔
613
    atomic_relaxation = get_node_value_bool(root, "atomic_relaxation");
15✔
614
  }
615

616
  // Number of bins for logarithmic grid
617
  if (check_for_node(root, "log_grid_bins")) {
8,224✔
618
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
30✔
619
    if (n_log_bins < 1) {
15!
UNCOV
620
      fatal_error("Number of bins for logarithmic grid must be greater "
×
621
                  "than zero.");
622
    }
623
  }
624

625
  // Number of OpenMP threads
626
  if (check_for_node(root, "threads")) {
8,224!
UNCOV
627
    if (mpi::master)
×
UNCOV
628
      warning("The <threads> element has been deprecated. Use "
×
629
              "the OMP_NUM_THREADS environment variable to set the number of "
630
              "threads.");
631
  }
632

633
  // ==========================================================================
634
  // EXTERNAL SOURCE
635

636
  // Get point to list of <source> elements and make sure there is at least one
637
  for (pugi::xml_node node : root.children("source")) {
15,893✔
638
    model::external_sources.push_back(Source::create(node));
15,348✔
639
  }
640

641
  // Check if the user has specified to read surface source
642
  if (check_for_node(root, "surf_source_read")) {
8,214✔
643
    surf_source_read = true;
30✔
644
    // Get surface source read node
645
    xml_node node_ssr = root.child("surf_source_read");
30✔
646

647
    std::string path = "surface_source.h5";
30✔
648
    // Check if the user has specified different file for surface source reading
649
    if (check_for_node(node_ssr, "path")) {
30!
650
      path = get_node_value(node_ssr, "path", false, true);
30✔
651
    }
652
    model::external_sources.push_back(make_unique<FileSource>(path));
30✔
653
  }
30✔
654

655
  // If no source specified, default to isotropic point source at origin with
656
  // Watt spectrum. No default source is needed in random ray mode.
657
  if (model::external_sources.empty() &&
8,214✔
658
      settings::solver_type != SolverType::RANDOM_RAY) {
2,238✔
659
    double T[] {0.0};
2,092✔
660
    double p[] {1.0};
2,092✔
661
    model::external_sources.push_back(make_unique<IndependentSource>(
2,092✔
662
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
4,184✔
663
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
4,184✔
664
      UPtrDist {new Discrete(T, p, 1)}));
4,184✔
665
  }
666

667
  // Build probability mass function for sampling external sources
668
  vector<double> source_strengths;
8,214✔
669
  for (auto& s : model::external_sources) {
18,005✔
670
    source_strengths.push_back(s->strength());
9,791✔
671
  }
672
  model::external_sources_probability.assign(source_strengths);
8,214✔
673

674
  // Check if we want to write out source
675
  if (check_for_node(root, "write_initial_source")) {
8,214!
676
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
677
  }
678

679
  // Get relative number of lost particles
680
  if (check_for_node(root, "source_rejection_fraction")) {
8,214✔
681
    source_rejection_fraction =
14✔
682
      std::stod(get_node_value(root, "source_rejection_fraction"));
14!
683
  }
684

685
  if (check_for_node(root, "free_gas_threshold")) {
8,214!
UNCOV
686
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
687
  }
688

689
  // Surface grazing
690
  if (check_for_node(root, "surface_grazing_cutoff"))
8,214!
UNCOV
691
    surface_grazing_cutoff =
×
UNCOV
692
      std::stod(get_node_value(root, "surface_grazing_cutoff"));
×
693
  if (check_for_node(root, "surface_grazing_ratio"))
8,214!
UNCOV
694
    surface_grazing_ratio =
×
UNCOV
695
      std::stod(get_node_value(root, "surface_grazing_ratio"));
×
696

697
  // Survival biasing
698
  if (check_for_node(root, "survival_biasing")) {
8,214✔
699
    survival_biasing = get_node_value_bool(root, "survival_biasing");
190✔
700
  }
701

702
  // Probability tables
703
  if (check_for_node(root, "ptables")) {
8,214✔
704
    urr_ptables_on = get_node_value_bool(root, "ptables");
15✔
705
  }
706

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

754
  // Particle trace
755
  if (check_for_node(root, "trace")) {
8,214✔
756
    auto temp = get_node_array<int64_t>(root, "trace");
15✔
757
    if (temp.size() != 3) {
15!
UNCOV
758
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
759
                  "batch, generation, and particle number.");
760
    }
761
    trace_batch = temp.at(0);
15✔
762
    trace_gen = temp.at(1);
15✔
763
    trace_particle = temp.at(2);
15✔
764
  }
15✔
765

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

777
    // Reshape into track_identifiers
778
    int n_tracks = temp.size() / 3;
45✔
779
    for (int i = 0; i < n_tracks; ++i) {
180✔
780
      track_identifiers.push_back(
135✔
781
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
135✔
782
    }
783
  }
45✔
784

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

800
      auto* m = dynamic_cast<RegularMesh*>(
334!
801
        model::meshes[model::mesh_map.at(temp)].get());
334!
802
      if (!m)
334!
UNCOV
803
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
804
      simulation::entropy_mesh = m;
334✔
805

806
      // Turn on Shannon entropy calculation
807
      entropy_on = true;
334✔
808

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

825
    auto* m =
15✔
826
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
15!
827
    if (!m)
15!
UNCOV
828
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
829
    simulation::ufs_mesh = m;
15✔
830

831
    // Turn on uniform fission source weighting
832
    ufs_on = true;
15✔
833

834
  } else if (check_for_node(root, "uniform_fs")) {
8,199!
UNCOV
835
    fatal_error(
×
836
      "Specifying a UFS mesh via the <uniform_fs> element "
837
      "is deprecated. Please create a mesh using <mesh> and then reference "
838
      "it by specifying its ID in a <ufs_mesh> element.");
839
  }
840

841
  // Check if the user has specified to write state points
842
  if (check_for_node(root, "state_point")) {
8,214✔
843

844
    // Get pointer to state_point node
845
    auto node_sp = root.child("state_point");
160✔
846

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

864
  // Check if the user has specified to write source points
865
  if (check_for_node(root, "source_point")) {
8,214✔
866
    // Get source_point node
867
    xml_node node_sp = root.child("source_point");
101✔
868

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

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

902
  // Check is the user specified to convert strength to statistical weight
903
  if (check_for_node(root, "uniform_source_sampling")) {
8,214✔
904
    uniform_source_sampling =
55✔
905
      get_node_value_bool(root, "uniform_source_sampling");
55✔
906
  }
907

908
  // Check if the user has specified to write surface source
909
  if (check_for_node(root, "surf_source_write")) {
8,214✔
910
    surf_source_write = true;
412✔
911
    // Get surface source write node
912
    xml_node node_ssw = root.child("surf_source_write");
412✔
913

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

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

933
    // Get maximum number of surface source files to be created
934
    if (check_for_node(node_ssw, "max_source_files")) {
403✔
935
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
66✔
936
    } else {
937
      ssw_max_files = 1;
370✔
938
    }
939

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

966
  // Check if the user has specified to write specific collisions
967
  if (check_for_node(root, "collision_track")) {
8,169✔
968
    settings::collision_track = true;
148✔
969
    // Get collision track node
970
    xml_node node_ct = root.child("collision_track");
148✔
971
    collision_track_config = CollisionTrackConfig {};
148✔
972

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

1030
  // If source is not separate and is to be written out in the statepoint
1031
  // file, make sure that the sourcepoint batch numbers are contained in the
1032
  // statepoint list
1033
  if (!source_separate) {
8,169✔
1034
    for (const auto& b : sourcepoint_batch) {
16,292✔
1035
      if (!contains(statepoint_batch, b)) {
16,418!
UNCOV
1036
        fatal_error(
×
1037
          "Sourcepoint batches are not a subset of statepoint batches.");
1038
      }
1039
    }
1040
  }
1041

1042
  // Check if the user has specified to not reduce tallies at the end of every
1043
  // batch
1044
  if (check_for_node(root, "no_reduce")) {
8,169✔
1045
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
30✔
1046
  }
1047

1048
  // Check if the user has specified to use confidence intervals for
1049
  // uncertainties rather than standard deviations
1050
  if (check_for_node(root, "confidence_intervals")) {
8,169✔
1051
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
15✔
1052
  }
1053

1054
  // Check for output options
1055
  if (check_for_node(root, "output")) {
8,169✔
1056
    // Get pointer to output node
1057
    pugi::xml_node node_output = root.child("output");
764✔
1058

1059
    // Check for summary option
1060
    if (check_for_node(node_output, "summary")) {
764✔
1061
      output_summary = get_node_value_bool(node_output, "summary");
738✔
1062
    }
1063

1064
    // Check for ASCII tallies output option
1065
    if (check_for_node(node_output, "tallies")) {
764✔
1066
      output_tallies = get_node_value_bool(node_output, "tallies");
349✔
1067
    }
1068

1069
    // Set output directory if a path has been specified
1070
    if (check_for_node(node_output, "path")) {
764!
UNCOV
1071
      path_output = get_node_value(node_output, "path");
×
UNCOV
1072
      if (!ends_with(path_output, "/")) {
×
1073
        path_output += "/";
764!
1074
      }
1075
    }
1076
  }
1077

1078
  // Resonance scattering parameters
1079
  if (check_for_node(root, "resonance_scattering")) {
8,169✔
1080
    xml_node node_res_scat = root.child("resonance_scattering");
15✔
1081

1082
    // See if resonance scattering is enabled
1083
    if (check_for_node(node_res_scat, "enable")) {
15!
1084
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
15✔
1085
    } else {
UNCOV
1086
      res_scat_on = true;
×
1087
    }
1088

1089
    // Determine what method is used
1090
    if (check_for_node(node_res_scat, "method")) {
15!
1091
      auto temp = get_node_value(node_res_scat, "method", true, true);
15✔
1092
      if (temp == "rvs") {
15!
1093
        res_scat_method = ResScatMethod::rvs;
15✔
UNCOV
1094
      } else if (temp == "dbrc") {
×
UNCOV
1095
        res_scat_method = ResScatMethod::dbrc;
×
1096
      } else {
UNCOV
1097
        fatal_error(
×
UNCOV
1098
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1099
      }
1100
    }
15✔
1101

1102
    // Minimum energy for resonance scattering
1103
    if (check_for_node(node_res_scat, "energy_min")) {
15!
1104
      res_scat_energy_min =
30✔
1105
        std::stod(get_node_value(node_res_scat, "energy_min"));
30✔
1106
    }
1107
    if (res_scat_energy_min < 0.0) {
15!
UNCOV
1108
      fatal_error("Lower resonance scattering energy bound is negative");
×
1109
    }
1110

1111
    // Maximum energy for resonance scattering
1112
    if (check_for_node(node_res_scat, "energy_max")) {
15!
1113
      res_scat_energy_max =
30✔
1114
        std::stod(get_node_value(node_res_scat, "energy_max"));
30✔
1115
    }
1116
    if (res_scat_energy_max < res_scat_energy_min) {
15!
UNCOV
1117
      fatal_error("Upper resonance scattering energy bound is below the "
×
1118
                  "lower resonance scattering energy bound.");
1119
    }
1120

1121
    // Get resonance scattering nuclides
1122
    if (check_for_node(node_res_scat, "nuclides")) {
15!
1123
      res_scat_nuclides =
15✔
1124
        get_node_array<std::string>(node_res_scat, "nuclides");
30✔
1125
    }
1126
  }
1127

1128
  // Get volume calculations
1129
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
8,483✔
1130
    model::volume_calcs.emplace_back(node_vol);
314✔
1131
  }
1132

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

1155
    // Multipole currently doesn't work with photon transport
1156
    if (temperature_multipole && photon_transport) {
185!
UNCOV
1157
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1158
                  "photon transport.");
1159
    }
1160
  }
1161
  if (check_for_node(root, "temperature_range")) {
8,169✔
1162
    auto range = get_node_array<double>(root, "temperature_range");
170✔
1163
    temperature_range[0] = range.at(0);
170✔
1164
    temperature_range[1] = range.at(1);
170✔
1165
  }
170✔
1166

1167
  // Check for tabular_legendre options
1168
  if (check_for_node(root, "tabular_legendre")) {
8,169✔
1169
    // Get pointer to tabular_legendre node
1170
    xml_node node_tab_leg = root.child("tabular_legendre");
90✔
1171

1172
    // Check for enable option
1173
    if (check_for_node(node_tab_leg, "enable")) {
90!
1174
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
90✔
1175
    }
1176

1177
    // Check for the number of points
1178
    if (check_for_node(node_tab_leg, "num_points")) {
90!
UNCOV
1179
      legendre_to_tabular_points =
×
UNCOV
1180
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
UNCOV
1181
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
UNCOV
1182
        fatal_error(
×
1183
          "The 'num_points' subelement/attribute of the "
1184
          "<tabular_legendre> element must contain a value greater than 1");
1185
      }
1186
    }
1187
  }
1188

1189
  // Check whether create delayed neutrons in fission
1190
  if (check_for_node(root, "create_delayed_neutrons")) {
8,169!
UNCOV
1191
    create_delayed_neutrons =
×
UNCOV
1192
      get_node_value_bool(root, "create_delayed_neutrons");
×
1193
  }
1194

1195
  // Check whether create fission sites
1196
  if (run_mode == RunMode::FIXED_SOURCE) {
8,169✔
1197
    if (check_for_node(root, "create_fission_neutrons")) {
2,798✔
1198
      create_fission_neutrons =
280✔
1199
        get_node_value_bool(root, "create_fission_neutrons");
280✔
1200
    }
1201
  }
1202

1203
  // Check whether to scale fission photon yields
1204
  if (check_for_node(root, "delayed_photon_scaling")) {
8,169!
UNCOV
1205
    delayed_photon_scaling =
×
UNCOV
1206
      get_node_value_bool(root, "delayed_photon_scaling");
×
1207
  }
1208

1209
  // Check whether to use event-based parallelism
1210
  if (check_for_node(root, "event_based")) {
8,169!
UNCOV
1211
    event_based = get_node_value_bool(root, "event_based");
×
1212
  }
1213

1214
  // Check whether material cell offsets should be generated
1215
  if (check_for_node(root, "material_cell_offsets")) {
8,169!
UNCOV
1216
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1217
  }
1218

1219
  // Weight window information
1220
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
8,274✔
1221
    variance_reduction::weight_windows.emplace_back(
105✔
1222
      std::make_unique<WeightWindows>(node_ww));
210✔
1223
  }
1224

1225
  // Enable weight windows by default if one or more are present
1226
  if (variance_reduction::weight_windows.size() > 0)
8,169✔
1227
    settings::weight_windows_on = true;
79✔
1228

1229
  // read weight windows from file
1230
  if (check_for_node(root, "weight_windows_file")) {
8,169!
UNCOV
1231
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1232
  }
1233

1234
  // read settings for weight windows value, this will override
1235
  // the automatic setting even if weight windows are present
1236
  if (check_for_node(root, "weight_windows_on")) {
8,169✔
1237
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
38✔
1238
  }
1239

1240
  if (check_for_node(root, "max_secondaries")) {
8,169!
UNCOV
1241
    settings::max_secondaries =
×
UNCOV
1242
      std::stoi(get_node_value(root, "max_secondaries"));
×
1243
  }
1244

1245
  if (check_for_node(root, "max_history_splits")) {
8,169✔
1246
    settings::max_history_splits =
428✔
1247
      std::stoi(get_node_value(root, "max_history_splits"));
428✔
1248
  }
1249

1250
  if (check_for_node(root, "max_tracks")) {
8,169✔
1251
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
90✔
1252
  }
1253

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

1272
  // Set up weight window checkpoints
1273
  if (check_for_node(root, "weight_window_checkpoints")) {
8,169✔
1274
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
32✔
1275
    if (check_for_node(ww_checkpoints, "collision")) {
32!
1276
      weight_window_checkpoint_collision =
32✔
1277
        get_node_value_bool(ww_checkpoints, "collision");
32✔
1278
    }
1279
    if (check_for_node(ww_checkpoints, "surface")) {
32!
1280
      weight_window_checkpoint_surface =
32✔
1281
        get_node_value_bool(ww_checkpoints, "surface");
32✔
1282
    }
1283
  }
1284

1285
  if (weight_windows_on) {
8,169✔
1286
    if (!weight_window_checkpoint_surface &&
158✔
1287
        !weight_window_checkpoint_collision)
126!
UNCOV
1288
      fatal_error(
×
1289
        "Weight Windows are enabled but there are no valid checkpoints.");
1290
  }
1291

1292
  if (check_for_node(root, "use_decay_photons")) {
8,169✔
1293
    settings::use_decay_photons =
11✔
1294
      get_node_value_bool(root, "use_decay_photons");
11✔
1295
  }
1296
}
8,169✔
1297

1298
void free_memory_settings()
8,320✔
1299
{
1300
  settings::statepoint_batch.clear();
8,320✔
1301
  settings::sourcepoint_batch.clear();
8,320✔
1302
  settings::source_write_surf_id.clear();
8,320✔
1303
  settings::res_scat_nuclides.clear();
8,320✔
1304
}
8,320✔
1305

1306
//==============================================================================
1307
// C API functions
1308
//==============================================================================
1309

1310
extern "C" int openmc_set_n_batches(
221✔
1311
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1312
{
1313
  if (settings::n_inactive >= n_batches) {
221✔
1314
    set_errmsg("Number of active batches must be greater than zero.");
11✔
1315
    return OPENMC_E_INVALID_ARGUMENT;
11✔
1316
  }
1317

1318
  if (!settings::trigger_on) {
210✔
1319
    // Set n_batches and n_max_batches to same value
1320
    settings::n_batches = n_batches;
188✔
1321
    settings::n_max_batches = n_batches;
188✔
1322
  } else {
1323
    // Set n_batches and n_max_batches based on value of set_max_batches
1324
    if (set_max_batches) {
22✔
1325
      settings::n_max_batches = n_batches;
11✔
1326
    } else {
1327
      settings::n_batches = n_batches;
11✔
1328
    }
1329
  }
1330

1331
  // Update size of k_generation and entropy
1332
  int m = settings::n_max_batches * settings::gen_per_batch;
210✔
1333
  simulation::k_generation.reserve(m);
210✔
1334
  simulation::entropy.reserve(m);
210✔
1335

1336
  // Add value of n_batches to statepoint_batch
1337
  if (add_statepoint_batch &&
210✔
1338
      !(contains(settings::statepoint_batch, n_batches)))
199✔
1339
    settings::statepoint_batch.insert(n_batches);
33✔
1340

1341
  return 0;
1342
}
1343

1344
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,530✔
1345
{
1346
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,530✔
1347

1348
  return 0;
2,530✔
1349
}
1350

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