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

openmc-dev / openmc / 30942440215

04 Aug 2026 07:15PM UTC coverage: 81.481% (+0.06%) from 81.425%
30942440215

Pull #4044

github

web-flow
Merge 5f06a886a into 8202ef6fb
Pull Request #4044: Hybrid delta tracking

18963 of 27411 branches covered (69.18%)

Branch coverage included in aggregate %.

721 of 782 new or added lines in 20 files covered. (92.2%)

3 existing lines in 1 file now uncovered.

60943 of 70656 relevant lines covered (86.25%)

51279318.47 hits per line

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

75.89
/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 delta_tracking {false};
57
bool entropy_on {false};
58
bool event_based {false};
59
bool ifp_on {false};
60
bool legendre_to_tabular {true};
61
bool material_cell_offsets {true};
62
bool output_summary {true};
63
bool output_tallies {true};
64
bool particle_restart_run {false};
65
bool photon_transport {false};
66
bool atomic_relaxation {true};
67
bool reduce_tallies {true};
68
bool res_scat_on {false};
69
bool restart_run {false};
70
bool run_CE {true};
71
bool source_latest {false};
72
bool source_separate {false};
73
bool source_write {true};
74
bool source_mcpl_write {false};
75
bool surf_source_write {false};
76
bool surf_mcpl_write {false};
77
bool surf_source_read {false};
78
bool survival_biasing {false};
79
bool survival_normalization {false};
80
bool temperature_multipole {false};
81
bool trigger_on {false};
82
bool trigger_predict {false};
83
bool uniform_source_sampling {false};
84
bool ufs_on {false};
85
bool urr_ptables_on {true};
86
bool use_decay_photons {false};
87
bool use_shared_secondary_bank {false};
88
bool weight_windows_on {false};
89
bool weight_window_checkpoint_surface {false};
90
bool weight_window_checkpoint_collision {true};
91
bool write_all_tracks {false};
92
bool write_initial_source {false};
93

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

104
int32_t n_inactive {0};
105
int32_t max_lost_particles {10};
106
double rel_max_lost_particles {1.0e-6};
107
int32_t max_write_lost_particles {-1};
108
int32_t gen_per_batch {1};
109
int64_t n_particles {-1};
110

111
// Default to hybrid-in-cross-section as it is the standard
112
// approach implemented in Serpent.
113
HybridTrackingType hybrid_delta_type {HybridTrackingType::CrossSection};
114
// Based on the default in Serpent. See Section 4.1 in
115
// http://doi.org/10.1016/j.anucene.2010.01.011
116
double hybrid_xs_threshold {0.9};
117
// The defaults are based on parameter studies performed different
118
// whole-core fission reactor problems
119
array<double, 4> hybrid_energy_threshold {1e1, 1e5, 0.0, 0.0};
120

121
int64_t max_particles_in_flight {100000};
122
int max_particle_events {1000000};
123

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

168
} // namespace settings
169

170
//==============================================================================
171
// Functions
172
//==============================================================================
173

