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

openmc-dev / openmc / 38075920163

10 Oct 2026 06:28PM UTC coverage: 81.473% (+0.03%) from 81.44%
38075920163

Pull #3971

github

web-flow
Merge 660c1eca0 into aa4afc41e
Pull Request #3971: Delta tracking

20444 of 29679 branches covered (68.88%)

Branch coverage included in aggregate %.

598 of 644 new or added lines in 20 files covered. (92.86%)

6 existing lines in 3 files now uncovered.

63211 of 72999 relevant lines covered (86.59%)

43179699.87 hits per line

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

76.08
/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 delta_tracking {false};
58
bool entropy_on {false};
59
bool event_based {false};
60
bool ifp_delayed_group_on {false};
61
bool ifp_lifetime_on {false};
62
bool legendre_to_tabular {true};
63
bool material_cell_offsets {true};
64
bool output_summary {true};
65
bool output_tallies {true};
66
bool particle_restart_run {false};
67
bool photon_transport {false};
68
bool atomic_relaxation {true};
69
bool reduce_tallies {true};
70
bool res_scat_on {false};
71
bool restart_run {false};
72
bool run_CE {true};
73
bool source_latest {false};
74
bool source_separate {false};
75
bool source_write {true};
76
bool source_mcpl_write {false};
77
bool surf_source_write {false};
78
bool surf_mcpl_write {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)
6,157 ✔
164
{
165
  using namespace settings;
6,157 ✔
166
  using namespace pugi;
6,157 ✔
167

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

197
  // Get max number of lost particles
198
  if (check_for_node(node_base, "max_lost_particles")) {
6,157 ✔
199
    max_lost_particles =
62 ✔
200
      std::stoi(get_node_value(node_base, "max_lost_particles"));
31 ✔
201
  }
202

203
  // Get relative number of lost particles
204
  if (check_for_node(node_base, "rel_max_lost_particles")) {
6,157 !
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")) {
6,157 ✔
211
    max_write_lost_particles =
20 ✔
212
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
10 ✔
213
  }
214

215
  // Get number of inactive batches
216
  if (run_mode == RunMode::EIGENVALUE ||
6,157 ✔
217
      solver_type == SolverType::RANDOM_RAY) {
2,668 ✔
218
    if (check_for_node(node_base, "inactive")) {
3,912 ✔
219
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
3,701 ✔
220
    }
221
    if (check_for_node(node_base, "generations_per_batch")) {
3,912 ✔
222
      gen_per_batch =
20 ✔
223
        std::stoi(get_node_value(node_base, "generations_per_batch"));
10 ✔
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) {
10 !
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;
3,912 ✔
237
    simulation::k_generation.reserve(m);
3,912 ✔
238
    simulation::entropy.reserve(m);
3,912 ✔
239

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

244
      if (check_for_node(node_keff_trigger, "type")) {
68 !
245
        auto temp = get_node_value(node_keff_trigger, "type", true, true);
68 ✔
246
        if (temp == "std_dev") {
68 !
247
          keff_trigger.metric = TriggerMetric::standard_deviation;
68 ✔
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")) {
68 !
260
        keff_trigger.threshold =
136 ✔
261
          std::stod(get_node_value(node_keff_trigger, "threshold"));
136 ✔
262
        if (keff_trigger.threshold <= 0) {
68 !
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) {
6,157 ✔
273
    xml_node random_ray_node = node_base.child("random_ray");
711 ✔
274
    if (check_for_node(random_ray_node, "distance_active")) {
711 !
275
      RandomRay::distance_active_ =
1,422 ✔
276
        std::stod(get_node_value(random_ray_node, "distance_active"));
1,422 ✔
277
      if (RandomRay::distance_active_ <= 0.0) {
711 !
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")) {
711 !
284
      RandomRay::distance_inactive_ =
1,422 ✔
285
        std::stod(get_node_value(random_ray_node, "distance_inactive"));
1,422 ✔
286
      if (RandomRay::distance_inactive_ < 0) {
711 !
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")) {
711 !
294
      xml_node ray_source_node = random_ray_node.child("ray_source");
711 ✔
295
      xml_node source_node = ray_source_node.child("source");
711 ✔
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,422 ✔
299
    } else {
300
      fatal_error("Specify random ray source in settings XML");
×
301
    }
302
    if (check_for_node(random_ray_node, "volume_estimator")) {
711 ✔
303
      std::string temp_str =
445 ✔
304
        get_node_value(random_ray_node, "volume_estimator", true, true);
445 ✔
305
      if (temp_str == "simulation_averaged") {
445 ✔
306
        FlatSourceDomain::volume_estimator_ =
20 ✔
307
          RandomRayVolumeEstimator::SIMULATION_AVERAGED;
308
      } else if (temp_str == "naive") {
425 ✔
309
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::NAIVE;
89 ✔
310
      } else if (temp_str == "hybrid") {
336 ✔
311
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::HYBRID;
246 ✔
312
      } else if (temp_str == "adaptive") {
90 ✔
313
        FlatSourceDomain::volume_estimator_ =
60 ✔
314
          RandomRayVolumeEstimator::ADAPTIVE;
315
      } else if (temp_str == "strict_adaptive") {
30 !
316
        FlatSourceDomain::volume_estimator_ =
30 ✔
317
          RandomRayVolumeEstimator::STRICT_ADAPTIVE;
318
      } else if (temp_str == "auto") {
×
319
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::AUTO;
×
320
      } else {
321
        fatal_error("Unrecognized volume estimator: " + temp_str);
×
322
      }
323
    }
445 ✔
324
    if (check_for_node(random_ray_node, "source_shape")) {
711 ✔
325
      std::string temp_str =
366 ✔
326
        get_node_value(random_ray_node, "source_shape", true, true);
366 ✔
327
      if (temp_str == "flat") {
366 ✔
328
        RandomRay::source_shape_ = RandomRaySourceShape::FLAT;
66 ✔
329
      } else if (temp_str == "linear") {
300 ✔
330
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR;
270 ✔
331
      } else if (temp_str == "linear_xy") {
30 !
332
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR_XY;
30 ✔
333
      } else {
334
        fatal_error("Unrecognized source shape: " + temp_str);
×
335
      }
336
    }
366 ✔
337
    if (check_for_node(random_ray_node, "volume_normalized_flux_tallies")) {
711 ✔
338
      FlatSourceDomain::volume_normalized_flux_tallies_ =
494 ✔
339
        get_node_value_bool(random_ray_node, "volume_normalized_flux_tallies");
494 ✔
340
    }
341
    if (check_for_node(random_ray_node, "adjoint")) {
711 ✔
342
      FlatSourceDomain::adjoint_requested_ =
58 ✔
343
        get_node_value_bool(random_ray_node, "adjoint");
58 ✔
344
    }
345
    if (check_for_node(random_ray_node, "source_gradient_limiter")) {
711 ✔
346
      FlatSourceDomain::source_gradient_limiter_ =
10 ✔
347
        get_node_value_bool(random_ray_node, "source_gradient_limiter");
10 ✔
348
    }
349
    if (check_for_node(random_ray_node, "sample_method")) {
711 ✔
350
      std::string temp_str =
36 ✔
351
        get_node_value(random_ray_node, "sample_method", true, true);
36 ✔
352
      if (temp_str == "prng") {
36 !
353
        RandomRay::sample_method_ = RandomRaySampleMethod::PRNG;
×
354
      } else if (temp_str == "halton") {
36 ✔
355
        RandomRay::sample_method_ = RandomRaySampleMethod::HALTON;
26 ✔
356
      } else if (temp_str == "s2") {
10 !
357
        RandomRay::sample_method_ = RandomRaySampleMethod::S2;
10 ✔
358
      } else {
359
        fatal_error("Unrecognized sample method: " + temp_str);
×
360
      }
361
    }
36 ✔
362
    if (check_for_node(random_ray_node, "source_region_meshes")) {
711 ✔
363
      pugi::xml_node node_source_region_meshes =
307 ✔
364
        random_ray_node.child("source_region_meshes");
307 ✔
365
      for (pugi::xml_node node_mesh :
654 ✔
366
        node_source_region_meshes.children("mesh")) {
654 ✔
367
        int mesh_id = std::stoi(node_mesh.attribute("id").value());
694 ✔
368
        for (pugi::xml_node node_domain : node_mesh.children("domain")) {
694 ✔
369
          int domain_id = std::stoi(node_domain.attribute("id").value());
694 ✔
370
          std::string domain_type = node_domain.attribute("type").value();
347 ✔
371
          Source::DomainType type;
347 ✔
372
          if (domain_type == "material") {
347 ✔
373
            type = Source::DomainType::MATERIAL;
20 ✔
374
          } else if (domain_type == "cell") {
327 ✔
375
            type = Source::DomainType::CELL;
20 ✔
376
          } else if (domain_type == "universe") {
307 !
377
            type = Source::DomainType::UNIVERSE;
307 ✔
378
          } else {
379
            throw std::runtime_error("Unknown domain type: " + domain_type);
×
380
          }
381
          FlatSourceDomain::mesh_domain_map_[mesh_id].emplace_back(
347 ✔
382
            type, domain_id);
383
        }
347 ✔
384
      }
385
    }
386
    if (check_for_node(random_ray_node, "diagonal_stabilization_rho")) {
711 ✔
387
      FlatSourceDomain::diagonal_stabilization_rho_ = std::stod(
20 ✔
388
        get_node_value(random_ray_node, "diagonal_stabilization_rho"));
20 ✔
389
      if (FlatSourceDomain::diagonal_stabilization_rho_ < 0.0 ||
20 !
390
          FlatSourceDomain::diagonal_stabilization_rho_ > 1.0) {
391
        fatal_error("Random ray diagonal stabilization rho factor must be "
×
392
                    "between 0 and 1");
393
      }
394
    }
395
    if (check_for_node(random_ray_node, "adjoint_source")) {
711 ✔
396
      pugi::xml_node adj_source_node = random_ray_node.child("adjoint_source");
10 ✔
397
      for (pugi::xml_node source_node : adj_source_node.children("source")) {
20 ✔
398
        // Find any local adjoint sources
399
        model::adjoint_sources.push_back(Source::create(source_node));
20 ✔
400
      }
401
    }
402
  }
403
}
6,157 ✔
404

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

424
  // Parse settings.xml file
425
  xml_document doc;
1,002 ✔
426
  auto result = doc.load_file(filename.c_str());
1,002 ✔
427
  if (!result) {
1,002 !
428
    fatal_error("Error processing settings.xml file.");
×
429
  }
430

431
  // Get root element
432
  xml_node root = doc.document_element();
1,002 ✔
433

434
  // Verbosity
435
  if (check_for_node(root, "verbosity") && verbosity == -1) {
1,002 !
436
    verbosity = std::stoi(get_node_value(root, "verbosity"));
310 ✔
437
  } else if (verbosity == -1) {
847 !
438
    verbosity = 7;
847 ✔
439
  }
440

441
  // To this point, we haven't displayed any output since we didn't know what
442
  // the verbosity is. Now that we checked for it, show the title if necessary
443
  if (mpi::master) {
1,002 ✔
444
    if (verbosity >= 2)
906 ✔
445
      title();
755 ✔
446
  }
447

448
  write_message("Reading settings XML file...", 5);
1,002 ✔
449

450
  read_settings_xml(root);
1,002 ✔
451
}
1,011 ✔
452

453
void read_settings_xml(pugi::xml_node root)
6,955 ✔
454
{
455
  using namespace settings;
6,955 ✔
456
  using namespace pugi;
6,955 ✔
457

458
  // Find if a multi-group or continuous-energy simulation is desired
459
  if (check_for_node(root, "energy_mode")) {
6,955 ✔
460
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
1,091 ✔
461
    if (temp_str == "mg" || temp_str == "multi-group") {
2,182 !
462
      run_CE = false;
1,091 ✔
463
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
464
      run_CE = true;
×
465
    }
466
  }
1,091 ✔
467

468
  // Check for user meshes and allocate
469
  read_meshes(root);
6,955 ✔
470

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

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

495
  // Check for a trigger node and get trigger information
496
  if (check_for_node(root, "trigger")) {
6,955 ✔
497
    xml_node node_trigger = root.child("trigger");
124 ✔
498

499
    // Check if trigger(s) are to be turned on
500
    trigger_on = get_node_value_bool(node_trigger, "active");
124 ✔
501

502
    if (trigger_on) {
124 ✔
503
      if (check_for_node(node_trigger, "max_batches")) {
114 !
504
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
228 ✔
505
      } else {
506
        fatal_error("<max_batches> must be specified with triggers");
×
507
      }
508

509
      // Get the batch interval to check triggers
510
      if (!check_for_node(node_trigger, "batch_interval")) {
114 ✔
511
        trigger_predict = true;
10 ✔
512
      } else {
513
        trigger_batch_interval =
208 ✔
514
          std::stoi(get_node_value(node_trigger, "batch_interval"));
208 ✔
515
        if (trigger_batch_interval <= 0) {
104 !
516
          fatal_error("Trigger batch interval must be greater than zero");
×
517
        }
518
      }
519
    }
520
  }
521

522
  // Check run mode if it hasn't been set from the command line
523
  xml_node node_mode;
6,955 ✔
524
  if (run_mode == RunMode::UNSET) {
6,955 ✔
525
    if (check_for_node(root, "run_mode")) {
6,179 ✔
526
      std::string temp_str = get_node_value(root, "run_mode", true, true);
6,159 ✔
527
      if (temp_str == "eigenvalue") {
6,159 ✔
528
        run_mode = RunMode::EIGENVALUE;
3,469 ✔
529
      } else if (temp_str == "fixed source") {
2,690 ✔
530
        run_mode = RunMode::FIXED_SOURCE;
2,668 ✔
531
      } else if (temp_str == "plot") {
22 !
532
        run_mode = RunMode::PLOTTING;
×
533
      } else if (temp_str == "particle restart") {
22 !
534
        run_mode = RunMode::PARTICLE;
×
535
      } else if (temp_str == "volume") {
22 !
536
        run_mode = RunMode::VOLUME;
22 ✔
537
      } else {
538
        fatal_error("Unrecognized run mode: " + temp_str);
×
539
      }
540

541
      // Assume XML specifies <particles>, <batches>, etc. directly
542
      node_mode = root;
6,159 ✔
543
    } else {
6,159 ✔
544
      warning("<run_mode> should be specified.");
20 ✔
545

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

561
  // Check solver type
562
  if (check_for_node(root, "random_ray")) {
6,955 ✔
563
    solver_type = SolverType::RANDOM_RAY;
711 ✔
564
    if (run_CE)
711 !
565
      fatal_error("multi-group energy mode must be specified in settings XML "
×
566
                  "when using the random ray solver.");
567
  }
568

569
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
6,955 ✔
570
    // Read run parameters
571
    get_run_parameters(node_mode);
6,157 ✔
572

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

587
    // Check for user value for the number of generation of the Iterated Fission
588
    // Probability (IFP) method
589
    if (check_for_node(root, "ifp_n_generation")) {
6,157 ✔
590
      ifp_n_generation = std::stoi(get_node_value(root, "ifp_n_generation"));
150 ✔
591
      if (ifp_n_generation <= 0) {
75 !
592
        fatal_error("'ifp_n_generation' must be greater than 0.");
×
593
      }
594
      // Avoid tallying 0 if IFP logs are not complete when active cycles start
595
      if (ifp_n_generation > n_inactive) {
75 ✔
596
        fatal_error("'ifp_n_generation' must be lower than or equal to the "
7 ✔
597
                    "number of inactive cycles.");
598
      }
599
    }
600
  }
601

602
  // Copy plotting random number seed if specified
603
  if (check_for_node(root, "plot_seed")) {
6,948 !
604
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
605
    model::plotter_seed = seed;
×
606
  }
607

608
  // Copy random number seed if specified
609
  if (check_for_node(root, "seed")) {
6,948 ✔
610
    auto seed = std::stoll(get_node_value(root, "seed"));
846 ✔
611
    openmc_set_seed(seed);
423 ✔
612
  }
613

614
  // Copy random number stride if specified
615
  if (check_for_node(root, "stride")) {
6,948 ✔
616
    auto stride = std::stoull(get_node_value(root, "stride"));
20 ✔
617
    openmc_set_stride(stride);
10 ✔
618
  }
619

620
  // Check for electron treatment
621
  if (check_for_node(root, "electron_treatment")) {
6,948 ✔
622
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
90 ✔
623
    if (temp_str == "led") {
90 ✔
624
      electron_treatment = ElectronTreatment::LED;
44 ✔
625
    } else if (temp_str == "ttb") {
46 !
626
      electron_treatment = ElectronTreatment::TTB;
46 ✔
627
    } else {
628
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
629
    }
630
  }
90 ✔
631

632
  // Check for photon transport
633
  if (check_for_node(root, "photon_transport")) {
6,948 ✔
634
    photon_transport = get_node_value_bool(root, "photon_transport");
438 ✔
635

636
    if (!run_CE && photon_transport) {
438 !
637
      fatal_error("Photon transport is not currently supported in "
×
638
                  "multigroup mode");
639
    }
640
  }
641

642
  // Check for atomic relaxation
643
  if (check_for_node(root, "atomic_relaxation")) {
6,948 ✔
644
    atomic_relaxation = get_node_value_bool(root, "atomic_relaxation");
20 ✔
645
  }
646

647
  // Number of bins for logarithmic grid
648
  if (check_for_node(root, "log_grid_bins")) {
6,948 ✔
649
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
20 ✔
650
    if (n_log_bins < 1) {
10 !
651
      fatal_error("Number of bins for logarithmic grid must be greater "
×
652
                  "than zero.");
653
    }
654
  }
655

656
  // Number of OpenMP threads
657
  if (check_for_node(root, "threads")) {
6,948 !
658
    if (mpi::master)
×
659
      warning("The <threads> element has been deprecated. Use "
×
660
              "the OMP_NUM_THREADS environment variable to set the number of "
661
              "threads.");
662
  }
663

664
  // ==========================================================================
665
  // EXTERNAL SOURCE
666

667
  // Get point to list of <source> elements and make sure there is at least one
668
  for (pugi::xml_node node : root.children("source")) {
13,164 ✔
669
    model::external_sources.push_back(Source::create(node));
12,439 ✔
670
  }
671

672
  // Check if the user has specified to read surface source
673
  if (check_for_node(root, "surf_source_read")) {
6,941 ✔
674
    if (mpi::master)
20 ✔
675
      warning("The <surf_source_read> element has been deprecated. Use a file "
32 ✔
676
              "source instead, i.e., <source type=\"file\" "
677
              "file=\"surface_source.h5\"/>, which additionally supports a "
678
              "source strength and source constraints.");
679

680
    // Get surface source read node
681
    xml_node node_ssr = root.child("surf_source_read");
20 ✔
682

683
    std::string path = "surface_source.h5";
20 ✔
684
    // Check if the user has specified different file for surface source reading
685
    if (check_for_node(node_ssr, "path")) {
20 !
686
      path = get_node_value(node_ssr, "path", false, true);
20 ✔
687
    }
688
    model::external_sources.push_back(make_unique<FileSource>(path));
20 ✔
689
  }
20 ✔
690

691
  // If no source specified, default to isotropic point source at origin with
692
  // Watt spectrum. No default source is needed in random ray mode.
693
  if (model::external_sources.empty() &&
6,941 ✔
694
      settings::solver_type != SolverType::RANDOM_RAY) {
2,000 ✔
695
    double T[] {0.0};
1,862 ✔
696
    double p[] {1.0};
1,862 ✔
697
    model::external_sources.push_back(make_unique<IndependentSource>(
1,862 ✔
698
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
3,724 ✔
699
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
3,724 ✔
700
      UPtrDist {new Discrete(T, p, 1)}));
3,724 ✔
701
  }
702

703
  // Build probability mass function for sampling external sources
704
  vector<double> source_strengths;
6,941 ✔
705
  for (auto& s : model::external_sources) {
15,039 ✔
706
    source_strengths.push_back(s->strength());
8,098 ✔
707
  }
708
  model::external_sources_probability.assign(source_strengths);
6,941 ✔
709

710
  // Check if we want to write out source
711
  if (check_for_node(root, "write_initial_source")) {
6,941 !
712
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
713
  }
714

715
  // Get relative number of lost particles
716
  if (check_for_node(root, "source_rejection_fraction")) {
6,941 ✔
717
    source_rejection_fraction =
12 ✔
718
      std::stod(get_node_value(root, "source_rejection_fraction"));
12 !
719
  }
720

721
  if (check_for_node(root, "free_gas_threshold")) {
6,941 !
722
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
723
  }
724

725
  // Surface grazing
726
  if (check_for_node(root, "surface_grazing_cutoff"))
6,941 !
727
    surface_grazing_cutoff =
×
728
      std::stod(get_node_value(root, "surface_grazing_cutoff"));
×
729
  if (check_for_node(root, "surface_grazing_ratio"))
6,941 !
730
    surface_grazing_ratio =
×
731
      std::stod(get_node_value(root, "surface_grazing_ratio"));
×
732

733
  // Survival biasing
734
  if (check_for_node(root, "survival_biasing")) {
6,941 ✔
735
    survival_biasing = get_node_value_bool(root, "survival_biasing");
162 ✔
736
  }
737

738
  // Probability tables
739
  if (check_for_node(root, "ptables")) {
6,941 ✔
740
    urr_ptables_on = get_node_value_bool(root, "ptables");
10 ✔
741
  }
742

743
  // Cutoffs
744
  if (check_for_node(root, "cutoff")) {
6,941 ✔
745
    xml_node node_cutoff = root.child("cutoff");
110 ✔
746
    if (check_for_node(node_cutoff, "weight")) {
110 ✔
747
      weight_cutoff = std::stod(get_node_value(node_cutoff, "weight"));
20 ✔
748
    }
749
    if (check_for_node(node_cutoff, "weight_avg")) {
110 ✔
750
      weight_survive = std::stod(get_node_value(node_cutoff, "weight_avg"));
20 ✔
751
    }
752
    if (check_for_node(node_cutoff, "survival_normalization")) {
110 !
753
      survival_normalization =
×
754
        get_node_value_bool(node_cutoff, "survival_normalization");
×
755
    }
756
    if (check_for_node(node_cutoff, "energy_neutron")) {
110 ✔
757
      energy_cutoff[0] =
10 ✔
758
        std::stod(get_node_value(node_cutoff, "energy_neutron"));
20 ✔
759
    } else if (check_for_node(node_cutoff, "energy")) {
100 !
760
      warning("The use of an <energy> cutoff is deprecated and should "
×
761
              "be replaced by <energy_neutron>.");
762
      energy_cutoff[0] = std::stod(get_node_value(node_cutoff, "energy"));
×
763
    }
764
    if (check_for_node(node_cutoff, "energy_photon")) {
110 ✔
765
      energy_cutoff[1] =
72 ✔
766
        std::stod(get_node_value(node_cutoff, "energy_photon"));
144 ✔
767
    }
768
    if (check_for_node(node_cutoff, "energy_electron")) {
110 !
769
      energy_cutoff[2] =
×
770
        std::stof(get_node_value(node_cutoff, "energy_electron"));
×
771
    }
772
    if (check_for_node(node_cutoff, "energy_positron")) {
110 ✔
773
      energy_cutoff[3] =
8 ✔
774
        std::stod(get_node_value(node_cutoff, "energy_positron"));
16 ✔
775
    }
776
    if (check_for_node(node_cutoff, "time_neutron")) {
110 ✔
777
      time_cutoff[0] = std::stod(get_node_value(node_cutoff, "time_neutron"));
18 ✔
778
    }
779
    if (check_for_node(node_cutoff, "time_photon")) {
110 !
780
      time_cutoff[1] = std::stod(get_node_value(node_cutoff, "time_photon"));
×
781
    }
782
    if (check_for_node(node_cutoff, "time_electron")) {
110 !
783
      time_cutoff[2] = std::stod(get_node_value(node_cutoff, "time_electron"));
×
784
    }
785
    if (check_for_node(node_cutoff, "time_positron")) {
110 !
786
      time_cutoff[3] = std::stod(get_node_value(node_cutoff, "time_positron"));
×
787
    }
788
  }
789

790
  // read properties from file
791
  if (check_for_node(root, "properties_file")) {
6,941 ✔
792
    properties_file = get_node_value(root, "properties_file");
8 ✔
793
    if (!file_exists(properties_file)) {
8 !
794
      fatal_error(fmt::format("File '{}' does not exist.", properties_file));
×
795
    }
796
  }
797

798
  // Particle trace
799
  if (check_for_node(root, "trace")) {
6,941 ✔
800
    auto temp = get_node_array<int64_t>(root, "trace");
10 ✔
801
    if (temp.size() != 3) {
10 !
802
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
803
                  "batch, generation, and particle number.");
804
    }
805
    trace_batch = temp.at(0);
10 ✔
806
    trace_gen = temp.at(1);
10 ✔
807
    trace_particle = temp.at(2);
10 ✔
808
  }
10 ✔
809

810
  // Particle tracks
811
  if (check_for_node(root, "track")) {
6,941 ✔
812
    // Get values and make sure there are three per particle
813
    auto temp = get_node_array<int>(root, "track");
30 ✔
814
    if (temp.size() % 3 != 0) {
30 !
815
      fatal_error(
×
816
        "Number of integers specified in 'track' is not "
817
        "divisible by 3.  Please provide 3 integers per particle to be "
818
        "tracked.");
819
    }
820

821
    // Reshape into track_identifiers
822
    int n_tracks = temp.size() / 3;
30 ✔
823
    for (int i = 0; i < n_tracks; ++i) {
120 ✔
824
      track_identifiers.push_back(
90 ✔
825
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
90 ✔
826
    }
827
  }
30 ✔
828

829
  // Shannon entropy
830
  if (solver_type == SolverType::RANDOM_RAY) {
6,941 ✔
831
    if (check_for_node(root, "entropy_mesh")) {
711 !
832
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
833
                  "No user-defined entropy mesh is supported.");
834
    }
835
    entropy_on = true;
711 ✔
836
  } else if (solver_type == SolverType::MONTE_CARLO) {
6,230 !
837
    if (check_for_node(root, "entropy_mesh")) {
6,230 ✔
838
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
484 ✔
839
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
242 !
840
        fatal_error(fmt::format(
×
841
          "Mesh {} specified for Shannon entropy does not exist.", temp));
842
      }
843

844
      auto* m = dynamic_cast<RegularMesh*>(
242 !
845
        model::meshes[model::mesh_map.at(temp)].get());
242 !
846
      if (!m)
242 !
847
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
848
      simulation::entropy_mesh = m;
242 ✔
849

850
      // Turn on Shannon entropy calculation
851
      entropy_on = true;
242 ✔
852

853
    } else if (check_for_node(root, "entropy")) {
5,988 !
854
      fatal_error(
×
855
        "Specifying a Shannon entropy mesh via the <entropy> element "
856
        "is deprecated. Please create a mesh using <mesh> and then reference "
857
        "it by specifying its ID in an <entropy_mesh> element.");
858
    }
859
  }
860
  // Uniform fission source weighting mesh
861
  if (check_for_node(root, "ufs_mesh")) {
6,941 ✔
862
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
20 ✔
863
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
10 !
864
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
865
                              "method does not exist.",
866
        temp));
867
    }
868

869
    auto* m =
10 ✔
870
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
10 !
871
    if (!m)
10 !
872
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
873
    simulation::ufs_mesh = m;
10 ✔
874

875
    // Turn on uniform fission source weighting
876
    ufs_on = true;
10 ✔
877

878
  } else if (check_for_node(root, "uniform_fs")) {
6,931 !
879
    fatal_error(
×
880
      "Specifying a UFS mesh via the <uniform_fs> element "
881
      "is deprecated. Please create a mesh using <mesh> and then reference "
882
      "it by specifying its ID in a <ufs_mesh> element.");
883
  }
884

885
  // Check if the user has specified to write state points
886
  if (check_for_node(root, "state_point")) {
6,941 ✔
887

888
    // Get pointer to state_point node
889
    auto node_sp = root.child("state_point");
110 ✔
890

891
    // Determine number of batches at which to store state points
892
    if (check_for_node(node_sp, "batches")) {
110 !
893
      // User gave specific batches to write state points
894
      auto temp = get_node_array<int>(node_sp, "batches");
110 ✔
895
      for (const auto& b : temp) {
338 ✔
896
        statepoint_batch.insert(b);
228 ✔
897
      }
898
    } else {
110 ✔
899
      // If neither were specified, write state point at last batch
900
      statepoint_batch.insert(n_batches);
×
901
    }
902
  } else {
903
    // If no <state_point> tag was present, by default write state point at
904
    // last batch only
905
    statepoint_batch.insert(n_batches);
6,831 ✔
906
  }
907

908
  // Check if the user has specified to write source points
909
  if (check_for_node(root, "source_point")) {
6,941 ✔
910
    // Get source_point node
911
    xml_node node_sp = root.child("source_point");
68 ✔
912

913
    // Determine batches at which to store source points
914
    if (check_for_node(node_sp, "batches")) {
68 ✔
915
      // User gave specific batches to write source points
916
      auto temp = get_node_array<int>(node_sp, "batches");
30 ✔
917
      for (const auto& b : temp) {
80 ✔
918
        sourcepoint_batch.insert(b);
50 ✔
919
      }
920
    } else {
30 ✔
921
      // If neither were specified, write source points with state points
922
      sourcepoint_batch = statepoint_batch;
38 !
923
    }
924

925
    // Check if the user has specified to write binary source file
926
    if (check_for_node(node_sp, "separate")) {
68 ✔
927
      source_separate = get_node_value_bool(node_sp, "separate");
48 ✔
928
    }
929
    if (check_for_node(node_sp, "write")) {
68 !
930
      source_write = get_node_value_bool(node_sp, "write");
×
931
    }
932
    if (check_for_node(node_sp, "mcpl")) {
68 ✔
933
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
18 ✔
934
    }
935
    if (check_for_node(node_sp, "overwrite_latest")) {
68 ✔
936
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
10 ✔
937
      source_separate = source_latest;
10 ✔
938
    }
939
  } else {
940
    // If no <source_point> tag was present, by default we keep source bank in
941
    // statepoint file and write it out at statepoints intervals
942
    source_separate = false;
6,873 ✔
943
    sourcepoint_batch = statepoint_batch;
6,873 !
944
  }
945

946
  // Check is the user specified to convert strength to statistical weight
947
  if (check_for_node(root, "uniform_source_sampling")) {
6,941 ✔
948
    uniform_source_sampling =
40 ✔
949
      get_node_value_bool(root, "uniform_source_sampling");
40 ✔
950
  }
951

952
  // Check if the user has specified to write surface source
953
  if (check_for_node(root, "surf_source_write")) {
6,941 ✔
954
    surf_source_write = true;
299 ✔
955
    // Get surface source write node
956
    xml_node node_ssw = root.child("surf_source_write");
299 ✔
957

958
    // Determine surface ids at which crossing particles are to be banked.
959
    // If no surfaces are specified, all surfaces in the model will be used
960
    // to bank source points.
961
    if (check_for_node(node_ssw, "surface_ids")) {
299 ✔
962
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
144 ✔
963
      for (const auto& b : temp) {
707 ✔
964
        source_write_surf_id.insert(b);
563 ✔
965
      }
966
    }
144 ✔
967

968
    // Get maximum number of particles to be banked per surface
969
    if (check_for_node(node_ssw, "max_particles")) {
299 ✔
970
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
584 ✔
971
    } else {
972
      fatal_error("A maximum number of particles needs to be specified "
7 ✔
973
                  "using the 'max_particles' parameter to store surface "
974
                  "source points.");
975
    }
976

977
    // Get maximum number of surface source files to be created
978
    if (check_for_node(node_ssw, "max_source_files")) {
292 ✔
979
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
48 ✔
980
    } else {
981
      ssw_max_files = 1;
268 ✔
982
    }
983

984
    if (check_for_node(node_ssw, "mcpl")) {
292 ✔
985
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
8 ✔
986
    }
987
    // Get cell information
988
    if (check_for_node(node_ssw, "cell")) {
292 ✔
989
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
154 ✔
990
      ssw_cell_type = SSWCellType::Both;
77 ✔
991
    }
992
    if (check_for_node(node_ssw, "cellfrom")) {
292 ✔
993
      if (ssw_cell_id != C_NONE) {
66 ✔
994
        fatal_error(
14 ✔
995
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
996
      }
997
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
104 ✔
998
      ssw_cell_type = SSWCellType::From;
52 ✔
999
    }
1000
    if (check_for_node(node_ssw, "cellto")) {
278 ✔
1001
      if (ssw_cell_id != C_NONE) {
52 ✔
1002
        fatal_error(
14 ✔
1003
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
1004
      }
1005
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
76 ✔
1006
      ssw_cell_type = SSWCellType::To;
38 ✔
1007
    }
1008
  }
1009

1010
  // Check if the user has specified to write specific collisions
1011
  if (check_for_node(root, "collision_track")) {
6,906 ✔
1012
    settings::collision_track = true;
110 ✔
1013
    // Get collision track node
1014
    xml_node node_ct = root.child("collision_track");
110 ✔
1015
    collision_track_config = CollisionTrackConfig {};
110 ✔
1016

1017
    // Determine cell ids at which crossing particles are to be banked
1018
    if (check_for_node(node_ct, "cell_ids")) {
110 ✔
1019
      auto temp = get_node_array<int>(node_ct, "cell_ids");
62 ✔
1020
      for (const auto& b : temp) {
166 ✔
1021
        collision_track_config.cell_ids.insert(b);
104 ✔
1022
      }
1023
    }
62 ✔
1024
    if (check_for_node(node_ct, "reactions")) {
110 ✔
1025
      auto temp = get_node_array<std::string>(node_ct, "reactions");
44 ✔
1026
      for (const auto& b : temp) {
118 ✔
1027
        int reaction_int = reaction_mt(b);
74 ✔
1028
        if (reaction_int > 0) {
74 !
1029
          collision_track_config.mt_numbers.insert(reaction_int);
74 ✔
1030
        }
1031
      }
1032
    }
44 ✔
1033
    if (check_for_node(node_ct, "universe_ids")) {
110 ✔
1034
      auto temp = get_node_array<int>(node_ct, "universe_ids");
20 ✔
1035
      for (const auto& b : temp) {
40 ✔
1036
        collision_track_config.universe_ids.insert(b);
20 ✔
1037
      }
1038
    }
20 ✔
1039
    if (check_for_node(node_ct, "material_ids")) {
110 ✔
1040
      auto temp = get_node_array<int>(node_ct, "material_ids");
20 ✔
1041
      for (const auto& b : temp) {
50 ✔
1042
        collision_track_config.material_ids.insert(b);
30 ✔
1043
      }
1044
    }
20 ✔
1045
    if (check_for_node(node_ct, "nuclides")) {
110 ✔
1046
      auto temp = get_node_array<std::string>(node_ct, "nuclides");
20 ✔
1047
      for (const auto& b : temp) {
80 ✔
1048
        collision_track_config.nuclides.insert(b);
60 ✔
1049
      }
1050
    }
20 ✔
1051
    if (check_for_node(node_ct, "deposited_E_threshold")) {
110 ✔
1052
      collision_track_config.deposited_energy_threshold =
40 ✔
1053
        std::stod(get_node_value(node_ct, "deposited_E_threshold"));
40 ✔
1054
    }
1055
    // Get maximum number of particles to be banked per collision
1056
    if (check_for_node(node_ct, "max_collisions")) {
110 !
1057
      collision_track_config.max_collisions =
220 ✔
1058
        std::stoll(get_node_value(node_ct, "max_collisions"));
220 ✔
1059
    } else {
1060
      warning("A maximum number of collisions needs to be specified. "
×
1061
              "By default the code sets 'max_collisions' parameter equals to "
1062
              "1000.");
1063
    }
1064
    // Get maximum number of collision_track files to be created
1065
    if (check_for_node(node_ct, "max_collision_track_files")) {
110 !
1066
      collision_track_config.max_files =
×
1067
        std::stoll(get_node_value(node_ct, "max_collision_track_files"));
×
1068
    }
1069
    if (check_for_node(node_ct, "mcpl")) {
110 ✔
1070
      collision_track_config.mcpl_write = get_node_value_bool(node_ct, "mcpl");
16 ✔
1071
    }
1072
  }
1073

1074
  // If source is not separate and is to be written out in the statepoint
1075
  // file, make sure that the sourcepoint batch numbers are contained in the
1076
  // statepoint list
1077
  if (!source_separate) {
6,906 ✔
1078
    for (const auto& b : sourcepoint_batch) {
13,784 ✔
1079
      if (!contains(statepoint_batch, b)) {
13,872 !
1080
        fatal_error(
×
1081
          "Sourcepoint batches are not a subset of statepoint batches.");
1082
      }
1083
    }
1084
  }
1085

1086
  // Check if the user has specified to not reduce tallies at the end of every
1087
  // batch
1088
  if (check_for_node(root, "no_reduce")) {
6,906 ✔
1089
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
20 ✔
1090
  }
1091

1092
  // Check if the user has specified to use confidence intervals for
1093
  // uncertainties rather than standard deviations
1094
  if (check_for_node(root, "confidence_intervals")) {
6,906 ✔
1095
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
10 ✔
1096
  }
1097

1098
  // Check for output options
1099
  if (check_for_node(root, "output")) {
6,906 ✔
1100
    // Get pointer to output node
1101
    pugi::xml_node node_output = root.child("output");
631 ✔
1102

1103
    // Check for summary option
1104
    if (check_for_node(node_output, "summary")) {
631 ✔
1105
      output_summary = get_node_value_bool(node_output, "summary");
613 ✔
1106
    }
1107

1108
    // Check for ASCII tallies output option
1109
    if (check_for_node(node_output, "tallies")) {
631 ✔
1110
      output_tallies = get_node_value_bool(node_output, "tallies");
278 ✔
1111
    }
1112

1113
    // Set output directory if a path has been specified
1114
    if (check_for_node(node_output, "path")) {
631 !
1115
      path_output = get_node_value(node_output, "path");
×
1116
      if (!ends_with(path_output, "/")) {
×
1117
        path_output += "/";
631 !
1118
      }
1119
    }
1120
  }
1121

1122
  // Resonance scattering parameters
1123
  if (check_for_node(root, "resonance_scattering")) {
6,906 ✔
1124
    xml_node node_res_scat = root.child("resonance_scattering");
10 ✔
1125

1126
    // See if resonance scattering is enabled
1127
    if (check_for_node(node_res_scat, "enable")) {
10 !
1128
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
10 ✔
1129
    } else {
1130
      res_scat_on = true;
×
1131
    }
1132

1133
    // Determine what method is used
1134
    if (check_for_node(node_res_scat, "method")) {
10 !
1135
      auto temp = get_node_value(node_res_scat, "method", true, true);
10 ✔
1136
      if (temp == "rvs") {
10 !
1137
        res_scat_method = ResScatMethod::rvs;
10 ✔
1138
      } else if (temp == "dbrc") {
×
1139
        res_scat_method = ResScatMethod::dbrc;
×
1140
      } else {
1141
        fatal_error(
×
1142
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1143
      }
1144
    }
10 ✔
1145

1146
    // Minimum energy for resonance scattering
1147
    if (check_for_node(node_res_scat, "energy_min")) {
10 !
1148
      res_scat_energy_min =
20 ✔
1149
        std::stod(get_node_value(node_res_scat, "energy_min"));
20 ✔
1150
    }
1151
    if (res_scat_energy_min < 0.0) {
10 !
1152
      fatal_error("Lower resonance scattering energy bound is negative");
×
1153
    }
1154

1155
    // Maximum energy for resonance scattering
1156
    if (check_for_node(node_res_scat, "energy_max")) {
10 !
1157
      res_scat_energy_max =
20 ✔
1158
        std::stod(get_node_value(node_res_scat, "energy_max"));
20 ✔
1159
    }
1160
    if (res_scat_energy_max < res_scat_energy_min) {
10 !
1161
      fatal_error("Upper resonance scattering energy bound is below the "
×
1162
                  "lower resonance scattering energy bound.");
1163
    }
1164

1165
    // Get resonance scattering nuclides
1166
    if (check_for_node(node_res_scat, "nuclides")) {
10 !
1167
      res_scat_nuclides =
10 ✔
1168
        get_node_array<std::string>(node_res_scat, "nuclides");
20 ✔
1169
    }
1170
  }
1171

1172
  // Get volume calculations
1173
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
7,126 ✔
1174
    model::volume_calcs.emplace_back(node_vol);
220 ✔
1175
  }
1176

1177
  // Get temperature settings
1178
  if (check_for_node(root, "temperature_default")) {
6,906 ✔
1179
    temperature_default =
246 ✔
1180
      std::stod(get_node_value(root, "temperature_default"));
246 ✔
1181
  }
1182
  if (check_for_node(root, "temperature_method")) {
6,906 ✔
1183
    auto temp = get_node_value(root, "temperature_method", true, true);
340 ✔
1184
    if (temp == "nearest") {
340 ✔
1185
      temperature_method = TemperatureMethod::NEAREST;
212 ✔
1186
    } else if (temp == "interpolation") {
128 !
1187
      temperature_method = TemperatureMethod::INTERPOLATION;
128 ✔
1188
    } else {
1189
      fatal_error("Unknown temperature method: " + temp);
×
1190
    }
1191
  }
340 ✔
1192
  if (check_for_node(root, "temperature_tolerance")) {
6,906 ✔
1193
    temperature_tolerance =
486 ✔
1194
      std::stod(get_node_value(root, "temperature_tolerance"));
486 ✔
1195
  }
1196
  if (check_for_node(root, "temperature_multipole")) {
6,906 ✔
1197
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
130 ✔
1198

1199
    // Multipole currently doesn't work with photon transport
1200
    if (temperature_multipole && photon_transport) {
130 !
1201
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1202
                  "photon transport.");
1203
    }
1204
  }
1205
  if (check_for_node(root, "temperature_range")) {
6,906 ✔
1206
    auto range = get_node_array<double>(root, "temperature_range");
120 ✔
1207
    temperature_range[0] = range.at(0);
120 ✔
1208
    temperature_range[1] = range.at(1);
120 ✔
1209
  }
120 ✔
1210

1211
  // Check for tabular_legendre options
1212
  if (check_for_node(root, "tabular_legendre")) {
6,906 ✔
1213
    // Get pointer to tabular_legendre node
1214
    xml_node node_tab_leg = root.child("tabular_legendre");
70 ✔
1215

1216
    // Check for enable option
1217
    if (check_for_node(node_tab_leg, "enable")) {
70 !
1218
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
70 ✔
1219
    }
1220

1221
    // Check for the number of points
1222
    if (check_for_node(node_tab_leg, "num_points")) {
70 !
1223
      legendre_to_tabular_points =
×
1224
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
1225
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
1226
        fatal_error(
×
1227
          "The 'num_points' subelement/attribute of the "
1228
          "<tabular_legendre> element must contain a value greater than 1");
1229
      }
1230
    }
1231
  }
1232

1233
  // Check whether create delayed neutrons in fission
1234
  if (check_for_node(root, "create_delayed_neutrons")) {
6,906 !
1235
    create_delayed_neutrons =
×
1236
      get_node_value_bool(root, "create_delayed_neutrons");
×
1237
  }
1238

1239
  // Check whether create fission sites
1240
  if (run_mode == RunMode::FIXED_SOURCE) {
6,906 ✔
1241
    if (check_for_node(root, "create_fission_neutrons")) {
2,633 ✔
1242
      create_fission_neutrons =
241 ✔
1243
        get_node_value_bool(root, "create_fission_neutrons");
241 ✔
1244
    }
1245
  }
1246

1247
  // Check whether to scale fission photon yields
1248
  if (check_for_node(root, "delayed_photon_scaling")) {
6,906 !
1249
    delayed_photon_scaling =
×
1250
      get_node_value_bool(root, "delayed_photon_scaling");
×
1251
  }
1252

1253
  // Check whether to use event-based parallelism
1254
  if (check_for_node(root, "event_based")) {
6,906 ✔
1255
    event_based = get_node_value_bool(root, "event_based");
20 ✔
1256
  }
1257

1258
  // Check whether or not to use delta tracking
1259
  if (check_for_node(root, "delta_tracking")) {
6,906 ✔
1260
    delta_tracking = get_node_value_bool(root, "delta_tracking");
100 ✔
1261

1262
    if (temperature_multipole && delta_tracking) {
100 !
NEW
1263
      fatal_error(
×
1264
        "At present, delta tracking cannot be used with a windowed multipole "
1265
        "temperature treatment.");
1266
    }
1267

1268
    if (!run_CE && delta_tracking) {
100 !
NEW
1269
      fatal_error("At present, delta tracking can only be used in continuous "
×
1270
                  "energy simulations.");
1271
    }
1272
  }
1273

1274
  // Check whether material cell offsets should be generated
1275
  if (check_for_node(root, "material_cell_offsets")) {
6,906 !
1276
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1277
  }
1278

1279
  // Weight window information
1280
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
7,122 ✔
1281
    variance_reduction::weight_windows.emplace_back(
216 ✔
1282
      std::make_unique<WeightWindows>(node_ww));
432 ✔
1283
  }
1284

1285
  // Enable weight windows by default if one or more are present
1286
  if (variance_reduction::weight_windows.size() > 0)
6,906 ✔
1287
    settings::weight_windows_on = true;
148 ✔
1288

1289
  // read weight windows from file
1290
  if (check_for_node(root, "weight_windows_file")) {
6,906 ✔
1291
    weight_windows_file = get_node_value(root, "weight_windows_file");
18 ✔
1292
    weight_windows_on = true;
18 ✔
1293
  }
1294

1295
  // read settings for weight windows value, this will override
1296
  // the automatic setting even if weight windows are present
1297
  if (check_for_node(root, "weight_windows_on")) {
6,906 ✔
1298
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
70 ✔
1299
  }
1300

1301
  if (check_for_node(root, "max_secondaries")) {
6,906 !
1302
    settings::max_secondaries =
×
1303
      std::stoi(get_node_value(root, "max_secondaries"));
×
1304
  }
1305

1306
  if (check_for_node(root, "max_history_splits")) {
6,906 ✔
1307
    settings::max_history_splits =
570 ✔
1308
      std::stoi(get_node_value(root, "max_history_splits"));
570 ✔
1309
  }
1310

1311
  if (check_for_node(root, "max_tracks")) {
6,906 ✔
1312
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
60 ✔
1313
  }
1314

1315
  // Create weight window generator objects
1316
  if (check_for_node(root, "weight_window_generators")) {
6,906 ✔
1317
    auto wwgs_node = root.child("weight_window_generators");
99 ✔
1318
    for (pugi::xml_node node_wwg :
198 ✔
1319
      wwgs_node.children("weight_windows_generator")) {
198 ✔
1320
      variance_reduction::weight_windows_generators.emplace_back(
99 ✔
1321
        std::make_unique<WeightWindowsGenerator>(node_wwg));
198 ✔
1322
    }
1323
    // if any of the weight windows are intended to be generated otf, make
1324
    // sure they're applied
1325
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
99 !
1326
      if (wwg->on_the_fly_) {
99 !
1327
        settings::weight_windows_on = true;
99 ✔
1328
        break;
99 ✔
1329
      }
1330
    }
1331
    // If any weight window generators have local FW-CADIS target tallies,
1332
    // user-defined adjoint sources cannot be used at the same time.
1333
    if (!model::adjoint_sources.empty()) {
99 !
1334
      for (const auto& wwg : variance_reduction::weight_windows_generators) {
×
1335
        if (!wwg->targets_.empty()) {
×
1336
          fatal_error("Cannot use both user-defined adjoint sources and "
×
1337
                      "FW-CADIS target tallies at the same time.");
1338
        }
1339
      }
1340
    }
1341
  }
