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

openmc-dev / openmc / 33949948625

05 Sep 2026 06:29AM UTC coverage: 81.404% (+0.05%) from 81.353%
33949948625

Pull #3944

github

web-flow
Merge 5b204ae1e into 33eaa7cf2
Pull Request #3944: DNP drift (regular mesh only)

19248 of 27890 branches covered (69.01%)

Branch coverage included in aggregate %.

1044 of 1204 new or added lines in 24 files covered. (86.71%)

10 existing lines in 3 files now uncovered.

61500 of 71304 relevant lines covered (86.25%)

50329400.81 hits per line

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

76.1
/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/field.h"
24
#include "openmc/file_utils.h"
25
#include "openmc/mcpl_interface.h"
26
#include "openmc/mesh.h"
27
#include "openmc/message_passing.h"
28
#include "openmc/output.h"
29
#include "openmc/plot.h"
30
#include "openmc/random_lcg.h"
31
#include "openmc/random_ray/random_ray.h"
32
#include "openmc/reaction.h"
33
#include "openmc/simulation.h"
34
#include "openmc/source.h"
35
#include "openmc/string_utils.h"
36
#include "openmc/tallies/trigger.h"
37
#include "openmc/volume_calc.h"
38
#include "openmc/weight_windows.h"
39
#include "openmc/xml_interface.h"
40

