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

openmc-dev / openmc / 13183757653

06 Feb 2025 04:49PM UTC coverage: 82.603% (-2.3%) from 84.867%
13183757653

Pull #3087

github

web-flow
Merge 97d1083b5 into 6e0f156d3
Pull Request #3087: wheel building with scikit build core

107125 of 129687 relevant lines covered (82.6%)

12608197.33 hits per line

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

74.76
/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)
5,133✔
146
{
147
  using namespace settings;
148
  using namespace pugi;
149

150
  // Check number of particles
151
  if (!check_for_node(node_base, "particles")) {
5,133✔
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) {
5,133✔
157
    n_particles = std::stoll(get_node_value(node_base, "particles"));
5,133✔
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")) {
5,133✔
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")) {
5,133✔
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")) {
5,133✔
174
    n_batches = std::stoi(get_node_value(node_base, "batches"));
5,133✔
175
  }
176
  if (!trigger_on)
5,133✔
177
    n_max_batches = n_batches;
4,988✔
178

179
  // Get max number of lost particles
180
  if (check_for_node(node_base, "max_lost_particles")) {
5,133✔
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")) {
5,133✔
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")) {
5,133✔
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 ||
5,133✔
199
      solver_type == SolverType::RANDOM_RAY) {
1,897✔
200
    if (check_for_node(node_base, "inactive")) {
3,525✔
201
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
3,515✔
202
    }
203
    if (check_for_node(node_base, "generations_per_batch")) {
3,525✔
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;
3,525✔
210
    simulation::k_generation.reserve(m);
3,525✔
211
    simulation::entropy.reserve(m);
3,525✔
212

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

217
      if (check_for_node(node_keff_trigger, "type")) {
102✔
218
        auto temp = get_node_value(node_keff_trigger, "type", true, true);
102✔
219
        if (temp == "std_dev") {
102✔
220
          keff_trigger.metric = TriggerMetric::standard_deviation;
102✔
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 {
102✔
229
        fatal_error("Specify keff trigger type in settings XML");
×
230
      }
231

232
      if (check_for_node(node_keff_trigger, "threshold")) {
102✔
233
        keff_trigger.threshold =
102✔
234
          std::stod(get_node_value(node_keff_trigger, "threshold"));
102✔
235
        if (keff_trigger.threshold <= 0) {
102✔
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) {
5,133✔
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);
119✔
277
      if (temp_str == "simulation_averaged") {
119✔
278
        FlatSourceDomain::volume_estimator_ =
34✔
279
          RandomRayVolumeEstimator::SIMULATION_AVERAGED;
280
      } else if (temp_str == "naive") {
85✔
281
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::NAIVE;
51✔
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
    }
119✔
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
  }
310
}
5,133✔
311

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

331
  // Parse settings.xml file
332
  xml_document doc;
913✔
333
  auto result = doc.load_file(filename.c_str());
913✔
334
  if (!result) {
913✔
335
    fatal_error("Error processing settings.xml file.");
×
336
  }
337

338
  // Get root element
339
  xml_node root = doc.document_element();
913✔
340

341
  // Verbosity
342
  if (check_for_node(root, "verbosity")) {
913✔
343
    verbosity = std::stoi(get_node_value(root, "verbosity"));
34✔
344
  }
345

346
  // To this point, we haven't displayed any output since we didn't know what
347
  // the verbosity is. Now that we checked for it, show the title if necessary
348
  if (mpi::master) {
913✔
349
    if (verbosity >= 2)
683✔
350
      title();
659✔
351
  }
352

353
  write_message("Reading settings XML file...", 5);
913✔
354

355
  read_settings_xml(root);
913✔
356
}
926✔
357

358
void read_settings_xml(pugi::xml_node root)
5,519✔
359
{
360
  using namespace settings;
361
  using namespace pugi;
362

363
  // Find if a multi-group or continuous-energy simulation is desired
364
  if (check_for_node(root, "energy_mode")) {
5,519✔
365
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
942✔
366
    if (temp_str == "mg" || temp_str == "multi-group") {
942✔
367
      run_CE = false;
942✔
368
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
369
      run_CE = true;
×
370
    }
371
  }
942✔
372

373
  // Check for user meshes and allocate
374
  read_meshes(root);
5,519✔
375

376
  // Look for deprecated cross_sections.xml file in settings.xml
377
  if (check_for_node(root, "cross_sections")) {
5,519✔
378
    warning(
×
379
      "Setting cross_sections in settings.xml has been deprecated."
380
      " The cross_sections are now set in materials.xml and the "
381
      "cross_sections input to materials.xml and the OPENMC_CROSS_SECTIONS"
382
      " environment variable will take precendent over setting "
383
      "cross_sections in settings.xml.");
384
    path_cross_sections = get_node_value(root, "cross_sections");
×
385
  }
386

387
  if (!run_CE) {
5,519✔
388
    // Scattering Treatments
389
    if (check_for_node(root, "max_order")) {
942✔
390
      max_order = std::stoi(get_node_value(root, "max_order"));
17✔
391
    } else {
392
      // Set to default of largest int - 1, which means to use whatever is
393
      // contained in library. This is largest int - 1 because for legendre
394
      // scattering, a value of 1 is added to the order; adding 1 to the largest
395
      // int gets you the largest negative integer, which is not what we want.
396
      max_order = std::numeric_limits<int>::max() - 1;
925✔
397
    }
398
  }
399

400
  // Check for a trigger node and get trigger information
401
  if (check_for_node(root, "trigger")) {
5,519✔
402
    xml_node node_trigger = root.child("trigger");
162✔
403

404
    // Check if trigger(s) are to be turned on
405
    trigger_on = get_node_value_bool(node_trigger, "active");
162✔
406

407
    if (trigger_on) {
162✔
408
      if (check_for_node(node_trigger, "max_batches")) {
145✔
409
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
145✔
410
      } else {
411
        fatal_error("<max_batches> must be specified with triggers");
×
412
      }
413

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

427
  // Check run mode if it hasn't been set from the command line
428
  xml_node node_mode;
5,519✔
429
  if (run_mode == RunMode::UNSET) {
5,519✔
430
    if (check_for_node(root, "run_mode")) {
5,167✔
431
      std::string temp_str = get_node_value(root, "run_mode", true, true);
5,099✔
432
      if (temp_str == "eigenvalue") {
5,099✔
433
        run_mode = RunMode::EIGENVALUE;
3,168✔
434
      } else if (temp_str == "fixed source") {
1,931✔
435
        run_mode = RunMode::FIXED_SOURCE;
1,897✔
436
      } else if (temp_str == "plot") {
34✔
437
        run_mode = RunMode::PLOTTING;
×
438
      } else if (temp_str == "particle restart") {
34✔
439
        run_mode = RunMode::PARTICLE;
×
440
      } else if (temp_str == "volume") {
34✔
441
        run_mode = RunMode::VOLUME;
34✔
442
      } else {
443
        fatal_error("Unrecognized run mode: " + temp_str);
×
444
      }
445

446
      // Assume XML specifies <particles>, <batches>, etc. directly
447
      node_mode = root;
5,099✔
448
    } else {
5,099✔
449
      warning("<run_mode> should be specified.");
68✔
450

451
      // Make sure that either eigenvalue or fixed source was specified
452
      node_mode = root.child("eigenvalue");
68✔
453
      if (node_mode) {
68✔
454
        run_mode = RunMode::EIGENVALUE;
68✔
455
      } else {
456
        node_mode = root.child("fixed_source");
×
457
        if (node_mode) {
×
458
          run_mode = RunMode::FIXED_SOURCE;
×
459
        } else {
460
          fatal_error("<eigenvalue> or <fixed_source> not specified.");
×
461
        }
462
      }
463
    }
464
  }
465

466
  // Check solver type
467
  if (check_for_node(root, "random_ray")) {
5,519✔
468
    solver_type = SolverType::RANDOM_RAY;
374✔
469
    if (run_CE)
374✔
470
      fatal_error("multi-group energy mode must be specified in settings XML "
×
471
                  "when using the random ray solver.");
472
  }
473

474
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
5,519✔
475
    // Read run parameters
476
    get_run_parameters(node_mode);
5,133✔
477

478
    // Check number of active batches, inactive batches, max lost particles and
479
    // particles
480
    if (n_batches <= n_inactive) {
5,133✔
481
      fatal_error("Number of active batches must be greater than zero.");
×
482
    } else if (n_inactive < 0) {
5,133✔
483
      fatal_error("Number of inactive batches must be non-negative.");
×
484
    } else if (n_particles <= 0) {
5,133✔
485
      fatal_error("Number of particles must be greater than zero.");
×
486
    } else if (max_lost_particles <= 0) {
5,133✔
487
      fatal_error("Number of max lost particles must be greater than zero.");
×
488
    } else if (rel_max_lost_particles <= 0.0 || rel_max_lost_particles >= 1.0) {
5,133✔
489
      fatal_error("Relative max lost particles must be between zero and one.");
×
490
    }
491
  }
492

493
  // Copy plotting random number seed if specified
494
  if (check_for_node(root, "plot_seed")) {
5,519✔
495
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
496
    model::plotter_seed = seed;
×
497
  }
498

499
  // Copy random number seed if specified
500
  if (check_for_node(root, "seed")) {
5,519✔
501
    auto seed = std::stoll(get_node_value(root, "seed"));
412✔
502
    openmc_set_seed(seed);
412✔
503
  }
504

505
  // Check for electron treatment
506
  if (check_for_node(root, "electron_treatment")) {
5,519✔
507
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
51✔
508
    if (temp_str == "led") {
51✔
509
      electron_treatment = ElectronTreatment::LED;
×
510
    } else if (temp_str == "ttb") {
51✔
511
      electron_treatment = ElectronTreatment::TTB;
51✔
512
    } else {
513
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
514
    }
515
  }
51✔
516

517
  // Check for photon transport
518
  if (check_for_node(root, "photon_transport")) {
5,519✔
519
    photon_transport = get_node_value_bool(root, "photon_transport");
177✔
520

521
    if (!run_CE && photon_transport) {
177✔
522
      fatal_error("Photon transport is not currently supported in "
×
523
                  "multigroup mode");
524
    }
525
  }
526

527
  // Number of bins for logarithmic grid
528
  if (check_for_node(root, "log_grid_bins")) {
5,519✔
529
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
17✔
530
    if (n_log_bins < 1) {
17✔
531
      fatal_error("Number of bins for logarithmic grid must be greater "
×
532
                  "than zero.");
533
    }
534
  }
535

536
  // Number of OpenMP threads
537
  if (check_for_node(root, "threads")) {
5,519✔
538
    if (mpi::master)
×
539
      warning("The <threads> element has been deprecated. Use "
×
540
              "the OMP_NUM_THREADS environment variable to set the number of "
541
              "threads.");
542
  }
543

544
  // ==========================================================================
545
  // EXTERNAL SOURCE
546

547
  // Get point to list of <source> elements and make sure there is at least one
548
  for (pugi::xml_node node : root.children("source")) {
11,105✔
549
    model::external_sources.push_back(Source::create(node));
5,597✔
550
  }
551

552
  // Check if the user has specified to read surface source
553
  if (check_for_node(root, "surf_source_read")) {
5,508✔
554
    surf_source_read = true;
17✔
555
    // Get surface source read node
556
    xml_node node_ssr = root.child("surf_source_read");
17✔
557

558
    std::string path = "surface_source.h5";
17✔
559
    // Check if the user has specified different file for surface source reading
560
    if (check_for_node(node_ssr, "path")) {
17✔
561
      path = get_node_value(node_ssr, "path", false, true);
17✔
562
    }
563
    model::external_sources.push_back(make_unique<FileSource>(path));
17✔
564
  }
17✔
565

566
  // Build probability mass function for sampling external sources
567
  vector<double> source_strengths;
5,508✔
568
  for (auto& s : model::external_sources) {
11,111✔
569
    source_strengths.push_back(s->strength());
5,603✔
570
  }
571
  model::external_sources_probability.assign(source_strengths);
5,508✔
572

573
  // If no source specified, default to isotropic point source at origin with
574
  // Watt spectrum. No default source is needed in random ray mode.
575
  if (model::external_sources.empty() &&
6,948✔
576
      settings::solver_type != SolverType::RANDOM_RAY) {
1,440✔
577
    double T[] {0.0};
1,355✔
578
    double p[] {1.0};
1,355✔
579
    model::external_sources.push_back(make_unique<IndependentSource>(
1,355✔
580
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
2,710✔
581
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
2,710✔
582
      UPtrDist {new Discrete(T, p, 1)}));
2,710✔
583
  }
584

585
  // Check if we want to write out source
586
  if (check_for_node(root, "write_initial_source")) {
5,508✔
587
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
588
  }
589

590
  // Survival biasing
591
  if (check_for_node(root, "survival_biasing")) {
5,508✔
592
    survival_biasing = get_node_value_bool(root, "survival_biasing");
34✔
593
  }
594

595
  // Probability tables
596
  if (check_for_node(root, "ptables")) {
5,508✔
597
    urr_ptables_on = get_node_value_bool(root, "ptables");
17✔
598
  }
599

600
  // Cutoffs
601
  if (check_for_node(root, "cutoff")) {
5,508✔
602
    xml_node node_cutoff = root.child("cutoff");
114✔
603
    if (check_for_node(node_cutoff, "weight")) {
114✔
604
      weight_cutoff = std::stod(get_node_value(node_cutoff, "weight"));
17✔
605
    }
606
    if (check_for_node(node_cutoff, "weight_avg")) {
114✔
607
      weight_survive = std::stod(get_node_value(node_cutoff, "weight_avg"));
17✔
608
    }
609
    if (check_for_node(node_cutoff, "energy_neutron")) {
114✔
610
      energy_cutoff[0] =
34✔
611
        std::stod(get_node_value(node_cutoff, "energy_neutron"));
17✔
612
    } else if (check_for_node(node_cutoff, "energy")) {
97✔
613
      warning("The use of an <energy> cutoff is deprecated and should "
×
614
              "be replaced by <energy_neutron>.");
615
      energy_cutoff[0] = std::stod(get_node_value(node_cutoff, "energy"));
×
616
    }
617
    if (check_for_node(node_cutoff, "energy_photon")) {
114✔
618
      energy_cutoff[1] =
126✔
619
        std::stod(get_node_value(node_cutoff, "energy_photon"));
63✔
620
    }
621
    if (check_for_node(node_cutoff, "energy_electron")) {
114✔
622
      energy_cutoff[2] =
×
623
        std::stof(get_node_value(node_cutoff, "energy_electron"));
×
624
    }
625
    if (check_for_node(node_cutoff, "energy_positron")) {
114✔
626
      energy_cutoff[3] =
×
627
        std::stod(get_node_value(node_cutoff, "energy_positron"));
×
628
    }
629
    if (check_for_node(node_cutoff, "time_neutron")) {
114✔
630
      time_cutoff[0] = std::stod(get_node_value(node_cutoff, "time_neutron"));
17✔
631
    }
632
    if (check_for_node(node_cutoff, "time_photon")) {
114✔
633
      time_cutoff[1] = std::stod(get_node_value(node_cutoff, "time_photon"));
×
634
    }
635
    if (check_for_node(node_cutoff, "time_electron")) {
114✔
636
      time_cutoff[2] = std::stod(get_node_value(node_cutoff, "time_electron"));
×
637
    }
638
    if (check_for_node(node_cutoff, "time_positron")) {
114✔
639
      time_cutoff[3] = std::stod(get_node_value(node_cutoff, "time_positron"));
×
640
    }
641
  }
642

643
  // Particle trace
644
  if (check_for_node(root, "trace")) {
5,508✔
645
    auto temp = get_node_array<int64_t>(root, "trace");
17✔
646
    if (temp.size() != 3) {
17✔
647
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
648
                  "batch, generation, and particle number.");
649
    }
650
    trace_batch = temp.at(0);
17✔
651
    trace_gen = temp.at(1);
17✔
652
    trace_particle = temp.at(2);
17✔
653
  }
17✔
654

655
  // Particle tracks
656
  if (check_for_node(root, "track")) {
5,508✔
657
    // Get values and make sure there are three per particle
658
    auto temp = get_node_array<int>(root, "track");
51✔
659
    if (temp.size() % 3 != 0) {
51✔
660
      fatal_error(
×
661
        "Number of integers specified in 'track' is not "
662
        "divisible by 3.  Please provide 3 integers per particle to be "
663
        "tracked.");
664
    }
665

666
    // Reshape into track_identifiers
667
    int n_tracks = temp.size() / 3;
51✔
668
    for (int i = 0; i < n_tracks; ++i) {
204✔
669
      track_identifiers.push_back(
153✔
670
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
153✔
671
    }
672
  }
51✔
673

674
  // Shannon entropy
675
  if (solver_type == SolverType::RANDOM_RAY) {
5,508✔
676
    if (check_for_node(root, "entropy_mesh")) {
374✔
677
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
678
                  "No user-defined entropy mesh is supported.");
679
    }
680
    entropy_on = true;
374✔
681
  } else if (solver_type == SolverType::MONTE_CARLO) {
5,134✔
682
    if (check_for_node(root, "entropy_mesh")) {
5,134✔
683
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
101✔
684
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
101✔
685
        fatal_error(fmt::format(
×
686
          "Mesh {} specified for Shannon entropy does not exist.", temp));
687
      }
688

689
      auto* m = dynamic_cast<RegularMesh*>(
101✔
690
        model::meshes[model::mesh_map.at(temp)].get());
101✔
691
      if (!m)
101✔
692
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
693
      simulation::entropy_mesh = m;
101✔
694

695
      // Turn on Shannon entropy calculation
696
      entropy_on = true;
101✔
697

698
    } else if (check_for_node(root, "entropy")) {
5,033✔
699
      fatal_error(
×
700
        "Specifying a Shannon entropy mesh via the <entropy> element "
701
        "is deprecated. Please create a mesh using <mesh> and then reference "
702
        "it by specifying its ID in an <entropy_mesh> element.");
703
    }
704
  }
705
  // Uniform fission source weighting mesh
706
  if (check_for_node(root, "ufs_mesh")) {
5,508✔
707
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
17✔
708
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
17✔
709
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
710
                              "method does not exist.",
711
        temp));
712
    }
713

714
    auto* m =
715
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
17✔
716
    if (!m)
17✔
717
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
718
    simulation::ufs_mesh = m;
17✔
719

720
    // Turn on uniform fission source weighting
721
    ufs_on = true;
17✔
722

723
  } else if (check_for_node(root, "uniform_fs")) {
5,491✔
724
    fatal_error(
×
725
      "Specifying a UFS mesh via the <uniform_fs> element "
726
      "is deprecated. Please create a mesh using <mesh> and then reference "
727
      "it by specifying its ID in a <ufs_mesh> element.");
728
  }