1342

1343
  // Set up weight window checkpoints
1344
  if (check_for_node(root, "weight_window_checkpoints")) {
6,906 ✔
1345
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
128 ✔
1346
    if (check_for_node(ww_checkpoints, "collision")) {
128 !
1347
      weight_window_checkpoint_collision =
128 ✔
1348
        get_node_value_bool(ww_checkpoints, "collision");
128 ✔
1349
    }
1350
    if (check_for_node(ww_checkpoints, "surface")) {
128 !
1351
      weight_window_checkpoint_surface =
128 ✔
1352
        get_node_value_bool(ww_checkpoints, "surface");
128 ✔
1353
    }
1354
  }
1355

1356
  if (weight_windows_on) {
6,906 ✔
1357
    if (!weight_window_checkpoint_surface &&
257 ✔
1358
        !weight_window_checkpoint_collision)
137 !
1359
      fatal_error(
×
1360
        "Weight Windows are enabled but there are no valid checkpoints.");
1361
  }
1362

1363
  if (check_for_node(root, "use_decay_photons")) {
6,906 ✔
1364
    settings::use_decay_photons =
8 ✔
1365
      get_node_value_bool(root, "use_decay_photons");
8 ✔
1366
  }
1367

1368
  // If weight windows are on, also enable shared secondary bank (unless
