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

openmc-dev / openmc / 10586562087

27 Aug 2024 10:05PM UTC coverage: 84.707% (-0.2%) from 84.9%
10586562087

Pull #3112

github

web-flow
Merge f7f32bf18 into 5bc04b5d7
Pull Request #3112: Revamp CI with dependency and Python caching for efficient installs

49553 of 58499 relevant lines covered (84.71%)

34324762.08 hits per line

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

78.61
/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 ufs_on {false};
76
bool urr_ptables_on {true};
77
bool weight_windows_on {false};
78
bool weight_window_checkpoint_surface {false};
79
bool weight_window_checkpoint_collision {true};
80
bool write_all_tracks {false};
81
bool write_initial_source {false};
82

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

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

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

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

137
} // namespace settings
138

139
//==============================================================================
140
// Functions
141
//==============================================================================
142

143
void get_run_parameters(pugi::xml_node node_base)
6,185✔
144
{
145
  using namespace settings;
146
  using namespace pugi;
147

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

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

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

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

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

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

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

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

195
  // Get number of inactive batches
196
  if (run_mode == RunMode::EIGENVALUE ||
6,185✔
197
      solver_type == SolverType::RANDOM_RAY) {
2,001✔
198
    if (check_for_node(node_base, "inactive")) {
4,439✔
199
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,309✔
200
    }
201
    if (check_for_node(node_base, "generations_per_batch")) {
4,439✔
202
      gen_per_batch =
17✔
203
        std::stoi(get_node_value(node_base, "generations_per_batch"));
17✔
204
    }
205

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

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

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

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

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

306
void read_settings_xml()
1,762✔
307
{
308
  using namespace settings;
309
  using namespace pugi;
310
  // Check if settings.xml exists
311
  std::string filename = settings::path_input + "settings.xml";
1,762✔
312
  if (!file_exists(filename)) {
1,762✔
313
    if (run_mode != RunMode::PLOTTING) {
24✔
314
      fatal_error("Could not find any XML input files! In order to run OpenMC, "
×
315
                  "you first need a set of input files; at a minimum, this "
316
                  "includes settings.xml, geometry.xml, and materials.xml or a "
317
                  "single model XML file. Please consult the user's guide at "
318
                  "https://docs.openmc.org for further information.");
319
    } else {
320
      // The settings.xml file is optional if we just want to make a plot.
321
      return;
24✔
322
    }
323
  }
324

325
  // Parse settings.xml file
326
  xml_document doc;
1,738✔
327
  auto result = doc.load_file(filename.c_str());
1,738✔
328
  if (!result) {
1,738✔
329
    fatal_error("Error processing settings.xml file.");
×
330
  }
331

332
  // Get root element
333
  xml_node root = doc.document_element();
1,738✔
334

335
  // Verbosity
336
  if (check_for_node(root, "verbosity")) {
1,738✔
337
    verbosity = std::stoi(get_node_value(root, "verbosity"));
216✔
338
  }
339

340
  // To this point, we haven't displayed any output since we didn't know what
341
  // the verbosity is. Now that we checked for it, show the title if necessary
342
  if (mpi::master) {
1,738✔
343
    if (verbosity >= 2)
1,508✔
344
      title();
1,302✔
345
  }
346

347
  write_message("Reading settings XML file...", 5);
1,738✔
348

349
  read_settings_xml(root);
1,738✔
350
}
1,751✔
351

352
void read_settings_xml(pugi::xml_node root)
6,535✔
353
{
354
  using namespace settings;
355
  using namespace pugi;
356

357
  // Find if a multi-group or continuous-energy simulation is desired
358
  if (check_for_node(root, "energy_mode")) {
6,535✔
359
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
867✔
360
    if (temp_str == "mg" || temp_str == "multi-group") {
867✔
361
      run_CE = false;
867✔
362
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
363
      run_CE = true;
×
364
    }
365
  }
867✔
366

367
  // Check for user meshes and allocate
368
  read_meshes(root);
6,535✔
369

370
  // Look for deprecated cross_sections.xml file in settings.xml
371
  if (check_for_node(root, "cross_sections")) {
6,535✔
372
    warning(
×
373
      "Setting cross_sections in settings.xml has been deprecated."
374
      " The cross_sections are now set in materials.xml and the "
375
      "cross_sections input to materials.xml and the OPENMC_CROSS_SECTIONS"
376
      " environment variable will take precendent over setting "
377
      "cross_sections in settings.xml.");
378
    path_cross_sections = get_node_value(root, "cross_sections");
×
379
  }
380

381
  if (!run_CE) {
6,535✔
382
    // Scattering Treatments
383
    if (check_for_node(root, "max_order")) {
867✔
384
      max_order = std::stoi(get_node_value(root, "max_order"));
17✔
385
    } else {
386
      // Set to default of largest int - 1, which means to use whatever is
387
      // contained in library. This is largest int - 1 because for legendre
388
      // scattering, a value of 1 is added to the order; adding 1 to the largest
389
      // int gets you the largest negative integer, which is not what we want.
390
      max_order = std::numeric_limits<int>::max() - 1;
850✔
391
    }
392
  }
393

394
  // Check for a trigger node and get trigger information
395
  if (check_for_node(root, "trigger")) {
6,535✔
396
    xml_node node_trigger = root.child("trigger");
162✔
397

398
    // Check if trigger(s) are to be turned on
399
    trigger_on = get_node_value_bool(node_trigger, "active");
162✔
400

401
    if (trigger_on) {
162✔
402
      if (check_for_node(node_trigger, "max_batches")) {
145✔
403
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
145✔
404
      } else {
405
        fatal_error("<max_batches> must be specified with triggers");
×
406
      }
407

408
      // Get the batch interval to check triggers
409
      if (!check_for_node(node_trigger, "batch_interval")) {
145✔
410
        trigger_predict = true;
17✔
411
      } else {
412
        trigger_batch_interval =
128✔
413
          std::stoi(get_node_value(node_trigger, "batch_interval"));
128✔
414
        if (trigger_batch_interval <= 0) {
128✔
415
          fatal_error("Trigger batch interval must be greater than zero");
×
416
        }
417
      }
418
    }
419
  }
420

421
  // Check run mode if it hasn't been set from the command line
422
  xml_node node_mode;
6,535✔
423
  if (run_mode == RunMode::UNSET) {
6,535✔
424
    if (check_for_node(root, "run_mode")) {
6,219✔
425
      std::string temp_str = get_node_value(root, "run_mode", true, true);
6,151✔
426
      if (temp_str == "eigenvalue") {
6,151✔
427
        run_mode = RunMode::EIGENVALUE;
4,116✔
428
      } else if (temp_str == "fixed source") {
2,035✔
429
        run_mode = RunMode::FIXED_SOURCE;
2,001✔
430
      } else if (temp_str == "plot") {
34✔
431
        run_mode = RunMode::PLOTTING;
×
432
      } else if (temp_str == "particle restart") {
34✔
433
        run_mode = RunMode::PARTICLE;
×
434
      } else if (temp_str == "volume") {
34✔
435
        run_mode = RunMode::VOLUME;
34✔
436
      } else {
437
        fatal_error("Unrecognized run mode: " + temp_str);
×
438
      }
439

440
      // Assume XML specifies <particles>, <batches>, etc. directly
441
      node_mode = root;
6,151✔
442
    } else {
6,151✔
443
      warning("<run_mode> should be specified.");
68✔
444

445
      // Make sure that either eigenvalue or fixed source was specified
446
      node_mode = root.child("eigenvalue");
68✔
447
      if (node_mode) {
68✔
448
        run_mode = RunMode::EIGENVALUE;
68✔
449
      } else {
450
        node_mode = root.child("fixed_source");
×
451
        if (node_mode) {
×
452
          run_mode = RunMode::FIXED_SOURCE;
×
453
        } else {
454
          fatal_error("<eigenvalue> or <fixed_source> not specified.");
×
455
        }
456
      }
457
    }
458
  }
459

460
  // Check solver type
461
  if (check_for_node(root, "random_ray")) {
6,535✔
462
    solver_type = SolverType::RANDOM_RAY;
323✔
463
    if (run_CE)
323✔
464
      fatal_error("multi-group energy mode must be specified in settings XML "
×
465
                  "when using the random ray solver.");
466
  }
467

468
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
6,535✔
469
    // Read run parameters
470
    get_run_parameters(node_mode);
6,185✔
471

472
    // Check number of active batches, inactive batches, max lost particles and
473
    // particles
474
    if (n_batches <= n_inactive) {
6,185✔
475
      fatal_error("Number of active batches must be greater than zero.");
×
476
    } else if (n_inactive < 0) {
6,185✔
477
      fatal_error("Number of inactive batches must be non-negative.");
×
478
    } else if (n_particles <= 0) {
6,185✔
479
      fatal_error("Number of particles must be greater than zero.");
×
480
    } else if (max_lost_particles <= 0) {
6,185✔
481
      fatal_error("Number of max lost particles must be greater than zero.");
×
482
    } else if (rel_max_lost_particles <= 0.0 || rel_max_lost_particles >= 1.0) {
6,185✔
483
      fatal_error("Relative max lost particles must be between zero and one.");
×
484
    }
485
  }
486

487
  // Copy plotting random number seed if specified
488
  if (check_for_node(root, "plot_seed")) {
6,535✔
489
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
490
    model::plotter_seed = seed;
×
491
  }
492

493
  // Copy random number seed if specified
494
  if (check_for_node(root, "seed")) {
6,535✔
495
    auto seed = std::stoll(get_node_value(root, "seed"));
413✔
496
    openmc_set_seed(seed);
413✔
497
  }
498

499
  // Check for electron treatment
500
  if (check_for_node(root, "electron_treatment")) {
6,535✔
501
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
51✔
502
    if (temp_str == "led") {
51✔
503
      electron_treatment = ElectronTreatment::LED;
×
504
    } else if (temp_str == "ttb") {
51✔
505
      electron_treatment = ElectronTreatment::TTB;
51✔
506
    } else {
507
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
508
    }
509
  }
51✔
510

511
  // Check for photon transport
512
  if (check_for_node(root, "photon_transport")) {
6,535✔
513
    photon_transport = get_node_value_bool(root, "photon_transport");
189✔
514

515
    if (!run_CE && photon_transport) {
189✔
516
      fatal_error("Photon transport is not currently supported in "
×
517
                  "multigroup mode");
518
    }
519
  }
520

521
  // Number of bins for logarithmic grid
522
  if (check_for_node(root, "log_grid_bins")) {
6,535✔
523
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
17✔
524
    if (n_log_bins < 1) {
17✔
525
      fatal_error("Number of bins for logarithmic grid must be greater "
×
526
                  "than zero.");
527
    }
528
  }
529

530
  // Number of OpenMP threads
531
  if (check_for_node(root, "threads")) {
6,535✔
532
    if (mpi::master)
×
533
      warning("The <threads> element has been deprecated. Use "
×
534
              "the OMP_NUM_THREADS environment variable to set the number of "
535
              "threads.");
536
  }
537

538
  // ==========================================================================
539
  // EXTERNAL SOURCE
540

541
  // Get point to list of <source> elements and make sure there is at least one
542
  for (pugi::xml_node node : root.children("source")) {
12,853✔
543
    model::external_sources.push_back(Source::create(node));
6,329✔
544
  }
545

546
  // Check if the user has specified to read surface source
547
  if (check_for_node(root, "surf_source_read")) {
6,524✔
548
    surf_source_read = true;
17✔
549
    // Get surface source read node
550
    xml_node node_ssr = root.child("surf_source_read");
17✔
551

552
    std::string path = "surface_source.h5";
17✔
553
    // Check if the user has specified different file for surface source reading
554
    if (check_for_node(node_ssr, "path")) {
17✔
555
      path = get_node_value(node_ssr, "path", false, true);
17✔
556
    }
557
    model::external_sources.push_back(make_unique<FileSource>(path));
17✔
558
  }
17✔
559

560
  // If no source specified, default to isotropic point source at origin with
561
  // Watt spectrum. No default source is needed in random ray mode.
562
  if (model::external_sources.empty() &&
8,248✔
563
      settings::solver_type != SolverType::RANDOM_RAY) {
1,724✔
564
    double T[] {0.0};
1,656✔
565
    double p[] {1.0};
1,656✔
566
    model::external_sources.push_back(make_unique<IndependentSource>(
1,656✔
567
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
3,312✔
568
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
3,312✔
569
      UPtrDist {new Discrete(T, p, 1)}));
3,312✔
570
  }
571

572
  // Check if we want to write out source
573
  if (check_for_node(root, "write_initial_source")) {
6,524✔
574
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
575
  }
576

577
  // Survival biasing
578
  if (check_for_node(root, "survival_biasing")) {
6,524✔
579
    survival_biasing = get_node_value_bool(root, "survival_biasing");
190✔
580
  }
581

582
  // Probability tables
583
  if (check_for_node(root, "ptables")) {
6,524✔
584
    urr_ptables_on = get_node_value_bool(root, "ptables");
17✔
585
  }
586

587
  // Cutoffs
588
  if (check_for_node(root, "cutoff")) {
6,524✔
589
    xml_node node_cutoff = root.child("cutoff");
114✔
590
    if (check_for_node(node_cutoff, "weight")) {
114✔
591
      weight_cutoff = std::stod(get_node_value(node_cutoff, "weight"));
17✔
592
    }
593
    if (check_for_node(node_cutoff, "weight_avg")) {
114✔
594
      weight_survive = std::stod(get_node_value(node_cutoff, "weight_avg"));
17✔
595
    }
596
    if (check_for_node(node_cutoff, "energy_neutron")) {
114✔
597
      energy_cutoff[0] =
34✔
598
        std::stod(get_node_value(node_cutoff, "energy_neutron"));
17✔
599
    } else if (check_for_node(node_cutoff, "energy")) {
97✔
600
      warning("The use of an <energy> cutoff is deprecated and should "
×
601
              "be replaced by <energy_neutron>.");
602
      energy_cutoff[0] = std::stod(get_node_value(node_cutoff, "energy"));
×
603
    }
604
    if (check_for_node(node_cutoff, "energy_photon")) {
114✔
605
      energy_cutoff[1] =
126✔
606
        std::stod(get_node_value(node_cutoff, "energy_photon"));
63✔
607
    }
608
    if (check_for_node(node_cutoff, "energy_electron")) {
114✔
609
      energy_cutoff[2] =
×
610
        std::stof(get_node_value(node_cutoff, "energy_electron"));
×
611
    }
612
    if (check_for_node(node_cutoff, "energy_positron")) {
114✔
613
      energy_cutoff[3] =
×
614
        std::stod(get_node_value(node_cutoff, "energy_positron"));
×
615
    }
616
    if (check_for_node(node_cutoff, "time_neutron")) {
114✔
617
      time_cutoff[0] = std::stod(get_node_value(node_cutoff, "time_neutron"));
17✔
618
    }
619
    if (check_for_node(node_cutoff, "time_photon")) {
114✔
620
      time_cutoff[1] = std::stod(get_node_value(node_cutoff, "time_photon"));
×
621
    }
622
    if (check_for_node(node_cutoff, "time_electron")) {
114✔
623
      time_cutoff[2] = std::stod(get_node_value(node_cutoff, "time_electron"));
×
624
    }
625
    if (check_for_node(node_cutoff, "time_positron")) {
114✔
626
      time_cutoff[3] = std::stod(get_node_value(node_cutoff, "time_positron"));
×
627
    }
628
  }
629

630
  // Particle trace
631
  if (check_for_node(root, "trace")) {
6,524✔
632
    auto temp = get_node_array<int64_t>(root, "trace");
17✔
633
    if (temp.size() != 3) {
17✔
634
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
635
                  "batch, generation, and particle number.");
636
    }
637
    trace_batch = temp.at(0);
17✔
638
    trace_gen = temp.at(1);
17✔
639
    trace_particle = temp.at(2);
17✔
640
  }
17✔
641

642
  // Particle tracks
643
  if (check_for_node(root, "track")) {
6,524✔
644
    // Get values and make sure there are three per particle
645
    auto temp = get_node_array<int>(root, "track");
51✔
646
    if (temp.size() % 3 != 0) {
51✔
647
      fatal_error(
×
648
        "Number of integers specified in 'track' is not "
649
        "divisible by 3.  Please provide 3 integers per particle to be "
650
        "tracked.");
651
    }
652

653
    // Reshape into track_identifiers
654
    int n_tracks = temp.size() / 3;
51✔
655
    for (int i = 0; i < n_tracks; ++i) {
204✔
656
      track_identifiers.push_back(
153✔
657
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
153✔
658
    }
659
  }
51✔
660

661
  // Shannon entropy
662
  if (solver_type == SolverType::RANDOM_RAY) {
6,524✔
663
    if (check_for_node(root, "entropy_mesh")) {
323✔
664
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
665
                  "No user-defined entropy mesh is supported.");
666
    }
667
    entropy_on = true;
323✔
668
  } else if (solver_type == SolverType::MONTE_CARLO) {
6,201✔
669
    if (check_for_node(root, "entropy_mesh")) {
6,201✔
670
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
560✔
671
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
560✔
672
        fatal_error(fmt::format(
×
673
          "Mesh {} specified for Shannon entropy does not exist.", temp));
674
      }
675

676
      auto* m = dynamic_cast<RegularMesh*>(
560✔
677
        model::meshes[model::mesh_map.at(temp)].get());
560✔
678
      if (!m)
560✔
679
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
680
      simulation::entropy_mesh = m;
560✔
681

682
      // Turn on Shannon entropy calculation
683
      entropy_on = true;
560✔
684

685
    } else if (check_for_node(root, "entropy")) {
5,641✔
686
      fatal_error(
×
687
        "Specifying a Shannon entropy mesh via the <entropy> element "
688
        "is deprecated. Please create a mesh using <mesh> and then reference "
689
        "it by specifying its ID in an <entropy_mesh> element.");
690
    }
691
  }
692
  // Uniform fission source weighting mesh
693
  if (check_for_node(root, "ufs_mesh")) {
6,524✔
694
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
17✔
695
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
17✔
696
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
697
                              "method does not exist.",
698
        temp));
699
    }
700

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

707
    // Turn on uniform fission source weighting
708
    ufs_on = true;
17✔
709

710
  } else if (check_for_node(root, "uniform_fs")) {
6,507✔
711
    fatal_error(
×
712
      "Specifying a UFS mesh via the <uniform_fs> element "
713
      "is deprecated. Please create a mesh using <mesh> and then reference "
714
      "it by specifying its ID in a <ufs_mesh> element.");
715
  }
716

717
  // Check if the user has specified to write state points
718
  if (check_for_node(root, "state_point")) {
6,524✔
719

720
    // Get pointer to state_point node
721
    auto node_sp = root.child("state_point");
210✔
722

723
    // Determine number of batches at which to store state points
724
    if (check_for_node(node_sp, "batches")) {
210✔
725
      // User gave specific batches to write state points
726
      auto temp = get_node_array<int>(node_sp, "batches");
210✔
727
      for (const auto& b : temp) {
647✔
728
        statepoint_batch.insert(b);
437✔
729
      }
730
    } else {
210✔
731
      // If neither were specified, write state point at last batch
732
      statepoint_batch.insert(n_batches);
×
733
    }
734
  } else {
735
    // If no <state_point> tag was present, by default write state point at
736
    // last batch only
737
    statepoint_batch.insert(n_batches);
6,314✔
738
  }