174
void get_run_parameters(pugi::xml_node node_base)
8,412✔
175
{
176
  using namespace settings;
8,412✔
177
  using namespace pugi;
8,412✔
178

179
  // Check number of particles
180
  if (!check_for_node(node_base, "particles")) {
8,412!
181
    fatal_error("Need to specify number of particles.");
×
182
  }
183

184
  // Get number of particles if it wasn't specified as a command-line argument
185
  if (n_particles == -1) {
8,412✔
186
    n_particles = std::stoll(get_node_value(node_base, "particles"));
8,401✔
187
  }
188

189
  // Get maximum number of in flight particles for event-based mode
190
  if (check_for_node(node_base, "max_particles_in_flight")) {
8,412!
191
    max_particles_in_flight =
×
192
      std::stoll(get_node_value(node_base, "max_particles_in_flight"));
×
193
  }
194

195
  // Get maximum number of events allowed per particle
196
  if (check_for_node(node_base, "max_particle_events")) {
8,412!
197
    max_particle_events =
×
198
      std::stoll(get_node_value(node_base, "max_particle_events"));
×
199
  }
200

201
  // Get number of basic batches
202
  if (check_for_node(node_base, "batches")) {
8,412!
203
    n_batches = std::stoi(get_node_value(node_base, "batches"));
8,412✔
204
  }
205
  if (!trigger_on)
8,412✔
206
    n_max_batches = n_batches;
8,271✔
207

208
  // Get max number of lost particles
209
  if (check_for_node(node_base, "max_lost_particles")) {
8,412✔
210
    max_lost_particles =
92✔
211
      std::stoi(get_node_value(node_base, "max_lost_particles"));
46✔
212
  }
213

214
  // Get relative number of lost particles
215
  if (check_for_node(node_base, "rel_max_lost_particles")) {
8,412!
216
    rel_max_lost_particles =
×
217
      std::stod(get_node_value(node_base, "rel_max_lost_particles"));
×
218
  }
219

220
  // Get relative number of lost particles
221
  if (check_for_node(node_base, "max_write_lost_particles")) {
8,412✔
222
    max_write_lost_particles =
30✔
223
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
15✔
224
  }
225

226
  // Get number of inactive batches
227
  if (run_mode == RunMode::EIGENVALUE ||
8,412✔
228
      solver_type == SolverType::RANDOM_RAY) {
3,464✔
229
    if (check_for_node(node_base, "inactive")) {
5,406✔
230
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
5,151✔
231
    }
232
    if (check_for_node(node_base, "generations_per_batch")) {
5,406✔
233
      gen_per_batch =
30✔
234
        std::stoi(get_node_value(node_base, "generations_per_batch"));
15✔
235
    }
236

237
    // Preallocate space for keff and entropy by generation
238
    int m = settings::n_max_batches * settings::gen_per_batch;
5,406✔
239
    simulation::k_generation.reserve(m);
5,406✔
240
    simulation::entropy.reserve(m);
5,406✔
241

242
    // Get the trigger information for keff
243
    if (check_for_node(node_base, "keff_trigger")) {
5,406✔
244
      xml_node node_keff_trigger = node_base.child("keff_trigger");
101✔
245

246
      if (check_for_node(node_keff_trigger, "type")) {
101!
247
        auto temp = get_node_value(node_keff_trigger, "type", true, true);
101✔
248
        if (temp == "std_dev") {
101!
249
          keff_trigger.metric = TriggerMetric::standard_deviation;
101✔
250
        } else if (temp == "variance") {
×
251
          keff_trigger.metric = TriggerMetric::variance;
×
252
        } else if (temp == "rel_err") {
×
253
          keff_trigger.metric = TriggerMetric::relative_error;
×
254
        } else {
255
          fatal_error("Unrecognized keff trigger type " + temp);
×
256
        }
257
      } else {
×
258
        fatal_error("Specify keff trigger type in settings XML");
×
259
      }
260

261
      if (check_for_node(node_keff_trigger, "threshold")) {
101!
262
        keff_trigger.threshold =
202✔
263
          std::stod(get_node_value(node_keff_trigger, "threshold"));
202✔
264
        if (keff_trigger.threshold <= 0) {
101!
265
          fatal_error("keff trigger threshold must be positive");
×
266
        }
267
      } else {
268
        fatal_error("Specify keff trigger threshold in settings XML");
×
269
      }
270
    }
271
  }
272

273
  // Random ray variables
274
  if (solver_type == SolverType::RANDOM_RAY) {
8,412✔
275
    xml_node random_ray_node = node_base.child("random_ray");
814✔
276
    if (check_for_node(random_ray_node, "distance_active")) {
814!
277
      RandomRay::distance_active_ =
1,628✔
278
        std::stod(get_node_value(random_ray_node, "distance_active"));
1,628✔
279
      if (RandomRay::distance_active_ <= 0.0) {
814!
280
        fatal_error("Random ray active distance must be greater than 0");
×
281
      }
282
    } else {
283
      fatal_error("Specify random ray active distance in settings XML");
×
284
    }
285
    if (check_for_node(random_ray_node, "distance_inactive")) {
814!
286
      RandomRay::distance_inactive_ =
1,628✔
287
        std::stod(get_node_value(random_ray_node, "distance_inactive"));
1,628✔
288
      if (RandomRay::distance_inactive_ < 0) {
814!
289
        fatal_error(
×
290
          "Random ray inactive distance must be greater than or equal to 0");
291
      }
292
    } else {
293
      fatal_error("Specify random ray inactive distance in settings XML");
×
294
    }
295
    if (check_for_node(random_ray_node, "ray_source")) {
814!
296
      xml_node ray_source_node = random_ray_node.child("ray_source");
814✔
297
      xml_node source_node = ray_source_node.child("source");
814✔
298
      // Get point to list of <source> elements and make sure there is at least
299
      // one
300
      RandomRay::ray_source_ = Source::create(source_node);
1,628✔
301
    } else {
302
      fatal_error("Specify random ray source in settings XML");
×
303
    }
304
    if (check_for_node(random_ray_node, "volume_estimator")) {
814✔
305
      std::string temp_str =
173✔
306
        get_node_value(random_ray_node, "volume_estimator", true, true);
173✔
307
      if (temp_str == "simulation_averaged") {
173✔
308
        FlatSourceDomain::volume_estimator_ =
30✔
309
          RandomRayVolumeEstimator::SIMULATION_AVERAGED;
310
      } else if (temp_str == "naive") {
143✔
311
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::NAIVE;
91✔
312
      } else if (temp_str == "hybrid") {
52!
313
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::HYBRID;
52✔
314
      } else {
315
        fatal_error("Unrecognized volume estimator: " + temp_str);
×
316
      }
317
    }
173✔
318
    if (check_for_node(random_ray_node, "source_shape")) {
814✔
319
      std::string temp_str =
472✔
320
        get_node_value(random_ray_node, "source_shape", true, true);
472✔
321
      if (temp_str == "flat") {
472✔
322
        RandomRay::source_shape_ = RandomRaySourceShape::FLAT;
97✔
323
      } else if (temp_str == "linear") {
375✔
324
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR;
330✔
325
      } else if (temp_str == "linear_xy") {
45!
326
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR_XY;
45✔
327
      } else {
328
        fatal_error("Unrecognized source shape: " + temp_str);
×
329
      }
330
    }
472✔
331
    if (check_for_node(random_ray_node, "volume_normalized_flux_tallies")) {
814✔
332
      FlatSourceDomain::volume_normalized_flux_tallies_ =
551✔
333
        get_node_value_bool(random_ray_node, "volume_normalized_flux_tallies");
551✔
334
    }
335
    if (check_for_node(random_ray_node, "adjoint")) {
814✔
336
      FlatSourceDomain::adjoint_requested_ =
45✔
337
        get_node_value_bool(random_ray_node, "adjoint");
45✔
338
    }
339
    if (check_for_node(random_ray_node, "sample_method")) {
814✔
340
      std::string temp_str =
52✔
341
        get_node_value(random_ray_node, "sample_method", true, true);
52✔
342
      if (temp_str == "prng") {
52!
343
        RandomRay::sample_method_ = RandomRaySampleMethod::PRNG;
×
344
      } else if (temp_str == "halton") {
52✔
345
        RandomRay::sample_method_ = RandomRaySampleMethod::HALTON;
37✔
346
      } else if (temp_str == "s2") {
15!
347
        RandomRay::sample_method_ = RandomRaySampleMethod::S2;
15✔
348
      } else {
349
        fatal_error("Unrecognized sample method: " + temp_str);
×
350
      }
351
    }
52✔
352
    if (check_for_node(random_ray_node, "source_region_meshes")) {
814✔
353
      pugi::xml_node node_source_region_meshes =
368✔
354
        random_ray_node.child("source_region_meshes");
368✔
355
      for (pugi::xml_node node_mesh :
796✔
356
        node_source_region_meshes.children("mesh")) {
796✔
357
        int mesh_id = std::stoi(node_mesh.attribute("id").value());
856✔
358
        for (pugi::xml_node node_domain : node_mesh.children("domain")) {
856✔
359
          int domain_id = std::stoi(node_domain.attribute("id").value());
856✔
360
          std::string domain_type = node_domain.attribute("type").value();
428✔
361
          Source::DomainType type;
428✔
362
          if (domain_type == "material") {
428✔
363
            type = Source::DomainType::MATERIAL;
30✔
364
          } else if (domain_type == "cell") {
398✔
365
            type = Source::DomainType::CELL;
30✔
366
          } else if (domain_type == "universe") {
368!
367
            type = Source::DomainType::UNIVERSE;
368✔
368
          } else {
369
            throw std::runtime_error("Unknown domain type: " + domain_type);
×
370
          }
371
          FlatSourceDomain::mesh_domain_map_[mesh_id].emplace_back(
428✔
372
            type, domain_id);
373
        }
428✔
374
      }
375
    }
376
    if (check_for_node(random_ray_node, "diagonal_stabilization_rho")) {
814✔
377
      FlatSourceDomain::diagonal_stabilization_rho_ = std::stod(
15✔
378
        get_node_value(random_ray_node, "diagonal_stabilization_rho"));
15✔
379
      if (FlatSourceDomain::diagonal_stabilization_rho_ < 0.0 ||
15!
380
          FlatSourceDomain::diagonal_stabilization_rho_ > 1.0) {
381
        fatal_error("Random ray diagonal stabilization rho factor must be "
×
382
                    "between 0 and 1");
383
      }
384
    }
385
    if (check_for_node(random_ray_node, "adjoint_source")) {
814✔
386
      pugi::xml_node adj_source_node = random_ray_node.child("adjoint_source");
15✔
387
      for (pugi::xml_node source_node : adj_source_node.children("source")) {
30✔
388
        // Find any local adjoint sources
389
        model::adjoint_sources.push_back(Source::create(source_node));
30✔
390
      }
391
    }
392
  }
393
}
8,412✔
394

395
void read_settings_xml()
1,423✔
396
{
397
  using namespace settings;
1,423✔
398
  using namespace pugi;
1,423✔
399
  // Check if settings.xml exists
400
  std::string filename = settings::path_input + "settings.xml";
1,423✔
401
  if (!file_exists(filename)) {
1,423✔
402
    if (run_mode != RunMode::PLOTTING) {
22!
403
      fatal_error("Could not find any XML input files! In order to run OpenMC, "
×
404
                  "you first need a set of input files; at a minimum, this "
405
                  "includes settings.xml, geometry.xml, and materials.xml or a "
406
                  "single model XML file. Please consult the user's guide at "
407
                  "https://docs.openmc.org for further information.");
408
    } else {
409
      // The settings.xml file is optional if we just want to make a plot.
410
      return;
22✔
411
    }
412
  }
413

414
  // Parse settings.xml file
415
  xml_document doc;
1,401✔
416
  auto result = doc.load_file(filename.c_str());
1,401✔
417
  if (!result) {
1,401!
418
    fatal_error("Error processing settings.xml file.");
×
419
  }
420

421
  // Get root element
422
  xml_node root = doc.document_element();
1,401✔
423

424
  // Verbosity
425
  if (check_for_node(root, "verbosity") && verbosity == -1) {
1,401!
426
    verbosity = std::stoi(get_node_value(root, "verbosity"));
428✔
427
  } else if (verbosity == -1) {
1,187!
428
    verbosity = 7;
1,187✔
429
  }
430

431
  // To this point, we haven't displayed any output since we didn't know what
432
  // the verbosity is. Now that we checked for it, show the title if necessary
433
  if (mpi::master) {
1,401✔
434
    if (verbosity >= 2)
1,213✔
435
      title();
1,007✔
436
  }
437

438
  write_message("Reading settings XML file...", 5);
1,401✔
439

440
  read_settings_xml(root);
1,401✔
441
}
1,413✔
442