1369
  // explicitly disabled by user).
1370
  if (check_for_node(root, "shared_secondary_bank")) {
6,906 ✔
1371
    bool val = get_node_value_bool(root, "shared_secondary_bank");
230 ✔
1372
    if (val && run_mode == RunMode::EIGENVALUE) {
230 !
1373
      warning(
×
1374
        "Shared secondary bank is not supported in eigenvalue calculations. "
1375
        "Setting will be ignored.");
1376
    } else {
1377
      settings::use_shared_secondary_bank = val;
230 ✔
1378
    }
1379
  } else if (settings::weight_windows_on) {
6,676 ✔
1380
    if (run_mode == RunMode::EIGENVALUE) {
131 !
1381
      warning(
×
1382
        "Shared secondary bank is not supported in eigenvalue calculations. "
1383
        "Particle local secondary banks will be used instead.");
1384
    } else if (run_mode == RunMode::FIXED_SOURCE) {
131 !
1385
      settings::use_shared_secondary_bank = true;
131 ✔
1386
    }
1387
  }
1388
}
6,906 ✔
1389

1390
void free_memory_settings()
7,015 ✔
1391
{
1392
  settings::statepoint_batch.clear();
7,015 ✔
1393
  settings::sourcepoint_batch.clear();
7,015 ✔
1394
  settings::source_write_surf_id.clear();
7,015 ✔
1395
  settings::res_scat_nuclides.clear();
7,015 ✔
1396
  settings::track_identifiers.clear();
7,015 ✔
1397
  settings::ifp_delayed_group_on = false;
7,015 ✔
1398
  settings::ifp_lifetime_on = false;
7,015 ✔
1399
}
7,015 ✔
1400

