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

openmc-dev / openmc / 25930573650

15 May 2026 05:01PM UTC coverage: 81.375% (+0.05%) from 81.326%
25930573650

Pull #3863

github

web-flow
Merge 95bd57fc1 into d56cda254
Pull Request #3863: Shared Secondary Particle Bank

17950 of 25871 branches covered (69.38%)

Branch coverage included in aggregate %.

407 of 417 new or added lines in 17 files covered. (97.6%)

1464 existing lines in 34 files now uncovered.

59095 of 68808 relevant lines covered (85.88%)

48517262.56 hits per line

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

76.4
/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 use_shared_secondary_bank {false};
87
bool weight_windows_on {false};
88
bool weight_window_checkpoint_surface {false};
89
bool weight_window_checkpoint_collision {true};
90
bool write_all_tracks {false};
91
bool write_initial_source {false};
92

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

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

110
int64_t max_particles_in_flight {100000};
111
int max_particle_events {1000000};
112

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

157
} // namespace settings
158

159
//==============================================================================
160
// Functions
161
//==============================================================================
162

163
void get_run_parameters(pugi::xml_node node_base)
7,737✔
164
{
165
  using namespace settings;
7,737✔
166
  using namespace pugi;
7,737✔
167

168
  // Check number of particles
169
  if (!check_for_node(node_base, "particles")) {
7,737!
170
    fatal_error("Need to specify number of particles.");
×
171
  }
172

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

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

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

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

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

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

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

215
  // Get number of inactive batches
216
  if (run_mode == RunMode::EIGENVALUE ||
7,737✔
217
      solver_type == SolverType::RANDOM_RAY) {
3,123✔
218
    if (check_for_node(node_base, "inactive")) {
5,050✔
219
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,828✔
220
    }
221
    if (check_for_node(node_base, "generations_per_batch")) {
5,050✔
222
      gen_per_batch =
30✔
223
        std::stoi(get_node_value(node_base, "generations_per_batch"));
15✔
224
    }
225

226
    // Preallocate space for keff and entropy by generation
227
    int m = settings::n_max_batches * settings::gen_per_batch;
5,050✔
228
    simulation::k_generation.reserve(m);
5,050✔
229
    simulation::entropy.reserve(m);
5,050✔
230

231
    // Get the trigger information for keff
232
    if (check_for_node(node_base, "keff_trigger")) {
5,050✔
233
      xml_node node_keff_trigger = node_base.child("keff_trigger");
101✔
234

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

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

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

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

403
  // Parse settings.xml file
404
  xml_document doc;
1,390✔
405
  auto result = doc.load_file(filename.c_str());
1,390✔
406
  if (!result) {
1,390!
UNCOV
407
    fatal_error("Error processing settings.xml file.");
×
408
  }
409

410
  // Get root element
411
  xml_node root = doc.document_element();
1,390✔
412

413
  // Verbosity
414
  if (check_for_node(root, "verbosity") && verbosity == -1) {
1,390!
415
    verbosity = std::stoi(get_node_value(root, "verbosity"));
428✔
416
  } else if (verbosity == -1) {
1,176!
417
    verbosity = 7;
1,176✔
418
  }
419

420
  // To this point, we haven't displayed any output since we didn't know what
421
  // the verbosity is. Now that we checked for it, show the title if necessary
422
  if (mpi::master) {
1,390✔
423
    if (verbosity >= 2)
1,202✔
424
      title();
996✔
425
  }
426

427
  write_message("Reading settings XML file...", 5);
1,390✔
428

429
  read_settings_xml(root);
1,390✔
430
}
1,402✔
431

432
void read_settings_xml(pugi::xml_node root)
8,567✔
433
{
434
  using namespace settings;
8,567✔
435
  using namespace pugi;
8,567✔
436

437
  // Find if a multi-group or continuous-energy simulation is desired
438
  if (check_for_node(root, "energy_mode")) {
8,567✔
439
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
1,342✔
440
    if (temp_str == "mg" || temp_str == "multi-group") {
2,684!
441
      run_CE = false;
1,342✔
UNCOV
442
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
UNCOV
443
      run_CE = true;
×
444
    }
445
  }
1,342✔
446

447
  // Check for user meshes and allocate
448
  read_meshes(root);
8,567✔
449

450
  // Look for deprecated cross_sections.xml file in settings.xml
451
  if (check_for_node(root, "cross_sections")) {
8,567!
UNCOV
452
    warning(
×
453
      "Setting cross_sections in settings.xml has been deprecated."
454
      " The cross_sections are now set in materials.xml and the "
455
      "cross_sections input to materials.xml and the OPENMC_CROSS_SECTIONS"
456
      " environment variable will take precendent over setting "
457
      "cross_sections in settings.xml.");
UNCOV
458
    path_cross_sections = get_node_value(root, "cross_sections");
×
459
  }
460

461
  if (!run_CE) {
8,567✔
462
    // Scattering Treatments
463
    if (check_for_node(root, "max_order")) {
1,342✔
464
      max_order = std::stoi(get_node_value(root, "max_order"));
30✔
465
    } else {
466
      // Set to default of largest int - 1, which means to use whatever is
467
      // contained in library. This is largest int - 1 because for legendre
468
      // scattering, a value of 1 is added to the order; adding 1 to the largest
469
      // int gets you the largest negative integer, which is not what we want.
470
      max_order = std::numeric_limits<int>::max() - 1;
1,327✔
471
    }
472
  }
473

474
  // Check for a trigger node and get trigger information
475
  if (check_for_node(root, "trigger")) {
8,567✔
476
    xml_node node_trigger = root.child("trigger");
156✔
477

478
    // Check if trigger(s) are to be turned on
479
    trigger_on = get_node_value_bool(node_trigger, "active");
156✔
480

481
    if (trigger_on) {
156✔
482
      if (check_for_node(node_trigger, "max_batches")) {
141!
483
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
282✔
484
      } else {
UNCOV
485
        fatal_error("<max_batches> must be specified with triggers");
×
486
      }
487

488
      // Get the batch interval to check triggers
489
      if (!check_for_node(node_trigger, "batch_interval")) {
141✔
490
        trigger_predict = true;
15✔
491
      } else {
492
        trigger_batch_interval =
252✔
493
          std::stoi(get_node_value(node_trigger, "batch_interval"));
252✔
494
        if (trigger_batch_interval <= 0) {
126!
UNCOV
495
          fatal_error("Trigger batch interval must be greater than zero");
×
496
        }
497
      }
498
    }
499
  }
500

501
  // Check run mode if it hasn't been set from the command line
502
  xml_node node_mode;
8,567✔
503
  if (run_mode == RunMode::UNSET) {
8,567✔
504
    if (check_for_node(root, "run_mode")) {
7,769✔
505
      std::string temp_str = get_node_value(root, "run_mode", true, true);
7,739✔
506
      if (temp_str == "eigenvalue") {
7,739✔
507
        run_mode = RunMode::EIGENVALUE;
4,584✔
508
      } else if (temp_str == "fixed source") {
3,155✔
509
        run_mode = RunMode::FIXED_SOURCE;
3,123✔
510
      } else if (temp_str == "plot") {
32!
UNCOV
511
        run_mode = RunMode::PLOTTING;
×
512
      } else if (temp_str == "particle restart") {
32!
UNCOV
513
        run_mode = RunMode::PARTICLE;
×
514
      } else if (temp_str == "volume") {
32!
515
        run_mode = RunMode::VOLUME;
32✔
516
      } else {
UNCOV
517
        fatal_error("Unrecognized run mode: " + temp_str);
×
518
      }
519

520
      // Assume XML specifies <particles>, <batches>, etc. directly
521
      node_mode = root;
7,739✔
522
    } else {
7,739✔
523
      warning("<run_mode> should be specified.");
30✔
524

525
      // Make sure that either eigenvalue or fixed source was specified
526
      node_mode = root.child("eigenvalue");
30✔
527
      if (node_mode) {
30!
528
        run_mode = RunMode::EIGENVALUE;
30✔
529
      } else {
UNCOV
530
        node_mode = root.child("fixed_source");
×
UNCOV
531
        if (node_mode) {
×
UNCOV
532
          run_mode = RunMode::FIXED_SOURCE;
×
533
        } else {
UNCOV
534
          fatal_error("<eigenvalue> or <fixed_source> not specified.");
×
535
        }
536
      }
537
    }
538
  }
539

540
  // Check solver type
541
  if (check_for_node(root, "random_ray")) {
8,567✔
542
    solver_type = SolverType::RANDOM_RAY;
792✔
543
    if (run_CE)
792!
UNCOV
544
      fatal_error("multi-group energy mode must be specified in settings XML "
×
545
                  "when using the random ray solver.");
546
  }
547

548
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
8,567✔
549
    // Read run parameters
550
    get_run_parameters(node_mode);
7,737✔
551

552
    // Check number of active batches, inactive batches, max lost particles and
553
    // particles
554
    if (n_batches <= n_inactive) {
7,737!
555
      fatal_error("Number of active batches must be greater than zero.");
×
556
    } else if (n_inactive < 0) {
7,737!
UNCOV
557
      fatal_error("Number of inactive batches must be non-negative.");
×
558
    } else if (n_particles <= 0) {
7,737!
UNCOV
559
      fatal_error("Number of particles must be greater than zero.");
×
560
    } else if (max_lost_particles <= 0) {
7,737!
UNCOV
561
      fatal_error("Number of max lost particles must be greater than zero.");
×
562
    } else if (rel_max_lost_particles <= 0.0 || rel_max_lost_particles >= 1.0) {
7,737!
563
      fatal_error("Relative max lost particles must be between zero and one.");
×
564
    }
565

566
    // Check for user value for the number of generation of the Iterated Fission
567
    // Probability (IFP) method
568
    if (check_for_node(root, "ifp_n_generation")) {
7,737✔
569
      ifp_n_generation = std::stoi(get_node_value(root, "ifp_n_generation"));
166✔
570
      if (ifp_n_generation <= 0) {
83!
UNCOV
571
        fatal_error("'ifp_n_generation' must be greater than 0.");
×
572
      }
573
      // Avoid tallying 0 if IFP logs are not complete when active cycles start
574
      if (ifp_n_generation > n_inactive) {
83✔
575
        fatal_error("'ifp_n_generation' must be lower than or equal to the "
9✔
576
                    "number of inactive cycles.");
577
      }
578
    }
579
  }
580

581
  // Copy plotting random number seed if specified
582
  if (check_for_node(root, "plot_seed")) {
8,558!
UNCOV
583
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
UNCOV
584
    model::plotter_seed = seed;
×
585
  }
586

587
  // Copy random number seed if specified
588
  if (check_for_node(root, "seed")) {
8,558✔
589
    auto seed = std::stoll(get_node_value(root, "seed"));
1,154✔
590
    openmc_set_seed(seed);
577✔
591
  }
592

593
  // Copy random number stride if specified
594
  if (check_for_node(root, "stride")) {
8,558✔
595
    auto stride = std::stoull(get_node_value(root, "stride"));
30✔
596
    openmc_set_stride(stride);
15✔
597
  }
598

599
  // Check for electron treatment
600
  if (check_for_node(root, "electron_treatment")) {
8,558✔
601
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
82✔
602
    if (temp_str == "led") {
82✔
603
      electron_treatment = ElectronTreatment::LED;
26✔
604
    } else if (temp_str == "ttb") {
56!
605
      electron_treatment = ElectronTreatment::TTB;
56✔
606
    } else {
UNCOV
607
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
608
    }
609
  }
82✔
610

611
  // Check for photon transport
612
  if (check_for_node(root, "photon_transport")) {
8,558✔
613
    photon_transport = get_node_value_bool(root, "photon_transport");
331✔
614

615
    if (!run_CE && photon_transport) {
331!
UNCOV
616
      fatal_error("Photon transport is not currently supported in "
×
617
                  "multigroup mode");
618
    }
619
  }
620

621
  // Check for atomic relaxation
622
  if (check_for_node(root, "atomic_relaxation")) {
8,558✔
623
    atomic_relaxation = get_node_value_bool(root, "atomic_relaxation");
15✔
624
  }
625

626
  // Number of bins for logarithmic grid
627
  if (check_for_node(root, "log_grid_bins")) {
8,558✔
628
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
30✔
629
    if (n_log_bins < 1) {
15!
630
      fatal_error("Number of bins for logarithmic grid must be greater "
×
631
                  "than zero.");
632
    }
633
  }
634

635
  // Number of OpenMP threads
636
  if (check_for_node(root, "threads")) {
8,558!
UNCOV
637
    if (mpi::master)
×
UNCOV
638
      warning("The <threads> element has been deprecated. Use "
×
639
              "the OMP_NUM_THREADS environment variable to set the number of "
640
              "threads.");
641
  }
642

643
  // ==========================================================================
644
  // EXTERNAL SOURCE
645

646
  // Get point to list of <source> elements and make sure there is at least one
647
  for (pugi::xml_node node : root.children("source")) {
16,539✔
648
    model::external_sources.push_back(Source::create(node));
15,972✔
649
  }
650

651
  // Check if the user has specified to read surface source
652
  if (check_for_node(root, "surf_source_read")) {
8,548✔
653
    surf_source_read = true;
30✔
654
    // Get surface source read node
655
    xml_node node_ssr = root.child("surf_source_read");
30✔
656

657
    std::string path = "surface_source.h5";
30✔
658
    // Check if the user has specified different file for surface source reading
659
    if (check_for_node(node_ssr, "path")) {
30!
660
      path = get_node_value(node_ssr, "path", false, true);
30✔
661
    }
662
    model::external_sources.push_back(make_unique<FileSource>(path));
30✔
663
  }
30✔
664

665
  // If no source specified, default to isotropic point source at origin with
666
  // Watt spectrum. No default source is needed in random ray mode.
667
  if (model::external_sources.empty() &&
8,548✔
668
      settings::solver_type != SolverType::RANDOM_RAY) {
2,260✔
669
    double T[] {0.0};
2,114✔
670
    double p[] {1.0};
2,114✔
671
    model::external_sources.push_back(make_unique<IndependentSource>(
2,114✔
672
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
4,228✔
673
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
4,228✔
674
      UPtrDist {new Discrete(T, p, 1)}));
4,228✔
675
  }
676

677
  // Build probability mass function for sampling external sources
678
  vector<double> source_strengths;
8,548✔
679
  for (auto& s : model::external_sources) {
18,673✔
680
    source_strengths.push_back(s->strength());
10,125✔
681
  }
682
  model::external_sources_probability.assign(source_strengths);
8,548✔
683

684
  // Check if we want to write out source
685
  if (check_for_node(root, "write_initial_source")) {
8,548!
UNCOV
686
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
687
  }
688

689
  // Get relative number of lost particles
690
  if (check_for_node(root, "source_rejection_fraction")) {
8,548✔
691
    source_rejection_fraction =
14✔
692
      std::stod(get_node_value(root, "source_rejection_fraction"));
14!
693
  }
694

695
  if (check_for_node(root, "free_gas_threshold")) {
8,548!
696
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
697
  }
698

699
  // Surface grazing
700
  if (check_for_node(root, "surface_grazing_cutoff"))
8,548!
UNCOV
701
    surface_grazing_cutoff =
×
UNCOV
702
      std::stod(get_node_value(root, "surface_grazing_cutoff"));
×
703
  if (check_for_node(root, "surface_grazing_ratio"))
8,548!
UNCOV
704
    surface_grazing_ratio =
×
UNCOV
705
      std::stod(get_node_value(root, "surface_grazing_ratio"));
×
706

707
  // Survival biasing
708
  if (check_for_node(root, "survival_biasing")) {
8,548✔
709
    survival_biasing = get_node_value_bool(root, "survival_biasing");
205✔
710
  }
711

712
  // Probability tables
713
  if (check_for_node(root, "ptables")) {
8,548✔
714
    urr_ptables_on = get_node_value_bool(root, "ptables");
15✔
715
  }
716

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

764
  // read properties from file
765
  if (check_for_node(root, "properties_file")) {
8,548✔
766
    properties_file = get_node_value(root, "properties_file");
11✔
767
    if (!file_exists(properties_file)) {
11!
768
      fatal_error(fmt::format("File '{}' does not exist.", properties_file));
×
769
    }
770
  }
771

772
  // Particle trace
773
  if (check_for_node(root, "trace")) {
8,548✔
774
    auto temp = get_node_array<int64_t>(root, "trace");
15✔
775
    if (temp.size() != 3) {
15!
UNCOV
776
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
777
                  "batch, generation, and particle number.");
778
    }
779
    trace_batch = temp.at(0);
15✔
780
    trace_gen = temp.at(1);
15✔
781
    trace_particle = temp.at(2);
15✔
782
  }
15✔
783

784
  // Particle tracks
785
  if (check_for_node(root, "track")) {
8,548✔
786
    // Get values and make sure there are three per particle
787
    auto temp = get_node_array<int>(root, "track");
45✔
788
    if (temp.size() % 3 != 0) {
45!
UNCOV
789
      fatal_error(
×
790
        "Number of integers specified in 'track' is not "
791
        "divisible by 3.  Please provide 3 integers per particle to be "
792
        "tracked.");
793
    }
794

795
    // Reshape into track_identifiers
796
    int n_tracks = temp.size() / 3;
45✔
797
    for (int i = 0; i < n_tracks; ++i) {
180✔
798
      track_identifiers.push_back(
135✔
799
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
135✔
800
    }
801
  }
45✔
802

803
  // Shannon entropy
804
  if (solver_type == SolverType::RANDOM_RAY) {
8,548✔
805
    if (check_for_node(root, "entropy_mesh")) {
792!
806
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
807
                  "No user-defined entropy mesh is supported.");
808
    }
809
    entropy_on = true;
792✔
810
  } else if (solver_type == SolverType::MONTE_CARLO) {
7,756!
811
    if (check_for_node(root, "entropy_mesh")) {
7,756✔
812
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
668✔
813
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
334!
UNCOV
814
        fatal_error(fmt::format(
×
815
          "Mesh {} specified for Shannon entropy does not exist.", temp));
816
      }
817

818
      auto* m = dynamic_cast<RegularMesh*>(
334!
819
        model::meshes[model::mesh_map.at(temp)].get());
334!
820
      if (!m)
334!
UNCOV
821
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
822
      simulation::entropy_mesh = m;
334✔
823

824
      // Turn on Shannon entropy calculation
825
      entropy_on = true;
334✔
826

827
    } else if (check_for_node(root, "entropy")) {
7,422!
UNCOV
828
      fatal_error(
×
829
        "Specifying a Shannon entropy mesh via the <entropy> element "
830
        "is deprecated. Please create a mesh using <mesh> and then reference "
831
        "it by specifying its ID in an <entropy_mesh> element.");
832
    }
833
  }
