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

openmc-dev / openmc / 12992353024

27 Jan 2025 03:25PM UTC coverage: 84.854% (-0.01%) from 84.867%
12992353024

Pull #3268

github

web-flow
Merge 2f5de56d8 into 2bea7f338
Pull Request #3268: Randomized Quasi-Monte Carlo Sampling in The Random Ray Method

74 of 82 new or added lines in 4 files covered. (90.24%)

685 existing lines in 31 files now uncovered.

50168 of 59123 relevant lines covered (84.85%)

35036956.25 hits per line

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

79.04
/src/settings.cpp
1
#include "openmc/settings.h"
2

3
#include <cmath>  // for ceil, pow
4
#include <limits> // for numeric_limits
5
#include <string>
6

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

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

36
namespace openmc {
37

38
//==============================================================================
39
// Global variables
40
//==============================================================================
41

42
namespace settings {
43

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

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

93
int32_t n_inactive {0};
94
int32_t max_lost_particles {10};
95
double rel_max_lost_particles {1.0e-6};
96
int32_t max_write_lost_particles {-1};
97
int32_t gen_per_batch {1};
98
int64_t n_particles {-1};
99

100
int64_t max_particles_in_flight {100000};
101
int max_particle_events {1000000};
102

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

139
} // namespace settings
140

141
//==============================================================================
142
// Functions
143
//==============================================================================
144

145
void get_run_parameters(pugi::xml_node node_base)
6,415✔
146
{
147
  using namespace settings;
148
  using namespace pugi;
149

150
  // Check number of particles
151
  if (!check_for_node(node_base, "particles")) {
6,415✔
152
    fatal_error("Need to specify number of particles.");
×
153
  }
154

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

160
  // Get maximum number of in flight particles for event-based mode
161
  if (check_for_node(node_base, "max_particles_in_flight")) {
6,415✔
162
    max_particles_in_flight =
×
163
      std::stoll(get_node_value(node_base, "max_particles_in_flight"));
×
164
  }
165

166
  // Get maximum number of events allowed per particle
167
  if (check_for_node(node_base, "max_particle_events")) {
6,415✔
168
    max_particle_events =
×
169
      std::stoll(get_node_value(node_base, "max_particle_events"));
×
170
  }
171

172
  // Get number of basic batches
173
  if (check_for_node(node_base, "batches")) {
6,415✔
174
    n_batches = std::stoi(get_node_value(node_base, "batches"));
6,415✔
175
  }
176
  if (!trigger_on)
6,415✔
177
    n_max_batches = n_batches;
6,258✔
178

179
  // Get max number of lost particles
180
  if (check_for_node(node_base, "max_lost_particles")) {
6,415✔
181
    max_lost_particles =
17✔
182
      std::stoi(get_node_value(node_base, "max_lost_particles"));
17✔
183
  }
184

185
  // Get relative number of lost particles
186
  if (check_for_node(node_base, "rel_max_lost_particles")) {
6,415✔
187
    rel_max_lost_particles =
×
188
      std::stod(get_node_value(node_base, "rel_max_lost_particles"));
×
189
  }
190

191
  // Get relative number of lost particles
192
  if (check_for_node(node_base, "max_write_lost_particles")) {
6,415✔
193
    max_write_lost_particles =
17✔
194
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
17✔
195
  }
196

197
  // Get number of inactive batches
198
  if (run_mode == RunMode::EIGENVALUE ||
6,415✔
199
      solver_type == SolverType::RANDOM_RAY) {
2,189✔
200
    if (check_for_node(node_base, "inactive")) {
4,498✔
201
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,368✔
202
    }
203
    if (check_for_node(node_base, "generations_per_batch")) {
4,498✔
204
      gen_per_batch =
17✔
205
        std::stoi(get_node_value(node_base, "generations_per_batch"));
17✔
206
    }
207

208
    // Preallocate space for keff and entropy by generation
209
    int m = settings::n_max_batches * settings::gen_per_batch;
4,498✔
210
    simulation::k_generation.reserve(m);
4,498✔
211
    simulation::entropy.reserve(m);
4,498✔
212

213
    // Get the trigger information for keff
214
    if (check_for_node(node_base, "keff_trigger")) {
4,498✔
215
      xml_node node_keff_trigger = node_base.child("keff_trigger");
114✔
216

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

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

244
  // Random ray variables
245
  if (solver_type == SolverType::RANDOM_RAY) {
6,415✔
246
    xml_node random_ray_node = node_base.child("random_ray");
374✔
247
    if (check_for_node(random_ray_node, "distance_active")) {
374✔
248
      RandomRay::distance_active_ =
374✔
249
        std::stod(get_node_value(random_ray_node, "distance_active"));
374✔
250
      if (RandomRay::distance_active_ <= 0.0) {
374✔
251
        fatal_error("Random ray active distance must be greater than 0");
×
252
      }
253
    } else {
254
      fatal_error("Specify random ray active distance in settings XML");
×
255
    }
256
    if (check_for_node(random_ray_node, "distance_inactive")) {
374✔
257
      RandomRay::distance_inactive_ =
374✔
258
        std::stod(get_node_value(random_ray_node, "distance_inactive"));
374✔
259
      if (RandomRay::distance_inactive_ < 0) {
374✔
260
        fatal_error(
×
261
          "Random ray inactive distance must be greater than or equal to 0");
262
      }
263
    } else {
264
      fatal_error("Specify random ray inactive distance in settings XML");
×
265
    }
266
    if (check_for_node(random_ray_node, "source")) {
374✔
267
      xml_node source_node = random_ray_node.child("source");
374✔
268
      // Get point to list of <source> elements and make sure there is at least
269
      // one
270
      RandomRay::ray_source_ = Source::create(source_node);
374✔
271
    } else {
272
      fatal_error("Specify random ray source in settings XML");
×
273
    }
274
    if (check_for_node(random_ray_node, "volume_estimator")) {
374✔
275
      std::string temp_str =
276
        get_node_value(random_ray_node, "volume_estimator", true, true);
102✔
277
      if (temp_str == "simulation_averaged") {
102✔
278
        FlatSourceDomain::volume_estimator_ =
34✔
279
          RandomRayVolumeEstimator::SIMULATION_AVERAGED;
280
      } else if (temp_str == "naive") {
68✔
281
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::NAIVE;
34✔
282
      } else if (temp_str == "hybrid") {
34✔
283
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::HYBRID;
34✔
284
      } else {
285
        fatal_error("Unrecognized volume estimator: " + temp_str);
×
286
      }
287
    }
102✔
288
    if (check_for_node(random_ray_node, "source_shape")) {
374✔
289
      std::string temp_str =
290
        get_node_value(random_ray_node, "source_shape", true, true);
153✔
291
      if (temp_str == "flat") {
153✔
292
        RandomRay::source_shape_ = RandomRaySourceShape::FLAT;
17✔
293
      } else if (temp_str == "linear") {
136✔
294
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR;
85✔
295
      } else if (temp_str == "linear_xy") {
51✔
296
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR_XY;
51✔
297
      } else {
298
        fatal_error("Unrecognized source shape: " + temp_str);
×
299
      }
300
    }
153✔
301
    if (check_for_node(random_ray_node, "volume_normalized_flux_tallies")) {
374✔
302
      FlatSourceDomain::volume_normalized_flux_tallies_ =
357✔
303
        get_node_value_bool(random_ray_node, "volume_normalized_flux_tallies");
357✔
304
    }
305
    if (check_for_node(random_ray_node, "adjoint")) {
374✔
306
      FlatSourceDomain::adjoint_ =
34✔
307
        get_node_value_bool(random_ray_node, "adjoint");
34✔
308
    }
309
    if (check_for_node(random_ray_node, "sample_method")) {
374✔
310
      std::string temp_str =
311
        get_node_value(random_ray_node, "sample_method", true, true);
17✔
312
      if (temp_str == "prng") {
17✔
NEW
313
        RandomRay::sample_method_ = RandomRaySampleMethod::PRNG;
×
314
      } else if (temp_str == "halton") {
17✔
315
        RandomRay::sample_method_ = RandomRaySampleMethod::HALTON;
17✔
316
      } else {
NEW
317
        fatal_error("Unrecognized sample method: " + temp_str);
×
318
      }
319
    }
17✔
320
  }
321
}
6,415✔
322

323
void read_settings_xml()
1,542✔
324
{
325
  using namespace settings;
326
  using namespace pugi;
327
  // Check if settings.xml exists
328
  std::string filename = settings::path_input + "settings.xml";
1,542✔
329
  if (!file_exists(filename)) {
1,542✔
330
    if (run_mode != RunMode::PLOTTING) {
24✔
331
      fatal_error("Could not find any XML input files! In order to run OpenMC, "
×
332
                  "you first need a set of input files; at a minimum, this "
333
                  "includes settings.xml, geometry.xml, and materials.xml or a "
334
                  "single model XML file. Please consult the user's guide at "
335
                  "https://docs.openmc.org for further information.");
336
    } else {
337
      // The settings.xml file is optional if we just want to make a plot.
338
      return;
24✔
339
    }
340
  }
341

342
  // Parse settings.xml file
343
  xml_document doc;
1,518✔
344
  auto result = doc.load_file(filename.c_str());
1,518✔
345
  if (!result) {
1,518✔
346
    fatal_error("Error processing settings.xml file.");
×
347
  }
348

349
  // Get root element
350
  xml_node root = doc.document_element();
1,518✔
351

352
  // Verbosity
353
  if (check_for_node(root, "verbosity")) {
1,518✔
354
    verbosity = std::stoi(get_node_value(root, "verbosity"));
215✔
355
  }
356

357
  // To this point, we haven't displayed any output since we didn't know what
358
  // the verbosity is. Now that we checked for it, show the title if necessary
359
  if (mpi::master) {
1,518✔
360
    if (verbosity >= 2)
1,288✔
361
      title();
1,083✔
362
  }
363

364
  write_message("Reading settings XML file...", 5);
1,518✔
365

366
  read_settings_xml(root);
1,518✔
367
}
1,531✔
368

369
void read_settings_xml(pugi::xml_node root)
6,873✔
370
{
371
  using namespace settings;
372
  using namespace pugi;
373

374
  // Find if a multi-group or continuous-energy simulation is desired
375
  if (check_for_node(root, "energy_mode")) {
6,873✔
376
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
942✔
377
    if (temp_str == "mg" || temp_str == "multi-group") {
942✔
378
      run_CE = false;
942✔
379
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
380
      run_CE = true;
×
381
    }
382
  }
942✔
383

384
  // Check for user meshes and allocate
385
  read_meshes(root);
6,873✔
386

387
  // Look for deprecated cross_sections.xml file in settings.xml
388
  if (check_for_node(root, "cross_sections")) {
6,873✔
389
    warning(
×
390
      "Setting cross_sections in settings.xml has been deprecated."
391
      " The cross_sections are now set in materials.xml and the "
392
      "cross_sections input to materials.xml and the OPENMC_CROSS_SECTIONS"
393
      " environment variable will take precendent over setting "
394
      "cross_sections in settings.xml.");
395
    path_cross_sections = get_node_value(root, "cross_sections");
×
396
  }
397

398
  if (!run_CE) {
6,873✔
399
    // Scattering Treatments
400
    if (check_for_node(root, "max_order")) {
942✔
401
      max_order = std::stoi(get_node_value(root, "max_order"));
17✔
402
    } else {
403
      // Set to default of largest int - 1, which means to use whatever is
404
      // contained in library. This is largest int - 1 because for legendre
405
      // scattering, a value of 1 is added to the order; adding 1 to the largest
406
      // int gets you the largest negative integer, which is not what we want.
407
      max_order = std::numeric_limits<int>::max() - 1;
925✔
408
    }
409
  }
410

411
  // Check for a trigger node and get trigger information
412
  if (check_for_node(root, "trigger")) {
6,873✔
413
    xml_node node_trigger = root.child("trigger");
174✔
414

415
    // Check if trigger(s) are to be turned on
416
    trigger_on = get_node_value_bool(node_trigger, "active");
174✔
417

418
    if (trigger_on) {
174✔
419
      if (check_for_node(node_trigger, "max_batches")) {
157✔
420
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
157✔
421
      } else {
422
        fatal_error("<max_batches> must be specified with triggers");
×
423
      }
424

425
      // Get the batch interval to check triggers
426
      if (!check_for_node(node_trigger, "batch_interval")) {
157✔
427
        trigger_predict = true;
17✔
428
      } else {
429
        trigger_batch_interval =
140✔
430
          std::stoi(get_node_value(node_trigger, "batch_interval"));
140✔
431
        if (trigger_batch_interval <= 0) {
140✔
432
          fatal_error("Trigger batch interval must be greater than zero");
×
433
        }
434
      }
435
    }
436
  }
437

438
  // Check run mode if it hasn't been set from the command line
439
  xml_node node_mode;
6,873✔
440
  if (run_mode == RunMode::UNSET) {
6,873✔
441
    if (check_for_node(root, "run_mode")) {
6,449✔
442
      std::string temp_str = get_node_value(root, "run_mode", true, true);
6,381✔
443
      if (temp_str == "eigenvalue") {
6,381✔
444
        run_mode = RunMode::EIGENVALUE;
4,158✔
445
      } else if (temp_str == "fixed source") {
2,223✔
446
        run_mode = RunMode::FIXED_SOURCE;
2,189✔
447
      } else if (temp_str == "plot") {
34✔
448
        run_mode = RunMode::PLOTTING;
×
449
      } else if (temp_str == "particle restart") {
34✔
450
        run_mode = RunMode::PARTICLE;
×
451
      } else if (temp_str == "volume") {
34✔
452
        run_mode = RunMode::VOLUME;
34✔
453
      } else {
454
        fatal_error("Unrecognized run mode: " + temp_str);
×
455
      }
456

457
      // Assume XML specifies <particles>, <batches>, etc. directly
458
      node_mode = root;
6,381✔
459
    } else {
6,381✔
460
      warning("<run_mode> should be specified.");
68✔
461

462
      // Make sure that either eigenvalue or fixed source was specified
463
      node_mode = root.child("eigenvalue");
68✔
464
      if (node_mode) {
68✔
465
        run_mode = RunMode::EIGENVALUE;
68✔
466
      } else {
467
        node_mode = root.child("fixed_source");
×
468
        if (node_mode) {
×
469
          run_mode = RunMode::FIXED_SOURCE;
×
470
        } else {
471
          fatal_error("<eigenvalue> or <fixed_source> not specified.");
×
472
        }
473
      }
474
    }
475
  }
476

477
  // Check solver type
478
  if (check_for_node(root, "random_ray")) {
6,873✔
479
    solver_type = SolverType::RANDOM_RAY;
374✔
480
    if (run_CE)
374✔
481
      fatal_error("multi-group energy mode must be specified in settings XML "
×
482
                  "when using the random ray solver.");
483
  }
484

485
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
6,873✔
486
    // Read run parameters
487
    get_run_parameters(node_mode);
6,415✔
488

489
    // Check number of active batches, inactive batches, max lost particles and
490
    // particles
491
    if (n_batches <= n_inactive) {
6,415✔
492
      fatal_error("Number of active batches must be greater than zero.");
×
493
    } else if (n_inactive < 0) {
6,415✔
494
      fatal_error("Number of inactive batches must be non-negative.");
×
495
    } else if (n_particles <= 0) {
6,415✔
496
      fatal_error("Number of particles must be greater than zero.");
×
497
    } else if (max_lost_particles <= 0) {
6,415✔
498
      fatal_error("Number of max lost particles must be greater than zero.");
×
499
    } else if (rel_max_lost_particles <= 0.0 || rel_max_lost_particles >= 1.0) {
6,415✔
500
      fatal_error("Relative max lost particles must be between zero and one.");
×
501
    }
502
  }
503

504
  // Copy plotting random number seed if specified
505
  if (check_for_node(root, "plot_seed")) {
6,873✔
506
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
507
    model::plotter_seed = seed;
×
508
  }
509

510
  // Copy random number seed if specified
511
  if (check_for_node(root, "seed")) {
6,873✔
512
    auto seed = std::stoll(get_node_value(root, "seed"));
448✔
513
    openmc_set_seed(seed);
448✔
514
  }
515

516
  // Check for electron treatment
517
  if (check_for_node(root, "electron_treatment")) {
6,873✔
518
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
51✔
519
    if (temp_str == "led") {
51✔
520
      electron_treatment = ElectronTreatment::LED;
×
521
    } else if (temp_str == "ttb") {
51✔
522
      electron_treatment = ElectronTreatment::TTB;
51✔
523
    } else {
524
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
525
    }
526
  }
51✔
527

528
  // Check for photon transport
529
  if (check_for_node(root, "photon_transport")) {
6,873✔
530
    photon_transport = get_node_value_bool(root, "photon_transport");
189✔
531

532
    if (!run_CE && photon_transport) {
189✔
533
      fatal_error("Photon transport is not currently supported in "
×
534
                  "multigroup mode");
535
    }
536
  }
537

538
  // Number of bins for logarithmic grid
539
  if (check_for_node(root, "log_grid_bins")) {
6,873✔
540
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
17✔
541
    if (n_log_bins < 1) {
17✔
542
      fatal_error("Number of bins for logarithmic grid must be greater "
×
543
                  "than zero.");
544
    }
545
  }
546

547
  // Number of OpenMP threads
548
  if (check_for_node(root, "threads")) {
6,873✔
549
    if (mpi::master)
×
550
      warning("The <threads> element has been deprecated. Use "
×
551
              "the OMP_NUM_THREADS environment variable to set the number of "
552
              "threads.");
553
  }
554

555
  // ==========================================================================
556
  // EXTERNAL SOURCE
557

558
  // Get point to list of <source> elements and make sure there is at least one
559
  for (pugi::xml_node node : root.children("source")) {
13,436✔
560
    model::external_sources.push_back(Source::create(node));
6,574✔
561
  }
562

563
  // Check if the user has specified to read surface source
564
  if (check_for_node(root, "surf_source_read")) {
6,862✔
565
    surf_source_read = true;
17✔
566
    // Get surface source read node
567
    xml_node node_ssr = root.child("surf_source_read");
17✔
568

569
    std::string path = "surface_source.h5";
17✔
570
    // Check if the user has specified different file for surface source reading
571
    if (check_for_node(node_ssr, "path")) {
17✔
572
      path = get_node_value(node_ssr, "path", false, true);
17✔
573
    }
574
    model::external_sources.push_back(make_unique<FileSource>(path));
17✔
575
  }
17✔
576

577
  // Build probability mass function for sampling external sources
578
  vector<double> source_strengths;
6,862✔
579
  for (auto& s : model::external_sources) {
13,442✔
580
    source_strengths.push_back(s->strength());
6,580✔
581
  }
582
  model::external_sources_probability.assign(source_strengths);
6,862✔
583

584
  // If no source specified, default to isotropic point source at origin with
585
  // Watt spectrum. No default source is needed in random ray mode.
586
  if (model::external_sources.empty() &&
8,691✔
587
      settings::solver_type != SolverType::RANDOM_RAY) {
1,829✔
588
    double T[] {0.0};
1,727✔
589
    double p[] {1.0};
1,727✔
590
    model::external_sources.push_back(make_unique<IndependentSource>(
1,727✔
591
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
3,454✔
592
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
3,454✔
593
      UPtrDist {new Discrete(T, p, 1)}));
3,454✔
594
  }
595

596
  // Check if we want to write out source
597
  if (check_for_node(root, "write_initial_source")) {
6,862✔
598
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
599
  }
600

601
  // Survival biasing
602
  if (check_for_node(root, "survival_biasing")) {
6,862✔
603
    survival_biasing = get_node_value_bool(root, "survival_biasing");
190✔
604
  }
605

606
  // Probability tables
607
  if (check_for_node(root, "ptables")) {
6,862✔
608
    urr_ptables_on = get_node_value_bool(root, "ptables");
17✔
609
  }
610

611
  // Cutoffs
612
  if (check_for_node(root, "cutoff")) {
6,862✔
613
    xml_node node_cutoff = root.child("cutoff");
114✔
614
    if (check_for_node(node_cutoff, "weight")) {
114✔
615
      weight_cutoff = std::stod(get_node_value(node_cutoff, "weight"));
17✔
616
    }
617
    if (check_for_node(node_cutoff, "weight_avg")) {
114✔
618
      weight_survive = std::stod(get_node_value(node_cutoff, "weight_avg"));
17✔
619
    }
620
    if (check_for_node(node_cutoff, "energy_neutron")) {
114✔
621
      energy_cutoff[0] =
34✔
622
        std::stod(get_node_value(node_cutoff, "energy_neutron"));
17✔
623
    } else if (check_for_node(node_cutoff, "energy")) {
97✔
624
      warning("The use of an <energy> cutoff is deprecated and should "
×
625
              "be replaced by <energy_neutron>.");
626
      energy_cutoff[0] = std::stod(get_node_value(node_cutoff, "energy"));
×
627
    }
628
    if (check_for_node(node_cutoff, "energy_photon")) {
114✔
629
      energy_cutoff[1] =
126✔
630
        std::stod(get_node_value(node_cutoff, "energy_photon"));
63✔
631
    }
632
    if (check_for_node(node_cutoff, "energy_electron")) {
114✔
633
      energy_cutoff[2] =
×
634
        std::stof(get_node_value(node_cutoff, "energy_electron"));
×
635
    }
636
    if (check_for_node(node_cutoff, "energy_positron")) {
114✔
637
      energy_cutoff[3] =
×
638
        std::stod(get_node_value(node_cutoff, "energy_positron"));
×
639
    }
640
    if (check_for_node(node_cutoff, "time_neutron")) {
114✔
641
      time_cutoff[0] = std::stod(get_node_value(node_cutoff, "time_neutron"));
17✔
642
    }
643
    if (check_for_node(node_cutoff, "time_photon")) {
114✔
644
      time_cutoff[1] = std::stod(get_node_value(node_cutoff, "time_photon"));
×
645
    }
646
    if (check_for_node(node_cutoff, "time_electron")) {
114✔
647
      time_cutoff[2] = std::stod(get_node_value(node_cutoff, "time_electron"));
×
648
    }
649
    if (check_for_node(node_cutoff, "time_positron")) {
114✔
650
      time_cutoff[3] = std::stod(get_node_value(node_cutoff, "time_positron"));
×
651
    }
652
  }
653

654
  // Particle trace
655
  if (check_for_node(root, "trace")) {
6,862✔
656
    auto temp = get_node_array<int64_t>(root, "trace");
17✔
657
    if (temp.size() != 3) {
17✔
658
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
659
                  "batch, generation, and particle number.");
660
    }
661
    trace_batch = temp.at(0);
17✔
662
    trace_gen = temp.at(1);
17✔
663
    trace_particle = temp.at(2);
17✔
664
  }
17✔
665

666
  // Particle tracks
667
  if (check_for_node(root, "track")) {
6,862✔
668
    // Get values and make sure there are three per particle
669
    auto temp = get_node_array<int>(root, "track");
51✔
670
    if (temp.size() % 3 != 0) {
51✔
671
      fatal_error(
×
672
        "Number of integers specified in 'track' is not "
673
        "divisible by 3.  Please provide 3 integers per particle to be "
674
        "tracked.");
675
    }
676

677
    // Reshape into track_identifiers
678
    int n_tracks = temp.size() / 3;
51✔
679
    for (int i = 0; i < n_tracks; ++i) {
204✔
680
      track_identifiers.push_back(
153✔
681
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
153✔
682
    }
683
  }
51✔
684

685
  // Shannon entropy
686
  if (solver_type == SolverType::RANDOM_RAY) {
6,862✔
687
    if (check_for_node(root, "entropy_mesh")) {
374✔
688
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
689
                  "No user-defined entropy mesh is supported.");
690
    }
691
    entropy_on = true;
374✔
692
  } else if (solver_type == SolverType::MONTE_CARLO) {
6,488✔
693
    if (check_for_node(root, "entropy_mesh")) {
6,488✔
694
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
545✔
695
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
545✔
696
        fatal_error(fmt::format(
×
697
          "Mesh {} specified for Shannon entropy does not exist.", temp));
698
      }
699

700
      auto* m = dynamic_cast<RegularMesh*>(
545✔
701
        model::meshes[model::mesh_map.at(temp)].get());
545✔
702
      if (!m)
545✔
703
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
704
      simulation::entropy_mesh = m;
545✔
705

706
      // Turn on Shannon entropy calculation
707
      entropy_on = true;
545✔
708

709
    } else if (check_for_node(root, "entropy")) {
5,943✔
710
      fatal_error(
×
711
        "Specifying a Shannon entropy mesh via the <entropy> element "
712
        "is deprecated. Please create a mesh using <mesh> and then reference "
713
        "it by specifying its ID in an <entropy_mesh> element.");
714
    }
715
  }
716
  // Uniform fission source weighting mesh
717
  if (check_for_node(root, "ufs_mesh")) {
6,862✔
718
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
17✔
719
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
17✔
720
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
721
                              "method does not exist.",
722
        temp));