1401
//==============================================================================
1402
// C API functions
1403
//==============================================================================
1404

1405
namespace {
1406

1407
int invalid_setting(const char* type, const char* name)
×
1408
{
1409
  set_errmsg(fmt::format("Unknown {} setting '{}'.", type, name));
×
1410
  return OPENMC_E_INVALID_ARGUMENT;
×
1411
}
1412

1413
bool* bool_setting(const char* name)
3,248 ✔
1414
{
1415
  if (std::strcmp(name, "cmfd_run") == 0) {
3,248 ✔
1416
    return &settings::cmfd_run;
1417
  } else if (std::strcmp(name, "entropy_on") == 0) {
3,088 ✔
1418
    return &settings::entropy_on;
1419
  } else if (std::strcmp(name, "event_based") == 0) {
1,376 ✔
1420
    return &settings::event_based;
1421
  } else if (std::strcmp(name, "need_depletion_rx") == 0) {
1,216 ✔
1422
    return &simulation::need_depletion_rx;
1423
  } else if (std::strcmp(name, "photon_transport") == 0) {
592 ✔
1424
    return &settings::photon_transport;
1425
  } else if (std::strcmp(name, "output_summary") == 0) {
552 ✔
1426
    return &settings::output_summary;
1427
  } else if (std::strcmp(name, "reduce_tallies") == 0) {
512 ✔
1428
    return &settings::reduce_tallies;
1429
  } else if (std::strcmp(name, "restart_run") == 0) {
472 ✔
1430
    return &settings::restart_run;
1431
  } else if (std::strcmp(name, "run_ce") == 0) {
312 ✔
1432
    return &settings::run_CE;
1433
  } else if (std::strcmp(name, "trigger_on") == 0) {
160 ✔
1434
    return &settings::trigger_on;
1435
  } else if (std::strcmp(name, "weight_windows_on") == 0) {
120 !
1436
    return &settings::weight_windows_on;
120 ✔
1437
  }
1438
  return nullptr;
1439
}
1440

1441
} // namespace
1442