834
  // Uniform fission source weighting mesh
835
  if (check_for_node(root, "ufs_mesh")) {
8,548✔
836
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
30✔
837
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
15!
838
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
839
                              "method does not exist.",
840
        temp));
841
    }
842

843
    auto* m =
15✔
844
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
15!
845
    if (!m)
15!
UNCOV
846
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
847
    simulation::ufs_mesh = m;
15✔
848

849
    // Turn on uniform fission source weighting
850
    ufs_on = true;
15✔
851

852
  } else if (check_for_node(root, "uniform_fs")) {
8,533!
UNCOV
853
    fatal_error(
×
854
      "Specifying a UFS mesh via the <uniform_fs> element "
855
      "is deprecated. Please create a mesh using <mesh> and then reference "
856
      "it by specifying its ID in a <ufs_mesh> element.");
857
  }
858

859
  // Check if the user has specified to write state points
860
  if (check_for_node(root, "state_point")) {
8,548✔
861

862
    // Get pointer to state_point node
863
    auto node_sp = root.child("state_point");
160✔
864

865
    // Determine number of batches at which to store state points
866
    if (check_for_node(node_sp, "batches")) {
160!
867
      // User gave specific batches to write state points
868
      auto temp = get_node_array<int>(node_sp, "batches");
160✔
869
      for (const auto& b : temp) {
491✔
870
        statepoint_batch.insert(b);
331✔
871
      }
872
    } else {
160✔
873
      // If neither were specified, write state point at last batch
UNCOV
874
      statepoint_batch.insert(n_batches);
×
875
    }
876
  } else {
877
    // If no <state_point> tag was present, by default write state point at
878
    // last batch only
879
    statepoint_batch.insert(n_batches);
8,388✔
880
  }
