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

openmc-dev / openmc / 14260484407

04 Apr 2025 07:41AM UTC coverage: 84.589% (-0.3%) from 84.851%
14260484407

Pull #3279

github

web-flow
Merge 33e03305e into 07f533461
Pull Request #3279: Hexagonal mesh model

2 of 332 new or added lines in 3 files covered. (0.6%)

2798 existing lines in 84 files now uncovered.

51799 of 61236 relevant lines covered (84.59%)

38650400.15 hits per line

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

79.55
/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 legendre_to_tabular {true};
56
bool material_cell_offsets {true};
57
bool output_summary {true};
58
bool output_tallies {true};
59
bool particle_restart_run {false};
60
bool photon_transport {false};
61
bool reduce_tallies {true};
62
bool res_scat_on {false};
63
bool restart_run {false};
64
bool run_CE {true};
65
bool source_latest {false};
66
bool source_separate {false};
67
bool source_write {true};
68
bool source_mcpl_write {false};
69
bool surf_source_write {false};
70
bool surf_mcpl_write {false};
71
bool surf_source_read {false};
72
bool survival_biasing {false};
73
bool survival_normalization {false};
74
bool temperature_multipole {false};
75
bool trigger_on {false};
76
bool trigger_predict {false};
77
bool uniform_source_sampling {false};
78
bool ufs_on {false};
79
bool urr_ptables_on {true};
80
bool use_decay_photons {false};
81
bool weight_windows_on {false};
82
bool weight_window_checkpoint_surface {false};
83
bool weight_window_checkpoint_collision {true};
84
bool write_all_tracks {false};
85
bool write_initial_source {false};
86

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

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

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

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

142
} // namespace settings
143

144
//==============================================================================
145
// Functions
146
//==============================================================================
147

148
void get_run_parameters(pugi::xml_node node_base)
6,037✔
149
{
150
  using namespace settings;
151
  using namespace pugi;
152

153
  // Check number of particles
154
  if (!check_for_node(node_base, "particles")) {
6,037✔
UNCOV
155
    fatal_error("Need to specify number of particles.");
×
156
  }
157

158
  // Get number of particles if it wasn't specified as a command-line argument
159
  if (n_particles == -1) {
6,037✔
160
    n_particles = std::stoll(get_node_value(node_base, "particles"));
6,037✔
161
  }
162

163
  // Get maximum number of in flight particles for event-based mode
164
  if (check_for_node(node_base, "max_particles_in_flight")) {
6,037✔
UNCOV
165
    max_particles_in_flight =
×
UNCOV
166
      std::stoll(get_node_value(node_base, "max_particles_in_flight"));
×
167
  }
168

169
  // Get maximum number of events allowed per particle
170
  if (check_for_node(node_base, "max_particle_events")) {
6,037✔
UNCOV
171
    max_particle_events =
×
UNCOV
172
      std::stoll(get_node_value(node_base, "max_particle_events"));
×
173
  }
174

175
  // Get number of basic batches
176
  if (check_for_node(node_base, "batches")) {
6,037✔
177
    n_batches = std::stoi(get_node_value(node_base, "batches"));
6,037✔
178
  }
179
  if (!trigger_on)
6,037✔
180
    n_max_batches = n_batches;
5,891✔
181

182
  // Get max number of lost particles
183
  if (check_for_node(node_base, "max_lost_particles")) {
6,037✔
184
    max_lost_particles =
16✔
185
      std::stoi(get_node_value(node_base, "max_lost_particles"));
16✔
186
  }
187

188
  // Get relative number of lost particles
189
  if (check_for_node(node_base, "rel_max_lost_particles")) {
6,037✔
UNCOV
190
    rel_max_lost_particles =
×
UNCOV
191
      std::stod(get_node_value(node_base, "rel_max_lost_particles"));
×
192
  }
193

194
  // Get relative number of lost particles
195
  if (check_for_node(node_base, "max_write_lost_particles")) {
6,037✔
196
    max_write_lost_particles =
16✔
197
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
16✔
198
  }
199

200
  // Get number of inactive batches
201
  if (run_mode == RunMode::EIGENVALUE ||
6,037✔
202
      solver_type == SolverType::RANDOM_RAY) {
2,224✔
203
    if (check_for_node(node_base, "inactive")) {
4,197✔
204
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,111✔
205
    }
206
    if (check_for_node(node_base, "generations_per_batch")) {
4,197✔
207
      gen_per_batch =
16✔
208
        std::stoi(get_node_value(node_base, "generations_per_batch"));
16✔
209
    }
210

211
    // Preallocate space for keff and entropy by generation
212
    int m = settings::n_max_batches * settings::gen_per_batch;
4,197✔
213
    simulation::k_generation.reserve(m);
4,197✔
214
    simulation::entropy.reserve(m);
4,197✔
215

216
    // Get the trigger information for keff
217
    if (check_for_node(node_base, "keff_trigger")) {
4,197✔
218
      xml_node node_keff_trigger = node_base.child("keff_trigger");
107✔
219

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

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

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

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

379
  // Parse settings.xml file
380
  xml_document doc;
1,315✔
381
  auto result = doc.load_file(filename.c_str());
1,315✔
382
  if (!result) {
1,315✔
UNCOV
383
    fatal_error("Error processing settings.xml file.");
×
384
  }
385

386
  // Get root element
387
  xml_node root = doc.document_element();
1,315✔
388

389
  // Verbosity
390
  if (check_for_node(root, "verbosity")) {
1,315✔
391
    verbosity = std::stoi(get_node_value(root, "verbosity"));
188✔
392
  }
393

394
  // To this point, we haven't displayed any output since we didn't know what
395
  // the verbosity is. Now that we checked for it, show the title if necessary
396
  if (mpi::master) {
1,315✔
397
    if (verbosity >= 2)
1,085✔
398
      title();
907✔
399
  }
400

401
  write_message("Reading settings XML file...", 5);
1,315✔
402

403
  read_settings_xml(root);
1,315✔
404
}
1,327✔
405

406
void read_settings_xml(pugi::xml_node root)
6,556✔
407
{
408
  using namespace settings;
409
  using namespace pugi;
410

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

421
  // Check for user meshes and allocate
422
  read_meshes(root);
6,556✔
423

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

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

448
  // Check for a trigger node and get trigger information
449
  if (check_for_node(root, "trigger")) {
6,556✔
450
    xml_node node_trigger = root.child("trigger");
162✔
451

452
    // Check if trigger(s) are to be turned on
453
    trigger_on = get_node_value_bool(node_trigger, "active");
162✔
454

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

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

475
  // Check run mode if it hasn't been set from the command line
476
  xml_node node_mode;
6,556✔
477
  if (run_mode == RunMode::UNSET) {
6,556✔
478
    if (check_for_node(root, "run_mode")) {
6,069✔
479
      std::string temp_str = get_node_value(root, "run_mode", true, true);
6,005✔
480
      if (temp_str == "eigenvalue") {
6,005✔
481
        run_mode = RunMode::EIGENVALUE;
3,749✔
482
      } else if (temp_str == "fixed source") {
2,256✔
483
        run_mode = RunMode::FIXED_SOURCE;
2,224✔
484
      } else if (temp_str == "plot") {
32✔
485
        run_mode = RunMode::PLOTTING;
×
486
      } else if (temp_str == "particle restart") {
32✔
487
        run_mode = RunMode::PARTICLE;
×
488
      } else if (temp_str == "volume") {
32✔
489
        run_mode = RunMode::VOLUME;
32✔
490
      } else {
UNCOV
491
        fatal_error("Unrecognized run mode: " + temp_str);
×
492
      }
493

494
      // Assume XML specifies <particles>, <batches>, etc. directly
495
      node_mode = root;
6,005✔
496
    } else {
6,005✔
497
      warning("<run_mode> should be specified.");
64✔
498

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

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

522
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
6,556✔
523
    // Read run parameters
524
    get_run_parameters(node_mode);
6,037✔
525

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

541
  // Copy plotting random number seed if specified
542
  if (check_for_node(root, "plot_seed")) {
6,556✔
UNCOV
543
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
UNCOV
544
    model::plotter_seed = seed;
×
545
  }
546

547
  // Copy random number seed if specified
548
  if (check_for_node(root, "seed")) {
6,556✔
549
    auto seed = std::stoll(get_node_value(root, "seed"));
402✔
550
    openmc_set_seed(seed);
402✔
551
  }
552

553
  // Copy random number stride if specified
554
  if (check_for_node(root, "stride")) {
6,556✔
555
    auto stride = std::stoull(get_node_value(root, "stride"));
16✔
556
    openmc_set_stride(stride);
16✔
557
  }
558

559
  // Check for electron treatment
560
  if (check_for_node(root, "electron_treatment")) {
6,556✔
561
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
48✔
562
    if (temp_str == "led") {
48✔
UNCOV
563
      electron_treatment = ElectronTreatment::LED;
×
564
    } else if (temp_str == "ttb") {
48✔
565
      electron_treatment = ElectronTreatment::TTB;
48✔
566
    } else {
UNCOV
567
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
568
    }
569
  }
48✔
570

571
  // Check for photon transport
572
  if (check_for_node(root, "photon_transport")) {
6,556✔
573
    photon_transport = get_node_value_bool(root, "photon_transport");
188✔
574

575
    if (!run_CE && photon_transport) {
188✔
UNCOV
576
      fatal_error("Photon transport is not currently supported in "
×
577
                  "multigroup mode");
578
    }
579
  }
580

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

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

598
  // ==========================================================================
599
  // EXTERNAL SOURCE
600

601
  // Get point to list of <source> elements and make sure there is at least one
602
  for (pugi::xml_node node : root.children("source")) {
12,849✔
603
    model::external_sources.push_back(Source::create(node));
6,303✔
604
  }
605

606
  // Check if the user has specified to read surface source
607
  if (check_for_node(root, "surf_source_read")) {
6,546✔
608
    surf_source_read = true;
16✔
609
    // Get surface source read node
610
    xml_node node_ssr = root.child("surf_source_read");
16✔
611

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

620
  // Build probability mass function for sampling external sources
621
  vector<double> source_strengths;
6,546✔
622
  for (auto& s : model::external_sources) {
12,855✔
623
    source_strengths.push_back(s->strength());
6,309✔
624
  }
625
  model::external_sources_probability.assign(source_strengths);
6,546✔
626

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

639
  // Check if we want to write out source
640
  if (check_for_node(root, "write_initial_source")) {
6,546✔
UNCOV
641
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
642
  }
643

644
  // Survival biasing
645
  if (check_for_node(root, "survival_biasing")) {
6,546✔
646
    survival_biasing = get_node_value_bool(root, "survival_biasing");
175✔
647
  }
648

649
  // Probability tables
650
  if (check_for_node(root, "ptables")) {
6,546✔
651
    urr_ptables_on = get_node_value_bool(root, "ptables");
16✔
652
  }
653

654
  // Cutoffs
655
  if (check_for_node(root, "cutoff")) {
6,546✔
656
    xml_node node_cutoff = root.child("cutoff");
107✔
657
    if (check_for_node(node_cutoff, "weight")) {
107✔
658
      weight_cutoff = std::stod(get_node_value(node_cutoff, "weight"));
16✔
659
    }
660
    if (check_for_node(node_cutoff, "weight_avg")) {
107✔
661
      weight_survive = std::stod(get_node_value(node_cutoff, "weight_avg"));
16✔
662
    }
663
    if (check_for_node(node_cutoff, "survival_normalization")) {
107✔
UNCOV
664
      survival_normalization =
×
UNCOV
665
        get_node_value_bool(node_cutoff, "survival_normalization");
×
666
    }
667
    if (check_for_node(node_cutoff, "energy_neutron")) {
107✔
668
      energy_cutoff[0] =
32✔
669
        std::stod(get_node_value(node_cutoff, "energy_neutron"));
16✔
670
    } else if (check_for_node(node_cutoff, "energy")) {
91✔
UNCOV
671
      warning("The use of an <energy> cutoff is deprecated and should "
×
672
              "be replaced by <energy_neutron>.");
UNCOV
673
      energy_cutoff[0] = std::stod(get_node_value(node_cutoff, "energy"));
×
674
    }
675
    if (check_for_node(node_cutoff, "energy_photon")) {
107✔
676
      energy_cutoff[1] =
118✔
677
        std::stod(get_node_value(node_cutoff, "energy_photon"));
59✔
678
    }
679
    if (check_for_node(node_cutoff, "energy_electron")) {
107✔
UNCOV
680
      energy_cutoff[2] =
×
UNCOV
681
        std::stof(get_node_value(node_cutoff, "energy_electron"));
×
682
    }
683
    if (check_for_node(node_cutoff, "energy_positron")) {
107✔
UNCOV
684
      energy_cutoff[3] =
×
685
        std::stod(get_node_value(node_cutoff, "energy_positron"));
×
686
    }
687
    if (check_for_node(node_cutoff, "time_neutron")) {
107✔
688
      time_cutoff[0] = std::stod(get_node_value(node_cutoff, "time_neutron"));
16✔
689
    }
690
    if (check_for_node(node_cutoff, "time_photon")) {
107✔
UNCOV
691
      time_cutoff[1] = std::stod(get_node_value(node_cutoff, "time_photon"));
×
692
    }
693
    if (check_for_node(node_cutoff, "time_electron")) {
107✔
UNCOV
694
      time_cutoff[2] = std::stod(get_node_value(node_cutoff, "time_electron"));
×
695
    }
696
    if (check_for_node(node_cutoff, "time_positron")) {
107✔
UNCOV
697
      time_cutoff[3] = std::stod(get_node_value(node_cutoff, "time_positron"));
×
698
    }
699
  }
700

701
  // Particle trace
702
  if (check_for_node(root, "trace")) {
6,546✔
703
    auto temp = get_node_array<int64_t>(root, "trace");
16✔
704
    if (temp.size() != 3) {
16✔
UNCOV
705
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
706
                  "batch, generation, and particle number.");
707
    }
708
    trace_batch = temp.at(0);
16✔
709
    trace_gen = temp.at(1);
16✔
710
    trace_particle = temp.at(2);
16✔
711
  }
16✔
712

713
  // Particle tracks
714
  if (check_for_node(root, "track")) {
6,546✔
715
    // Get values and make sure there are three per particle
716
    auto temp = get_node_array<int>(root, "track");
48✔
717
    if (temp.size() % 3 != 0) {
48✔
UNCOV
718
      fatal_error(
×
719
        "Number of integers specified in 'track' is not "
720
        "divisible by 3.  Please provide 3 integers per particle to be "
721
        "tracked.");
722
    }
723

724
    // Reshape into track_identifiers
725
    int n_tracks = temp.size() / 3;
48✔
726
    for (int i = 0; i < n_tracks; ++i) {
192✔
727
      track_identifiers.push_back(
144✔
728
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
144✔
729
    }
730
  }
48✔
731

732
  // Shannon entropy
733
  if (solver_type == SolverType::RANDOM_RAY) {
6,546✔
734
    if (check_for_node(root, "entropy_mesh")) {
560✔
UNCOV
735
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
736
                  "No user-defined entropy mesh is supported.");
737
    }
738
    entropy_on = true;
560✔
739
  } else if (solver_type == SolverType::MONTE_CARLO) {
5,986✔
740
    if (check_for_node(root, "entropy_mesh")) {
5,986✔
741
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
365✔
742
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
365✔
UNCOV
743
        fatal_error(fmt::format(
×
744
          "Mesh {} specified for Shannon entropy does not exist.", temp));
745
      }
746

747
      auto* m = dynamic_cast<RegularMesh*>(
365✔
748
        model::meshes[model::mesh_map.at(temp)].get());
365✔
749
      if (!m)
365✔
UNCOV
750
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
751
      simulation::entropy_mesh = m;
365✔
752

753
      // Turn on Shannon entropy calculation
754
      entropy_on = true;
365✔
755

756
    } else if (check_for_node(root, "entropy")) {
5,621✔
UNCOV
757
      fatal_error(
×
758
        "Specifying a Shannon entropy mesh via the <entropy> element "
759
        "is deprecated. Please create a mesh using <mesh> and then reference "
760
        "it by specifying its ID in an <entropy_mesh> element.");
761
    }
762
  }
763
  // Uniform fission source weighting mesh
764
  if (check_for_node(root, "ufs_mesh")) {
6,546✔
765
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
16✔
766
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
16✔
UNCOV
767
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
768
                              "method does not exist.",
769
        temp));
770
    }
771

772
    auto* m =
773
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
16✔
774
    if (!m)
16✔
775
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
776
    simulation::ufs_mesh = m;
16✔
777

778
    // Turn on uniform fission source weighting
779
    ufs_on = true;
16✔
780

781
  } else if (check_for_node(root, "uniform_fs")) {
6,530✔
782
    fatal_error(
×
783
      "Specifying a UFS mesh via the <uniform_fs> element "
784
      "is deprecated. Please create a mesh using <mesh> and then reference "
785
      "it by specifying its ID in a <ufs_mesh> element.");
786
  }
787

788
  // Check if the user has specified to write state points
789
  if (check_for_node(root, "state_point")) {
6,546✔
790

791
    // Get pointer to state_point node
792
    auto node_sp = root.child("state_point");
176✔
793

794
    // Determine number of batches at which to store state points
795
    if (check_for_node(node_sp, "batches")) {
176✔
796
      // User gave specific batches to write state points
797
      auto temp = get_node_array<int>(node_sp, "batches");
176✔
798
      for (const auto& b : temp) {
544✔
799
        statepoint_batch.insert(b);
368✔
800
      }
801
    } else {
176✔
802
      // If neither were specified, write state point at last batch
UNCOV
803
      statepoint_batch.insert(n_batches);
×
804
    }
805
  } else {
806
    // If no <state_point> tag was present, by default write state point at
807
    // last batch only
808
    statepoint_batch.insert(n_batches);
6,370✔
809
  }
810

811
  // Check if the user has specified to write source points
812
  if (check_for_node(root, "source_point")) {
6,546✔
813
    // Get source_point node
814
    xml_node node_sp = root.child("source_point");
96✔
815

816
    // Determine batches at which to store source points
817
    if (check_for_node(node_sp, "batches")) {
96✔
818
      // User gave specific batches to write source points
819
      auto temp = get_node_array<int>(node_sp, "batches");
48✔
820
      for (const auto& b : temp) {
128✔
821
        sourcepoint_batch.insert(b);
80✔
822
      }
823
    } else {
48✔
824
      // If neither were specified, write source points with state points
825
      sourcepoint_batch = statepoint_batch;
48✔
826
    }
827

828
    // Check if the user has specified to write binary source file
829
    if (check_for_node(node_sp, "separate")) {
96✔
830
      source_separate = get_node_value_bool(node_sp, "separate");
64✔
831
    }
832
    if (check_for_node(node_sp, "write")) {
96✔
UNCOV
833
      source_write = get_node_value_bool(node_sp, "write");
×
834
    }
835
    if (check_for_node(node_sp, "mcpl")) {
96✔
836
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
16✔
837

838
      // Make sure MCPL support is enabled
839
      if (source_mcpl_write && !MCPL_ENABLED) {
16✔
840
        fatal_error(
×
841
          "Your build of OpenMC does not support writing MCPL source files.");
842
      }
843
    }
844
    if (check_for_node(node_sp, "overwrite_latest")) {
96✔
845
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
16✔
846
      source_separate = source_latest;
16✔
847
    }
848
  } else {
849
    // If no <source_point> tag was present, by default we keep source bank in
850
    // statepoint file and write it out at statepoints intervals
851
    source_separate = false;
6,450✔
852
    sourcepoint_batch = statepoint_batch;
6,450✔
853
  }
854

855
  // Check is the user specified to convert strength to statistical weight
856
  if (check_for_node(root, "uniform_source_sampling")) {
6,546✔
857
    uniform_source_sampling =
55✔
858
      get_node_value_bool(root, "uniform_source_sampling");
55✔
859
  }
860

861
  // Check if the user has specified to write surface source
862
  if (check_for_node(root, "surf_source_write")) {
6,546✔
863
    surf_source_write = true;
401✔
864
    // Get surface source write node
865
    xml_node node_ssw = root.child("surf_source_write");
401✔
866

867
    // Determine surface ids at which crossing particles are to be banked.
868
    // If no surfaces are specified, all surfaces in the model will be used
869
    // to bank source points.
870
    if (check_for_node(node_ssw, "surface_ids")) {
401✔
871
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
191✔
872
      for (const auto& b : temp) {
972✔
873
        source_write_surf_id.insert(b);
781✔
874
      }
875
    }
191✔
876

877
    // Get maximum number of particles to be banked per surface
878
    if (check_for_node(node_ssw, "max_particles")) {
401✔
879
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
392✔
880
    } else {
881
      fatal_error("A maximum number of particles needs to be specified "
9✔
882
                  "using the 'max_particles' parameter to store surface "
883
                  "source points.");
884
    }
885

886
    // Get maximum number of surface source files to be created
887
    if (check_for_node(node_ssw, "max_source_files")) {
392✔
888
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
33✔
889
    } else {
890
      ssw_max_files = 1;
359✔
891
    }
892

893
    if (check_for_node(node_ssw, "mcpl")) {
392✔
UNCOV
894
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
×
895

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

925
  // If source is not separate and is to be written out in the statepoint file,
926
  // make sure that the sourcepoint batch numbers are contained in the
927
  // statepoint list
928
  if (!source_separate) {
6,501✔
929
    for (const auto& b : sourcepoint_batch) {
12,986✔
930
      if (!contains(statepoint_batch, b)) {
6,565✔
931
        fatal_error(
×
932
          "Sourcepoint batches are not a subset of statepoint batches.");
933
      }
934
    }
935
  }
936

937
  // Check if the user has specified to not reduce tallies at the end of every
938
  // batch
939
  if (check_for_node(root, "no_reduce")) {
6,501✔
UNCOV
940
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
×
941
  }
942

943
  // Check if the user has specified to use confidence intervals for
944
  // uncertainties rather than standard deviations
945
  if (check_for_node(root, "confidence_intervals")) {
6,501✔
946
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
16✔
947
  }
948

949
  // Check for output options
950
  if (check_for_node(root, "output")) {
6,501✔
951
    // Get pointer to output node
952
    pugi::xml_node node_output = root.child("output");
438✔
953

954
    // Check for summary option
955
    if (check_for_node(node_output, "summary")) {
438✔
956
      output_summary = get_node_value_bool(node_output, "summary");
422✔
957
    }
958

959
    // Check for ASCII tallies output option
960
    if (check_for_node(node_output, "tallies")) {
438✔
961
      output_tallies = get_node_value_bool(node_output, "tallies");
82✔
962
    }
963

964
    // Set output directory if a path has been specified
965
    if (check_for_node(node_output, "path")) {
438✔
UNCOV
966
      path_output = get_node_value(node_output, "path");
×
UNCOV
967
      if (!ends_with(path_output, "/")) {
×
UNCOV
968
        path_output += "/";
×
969
      }
970
    }
971
  }
972

973
  // Resonance scattering parameters
974
  if (check_for_node(root, "resonance_scattering")) {
6,501✔
975
    xml_node node_res_scat = root.child("resonance_scattering");
16✔
976

977
    // See if resonance scattering is enabled
978
    if (check_for_node(node_res_scat, "enable")) {
16✔
979
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
16✔
980
    } else {
UNCOV
981
      res_scat_on = true;
×
982
    }
983

984
    // Determine what method is used
985
    if (check_for_node(node_res_scat, "method")) {
16✔
986
      auto temp = get_node_value(node_res_scat, "method", true, true);
16✔
987
      if (temp == "rvs") {
16✔
988
        res_scat_method = ResScatMethod::rvs;
16✔
UNCOV
989
      } else if (temp == "dbrc") {
×
UNCOV
990
        res_scat_method = ResScatMethod::dbrc;
×
991
      } else {
UNCOV
992
        fatal_error(
×
UNCOV
993
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
994
      }
995
    }
16✔
996

997
    // Minimum energy for resonance scattering
998
    if (check_for_node(node_res_scat, "energy_min")) {
16✔
999
      res_scat_energy_min =
16✔
1000
        std::stod(get_node_value(node_res_scat, "energy_min"));
16✔
1001
    }
1002
    if (res_scat_energy_min < 0.0) {
16✔
UNCOV
1003
      fatal_error("Lower resonance scattering energy bound is negative");
×
1004
    }
1005

1006
    // Maximum energy for resonance scattering
1007
    if (check_for_node(node_res_scat, "energy_max")) {
16✔
1008
      res_scat_energy_max =
16✔
1009
        std::stod(get_node_value(node_res_scat, "energy_max"));
16✔
1010
    }
1011
    if (res_scat_energy_max < res_scat_energy_min) {
16✔
UNCOV
1012
      fatal_error("Upper resonance scattering energy bound is below the "
×
1013
                  "lower resonance scattering energy bound.");
1014
    }
1015

1016
    // Get resonance scattering nuclides
1017
    if (check_for_node(node_res_scat, "nuclides")) {
16✔
1018
      res_scat_nuclides =
1019
        get_node_array<std::string>(node_res_scat, "nuclides");
16✔
1020
    }
1021
  }
1022

1023
  // Get volume calculations
1024
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
6,827✔
1025
    model::volume_calcs.emplace_back(node_vol);
326✔
1026
  }
1027

1028
  // Get temperature settings
1029
  if (check_for_node(root, "temperature_default")) {
6,501✔
1030
    temperature_default =
172✔
1031
      std::stod(get_node_value(root, "temperature_default"));
172✔
1032
  }
1033
  if (check_for_node(root, "temperature_method")) {
6,501✔
1034
    auto temp = get_node_value(root, "temperature_method", true, true);
325✔
1035
    if (temp == "nearest") {
325✔
1036
      temperature_method = TemperatureMethod::NEAREST;
140✔
1037
    } else if (temp == "interpolation") {
185✔
1038
      temperature_method = TemperatureMethod::INTERPOLATION;
185✔
1039
    } else {
UNCOV
1040
      fatal_error("Unknown temperature method: " + temp);
×
1041
    }
1042
  }
325✔
1043
  if (check_for_node(root, "temperature_tolerance")) {
6,501✔
1044
    temperature_tolerance =
171✔
1045
      std::stod(get_node_value(root, "temperature_tolerance"));
171✔
1046
  }
1047
  if (check_for_node(root, "temperature_multipole")) {
6,501✔
1048
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
32✔
1049

1050
    // Multipole currently doesn't work with photon transport
1051
    if (temperature_multipole && photon_transport) {
32✔
UNCOV
1052
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1053
                  "photon transport.");
1054
    }
1055
  }
1056
  if (check_for_node(root, "temperature_range")) {
6,501✔
UNCOV
1057
    auto range = get_node_array<double>(root, "temperature_range");
×
UNCOV
1058
    temperature_range[0] = range.at(0);
×
UNCOV
1059
    temperature_range[1] = range.at(1);
×
1060
  }
1061

1062
  // Check for tabular_legendre options
1063
  if (check_for_node(root, "tabular_legendre")) {
6,501✔
1064
    // Get pointer to tabular_legendre node
1065
    xml_node node_tab_leg = root.child("tabular_legendre");
96✔
1066

1067
    // Check for enable option
1068
    if (check_for_node(node_tab_leg, "enable")) {
96✔
1069
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
96✔
1070
    }
1071

1072
    // Check for the number of points
1073
    if (check_for_node(node_tab_leg, "num_points")) {
96✔
UNCOV
1074
      legendre_to_tabular_points =
×
UNCOV
1075
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
UNCOV
1076
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
UNCOV
1077
        fatal_error(
×
1078
          "The 'num_points' subelement/attribute of the "
1079
          "<tabular_legendre> element must contain a value greater than 1");
1080
      }
1081
    }
1082
  }
1083

1084
  // Check whether create delayed neutrons in fission
1085
  if (check_for_node(root, "create_delayed_neutrons")) {
6,501✔
UNCOV
1086
    create_delayed_neutrons =
×
UNCOV
1087
      get_node_value_bool(root, "create_delayed_neutrons");
×
1088
  }
1089

1090
  // Check whether create fission sites
1091
  if (run_mode == RunMode::FIXED_SOURCE) {
6,501✔
1092
    if (check_for_node(root, "create_fission_neutrons")) {
2,178✔
1093
      create_fission_neutrons =
16✔
1094
        get_node_value_bool(root, "create_fission_neutrons");
16✔
1095
    }
1096
  }
1097

1098
  // Check whether to scale fission photon yields
1099
  if (check_for_node(root, "delayed_photon_scaling")) {
6,501✔
UNCOV
1100
    delayed_photon_scaling =
×
UNCOV
1101
      get_node_value_bool(root, "delayed_photon_scaling");
×
1102
  }
1103

1104
  // Check whether to use event-based parallelism
1105
  if (check_for_node(root, "event_based")) {
6,501✔
1106
    event_based = get_node_value_bool(root, "event_based");
×
1107
  }
1108

1109
  // Check whether material cell offsets should be generated
1110
  if (check_for_node(root, "material_cell_offsets")) {
6,501✔
1111
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1112
  }
1113

1114
  // Weight window information
1115
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
6,580✔
1116
    variance_reduction::weight_windows.emplace_back(
79✔
1117
      std::make_unique<WeightWindows>(node_ww));
158✔
1118
  }
1119

1120
  // Enable weight windows by default if one or more are present
1121
  if (variance_reduction::weight_windows.size() > 0)
6,501✔
1122
    settings::weight_windows_on = true;
52✔
1123

1124
  // read weight windows from file
1125
  if (check_for_node(root, "weight_windows_file")) {
6,501✔
UNCOV
1126
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1127
  }
1128

1129
  // read settings for weight windows value, this will override
1130
  // the automatic setting even if weight windows are present
1131
  if (check_for_node(root, "weight_windows_on")) {
6,501✔
1132
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
36✔
1133
  }
1134

1135
  if (check_for_node(root, "max_history_splits")) {
6,501✔
1136
    settings::max_history_splits =
214✔
1137
      std::stoi(get_node_value(root, "max_history_splits"));
214✔
1138
  }
1139

1140
  if (check_for_node(root, "max_tracks")) {
6,501✔
1141
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
48✔
1142
  }
1143

1144
  // Create weight window generator objects
1145
  if (check_for_node(root, "weight_window_generators")) {
6,501✔
1146
    auto wwgs_node = root.child("weight_window_generators");
81✔
1147
    for (pugi::xml_node node_wwg :
81✔
1148
      wwgs_node.children("weight_windows_generator")) {
243✔
1149
      variance_reduction::weight_windows_generators.emplace_back(
81✔
1150
        std::make_unique<WeightWindowsGenerator>(node_wwg));
162✔
1151
    }
1152
    // if any of the weight windows are intended to be generated otf, make sure
1153
    // they're applied
1154
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
81✔
1155
      if (wwg->on_the_fly_) {
81✔
1156
        settings::weight_windows_on = true;
81✔
1157
        break;
81✔
1158
      }
1159
    }
1160
  }