729

730
  // Check if the user has specified to write state points
731
  if (check_for_node(root, "state_point")) {
5,508✔
732

733
    // Get pointer to state_point node
734
    auto node_sp = root.child("state_point");
160✔
735

736
    // Determine number of batches at which to store state points
737
    if (check_for_node(node_sp, "batches")) {
160✔
738
      // User gave specific batches to write state points
739
      auto temp = get_node_array<int>(node_sp, "batches");
160✔
740
      for (const auto& b : temp) {
497✔
741
        statepoint_batch.insert(b);
337✔
742
      }
743
    } else {
160✔
744
      // If neither were specified, write state point at last batch
745
      statepoint_batch.insert(n_batches);
×
746
    }
747
  } else {
748
    // If no <state_point> tag was present, by default write state point at
749
    // last batch only
750
    statepoint_batch.insert(n_batches);
5,348✔
751
  }
752

753
  // Check if the user has specified to write source points
754
  if (check_for_node(root, "source_point")) {
5,508✔
755
    // Get source_point node
756
    xml_node node_sp = root.child("source_point");
102✔
757

758
    // Determine batches at which to store source points
759
    if (check_for_node(node_sp, "batches")) {
102✔
760
      // User gave specific batches to write source points
761
      auto temp = get_node_array<int>(node_sp, "batches");
51✔
762
      for (const auto& b : temp) {
136✔
763
        sourcepoint_batch.insert(b);
85✔
764
      }
765
    } else {
51✔
766
      // If neither were specified, write source points with state points
767
      sourcepoint_batch = statepoint_batch;
51✔
768
    }
769

770
    // Check if the user has specified to write binary source file
771
    if (check_for_node(node_sp, "separate")) {
102✔
772
      source_separate = get_node_value_bool(node_sp, "separate");
68✔
773
    }
774
    if (check_for_node(node_sp, "write")) {
102✔
775
      source_write = get_node_value_bool(node_sp, "write");
×
776
    }
777
    if (check_for_node(node_sp, "mcpl")) {
102✔
778
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
17✔
779

780
      // Make sure MCPL support is enabled
781
      if (source_mcpl_write && !MCPL_ENABLED) {
17✔
782
        fatal_error(
×
783
          "Your build of OpenMC does not support writing MCPL source files.");
784
      }
785
    }
786
    if (check_for_node(node_sp, "overwrite_latest")) {
102✔
787
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
17✔
788
      source_separate = source_latest;
17✔
789
    }
790
  } else {
791
    // If no <source_point> tag was present, by default we keep source bank in
792
    // statepoint file and write it out at statepoints intervals
793
    source_separate = false;
5,406✔
794
    sourcepoint_batch = statepoint_batch;
5,406✔
795
  }