1443
extern "C" int openmc_setting_get_bool(const char* name, bool* value)
2,232 ✔
1444
{
1445
  if (!name || !value) {
2,232 !
1446
    set_errmsg("Setting name and output pointer must not be null.");
×
1447
    return OPENMC_E_INVALID_ARGUMENT;
×
1448
  }
1449

1450
  bool* setting = bool_setting(name);
2,232 ✔
1451
  if (!setting)
2,232 !
1452
    return invalid_setting("boolean", name);
×
1453

1454
  *value = *setting;
2,232 ✔
1455
  return 0;
2,232 ✔
1456
}
1457

1458
extern "C" int openmc_setting_set_bool(const char* name, bool value)
1,016 ✔
1459
{
1460
  if (!name) {
1,016 !
1461
    set_errmsg("Setting name must not be null.");
×
1462
    return OPENMC_E_INVALID_ARGUMENT;
×
1463
  }
1464

1465
  bool* setting = bool_setting(name);
1,016 ✔
1466
  if (!setting)
1,016 !
1467
    return invalid_setting("boolean", name);
×
1468

1469
  *setting = value;
1,016 ✔
1470
  return 0;
1,016 ✔
1471
}
1472

1473
extern "C" int openmc_setting_get_int32(const char* name, int32_t* value)
888 ✔
1474
{
1475
  if (!name || !value) {
888 !
1476
    set_errmsg("Setting name and output pointer must not be null.");
×
1477
    return OPENMC_E_INVALID_ARGUMENT;
×
1478
  }
1479

1480
  if (std::strcmp(name, "gen_per_batch") == 0) {
888 ✔
1481
    *value = settings::gen_per_batch;
32 ✔
1482
  } else if (std::strcmp(name, "max_lost_particles") == 0) {
856 ✔
1483
    *value = settings::max_lost_particles;
24 ✔
1484
  } else if (std::strcmp(name, "max_write_lost_particles") == 0) {
832 ✔
1485
    *value = settings::max_write_lost_particles;
24 ✔
1486
  } else if (std::strcmp(name, "n_inactive") == 0) {
808 ✔
1487
    *value = settings::n_inactive;
32 ✔
1488
  } else if (std::strcmp(name, "run_mode") == 0) {
776 ✔
1489
    *value = static_cast<int32_t>(settings::run_mode);
16 ✔
1490
  } else if (std::strcmp(name, "verbosity") == 0) {
760 !
1491
    *value = settings::verbosity;
760 ✔
1492
  } else {
1493
    return invalid_setting("int32", name);
×
1494
  }
1495
  return 0;
1496
}
1497

