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

openmc-dev / openmc / 15618759193

12 Jun 2025 06:59PM UTC coverage: 85.165% (+0.007%) from 85.158%
15618759193

Pull #3436

github

web-flow
Merge f2964f7dc into 6c9c69628
Pull Request #3436: Allowing chain_file to be chain object to save reloading time

18 of 22 new or added lines in 4 files covered. (81.82%)

374 existing lines in 7 files now uncovered.

52385 of 61510 relevant lines covered (85.17%)

36774825.05 hits per line

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

79.86
/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/constants.h"
15
#include "openmc/container_util.h"
16
#include "openmc/distribution.h"
17
#include "openmc/distribution_multi.h"
18
#include "openmc/distribution_spatial.h"
19
#include "openmc/eigenvalue.h"
20
#include "openmc/error.h"
21
#include "openmc/file_utils.h"
22
#include "openmc/mcpl_interface.h"
23
#include "openmc/mesh.h"
24
#include "openmc/message_passing.h"
25
#include "openmc/output.h"
26
#include "openmc/plot.h"
27
#include "openmc/random_lcg.h"
28
#include "openmc/random_ray/random_ray.h"
29
#include "openmc/simulation.h"
30
#include "openmc/source.h"
31
#include "openmc/string_utils.h"
32
#include "openmc/tallies/trigger.h"
33
#include "openmc/volume_calc.h"
34
#include "openmc/weight_windows.h"
35
#include "openmc/xml_interface.h"
36