443
void read_settings_xml(pugi::xml_node root)
9,407✔
444
{
445
  using namespace settings;
9,407✔
446
  using namespace pugi;
9,407✔
447

448
  // Find if a multi-group or continuous-energy simulation is desired
449
  if (check_for_node(root, "energy_mode")) {
9,407✔
450
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
1,379✔
451
    if (temp_str == "mg" || temp_str == "multi-group") {
2,758!
452
      run_CE = false;
1,379✔
453
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
454
      run_CE = true;
×
455
    }
456
  }
1,379✔
457

458
  // Check for user meshes and allocate
459
  read_meshes(root);
9,407✔
460

461
  // Look for deprecated cross_sections.xml file in settings.xml
462
  if (check_for_node(root, "cross_sections")) {
9,407!
463
    warning(
×
464
      "Setting cross_sections in settings.xml has been deprecated."
465
      " The cross_sections are now set in materials.xml and the "
466
      "cross_sections input to materials.xml and the OPENMC_CROSS_SECTIONS"
467
      " environment variable will take precendent over setting "
468
      "cross_sections in settings.xml.");
469
    path_cross_sections = get_node_value(root, "cross_sections");
×
470
  }
471

472
  if (!run_CE) {
9,407✔
473
    // Scattering Treatments
474
    if (check_for_node(root, "max_order")) {
1,379✔
475
      max_order = std::stoi(get_node_value(root, "max_order"));
30✔
476
    } else {
477
      // Set to default of largest int - 1, which means to use whatever is
478
      // contained in library. This is largest int - 1 because for legendre
479
      // scattering, a value of 1 is added to the order; adding 1 to the largest
480
      // int gets you the largest negative integer, which is not what we want.
481
      max_order = std::numeric_limits<int>::max() - 1;
1,364✔
482
    }
483
  }
484

485
  // Check for a trigger node and get trigger information
486
  if (check_for_node(root, "trigger")) {
9,407✔
487
    xml_node node_trigger = root.child("trigger");
156✔
488

489
    // Check if trigger(s) are to be turned on
490
    trigger_on = get_node_value_bool(node_trigger, "active");
156✔
491

492
    if (trigger_on) {
156✔
493
      if (check_for_node(node_trigger, "max_batches")) {
141!
494
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
282✔
495
      } else {
496
        fatal_error("<max_batches> must be specified with triggers");
×
497
      }
498

499
      // Get the batch interval to check triggers
500
      if (!check_for_node(node_trigger, "batch_interval")) {
141✔
501
        trigger_predict = true;
15✔
502
      } else {
503
        trigger_batch_interval =
252✔
504
          std::stoi(get_node_value(node_trigger, "batch_interval"));
252✔
505
        if (trigger_batch_interval <= 0) {
126!
506
          fatal_error("Trigger batch interval must be greater than zero");
×
507
        }
508
      }
509
    }
510
  }
511

512
  // Check run mode if it hasn't been set from the command line
513
  xml_node node_mode;
9,407✔
514
  if (run_mode == RunMode::UNSET) {
9,407✔
515
    if (check_for_node(root, "run_mode")) {
8,444✔
516
      std::string temp_str = get_node_value(root, "run_mode", true, true);
8,414✔
517
      if (temp_str == "eigenvalue") {
8,414✔
518
        run_mode = RunMode::EIGENVALUE;
4,918✔
519
      } else if (temp_str == "fixed source") {
3,496✔
520
        run_mode = RunMode::FIXED_SOURCE;
3,464✔
521
      } else if (temp_str == "plot") {
32!
522
        run_mode = RunMode::PLOTTING;
×
523
      } else if (temp_str == "particle restart") {
32!
524
        run_mode = RunMode::PARTICLE;
×
525
      } else if (temp_str == "volume") {
32!
526
        run_mode = RunMode::VOLUME;
32✔
527
      } else {
528
        fatal_error("Unrecognized run mode: " + temp_str);
×
529
      }
530

531
      // Assume XML specifies <particles>, <batches>, etc. directly
532
      node_mode = root;
8,414✔
533
    } else {
8,414✔
534
      warning("<run_mode> should be specified.");
30✔
535

536
      // Make sure that either eigenvalue or fixed source was specified
537
      node_mode = root.child("eigenvalue");
30✔
538
      if (node_mode) {
30!
539
        run_mode = RunMode::EIGENVALUE;
30✔
540
      } else {
541
        node_mode = root.child("fixed_source");
×
542
        if (node_mode) {
×
543
          run_mode = RunMode::FIXED_SOURCE;
×
544
        } else {
545
          fatal_error("<eigenvalue> or <fixed_source> not specified.");
×
546
        }
547
      }
548
    }
549
  }
550

551
  // Check solver type
552
  if (check_for_node(root, "random_ray")) {
9,407✔
553
    solver_type = SolverType::RANDOM_RAY;
814✔
554
    if (run_CE)
814!
555
      fatal_error("multi-group energy mode must be specified in settings XML "
×
556
                  "when using the random ray solver.");
557
  }
558

559
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
9,407✔
560
    // Read run parameters
561
    get_run_parameters(node_mode);
8,412✔
562

563
    // Check number of active batches, inactive batches, max lost particles and
564
    // particles
565
    if (n_batches <= n_inactive) {
8,412!
566
      fatal_error("Number of active batches must be greater than zero.");
×
567
    } else if (n_inactive < 0) {
8,412!
568
      fatal_error("Number of inactive batches must be non-negative.");
×
569
    } else if (n_particles <= 0) {
8,412!
570
      fatal_error("Number of particles must be greater than zero.");
×
571
    } else if (max_lost_particles <= 0) {
8,412!
572
      fatal_error("Number of max lost particles must be greater than zero.");
×
573
    } else if (rel_max_lost_particles <= 0.0 || rel_max_lost_particles >= 1.0) {
8,412!
574
      fatal_error("Relative max lost particles must be between zero and one.");
×
575
    }
576

577
    // Check for user value for the number of generation of the Iterated Fission
578
    // Probability (IFP) method
579
    if (check_for_node(root, "ifp_n_generation")) {
8,412✔
580
      ifp_n_generation = std::stoi(get_node_value(root, "ifp_n_generation"));
166✔
581
      if (ifp_n_generation <= 0) {
83!
582
        fatal_error("'ifp_n_generation' must be greater than 0.");
×
583
      }
584
      // Avoid tallying 0 if IFP logs are not complete when active cycles start
585
      if (ifp_n_generation > n_inactive) {
83✔
586
        fatal_error("'ifp_n_generation' must be lower than or equal to the "
9✔
587
                    "number of inactive cycles.");
588
      }
589
    }
590
  }
591

592
  // Copy plotting random number seed if specified
593
  if (check_for_node(root, "plot_seed")) {
9,398!
594
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
595
    model::plotter_seed = seed;
×
596
  }
597

598
  // Copy random number seed if specified
599
  if (check_for_node(root, "seed")) {
9,398✔
600
    auto seed = std::stoll(get_node_value(root, "seed"));
1,200✔
601
    openmc_set_seed(seed);
600✔
602
  }
603

604
  // Copy random number stride if specified
605
  if (check_for_node(root, "stride")) {
9,398✔
606
    auto stride = std::stoull(get_node_value(root, "stride"));
30✔
607
    openmc_set_stride(stride);
15✔
608
  }