881

882
  // Check if the user has specified to write source points
883
  if (check_for_node(root, "source_point")) {
8,548✔
884
    // Get source_point node
885
    xml_node node_sp = root.child("source_point");
101✔
886

887
    // Determine batches at which to store source points
888
    if (check_for_node(node_sp, "batches")) {
101✔
889
      // User gave specific batches to write source points
890
      auto temp = get_node_array<int>(node_sp, "batches");
45✔
891
      for (const auto& b : temp) {
120✔
892
        sourcepoint_batch.insert(b);
75✔
893
      }
894
    } else {
45✔
895
      // If neither were specified, write source points with state points
896
      sourcepoint_batch = statepoint_batch;
56!
897
    }
898

899
    // Check if the user has specified to write binary source file
900
    if (check_for_node(node_sp, "separate")) {
101✔
901
      source_separate = get_node_value_bool(node_sp, "separate");
71✔
902
    }
903
    if (check_for_node(node_sp, "write")) {
101!
UNCOV
904
      source_write = get_node_value_bool(node_sp, "write");
×
905
    }
906
    if (check_for_node(node_sp, "mcpl")) {
101✔
907
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
26✔
908
    }
909
    if (check_for_node(node_sp, "overwrite_latest")) {
101✔
910
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
15✔
911
      source_separate = source_latest;
15✔
912
    }
913
  } else {
914
    // If no <source_point> tag was present, by default we keep source bank in
915
    // statepoint file and write it out at statepoints intervals
916
    source_separate = false;
8,447✔
917
    sourcepoint_batch = statepoint_batch;
8,447!
918
  }