37
namespace openmc {
38

39
//==============================================================================
40
// Global variables
41
//==============================================================================
42

43
namespace settings {
44

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

88
std::string path_cross_sections;
89
std::string path_input;
90
std::string path_output;
91
std::string path_particle_restart;
92
std::string path_sourcepoint;
93
std::string path_statepoint;
94
const char* path_statepoint_c {path_statepoint.c_str()};
95
std::string weight_windows_file;
96

97
int32_t n_inactive {0};
98
int32_t max_lost_particles {10};
99
double rel_max_lost_particles {1.0e-6};
100
int32_t max_write_lost_particles {-1};
101
int32_t gen_per_batch {1};
102
int64_t n_particles {-1};
103

104
int64_t max_particles_in_flight {100000};
105
int max_particle_events {1000000};
106

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

146
} // namespace settings
147

148
//==============================================================================
149
// Functions
150
//==============================================================================
151

152
void get_run_parameters(pugi::xml_node node_base)
6,240✔
153
{
154
  using namespace settings;
155
  using namespace pugi;
156

157
  // Check number of particles
158
  if (!check_for_node(node_base, "particles")) {
6,240✔
UNCOV
159
    fatal_error("Need to specify number of particles.");
×
160
  }
161

162
  // Get number of particles if it wasn't specified as a command-line argument
163
  if (n_particles == -1) {
6,240✔
164
    n_particles = std::stoll(get_node_value(node_base, "particles"));
6,240✔
165
  }
166

167
  // Get maximum number of in flight particles for event-based mode
168
  if (check_for_node(node_base, "max_particles_in_flight")) {
6,240✔
169
    max_particles_in_flight =
×
UNCOV
170
      std::stoll(get_node_value(node_base, "max_particles_in_flight"));
×
171
  }
172

173
  // Get maximum number of events allowed per particle
174
  if (check_for_node(node_base, "max_particle_events")) {
6,240✔
175
    max_particle_events =
×
UNCOV
176
      std::stoll(get_node_value(node_base, "max_particle_events"));
×
177
  }
178

179
  // Get number of basic batches
180
  if (check_for_node(node_base, "batches")) {
6,240✔
181
    n_batches = std::stoi(get_node_value(node_base, "batches"));
6,240✔
182
  }
183
  if (!trigger_on)
6,240✔
184
    n_max_batches = n_batches;
6,094✔
185

186
  // Get max number of lost particles
187
  if (check_for_node(node_base, "max_lost_particles")) {
6,240✔
188
    max_lost_particles =
16✔
189
      std::stoi(get_node_value(node_base, "max_lost_particles"));
16✔
190
  }
191

192
  // Get relative number of lost particles
193
  if (check_for_node(node_base, "rel_max_lost_particles")) {
6,240✔
194
    rel_max_lost_particles =
×
UNCOV
195
      std::stod(get_node_value(node_base, "rel_max_lost_particles"));
×
196
  }
197

198
  // Get relative number of lost particles
199
  if (check_for_node(node_base, "max_write_lost_particles")) {
6,240✔
200
    max_write_lost_particles =
16✔
201
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
16✔
202
  }
203

204
  // Get number of inactive batches
205
  if (run_mode == RunMode::EIGENVALUE ||
6,240✔
206
      solver_type == SolverType::RANDOM_RAY) {
2,349✔
207
    if (check_for_node(node_base, "inactive")) {
4,275✔
208
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,189✔
209
    }
210
    if (check_for_node(node_base, "generations_per_batch")) {
4,275✔
211
      gen_per_batch =
16✔
212
        std::stoi(get_node_value(node_base, "generations_per_batch"));
16✔
213
    }
214

215
    // Preallocate space for keff and entropy by generation
216
    int m = settings::n_max_batches * settings::gen_per_batch;
4,275✔
217
    simulation::k_generation.reserve(m);
4,275✔
218
    simulation::entropy.reserve(m);
4,275✔
219

220
    // Get the trigger information for keff
221
    if (check_for_node(node_base, "keff_trigger")) {
4,275✔
222
      xml_node node_keff_trigger = node_base.child("keff_trigger");
107✔
223

224
      if (check_for_node(node_keff_trigger, "type")) {
107✔
225
        auto temp = get_node_value(node_keff_trigger, "type", true, true);
107✔
226
        if (temp == "std_dev") {
107✔
227
          keff_trigger.metric = TriggerMetric::standard_deviation;
107✔
228
        } else if (temp == "variance") {
×
229
          keff_trigger.metric = TriggerMetric::variance;
×
230
        } else if (temp == "rel_err") {
×
UNCOV
231
          keff_trigger.metric = TriggerMetric::relative_error;
×
232
        } else {
UNCOV
233
          fatal_error("Unrecognized keff trigger type " + temp);
×
234
        }
235
      } else {
107✔
UNCOV
236
        fatal_error("Specify keff trigger type in settings XML");
×
237
      }
238

239
      if (check_for_node(node_keff_trigger, "threshold")) {
107✔
240
        keff_trigger.threshold =
107✔
241
          std::stod(get_node_value(node_keff_trigger, "threshold"));
107✔
242
        if (keff_trigger.threshold <= 0) {
107✔
UNCOV
243
          fatal_error("keff trigger threshold must be positive");
×
244
        }
245
      } else {
UNCOV
246
        fatal_error("Specify keff trigger threshold in settings XML");
×
247
      }
248
    }
249
  }
250

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

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

383
  // Parse settings.xml file
384
  xml_document doc;
1,359✔
385
  auto result = doc.load_file(filename.c_str());
1,359✔
386
  if (!result) {
1,359✔
UNCOV
387
    fatal_error("Error processing settings.xml file.");
×
388
  }
389

390
  // Get root element
391
  xml_node root = doc.document_element();
1,359✔
392

393
  // Verbosity
394
  if (check_for_node(root, "verbosity")) {
1,359✔
395
    verbosity = std::stoi(get_node_value(root, "verbosity"));
189✔
396
  }
397

398
  // To this point, we haven't displayed any output since we didn't know what
399
  // the verbosity is. Now that we checked for it, show the title if necessary
400
  if (mpi::master) {
1,359✔
401
    if (verbosity >= 2)
1,129✔
402
      title();
950✔
403
  }
404

405
  write_message("Reading settings XML file...", 5);
1,359✔
406

407
  read_settings_xml(root);
1,359✔
408
}
1,371✔
409

410
void read_settings_xml(pugi::xml_node root)
6,771✔
411
{
412
  using namespace settings;
413
  using namespace pugi;
414

415
  // Find if a multi-group or continuous-energy simulation is desired
416
  if (check_for_node(root, "energy_mode")) {
6,771✔
417
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
1,094✔
418
    if (temp_str == "mg" || temp_str == "multi-group") {
1,094✔
419
      run_CE = false;
1,094✔
420
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
UNCOV
421
      run_CE = true;
×
422
    }
423
  }
1,094✔
424

425
  // Check for user meshes and allocate
426
  read_meshes(root);
6,771✔
427

428
  // Look for deprecated cross_sections.xml file in settings.xml
429
  if (check_for_node(root, "cross_sections")) {
6,771✔
UNCOV
430
    warning(
×
431
      "Setting cross_sections in settings.xml has been deprecated."
432
      " The cross_sections are now set in materials.xml and the "
433
      "cross_sections input to materials.xml and the OPENMC_CROSS_SECTIONS"
434
      " environment variable will take precendent over setting "
435
      "cross_sections in settings.xml.");
UNCOV
436
    path_cross_sections = get_node_value(root, "cross_sections");
×
437
  }
438

439
  if (!run_CE) {
6,771✔
440
    // Scattering Treatments
441
    if (check_for_node(root, "max_order")) {
1,094✔
442
      max_order = std::stoi(get_node_value(root, "max_order"));
16✔
443
    } else {
444
      // Set to default of largest int - 1, which means to use whatever is
445
      // contained in library. This is largest int - 1 because for legendre
446
      // scattering, a value of 1 is added to the order; adding 1 to the largest
447
      // int gets you the largest negative integer, which is not what we want.
448
      max_order = std::numeric_limits<int>::max() - 1;
1,078✔
449
    }
450
  }
451

452
  // Check for a trigger node and get trigger information
453
  if (check_for_node(root, "trigger")) {
6,771✔
454
    xml_node node_trigger = root.child("trigger");
162✔
455

456
    // Check if trigger(s) are to be turned on
457
    trigger_on = get_node_value_bool(node_trigger, "active");
162✔
458

459
    if (trigger_on) {
162✔
460
      if (check_for_node(node_trigger, "max_batches")) {
146✔
461
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
146✔
462
      } else {
UNCOV
463
        fatal_error("<max_batches> must be specified with triggers");
×
464
      }
465

466
      // Get the batch interval to check triggers
467
      if (!check_for_node(node_trigger, "batch_interval")) {
146✔
468
        trigger_predict = true;
16✔
469
      } else {
470
        trigger_batch_interval =
130✔
471
          std::stoi(get_node_value(node_trigger, "batch_interval"));
130✔
472
        if (trigger_batch_interval <= 0) {
130✔
UNCOV
473
          fatal_error("Trigger batch interval must be greater than zero");
×
474
        }
475
      }
476
    }
477
  }
478

479
  // Check run mode if it hasn't been set from the command line
480
  xml_node node_mode;
6,771✔
481
  if (run_mode == RunMode::UNSET) {
6,771✔
482
    if (check_for_node(root, "run_mode")) {
6,272✔
483
      std::string temp_str = get_node_value(root, "run_mode", true, true);
6,208✔
484
      if (temp_str == "eigenvalue") {
6,208✔
485
        run_mode = RunMode::EIGENVALUE;
3,827✔
486
      } else if (temp_str == "fixed source") {
2,381✔
487
        run_mode = RunMode::FIXED_SOURCE;
2,349✔
488
      } else if (temp_str == "plot") {
32✔
UNCOV
489
        run_mode = RunMode::PLOTTING;
×
490
      } else if (temp_str == "particle restart") {
32✔
UNCOV
491
        run_mode = RunMode::PARTICLE;
×
492
      } else if (temp_str == "volume") {
32✔
493
        run_mode = RunMode::VOLUME;
32✔
494
      } else {
UNCOV
495
        fatal_error("Unrecognized run mode: " + temp_str);
×
496
      }
497

498
      // Assume XML specifies <particles>, <batches>, etc. directly
499
      node_mode = root;
6,208✔
500
    } else {
6,208✔
501
      warning("<run_mode> should be specified.");
64✔
502

503
      // Make sure that either eigenvalue or fixed source was specified
504
      node_mode = root.child("eigenvalue");
64✔
505
      if (node_mode) {
64✔
506
        run_mode = RunMode::EIGENVALUE;
64✔
507
      } else {
508
        node_mode = root.child("fixed_source");
×
509
        if (node_mode) {
×
UNCOV
510
          run_mode = RunMode::FIXED_SOURCE;
×
511
        } else {
UNCOV
512
          fatal_error("<eigenvalue> or <fixed_source> not specified.");
×
513
        }
514
      }
515
    }
516
  }
517

518
  // Check solver type
519
  if (check_for_node(root, "random_ray")) {
6,771✔
520
    solver_type = SolverType::RANDOM_RAY;
560✔
521
    if (run_CE)
560✔
UNCOV
522
      fatal_error("multi-group energy mode must be specified in settings XML "
×
523
                  "when using the random ray solver.");
524
  }
525

526
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
6,771✔
527
    // Read run parameters
528
    get_run_parameters(node_mode);
6,240✔
529

530
    // Check number of active batches, inactive batches, max lost particles and
531
    // particles
532
    if (n_batches <= n_inactive) {
6,240✔
UNCOV
533
      fatal_error("Number of active batches must be greater than zero.");
×
534
    } else if (n_inactive < 0) {
6,240✔
UNCOV
535
      fatal_error("Number of inactive batches must be non-negative.");
×
536
    } else if (n_particles <= 0) {
6,240✔
UNCOV
537
      fatal_error("Number of particles must be greater than zero.");
×
538
    } else if (max_lost_particles <= 0) {
6,240✔
UNCOV
539
      fatal_error("Number of max lost particles must be greater than zero.");
×
540
    } else if (rel_max_lost_particles <= 0.0 || rel_max_lost_particles >= 1.0) {
6,240✔
UNCOV
541
      fatal_error("Relative max lost particles must be between zero and one.");
×
542
    }
543
  }
544

545
  // Copy plotting random number seed if specified
546
  if (check_for_node(root, "plot_seed")) {
6,771✔
547
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
UNCOV
548
    model::plotter_seed = seed;
×
549
  }
550

551
  // Copy random number seed if specified
552
  if (check_for_node(root, "seed")) {
6,771✔
553
    auto seed = std::stoll(get_node_value(root, "seed"));
518✔
554
    openmc_set_seed(seed);
518✔
555
  }
556

557
  // Copy random number stride if specified
558
  if (check_for_node(root, "stride")) {
6,771✔
559
    auto stride = std::stoull(get_node_value(root, "stride"));
16✔
560
    openmc_set_stride(stride);
16✔
561
  }
562

563
  // Check for electron treatment
564
  if (check_for_node(root, "electron_treatment")) {
6,771✔
565
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
70✔
566
    if (temp_str == "led") {
70✔
567
      electron_treatment = ElectronTreatment::LED;
11✔
568
    } else if (temp_str == "ttb") {
59✔
569
      electron_treatment = ElectronTreatment::TTB;
59✔
570
    } else {
UNCOV
571
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
572
    }
573
  }
70✔
574

575
  // Check for photon transport
576
  if (check_for_node(root, "photon_transport")) {
6,771✔
577
    photon_transport = get_node_value_bool(root, "photon_transport");
199✔
578

579
    if (!run_CE && photon_transport) {
199✔
UNCOV
580
      fatal_error("Photon transport is not currently supported in "
×
581
                  "multigroup mode");
582
    }
583
  }
584

585
  // Number of bins for logarithmic grid
586
  if (check_for_node(root, "log_grid_bins")) {
6,771✔
587
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
16✔
588
    if (n_log_bins < 1) {
16✔
UNCOV
589
      fatal_error("Number of bins for logarithmic grid must be greater "
×
590
                  "than zero.");
591
    }
592
  }
593

594
  // Number of OpenMP threads
595
  if (check_for_node(root, "threads")) {
6,771✔
596
    if (mpi::master)
×
UNCOV
597
      warning("The <threads> element has been deprecated. Use "
×
598
              "the OMP_NUM_THREADS environment variable to set the number of "
599
              "threads.");
600
  }
601

602
  // ==========================================================================
603
  // EXTERNAL SOURCE
604

605
  // Get point to list of <source> elements and make sure there is at least one
606
  for (pugi::xml_node node : root.children("source")) {
13,220✔
607
    model::external_sources.push_back(Source::create(node));
6,459✔
608
  }
609

610
  // Check if the user has specified to read surface source
611
  if (check_for_node(root, "surf_source_read")) {
6,761✔
612
    surf_source_read = true;
16✔
613
    // Get surface source read node
614
    xml_node node_ssr = root.child("surf_source_read");
16✔
615

616
    std::string path = "surface_source.h5";
16✔
617
    // Check if the user has specified different file for surface source reading
618
    if (check_for_node(node_ssr, "path")) {
16✔
619
      path = get_node_value(node_ssr, "path", false, true);
16✔
620
    }
621
    model::external_sources.push_back(make_unique<FileSource>(path));
16✔
622
  }
16✔
623

624
  // If no source specified, default to isotropic point source at origin with
625
  // Watt spectrum. No default source is needed in random ray mode.
626
  if (model::external_sources.empty() &&
8,511✔
627
      settings::solver_type != SolverType::RANDOM_RAY) {
1,750✔
628
    double T[] {0.0};
1,638✔
629
    double p[] {1.0};
1,638✔
630
    model::external_sources.push_back(make_unique<IndependentSource>(
1,638✔
631
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
3,276✔
632
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
3,276✔
633
      UPtrDist {new Discrete(T, p, 1)}));
3,276✔
634
  }
635

636
  // Build probability mass function for sampling external sources
637
  vector<double> source_strengths;
6,761✔
638
  for (auto& s : model::external_sources) {
14,864✔
639
    source_strengths.push_back(s->strength());
8,103✔
640
  }
641
  model::external_sources_probability.assign(source_strengths);
6,761✔
642

643
  // Check if we want to write out source
644
  if (check_for_node(root, "write_initial_source")) {
6,761✔
UNCOV
645
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
646
  }
647

648
  // Get relative number of lost particles
649
  if (check_for_node(root, "source_rejection_fraction")) {
6,761✔
650
    source_rejection_fraction =
6✔
651
      std::stod(get_node_value(root, "source_rejection_fraction"));
6✔
652
  }
653

654
  // Survival biasing
655
  if (check_for_node(root, "survival_biasing")) {
6,761✔
656
    survival_biasing = get_node_value_bool(root, "survival_biasing");
175✔
657
  }
658

659
  // Probability tables
660
  if (check_for_node(root, "ptables")) {
6,761✔
661
    urr_ptables_on = get_node_value_bool(root, "ptables");
16✔
662
  }
663

664
  // Cutoffs
665
  if (check_for_node(root, "cutoff")) {
6,761✔
666
    xml_node node_cutoff = root.child("cutoff");
118✔
667
    if (check_for_node(node_cutoff, "weight")) {
118✔
668
      weight_cutoff = std::stod(get_node_value(node_cutoff, "weight"));
16✔
669
    }
670
    if (check_for_node(node_cutoff, "weight_avg")) {
118✔
671
      weight_survive = std::stod(get_node_value(node_cutoff, "weight_avg"));
16✔
672
    }
673
    if (check_for_node(node_cutoff, "survival_normalization")) {
118✔
674
      survival_normalization =
×
UNCOV
675
        get_node_value_bool(node_cutoff, "survival_normalization");
×
676
    }
677
    if (check_for_node(node_cutoff, "energy_neutron")) {
118✔
678
      energy_cutoff[0] =
32✔
679
        std::stod(get_node_value(node_cutoff, "energy_neutron"));
16✔
680
    } else if (check_for_node(node_cutoff, "energy")) {
102✔
UNCOV
681
      warning("The use of an <energy> cutoff is deprecated and should "
×
682
              "be replaced by <energy_neutron>.");
683
      energy_cutoff[0] = std::stod(get_node_value(node_cutoff, "energy"));
×
684
    }
685
    if (check_for_node(node_cutoff, "energy_photon")) {
118✔
686
      energy_cutoff[1] =
140✔
687
        std::stod(get_node_value(node_cutoff, "energy_photon"));
70✔
688
    }
689
    if (check_for_node(node_cutoff, "energy_electron")) {
118✔
UNCOV
690
      energy_cutoff[2] =
×
UNCOV
691
        std::stof(get_node_value(node_cutoff, "energy_electron"));
×
692
    }
693
    if (check_for_node(node_cutoff, "energy_positron")) {
118✔
694
      energy_cutoff[3] =
×
UNCOV
695
        std::stod(get_node_value(node_cutoff, "energy_positron"));
×
696
    }
697
    if (check_for_node(node_cutoff, "time_neutron")) {
118✔
698
      time_cutoff[0] = std::stod(get_node_value(node_cutoff, "time_neutron"));
16✔
699
    }
700
    if (check_for_node(node_cutoff, "time_photon")) {
118✔
UNCOV
701
      time_cutoff[1] = std::stod(get_node_value(node_cutoff, "time_photon"));
×
702
    }
703
    if (check_for_node(node_cutoff, "time_electron")) {
118✔
UNCOV
704
      time_cutoff[2] = std::stod(get_node_value(node_cutoff, "time_electron"));
×
705
    }
706
    if (check_for_node(node_cutoff, "time_positron")) {
118✔
UNCOV
707
      time_cutoff[3] = std::stod(get_node_value(node_cutoff, "time_positron"));
×
708
    }
709
  }
710

711
  // Particle trace
712
  if (check_for_node(root, "trace")) {
6,761✔
713
    auto temp = get_node_array<int64_t>(root, "trace");
16✔
714
    if (temp.size() != 3) {
16✔
UNCOV
715
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
716
                  "batch, generation, and particle number.");
717
    }
718
    trace_batch = temp.at(0);
16✔
719
    trace_gen = temp.at(1);
16✔
720
    trace_particle = temp.at(2);
16✔
721
  }