41
namespace openmc {
42

43
//==============================================================================
44
// Global variables
45
//==============================================================================
46

47
namespace settings {
48

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

98
std::string path_cross_sections;
99
std::string path_input;
100
std::string path_output;
101
std::string path_particle_restart;
102
std::string path_sourcepoint;
103
std::string path_statepoint;
104
std::string weight_windows_file;
105
std::string properties_file;
106

107
int32_t n_inactive {0};
108
int32_t max_lost_particles {10};
109
double rel_max_lost_particles {1.0e-6};
110
int32_t max_write_lost_particles {-1};
111
int32_t gen_per_batch {1};
112
int64_t n_particles {-1};
113

114
int64_t max_particles_in_flight {100000};
115
int max_particle_events {1000000};
116

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

160
double dnp_drift_external_travel_time {0.0};
161
bool dnp_drift_recycling_on {false};
162

163
} // namespace settings
164

165
//==============================================================================
166
// Functions
167
//==============================================================================
168

169
void get_run_parameters(pugi::xml_node node_base)
8,452 ✔
170
{
171
  using namespace settings;
8,452 ✔
172
  using namespace pugi;
8,452 ✔
173

174
  // Check number of particles
175
  if (!check_for_node(node_base, "particles")) {
8,452 !
176
    fatal_error("Need to specify number of particles.");
×
177
  }
178

179
  // Get number of particles if it wasn't specified as a command-line argument
180
  if (n_particles == -1) {
8,452 ✔
181
    n_particles = std::stoll(get_node_value(node_base, "particles"));
8,441 ✔
182
  }
183

184
  // Get maximum number of in flight particles for event-based mode
185
  if (check_for_node(node_base, "max_particles_in_flight")) {
8,452 !
186
    max_particles_in_flight =
×
187
      std::stoll(get_node_value(node_base, "max_particles_in_flight"));
×
188
  }
189

190
  // Get maximum number of events allowed per particle
191
  if (check_for_node(node_base, "max_particle_events")) {
8,452 !
192
    max_particle_events =
×
193
      std::stoll(get_node_value(node_base, "max_particle_events"));
×
194
  }
195

196
  // Get number of basic batches
197
  if (check_for_node(node_base, "batches")) {
8,452 !
198
    n_batches = std::stoi(get_node_value(node_base, "batches"));
8,452 ✔
199
  }
200
  if (!trigger_on)
8,452 ✔
201
    n_max_batches = n_batches;
8,311 ✔
202

203
  // Get max number of lost particles
204
  if (check_for_node(node_base, "max_lost_particles")) {
8,452 ✔
205
    max_lost_particles =
92 ✔
206
      std::stoi(get_node_value(node_base, "max_lost_particles"));
46 ✔
207
  }
208

209
  // Get relative number of lost particles
210
  if (check_for_node(node_base, "rel_max_lost_particles")) {
8,452 !
211
    rel_max_lost_particles =
×
212
      std::stod(get_node_value(node_base, "rel_max_lost_particles"));
×
213
  }
214

215
  // Get relative number of lost particles
216
  if (check_for_node(node_base, "max_write_lost_particles")) {
8,452 ✔
217
    max_write_lost_particles =
30 ✔
218
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
15 ✔
219
  }
220

221
  // Get number of inactive batches
222
  if (run_mode == RunMode::EIGENVALUE ||
8,452 ✔
223
      solver_type == SolverType::RANDOM_RAY) {
3,519 ✔
224
    if (check_for_node(node_base, "inactive")) {
5,391 ✔
225
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,948 ✔
226
    }
227
    if (check_for_node(node_base, "generations_per_batch")) {
5,391 ✔
228
      gen_per_batch =
30 ✔
229
        std::stoi(get_node_value(node_base, "generations_per_batch"));
15 ✔
230
    }
231

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

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

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

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

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

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

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

416
  // Get root element
417
  xml_node root = doc.document_element();
1,401 ✔
418

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

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

433
  write_message("Reading settings XML file...", 5);
1,401 ✔
434

435
  read_settings_xml(root);
1,401 ✔
436
}
1,413 ✔
437

438
void read_settings_xml(pugi::xml_node root)
9,514 ✔
439
{
440
  using namespace settings;
9,514 ✔
441
  using namespace pugi;
9,514 ✔
442

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

453
  // Check for user meshes and allocate
454
  read_meshes(root);
9,514 ✔
455

456
  // Read all fields
457
  read_fields(root);
9,514 ✔
458

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

836
    } else if (check_for_node(root, "entropy")) {
8,303 !
837
      fatal_error(
×
838
        "Specifying a Shannon entropy mesh via the <entropy> element "
839
        "is deprecated. Please create a mesh using <mesh> and then reference "
840
        "it by specifying its ID in an <entropy_mesh> element.");
841
    }
842
  }
843

844
  // Temperature field
845
  if (check_for_node(root, "temperature_field")) {
9,451 ✔
846
    temperature_field_on = true;
188 ✔
847
    int field_id = std::stoi(get_node_value(root, "temperature_field"));
376 ✔
848
    simulation::temperature_field = get_field<TemperatureField>(field_id);
188 ✔
849
  }
850

851
  // Uniform fission source weighting mesh
852
  if (check_for_node(root, "ufs_mesh")) {
9,451 ✔
853
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
30 ✔
854
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
15 !
855
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
856
                              "method does not exist.",
857
        temp));
858
    }
859

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1202
  // Explicit transport of Delayed Neutron Precursor (DNP)