609

610
  // Check for electron treatment
611
  if (check_for_node(root, "electron_treatment")) {
9,398✔
612
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
108✔
613
    if (temp_str == "led") {
108✔
614
      electron_treatment = ElectronTreatment::LED;
41✔
615
    } else if (temp_str == "ttb") {
67!
616
      electron_treatment = ElectronTreatment::TTB;
67✔
617
    } else {
618
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
619
    }
620
  }
108✔
621

622
  // Check for photon transport
623
  if (check_for_node(root, "photon_transport")) {
9,398✔
624
    photon_transport = get_node_value_bool(root, "photon_transport");
712✔
625

626
    if (!run_CE && photon_transport) {
712!
627
      fatal_error("Photon transport is not currently supported in "
×
628
                  "multigroup mode");
629
    }
630
  }
631

632
  // Check for atomic relaxation
633
  if (check_for_node(root, "atomic_relaxation")) {
9,398✔
634
    atomic_relaxation = get_node_value_bool(root, "atomic_relaxation");
30✔
635
  }
636

637
  // Number of bins for logarithmic grid
638
  if (check_for_node(root, "log_grid_bins")) {
9,398✔
639
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
30✔
640
    if (n_log_bins < 1) {
15!
641
      fatal_error("Number of bins for logarithmic grid must be greater "
×
642
                  "than zero.");
643
    }
644
  }
645

646
  // Number of OpenMP threads
647
  if (check_for_node(root, "threads")) {
9,398!
648
    if (mpi::master)
×
649
      warning("The <threads> element has been deprecated. Use "
×
650
              "the OMP_NUM_THREADS environment variable to set the number of "
651
              "threads.");
652
  }
653

654
  // ==========================================================================
655
  // EXTERNAL SOURCE
656

657
  // Get point to list of <source> elements and make sure there is at least one
658
  for (pugi::xml_node node : root.children("source")) {
17,910✔
659
    model::external_sources.push_back(Source::create(node));
17,034✔
660
  }
661

662
  // Check if the user has specified to read surface source
663
  if (check_for_node(root, "surf_source_read")) {
9,388✔
664
    surf_source_read = true;
30✔
665
    // Get surface source read node
666
    xml_node node_ssr = root.child("surf_source_read");
30✔
667

668
    std::string path = "surface_source.h5";
30✔
669
    // Check if the user has specified different file for surface source reading
670
    if (check_for_node(node_ssr, "path")) {
30!
671
      path = get_node_value(node_ssr, "path", false, true);
30✔
672
    }
673
    model::external_sources.push_back(make_unique<FileSource>(path));
30✔
674
  }
30✔
675

676
  // If no source specified, default to isotropic point source at origin with
677
  // Watt spectrum. No default source is needed in random ray mode.
678
  if (model::external_sources.empty() &&
9,388✔
679
      settings::solver_type != SolverType::RANDOM_RAY) {
2,635✔
680
    double T[] {0.0};
2,489✔
681
    double p[] {1.0};
2,489✔
682
    model::external_sources.push_back(make_unique<IndependentSource>(
2,489✔
683
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
4,978✔
684
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
4,978✔
685
      UPtrDist {new Discrete(T, p, 1)}));
4,978✔
686
  }
687

688
  // Build probability mass function for sampling external sources
689
  vector<double> source_strengths;
9,388✔
690
  for (auto& s : model::external_sources) {
20,419✔
691
    source_strengths.push_back(s->strength());
11,031✔
692
  }
693
  model::external_sources_probability.assign(source_strengths);
9,388✔
694

695
  // Check if we want to write out source
696
  if (check_for_node(root, "write_initial_source")) {
9,388!
697
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
698
  }
699

700
  // Get relative number of lost particles
701
  if (check_for_node(root, "source_rejection_fraction")) {
9,388✔
702
    source_rejection_fraction =
14✔
703
      std::stod(get_node_value(root, "source_rejection_fraction"));
14!
704
  }
705

706
  if (check_for_node(root, "free_gas_threshold")) {
9,388!
707
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
708
  }
709

710
  // Surface grazing
711
  if (check_for_node(root, "surface_grazing_cutoff"))
9,388!
712
    surface_grazing_cutoff =
×
713
      std::stod(get_node_value(root, "surface_grazing_cutoff"));
×
714
  if (check_for_node(root, "surface_grazing_ratio"))
9,388!
715
    surface_grazing_ratio =
×
716
      std::stod(get_node_value(root, "surface_grazing_ratio"));
×
717

718
  // Survival biasing
719
  if (check_for_node(root, "survival_biasing")) {
9,388✔
720
    survival_biasing = get_node_value_bool(root, "survival_biasing");
227✔
721
  }
722

723
  // Probability tables
724
  if (check_for_node(root, "ptables")) {
9,388✔
725
    urr_ptables_on = get_node_value_bool(root, "ptables");
15✔
726
  }
727

728
  // Cutoffs
729
  if (check_for_node(root, "cutoff")) {
9,388✔
730
    xml_node node_cutoff = root.child("cutoff");
138✔
731
    if (check_for_node(node_cutoff, "weight")) {
138✔
732
      weight_cutoff = std::stod(get_node_value(node_cutoff, "weight"));
30✔
733
    }
734
    if (check_for_node(node_cutoff, "weight_avg")) {
138✔
735
      weight_survive = std::stod(get_node_value(node_cutoff, "weight_avg"));
30✔
736
    }
737
    if (check_for_node(node_cutoff, "survival_normalization")) {
138!
738
      survival_normalization =
×
739
        get_node_value_bool(node_cutoff, "survival_normalization");
×
740
    }
741
    if (check_for_node(node_cutoff, "energy_neutron")) {
138✔
742
      energy_cutoff[0] =
15✔
743
        std::stod(get_node_value(node_cutoff, "energy_neutron"));
30✔
744
    } else if (check_for_node(node_cutoff, "energy")) {
123!
745
      warning("The use of an <energy> cutoff is deprecated and should "
×
746
              "be replaced by <energy_neutron>.");
747
      energy_cutoff[0] = std::stod(get_node_value(node_cutoff, "energy"));
×
748
    }
749
    if (check_for_node(node_cutoff, "energy_photon")) {
138✔
750
      energy_cutoff[1] =
82✔
751
        std::stod(get_node_value(node_cutoff, "energy_photon"));
164✔
752
    }
753
    if (check_for_node(node_cutoff, "energy_electron")) {
138!
754
      energy_cutoff[2] =
×
755
        std::stof(get_node_value(node_cutoff, "energy_electron"));
×
756
    }
757
    if (check_for_node(node_cutoff, "energy_positron")) {
138!
758
      energy_cutoff[3] =
×
759
        std::stod(get_node_value(node_cutoff, "energy_positron"));
×
760
    }
761
    if (check_for_node(node_cutoff, "time_neutron")) {
138✔
762
      time_cutoff[0] = std::stod(get_node_value(node_cutoff, "time_neutron"));
26✔
763
    }
764
    if (check_for_node(node_cutoff, "time_photon")) {
138!
765
      time_cutoff[1] = std::stod(get_node_value(node_cutoff, "time_photon"));
×
766
    }
767
    if (check_for_node(node_cutoff, "time_electron")) {
138!
768
      time_cutoff[2] = std::stod(get_node_value(node_cutoff, "time_electron"));
×
769
    }
770
    if (check_for_node(node_cutoff, "time_positron")) {
138!
771
      time_cutoff[3] = std::stod(get_node_value(node_cutoff, "time_positron"));
×
772
    }
773
  }
774

775
  // read properties from file