16✔
722

723
  // Particle tracks
724
  if (check_for_node(root, "track")) {
6,761✔
725
    // Get values and make sure there are three per particle
726
    auto temp = get_node_array<int>(root, "track");
48✔
727
    if (temp.size() % 3 != 0) {
48✔
UNCOV
728
      fatal_error(
×
729
        "Number of integers specified in 'track' is not "
730
        "divisible by 3.  Please provide 3 integers per particle to be "
731
        "tracked.");
732
    }
733

734
    // Reshape into track_identifiers
735
    int n_tracks = temp.size() / 3;
48✔
736
    for (int i = 0; i < n_tracks; ++i) {
192✔
737
      track_identifiers.push_back(
144✔
738
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
144✔
739
    }
740
  }
48✔
741

742
  // Shannon entropy
743
  if (solver_type == SolverType::RANDOM_RAY) {
6,761✔
744
    if (check_for_node(root, "entropy_mesh")) {
560✔
UNCOV
745
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
746
                  "No user-defined entropy mesh is supported.");
747
    }
748
    entropy_on = true;
560✔
749
  } else if (solver_type == SolverType::MONTE_CARLO) {
6,201✔
750
    if (check_for_node(root, "entropy_mesh")) {
6,201✔
751
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
365✔
752
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
365✔
753
        fatal_error(fmt::format(
×
754
          "Mesh {} specified for Shannon entropy does not exist.", temp));
755
      }
756

757
      auto* m = dynamic_cast<RegularMesh*>(
365✔
758
        model::meshes[model::mesh_map.at(temp)].get());
365✔
759
      if (!m)
365✔
760
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
761
      simulation::entropy_mesh = m;
365✔
762

763
      // Turn on Shannon entropy calculation
764
      entropy_on = true;
365✔
765

766
    } else if (check_for_node(root, "entropy")) {
5,836✔
UNCOV
767
      fatal_error(
×
768
        "Specifying a Shannon entropy mesh via the <entropy> element "
769
        "is deprecated. Please create a mesh using <mesh> and then reference "
770
        "it by specifying its ID in an <entropy_mesh> element.");
771
    }