1203
  if (check_for_node(root, "dnp_drift")) {
9,406 ✔
1204
    dnp_drift_on = true;
30 ✔
1205
    auto node_dnp_drift = root.child("dnp_drift");
30 ✔
1206

1207
    // Velocity field
1208
    int field_id = std::stoi(get_node_value(node_dnp_drift, "velocity_field"));
60 ✔
1209
    simulation::velocity_field = get_field<VelocityField>(field_id);
30 ✔
1210

1211
    // Boundary conditions map
1212
    if (check_for_node(node_dnp_drift, "boundary_map")) {
30 !
1213
      BCMap bc_map;
30 ✔
1214
      auto node_boundary = node_dnp_drift.child("boundary_map");
30 ✔
1215

1216
      if (check_for_node(node_boundary, "inlet")) {
30 !
1217
        bc_map[BCType::INLET] = get_node_array<int>(node_boundary, "inlet");
30 ✔
1218
      } else {
NEW
UNCOV
1219
        fatal_error("Inlet boundary conditions must be declared.");
×
1220
      }
1221

1222
      if (check_for_node(node_boundary, "outlet")) {
30 !
1223
        bc_map[BCType::OUTLET] = get_node_array<int>(node_boundary, "outlet");
30 ✔
1224
      } else {
NEW
1225
        fatal_error("Outlet boundary conditions must be declared.");
×
1226
      }
1227

1228
      if (check_for_node(node_boundary, "wall")) {
30 !
1229
        bc_map[BCType::WALL] = get_node_array<int>(node_boundary, "wall");
30 ✔
1230
      } else {
NEW
1231
        fatal_error("Wall boundary conditions must be declared.");
×
1232
      }
1233

1234
      simulation::velocity_field->bc_map() = bc_map;
60 !
1235

NEW
1236
    } else {
×
NEW
1237
      fatal_error("Boundary conditions must be declared.");
×
1238
    }
1239

1240
    // Physical group map
1241
    if (check_for_node(node_dnp_drift, "physical_group_map")) {
30 !
1242

1243
      auto node_physical_group = node_dnp_drift.child("physical_group_map");
30 ✔
1244

1245
      // Face IDs
1246
      vector<int> face_ids;
30 ✔
1247
      if (check_for_node(node_physical_group, "face_ids")) {
30 !
1248
        face_ids = get_node_array<int>(node_physical_group, "face_ids");
60 ✔
1249
      } else {
NEW
1250
        fatal_error("Surface IDs must be declared.");
×
1251
      }
1252

1253
      // Check for duplicate face IDs
1254
      std::set<int> unique_face_ids(face_ids.begin(), face_ids.end());
30 ✔
1255
      if (unique_face_ids.size() != face_ids.size()) {
30 !
NEW
1256
        fatal_error("Duplicate face IDs found in physical groups definition!");
×
1257
      }
1258

1259
      // Physical groups
1260
      vector<int> physical_groups;
30 ✔
1261
      if (check_for_node(node_physical_group, "physical_groups")) {
30 !
1262
        physical_groups =
30 ✔
1263
          get_node_array<int>(node_physical_group, "physical_groups");
60 ✔
1264
      } else {
NEW
1265
        fatal_error("Physical_groups must be declared.");
×
1266
      }
1267

1268
      // Check for consistency
1269
      if (face_ids.size() != physical_groups.size()) {
30 !
NEW
1270
        fatal_error(
×
1271
          "The lists of face IDs and physical groups must have the same size!");
1272
      }
1273

1274
      // Create the physical group map
1275
      PGMap pg_map;
30 ✔
1276
      for (size_t i = 0; i < face_ids.size(); i++) {
750 ✔
1277
        pg_map[physical_groups[i]].push_back(face_ids[i]);
720 ✔
1278
      }
1279

1280
      // Save the map in the mesh
1281
      simulation::velocity_field->mesh_ptr()->pg_map() = pg_map;
60 !
1282
    }
30 ✔
1283

1284
    // Integrator
1285
    if (check_for_node(node_dnp_drift, "integrator")) {
30 !
1286
      std::string integration_method =
30 ✔
1287
        get_node_value(node_dnp_drift, "integrator");
30 ✔
1288

1289
      // Runge Kutta 4
1290
      if (integration_method == "RK4") {
30 !
1291

1292
        // Time step
1293
        double dt;
30 ✔
1294
        if (!check_for_node(node_dnp_drift, "integrator_dt")) {
30 !
NEW
1295
          fatal_error("The attribute 'integrator_dt' is not declared in the "
×
1296
                      "DNP drift settings.");
1297
        } else {
1298
          dt = std::stod(get_node_value(node_dnp_drift, "integrator_dt"));
60 ✔
1299
        }
1300

1301
        // Instantiate integrator
1302
        simulation::streamline_integrator =
30 ✔
1303
          std::make_unique<RK4StreamlineIntegrator>(dt);
30 ✔
1304

1305
        // Undefined integration method
1306
      } else {
NEW
1307
        fatal_error(
×
NEW
1308
          fmt::format("Integrator '{}' not implemented", integration_method));
×
1309
      }
NEW
1310
    } else {
×
NEW
1311
      fatal_error("An integrator should be defined in the DNP drift settings.");
×
1312
    }
1313

1314
    // Recycle precursor when reaching an outlet?
1315
    if (check_for_node(node_dnp_drift, "recycling")) {
30 !
1316
      dnp_drift_recycling_on = get_node_value_bool(node_dnp_drift, "recycling");
30 ✔
1317
      if (dnp_drift_recycling_on) {
30 !
1318
        if (!check_for_node(node_dnp_drift, "external_travel_time")) {
30 !
NEW
1319
          fatal_error("The external travel time is not declared in "
×
1320
                      "the DNP drift settings.");
1321
        } else {
1322
          dnp_drift_external_travel_time =
60 ✔
1323
            std::stod(get_node_value(node_dnp_drift, "external_travel_time"));
60 ✔
1324
        }
1325
      }
1326
    }
1327
  }
