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

openmc-dev / openmc / 23562589134

25 Mar 2026 08:30PM UTC coverage: 80.33% (-1.0%) from 81.326%
23562589134

Pull #3702

github

web-flow
Merge b34a5c94e into 6cd39073b
Pull Request #3702: Random Ray Kinetic Simulation Mode

17619 of 25259 branches covered (69.75%)

Branch coverage included in aggregate %.

942 of 1975 new or added lines in 21 files covered. (47.7%)

374 existing lines in 28 files now uncovered.

57996 of 68871 relevant lines covered (84.21%)

48728124.42 hits per line

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

75.65
/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 kinetic_simulation {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 atomic_relaxation {true};
67
bool reduce_tallies {true};
68
bool res_scat_on {false};
69
bool restart_run {false};
70
bool run_CE {true};
71
bool source_latest {false};
72
bool source_separate {false};
73
bool source_write {true};
74
bool source_mcpl_write {false};
75
bool surf_source_write {false};
76
bool surf_mcpl_write {false};
77
bool surf_source_read {false};
78
bool survival_biasing {false};
79
bool survival_normalization {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
std::string properties_file;
102

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

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

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

157
// Timestep variables for kinetic simulation
158
int n_timesteps;
159
double dt;
160

161
} // namespace settings
162

163
//==============================================================================
164
// Functions
165
//==============================================================================
166

167
void get_run_parameters(pugi::xml_node node_base)
6,201✔
168
{
169
  using namespace settings;
6,201✔
170
  using namespace pugi;
6,201✔
171

172
  // Check number of particles
173
  if (!check_for_node(node_base, "particles")) {
6,201!
174
    fatal_error("Need to specify number of particles.");
×
175
  }
176

177
  // Get number of particles if it wasn't specified as a command-line argument
178
  if (n_particles == -1) {
6,201!
179
    n_particles = std::stoll(get_node_value(node_base, "particles"));
6,201✔
180
  }
181

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

188
  // Get maximum number of events allowed per particle
189
  if (check_for_node(node_base, "max_particle_events")) {
6,201!
190
    max_particle_events =
×
191
      std::stoll(get_node_value(node_base, "max_particle_events"));
×
192
  }
193

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

201
  // Get max number of lost particles
202
  if (check_for_node(node_base, "max_lost_particles")) {
6,201✔
203
    max_lost_particles =
72✔
204
      std::stoi(get_node_value(node_base, "max_lost_particles"));
36✔
205
  }
206

207
  // Get relative number of lost particles
208
  if (check_for_node(node_base, "rel_max_lost_particles")) {
6,201!
209
    rel_max_lost_particles =
×
210
      std::stod(get_node_value(node_base, "rel_max_lost_particles"));
×
211
  }
212

213
  // Get relative number of lost particles
214
  if (check_for_node(node_base, "max_write_lost_particles")) {
6,201✔
215
    max_write_lost_particles =
24✔
216
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
12✔
217
  }
218

219
  // Get number of inactive batches
220
  if (run_mode == RunMode::EIGENVALUE ||
6,201✔
221
      solver_type == SolverType::RANDOM_RAY) {
2,360✔
222
    if (check_for_node(node_base, "inactive")) {
4,165✔
223
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
3,992✔
224
    }
225
    if (check_for_node(node_base, "generations_per_batch")) {
4,165✔
226
      gen_per_batch =
24✔
227
        std::stoi(get_node_value(node_base, "generations_per_batch"));
12✔
228
    }
229

230
    // Preallocate space for keff and entropy by generation
231
    int m = settings::n_max_batches * settings::gen_per_batch;
4,165✔
232
    simulation::k_generation.reserve(m);
4,165✔
233
    simulation::entropy.reserve(m);
4,165✔
234

235
    // Get the trigger information for keff
236
    if (check_for_node(node_base, "keff_trigger")) {
4,165✔
237
      xml_node node_keff_trigger = node_base.child("keff_trigger");
81✔
238

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

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

266
  // Kinetic variables
267
  if (check_for_node(node_base, "kinetic_simulation")) {
6,201✔
268
    kinetic_simulation = get_node_value_bool(node_base, "kinetic_simulation");
144✔
269
    if (solver_type != SolverType::RANDOM_RAY) {
144!
NEW
270
      fatal_error("Unsupported solver selected for kinetic simulation. Kinetic "
×
271
                  "simulations currently only support the random ray solver.");
272
    }
273
    if (run_mode != RunMode::EIGENVALUE) {
144!
NEW
274
      fatal_error(
×
275
        "Unsupported run mode selected for kinetic simulation. Kinetic "
276
        "simulations currently only support run mode based on an eigenvalue "
277
        "simulation establishing an initial condition.");
278
    }
279
  }
280

281
  // Get timestep parameters for kinetic simulations
282
  if (kinetic_simulation) {
6,201✔
283
    xml_node ts_node = node_base.child("timestep_parameters");
144✔
284
    if (check_for_node(ts_node, "n_timesteps")) {
144!
285
      n_timesteps = std::stoi(get_node_value(ts_node, "n_timesteps"));
288✔
286
    } else {
NEW
287
      fatal_error("Specify number of timesteps in settings XML");
×
288
    }
289
    if (check_for_node(ts_node, "timestep_units")) {
144!
290
      std::string units = get_node_value(ts_node, "timestep_units");
144✔
291
      if (check_for_node(ts_node, "dt")) {
144!
292
        dt = std::stod(get_node_value(ts_node, "dt"));
288✔
293
        double factor_to_seconds;
144✔
294
        if (units == "ms") {
144!
295
          factor_to_seconds = 1e-3;
296
        } else if (units == "s") {
144!
297
          factor_to_seconds = 1.0;
NEW
298
        } else if (units == "min") {
×
299
          factor_to_seconds = 1 / 60;
300
        } else {
NEW
301
          fatal_error("Invalid timestep unit, " + units);
×
302
        }
303
        dt *= factor_to_seconds;
144✔
304
      } else {
NEW
305
        fatal_error("Specify dt in settings XML");
×
306
      }
307
    } else {
144✔
NEW
308
      fatal_error("Specify timestep units in settings XML");
×
309
    }
310
  }
311

312
  // Random ray variables
313
  if (solver_type == SolverType::RANDOM_RAY) {
6,201✔
314
    xml_node random_ray_node = node_base.child("random_ray");
753✔
315
    if (check_for_node(random_ray_node, "distance_active")) {
753!
316
      RandomRay::distance_active_ =
1,506✔
317
        std::stod(get_node_value(random_ray_node, "distance_active"));
1,506✔
318
      if (RandomRay::distance_active_ <= 0.0) {
753!
319
        fatal_error("Random ray active distance must be greater than 0");
×
320
      }
321
    } else {
322
      fatal_error("Specify random ray active distance in settings XML");
×
323
    }
324
    if (check_for_node(random_ray_node, "distance_inactive")) {
753!
325
      RandomRay::distance_inactive_ =
1,506✔
326
        std::stod(get_node_value(random_ray_node, "distance_inactive"));
1,506✔
327
      if (RandomRay::distance_inactive_ < 0) {
753!
328
        fatal_error(
×
329
          "Random ray inactive distance must be greater than or equal to 0");
330
      }
331
    } else {
332
      fatal_error("Specify random ray inactive distance in settings XML");
×
333
    }
334
    if (check_for_node(random_ray_node, "source")) {
753!
335
      xml_node source_node = random_ray_node.child("source");
753✔
336
      // Get point to list of <source> elements and make sure there is at least
337
      // one
338
      RandomRay::ray_source_ = Source::create(source_node);
1,506✔
339
    } else {
340
      fatal_error("Specify random ray source in settings XML");
×
341
    }
342
    if (check_for_node(random_ray_node, "volume_estimator")) {
753✔
343
      std::string temp_str =
96✔
344
        get_node_value(random_ray_node, "volume_estimator", true, true);
96✔
345
      if (temp_str == "simulation_averaged") {
96✔
346
        FlatSourceDomain::volume_estimator_ =
24✔
347
          RandomRayVolumeEstimator::SIMULATION_AVERAGED;
348
      } else if (temp_str == "naive") {
72✔
349
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::NAIVE;
48✔
350
      } else if (temp_str == "hybrid") {
24!
351
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::HYBRID;
24✔
352
      } else {
353
        fatal_error("Unrecognized volume estimator: " + temp_str);
×
354
      }
355
    }
96✔
356
    if (check_for_node(random_ray_node, "source_shape")) {
753✔
357
      std::string temp_str =
360✔
358
        get_node_value(random_ray_node, "source_shape", true, true);
360✔
359
      if (temp_str == "flat") {
360✔
360
        RandomRay::source_shape_ = RandomRaySourceShape::FLAT;
60✔
361
      } else if (temp_str == "linear") {
300✔
362
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR;
264✔
363
        if (settings::kinetic_simulation) {
264!
NEW
364
          fatal_error(
×
365
            "linear source shapes unimplemented for kinetic simulations.");
366
        }
367
      } else if (temp_str == "linear_xy") {
36!
368
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR_XY;
36✔
369
        if (settings::kinetic_simulation) {
36!
NEW
370
          fatal_error(
×
371
            "linear_xy source shapes unimplemented for kinetic simulations.");
372
        }
373
      } else {
374
        fatal_error("Unrecognized source shape: " + temp_str);
×
375
      }
376
    }
360✔
377
    if (check_for_node(random_ray_node, "volume_normalized_flux_tallies")) {
753✔
378
      FlatSourceDomain::volume_normalized_flux_tallies_ =
465✔
379
        get_node_value_bool(random_ray_node, "volume_normalized_flux_tallies");
465✔
380
    }
381
    if (check_for_node(random_ray_node, "adjoint")) {
753✔
382
      FlatSourceDomain::adjoint_ =
48✔
383
        get_node_value_bool(random_ray_node, "adjoint");
24✔
384
      if (FlatSourceDomain::adjoint_ && kinetic_simulation) {
24!
NEW
385
        fatal_error("Adjoint kinetic simulations are currently unsupported .");
×
386
      }
387
    }
388
    if (check_for_node(random_ray_node, "sample_method")) {
753✔
389
      std::string temp_str =
24✔
390
        get_node_value(random_ray_node, "sample_method", true, true);
24✔
391
      if (temp_str == "prng") {
24!
392
        RandomRay::sample_method_ = RandomRaySampleMethod::PRNG;
×
393
      } else if (temp_str == "halton") {
24✔
394
        RandomRay::sample_method_ = RandomRaySampleMethod::HALTON;
12✔
395
      } else if (temp_str == "s2") {
12!
396
        RandomRay::sample_method_ = RandomRaySampleMethod::S2;
12✔
397
      } else {
398
        fatal_error("Unrecognized sample method: " + temp_str);
×
399
      }
400
    }
24✔
401
    if (check_for_node(random_ray_node, "source_region_meshes")) {
753✔
402
      pugi::xml_node node_source_region_meshes =
372✔
403
        random_ray_node.child("source_region_meshes");
372✔
404
      for (pugi::xml_node node_mesh :
792✔
405
        node_source_region_meshes.children("mesh")) {
792✔
406
        int mesh_id = std::stoi(node_mesh.attribute("id").value());
840✔
407
        for (pugi::xml_node node_domain : node_mesh.children("domain")) {
840✔
408
          int domain_id = std::stoi(node_domain.attribute("id").value());
840✔
409
          std::string domain_type = node_domain.attribute("type").value();
420✔
410
          Source::DomainType type;
420✔
411
          if (domain_type == "material") {
420✔
412
            type = Source::DomainType::MATERIAL;
24✔
413
          } else if (domain_type == "cell") {
396✔
414
            type = Source::DomainType::CELL;
24✔
415
          } else if (domain_type == "universe") {
372!
416
            type = Source::DomainType::UNIVERSE;
372✔
417
          } else {
418
            throw std::runtime_error("Unknown domain type: " + domain_type);
×
419
          }
420
          FlatSourceDomain::mesh_domain_map_[mesh_id].emplace_back(
420✔
421
            type, domain_id);
422
        }
420✔
423
      }
424
    }
425
    if (check_for_node(random_ray_node, "diagonal_stabilization_rho")) {
753✔
426
      FlatSourceDomain::diagonal_stabilization_rho_ = std::stod(
36✔
427
        get_node_value(random_ray_node, "diagonal_stabilization_rho"));
36✔
428
      if (FlatSourceDomain::diagonal_stabilization_rho_ < 0.0 ||
36!
429
          FlatSourceDomain::diagonal_stabilization_rho_ > 1.0) {
430
        fatal_error("Random ray diagonal stabilization rho factor must be "
×
431
                    "between 0 and 1");
432
      }
433
    }
434
    if (kinetic_simulation) {
753✔
435
      if (check_for_node(random_ray_node, "bd_order")) {
144✔
436
        static int n = std::stod(get_node_value(random_ray_node, "bd_order"));
96!
437
        if (n < 1 || n > 6) {
48!
NEW
438
          fatal_error("Specified BD order of " + std::to_string(n) +
×
439
                      ". BD order must be between 1 and 6");
440
        } else {
441
          RandomRay::bd_order_ = n;
48✔
442
        }
443
      }
444
      if (check_for_node(random_ray_node, "time_derivative_method")) {
144✔
445
        std::string temp_str =
96✔
446
          get_node_value(random_ray_node, "time_derivative_method", true, true);
96✔
447
        if (temp_str == "isotropic") {
96✔
448
          RandomRay::time_method_ = RandomRayTimeMethod::ISOTROPIC;
48✔
449
        } else if (temp_str == "propagation") {
48!
450
          RandomRay::time_method_ = RandomRayTimeMethod::PROPAGATION;
48✔
451
        } else {
NEW
452
          fatal_error("Unrecognized time derivative method: " + temp_str);
×
453
        }
454
      }
96✔
455
    }
456
  }
457
}
6,201✔
458

459
void read_settings_xml()
1,078✔
460
{
461
  using namespace settings;
1,078✔
462
  using namespace pugi;
1,078✔
463
  // Check if settings.xml exists
464
  std::string filename = settings::path_input + "settings.xml";
1,078✔
465
  if (!file_exists(filename)) {
1,078✔
466
    if (run_mode != RunMode::PLOTTING) {
18!
467
      fatal_error("Could not find any XML input files! In order to run OpenMC, "
×
468
                  "you first need a set of input files; at a minimum, this "
469
                  "includes settings.xml, geometry.xml, and materials.xml or a "
470
                  "single model XML file. Please consult the user's guide at "
471
                  "https://docs.openmc.org for further information.");
472
    } else {
473
      // The settings.xml file is optional if we just want to make a plot.
474
      return;
18✔
475
    }
476
  }
477

478
  // Parse settings.xml file
479
  xml_document doc;
1,060✔
480
  auto result = doc.load_file(filename.c_str());
1,060✔
481
  if (!result) {
1,060!
482
    fatal_error("Error processing settings.xml file.");
×
483
  }
484

485
  // Get root element
486
  xml_node root = doc.document_element();
1,060✔
487

488
  // Verbosity
489
  if (check_for_node(root, "verbosity") && verbosity == -1) {
1,060!
490
    verbosity = std::stoi(get_node_value(root, "verbosity"));
294✔
491
  } else if (verbosity == -1) {
913!
492
    verbosity = 7;
913✔
493
  }
494

495
  // To this point, we haven't displayed any output since we didn't know what
496
  // the verbosity is. Now that we checked for it, show the title if necessary
497
  if (mpi::master) {
1,060✔
498
    if (verbosity >= 2)
925✔
499
      title();
784✔
500
  }
501

502
  write_message("Reading settings XML file...", 5);
1,060✔
503

504
  read_settings_xml(root);
1,060✔
505
}
1,070✔
506

507
void read_settings_xml(pugi::xml_node root)
6,860✔
508
{
509
  using namespace settings;
6,860✔
510
  using namespace pugi;
6,860✔
511

512
  // Find if a multi-group or continuous-energy simulation is desired
513
  if (check_for_node(root, "energy_mode")) {
6,860✔
514
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
1,173✔
515
    if (temp_str == "mg" || temp_str == "multi-group") {
2,346!
516
      run_CE = false;
1,173✔
517
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
518
      run_CE = true;
×
519
    }
520
  }
1,173✔
521

522
  // Check for user meshes and allocate
523
  read_meshes(root);
6,860✔
524

525
  // Look for deprecated cross_sections.xml file in settings.xml
526
  if (check_for_node(root, "cross_sections")) {
6,860!
527
    warning(
×
528
      "Setting cross_sections in settings.xml has been deprecated."
529
      " The cross_sections are now set in materials.xml and the "
530
      "cross_sections input to materials.xml and the OPENMC_CROSS_SECTIONS"
531
      " environment variable will take precendent over setting "
532
      "cross_sections in settings.xml.");
533
    path_cross_sections = get_node_value(root, "cross_sections");
×
534
  }
535

536
  if (!run_CE) {
6,860✔
537
    // Scattering Treatments
538
    if (check_for_node(root, "max_order")) {
1,173✔
539
      max_order = std::stoi(get_node_value(root, "max_order"));
24✔
540
    } else {
541
      // Set to default of largest int - 1, which means to use whatever is
542
      // contained in library. This is largest int - 1 because for legendre
543
      // scattering, a value of 1 is added to the order; adding 1 to the largest
544
      // int gets you the largest negative integer, which is not what we want.
545
      max_order = std::numeric_limits<int>::max() - 1;
1,161✔
546
    }
547
  }
548

549
  // Check for a trigger node and get trigger information
550
  if (check_for_node(root, "trigger")) {
6,860✔
551
    xml_node node_trigger = root.child("trigger");
126✔
552

553
    // Check if trigger(s) are to be turned on
554
    trigger_on = get_node_value_bool(node_trigger, "active");
126✔
555

556
    if (trigger_on) {
126✔
557
      if (check_for_node(node_trigger, "max_batches")) {
114!
558
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
228✔
559
      } else {
560
        fatal_error("<max_batches> must be specified with triggers");
×
561
      }
562

563
      // Get the batch interval to check triggers
564
      if (!check_for_node(node_trigger, "batch_interval")) {
114✔
565
        trigger_predict = true;
12✔
566
      } else {
567
        trigger_batch_interval =
204✔
568
          std::stoi(get_node_value(node_trigger, "batch_interval"));
204✔
569
        if (trigger_batch_interval <= 0) {
102!
570
          fatal_error("Trigger batch interval must be greater than zero");
×
571
        }
572
      }
573
    }
574
  }
575

576
  // Check run mode if it hasn't been set from the command line
577
  xml_node node_mode;
6,860✔
578
  if (run_mode == RunMode::UNSET) {
6,860✔
579
    if (check_for_node(root, "run_mode")) {
6,225✔
580
      std::string temp_str = get_node_value(root, "run_mode", true, true);
6,201✔
581
      if (temp_str == "eigenvalue") {
6,201✔
582
        run_mode = RunMode::EIGENVALUE;
3,817✔
583
      } else if (temp_str == "fixed source") {
2,384✔
584
        run_mode = RunMode::FIXED_SOURCE;
2,360✔
585
      } else if (temp_str == "plot") {
24!
586
        run_mode = RunMode::PLOTTING;
×
587
      } else if (temp_str == "particle restart") {
24!
588
        run_mode = RunMode::PARTICLE;
×
589
      } else if (temp_str == "volume") {
24!
590
        run_mode = RunMode::VOLUME;
24✔
591
      } else {
592
        fatal_error("Unrecognized run mode: " + temp_str);
×
593
      }
594

595
      // Assume XML specifies <particles>, <batches>, etc. directly
596
      node_mode = root;
6,201✔
597
    } else {
6,201✔
598
      warning("<run_mode> should be specified.");
24✔
599

600
      // Make sure that either eigenvalue or fixed source was specified
601
      node_mode = root.child("eigenvalue");
24✔
602
      if (node_mode) {
24!
603
        run_mode = RunMode::EIGENVALUE;
24✔
604
      } else {
605
        node_mode = root.child("fixed_source");
×
606
        if (node_mode) {
×
607
          run_mode = RunMode::FIXED_SOURCE;
×
608
        } else {
609
          fatal_error("<eigenvalue> or <fixed_source> not specified.");
×
610
        }
611
      }
612
    }
613
  }
614

615
  // Check solver type
616
  if (check_for_node(root, "random_ray")) {
6,860✔
617
    solver_type = SolverType::RANDOM_RAY;
753✔
618
    if (run_CE)
753!
619
      fatal_error("multi-group energy mode must be specified in settings XML "
×
620
                  "when using the random ray solver.");
621
  }
622

623
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
6,860✔
624
    // Read run parameters
625
    get_run_parameters(node_mode);
6,201✔
626

627
    // Check number of active batches, inactive batches, max lost particles and
628
    // particles
629
    if (n_batches <= n_inactive) {
6,201!
630
      fatal_error("Number of active batches must be greater than zero.");
×
631
    } else if (n_inactive < 0) {
6,201!
632
      fatal_error("Number of inactive batches must be non-negative.");
×
633
    } else if (n_particles <= 0) {
6,201!
634
      fatal_error("Number of particles must be greater than zero.");
×
635
    } else if (max_lost_particles <= 0) {
6,201!
636
      fatal_error("Number of max lost particles must be greater than zero.");
×
637
    } else if (rel_max_lost_particles <= 0.0 || rel_max_lost_particles >= 1.0) {
6,201!
638
      fatal_error("Relative max lost particles must be between zero and one.");
×
639
    }
640

641
    // Check for user value for the number of generation of the Iterated Fission
642
    // Probability (IFP) method
643
    if (check_for_node(root, "ifp_n_generation")) {
6,201✔
644
      ifp_n_generation = std::stoi(get_node_value(root, "ifp_n_generation"));
136✔
645
      if (ifp_n_generation <= 0) {
68!
646
        fatal_error("'ifp_n_generation' must be greater than 0.");
×
647
      }
648
      // Avoid tallying 0 if IFP logs are not complete when active cycles start
649
      if (ifp_n_generation > n_inactive) {
68✔
650
        fatal_error("'ifp_n_generation' must be lower than or equal to the "
8✔
651
                    "number of inactive cycles.");
652
      }
653
    }
654
  }
655

656
  // Copy plotting random number seed if specified
657
  if (check_for_node(root, "plot_seed")) {
6,852!
658
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
659
    model::plotter_seed = seed;
×
660
  }
661

662
  // Copy random number seed if specified
663
  if (check_for_node(root, "seed")) {
6,852✔
664
    auto seed = std::stoll(get_node_value(root, "seed"));
914✔
665
    openmc_set_seed(seed);
457✔
666
  }
667

668
  // Copy random number stride if specified
669
  if (check_for_node(root, "stride")) {
6,852✔
670
    auto stride = std::stoull(get_node_value(root, "stride"));
24✔
671
    openmc_set_stride(stride);
12✔
672
  }
673

674
  // Check for electron treatment
675
  if (check_for_node(root, "electron_treatment")) {
6,852✔
676
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
66✔
677
    if (temp_str == "led") {
66✔
678
      electron_treatment = ElectronTreatment::LED;
21✔
679
    } else if (temp_str == "ttb") {
45!
680
      electron_treatment = ElectronTreatment::TTB;
45✔
681
    } else {
682
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
683
    }
684
  }
66✔
685

686
  // Check for photon transport
687
  if (check_for_node(root, "photon_transport")) {
6,852✔
688
    photon_transport = get_node_value_bool(root, "photon_transport");
165✔
689

690
    if (!run_CE && photon_transport) {
165!
691
      fatal_error("Photon transport is not currently supported in "
×
692
                  "multigroup mode");
693
    }
694
  }
695

696
  // Check for atomic relaxation
697
  if (check_for_node(root, "atomic_relaxation")) {
6,852✔
698
    atomic_relaxation = get_node_value_bool(root, "atomic_relaxation");
12✔
699
  }
700

701
  // Number of bins for logarithmic grid
702
  if (check_for_node(root, "log_grid_bins")) {
6,852✔
703
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
24✔
704
    if (n_log_bins < 1) {
12!
705
      fatal_error("Number of bins for logarithmic grid must be greater "
×
706
                  "than zero.");
707
    }
708
  }
709

710
  // Number of OpenMP threads
711
  if (check_for_node(root, "threads")) {
6,852!
712
    if (mpi::master)
×
713
      warning("The <threads> element has been deprecated. Use "
×
714
              "the OMP_NUM_THREADS environment variable to set the number of "
715
              "threads.");
716
  }
717

718
  // ==========================================================================
719
  // EXTERNAL SOURCE
720

721
  // Get point to list of <source> elements and make sure there is at least one
722
  for (pugi::xml_node node : root.children("source")) {
13,316✔
723
    model::external_sources.push_back(Source::create(node));
12,936✔
724
  }
725

726
  // Check if the user has specified to read surface source
727
  if (check_for_node(root, "surf_source_read")) {
6,844✔
728
    surf_source_read = true;
24✔
729
    // Get surface source read node
730
    xml_node node_ssr = root.child("surf_source_read");
24✔
731

732
    std::string path = "surface_source.h5";
24✔
733
    // Check if the user has specified different file for surface source reading
734
    if (check_for_node(node_ssr, "path")) {
24!
735
      path = get_node_value(node_ssr, "path", false, true);
24✔
736
    }
737
    model::external_sources.push_back(make_unique<FileSource>(path));
24✔
738
  }
24✔
739

740
  // If no source specified, default to isotropic point source at origin with
741
  // Watt spectrum. No default source is needed in random ray mode.
742
  if (model::external_sources.empty() &&
6,844✔
743
      settings::solver_type != SolverType::RANDOM_RAY) {
1,835✔
744
    double T[] {0.0};
1,670✔
745
    double p[] {1.0};
1,670✔
746
    model::external_sources.push_back(make_unique<IndependentSource>(
1,670✔
747
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
3,340✔
748
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
3,340✔
749
      UPtrDist {new Discrete(T, p, 1)}));
3,340✔
750
  }
751

752
  // Build probability mass function for sampling external sources
753
  vector<double> source_strengths;
6,844✔
754
  for (auto& s : model::external_sources) {
15,002✔
755
    source_strengths.push_back(s->strength());
8,158✔
756
  }
757
  model::external_sources_probability.assign(source_strengths);
6,844✔
758

759
  // Check if we want to write out source
760
  if (check_for_node(root, "write_initial_source")) {
6,844!
761
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
762
  }
763

764
  // Get relative number of lost particles
765
  if (check_for_node(root, "source_rejection_fraction")) {
6,844✔
766
    source_rejection_fraction =
12✔
767
      std::stod(get_node_value(root, "source_rejection_fraction"));
12!
768
  }
769

770
  if (check_for_node(root, "free_gas_threshold")) {
6,844!
771
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
772
  }
773

774
  // Surface grazing
775
  if (check_for_node(root, "surface_grazing_cutoff"))
6,844!
776
    surface_grazing_cutoff =
×
777
      std::stod(get_node_value(root, "surface_grazing_cutoff"));
×
778
  if (check_for_node(root, "surface_grazing_ratio"))
6,844!
779
    surface_grazing_ratio =
×
780
      std::stod(get_node_value(root, "surface_grazing_ratio"));
×
781

782
  // Survival biasing
783
  if (check_for_node(root, "survival_biasing")) {
6,844✔
784
    survival_biasing = get_node_value_bool(root, "survival_biasing");
153✔
785
  }
786

787
  // Probability tables
788
  if (check_for_node(root, "ptables")) {
6,844✔
789
    urr_ptables_on = get_node_value_bool(root, "ptables");
12✔
790
  }
791

792
  // Cutoffs
793
  if (check_for_node(root, "cutoff")) {
6,844✔
794
    xml_node node_cutoff = root.child("cutoff");
111✔
795
    if (check_for_node(node_cutoff, "weight")) {
111✔
796
      weight_cutoff = std::stod(get_node_value(node_cutoff, "weight"));
24✔
797
    }
798
    if (check_for_node(node_cutoff, "weight_avg")) {
111✔
799
      weight_survive = std::stod(get_node_value(node_cutoff, "weight_avg"));
24✔
800
    }
801
    if (check_for_node(node_cutoff, "survival_normalization")) {
111!
802
      survival_normalization =
×
803
        get_node_value_bool(node_cutoff, "survival_normalization");
×
804
    }
805
    if (check_for_node(node_cutoff, "energy_neutron")) {
111✔
806
      energy_cutoff[0] =
12✔
807
        std::stod(get_node_value(node_cutoff, "energy_neutron"));
24✔
808
    } else if (check_for_node(node_cutoff, "energy")) {
99!
809
      warning("The use of an <energy> cutoff is deprecated and should "
×
810
              "be replaced by <energy_neutron>.");
811
      energy_cutoff[0] = std::stod(get_node_value(node_cutoff, "energy"));
×
812
    }
813
    if (check_for_node(node_cutoff, "energy_photon")) {
111✔
814
      energy_cutoff[1] =
66✔
815
        std::stod(get_node_value(node_cutoff, "energy_photon"));
132✔
816
    }
817
    if (check_for_node(node_cutoff, "energy_electron")) {
111!
818
      energy_cutoff[2] =
×
819
        std::stof(get_node_value(node_cutoff, "energy_electron"));
×
820
    }
821
    if (check_for_node(node_cutoff, "energy_positron")) {
111!
822
      energy_cutoff[3] =
×
823
        std::stod(get_node_value(node_cutoff, "energy_positron"));
×
824
    }
825
    if (check_for_node(node_cutoff, "time_neutron")) {
111✔
826
      time_cutoff[0] = std::stod(get_node_value(node_cutoff, "time_neutron"));
21✔
827
    }
828
    if (check_for_node(node_cutoff, "time_photon")) {
111!
829
      time_cutoff[1] = std::stod(get_node_value(node_cutoff, "time_photon"));
×
830
    }
831
    if (check_for_node(node_cutoff, "time_electron")) {
111!
832
      time_cutoff[2] = std::stod(get_node_value(node_cutoff, "time_electron"));
×
833
    }
834
    if (check_for_node(node_cutoff, "time_positron")) {
111!
835
      time_cutoff[3] = std::stod(get_node_value(node_cutoff, "time_positron"));
×
836
    }
837
  }
838

839
  // read properties from file
840
  if (check_for_node(root, "properties_file")) {
6,844✔
841
    properties_file = get_node_value(root, "properties_file");
9✔
842
    if (!file_exists(properties_file)) {
9!
843
      fatal_error(fmt::format("File '{}' does not exist.", properties_file));
×
844
    }
845
  }
846

847
  // Particle trace
848
  if (check_for_node(root, "trace")) {
6,844✔
849
    auto temp = get_node_array<int64_t>(root, "trace");
12✔
850
    if (temp.size() != 3) {
12!
851
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
852
                  "batch, generation, and particle number.");
853
    }
854
    trace_batch = temp.at(0);
12✔
855
    trace_gen = temp.at(1);
12✔
856
    trace_particle = temp.at(2);
12✔
857
  }
12✔
858

859
  // Particle tracks
860
  if (check_for_node(root, "track")) {
6,844✔
861
    // Get values and make sure there are three per particle
862
    auto temp = get_node_array<int>(root, "track");
36✔
863
    if (temp.size() % 3 != 0) {
36!
864
      fatal_error(
×
865
        "Number of integers specified in 'track' is not "
866
        "divisible by 3.  Please provide 3 integers per particle to be "
867
        "tracked.");
868
    }
869

870
    // Reshape into track_identifiers
871
    int n_tracks = temp.size() / 3;
36✔
872
    for (int i = 0; i < n_tracks; ++i) {
144✔
873
      track_identifiers.push_back(
108✔
874
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
108✔
875
    }
876
  }
36✔
877

878
  // Shannon entropy
879
  if (solver_type == SolverType::RANDOM_RAY) {
6,844✔
880
    if (check_for_node(root, "entropy_mesh")) {
753!
881
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
882
                  "No user-defined entropy mesh is supported.");
883
    }
884
    entropy_on = true;
753✔
885
  } else if (solver_type == SolverType::MONTE_CARLO) {
6,091!
886
    if (check_for_node(root, "entropy_mesh")) {
6,091✔
887
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
546✔
888
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
273!
889
        fatal_error(fmt::format(
×
890
          "Mesh {} specified for Shannon entropy does not exist.", temp));
891
      }
892

893
      auto* m = dynamic_cast<RegularMesh*>(
273!
894
        model::meshes[model::mesh_map.at(temp)].get());
273!
895
      if (!m)
273!
896
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
897
      simulation::entropy_mesh = m;
273✔
898

899
      // Turn on Shannon entropy calculation
900
      entropy_on = true;
273✔
901

902
    } else if (check_for_node(root, "entropy")) {
5,818!
903
      fatal_error(
×
904
        "Specifying a Shannon entropy mesh via the <entropy> element "
905
        "is deprecated. Please create a mesh using <mesh> and then reference "
906
        "it by specifying its ID in an <entropy_mesh> element.");
907
    }
908
  }
909
  // Uniform fission source weighting mesh
910
  if (check_for_node(root, "ufs_mesh")) {
6,844✔
911
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
24✔
912
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
12!
913
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
914
                              "method does not exist.",
915
        temp));
