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

openmc-dev / openmc / 34180481077

08 Sep 2026 02:33AM UTC coverage: 81.355% (-0.005%) from 81.36%
34180481077

Pull #4114

github

web-flow
Merge d77060dd6 into d7d3284a1
Pull Request #4114: Fix zero k-effective in random ray runs with generations_per_batch > 1

18691 of 27179 branches covered (68.77%)

Branch coverage included in aggregate %.

1 of 3 new or added lines in 1 file covered. (33.33%)

60587 of 70268 relevant lines covered (86.22%)

49880025.57 hits per line

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

75.92
/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 <cstring> // for strcmp
6
#include <limits>  // for numeric_limits
7
#include <string>
8

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

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

40
namespace openmc {
41

42
//==============================================================================
43
// Global variables
44
//==============================================================================
45

46
namespace settings {
47

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

95
std::string path_cross_sections;
96
std::string path_input;
97
std::string path_output;
98
std::string path_particle_restart;
99
std::string path_sourcepoint;
100
std::string path_statepoint;
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
int64_t max_particles_in_flight {100000};
112
int max_particle_events {1000000};
113

114
ElectronTreatment electron_treatment {ElectronTreatment::TTB};
115
array<double, 4> energy_cutoff {0.0, 1000.0, 0.0, 0.0};
116
array<double, 4> time_cutoff {INFTY, INFTY, INFTY, INFTY};
117
int ifp_n_generation {-1};
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)
8,223 ✔
164
{
165
  using namespace settings;
8,223 ✔
166
  using namespace pugi;
8,223 ✔
167

168
  // Check number of particles
169
  if (!check_for_node(node_base, "particles")) {
8,223 !
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) {
8,223 ✔
175
    n_particles = std::stoll(get_node_value(node_base, "particles"));
8,212 ✔
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")) {
8,223 !
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")) {
8,223 !
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")) {
8,223 !
192
    n_batches = std::stoi(get_node_value(node_base, "batches"));
8,223 ✔
193
  }
194
  if (!trigger_on)
8,223 ✔
195
    n_max_batches = n_batches;
8,082 ✔
196

197
  // Get max number of lost particles
198
  if (check_for_node(node_base, "max_lost_particles")) {
8,223 ✔
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")) {
8,223 !
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")) {
8,223 ✔
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 ||
8,223 ✔
217
      solver_type == SolverType::RANDOM_RAY) {
3,508 ✔
218
    if (check_for_node(node_base, "inactive")) {
5,173 ✔
219
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,918 ✔
220
    }
221
    if (check_for_node(node_base, "generations_per_batch")) {
5,173 ✔
222
      gen_per_batch =
30 ✔
223
        std::stoi(get_node_value(node_base, "generations_per_batch"));
15 ✔
224

225
      // The random ray solver runs a single generation per batch. The rest of
226
      // the code has to see that, since overall_generation() strides by
227
      // gen_per_batch while only one generation per batch is ever recorded.
228
      if (gen_per_batch != 1 && solver_type == SolverType::RANDOM_RAY) {
15 !
NEW
229
        warning("The 'generations_per_batch' setting does not apply to the "
×
230
                "random ray solver and is ignored.");
NEW
231
        gen_per_batch = 1;
×
232
      }
233
    }
234

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

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

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

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

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

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

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

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

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

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

436
  write_message("Reading settings XML file...", 5);
1,401 ✔
437

438
  read_settings_xml(root);
1,401 ✔
439
}
1,413 ✔
440

441
void read_settings_xml(pugi::xml_node root)
9,318 ✔
442
{
443
  using namespace settings;
9,318 ✔
444
  using namespace pugi;
9,318 ✔
445

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

456
  // Check for user meshes and allocate
457
  read_meshes(root);
9,318 ✔
458

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

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

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

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

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

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

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

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

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

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

557
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
9,318 ✔
558
    // Read run parameters
559
    get_run_parameters(node_mode);
8,223 ✔
560

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

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

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

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

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

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

620
  // Check for photon transport
621
  if (check_for_node(root, "photon_transport")) {
9,309 ✔
622
    photon_transport = get_node_value_bool(root, "photon_transport");
486 ✔
623

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

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

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

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

652
  // ==========================================================================
653
  // EXTERNAL SOURCE
654

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

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

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

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

686
  // Build probability mass function for sampling external sources
687
  vector<double> source_strengths;
9,299 ✔
688
  for (auto& s : model::external_sources) {
20,241 ✔
689
    source_strengths.push_back(s->strength());
10,942 ✔
690
  }
691
  model::external_sources_probability.assign(source_strengths);
9,299 ✔
692

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

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

704
  if (check_for_node(root, "free_gas_threshold")) {
9,299 !
705
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
706
  }
707

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

716
  // Survival biasing
717
  if (check_for_node(root, "survival_biasing")) {
9,299 ✔
718
    survival_biasing = get_node_value_bool(root, "survival_biasing");
227 ✔
719
  }
720

721
  // Probability tables
722
  if (check_for_node(root, "ptables")) {
9,299 ✔
723
    urr_ptables_on = get_node_value_bool(root, "ptables");
15 ✔
724
  }
725

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

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

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

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

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

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

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

833
      // Turn on Shannon entropy calculation
834
      entropy_on = true;
334 ✔
835

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

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

858
    // Turn on uniform fission source weighting
859
    ufs_on = true;
15 ✔
860

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

868
  // Check if the user has specified to write state points
869
  if (check_for_node(root, "state_point")) {
9,299 ✔
870

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1236
  // Check whether to use event-based parallelism
1237
  if (check_for_node(root, "event_based")) {
9,254 !
1238
    event_based = get_node_value_bool(root, "event_based");
×
1239
  }
1240

1241
  // Check whether material cell offsets should be generated
1242
  if (check_for_node(root, "material_cell_offsets")) {
9,254 !
1243
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1244
  }
1245

1246
  // Weight window information
1247
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
9,570 ✔
1248
    variance_reduction::weight_windows.emplace_back(
316 ✔
1249
      std::make_unique<WeightWindows>(node_ww));
632 ✔
1250
  }
1251

1252
  // Enable weight windows by default if one or more are present
1253
  if (variance_reduction::weight_windows.size() > 0)
9,254 ✔
1254
    settings::weight_windows_on = true;
220 ✔
1255

1256
  // read weight windows from file
1257
  if (check_for_node(root, "weight_windows_file")) {
9,254 ✔
1258
    weight_windows_file = get_node_value(root, "weight_windows_file");
26 ✔
1259
    weight_windows_on = true;
26 ✔
1260
  }
1261

1262
  // read settings for weight windows value, this will override
1263
  // the automatic setting even if weight windows are present
1264
  if (check_for_node(root, "weight_windows_on")) {
9,254 ✔
1265
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
93 ✔
1266
  }
1267

1268
  if (check_for_node(root, "max_secondaries")) {
9,254 !
1269
    settings::max_secondaries =
×
1270
      std::stoi(get_node_value(root, "max_secondaries"));
×
1271
  }
1272

1273
  if (check_for_node(root, "max_history_splits")) {
9,254 ✔
1274
    settings::max_history_splits =
798 ✔
1275
      std::stoi(get_node_value(root, "max_history_splits"));
798 ✔
1276
  }
1277

1278
  if (check_for_node(root, "max_tracks")) {
9,254 ✔
1279
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
90 ✔
1280
  }
1281

1282
  // Create weight window generator objects
1283
  if (check_for_node(root, "weight_window_generators")) {
9,254 ✔
1284
    auto wwgs_node = root.child("weight_window_generators");
127 ✔
1285
    for (pugi::xml_node node_wwg :
254 ✔
1286
      wwgs_node.children("weight_windows_generator")) {
254 ✔
1287
      variance_reduction::weight_windows_generators.emplace_back(
127 ✔
1288
        std::make_unique<WeightWindowsGenerator>(node_wwg));
254 ✔
1289
    }
1290
    // if any of the weight windows are intended to be generated otf, make
1291
    // sure they're applied
1292
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
127 !
1293
      if (wwg->on_the_fly_) {
127 !
1294
        settings::weight_windows_on = true;
127 ✔
1295
        break;
127 ✔
1296
      }
1297
    }
1298
    // If any weight window generators have local FW-CADIS target tallies,
1299
    // user-defined adjoint sources cannot be used at the same time.
1300
    if (!model::adjoint_sources.empty()) {
127 !
1301
      for (const auto& wwg : variance_reduction::weight_windows_generators) {
×
1302
        if (!wwg->targets_.empty()) {
×
1303
          fatal_error("Cannot use both user-defined adjoint sources and "
×
1304
                      "FW-CADIS target tallies at the same time.");
1305
        }
1306
      }
1307
    }
1308
  }
1309

1310
  // Set up weight window checkpoints
1311
  if (check_for_node(root, "weight_window_checkpoints")) {
9,254 ✔
1312
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
184 ✔
1313
    if (check_for_node(ww_checkpoints, "collision")) {
184 !
1314
      weight_window_checkpoint_collision =
184 ✔
1315
        get_node_value_bool(ww_checkpoints, "collision");
184 ✔
1316
    }
1317
    if (check_for_node(ww_checkpoints, "surface")) {
184 !
1318
      weight_window_checkpoint_surface =
184 ✔
1319
        get_node_value_bool(ww_checkpoints, "surface");
184 ✔
1320
    }
1321
  }
1322

1323
  if (weight_windows_on) {
9,254 ✔
1324
    if (!weight_window_checkpoint_surface &&
362 ✔
1325
        !weight_window_checkpoint_collision)
189 !
1326
      fatal_error(
×
1327
        "Weight Windows are enabled but there are no valid checkpoints.");
1328
  }
1329

1330
  if (check_for_node(root, "use_decay_photons")) {
9,254 ✔
1331
    settings::use_decay_photons =
11 ✔
1332
      get_node_value_bool(root, "use_decay_photons");
11 ✔
1333
  }
1334

1335
  // If weight windows are on, also enable shared secondary bank (unless
1336
  // explicitly disabled by user).
1337
  if (check_for_node(root, "shared_secondary_bank")) {
9,254 ✔
1338
    bool val = get_node_value_bool(root, "shared_secondary_bank");
335 ✔
1339
    if (val && run_mode == RunMode::EIGENVALUE) {
335 !
1340
      warning(
×
1341
        "Shared secondary bank is not supported in eigenvalue calculations. "
1342
        "Setting will be ignored.");
1343
    } else {
1344
      settings::use_shared_secondary_bank = val;
335 ✔
1345
    }
1346
  } else if (settings::weight_windows_on) {
8,919 ✔
1347
    if (run_mode == RunMode::EIGENVALUE) {
180 ✔
1348
      warning(
22 ✔
1349
        "Shared secondary bank is not supported in eigenvalue calculations. "
1350
        "Particle local secondary banks will be used instead.");
1351
    } else if (run_mode == RunMode::FIXED_SOURCE) {
169 !
1352
      settings::use_shared_secondary_bank = true;
169 ✔
1353
    }
1354
  }
1355
}
9,254 ✔
1356

1357
void free_memory_settings()
9,405 ✔
1358
{
1359
  settings::statepoint_batch.clear();
9,405 ✔
1360
  settings::sourcepoint_batch.clear();
9,405 ✔
1361
  settings::source_write_surf_id.clear();
9,405 ✔
1362
  settings::res_scat_nuclides.clear();
9,405 ✔
1363
  settings::ifp_delayed_group_on = false;
9,405 ✔
1364
  settings::ifp_lifetime_on = false;
9,405 ✔
1365
}
9,405 ✔
1366

1367
//==============================================================================
1368
// C API functions
1369
//==============================================================================
1370

1371
namespace {
1372

1373
int invalid_setting(const char* type, const char* name)
×
1374
{
1375
  set_errmsg(fmt::format("Unknown {} setting '{}'.", type, name));
×
1376
  return OPENMC_E_INVALID_ARGUMENT;
×
1377
}
1378

1379
bool* bool_setting(const char* name)
4,466 ✔
1380
{
1381
  if (std::strcmp(name, "cmfd_run") == 0) {
4,466 ✔
1382
    return &settings::cmfd_run;
1383
  } else if (std::strcmp(name, "entropy_on") == 0) {
4,246 ✔
1384
    return &settings::entropy_on;
1385
  } else if (std::strcmp(name, "event_based") == 0) {
1,892 ✔
1386
    return &settings::event_based;
1387
  } else if (std::strcmp(name, "need_depletion_rx") == 0) {
1,672 ✔
1388
    return &simulation::need_depletion_rx;
1389
  } else if (std::strcmp(name, "photon_transport") == 0) {
814 ✔
1390
    return &settings::photon_transport;
1391
  } else if (std::strcmp(name, "output_summary") == 0) {
759 ✔
1392
    return &settings::output_summary;
1393
  } else if (std::strcmp(name, "reduce_tallies") == 0) {
704 ✔
1394
    return &settings::reduce_tallies;
1395
  } else if (std::strcmp(name, "restart_run") == 0) {
649 ✔
1396
    return &settings::restart_run;
1397
  } else if (std::strcmp(name, "run_ce") == 0) {
429 ✔
1398
    return &settings::run_CE;
1399
  } else if (std::strcmp(name, "trigger_on") == 0) {
220 ✔
1400
    return &settings::trigger_on;
1401
  } else if (std::strcmp(name, "weight_windows_on") == 0) {
165 !
1402
    return &settings::weight_windows_on;
165 ✔
1403
  }
1404
  return nullptr;
1405
}
1406

1407
} // namespace
1408

1409
extern "C" int openmc_setting_get_bool(const char* name, bool* value)
3,069 ✔
1410
{
1411
  if (!name || !value) {
3,069 !
1412
    set_errmsg("Setting name and output pointer must not be null.");
×
1413
    return OPENMC_E_INVALID_ARGUMENT;
×
1414
  }
1415

1416
  bool* setting = bool_setting(name);
3,069 ✔
1417
  if (!setting)
3,069 !
1418
    return invalid_setting("boolean", name);
×
1419

1420
  *value = *setting;
3,069 ✔
1421
  return 0;
3,069 ✔
1422
}
1423

1424
extern "C" int openmc_setting_set_bool(const char* name, bool value)
1,397 ✔
1425
{
1426
  if (!name) {
1,397 !
1427
    set_errmsg("Setting name must not be null.");
×
1428
    return OPENMC_E_INVALID_ARGUMENT;
×
1429
  }
1430

1431
  bool* setting = bool_setting(name);
1,397 ✔
1432
  if (!setting)
1,397 !
1433
    return invalid_setting("boolean", name);
×
1434

1435
  *setting = value;
1,397 ✔
1436
  return 0;
1,397 ✔
1437
}
1438

1439
extern "C" int openmc_setting_get_int32(const char* name, int32_t* value)
1,221 ✔
1440
{
1441
  if (!name || !value) {
1,221 !
1442
    set_errmsg("Setting name and output pointer must not be null.");
×
1443
    return OPENMC_E_INVALID_ARGUMENT;
×
1444
  }
1445

1446
  if (std::strcmp(name, "gen_per_batch") == 0) {
1,221 ✔
1447
    *value = settings::gen_per_batch;
44 ✔
1448
  } else if (std::strcmp(name, "max_lost_particles") == 0) {
1,177 ✔
1449
    *value = settings::max_lost_particles;
33 ✔
1450
  } else if (std::strcmp(name, "max_write_lost_particles") == 0) {
1,144 ✔
1451
    *value = settings::max_write_lost_particles;
33 ✔
1452
  } else if (std::strcmp(name, "n_inactive") == 0) {
1,111 ✔
1453
    *value = settings::n_inactive;
44 ✔
1454
  } else if (std::strcmp(name, "run_mode") == 0) {
1,067 ✔
1455
    *value = static_cast<int32_t>(settings::run_mode);
22 ✔
1456
  } else if (std::strcmp(name, "verbosity") == 0) {
1,045 !
1457
    *value = settings::verbosity;
1,045 ✔
1458
  } else {
1459
    return invalid_setting("int32", name);
×
1460
  }
1461
  return 0;
1462
}
1463

1464
extern "C" int openmc_setting_set_int32(const char* name, int32_t value)
132 ✔
1465
{
1466
  if (!name) {
132 !
1467
    set_errmsg("Setting name must not be null.");
×
1468
    return OPENMC_E_INVALID_ARGUMENT;
×
1469
  }
1470

1471
  if (std::strcmp(name, "gen_per_batch") == 0) {
132 ✔
1472
    settings::gen_per_batch = value;
22 ✔
1473
  } else if (std::strcmp(name, "max_lost_particles") == 0) {
110 ✔
1474
    settings::max_lost_particles = value;
22 ✔
1475
  } else if (std::strcmp(name, "max_write_lost_particles") == 0) {
88 ✔
1476
    settings::max_write_lost_particles = value;
22 ✔
1477
  } else if (std::strcmp(name, "n_inactive") == 0) {
66 ✔
1478
    settings::n_inactive = value;
22 ✔
1479
  } else if (std::strcmp(name, "run_mode") == 0) {
44 ✔
1480
    if (value < static_cast<int32_t>(RunMode::UNSET) ||
22 !
1481
        value > static_cast<int32_t>(RunMode::VOLUME)) {
1482
      set_errmsg(fmt::format("Invalid run mode: {}.", value));
×
1483
      return OPENMC_E_INVALID_ARGUMENT;
×
1484
    }
1485
    settings::run_mode = static_cast<RunMode>(value);
22 ✔
1486
  } else if (std::strcmp(name, "verbosity") == 0) {
22 !
1487
    settings::verbosity = value;
22 ✔
1488
  } else {
1489
    return invalid_setting("int32", name);
×
1490
  }
1491
  return 0;
1492
}
1493

1494
extern "C" int openmc_setting_get_int64(const char* name, int64_t* value)
121 ✔
1495
{
1496
  if (!name || !value) {
121 !
1497
    set_errmsg("Setting name and output pointer must not be null.");
×
1498
    return OPENMC_E_INVALID_ARGUMENT;
×
1499
  }
1500

1501
  if (std::strcmp(name, "n_particles") != 0)
121 !
1502
    return invalid_setting("int64", name);
×
1503

1504
  *value = settings::n_particles;
121 ✔
1505
  return 0;
121 ✔
1506
}
1507

1508
extern "C" int openmc_setting_set_int64(const char* name, int64_t value)
99 ✔
1509
{
1510
  if (!name) {
99 !
1511
    set_errmsg("Setting name must not be null.");
×
1512
    return OPENMC_E_INVALID_ARGUMENT;
×
1513
  }
1514

1515
  if (std::strcmp(name, "n_particles") != 0)
99 !
1516
    return invalid_setting("int64", name);
×
1517

1518
  settings::n_particles = value;
99 ✔
1519
  return 0;
99 ✔
1520
}
1521

1522
extern "C" int openmc_setting_get_double(const char* name, double* value)
33 ✔
1523
{
1524
  if (!name || !value) {
33 !
1525
    set_errmsg("Setting name and output pointer must not be null.");
×
1526
    return OPENMC_E_INVALID_ARGUMENT;
×
1527
  }
1528

1529
  if (std::strcmp(name, "rel_max_lost_particles") != 0)
33 !
1530
    return invalid_setting("double", name);
×
1531

1532
  *value = settings::rel_max_lost_particles;
33 ✔
1533
  return 0;
33 ✔
1534
}
1535

1536
extern "C" int openmc_setting_set_double(const char* name, double value)
22 ✔
1537
{
1538
  if (!name) {
22 !
1539
    set_errmsg("Setting name must not be null.");
×
1540
    return OPENMC_E_INVALID_ARGUMENT;
×
1541
  }
1542

1543
  if (std::strcmp(name, "rel_max_lost_particles") != 0)
22 !
1544
    return invalid_setting("double", name);
×
1545

1546
  settings::rel_max_lost_particles = value;
22 ✔
1547
  return 0;
22 ✔
1548
}
1549

1550
extern "C" int openmc_setting_get_string(const char* name, const char** value)
22 ✔
1551
{
1552
  if (!name || !value) {
22 !
1553
    set_errmsg("Setting name and output pointer must not be null.");
×
1554
    return OPENMC_E_INVALID_ARGUMENT;
×
1555
  }
1556

1557
  if (std::strcmp(name, "path_statepoint") != 0)
22 !
1558
    return invalid_setting("string", name);
×
1559

1560
  *value = settings::path_statepoint.c_str();
22 ✔
1561
  return 0;
22 ✔
1562
}
1563

1564
extern "C" int openmc_set_n_batches(
220 ✔
1565
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1566
{
1567
  if (settings::n_inactive >= n_batches) {
220 ✔
1568
    set_errmsg("Number of active batches must be greater than zero.");
11 ✔
1569
    return OPENMC_E_INVALID_ARGUMENT;
11 ✔
1570
  }
1571

1572
  if (!settings::trigger_on) {
209 ✔
1573
    // Set n_batches and n_max_batches to same value
1574
    settings::n_batches = n_batches;
187 ✔
1575
    settings::n_max_batches = n_batches;
187 ✔
1576
  } else {
1577
    // Set n_batches and n_max_batches based on value of set_max_batches
1578
    if (set_max_batches) {
22 ✔
1579
      settings::n_max_batches = n_batches;
11 ✔
1580
    } else {
1581
      settings::n_batches = n_batches;
11 ✔
1582
    }
1583
  }
1584

1585
  // Update size of k_generation and entropy
1586
  int m = settings::n_max_batches * settings::gen_per_batch;
209 ✔
1587
  simulation::k_generation.reserve(m);
209 ✔
1588
  simulation::entropy.reserve(m);
209 ✔
1589

1590
  // Add value of n_batches to statepoint_batch
1591
  if (add_statepoint_batch &&
209 ✔
1592
      !(contains(settings::statepoint_batch, n_batches)))
198 ✔
1593
    settings::statepoint_batch.insert(n_batches);
33 ✔
1594

1595
  return 0;
1596
}
1597

1598
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,530 ✔
1599
{
1600
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,530 ✔
1601

1602
  return 0;
2,530 ✔
1603
}
1604

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