739

740
  // Check if the user has specified to write source points
741
  if (check_for_node(root, "source_point")) {
6,524✔
742
    // Get source_point node
743
    xml_node node_sp = root.child("source_point");
102✔
744

745
    // Determine batches at which to store source points
746
    if (check_for_node(node_sp, "batches")) {
102✔
747
      // User gave specific batches to write source points
748
      auto temp = get_node_array<int>(node_sp, "batches");
51✔
749
      for (const auto& b : temp) {
136✔
750
        sourcepoint_batch.insert(b);
85✔
751
      }
752
    } else {
51✔
753
      // If neither were specified, write source points with state points
754
      sourcepoint_batch = statepoint_batch;
51✔
755
    }
756

757
    // Check if the user has specified to write binary source file
758
    if (check_for_node(node_sp, "separate")) {
102✔
759
      source_separate = get_node_value_bool(node_sp, "separate");
68✔
760
    }
761
    if (check_for_node(node_sp, "write")) {
102✔
762
      source_write = get_node_value_bool(node_sp, "write");
×
763
    }
764
    if (check_for_node(node_sp, "mcpl")) {
102✔
765
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
17✔
766

767
      // Make sure MCPL support is enabled
768
      if (source_mcpl_write && !MCPL_ENABLED) {
17✔
769
        fatal_error(
×
770
          "Your build of OpenMC does not support writing MCPL source files.");
771
      }
772
    }
773
    if (check_for_node(node_sp, "overwrite_latest")) {
102✔
774
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
17✔
775
      source_separate = source_latest;
17✔
776
    }
777
  } else {
778
    // If no <source_point> tag was present, by default we keep source bank in
779
    // statepoint file and write it out at statepoints intervals
780
    source_separate = false;
6,422✔
781
    sourcepoint_batch = statepoint_batch;
6,422✔
782
  }