776
  if (check_for_node(root, "properties_file")) {
9,388✔
777
    properties_file = get_node_value(root, "properties_file");
11✔
778
    if (!file_exists(properties_file)) {
11!
779
      fatal_error(fmt::format("File '{}' does not exist.", properties_file));
×
780
    }
781
  }
782

783
  // Particle trace
784
  if (check_for_node(root, "trace")) {
9,388✔
785
    auto temp = get_node_array<int64_t>(root, "trace");
15✔
786
    if (temp.size() != 3) {
15!
787
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
788
                  "batch, generation, and particle number.");
789
    }
790
    trace_batch = temp.at(0);
15✔
791
    trace_gen = temp.at(1);
15✔
792
    trace_particle = temp.at(2);
15✔
793
  }
15✔
794

795
  // Particle tracks
796
  if (check_for_node(root, "track")) {
9,388✔
797
    // Get values and make sure there are three per particle
798
    auto temp = get_node_array<int>(root, "track");
45✔
799
    if (temp.size() % 3 != 0) {
45!
800
      fatal_error(
×
801
        "Number of integers specified in 'track' is not "
802
        "divisible by 3.  Please provide 3 integers per particle to be "
803
        "tracked.");
804
    }
805

806
    // Reshape into track_identifiers
807
    int n_tracks = temp.size() / 3;
45✔
808
    for (int i = 0; i < n_tracks; ++i) {
180✔
809
      track_identifiers.push_back(
135✔
810
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
135✔
811
    }
812
  }
45✔
813

814
  // Shannon entropy
815
  if (solver_type == SolverType::RANDOM_RAY) {
9,388✔
816
    if (check_for_node(root, "entropy_mesh")) {
814!
817
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
818
                  "No user-defined entropy mesh is supported.");
819
    }
820
    entropy_on = true;
814✔
821
  } else if (solver_type == SolverType::MONTE_CARLO) {
8,574!
822
    if (check_for_node(root, "entropy_mesh")) {
8,574✔
823
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
668✔
824
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
334!
825
        fatal_error(fmt::format(
×
826
          "Mesh {} specified for Shannon entropy does not exist.", temp));
827
      }
828

829
      auto* m = dynamic_cast<RegularMesh*>(
334!
830
        model::meshes[model::mesh_map.at(temp)].get());
334!
831
      if (!m)
334!
832
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
833
      simulation::entropy_mesh = m;
334✔
834

835
      // Turn on Shannon entropy calculation
836
      entropy_on = true;
334✔
837

838
    } else if (check_for_node(root, "entropy")) {
8,240!
839
      fatal_error(
×
840
        "Specifying a Shannon entropy mesh via the <entropy> element "
841
        "is deprecated. Please create a mesh using <mesh> and then reference "
842
        "it by specifying its ID in an <entropy_mesh> element.");
843
    }
844
  }
845
  // Uniform fission source weighting mesh
846
  if (check_for_node(root, "ufs_mesh")) {
9,388✔
847
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
30✔
848
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
15!
849
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
850
                              "method does not exist.",
851
        temp));
852
    }
853

854
    auto* m =
15✔
855
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
15!
856
    if (!m)
15!
857
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
858
    simulation::ufs_mesh = m;
15✔
859

860
    // Turn on uniform fission source weighting
861
    ufs_on = true;
15✔
862

863
  } else if (check_for_node(root, "uniform_fs")) {
9,373!
864
    fatal_error(
×
865
      "Specifying a UFS mesh via the <uniform_fs> element "
866
      "is deprecated. Please create a mesh using <mesh> and then reference "
867
      "it by specifying its ID in a <ufs_mesh> element.");
868
  }
869

870
  // Check if the user has specified to write state points
871
  if (check_for_node(root, "state_point")) {
9,388✔
872

873
    // Get pointer to state_point node
874
    auto node_sp = root.child("state_point");
160✔
875

876
    // Determine number of batches at which to store state points
877
    if (check_for_node(node_sp, "batches")) {
160!
878
      // User gave specific batches to write state points
879
      auto temp = get_node_array<int>(node_sp, "batches");
160✔
880
      for (const auto& b : temp) {
491✔
881
        statepoint_batch.insert(b);
331✔
882
      }
883
    } else {
160✔
884
      // If neither were specified, write state point at last batch
885
      statepoint_batch.insert(n_batches);
×
886
    }
887
  } else {
888
    // If no <state_point> tag was present, by default write state point at
889
    // last batch only
890
    statepoint_batch.insert(n_batches);
9,228✔
891
  }
892

893
  // Check if the user has specified to write source points
894
  if (check_for_node(root, "source_point")) {
9,388✔
895
    // Get source_point node
896
    xml_node node_sp = root.child("source_point");
101✔
897

898
    // Determine batches at which to store source points
899
    if (check_for_node(node_sp, "batches")) {
101✔
900
      // User gave specific batches to write source points
901
      auto temp = get_node_array<int>(node_sp, "batches");
45✔
902
      for (const auto& b : temp) {
120✔
903
        sourcepoint_batch.insert(b);
75✔
904
      }
905
    } else {
45✔
906
      // If neither were specified, write source points with state points
907
      sourcepoint_batch = statepoint_batch;
56!
908
    }
909

910
    // Check if the user has specified to write binary source file
911
    if (check_for_node(node_sp, "separate")) {
101✔
912
      source_separate = get_node_value_bool(node_sp, "separate");
71✔
913
    }
914
    if (check_for_node(node_sp, "write")) {
101!
915
      source_write = get_node_value_bool(node_sp, "write");
×
916
    }
917
    if (check_for_node(node_sp, "mcpl")) {
101✔
918
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
26✔
919
    }
920
    if (check_for_node(node_sp, "overwrite_latest")) {
101✔
921
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
15✔
922
      source_separate = source_latest;
15✔
923
    }
924
  } else {
925
    // If no <source_point> tag was present, by default we keep source bank in
926
    // statepoint file and write it out at statepoints intervals
927
    source_separate = false;
9,287✔
928
    sourcepoint_batch = statepoint_batch;
9,287!
929
  }
930

931
  // Check is the user specified to convert strength to statistical weight
932
  if (check_for_node(root, "uniform_source_sampling")) {
9,388✔
933
    uniform_source_sampling =
55✔
934
      get_node_value_bool(root, "uniform_source_sampling");
55✔
935
  }
936

937
  // Check if the user has specified to write surface source