772
  }
773
  // Uniform fission source weighting mesh
774
  if (check_for_node(root, "ufs_mesh")) {
6,761✔
775
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
16✔
776
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
16✔
UNCOV
777
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
778
                              "method does not exist.",
779
        temp));
780
    }
781

782
    auto* m =
783
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
16✔
784
    if (!m)
16✔
785
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
786
    simulation::ufs_mesh = m;
16✔
787

788
    // Turn on uniform fission source weighting
789
    ufs_on = true;
16✔
790

791
  } else if (check_for_node(root, "uniform_fs")) {
6,745✔
UNCOV
792
    fatal_error(
×
793
      "Specifying a UFS mesh via the <uniform_fs> element "
794
      "is deprecated. Please create a mesh using <mesh> and then reference "
795
      "it by specifying its ID in a <ufs_mesh> element.");
796
  }
797

798
  // Check if the user has specified to write state points
799
  if (check_for_node(root, "state_point")) {
6,761✔
800

801
    // Get pointer to state_point node
802
    auto node_sp = root.child("state_point");
176✔
803

804
    // Determine number of batches at which to store state points
805
    if (check_for_node(node_sp, "batches")) {
176✔
806
      // User gave specific batches to write state points
807
      auto temp = get_node_array<int>(node_sp, "batches");
176✔
808
      for (const auto& b : temp) {
544✔
809
        statepoint_batch.insert(b);
368✔
810
      }
811
    } else {
176✔
812
      // If neither were specified, write state point at last batch
UNCOV
813
      statepoint_batch.insert(n_batches);
×
814
    }
815
  } else {
816
    // If no <state_point> tag was present, by default write state point at
817
    // last batch only
818
    statepoint_batch.insert(n_batches);
6,585✔
819
  }
