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

openmc-dev / openmc / 21043587909

15 Jan 2026 07:25PM UTC coverage: 81.332% (-0.7%) from 82.044%
21043587909

Pull #3734

github

web-flow
Merge 0c6701672 into 179048b80
Pull Request #3734: Specify temperature from a field (structured mesh only)

16365 of 22657 branches covered (72.23%)

Branch coverage included in aggregate %.

157 of 180 new or added lines in 12 files covered. (87.22%)

681 existing lines in 43 files now uncovered.

54412 of 64365 relevant lines covered (84.54%)

23556062.71 hits per line

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

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

40
namespace openmc {
41

42
//==============================================================================
43
// Global variables
44
//==============================================================================
45

46
namespace settings {
47

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

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

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

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

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

154
} // namespace settings
155

156
//==============================================================================
157
// Functions
158
//==============================================================================
159

160
void get_run_parameters(pugi::xml_node node_base)
2,646✔
161
{
162
  using namespace settings;
163
  using namespace pugi;
164

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

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

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

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

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

194
  // Get max number of lost particles
195
  if (check_for_node(node_base, "max_lost_particles")) {
2,646✔
196
    max_lost_particles =
18✔
197
      std::stoi(get_node_value(node_base, "max_lost_particles"));
18✔
198
  }
199

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

206
  // Get relative number of lost particles
207
  if (check_for_node(node_base, "max_write_lost_particles")) {
2,646✔
208
    max_write_lost_particles =
6✔
209
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
6✔
210
  }
211

212
  // Get number of inactive batches
213
  if (run_mode == RunMode::EIGENVALUE ||
2,646✔
214
      solver_type == SolverType::RANDOM_RAY) {
970✔
215
    if (check_for_node(node_base, "inactive")) {
1,832✔
216
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
1,758✔
217
    }
218
    if (check_for_node(node_base, "generations_per_batch")) {
1,832✔
219
      gen_per_batch =
6✔
220
        std::stoi(get_node_value(node_base, "generations_per_batch"));
6✔
221
    }
222

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

228
    // Get the trigger information for keff
229
    if (check_for_node(node_base, "keff_trigger")) {
1,832✔
230
      xml_node node_keff_trigger = node_base.child("keff_trigger");
40✔
231

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

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

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

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

390
  // Parse settings.xml file
391
  xml_document doc;
496✔
392
  auto result = doc.load_file(filename.c_str());
496✔
393
  if (!result) {
496!
394
    fatal_error("Error processing settings.xml file.");
×
395
  }
396

397
  // Get root element
398
  xml_node root = doc.document_element();
496✔
399

400
  // Verbosity
401
  if (check_for_node(root, "verbosity") && verbosity == -1) {
496!
402
    verbosity = std::stoi(get_node_value(root, "verbosity"));
66✔
403
  } else if (verbosity == -1) {
430!
404
    verbosity = 7;
430✔
405
  }
406

407
  // To this point, we haven't displayed any output since we didn't know what
408
  // the verbosity is. Now that we checked for it, show the title if necessary
409
  if (mpi::master) {
496✔
410
    if (verbosity >= 2)
406✔
411
      title();
344✔
412
  }
413

414
  write_message("Reading settings XML file...", 5);
496✔
415

416
  read_settings_xml(root);
496✔
417
}
500✔
418

419
void read_settings_xml(pugi::xml_node root)
2,930✔
420
{
421
  using namespace settings;
422
  using namespace pugi;
423

424
  // Find if a multi-group or continuous-energy simulation is desired
425
  if (check_for_node(root, "energy_mode")) {
2,930✔
426
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
452✔
427
    if (temp_str == "mg" || temp_str == "multi-group") {
452!
428
      run_CE = false;
452✔
429
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
430
      run_CE = true;
×
431
    }
432
  }
452✔
433

434
  // Check for user meshes and allocate
435
  read_meshes(root);
2,930✔
436

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

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

461
  // Check for a trigger node and get trigger information
462
  if (check_for_node(root, "trigger")) {
2,930✔
463
    xml_node node_trigger = root.child("trigger");
60✔
464

465
    // Check if trigger(s) are to be turned on
466
    trigger_on = get_node_value_bool(node_trigger, "active");
60✔
467

468
    if (trigger_on) {
60✔
469
      if (check_for_node(node_trigger, "max_batches")) {
54!
470
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
54✔
471
      } else {
472
        fatal_error("<max_batches> must be specified with triggers");
×
473
      }
474

475
      // Get the batch interval to check triggers
476
      if (!check_for_node(node_trigger, "batch_interval")) {
54✔
477
        trigger_predict = true;
6✔
478
      } else {
479
        trigger_batch_interval =
48✔
480
          std::stoi(get_node_value(node_trigger, "batch_interval"));
48✔
481
        if (trigger_batch_interval <= 0) {
48!
482
          fatal_error("Trigger batch interval must be greater than zero");
×
483
        }
484
      }
485
    }
486
  }
487

488
  // Check run mode if it hasn't been set from the command line
489
  xml_node node_mode;
2,930✔
490
  if (run_mode == RunMode::UNSET) {
2,930✔
491
    if (check_for_node(root, "run_mode")) {
2,658✔
492
      std::string temp_str = get_node_value(root, "run_mode", true, true);
2,646✔
493
      if (temp_str == "eigenvalue") {
2,646✔
494
        run_mode = RunMode::EIGENVALUE;
1,664✔
495
      } else if (temp_str == "fixed source") {
982✔
496
        run_mode = RunMode::FIXED_SOURCE;
970✔
497
      } else if (temp_str == "plot") {
12!
498
        run_mode = RunMode::PLOTTING;
×
499
      } else if (temp_str == "particle restart") {
12!
500
        run_mode = RunMode::PARTICLE;
×
501
      } else if (temp_str == "volume") {
12!
502
        run_mode = RunMode::VOLUME;
12✔
503
      } else {
504
        fatal_error("Unrecognized run mode: " + temp_str);
×
505
      }
506

507
      // Assume XML specifies <particles>, <batches>, etc. directly
508
      node_mode = root;
2,646✔
509
    } else {
2,646✔
510
      warning("<run_mode> should be specified.");
12✔
511

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

527
  // Check solver type
528
  if (check_for_node(root, "random_ray")) {
2,930✔
529
    solver_type = SolverType::RANDOM_RAY;
252✔
530
    if (run_CE)
252!
531
      fatal_error("multi-group energy mode must be specified in settings XML "
×
532
                  "when using the random ray solver.");
533
  }
534

535
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
2,930✔
536
    // Read run parameters
537
    get_run_parameters(node_mode);
2,646✔
538

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

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

568
  // Copy plotting random number seed if specified
569
  if (check_for_node(root, "plot_seed")) {
2,926!
570
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
571
    model::plotter_seed = seed;
×
572
  }
573

574
  // Copy random number seed if specified
575
  if (check_for_node(root, "seed")) {
2,926✔
576
    auto seed = std::stoll(get_node_value(root, "seed"));
220✔
577
    openmc_set_seed(seed);
220✔
578
  }
579

580
  // Copy random number stride if specified
581
  if (check_for_node(root, "stride")) {
2,926✔
582
    auto stride = std::stoull(get_node_value(root, "stride"));
6✔
583
    openmc_set_stride(stride);
6✔
584
  }
585

586
  // Check for electron treatment
587
  if (check_for_node(root, "electron_treatment")) {
2,926✔
588
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
26✔
589
    if (temp_str == "led") {
26✔
590
      electron_treatment = ElectronTreatment::LED;
4✔
591
    } else if (temp_str == "ttb") {
22!
592
      electron_treatment = ElectronTreatment::TTB;
22✔
593
    } else {
594
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
595
    }
596
  }
26✔
597

598
  // Check for photon transport
599
  if (check_for_node(root, "photon_transport")) {
2,926✔
600
    photon_transport = get_node_value_bool(root, "photon_transport");
74✔
601

602
    if (!run_CE && photon_transport) {
74!
603
      fatal_error("Photon transport is not currently supported in "
×
604
                  "multigroup mode");
605
    }
606
  }
607

608
  // Number of bins for logarithmic grid
609
  if (check_for_node(root, "log_grid_bins")) {
2,926✔
610
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
6✔
611
    if (n_log_bins < 1) {
6!
612
      fatal_error("Number of bins for logarithmic grid must be greater "
×
613
                  "than zero.");
614
    }
615
  }
616

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

625
  // ==========================================================================
626
  // EXTERNAL SOURCE
627

628
  // Get point to list of <source> elements and make sure there is at least one
629
  for (pugi::xml_node node : root.children("source")) {
5,638✔
630
    model::external_sources.push_back(Source::create(node));
2,716✔
631
  }
632

633
  // Check if the user has specified to read surface source
634
  if (check_for_node(root, "surf_source_read")) {
2,922✔
635
    surf_source_read = true;
12✔
636
    // Get surface source read node
637
    xml_node node_ssr = root.child("surf_source_read");
12✔
638

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

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

659
  // Build probability mass function for sampling external sources
660
  vector<double> source_strengths;
2,922✔
661
  for (auto& s : model::external_sources) {
6,382✔
662
    source_strengths.push_back(s->strength());
3,460✔
663
  }
664
  model::external_sources_probability.assign(source_strengths);
2,922✔
665

666
  // Check if we want to write out source
667
  if (check_for_node(root, "write_initial_source")) {
2,922!
668
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
669
  }
670

671
  // Get relative number of lost particles
672
  if (check_for_node(root, "source_rejection_fraction")) {
2,922✔
673
    source_rejection_fraction =
2✔
674
      std::stod(get_node_value(root, "source_rejection_fraction"));
2!
675
  }
676

677
  if (check_for_node(root, "free_gas_threshold")) {
2,922!
678
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
679
  }
680

681
  // Survival biasing
682
  if (check_for_node(root, "survival_biasing")) {
2,922✔
683
    survival_biasing = get_node_value_bool(root, "survival_biasing");
64✔
684
  }
685

686
  // Probability tables
687
  if (check_for_node(root, "ptables")) {
2,922✔
688
    urr_ptables_on = get_node_value_bool(root, "ptables");
6✔
689
  }
690

691
  // Cutoffs
692
  if (check_for_node(root, "cutoff")) {
2,922✔
693
    xml_node node_cutoff = root.child("cutoff");
54✔
694
    if (check_for_node(node_cutoff, "weight")) {
54✔
695
      weight_cutoff = std::stod(get_node_value(node_cutoff, "weight"));
6✔
696
    }
697
    if (check_for_node(node_cutoff, "weight_avg")) {
54✔
698
      weight_survive = std::stod(get_node_value(node_cutoff, "weight_avg"));
6✔
699
    }
700
    if (check_for_node(node_cutoff, "survival_normalization")) {
54!
701
      survival_normalization =
×
702
        get_node_value_bool(node_cutoff, "survival_normalization");
×
703
    }
704
    if (check_for_node(node_cutoff, "energy_neutron")) {
54✔
705
      energy_cutoff[0] =
12✔
706
        std::stod(get_node_value(node_cutoff, "energy_neutron"));
6✔
707
    } else if (check_for_node(node_cutoff, "energy")) {
48!
708
      warning("The use of an <energy> cutoff is deprecated and should "
×
709
              "be replaced by <energy_neutron>.");
710
      energy_cutoff[0] = std::stod(get_node_value(node_cutoff, "energy"));
×
711
    }
712
    if (check_for_node(node_cutoff, "energy_photon")) {
54✔
713
      energy_cutoff[1] =
64✔
714
        std::stod(get_node_value(node_cutoff, "energy_photon"));
32✔
715
    }
716
    if (check_for_node(node_cutoff, "energy_electron")) {
54!
717
      energy_cutoff[2] =
×
718
        std::stof(get_node_value(node_cutoff, "energy_electron"));
×
719
    }
720
    if (check_for_node(node_cutoff, "energy_positron")) {
54!
721
      energy_cutoff[3] =
×
722
        std::stod(get_node_value(node_cutoff, "energy_positron"));
×
723
    }
724
    if (check_for_node(node_cutoff, "time_neutron")) {
54✔
725
      time_cutoff[0] = std::stod(get_node_value(node_cutoff, "time_neutron"));
10✔
726
    }
727
    if (check_for_node(node_cutoff, "time_photon")) {
54!
728
      time_cutoff[1] = std::stod(get_node_value(node_cutoff, "time_photon"));
×
729
    }
730
    if (check_for_node(node_cutoff, "time_electron")) {
54!
731
      time_cutoff[2] = std::stod(get_node_value(node_cutoff, "time_electron"));
×
732
    }
733
    if (check_for_node(node_cutoff, "time_positron")) {
54!
734
      time_cutoff[3] = std::stod(get_node_value(node_cutoff, "time_positron"));
×
735
    }
736
  }
737

738
  // Particle trace
739
  if (check_for_node(root, "trace")) {
2,922✔
740
    auto temp = get_node_array<int64_t>(root, "trace");
6✔
741
    if (temp.size() != 3) {
6!
742
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
743
                  "batch, generation, and particle number.");
744
    }
745
    trace_batch = temp.at(0);
6✔
746
    trace_gen = temp.at(1);
6✔
747
    trace_particle = temp.at(2);
6✔
748
  }
6✔
749

750
  // Particle tracks
751
  if (check_for_node(root, "track")) {
2,922✔
752
    // Get values and make sure there are three per particle
753
    auto temp = get_node_array<int>(root, "track");
18✔
754
    if (temp.size() % 3 != 0) {
18!
755
      fatal_error(
×
756
        "Number of integers specified in 'track' is not "
757
        "divisible by 3.  Please provide 3 integers per particle to be "
758
        "tracked.");
759
    }
760

761
    // Reshape into track_identifiers
762
    int n_tracks = temp.size() / 3;
18✔
763
    for (int i = 0; i < n_tracks; ++i) {
72✔
764
      track_identifiers.push_back(
54✔
765
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
54✔
766
    }
767
  }
18✔
768

769
  // Shannon entropy
770
  if (solver_type == SolverType::RANDOM_RAY) {
2,922✔
771
    if (check_for_node(root, "entropy_mesh")) {
252!
772
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
773
                  "No user-defined entropy mesh is supported.");
774
    }
775
    entropy_on = true;
252✔
776
  } else if (solver_type == SolverType::MONTE_CARLO) {
2,670!
777
    if (check_for_node(root, "entropy_mesh")) {
2,670✔
778
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
122✔
779
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
122!
780
        fatal_error(fmt::format(
×
781
          "Mesh {} specified for Shannon entropy does not exist.", temp));
782
      }
783

784
      auto* m = dynamic_cast<RegularMesh*>(
122!
785
        model::meshes[model::mesh_map.at(temp)].get());
122✔
786
      if (!m)
122!
NEW
787
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
788
      simulation::entropy_mesh = m;
122✔
789

790
      // Turn on Shannon entropy calculation
791
      entropy_on = true;
122✔
792

793
    } else if (check_for_node(root, "entropy")) {
2,548!
NEW
794
      fatal_error(
×
795
        "Specifying a Shannon entropy mesh via the <entropy> element "
796
        "is deprecated. Please create a mesh using <mesh> and then reference "
797
        "it by specifying its ID in an <entropy_mesh> element.");
798
    }
799
  }
800

801
  // Temperature field
802
  if (check_for_node(root, "temperature_field")) {
2,922✔
803
    temperature_field_on = true;
6✔
804

805
    // Get pointer to temperature_field node
806
    auto node_tf = root.child("temperature_field");
6✔
807

808
    // Mesh parameter
809
    Mesh* tf_mesh_ptr;
810
    if (check_for_node(node_tf, "mesh")) {
6!
811
      int temp = std::stoi(get_node_value(node_tf, "mesh"));
6✔
812
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
6!
NEW
813
        fatal_error(fmt::format(
×
814
          "Mesh {} specified for the temperature field does not exist.", temp));
815
      }
816
      tf_mesh_ptr = model::meshes[model::mesh_map.at(temp)].get();
6✔
817
    } else {
NEW
818
      fatal_error("A mesh should be given for the temperature field.");
×
819
    }
820

821
    // Values parameter
822
    vector<double> tf_values;
6✔
823
    if (check_for_node(node_tf, "values")) {
6!
824
      auto temp = get_node_array<double>(node_tf, "values");
6✔
825
      for (const auto& b : temp) {
54✔
826
        tf_values.push_back(b);
48✔
827
      }
828
    } else {
6✔
UNCOV
829
      fatal_error(
×
830
        "Temperature values should be given for the temperature field.");
831
    }
832

833
    // Instantiate the temperature field
834
    simulation::temperature_field = TemperatureField(tf_mesh_ptr, tf_values);
6✔
835
  }
6✔
836

837
  // Uniform fission source weighting mesh
838
  if (check_for_node(root, "ufs_mesh")) {
2,922✔
839
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
6✔
840
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
6!
841
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
842
                              "method does not exist.",
843
        temp));
844
    }
845

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

852
    // Turn on uniform fission source weighting
853
    ufs_on = true;
6✔
854

855
  } else if (check_for_node(root, "uniform_fs")) {
2,916!
856
    fatal_error(
×
857
      "Specifying a UFS mesh via the <uniform_fs> element "
858
      "is deprecated. Please create a mesh using <mesh> and then reference "
859
      "it by specifying its ID in a <ufs_mesh> element.");
860
  }
861

862
  // Check if the user has specified to write state points
863
  if (check_for_node(root, "state_point")) {
2,922✔
864

865
    // Get pointer to state_point node
866
    auto node_sp = root.child("state_point");
62✔
867

868
    // Determine number of batches at which to store state points
869
    if (check_for_node(node_sp, "batches")) {
62!
870
      // User gave specific batches to write state points
871
      auto temp = get_node_array<int>(node_sp, "batches");
62✔
872
      for (const auto& b : temp) {
190✔
873
        statepoint_batch.insert(b);
128✔
874
      }
875
    } else {
62✔
876
      // If neither were specified, write state point at last batch
877
      statepoint_batch.insert(n_batches);
×
878
    }
879
  } else {
880
    // If no <state_point> tag was present, by default write state point at
881
    // last batch only
882
    statepoint_batch.insert(n_batches);
2,860✔
883
  }
884

885
  // Check if the user has specified to write source points
886
  if (check_for_node(root, "source_point")) {
2,922✔
887
    // Get source_point node
888
    xml_node node_sp = root.child("source_point");
40✔
889

890
    // Determine batches at which to store source points
891
    if (check_for_node(node_sp, "batches")) {
40✔
892
      // User gave specific batches to write source points
893
      auto temp = get_node_array<int>(node_sp, "batches");
18✔
894
      for (const auto& b : temp) {
48✔
895
        sourcepoint_batch.insert(b);
30✔
896
      }
897
    } else {
18✔
898
      // If neither were specified, write source points with state points
899
      sourcepoint_batch = statepoint_batch;
22✔
900
    }
901

902
    // Check if the user has specified to write binary source file
903
    if (check_for_node(node_sp, "separate")) {
40✔
904
      source_separate = get_node_value_bool(node_sp, "separate");
28✔
905
    }
906
    if (check_for_node(node_sp, "write")) {
40!
907
      source_write = get_node_value_bool(node_sp, "write");
×
908
    }
909
    if (check_for_node(node_sp, "mcpl")) {
40✔
910
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
10✔
911
    }
912
    if (check_for_node(node_sp, "overwrite_latest")) {
40✔
913
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
6✔
914
      source_separate = source_latest;
6✔
915
    }
916
  } else {
917
    // If no <source_point> tag was present, by default we keep source bank in
918
    // statepoint file and write it out at statepoints intervals
919
    source_separate = false;
2,882✔
920
    sourcepoint_batch = statepoint_batch;
2,882✔
921
  }
922

923
  // Check is the user specified to convert strength to statistical weight
924
  if (check_for_node(root, "uniform_source_sampling")) {
2,922✔
925
    uniform_source_sampling =
20✔
926
      get_node_value_bool(root, "uniform_source_sampling");
20✔
927
  }
928

929
  // Check if the user has specified to write surface source
930
  if (check_for_node(root, "surf_source_write")) {
2,922✔
931
    surf_source_write = true;
156✔
932
    // Get surface source write node
933
    xml_node node_ssw = root.child("surf_source_write");
156✔
934

935
    // Determine surface ids at which crossing particles are to be banked.
936
    // If no surfaces are specified, all surfaces in the model will be used
937
    // to bank source points.
938
    if (check_for_node(node_ssw, "surface_ids")) {
156✔
939
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
76✔
940
      for (const auto& b : temp) {
380✔
941
        source_write_surf_id.insert(b);
304✔
942
      }
943
    }
76✔
944

945
    // Get maximum number of particles to be banked per surface
946
    if (check_for_node(node_ssw, "max_particles")) {
156✔
947
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
152✔
948
    } else {
949
      fatal_error("A maximum number of particles needs to be specified "
4✔
950
                  "using the 'max_particles' parameter to store surface "
951
                  "source points.");
952
    }
953

954
    // Get maximum number of surface source files to be created
955
    if (check_for_node(node_ssw, "max_source_files")) {
152✔
956
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
12✔
957
    } else {
958
      ssw_max_files = 1;
140✔
959
    }
960

961
    if (check_for_node(node_ssw, "mcpl")) {
152✔
962
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
4✔
963
    }
964
    // Get cell information
965
    if (check_for_node(node_ssw, "cell")) {
152✔
966
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
40✔
967
      ssw_cell_type = SSWCellType::Both;
40✔
968
    }
969
    if (check_for_node(node_ssw, "cellfrom")) {
152✔
970
      if (ssw_cell_id != C_NONE) {
36✔
971
        fatal_error(
8✔
972
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
973
      }
974
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
28✔
975
      ssw_cell_type = SSWCellType::From;
28✔
976
    }
977
    if (check_for_node(node_ssw, "cellto")) {
144✔
978
      if (ssw_cell_id != C_NONE) {
28✔
979
        fatal_error(
8✔
980
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
981
      }
982
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
20✔
983
      ssw_cell_type = SSWCellType::To;
20✔
984
    }
985
  }
986

987
  // Check if the user has specified to write specific collisions
988
  if (check_for_node(root, "collision_track")) {
2,902✔
989
    settings::collision_track = true;
58✔
990
    // Get collision track node
991
    xml_node node_ct = root.child("collision_track");
58✔
992
    collision_track_config = CollisionTrackConfig {};
58✔
993

994
    // Determine cell ids at which crossing particles are to be banked
995
    if (check_for_node(node_ct, "cell_ids")) {
58✔
996
      auto temp = get_node_array<int>(node_ct, "cell_ids");
30✔
997
      for (const auto& b : temp) {
78✔
998
        collision_track_config.cell_ids.insert(b);
48✔
999
      }
1000
    }
30✔
1001
    if (check_for_node(node_ct, "reactions")) {
58✔
1002
      auto temp = get_node_array<std::string>(node_ct, "reactions");
24✔
1003
      for (const auto& b : temp) {
66✔
1004
        int reaction_int = reaction_type(b);
42✔
1005
        if (reaction_int > 0) {
42!
1006
          collision_track_config.mt_numbers.insert(reaction_int);
42✔
1007
        }
1008
      }
1009
    }
24✔
1010
    if (check_for_node(node_ct, "universe_ids")) {
58✔
1011
      auto temp = get_node_array<int>(node_ct, "universe_ids");
12✔
1012
      for (const auto& b : temp) {
24✔
1013
        collision_track_config.universe_ids.insert(b);
12✔
1014
      }
1015
    }
12✔
1016
    if (check_for_node(node_ct, "material_ids")) {
58✔
1017
      auto temp = get_node_array<int>(node_ct, "material_ids");
12✔
1018
      for (const auto& b : temp) {
30✔
1019
        collision_track_config.material_ids.insert(b);
18✔
1020
      }
1021
    }
12✔
1022
    if (check_for_node(node_ct, "nuclides")) {
58✔
1023
      auto temp = get_node_array<std::string>(node_ct, "nuclides");
12✔
1024
      for (const auto& b : temp) {
48✔
1025
        collision_track_config.nuclides.insert(b);
36✔
1026
      }
1027
    }
12✔
1028
    if (check_for_node(node_ct, "deposited_E_threshold")) {
58✔
1029
      collision_track_config.deposited_energy_threshold =
12✔
1030
        std::stod(get_node_value(node_ct, "deposited_E_threshold"));
12✔
1031
    }
1032
    // Get maximum number of particles to be banked per collision
1033
    if (check_for_node(node_ct, "max_collisions")) {
58!
1034
      collision_track_config.max_collisions =
58✔
1035
        std::stoll(get_node_value(node_ct, "max_collisions"));
58✔
1036
    } else {
1037
      warning("A maximum number of collisions needs to be specified. "
×
1038
              "By default the code sets 'max_collisions' parameter equals to "
1039
              "1000.");
1040
    }
1041
    // Get maximum number of collision_track files to be created
1042
    if (check_for_node(node_ct, "max_collision_track_files")) {
58!
1043
      collision_track_config.max_files =
×
1044
        std::stoll(get_node_value(node_ct, "max_collision_track_files"));
×
1045
    }
1046
    if (check_for_node(node_ct, "mcpl")) {
58✔
1047
      collision_track_config.mcpl_write = get_node_value_bool(node_ct, "mcpl");
8✔
1048
    }
1049
  }
1050

1051
  // If source is not separate and is to be written out in the statepoint
1052
  // file, make sure that the sourcepoint batch numbers are contained in the
1053
  // statepoint list
1054
  if (!source_separate) {
2,902✔
1055
    for (const auto& b : sourcepoint_batch) {
5,784✔
1056
      if (!contains(statepoint_batch, b)) {
2,916!
1057
        fatal_error(
×
1058
          "Sourcepoint batches are not a subset of statepoint batches.");
1059
      }
1060
    }
1061
  }
1062

1063
  // Check if the user has specified to not reduce tallies at the end of every
1064
  // batch
1065
  if (check_for_node(root, "no_reduce")) {
2,902✔
1066
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
12✔
1067
  }
1068

1069
  // Check if the user has specified to use confidence intervals for
1070
  // uncertainties rather than standard deviations
1071
  if (check_for_node(root, "confidence_intervals")) {
2,902✔
1072
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
6✔
1073
  }
1074

1075
  // Check for output options
1076
  if (check_for_node(root, "output")) {
2,902✔
1077
    // Get pointer to output node
1078
    pugi::xml_node node_output = root.child("output");
222✔
1079

1080
    // Check for summary option
1081
    if (check_for_node(node_output, "summary")) {
222✔
1082
      output_summary = get_node_value_bool(node_output, "summary");
212✔
1083
    }
1084

1085
    // Check for ASCII tallies output option
1086
    if (check_for_node(node_output, "tallies")) {
222✔
1087
      output_tallies = get_node_value_bool(node_output, "tallies");
66✔
1088
    }
1089

1090
    // Set output directory if a path has been specified
1091
    if (check_for_node(node_output, "path")) {
222!
1092
      path_output = get_node_value(node_output, "path");
×
1093
      if (!ends_with(path_output, "/")) {
×
1094
        path_output += "/";
×
1095
      }
1096
    }
1097
  }
1098

1099
  // Resonance scattering parameters
1100
  if (check_for_node(root, "resonance_scattering")) {
2,902✔
1101
    xml_node node_res_scat = root.child("resonance_scattering");
6✔
1102

1103
    // See if resonance scattering is enabled
1104
    if (check_for_node(node_res_scat, "enable")) {
6!
1105
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
6✔
1106
    } else {
1107
      res_scat_on = true;
×
1108
    }
1109

1110
    // Determine what method is used
1111
    if (check_for_node(node_res_scat, "method")) {
6!
1112
      auto temp = get_node_value(node_res_scat, "method", true, true);
6✔
1113
      if (temp == "rvs") {
6!
1114
        res_scat_method = ResScatMethod::rvs;
6✔
1115
      } else if (temp == "dbrc") {
×
1116
        res_scat_method = ResScatMethod::dbrc;
×
1117
      } else {
1118
        fatal_error(
×
1119
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1120
      }
1121
    }
6✔
1122

1123
    // Minimum energy for resonance scattering
1124
    if (check_for_node(node_res_scat, "energy_min")) {
6!
1125
      res_scat_energy_min =
6✔
1126
        std::stod(get_node_value(node_res_scat, "energy_min"));
6✔
1127
    }
1128
    if (res_scat_energy_min < 0.0) {
6!
1129
      fatal_error("Lower resonance scattering energy bound is negative");
×
1130
    }
1131

1132
    // Maximum energy for resonance scattering
1133
    if (check_for_node(node_res_scat, "energy_max")) {
6!
1134
      res_scat_energy_max =
6✔
1135
        std::stod(get_node_value(node_res_scat, "energy_max"));
6✔
1136
    }
1137
    if (res_scat_energy_max < res_scat_energy_min) {
6!
1138
      fatal_error("Upper resonance scattering energy bound is below the "
×
1139
                  "lower resonance scattering energy bound.");
1140
    }
1141

1142
    // Get resonance scattering nuclides
1143
    if (check_for_node(node_res_scat, "nuclides")) {
6!
1144
      res_scat_nuclides =
1145
        get_node_array<std::string>(node_res_scat, "nuclides");
6✔
1146
    }
1147
  }
1148

1149
  // Get volume calculations
1150
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
3,018✔
1151
    model::volume_calcs.emplace_back(node_vol);
116✔
1152
  }
1153

1154
  // Get temperature settings
1155
  if (check_for_node(root, "temperature_default")) {
2,902✔
1156
    temperature_default =
62✔
1157
      std::stod(get_node_value(root, "temperature_default"));
62✔
1158
  }
1159
  if (check_for_node(root, "temperature_method")) {
2,902✔
1160
    auto temp = get_node_value(root, "temperature_method", true, true);
120✔
1161
    if (temp == "nearest") {
120✔
1162
      temperature_method = TemperatureMethod::NEAREST;
52✔
1163
    } else if (temp == "interpolation") {
68!
1164
      temperature_method = TemperatureMethod::INTERPOLATION;
68✔
1165
    } else {
1166
      fatal_error("Unknown temperature method: " + temp);
×
1167
    }
1168
  }
120✔
1169
  if (check_for_node(root, "temperature_tolerance")) {
2,902✔
1170
    temperature_tolerance =
68✔
1171
      std::stod(get_node_value(root, "temperature_tolerance"));
68✔
1172
  }
1173
  if (check_for_node(root, "temperature_multipole")) {
2,902✔
1174
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
18✔
1175

1176
    // Multipole currently doesn't work with photon transport
1177
    if (temperature_multipole && photon_transport) {
18!
1178
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1179
                  "photon transport.");
1180
    }
1181
  }
1182
  if (check_for_node(root, "temperature_range")) {
2,902!
1183
    auto range = get_node_array<double>(root, "temperature_range");
×
1184
    temperature_range[0] = range.at(0);
×
1185
    temperature_range[1] = range.at(1);
×
1186
  }
×
1187

1188
  // Check for tabular_legendre options
1189
  if (check_for_node(root, "tabular_legendre")) {
2,902✔
1190
    // Get pointer to tabular_legendre node
1191
    xml_node node_tab_leg = root.child("tabular_legendre");
36✔
1192

1193
    // Check for enable option
1194
    if (check_for_node(node_tab_leg, "enable")) {
36!
1195
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
36✔
1196
    }
1197

1198
    // Check for the number of points
1199
    if (check_for_node(node_tab_leg, "num_points")) {
36!
1200
      legendre_to_tabular_points =
×
1201
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
1202
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
1203
        fatal_error(
×
1204
          "The 'num_points' subelement/attribute of the "
1205
          "<tabular_legendre> element must contain a value greater than 1");
1206
      }
1207
    }
1208
  }
1209

1210
  // Check whether create delayed neutrons in fission
1211
  if (check_for_node(root, "create_delayed_neutrons")) {
2,902!
1212
    create_delayed_neutrons =
×
1213
      get_node_value_bool(root, "create_delayed_neutrons");
×
1214
  }
1215

1216
  // Check whether create fission sites
1217
  if (run_mode == RunMode::FIXED_SOURCE) {
2,902✔
1218
    if (check_for_node(root, "create_fission_neutrons")) {
950✔
1219
      create_fission_neutrons =
54✔
1220
        get_node_value_bool(root, "create_fission_neutrons");
54✔
1221
    }
1222
  }
1223

1224
  // Check whether to scale fission photon yields
1225
  if (check_for_node(root, "delayed_photon_scaling")) {
2,902!
1226
    delayed_photon_scaling =
×
1227
      get_node_value_bool(root, "delayed_photon_scaling");
×
1228
  }
1229

1230
  // Check whether to use event-based parallelism
1231
  if (check_for_node(root, "event_based")) {
2,902!
NEW
1232
    event_based = get_node_value_bool(root, "event_based");
×
NEW
1233
    if (temperature_field_on && event_based) {
×
NEW
1234
      fatal_error(
×
1235
        "Event-based transport is not yet compatible with temperature fields.");
1236
    }
1237
  }
1238

1239
  // Check whether material cell offsets should be generated
1240
  if (check_for_node(root, "material_cell_offsets")) {
2,902!
1241
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1242
  }
1243

1244
  // Weight window information
1245
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
2,934✔
1246
    variance_reduction::weight_windows.emplace_back(
32✔
1247
      std::make_unique<WeightWindows>(node_ww));
64✔
1248
  }