796

797
  // Check is the user specified to convert strength to statistical weight
798
  if (check_for_node(root, "uniform_source_sampling")) {
5,508✔
799
    uniform_source_sampling =
48✔
800
      get_node_value_bool(root, "uniform_source_sampling");
48✔
801
  }
802

803
  // Check if the user has specified to write surface source
804
  if (check_for_node(root, "surf_source_write")) {
5,508✔
805
    surf_source_write = true;
427✔
806
    // Get surface source write node
807
    xml_node node_ssw = root.child("surf_source_write");
427✔
808

809
    // Determine surface ids at which crossing particles are to be banked.
810
    // If no surfaces are specified, all surfaces in the model will be used
811
    // to bank source points.
812
    if (check_for_node(node_ssw, "surface_ids")) {
427✔
813
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
209✔
814
      for (const auto& b : temp) {
1,065✔
815
        source_write_surf_id.insert(b);
856✔
816
      }
817
    }
209✔
818

819
    // Get maximum number of particles to be banked per surface
820
    if (check_for_node(node_ssw, "max_particles")) {
427✔
821
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
417✔
822
    } else {
823
      fatal_error("A maximum number of particles needs to be specified "
10✔
824
                  "using the 'max_particles' parameter to store surface "
825
                  "source points.");
826
    }
827

828
    // Get maximum number of surface source files to be created
829
    if (check_for_node(node_ssw, "max_source_files")) {
417✔
830
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
36✔
831
    } else {
832
      ssw_max_files = 1;
381✔
833
    }
834

835
    if (check_for_node(node_ssw, "mcpl")) {
417✔
836
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
×
837

838
      // Make sure MCPL support is enabled
839
      if (surf_mcpl_write && !MCPL_ENABLED) {
×
840
        fatal_error("Your build of OpenMC does not support writing MCPL "
×
841
                    "surface source files.");
842
      }
843
    }
844
    // Get cell information
845
    if (check_for_node(node_ssw, "cell")) {
417✔
846
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
114✔
847
      ssw_cell_type = SSWCellType::Both;
114✔
848
    }
849
    if (check_for_node(node_ssw, "cellfrom")) {
417✔
850
      if (ssw_cell_id != C_NONE) {
99✔
851
        fatal_error(
20✔
852
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
853
      }
854
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
79✔
855
      ssw_cell_type = SSWCellType::From;
79✔
856
    }
857
    if (check_for_node(node_ssw, "cellto")) {
397✔
858
      if (ssw_cell_id != C_NONE) {
78✔
859
        fatal_error(
20✔
860
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
861
      }
862
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
58✔
863
      ssw_cell_type = SSWCellType::To;
58✔
864
    }
865
  }
866

867
  // If source is not separate and is to be written out in the statepoint file,
868
  // make sure that the sourcepoint batch numbers are contained in the
869
  // statepoint list
870
  if (!source_separate) {
5,458✔
871
    for (const auto& b : sourcepoint_batch) {
10,872✔
872
      if (!contains(statepoint_batch, b)) {
5,499✔
873
        fatal_error(
×
874
          "Sourcepoint batches are not a subset of statepoint batches.");
875
      }
876
    }
877
  }
878

879
  // Check if the user has specified to not reduce tallies at the end of every
880
  // batch
881
  if (check_for_node(root, "no_reduce")) {
5,458✔
882
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
×
883
  }
884

885
  // Check if the user has specified to use confidence intervals for
886
  // uncertainties rather than standard deviations
887
  if (check_for_node(root, "confidence_intervals")) {
5,458✔
888
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
17✔
889
  }
890

891
  // Check for output options
892
  if (check_for_node(root, "output")) {
5,458✔
893
    // Get pointer to output node
894
    pugi::xml_node node_output = root.child("output");
325✔
895

896
    // Check for summary option
897
    if (check_for_node(node_output, "summary")) {
325✔
898
      output_summary = get_node_value_bool(node_output, "summary");
308✔
899
    }
900

901
    // Check for ASCII tallies output option
902
    if (check_for_node(node_output, "tallies")) {
325✔
903
      output_tallies = get_node_value_bool(node_output, "tallies");
17✔
904
    }
905

906
    // Set output directory if a path has been specified
907
    if (check_for_node(node_output, "path")) {
325✔
908
      path_output = get_node_value(node_output, "path");
×
909
      if (!ends_with(path_output, "/")) {
×
910
        path_output += "/";
×
911
      }
912
    }
913
  }
914

915
  // Resonance scattering parameters
916
  if (check_for_node(root, "resonance_scattering")) {
5,458✔
917
    xml_node node_res_scat = root.child("resonance_scattering");
17✔
918

919
    // See if resonance scattering is enabled
920
    if (check_for_node(node_res_scat, "enable")) {
17✔
921
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
17✔
922
    } else {
923
      res_scat_on = true;
×
924
    }
925

926
    // Determine what method is used
927
    if (check_for_node(node_res_scat, "method")) {
17✔
928
      auto temp = get_node_value(node_res_scat, "method", true, true);
17✔
929
      if (temp == "rvs") {
17✔
930
        res_scat_method = ResScatMethod::rvs;
17✔
931
      } else if (temp == "dbrc") {
×
932
        res_scat_method = ResScatMethod::dbrc;
×
933
      } else {
934
        fatal_error(
×
935
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
936
      }
937
    }
17✔
938

939
    // Minimum energy for resonance scattering
940
    if (check_for_node(node_res_scat, "energy_min")) {
17✔
941
      res_scat_energy_min =
17✔
942
        std::stod(get_node_value(node_res_scat, "energy_min"));
17✔
943
    }
944
    if (res_scat_energy_min < 0.0) {
17✔
945
      fatal_error("Lower resonance scattering energy bound is negative");
×
946
    }
947

948
    // Maximum energy for resonance scattering
949
    if (check_for_node(node_res_scat, "energy_max")) {
17✔
950
      res_scat_energy_max =
17✔
951
        std::stod(get_node_value(node_res_scat, "energy_max"));
17✔
952
    }
953
    if (res_scat_energy_max < res_scat_energy_min) {
17✔
954
      fatal_error("Upper resonance scattering energy bound is below the "
×
955
                  "lower resonance scattering energy bound.");
956
    }
957

958
    // Get resonance scattering nuclides
959
    if (check_for_node(node_res_scat, "nuclides")) {
17✔
960
      res_scat_nuclides =
961
        get_node_array<std::string>(node_res_scat, "nuclides");
17✔
962
    }
963
  }
964

965
  // Get volume calculations
966
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
5,764✔
967
    model::volume_calcs.emplace_back(node_vol);
306✔
968
  }
969

970
  // Get temperature settings
971
  if (check_for_node(root, "temperature_default")) {
5,458✔
972
    temperature_default =
187✔
973
      std::stod(get_node_value(root, "temperature_default"));
187✔
974
  }
975
  if (check_for_node(root, "temperature_method")) {
5,458✔
976
    auto temp = get_node_value(root, "temperature_method", true, true);
350✔
977
    if (temp == "nearest") {
350✔
978
      temperature_method = TemperatureMethod::NEAREST;
150✔
979
    } else if (temp == "interpolation") {
200✔
980
      temperature_method = TemperatureMethod::INTERPOLATION;
200✔
981
    } else {
982
      fatal_error("Unknown temperature method: " + temp);
×
983
    }
984
  }
350✔
985
  if (check_for_node(root, "temperature_tolerance")) {
5,458✔
986
    temperature_tolerance =
185✔
987
      std::stod(get_node_value(root, "temperature_tolerance"));
185✔
988
  }
989
  if (check_for_node(root, "temperature_multipole")) {
5,458✔
990
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
34✔
991

992
    // Multipole currently doesn't work with photon transport
993
    if (temperature_multipole && photon_transport) {
34✔
994
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
995
                  "photon transport.");
996
    }
997
  }
998
  if (check_for_node(root, "temperature_range")) {
5,458✔
999
    auto range = get_node_array<double>(root, "temperature_range");
×
1000
    temperature_range[0] = range.at(0);
×
1001
    temperature_range[1] = range.at(1);
×
1002
  }
1003

1004
  // Check for tabular_legendre options
1005
  if (check_for_node(root, "tabular_legendre")) {
5,458✔
1006
    // Get pointer to tabular_legendre node
1007
    xml_node node_tab_leg = root.child("tabular_legendre");
102✔
1008

1009
    // Check for enable option
1010
    if (check_for_node(node_tab_leg, "enable")) {
102✔
1011
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
102✔
1012
    }
1013

1014
    // Check for the number of points
1015
    if (check_for_node(node_tab_leg, "num_points")) {
102✔
1016
      legendre_to_tabular_points =
×
1017
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
1018
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
1019
        fatal_error(
×
1020
          "The 'num_points' subelement/attribute of the "
1021
          "<tabular_legendre> element must contain a value greater than 1");
1022
      }
1023
    }
1024
  }
