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

openmc-dev / openmc / 22717173802

05 Mar 2026 12:07PM UTC coverage: 81.546% (+0.1%) from 81.45%
22717173802

Pull #3808

github

web-flow
Merge cde42e1c4 into dbfd6387b
Pull Request #3808: Add properties to settings w/ documentation, c++ loading of filename, and python round-trip test

17546 of 25273 branches covered (69.43%)

Branch coverage included in aggregate %.

25 of 29 new or added lines in 4 files covered. (86.21%)

5 existing lines in 2 files now uncovered.

57974 of 67337 relevant lines covered (86.1%)

44845803.14 hits per line

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

76.0
/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 <limits> // for numeric_limits
6
#include <string>
7

8
#include <fmt/core.h>
9
#ifdef _OPENMP
10
#include <omp.h>
11
#endif
12

13
#include "openmc/capi.h"
14
#include "openmc/collision_track.h"
15
#include "openmc/constants.h"
16
#include "openmc/container_util.h"
17
#include "openmc/distribution.h"
18
#include "openmc/distribution_multi.h"
19
#include "openmc/distribution_spatial.h"
20
#include "openmc/eigenvalue.h"
21
#include "openmc/error.h"
22
#include "openmc/file_utils.h"
23
#include "openmc/mcpl_interface.h"
24
#include "openmc/mesh.h"
25
#include "openmc/message_passing.h"
26
#include "openmc/output.h"
27
#include "openmc/plot.h"
28
#include "openmc/random_lcg.h"
29
#include "openmc/random_ray/random_ray.h"
30
#include "openmc/reaction.h"
31
#include "openmc/simulation.h"
32
#include "openmc/source.h"
33
#include "openmc/string_utils.h"
34
#include "openmc/tallies/trigger.h"
35
#include "openmc/volume_calc.h"
36
#include "openmc/weight_windows.h"
37
#include "openmc/xml_interface.h"
38