1328

1329
  // Check for tabular_legendre options
1330
  if (check_for_node(root, "tabular_legendre")) {
9,406 ✔
1331
    // Get pointer to tabular_legendre node
1332
    xml_node node_tab_leg = root.child("tabular_legendre");
105 ✔
1333

1334
    // Check for enable option
1335
    if (check_for_node(node_tab_leg, "enable")) {
105 !
1336
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
105 ✔
1337
    }
1338

1339
    // Check for the number of points
1340
    if (check_for_node(node_tab_leg, "num_points")) {
105 !
1341
      legendre_to_tabular_points =
×
1342
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
1343
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
1344
        fatal_error(
×
1345
          "The 'num_points' subelement/attribute of the "
1346
          "<tabular_legendre> element must contain a value greater than 1");
1347
      }
1348
    }
1349
  }
1350

1351
  // Check whether create delayed neutrons in fission
1352
  if (check_for_node(root, "create_delayed_neutrons")) {
9,406 !
1353
    create_delayed_neutrons =
×
1354
      get_node_value_bool(root, "create_delayed_neutrons");
×
1355
  }
1356

1357
  // Check whether create fission sites
1358
  if (run_mode == RunMode::FIXED_SOURCE) {
9,406 ✔
1359
    if (check_for_node(root, "create_fission_neutrons")) {
3,473 ✔
1360
      create_fission_neutrons =
336 ✔
1361
        get_node_value_bool(root, "create_fission_neutrons");
336 ✔
1362
    }
1363
  }
1364

1365
  // Check whether to scale fission photon yields
1366
  if (check_for_node(root, "delayed_photon_scaling")) {
9,406 !
1367
    delayed_photon_scaling =
×
1368
      get_node_value_bool(root, "delayed_photon_scaling");
×
1369
  }
1370

1371
  // Check whether to use event-based parallelism
1372
  if (check_for_node(root, "event_based")) {
9,406 !
1373
    event_based = get_node_value_bool(root, "event_based");
×
1374
  }
1375

1376
  // Check whether material cell offsets should be generated
1377
  if (check_for_node(root, "material_cell_offsets")) {
9,406 !
1378
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1379
  }
1380

1381
  // Weight window information
1382
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
9,722 ✔
1383
    variance_reduction::weight_windows.emplace_back(
316 ✔
1384
      std::make_unique<WeightWindows>(node_ww));
632 ✔
1385
  }
1386

1387
  // Enable weight windows by default if one or more are present
1388
  if (variance_reduction::weight_windows.size() > 0)
9,406 ✔
1389
    settings::weight_windows_on = true;
220 ✔
1390

1391
  // read weight windows from file
1392
  if (check_for_node(root, "weight_windows_file")) {
9,406 ✔
1393
    weight_windows_file = get_node_value(root, "weight_windows_file");
26 ✔
1394
    weight_windows_on = true;
26 ✔
1395
  }
1396

1397
  // read settings for weight windows value, this will override
1398
  // the automatic setting even if weight windows are present