723
    }
724

725
    auto* m =
726
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
17✔
727
    if (!m)
17✔
728
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
729
    simulation::ufs_mesh = m;
17✔
730

731
    // Turn on uniform fission source weighting
732
    ufs_on = true;
17✔
733

734
  } else if (check_for_node(root, "uniform_fs")) {
6,845✔
735
    fatal_error(
×
736
      "Specifying a UFS mesh via the <uniform_fs> element "
737
      "is deprecated. Please create a mesh using <mesh> and then reference "
738
      "it by specifying its ID in a <ufs_mesh> element.");
739
  }
740

741
  // Check if the user has specified to write state points
742
  if (check_for_node(root, "state_point")) {
6,862✔
743

744
    // Get pointer to state_point node
745
    auto node_sp = root.child("state_point");
208✔
746

747
    // Determine number of batches at which to store state points
748
    if (check_for_node(node_sp, "batches")) {
208✔
749
      // User gave specific batches to write state points
750
      auto temp = get_node_array<int>(node_sp, "batches");
208✔
751
      for (const auto& b : temp) {
641✔
752
        statepoint_batch.insert(b);
433✔
753
      }
754
    } else {
208✔
755
      // If neither were specified, write state point at last batch
756
      statepoint_batch.insert(n_batches);
×
757
    }
758
  } else {
759
    // If no <state_point> tag was present, by default write state point at
760
    // last batch only
761
    statepoint_batch.insert(n_batches);
6,654✔
762
  }
763

764
  // Check if the user has specified to write source points
765
  if (check_for_node(root, "source_point")) {
6,862✔
766
    // Get source_point node
767
    xml_node node_sp = root.child("source_point");
102✔
768

769
    // Determine batches at which to store source points
770
    if (check_for_node(node_sp, "batches")) {
102✔
771
      // User gave specific batches to write source points
772
      auto temp = get_node_array<int>(node_sp, "batches");
51✔
773
      for (const auto& b : temp) {
136✔
774
        sourcepoint_batch.insert(b);
85✔
775
      }
776
    } else {
51✔
777
      // If neither were specified, write source points with state points
778
      sourcepoint_batch = statepoint_batch;
51✔
779
    }
780

781
    // Check if the user has specified to write binary source file
782
    if (check_for_node(node_sp, "separate")) {
102✔
783
      source_separate = get_node_value_bool(node_sp, "separate");
68✔
784
    }
785
    if (check_for_node(node_sp, "write")) {
102✔
786
      source_write = get_node_value_bool(node_sp, "write");
×
787
    }
788
    if (check_for_node(node_sp, "mcpl")) {
102✔
789
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
17✔
790

791
      // Make sure MCPL support is enabled
792
      if (source_mcpl_write && !MCPL_ENABLED) {
17✔
793
        fatal_error(
×
794
          "Your build of OpenMC does not support writing MCPL source files.");
795
      }
796
    }
797
    if (check_for_node(node_sp, "overwrite_latest")) {
102✔
798
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
17✔
799
      source_separate = source_latest;
17✔
800
    }
801
  } else {
802
    // If no <source_point> tag was present, by default we keep source bank in
803
    // statepoint file and write it out at statepoints intervals
804
    source_separate = false;
6,760✔
805
    sourcepoint_batch = statepoint_batch;
6,760✔
806
  }
807

808
  // Check is the user specified to convert strength to statistical weight
809
  if (check_for_node(root, "uniform_source_sampling")) {
6,862✔
810
    uniform_source_sampling =
60✔
811
      get_node_value_bool(root, "uniform_source_sampling");
60✔
812
  }
813

814
  // Check if the user has specified to write surface source
815
  if (check_for_node(root, "surf_source_write")) {
6,862✔
816
    surf_source_write = true;
439✔
817
    // Get surface source write node
818
    xml_node node_ssw = root.child("surf_source_write");
439✔
819

820
    // Determine surface ids at which crossing particles are to be banked.
821
    // If no surfaces are specified, all surfaces in the model will be used
822
    // to bank source points.
823
    if (check_for_node(node_ssw, "surface_ids")) {
439✔
824
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
209✔
825
      for (const auto& b : temp) {
1,065✔
826
        source_write_surf_id.insert(b);
856✔
827
      }
828
    }
209✔
829

830
    // Get maximum number of particles to be banked per surface
831
    if (check_for_node(node_ssw, "max_particles")) {
439✔
832
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
429✔
833
    } else {
834
      fatal_error("A maximum number of particles needs to be specified "
10✔
835
                  "using the 'max_particles' parameter to store surface "
836
                  "source points.");
837
    }
838

839
    // Get maximum number of surface source files to be created
840
    if (check_for_node(node_ssw, "max_source_files")) {
429✔
841
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
36✔
842
    } else {
843
      ssw_max_files = 1;
393✔
844
    }
845

846
    if (check_for_node(node_ssw, "mcpl")) {
429✔
847
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
×
848

849
      // Make sure MCPL support is enabled
850
      if (surf_mcpl_write && !MCPL_ENABLED) {
×
851
        fatal_error("Your build of OpenMC does not support writing MCPL "
×
852
                    "surface source files.");
853
      }
854
    }
855
    // Get cell information
856
    if (check_for_node(node_ssw, "cell")) {
429✔
857
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
114✔
858
      ssw_cell_type = SSWCellType::Both;
114✔
859
    }
860
    if (check_for_node(node_ssw, "cellfrom")) {
429✔
861
      if (ssw_cell_id != C_NONE) {
99✔
862
        fatal_error(
20✔
863
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
864
      }
865
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
79✔
866
      ssw_cell_type = SSWCellType::From;
79✔
867
    }
868
    if (check_for_node(node_ssw, "cellto")) {
409✔
869
      if (ssw_cell_id != C_NONE) {
78✔
870
        fatal_error(
20✔
871
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
872
      }
873
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
58✔
874
      ssw_cell_type = SSWCellType::To;
58✔
875
    }
876
  }
877

878
  // If source is not separate and is to be written out in the statepoint file,
879
  // make sure that the sourcepoint batch numbers are contained in the
880
  // statepoint list
881
  if (!source_separate) {
6,812✔
882
    for (const auto& b : sourcepoint_batch) {
13,628✔
883
      if (!contains(statepoint_batch, b)) {
6,901✔
884
        fatal_error(
×
885
          "Sourcepoint batches are not a subset of statepoint batches.");
886
      }
887
    }
888
  }
889

890
  // Check if the user has specified to not reduce tallies at the end of every
891
  // batch
892
  if (check_for_node(root, "no_reduce")) {
6,812✔
893
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
×
894
  }
895

896
  // Check if the user has specified to use confidence intervals for
897
  // uncertainties rather than standard deviations
898
  if (check_for_node(root, "confidence_intervals")) {
6,812✔
899
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
17✔
900
  }
901

902
  // Check for output options
903
  if (check_for_node(root, "output")) {
6,812✔
904
    // Get pointer to output node
905
    pugi::xml_node node_output = root.child("output");
397✔
906

907
    // Check for summary option
908
    if (check_for_node(node_output, "summary")) {
397✔
909
      output_summary = get_node_value_bool(node_output, "summary");
380✔
910
    }
911

912
    // Check for ASCII tallies output option
913
    if (check_for_node(node_output, "tallies")) {
397✔
914
      output_tallies = get_node_value_bool(node_output, "tallies");
17✔
915
    }
916

917
    // Set output directory if a path has been specified
918
    if (check_for_node(node_output, "path")) {
397✔
919
      path_output = get_node_value(node_output, "path");
×
920
      if (!ends_with(path_output, "/")) {
×
921
        path_output += "/";
×
922
      }
923
    }
924
  }
925

926
  // Resonance scattering parameters
927
  if (check_for_node(root, "resonance_scattering")) {
6,812✔
928
    xml_node node_res_scat = root.child("resonance_scattering");
17✔
929

930
    // See if resonance scattering is enabled
931
    if (check_for_node(node_res_scat, "enable")) {
17✔
932
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
17✔
933
    } else {
934
      res_scat_on = true;
×
935
    }
936

937
    // Determine what method is used
938
    if (check_for_node(node_res_scat, "method")) {
17✔
939
      auto temp = get_node_value(node_res_scat, "method", true, true);
17✔
940
      if (temp == "rvs") {
17✔
941
        res_scat_method = ResScatMethod::rvs;
17✔
942
      } else if (temp == "dbrc") {
×
943
        res_scat_method = ResScatMethod::dbrc;
×
944
      } else {
945
        fatal_error(
×
946
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
947
      }
948
    }
17✔
949

950
    // Minimum energy for resonance scattering
951
    if (check_for_node(node_res_scat, "energy_min")) {
17✔
952
      res_scat_energy_min =
17✔
953
        std::stod(get_node_value(node_res_scat, "energy_min"));
17✔
954
    }
955
    if (res_scat_energy_min < 0.0) {
17✔
956
      fatal_error("Lower resonance scattering energy bound is negative");
×
957
    }
958

959
    // Maximum energy for resonance scattering
960
    if (check_for_node(node_res_scat, "energy_max")) {
17✔
961
      res_scat_energy_max =
17✔
962
        std::stod(get_node_value(node_res_scat, "energy_max"));
17✔
963
    }
964
    if (res_scat_energy_max < res_scat_energy_min) {
17✔
965
      fatal_error("Upper resonance scattering energy bound is below the "
×
966
                  "lower resonance scattering energy bound.");
967
    }
968

969
    // Get resonance scattering nuclides
970
    if (check_for_node(node_res_scat, "nuclides")) {
17✔
971
      res_scat_nuclides =
972
        get_node_array<std::string>(node_res_scat, "nuclides");
17✔
973
    }
974
  }
975

976
  // Get volume calculations
977
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
7,161✔
978
    model::volume_calcs.emplace_back(node_vol);
349✔
979
  }
980

981
  // Get temperature settings
982
  if (check_for_node(root, "temperature_default")) {
6,812✔
983
    temperature_default =
187✔
984
      std::stod(get_node_value(root, "temperature_default"));
187✔
985
  }
986
  if (check_for_node(root, "temperature_method")) {
6,812✔
987
    auto temp = get_node_value(root, "temperature_method", true, true);
350✔
988
    if (temp == "nearest") {
350✔
989
      temperature_method = TemperatureMethod::NEAREST;
150✔
990
    } else if (temp == "interpolation") {
200✔
991
      temperature_method = TemperatureMethod::INTERPOLATION;
200✔
992
    } else {
993
      fatal_error("Unknown temperature method: " + temp);
×
994
    }
995
  }
350✔
996
  if (check_for_node(root, "temperature_tolerance")) {
6,812✔
997
    temperature_tolerance =
186✔
998
      std::stod(get_node_value(root, "temperature_tolerance"));
186✔
999
  }
1000
  if (check_for_node(root, "temperature_multipole")) {
6,812✔
1001
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
34✔
1002

1003
    // Multipole currently doesn't work with photon transport
1004
    if (temperature_multipole && photon_transport) {
34✔
1005
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1006
                  "photon transport.");
1007
    }
1008
  }
1009
  if (check_for_node(root, "temperature_range")) {
6,812✔
1010
    auto range = get_node_array<double>(root, "temperature_range");
×
1011
    temperature_range[0] = range.at(0);
×
1012
    temperature_range[1] = range.at(1);
×
1013
  }
1014

1015
  // Check for tabular_legendre options
1016
  if (check_for_node(root, "tabular_legendre")) {
6,812✔
1017
    // Get pointer to tabular_legendre node
1018
    xml_node node_tab_leg = root.child("tabular_legendre");
102✔
1019

1020
    // Check for enable option
1021
    if (check_for_node(node_tab_leg, "enable")) {
102✔
1022
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
102✔
1023
    }
1024

1025
    // Check for the number of points
1026
    if (check_for_node(node_tab_leg, "num_points")) {
102✔
1027
      legendre_to_tabular_points =
×
1028
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
1029
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
1030
        fatal_error(
×
1031
          "The 'num_points' subelement/attribute of the "
1032
          "<tabular_legendre> element must contain a value greater than 1");
1033
      }
1034
    }
1035
  }
1036

1037
  // Check whether create delayed neutrons in fission
1038
  if (check_for_node(root, "create_delayed_neutrons")) {
6,812✔
1039
    create_delayed_neutrons =
×
1040
      get_node_value_bool(root, "create_delayed_neutrons");
×
1041
  }
1042

1043
  // Check whether create fission sites
1044
  if (run_mode == RunMode::FIXED_SOURCE) {
6,812✔
1045
    if (check_for_node(root, "create_fission_neutrons")) {
2,138✔
1046
      create_fission_neutrons =
17✔
1047
        get_node_value_bool(root, "create_fission_neutrons");
17✔
1048
    }
1049
  }
1050

1051
  // Check whether to scale fission photon yields
1052
  if (check_for_node(root, "delayed_photon_scaling")) {
6,812✔
1053
    delayed_photon_scaling =
×
1054
      get_node_value_bool(root, "delayed_photon_scaling");
×
1055
  }
1056

1057
  // Check whether to use event-based parallelism
1058
  if (check_for_node(root, "event_based")) {
6,812✔
1059
    event_based = get_node_value_bool(root, "event_based");
×
1060
  }
1061

1062
  // Check whether material cell offsets should be generated
1063
  if (check_for_node(root, "material_cell_offsets")) {
6,812✔
1064
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1065
  }
1066

1067
  // Weight window information
1068
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
6,897✔
1069
    variance_reduction::weight_windows.emplace_back(
85✔
1070
      std::make_unique<WeightWindows>(node_ww));
170✔
1071
  }
1072

1073
  // Enable weight windows by default if one or more are present
1074
  if (variance_reduction::weight_windows.size() > 0)
6,812✔
1075
    settings::weight_windows_on = true;
56✔
1076

1077
  // read weight windows from file
1078
  if (check_for_node(root, "weight_windows_file")) {
6,812✔
1079
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1080
  }
1081

1082
  // read settings for weight windows value, this will override
1083
  // the automatic setting even if weight windows are present
1084
  if (check_for_node(root, "weight_windows_on")) {
6,812✔
1085
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
39✔
1086
  }
1087

1088
  if (check_for_node(root, "max_history_splits")) {
6,812✔
1089
    settings::max_history_splits =
233✔
1090
      std::stoi(get_node_value(root, "max_history_splits"));
233✔
1091
  }
1092

1093
  if (check_for_node(root, "max_tracks")) {
6,812✔
1094
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
51✔
1095
  }
1096

1097
  // Create weight window generator objects
1098
  if (check_for_node(root, "weight_window_generators")) {
6,812✔
1099
    auto wwgs_node = root.child("weight_window_generators");
36✔
1100
    for (pugi::xml_node node_wwg :
36✔
1101
      wwgs_node.children("weight_windows_generator")) {
108✔
1102
      variance_reduction::weight_windows_generators.emplace_back(
36✔
1103
        std::make_unique<WeightWindowsGenerator>(node_wwg));
72✔
1104
    }
1105
    // if any of the weight windows are intended to be generated otf, make sure
1106
    // they're applied
1107
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
36✔
1108
      if (wwg->on_the_fly_) {
36✔
1109
        settings::weight_windows_on = true;
36✔
1110
        break;
36✔
1111
      }
1112
    }