919

920
  // Check is the user specified to convert strength to statistical weight
921
  if (check_for_node(root, "uniform_source_sampling")) {
8,548✔
922
    uniform_source_sampling =
55✔
923
      get_node_value_bool(root, "uniform_source_sampling");
55✔
924
  }
925

926
  // Check if the user has specified to write surface source
927
  if (check_for_node(root, "surf_source_write")) {
8,548✔
928
    surf_source_write = true;
412✔
929
    // Get surface source write node
930
    xml_node node_ssw = root.child("surf_source_write");
412✔
931

932
    // Determine surface ids at which crossing particles are to be banked.
933
    // If no surfaces are specified, all surfaces in the model will be used
934
    // to bank source points.
935
    if (check_for_node(node_ssw, "surface_ids")) {
412✔
936
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
202✔
937
      for (const auto& b : temp) {
994✔
938
        source_write_surf_id.insert(b);
792✔
939
      }
940
    }
202✔
941

942
    // Get maximum number of particles to be banked per surface
943
    if (check_for_node(node_ssw, "max_particles")) {
412✔
944
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
806✔
945
    } else {
946
      fatal_error("A maximum number of particles needs to be specified "
9✔
947
                  "using the 'max_particles' parameter to store surface "
948
                  "source points.");
949
    }
950

951
    // Get maximum number of surface source files to be created
952
    if (check_for_node(node_ssw, "max_source_files")) {
403✔
953
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
66✔
954
    } else {
955
      ssw_max_files = 1;
370✔
956
    }
957

958
    if (check_for_node(node_ssw, "mcpl")) {
403✔
959
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
11✔
960
    }
961
    // Get cell information
962
    if (check_for_node(node_ssw, "cell")) {
403✔
963
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
208✔
964
      ssw_cell_type = SSWCellType::Both;
104✔
965
    }
966
    if (check_for_node(node_ssw, "cellfrom")) {
403✔
967
      if (ssw_cell_id != C_NONE) {
90✔
968
        fatal_error(
18✔
969
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
970
      }
971
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
144✔
972
      ssw_cell_type = SSWCellType::From;
72✔
973
    }
974
    if (check_for_node(node_ssw, "cellto")) {
385✔
975
      if (ssw_cell_id != C_NONE) {
71✔
976
        fatal_error(
18✔
977
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
978
      }
979
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
106✔
980
      ssw_cell_type = SSWCellType::To;
53✔
981
    }
982
  }
983

984
  // Check if the user has specified to write specific collisions
985
  if (check_for_node(root, "collision_track")) {
8,503✔
986
    settings::collision_track = true;
148✔
987
    // Get collision track node
988
    xml_node node_ct = root.child("collision_track");
148✔
989
    collision_track_config = CollisionTrackConfig {};
148✔
990

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

1048
  // If source is not separate and is to be written out in the statepoint
1049
  // file, make sure that the sourcepoint batch numbers are contained in the
1050
  // statepoint list
1051
  if (!source_separate) {
8,503✔
1052
    for (const auto& b : sourcepoint_batch) {
16,960✔
1053
      if (!contains(statepoint_batch, b)) {
17,086!
UNCOV
1054
        fatal_error(
×
1055
          "Sourcepoint batches are not a subset of statepoint batches.");
1056
      }
1057
    }
1058
  }
1059

1060
  // Check if the user has specified to not reduce tallies at the end of every
1061
  // batch
1062
  if (check_for_node(root, "no_reduce")) {
8,503✔
1063
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
30✔
1064
  }
1065

1066
  // Check if the user has specified to use confidence intervals for
1067
  // uncertainties rather than standard deviations
1068
  if (check_for_node(root, "confidence_intervals")) {
8,503✔
1069
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
15✔
1070
  }
1071

1072
  // Check for output options
1073
  if (check_for_node(root, "output")) {
8,503✔
1074
    // Get pointer to output node
1075
    pugi::xml_node node_output = root.child("output");
790✔
1076

1077
    // Check for summary option
1078
    if (check_for_node(node_output, "summary")) {
790✔
1079
      output_summary = get_node_value_bool(node_output, "summary");
764✔
1080
    }
1081

1082
    // Check for ASCII tallies output option
1083
    if (check_for_node(node_output, "tallies")) {
790✔
1084
      output_tallies = get_node_value_bool(node_output, "tallies");
349✔
1085
    }
1086

1087
    // Set output directory if a path has been specified
1088
    if (check_for_node(node_output, "path")) {
790!
UNCOV
1089
      path_output = get_node_value(node_output, "path");
×
UNCOV
1090
      if (!ends_with(path_output, "/")) {
×
1091
        path_output += "/";
790!
1092
      }
1093
    }
1094
  }
1095

1096
  // Resonance scattering parameters
1097
  if (check_for_node(root, "resonance_scattering")) {
8,503✔
1098
    xml_node node_res_scat = root.child("resonance_scattering");
15✔
1099

1100
    // See if resonance scattering is enabled
1101
    if (check_for_node(node_res_scat, "enable")) {
15!
1102
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
15✔
1103
    } else {
1104
      res_scat_on = true;
×
1105
    }
1106

1107
    // Determine what method is used
1108
    if (check_for_node(node_res_scat, "method")) {
15!
1109
      auto temp = get_node_value(node_res_scat, "method", true, true);
15✔
1110
      if (temp == "rvs") {
15!
1111
        res_scat_method = ResScatMethod::rvs;
15✔
UNCOV
1112
      } else if (temp == "dbrc") {
×
UNCOV
1113
        res_scat_method = ResScatMethod::dbrc;
×
1114
      } else {
UNCOV
1115
        fatal_error(
×
UNCOV
1116
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1117
      }
1118
    }
15✔
1119

1120
    // Minimum energy for resonance scattering
1121
    if (check_for_node(node_res_scat, "energy_min")) {
15!
1122
      res_scat_energy_min =
30✔
1123
        std::stod(get_node_value(node_res_scat, "energy_min"));
30✔
1124
    }
1125
    if (res_scat_energy_min < 0.0) {
15!
UNCOV
1126
      fatal_error("Lower resonance scattering energy bound is negative");
×
1127
    }
1128

1129
    // Maximum energy for resonance scattering
1130
    if (check_for_node(node_res_scat, "energy_max")) {
15!
1131
      res_scat_energy_max =
30✔
1132
        std::stod(get_node_value(node_res_scat, "energy_max"));
30✔
1133
    }
1134
    if (res_scat_energy_max < res_scat_energy_min) {
15!
UNCOV
1135
      fatal_error("Upper resonance scattering energy bound is below the "
×
1136
                  "lower resonance scattering energy bound.");
1137
    }
1138

1139
    // Get resonance scattering nuclides
1140
    if (check_for_node(node_res_scat, "nuclides")) {
15!
1141
      res_scat_nuclides =
15✔
1142
        get_node_array<std::string>(node_res_scat, "nuclides");
30✔
1143
    }
1144
  }
1145

1146
  // Get volume calculations
1147
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
8,817✔
1148
    model::volume_calcs.emplace_back(node_vol);
314✔
1149
  }
1150

1151
  // Get temperature settings
1152
  if (check_for_node(root, "temperature_default")) {
8,503✔
1153
    temperature_default =
342✔
1154
      std::stod(get_node_value(root, "temperature_default"));
342✔
1155
  }
1156
  if (check_for_node(root, "temperature_method")) {
8,503✔
1157
    auto temp = get_node_value(root, "temperature_method", true, true);
485✔
1158
    if (temp == "nearest") {
485✔
1159
      temperature_method = TemperatureMethod::NEAREST;
304✔
1160
    } else if (temp == "interpolation") {
181!
1161
      temperature_method = TemperatureMethod::INTERPOLATION;
181✔
1162
    } else {
UNCOV
1163
      fatal_error("Unknown temperature method: " + temp);
×
1164
    }
1165
  }
485✔
1166
  if (check_for_node(root, "temperature_tolerance")) {
8,503✔
1167
    temperature_tolerance =
680✔
1168
      std::stod(get_node_value(root, "temperature_tolerance"));
680✔
1169
  }
1170
  if (check_for_node(root, "temperature_multipole")) {
8,503✔
1171
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
185✔
1172

1173
    // Multipole currently doesn't work with photon transport
1174
    if (temperature_multipole && photon_transport) {
185!
UNCOV
1175
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1176
                  "photon transport.");
1177
    }
1178
  }
1179
  if (check_for_node(root, "temperature_range")) {
8,503✔
1180
    auto range = get_node_array<double>(root, "temperature_range");
170✔
1181
    temperature_range[0] = range.at(0);
170✔
1182
    temperature_range[1] = range.at(1);
170✔
1183
  }
170✔
1184

1185
  // Check for tabular_legendre options
1186
  if (check_for_node(root, "tabular_legendre")) {
8,503✔
1187
    // Get pointer to tabular_legendre node
1188
    xml_node node_tab_leg = root.child("tabular_legendre");
105✔
1189

1190
    // Check for enable option
1191
    if (check_for_node(node_tab_leg, "enable")) {
105!
1192
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
105✔
1193
    }
1194

1195
    // Check for the number of points
1196
    if (check_for_node(node_tab_leg, "num_points")) {
105!
UNCOV
1197
      legendre_to_tabular_points =
×
UNCOV
1198
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
UNCOV
1199
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
UNCOV
1200
        fatal_error(
×
1201
          "The 'num_points' subelement/attribute of the "
1202
          "<tabular_legendre> element must contain a value greater than 1");
1203
      }
1204
    }
1205
  }
1206

1207
  // Check whether create delayed neutrons in fission
1208
  if (check_for_node(root, "create_delayed_neutrons")) {
8,503!
UNCOV
1209
    create_delayed_neutrons =
×
UNCOV
1210
      get_node_value_bool(root, "create_delayed_neutrons");
×
1211
  }
1212

1213
  // Check whether create fission sites
1214
  if (run_mode == RunMode::FIXED_SOURCE) {
8,503✔
1215
    if (check_for_node(root, "create_fission_neutrons")) {
3,077✔
1216
      create_fission_neutrons =
325✔
1217
        get_node_value_bool(root, "create_fission_neutrons");
325✔
1218
    }
1219
  }
1220

1221
  // Check whether to scale fission photon yields
1222
  if (check_for_node(root, "delayed_photon_scaling")) {
8,503!
UNCOV
1223
    delayed_photon_scaling =
×
UNCOV
1224
      get_node_value_bool(root, "delayed_photon_scaling");
×
1225
  }
1226

1227
  // Check whether to use event-based parallelism
1228
  if (check_for_node(root, "event_based")) {
8,503!
UNCOV
1229
    event_based = get_node_value_bool(root, "event_based");
×
1230
  }
1231

1232
  // Check whether material cell offsets should be generated
1233
  if (check_for_node(root, "material_cell_offsets")) {
8,503!
UNCOV
1234
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1235
  }
1236

1237
  // Weight window information
1238
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
8,720✔
1239
    variance_reduction::weight_windows.emplace_back(
217✔
1240
      std::make_unique<WeightWindows>(node_ww));
434✔
1241
  }
1242

1243
  // Enable weight windows by default if one or more are present
1244
  if (variance_reduction::weight_windows.size() > 0)
8,503✔
1245
    settings::weight_windows_on = true;
165✔
1246

1247
  // read weight windows from file
1248
  if (check_for_node(root, "weight_windows_file")) {
8,503!
UNCOV
1249
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1250
  }
1251

1252
  // read settings for weight windows value, this will override
1253
  // the automatic setting even if weight windows are present
1254
  if (check_for_node(root, "weight_windows_on")) {
8,503✔
1255
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
60✔
1256
  }
1257

1258
  if (check_for_node(root, "max_secondaries")) {
8,503!
UNCOV
1259
    settings::max_secondaries =
×
UNCOV
1260
      std::stoi(get_node_value(root, "max_secondaries"));
×
1261
  }
1262

1263
  if (check_for_node(root, "max_history_splits")) {
8,503✔
1264
    settings::max_history_splits =
592✔
1265
      std::stoi(get_node_value(root, "max_history_splits"));
592✔
1266
  }
1267

1268
  if (check_for_node(root, "max_tracks")) {
8,503✔
1269
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
90✔
1270
  }
1271

1272
  // Create weight window generator objects
1273
  if (check_for_node(root, "weight_window_generators")) {
8,503✔
1274
    auto wwgs_node = root.child("weight_window_generators");
105✔
1275
    for (pugi::xml_node node_wwg :
210✔
1276
      wwgs_node.children("weight_windows_generator")) {
210✔
1277
      variance_reduction::weight_windows_generators.emplace_back(
105✔
1278
        std::make_unique<WeightWindowsGenerator>(node_wwg));
210✔
1279
    }
1280
    // if any of the weight windows are intended to be generated otf, make
1281
    // sure they're applied
1282
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
105!
1283
      if (wwg->on_the_fly_) {
105!
1284
        settings::weight_windows_on = true;
105✔
1285
        break;
105✔
1286
      }
1287
    }