1399
  if (check_for_node(root, "weight_windows_on")) {
9,406 ✔
1400
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
93 ✔
1401
  }
1402

1403
  if (check_for_node(root, "max_secondaries")) {
9,406 !
1404
    settings::max_secondaries =
×
1405
      std::stoi(get_node_value(root, "max_secondaries"));
×
1406
  }
1407

1408
  if (check_for_node(root, "max_history_splits")) {
9,406 ✔
1409
    settings::max_history_splits =
798 ✔
1410
      std::stoi(get_node_value(root, "max_history_splits"));
798 ✔
1411
  }
1412

1413
  if (check_for_node(root, "max_tracks")) {
9,406 ✔
1414
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
90 ✔
1415
  }
1416

1417
  // Create weight window generator objects
1418
  if (check_for_node(root, "weight_window_generators")) {
9,406 ✔
1419
    auto wwgs_node = root.child("weight_window_generators");
127 ✔
1420
    for (pugi::xml_node node_wwg :
254 ✔
1421
      wwgs_node.children("weight_windows_generator")) {
254 ✔
1422
      variance_reduction::weight_windows_generators.emplace_back(
127 ✔
1423
        std::make_unique<WeightWindowsGenerator>(node_wwg));
254 ✔
1424
    }
1425
    // if any of the weight windows are intended to be generated otf, make
1426
    // sure they're applied
1427
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
127 !
1428
      if (wwg->on_the_fly_) {
127 !
1429
        settings::weight_windows_on = true;
127 ✔
1430
        break;
127 ✔
1431
      }
1432
    }
1433
    // If any weight window generators have local FW-CADIS target tallies,
1434
    // user-defined adjoint sources cannot be used at the same time.
1435
    if (!model::adjoint_sources.empty()) {
127 !
1436
      for (const auto& wwg : variance_reduction::weight_windows_generators) {
×
1437
        if (!wwg->targets_.empty()) {
×
1438
          fatal_error("Cannot use both user-defined adjoint sources and "
×
1439
                      "FW-CADIS target tallies at the same time.");
1440
        }
1441
      }
1442
    }
1443
  }
1444

1445
  // Set up weight window checkpoints
1446
  if (check_for_node(root, "weight_window_checkpoints")) {
9,406 ✔
1447
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
184 ✔
1448
    if (check_for_node(ww_checkpoints, "collision")) {
184 !
1449
      weight_window_checkpoint_collision =
184 ✔
1450
        get_node_value_bool(ww_checkpoints, "collision");
184 ✔
1451
    }
1452
    if (check_for_node(ww_checkpoints, "surface")) {
184 !
1453
      weight_window_checkpoint_surface =
184 ✔
1454
        get_node_value_bool(ww_checkpoints, "surface");
184 ✔
1455
    }
1456
  }
1457

1458
  if (weight_windows_on) {
9,406 ✔
1459
    if (!weight_window_checkpoint_surface &&
362 ✔
1460
        !weight_window_checkpoint_collision)
189 !
1461
      fatal_error(
×
1462
        "Weight Windows are enabled but there are no valid checkpoints.");
1463
  }
1464

1465
  if (check_for_node(root, "use_decay_photons")) {
9,406 ✔
1466
    settings::use_decay_photons =
11 ✔
1467
      get_node_value_bool(root, "use_decay_photons");
11 ✔
1468
  }
1469

1470
  // If weight windows are on, also enable shared secondary bank (unless
1471
  // explicitly disabled by user).
1472
  if (check_for_node(root, "shared_secondary_bank")) {
9,406 ✔
1473
    bool val = get_node_value_bool(root, "shared_secondary_bank");
335 ✔
1474
    if (val && run_mode == RunMode::EIGENVALUE) {
335 !
1475
      warning(
×
1476
        "Shared secondary bank is not supported in eigenvalue calculations. "
1477
        "Setting will be ignored.");
1478
    } else {
1479
      settings::use_shared_secondary_bank = val;
335 ✔
1480
    }
1481
  } else if (settings::weight_windows_on) {
9,071 ✔
1482
    if (run_mode == RunMode::EIGENVALUE) {
180 ✔
1483
      warning(
22 ✔
1484
        "Shared secondary bank is not supported in eigenvalue calculations. "
1485
        "Particle local secondary banks will be used instead.");
1486
    } else if (run_mode == RunMode::FIXED_SOURCE) {
169 !
1487
      settings::use_shared_secondary_bank = true;
169 ✔
1488
    }
1489
  }