39
namespace openmc {
40

41
//==============================================================================
42
// Global variables
43
//==============================================================================
44

45
namespace settings {
46

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

91
std::string path_cross_sections;
92
std::string path_input;
93
std::string path_output;
94
std::string path_particle_restart;
95
std::string path_sourcepoint;
96
std::string path_statepoint;
97
const char* path_statepoint_c {path_statepoint.c_str()};
98
std::string weight_windows_file;
99
std::string properties_file;
100

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

108
int64_t max_particles_in_flight {100000};
109
int max_particle_events {1000000};
110

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

155
} // namespace settings
156

157
//==============================================================================
158
// Functions
159
//==============================================================================
160

161
void get_run_parameters(pugi::xml_node node_base)
7,377✔
162
{
163
  using namespace settings;
7,377✔
164
  using namespace pugi;
7,377✔
165

166
  // Check number of particles
167
  if (!check_for_node(node_base, "particles")) {
7,377!
168
    fatal_error("Need to specify number of particles.");
×
169
  }
170

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

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

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

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

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

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

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

213
  // Get number of inactive batches
214
  if (run_mode == RunMode::EIGENVALUE ||
7,377✔
215
      solver_type == SolverType::RANDOM_RAY) {
2,829✔
216
    if (check_for_node(node_base, "inactive")) {
4,954✔
217
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,743✔
218
    }
219
    if (check_for_node(node_base, "generations_per_batch")) {
4,954✔
220
      gen_per_batch =
30✔
221
        std::stoi(get_node_value(node_base, "generations_per_batch"));
15✔
222
    }
223

224
    // Preallocate space for keff and entropy by generation
225
    int m = settings::n_max_batches * settings::gen_per_batch;
4,954✔
226
    simulation::k_generation.reserve(m);
4,954✔
227
    simulation::entropy.reserve(m);
4,954✔
228

229
    // Get the trigger information for keff
230
    if (check_for_node(node_base, "keff_trigger")) {
4,954✔
231
      xml_node node_keff_trigger = node_base.child("keff_trigger");
101✔
232

233
      if (check_for_node(node_keff_trigger, "type")) {
101!
234
        auto temp = get_node_value(node_keff_trigger, "type", true, true);
101✔
235
        if (temp == "std_dev") {
101!
236
          keff_trigger.metric = TriggerMetric::standard_deviation;
101✔
237
        } else if (temp == "variance") {
×
238
          keff_trigger.metric = TriggerMetric::variance;
×
239
        } else if (temp == "rel_err") {
×
240
          keff_trigger.metric = TriggerMetric::relative_error;
×
241
        } else {
242
          fatal_error("Unrecognized keff trigger type " + temp);
×
243
        }
244
      } else {
×
245
        fatal_error("Specify keff trigger type in settings XML");
×
246
      }
247

248
      if (check_for_node(node_keff_trigger, "threshold")) {
101!
249
        keff_trigger.threshold =
202✔
250
          std::stod(get_node_value(node_keff_trigger, "threshold"));
202✔
251
        if (keff_trigger.threshold <= 0) {
101!
252
          fatal_error("keff trigger threshold must be positive");
×
253
        }
254
      } else {
255
        fatal_error("Specify keff trigger threshold in settings XML");
×
256
      }
257
    }
258
  }
259

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

374
void read_settings_xml()
1,349✔
375
{
376
  using namespace settings;
1,349✔
377
  using namespace pugi;
1,349✔
378
  // Check if settings.xml exists
379
  std::string filename = settings::path_input + "settings.xml";
1,349✔
380
  if (!file_exists(filename)) {
1,349✔
381
    if (run_mode != RunMode::PLOTTING) {
22!
382
      fatal_error("Could not find any XML input files! In order to run OpenMC, "
×
383
                  "you first need a set of input files; at a minimum, this "
384
                  "includes settings.xml, geometry.xml, and materials.xml or a "
385
                  "single model XML file. Please consult the user's guide at "
386
                  "https://docs.openmc.org for further information.");
387
    } else {
388
      // The settings.xml file is optional if we just want to make a plot.
389
      return;
22✔
390
    }
391
  }
392

393
  // Parse settings.xml file
394
  xml_document doc;
1,327✔
395
  auto result = doc.load_file(filename.c_str());
1,327✔
396
  if (!result) {
1,327!
397
    fatal_error("Error processing settings.xml file.");
×
398
  }
399

400
  // Get root element
401
  xml_node root = doc.document_element();
1,327✔
402

403
  // Verbosity
404
  if (check_for_node(root, "verbosity") && verbosity == -1) {
1,327!
405
    verbosity = std::stoi(get_node_value(root, "verbosity"));
362✔
406
  } else if (verbosity == -1) {
1,146!
407
    verbosity = 7;
1,146✔
408
  }
409

410
  // To this point, we haven't displayed any output since we didn't know what
411
  // the verbosity is. Now that we checked for it, show the title if necessary
412
  if (mpi::master) {
1,327✔
413
    if (verbosity >= 2)
1,147✔
414
      title();
974✔
415
  }
416

417
  write_message("Reading settings XML file...", 5);
1,327✔
418

419
  read_settings_xml(root);
1,327✔
420
}
1,339✔
421

422
void read_settings_xml(pugi::xml_node root)
8,185✔
423
{
424
  using namespace settings;
8,185✔
425
  using namespace pugi;
8,185✔
426

427
  // Find if a multi-group or continuous-energy simulation is desired
428
  if (check_for_node(root, "energy_mode")) {
8,185✔
429
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
1,286✔
430
    if (temp_str == "mg" || temp_str == "multi-group") {
2,572!
431
      run_CE = false;
1,286✔
432
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
433
      run_CE = true;
×
434
    }
435
  }
1,286✔
436

437
  // Check for user meshes and allocate
438
  read_meshes(root);
8,185✔
439

440
  // Look for deprecated cross_sections.xml file in settings.xml
441
  if (check_for_node(root, "cross_sections")) {
8,185!
442
    warning(
×
443
      "Setting cross_sections in settings.xml has been deprecated."
444
      " The cross_sections are now set in materials.xml and the "
445
      "cross_sections input to materials.xml and the OPENMC_CROSS_SECTIONS"
446
      " environment variable will take precendent over setting "
447
      "cross_sections in settings.xml.");
448
    path_cross_sections = get_node_value(root, "cross_sections");
×
449
  }
450

451
  if (!run_CE) {
8,185✔
452
    // Scattering Treatments
453
    if (check_for_node(root, "max_order")) {
1,286✔
454
      max_order = std::stoi(get_node_value(root, "max_order"));
30✔
455
    } else {
456
      // Set to default of largest int - 1, which means to use whatever is
457
      // contained in library. This is largest int - 1 because for legendre
458
      // scattering, a value of 1 is added to the order; adding 1 to the largest
459
      // int gets you the largest negative integer, which is not what we want.
460
      max_order = std::numeric_limits<int>::max() - 1;
1,271✔
461
    }
462
  }
463

464
  // Check for a trigger node and get trigger information
465
  if (check_for_node(root, "trigger")) {
8,185✔
466
    xml_node node_trigger = root.child("trigger");
156✔
467

468
    // Check if trigger(s) are to be turned on
469
    trigger_on = get_node_value_bool(node_trigger, "active");
156✔
470

471
    if (trigger_on) {
156✔
472
      if (check_for_node(node_trigger, "max_batches")) {
141!
473
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
282✔
474
      } else {
475
        fatal_error("<max_batches> must be specified with triggers");
×
476
      }
477

478
      // Get the batch interval to check triggers
479
      if (!check_for_node(node_trigger, "batch_interval")) {
141✔
480
        trigger_predict = true;
15✔
481
      } else {
482
        trigger_batch_interval =
252✔
483
          std::stoi(get_node_value(node_trigger, "batch_interval"));
252✔
484
        if (trigger_batch_interval <= 0) {
126!
485
          fatal_error("Trigger batch interval must be greater than zero");
×
486
        }
487
      }
488
    }
489
  }
490

491
  // Check run mode if it hasn't been set from the command line
492
  xml_node node_mode;
8,185✔
493
  if (run_mode == RunMode::UNSET) {
8,185✔
494
    if (check_for_node(root, "run_mode")) {
7,409✔
495
      std::string temp_str = get_node_value(root, "run_mode", true, true);
7,379✔
496
      if (temp_str == "eigenvalue") {
7,379✔
497
        run_mode = RunMode::EIGENVALUE;
4,518✔
498
      } else if (temp_str == "fixed source") {
2,861✔
499
        run_mode = RunMode::FIXED_SOURCE;
2,829✔
500
      } else if (temp_str == "plot") {
32!
501
        run_mode = RunMode::PLOTTING;
×
502
      } else if (temp_str == "particle restart") {
32!
503
        run_mode = RunMode::PARTICLE;
×
504
      } else if (temp_str == "volume") {
32!
505
        run_mode = RunMode::VOLUME;
32✔
506
      } else {
507
        fatal_error("Unrecognized run mode: " + temp_str);
×
508
      }
509

510
      // Assume XML specifies <particles>, <batches>, etc. directly
511
      node_mode = root;
7,379✔
512
    } else {
7,379✔
513
      warning("<run_mode> should be specified.");
30✔
514

515
      // Make sure that either eigenvalue or fixed source was specified
516
      node_mode = root.child("eigenvalue");
30✔
517
      if (node_mode) {
30!
518
        run_mode = RunMode::EIGENVALUE;
30✔
519
      } else {
520
        node_mode = root.child("fixed_source");
×
521
        if (node_mode) {
×
522
          run_mode = RunMode::FIXED_SOURCE;
×
523
        } else {
524
          fatal_error("<eigenvalue> or <fixed_source> not specified.");
×
525
        }
526
      }
527
    }
528
  }
529

530
  // Check solver type
531
  if (check_for_node(root, "random_ray")) {
8,185✔
532
    solver_type = SolverType::RANDOM_RAY;
762✔
533
    if (run_CE)
762!
534
      fatal_error("multi-group energy mode must be specified in settings XML "
×
535
                  "when using the random ray solver.");
536
  }
537

538
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
8,185✔
539
    // Read run parameters
540
    get_run_parameters(node_mode);
7,377✔
541

542
    // Check number of active batches, inactive batches, max lost particles and
543
    // particles
544
    if (n_batches <= n_inactive) {
7,377!
545
      fatal_error("Number of active batches must be greater than zero.");
×
546
    } else if (n_inactive < 0) {
7,377!
547
      fatal_error("Number of inactive batches must be non-negative.");
×
548
    } else if (n_particles <= 0) {
7,377!
549
      fatal_error("Number of particles must be greater than zero.");
×
550
    } else if (max_lost_particles <= 0) {
7,377!
551
      fatal_error("Number of max lost particles must be greater than zero.");
×
552
    } else if (rel_max_lost_particles <= 0.0 || rel_max_lost_particles >= 1.0) {
7,377!
553
      fatal_error("Relative max lost particles must be between zero and one.");
×
554
    }
555

556
    // Check for user value for the number of generation of the Iterated Fission
557
    // Probability (IFP) method
558
    if (check_for_node(root, "ifp_n_generation")) {
7,377✔
559
      ifp_n_generation = std::stoi(get_node_value(root, "ifp_n_generation"));
166✔
560
      if (ifp_n_generation <= 0) {
83!
561
        fatal_error("'ifp_n_generation' must be greater than 0.");
×
562
      }
563
      // Avoid tallying 0 if IFP logs are not complete when active cycles start
564
      if (ifp_n_generation > n_inactive) {
83✔
565
        fatal_error("'ifp_n_generation' must be lower than or equal to the "
9✔
566
                    "number of inactive cycles.");
567
      }
568
    }
569
  }
570

571
  // Copy plotting random number seed if specified
572
  if (check_for_node(root, "plot_seed")) {
8,176!
573
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
574
    model::plotter_seed = seed;
×
575
  }
576

577
  // Copy random number seed if specified
578
  if (check_for_node(root, "seed")) {
8,176✔
579
    auto seed = std::stoll(get_node_value(root, "seed"));
1,154✔
580
    openmc_set_seed(seed);
577✔
581
  }
582

583
  // Copy random number stride if specified
584
  if (check_for_node(root, "stride")) {
8,176✔
585
    auto stride = std::stoull(get_node_value(root, "stride"));
30✔
586
    openmc_set_stride(stride);
15✔
587
  }
588

589
  // Check for electron treatment
590
  if (check_for_node(root, "electron_treatment")) {
8,176✔
591
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
67✔
592
    if (temp_str == "led") {
67✔
593
      electron_treatment = ElectronTreatment::LED;
11✔
594
    } else if (temp_str == "ttb") {
56!
595
      electron_treatment = ElectronTreatment::TTB;
56✔
596
    } else {
597
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
598
    }
599
  }
67✔
600

601
  // Check for photon transport
602
  if (check_for_node(root, "photon_transport")) {
8,176✔
603
    photon_transport = get_node_value_bool(root, "photon_transport");
190✔
604

605
    if (!run_CE && photon_transport) {
190!
606
      fatal_error("Photon transport is not currently supported in "
×
607
                  "multigroup mode");
608
    }
609
  }
610

611
  // Number of bins for logarithmic grid
612
  if (check_for_node(root, "log_grid_bins")) {
8,176✔
613
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
30✔
614
    if (n_log_bins < 1) {
15!
615
      fatal_error("Number of bins for logarithmic grid must be greater "
×
616
                  "than zero.");
617
    }
618
  }
619

620
  // Number of OpenMP threads
621
  if (check_for_node(root, "threads")) {
8,176!
622
    if (mpi::master)
×
623
      warning("The <threads> element has been deprecated. Use "
×
624
              "the OMP_NUM_THREADS environment variable to set the number of "
625
              "threads.");
626
  }
627

628
  // ==========================================================================
629
  // EXTERNAL SOURCE
630

631
  // Get point to list of <source> elements and make sure there is at least one
632
  for (pugi::xml_node node : root.children("source")) {
15,830✔
633
    model::external_sources.push_back(Source::create(node));
15,318✔
634
  }
635

636
  // Check if the user has specified to read surface source
637
  if (check_for_node(root, "surf_source_read")) {
8,166✔
638
    surf_source_read = true;
30✔
639
    // Get surface source read node
640
    xml_node node_ssr = root.child("surf_source_read");
30✔
641

642
    std::string path = "surface_source.h5";
30✔
643
    // Check if the user has specified different file for surface source reading
644
    if (check_for_node(node_ssr, "path")) {
30!
645
      path = get_node_value(node_ssr, "path", false, true);
30✔
646
    }
647
    model::external_sources.push_back(make_unique<FileSource>(path));
30✔
648
  }
30✔
649

650
  // If no source specified, default to isotropic point source at origin with
651
  // Watt spectrum. No default source is needed in random ray mode.
652
  if (model::external_sources.empty() &&
8,166✔
653
      settings::solver_type != SolverType::RANDOM_RAY) {
2,205✔
654
    double T[] {0.0};
2,059✔
655
    double p[] {1.0};
2,059✔
656
    model::external_sources.push_back(make_unique<IndependentSource>(
2,059✔
657
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
4,118✔
658
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
4,118✔
659
      UPtrDist {new Discrete(T, p, 1)}));
4,118✔
660
  }
661

662
  // Build probability mass function for sampling external sources
663
  vector<double> source_strengths;
8,166✔
664
  for (auto& s : model::external_sources) {
17,909✔
665
    source_strengths.push_back(s->strength());
9,743✔
666
  }
667
  model::external_sources_probability.assign(source_strengths);
8,166✔
668

669
  // Check if we want to write out source
670
  if (check_for_node(root, "write_initial_source")) {
8,166!
671
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
672
  }
673

674
  // Get relative number of lost particles
675
  if (check_for_node(root, "source_rejection_fraction")) {
8,166✔
676
    source_rejection_fraction =
14✔
677
      std::stod(get_node_value(root, "source_rejection_fraction"));
14!
678
  }
679

680
  if (check_for_node(root, "free_gas_threshold")) {
8,166!
681
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
682
  }
683

684
  // Surface grazing
685
  if (check_for_node(root, "surface_grazing_cutoff"))
8,166!
686
    surface_grazing_cutoff =
×
687
      std::stod(get_node_value(root, "surface_grazing_cutoff"));
×
688
  if (check_for_node(root, "surface_grazing_ratio"))
8,166!
689
    surface_grazing_ratio =
×
690
      std::stod(get_node_value(root, "surface_grazing_ratio"));
×
691

692
  // Survival biasing
693
  if (check_for_node(root, "survival_biasing")) {
8,166✔
694
    survival_biasing = get_node_value_bool(root, "survival_biasing");
190✔
695
  }
696

697
  // Probability tables
698
  if (check_for_node(root, "ptables")) {
8,166✔
699
    urr_ptables_on = get_node_value_bool(root, "ptables");
15✔
700
  }
701

702
  // Cutoffs
703
  if (check_for_node(root, "cutoff")) {
8,166✔
704
    xml_node node_cutoff = root.child("cutoff");
138✔
705
    if (check_for_node(node_cutoff, "weight")) {
138✔
706
      weight_cutoff = std::stod(get_node_value(node_cutoff, "weight"));
30✔
707
    }
708
    if (check_for_node(node_cutoff, "weight_avg")) {
138✔
709
      weight_survive = std::stod(get_node_value(node_cutoff, "weight_avg"));
30✔
710
    }
711
    if (check_for_node(node_cutoff, "survival_normalization")) {
138!
712
      survival_normalization =
×
713
        get_node_value_bool(node_cutoff, "survival_normalization");
×
714
    }
715
    if (check_for_node(node_cutoff, "energy_neutron")) {
138✔
716
      energy_cutoff[0] =
15✔
717
        std::stod(get_node_value(node_cutoff, "energy_neutron"));
30✔
718
    } else if (check_for_node(node_cutoff, "energy")) {
123!
719
      warning("The use of an <energy> cutoff is deprecated and should "
×
720
              "be replaced by <energy_neutron>.");
721
      energy_cutoff[0] = std::stod(get_node_value(node_cutoff, "energy"));
×
722
    }
723
    if (check_for_node(node_cutoff, "energy_photon")) {
138✔
724
      energy_cutoff[1] =
82✔
725
        std::stod(get_node_value(node_cutoff, "energy_photon"));
164✔
726
    }
727
    if (check_for_node(node_cutoff, "energy_electron")) {
138!
728
      energy_cutoff[2] =
×
729
        std::stof(get_node_value(node_cutoff, "energy_electron"));
×
730
    }
731
    if (check_for_node(node_cutoff, "energy_positron")) {
138!
732
      energy_cutoff[3] =
×
733
        std::stod(get_node_value(node_cutoff, "energy_positron"));
×
734
    }
735
    if (check_for_node(node_cutoff, "time_neutron")) {
138✔
736
      time_cutoff[0] = std::stod(get_node_value(node_cutoff, "time_neutron"));
26✔
737
    }
738
    if (check_for_node(node_cutoff, "time_photon")) {
138!
NEW
739
      time_cutoff[1] = std::stod(get_node_value(node_cutoff, "time_photon"));
×
740
    }
741
    if (check_for_node(node_cutoff, "time_electron")) {
138!
NEW
742
      time_cutoff[2] = std::stod(get_node_value(node_cutoff, "time_electron"));
×
743
    }
744
    if (check_for_node(node_cutoff, "time_positron")) {
138!
UNCOV
745
      time_cutoff[3] = std::stod(get_node_value(node_cutoff, "time_positron"));
×
746
    }
747
  }
748

749
  // read properties from file
750
  if (check_for_node(root, "properties")) {
8,166!
UNCOV
751
    properties_file = get_node_value(root, "properties");
×
UNCOV
752
    if (!file_exists(properties_file)) {
×
753
      fatal_error(fmt::format("File '{}' does not exist.", properties_file));
×
754
    }
755
  }
756

757
  // Particle trace
758
  if (check_for_node(root, "trace")) {
8,166✔
759
    auto temp = get_node_array<int64_t>(root, "trace");
15✔
760
    if (temp.size() != 3) {
15!
761
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
762
                  "batch, generation, and particle number.");
763
    }
764
    trace_batch = temp.at(0);
15✔
765
    trace_gen = temp.at(1);
15✔
766
    trace_particle = temp.at(2);
15✔
767
  }
15✔
768

769
  // Particle tracks
770
  if (check_for_node(root, "track")) {
8,166✔
771
    // Get values and make sure there are three per particle
772
    auto temp = get_node_array<int>(root, "track");
45✔
773
    if (temp.size() % 3 != 0) {
45!
774
      fatal_error(
×
775
        "Number of integers specified in 'track' is not "
776
        "divisible by 3.  Please provide 3 integers per particle to be "
777
        "tracked.");
778
    }
779

780
    // Reshape into track_identifiers
781
    int n_tracks = temp.size() / 3;
45✔
782
    for (int i = 0; i < n_tracks; ++i) {
180✔
783
      track_identifiers.push_back(
135✔
784
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
135✔
785
    }
786
  }
45✔
787

788
  // Shannon entropy
789
  if (solver_type == SolverType::RANDOM_RAY) {
8,166✔
790
    if (check_for_node(root, "entropy_mesh")) {
762!
791
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
792
                  "No user-defined entropy mesh is supported.");
793
    }
794
    entropy_on = true;
762✔
795
  } else if (solver_type == SolverType::MONTE_CARLO) {
7,404!
796
    if (check_for_node(root, "entropy_mesh")) {
7,404✔
797
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
668✔
798
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
334!
799
        fatal_error(fmt::format(
×
800
          "Mesh {} specified for Shannon entropy does not exist.", temp));
801
      }
802

803
      auto* m = dynamic_cast<RegularMesh*>(
334!
804
        model::meshes[model::mesh_map.at(temp)].get());
334!
805
      if (!m)
334!
806
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
807
      simulation::entropy_mesh = m;
334✔
808

809
      // Turn on Shannon entropy calculation
810
      entropy_on = true;
334✔
811

812
    } else if (check_for_node(root, "entropy")) {
7,070!
813
      fatal_error(
×
814
        "Specifying a Shannon entropy mesh via the <entropy> element "
815
        "is deprecated. Please create a mesh using <mesh> and then reference "
816
        "it by specifying its ID in an <entropy_mesh> element.");
817
    }
818
  }
819
  // Uniform fission source weighting mesh
820
  if (check_for_node(root, "ufs_mesh")) {
8,166✔
821
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
30✔
822
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
15!
823
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
824
                              "method does not exist.",
825
        temp));
826
    }
827

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

834
    // Turn on uniform fission source weighting
835
    ufs_on = true;
15✔
836

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

844
  // Check if the user has specified to write state points
845
  if (check_for_node(root, "state_point")) {
8,166✔
846

847
    // Get pointer to state_point node
848
    auto node_sp = root.child("state_point");
160✔
849

850
    // Determine number of batches at which to store state points
851
    if (check_for_node(node_sp, "batches")) {
160!
852
      // User gave specific batches to write state points
853
      auto temp = get_node_array<int>(node_sp, "batches");
160✔
854
      for (const auto& b : temp) {
491✔
855
        statepoint_batch.insert(b);
331✔
856
      }
857
    } else {
160✔
858
      // If neither were specified, write state point at last batch
859
      statepoint_batch.insert(n_batches);
×
860
    }
861
  } else {
862
    // If no <state_point> tag was present, by default write state point at
863
    // last batch only
864
    statepoint_batch.insert(n_batches);
8,006✔
865
  }
866

867
  // Check if the user has specified to write source points
868
  if (check_for_node(root, "source_point")) {
8,166✔
869
    // Get source_point node
870
    xml_node node_sp = root.child("source_point");
101✔
871

872
    // Determine batches at which to store source points
873
    if (check_for_node(node_sp, "batches")) {
101✔
874
      // User gave specific batches to write source points
875
      auto temp = get_node_array<int>(node_sp, "batches");
45✔
876
      for (const auto& b : temp) {
120✔
877
        sourcepoint_batch.insert(b);
75✔
878
      }
879
    } else {
45✔
880
      // If neither were specified, write source points with state points
881
      sourcepoint_batch = statepoint_batch;
56!
882
    }
883

884
    // Check if the user has specified to write binary source file
885
    if (check_for_node(node_sp, "separate")) {
101✔
886
      source_separate = get_node_value_bool(node_sp, "separate");
71✔
887
    }
888
    if (check_for_node(node_sp, "write")) {
101!
889
      source_write = get_node_value_bool(node_sp, "write");
×
890
    }
891
    if (check_for_node(node_sp, "mcpl")) {
101✔
892
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
26✔
893
    }
894
    if (check_for_node(node_sp, "overwrite_latest")) {
101✔
895
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
15✔
896
      source_separate = source_latest;
15✔
897
    }
898
  } else {
899
    // If no <source_point> tag was present, by default we keep source bank in
900
    // statepoint file and write it out at statepoints intervals
901
    source_separate = false;
8,065✔
902
    sourcepoint_batch = statepoint_batch;
8,065!
903
  }
904

905
  // Check is the user specified to convert strength to statistical weight
906
  if (check_for_node(root, "uniform_source_sampling")) {
8,166✔
907
    uniform_source_sampling =
55✔
908
      get_node_value_bool(root, "uniform_source_sampling");
55✔
909
  }
910

911
  // Check if the user has specified to write surface source
912
  if (check_for_node(root, "surf_source_write")) {
8,166✔
913
    surf_source_write = true;
412✔
914
    // Get surface source write node
915
    xml_node node_ssw = root.child("surf_source_write");
412✔
916

917
    // Determine surface ids at which crossing particles are to be banked.
918
    // If no surfaces are specified, all surfaces in the model will be used
919
    // to bank source points.
920
    if (check_for_node(node_ssw, "surface_ids")) {
412✔
921
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
202✔
922
      for (const auto& b : temp) {
994✔
923
        source_write_surf_id.insert(b);
792✔
924
      }
925
    }
202✔
926

927
    // Get maximum number of particles to be banked per surface
928
    if (check_for_node(node_ssw, "max_particles")) {
412✔
929
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
806✔
930
    } else {
931
      fatal_error("A maximum number of particles needs to be specified "
9✔
932
                  "using the 'max_particles' parameter to store surface "
933
                  "source points.");
934
    }
935

936
    // Get maximum number of surface source files to be created
937
    if (check_for_node(node_ssw, "max_source_files")) {
403✔
938
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
66✔
939
    } else {
940
      ssw_max_files = 1;
370✔
941
    }
942

943
    if (check_for_node(node_ssw, "mcpl")) {
403✔
944
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
11✔
945
    }
946
    // Get cell information
947
    if (check_for_node(node_ssw, "cell")) {
403✔
948
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
208✔
949
      ssw_cell_type = SSWCellType::Both;
104✔
950
    }
951
    if (check_for_node(node_ssw, "cellfrom")) {
403✔
952
      if (ssw_cell_id != C_NONE) {
90✔
953
        fatal_error(
18✔
954
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
955
      }
956
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
144✔
957
      ssw_cell_type = SSWCellType::From;
72✔
958
    }
959
    if (check_for_node(node_ssw, "cellto")) {
385✔
960
      if (ssw_cell_id != C_NONE) {
71✔
961
        fatal_error(
18✔
962
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
963
      }
964
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
106✔
965
      ssw_cell_type = SSWCellType::To;
53✔
966
    }
967
  }
968

969
  // Check if the user has specified to write specific collisions
970
  if (check_for_node(root, "collision_track")) {
8,121✔
971
    settings::collision_track = true;
148✔
972
    // Get collision track node
973
    xml_node node_ct = root.child("collision_track");
148✔
974
    collision_track_config = CollisionTrackConfig {};
148✔
975

976
    // Determine cell ids at which crossing particles are to be banked
977
    if (check_for_node(node_ct, "cell_ids")) {
148✔
978
      auto temp = get_node_array<int>(node_ct, "cell_ids");
78✔
979
      for (const auto& b : temp) {
204✔
980
        collision_track_config.cell_ids.insert(b);
126✔
981
      }
982
    }
78✔
983
    if (check_for_node(node_ct, "reactions")) {
148✔
984
      auto temp = get_node_array<std::string>(node_ct, "reactions");
63✔
985
      for (const auto& b : temp) {
171✔
986
        int reaction_int = reaction_mt(b);
108✔
987
        if (reaction_int > 0) {
108!
988
          collision_track_config.mt_numbers.insert(reaction_int);
108✔
989
        }
990
      }
991
    }
63✔
992
    if (check_for_node(node_ct, "universe_ids")) {
148✔
993
      auto temp = get_node_array<int>(node_ct, "universe_ids");
30✔
994
      for (const auto& b : temp) {
60✔
995
        collision_track_config.universe_ids.insert(b);
30✔
996
      }
997
    }
30✔
998
    if (check_for_node(node_ct, "material_ids")) {
148✔
999
      auto temp = get_node_array<int>(node_ct, "material_ids");
30✔
1000
      for (const auto& b : temp) {
75✔
1001
        collision_track_config.material_ids.insert(b);
45✔
1002
      }
1003
    }
30✔
1004
    if (check_for_node(node_ct, "nuclides")) {
148✔
1005
      auto temp = get_node_array<std::string>(node_ct, "nuclides");
30✔
1006
      for (const auto& b : temp) {
120✔
1007
        collision_track_config.nuclides.insert(b);
90✔
1008
      }
1009
    }
30✔
1010
    if (check_for_node(node_ct, "deposited_E_threshold")) {
148✔
1011
      collision_track_config.deposited_energy_threshold =
60✔
1012
        std::stod(get_node_value(node_ct, "deposited_E_threshold"));
60✔
1013
    }
1014
    // Get maximum number of particles to be banked per collision
1015
    if (check_for_node(node_ct, "max_collisions")) {
148!
1016
      collision_track_config.max_collisions =
296✔
1017
        std::stoll(get_node_value(node_ct, "max_collisions"));
296✔
1018
    } else {
1019
      warning("A maximum number of collisions needs to be specified. "
×
1020
              "By default the code sets 'max_collisions' parameter equals to "
1021
              "1000.");
1022
    }
1023
    // Get maximum number of collision_track files to be created
1024
    if (check_for_node(node_ct, "max_collision_track_files")) {
148!
1025
      collision_track_config.max_files =
×
1026
        std::stoll(get_node_value(node_ct, "max_collision_track_files"));
×
1027
    }
1028
    if (check_for_node(node_ct, "mcpl")) {
148✔
1029
      collision_track_config.mcpl_write = get_node_value_bool(node_ct, "mcpl");
22✔
1030
    }
1031
  }
1032

1033
  // If source is not separate and is to be written out in the statepoint
1034
  // file, make sure that the sourcepoint batch numbers are contained in the
1035
  // statepoint list
1036
  if (!source_separate) {
8,121✔
1037
    for (const auto& b : sourcepoint_batch) {
16,196✔
1038
      if (!contains(statepoint_batch, b)) {
16,322!
1039
        fatal_error(
×
1040
          "Sourcepoint batches are not a subset of statepoint batches.");
1041
      }
1042
    }
1043
  }
1044

1045
  // Check if the user has specified to not reduce tallies at the end of every
1046
  // batch
1047
  if (check_for_node(root, "no_reduce")) {
8,121✔
1048
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
30✔
1049
  }
1050

1051
  // Check if the user has specified to use confidence intervals for
1052
  // uncertainties rather than standard deviations
1053
  if (check_for_node(root, "confidence_intervals")) {
8,121✔
1054
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
15✔
1055
  }
1056

1057
  // Check for output options
1058
  if (check_for_node(root, "output")) {
8,121✔
1059
    // Get pointer to output node
1060
    pugi::xml_node node_output = root.child("output");
764✔
1061

1062
    // Check for summary option
1063
    if (check_for_node(node_output, "summary")) {
764✔
1064
      output_summary = get_node_value_bool(node_output, "summary");
738✔
1065
    }
1066

1067
    // Check for ASCII tallies output option
1068
    if (check_for_node(node_output, "tallies")) {
764✔
1069
      output_tallies = get_node_value_bool(node_output, "tallies");
349✔
1070
    }
1071

1072
    // Set output directory if a path has been specified
1073
    if (check_for_node(node_output, "path")) {
764!
1074
      path_output = get_node_value(node_output, "path");
×
1075
      if (!ends_with(path_output, "/")) {
×
1076
        path_output += "/";
764!
1077
      }
1078
    }
1079
  }
1080

1081
  // Resonance scattering parameters
1082
  if (check_for_node(root, "resonance_scattering")) {
8,121✔
1083
    xml_node node_res_scat = root.child("resonance_scattering");
15✔
1084

1085
    // See if resonance scattering is enabled
1086
    if (check_for_node(node_res_scat, "enable")) {
15!
1087
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
15✔
1088
    } else {
1089
      res_scat_on = true;
×
1090
    }
1091

1092
    // Determine what method is used
1093
    if (check_for_node(node_res_scat, "method")) {
15!
1094
      auto temp = get_node_value(node_res_scat, "method", true, true);
15✔
1095
      if (temp == "rvs") {
15!
1096
        res_scat_method = ResScatMethod::rvs;
15✔
1097
      } else if (temp == "dbrc") {
×
1098
        res_scat_method = ResScatMethod::dbrc;
×
1099
      } else {
1100
        fatal_error(
×
1101
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1102
      }
1103
    }
15✔
1104

1105
    // Minimum energy for resonance scattering
1106
    if (check_for_node(node_res_scat, "energy_min")) {
15!
1107
      res_scat_energy_min =
30✔
1108
        std::stod(get_node_value(node_res_scat, "energy_min"));
30✔
1109
    }
1110
    if (res_scat_energy_min < 0.0) {
15!
1111
      fatal_error("Lower resonance scattering energy bound is negative");
×
1112
    }
1113

1114
    // Maximum energy for resonance scattering
1115
    if (check_for_node(node_res_scat, "energy_max")) {
15!
1116
      res_scat_energy_max =
30✔
1117
        std::stod(get_node_value(node_res_scat, "energy_max"));
30✔
1118
    }
1119
    if (res_scat_energy_max < res_scat_energy_min) {
15!
1120
      fatal_error("Upper resonance scattering energy bound is below the "
×
1121
                  "lower resonance scattering energy bound.");
1122
    }
1123

1124
    // Get resonance scattering nuclides
1125
    if (check_for_node(node_res_scat, "nuclides")) {
15!
1126
      res_scat_nuclides =
15✔
1127
        get_node_array<std::string>(node_res_scat, "nuclides");
30✔
1128
    }
1129
  }
1130

1131
  // Get volume calculations
1132
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
8,435✔
1133
    model::volume_calcs.emplace_back(node_vol);
314✔
1134
  }
1135

1136
  // Get temperature settings
1137
  if (check_for_node(root, "temperature_default")) {
8,121✔
1138
    temperature_default =
342✔
1139
      std::stod(get_node_value(root, "temperature_default"));
342✔
1140
  }
1141
  if (check_for_node(root, "temperature_method")) {
8,121✔
1142
    auto temp = get_node_value(root, "temperature_method", true, true);
485✔
1143
    if (temp == "nearest") {
485✔
1144
      temperature_method = TemperatureMethod::NEAREST;
304✔
1145
    } else if (temp == "interpolation") {
181!
1146
      temperature_method = TemperatureMethod::INTERPOLATION;
181✔
1147
    } else {
1148
      fatal_error("Unknown temperature method: " + temp);
×
1149
    }
1150
  }
485✔
1151
  if (check_for_node(root, "temperature_tolerance")) {
8,121✔
1152
    temperature_tolerance =
680✔
1153
      std::stod(get_node_value(root, "temperature_tolerance"));
680✔
1154
  }
1155
  if (check_for_node(root, "temperature_multipole")) {
8,121✔
1156
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
185✔
1157

1158
    // Multipole currently doesn't work with photon transport
1159
    if (temperature_multipole && photon_transport) {
185!
1160
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1161
                  "photon transport.");
1162
    }
1163
  }
1164
  if (check_for_node(root, "temperature_range")) {
8,121✔
1165
    auto range = get_node_array<double>(root, "temperature_range");
170✔
1166
    temperature_range[0] = range.at(0);
170✔
1167
    temperature_range[1] = range.at(1);
170✔
1168
  }
170✔
1169

1170
  // Check for tabular_legendre options
1171
  if (check_for_node(root, "tabular_legendre")) {
8,121✔
1172
    // Get pointer to tabular_legendre node
1173
    xml_node node_tab_leg = root.child("tabular_legendre");
90✔
1174

1175
    // Check for enable option
1176
    if (check_for_node(node_tab_leg, "enable")) {
90!
1177
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
90✔
1178
    }
1179

1180
    // Check for the number of points
1181
    if (check_for_node(node_tab_leg, "num_points")) {
90!
1182
      legendre_to_tabular_points =
×
1183
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
1184
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
1185
        fatal_error(
×
1186
          "The 'num_points' subelement/attribute of the "
1187
          "<tabular_legendre> element must contain a value greater than 1");
1188
      }
1189
    }
1190
  }
1191

1192
  // Check whether create delayed neutrons in fission
1193
  if (check_for_node(root, "create_delayed_neutrons")) {
8,121!
1194
    create_delayed_neutrons =
×
1195
      get_node_value_bool(root, "create_delayed_neutrons");
×
1196
  }
1197

1198
  // Check whether create fission sites
1199
  if (run_mode == RunMode::FIXED_SOURCE) {
8,121✔
1200
    if (check_for_node(root, "create_fission_neutrons")) {
2,783✔
1201
      create_fission_neutrons =
280✔
1202
        get_node_value_bool(root, "create_fission_neutrons");
280✔
1203
    }
1204
  }
1205

1206
  // Check whether to scale fission photon yields
1207
  if (check_for_node(root, "delayed_photon_scaling")) {
8,121!
1208
    delayed_photon_scaling =
×
1209
      get_node_value_bool(root, "delayed_photon_scaling");
×
1210
  }
1211

1212
  // Check whether to use event-based parallelism
1213
  if (check_for_node(root, "event_based")) {
8,121!
1214
    event_based = get_node_value_bool(root, "event_based");
×
1215
  }
1216

1217
  // Check whether material cell offsets should be generated
1218
  if (check_for_node(root, "material_cell_offsets")) {
8,121!
1219
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1220
  }
1221

1222
  // Weight window information
1223
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
8,226✔
1224
    variance_reduction::weight_windows.emplace_back(
105✔
1225
      std::make_unique<WeightWindows>(node_ww));
210✔
1226
  }
1227

1228
  // Enable weight windows by default if one or more are present
1229
  if (variance_reduction::weight_windows.size() > 0)
8,121✔
1230
    settings::weight_windows_on = true;
79✔
1231

1232
  // read weight windows from file
1233
  if (check_for_node(root, "weight_windows_file")) {
8,121!
1234
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1235
  }
1236

1237
  // read settings for weight windows value, this will override
1238
  // the automatic setting even if weight windows are present
1239
  if (check_for_node(root, "weight_windows_on")) {
8,121✔
1240
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
38✔
1241
  }
1242

1243
  if (check_for_node(root, "max_secondaries")) {
8,121!
1244
    settings::max_secondaries =
×
1245
      std::stoi(get_node_value(root, "max_secondaries"));
×
1246
  }
1247

1248
  if (check_for_node(root, "max_history_splits")) {
8,121✔
1249
    settings::max_history_splits =
428✔
1250
      std::stoi(get_node_value(root, "max_history_splits"));
428✔
1251
  }
1252

1253
  if (check_for_node(root, "max_tracks")) {
8,121✔
1254
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
90✔
1255
  }
1256

1257
  // Create weight window generator objects
1258
  if (check_for_node(root, "weight_window_generators")) {
8,121✔
1259
    auto wwgs_node = root.child("weight_window_generators");
79✔
1260
    for (pugi::xml_node node_wwg :
158✔
1261
      wwgs_node.children("weight_windows_generator")) {
158✔
1262
      variance_reduction::weight_windows_generators.emplace_back(
79✔
1263
        std::make_unique<WeightWindowsGenerator>(node_wwg));
158✔
1264
    }
1265
    // if any of the weight windows are intended to be generated otf, make
1266
    // sure they're applied
1267
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
79!
1268
      if (wwg->on_the_fly_) {
79!
1269
        settings::weight_windows_on = true;
79✔
1270
        break;
79✔
1271
      }
1272
    }
1273
  }
1274

1275
  // Set up weight window checkpoints
1276
  if (check_for_node(root, "weight_window_checkpoints")) {
8,121✔
1277
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
32✔
1278
    if (check_for_node(ww_checkpoints, "collision")) {
32!
1279
      weight_window_checkpoint_collision =
32✔
1280
        get_node_value_bool(ww_checkpoints, "collision");
32✔
1281
    }
1282
    if (check_for_node(ww_checkpoints, "surface")) {
32!
1283
      weight_window_checkpoint_surface =
32✔
1284
        get_node_value_bool(ww_checkpoints, "surface");
32✔
1285
    }
1286
  }
1287

1288
  if (weight_windows_on) {
8,121✔
1289
    if (!weight_window_checkpoint_surface &&
158✔
1290
        !weight_window_checkpoint_collision)
126!
1291
      fatal_error(
×
1292
        "Weight Windows are enabled but there are no valid checkpoints.");
1293
  }
1294

1295
  if (check_for_node(root, "use_decay_photons")) {
8,121✔
1296
    settings::use_decay_photons =
11✔
1297
      get_node_value_bool(root, "use_decay_photons");
11✔
1298
  }
1299
}
8,121✔
1300

1301
void free_memory_settings()
8,272✔
1302
{
1303
  settings::statepoint_batch.clear();
8,272✔
1304
  settings::sourcepoint_batch.clear();
8,272✔
1305
  settings::source_write_surf_id.clear();
8,272✔
1306
  settings::res_scat_nuclides.clear();
8,272✔
1307
}
8,272✔
1308

1309
//==============================================================================
1310
// C API functions
1311
//==============================================================================
1312

1313
extern "C" int openmc_set_n_batches(
44✔
1314
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1315
{
1316
  if (settings::n_inactive >= n_batches) {
44✔
1317
    set_errmsg("Number of active batches must be greater than zero.");
11✔
1318
    return OPENMC_E_INVALID_ARGUMENT;
11✔
1319
  }
1320

1321
  if (!settings::trigger_on) {
33✔
1322
    // Set n_batches and n_max_batches to same value
1323
    settings::n_batches = n_batches;
11✔
1324
    settings::n_max_batches = n_batches;
11✔
1325
  } else {
1326
    // Set n_batches and n_max_batches based on value of set_max_batches
1327
    if (set_max_batches) {
22✔
1328
      settings::n_max_batches = n_batches;
11✔
1329
    } else {
1330
      settings::n_batches = n_batches;
11✔
1331
    }
1332
  }
1333

1334
  // Update size of k_generation and entropy
1335
  int m = settings::n_max_batches * settings::gen_per_batch;
33✔
1336
  simulation::k_generation.reserve(m);
33✔
1337
  simulation::entropy.reserve(m);
33✔
1338

1339
  // Add value of n_batches to statepoint_batch
1340
  if (add_statepoint_batch &&
33✔
1341
      !(contains(settings::statepoint_batch, n_batches)))
22!
1342
    settings::statepoint_batch.insert(n_batches);
22✔
1343

1344
  return 0;
1345
}
1346

1347
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,530✔
1348
{
1349
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,530✔
1350

1351
  return 0;
2,530✔
1352
}
1353

1354
} // namespace openmc
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc