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

openmc-dev / openmc / 43538648659

14 Nov 2026 01:07AM UTC coverage: 82.356% (+0.05%) from 82.304%
43538648659

push

github

web-flow
Specify temperature from a field (structured mesh only) (#3734)

Co-authored-by: Paul Romano <paul.k.romano@gmail.com>

20953 of 29717 branches covered (70.51%)

Branch coverage included in aggregate %.

320 of 342 new or added lines in 15 files covered. (93.57%)

64452 of 73985 relevant lines covered (87.11%)

42544112.91 hits per line

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

76.4
/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 entropy_on {false};
59
bool event_based {false};
60
bool ifp_delayed_group_on {false};
61
bool ifp_lifetime_on {false};
62
bool legendre_to_tabular {true};
63
bool material_cell_offsets {true};
64
bool output_summary {true};
65
bool output_tallies {true};
66
bool particle_restart_run {false};
67
bool photon_transport {false};
68
bool atomic_relaxation {true};
69
bool reduce_tallies {true};
70
bool res_scat_on {false};
71
bool restart_run {false};
72
bool run_CE {true};
73
bool source_latest {false};
74
bool source_separate {false};
75
bool source_write {true};
76
bool source_mcpl_write {false};
77
bool surf_source_write {false};
78
bool surf_mcpl_write {false};
79
bool survival_biasing {false};
80
bool survival_normalization {false};
81
bool temperature_field_on {false};
82
bool temperature_multipole {false};
83
bool trigger_on {false};
84
bool trigger_predict {false};
85
bool uniform_source_sampling {false};
86
bool ufs_on {false};
87
bool urr_ptables_on {true};
88
bool use_decay_photons {false};
89
bool use_shared_secondary_bank {false};
90
bool weight_windows_on {false};
91
bool weight_window_checkpoint_surface {false};
92
bool weight_window_checkpoint_collision {true};
93
bool write_all_tracks {false};
94
bool write_initial_source {false};
95

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

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

112
int64_t max_particles_in_flight {100000};
113
int max_particle_events {1000000};
114

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

158
} // namespace settings
159

160
//==============================================================================
161
// Functions
162
//==============================================================================
163