1490
}
9,406 ✔
1491

1492
void free_memory_settings()
9,601 ✔
1493
{
1494
  settings::statepoint_batch.clear();
9,601 ✔
1495
  settings::sourcepoint_batch.clear();
9,601 ✔
1496
  settings::source_write_surf_id.clear();
9,601 ✔
1497
  settings::res_scat_nuclides.clear();
9,601 ✔
1498
  settings::ifp_delayed_group_on = false;
9,601 ✔
1499
  settings::ifp_lifetime_on = false;
9,601 ✔
1500
}
9,601 ✔
1501

1502
//==============================================================================
1503
// C API functions
1504
//==============================================================================
1505

1506
namespace {
1507

1508
int invalid_setting(const char* type, const char* name)
×
1509
{
1510
  set_errmsg(fmt::format("Unknown {} setting '{}'.", type, name));
×
1511
  return OPENMC_E_INVALID_ARGUMENT;
×
1512
}
1513

1514
bool* bool_setting(const char* name)
4,466 ✔
1515
{
1516
  if (std::strcmp(name, "cmfd_run") == 0) {
4,466 ✔
1517
    return &settings::cmfd_run;
1518
  } else if (std::strcmp(name, "entropy_on") == 0) {
4,246 ✔
1519
    return &settings::entropy_on;
1520
  } else if (std::strcmp(name, "event_based") == 0) {
1,892 ✔
1521
    return &settings::event_based;
1522
  } else if (std::strcmp(name, "need_depletion_rx") == 0) {
1,672 ✔
1523
    return &simulation::need_depletion_rx;
1524
  } else if (std::strcmp(name, "photon_transport") == 0) {
814 ✔
1525
    return &settings::photon_transport;
1526
  } else if (std::strcmp(name, "output_summary") == 0) {
759 ✔
1527
    return &settings::output_summary;
1528
  } else if (std::strcmp(name, "reduce_tallies") == 0) {
704 ✔
1529
    return &settings::reduce_tallies;
1530
  } else if (std::strcmp(name, "restart_run") == 0) {
649 ✔
1531
    return &settings::restart_run;
1532
  } else if (std::strcmp(name, "run_ce") == 0) {
429 ✔
1533
    return &settings::run_CE;
1534
  } else if (std::strcmp(name, "trigger_on") == 0) {
220 ✔
1535
    return &settings::trigger_on;
1536
  } else if (std::strcmp(name, "weight_windows_on") == 0) {
165 !
1537
    return &settings::weight_windows_on;
165 ✔
1538
  }
1539
  return nullptr;
1540
}
1541

1542
} // namespace
1543

1544
extern "C" int openmc_setting_get_bool(const char* name, bool* value)
3,069 ✔
1545
{
1546
  if (!name || !value) {
3,069 !
1547
    set_errmsg("Setting name and output pointer must not be null.");
×
1548
    return OPENMC_E_INVALID_ARGUMENT;
×
1549
  }
1550

1551
  bool* setting = bool_setting(name);
3,069 ✔
1552
  if (!setting)
3,069 !
1553
    return invalid_setting("boolean", name);
×
1554

1555
  *value = *setting;
3,069 ✔
1556
  return 0;
3,069 ✔
1557
}
1558