916
    }
917

918
    auto* m =
12✔
919
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
12!
920
    if (!m)
12!
921
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
922
    simulation::ufs_mesh = m;
12✔
923

924
    // Turn on uniform fission source weighting
925
    ufs_on = true;
12✔
926

927
  } else if (check_for_node(root, "uniform_fs")) {
6,832!
928
    fatal_error(
×
929
      "Specifying a UFS mesh via the <uniform_fs> element "
930
      "is deprecated. Please create a mesh using <mesh> and then reference "
931
      "it by specifying its ID in a <ufs_mesh> element.");
932
  }
933

934
  // Check if the user has specified to write state points
935
  if (check_for_node(root, "state_point")) {
6,844✔
936

937
    // Get pointer to state_point node
938
    auto node_sp = root.child("state_point");
129✔
939

940
    // Determine number of batches at which to store state points
941
    if (check_for_node(node_sp, "batches")) {
129!
942
      // User gave specific batches to write state points
943
      auto temp = get_node_array<int>(node_sp, "batches");
129✔
944
      for (const auto& b : temp) {
396✔
945
        statepoint_batch.insert(b);
267✔
946
      }
947
    } else {
129✔
948
      // If neither were specified, write state point at last batch
949
      statepoint_batch.insert(n_batches);
×
950
    }
951
  } else {
952
    // If no <state_point> tag was present, by default write state point at
953
    // last batch only
954
    statepoint_batch.insert(n_batches);
6,715✔
955
  }