1288
    // If any weight window generators have local FW-CADIS target tallies,
1289
    // user-defined adjoint sources cannot be used at the same time.
1290
    if (!model::adjoint_sources.empty()) {
105!
UNCOV
1291
      for (const auto& wwg : variance_reduction::weight_windows_generators) {
×
UNCOV
1292
        if (!wwg->targets_.empty()) {
×
UNCOV
1293
          fatal_error("Cannot use both user-defined adjoint sources and "
×
1294
                      "FW-CADIS target tallies at the same time.");
1295
        }
1296
      }
1297
    }
1298
  }
1299

1300
  // Set up weight window checkpoints
1301
  if (check_for_node(root, "weight_window_checkpoints")) {
8,503✔
1302
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
92✔
1303
    if (check_for_node(ww_checkpoints, "collision")) {
92!
1304
      weight_window_checkpoint_collision =
92✔
1305
        get_node_value_bool(ww_checkpoints, "collision");
92✔
1306
    }
1307
    if (check_for_node(ww_checkpoints, "surface")) {
92!
1308
      weight_window_checkpoint_surface =
92✔
1309
        get_node_value_bool(ww_checkpoints, "surface");
92✔
1310
    }
1311
  }
1312

1313
  if (weight_windows_on) {
8,503✔
1314
    if (!weight_window_checkpoint_surface &&
270✔
1315
        !weight_window_checkpoint_collision)
178!
NEW
1316
      fatal_error(
×
1317
        "Weight Windows are enabled but there are no valid checkpoints.");
1318
  }