1249

1250
  // Enable weight windows by default if one or more are present
1251
  if (variance_reduction::weight_windows.size() > 0)
2,902✔
1252
    settings::weight_windows_on = true;
22✔
1253

1254
  // read weight windows from file
1255
  if (check_for_node(root, "weight_windows_file")) {
2,902!
1256
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1257
  }
1258

1259
  // read settings for weight windows value, this will override
1260
  // the automatic setting even if weight windows are present
1261
  if (check_for_node(root, "weight_windows_on")) {
2,902✔
1262
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
12✔
1263
  }
1264

1265
  if (check_for_node(root, "max_secondaries")) {
2,902!
1266
    settings::max_secondaries =
×
1267
      std::stoi(get_node_value(root, "max_secondaries"));
×
1268
  }
1269

1270
  if (check_for_node(root, "max_history_splits")) {
2,902✔
1271
    settings::max_history_splits =
78✔
1272
      std::stoi(get_node_value(root, "max_history_splits"));
78✔
1273
  }
1274

1275
  if (check_for_node(root, "max_tracks")) {
2,902✔
1276
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
18✔
1277
  }
1278

1279
  // Create weight window generator objects
1280
  if (check_for_node(root, "weight_window_generators")) {
2,902✔
1281
    auto wwgs_node = root.child("weight_window_generators");
30✔
1282
    for (pugi::xml_node node_wwg :
30✔
1283
      wwgs_node.children("weight_windows_generator")) {
90✔
1284
      variance_reduction::weight_windows_generators.emplace_back(
30✔
1285
        std::make_unique<WeightWindowsGenerator>(node_wwg));
60✔
1286
    }
1287
    // if any of the weight windows are intended to be generated otf, make
1288
    // sure they're applied
1289
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
30!
1290
      if (wwg->on_the_fly_) {
30!
1291
        settings::weight_windows_on = true;
30✔
1292
        break;
30✔
1293
      }
1294
    }