820

821
  // Check if the user has specified to write source points
822
  if (check_for_node(root, "source_point")) {
6,761✔
823
    // Get source_point node
824
    xml_node node_sp = root.child("source_point");
96✔
825

826
    // Determine batches at which to store source points
827
    if (check_for_node(node_sp, "batches")) {
96✔
828
      // User gave specific batches to write source points
829
      auto temp = get_node_array<int>(node_sp, "batches");
48✔
830
      for (const auto& b : temp) {
128✔
831
        sourcepoint_batch.insert(b);
80✔
832
      }
833
    } else {
48✔
834
      // If neither were specified, write source points with state points
835
      sourcepoint_batch = statepoint_batch;
48✔
836
    }
837

838
    // Check if the user has specified to write binary source file
839
    if (check_for_node(node_sp, "separate")) {
96✔
840
      source_separate = get_node_value_bool(node_sp, "separate");
64✔
841
    }
842
    if (check_for_node(node_sp, "write")) {
96✔
843
      source_write = get_node_value_bool(node_sp, "write");
×
844
    }
845
    if (check_for_node(node_sp, "mcpl")) {
96✔
846
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
16✔
847

848
      // Make sure MCPL support is enabled
849
      if (source_mcpl_write && !MCPL_ENABLED) {
16✔
UNCOV
850
        fatal_error(
×
851
          "Your build of OpenMC does not support writing MCPL source files.");
852
      }
853
    }
854
    if (check_for_node(node_sp, "overwrite_latest")) {
96✔
855
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
16✔
856
      source_separate = source_latest;
16✔
857
    }
858
  } else {
859
    // If no <source_point> tag was present, by default we keep source bank in
860
    // statepoint file and write it out at statepoints intervals
861
    source_separate = false;
6,665✔
862
    sourcepoint_batch = statepoint_batch;
6,665✔
863
  }
864

865
  // Check is the user specified to convert strength to statistical weight