783

784
  // Check if the user has specified to write surface source
785
  if (check_for_node(root, "surf_source_write")) {
6,524✔
786
    surf_source_write = true;
343✔
787
    // Get surface source write node
788
    xml_node node_ssw = root.child("surf_source_write");
343✔
789

790
    // Determine surface ids at which crossing particles are to be banked.
791
    // If no surfaces are specified, all surfaces in the model will be used
792
    // to bank source points.
793
    if (check_for_node(node_ssw, "surface_ids")) {
343✔
794
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
209✔
795
      for (const auto& b : temp) {
1,065✔
796
        source_write_surf_id.insert(b);
856✔
797
      }
798
    }
209✔
799

800
    // Get maximum number of particles to be banked per surface
801
    if (check_for_node(node_ssw, "max_particles")) {
343✔
802
      max_surface_particles =
333✔
803
        std::stoll(get_node_value(node_ssw, "max_particles"));
333✔
804
    } else {
805
      fatal_error("A maximum number of particles needs to be specified "
10✔
806
                  "using the 'max_particles' parameter to store surface "
807
                  "source points.");
808
    }
809

810
    if (check_for_node(node_ssw, "mcpl")) {
333✔
811
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
×
812

813
      // Make sure MCPL support is enabled
814
      if (surf_mcpl_write && !MCPL_ENABLED) {
×
815
        fatal_error("Your build of OpenMC does not support writing MCPL "
×
816
                    "surface source files.");
817
      }
818
    }
819
    // Get cell information
820
    if (check_for_node(node_ssw, "cell")) {
333✔
821
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
114✔
822
      ssw_cell_type = SSWCellType::Both;
114✔
823
    }
824
    if (check_for_node(node_ssw, "cellfrom")) {
333✔
825
      if (ssw_cell_id != C_NONE) {
99✔
826
        fatal_error(
20✔
827
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
828
      }
829
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
79✔
830
      ssw_cell_type = SSWCellType::From;
79✔
831
    }
832
    if (check_for_node(node_ssw, "cellto")) {
313✔
833
      if (ssw_cell_id != C_NONE) {
78✔
834
        fatal_error(
20✔
835
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
836
      }
837
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
58✔
838
      ssw_cell_type = SSWCellType::To;
58✔
839
    }
840
  }
841

842
  // If source is not separate and is to be written out in the statepoint file,
843
  // make sure that the sourcepoint batch numbers are contained in the
844
  // statepoint list
845
  if (!source_separate) {
6,474✔
846
    for (const auto& b : sourcepoint_batch) {
12,954✔
847
      if (!contains(statepoint_batch, b)) {
6,565✔
848
        fatal_error(
×
849
          "Sourcepoint batches are not a subset of statepoint batches.");
850
      }
851
    }
852
  }
853

854
  // Check if the user has specified to not reduce tallies at the end of every
855
  // batch
856
  if (check_for_node(root, "no_reduce")) {
6,474✔
857
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
×
858
  }
859

860
  // Check if the user has specified to use confidence intervals for
861
  // uncertainties rather than standard deviations
862
  if (check_for_node(root, "confidence_intervals")) {
6,474✔
863
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
17✔
864
  }
865

866
  // Check for output options
867
  if (check_for_node(root, "output")) {
6,474✔
868
    // Get pointer to output node
869
    pugi::xml_node node_output = root.child("output");
397✔
870

871
    // Check for summary option
872
    if (check_for_node(node_output, "summary")) {
397✔
873
      output_summary = get_node_value_bool(node_output, "summary");
380✔
874
    }
875

876
    // Check for ASCII tallies output option
877
    if (check_for_node(node_output, "tallies")) {
397✔
878
      output_tallies = get_node_value_bool(node_output, "tallies");
17✔
879
    }
880

881
    // Set output directory if a path has been specified
882
    if (check_for_node(node_output, "path")) {
397✔
883
      path_output = get_node_value(node_output, "path");
×
884
      if (!ends_with(path_output, "/")) {
×
885
        path_output += "/";
×
886
      }
887
    }
888
  }
889

890
  // Resonance scattering parameters
891
  if (check_for_node(root, "resonance_scattering")) {
6,474✔
892
    xml_node node_res_scat = root.child("resonance_scattering");
17✔
893

894
    // See if resonance scattering is enabled
895
    if (check_for_node(node_res_scat, "enable")) {
17✔
896
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
17✔
897
    } else {
898
      res_scat_on = true;
×
899
    }
900

901
    // Determine what method is used
902
    if (check_for_node(node_res_scat, "method")) {
17✔
903
      auto temp = get_node_value(node_res_scat, "method", true, true);
17✔
904
      if (temp == "rvs") {
17✔
905
        res_scat_method = ResScatMethod::rvs;
17✔
906
      } else if (temp == "dbrc") {
×
907
        res_scat_method = ResScatMethod::dbrc;
×
908
      } else {
909
        fatal_error(
×
910
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
911
      }
912
    }
17✔
913

914
    // Minimum energy for resonance scattering
915
    if (check_for_node(node_res_scat, "energy_min")) {
17✔
916
      res_scat_energy_min =
17✔
917
        std::stod(get_node_value(node_res_scat, "energy_min"));
17✔
918
    }
919
    if (res_scat_energy_min < 0.0) {
17✔
920
      fatal_error("Lower resonance scattering energy bound is negative");
×
921
    }
922

923
    // Maximum energy for resonance scattering
924
    if (check_for_node(node_res_scat, "energy_max")) {
17✔
925
      res_scat_energy_max =
17✔
926
        std::stod(get_node_value(node_res_scat, "energy_max"));
17✔
927
    }
928
    if (res_scat_energy_max < res_scat_energy_min) {
17✔
929
      fatal_error("Upper resonance scattering energy bound is below the "
×
930
                  "lower resonance scattering energy bound.");
931
    }
932

933
    // Get resonance scattering nuclides
934
    if (check_for_node(node_res_scat, "nuclides")) {
17✔
935
      res_scat_nuclides =
936
        get_node_array<std::string>(node_res_scat, "nuclides");
17✔
937
    }
938
  }
939

940
  // Get volume calculations
941
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
6,804✔
942
    model::volume_calcs.emplace_back(node_vol);
330✔
943
  }
944

945
  // Get temperature settings
946
  if (check_for_node(root, "temperature_default")) {
6,474✔
947
    temperature_default =
187✔
948
      std::stod(get_node_value(root, "temperature_default"));
187✔
949
  }
950
  if (check_for_node(root, "temperature_method")) {
6,474✔
951
    auto temp = get_node_value(root, "temperature_method", true, true);
350✔
952
    if (temp == "nearest") {
350✔
953
      temperature_method = TemperatureMethod::NEAREST;
150✔
954
    } else if (temp == "interpolation") {
200✔
955
      temperature_method = TemperatureMethod::INTERPOLATION;
200✔
956
    } else {
957
      fatal_error("Unknown temperature method: " + temp);
×
958
    }
959
  }
350✔
960
  if (check_for_node(root, "temperature_tolerance")) {
6,474✔
961
    temperature_tolerance =
186✔
962
      std::stod(get_node_value(root, "temperature_tolerance"));
186✔
963
  }
964
  if (check_for_node(root, "temperature_multipole")) {
6,474✔
965
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
34✔
966

967
    // Multipole currently doesn't work with photon transport
968
    if (temperature_multipole && photon_transport) {
34✔
969
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
970
                  "photon transport.");
971
    }
972
  }
973
  if (check_for_node(root, "temperature_range")) {
6,474✔
974
    auto range = get_node_array<double>(root, "temperature_range");
×
975
    temperature_range[0] = range.at(0);
×
976
    temperature_range[1] = range.at(1);
×
977
  }
978

979
  // Check for tabular_legendre options
980
  if (check_for_node(root, "tabular_legendre")) {
6,474✔
981
    // Get pointer to tabular_legendre node
982
    xml_node node_tab_leg = root.child("tabular_legendre");
102✔
983

984
    // Check for enable option
985
    if (check_for_node(node_tab_leg, "enable")) {
102✔
986
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
102✔
987
    }
988

989
    // Check for the number of points
990
    if (check_for_node(node_tab_leg, "num_points")) {
102✔
991
      legendre_to_tabular_points =
×
992
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
993
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
994
        fatal_error(
×
995
          "The 'num_points' subelement/attribute of the "
996
          "<tabular_legendre> element must contain a value greater than 1");
997
      }
998
    }
999
  }
1000

1001
  // Check whether create delayed neutrons in fission
1002
  if (check_for_node(root, "create_delayed_neutrons")) {
6,474✔
1003
    create_delayed_neutrons =
×
1004
      get_node_value_bool(root, "create_delayed_neutrons");
×
1005
  }
1006

1007
  // Check whether create fission sites
1008
  if (run_mode == RunMode::FIXED_SOURCE) {
6,474✔
1009
    if (check_for_node(root, "create_fission_neutrons")) {
1,950✔
1010
      create_fission_neutrons =
17✔
1011
        get_node_value_bool(root, "create_fission_neutrons");
17✔
1012
    }
1013
  }
1014

1015
  // Check whether to scale fission photon yields
1016
  if (check_for_node(root, "delayed_photon_scaling")) {
6,474✔
1017
    delayed_photon_scaling =
×
1018
      get_node_value_bool(root, "delayed_photon_scaling");
×
1019
  }
1020

1021
  // Check whether to use event-based parallelism
1022
  if (check_for_node(root, "event_based")) {
6,474✔
1023
    event_based = get_node_value_bool(root, "event_based");
×
1024
  }
1025

1026
  // Check whether material cell offsets should be generated
1027
  if (check_for_node(root, "material_cell_offsets")) {
6,474✔
1028
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1029
  }