1319

1320
  if (check_for_node(root, "use_decay_photons")) {
8,503✔
1321
    settings::use_decay_photons =
11✔
1322
      get_node_value_bool(root, "use_decay_photons");
11✔
1323
  }
1324

1325
  // If weight windows are on, also enable shared secondary bank (unless
1326
  // explicitly disabled by user).
1327
  if (check_for_node(root, "shared_secondary_bank")) {
8,503✔
1328
    bool val = get_node_value_bool(root, "shared_secondary_bank");
261✔
1329
    if (val && run_mode == RunMode::EIGENVALUE) {
261!
UNCOV
1330
      warning(
×
1331
        "Shared secondary bank is not supported in eigenvalue calculations. "
1332
        "Setting will be ignored.");
1333
    } else {
1334
      settings::use_shared_secondary_bank = val;
261✔
1335
    }
1336
  } else if (settings::weight_windows_on) {
8,242✔
1337
    if (run_mode == RunMode::EIGENVALUE) {
121✔
1338
      warning(
22✔
1339
        "Shared secondary bank is not supported in eigenvalue calculations. "
1340
        "Particle local secondary banks will be used instead.");
1341
    } else if (run_mode == RunMode::FIXED_SOURCE) {
110!
1342
      settings::use_shared_secondary_bank = true;
110✔
1343
    }
1344
  }