866
  if (check_for_node(root, "uniform_source_sampling")) {
6,761✔
867
    uniform_source_sampling =
55✔
868
      get_node_value_bool(root, "uniform_source_sampling");
55✔
869
  }
870

871
  // Check if the user has specified to write surface source
872
  if (check_for_node(root, "surf_source_write")) {
6,761✔
873
    surf_source_write = true;
401✔
874
    // Get surface source write node
875
    xml_node node_ssw = root.child("surf_source_write");
401✔
876

877
    // Determine surface ids at which crossing particles are to be banked.
878
    // If no surfaces are specified, all surfaces in the model will be used
879
    // to bank source points.
880
    if (check_for_node(node_ssw, "surface_ids")) {
401✔
881
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
191✔
882
      for (const auto& b : temp) {
972✔
883
        source_write_surf_id.insert(b);
781✔
884
      }
885
    }
191✔
886

887
    // Get maximum number of particles to be banked per surface
888
    if (check_for_node(node_ssw, "max_particles")) {
401✔
889
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
392✔
890
    } else {
891
      fatal_error("A maximum number of particles needs to be specified "
9✔
892
                  "using the 'max_particles' parameter to store surface "
893
                  "source points.");
894
    }
895

896
    // Get maximum number of surface source files to be created
897
    if (check_for_node(node_ssw, "max_source_files")) {
392✔
898
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
33✔
899
    } else {
900
      ssw_max_files = 1;
359✔
901
    }
902

903
    if (check_for_node(node_ssw, "mcpl")) {
392✔
UNCOV
904
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
×
905

906
      // Make sure MCPL support is enabled
UNCOV
907
      if (surf_mcpl_write && !MCPL_ENABLED) {
×
UNCOV
908
        fatal_error("Your build of OpenMC does not support writing MCPL "
×
909
                    "surface source files.");
910
      }
911
    }
912
    // Get cell information
913
    if (check_for_node(node_ssw, "cell")) {
392✔
914
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
104✔
915
      ssw_cell_type = SSWCellType::Both;
104✔
916
    }
917
    if (check_for_node(node_ssw, "cellfrom")) {
392✔
918
      if (ssw_cell_id != C_NONE) {
90✔
919
        fatal_error(
18✔
920
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
921
      }
922
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
72✔
923
      ssw_cell_type = SSWCellType::From;
72✔
924
    }
925
    if (check_for_node(node_ssw, "cellto")) {
374✔
926
      if (ssw_cell_id != C_NONE) {
71✔
927
        fatal_error(
18✔
928
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
929
      }
930
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
53✔
931
      ssw_cell_type = SSWCellType::To;
53✔
932
    }
933
  }
934

935
  // If source is not separate and is to be written out in the statepoint file,
936
  // make sure that the sourcepoint batch numbers are contained in the
937
  // statepoint list
938
  if (!source_separate) {
6,716✔
939
    for (const auto& b : sourcepoint_batch) {
13,416✔
940
      if (!contains(statepoint_batch, b)) {
6,780✔
UNCOV
941
        fatal_error(
×
942
          "Sourcepoint batches are not a subset of statepoint batches.");
943
      }
944
    }
945
  }
946

947
  // Check if the user has specified to not reduce tallies at the end of every
948
  // batch
949
  if (check_for_node(root, "no_reduce")) {
6,716✔
UNCOV
950
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
×
951
  }
952

953
  // Check if the user has specified to use confidence intervals for
954
  // uncertainties rather than standard deviations
955
  if (check_for_node(root, "confidence_intervals")) {
6,716✔
956
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
16✔
957
  }
958

959
  // Check for output options
960
  if (check_for_node(root, "output")) {
6,716✔
961
    // Get pointer to output node
962
    pugi::xml_node node_output = root.child("output");
438✔
963

964
    // Check for summary option
965
    if (check_for_node(node_output, "summary")) {
438✔
966
      output_summary = get_node_value_bool(node_output, "summary");
422✔
967
    }
968

969
    // Check for ASCII tallies output option
970
    if (check_for_node(node_output, "tallies")) {
438✔
971
      output_tallies = get_node_value_bool(node_output, "tallies");
82✔
972
    }
973

974
    // Set output directory if a path has been specified
975
    if (check_for_node(node_output, "path")) {
438✔
UNCOV
976
      path_output = get_node_value(node_output, "path");
×
UNCOV
977
      if (!ends_with(path_output, "/")) {
×
UNCOV
978
        path_output += "/";
×
979
      }
980
    }
981
  }
982

983
  // Resonance scattering parameters
984
  if (check_for_node(root, "resonance_scattering")) {
6,716✔
985
    xml_node node_res_scat = root.child("resonance_scattering");
16✔
986

987
    // See if resonance scattering is enabled
988
    if (check_for_node(node_res_scat, "enable")) {
16✔
989
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
16✔
990
    } else {
UNCOV
991
      res_scat_on = true;
×
992
    }
993

994
    // Determine what method is used
995
    if (check_for_node(node_res_scat, "method")) {
16✔
996
      auto temp = get_node_value(node_res_scat, "method", true, true);
16✔
997
      if (temp == "rvs") {
16✔
998
        res_scat_method = ResScatMethod::rvs;
16✔
UNCOV
999
      } else if (temp == "dbrc") {
×
UNCOV
1000
        res_scat_method = ResScatMethod::dbrc;
×
1001
      } else {
UNCOV
1002
        fatal_error(
×
UNCOV
1003
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1004
      }
1005
    }
16✔
1006

1007
    // Minimum energy for resonance scattering
1008
    if (check_for_node(node_res_scat, "energy_min")) {
16✔
1009
      res_scat_energy_min =
16✔
1010
        std::stod(get_node_value(node_res_scat, "energy_min"));
16✔
1011
    }
1012
    if (res_scat_energy_min < 0.0) {
16✔
UNCOV
1013
      fatal_error("Lower resonance scattering energy bound is negative");
×
1014
    }
1015

1016
    // Maximum energy for resonance scattering
1017
    if (check_for_node(node_res_scat, "energy_max")) {
16✔
1018
      res_scat_energy_max =
16✔
1019
        std::stod(get_node_value(node_res_scat, "energy_max"));
16✔
1020
    }
1021
    if (res_scat_energy_max < res_scat_energy_min) {
16✔
UNCOV
1022
      fatal_error("Upper resonance scattering energy bound is below the "
×
1023
                  "lower resonance scattering energy bound.");
1024
    }
1025

1026
    // Get resonance scattering nuclides
1027
    if (check_for_node(node_res_scat, "nuclides")) {
16✔
1028
      res_scat_nuclides =
1029
        get_node_array<std::string>(node_res_scat, "nuclides");
16✔
1030
    }
1031
  }
1032

1033
  // Get volume calculations
1034
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
7,042✔
1035
    model::volume_calcs.emplace_back(node_vol);
326✔
1036
  }
1037

1038
  // Get temperature settings
1039
  if (check_for_node(root, "temperature_default")) {
6,716✔
1040
    temperature_default =
172✔
1041
      std::stod(get_node_value(root, "temperature_default"));
172✔
1042
  }
1043
  if (check_for_node(root, "temperature_method")) {
6,716✔
1044
    auto temp = get_node_value(root, "temperature_method", true, true);
325✔
1045
    if (temp == "nearest") {
325✔
1046
      temperature_method = TemperatureMethod::NEAREST;
140✔
1047
    } else if (temp == "interpolation") {
185✔
1048
      temperature_method = TemperatureMethod::INTERPOLATION;
185✔
1049
    } else {
UNCOV
1050
      fatal_error("Unknown temperature method: " + temp);
×
1051
    }
1052
  }
325✔
1053
  if (check_for_node(root, "temperature_tolerance")) {
6,716✔
1054
    temperature_tolerance =
171✔
1055
      std::stod(get_node_value(root, "temperature_tolerance"));
171✔
1056
  }
1057
  if (check_for_node(root, "temperature_multipole")) {
6,716✔
1058
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
32✔
1059

1060
    // Multipole currently doesn't work with photon transport
1061
    if (temperature_multipole && photon_transport) {
32✔
1062
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1063
                  "photon transport.");
1064
    }
1065
  }
1066
  if (check_for_node(root, "temperature_range")) {
6,716✔
UNCOV
1067
    auto range = get_node_array<double>(root, "temperature_range");
×
UNCOV
1068
    temperature_range[0] = range.at(0);
×
UNCOV
1069
    temperature_range[1] = range.at(1);
×
1070
  }
1071

1072
  // Check for user value for the number of generation of the Iterated Fission
1073
  // Probability (IFP) method
1074
  if (check_for_node(root, "ifp_n_generation")) {
6,716✔
1075
    ifp_n_generation = std::stoi(get_node_value(root, "ifp_n_generation"));
25✔
1076
    if (ifp_n_generation <= 0) {
25✔
UNCOV
1077
      fatal_error("'ifp_n_generation' must be greater than 0.");
×
1078
    }
1079
    // Avoid tallying 0 if IFP logs are not complete when active cycles start
1080
    if (ifp_n_generation > n_inactive) {
25✔
1081
      fatal_error("'ifp_n_generation' must be lower than or equal to the "
9✔
1082
                  "number of inactive cycles.");
1083
    }
1084
  }
1085

1086
  // Check for tabular_legendre options
1087
  if (check_for_node(root, "tabular_legendre")) {
6,707✔
1088
    // Get pointer to tabular_legendre node
1089
    xml_node node_tab_leg = root.child("tabular_legendre");
96✔
1090

1091
    // Check for enable option
1092
    if (check_for_node(node_tab_leg, "enable")) {
96✔
1093
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
96✔
1094
    }
1095

1096
    // Check for the number of points
1097
    if (check_for_node(node_tab_leg, "num_points")) {
96✔
UNCOV
1098
      legendre_to_tabular_points =
×
UNCOV
1099
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
UNCOV
1100
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
UNCOV
1101
        fatal_error(
×
1102
          "The 'num_points' subelement/attribute of the "
1103
          "<tabular_legendre> element must contain a value greater than 1");
1104
      }
1105
    }
1106
  }