164
void get_run_parameters(pugi::xml_node node_base)
6,286 ✔
165
{
166
  using namespace settings;
6,286 ✔
167
  using namespace pugi;
6,286 ✔
168

169
  // Check number of particles
170
  if (!check_for_node(node_base, "particles")) {
6,286 !
171
    fatal_error("Need to specify number of particles.");
×
172
  }
173

174
  // Get number of particles if it wasn't specified as a command-line argument
175
  if (n_particles == -1) {
6,286 ✔
176
    n_particles = std::stoll(get_node_value(node_base, "particles"));
6,238 ✔
177
  }
178

179
  // Get maximum number of in flight particles for event-based mode
180
  if (check_for_node(node_base, "max_particles_in_flight")) {
6,286 !
181
    max_particles_in_flight =
×
182
      std::stoll(get_node_value(node_base, "max_particles_in_flight"));
×
183
  }
184

185
  // Get maximum number of events allowed per particle
186
  if (check_for_node(node_base, "max_particle_events")) {
6,286 !
187
    max_particle_events =
×
188
      std::stoll(get_node_value(node_base, "max_particle_events"));
×
189
  }
190

191
  // Get number of basic batches
192
  if (check_for_node(node_base, "batches")) {
6,286 !
193
    n_batches = std::stoi(get_node_value(node_base, "batches"));
6,286 ✔
194
  }
195
  if (!trigger_on)
6,286 ✔
196
    n_max_batches = n_batches;
6,172 ✔
197

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

204
  // Get relative number of lost particles
205
  if (check_for_node(node_base, "rel_max_lost_particles")) {
6,286 !
206
    rel_max_lost_particles =
×
207
      std::stod(get_node_value(node_base, "rel_max_lost_particles"));
×
208
  }
209

210
  // Get relative number of lost particles
211
  if (check_for_node(node_base, "max_write_lost_particles")) {
6,286 ✔
212
    max_write_lost_particles =
20 ✔
213
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
10 ✔
214
  }
215

216
  // Get number of inactive batches
217
  if (run_mode == RunMode::EIGENVALUE ||
6,286 ✔
218
      solver_type == SolverType::RANDOM_RAY) {
2,708 ✔
219
    if (check_for_node(node_base, "inactive")) {
4,031 ✔
220
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
3,661 ✔
221
    }
222
    if (check_for_node(node_base, "generations_per_batch")) {
4,031 ✔
223
      gen_per_batch =
20 ✔
224
        std::stoi(get_node_value(node_base, "generations_per_batch"));
10 ✔
225

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

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

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

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

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

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

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

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

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

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

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

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

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

454
void read_settings_xml(pugi::xml_node root)
7,140 ✔
455
{
456
  using namespace settings;
7,140 ✔
457
  using namespace pugi;
7,140 ✔
458

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

469
  // Check for user meshes and allocate
470
  read_meshes(root);
7,140 ✔
471

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

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

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

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

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

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

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

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

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

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

570
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
7,140 ✔
571
    // Read run parameters
572
    get_run_parameters(node_mode);
6,286 ✔
573

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

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

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

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

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

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

633
  // Check for photon transport
634
  if (check_for_node(root, "photon_transport")) {
7,133 ✔
635
    photon_transport = get_node_value_bool(root, "photon_transport");
348 ✔
636

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

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

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

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

665
  // ==========================================================================
666
  // EXTERNAL SOURCE
667

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

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

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

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

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

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

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

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

722
  if (check_for_node(root, "free_gas_threshold")) {
7,126 !
723
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
724
  }
725

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

734
  // Survival biasing
735
  if (check_for_node(root, "survival_biasing")) {
7,126 ✔
736
    survival_biasing = get_node_value_bool(root, "survival_biasing");
172 ✔
737
  }
738

739
  // Probability tables
740
  if (check_for_node(root, "ptables")) {
7,126 ✔
741
    urr_ptables_on = get_node_value_bool(root, "ptables");
10 ✔
742
  }
743

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

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

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

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

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

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

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

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

854
    } else if (check_for_node(root, "entropy")) {
6,123 !
855
      fatal_error(
×
856
        "Specifying a Shannon entropy mesh via the <entropy> element "
857
        "is deprecated. Please create a mesh using <mesh> and then reference "
858
        "it by specifying its ID in an <entropy_mesh> element.");
859
    }
860
  }
861

862
  // Temperature field
863
  if (check_for_node(root, "temperature_field")) {
7,126 ✔
864
    if (!run_CE) {
135 !
NEW
865
      throw std::runtime_error(
×
NEW
866
        "Temperature fields are not supported in multi-group mode.");
×
867
    }
868

869
    // The random ray solver does not apply temperature fields. Leave the flag
870
    // off here so that every consumer of the field -- cross section loading,
871
    // transport, plotting -- agrees that it is not in use, rather than each
872
    // one having to exclude the solver on its own. The field is still parsed
873
    // so that malformed input is still reported.
874
    if (solver_type == SolverType::RANDOM_RAY) {
135 !
NEW
875
      warning("Temperature fields are not supported with the random ray "
×
876
              "solver. It will be ignored during this simulation.");
877
    } else {
878
      temperature_field_on = true;
135 ✔
879
    }
880

881
    // Get pointer to temperature_field node
882
    auto node_tf = root.child("temperature_field");
135 ✔
883

884
    // Mesh parameter
885
    Mesh* tf_mesh_ptr;
135 ✔
886
    if (check_for_node(node_tf, "mesh")) {
135 ✔
887
      int temp = std::stoi(get_node_value(node_tf, "mesh"));
254 ✔
888
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
127 ✔
889
        throw std::runtime_error(fmt::format(
8 ✔
890
          "Mesh {} specified for the temperature field does not exist.", temp));
16 ✔
891
      }
892
      tf_mesh_ptr = model::meshes[model::mesh_map.at(temp)].get();
119 !
893
      if (!dynamic_cast<RegularMesh*>(tf_mesh_ptr) &&
119 !
894
          !dynamic_cast<RectilinearMesh*>(tf_mesh_ptr)) {
8 !
895
        throw std::runtime_error(
8 ✔
896
          "Temperature fields are only supported on regular and rectilinear "
897
          "meshes.");
16 ✔
898
      }
899
    } else {
900
      throw std::runtime_error(
8 ✔
901
        "A mesh should be given for the temperature field.");
16 ✔
902
    }
903

904
    // Values parameter
905
    vector<double> tf_values;
111 ✔
906
    if (check_for_node(node_tf, "values")) {
111 ✔
907
      auto temp = get_node_array<double>(node_tf, "values");
103 ✔
908
      if (temp.size() != tf_mesh_ptr->n_bins()) {
103 ✔
909
        throw std::runtime_error(
8 ✔
910
          "Inconsistency in the temperature field: the number of "
911
          "values must be equal to the number of bins in the mesh.");
16 ✔
912
      }
913
      for (const auto& b : temp) {
751 ✔
914
        tf_values.push_back(b);
656 ✔
915
      }
916
    } else {
8 ✔
917
      throw std::runtime_error(
8 ✔
918
        "Temperature values should be given for the temperature field.");
16 ✔
919
    }
920

921
    // Instantiate the temperature field
922
    simulation::temperature_field = TemperatureField(tf_mesh_ptr, tf_values);
293 ✔
923
  }
111 ✔
924

925
  // Uniform fission source weighting mesh
926
  if (check_for_node(root, "ufs_mesh")) {
7,078 ✔
927
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
20 ✔
928
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
10 !
929
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
930
                              "method does not exist.",
931
        temp));
932
    }
933

934
    auto* m =
10 ✔
935
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
10 !
936
    if (!m)
10 !
937
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
938
    simulation::ufs_mesh = m;
10 ✔
939

940
    // Turn on uniform fission source weighting
941
    ufs_on = true;
10 ✔
942

943
  } else if (check_for_node(root, "uniform_fs")) {
7,068 !
944
    fatal_error(
×
945
      "Specifying a UFS mesh via the <uniform_fs> element "
946
      "is deprecated. Please create a mesh using <mesh> and then reference "
947
      "it by specifying its ID in a <ufs_mesh> element.");
948
  }
949

950
  // Check if the user has specified to write state points
951
  if (check_for_node(root, "state_point")) {
7,078 ✔
952

953
    // Get pointer to state_point node
954
    auto node_sp = root.child("state_point");
110 ✔
955

956
    // Determine number of batches at which to store state points
957
    if (check_for_node(node_sp, "batches")) {
110 !
958
      // User gave specific batches to write state points
959
      auto temp = get_node_array<int>(node_sp, "batches");
110 ✔
960
      for (const auto& b : temp) {
338 ✔
961
        statepoint_batch.insert(b);
228 ✔
962
      }
963
    } else {
110 ✔
964
      // If neither were specified, write state point at last batch
965
      statepoint_batch.insert(n_batches);
×
966
    }
967
  } else {
968
    // If no <state_point> tag was present, by default write state point at
969
    // last batch only
970
    statepoint_batch.insert(n_batches);
6,968 ✔
971
  }