1345
}
8,503✔
1346

1347
void free_memory_settings()
8,654✔
1348
{
1349
  settings::statepoint_batch.clear();
8,654✔
1350
  settings::sourcepoint_batch.clear();
8,654✔
1351
  settings::source_write_surf_id.clear();
8,654✔
1352
  settings::res_scat_nuclides.clear();
8,654✔
1353
}
8,654✔
1354

1355
//==============================================================================
1356
// C API functions
1357
//==============================================================================
1358

1359
extern "C" int openmc_set_n_batches(
220✔
1360
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1361
{
1362
  if (settings::n_inactive >= n_batches) {
220✔
1363
    set_errmsg("Number of active batches must be greater than zero.");
11✔
1364
    return OPENMC_E_INVALID_ARGUMENT;
11✔
1365
  }
1366

1367
  if (!settings::trigger_on) {
209✔
1368
    // Set n_batches and n_max_batches to same value
1369
    settings::n_batches = n_batches;
187✔
1370
    settings::n_max_batches = n_batches;
187✔
1371
  } else {
1372
    // Set n_batches and n_max_batches based on value of set_max_batches
1373
    if (set_max_batches) {
22✔
1374
      settings::n_max_batches = n_batches;
11✔
1375
    } else {
1376
      settings::n_batches = n_batches;
11✔
1377
    }
1378
  }
1379

1380
  // Update size of k_generation and entropy
1381
  int m = settings::n_max_batches * settings::gen_per_batch;
209✔
1382
  simulation::k_generation.reserve(m);
209✔
1383
  simulation::entropy.reserve(m);
209✔
1384

1385
  // Add value of n_batches to statepoint_batch
1386
  if (add_statepoint_batch &&
209✔
1387
      !(contains(settings::statepoint_batch, n_batches)))
198✔
1388
    settings::statepoint_batch.insert(n_batches);
33✔
1389

1390
  return 0;
1391
}
1392

1393
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,530✔
1394
{
1395
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,530✔
1396

1397
  return 0;
2,530✔
1398
}
1399

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