1107

1108
  // Check whether create delayed neutrons in fission
1109
  if (check_for_node(root, "create_delayed_neutrons")) {
6,707✔
UNCOV
1110
    create_delayed_neutrons =
×
UNCOV
1111
      get_node_value_bool(root, "create_delayed_neutrons");
×
1112
  }
1113

1114
  // Check whether create fission sites
1115
  if (run_mode == RunMode::FIXED_SOURCE) {
6,707✔
1116
    if (check_for_node(root, "create_fission_neutrons")) {
2,303✔
1117
      create_fission_neutrons =
16✔
1118
        get_node_value_bool(root, "create_fission_neutrons");
16✔
1119
    }
1120
  }
1121

1122
  // Check whether to scale fission photon yields
1123
  if (check_for_node(root, "delayed_photon_scaling")) {
6,707✔
UNCOV
1124
    delayed_photon_scaling =
×
UNCOV
1125
      get_node_value_bool(root, "delayed_photon_scaling");
×
1126
  }
1127

1128
  // Check whether to use event-based parallelism
1129
  if (check_for_node(root, "event_based")) {
6,707✔
UNCOV
1130
    event_based = get_node_value_bool(root, "event_based");
×
1131
  }
1132

1133
  // Check whether material cell offsets should be generated
1134
  if (check_for_node(root, "material_cell_offsets")) {
6,707✔
UNCOV
1135
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1136
  }
1137

1138
  // Weight window information
1139
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
6,786✔
1140
    variance_reduction::weight_windows.emplace_back(
79✔
1141
      std::make_unique<WeightWindows>(node_ww));
158✔
1142
  }
1143

1144
  // Enable weight windows by default if one or more are present
1145
  if (variance_reduction::weight_windows.size() > 0)
6,707✔
1146
    settings::weight_windows_on = true;
52✔
1147

1148
  // read weight windows from file
1149
  if (check_for_node(root, "weight_windows_file")) {
6,707✔
UNCOV
1150
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1151
  }
1152

1153
  // read settings for weight windows value, this will override
1154
  // the automatic setting even if weight windows are present
1155
  if (check_for_node(root, "weight_windows_on")) {
6,707✔
1156
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
36✔
1157
  }
1158

1159
  if (check_for_node(root, "max_history_splits")) {
6,707✔
1160
    settings::max_history_splits =
214✔
1161
      std::stoi(get_node_value(root, "max_history_splits"));
214✔
1162
  }
1163

1164
  if (check_for_node(root, "max_tracks")) {
6,707✔
1165
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
48✔
1166
  }
1167

1168
  // Create weight window generator objects
1169
  if (check_for_node(root, "weight_window_generators")) {
6,707✔
1170
    auto wwgs_node = root.child("weight_window_generators");
81✔
1171
    for (pugi::xml_node node_wwg :
81✔
1172
      wwgs_node.children("weight_windows_generator")) {
243✔
1173
      variance_reduction::weight_windows_generators.emplace_back(
81✔
1174
        std::make_unique<WeightWindowsGenerator>(node_wwg));
162✔
1175
    }
1176
    // if any of the weight windows are intended to be generated otf, make sure
1177
    // they're applied
1178
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
81✔
1179
      if (wwg->on_the_fly_) {
81✔
1180
        settings::weight_windows_on = true;
81✔
1181
        break;
81✔
1182
      }
1183
    }
1184
  }
1185

1186
  // Set up weight window checkpoints
1187
  if (check_for_node(root, "weight_window_checkpoints")) {
6,707✔
1188
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
×
UNCOV
1189
    if (check_for_node(ww_checkpoints, "collision")) {
×
UNCOV
1190
      weight_window_checkpoint_collision =
×
UNCOV
1191
        get_node_value_bool(ww_checkpoints, "collision");
×
1192
    }
UNCOV
1193
    if (check_for_node(ww_checkpoints, "surface")) {
×
UNCOV
1194
      weight_window_checkpoint_surface =
×
UNCOV
1195
        get_node_value_bool(ww_checkpoints, "surface");
×
1196
    }
1197
  }
1198

1199
  if (check_for_node(root, "use_decay_photons")) {
6,707✔
1200
    settings::use_decay_photons =
11✔
1201
      get_node_value_bool(root, "use_decay_photons");
11✔
1202
  }
1203
}
6,707✔
1204

1205
void free_memory_settings()
6,833✔
1206
{
1207
  settings::statepoint_batch.clear();
6,833✔
1208
  settings::sourcepoint_batch.clear();
6,833✔
1209
  settings::source_write_surf_id.clear();
6,833✔
1210
  settings::res_scat_nuclides.clear();
6,833✔
1211
}
6,833✔
1212

1213
//==============================================================================
1214
// C API functions
1215
//==============================================================================
1216

1217
extern "C" int openmc_set_n_batches(
55✔
1218
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1219
{
1220
  if (settings::n_inactive >= n_batches) {
55✔
1221
    set_errmsg("Number of active batches must be greater than zero.");
11✔
1222
    return OPENMC_E_INVALID_ARGUMENT;
11✔
1223
  }
1224

1225
  if (simulation::current_batch >= n_batches) {
44✔
1226
    set_errmsg("Number of batches must be greater than current batch.");
11✔
1227
    return OPENMC_E_INVALID_ARGUMENT;
11✔
1228
  }
1229

1230
  if (!settings::trigger_on) {
33✔
1231
    // Set n_batches and n_max_batches to same value
1232
    settings::n_batches = n_batches;
11✔
1233
    settings::n_max_batches = n_batches;
11✔
1234
  } else {
1235
    // Set n_batches and n_max_batches based on value of set_max_batches
1236
    if (set_max_batches) {
22✔
1237
      settings::n_max_batches = n_batches;
11✔
1238
    } else {
1239
      settings::n_batches = n_batches;
11✔
1240
    }
1241
  }
1242

1243
  // Update size of k_generation and entropy
1244
  int m = settings::n_max_batches * settings::gen_per_batch;
33✔
1245
  simulation::k_generation.reserve(m);
33✔
1246
  simulation::entropy.reserve(m);
33✔
1247

1248
  // Add value of n_batches to statepoint_batch
1249
  if (add_statepoint_batch &&
55✔
1250
      !(contains(settings::statepoint_batch, n_batches)))
22✔
1251
    settings::statepoint_batch.insert(n_batches);
22✔
1252

1253
  return 0;
33✔
1254
}
1255

1256
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,980✔
1257
{
1258
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,980✔
1259

1260
  return 0;
2,980✔
1261
}
1262

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

© 2025 Coveralls, Inc