1559
extern "C" int openmc_setting_set_bool(const char* name, bool value)
1,397 ✔
1560
{
1561
  if (!name) {
1,397 !
1562
    set_errmsg("Setting name must not be null.");
×
1563
    return OPENMC_E_INVALID_ARGUMENT;
×
1564
  }
1565

1566
  bool* setting = bool_setting(name);
1,397 ✔
1567
  if (!setting)
1,397 !
1568
    return invalid_setting("boolean", name);
×
1569

1570
  *setting = value;
1,397 ✔
1571
  return 0;
1,397 ✔
1572
}
1573

1574
extern "C" int openmc_setting_get_int32(const char* name, int32_t* value)
1,221 ✔
1575
{
1576
  if (!name || !value) {
1,221 !
1577
    set_errmsg("Setting name and output pointer must not be null.");
×
1578
    return OPENMC_E_INVALID_ARGUMENT;
×
1579
  }
1580

1581
  if (std::strcmp(name, "gen_per_batch") == 0) {
1,221 ✔
1582
    *value = settings::gen_per_batch;
44 ✔
1583
  } else if (std::strcmp(name, "max_lost_particles") == 0) {
1,177 ✔
1584
    *value = settings::max_lost_particles;
33 ✔
1585
  } else if (std::strcmp(name, "max_write_lost_particles") == 0) {
1,144 ✔
1586
    *value = settings::max_write_lost_particles;
33 ✔
1587
  } else if (std::strcmp(name, "n_inactive") == 0) {
1,111 ✔
1588
    *value = settings::n_inactive;
44 ✔
1589
  } else if (std::strcmp(name, "run_mode") == 0) {
1,067 ✔
1590
    *value = static_cast<int32_t>(settings::run_mode);
22 ✔
1591
  } else if (std::strcmp(name, "verbosity") == 0) {
1,045 !
1592
    *value = settings::verbosity;
1,045 ✔
1593
  } else {
1594
    return invalid_setting("int32", name);
×
1595
  }
1596
  return 0;
1597
}
1598

1599
extern "C" int openmc_setting_set_int32(const char* name, int32_t value)
132 ✔
1600
{
1601
  if (!name) {
132 !
1602
    set_errmsg("Setting name must not be null.");
×
1603
    return OPENMC_E_INVALID_ARGUMENT;
×
1604
  }
1605

1606
  if (std::strcmp(name, "gen_per_batch") == 0) {
132 ✔
1607
    settings::gen_per_batch = value;
22 ✔
1608
  } else if (std::strcmp(name, "max_lost_particles") == 0) {
110 ✔
1609
    settings::max_lost_particles = value;
22 ✔
1610
  } else if (std::strcmp(name, "max_write_lost_particles") == 0) {
88 ✔
1611
    settings::max_write_lost_particles = value;
22 ✔
1612
  } else if (std::strcmp(name, "n_inactive") == 0) {
66 ✔
1613
    settings::n_inactive = value;
22 ✔
1614
  } else if (std::strcmp(name, "run_mode") == 0) {
44 ✔
1615
    if (value < static_cast<int32_t>(RunMode::UNSET) ||
22 !
1616
        value > static_cast<int32_t>(RunMode::VOLUME)) {
1617
      set_errmsg(fmt::format("Invalid run mode: {}.", value));
×
1618
      return OPENMC_E_INVALID_ARGUMENT;
×
1619
    }
1620
    settings::run_mode = static_cast<RunMode>(value);
22 ✔
1621
  } else if (std::strcmp(name, "verbosity") == 0) {
22 !
1622
    settings::verbosity = value;
22 ✔
1623
  } else {
1624
    return invalid_setting("int32", name);
×
1625
  }
1626
  return 0;
1627
}
1628

1629
extern "C" int openmc_setting_get_int64(const char* name, int64_t* value)
121 ✔
1630
{
1631
  if (!name || !value) {
121 !
1632
    set_errmsg("Setting name and output pointer must not be null.");
×
1633
    return OPENMC_E_INVALID_ARGUMENT;
×
1634
  }
1635

1636
  if (std::strcmp(name, "n_particles") != 0)
121 !
1637
    return invalid_setting("int64", name);
×
1638

1639
  *value = settings::n_particles;
121 ✔
1640
  return 0;
121 ✔
1641
}
1642