1025

1026
  // Check whether create delayed neutrons in fission
1027
  if (check_for_node(root, "create_delayed_neutrons")) {
5,458✔
1028
    create_delayed_neutrons =
×
1029
      get_node_value_bool(root, "create_delayed_neutrons");
×
1030
  }
1031

1032
  // Check whether create fission sites
1033
  if (run_mode == RunMode::FIXED_SOURCE) {
5,458✔
1034
    if (check_for_node(root, "create_fission_neutrons")) {
1,846✔
1035
      create_fission_neutrons =
17✔
1036
        get_node_value_bool(root, "create_fission_neutrons");
17✔
1037
    }
1038
  }
1039

1040
  // Check whether to scale fission photon yields
1041
  if (check_for_node(root, "delayed_photon_scaling")) {
5,458✔
1042
    delayed_photon_scaling =
×
1043
      get_node_value_bool(root, "delayed_photon_scaling");
×
1044
  }
1045

1046
  // Check whether to use event-based parallelism
1047
  if (check_for_node(root, "event_based")) {
5,458✔
1048
    event_based = get_node_value_bool(root, "event_based");
×
1049
  }
1050

1051
  // Check whether material cell offsets should be generated
1052
  if (check_for_node(root, "material_cell_offsets")) {
5,458✔
1053
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1054
  }