1498
extern "C" int openmc_setting_set_int32(const char* name, int32_t value)
96 ✔
1499
{
1500
  if (!name) {
96 !
1501
    set_errmsg("Setting name must not be null.");
×
1502
    return OPENMC_E_INVALID_ARGUMENT;
×
1503
  }
1504

1505
  if (std::strcmp(name, "gen_per_batch") == 0) {
96 ✔
1506
    settings::gen_per_batch = value;
16 ✔
1507
  } else if (std::strcmp(name, "max_lost_particles") == 0) {
80 ✔
1508
    settings::max_lost_particles = value;
16 ✔
1509
  } else if (std::strcmp(name, "max_write_lost_particles") == 0) {
64 ✔
1510
    settings::max_write_lost_particles = value;
16 ✔
1511
  } else if (std::strcmp(name, "n_inactive") == 0) {
48 ✔
1512
    settings::n_inactive = value;
16 ✔
1513
  } else if (std::strcmp(name, "run_mode") == 0) {
32 ✔
1514
    if (value < static_cast<int32_t>(RunMode::UNSET) ||
16 !
1515
        value > static_cast<int32_t>(RunMode::VOLUME)) {
1516
      set_errmsg(fmt::format("Invalid run mode: {}.", value));
×
1517
      return OPENMC_E_INVALID_ARGUMENT;
×
1518
    }
1519
    settings::run_mode = static_cast<RunMode>(value);
16 ✔
1520
  } else if (std::strcmp(name, "verbosity") == 0) {
16 !
1521
    settings::verbosity = value;
16 ✔
1522
  } else {
1523
    return invalid_setting("int32", name);
×
1524
  }
1525
  return 0;
1526
}
1527