1113
  }
1114

1115
  // Set up weight window checkpoints
1116
  if (check_for_node(root, "weight_window_checkpoints")) {
6,812✔
1117
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
×
1118
    if (check_for_node(ww_checkpoints, "collision")) {
×
1119
      weight_window_checkpoint_collision =
×
1120
        get_node_value_bool(ww_checkpoints, "collision");
×
1121
    }
1122
    if (check_for_node(ww_checkpoints, "surface")) {
×
1123
      weight_window_checkpoint_surface =
×
1124
        get_node_value_bool(ww_checkpoints, "surface");
×
1125
    }
1126
  }
1127
}
6,812✔
1128

1129
void free_memory_settings()
6,957✔
1130
{
1131
  settings::statepoint_batch.clear();
6,957✔
1132
  settings::sourcepoint_batch.clear();
6,957✔
1133
  settings::source_write_surf_id.clear();
6,957✔
1134
  settings::res_scat_nuclides.clear();
6,957✔
1135
}
6,957✔
1136

1137
//==============================================================================
1138
// C API functions
1139
//==============================================================================
1140

1141
extern "C" int openmc_set_n_batches(
60✔
1142
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1143
{
1144
  if (settings::n_inactive >= n_batches) {
60✔
1145
    set_errmsg("Number of active batches must be greater than zero.");
12✔
1146
    return OPENMC_E_INVALID_ARGUMENT;
12✔
1147
  }
1148

1149
  if (simulation::current_batch >= n_batches) {
48✔
1150
    set_errmsg("Number of batches must be greater than current batch.");
12✔
1151
    return OPENMC_E_INVALID_ARGUMENT;
12✔
1152
  }
1153

1154
  if (!settings::trigger_on) {
36✔
1155
    // Set n_batches and n_max_batches to same value
1156
    settings::n_batches = n_batches;
12✔
1157
    settings::n_max_batches = n_batches;
12✔
1158
  } else {
1159
    // Set n_batches and n_max_batches based on value of set_max_batches
1160
    if (set_max_batches) {
24✔
1161
      settings::n_max_batches = n_batches;
12✔
1162
    } else {
1163
      settings::n_batches = n_batches;
12✔
1164
    }
1165
  }
1166

1167
  // Update size of k_generation and entropy
1168
  int m = settings::n_max_batches * settings::gen_per_batch;
36✔
1169
  simulation::k_generation.reserve(m);
36✔
1170
  simulation::entropy.reserve(m);
36✔
1171

1172
  // Add value of n_batches to statepoint_batch
1173
  if (add_statepoint_batch &&
60✔
1174
      !(contains(settings::statepoint_batch, n_batches)))
24✔
1175
    settings::statepoint_batch.insert(n_batches);
24✔
1176

1177
  return 0;
36✔
1178
}
1179

1180
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
5,460✔
1181
{
1182
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
5,460✔
1183

1184
  return 0;
5,460✔
1185
}
1186

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