1055

1056
  // Weight window information
1057
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
5,531✔
1058
    variance_reduction::weight_windows.emplace_back(
73✔
1059
      std::make_unique<WeightWindows>(node_ww));
146✔
1060
  }
1061

1062
  // Enable weight windows by default if one or more are present
1063
  if (variance_reduction::weight_windows.size() > 0)
5,458✔
1064
    settings::weight_windows_on = true;
44✔
1065

1066
  // read weight windows from file
1067
  if (check_for_node(root, "weight_windows_file")) {
5,458✔
1068
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1069
  }
1070

1071
  // read settings for weight windows value, this will override
1072
  // the automatic setting even if weight windows are present
1073
  if (check_for_node(root, "weight_windows_on")) {
5,458✔
1074
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
39✔
1075
  }
1076

1077
  if (check_for_node(root, "max_history_splits")) {
5,458✔
1078
    settings::max_history_splits =
65✔
1079
      std::stoi(get_node_value(root, "max_history_splits"));
65✔
1080
  }
1081

1082
  if (check_for_node(root, "max_tracks")) {
5,458✔
1083
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
51✔
1084
  }
1085

1086
  // Create weight window generator objects
1087
  if (check_for_node(root, "weight_window_generators")) {
5,458✔
1088
    auto wwgs_node = root.child("weight_window_generators");
53✔
1089
    for (pugi::xml_node node_wwg :
53✔
1090
      wwgs_node.children("weight_windows_generator")) {
159✔
1091
      variance_reduction::weight_windows_generators.emplace_back(
53✔
1092
        std::make_unique<WeightWindowsGenerator>(node_wwg));
106✔
1093
    }
1094
    // if any of the weight windows are intended to be generated otf, make sure
1095
    // they're applied
1096
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
53✔
1097
      if (wwg->on_the_fly_) {
53✔
1098
        settings::weight_windows_on = true;
53✔
1099
        break;
53✔
1100
      }
1101
    }