1528
extern "C" int openmc_setting_get_int64(const char* name, int64_t* value)
88 ✔
1529
{
1530
  if (!name || !value) {
88 !
1531
    set_errmsg("Setting name and output pointer must not be null.");
×
1532
    return OPENMC_E_INVALID_ARGUMENT;
×
1533
  }
1534

1535
  if (std::strcmp(name, "n_particles") != 0)
88 !
1536
    return invalid_setting("int64", name);
×
1537

1538
  *value = settings::n_particles;
88 ✔
1539
  return 0;
88 ✔
1540
}
1541

1542
extern "C" int openmc_setting_set_int64(const char* name, int64_t value)
72 ✔
1543
{
1544
  if (!name) {
72 !
1545
    set_errmsg("Setting name must not be null.");
×
1546
    return OPENMC_E_INVALID_ARGUMENT;
×
1547
  }
1548

1549
  if (std::strcmp(name, "n_particles") != 0)
72 !
1550
    return invalid_setting("int64", name);
×
1551

1552
  settings::n_particles = value;
72 ✔
1553
  return 0;
72 ✔
1554
}
1555

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

1563
  if (std::strcmp(name, "rel_max_lost_particles") != 0)
24 !
1564
    return invalid_setting("double", name);
×
1565

1566
  *value = settings::rel_max_lost_particles;