938
  if (check_for_node(root, "surf_source_write")) {
9,388✔
939
    surf_source_write = true;
412✔
940
    // Get surface source write node
941
    xml_node node_ssw = root.child("surf_source_write");
412✔
942

943
    // Determine surface ids at which crossing particles are to be banked.
944
    // If no surfaces are specified, all surfaces in the model will be used
945
    // to bank source points.
946
    if (check_for_node(node_ssw, "surface_ids")) {
412✔
947
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
202✔
948
      for (const auto& b : temp) {
994✔
949
        source_write_surf_id.insert(b);
792✔
950
      }
951
    }
202✔
952

953
    // Get maximum number of particles to be banked per surface
954
    if (check_for_node(node_ssw, "max_particles")) {
412✔
955
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
806✔
956
    } else {
957
      fatal_error("A maximum number of particles needs to be specified "
9✔
958
                  "using the 'max_particles' parameter to store surface "
959
                  "source points.");
960
    }
961

962
    // Get maximum number of surface source files to be created
963
    if (check_for_node(node_ssw, "max_source_files")) {
403✔
964
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
66✔
965
    } else {
966
      ssw_max_files = 1;
370✔
967
    }
968

969
    if (check_for_node(node_ssw, "mcpl")) {
403✔
970
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
11✔
971
    }
972
    // Get cell information
973
    if (check_for_node(node_ssw, "cell")) {
403✔
974
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
208✔
975
      ssw_cell_type = SSWCellType::Both;
104✔
976
    }
977
    if (check_for_node(node_ssw, "cellfrom")) {
403✔
978
      if (ssw_cell_id != C_NONE) {
90✔
979
        fatal_error(
18✔
980
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
981
      }
982
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
144✔
983
      ssw_cell_type = SSWCellType::From;
72✔
984
    }
985
    if (check_for_node(node_ssw, "cellto")) {
385✔
986
      if (ssw_cell_id != C_NONE) {
71✔
987
        fatal_error(
18✔
988
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
989
      }
990
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
106✔
991
      ssw_cell_type = SSWCellType::To;
53✔
992
    }
993
  }
994

995
  // Check if the user has specified to write specific collisions
996
  if (check_for_node(root, "collision_track")) {
9,343✔
997
    settings::collision_track = true;
160✔
998
    // Get collision track node
999
    xml_node node_ct = root.child("collision_track");
160✔
1000
    collision_track_config = CollisionTrackConfig {};
160✔
1001

1002
    // Determine cell ids at which crossing particles are to be banked
1003
    if (check_for_node(node_ct, "cell_ids")) {
160✔
1004
      auto temp = get_node_array<int>(node_ct, "cell_ids");
89✔
1005
      for (const auto& b : temp) {
237✔
1006
        collision_track_config.cell_ids.insert(b);
148✔
1007
      }
1008
    }
89✔
1009
    if (check_for_node(node_ct, "reactions")) {
160✔
1010
      auto temp = get_node_array<std::string>(node_ct, "reactions");
63✔
1011
      for (const auto& b : temp) {
171✔
1012
        int reaction_int = reaction_mt(b);
108✔
1013
        if (reaction_int > 0) {
108!
1014
          collision_track_config.mt_numbers.insert(reaction_int);
108✔
1015
        }
1016
      }
1017
    }
63✔
1018
    if (check_for_node(node_ct, "universe_ids")) {
160✔
1019
      auto temp = get_node_array<int>(node_ct, "universe_ids");
30✔
1020
      for (const auto& b : temp) {
60✔
1021
        collision_track_config.universe_ids.insert(b);
30✔
1022
      }
1023
    }
30✔
1024
    if (check_for_node(node_ct, "material_ids")) {
160✔
1025
      auto temp = get_node_array<int>(node_ct, "material_ids");
30✔
1026
      for (const auto& b : temp) {
75✔
1027
        collision_track_config.material_ids.insert(b);
45✔
1028
      }
1029
    }
30✔
1030
    if (check_for_node(node_ct, "nuclides")) {
160✔
1031
      auto temp = get_node_array<std::string>(node_ct, "nuclides");
30✔
1032
      for (const auto& b : temp) {
120✔
1033
        collision_track_config.nuclides.insert(b);
90✔
1034
      }
1035
    }
30✔
1036
    if (check_for_node(node_ct, "deposited_E_threshold")) {
160✔
1037
      collision_track_config.deposited_energy_threshold =
60✔
1038
        std::stod(get_node_value(node_ct, "deposited_E_threshold"));
60✔
1039
    }
1040
    // Get maximum number of particles to be banked per collision
1041
    if (check_for_node(node_ct, "max_collisions")) {
160!
1042
      collision_track_config.max_collisions =
320✔
1043
        std::stoll(get_node_value(node_ct, "max_collisions"));
320✔
1044
    } else {
1045
      warning("A maximum number of collisions needs to be specified. "
×
1046
              "By default the code sets 'max_collisions' parameter equals to "
1047
              "1000.");
1048
    }
1049
    // Get maximum number of collision_track files to be created
1050
    if (check_for_node(node_ct, "max_collision_track_files")) {
160!
1051
      collision_track_config.max_files =
×
1052
        std::stoll(get_node_value(node_ct, "max_collision_track_files"));
×
1053
    }
1054
    if (check_for_node(node_ct, "mcpl")) {
160✔
1055
      collision_track_config.mcpl_write = get_node_value_bool(node_ct, "mcpl");
22✔
1056
    }
1057
  }
1058

1059
  // If source is not separate and is to be written out in the statepoint
1060
  // file, make sure that the sourcepoint batch numbers are contained in the
1061
  // statepoint list
1062
  if (!source_separate) {
9,343✔
1063
    for (const auto& b : sourcepoint_batch) {
18,640✔
1064
      if (!contains(statepoint_batch, b)) {
18,766!
1065
        fatal_error(
×
1066
          "Sourcepoint batches are not a subset of statepoint batches.");
1067
      }
1068
    }
1069
  }
1070

1071
  // Check if the user has specified to not reduce tallies at the end of every
1072
  // batch
1073
  if (check_for_node(root, "no_reduce")) {
9,343✔
1074
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
30✔
1075
  }
1076

1077
  // Check if the user has specified to use confidence intervals for
1078
  // uncertainties rather than standard deviations
1079
  if (check_for_node(root, "confidence_intervals")) {
9,343✔
1080
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
15✔
1081
  }
1082

1083
  // Check for output options
1084
  if (check_for_node(root, "output")) {
9,343✔
1085
    // Get pointer to output node
1086
    pugi::xml_node node_output = root.child("output");
845✔
1087

1088
    // Check for summary option
1089
    if (check_for_node(node_output, "summary")) {
845✔
1090
      output_summary = get_node_value_bool(node_output, "summary");
819✔
1091
    }
1092

1093
    // Check for ASCII tallies output option
1094
    if (check_for_node(node_output, "tallies")) {
845✔
1095
      output_tallies = get_node_value_bool(node_output, "tallies");
371✔
1096
    }
1097

1098
    // Set output directory if a path has been specified
1099
    if (check_for_node(node_output, "path")) {
845!
1100
      path_output = get_node_value(node_output, "path");
×
1101
      if (!ends_with(path_output, "/")) {
×
1102
        path_output += "/";
845!
1103
      }
1104
    }
1105
  }
1106

1107
  // Resonance scattering parameters
1108
  if (check_for_node(root, "resonance_scattering")) {
9,343✔
1109
    xml_node node_res_scat = root.child("resonance_scattering");
15✔
1110

1111
    // See if resonance scattering is enabled
1112
    if (check_for_node(node_res_scat, "enable")) {
15!
1113
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
15✔
1114
    } else {
1115
      res_scat_on = true;
×
1116
    }
1117

1118
    // Determine what method is used
1119
    if (check_for_node(node_res_scat, "method")) {
15!
1120
      auto temp = get_node_value(node_res_scat, "method", true, true);
15✔
1121
      if (temp == "rvs") {
15!
1122
        res_scat_method = ResScatMethod::rvs;
15✔
1123
      } else if (temp == "dbrc") {
×
1124
        res_scat_method = ResScatMethod::dbrc;
×
1125
      } else {
1126
        fatal_error(
×
1127
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1128
      }
1129
    }
15✔
1130

1131
    // Minimum energy for resonance scattering
1132
    if (check_for_node(node_res_scat, "energy_min")) {
15!
1133
      res_scat_energy_min =
30✔
1134
        std::stod(get_node_value(node_res_scat, "energy_min"));
30✔
1135
    }
1136
    if (res_scat_energy_min < 0.0) {
15!
1137
      fatal_error("Lower resonance scattering energy bound is negative");
×
1138
    }
1139

1140
    // Maximum energy for resonance scattering
1141
    if (check_for_node(node_res_scat, "energy_max")) {
15!
1142
      res_scat_energy_max =
30✔
1143
        std::stod(get_node_value(node_res_scat, "energy_max"));
30✔
1144
    }
1145
    if (res_scat_energy_max < res_scat_energy_min) {
15!
1146
      fatal_error("Upper resonance scattering energy bound is below the "
×
1147
                  "lower resonance scattering energy bound.");
1148
    }
1149

1150
    // Get resonance scattering nuclides
1151
    if (check_for_node(node_res_scat, "nuclides")) {
15!
1152
      res_scat_nuclides =
15✔
1153
        get_node_array<std::string>(node_res_scat, "nuclides");
30✔
1154
    }
1155
  }
1156

1157
  // Get volume calculations
1158
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
9,653✔
1159
    model::volume_calcs.emplace_back(node_vol);
310✔
1160
  }
1161

1162
  // Get temperature settings
1163
  if (check_for_node(root, "temperature_default")) {
9,343✔
1164
    temperature_default =
342✔
1165
      std::stod(get_node_value(root, "temperature_default"));
342✔
1166
  }
1167
  if (check_for_node(root, "temperature_method")) {
9,343✔
1168
    auto temp = get_node_value(root, "temperature_method", true, true);
485✔
1169
    if (temp == "nearest") {
485✔
1170
      temperature_method = TemperatureMethod::NEAREST;
304✔
1171
    } else if (temp == "interpolation") {
181!
1172
      temperature_method = TemperatureMethod::INTERPOLATION;
181✔
1173
    } else {
1174
      fatal_error("Unknown temperature method: " + temp);
×
1175
    }
1176
  }
485✔
1177
  if (check_for_node(root, "temperature_tolerance")) {
9,343✔
1178
    temperature_tolerance =
680✔
1179
      std::stod(get_node_value(root, "temperature_tolerance"));
680✔
1180
  }
1181
  if (check_for_node(root, "temperature_multipole")) {
9,343✔
1182
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
185✔
1183

1184
    // Multipole currently doesn't work with photon transport
1185
    if (temperature_multipole && photon_transport) {
185!
1186
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1187
                  "photon transport.");
1188
    }
1189
  }
1190
  if (check_for_node(root, "temperature_range")) {
9,343✔
1191
    auto range = get_node_array<double>(root, "temperature_range");
170✔
1192
    temperature_range[0] = range.at(0);
170✔
1193
    temperature_range[1] = range.at(1);
170✔
1194
  }
170✔
1195

1196
  // Check for tabular_legendre options
1197
  if (check_for_node(root, "tabular_legendre")) {
9,343✔
1198
    // Get pointer to tabular_legendre node
1199
    xml_node node_tab_leg = root.child("tabular_legendre");
105✔
1200

1201
    // Check for enable option
1202
    if (check_for_node(node_tab_leg, "enable")) {
105!
1203
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
105✔
1204
    }
1205

1206
    // Check for the number of points
1207
    if (check_for_node(node_tab_leg, "num_points")) {
105!
1208
      legendre_to_tabular_points =
×
1209
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
1210
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
1211
        fatal_error(
×
1212
          "The 'num_points' subelement/attribute of the "
1213
          "<tabular_legendre> element must contain a value greater than 1");
1214
      }
1215
    }
1216
  }
