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

openmc-dev / openmc / 35134638866

16 Sep 2026 06:28PM UTC coverage: 81.443% (+0.02%) from 81.425%
35134638866

Pull #3683

github

web-flow
Merge ece9487b4 into c66d748ca
Pull Request #3683: Using NJOY2016 to create derived photonuclear data libraries.

19990 of 29022 branches covered (68.88%)

Branch coverage included in aggregate %.

2 of 44 new or added lines in 1 file covered. (4.55%)

2273 existing lines in 63 files now uncovered.

62397 of 72137 relevant lines covered (86.5%)

49668660.57 hits per line

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

75.71
/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 survival_biasing {false};
79
bool survival_normalization {false};
80
bool temperature_multipole {false};
81
bool trigger_on {false};
82
bool trigger_predict {false};
83
bool uniform_source_sampling {false};
84
bool ufs_on {false};
85
bool urr_ptables_on {true};
86
bool use_decay_photons {false};
87
bool use_shared_secondary_bank {false};
88
bool weight_windows_on {false};
89
bool weight_window_checkpoint_surface {false};
90
bool weight_window_checkpoint_collision {true};
91
bool write_all_tracks {false};
92
bool write_initial_source {false};
93

94
std::string path_cross_sections;
95
std::string path_input;
96
std::string path_output;
97
std::string path_particle_restart;
98
std::string path_sourcepoint;
99
std::string path_statepoint;
100
std::string weight_windows_file;
101
std::string properties_file;
102

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

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

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

156
} // namespace settings
157

158
//==============================================================================
159
// Functions
160
//==============================================================================
161

162
void get_run_parameters(pugi::xml_node node_base)
8,517 ✔
163
{
164
  using namespace settings;
8,517 ✔
165
  using namespace pugi;
8,517 ✔
166

167
  // Check number of particles
168
  if (!check_for_node(node_base, "particles")) {
8,517 !
UNCOV
169
    fatal_error("Need to specify number of particles.");
×
170
  }
171

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

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

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

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

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

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

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

214
  // Get number of inactive batches
215
  if (run_mode == RunMode::EIGENVALUE ||
8,517 ✔
216
      solver_type == SolverType::RANDOM_RAY) {
3,680 ✔
217
    if (check_for_node(node_base, "inactive")) {
5,467 ✔
218
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
5,176 ✔
219
    }
220
    if (check_for_node(node_base, "generations_per_batch")) {
5,467 ✔
221
      gen_per_batch =
30 ✔
222
        std::stoi(get_node_value(node_base, "generations_per_batch"));
15 ✔
223

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

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

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

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

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

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

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

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

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

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

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

447
  write_message("Reading settings XML file...", 5);
1,401 ✔
448

449
  read_settings_xml(root);
1,401 ✔
450
}
1,413 ✔
451

452
void read_settings_xml(pugi::xml_node root)
9,612 ✔
453
{
454
  using namespace settings;
9,612 ✔
455
  using namespace pugi;
9,612 ✔
456

457
  // Find if a multi-group or continuous-energy simulation is desired
458
  if (check_for_node(root, "energy_mode")) {
9,612 ✔
459
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
1,626 ✔
460
    if (temp_str == "mg" || temp_str == "multi-group") {
3,252 !
461
      run_CE = false;
1,626 ✔
UNCOV
462
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
UNCOV
463
      run_CE = true;
×
464
    }
465
  }
1,626 ✔
466

467
  // Check for user meshes and allocate
468
  read_meshes(root);
9,612 ✔
469

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

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

494
  // Check for a trigger node and get trigger information
495
  if (check_for_node(root, "trigger")) {
9,612 ✔
496
    xml_node node_trigger = root.child("trigger");
156 ✔
497

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

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

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

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

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

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

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

568
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
9,612 ✔
569
    // Read run parameters
570
    get_run_parameters(node_mode);
8,517 ✔
571

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

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

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

607
  // Copy random number seed if specified
608
  if (check_for_node(root, "seed")) {
9,603 ✔
609
    auto seed = std::stoll(get_node_value(root, "seed"));
1,200 ✔
610
    openmc_set_seed(seed);
600 ✔
611
  }
612

613
  // Copy random number stride if specified
614
  if (check_for_node(root, "stride")) {
9,603 ✔
615
    auto stride = std::stoull(get_node_value(root, "stride"));
30 ✔
616
    openmc_set_stride(stride);
15 ✔
617
  }
618

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

631
  // Check for photon transport
632
  if (check_for_node(root, "photon_transport")) {
9,603 ✔
633
    photon_transport = get_node_value_bool(root, "photon_transport");
486 ✔
634

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

641
  // Check for atomic relaxation
642
  if (check_for_node(root, "atomic_relaxation")) {
9,603 ✔
643
    atomic_relaxation = get_node_value_bool(root, "atomic_relaxation");
30 ✔
644
  }
645

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

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

663
  // ==========================================================================
664
  // EXTERNAL SOURCE
665

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

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

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

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

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

702
  // Build probability mass function for sampling external sources
703
  vector<double> source_strengths;
9,593 ✔
704
  for (auto& s : model::external_sources) {
20,769 ✔
705
    source_strengths.push_back(s->strength());
11,176 ✔
706
  }
707
  model::external_sources_probability.assign(source_strengths);
9,593 ✔
708

709
  // Check if we want to write out source
710
  if (check_for_node(root, "write_initial_source")) {
9,593 !
UNCOV
711
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
712
  }
713

714
  // Get relative number of lost particles
715
  if (check_for_node(root, "source_rejection_fraction")) {
9,593 ✔
716
    source_rejection_fraction =
14 ✔
717
      std::stod(get_node_value(root, "source_rejection_fraction"));
14 !
718
  }
719

720
  if (check_for_node(root, "free_gas_threshold")) {
9,593 !
UNCOV
721
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
722
  }
723

724
  // Surface grazing
725
  if (check_for_node(root, "surface_grazing_cutoff"))
9,593 !
UNCOV
726
    surface_grazing_cutoff =
×
727
      std::stod(get_node_value(root, "surface_grazing_cutoff"));
×
728
  if (check_for_node(root, "surface_grazing_ratio"))
9,593 !
UNCOV
729
    surface_grazing_ratio =
×
UNCOV
730
      std::stod(get_node_value(root, "surface_grazing_ratio"));
×
731

732
  // Survival biasing
733
  if (check_for_node(root, "survival_biasing")) {
9,593 ✔
734
    survival_biasing = get_node_value_bool(root, "survival_biasing");
227 ✔
735
  }
736

737
  // Probability tables
738
  if (check_for_node(root, "ptables")) {
9,593 ✔
739
    urr_ptables_on = get_node_value_bool(root, "ptables");
15 ✔
740
  }
741

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

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

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

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

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

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

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

849
      // Turn on Shannon entropy calculation
850
      entropy_on = true;
334 ✔
851

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

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

874
    // Turn on uniform fission source weighting
875
    ufs_on = true;
15 ✔
876

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

884
  // Check if the user has specified to write state points
885
  if (check_for_node(root, "state_point")) {
9,593 ✔
886

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

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

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

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

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

945
  // Check is the user specified to convert strength to statistical weight
946
  if (check_for_node(root, "uniform_source_sampling")) {
9,593 ✔
947
    uniform_source_sampling =
55 ✔
948
      get_node_value_bool(root, "uniform_source_sampling");
55 ✔
949
  }
950

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

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

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

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

983
    if (check_for_node(node_ssw, "mcpl")) {
403 ✔
984
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
11 ✔
985
    }
986
    // Get cell information
987
    if (check_for_node(node_ssw, "cell")) {
403 ✔
988
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
208 ✔
989
      ssw_cell_type = SSWCellType::Both;
104 ✔
990
    }
991
    if (check_for_node(node_ssw, "cellfrom")) {
403 ✔
992
      if (ssw_cell_id != C_NONE) {
90 ✔
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, "cellfrom"));
144 ✔
997
      ssw_cell_type = SSWCellType::From;
72 ✔
998
    }
999
    if (check_for_node(node_ssw, "cellto")) {
385 ✔
1000
      if (ssw_cell_id != C_NONE) {
71 ✔
1001
        fatal_error(
18 ✔
1002
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
1003
      }
1004
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
106 ✔
1005
      ssw_cell_type = SSWCellType::To;
53 ✔
1006
    }
1007
  }
1008

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

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

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

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

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

1097
  // Check for output options
1098
  if (check_for_node(root, "output")) {
9,548 ✔
1099
    // Get pointer to output node
1100
    pugi::xml_node node_output = root.child("output");
892 ✔
1101

1102
    // Check for summary option
1103
    if (check_for_node(node_output, "summary")) {
892 ✔
1104
      output_summary = get_node_value_bool(node_output, "summary");
866 ✔
1105
    }
1106

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

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

1121
  // Resonance scattering parameters
1122
  if (check_for_node(root, "resonance_scattering")) {
9,548 ✔
1123
    xml_node node_res_scat = root.child("resonance_scattering");
15 ✔
1124

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

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

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

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

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

1171
  // Get volume calculations
1172
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
9,858 ✔
1173
    model::volume_calcs.emplace_back(node_vol);
310 ✔
1174
  }
1175

1176
  // Get temperature settings
1177
  if (check_for_node(root, "temperature_default")) {
9,548 ✔
1178
    temperature_default =
342 ✔
1179
      std::stod(get_node_value(root, "temperature_default"));
342 ✔
1180
  }
1181
  if (check_for_node(root, "temperature_method")) {
9,548 ✔
1182
    auto temp = get_node_value(root, "temperature_method", true, true);
485 ✔
1183
    if (temp == "nearest") {
485 ✔
1184
      temperature_method = TemperatureMethod::NEAREST;
304 ✔
1185
    } else if (temp == "interpolation") {
181 !
1186
      temperature_method = TemperatureMethod::INTERPOLATION;
181 ✔
1187
    } else {
UNCOV
1188
      fatal_error("Unknown temperature method: " + temp);
×
1189
    }
1190
  }
485 ✔
1191
  if (check_for_node(root, "temperature_tolerance")) {
9,548 ✔
1192
    temperature_tolerance =
680 ✔
1193
      std::stod(get_node_value(root, "temperature_tolerance"));
680 ✔
1194
  }
1195
  if (check_for_node(root, "temperature_multipole")) {
9,548 ✔
1196
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
185 ✔
1197

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

1210
  // Check for tabular_legendre options
1211
  if (check_for_node(root, "tabular_legendre")) {
9,548 ✔
1212
    // Get pointer to tabular_legendre node
1213
    xml_node node_tab_leg = root.child("tabular_legendre");
105 ✔
1214

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

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

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

1238
  // Check whether create fission sites
1239
  if (run_mode == RunMode::FIXED_SOURCE) {
9,548 ✔
1240
    if (check_for_node(root, "create_fission_neutrons")) {
3,634 ✔
1241
      create_fission_neutrons =
336 ✔
1242
        get_node_value_bool(root, "create_fission_neutrons");
336 ✔
1243
    }
1244
  }
1245

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

1252
  // Check whether to use event-based parallelism
1253
  if (check_for_node(root, "event_based")) {
9,548 !
UNCOV
1254
    event_based = get_node_value_bool(root, "event_based");
×
1255
  }
1256

1257
  // Check whether material cell offsets should be generated
1258
  if (check_for_node(root, "material_cell_offsets")) {
9,548 !
UNCOV
1259
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1260
  }
1261

1262
  // Weight window information
1263
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
9,853 ✔
1264
    variance_reduction::weight_windows.emplace_back(
305 ✔
1265
      std::make_unique<WeightWindows>(node_ww));
610 ✔
1266
  }
1267

1268
  // Enable weight windows by default if one or more are present
1269
  if (variance_reduction::weight_windows.size() > 0)
9,548 ✔
1270
    settings::weight_windows_on = true;
209 ✔
1271

1272
  // read weight windows from file
1273
  if (check_for_node(root, "weight_windows_file")) {
9,548 ✔
1274
    weight_windows_file = get_node_value(root, "weight_windows_file");
26 ✔
1275
    weight_windows_on = true;
26 ✔
1276
  }
1277

1278
  // read settings for weight windows value, this will override
1279
  // the automatic setting even if weight windows are present
1280
  if (check_for_node(root, "weight_windows_on")) {
9,548 ✔
1281
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
93 ✔
1282
  }
1283

1284
  if (check_for_node(root, "max_secondaries")) {
9,548 !
UNCOV
1285
    settings::max_secondaries =
×
UNCOV
1286
      std::stoi(get_node_value(root, "max_secondaries"));
×
1287
  }
1288

1289
  if (check_for_node(root, "max_history_splits")) {
9,548 ✔
1290
    settings::max_history_splits =
798 ✔
1291
      std::stoi(get_node_value(root, "max_history_splits"));
798 ✔
1292
  }
1293

1294
  if (check_for_node(root, "max_tracks")) {
9,548 ✔
1295
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
90 ✔
1296
  }
1297

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

1326
  // Set up weight window checkpoints
1327
  if (check_for_node(root, "weight_window_checkpoints")) {
9,548 ✔
1328
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
184 ✔
1329
    if (check_for_node(ww_checkpoints, "collision")) {
184 !
1330
      weight_window_checkpoint_collision =
184 ✔
1331
        get_node_value_bool(ww_checkpoints, "collision");
184 ✔
1332
    }
1333
    if (check_for_node(ww_checkpoints, "surface")) {
184 !
1334
      weight_window_checkpoint_surface =
184 ✔
1335
        get_node_value_bool(ww_checkpoints, "surface");
184 ✔
1336
    }
1337
  }
1338

1339
  if (weight_windows_on) {
9,548 ✔
1340
    if (!weight_window_checkpoint_surface &&
366 ✔
1341
        !weight_window_checkpoint_collision)
193 !
UNCOV
1342
      fatal_error(
×
1343
        "Weight Windows are enabled but there are no valid checkpoints.");
1344
  }
1345

1346
  if (check_for_node(root, "use_decay_photons")) {
9,548 ✔
1347
    settings::use_decay_photons =
11 ✔
1348
      get_node_value_bool(root, "use_decay_photons");
11 ✔
1349
  }
1350

1351
  // If weight windows are on, also enable shared secondary bank (unless
1352
  // explicitly disabled by user).
1353
  if (check_for_node(root, "shared_secondary_bank")) {
9,548 ✔
1354
    bool val = get_node_value_bool(root, "shared_secondary_bank");
335 ✔
1355
    if (val && run_mode == RunMode::EIGENVALUE) {
335 !
UNCOV
1356
      warning(
×
1357
        "Shared secondary bank is not supported in eigenvalue calculations. "
1358
        "Setting will be ignored.");
1359
    } else {
1360
      settings::use_shared_secondary_bank = val;
335 ✔
1361
    }
1362
  } else if (settings::weight_windows_on) {
9,213 ✔
1363
    if (run_mode == RunMode::EIGENVALUE) {
184 !
UNCOV
1364
      warning(
×
1365
        "Shared secondary bank is not supported in eigenvalue calculations. "
1366
        "Particle local secondary banks will be used instead.");
1367
    } else if (run_mode == RunMode::FIXED_SOURCE) {
184 !
1368
      settings::use_shared_secondary_bank = true;
184 ✔
1369
    }
1370
  }
1371
}
9,548 ✔
1372

1373
void free_memory_settings()
9,699 ✔
1374
{
1375
  settings::statepoint_batch.clear();
9,699 ✔
1376
  settings::sourcepoint_batch.clear();
9,699 ✔
1377
  settings::source_write_surf_id.clear();
9,699 ✔
1378
  settings::res_scat_nuclides.clear();
9,699 ✔
1379
  settings::track_identifiers.clear();
9,699 ✔
1380
  settings::ifp_delayed_group_on = false;
9,699 ✔
1381
  settings::ifp_lifetime_on = false;
9,699 ✔
1382
}
9,699 ✔
1383

1384
//==============================================================================
1385
// C API functions
1386
//==============================================================================
1387

1388
namespace {
1389

UNCOV
1390
int invalid_setting(const char* type, const char* name)
×
1391
{
UNCOV
1392
  set_errmsg(fmt::format("Unknown {} setting '{}'.", type, name));
×
UNCOV
1393
  return OPENMC_E_INVALID_ARGUMENT;
×
1394
}
1395

1396
bool* bool_setting(const char* name)
4,466 ✔
1397
{
1398
  if (std::strcmp(name, "cmfd_run") == 0) {
4,466 ✔
1399
    return &settings::cmfd_run;
1400
  } else if (std::strcmp(name, "entropy_on") == 0) {
4,246 ✔
1401
    return &settings::entropy_on;
1402
  } else if (std::strcmp(name, "event_based") == 0) {
1,892 ✔
1403
    return &settings::event_based;
1404
  } else if (std::strcmp(name, "need_depletion_rx") == 0) {
1,672 ✔
1405
    return &simulation::need_depletion_rx;
1406
  } else if (std::strcmp(name, "photon_transport") == 0) {
814 ✔
1407
    return &settings::photon_transport;
1408
  } else if (std::strcmp(name, "output_summary") == 0) {
759 ✔
1409
    return &settings::output_summary;
1410
  } else if (std::strcmp(name, "reduce_tallies") == 0) {
704 ✔
1411
    return &settings::reduce_tallies;
1412
  } else if (std::strcmp(name, "restart_run") == 0) {
649 ✔
1413
    return &settings::restart_run;
1414
  } else if (std::strcmp(name, "run_ce") == 0) {
429 ✔
1415
    return &settings::run_CE;
1416
  } else if (std::strcmp(name, "trigger_on") == 0) {
220 ✔
1417
    return &settings::trigger_on;
1418
  } else if (std::strcmp(name, "weight_windows_on") == 0) {
165 !
1419
    return &settings::weight_windows_on;
165 ✔
1420
  }
1421
  return nullptr;
1422
}
1423

1424
} // namespace
1425

1426
extern "C" int openmc_setting_get_bool(const char* name, bool* value)
3,069 ✔
1427
{
1428
  if (!name || !value) {
3,069 !
UNCOV
1429
    set_errmsg("Setting name and output pointer must not be null.");
×
UNCOV
1430
    return OPENMC_E_INVALID_ARGUMENT;
×
1431
  }
1432

1433
  bool* setting = bool_setting(name);
3,069 ✔
1434
  if (!setting)
3,069 !
UNCOV
1435
    return invalid_setting("boolean", name);
×
1436

1437
  *value = *setting;
3,069 ✔
1438
  return 0;
3,069 ✔
1439
}
1440

1441
extern "C" int openmc_setting_set_bool(const char* name, bool value)
1,397 ✔
1442
{
1443
  if (!name) {
1,397 !
UNCOV
1444
    set_errmsg("Setting name must not be null.");
×
UNCOV
1445
    return OPENMC_E_INVALID_ARGUMENT;
×
1446
  }
1447

1448
  bool* setting = bool_setting(name);
1,397 ✔
1449
  if (!setting)
1,397 !
UNCOV
1450
    return invalid_setting("boolean", name);
×
1451

1452
  *setting = value;
1,397 ✔
1453
  return 0;
1,397 ✔
1454
}
1455

1456
extern "C" int openmc_setting_get_int32(const char* name, int32_t* value)
1,221 ✔
1457
{
1458
  if (!name || !value) {
1,221 !
UNCOV
1459
    set_errmsg("Setting name and output pointer must not be null.");
×
UNCOV
1460
    return OPENMC_E_INVALID_ARGUMENT;
×
1461
  }
1462

1463
  if (std::strcmp(name, "gen_per_batch") == 0) {
1,221 ✔
1464
    *value = settings::gen_per_batch;
44 ✔
1465
  } else if (std::strcmp(name, "max_lost_particles") == 0) {
1,177 ✔
1466
    *value = settings::max_lost_particles;
33 ✔
1467
  } else if (std::strcmp(name, "max_write_lost_particles") == 0) {
1,144 ✔
1468
    *value = settings::max_write_lost_particles;
33 ✔
1469
  } else if (std::strcmp(name, "n_inactive") == 0) {
1,111 ✔
1470
    *value = settings::n_inactive;
44 ✔
1471
  } else if (std::strcmp(name, "run_mode") == 0) {
1,067 ✔
1472
    *value = static_cast<int32_t>(settings::run_mode);
22 ✔
1473
  } else if (std::strcmp(name, "verbosity") == 0) {
1,045 !
1474
    *value = settings::verbosity;
1,045 ✔
1475
  } else {
UNCOV
1476
    return invalid_setting("int32", name);
×
1477
  }
1478
  return 0;
1479
}
1480

1481
extern "C" int openmc_setting_set_int32(const char* name, int32_t value)
132 ✔
1482
{
1483
  if (!name) {
132 !
UNCOV
1484
    set_errmsg("Setting name must not be null.");
×
UNCOV
1485
    return OPENMC_E_INVALID_ARGUMENT;
×
1486
  }
1487

1488
  if (std::strcmp(name, "gen_per_batch") == 0) {
132 ✔
1489
    settings::gen_per_batch = value;
22 ✔
1490
  } else if (std::strcmp(name, "max_lost_particles") == 0) {
110 ✔
1491
    settings::max_lost_particles = value;
22 ✔
1492
  } else if (std::strcmp(name, "max_write_lost_particles") == 0) {
88 ✔
1493
    settings::max_write_lost_particles = value;
22 ✔
1494
  } else if (std::strcmp(name, "n_inactive") == 0) {
66 ✔
1495
    settings::n_inactive = value;
22 ✔
1496
  } else if (std::strcmp(name, "run_mode") == 0) {
44 ✔
1497
    if (value < static_cast<int32_t>(RunMode::UNSET) ||
22 !
1498
        value > static_cast<int32_t>(RunMode::VOLUME)) {
UNCOV
1499
      set_errmsg(fmt::format("Invalid run mode: {}.", value));
×
UNCOV
1500
      return OPENMC_E_INVALID_ARGUMENT;
×
1501
    }
1502
    settings::run_mode = static_cast<RunMode>(value);
22 ✔
1503
  } else if (std::strcmp(name, "verbosity") == 0) {
22 !
1504
    settings::verbosity = value;
22 ✔
1505
  } else {
UNCOV
1506
    return invalid_setting("int32", name);
×
1507
  }
1508
  return 0;
1509
}
1510

1511
extern "C" int openmc_setting_get_int64(const char* name, int64_t* value)
121 ✔
1512
{
1513
  if (!name || !value) {
121 !
UNCOV
1514
    set_errmsg("Setting name and output pointer must not be null.");
×
UNCOV
1515
    return OPENMC_E_INVALID_ARGUMENT;
×
1516
  }
1517

1518
  if (std::strcmp(name, "n_particles") != 0)
121 !
UNCOV
1519
    return invalid_setting("int64", name);
×
1520

1521
  *value = settings::n_particles;
121 ✔
1522
  return 0;
121 ✔
1523
}
1524

1525
extern "C" int openmc_setting_set_int64(const char* name, int64_t value)
99 ✔
1526
{
1527
  if (!name) {
99 !
UNCOV
1528
    set_errmsg("Setting name must not be null.");
×
UNCOV
1529
    return OPENMC_E_INVALID_ARGUMENT;
×
1530
  }
1531

1532
  if (std::strcmp(name, "n_particles") != 0)
99 !
UNCOV
1533
    return invalid_setting("int64", name);
×
1534

1535
  settings::n_particles = value;
99 ✔
1536
  return 0;
99 ✔
1537
}
1538

1539
extern "C" int openmc_setting_get_double(const char* name, double* value)
33 ✔
1540
{
1541
  if (!name || !value) {
33 !
UNCOV
1542
    set_errmsg("Setting name and output pointer must not be null.");
×
UNCOV
1543
    return OPENMC_E_INVALID_ARGUMENT;
×
1544
  }
1545

1546
  if (std::strcmp(name, "rel_max_lost_particles") != 0)
33 !
UNCOV
1547
    return invalid_setting("double", name);
×
1548

1549
  *value = settings::rel_max_lost_particles;
33 ✔
1550
  return 0;
33 ✔
1551
}
1552

1553
extern "C" int openmc_setting_set_double(const char* name, double value)
22 ✔
1554
{
1555
  if (!name) {
22 !
UNCOV
1556
    set_errmsg("Setting name must not be null.");
×
UNCOV
1557
    return OPENMC_E_INVALID_ARGUMENT;
×
1558
  }
1559

1560
  if (std::strcmp(name, "rel_max_lost_particles") != 0)
22 !
UNCOV
1561
    return invalid_setting("double", name);
×
1562

1563
  settings::rel_max_lost_particles = value;
22 ✔
1564
  return 0;
22 ✔
1565
}
1566

1567
extern "C" int openmc_setting_get_string(const char* name, const char** value)
22 ✔
1568
{
1569
  if (!name || !value) {
22 !
UNCOV
1570
    set_errmsg("Setting name and output pointer must not be null.");
×
UNCOV
1571
    return OPENMC_E_INVALID_ARGUMENT;
×
1572
  }
1573

1574
  if (std::strcmp(name, "path_statepoint") != 0)
22 !
UNCOV
1575
    return invalid_setting("string", name);
×
1576

1577
  *value = settings::path_statepoint.c_str();
22 ✔
1578
  return 0;
22 ✔
1579
}
1580

1581
extern "C" int openmc_set_n_batches(
220 ✔
1582
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1583
{
1584
  if (settings::n_inactive >= n_batches) {
220 ✔
1585
    set_errmsg("Number of active batches must be greater than zero.");
11 ✔
1586
    return OPENMC_E_INVALID_ARGUMENT;
11 ✔
1587
  }
1588

1589
  if (!settings::trigger_on) {
209 ✔
1590
    // Set n_batches and n_max_batches to same value
1591
    settings::n_batches = n_batches;
187 ✔
1592
    settings::n_max_batches = n_batches;
187 ✔
1593
  } else {
1594
    // Set n_batches and n_max_batches based on value of set_max_batches
1595
    if (set_max_batches) {
22 ✔
1596
      settings::n_max_batches = n_batches;
11 ✔
1597
    } else {
1598
      settings::n_batches = n_batches;
11 ✔
1599
    }
1600
  }
1601

1602
  // Update size of k_generation and entropy
1603
  int m = settings::n_max_batches * settings::gen_per_batch;
209 ✔
1604
  simulation::k_generation.reserve(m);
209 ✔
1605
  simulation::entropy.reserve(m);
209 ✔
1606

1607
  // Add value of n_batches to statepoint_batch
1608
  if (add_statepoint_batch &&
209 ✔
1609
      !(contains(settings::statepoint_batch, n_batches)))
198 ✔
1610
    settings::statepoint_batch.insert(n_batches);
33 ✔
1611

1612
  return 0;
1613
}
1614

1615
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,530 ✔
1616
{
1617
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,530 ✔
1618

1619
  return 0;
2,530 ✔
1620
}
1621

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