1643
extern "C" int openmc_setting_set_int64(const char* name, int64_t value)
99 ✔
1644
{
1645
  if (!name) {
99 !
1646
    set_errmsg("Setting name must not be null.");
×
1647
    return OPENMC_E_INVALID_ARGUMENT;
×
1648
  }
1649

1650
  if (std::strcmp(name, "n_particles") != 0)
99 !
1651
    return invalid_setting("int64", name);
×
1652

1653
  settings::n_particles = value;
99 ✔
1654
  return 0;
99 ✔
1655
}
1656

1657
extern "C" int openmc_setting_get_double(const char* name, double* value)
33 ✔
1658
{
1659
  if (!name || !value) {
33 !
1660
    set_errmsg("Setting name and output pointer must not be null.");
×
1661
    return OPENMC_E_INVALID_ARGUMENT;
×
1662
  }
1663

1664
  if (std::strcmp(name, "rel_max_lost_particles") != 0)
33 !
1665
    return invalid_setting("double", name);
×
1666

1667
  *value = settings::rel_max_lost_particles;
33 ✔
1668
  return 0;
33 ✔
1669
}
1670

1671
extern "C" int openmc_setting_set_double(const char* name, double value)
22 ✔
1672
{
1673
  if (!name) {
22 !
1674
    set_errmsg("Setting name must not be null.");
×
1675
    return OPENMC_E_INVALID_ARGUMENT;
×
1676
  }
1677

1678
  if (std::strcmp(name, "rel_max_lost_particles") != 0)
22 !
1679
    return invalid_setting("double", name);
×
1680

1681
  settings::rel_max_lost_particles = value;
22 ✔
1682
  return 0;
22 ✔
1683
}
1684

1685
extern "C" int openmc_setting_get_string(const char* name, const char** value)
22 ✔
1686
{
1687
  if (!name || !value) {
22 !
1688
    set_errmsg("Setting name and output pointer must not be null.");
×
1689
    return OPENMC_E_INVALID_ARGUMENT;
×
1690
  }
1691

1692
  if (std::strcmp(name, "path_statepoint") != 0)
22 !
1693
    return invalid_setting("string", name);
×
1694

1695
  *value = settings::path_statepoint.c_str();
22 ✔
1696
  return 0;
22 ✔
1697
}
1698

1699
extern "C" int openmc_set_n_batches(
220 ✔
1700
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1701
{
1702
  if (settings::n_inactive >= n_batches) {
220 ✔
1703
    set_errmsg("Number of active batches must be greater than zero.");
11 ✔
1704
    return OPENMC_E_INVALID_ARGUMENT;
11 ✔
1705
  }
1706

1707
  if (!settings::trigger_on) {
209 ✔
1708
    // Set n_batches and n_max_batches to same value
1709
    settings::n_batches = n_batches;
187 ✔
1710
    settings::n_max_batches = n_batches;
187 ✔
1711
  } else {
1712
    // Set n_batches and n_max_batches based on value of set_max_batches
1713
    if (set_max_batches) {
22 ✔
1714
      settings::n_max_batches = n_batches;
11 ✔
1715
    } else {
1716
      settings::n_batches = n_batches;
11 ✔
1717
    }
1718
  }
1719

1720
  // Update size of k_generation and entropy
1721
  int m = settings::n_max_batches * settings::gen_per_batch;
209 ✔
1722
  simulation::k_generation.reserve(m);
209 ✔
1723
  simulation::entropy.reserve(m);
209 ✔
1724

1725
  // Add value of n_batches to statepoint_batch
1726
  if (add_statepoint_batch &&
209 ✔
1727
      !(contains(settings::statepoint_batch, n_batches)))
198 ✔
1728
    settings::statepoint_batch.insert(n_batches);
33 ✔
1729

1730
  return 0;
1731
}
1732

1733
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,530 ✔
1734
{
1735
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,530 ✔
1736

1737
  return 0;
2,530 ✔
1738
}
1739

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