1030

1031
  // Weight window information
1032
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
6,544✔
1033
    variance_reduction::weight_windows.emplace_back(
70✔
1034
      std::make_unique<WeightWindows>(node_ww));
140✔
1035
  }
1036

1037
  // Enable weight windows by default if one or more are present
1038
  if (variance_reduction::weight_windows.size() > 0)
6,474✔
1039
    settings::weight_windows_on = true;
41✔
1040

1041
  // read weight windows from file
1042
  if (check_for_node(root, "weight_windows_file")) {
6,474✔
1043
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1044
  }
1045

1046
  // read settings for weight windows value, this will override
1047
  // the automatic setting even if weight windows are present
1048
  if (check_for_node(root, "weight_windows_on")) {
6,474✔
1049
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
24✔
1050
  }
1051

1052
  if (check_for_node(root, "max_history_splits")) {
6,474✔
1053
    settings::max_history_splits =
233✔
1054
      std::stoi(get_node_value(root, "max_history_splits"));
233✔
1055
  }
1056

1057
  if (check_for_node(root, "max_tracks")) {
6,474✔
1058
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
51✔
1059
  }
1060

1061
  // Create weight window generator objects
1062
  if (check_for_node(root, "weight_window_generators")) {
6,474✔
1063
    auto wwgs_node = root.child("weight_window_generators");
24✔
1064
    for (pugi::xml_node node_wwg :
24✔
1065
      wwgs_node.children("weight_windows_generator")) {
72✔
1066
      variance_reduction::weight_windows_generators.emplace_back(
24✔
1067
        std::make_unique<WeightWindowsGenerator>(node_wwg));
48✔
1068
    }
1069
    // if any of the weight windows are intended to be generated otf, make sure
1070
    // they're applied
1071
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
24✔
1072
      if (wwg->on_the_fly_) {
24✔
1073
        settings::weight_windows_on = true;
24✔
1074
        break;
24✔
1075
      }
1076
    }