972

973
  // Check if the user has specified to write source points
974
  if (check_for_node(root, "source_point")) {
7,078 ✔
975
    // Get source_point node
976
    xml_node node_sp = root.child("source_point");
68 ✔
977

978
    // Determine batches at which to store source points
979
    if (check_for_node(node_sp, "batches")) {
68 ✔
980
      // User gave specific batches to write source points
981
      auto temp = get_node_array<int>(node_sp, "batches");
30 ✔
982
      for (const auto& b : temp) {
80 ✔
983
        sourcepoint_batch.insert(b);
50 ✔
984
      }
985
    } else {
30 ✔
986
      // If neither were specified, write source points with state points
987
      sourcepoint_batch = statepoint_batch;
38 !
988
    }
989

990
    // Check if the user has specified to write binary source file
991
    if (check_for_node(node_sp, "separate")) {
68 ✔
992
      source_separate = get_node_value_bool(node_sp, "separate");
48 ✔
993
    }
994
    if (check_for_node(node_sp, "write")) {
68 !
995
      source_write = get_node_value_bool(node_sp, "write");
×
996
    }
997
    if (check_for_node(node_sp, "mcpl")) {
68 ✔
998
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
18 ✔
999
    }
1000
    if (check_for_node(node_sp, "overwrite_latest")) {
68 ✔
1001
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
10 ✔
1002
      source_separate = source_latest;
10 ✔
1003
    }
1004
  } else {
1005
    // If no <source_point> tag was present, by default we keep source bank in
1006
    // statepoint file and write it out at statepoints intervals
1007
    source_separate = false;
7,010 ✔
1008
    sourcepoint_batch = statepoint_batch;
7,010 !
1009
  }
1010

1011
  // Check is the user specified to convert strength to statistical weight
1012
  if (check_for_node(root, "uniform_source_sampling")) {
7,078 ✔
1013
    uniform_source_sampling =
40 ✔
1014
      get_node_value_bool(root, "uniform_source_sampling");
40 ✔
1015
  }
1016

1017
  // Check if the user has specified to write surface source