1102
  }
1103

1104
  // Set up weight window checkpoints
1105
  if (check_for_node(root, "weight_window_checkpoints")) {
5,458✔
1106
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
×
1107
    if (check_for_node(ww_checkpoints, "collision")) {
×
1108
      weight_window_checkpoint_collision =
×
1109
        get_node_value_bool(ww_checkpoints, "collision");
×
1110
    }
1111
    if (check_for_node(ww_checkpoints, "surface")) {
×
1112
      weight_window_checkpoint_surface =
×
1113
        get_node_value_bool(ww_checkpoints, "surface");
×
1114
    }
1115
  }
1116
}
5,458✔
1117

1118
void free_memory_settings()
5,426✔
1119
{
1120
  settings::statepoint_batch.clear();
5,426✔
1121
  settings::sourcepoint_batch.clear();
5,426✔
1122
  settings::source_write_surf_id.clear();
5,426✔
1123
  settings::res_scat_nuclides.clear();
5,426✔
1124
}
5,426✔
1125

1126
//==============================================================================
1127
// C API functions
1128
//==============================================================================
1129

1130
extern "C" int openmc_set_n_batches(
×
1131
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1132
{
1133
  if (settings::n_inactive >= n_batches) {
×
1134
    set_errmsg("Number of active batches must be greater than zero.");
×
1135
    return OPENMC_E_INVALID_ARGUMENT;
×
1136
  }
1137

1138
  if (simulation::current_batch >= n_batches) {
×
1139
    set_errmsg("Number of batches must be greater than current batch.");
×
1140
    return OPENMC_E_INVALID_ARGUMENT;
×
1141
  }
1142

1143
  if (!settings::trigger_on) {
×
1144
    // Set n_batches and n_max_batches to same value
1145
    settings::n_batches = n_batches;
×
1146
    settings::n_max_batches = n_batches;
×
1147
  } else {
1148
    // Set n_batches and n_max_batches based on value of set_max_batches
1149
    if (set_max_batches) {
×
1150
      settings::n_max_batches = n_batches;
×
1151
    } else {
1152
      settings::n_batches = n_batches;
×
1153
    }
1154
  }
1155

1156
  // Update size of k_generation and entropy
1157
  int m = settings::n_max_batches * settings::gen_per_batch;
×
1158
  simulation::k_generation.reserve(m);
×
1159
  simulation::entropy.reserve(m);
×
1160

1161
  // Add value of n_batches to statepoint_batch
1162
  if (add_statepoint_batch &&
×
1163
      !(contains(settings::statepoint_batch, n_batches)))
×
1164
    settings::statepoint_batch.insert(n_batches);
×
1165

1166
  return 0;
×
1167
}
1168

1169
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
×
1170
{
1171
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
×
1172

1173
  return 0;
×
1174
}
1175

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