956

957
  // Check if the user has specified to write source points
958
  if (check_for_node(root, "source_point")) {
6,844✔
959
    // Get source_point node
960
    xml_node node_sp = root.child("source_point");
81✔
961

962
    // Determine batches at which to store source points
963
    if (check_for_node(node_sp, "batches")) {
81✔
964
      // User gave specific batches to write source points
965
      auto temp = get_node_array<int>(node_sp, "batches");
36✔
966
      for (const auto& b : temp) {
96✔
967
        sourcepoint_batch.insert(b);
60✔
968
      }
969
    } else {
36✔
970
      // If neither were specified, write source points with state points
971
      sourcepoint_batch = statepoint_batch;
45!
972
    }
973

974
    // Check if the user has specified to write binary source file
975
    if (check_for_node(node_sp, "separate")) {
81✔
976
      source_separate = get_node_value_bool(node_sp, "separate");
57✔
977
    }
978
    if (check_for_node(node_sp, "write")) {
81!
979
      source_write = get_node_value_bool(node_sp, "write");
×
980
    }
981
    if (check_for_node(node_sp, "mcpl")) {
81✔
982
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
21✔
983
    }
984
    if (check_for_node(node_sp, "overwrite_latest")) {
81✔
985
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
12✔
986
      source_separate = source_latest;
12✔
987
    }
988
  } else {
989
    // If no <source_point> tag was present, by default we keep source bank in
990
    // statepoint file and write it out at statepoints intervals
991
    source_separate = false;
6,763✔
992
    sourcepoint_batch = statepoint_batch;
6,763!
993
  }
