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

openmc-dev / openmc / 34417681268

09 Sep 2026 11:36PM UTC coverage: 81.487% (+0.02%) from 81.465%
34417681268

push

github

web-flow
Adaptive Volume Estimators (#4110)

Co-authored-by: John Tramm <jtramm@gmail.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>

18904 of 27383 branches covered (69.04%)

Branch coverage included in aggregate %.

221 of 241 new or added lines in 7 files covered. (91.7%)

61015 of 70693 relevant lines covered (86.31%)

49786697.92 hits per line

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

75.55
/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,476 ✔
164
{
165
  using namespace settings;
8,476 ✔
166
  using namespace pugi;
8,476 ✔
167

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

197
  // Get max number of lost particles
198
  if (check_for_node(node_base, "max_lost_particles")) {
8,476 ✔
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,476 !
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,476 ✔
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,476 ✔
217
      solver_type == SolverType::RANDOM_RAY) {
3,650 ✔
218
    if (check_for_node(node_base, "inactive")) {
5,426 ✔
219
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
5,146 ✔
220
    }
221
    if (check_for_node(node_base, "generations_per_batch")) {
5,426 ✔
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 !
229
        warning("The 'generations_per_batch' setting does not apply to the "
×
230
                "random ray solver and is ignored.");
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,426 ✔
237
    simulation::k_generation.reserve(m);
5,426 ✔
238
    simulation::entropy.reserve(m);
5,426 ✔
239

240
    // Get the trigger information for keff
241
    if (check_for_node(node_base, "keff_trigger")) {
5,426 ✔
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,476 ✔
273
    xml_node random_ray_node = node_base.child("random_ray");
1,031 ✔
274
    if (check_for_node(random_ray_node, "distance_active")) {
1,031 !
275
      RandomRay::distance_active_ =
2,062 ✔
276
        std::stod(get_node_value(random_ray_node, "distance_active"));
2,062 ✔
277
      if (RandomRay::distance_active_ <= 0.0) {
1,031 !
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")) {
1,031 !
284
      RandomRay::distance_inactive_ =
2,062 ✔
285
        std::stod(get_node_value(random_ray_node, "distance_inactive"));
2,062 ✔
286
      if (RandomRay::distance_inactive_ < 0) {
1,031 !
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")) {
1,031 !
294
      xml_node ray_source_node = random_ray_node.child("ray_source");
1,031 ✔
295
      xml_node source_node = ray_source_node.child("source");
1,031 ✔
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);
2,062 ✔
299
    } else {
300
      fatal_error("Specify random ray source in settings XML");
×
301
    }
302
    if (check_for_node(random_ray_node, "volume_estimator")) {
1,031 ✔
303
      std::string temp_str =
634 ✔
304
        get_node_value(random_ray_node, "volume_estimator", true, true);
634 ✔
305
      if (temp_str == "simulation_averaged") {
634 ✔
306
        FlatSourceDomain::volume_estimator_ =
30 ✔
307
          RandomRayVolumeEstimator::SIMULATION_AVERAGED;
308
      } else if (temp_str == "naive") {
604 ✔
309
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::NAIVE;
102 ✔
310
      } else if (temp_str == "hybrid") {
502 ✔
311
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::HYBRID;
367 ✔
312
      } else if (temp_str == "adaptive") {
135 ✔
313
        FlatSourceDomain::volume_estimator_ =
90 ✔
314
          RandomRayVolumeEstimator::ADAPTIVE;
315
      } else if (temp_str == "strict_adaptive") {
45 !
316
        FlatSourceDomain::volume_estimator_ =
45 ✔
317
          RandomRayVolumeEstimator::STRICT_ADAPTIVE;
NEW
318
      } else if (temp_str == "auto") {
×
NEW
319
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::AUTO;
×
320
      } else {
321
        fatal_error("Unrecognized volume estimator: " + temp_str);
×
322
      }
323
    }
634 ✔
324
    if (check_for_node(random_ray_node, "source_shape")) {
1,031 ✔
325
      std::string temp_str =
517 ✔
326
        get_node_value(random_ray_node, "source_shape", true, true);
517 ✔
327
      if (temp_str == "flat") {
517 ✔
328
        RandomRay::source_shape_ = RandomRaySourceShape::FLAT;
97 ✔
329
      } else if (temp_str == "linear") {
420 ✔
330
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR;
375 ✔
331
      } else if (temp_str == "linear_xy") {
45 !
332
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR_XY;
45 ✔
333
      } else {
334
        fatal_error("Unrecognized source shape: " + temp_str);
×
335
      }
336
    }
517 ✔
337
    if (check_for_node(random_ray_node, "volume_normalized_flux_tallies")) {
1,031 ✔
338
      FlatSourceDomain::volume_normalized_flux_tallies_ =
708 ✔
339
        get_node_value_bool(random_ray_node, "volume_normalized_flux_tallies");
708 ✔
340
    }
341
    if (check_for_node(random_ray_node, "adjoint")) {
1,031 ✔
342
      FlatSourceDomain::adjoint_requested_ =
86 ✔
343
        get_node_value_bool(random_ray_node, "adjoint");
86 ✔
344
    }
345
    if (check_for_node(random_ray_node, "sample_method")) {
1,031 ✔
346
      std::string temp_str =
52 ✔
347
        get_node_value(random_ray_node, "sample_method", true, true);
52 ✔
348
      if (temp_str == "prng") {
52 !
349
        RandomRay::sample_method_ = RandomRaySampleMethod::PRNG;
×
350
      } else if (temp_str == "halton") {
52 ✔
351
        RandomRay::sample_method_ = RandomRaySampleMethod::HALTON;
37 ✔
352
      } else if (temp_str == "s2") {
15 !
353
        RandomRay::sample_method_ = RandomRaySampleMethod::S2;
15 ✔
354
      } else {
355
        fatal_error("Unrecognized sample method: " + temp_str);
×
356
      }
357
    }
52 ✔
358
    if (check_for_node(random_ray_node, "source_region_meshes")) {
1,031 ✔
359
      pugi::xml_node node_source_region_meshes =
443 ✔
360
        random_ray_node.child("source_region_meshes");
443 ✔
361
      for (pugi::xml_node node_mesh :
946 ✔
362
        node_source_region_meshes.children("mesh")) {
946 ✔
363
        int mesh_id = std::stoi(node_mesh.attribute("id").value());
1,006 ✔
364
        for (pugi::xml_node node_domain : node_mesh.children("domain")) {
1,006 ✔
365
          int domain_id = std::stoi(node_domain.attribute("id").value());
1,006 ✔
366
          std::string domain_type = node_domain.attribute("type").value();
503 ✔
367
          Source::DomainType type;
503 ✔
368
          if (domain_type == "material") {
503 ✔
369
            type = Source::DomainType::MATERIAL;
30 ✔
370
          } else if (domain_type == "cell") {
473 ✔
371
            type = Source::DomainType::CELL;
30 ✔
372
          } else if (domain_type == "universe") {
443 !
373
            type = Source::DomainType::UNIVERSE;
443 ✔
374
          } else {
375
            throw std::runtime_error("Unknown domain type: " + domain_type);
×
376
          }
377
          FlatSourceDomain::mesh_domain_map_[mesh_id].emplace_back(
503 ✔
378
            type, domain_id);
379
        }
503 ✔
380
      }
381
    }
382
    if (check_for_node(random_ray_node, "diagonal_stabilization_rho")) {
1,031 ✔
383
      FlatSourceDomain::diagonal_stabilization_rho_ = std::stod(
30 ✔
384
        get_node_value(random_ray_node, "diagonal_stabilization_rho"));
30 ✔
385
      if (FlatSourceDomain::diagonal_stabilization_rho_ < 0.0 ||
30 !
386
          FlatSourceDomain::diagonal_stabilization_rho_ > 1.0) {
387
        fatal_error("Random ray diagonal stabilization rho factor must be "
×
388
                    "between 0 and 1");
389
      }
390
    }
391
    if (check_for_node(random_ray_node, "adjoint_source")) {
1,031 ✔
392
      pugi::xml_node adj_source_node = random_ray_node.child("adjoint_source");
15 ✔
393
      for (pugi::xml_node source_node : adj_source_node.children("source")) {
30 ✔
394
        // Find any local adjoint sources
395
        model::adjoint_sources.push_back(Source::create(source_node));
30 ✔
396
      }
397
    }
398
  }
399
}
8,476 ✔
400

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

420
  // Parse settings.xml file
421
  xml_document doc;
1,401 ✔
422
  auto result = doc.load_file(filename.c_str());
1,401 ✔
423
  if (!result) {
1,401 !
424
    fatal_error("Error processing settings.xml file.");
×
425
  }
426

427
  // Get root element
428
  xml_node root = doc.document_element();
1,401 ✔
429

430
  // Verbosity
431
  if (check_for_node(root, "verbosity") && verbosity == -1) {
1,401 !
432
    verbosity = std::stoi(get_node_value(root, "verbosity"));
428 ✔
433
  } else if (verbosity == -1) {
1,187 !
434
    verbosity = 7;
1,187 ✔
435
  }
436

437
  // To this point, we haven't displayed any output since we didn't know what
438
  // the verbosity is. Now that we checked for it, show the title if necessary
439
  if (mpi::master) {
1,401 ✔
440
    if (verbosity >= 2)
1,213 ✔
441
      title();
1,007 ✔
442
  }
443

444
  write_message("Reading settings XML file...", 5);
1,401 ✔
445

446
  read_settings_xml(root);
1,401 ✔
447
}
1,413 ✔
448

449
void read_settings_xml(pugi::xml_node root)
9,571 ✔
450
{
451
  using namespace settings;
9,571 ✔
452
  using namespace pugi;
9,571 ✔
453

454
  // Find if a multi-group or continuous-energy simulation is desired
455
  if (check_for_node(root, "energy_mode")) {
9,571 ✔
456
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
1,596 ✔
457
    if (temp_str == "mg" || temp_str == "multi-group") {
3,192 !
458
      run_CE = false;
1,596 ✔
459
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
460
      run_CE = true;
×
461
    }
462
  }
1,596 ✔
463

464
  // Check for user meshes and allocate
465
  read_meshes(root);
9,571 ✔
466

467
  // Look for deprecated cross_sections.xml file in settings.xml
468
  if (check_for_node(root, "cross_sections")) {
9,571 !
469
    warning(
×
470
      "Setting cross_sections in settings.xml has been deprecated."
471
      " The cross_sections are now set in materials.xml and the "
472
      "cross_sections input to materials.xml and the OPENMC_CROSS_SECTIONS"
473
      " environment variable will take precendent over setting "
474
      "cross_sections in settings.xml.");
475
    path_cross_sections = get_node_value(root, "cross_sections");
×
476
  }
477

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

491
  // Check for a trigger node and get trigger information
492
  if (check_for_node(root, "trigger")) {
9,571 ✔
493
    xml_node node_trigger = root.child("trigger");
156 ✔
494

495
    // Check if trigger(s) are to be turned on
496
    trigger_on = get_node_value_bool(node_trigger, "active");
156 ✔
497

498
    if (trigger_on) {
156 ✔
499
      if (check_for_node(node_trigger, "max_batches")) {
141 !
500
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
282 ✔
501
      } else {
502
        fatal_error("<max_batches> must be specified with triggers");
×
503
      }
504

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

518
  // Check run mode if it hasn't been set from the command line
519
  xml_node node_mode;
9,571 ✔
520
  if (run_mode == RunMode::UNSET) {
9,571 ✔
521
    if (check_for_node(root, "run_mode")) {
8,508 ✔
522
      std::string temp_str = get_node_value(root, "run_mode", true, true);
8,478 ✔
523
      if (temp_str == "eigenvalue") {
8,478 ✔
524
        run_mode = RunMode::EIGENVALUE;
4,796 ✔
525
      } else if (temp_str == "fixed source") {
3,682 ✔
526
        run_mode = RunMode::FIXED_SOURCE;
3,650 ✔
527
      } else if (temp_str == "plot") {
32 !
528
        run_mode = RunMode::PLOTTING;
×
529
      } else if (temp_str == "particle restart") {
32 !
530
        run_mode = RunMode::PARTICLE;
×
531
      } else if (temp_str == "volume") {
32 !
532
        run_mode = RunMode::VOLUME;
32 ✔
533
      } else {
534
        fatal_error("Unrecognized run mode: " + temp_str);
×
535
      }
536

537
      // Assume XML specifies <particles>, <batches>, etc. directly
538
      node_mode = root;
8,478 ✔
539
    } else {
8,478 ✔
540
      warning("<run_mode> should be specified.");
30 ✔
541

542
      // Make sure that either eigenvalue or fixed source was specified
543
      node_mode = root.child("eigenvalue");
30 ✔
544
      if (node_mode) {
30 !
545
        run_mode = RunMode::EIGENVALUE;
30 ✔
546
      } else {
547
        node_mode = root.child("fixed_source");
×
548
        if (node_mode) {
×
549
          run_mode = RunMode::FIXED_SOURCE;
×
550
        } else {
551
          fatal_error("<eigenvalue> or <fixed_source> not specified.");
×
552
        }
553
      }
554
    }
555
  }
556

557
  // Check solver type
558
  if (check_for_node(root, "random_ray")) {
9,571 ✔
559
    solver_type = SolverType::RANDOM_RAY;
1,031 ✔
560
    if (run_CE)
1,031 !
561
      fatal_error("multi-group energy mode must be specified in settings XML "
×
562
                  "when using the random ray solver.");
563
  }
564

565
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
9,571 ✔
566
    // Read run parameters
567
    get_run_parameters(node_mode);
8,476 ✔
568

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

583
    // Check for user value for the number of generation of the Iterated Fission
584
    // Probability (IFP) method
585
    if (check_for_node(root, "ifp_n_generation")) {
8,476 ✔
586
      ifp_n_generation = std::stoi(get_node_value(root, "ifp_n_generation"));
210 ✔
587
      if (ifp_n_generation <= 0) {
105 !
588
        fatal_error("'ifp_n_generation' must be greater than 0.");
×
589
      }
590
      // Avoid tallying 0 if IFP logs are not complete when active cycles start
591
      if (ifp_n_generation > n_inactive) {
105 ✔
592
        fatal_error("'ifp_n_generation' must be lower than or equal to the "
9 ✔
593
                    "number of inactive cycles.");
594
      }
595
    }
596
  }
597

598
  // Copy plotting random number seed if specified
599
  if (check_for_node(root, "plot_seed")) {
9,562 !
600
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
601
    model::plotter_seed = seed;
×
602
  }
603

604
  // Copy random number seed if specified
605
  if (check_for_node(root, "seed")) {
9,562 ✔
606
    auto seed = std::stoll(get_node_value(root, "seed"));
1,200 ✔
607
    openmc_set_seed(seed);
600 ✔
608
  }
609

610
  // Copy random number stride if specified
611
  if (check_for_node(root, "stride")) {
9,562 ✔
612
    auto stride = std::stoull(get_node_value(root, "stride"));
30 ✔
613
    openmc_set_stride(stride);
15 ✔
614
  }
615

616
  // Check for electron treatment
617
  if (check_for_node(root, "electron_treatment")) {
9,562 ✔
618
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
108 ✔
619
    if (temp_str == "led") {
108 ✔
620
      electron_treatment = ElectronTreatment::LED;
41 ✔
621
    } else if (temp_str == "ttb") {
67 !
622
      electron_treatment = ElectronTreatment::TTB;
67 ✔
623
    } else {
624
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
625
    }
626
  }
108 ✔
627

628
  // Check for photon transport
629
  if (check_for_node(root, "photon_transport")) {
9,562 ✔
630
    photon_transport = get_node_value_bool(root, "photon_transport");
486 ✔
631

632
    if (!run_CE && photon_transport) {
486 !
633
      fatal_error("Photon transport is not currently supported in "
×
634
                  "multigroup mode");
635
    }
636
  }
637

638
  // Check for atomic relaxation
639
  if (check_for_node(root, "atomic_relaxation")) {
9,562 ✔
640
    atomic_relaxation = get_node_value_bool(root, "atomic_relaxation");
30 ✔
641
  }
642

643
  // Number of bins for logarithmic grid
644
  if (check_for_node(root, "log_grid_bins")) {
9,562 ✔
645
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
30 ✔
646
    if (n_log_bins < 1) {
15 !
647
      fatal_error("Number of bins for logarithmic grid must be greater "
×
648
                  "than zero.");
649
    }
650
  }
651

652
  // Number of OpenMP threads
653
  if (check_for_node(root, "threads")) {
9,562 !
654
    if (mpi::master)
×
655
      warning("The <threads> element has been deprecated. Use "
×
656
              "the OMP_NUM_THREADS environment variable to set the number of "
657
              "threads.");
658
  }
659

660
  // ==========================================================================
661
  // EXTERNAL SOURCE
662

663
  // Get point to list of <source> elements and make sure there is at least one
664
  for (pugi::xml_node node : root.children("source")) {
18,257 ✔
665
    model::external_sources.push_back(Source::create(node));
17,400 ✔
666
  }
667

668
  // Check if the user has specified to read surface source
669
  if (check_for_node(root, "surf_source_read")) {
9,552 ✔
670
    surf_source_read = true;
30 ✔
671
    // Get surface source read node
672
    xml_node node_ssr = root.child("surf_source_read");
30 ✔
673

674
    std::string path = "surface_source.h5";
30 ✔
675
    // Check if the user has specified different file for surface source reading
676
    if (check_for_node(node_ssr, "path")) {
30 !
677
      path = get_node_value(node_ssr, "path", false, true);
30 ✔
678
    }
679
    model::external_sources.push_back(make_unique<FileSource>(path));
30 ✔
680
  }
30 ✔
681

682
  // If no source specified, default to isotropic point source at origin with
683
  // Watt spectrum. No default source is needed in random ray mode.
684
  if (model::external_sources.empty() &&
9,552 ✔
685
      settings::solver_type != SolverType::RANDOM_RAY) {
2,616 ✔
686
    double T[] {0.0};
2,410 ✔
687
    double p[] {1.0};
2,410 ✔
688
    model::external_sources.push_back(make_unique<IndependentSource>(
2,410 ✔
689
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
4,820 ✔
690
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
4,820 ✔
691
      UPtrDist {new Discrete(T, p, 1)}));
4,820 ✔
692
  }
693

694
  // Build probability mass function for sampling external sources
695
  vector<double> source_strengths;
9,552 ✔
696
  for (auto& s : model::external_sources) {
20,687 ✔
697
    source_strengths.push_back(s->strength());
11,135 ✔
698
  }
699
  model::external_sources_probability.assign(source_strengths);
9,552 ✔
700

701
  // Check if we want to write out source
702
  if (check_for_node(root, "write_initial_source")) {
9,552 !
703
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
704
  }
705

706
  // Get relative number of lost particles
707
  if (check_for_node(root, "source_rejection_fraction")) {
9,552 ✔
708
    source_rejection_fraction =
14 ✔
709
      std::stod(get_node_value(root, "source_rejection_fraction"));
14 !
710
  }
711

712
  if (check_for_node(root, "free_gas_threshold")) {
9,552 !
713
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
714
  }
715

716
  // Surface grazing
717
  if (check_for_node(root, "surface_grazing_cutoff"))
9,552 !
718
    surface_grazing_cutoff =
×
719
      std::stod(get_node_value(root, "surface_grazing_cutoff"));
×
720
  if (check_for_node(root, "surface_grazing_ratio"))
9,552 !
721
    surface_grazing_ratio =
×
722
      std::stod(get_node_value(root, "surface_grazing_ratio"));
×
723

724
  // Survival biasing
725
  if (check_for_node(root, "survival_biasing")) {
9,552 ✔
726
    survival_biasing = get_node_value_bool(root, "survival_biasing");
227 ✔
727
  }
728

729
  // Probability tables
730
  if (check_for_node(root, "ptables")) {
9,552 ✔
731
    urr_ptables_on = get_node_value_bool(root, "ptables");
15 ✔
732
  }
733

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

781
  // read properties from file
782
  if (check_for_node(root, "properties_file")) {
9,552 ✔
783
    properties_file = get_node_value(root, "properties_file");
11 ✔
784
    if (!file_exists(properties_file)) {
11 !
785
      fatal_error(fmt::format("File '{}' does not exist.", properties_file));
×
786
    }
787
  }
788

789
  // Particle trace
790
  if (check_for_node(root, "trace")) {
9,552 ✔
791
    auto temp = get_node_array<int64_t>(root, "trace");
15 ✔
792
    if (temp.size() != 3) {
15 !
793
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
794
                  "batch, generation, and particle number.");
795
    }
796
    trace_batch = temp.at(0);
15 ✔
797
    trace_gen = temp.at(1);
15 ✔
798
    trace_particle = temp.at(2);
15 ✔
799
  }
15 ✔
800

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

812
    // Reshape into track_identifiers
813
    int n_tracks = temp.size() / 3;
45 ✔
814
    for (int i = 0; i < n_tracks; ++i) {
180 ✔
815
      track_identifiers.push_back(
135 ✔
816
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
135 ✔
817
    }
818
  }
45 ✔
819

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

835
      auto* m = dynamic_cast<RegularMesh*>(
334 !
836
        model::meshes[model::mesh_map.at(temp)].get());
334 !
837
      if (!m)
334 !
838
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
839
      simulation::entropy_mesh = m;
334 ✔
840

841
      // Turn on Shannon entropy calculation
842
      entropy_on = true;
334 ✔
843

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

860
    auto* m =
15 ✔
861
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
15 !
862
    if (!m)
15 !
863
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
864
    simulation::ufs_mesh = m;
15 ✔
865

866
    // Turn on uniform fission source weighting
867
    ufs_on = true;
15 ✔
868

869
  } else if (check_for_node(root, "uniform_fs")) {
9,537 !
870
    fatal_error(
×
871
      "Specifying a UFS mesh via the <uniform_fs> element "
872
      "is deprecated. Please create a mesh using <mesh> and then reference "
873
      "it by specifying its ID in a <ufs_mesh> element.");
874
  }
875

876
  // Check if the user has specified to write state points
877
  if (check_for_node(root, "state_point")) {
9,552 ✔
878

879
    // Get pointer to state_point node
880
    auto node_sp = root.child("state_point");
160 ✔
881

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

899
  // Check if the user has specified to write source points
900
  if (check_for_node(root, "source_point")) {
9,552 ✔
901
    // Get source_point node
902
    xml_node node_sp = root.child("source_point");
101 ✔
903

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

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

937
  // Check is the user specified to convert strength to statistical weight
938
  if (check_for_node(root, "uniform_source_sampling")) {
9,552 ✔
939
    uniform_source_sampling =
55 ✔
940
      get_node_value_bool(root, "uniform_source_sampling");
55 ✔
941
  }
942

943
  // Check if the user has specified to write surface source
944
  if (check_for_node(root, "surf_source_write")) {
9,552 ✔
945
    surf_source_write = true;
412 ✔
946
    // Get surface source write node
947
    xml_node node_ssw = root.child("surf_source_write");
412 ✔
948

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

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

968
    // Get maximum number of surface source files to be created
969
    if (check_for_node(node_ssw, "max_source_files")) {
403 ✔
970
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
66 ✔
971
    } else {
972
      ssw_max_files = 1;
370 ✔
973
    }
974

975
    if (check_for_node(node_ssw, "mcpl")) {
403 ✔
976
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
11 ✔
977
    }
978
    // Get cell information
979
    if (check_for_node(node_ssw, "cell")) {
403 ✔
980
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
208 ✔
981
      ssw_cell_type = SSWCellType::Both;
104 ✔
982
    }
983
    if (check_for_node(node_ssw, "cellfrom")) {
403 ✔
984
      if (ssw_cell_id != C_NONE) {
90 ✔
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, "cellfrom"));
144 ✔
989
      ssw_cell_type = SSWCellType::From;
72 ✔
990
    }
991
    if (check_for_node(node_ssw, "cellto")) {
385 ✔
992
      if (ssw_cell_id != C_NONE) {
71 ✔
993
        fatal_error(
18 ✔
994
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
995
      }
996
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
106 ✔
997
      ssw_cell_type = SSWCellType::To;
53 ✔
998
    }
999
  }
1000

1001
  // Check if the user has specified to write specific collisions
1002
  if (check_for_node(root, "collision_track")) {
9,507 ✔
1003
    settings::collision_track = true;
160 ✔
1004
    // Get collision track node
1005
    xml_node node_ct = root.child("collision_track");
160 ✔
1006
    collision_track_config = CollisionTrackConfig {};
160 ✔
1007

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

1065
  // If source is not separate and is to be written out in the statepoint
1066
  // file, make sure that the sourcepoint batch numbers are contained in the
1067
  // statepoint list
1068
  if (!source_separate) {
9,507 ✔
1069
    for (const auto& b : sourcepoint_batch) {
18,968 ✔
1070
      if (!contains(statepoint_batch, b)) {
19,094 !
1071
        fatal_error(
×
1072
          "Sourcepoint batches are not a subset of statepoint batches.");
1073
      }
1074
    }
1075
  }
1076

1077
  // Check if the user has specified to not reduce tallies at the end of every
1078
  // batch
1079
  if (check_for_node(root, "no_reduce")) {
9,507 ✔
1080
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
30 ✔
1081
  }
1082

1083
  // Check if the user has specified to use confidence intervals for
1084
  // uncertainties rather than standard deviations
1085
  if (check_for_node(root, "confidence_intervals")) {
9,507 ✔
1086
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
15 ✔
1087
  }
1088

1089
  // Check for output options
1090
  if (check_for_node(root, "output")) {
9,507 ✔
1091
    // Get pointer to output node
1092
    pugi::xml_node node_output = root.child("output");
892 ✔
1093

1094
    // Check for summary option
1095
    if (check_for_node(node_output, "summary")) {
892 ✔
1096
      output_summary = get_node_value_bool(node_output, "summary");
866 ✔
1097
    }
1098

1099
    // Check for ASCII tallies output option
1100
    if (check_for_node(node_output, "tallies")) {
892 ✔
1101
      output_tallies = get_node_value_bool(node_output, "tallies");
382 ✔
1102
    }
1103

1104
    // Set output directory if a path has been specified
1105
    if (check_for_node(node_output, "path")) {
892 !
1106
      path_output = get_node_value(node_output, "path");
×
1107
      if (!ends_with(path_output, "/")) {
×
1108
        path_output += "/";
892 !
1109
      }
1110
    }
1111
  }
1112

1113
  // Resonance scattering parameters
1114
  if (check_for_node(root, "resonance_scattering")) {
9,507 ✔
1115
    xml_node node_res_scat = root.child("resonance_scattering");
15 ✔
1116

1117
    // See if resonance scattering is enabled
1118
    if (check_for_node(node_res_scat, "enable")) {
15 !
1119
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
15 ✔
1120
    } else {
1121
      res_scat_on = true;
×
1122
    }
1123

1124
    // Determine what method is used
1125
    if (check_for_node(node_res_scat, "method")) {
15 !
1126
      auto temp = get_node_value(node_res_scat, "method", true, true);
15 ✔
1127
      if (temp == "rvs") {
15 !
1128
        res_scat_method = ResScatMethod::rvs;
15 ✔
1129
      } else if (temp == "dbrc") {
×
1130
        res_scat_method = ResScatMethod::dbrc;
×
1131
      } else {
1132
        fatal_error(
×
1133
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1134
      }
1135
    }
15 ✔
1136

1137
    // Minimum energy for resonance scattering
1138
    if (check_for_node(node_res_scat, "energy_min")) {
15 !
1139
      res_scat_energy_min =
30 ✔
1140
        std::stod(get_node_value(node_res_scat, "energy_min"));
30 ✔
1141
    }
1142
    if (res_scat_energy_min < 0.0) {
15 !
1143
      fatal_error("Lower resonance scattering energy bound is negative");
×
1144
    }
1145

1146
    // Maximum energy for resonance scattering
1147
    if (check_for_node(node_res_scat, "energy_max")) {
15 !
1148
      res_scat_energy_max =
30 ✔
1149
        std::stod(get_node_value(node_res_scat, "energy_max"));
30 ✔
1150
    }
1151
    if (res_scat_energy_max < res_scat_energy_min) {
15 !
1152
      fatal_error("Upper resonance scattering energy bound is below the "
×
1153
                  "lower resonance scattering energy bound.");
1154
    }
1155

1156
    // Get resonance scattering nuclides
1157
    if (check_for_node(node_res_scat, "nuclides")) {
15 !
1158
      res_scat_nuclides =
15 ✔
1159
        get_node_array<std::string>(node_res_scat, "nuclides");
30 ✔
1160
    }
1161
  }
1162

1163
  // Get volume calculations
1164
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
9,817 ✔
1165
    model::volume_calcs.emplace_back(node_vol);
310 ✔
1166
  }
1167

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

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

1202
  // Check for tabular_legendre options
1203
  if (check_for_node(root, "tabular_legendre")) {
9,507 ✔
1204
    // Get pointer to tabular_legendre node
1205
    xml_node node_tab_leg = root.child("tabular_legendre");
105 ✔
1206

1207
    // Check for enable option
1208
    if (check_for_node(node_tab_leg, "enable")) {
105 !
1209
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
105 ✔
1210
    }
1211

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

1224
  // Check whether create delayed neutrons in fission
1225
  if (check_for_node(root, "create_delayed_neutrons")) {
9,507 !
1226
    create_delayed_neutrons =
×
1227
      get_node_value_bool(root, "create_delayed_neutrons");
×
1228
  }
1229

1230
  // Check whether create fission sites
1231
  if (run_mode == RunMode::FIXED_SOURCE) {
9,507 ✔
1232
    if (check_for_node(root, "create_fission_neutrons")) {
3,604 ✔
1233
      create_fission_neutrons =
336 ✔
1234
        get_node_value_bool(root, "create_fission_neutrons");
336 ✔
1235
    }
1236
  }
1237

1238
  // Check whether to scale fission photon yields
1239
  if (check_for_node(root, "delayed_photon_scaling")) {
9,507 !
1240
    delayed_photon_scaling =
×
1241
      get_node_value_bool(root, "delayed_photon_scaling");
×
1242
  }
1243

1244
  // Check whether to use event-based parallelism
1245
  if (check_for_node(root, "event_based")) {
9,507 !
1246
    event_based = get_node_value_bool(root, "event_based");
×
1247
  }
1248

1249
  // Check whether material cell offsets should be generated
1250
  if (check_for_node(root, "material_cell_offsets")) {
9,507 !
1251
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1252
  }
1253

1254
  // Weight window information
1255
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
9,812 ✔
1256
    variance_reduction::weight_windows.emplace_back(
305 ✔
1257
      std::make_unique<WeightWindows>(node_ww));
610 ✔
1258
  }
1259

1260
  // Enable weight windows by default if one or more are present
1261
  if (variance_reduction::weight_windows.size() > 0)
9,507 ✔
1262
    settings::weight_windows_on = true;
209 ✔
1263

1264
  // read weight windows from file
1265
  if (check_for_node(root, "weight_windows_file")) {
9,507 ✔
1266
    weight_windows_file = get_node_value(root, "weight_windows_file");
26 ✔
1267
    weight_windows_on = true;
26 ✔
1268
  }
1269

1270
  // read settings for weight windows value, this will override
1271
  // the automatic setting even if weight windows are present
1272
  if (check_for_node(root, "weight_windows_on")) {
9,507 ✔
1273
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
93 ✔
1274
  }
1275

1276
  if (check_for_node(root, "max_secondaries")) {
9,507 !
1277
    settings::max_secondaries =
×
1278
      std::stoi(get_node_value(root, "max_secondaries"));
×
1279
  }
1280

1281
  if (check_for_node(root, "max_history_splits")) {
9,507 ✔
1282
    settings::max_history_splits =
798 ✔
1283
      std::stoi(get_node_value(root, "max_history_splits"));
798 ✔
1284
  }
1285

1286
  if (check_for_node(root, "max_tracks")) {
9,507 ✔
1287
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
90 ✔
1288
  }
1289

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

1318
  // Set up weight window checkpoints
1319
  if (check_for_node(root, "weight_window_checkpoints")) {
9,507 ✔
1320
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
184 ✔
1321
    if (check_for_node(ww_checkpoints, "collision")) {
184 !
1322
      weight_window_checkpoint_collision =
184 ✔
1323
        get_node_value_bool(ww_checkpoints, "collision");
184 ✔
1324
    }
1325
    if (check_for_node(ww_checkpoints, "surface")) {
184 !
1326
      weight_window_checkpoint_surface =
184 ✔
1327
        get_node_value_bool(ww_checkpoints, "surface");
184 ✔
1328
    }
1329
  }
1330

1331
  if (weight_windows_on) {
9,507 ✔
1332
    if (!weight_window_checkpoint_surface &&
366 ✔
1333
        !weight_window_checkpoint_collision)
193 !
1334
      fatal_error(
×
1335
        "Weight Windows are enabled but there are no valid checkpoints.");
1336
  }
1337

1338
  if (check_for_node(root, "use_decay_photons")) {
9,507 ✔
1339
    settings::use_decay_photons =
11 ✔
1340
      get_node_value_bool(root, "use_decay_photons");
11 ✔
1341
  }
1342

1343
  // If weight windows are on, also enable shared secondary bank (unless
1344
  // explicitly disabled by user).
1345
  if (check_for_node(root, "shared_secondary_bank")) {
9,507 ✔
1346
    bool val = get_node_value_bool(root, "shared_secondary_bank");
335 ✔
1347
    if (val && run_mode == RunMode::EIGENVALUE) {
335 !
1348
      warning(
×
1349
        "Shared secondary bank is not supported in eigenvalue calculations. "
1350
        "Setting will be ignored.");
1351
    } else {
1352
      settings::use_shared_secondary_bank = val;
335 ✔
1353
    }
1354
  } else if (settings::weight_windows_on) {
9,172 ✔
1355
    if (run_mode == RunMode::EIGENVALUE) {
184 !
1356
      warning(
×
1357
        "Shared secondary bank is not supported in eigenvalue calculations. "
1358
        "Particle local secondary banks will be used instead.");
1359
    } else if (run_mode == RunMode::FIXED_SOURCE) {
184 !
1360
      settings::use_shared_secondary_bank = true;
184 ✔
1361
    }
1362
  }
1363
}
9,507 ✔
1364

1365
void free_memory_settings()
9,658 ✔
1366
{
1367
  settings::statepoint_batch.clear();
9,658 ✔
1368
  settings::sourcepoint_batch.clear();
9,658 ✔
1369
  settings::source_write_surf_id.clear();
9,658 ✔
1370
  settings::res_scat_nuclides.clear();
9,658 ✔
1371
  settings::ifp_delayed_group_on = false;
9,658 ✔
1372
  settings::ifp_lifetime_on = false;
9,658 ✔
1373
}
9,658 ✔
1374

1375
//==============================================================================
1376
// C API functions
1377
//==============================================================================
1378

1379
namespace {
1380

1381
int invalid_setting(const char* type, const char* name)
×
1382
{
1383
  set_errmsg(fmt::format("Unknown {} setting '{}'.", type, name));
×
1384
  return OPENMC_E_INVALID_ARGUMENT;
×
1385
}
1386

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

1415
} // namespace
1416

1417
extern "C" int openmc_setting_get_bool(const char* name, bool* value)
3,069 ✔
1418
{
1419
  if (!name || !value) {
3,069 !
1420
    set_errmsg("Setting name and output pointer must not be null.");
×
1421
    return OPENMC_E_INVALID_ARGUMENT;
×
1422
  }
1423

1424
  bool* setting = bool_setting(name);
3,069 ✔
1425
  if (!setting)
3,069 !
1426
    return invalid_setting("boolean", name);
×
1427

1428
  *value = *setting;
3,069 ✔
1429
  return 0;
3,069 ✔
1430
}
1431

1432
extern "C" int openmc_setting_set_bool(const char* name, bool value)
1,397 ✔
1433
{
1434
  if (!name) {
1,397 !
1435
    set_errmsg("Setting name must not be null.");
×
1436
    return OPENMC_E_INVALID_ARGUMENT;
×
1437
  }
1438

1439
  bool* setting = bool_setting(name);
1,397 ✔
1440
  if (!setting)
1,397 !
1441
    return invalid_setting("boolean", name);
×
1442

1443
  *setting = value;
1,397 ✔
1444
  return 0;
1,397 ✔
1445
}
1446

1447
extern "C" int openmc_setting_get_int32(const char* name, int32_t* value)
1,221 ✔
1448
{
1449
  if (!name || !value) {
1,221 !
1450
    set_errmsg("Setting name and output pointer must not be null.");
×
1451
    return OPENMC_E_INVALID_ARGUMENT;
×
1452
  }
1453

1454
  if (std::strcmp(name, "gen_per_batch") == 0) {
1,221 ✔
1455
    *value = settings::gen_per_batch;
44 ✔
1456
  } else if (std::strcmp(name, "max_lost_particles") == 0) {
1,177 ✔
1457
    *value = settings::max_lost_particles;
33 ✔
1458
  } else if (std::strcmp(name, "max_write_lost_particles") == 0) {
1,144 ✔
1459
    *value = settings::max_write_lost_particles;
33 ✔
1460
  } else if (std::strcmp(name, "n_inactive") == 0) {
1,111 ✔
1461
    *value = settings::n_inactive;
44 ✔
1462
  } else if (std::strcmp(name, "run_mode") == 0) {
1,067 ✔
1463
    *value = static_cast<int32_t>(settings::run_mode);
22 ✔
1464
  } else if (std::strcmp(name, "verbosity") == 0) {
1,045 !
1465
    *value = settings::verbosity;
1,045 ✔
1466
  } else {
1467
    return invalid_setting("int32", name);
×
1468
  }
1469
  return 0;
1470
}
1471

1472
extern "C" int openmc_setting_set_int32(const char* name, int32_t value)
132 ✔
1473
{
1474
  if (!name) {
132 !
1475
    set_errmsg("Setting name must not be null.");
×
1476
    return OPENMC_E_INVALID_ARGUMENT;
×
1477
  }
1478

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

1502
extern "C" int openmc_setting_get_int64(const char* name, int64_t* value)
121 ✔
1503
{
1504
  if (!name || !value) {
121 !
1505
    set_errmsg("Setting name and output pointer must not be null.");
×
1506
    return OPENMC_E_INVALID_ARGUMENT;
×
1507
  }
1508

1509
  if (std::strcmp(name, "n_particles") != 0)
121 !
1510
    return invalid_setting("int64", name);
×
1511

1512
  *value = settings::n_particles;
121 ✔
1513
  return 0;
121 ✔
1514
}
1515

1516
extern "C" int openmc_setting_set_int64(const char* name, int64_t value)
99 ✔
1517
{
1518
  if (!name) {
99 !
1519
    set_errmsg("Setting name must not be null.");
×
1520
    return OPENMC_E_INVALID_ARGUMENT;
×
1521
  }
1522

1523
  if (std::strcmp(name, "n_particles") != 0)
99 !
1524
    return invalid_setting("int64", name);
×
1525

1526
  settings::n_particles = value;
99 ✔
1527
  return 0;
99 ✔
1528
}
1529

1530
extern "C" int openmc_setting_get_double(const char* name, double* value)
33 ✔
1531
{
1532
  if (!name || !value) {
33 !
1533
    set_errmsg("Setting name and output pointer must not be null.");
×
1534
    return OPENMC_E_INVALID_ARGUMENT;
×
1535
  }
1536

1537
  if (std::strcmp(name, "rel_max_lost_particles") != 0)
33 !
1538
    return invalid_setting("double", name);
×
1539

1540
  *value = settings::rel_max_lost_particles;
33 ✔
1541
  return 0;
33 ✔
1542
}
1543

1544
extern "C" int openmc_setting_set_double(const char* name, double value)
22 ✔
1545
{
1546
  if (!name) {
22 !
1547
    set_errmsg("Setting name must not be null.");
×
1548
    return OPENMC_E_INVALID_ARGUMENT;
×
1549
  }
1550

1551
  if (std::strcmp(name, "rel_max_lost_particles") != 0)
22 !
1552
    return invalid_setting("double", name);
×
1553

1554
  settings::rel_max_lost_particles = value;
22 ✔
1555
  return 0;
22 ✔
1556
}
1557

1558
extern "C" int openmc_setting_get_string(const char* name, const char** value)
22 ✔
1559
{
1560
  if (!name || !value) {
22 !
1561
    set_errmsg("Setting name and output pointer must not be null.");
×
1562
    return OPENMC_E_INVALID_ARGUMENT;
×
1563
  }
1564

1565
  if (std::strcmp(name, "path_statepoint") != 0)
22 !
1566
    return invalid_setting("string", name);
×
1567

1568
  *value = settings::path_statepoint.c_str();
22 ✔
1569
  return 0;
22 ✔
1570
}
1571

1572
extern "C" int openmc_set_n_batches(
220 ✔
1573
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1574
{
1575
  if (settings::n_inactive >= n_batches) {
220 ✔
1576
    set_errmsg("Number of active batches must be greater than zero.");
11 ✔
1577
    return OPENMC_E_INVALID_ARGUMENT;
11 ✔
1578
  }
1579

1580
  if (!settings::trigger_on) {
209 ✔
1581
    // Set n_batches and n_max_batches to same value
1582
    settings::n_batches = n_batches;
187 ✔
1583
    settings::n_max_batches = n_batches;
187 ✔
1584
  } else {
1585
    // Set n_batches and n_max_batches based on value of set_max_batches
1586
    if (set_max_batches) {
22 ✔
1587
      settings::n_max_batches = n_batches;
11 ✔
1588
    } else {
1589
      settings::n_batches = n_batches;
11 ✔
1590
    }
1591
  }
1592

1593
  // Update size of k_generation and entropy
1594
  int m = settings::n_max_batches * settings::gen_per_batch;
209 ✔
1595
  simulation::k_generation.reserve(m);
209 ✔
1596
  simulation::entropy.reserve(m);
209 ✔
1597

1598
  // Add value of n_batches to statepoint_batch
1599
  if (add_statepoint_batch &&
209 ✔
1600
      !(contains(settings::statepoint_batch, n_batches)))
198 ✔
1601
    settings::statepoint_batch.insert(n_batches);
33 ✔
1602

1603
  return 0;
1604
}
1605

1606
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,530 ✔
1607
{
1608
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,530 ✔
1609

1610
  return 0;
2,530 ✔
1611
}
1612

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