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

openmc-dev / openmc / 34651633654

11 Sep 2026 09:54PM UTC coverage: 81.567% (+0.05%) from 81.519%
34651633654

Pull #3734

github

web-flow
Merge c6ad4e970 into 073c170cd
Pull Request #3734: Specify temperature from a field (structured mesh only)

19203 of 27733 branches covered (69.24%)

Branch coverage included in aggregate %.

293 of 311 new or added lines in 16 files covered. (94.21%)

317 existing lines in 10 files now uncovered.

61427 of 71118 relevant lines covered (86.37%)

49983235.31 hits per line

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

76.23
/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)
8,630 ✔
165
{
166
  using namespace settings;
8,630 ✔
167
  using namespace pugi;
8,630 ✔
168

169
  // Check number of particles
170
  if (!check_for_node(node_base, "particles")) {
8,630 !
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) {
8,630 ✔
176
    n_particles = std::stoll(get_node_value(node_base, "particles"));
8,564 ✔
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")) {
8,630 !
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")) {
8,630 !
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")) {
8,630 !
193
    n_batches = std::stoi(get_node_value(node_base, "batches"));
8,630 ✔
194
  }
195
  if (!trigger_on)
8,630 ✔
196
    n_max_batches = n_batches;
8,489 ✔
197

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

204
  // Get relative number of lost particles
205
  if (check_for_node(node_base, "rel_max_lost_particles")) {
8,630 !
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")) {
8,630 ✔
212
    max_write_lost_particles =
30 ✔
213
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
15 ✔
214
  }
215

216
  // Get number of inactive batches
217
  if (run_mode == RunMode::EIGENVALUE ||
8,630 ✔
218
      solver_type == SolverType::RANDOM_RAY) {
3,680 ✔
219
    if (check_for_node(node_base, "inactive")) {
5,580 ✔
220
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
5,176 ✔
221
    }
222
    if (check_for_node(node_base, "generations_per_batch")) {
5,580 ✔
223
      gen_per_batch =
30 ✔
224
        std::stoi(get_node_value(node_base, "generations_per_batch"));
15 ✔
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) {
15 !
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;
5,580 ✔
238
    simulation::k_generation.reserve(m);
5,580 ✔
239
    simulation::entropy.reserve(m);
5,580 ✔
240

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

245
      if (check_for_node(node_keff_trigger, "type")) {
101 !
246
        auto temp = get_node_value(node_keff_trigger, "type", true, true);
101 ✔
247
        if (temp == "std_dev") {
101 !
248
          keff_trigger.metric = TriggerMetric::standard_deviation;
101 ✔
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")) {
101 !
261
        keff_trigger.threshold =
202 ✔
262
          std::stod(get_node_value(node_keff_trigger, "threshold"));
202 ✔
263
        if (keff_trigger.threshold <= 0) {
101 !
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) {
8,630 ✔
274
    xml_node random_ray_node = node_base.child("random_ray");
1,061 ✔
275
    if (check_for_node(random_ray_node, "distance_active")) {
1,061 !
276
      RandomRay::distance_active_ =
2,122 ✔
277
        std::stod(get_node_value(random_ray_node, "distance_active"));
2,122 ✔
278
      if (RandomRay::distance_active_ <= 0.0) {
1,061 !
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")) {
1,061 !
285
      RandomRay::distance_inactive_ =
2,122 ✔
286
        std::stod(get_node_value(random_ray_node, "distance_inactive"));
2,122 ✔
287
      if (RandomRay::distance_inactive_ < 0) {
1,061 !
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")) {
1,061 !
295
      xml_node ray_source_node = random_ray_node.child("ray_source");
1,061 ✔
296
      xml_node source_node = ray_source_node.child("source");
1,061 ✔
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);
2,122 ✔
300
    } else {
301
      fatal_error("Specify random ray source in settings XML");
×
302
    }
303
    if (check_for_node(random_ray_node, "volume_estimator")) {
1,061 ✔
304
      std::string temp_str =
664 ✔
305
        get_node_value(random_ray_node, "volume_estimator", true, true);
664 ✔
306
      if (temp_str == "simulation_averaged") {
664 ✔
307
        FlatSourceDomain::volume_estimator_ =
30 ✔
308
          RandomRayVolumeEstimator::SIMULATION_AVERAGED;
309
      } else if (temp_str == "naive") {
634 ✔
310
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::NAIVE;
132 ✔
311
      } else if (temp_str == "hybrid") {
502 ✔
312
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::HYBRID;
367 ✔
313
      } else if (temp_str == "adaptive") {
135 ✔
314
        FlatSourceDomain::volume_estimator_ =
90 ✔
315
          RandomRayVolumeEstimator::ADAPTIVE;
316
      } else if (temp_str == "strict_adaptive") {
45 !
317
        FlatSourceDomain::volume_estimator_ =
45 ✔
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
    }
664 ✔
325
    if (check_for_node(random_ray_node, "source_shape")) {
1,061 ✔
326
      std::string temp_str =
547 ✔
327
        get_node_value(random_ray_node, "source_shape", true, true);
547 ✔
328
      if (temp_str == "flat") {
547 ✔
329
        RandomRay::source_shape_ = RandomRaySourceShape::FLAT;
97 ✔
330
      } else if (temp_str == "linear") {
450 ✔
331
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR;
405 ✔
332
      } else if (temp_str == "linear_xy") {
45 !
333
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR_XY;
45 ✔
334
      } else {
335
        fatal_error("Unrecognized source shape: " + temp_str);
×
336
      }
337
    }
547 ✔
338
    if (check_for_node(random_ray_node, "volume_normalized_flux_tallies")) {
1,061 ✔
339
      FlatSourceDomain::volume_normalized_flux_tallies_ =
738 ✔
340
        get_node_value_bool(random_ray_node, "volume_normalized_flux_tallies");
738 ✔
341
    }
342
    if (check_for_node(random_ray_node, "adjoint")) {
1,061 ✔
343
      FlatSourceDomain::adjoint_requested_ =
86 ✔
344
        get_node_value_bool(random_ray_node, "adjoint");
86 ✔
345
    }
346
    if (check_for_node(random_ray_node, "source_gradient_limiter")) {
1,061 ✔
347
      FlatSourceDomain::source_gradient_limiter_ =
15 ✔
348
        get_node_value_bool(random_ray_node, "source_gradient_limiter");
15 ✔
349
    }
350
    if (check_for_node(random_ray_node, "sample_method")) {
1,061 ✔
351
      std::string temp_str =
52 ✔
352
        get_node_value(random_ray_node, "sample_method", true, true);
52 ✔
353
      if (temp_str == "prng") {
52 !
UNCOV
354
        RandomRay::sample_method_ = RandomRaySampleMethod::PRNG;
×
355
      } else if (temp_str == "halton") {
52 ✔
356
        RandomRay::sample_method_ = RandomRaySampleMethod::HALTON;
37 ✔
357
      } else if (temp_str == "s2") {
15 !
358
        RandomRay::sample_method_ = RandomRaySampleMethod::S2;
15 ✔
359
      } else {
UNCOV
360
        fatal_error("Unrecognized sample method: " + temp_str);
×
361
      }
362
    }
52 ✔
363
    if (check_for_node(random_ray_node, "source_region_meshes")) {
1,061 ✔
364
      pugi::xml_node node_source_region_meshes =
458 ✔
365
        random_ray_node.child("source_region_meshes");
458 ✔
366
      for (pugi::xml_node node_mesh :
976 ✔
367
        node_source_region_meshes.children("mesh")) {
976 ✔
368
        int mesh_id = std::stoi(node_mesh.attribute("id").value());
1,036 ✔
369
        for (pugi::xml_node node_domain : node_mesh.children("domain")) {
1,036 ✔
370
          int domain_id = std::stoi(node_domain.attribute("id").value());
1,036 ✔
371
          std::string domain_type = node_domain.attribute("type").value();
518 ✔
372
          Source::DomainType type;
518 ✔
373
          if (domain_type == "material") {
518 ✔
374
            type = Source::DomainType::MATERIAL;
30 ✔
375
          } else if (domain_type == "cell") {
488 ✔
376
            type = Source::DomainType::CELL;
30 ✔
377
          } else if (domain_type == "universe") {
458 !
378
            type = Source::DomainType::UNIVERSE;
458 ✔
379
          } else {
UNCOV
380
            throw std::runtime_error("Unknown domain type: " + domain_type);
×
381
          }
382
          FlatSourceDomain::mesh_domain_map_[mesh_id].emplace_back(
518 ✔
383
            type, domain_id);
384
        }
518 ✔
385
      }
386
    }
387
    if (check_for_node(random_ray_node, "diagonal_stabilization_rho")) {
1,061 ✔
388
      FlatSourceDomain::diagonal_stabilization_rho_ = std::stod(
30 ✔
389
        get_node_value(random_ray_node, "diagonal_stabilization_rho"));
30 ✔
390
      if (FlatSourceDomain::diagonal_stabilization_rho_ < 0.0 ||
30 !
391
          FlatSourceDomain::diagonal_stabilization_rho_ > 1.0) {
UNCOV
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")) {
1,061 ✔
397
      pugi::xml_node adj_source_node = random_ray_node.child("adjoint_source");
15 ✔
398
      for (pugi::xml_node source_node : adj_source_node.children("source")) {
30 ✔
399
        // Find any local adjoint sources
400
        model::adjoint_sources.push_back(Source::create(source_node));
30 ✔
401
      }
402
    }
403
  }
404
}
8,630 ✔
405

406
void read_settings_xml()
1,423 ✔
407
{
408
  using namespace settings;
1,423 ✔
409
  using namespace pugi;
1,423 ✔
410
  // Check if settings.xml exists
411
  std::string filename = settings::path_input + "settings.xml";
1,423 ✔
412
  if (!file_exists(filename)) {
1,423 ✔
413
    if (run_mode != RunMode::PLOTTING) {
22 !
UNCOV
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;
22 ✔
422
    }
423
  }
424

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

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

435
  // Verbosity
436
  if (check_for_node(root, "verbosity") && verbosity == -1) {
1,401 !
437
    verbosity = std::stoi(get_node_value(root, "verbosity"));
428 ✔
438
  } else if (verbosity == -1) {
1,187 !
439
    verbosity = 7;
1,187 ✔
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,401 ✔
445
    if (verbosity >= 2)
1,213 ✔
446
      title();
1,007 ✔
447
  }
448

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

451
  read_settings_xml(root);
1,401 ✔
452
}
1,413 ✔
453

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

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

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

472
  // Look for deprecated cross_sections.xml file in settings.xml
473
  if (check_for_node(root, "cross_sections")) {
9,747 !
UNCOV
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.");
UNCOV
480
    path_cross_sections = get_node_value(root, "cross_sections");
×
481
  }
482

483
  if (!run_CE) {
9,747 ✔
484
    // Scattering Treatments
485
    if (check_for_node(root, "max_order")) {
1,626 ✔
486
      max_order = std::stoi(get_node_value(root, "max_order"));
30 ✔
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,611 ✔
493
    }
494
  }
495

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

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

503
    if (trigger_on) {
156 ✔
504
      if (check_for_node(node_trigger, "max_batches")) {
141 !
505
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
282 ✔
506
      } else {
UNCOV
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")) {
141 ✔
512
        trigger_predict = true;
15 ✔
513
      } else {
514
        trigger_batch_interval =
252 ✔
515
          std::stoi(get_node_value(node_trigger, "batch_interval"));
252 ✔
516
        if (trigger_batch_interval <= 0) {
126 !
UNCOV
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;
9,747 ✔
525
  if (run_mode == RunMode::UNSET) {
9,747 ✔
526
    if (check_for_node(root, "run_mode")) {
8,662 ✔
527
      std::string temp_str = get_node_value(root, "run_mode", true, true);
8,632 ✔
528
      if (temp_str == "eigenvalue") {
8,632 ✔
529
        run_mode = RunMode::EIGENVALUE;
4,920 ✔
530
      } else if (temp_str == "fixed source") {
3,712 ✔
531
        run_mode = RunMode::FIXED_SOURCE;
3,680 ✔
532
      } else if (temp_str == "plot") {
32 !
UNCOV
533
        run_mode = RunMode::PLOTTING;
×
534
      } else if (temp_str == "particle restart") {
32 !
535
        run_mode = RunMode::PARTICLE;
×
536
      } else if (temp_str == "volume") {
32 !
537
        run_mode = RunMode::VOLUME;
32 ✔
538
      } else {
UNCOV
539
        fatal_error("Unrecognized run mode: " + temp_str);
×
540
      }
541

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

547
      // Make sure that either eigenvalue or fixed source was specified
548
      node_mode = root.child("eigenvalue");
30 ✔
549
      if (node_mode) {
30 !
550
        run_mode = RunMode::EIGENVALUE;
30 ✔
551
      } else {
552
        node_mode = root.child("fixed_source");
×
UNCOV
553
        if (node_mode) {
×
UNCOV
554
          run_mode = RunMode::FIXED_SOURCE;
×
555
        } else {
UNCOV
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")) {
9,747 ✔
564
    solver_type = SolverType::RANDOM_RAY;
1,061 ✔
565
    if (run_CE)
1,061 !
UNCOV
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) {
9,747 ✔
571
    // Read run parameters
572
    get_run_parameters(node_mode);
8,630 ✔
573

574
    // Check number of active batches, inactive batches, max lost particles and
575
    // particles
576
    if (n_batches <= n_inactive) {
8,630 !
577
      fatal_error("Number of active batches must be greater than zero.");
×
578
    } else if (n_inactive < 0) {
8,630 !
579
      fatal_error("Number of inactive batches must be non-negative.");
×
580
    } else if (n_particles <= 0) {
8,630 !
581
      fatal_error("Number of particles must be greater than zero.");
×
582
    } else if (max_lost_particles <= 0) {
8,630 !
UNCOV
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) {
8,630 !
UNCOV
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")) {
8,630 ✔
591
      ifp_n_generation = std::stoi(get_node_value(root, "ifp_n_generation"));
210 ✔
592
      if (ifp_n_generation <= 0) {
105 !
UNCOV
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) {
105 ✔
597
        fatal_error("'ifp_n_generation' must be lower than or equal to the "
9 ✔
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")) {
9,738 !
UNCOV
605
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
UNCOV
606
    model::plotter_seed = seed;
×
607
  }
608

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

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

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

633
  // Check for photon transport
634
  if (check_for_node(root, "photon_transport")) {
9,738 ✔
635
    photon_transport = get_node_value_bool(root, "photon_transport");
486 ✔
636

637
    if (!run_CE && photon_transport) {
486 !
UNCOV
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")) {
9,738 ✔
645
    atomic_relaxation = get_node_value_bool(root, "atomic_relaxation");
30 ✔
646
  }
647

648
  // Number of bins for logarithmic grid
649
  if (check_for_node(root, "log_grid_bins")) {
9,738 ✔
650
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
30 ✔
651
    if (n_log_bins < 1) {
15 !
UNCOV
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")) {
9,738 !
UNCOV
659
    if (mpi::master)
×
UNCOV
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")) {
18,532 ✔
670
    model::external_sources.push_back(Source::create(node));
17,598 ✔
671
  }
672

673
  // Check if the user has specified to read surface source
674
  if (check_for_node(root, "surf_source_read")) {
9,728 ✔
675
    if (mpi::master)
30 ✔
676
      warning("The <surf_source_read> element has been deprecated. Use a file "
44 ✔
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");
30 ✔
683

684
    std::string path = "surface_source.h5";
30 ✔
685
    // Check if the user has specified different file for surface source reading
686
    if (check_for_node(node_ssr, "path")) {
30 !
687
      path = get_node_value(node_ssr, "path", false, true);
30 ✔
688
    }
689
    model::external_sources.push_back(make_unique<FileSource>(path));
30 ✔
690
  }
30 ✔
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() &&
9,728 ✔
695
      settings::solver_type != SolverType::RANDOM_RAY) {
2,638 ✔
696
    double T[] {0.0};
2,432 ✔
697
    double p[] {1.0};
2,432 ✔
698
    model::external_sources.push_back(make_unique<IndependentSource>(
2,432 ✔
699
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
4,864 ✔
700
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
4,864 ✔
701
      UPtrDist {new Discrete(T, p, 1)}));
4,864 ✔
702
  }
703

704
  // Build probability mass function for sampling external sources
705
  vector<double> source_strengths;
9,728 ✔
706
  for (auto& s : model::external_sources) {
21,039 ✔
707
    source_strengths.push_back(s->strength());
11,311 ✔
708
  }
709
  model::external_sources_probability.assign(source_strengths);
9,728 ✔
710

711
  // Check if we want to write out source
712
  if (check_for_node(root, "write_initial_source")) {
9,728 !
UNCOV
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")) {
9,728 ✔
718
    source_rejection_fraction =
14 ✔
719
      std::stod(get_node_value(root, "source_rejection_fraction"));
14 !
720
  }
721

722
  if (check_for_node(root, "free_gas_threshold")) {
9,728 !
UNCOV
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"))
9,728 !
728
    surface_grazing_cutoff =
×
UNCOV
729
      std::stod(get_node_value(root, "surface_grazing_cutoff"));
×
730
  if (check_for_node(root, "surface_grazing_ratio"))
9,728 !
UNCOV
731
    surface_grazing_ratio =
×
UNCOV
732
      std::stod(get_node_value(root, "surface_grazing_ratio"));
×
733

734
  // Survival biasing
735
  if (check_for_node(root, "survival_biasing")) {
9,728 ✔
736
    survival_biasing = get_node_value_bool(root, "survival_biasing");
227 ✔
737
  }
738

739
  // Probability tables
740
  if (check_for_node(root, "ptables")) {
9,728 ✔
741
    urr_ptables_on = get_node_value_bool(root, "ptables");
15 ✔
742
  }
743

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

799
  // Particle trace
800
  if (check_for_node(root, "trace")) {
9,728 ✔
801
    auto temp = get_node_array<int64_t>(root, "trace");
15 ✔
802
    if (temp.size() != 3) {
15 !
UNCOV
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);
15 ✔
807
    trace_gen = temp.at(1);
15 ✔
808
    trace_particle = temp.at(2);
15 ✔
809
  }
15 ✔
810

811
  // Particle tracks
812
  if (check_for_node(root, "track")) {
9,728 ✔
813
    // Get values and make sure there are three per particle
814
    auto temp = get_node_array<int>(root, "track");
45 ✔
815
    if (temp.size() % 3 != 0) {
45 !
UNCOV
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;
45 ✔
824
    for (int i = 0; i < n_tracks; ++i) {
180 ✔
825
      track_identifiers.push_back(
135 ✔
826
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
135 ✔
827
    }
828
  }
45 ✔
829

830
  // Shannon entropy
831
  if (solver_type == SolverType::RANDOM_RAY) {
9,728 ✔
832
    if (check_for_node(root, "entropy_mesh")) {
1,061 !
UNCOV
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;
1,061 ✔
837
  } else if (solver_type == SolverType::MONTE_CARLO) {
8,667 !
838
    if (check_for_node(root, "entropy_mesh")) {
8,667 ✔
839
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
668 ✔
840
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
334 !
UNCOV
841
        fatal_error(fmt::format(
×
842
          "Mesh {} specified for Shannon entropy does not exist.", temp));
843
      }
844

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

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

854
    } else if (check_for_node(root, "entropy")) {
8,333 !
UNCOV
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")) {
9,728 ✔
864
    // The random ray solver does not apply temperature fields. Leave the flag
865
    // off here so that every consumer of the field -- cross section loading,
866
    // transport, plotting -- agrees that it is not in use, rather than each
867
    // one having to exclude the solver on its own. The field is still parsed
868
    // so that malformed input is still reported.
869
    if (solver_type == SolverType::RANDOM_RAY) {
135 !
NEW
870
      warning("Temperature fields are not supported with the random ray "
×
871
              "solver. It will be ignored during this simulation.");
872
    } else {
873
      temperature_field_on = true;
135 ✔
874
    }
875

876
    // Get pointer to temperature_field node
877
    auto node_tf = root.child("temperature_field");
135 ✔
878

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

899
    // Values parameter
900
    vector<double> tf_values;
102 ✔
901
    if (check_for_node(node_tf, "values")) {
102 ✔
902
      auto temp = get_node_array<double>(node_tf, "values");
91 ✔
903
      if (temp.size() != tf_mesh_ptr->n_bins()) {
91 ✔
904
        throw std::runtime_error(
11 ✔
905
          "Inconsistency in the temperature field: the number of "
906
          "values must be equal to the number of bins in the mesh.");
22 ✔
907
      }
908
      for (const auto& b : temp) {
577 ✔
909
        tf_values.push_back(b);
497 ✔
910
      }
911
    } else {
11 ✔
912
      throw std::runtime_error(
11 ✔
913
        "Temperature values should be given for the temperature field.");
22 ✔
914
    }
915

916
    // Instantiate the temperature field
917
    simulation::temperature_field = TemperatureField(tf_mesh_ptr, tf_values);
251 ✔
918
  }
102 ✔
919

920
  // Uniform fission source weighting mesh
921
  if (check_for_node(root, "ufs_mesh")) {
9,662 ✔
922
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
30 ✔
923
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
15 !
UNCOV
924
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
925
                              "method does not exist.",
926
        temp));
927
    }
928

929
    auto* m =
15 ✔
930
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
15 !
931
    if (!m)
15 !
UNCOV
932
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
933
    simulation::ufs_mesh = m;
15 ✔
934

935
    // Turn on uniform fission source weighting
936
    ufs_on = true;
15 ✔
937

938
  } else if (check_for_node(root, "uniform_fs")) {
9,647 !
UNCOV
939
    fatal_error(
×
940
      "Specifying a UFS mesh via the <uniform_fs> element "
941
      "is deprecated. Please create a mesh using <mesh> and then reference "
942
      "it by specifying its ID in a <ufs_mesh> element.");
943
  }
944

945
  // Check if the user has specified to write state points
946
  if (check_for_node(root, "state_point")) {
9,662 ✔
947

948
    // Get pointer to state_point node
949
    auto node_sp = root.child("state_point");
160 ✔
950

951
    // Determine number of batches at which to store state points
952
    if (check_for_node(node_sp, "batches")) {
160 !
953
      // User gave specific batches to write state points
954
      auto temp = get_node_array<int>(node_sp, "batches");
160 ✔
955
      for (const auto& b : temp) {
491 ✔
956
        statepoint_batch.insert(b);
331 ✔
957
      }
958
    } else {
160 ✔
959
      // If neither were specified, write state point at last batch
UNCOV
960
      statepoint_batch.insert(n_batches);
×
961
    }
962
  } else {
963
    // If no <state_point> tag was present, by default write state point at
964
    // last batch only
965
    statepoint_batch.insert(n_batches);
9,502 ✔
966
  }
967

968
  // Check if the user has specified to write source points
969
  if (check_for_node(root, "source_point")) {
9,662 ✔
970
    // Get source_point node
971
    xml_node node_sp = root.child("source_point");
101 ✔
972

973
    // Determine batches at which to store source points
974
    if (check_for_node(node_sp, "batches")) {
101 ✔
975
      // User gave specific batches to write source points
976
      auto temp = get_node_array<int>(node_sp, "batches");
45 ✔
977
      for (const auto& b : temp) {
120 ✔
978
        sourcepoint_batch.insert(b);
75 ✔
979
      }
980
    } else {
45 ✔
981
      // If neither were specified, write source points with state points
982
      sourcepoint_batch = statepoint_batch;
56 !
983
    }
984

985
    // Check if the user has specified to write binary source file
986
    if (check_for_node(node_sp, "separate")) {
101 ✔
987
      source_separate = get_node_value_bool(node_sp, "separate");
71 ✔
988
    }
989
    if (check_for_node(node_sp, "write")) {
101 !
UNCOV
990
      source_write = get_node_value_bool(node_sp, "write");
×
991
    }
992
    if (check_for_node(node_sp, "mcpl")) {
101 ✔
993
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
26 ✔
994
    }
995
    if (check_for_node(node_sp, "overwrite_latest")) {
101 ✔
996
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
15 ✔
997
      source_separate = source_latest;
15 ✔
998
    }
999
  } else {
1000
    // If no <source_point> tag was present, by default we keep source bank in
1001
    // statepoint file and write it out at statepoints intervals
1002
    source_separate = false;
9,561 ✔
1003
    sourcepoint_batch = statepoint_batch;
9,561 !
1004
  }
1005

1006
  // Check is the user specified to convert strength to statistical weight
1007
  if (check_for_node(root, "uniform_source_sampling")) {
9,662 ✔
1008
    uniform_source_sampling =
55 ✔
1009
      get_node_value_bool(root, "uniform_source_sampling");
55 ✔
1010
  }
1011

1012
  // Check if the user has specified to write surface source
1013
  if (check_for_node(root, "surf_source_write")) {
9,662 ✔
1014
    surf_source_write = true;
412 ✔
1015
    // Get surface source write node
1016
    xml_node node_ssw = root.child("surf_source_write");
412 ✔
1017

1018
    // Determine surface ids at which crossing particles are to be banked.
1019
    // If no surfaces are specified, all surfaces in the model will be used
1020
    // to bank source points.
1021
    if (check_for_node(node_ssw, "surface_ids")) {
412 ✔
1022
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
202 ✔
1023
      for (const auto& b : temp) {
994 ✔
1024
        source_write_surf_id.insert(b);
792 ✔
1025
      }
1026
    }
202 ✔
1027

1028
    // Get maximum number of particles to be banked per surface
1029
    if (check_for_node(node_ssw, "max_particles")) {
412 ✔
1030
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
806 ✔
1031
    } else {
1032
      fatal_error("A maximum number of particles needs to be specified "
9 ✔
1033
                  "using the 'max_particles' parameter to store surface "
1034
                  "source points.");
1035
    }
1036

1037
    // Get maximum number of surface source files to be created
1038
    if (check_for_node(node_ssw, "max_source_files")) {
403 ✔
1039
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
66 ✔
1040
    } else {
1041
      ssw_max_files = 1;
370 ✔
1042
    }
1043

1044
    if (check_for_node(node_ssw, "mcpl")) {
403 ✔
1045
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
11 ✔
1046
    }
1047
    // Get cell information
1048
    if (check_for_node(node_ssw, "cell")) {
403 ✔
1049
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
208 ✔
1050
      ssw_cell_type = SSWCellType::Both;
104 ✔
1051
    }
1052
    if (check_for_node(node_ssw, "cellfrom")) {
403 ✔
1053
      if (ssw_cell_id != C_NONE) {
90 ✔
1054
        fatal_error(
18 ✔
1055
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
1056
      }
1057
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
144 ✔
1058
      ssw_cell_type = SSWCellType::From;
72 ✔
1059
    }
1060
    if (check_for_node(node_ssw, "cellto")) {
385 ✔
1061
      if (ssw_cell_id != C_NONE) {
71 ✔
1062
        fatal_error(
18 ✔
1063
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
1064
      }
1065
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
106 ✔
1066
      ssw_cell_type = SSWCellType::To;
53 ✔
1067
    }
1068
  }
1069

1070
  // Check if the user has specified to write specific collisions
1071
  if (check_for_node(root, "collision_track")) {
9,617 ✔
1072
    settings::collision_track = true;
160 ✔
1073
    // Get collision track node
1074
    xml_node node_ct = root.child("collision_track");
160 ✔
1075
    collision_track_config = CollisionTrackConfig {};
160 ✔
1076

1077
    // Determine cell ids at which crossing particles are to be banked
1078
    if (check_for_node(node_ct, "cell_ids")) {
160 ✔
1079
      auto temp = get_node_array<int>(node_ct, "cell_ids");
89 ✔
1080
      for (const auto& b : temp) {
237 ✔
1081
        collision_track_config.cell_ids.insert(b);
148 ✔
1082
      }
1083
    }
89 ✔
1084
    if (check_for_node(node_ct, "reactions")) {
160 ✔
1085
      auto temp = get_node_array<std::string>(node_ct, "reactions");
63 ✔
1086
      for (const auto& b : temp) {
171 ✔
1087
        int reaction_int = reaction_mt(b);
108 ✔
1088
        if (reaction_int > 0) {
108 !
1089
          collision_track_config.mt_numbers.insert(reaction_int);
108 ✔
1090
        }
1091
      }
1092
    }
63 ✔
1093
    if (check_for_node(node_ct, "universe_ids")) {
160 ✔
1094
      auto temp = get_node_array<int>(node_ct, "universe_ids");
30 ✔
1095
      for (const auto& b : temp) {
60 ✔
1096
        collision_track_config.universe_ids.insert(b);
30 ✔
1097
      }
1098
    }
30 ✔
1099
    if (check_for_node(node_ct, "material_ids")) {
160 ✔
1100
      auto temp = get_node_array<int>(node_ct, "material_ids");
30 ✔
1101
      for (const auto& b : temp) {
75 ✔
1102
        collision_track_config.material_ids.insert(b);
45 ✔
1103
      }
1104
    }
30 ✔
1105
    if (check_for_node(node_ct, "nuclides")) {
160 ✔
1106
      auto temp = get_node_array<std::string>(node_ct, "nuclides");
30 ✔
1107
      for (const auto& b : temp) {
120 ✔
1108
        collision_track_config.nuclides.insert(b);
90 ✔
1109
      }
1110
    }
30 ✔
1111
    if (check_for_node(node_ct, "deposited_E_threshold")) {
160 ✔
1112
      collision_track_config.deposited_energy_threshold =
60 ✔
1113
        std::stod(get_node_value(node_ct, "deposited_E_threshold"));
60 ✔
1114
    }
1115
    // Get maximum number of particles to be banked per collision
1116
    if (check_for_node(node_ct, "max_collisions")) {
160 !
1117
      collision_track_config.max_collisions =
320 ✔
1118
        std::stoll(get_node_value(node_ct, "max_collisions"));
320 ✔
1119
    } else {
UNCOV
1120
      warning("A maximum number of collisions needs to be specified. "
×
1121
              "By default the code sets 'max_collisions' parameter equals to "
1122
              "1000.");
1123
    }
1124
    // Get maximum number of collision_track files to be created
1125
    if (check_for_node(node_ct, "max_collision_track_files")) {
160 !
UNCOV
1126
      collision_track_config.max_files =
×
UNCOV
1127
        std::stoll(get_node_value(node_ct, "max_collision_track_files"));
×
1128
    }
1129
    if (check_for_node(node_ct, "mcpl")) {
160 ✔
1130
      collision_track_config.mcpl_write = get_node_value_bool(node_ct, "mcpl");
22 ✔
1131
    }
1132
  }
1133

1134
  // If source is not separate and is to be written out in the statepoint
1135
  // file, make sure that the sourcepoint batch numbers are contained in the
1136
  // statepoint list
1137
  if (!source_separate) {
9,617 ✔
1138
    for (const auto& b : sourcepoint_batch) {
19,188 ✔
1139
      if (!contains(statepoint_batch, b)) {
19,314 !
UNCOV
1140
        fatal_error(
×
1141
          "Sourcepoint batches are not a subset of statepoint batches.");
1142
      }
1143
    }
1144
  }
1145

1146
  // Check if the user has specified to not reduce tallies at the end of every
1147
  // batch
1148
  if (check_for_node(root, "no_reduce")) {
9,617 ✔
1149
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
30 ✔
1150
  }
1151

1152
  // Check if the user has specified to use confidence intervals for
1153
  // uncertainties rather than standard deviations
1154
  if (check_for_node(root, "confidence_intervals")) {
9,617 ✔
1155
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
15 ✔
1156
  }
1157

1158
  // Check for output options
1159
  if (check_for_node(root, "output")) {
9,617 ✔
1160
    // Get pointer to output node
1161
    pugi::xml_node node_output = root.child("output");
892 ✔
1162

1163
    // Check for summary option
1164
    if (check_for_node(node_output, "summary")) {
892 ✔
1165
      output_summary = get_node_value_bool(node_output, "summary");
866 ✔
1166
    }
1167

1168
    // Check for ASCII tallies output option
1169
    if (check_for_node(node_output, "tallies")) {
892 ✔
1170
      output_tallies = get_node_value_bool(node_output, "tallies");
382 ✔
1171
    }
1172

1173
    // Set output directory if a path has been specified
1174
    if (check_for_node(node_output, "path")) {
892 !
UNCOV
1175
      path_output = get_node_value(node_output, "path");
×
UNCOV
1176
      if (!ends_with(path_output, "/")) {
×
1177
        path_output += "/";
892 !
1178
      }
1179
    }
1180
  }
1181

1182
  // Resonance scattering parameters
1183
  if (check_for_node(root, "resonance_scattering")) {
9,617 ✔
1184
    xml_node node_res_scat = root.child("resonance_scattering");
15 ✔
1185

1186
    // See if resonance scattering is enabled
1187
    if (check_for_node(node_res_scat, "enable")) {
15 !
1188
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
15 ✔
1189
    } else {
UNCOV
1190
      res_scat_on = true;
×
1191
    }
1192

1193
    // Determine what method is used
1194
    if (check_for_node(node_res_scat, "method")) {
15 !
1195
      auto temp = get_node_value(node_res_scat, "method", true, true);
15 ✔
1196
      if (temp == "rvs") {
15 !
1197
        res_scat_method = ResScatMethod::rvs;
15 ✔
1198
      } else if (temp == "dbrc") {
×
UNCOV
1199
        res_scat_method = ResScatMethod::dbrc;
×
1200
      } else {
UNCOV
1201
        fatal_error(
×
UNCOV
1202
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1203
      }
1204
    }
15 ✔
1205

1206
    // Minimum energy for resonance scattering
1207
    if (check_for_node(node_res_scat, "energy_min")) {
15 !
1208
      res_scat_energy_min =
30 ✔
1209
        std::stod(get_node_value(node_res_scat, "energy_min"));
30 ✔
1210
    }
1211
    if (res_scat_energy_min < 0.0) {
15 !
UNCOV
1212
      fatal_error("Lower resonance scattering energy bound is negative");
×
1213
    }
1214

1215
    // Maximum energy for resonance scattering
1216
    if (check_for_node(node_res_scat, "energy_max")) {
15 !
1217
      res_scat_energy_max =
30 ✔
1218
        std::stod(get_node_value(node_res_scat, "energy_max"));
30 ✔
1219
    }
1220
    if (res_scat_energy_max < res_scat_energy_min) {
15 !
UNCOV
1221
      fatal_error("Upper resonance scattering energy bound is below the "
×
1222
                  "lower resonance scattering energy bound.");
1223
    }
1224

1225
    // Get resonance scattering nuclides
1226
    if (check_for_node(node_res_scat, "nuclides")) {
15 !
1227
      res_scat_nuclides =
15 ✔
1228
        get_node_array<std::string>(node_res_scat, "nuclides");
30 ✔
1229
    }
1230
  }
1231

1232
  // Get volume calculations
1233
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
9,927 ✔
1234
    model::volume_calcs.emplace_back(node_vol);
310 ✔
1235
  }
1236

1237
  // Get temperature settings
1238
  if (check_for_node(root, "temperature_default")) {
9,617 ✔
1239
    temperature_default =
342 ✔
1240
      std::stod(get_node_value(root, "temperature_default"));
342 ✔
1241
  }
1242
  if (check_for_node(root, "temperature_method")) {
9,617 ✔
1243
    auto temp = get_node_value(root, "temperature_method", true, true);
485 ✔
1244
    if (temp == "nearest") {
485 ✔
1245
      temperature_method = TemperatureMethod::NEAREST;
304 ✔
1246
    } else if (temp == "interpolation") {
181 !
1247
      temperature_method = TemperatureMethod::INTERPOLATION;
181 ✔
1248
    } else {
UNCOV
1249
      fatal_error("Unknown temperature method: " + temp);
×
1250
    }
1251
  }
485 ✔
1252
  if (check_for_node(root, "temperature_tolerance")) {
9,617 ✔
1253
    temperature_tolerance =
774 ✔
1254
      std::stod(get_node_value(root, "temperature_tolerance"));
774 ✔
1255
  }
1256
  if (check_for_node(root, "temperature_multipole")) {
9,617 ✔
1257
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
232 ✔
1258

1259
    // Multipole currently doesn't work with photon transport
1260
    if (temperature_multipole && photon_transport) {
232 !
UNCOV
1261
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1262
                  "photon transport.");
1263
    }
1264
  }
1265
  if (check_for_node(root, "temperature_range")) {
9,617 ✔
1266
    auto range = get_node_array<double>(root, "temperature_range");
170 ✔
1267
    temperature_range[0] = range.at(0);
170 ✔
1268
    temperature_range[1] = range.at(1);
170 ✔
1269
  }
170 ✔
1270

1271
  // Check for tabular_legendre options
1272
  if (check_for_node(root, "tabular_legendre")) {
9,617 ✔
1273
    // Get pointer to tabular_legendre node
1274
    xml_node node_tab_leg = root.child("tabular_legendre");
105 ✔
1275

1276
    // Check for enable option
1277
    if (check_for_node(node_tab_leg, "enable")) {
105 !
1278
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
105 ✔
1279
    }
1280

1281
    // Check for the number of points
1282
    if (check_for_node(node_tab_leg, "num_points")) {
105 !
UNCOV
1283
      legendre_to_tabular_points =
×
UNCOV
1284
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
UNCOV
1285
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
UNCOV
1286
        fatal_error(
×
1287
          "The 'num_points' subelement/attribute of the "
1288
          "<tabular_legendre> element must contain a value greater than 1");
1289
      }
1290
    }
1291
  }
1292

1293
  // Check whether create delayed neutrons in fission
1294
  if (check_for_node(root, "create_delayed_neutrons")) {
9,617 !
UNCOV
1295
    create_delayed_neutrons =
×
UNCOV
1296
      get_node_value_bool(root, "create_delayed_neutrons");
×
1297
  }
1298

1299
  // Check whether create fission sites
1300
  if (run_mode == RunMode::FIXED_SOURCE) {
9,617 ✔
1301
    if (check_for_node(root, "create_fission_neutrons")) {
3,634 ✔
1302
      create_fission_neutrons =
336 ✔
1303
        get_node_value_bool(root, "create_fission_neutrons");
336 ✔
1304
    }
1305
  }
1306

1307
  // Check whether to scale fission photon yields
1308
  if (check_for_node(root, "delayed_photon_scaling")) {
9,617 !
UNCOV
1309
    delayed_photon_scaling =
×
UNCOV
1310
      get_node_value_bool(root, "delayed_photon_scaling");
×
1311
  }
1312

1313
  // Check whether to use event-based parallelism
1314
  if (check_for_node(root, "event_based")) {
9,617 !
UNCOV
1315
    event_based = get_node_value_bool(root, "event_based");
×
1316
  }
1317

1318
  // Check whether material cell offsets should be generated
1319
  if (check_for_node(root, "material_cell_offsets")) {
9,617 !
UNCOV
1320
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1321
  }
1322

1323
  // Weight window information
1324
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
9,922 ✔
1325
    variance_reduction::weight_windows.emplace_back(
305 ✔
1326
      std::make_unique<WeightWindows>(node_ww));
610 ✔
1327
  }
1328

1329
  // Enable weight windows by default if one or more are present
1330
  if (variance_reduction::weight_windows.size() > 0)
9,617 ✔
1331
    settings::weight_windows_on = true;
209 ✔
1332

1333
  // read weight windows from file
1334
  if (check_for_node(root, "weight_windows_file")) {
9,617 ✔
1335
    weight_windows_file = get_node_value(root, "weight_windows_file");
26 ✔
1336
    weight_windows_on = true;
26 ✔
1337
  }
1338

1339
  // read settings for weight windows value, this will override
1340
  // the automatic setting even if weight windows are present
1341
  if (check_for_node(root, "weight_windows_on")) {
9,617 ✔
1342
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
93 ✔
1343
  }
1344

1345
  if (check_for_node(root, "max_secondaries")) {
9,617 !
UNCOV
1346
    settings::max_secondaries =
×
UNCOV
1347
      std::stoi(get_node_value(root, "max_secondaries"));
×
1348
  }
1349

1350
  if (check_for_node(root, "max_history_splits")) {
9,617 ✔
1351
    settings::max_history_splits =
798 ✔
1352
      std::stoi(get_node_value(root, "max_history_splits"));
798 ✔
1353
  }
1354

1355
  if (check_for_node(root, "max_tracks")) {
9,617 ✔
1356
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
90 ✔
1357
  }
1358

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

1387
  // Set up weight window checkpoints
1388
  if (check_for_node(root, "weight_window_checkpoints")) {
9,617 ✔
1389
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
184 ✔
1390
    if (check_for_node(ww_checkpoints, "collision")) {
184 !
1391
      weight_window_checkpoint_collision =
184 ✔
1392
        get_node_value_bool(ww_checkpoints, "collision");
184 ✔
1393
    }
1394
    if (check_for_node(ww_checkpoints, "surface")) {
184 !
1395
      weight_window_checkpoint_surface =
184 ✔
1396
        get_node_value_bool(ww_checkpoints, "surface");
184 ✔
1397
    }
1398
  }
1399

1400
  if (weight_windows_on) {
9,617 ✔
1401
    if (!weight_window_checkpoint_surface &&
366 ✔
1402
        !weight_window_checkpoint_collision)
193 !
UNCOV
1403
      fatal_error(
×
1404
        "Weight Windows are enabled but there are no valid checkpoints.");
1405
  }
1406

1407
  if (check_for_node(root, "use_decay_photons")) {
9,617 ✔
1408
    settings::use_decay_photons =
11 ✔
1409
      get_node_value_bool(root, "use_decay_photons");
11 ✔
1410
  }
1411

1412
  // If weight windows are on, also enable shared secondary bank (unless
1413
  // explicitly disabled by user).
1414
  if (check_for_node(root, "shared_secondary_bank")) {
9,617 ✔
1415
    bool val = get_node_value_bool(root, "shared_secondary_bank");
335 ✔
1416
    if (val && run_mode == RunMode::EIGENVALUE) {
335 !
UNCOV
1417
      warning(
×
1418
        "Shared secondary bank is not supported in eigenvalue calculations. "
1419
        "Setting will be ignored.");
1420
    } else {
1421
      settings::use_shared_secondary_bank = val;
335 ✔
1422
    }
1423
  } else if (settings::weight_windows_on) {
9,282 ✔
1424
    if (run_mode == RunMode::EIGENVALUE) {
184 !
1425
      warning(
66 !
1426
        "Shared secondary bank is not supported in eigenvalue calculations. "
1427
        "Particle local secondary banks will be used instead.");
1428
    } else if (run_mode == RunMode::FIXED_SOURCE) {
184 !
1429
      settings::use_shared_secondary_bank = true;
184 ✔
1430
    }
1431
  }
1432
}
9,617 ✔
1433

1434
void free_memory_settings()
9,834 ✔
1435
{
1436
  settings::statepoint_batch.clear();
9,834 ✔
1437
  settings::sourcepoint_batch.clear();
9,834 ✔
1438
  settings::source_write_surf_id.clear();
9,834 ✔
1439
  settings::res_scat_nuclides.clear();
9,834 ✔
1440
  settings::track_identifiers.clear();
9,834 ✔
1441
  settings::ifp_delayed_group_on = false;
9,834 ✔
1442
  settings::ifp_lifetime_on = false;
9,834 ✔
1443
}
9,834 ✔
1444

1445
//==============================================================================
1446
// C API functions
1447
//==============================================================================
1448

1449
namespace {
1450

UNCOV
1451
int invalid_setting(const char* type, const char* name)
×
1452
{
UNCOV
1453
  set_errmsg(fmt::format("Unknown {} setting '{}'.", type, name));
×
UNCOV
1454
  return OPENMC_E_INVALID_ARGUMENT;
×
1455
}
1456

1457
bool* bool_setting(const char* name)
4,466 ✔
1458
{
1459
  if (std::strcmp(name, "cmfd_run") == 0) {
4,466 ✔
1460
    return &settings::cmfd_run;
1461
  } else if (std::strcmp(name, "entropy_on") == 0) {
4,246 ✔
1462
    return &settings::entropy_on;
1463
  } else if (std::strcmp(name, "event_based") == 0) {
1,892 ✔
1464
    return &settings::event_based;
1465
  } else if (std::strcmp(name, "need_depletion_rx") == 0) {
1,672 ✔
1466
    return &simulation::need_depletion_rx;
1467
  } else if (std::strcmp(name, "photon_transport") == 0) {
814 ✔
1468
    return &settings::photon_transport;
1469
  } else if (std::strcmp(name, "output_summary") == 0) {
759 ✔
1470
    return &settings::output_summary;
1471
  } else if (std::strcmp(name, "reduce_tallies") == 0) {
704 ✔
1472
    return &settings::reduce_tallies;
1473
  } else if (std::strcmp(name, "restart_run") == 0) {
649 ✔
1474
    return &settings::restart_run;
1475
  } else if (std::strcmp(name, "run_ce") == 0) {
429 ✔
1476
    return &settings::run_CE;
1477
  } else if (std::strcmp(name, "trigger_on") == 0) {
220 ✔
1478
    return &settings::trigger_on;
1479
  } else if (std::strcmp(name, "weight_windows_on") == 0) {
165 !
1480
    return &settings::weight_windows_on;
165 ✔
1481
  }
1482
  return nullptr;
1483
}
1484

1485
} // namespace
1486

1487
extern "C" int openmc_setting_get_bool(const char* name, bool* value)
3,069 ✔
1488
{
1489
  if (!name || !value) {
3,069 !
UNCOV
1490
    set_errmsg("Setting name and output pointer must not be null.");
×
UNCOV
1491
    return OPENMC_E_INVALID_ARGUMENT;
×
1492
  }
1493

1494
  bool* setting = bool_setting(name);
3,069 ✔
1495
  if (!setting)
3,069 !
UNCOV
1496
    return invalid_setting("boolean", name);
×
1497

1498
  *value = *setting;
3,069 ✔
1499
  return 0;
3,069 ✔
1500
}
1501

1502
extern "C" int openmc_setting_set_bool(const char* name, bool value)
1,397 ✔
1503
{
1504
  if (!name) {
1,397 !
UNCOV
1505
    set_errmsg("Setting name must not be null.");
×
UNCOV
1506
    return OPENMC_E_INVALID_ARGUMENT;
×
1507
  }
1508

1509
  bool* setting = bool_setting(name);
1,397 ✔
1510
  if (!setting)
1,397 !
UNCOV
1511
    return invalid_setting("boolean", name);
×
1512

1513
  *setting = value;
1,397 ✔
1514
  return 0;
1,397 ✔
1515
}
1516

1517
extern "C" int openmc_setting_get_int32(const char* name, int32_t* value)
1,221 ✔
1518
{
1519
  if (!name || !value) {
1,221 !
UNCOV
1520
    set_errmsg("Setting name and output pointer must not be null.");
×
UNCOV
1521
    return OPENMC_E_INVALID_ARGUMENT;
×
1522
  }
1523

1524
  if (std::strcmp(name, "gen_per_batch") == 0) {
1,221 ✔
1525
    *value = settings::gen_per_batch;
44 ✔
1526
  } else if (std::strcmp(name, "max_lost_particles") == 0) {
1,177 ✔
1527
    *value = settings::max_lost_particles;
33 ✔
1528
  } else if (std::strcmp(name, "max_write_lost_particles") == 0) {
1,144 ✔
1529
    *value = settings::max_write_lost_particles;
33 ✔
1530
  } else if (std::strcmp(name, "n_inactive") == 0) {
1,111 ✔
1531
    *value = settings::n_inactive;
44 ✔
1532
  } else if (std::strcmp(name, "run_mode") == 0) {
1,067 ✔
1533
    *value = static_cast<int32_t>(settings::run_mode);
22 ✔
1534
  } else if (std::strcmp(name, "verbosity") == 0) {
1,045 !
1535
    *value = settings::verbosity;
1,045 ✔
1536
  } else {
UNCOV
1537
    return invalid_setting("int32", name);
×
1538
  }
1539
  return 0;
1540
}
1541

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

1549
  if (std::strcmp(name, "gen_per_batch") == 0) {
132 ✔
1550
    settings::gen_per_batch = value;
22 ✔
1551
  } else if (std::strcmp(name, "max_lost_particles") == 0) {
110 ✔
1552
    settings::max_lost_particles = value;
22 ✔
1553
  } else if (std::strcmp(name, "max_write_lost_particles") == 0) {
88 ✔
1554
    settings::max_write_lost_particles = value;
22 ✔
1555
  } else if (std::strcmp(name, "n_inactive") == 0) {
66 ✔
1556
    settings::n_inactive = value;
22 ✔
1557
  } else if (std::strcmp(name, "run_mode") == 0) {
44 ✔
1558
    if (value < static_cast<int32_t>(RunMode::UNSET) ||
22 !
1559
        value > static_cast<int32_t>(RunMode::VOLUME)) {
UNCOV
1560
      set_errmsg(fmt::format("Invalid run mode: {}.", value));
×
UNCOV
1561
      return OPENMC_E_INVALID_ARGUMENT;
×
1562
    }
1563
    settings::run_mode = static_cast<RunMode>(value);
22 ✔
1564
  } else if (std::strcmp(name, "verbosity") == 0) {
22 !
1565
    settings::verbosity = value;
22 ✔
1566
  } else {
UNCOV
1567
    return invalid_setting("int32", name);
×
1568
  }
1569
  return 0;
1570
}
1571

1572
extern "C" int openmc_setting_get_int64(const char* name, int64_t* value)
121 ✔
1573
{
1574
  if (!name || !value) {
121 !
UNCOV
1575
    set_errmsg("Setting name and output pointer must not be null.");
×
1576
    return OPENMC_E_INVALID_ARGUMENT;
×
1577
  }
1578

1579
  if (std::strcmp(name, "n_particles") != 0)
121 !
UNCOV
1580
    return invalid_setting("int64", name);
×
1581

1582
  *value = settings::n_particles;
121 ✔
1583
  return 0;
121 ✔
1584
}
1585

1586
extern "C" int openmc_setting_set_int64(const char* name, int64_t value)
99 ✔
1587
{
1588
  if (!name) {
99 !
UNCOV
1589
    set_errmsg("Setting name must not be null.");
×
1590
    return OPENMC_E_INVALID_ARGUMENT;
×
1591
  }
1592

1593
  if (std::strcmp(name, "n_particles") != 0)
99 !
UNCOV
1594
    return invalid_setting("int64", name);
×
1595

1596
  settings::n_particles = value;
99 ✔
1597
  return 0;
99 ✔
1598
}
1599

1600
extern "C" int openmc_setting_get_double(const char* name, double* value)
33 ✔
1601
{
1602
  if (!name || !value) {
33 !
UNCOV
1603
    set_errmsg("Setting name and output pointer must not be null.");
×
1604
    return OPENMC_E_INVALID_ARGUMENT;
×
1605
  }
1606

1607
  if (std::strcmp(name, "rel_max_lost_particles") != 0)
33 !
UNCOV
1608
    return invalid_setting("double", name);
×
1609

1610
  *value = settings::rel_max_lost_particles;
33 ✔
1611
  return 0;
33 ✔
1612
}
1613

1614
extern "C" int openmc_setting_set_double(const char* name, double value)
22 ✔
1615
{
1616
  if (!name) {
22 !
UNCOV
1617
    set_errmsg("Setting name must not be null.");
×
1618
    return OPENMC_E_INVALID_ARGUMENT;
×
1619
  }
1620

1621
  if (std::strcmp(name, "rel_max_lost_particles") != 0)
22 !
UNCOV
1622
    return invalid_setting("double", name);
×
1623

1624
  settings::rel_max_lost_particles = value;
22 ✔
1625
  return 0;
22 ✔
1626
}
1627

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

1635
  if (std::strcmp(name, "path_statepoint") != 0)
22 !
UNCOV
1636
    return invalid_setting("string", name);
×
1637

1638
  *value = settings::path_statepoint.c_str();
22 ✔
1639
  return 0;
22 ✔
1640
}
1641

1642
extern "C" int openmc_set_n_batches(
220 ✔
1643
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1644
{
1645
  if (settings::n_inactive >= n_batches) {
220 ✔
1646
    set_errmsg("Number of active batches must be greater than zero.");
11 ✔
1647
    return OPENMC_E_INVALID_ARGUMENT;
11 ✔
1648
  }
1649

1650
  if (!settings::trigger_on) {
209 ✔
1651
    // Set n_batches and n_max_batches to same value
1652
    settings::n_batches = n_batches;
187 ✔
1653
    settings::n_max_batches = n_batches;
187 ✔
1654
  } else {
1655
    // Set n_batches and n_max_batches based on value of set_max_batches
1656
    if (set_max_batches) {
22 ✔
1657
      settings::n_max_batches = n_batches;
11 ✔
1658
    } else {
1659
      settings::n_batches = n_batches;
11 ✔
1660
    }
1661
  }
1662

1663
  // Update size of k_generation and entropy
1664
  int m = settings::n_max_batches * settings::gen_per_batch;
209 ✔
1665
  simulation::k_generation.reserve(m);
209 ✔
1666
  simulation::entropy.reserve(m);
209 ✔
1667

1668
  // Add value of n_batches to statepoint_batch
1669
  if (add_statepoint_batch &&
209 ✔
1670
      !(contains(settings::statepoint_batch, n_batches)))
198 ✔
1671
    settings::statepoint_batch.insert(n_batches);
33 ✔
1672

1673
  return 0;
1674
}
1675

1676
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,530 ✔
1677
{
1678
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,530 ✔
1679

1680
  return 0;
2,530 ✔
1681
}
1682

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