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

openmc-dev / openmc / 13596900305

28 Feb 2025 09:34PM UTC coverage: 85.032% (-0.008%) from 85.04%
13596900305

Pull #3070

github

web-flow
Merge 90e4f6147 into 39ad29d82
Pull Request #3070: Add option for survival biasing source normalization

15 of 21 new or added lines in 5 files covered. (71.43%)

93 existing lines in 4 files now uncovered.

51026 of 60008 relevant lines covered (85.03%)

32654012.9 hits per line

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

78.9
/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 survival_normalization {false};
73
bool temperature_multipole {false};
74
bool trigger_on {false};
75
bool trigger_predict {false};
76
bool uniform_source_sampling {false};
77
bool ufs_on {false};
78
bool urr_ptables_on {true};
79
bool use_decay_photons {false};
80
bool weight_windows_on {false};
81
bool weight_window_checkpoint_surface {false};
82
bool weight_window_checkpoint_collision {true};
83
bool write_all_tracks {false};
84
bool write_initial_source {false};
85

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

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

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

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

141
} // namespace settings
142

143
//==============================================================================
144
// Functions
145
//==============================================================================
146

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

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

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

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

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

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

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

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

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

199
  // Get number of inactive batches
200
  if (run_mode == RunMode::EIGENVALUE ||
6,195✔
201
      solver_type == SolverType::RANDOM_RAY) {
2,265✔
202
    if (check_for_node(node_base, "inactive")) {
4,253✔
203
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,159✔
204
    }
205
    if (check_for_node(node_base, "generations_per_batch")) {
4,253✔
206
      gen_per_batch =
17✔
207
        std::stoi(get_node_value(node_base, "generations_per_batch"));
17✔
208
    }
209

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

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

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

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

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

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

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

351
  // Get root element
352
  xml_node root = doc.document_element();
1,401✔
353

354
  // Verbosity
355
  if (check_for_node(root, "verbosity")) {
1,401✔
356
    verbosity = std::stoi(get_node_value(root, "verbosity"));
203✔
357
  }
358

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

366
  write_message("Reading settings XML file...", 5);
1,401✔
367

368
  read_settings_xml(root);
1,401✔
369
}
1,414✔
370