994

995
  // Check is the user specified to convert strength to statistical weight
996
  if (check_for_node(root, "uniform_source_sampling")) {
6,844✔
997
    uniform_source_sampling =
45✔
998
      get_node_value_bool(root, "uniform_source_sampling");
45✔
999
  }
1000

1001
  // Check if the user has specified to write surface source
1002
  if (check_for_node(root, "surf_source_write")) {
6,844✔
1003
    surf_source_write = true;
327✔
1004
    // Get surface source write node
1005
    xml_node node_ssw = root.child("surf_source_write");
327✔
1006

1007
    // Determine surface ids at which crossing particles are to be banked.
1008
    // If no surfaces are specified, all surfaces in the model will be used
1009
    // to bank source points.
1010
    if (check_for_node(node_ssw, "surface_ids")) {
327✔
1011
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
158✔
1012
      for (const auto& b : temp) {
782✔
1013
        source_write_surf_id.insert(b);
624✔
1014
      }
1015
    }
158✔
1016

1017
    // Get maximum number of particles to be banked per surface
1018
    if (check_for_node(node_ssw, "max_particles")) {
327✔
1019
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
638✔
1020
    } else {
1021
      fatal_error("A maximum number of particles needs to be specified "
8✔
1022
                  "using the 'max_particles' parameter to store surface "
1023
                  "source points.");
1024
    }
1025

1026
    // Get maximum number of surface source files to be created
1027
    if (check_for_node(node_ssw, "max_source_files")) {
319✔
1028
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
54✔
1029
    } else {
1030
      ssw_max_files = 1;
292✔
1031
    }
1032

1033
    if (check_for_node(node_ssw, "mcpl")) {
319✔
1034
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
9✔
1035
    }
1036
    // Get cell information
1037
    if (check_for_node(node_ssw, "cell")) {
319✔
1038
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
166✔
1039
      ssw_cell_type = SSWCellType::Both;
83✔
1040
    }
1041
    if (check_for_node(node_ssw, "cellfrom")) {
319✔
1042
      if (ssw_cell_id != C_NONE) {
73✔
1043
        fatal_error(
16✔
1044
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
1045
      }
1046
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
114✔
1047
      ssw_cell_type = SSWCellType::From;
57✔
1048
    }
1049
    if (check_for_node(node_ssw, "cellto")) {
303✔
1050
      if (ssw_cell_id != C_NONE) {
57✔
1051
        fatal_error(
16✔
1052
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
1053
      }
1054
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
82✔
1055
      ssw_cell_type = SSWCellType::To;
41✔
1056
    }
1057
  }
1058

1059
  // Check if the user has specified to write specific collisions
1060
  if (check_for_node(root, "collision_track")) {
6,804✔
1061
    settings::collision_track = true;
119✔
1062
    // Get collision track node
1063
    xml_node node_ct = root.child("collision_track");
119✔
1064
    collision_track_config = CollisionTrackConfig {};
119✔
1065

1066
    // Determine cell ids at which crossing particles are to be banked
1067
    if (check_for_node(node_ct, "cell_ids")) {
119✔
1068
      auto temp = get_node_array<int>(node_ct, "cell_ids");
63✔
1069
      for (const auto& b : temp) {
165✔
1070
        collision_track_config.cell_ids.insert(b);
102✔
1071
      }
1072
    }
63✔
1073
    if (check_for_node(node_ct, "reactions")) {
119✔
1074
      auto temp = get_node_array<std::string>(node_ct, "reactions");
51✔
1075
      for (const auto& b : temp) {
138✔
1076
        int reaction_int = reaction_mt(b);
87✔
1077
        if (reaction_int > 0) {
87!
1078
          collision_track_config.mt_numbers.insert(reaction_int);
87✔
1079
        }
1080
      }
1081
    }
51✔
1082
    if (check_for_node(node_ct, "universe_ids")) {
119✔
1083
      auto temp = get_node_array<int>(node_ct, "universe_ids");
24✔
1084
      for (const auto& b : temp) {
48✔
1085
        collision_track_config.universe_ids.insert(b);
24✔
1086
      }
1087
    }
24✔
1088
    if (check_for_node(node_ct, "material_ids")) {
119✔
1089
      auto temp = get_node_array<int>(node_ct, "material_ids");
24✔
1090
      for (const auto& b : temp) {
60✔
1091
        collision_track_config.material_ids.insert(b);
36✔
1092
      }
1093
    }
24✔
1094
    if (check_for_node(node_ct, "nuclides")) {
119✔
1095
      auto temp = get_node_array<std::string>(node_ct, "nuclides");
24✔
1096
      for (const auto& b : temp) {
96✔
1097
        collision_track_config.nuclides.insert(b);
72✔
1098
      }
1099
    }
24✔
1100
    if (check_for_node(node_ct, "deposited_E_threshold")) {
119✔
1101
      collision_track_config.deposited_energy_threshold =
48✔
1102
        std::stod(get_node_value(node_ct, "deposited_E_threshold"));
48✔
1103
    }
1104
    // Get maximum number of particles to be banked per collision
1105
    if (check_for_node(node_ct, "max_collisions")) {
119!
1106
      collision_track_config.max_collisions =
238✔
1107
        std::stoll(get_node_value(node_ct, "max_collisions"));
238✔
1108
    } else {
1109
      warning("A maximum number of collisions needs to be specified. "
×
1110
              "By default the code sets 'max_collisions' parameter equals to "
1111
              "1000.");
1112
    }
1113
    // Get maximum number of collision_track files to be created
1114
    if (check_for_node(node_ct, "max_collision_track_files")) {
119!
1115
      collision_track_config.max_files =
×
1116
        std::stoll(get_node_value(node_ct, "max_collision_track_files"));
×
1117
    }
1118
    if (check_for_node(node_ct, "mcpl")) {
119✔
1119
      collision_track_config.mcpl_write = get_node_value_bool(node_ct, "mcpl");
18✔
1120
    }
1121
  }
1122

1123
  // If source is not separate and is to be written out in the statepoint
1124
  // file, make sure that the sourcepoint batch numbers are contained in the
1125
  // statepoint list
1126
  if (!source_separate) {
6,804✔
1127
    for (const auto& b : sourcepoint_batch) {
13,572✔
1128
      if (!contains(statepoint_batch, b)) {
13,674!
1129
        fatal_error(
×
1130
          "Sourcepoint batches are not a subset of statepoint batches.");
1131
      }
1132
    }
1133
  }
1134

1135
  // Check if the user has specified to not reduce tallies at the end of every
1136
  // batch
1137
  if (check_for_node(root, "no_reduce")) {
6,804✔
1138
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
24✔
1139
  }
1140

1141
  // Check if the user has specified to use confidence intervals for
1142
  // uncertainties rather than standard deviations
1143
  if (check_for_node(root, "confidence_intervals")) {
6,804✔
1144
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
12✔
1145
  }
1146

1147
  // Check for output options
1148
  if (check_for_node(root, "output")) {
6,804✔
1149
    // Get pointer to output node
1150
    pugi::xml_node node_output = root.child("output");
723✔
1151

1152
    // Check for summary option
1153
    if (check_for_node(node_output, "summary")) {
723✔
1154
      output_summary = get_node_value_bool(node_output, "summary");
702✔
1155
    }
1156

1157
    // Check for ASCII tallies output option
1158
    if (check_for_node(node_output, "tallies")) {
723✔
1159
      output_tallies = get_node_value_bool(node_output, "tallies");
390✔
1160
    }
1161

1162
    // Set output directory if a path has been specified
1163
    if (check_for_node(node_output, "path")) {
723!
1164
      path_output = get_node_value(node_output, "path");
×
1165
      if (!ends_with(path_output, "/")) {
×
1166
        path_output += "/";
723!
1167
      }
1168
    }
1169
  }
1170

1171
  // Resonance scattering parameters
1172
  if (check_for_node(root, "resonance_scattering")) {
6,804✔
1173
    xml_node node_res_scat = root.child("resonance_scattering");
12✔
1174

1175
    // See if resonance scattering is enabled
1176
    if (check_for_node(node_res_scat, "enable")) {
12!
1177
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
12✔
1178
    } else {
1179
      res_scat_on = true;
×
1180
    }
1181

1182
    // Determine what method is used
1183
    if (check_for_node(node_res_scat, "method")) {
12!
1184
      auto temp = get_node_value(node_res_scat, "method", true, true);
12✔
1185
      if (temp == "rvs") {
12!
1186
        res_scat_method = ResScatMethod::rvs;
12✔
1187
      } else if (temp == "dbrc") {
×
1188
        res_scat_method = ResScatMethod::dbrc;
×
1189
      } else {
1190
        fatal_error(
×
1191
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1192
      }
1193
    }
12✔
1194

1195
    // Minimum energy for resonance scattering
1196
    if (check_for_node(node_res_scat, "energy_min")) {
12!
1197
      res_scat_energy_min =
24✔
1198
        std::stod(get_node_value(node_res_scat, "energy_min"));
24✔
1199
    }
1200
    if (res_scat_energy_min < 0.0) {
12!
1201
      fatal_error("Lower resonance scattering energy bound is negative");
×
1202
    }
1203

1204
    // Maximum energy for resonance scattering
1205
    if (check_for_node(node_res_scat, "energy_max")) {
12!
1206
      res_scat_energy_max =
24✔
1207
        std::stod(get_node_value(node_res_scat, "energy_max"));
24✔
1208
    }
1209
    if (res_scat_energy_max < res_scat_energy_min) {
12!
1210
      fatal_error("Upper resonance scattering energy bound is below the "
×
1211
                  "lower resonance scattering energy bound.");
1212
    }
1213

1214
    // Get resonance scattering nuclides
1215
    if (check_for_node(node_res_scat, "nuclides")) {
12!
1216
      res_scat_nuclides =
12✔
1217
        get_node_array<std::string>(node_res_scat, "nuclides");
24✔
1218
    }
1219
  }
1220

1221
  // Get volume calculations
1222
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
7,044✔
1223
    model::volume_calcs.emplace_back(node_vol);
240✔
1224
  }
1225

1226
  // Get temperature settings
1227
  if (check_for_node(root, "temperature_default")) {
6,804✔
1228
    temperature_default =
276✔
1229
      std::stod(get_node_value(root, "temperature_default"));
276✔
1230
  }
1231
  if (check_for_node(root, "temperature_method")) {
6,804✔
1232
    auto temp = get_node_value(root, "temperature_method", true, true);
393✔
1233
    if (temp == "nearest") {
393✔
1234
      temperature_method = TemperatureMethod::NEAREST;
246✔
1235
    } else if (temp == "interpolation") {
147!
1236
      temperature_method = TemperatureMethod::INTERPOLATION;
147✔
1237
    } else {
1238
      fatal_error("Unknown temperature method: " + temp);
×
1239
    }
1240
  }
393✔
1241
  if (check_for_node(root, "temperature_tolerance")) {
6,804✔
1242
    temperature_tolerance =
552✔
1243
      std::stod(get_node_value(root, "temperature_tolerance"));
552✔
1244
  }
1245
  if (check_for_node(root, "temperature_multipole")) {
6,804✔
1246
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
150✔
1247

1248
    // Multipole currently doesn't work with photon transport
1249
    if (temperature_multipole && photon_transport) {
150!
1250
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1251
                  "photon transport.");
1252
    }
1253
  }
1254
  if (check_for_node(root, "temperature_range")) {
6,804✔
1255
    auto range = get_node_array<double>(root, "temperature_range");
138✔
1256
    temperature_range[0] = range.at(0);
138✔
1257
    temperature_range[1] = range.at(1);
138✔
1258
  }
138✔
1259

1260
  // Check for tabular_legendre options
1261
  if (check_for_node(root, "tabular_legendre")) {
6,804✔
1262
    // Get pointer to tabular_legendre node
1263
    xml_node node_tab_leg = root.child("tabular_legendre");
72✔
1264

1265
    // Check for enable option
1266
    if (check_for_node(node_tab_leg, "enable")) {
72!
1267
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
72✔
1268
    }
1269

1270
    // Check for the number of points
1271
    if (check_for_node(node_tab_leg, "num_points")) {
72!
1272
      legendre_to_tabular_points =
×
1273
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
1274
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
1275
        fatal_error(
×
1276
          "The 'num_points' subelement/attribute of the "
1277
          "<tabular_legendre> element must contain a value greater than 1");
1278
      }
1279
    }
1280
  }
1281

1282
  // Check whether create delayed neutrons in fission
1283
  if (check_for_node(root, "create_delayed_neutrons")) {
6,804!
1284
    create_delayed_neutrons =
×
1285
      get_node_value_bool(root, "create_delayed_neutrons");
×
1286
  }
1287

1288
  // Check whether create fission sites
1289
  if (run_mode == RunMode::FIXED_SOURCE) {
6,804✔
1290
    if (check_for_node(root, "create_fission_neutrons")) {
2,320✔
1291
      create_fission_neutrons =
300✔
1292
        get_node_value_bool(root, "create_fission_neutrons");
300✔
1293
    }
1294
  }
1295

1296
  // Check whether to scale fission photon yields
1297
  if (check_for_node(root, "delayed_photon_scaling")) {
6,804!
1298
    delayed_photon_scaling =
×
1299
      get_node_value_bool(root, "delayed_photon_scaling");
×
1300
  }
1301

1302
  // Check whether to use event-based parallelism
1303
  if (check_for_node(root, "event_based")) {
6,804!
1304
    event_based = get_node_value_bool(root, "event_based");
×
1305
  }
1306

1307
  // Check whether material cell offsets should be generated
1308
  if (check_for_node(root, "material_cell_offsets")) {
6,804!
1309
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1310
  }
1311

1312
  // Weight window information
1313
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
6,886✔
1314
    variance_reduction::weight_windows.emplace_back(
82✔
1315
      std::make_unique<WeightWindows>(node_ww));
164✔
1316
  }
1317

1318
  // Enable weight windows by default if one or more are present
1319
  if (variance_reduction::weight_windows.size() > 0)
6,804✔
1320
    settings::weight_windows_on = true;
61✔
1321

1322
  // read weight windows from file
1323
  if (check_for_node(root, "weight_windows_file")) {
6,804!
1324
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1325
  }
1326

1327
  // read settings for weight windows value, this will override
1328
  // the automatic setting even if weight windows are present
1329
  if (check_for_node(root, "weight_windows_on")) {
6,804✔
1330
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
28✔
1331
  }
1332

1333
  if (check_for_node(root, "max_secondaries")) {
6,804!
1334
    settings::max_secondaries =
×
1335
      std::stoi(get_node_value(root, "max_secondaries"));
×
1336
  }
1337

1338
  if (check_for_node(root, "max_history_splits")) {
6,804✔
1339
    settings::max_history_splits =
348✔
1340
      std::stoi(get_node_value(root, "max_history_splits"));
348✔
1341
  }
1342

1343
  if (check_for_node(root, "max_tracks")) {
6,804✔
1344
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
72✔
1345
  }
1346

1347
  // Create weight window generator objects
1348
  if (check_for_node(root, "weight_window_generators")) {
6,804✔
1349
    if (kinetic_simulation) {
63!
NEW
1350
      fatal_error("Weight window generation is currently unsupported in kinetic"
×
1351
                  " random ray solver mode.");
1352
    }
1353
    auto wwgs_node = root.child("weight_window_generators");
63✔
1354
    for (pugi::xml_node node_wwg :
126✔
1355
      wwgs_node.children("weight_windows_generator")) {
126✔
1356
      variance_reduction::weight_windows_generators.emplace_back(
63✔
1357
        std::make_unique<WeightWindowsGenerator>(node_wwg));
126✔
1358
    }
1359
    // if any of the weight windows are intended to be generated otf, make
1360
    // sure they're applied
1361
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
63!
1362
      if (wwg->on_the_fly_) {
63!
1363
        settings::weight_windows_on = true;
63✔
1364
        break;
63✔
1365
      }
1366
    }
1367
  }
1368

1369
  // Set up weight window checkpoints
1370
  if (check_for_node(root, "weight_window_checkpoints")) {
6,804✔
1371
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
24✔
1372
    if (check_for_node(ww_checkpoints, "collision")) {
24!
1373
      weight_window_checkpoint_collision =
24✔
1374
        get_node_value_bool(ww_checkpoints, "collision");
24✔
1375
    }
1376
    if (check_for_node(ww_checkpoints, "surface")) {
24!
1377
      weight_window_checkpoint_surface =
24✔
1378
        get_node_value_bool(ww_checkpoints, "surface");
24✔
1379
    }
1380
  }
1381

1382
  if (weight_windows_on) {
6,804✔
1383
    if (!weight_window_checkpoint_surface &&
124✔
1384
        !weight_window_checkpoint_collision)
100!
1385
      fatal_error(
×
1386
        "Weight Windows are enabled but there are no valid checkpoints.");
1387
  }
1388

1389
  if (check_for_node(root, "use_decay_photons")) {
6,804✔
1390
    settings::use_decay_photons =
9✔
1391
      get_node_value_bool(root, "use_decay_photons");
9✔
1392
  }
1393
}
6,804✔
1394

1395
void free_memory_settings()
6,915✔
1396
{
1397
  settings::statepoint_batch.clear();
6,915✔
1398
  settings::sourcepoint_batch.clear();
6,915✔
1399
  settings::source_write_surf_id.clear();
6,915✔
1400
  settings::res_scat_nuclides.clear();
6,915✔
1401
}
6,915✔
1402

1403
//==============================================================================
1404
// C API functions
1405
//==============================================================================
1406

1407
extern "C" int openmc_set_n_batches(
36✔
1408
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1409
{
1410
  if (settings::n_inactive >= n_batches) {
36✔
1411
    set_errmsg("Number of active batches must be greater than zero.");
9✔
1412
    return OPENMC_E_INVALID_ARGUMENT;
9✔
1413
  }
1414

1415
  if (!settings::trigger_on) {
27✔
1416
    // Set n_batches and n_max_batches to same value
1417
    settings::n_batches = n_batches;
9✔
1418
    settings::n_max_batches = n_batches;
9✔
1419
  } else {
1420
    // Set n_batches and n_max_batches based on value of set_max_batches
1421
    if (set_max_batches) {
18✔
1422
      settings::n_max_batches = n_batches;
9✔
1423
    } else {
1424
      settings::n_batches = n_batches;
9✔
1425
    }
1426
  }
1427

1428
  // Update size of k_generation and entropy
1429
  int m = settings::n_max_batches * settings::gen_per_batch;
27✔
1430
  simulation::k_generation.reserve(m);
27✔
1431
  simulation::entropy.reserve(m);
27✔
1432

1433
  // Add value of n_batches to statepoint_batch
1434
  if (add_statepoint_batch &&
27✔
1435
      !(contains(settings::statepoint_batch, n_batches)))
18!
1436
    settings::statepoint_batch.insert(n_batches);
18✔
1437

1438
  return 0;
1439
}
1440

1441
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,070✔
1442
{
1443
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,070✔
1444

1445
  return 0;
2,070✔
1446
}
1447

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