1217

1218
  // Check whether create delayed neutrons in fission
1219
  if (check_for_node(root, "create_delayed_neutrons")) {
9,343!
1220
    create_delayed_neutrons =
×
1221
      get_node_value_bool(root, "create_delayed_neutrons");
×
1222
  }
1223

1224
  // Check whether create fission sites
1225
  if (run_mode == RunMode::FIXED_SOURCE) {
9,343✔
1226
    if (check_for_node(root, "create_fission_neutrons")) {
3,418✔
1227
      create_fission_neutrons =
336✔
1228
        get_node_value_bool(root, "create_fission_neutrons");
336✔
1229
    }
1230
  }
1231

1232
  // Check whether to scale fission photon yields
1233
  if (check_for_node(root, "delayed_photon_scaling")) {
9,343!
1234
    delayed_photon_scaling =
×
1235
      get_node_value_bool(root, "delayed_photon_scaling");
×
1236
  }
1237

1238
  // Check whether to use event-based parallelism
1239
  if (check_for_node(root, "event_based")) {
9,343✔
1240
    event_based = get_node_value_bool(root, "event_based");
150✔
1241
  }
1242

1243
  // Check to see if we have a delta tracking node.
1244
  if (check_for_node(root, "delta_tracking")) {
9,343✔
1245
    xml_node delta_tracking_node = root.child("delta_tracking");
270✔
1246

1247
    // Check to see if we should enable delta tracking or not.
1248
    if (check_for_node(delta_tracking_node, "enable")) {
270!
1249
      delta_tracking = get_node_value_bool(delta_tracking_node, "enable");
270✔
1250
    }
1251

1252
    // If delta tracking is enabled...
1253
    if (delta_tracking) {
270!
1254
      // Parse the hybrid tracking type.
1255
      if (check_for_node(delta_tracking_node, "hybrid_type")) {
270!
1256
        auto hybrid_type =
270✔
1257
          get_node_value(delta_tracking_node, "hybrid_type", true, true);
270✔
1258
        if (hybrid_type == "cross_section") {
270✔
1259
          hybrid_delta_type = HybridTrackingType::CrossSection;
210✔
1260
        } else if (hybrid_type == "energy") {
60!
1261
          hybrid_delta_type = HybridTrackingType::Energy;
60✔
1262
        } else {
NEW
1263
          fatal_error("Unknown hybrid delta tracking method: " + hybrid_type);
×
1264
        }
1265
      }
270✔
1266

1267
      // If running the hybrid in-cross-section scheme, check for a threshold.
1268
      if (hybrid_delta_type == HybridTrackingType::CrossSection &&
480!
1269
          check_for_node(delta_tracking_node, "xs_threshold")) {
210✔
1270
        hybrid_xs_threshold =
420✔
1271
          std::stod(get_node_value(delta_tracking_node, "xs_threshold"));
420✔
1272

1273
        if (hybrid_xs_threshold < 0.0 || hybrid_xs_threshold > 1.0) {
210!
NEW
1274
          fatal_error(
×
NEW
1275
            "'xs_threshold' must be between 0 and 1 (inclusive). Value is: " +
×
NEW
1276
            std::to_string(hybrid_xs_threshold));
×
1277
        }
1278
      }
1279

1280
      // If running the hybrid in-energy scheme, check for photon/neutron energy
1281
      // thresholds.
1282
      constexpr int i_neutron = ParticleType::neutron().transport_index();
270✔
1283
      constexpr int i_photon = ParticleType::photon().transport_index();
270✔
1284
      if (hybrid_delta_type == HybridTrackingType::Energy) {
270✔
1285
        if (check_for_node(delta_tracking_node, "neutron_energy_threshold")) {
60!
1286
          hybrid_energy_threshold[i_neutron] = std::stod(
60✔
1287
            get_node_value(delta_tracking_node, "neutron_energy_threshold"));
60✔
1288

1289
          if (hybrid_energy_threshold[i_neutron] <= 0.0) {
60!
NEW
1290
            fatal_error(
×
NEW
1291
              "'neutron_energy_threshold' must be greater than 0. Value is: " +
×
NEW
1292
              std::to_string(hybrid_energy_threshold[i_neutron]));
×
1293
          }
1294
        }
1295

1296
        if (check_for_node(delta_tracking_node, "photon_energy_threshold")) {
60!
1297
          hybrid_energy_threshold[i_photon] = std::stod(
60✔
1298
            get_node_value(delta_tracking_node, "photon_energy_threshold"));
60✔
1299

1300
          if (hybrid_energy_threshold[i_photon] <= 0.0) {
60!
NEW
1301
            fatal_error(
×
NEW
1302
              "'photon_energy_threshold' must be greater than 0. Value is: " +
×
NEW
1303
              std::to_string(hybrid_energy_threshold[i_photon]));
×
1304
          }
1305
        }
1306
      }
1307

1308
      if (temperature_multipole && delta_tracking) {
270!
NEW
1309
        fatal_error(
×
1310
          "At present, delta tracking cannot be used with a windowed multipole "
1311
          "temperature treatment.");
1312
      }
1313

1314
      if (!run_CE && delta_tracking) {
270!
NEW
1315
        fatal_error("At present, delta tracking can only be used in continuous "
×
1316
                    "energy simulations.");
1317
      }
1318
    }
1319
  }