1018
  if (check_for_node(root, "surf_source_write")) {
7,078 ✔
1019
    surf_source_write = true;
299 ✔
1020
    // Get surface source write node
1021
    xml_node node_ssw = root.child("surf_source_write");
299 ✔
1022

1023
    // Determine surface ids at which crossing particles are to be banked.
1024
    // If no surfaces are specified, all surfaces in the model will be used
1025
    // to bank source points.
1026
    if (check_for_node(node_ssw, "surface_ids")) {
299 ✔
1027
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
144 ✔
1028
      for (const auto& b : temp) {
707 ✔
1029
        source_write_surf_id.insert(b);
563 ✔
1030
      }
1031
    }
144 ✔
1032

1033
    // Get maximum number of particles to be banked per surface
1034
    if (check_for_node(node_ssw, "max_particles")) {
299 ✔
1035
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
584 ✔
1036
    } else {
1037
      fatal_error("A maximum number of particles needs to be specified "
7 ✔
1038
                  "using the 'max_particles' parameter to store surface "
1039
                  "source points.");
1040
    }
1041

1042
    // Get maximum number of surface source files to be created
1043
    if (check_for_node(node_ssw, "max_source_files")) {
292 ✔
1044
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
48 ✔
1045
    } else {
1046
      ssw_max_files = 1;
268 ✔
1047
    }
1048

1049
    if (check_for_node(node_ssw, "mcpl")) {
292 ✔
1050
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
8 ✔
1051
    }
1052
    // Get cell information
1053
    if (check_for_node(node_ssw, "cell")) {
292 ✔
1054
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
154 ✔
1055
      ssw_cell_type = SSWCellType::Both;
77 ✔
1056
    }
1057
    if (check_for_node(node_ssw, "cellfrom")) {
292 ✔
1058
      if (ssw_cell_id != C_NONE) {
66 ✔
1059
        fatal_error(
14 ✔
1060
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
1061
      }
1062
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
104 ✔
1063
      ssw_cell_type = SSWCellType::From;
52 ✔
1064
    }
1065
    if (check_for_node(node_ssw, "cellto")) {
278 ✔
1066
      if (ssw_cell_id != C_NONE) {
52 ✔
1067
        fatal_error(
14 ✔
1068
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
1069
      }
1070
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
76 ✔
1071
      ssw_cell_type = SSWCellType::To;
38 ✔
1072
    }
1073
  }
1074

1075
  // Check if the user has specified to write specific collisions
1076
  if (check_for_node(root, "collision_track")) {
7,043 ✔
1077
    settings::collision_track = true;
110 ✔
1078
    // Get collision track node
1079
    xml_node node_ct = root.child("collision_track");
110 ✔
1080
    collision_track_config = CollisionTrackConfig {};
110 ✔
1081

1082
    // Determine cell ids at which crossing particles are to be banked
1083
    if (check_for_node(node_ct, "cell_ids")) {
110 ✔
1084
      auto temp = get_node_array<int>(node_ct, "cell_ids");
62 ✔
1085
      for (const auto& b : temp) {
166 ✔
1086
        collision_track_config.cell_ids.insert(b);
104 ✔
1087
      }
1088
    }
62 ✔
1089
    if (check_for_node(node_ct, "reactions")) {
110 ✔
1090
      auto temp = get_node_array<std::string>(node_ct, "reactions");
44 ✔
1091
      for (const auto& b : temp) {
118 ✔
1092
        int reaction_int = reaction_mt(b);
74 ✔
1093
        if (reaction_int > 0) {
74 !
1094
          collision_track_config.mt_numbers.insert(reaction_int);
74 ✔
1095
        }
1096
      }
1097
    }
44 ✔
1098
    if (check_for_node(node_ct, "universe_ids")) {
110 ✔
1099
      auto temp = get_node_array<int>(node_ct, "universe_ids");
20 ✔
1100
      for (const auto& b : temp) {
40 ✔
1101
        collision_track_config.universe_ids.insert(b);
20 ✔
1102
      }
1103
    }
20 ✔
1104
    if (check_for_node(node_ct, "material_ids")) {
110 ✔
1105
      auto temp = get_node_array<int>(node_ct, "material_ids");
20 ✔
1106
      for (const auto& b : temp) {
50 ✔
1107
        collision_track_config.material_ids.insert(b);
30 ✔
1108
      }
1109
    }
20 ✔
1110
    if (check_for_node(node_ct, "nuclides")) {
110 ✔
1111
      auto temp = get_node_array<std::string>(node_ct, "nuclides");
20 ✔
1112
      for (const auto& b : temp) {
80 ✔
1113
        collision_track_config.nuclides.insert(b);
60 ✔
1114
      }
1115
    }
20 ✔
1116
    if (check_for_node(node_ct, "deposited_E_threshold")) {
110 ✔
1117
      collision_track_config.deposited_energy_threshold =
40 ✔
1118
        std::stod(get_node_value(node_ct, "deposited_E_threshold"));
40 ✔
1119
    }
1120
    // Get maximum number of particles to be banked per collision
1121
    if (check_for_node(node_ct, "max_collisions")) {
110 !
1122
      collision_track_config.max_collisions =
220 ✔
1123
        std::stoll(get_node_value(node_ct, "max_collisions"));
220 ✔
1124
    } else {
1125
      warning("A maximum number of collisions needs to be specified. "
×
1126
              "By default the code sets 'max_collisions' parameter equals to "
1127
              "1000.");
1128
    }
1129
    // Get maximum number of collision_track files to be created
1130
    if (check_for_node(node_ct, "max_collision_track_files")) {
110 !
1131
      collision_track_config.max_files =
×
1132
        std::stoll(get_node_value(node_ct, "max_collision_track_files"));
×
1133
    }
1134
    if (check_for_node(node_ct, "mcpl")) {
110 ✔
1135
      collision_track_config.mcpl_write = get_node_value_bool(node_ct, "mcpl");
16 ✔
1136
    }
1137
  }
1138

1139
  // If source is not separate and is to be written out in the statepoint
1140
  // file, make sure that the sourcepoint batch numbers are contained in the
1141
  // statepoint list
1142
  if (!source_separate) {
7,043 ✔
1143
    for (const auto& b : sourcepoint_batch) {
14,058 ✔
1144
      if (!contains(statepoint_batch, b)) {
14,146 !
1145
        fatal_error(
×
1146
          "Sourcepoint batches are not a subset of statepoint batches.");
1147
      }
1148
    }
1149
  }
1150

1151
  // Check if the user has specified to not reduce tallies at the end of every
1152
  // batch
1153
  if (check_for_node(root, "no_reduce")) {
7,043 ✔
1154
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
20 ✔
1155
  }
1156

1157
  // Check if the user has specified to use confidence intervals for
1158
  // uncertainties rather than standard deviations
1159
  if (check_for_node(root, "confidence_intervals")) {
7,043 ✔
1160
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
10 ✔
1161
  }
1162

1163
  // Check for output options
1164
  if (check_for_node(root, "output")) {
7,043 ✔
1165
    // Get pointer to output node
1166
    pugi::xml_node node_output = root.child("output");
641 ✔
1167

1168
    // Check for summary option
1169
    if (check_for_node(node_output, "summary")) {
641 ✔
1170
      output_summary = get_node_value_bool(node_output, "summary");
623 ✔
1171
    }
1172

1173
    // Check for ASCII tallies output option
1174
    if (check_for_node(node_output, "tallies")) {
641 ✔
1175
      output_tallies = get_node_value_bool(node_output, "tallies");
278 ✔
1176
    }
1177

1178
    // Set output directory if a path has been specified
1179
    if (check_for_node(node_output, "path")) {
641 !
1180
      path_output = get_node_value(node_output, "path");
×
1181
      if (!ends_with(path_output, "/")) {
×
1182
        path_output += "/";
641 !
1183
      }
1184
    }
1185
  }
1186

1187
  // Resonance scattering parameters
1188
  if (check_for_node(root, "resonance_scattering")) {
7,043 ✔
1189
    xml_node node_res_scat = root.child("resonance_scattering");
10 ✔
1190

1191
    // See if resonance scattering is enabled
1192
    if (check_for_node(node_res_scat, "enable")) {
10 !
1193
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
10 ✔
1194
    } else {
1195
      res_scat_on = true;
×
1196
    }
1197

1198
    // Determine what method is used
1199
    if (check_for_node(node_res_scat, "method")) {
10 !
1200
      auto temp = get_node_value(node_res_scat, "method", true, true);
10 ✔
1201
      if (temp == "rvs") {
10 !
1202
        res_scat_method = ResScatMethod::rvs;
10 ✔
1203
      } else if (temp == "dbrc") {
×
1204
        res_scat_method = ResScatMethod::dbrc;
×
1205
      } else {
1206
        fatal_error(
×
1207
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1208
      }
1209
    }
10 ✔
1210

1211
    // Minimum energy for resonance scattering
1212
    if (check_for_node(node_res_scat, "energy_min")) {
10 !
1213
      res_scat_energy_min =
20 ✔
1214
        std::stod(get_node_value(node_res_scat, "energy_min"));
20 ✔
1215
    }
1216
    if (res_scat_energy_min < 0.0) {
10 !
1217
      fatal_error("Lower resonance scattering energy bound is negative");
×
1218
    }
1219

1220
    // Maximum energy for resonance scattering
1221
    if (check_for_node(node_res_scat, "energy_max")) {
10 !
1222
      res_scat_energy_max =
20 ✔
1223
        std::stod(get_node_value(node_res_scat, "energy_max"));
20 ✔
1224
    }
1225
    if (res_scat_energy_max < res_scat_energy_min) {
10 !
1226
      fatal_error("Upper resonance scattering energy bound is below the "
×
1227
                  "lower resonance scattering energy bound.");
1228
    }
1229

1230
    // Get resonance scattering nuclides
1231
    if (check_for_node(node_res_scat, "nuclides")) {
10 !
1232
      res_scat_nuclides =
10 ✔
1233
        get_node_array<std::string>(node_res_scat, "nuclides");
20 ✔
1234
    }
1235
  }
1236

1237
  // Get volume calculations
1238
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
7,263 ✔
1239
    model::volume_calcs.emplace_back(node_vol);
220 ✔
1240
  }
1241

1242
  // Get temperature settings
1243
  if (check_for_node(root, "temperature_default")) {
7,043 ✔
1244
    temperature_default =
246 ✔
1245
      std::stod(get_node_value(root, "temperature_default"));
246 ✔
1246
  }
1247
  if (check_for_node(root, "temperature_method")) {
7,043 ✔
1248
    auto temp = get_node_value(root, "temperature_method", true, true);
340 ✔
1249
    if (temp == "nearest") {
340 ✔
1250
      temperature_method = TemperatureMethod::NEAREST;
212 ✔
1251
    } else if (temp == "interpolation") {
128 !
1252
      temperature_method = TemperatureMethod::INTERPOLATION;
128 ✔
1253
    } else {
1254
      fatal_error("Unknown temperature method: " + temp);
×
1255
    }
1256
  }
340 ✔
1257
  if (check_for_node(root, "temperature_tolerance")) {
7,043 ✔
1258
    temperature_tolerance =
708 ✔
1259
      std::stod(get_node_value(root, "temperature_tolerance"));
708 ✔
1260
  }
1261
  if (check_for_node(root, "temperature_multipole")) {
7,043 ✔
1262
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
241 ✔
1263

1264
    // Multipole currently doesn't work with photon transport
1265
    if (temperature_multipole && photon_transport) {
241 !
1266
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1267
                  "photon transport.");
1268
    }
1269
  }
1270
  if (check_for_node(root, "temperature_range")) {
7,043 ✔
1271
    auto range = get_node_array<double>(root, "temperature_range");
120 ✔
1272
    temperature_range[0] = range.at(0);
120 ✔
1273
    temperature_range[1] = range.at(1);
120 ✔
1274
  }
120 ✔
1275

1276
  // Check for tabular_legendre options
1277
  if (check_for_node(root, "tabular_legendre")) {
7,043 ✔
1278
    // Get pointer to tabular_legendre node
1279
    xml_node node_tab_leg = root.child("tabular_legendre");
80 ✔
1280

1281
    // Check for enable option
1282
    if (check_for_node(node_tab_leg, "enable")) {
80 !
1283
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
80 ✔
1284
    }
1285

1286
    // Check for the number of points
1287
    if (check_for_node(node_tab_leg, "num_points")) {
80 !
1288
      legendre_to_tabular_points =
×
1289
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
1290
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
1291
        fatal_error(
×
1292
          "The 'num_points' subelement/attribute of the "
1293
          "<tabular_legendre> element must contain a value greater than 1");
1294
      }
1295
    }
1296
  }
1297

1298
  // Check whether create delayed neutrons in fission
1299
  if (check_for_node(root, "create_delayed_neutrons")) {
7,043 !
1300
    create_delayed_neutrons =
×
1301
      get_node_value_bool(root, "create_delayed_neutrons");
×
1302
  }
1303

1304
  // Check whether create fission sites
1305
  if (run_mode == RunMode::FIXED_SOURCE) {
7,043 ✔
1306
    if (check_for_node(root, "create_fission_neutrons")) {
2,673 ✔
1307
      create_fission_neutrons =
241 ✔
1308
        get_node_value_bool(root, "create_fission_neutrons");
241 ✔
1309
    }
1310
  }
1311

1312
  // Check whether to scale fission photon yields
1313
  if (check_for_node(root, "delayed_photon_scaling")) {
7,043 !
1314
    delayed_photon_scaling =
×
1315
      get_node_value_bool(root, "delayed_photon_scaling");
×
1316
  }
1317

1318
  // Check whether to use event-based parallelism
1319
  if (check_for_node(root, "event_based")) {
7,043 !
1320
    event_based = get_node_value_bool(root, "event_based");
×
1321
  }
1322

1323
  // Check whether material cell offsets should be generated
1324
  if (check_for_node(root, "material_cell_offsets")) {
7,043 !
1325
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1326
  }