24 ✔
1567
  return 0;
24 ✔
1568
}
1569

1570
extern "C" int openmc_setting_set_double(const char* name, double value)
16 ✔
1571
{
1572
  if (!name) {
16 !
1573
    set_errmsg("Setting name must not be null.");
×
1574
    return OPENMC_E_INVALID_ARGUMENT;
×
1575
  }
1576

1577
  if (std::strcmp(name, "rel_max_lost_particles") != 0)
16 !
1578
    return invalid_setting("double", name);
×
1579

1580
  settings::rel_max_lost_particles = value;
16 ✔
1581
  return 0;
16 ✔
1582
}
1583

1584
extern "C" int openmc_setting_get_string(const char* name, const char** value)
16 ✔
1585
{
1586
  if (!name || !value) {
16 !
1587
    set_errmsg("Setting name and output pointer must not be null.");
×
1588
    return OPENMC_E_INVALID_ARGUMENT;
×
1589
  }
1590

1591
  if (std::strcmp(name, "path_statepoint") != 0)
16 !
1592
    return invalid_setting("string", name);
×
1593

1594
  *value = settings::path_statepoint.c_str();
16 ✔
1595
  return 0;
16 ✔
1596
}
1597

1598
extern "C" int openmc_set_n_batches(
160 ✔
1599
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1600
{
1601
  if (settings::n_inactive >= n_batches) {
160 ✔
1602
    set_errmsg("Number of active batches must be greater than zero.");
8 ✔
1603
    return OPENMC_E_INVALID_ARGUMENT;
8 ✔
1604
  }
1605

1606
  if (!settings::trigger_on) {
152 ✔
1607
    // Set n_batches and n_max_batches to same value
1608
    settings::n_batches = n_batches;
136 ✔
1609
    settings::n_max_batches = n_batches;
136 ✔
1610
  } else {
1611
    // Set n_batches and n_max_batches based on value of set_max_batches
1612
    if (set_max_batches) {
16 ✔
1613
      settings::n_max_batches = n_batches;
8 ✔
1614
    } else {
1615
      settings::n_batches = n_batches;
8 ✔
1616
    }
1617
  }
1618

1619
  // Update size of k_generation and entropy
1620
  int m = settings::n_max_batches * settings::gen_per_batch;
152 ✔
1621
  simulation::k_generation.reserve(m);
152 ✔
1622
  simulation::entropy.reserve(m);
152 ✔
1623

1624
  // Add value of n_batches to statepoint_batch
1625
  if (add_statepoint_batch &&
152 ✔
1626
      !(contains(settings::statepoint_batch, n_batches)))
144 ✔
1627
    settings::statepoint_batch.insert(n_batches);
24 ✔
1628

1629
  return 0;
1630
}
1631

1632
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
1,840 ✔
1633
{
1634
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
1,840 ✔
1635

1636
  return 0;
1,840 ✔
1637
}
1638

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