1320

1321
  // Check whether material cell offsets should be generated
1322
  if (check_for_node(root, "material_cell_offsets")) {
9,343!
1323
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1324
  }
1325

1326
  // Weight window information
1327
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
9,659✔
1328
    variance_reduction::weight_windows.emplace_back(
316✔
1329
      std::make_unique<WeightWindows>(node_ww));
632✔
1330
  }
1331

1332
  // Enable weight windows by default if one or more are present
1333
  if (variance_reduction::weight_windows.size() > 0)
9,343✔
1334
    settings::weight_windows_on = true;
220✔
1335

1336
  // read weight windows from file
1337
  if (check_for_node(root, "weight_windows_file")) {
9,343✔
1338
    weight_windows_file = get_node_value(root, "weight_windows_file");
26✔
1339
    weight_windows_on = true;
26✔
1340
  }
1341

1342
  // read settings for weight windows value, this will override
1343
  // the automatic setting even if weight windows are present
1344
  if (check_for_node(root, "weight_windows_on")) {
9,343✔
1345
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
93✔
1346
  }
1347

1348
  if (check_for_node(root, "max_secondaries")) {
9,343!
1349
    settings::max_secondaries =
×
1350
      std::stoi(get_node_value(root, "max_secondaries"));
×
1351
  }
1352

1353
  if (check_for_node(root, "max_history_splits")) {
9,343✔
1354
    settings::max_history_splits =
798✔
1355
      std::stoi(get_node_value(root, "max_history_splits"));
798✔
1356
  }
1357

1358
  if (check_for_node(root, "max_tracks")) {
9,343✔
1359
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
90✔
1360
  }
1361

1362
  // Create weight window generator objects
1363
  if (check_for_node(root, "weight_window_generators")) {
9,343✔
1364
    auto wwgs_node = root.child("weight_window_generators");
127✔
1365
    for (pugi::xml_node node_wwg :
254✔
1366
      wwgs_node.children("weight_windows_generator")) {
254✔
1367
      variance_reduction::weight_windows_generators.emplace_back(
127✔
1368
        std::make_unique<WeightWindowsGenerator>(node_wwg));
254✔
1369
    }
1370
    // if any of the weight windows are intended to be generated otf, make
1371
    // sure they're applied
1372
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
127!
1373
      if (wwg->on_the_fly_) {
127!
1374
        settings::weight_windows_on = true;
127✔
1375
        break;
127✔
1376
      }
1377
    }
1378
    // If any weight window generators have local FW-CADIS target tallies,
1379
    // user-defined adjoint sources cannot be used at the same time.
1380
    if (!model::adjoint_sources.empty()) {
127!
1381
      for (const auto& wwg : variance_reduction::weight_windows_generators) {
×
1382
        if (!wwg->targets_.empty()) {
×
1383
          fatal_error("Cannot use both user-defined adjoint sources and "
×
1384
                      "FW-CADIS target tallies at the same time.");
1385
        }
1386
      }
1387
    }
1388
  }
1389

1390
  // Set up weight window checkpoints
1391
  if (check_for_node(root, "weight_window_checkpoints")) {
9,343✔
1392
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
184✔
1393
    if (check_for_node(ww_checkpoints, "collision")) {
184!
1394
      weight_window_checkpoint_collision =
184✔
1395
        get_node_value_bool(ww_checkpoints, "collision");
184✔
1396
    }
1397
    if (check_for_node(ww_checkpoints, "surface")) {
184!
1398
      weight_window_checkpoint_surface =
184✔
1399
        get_node_value_bool(ww_checkpoints, "surface");
184✔
1400
    }
1401
  }
1402

1403
  if (weight_windows_on) {
9,343✔
1404
    if (!weight_window_checkpoint_surface &&
362✔
1405
        !weight_window_checkpoint_collision)
189!
1406
      fatal_error(
×
1407
        "Weight Windows are enabled but there are no valid checkpoints.");
1408
  }
1409

1410
  if (check_for_node(root, "use_decay_photons")) {
9,343✔
1411
    settings::use_decay_photons =
11✔
1412
      get_node_value_bool(root, "use_decay_photons");
11✔
1413
  }
1414

1415
  // If weight windows are on, also enable shared secondary bank (unless
1416
  // explicitly disabled by user).
1417
  if (check_for_node(root, "shared_secondary_bank")) {
9,343✔
1418
    bool val = get_node_value_bool(root, "shared_secondary_bank");
335✔
1419
    if (val && run_mode == RunMode::EIGENVALUE) {
335!
1420
      warning(
×
1421
        "Shared secondary bank is not supported in eigenvalue calculations. "
1422
        "Setting will be ignored.");
1423
    } else {
1424
      settings::use_shared_secondary_bank = val;
335✔
1425
    }
1426
  } else if (settings::weight_windows_on) {
9,008✔
1427
    if (run_mode == RunMode::EIGENVALUE) {
180✔
1428
      warning(
22✔
1429
        "Shared secondary bank is not supported in eigenvalue calculations. "
1430
        "Particle local secondary banks will be used instead.");
1431
    } else if (run_mode == RunMode::FIXED_SOURCE) {
169!
1432
      settings::use_shared_secondary_bank = true;
169✔
1433
    }
1434
  }
1435
}
9,343✔
1436

1437
void free_memory_settings()
9,494✔
1438
{
1439
  settings::statepoint_batch.clear();
9,494✔
1440
  settings::sourcepoint_batch.clear();
9,494✔
1441
  settings::source_write_surf_id.clear();
9,494✔
1442
  settings::res_scat_nuclides.clear();
9,494✔
1443
}
9,494✔
1444

1445
//==============================================================================
1446
// C API functions
1447
//==============================================================================
1448

1449
extern "C" int openmc_set_n_batches(
220✔
1450
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1451
{
1452
  if (settings::n_inactive >= n_batches) {
220✔
1453
    set_errmsg("Number of active batches must be greater than zero.");
11✔
1454
    return OPENMC_E_INVALID_ARGUMENT;
11✔
1455
  }
1456

1457
  if (!settings::trigger_on) {
209✔
1458
    // Set n_batches and n_max_batches to same value
1459
    settings::n_batches = n_batches;
187✔
1460
    settings::n_max_batches = n_batches;
187✔
1461
  } else {
1462
    // Set n_batches and n_max_batches based on value of set_max_batches
1463
    if (set_max_batches) {
22✔
1464
      settings::n_max_batches = n_batches;
11✔
1465
    } else {
1466
      settings::n_batches = n_batches;
11✔
1467
    }
1468
  }
1469

1470
  // Update size of k_generation and entropy
1471
  int m = settings::n_max_batches * settings::gen_per_batch;
209✔
1472
  simulation::k_generation.reserve(m);
209✔
1473
  simulation::entropy.reserve(m);
209✔
1474

1475
  // Add value of n_batches to statepoint_batch
1476
  if (add_statepoint_batch &&
209✔
1477
      !(contains(settings::statepoint_batch, n_batches)))
198✔
1478
    settings::statepoint_batch.insert(n_batches);
33✔
1479

1480
  return 0;
1481
}
1482

1483
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,530✔
1484
{
1485
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,530✔
1486

1487
  return 0;
2,530✔
1488
}
1489

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

© 2026 Coveralls, Inc