1161

1162
  // Set up weight window checkpoints
1163
  if (check_for_node(root, "weight_window_checkpoints")) {
6,501✔
UNCOV
1164
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
×
UNCOV
1165
    if (check_for_node(ww_checkpoints, "collision")) {
×
UNCOV
1166
      weight_window_checkpoint_collision =
×
UNCOV
1167
        get_node_value_bool(ww_checkpoints, "collision");
×
1168
    }
UNCOV
1169
    if (check_for_node(ww_checkpoints, "surface")) {
×
UNCOV
1170
      weight_window_checkpoint_surface =
×
UNCOV
1171
        get_node_value_bool(ww_checkpoints, "surface");
×
1172
    }
1173
  }
1174

1175
  if (check_for_node(root, "use_decay_photons")) {
6,501✔
1176
    settings::use_decay_photons =
11✔
1177
      get_node_value_bool(root, "use_decay_photons");
11✔
1178
  }
1179
}
6,501✔
1180

1181
void free_memory_settings()
6,645✔
1182
{
1183
  settings::statepoint_batch.clear();
6,645✔
1184
  settings::sourcepoint_batch.clear();
6,645✔
1185
  settings::source_write_surf_id.clear();
6,645✔
1186
  settings::res_scat_nuclides.clear();
6,645✔
1187
}
6,645✔
1188

1189
//==============================================================================
1190
// C API functions
1191
//==============================================================================
1192

1193
extern "C" int openmc_set_n_batches(
55✔
1194
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1195
{
1196
  if (settings::n_inactive >= n_batches) {
55✔
1197
    set_errmsg("Number of active batches must be greater than zero.");
11✔
1198
    return OPENMC_E_INVALID_ARGUMENT;
11✔
1199
  }
1200

1201
  if (simulation::current_batch >= n_batches) {
44✔
1202
    set_errmsg("Number of batches must be greater than current batch.");
11✔
1203
    return OPENMC_E_INVALID_ARGUMENT;
11✔
1204
  }
1205

1206
  if (!settings::trigger_on) {
33✔
1207
    // Set n_batches and n_max_batches to same value
1208
    settings::n_batches = n_batches;
11✔
1209
    settings::n_max_batches = n_batches;
11✔
1210
  } else {
1211
    // Set n_batches and n_max_batches based on value of set_max_batches
1212
    if (set_max_batches) {
22✔
1213
      settings::n_max_batches = n_batches;
11✔
1214
    } else {
1215
      settings::n_batches = n_batches;
11✔
1216
    }
1217
  }
1218

1219
  // Update size of k_generation and entropy
1220
  int m = settings::n_max_batches * settings::gen_per_batch;
33✔
1221
  simulation::k_generation.reserve(m);
33✔
1222
  simulation::entropy.reserve(m);
33✔
1223

1224
  // Add value of n_batches to statepoint_batch
1225
  if (add_statepoint_batch &&
55✔
1226
      !(contains(settings::statepoint_batch, n_batches)))
22✔
1227
    settings::statepoint_batch.insert(n_batches);
22✔
1228

1229
  return 0;
33✔
1230
}
1231

1232
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,980✔
1233
{
1234
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,980✔
1235

1236
  return 0;
2,980✔
1237
}
1238

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