1295
  }
1296

1297
  // Set up weight window checkpoints
1298
  if (check_for_node(root, "weight_window_checkpoints")) {
2,902!
UNCOV
1299
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
×
UNCOV
1300
    if (check_for_node(ww_checkpoints, "collision")) {
×
UNCOV
1301
      weight_window_checkpoint_collision =
×
UNCOV
1302
        get_node_value_bool(ww_checkpoints, "collision");
×
1303
    }
UNCOV
1304
    if (check_for_node(ww_checkpoints, "surface")) {
×
UNCOV
1305
      weight_window_checkpoint_surface =
×
UNCOV
1306
        get_node_value_bool(ww_checkpoints, "surface");
×
1307
    }
1308
  }
1309

1310
  if (check_for_node(root, "use_decay_photons")) {
2,902✔
1311
    settings::use_decay_photons =
4✔
1312
      get_node_value_bool(root, "use_decay_photons");
4✔
1313
  }
1314
}
2,902✔
1315

1316
void free_memory_settings()
2,944✔
1317
{
1318
  settings::statepoint_batch.clear();
2,944✔
1319
  settings::sourcepoint_batch.clear();
2,944✔
1320
  settings::source_write_surf_id.clear();
2,944✔
1321
  settings::res_scat_nuclides.clear();
2,944✔
1322
}
2,944✔
1323

1324
//==============================================================================
1325
// C API functions
1326
//==============================================================================
1327

1328
extern "C" int openmc_set_n_batches(
16✔
1329
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1330
{
1331
  if (settings::n_inactive >= n_batches) {
16✔
1332
    set_errmsg("Number of active batches must be greater than zero.");
4✔
1333
    return OPENMC_E_INVALID_ARGUMENT;
4✔
1334
  }
1335

1336
  if (!settings::trigger_on) {
12✔
1337
    // Set n_batches and n_max_batches to same value
1338
    settings::n_batches = n_batches;
4✔
1339
    settings::n_max_batches = n_batches;
4✔
1340
  } else {
1341
    // Set n_batches and n_max_batches based on value of set_max_batches
1342
    if (set_max_batches) {
8✔
1343
      settings::n_max_batches = n_batches;
4✔
1344
    } else {
1345
      settings::n_batches = n_batches;
4✔
1346
    }
1347
  }
1348

1349
  // Update size of k_generation and entropy
1350
  int m = settings::n_max_batches * settings::gen_per_batch;
12✔
1351
  simulation::k_generation.reserve(m);
12✔
1352
  simulation::entropy.reserve(m);
12✔
1353

1354
  // Add value of n_batches to statepoint_batch
1355
  if (add_statepoint_batch &&
20✔
1356
      !(contains(settings::statepoint_batch, n_batches)))
8!
1357
    settings::statepoint_batch.insert(n_batches);
8✔
1358

1359
  return 0;
12✔
1360
}
1361

1362
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
920✔
1363
{
1364
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
920✔
1365

1366
  return 0;
920✔
1367
}
1368

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