1327

1328
  // Weight window information
1329
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
7,259 ✔
1330
    variance_reduction::weight_windows.emplace_back(
216 ✔
1331
      std::make_unique<WeightWindows>(node_ww));
432 ✔
1332
  }
1333

1334
  // Enable weight windows by default if one or more are present
1335
  if (variance_reduction::weight_windows.size() > 0)
7,043 ✔
1336
    settings::weight_windows_on = true;
148 ✔
1337

1338
  // read weight windows from file
1339
  if (check_for_node(root, "weight_windows_file")) {
7,043 ✔
1340
    weight_windows_file = get_node_value(root, "weight_windows_file");
18 ✔
1341
    weight_windows_on = true;
18 ✔
1342
  }
1343

1344
  // read settings for weight windows value, this will override
1345
  // the automatic setting even if weight windows are present
1346
  if (check_for_node(root, "weight_windows_on")) {
7,043 ✔
1347
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
70 ✔
1348
  }
1349

1350
  if (check_for_node(root, "max_secondaries")) {
7,043 !
1351
    settings::max_secondaries =
×
1352
      std::stoi(get_node_value(root, "max_secondaries"));
×
1353
  }
1354

1355
  if (check_for_node(root, "max_history_splits")) {
7,043 ✔
1356
    settings::max_history_splits =
570 ✔
1357
      std::stoi(get_node_value(root, "max_history_splits"));
570 ✔
1358
  }
1359

1360
  if (check_for_node(root, "max_tracks")) {
7,043 ✔
1361
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
60 ✔
1362
  }
1363

1364
  // Create weight window generator objects
1365
  if (check_for_node(root, "weight_window_generators")) {
7,043 ✔
1366
    auto wwgs_node = root.child("weight_window_generators");
109 ✔
1367
    for (pugi::xml_node node_wwg :
218 ✔
1368
      wwgs_node.children("weight_windows_generator")) {
218 ✔
1369
      variance_reduction::weight_windows_generators.emplace_back(
109 ✔
1370
        std::make_unique<WeightWindowsGenerator>(node_wwg));
218 ✔
1371
    }
1372
    // if any of the weight windows are intended to be generated otf, make
1373
    // sure they're applied
1374
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
109 !
1375
      if (wwg->on_the_fly_) {
109 !
1376
        settings::weight_windows_on = true;
109 ✔
1377
        break;
109 ✔
1378
      }
1379
    }
1380
    // If any weight window generators have local FW-CADIS target tallies,
1381
    // user-defined adjoint sources cannot be used at the same time.
1382
    if (!model::adjoint_sources.empty()) {
109 !
1383
      for (const auto& wwg : variance_reduction::weight_windows_generators) {
×
1384
        if (!wwg->targets_.empty()) {
×
1385
          fatal_error("Cannot use both user-defined adjoint sources and "
×
1386
                      "FW-CADIS target tallies at the same time.");
1387
        }
1388
      }
1389
    }
1390
  }
1391

1392
  // Set up weight window checkpoints
1393
  if (check_for_node(root, "weight_window_checkpoints")) {
7,043 ✔
1394
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
128 ✔
1395
    if (check_for_node(ww_checkpoints, "collision")) {
128 !
1396
      weight_window_checkpoint_collision =
128 ✔
1397
        get_node_value_bool(ww_checkpoints, "collision");
128 ✔
1398
    }
1399
    if (check_for_node(ww_checkpoints, "surface")) {
128 !
1400
      weight_window_checkpoint_surface =
128 ✔
1401
        get_node_value_bool(ww_checkpoints, "surface");
128 ✔
1402
    }
1403
  }
1404

1405
  if (weight_windows_on) {
7,043 ✔
1406
    if (!weight_window_checkpoint_surface &&
267 ✔
1407
        !weight_window_checkpoint_collision)
147 !
1408
      fatal_error(
×
1409
        "Weight Windows are enabled but there are no valid checkpoints.");
1410
  }
1411

1412
  if (check_for_node(root, "use_decay_photons")) {
7,043 ✔
1413
    settings::use_decay_photons =
8 ✔
1414
      get_node_value_bool(root, "use_decay_photons");
8 ✔
1415
  }
1416

1417
  // If weight windows are on, also enable shared secondary bank (unless
1418
  // explicitly disabled by user).
1419
  if (check_for_node(root, "shared_secondary_bank")) {
7,043 ✔
1420
    bool val = get_node_value_bool(root, "shared_secondary_bank");
230 ✔
1421
    if (val && run_mode == RunMode::EIGENVALUE) {
230 !
1422
      warning(
×
1423
        "Shared secondary bank is not supported in eigenvalue calculations. "
1424
        "Setting will be ignored.");
1425
    } else {
1426
      settings::use_shared_secondary_bank = val;
230 ✔
1427
    }
1428
  } else if (settings::weight_windows_on) {
6,813 ✔
1429
    if (run_mode == RunMode::EIGENVALUE) {
141 !
1430
      warning(
48 !
1431
        "Shared secondary bank is not supported in eigenvalue calculations. "
1432
        "Particle local secondary banks will be used instead.");
1433
    } else if (run_mode == RunMode::FIXED_SOURCE) {
141 !
1434
      settings::use_shared_secondary_bank = true;
141 ✔
1435
    }
1436
  }
1437
}
7,043 ✔
1438

1439
void free_memory_settings()
7,200 ✔
1440
{
1441
  settings::statepoint_batch.clear();
7,200 ✔
1442
  settings::sourcepoint_batch.clear();
7,200 ✔
1443
  settings::source_write_surf_id.clear();
7,200 ✔
1444
  settings::res_scat_nuclides.clear();
7,200 ✔
1445
  settings::track_identifiers.clear();
7,200 ✔
1446
  settings::ifp_delayed_group_on = false;
7,200 ✔
1447
  settings::ifp_lifetime_on = false;
7,200 ✔
1448
}
7,200 ✔
1449

1450
//==============================================================================
1451
// C API functions
1452
//==============================================================================
1453

1454
namespace {
1455

1456
int invalid_setting(const char* type, const char* name)
×
1457
{
1458
  set_errmsg(fmt::format("Unknown {} setting '{}'.", type, name));
×
1459
  return OPENMC_E_INVALID_ARGUMENT;
×
1460
}
1461

1462
bool* bool_setting(const char* name)
3,248 ✔
1463
{
1464
  if (std::strcmp(name, "cmfd_run") == 0) {
3,248 ✔
1465
    return &settings::cmfd_run;
1466
  } else if (std::strcmp(name, "entropy_on") == 0) {
3,088 ✔
1467
    return &settings::entropy_on;
1468
  } else if (std::strcmp(name, "event_based") == 0) {
1,376 ✔
1469
    return &settings::event_based;
1470
  } else if (std::strcmp(name, "need_depletion_rx") == 0) {
1,216 ✔
1471
    return &simulation::need_depletion_rx;
1472
  } else if (std::strcmp(name, "photon_transport") == 0) {
592 ✔
1473
    return &settings::photon_transport;
1474
  } else if (std::strcmp(name, "output_summary") == 0) {
552 ✔
1475
    return &settings::output_summary;
1476
  } else if (std::strcmp(name, "reduce_tallies") == 0) {
512 ✔
1477
    return &settings::reduce_tallies;
1478
  } else if (std::strcmp(name, "restart_run") == 0) {
472 ✔
1479
    return &settings::restart_run;
1480
  } else if (std::strcmp(name, "run_ce") == 0) {
312 ✔
1481
    return &settings::run_CE;
1482
  } else if (std::strcmp(name, "trigger_on") == 0) {
160 ✔
1483
    return &settings::trigger_on;
1484
  } else if (std::strcmp(name, "weight_windows_on") == 0) {
120 !
1485
    return &settings::weight_windows_on;
120 ✔
1486
  }
1487
  return nullptr;
1488
}
1489

1490
} // namespace
1491

1492
extern "C" int openmc_setting_get_bool(const char* name, bool* value)
2,232 ✔
1493
{
1494
  if (!name || !value) {
2,232 !
1495
    set_errmsg("Setting name and output pointer must not be null.");
×
1496
    return OPENMC_E_INVALID_ARGUMENT;
×
1497
  }
1498

1499
  bool* setting = bool_setting(name);
2,232 ✔
1500
  if (!setting)
2,232 !
1501
    return invalid_setting("boolean", name);
×
1502

1503
  *value = *setting;
2,232 ✔
1504
  return 0;
2,232 ✔
1505
}
1506

1507
extern "C" int openmc_setting_set_bool(const char* name, bool value)
1,016 ✔
1508
{
1509
  if (!name) {
1,016 !
1510
    set_errmsg("Setting name must not be null.");
×
1511
    return OPENMC_E_INVALID_ARGUMENT;
×
1512
  }
1513

1514
  bool* setting = bool_setting(name);
1,016 ✔
1515
  if (!setting)
1,016 !
1516
    return invalid_setting("boolean", name);
×
1517

1518
  *setting = value;
1,016 ✔
1519
  return 0;
1,016 ✔
1520
}
1521

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

1529
  if (std::strcmp(name, "gen_per_batch") == 0) {
888 ✔
1530
    *value = settings::gen_per_batch;
32 ✔
1531
  } else if (std::strcmp(name, "max_lost_particles") == 0) {
856 ✔
1532
    *value = settings::max_lost_particles;
24 ✔
1533
  } else if (std::strcmp(name, "max_write_lost_particles") == 0) {
832 ✔
1534
    *value = settings::max_write_lost_particles;
24 ✔
1535
  } else if (std::strcmp(name, "n_inactive") == 0) {
808 ✔
1536
    *value = settings::n_inactive;
32 ✔
1537
  } else if (std::strcmp(name, "run_mode") == 0) {
776 ✔
1538
    *value = static_cast<int32_t>(settings::run_mode);
16 ✔
1539
  } else if (std::strcmp(name, "verbosity") == 0) {
760 !
1540
    *value = settings::verbosity;
760 ✔
1541
  } else {
1542
    return invalid_setting("int32", name);
×
1543
  }
1544
  return 0;
1545
}
1546

1547
extern "C" int openmc_setting_set_int32(const char* name, int32_t value)
96 ✔
1548
{
1549
  if (!name) {
96 !
1550
    set_errmsg("Setting name must not be null.");
×
1551
    return OPENMC_E_INVALID_ARGUMENT;
×
1552
  }
1553

1554
  if (std::strcmp(name, "gen_per_batch") == 0) {
96 ✔
1555
    settings::gen_per_batch = value;
16 ✔
1556
  } else if (std::strcmp(name, "max_lost_particles") == 0) {
80 ✔
1557
    settings::max_lost_particles = value;
16 ✔
1558
  } else if (std::strcmp(name, "max_write_lost_particles") == 0) {
64 ✔
1559
    settings::max_write_lost_particles = value;
16 ✔
1560
  } else if (std::strcmp(name, "n_inactive") == 0) {
48 ✔
1561
    settings::n_inactive = value;
16 ✔
1562
  } else if (std::strcmp(name, "run_mode") == 0) {
32 ✔
1563
    if (value < static_cast<int32_t>(RunMode::UNSET) ||
16 !
1564
        value > static_cast<int32_t>(RunMode::VOLUME)) {
1565
      set_errmsg(fmt::format("Invalid run mode: {}.", value));
×
1566
      return OPENMC_E_INVALID_ARGUMENT;
×
1567
    }
1568
    settings::run_mode = static_cast<RunMode>(value);
16 ✔
1569
  } else if (std::strcmp(name, "verbosity") == 0) {
16 !
1570
    settings::verbosity = value;
16 ✔
1571
  } else {
1572
    return invalid_setting("int32", name);
×
1573
  }
1574
  return 0;
1575
}
1576

1577
extern "C" int openmc_setting_get_int64(const char* name, int64_t* value)
88 ✔
1578
{
1579
  if (!name || !value) {
88 !
1580
    set_errmsg("Setting name and output pointer must not be null.");
×
1581
    return OPENMC_E_INVALID_ARGUMENT;
×
1582
  }
1583

1584
  if (std::strcmp(name, "n_particles") != 0)
88 !
1585
    return invalid_setting("int64", name);
×
1586

1587
  *value = settings::n_particles;
88 ✔
1588
  return 0;
88 ✔
1589
}
1590

1591
extern "C" int openmc_setting_set_int64(const char* name, int64_t value)
72 ✔
1592
{
1593
  if (!name) {
72 !
1594
    set_errmsg("Setting name must not be null.");
×
1595
    return OPENMC_E_INVALID_ARGUMENT;
×
1596
  }
1597

1598
  if (std::strcmp(name, "n_particles") != 0)
72 !
1599
    return invalid_setting("int64", name);
×
1600

1601
  settings::n_particles = value;
72 ✔
1602
  return 0;
72 ✔
1603
}
1604

1605
extern "C" int openmc_setting_get_double(const char* name, double* value)
24 ✔
1606
{
1607
  if (!name || !value) {
24 !
1608
    set_errmsg("Setting name and output pointer must not be null.");
×
1609
    return OPENMC_E_INVALID_ARGUMENT;
×
1610
  }
1611

1612
  if (std::strcmp(name, "rel_max_lost_particles") != 0)
24 !
1613
    return invalid_setting("double", name);
×
1614

1615
  *value = settings::rel_max_lost_particles;
24 ✔
1616
  return 0;
24 ✔
1617
}
1618

1619
extern "C" int openmc_setting_set_double(const char* name, double value)
16 ✔
1620
{
1621
  if (!name) {
16 !
1622
    set_errmsg("Setting name must not be null.");
×
1623
    return OPENMC_E_INVALID_ARGUMENT;
×
1624
  }
1625

1626
  if (std::strcmp(name, "rel_max_lost_particles") != 0)
16 !
1627
    return invalid_setting("double", name);
×
1628

1629
  settings::rel_max_lost_particles = value;
16 ✔
1630
  return 0;
16 ✔
1631
}
1632

1633
extern "C" int openmc_setting_get_string(const char* name, const char** value)
16 ✔
1634
{
1635
  if (!name || !value) {
16 !
1636
    set_errmsg("Setting name and output pointer must not be null.");
×
1637
    return OPENMC_E_INVALID_ARGUMENT;
×
1638
  }
1639

1640
  if (std::strcmp(name, "path_statepoint") != 0)
16 !
1641
    return invalid_setting("string", name);
×
1642

1643
  *value = settings::path_statepoint.c_str();
16 ✔
1644
  return 0;
16 ✔
1645
}
1646

1647
extern "C" int openmc_set_n_batches(
160 ✔
1648
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1649
{
1650
  if (settings::n_inactive >= n_batches) {
160 ✔
1651
    set_errmsg("Number of active batches must be greater than zero.");
8 ✔
1652
    return OPENMC_E_INVALID_ARGUMENT;
8 ✔
1653
  }
1654

1655
  if (!settings::trigger_on) {
152 ✔
1656
    // Set n_batches and n_max_batches to same value
1657
    settings::n_batches = n_batches;
136 ✔
1658
    settings::n_max_batches = n_batches;
136 ✔
1659
  } else {
1660
    // Set n_batches and n_max_batches based on value of set_max_batches
1661
    if (set_max_batches) {
16 ✔
1662
      settings::n_max_batches = n_batches;
8 ✔
1663
    } else {
1664
      settings::n_batches = n_batches;
8 ✔
1665
    }
1666
  }
1667

1668
  // Update size of k_generation and entropy
1669
  int m = settings::n_max_batches * settings::gen_per_batch;
152 ✔
1670
  simulation::k_generation.reserve(m);
152 ✔
1671
  simulation::entropy.reserve(m);
152 ✔
1672

1673
  // Add value of n_batches to statepoint_batch
1674
  if (add_statepoint_batch &&
152 ✔
1675
      !(contains(settings::statepoint_batch, n_batches)))
144 ✔
1676
    settings::statepoint_batch.insert(n_batches);
24 ✔
1677

1678
  return 0;
1679
}
1680

1681
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
1,840 ✔
1682
{
1683
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
1,840 ✔
1684

1685
  return 0;
1,840 ✔
1686
}
1687

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