1077
  }
1078

1079
  // Set up weight window checkpoints
1080
  if (check_for_node(root, "weight_window_checkpoints")) {
6,474✔
1081
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
×
1082
    if (check_for_node(ww_checkpoints, "collision")) {
×
1083
      weight_window_checkpoint_collision =
×
1084
        get_node_value_bool(ww_checkpoints, "collision");
×
1085
    }
1086
    if (check_for_node(ww_checkpoints, "surface")) {
×
1087
      weight_window_checkpoint_surface =
×
1088
        get_node_value_bool(ww_checkpoints, "surface");
×
1089
    }
1090
  }
1091
}
6,474✔
1092

1093
void free_memory_settings()
6,597✔
1094
{
1095
  settings::statepoint_batch.clear();
6,597✔
1096
  settings::sourcepoint_batch.clear();
6,597✔
1097
  settings::source_write_surf_id.clear();
6,597✔
1098
  settings::res_scat_nuclides.clear();
6,597✔
1099
}
6,597✔
1100

1101
//==============================================================================
1102
// C API functions
1103
//==============================================================================
1104

1105
extern "C" int openmc_set_n_batches(
60✔
1106
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1107
{
1108
  if (settings::n_inactive >= n_batches) {
60✔
1109
    set_errmsg("Number of active batches must be greater than zero.");
12✔
1110
    return OPENMC_E_INVALID_ARGUMENT;
12✔
1111
  }
1112

1113
  if (simulation::current_batch >= n_batches) {
48✔
1114
    set_errmsg("Number of batches must be greater than current batch.");
12✔
1115
    return OPENMC_E_INVALID_ARGUMENT;
12✔
1116
  }
1117

1118
  if (!settings::trigger_on) {
36✔
1119
    // Set n_batches and n_max_batches to same value
1120
    settings::n_batches = n_batches;
12✔
1121
    settings::n_max_batches = n_batches;
12✔
1122
  } else {
1123
    // Set n_batches and n_max_batches based on value of set_max_batches
1124
    if (set_max_batches) {
24✔
1125
      settings::n_max_batches = n_batches;
12✔
1126
    } else {
1127
      settings::n_batches = n_batches;
12✔
1128
    }
1129
  }
1130

1131
  // Update size of k_generation and entropy
1132
  int m = settings::n_max_batches * settings::gen_per_batch;
36✔
1133
  simulation::k_generation.reserve(m);
36✔
1134
  simulation::entropy.reserve(m);
36✔
1135

1136
  // Add value of n_batches to statepoint_batch
1137
  if (add_statepoint_batch &&
60✔
1138
      !(contains(settings::statepoint_batch, n_batches)))
24✔
1139
    settings::statepoint_batch.insert(n_batches);
24✔
1140

1141
  return 0;
36✔
1142
}
1143

1144
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
5,685✔
1145
{
1146
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
5,685✔
1147

1148
  return 0;
5,685✔
1149
}
1150

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