371
void read_settings_xml(pugi::xml_node root)
6,761✔
372
{
373
  using namespace settings;
374
  using namespace pugi;
375

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

386
  // Check for user meshes and allocate
387
  read_meshes(root);
6,761✔
388

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

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

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

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

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

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

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

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

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

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

487
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
6,761✔
488
    // Read run parameters
489
    get_run_parameters(node_mode);
6,195✔
490

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

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

512
  // Copy random number seed if specified
513
  if (check_for_node(root, "seed")) {
6,761✔
514
    auto seed = std::stoll(get_node_value(root, "seed"));
436✔
515
    openmc_set_seed(seed);
436✔
516
  }
517

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

530
  // Check for photon transport
531
  if (check_for_node(root, "photon_transport")) {
6,761✔
532
    photon_transport = get_node_value_bool(root, "photon_transport");
201✔
533

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

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

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

557
  // ==========================================================================
558
  // EXTERNAL SOURCE
559

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

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

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

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

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

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

603
  // Survival biasing
604
  if (check_for_node(root, "survival_biasing")) {
6,750✔
605
    survival_biasing = get_node_value_bool(root, "survival_biasing");
190✔
606
  }
607

608
  // Probability tables
609
  if (check_for_node(root, "ptables")) {
6,750✔
610
    urr_ptables_on = get_node_value_bool(root, "ptables");
17✔
611
  }
612

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

660
  // Particle trace
661
  if (check_for_node(root, "trace")) {
6,750✔
662
    auto temp = get_node_array<int64_t>(root, "trace");
17✔
663
    if (temp.size() != 3) {
17✔
664
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
665
                  "batch, generation, and particle number.");
666
    }
667
    trace_batch = temp.at(0);
17✔
668
    trace_gen = temp.at(1);
17✔
669
    trace_particle = temp.at(2);
17✔
670
  }
17✔
671

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

683
    // Reshape into track_identifiers
684
    int n_tracks = temp.size() / 3;
51✔
685
    for (int i = 0; i < n_tracks; ++i) {
204✔
686
      track_identifiers.push_back(
153✔
687
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
153✔
688
    }
689
  }
51✔
690

691
  // Shannon entropy
692
  if (solver_type == SolverType::RANDOM_RAY) {
6,750✔
693
    if (check_for_node(root, "entropy_mesh")) {
425✔
694
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
695
                  "No user-defined entropy mesh is supported.");
696
    }
697
    entropy_on = true;
425✔
698
  } else if (solver_type == SolverType::MONTE_CARLO) {
6,325✔
699
    if (check_for_node(root, "entropy_mesh")) {
6,325✔
700
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
380✔
701
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
380✔
702
        fatal_error(fmt::format(
×
703
          "Mesh {} specified for Shannon entropy does not exist.", temp));
704
      }
705

706
      auto* m = dynamic_cast<RegularMesh*>(
380✔
707
        model::meshes[model::mesh_map.at(temp)].get());
380✔
708
      if (!m)
380✔
709
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
710
      simulation::entropy_mesh = m;
380✔
711

712
      // Turn on Shannon entropy calculation
713
      entropy_on = true;
380✔
714

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

731
    auto* m =
732
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
17✔
733
    if (!m)
17✔
734
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
735
    simulation::ufs_mesh = m;
17✔
736

737
    // Turn on uniform fission source weighting
738
    ufs_on = true;
17✔
739

740
  } else if (check_for_node(root, "uniform_fs")) {
6,733✔
741
    fatal_error(
×
742
      "Specifying a UFS mesh via the <uniform_fs> element "
743
      "is deprecated. Please create a mesh using <mesh> and then reference "
744
      "it by specifying its ID in a <ufs_mesh> element.");
745
  }
746

747
  // Check if the user has specified to write state points
748
  if (check_for_node(root, "state_point")) {
6,750✔
749

750
    // Get pointer to state_point node
751
    auto node_sp = root.child("state_point");
186✔
752

753
    // Determine number of batches at which to store state points
754
    if (check_for_node(node_sp, "batches")) {
186✔
755
      // User gave specific batches to write state points
756
      auto temp = get_node_array<int>(node_sp, "batches");
186✔
757
      for (const auto& b : temp) {
575✔
758
        statepoint_batch.insert(b);
389✔
759
      }
760
    } else {
186✔
761
      // If neither were specified, write state point at last batch
762
      statepoint_batch.insert(n_batches);
×
763
    }
764
  } else {
765
    // If no <state_point> tag was present, by default write state point at
766
    // last batch only
767
    statepoint_batch.insert(n_batches);
6,564✔
768
  }
769

770
  // Check if the user has specified to write source points
771
  if (check_for_node(root, "source_point")) {
6,750✔
772
    // Get source_point node
773
    xml_node node_sp = root.child("source_point");
102✔
774

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

787
    // Check if the user has specified to write binary source file
788
    if (check_for_node(node_sp, "separate")) {
102✔
789
      source_separate = get_node_value_bool(node_sp, "separate");
68✔
790
    }
791
    if (check_for_node(node_sp, "write")) {
102✔
792
      source_write = get_node_value_bool(node_sp, "write");
×
793
    }
794
    if (check_for_node(node_sp, "mcpl")) {
102✔
795
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
17✔
796

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

814
  // Check is the user specified to convert strength to statistical weight
815
  if (check_for_node(root, "uniform_source_sampling")) {
6,750✔
816
    uniform_source_sampling =
60✔
817
      get_node_value_bool(root, "uniform_source_sampling");
60✔
818
  }
819

820
  // Check if the user has specified to write surface source
821
  if (check_for_node(root, "surf_source_write")) {
6,750✔
822
    surf_source_write = true;
439✔
823
    // Get surface source write node
824
    xml_node node_ssw = root.child("surf_source_write");
439✔
825

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

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

845
    // Get maximum number of surface source files to be created
846
    if (check_for_node(node_ssw, "max_source_files")) {
429✔
847
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
36✔
848
    } else {
849
      ssw_max_files = 1;
393✔
850
    }
851

852
    if (check_for_node(node_ssw, "mcpl")) {
429✔
853
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
×
854

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

884
  // If source is not separate and is to be written out in the statepoint file,
885
  // make sure that the sourcepoint batch numbers are contained in the
886
  // statepoint list
887
  if (!source_separate) {
6,700✔
888
    for (const auto& b : sourcepoint_batch) {
13,382✔
889
      if (!contains(statepoint_batch, b)) {
6,767✔
890
        fatal_error(
×
891
          "Sourcepoint batches are not a subset of statepoint batches.");
892
      }
893
    }
894
  }
895

896
  // Check if the user has specified to not reduce tallies at the end of every
897
  // batch
898
  if (check_for_node(root, "no_reduce")) {
6,700✔
899
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
×
900
  }
901

902
  // Check if the user has specified to use confidence intervals for
903
  // uncertainties rather than standard deviations
904
  if (check_for_node(root, "confidence_intervals")) {
6,700✔
905
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
17✔
906
  }
907

908
  // Check for output options
909
  if (check_for_node(root, "output")) {
6,700✔
910
    // Get pointer to output node
911
    pugi::xml_node node_output = root.child("output");
397✔
912

913
    // Check for summary option
914
    if (check_for_node(node_output, "summary")) {
397✔
915
      output_summary = get_node_value_bool(node_output, "summary");
380✔
916
    }
917

918
    // Check for ASCII tallies output option
919
    if (check_for_node(node_output, "tallies")) {
397✔
920
      output_tallies = get_node_value_bool(node_output, "tallies");
17✔
921
    }
922

923
    // Set output directory if a path has been specified
924
    if (check_for_node(node_output, "path")) {
397✔
925
      path_output = get_node_value(node_output, "path");
×
926
      if (!ends_with(path_output, "/")) {
×
927
        path_output += "/";
×
928
      }
929
    }
930
  }
931

932
  // Resonance scattering parameters
933
  if (check_for_node(root, "resonance_scattering")) {
6,700✔
934
    xml_node node_res_scat = root.child("resonance_scattering");
17✔
935

936
    // See if resonance scattering is enabled
937
    if (check_for_node(node_res_scat, "enable")) {
17✔
938
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
17✔
939
    } else {
940
      res_scat_on = true;
×
941
    }
942

943
    // Determine what method is used
944
    if (check_for_node(node_res_scat, "method")) {
17✔
945
      auto temp = get_node_value(node_res_scat, "method", true, true);
17✔
946
      if (temp == "rvs") {
17✔
947
        res_scat_method = ResScatMethod::rvs;
17✔
948
      } else if (temp == "dbrc") {
×
949
        res_scat_method = ResScatMethod::dbrc;
×
950
      } else {
951
        fatal_error(
×
952
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
953
      }
954
    }
17✔
955

956
    // Minimum energy for resonance scattering
957
    if (check_for_node(node_res_scat, "energy_min")) {
17✔
958
      res_scat_energy_min =
17✔
959
        std::stod(get_node_value(node_res_scat, "energy_min"));
17✔
960
    }
961
    if (res_scat_energy_min < 0.0) {
17✔
962
      fatal_error("Lower resonance scattering energy bound is negative");
×
963
    }
964

965
    // Maximum energy for resonance scattering
966
    if (check_for_node(node_res_scat, "energy_max")) {
17✔
967
      res_scat_energy_max =
17✔
968
        std::stod(get_node_value(node_res_scat, "energy_max"));
17✔
969
    }
970
    if (res_scat_energy_max < res_scat_energy_min) {
17✔
971
      fatal_error("Upper resonance scattering energy bound is below the "
×
972
                  "lower resonance scattering energy bound.");
973
    }
974

975
    // Get resonance scattering nuclides
976
    if (check_for_node(node_res_scat, "nuclides")) {
17✔
977
      res_scat_nuclides =
978
        get_node_array<std::string>(node_res_scat, "nuclides");
17✔
979
    }
980
  }
981

982
  // Get volume calculations
983
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
7,049✔
984
    model::volume_calcs.emplace_back(node_vol);
349✔
985
  }
986

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

1009
    // Multipole currently doesn't work with photon transport
1010
    if (temperature_multipole && photon_transport) {
34✔
1011
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1012
                  "photon transport.");
1013
    }
1014
  }
1015
  if (check_for_node(root, "temperature_range")) {
6,700✔
1016
    auto range = get_node_array<double>(root, "temperature_range");
×
1017
    temperature_range[0] = range.at(0);
×
1018
    temperature_range[1] = range.at(1);
×
1019
  }
1020

1021
  // Check for tabular_legendre options
1022
  if (check_for_node(root, "tabular_legendre")) {
6,700✔
1023
    // Get pointer to tabular_legendre node
1024
    xml_node node_tab_leg = root.child("tabular_legendre");
102✔
1025

1026
    // Check for enable option
1027
    if (check_for_node(node_tab_leg, "enable")) {
102✔
1028
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
102✔
1029
    }
1030

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

1043
  // Check whether create delayed neutrons in fission
1044
  if (check_for_node(root, "create_delayed_neutrons")) {
6,700✔
1045
    create_delayed_neutrons =
×
1046
      get_node_value_bool(root, "create_delayed_neutrons");
×
1047
  }
1048

1049
  // Check whether create fission sites
1050
  if (run_mode == RunMode::FIXED_SOURCE) {
6,700✔
1051
    if (check_for_node(root, "create_fission_neutrons")) {
2,214✔
1052
      create_fission_neutrons =
17✔
1053
        get_node_value_bool(root, "create_fission_neutrons");
17✔
1054
    }
1055
  }
1056

1057
  // Check whether to scale fission photon yields
1058
  if (check_for_node(root, "delayed_photon_scaling")) {
6,700✔
1059
    delayed_photon_scaling =
×
1060
      get_node_value_bool(root, "delayed_photon_scaling");
×
1061
  }
1062

1063
  // Check whether to use event-based parallelism
1064
  if (check_for_node(root, "event_based")) {
6,700✔
1065
    event_based = get_node_value_bool(root, "event_based");
×
1066
  }
1067

1068
  // Check whether material cell offsets should be generated
1069
  if (check_for_node(root, "material_cell_offsets")) {
6,700✔
1070
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1071
  }
1072

1073
  // Weight window information
1074
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
6,785✔
1075
    variance_reduction::weight_windows.emplace_back(
85✔
1076
      std::make_unique<WeightWindows>(node_ww));
170✔
1077
  }
1078

1079
  // Enable weight windows by default if one or more are present
1080
  if (variance_reduction::weight_windows.size() > 0)
6,700✔
1081
    settings::weight_windows_on = true;
56✔
1082

1083
  // read weight windows from file
1084
  if (check_for_node(root, "weight_windows_file")) {
6,700✔
1085
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1086
  }
1087

1088
  // read settings for weight windows value, this will override
1089
  // the automatic setting even if weight windows are present
1090
  if (check_for_node(root, "weight_windows_on")) {
6,700✔
1091
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
39✔
1092
  }
1093

1094
  if (check_for_node(root, "max_history_splits")) {
6,700✔
1095
    settings::max_history_splits =
233✔
1096
      std::stoi(get_node_value(root, "max_history_splits"));
233✔
1097
  }
1098

1099
  if (check_for_node(root, "max_tracks")) {
6,700✔
1100
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
51✔
1101
  }
1102

1103
  // Create weight window generator objects
1104
  if (check_for_node(root, "weight_window_generators")) {
6,700✔
1105
    auto wwgs_node = root.child("weight_window_generators");
53✔
1106
    for (pugi::xml_node node_wwg :
53✔
1107
      wwgs_node.children("weight_windows_generator")) {
159✔
1108
      variance_reduction::weight_windows_generators.emplace_back(
53✔
1109
        std::make_unique<WeightWindowsGenerator>(node_wwg));
106✔
1110
    }
1111
    // if any of the weight windows are intended to be generated otf, make sure
1112
    // they're applied
1113
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
53✔
1114
      if (wwg->on_the_fly_) {
53✔
1115
        settings::weight_windows_on = true;
53✔
1116
        break;
53✔
1117
      }
1118
    }
1119
  }
1120

1121
  // Set up weight window checkpoints
1122
  if (check_for_node(root, "weight_window_checkpoints")) {
6,700✔
1123
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
×
1124
    if (check_for_node(ww_checkpoints, "collision")) {
×
1125
      weight_window_checkpoint_collision =
×
1126
        get_node_value_bool(ww_checkpoints, "collision");
×
1127
    }
1128
    if (check_for_node(ww_checkpoints, "surface")) {
×
1129
      weight_window_checkpoint_surface =
×
1130
        get_node_value_bool(ww_checkpoints, "surface");
×
1131
    }
1132
  }
1133

1134
  if (check_for_node(root, "use_decay_photons")) {
6,700✔
1135
    settings::use_decay_photons =
12✔
1136
      get_node_value_bool(root, "use_decay_photons");
12✔
1137
  }
1138
}
6,700✔
1139

1140
void free_memory_settings()
6,857✔
1141
{
1142
  settings::statepoint_batch.clear();
6,857✔
1143
  settings::sourcepoint_batch.clear();
6,857✔
1144
  settings::source_write_surf_id.clear();
6,857✔
1145
  settings::res_scat_nuclides.clear();
6,857✔
1146
}
6,857✔
1147

1148
//==============================================================================
1149
// C API functions
1150
//==============================================================================
1151

1152
extern "C" int openmc_set_n_batches(
60✔
1153
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1154
{
1155
  if (settings::n_inactive >= n_batches) {
60✔
1156
    set_errmsg("Number of active batches must be greater than zero.");
12✔
1157
    return OPENMC_E_INVALID_ARGUMENT;
12✔
1158
  }
1159

1160
  if (simulation::current_batch >= n_batches) {
48✔
1161
    set_errmsg("Number of batches must be greater than current batch.");
12✔
1162
    return OPENMC_E_INVALID_ARGUMENT;
12✔
1163
  }
1164

1165
  if (!settings::trigger_on) {
36✔
1166
    // Set n_batches and n_max_batches to same value
1167
    settings::n_batches = n_batches;
12✔
1168
    settings::n_max_batches = n_batches;
12✔
1169
  } else {
1170
    // Set n_batches and n_max_batches based on value of set_max_batches
1171
    if (set_max_batches) {
24✔
1172
      settings::n_max_batches = n_batches;
12✔
1173
    } else {
1174
      settings::n_batches = n_batches;
12✔
1175
    }
1176
  }
1177

1178
  // Update size of k_generation and entropy
1179
  int m = settings::n_max_batches * settings::gen_per_batch;
36✔
1180
  simulation::k_generation.reserve(m);
36✔
1181
  simulation::entropy.reserve(m);
36✔
1182

1183
  // Add value of n_batches to statepoint_batch
1184
  if (add_statepoint_batch &&
60✔
1185
      !(contains(settings::statepoint_batch, n_batches)))
24✔
1186
    settings::statepoint_batch.insert(n_batches);
24✔
1187

1188
  return 0;
36✔
1189
}
1190

1191
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,985✔
1192
{
1193
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,985✔
1194

1195
  return 0;
2,985✔
1196
}
1197

1198
} // namespace openmc
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc