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

openmc-dev / openmc / 13710627373

07 Mar 2025 12:00AM UTC coverage: 85.127%. First build
13710627373

push

github

web-flow
Add option for survival biasing source normalization (#3070)

Co-authored-by: Patrick Shriwise <pshriwise@gmail.com>
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>

12 of 18 new or added lines in 5 files covered. (66.67%)

51239 of 60191 relevant lines covered (85.13%)

32493891.2 hits per line

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

79.01
/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)
5,772✔
148
{
149
  using namespace settings;
150
  using namespace pugi;
151

152
  // Check number of particles
153
  if (!check_for_node(node_base, "particles")) {
5,772✔
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) {
5,772✔
159
    n_particles = std::stoll(get_node_value(node_base, "particles"));
5,772✔
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")) {
5,772✔
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")) {
5,772✔
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")) {
5,772✔
176
    n_batches = std::stoi(get_node_value(node_base, "batches"));
5,772✔
177
  }
178
  if (!trigger_on)
5,772✔
179
    n_max_batches = n_batches;
5,626✔
180

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

187
  // Get relative number of lost particles
188
  if (check_for_node(node_base, "rel_max_lost_particles")) {
5,772✔
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")) {
5,772✔
195
    max_write_lost_particles =
16✔
196
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
16✔
197
  }
198

199
  // Get number of inactive batches
200
  if (run_mode == RunMode::EIGENVALUE ||
5,772✔
201
      solver_type == SolverType::RANDOM_RAY) {
2,111✔
202
    if (check_for_node(node_base, "inactive")) {
3,965✔
203
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
3,879✔
204
    }
205
    if (check_for_node(node_base, "generations_per_batch")) {
3,965✔
206
      gen_per_batch =
16✔
207
        std::stoi(get_node_value(node_base, "generations_per_batch"));
16✔
208
    }
209

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

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

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

234
      if (check_for_node(node_keff_trigger, "threshold")) {
107✔
235
        keff_trigger.threshold =
107✔
236
          std::stod(get_node_value(node_keff_trigger, "threshold"));
107✔
237
        if (keff_trigger.threshold <= 0) {
107✔
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) {
5,772✔
248
    xml_node random_ray_node = node_base.child("random_ray");
400✔
249
    if (check_for_node(random_ray_node, "distance_active")) {
400✔
250
      RandomRay::distance_active_ =
400✔
251
        std::stod(get_node_value(random_ray_node, "distance_active"));
400✔
252
      if (RandomRay::distance_active_ <= 0.0) {
400✔
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")) {
400✔
259
      RandomRay::distance_inactive_ =
400✔
260
        std::stod(get_node_value(random_ray_node, "distance_inactive"));
400✔
261
      if (RandomRay::distance_inactive_ < 0) {
400✔
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")) {
400✔
269
      xml_node source_node = random_ray_node.child("source");
400✔
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);
400✔
273
    } else {
274
      fatal_error("Specify random ray source in settings XML");
×
275
    }
276
    if (check_for_node(random_ray_node, "volume_estimator")) {
400✔
277
      std::string temp_str =
278
        get_node_value(random_ray_node, "volume_estimator", true, true);
128✔
279
      if (temp_str == "simulation_averaged") {
128✔
280
        FlatSourceDomain::volume_estimator_ =
32✔
281
          RandomRayVolumeEstimator::SIMULATION_AVERAGED;
282
      } else if (temp_str == "naive") {
96✔
283
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::NAIVE;
64✔
284
      } else if (temp_str == "hybrid") {
32✔
285
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::HYBRID;
32✔
286
      } else {
287
        fatal_error("Unrecognized volume estimator: " + temp_str);
×
288
      }
289
    }
128✔
290
    if (check_for_node(random_ray_node, "source_shape")) {
400✔
291
      std::string temp_str =
292
        get_node_value(random_ray_node, "source_shape", true, true);
176✔
293
      if (temp_str == "flat") {
176✔
294
        RandomRay::source_shape_ = RandomRaySourceShape::FLAT;
32✔
295
      } else if (temp_str == "linear") {
144✔
296
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR;
96✔
297
      } else if (temp_str == "linear_xy") {
48✔
298
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR_XY;
48✔
299
      } else {
300
        fatal_error("Unrecognized source shape: " + temp_str);
×
301
      }
302
    }
176✔
303
    if (check_for_node(random_ray_node, "volume_normalized_flux_tallies")) {
400✔
304
      FlatSourceDomain::volume_normalized_flux_tallies_ =
384✔
305
        get_node_value_bool(random_ray_node, "volume_normalized_flux_tallies");
384✔
306
    }
307
    if (check_for_node(random_ray_node, "adjoint")) {
400✔
308
      FlatSourceDomain::adjoint_ =
32✔
309
        get_node_value_bool(random_ray_node, "adjoint");
32✔
310
    }
311
    if (check_for_node(random_ray_node, "sample_method")) {
400✔
312
      std::string temp_str =
313
        get_node_value(random_ray_node, "sample_method", true, true);
16✔
314
      if (temp_str == "prng") {
16✔
315
        RandomRay::sample_method_ = RandomRaySampleMethod::PRNG;
×
316
      } else if (temp_str == "halton") {
16✔
317
        RandomRay::sample_method_ = RandomRaySampleMethod::HALTON;
16✔
318
      } else {
319
        fatal_error("Unrecognized sample method: " + temp_str);
×
320
      }
321
    }
16✔
322
  }
323
}
5,772✔
324

325
void read_settings_xml()
1,324✔
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,324✔
331
  if (!file_exists(filename)) {
1,324✔
332
    if (run_mode != RunMode::PLOTTING) {
22✔
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;
22✔
341
    }
342
  }
343

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

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

354
  // Verbosity
355
  if (check_for_node(root, "verbosity")) {
1,302✔
356
    verbosity = std::stoi(get_node_value(root, "verbosity"));
187✔
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,302✔
362
    if (verbosity >= 2)
1,072✔
363
      title();
895✔
364
  }
365

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

368
  read_settings_xml(root);
1,302✔
369
}
1,314✔
370

371
void read_settings_xml(pugi::xml_node root)
6,291✔
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,291✔
378
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
934✔
379
    if (temp_str == "mg" || temp_str == "multi-group") {
934✔
380
      run_CE = false;
934✔
381
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
382
      run_CE = true;
×
383
    }
384
  }
934✔
385

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

389
  // Look for deprecated cross_sections.xml file in settings.xml
390
  if (check_for_node(root, "cross_sections")) {
6,291✔
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,291✔
401
    // Scattering Treatments
402
    if (check_for_node(root, "max_order")) {
934✔
403
      max_order = std::stoi(get_node_value(root, "max_order"));
16✔
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;
918✔
410
    }
411
  }
412

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

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

420
    if (trigger_on) {
162✔
421
      if (check_for_node(node_trigger, "max_batches")) {
146✔
422
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
146✔
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")) {
146✔
429
        trigger_predict = true;
16✔
430
      } else {
431
        trigger_batch_interval =
130✔
432
          std::stoi(get_node_value(node_trigger, "batch_interval"));
130✔
433
        if (trigger_batch_interval <= 0) {
130✔
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,291✔
442
  if (run_mode == RunMode::UNSET) {
6,291✔
443
    if (check_for_node(root, "run_mode")) {
5,804✔
444
      std::string temp_str = get_node_value(root, "run_mode", true, true);
5,740✔
445
      if (temp_str == "eigenvalue") {
5,740✔
446
        run_mode = RunMode::EIGENVALUE;
3,597✔
447
      } else if (temp_str == "fixed source") {
2,143✔
448
        run_mode = RunMode::FIXED_SOURCE;
2,111✔
449
      } else if (temp_str == "plot") {
32✔
450
        run_mode = RunMode::PLOTTING;
×
451
      } else if (temp_str == "particle restart") {
32✔
452
        run_mode = RunMode::PARTICLE;
×
453
      } else if (temp_str == "volume") {
32✔
454
        run_mode = RunMode::VOLUME;
32✔
455
      } else {
456
        fatal_error("Unrecognized run mode: " + temp_str);
×
457
      }
458

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

464
      // Make sure that either eigenvalue or fixed source was specified
465
      node_mode = root.child("eigenvalue");
64✔
466
      if (node_mode) {
64✔
467
        run_mode = RunMode::EIGENVALUE;
64✔
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,291✔
481
    solver_type = SolverType::RANDOM_RAY;
400✔
482
    if (run_CE)
400✔
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,291✔
488
    // Read run parameters
489
    get_run_parameters(node_mode);
5,772✔
490

491
    // Check number of active batches, inactive batches, max lost particles and
492
    // particles
493
    if (n_batches <= n_inactive) {
5,772✔
494
      fatal_error("Number of active batches must be greater than zero.");
×
495
    } else if (n_inactive < 0) {
5,772✔
496
      fatal_error("Number of inactive batches must be non-negative.");
×
497
    } else if (n_particles <= 0) {
5,772✔
498
      fatal_error("Number of particles must be greater than zero.");
×
499
    } else if (max_lost_particles <= 0) {
5,772✔
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) {
5,772✔
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,291✔
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,291✔
514
    auto seed = std::stoll(get_node_value(root, "seed"));
401✔
515
    openmc_set_seed(seed);
401✔
516
  }
517

518
  // Copy random number stride if specified
519
  if (check_for_node(root, "stride")) {
6,291✔
520
    auto stride = std::stoull(get_node_value(root, "stride"));
16✔
521
    openmc_set_stride(stride);
16✔
522
  }
523

524
  // Check for electron treatment
525
  if (check_for_node(root, "electron_treatment")) {
6,291✔
526
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
48✔
527
    if (temp_str == "led") {
48✔
528
      electron_treatment = ElectronTreatment::LED;
×
529
    } else if (temp_str == "ttb") {
48✔
530
      electron_treatment = ElectronTreatment::TTB;
48✔
531
    } else {
532
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
533
    }
534
  }
48✔
535

536
  // Check for photon transport
537
  if (check_for_node(root, "photon_transport")) {
6,291✔
538
    photon_transport = get_node_value_bool(root, "photon_transport");
188✔
539

540
    if (!run_CE && photon_transport) {
188✔
541
      fatal_error("Photon transport is not currently supported in "
×
542
                  "multigroup mode");
543
    }
544
  }
545

546
  // Number of bins for logarithmic grid
547
  if (check_for_node(root, "log_grid_bins")) {
6,291✔
548
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
16✔
549
    if (n_log_bins < 1) {
16✔
550
      fatal_error("Number of bins for logarithmic grid must be greater "
×
551
                  "than zero.");
552
    }
553
  }
554

555
  // Number of OpenMP threads
556
  if (check_for_node(root, "threads")) {
6,291✔
557
    if (mpi::master)
×
558
      warning("The <threads> element has been deprecated. Use "
×
559
              "the OMP_NUM_THREADS environment variable to set the number of "
560
              "threads.");
561
  }
562

563
  // ==========================================================================
564
  // EXTERNAL SOURCE
565

566
  // Get point to list of <source> elements and make sure there is at least one
567
  for (pugi::xml_node node : root.children("source")) {
12,343✔
568
    model::external_sources.push_back(Source::create(node));
6,062✔
569
  }
570

571
  // Check if the user has specified to read surface source
572
  if (check_for_node(root, "surf_source_read")) {
6,281✔
573
    surf_source_read = true;
16✔
574
    // Get surface source read node
575
    xml_node node_ssr = root.child("surf_source_read");
16✔
576

577
    std::string path = "surface_source.h5";
16✔
578
    // Check if the user has specified different file for surface source reading
579
    if (check_for_node(node_ssr, "path")) {
16✔
580
      path = get_node_value(node_ssr, "path", false, true);
16✔
581
    }
582
    model::external_sources.push_back(make_unique<FileSource>(path));
16✔
583
  }
16✔
584

585
  // Build probability mass function for sampling external sources
586
  vector<double> source_strengths;
6,281✔
587
  for (auto& s : model::external_sources) {
12,349✔
588
    source_strengths.push_back(s->strength());
6,068✔
589
  }
590
  model::external_sources_probability.assign(source_strengths);
6,281✔
591

592
  // If no source specified, default to isotropic point source at origin with
593
  // Watt spectrum. No default source is needed in random ray mode.
594
  if (model::external_sources.empty() &&
7,915✔
595
      settings::solver_type != SolverType::RANDOM_RAY) {
1,634✔
596
    double T[] {0.0};
1,538✔
597
    double p[] {1.0};
1,538✔
598
    model::external_sources.push_back(make_unique<IndependentSource>(
1,538✔
599
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
3,076✔
600
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
3,076✔
601
      UPtrDist {new Discrete(T, p, 1)}));
3,076✔
602
  }
603

604
  // Check if we want to write out source
605
  if (check_for_node(root, "write_initial_source")) {
6,281✔
606
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
607
  }
608

609
  // Survival biasing
610
  if (check_for_node(root, "survival_biasing")) {
6,281✔
611
    survival_biasing = get_node_value_bool(root, "survival_biasing");
175✔
612
  }
613

614
  // Probability tables
615
  if (check_for_node(root, "ptables")) {
6,281✔
616
    urr_ptables_on = get_node_value_bool(root, "ptables");
16✔
617
  }
618

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

666
  // Particle trace
667
  if (check_for_node(root, "trace")) {
6,281✔
668
    auto temp = get_node_array<int64_t>(root, "trace");
16✔
669
    if (temp.size() != 3) {
16✔
670
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
671
                  "batch, generation, and particle number.");
672
    }
673
    trace_batch = temp.at(0);
16✔
674
    trace_gen = temp.at(1);
16✔
675
    trace_particle = temp.at(2);
16✔
676
  }
16✔
677

678
  // Particle tracks
679
  if (check_for_node(root, "track")) {
6,281✔
680
    // Get values and make sure there are three per particle
681
    auto temp = get_node_array<int>(root, "track");
48✔
682
    if (temp.size() % 3 != 0) {
48✔
683
      fatal_error(
×
684
        "Number of integers specified in 'track' is not "
685
        "divisible by 3.  Please provide 3 integers per particle to be "
686
        "tracked.");
687
    }
688

689
    // Reshape into track_identifiers
690
    int n_tracks = temp.size() / 3;
48✔
691
    for (int i = 0; i < n_tracks; ++i) {
192✔
692
      track_identifiers.push_back(
144✔
693
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
144✔
694
    }
695
  }
48✔
696

697
  // Shannon entropy
698
  if (solver_type == SolverType::RANDOM_RAY) {
6,281✔
699
    if (check_for_node(root, "entropy_mesh")) {
400✔
700
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
701
                  "No user-defined entropy mesh is supported.");
702
    }
703
    entropy_on = true;
400✔
704
  } else if (solver_type == SolverType::MONTE_CARLO) {
5,881✔
705
    if (check_for_node(root, "entropy_mesh")) {
5,881✔
706
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
335✔
707
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
335✔
708
        fatal_error(fmt::format(
×
709
          "Mesh {} specified for Shannon entropy does not exist.", temp));
710
      }
711

712
      auto* m = dynamic_cast<RegularMesh*>(
335✔
713
        model::meshes[model::mesh_map.at(temp)].get());
335✔
714
      if (!m)
335✔
715
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
716
      simulation::entropy_mesh = m;
335✔
717

718
      // Turn on Shannon entropy calculation
719
      entropy_on = true;
335✔
720

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

737
    auto* m =
738
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
16✔
739
    if (!m)
16✔
740
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
741
    simulation::ufs_mesh = m;
16✔
742

743
    // Turn on uniform fission source weighting
744
    ufs_on = true;
16✔
745

746
  } else if (check_for_node(root, "uniform_fs")) {
6,265✔
747
    fatal_error(
×
748
      "Specifying a UFS mesh via the <uniform_fs> element "
749
      "is deprecated. Please create a mesh using <mesh> and then reference "
750
      "it by specifying its ID in a <ufs_mesh> element.");
751
  }
752

753
  // Check if the user has specified to write state points
754
  if (check_for_node(root, "state_point")) {
6,281✔
755

756
    // Get pointer to state_point node
757
    auto node_sp = root.child("state_point");
172✔
758

759
    // Determine number of batches at which to store state points
760
    if (check_for_node(node_sp, "batches")) {
172✔
761
      // User gave specific batches to write state points
762
      auto temp = get_node_array<int>(node_sp, "batches");
172✔
763
      for (const auto& b : temp) {
532✔
764
        statepoint_batch.insert(b);
360✔
765
      }
766
    } else {
172✔
767
      // If neither were specified, write state point at last batch
768
      statepoint_batch.insert(n_batches);
×
769
    }
770
  } else {
771
    // If no <state_point> tag was present, by default write state point at
772
    // last batch only
773
    statepoint_batch.insert(n_batches);
6,109✔
774
  }
775

776
  // Check if the user has specified to write source points
777
  if (check_for_node(root, "source_point")) {
6,281✔
778
    // Get source_point node
779
    xml_node node_sp = root.child("source_point");
96✔
780

781
    // Determine batches at which to store source points
782
    if (check_for_node(node_sp, "batches")) {
96✔
783
      // User gave specific batches to write source points
784
      auto temp = get_node_array<int>(node_sp, "batches");
48✔
785
      for (const auto& b : temp) {
128✔
786
        sourcepoint_batch.insert(b);
80✔
787
      }
788
    } else {
48✔
789
      // If neither were specified, write source points with state points
790
      sourcepoint_batch = statepoint_batch;
48✔
791
    }
792

793
    // Check if the user has specified to write binary source file
794
    if (check_for_node(node_sp, "separate")) {
96✔
795
      source_separate = get_node_value_bool(node_sp, "separate");
64✔
796
    }
797
    if (check_for_node(node_sp, "write")) {
96✔
798
      source_write = get_node_value_bool(node_sp, "write");
×
799
    }
800
    if (check_for_node(node_sp, "mcpl")) {
96✔
801
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
16✔
802

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

820
  // Check is the user specified to convert strength to statistical weight
821
  if (check_for_node(root, "uniform_source_sampling")) {
6,281✔
822
    uniform_source_sampling =
55✔
823
      get_node_value_bool(root, "uniform_source_sampling");
55✔
824
  }
825

826
  // Check if the user has specified to write surface source
827
  if (check_for_node(root, "surf_source_write")) {
6,281✔
828
    surf_source_write = true;
401✔
829
    // Get surface source write node
830
    xml_node node_ssw = root.child("surf_source_write");
401✔
831

832
    // Determine surface ids at which crossing particles are to be banked.
833
    // If no surfaces are specified, all surfaces in the model will be used
834
    // to bank source points.
835
    if (check_for_node(node_ssw, "surface_ids")) {
401✔
836
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
191✔
837
      for (const auto& b : temp) {
972✔
838
        source_write_surf_id.insert(b);
781✔
839
      }
840
    }
191✔
841

842
    // Get maximum number of particles to be banked per surface
843
    if (check_for_node(node_ssw, "max_particles")) {
401✔
844
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
392✔
845
    } else {
846
      fatal_error("A maximum number of particles needs to be specified "
9✔
847
                  "using the 'max_particles' parameter to store surface "
848
                  "source points.");
849
    }
850

851
    // Get maximum number of surface source files to be created
852
    if (check_for_node(node_ssw, "max_source_files")) {
392✔
853
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
33✔
854
    } else {
855
      ssw_max_files = 1;
359✔
856
    }
857

858
    if (check_for_node(node_ssw, "mcpl")) {
392✔
859
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
×
860

861
      // Make sure MCPL support is enabled
862
      if (surf_mcpl_write && !MCPL_ENABLED) {
×
863
        fatal_error("Your build of OpenMC does not support writing MCPL "
×
864
                    "surface source files.");
865
      }
866
    }
867
    // Get cell information
868
    if (check_for_node(node_ssw, "cell")) {
392✔
869
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
104✔
870
      ssw_cell_type = SSWCellType::Both;
104✔
871
    }
872
    if (check_for_node(node_ssw, "cellfrom")) {
392✔
873
      if (ssw_cell_id != C_NONE) {
90✔
874
        fatal_error(
18✔
875
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
876
      }
877
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
72✔
878
      ssw_cell_type = SSWCellType::From;
72✔
879
    }
880
    if (check_for_node(node_ssw, "cellto")) {
374✔
881
      if (ssw_cell_id != C_NONE) {
71✔
882
        fatal_error(
18✔
883
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
884
      }
885
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
53✔
886
      ssw_cell_type = SSWCellType::To;
53✔
887
    }
888
  }
889

890
  // If source is not separate and is to be written out in the statepoint file,
891
  // make sure that the sourcepoint batch numbers are contained in the
892
  // statepoint list
893
  if (!source_separate) {
6,236✔
894
    for (const auto& b : sourcepoint_batch) {
12,452✔
895
      if (!contains(statepoint_batch, b)) {
6,296✔
896
        fatal_error(
×
897
          "Sourcepoint batches are not a subset of statepoint batches.");
898
      }
899
    }
900
  }
901

902
  // Check if the user has specified to not reduce tallies at the end of every
903
  // batch
904
  if (check_for_node(root, "no_reduce")) {
6,236✔
905
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
×
906
  }
907

908
  // Check if the user has specified to use confidence intervals for
909
  // uncertainties rather than standard deviations
910
  if (check_for_node(root, "confidence_intervals")) {
6,236✔
911
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
16✔
912
  }
913

914
  // Check for output options
915
  if (check_for_node(root, "output")) {
6,236✔
916
    // Get pointer to output node
917
    pugi::xml_node node_output = root.child("output");
372✔
918

919
    // Check for summary option
920
    if (check_for_node(node_output, "summary")) {
372✔
921
      output_summary = get_node_value_bool(node_output, "summary");
356✔
922
    }
923

924
    // Check for ASCII tallies output option
925
    if (check_for_node(node_output, "tallies")) {
372✔
926
      output_tallies = get_node_value_bool(node_output, "tallies");
16✔
927
    }
928

929
    // Set output directory if a path has been specified
930
    if (check_for_node(node_output, "path")) {
372✔
931
      path_output = get_node_value(node_output, "path");
×
932
      if (!ends_with(path_output, "/")) {
×
933
        path_output += "/";
×
934
      }
935
    }
936
  }
937

938
  // Resonance scattering parameters
939
  if (check_for_node(root, "resonance_scattering")) {
6,236✔
940
    xml_node node_res_scat = root.child("resonance_scattering");
16✔
941

942
    // See if resonance scattering is enabled
943
    if (check_for_node(node_res_scat, "enable")) {
16✔
944
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
16✔
945
    } else {
946
      res_scat_on = true;
×
947
    }
948

949
    // Determine what method is used
950
    if (check_for_node(node_res_scat, "method")) {
16✔
951
      auto temp = get_node_value(node_res_scat, "method", true, true);
16✔
952
      if (temp == "rvs") {
16✔
953
        res_scat_method = ResScatMethod::rvs;
16✔
954
      } else if (temp == "dbrc") {
×
955
        res_scat_method = ResScatMethod::dbrc;
×
956
      } else {
957
        fatal_error(
×
958
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
959
      }
960
    }
16✔
961

962
    // Minimum energy for resonance scattering
963
    if (check_for_node(node_res_scat, "energy_min")) {
16✔
964
      res_scat_energy_min =
16✔
965
        std::stod(get_node_value(node_res_scat, "energy_min"));
16✔
966
    }
967
    if (res_scat_energy_min < 0.0) {
16✔
968
      fatal_error("Lower resonance scattering energy bound is negative");
×
969
    }
970

971
    // Maximum energy for resonance scattering
972
    if (check_for_node(node_res_scat, "energy_max")) {
16✔
973
      res_scat_energy_max =
16✔
974
        std::stod(get_node_value(node_res_scat, "energy_max"));
16✔
975
    }
976
    if (res_scat_energy_max < res_scat_energy_min) {
16✔
977
      fatal_error("Upper resonance scattering energy bound is below the "
×
978
                  "lower resonance scattering energy bound.");
979
    }
980

981
    // Get resonance scattering nuclides
982
    if (check_for_node(node_res_scat, "nuclides")) {
16✔
983
      res_scat_nuclides =
984
        get_node_array<std::string>(node_res_scat, "nuclides");
16✔
985
    }
986
  }
987

988
  // Get volume calculations
989
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
6,562✔
990
    model::volume_calcs.emplace_back(node_vol);
326✔
991
  }
992

993
  // Get temperature settings
994
  if (check_for_node(root, "temperature_default")) {
6,236✔
995
    temperature_default =
172✔
996
      std::stod(get_node_value(root, "temperature_default"));
172✔
997
  }
998
  if (check_for_node(root, "temperature_method")) {
6,236✔
999
    auto temp = get_node_value(root, "temperature_method", true, true);
325✔
1000
    if (temp == "nearest") {
325✔
1001
      temperature_method = TemperatureMethod::NEAREST;
140✔
1002
    } else if (temp == "interpolation") {
185✔
1003
      temperature_method = TemperatureMethod::INTERPOLATION;
185✔
1004
    } else {
1005
      fatal_error("Unknown temperature method: " + temp);
×
1006
    }
1007
  }
325✔
1008
  if (check_for_node(root, "temperature_tolerance")) {
6,236✔
1009
    temperature_tolerance =
171✔
1010
      std::stod(get_node_value(root, "temperature_tolerance"));
171✔
1011
  }
1012
  if (check_for_node(root, "temperature_multipole")) {
6,236✔
1013
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
32✔
1014

1015
    // Multipole currently doesn't work with photon transport
1016
    if (temperature_multipole && photon_transport) {
32✔
1017
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1018
                  "photon transport.");
1019
    }
1020
  }
1021
  if (check_for_node(root, "temperature_range")) {
6,236✔
1022
    auto range = get_node_array<double>(root, "temperature_range");
×
1023
    temperature_range[0] = range.at(0);
×
1024
    temperature_range[1] = range.at(1);
×
1025
  }
1026

1027
  // Check for tabular_legendre options
1028
  if (check_for_node(root, "tabular_legendre")) {
6,236✔
1029
    // Get pointer to tabular_legendre node
1030
    xml_node node_tab_leg = root.child("tabular_legendre");
96✔
1031

1032
    // Check for enable option
1033
    if (check_for_node(node_tab_leg, "enable")) {
96✔
1034
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
96✔
1035
    }
1036

1037
    // Check for the number of points
1038
    if (check_for_node(node_tab_leg, "num_points")) {
96✔
1039
      legendre_to_tabular_points =
×
1040
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
1041
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
1042
        fatal_error(
×
1043
          "The 'num_points' subelement/attribute of the "
1044
          "<tabular_legendre> element must contain a value greater than 1");
1045
      }
1046
    }
1047
  }
1048

1049
  // Check whether create delayed neutrons in fission
1050
  if (check_for_node(root, "create_delayed_neutrons")) {
6,236✔
1051
    create_delayed_neutrons =
×
1052
      get_node_value_bool(root, "create_delayed_neutrons");
×
1053
  }
1054

1055
  // Check whether create fission sites
1056
  if (run_mode == RunMode::FIXED_SOURCE) {
6,236✔
1057
    if (check_for_node(root, "create_fission_neutrons")) {
2,065✔
1058
      create_fission_neutrons =
16✔
1059
        get_node_value_bool(root, "create_fission_neutrons");
16✔
1060
    }
1061
  }
1062

1063
  // Check whether to scale fission photon yields
1064
  if (check_for_node(root, "delayed_photon_scaling")) {
6,236✔
1065
    delayed_photon_scaling =
×
1066
      get_node_value_bool(root, "delayed_photon_scaling");
×
1067
  }
1068

1069
  // Check whether to use event-based parallelism
1070
  if (check_for_node(root, "event_based")) {
6,236✔
1071
    event_based = get_node_value_bool(root, "event_based");
×
1072
  }
1073

1074
  // Check whether material cell offsets should be generated
1075
  if (check_for_node(root, "material_cell_offsets")) {
6,236✔
1076
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1077
  }
1078

1079
  // Weight window information
1080
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
6,315✔
1081
    variance_reduction::weight_windows.emplace_back(
79✔
1082
      std::make_unique<WeightWindows>(node_ww));
158✔
1083
  }
1084

1085
  // Enable weight windows by default if one or more are present
1086
  if (variance_reduction::weight_windows.size() > 0)
6,236✔
1087
    settings::weight_windows_on = true;
52✔
1088

1089
  // read weight windows from file
1090
  if (check_for_node(root, "weight_windows_file")) {
6,236✔
1091
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1092
  }
1093

1094
  // read settings for weight windows value, this will override
1095
  // the automatic setting even if weight windows are present
1096
  if (check_for_node(root, "weight_windows_on")) {
6,236✔
1097
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
36✔
1098
  }
1099

1100
  if (check_for_node(root, "max_history_splits")) {
6,236✔
1101
    settings::max_history_splits =
214✔
1102
      std::stoi(get_node_value(root, "max_history_splits"));
214✔
1103
  }
1104

1105
  if (check_for_node(root, "max_tracks")) {
6,236✔
1106
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
48✔
1107
  }
1108

1109
  // Create weight window generator objects
1110
  if (check_for_node(root, "weight_window_generators")) {
6,236✔
1111
    auto wwgs_node = root.child("weight_window_generators");
49✔
1112
    for (pugi::xml_node node_wwg :
49✔
1113
      wwgs_node.children("weight_windows_generator")) {
147✔
1114
      variance_reduction::weight_windows_generators.emplace_back(
49✔
1115
        std::make_unique<WeightWindowsGenerator>(node_wwg));
98✔
1116
    }
1117
    // if any of the weight windows are intended to be generated otf, make sure
1118
    // they're applied
1119
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
49✔
1120
      if (wwg->on_the_fly_) {
49✔
1121
        settings::weight_windows_on = true;
49✔
1122
        break;
49✔
1123
      }
1124
    }
1125
  }
1126

1127
  // Set up weight window checkpoints
1128
  if (check_for_node(root, "weight_window_checkpoints")) {
6,236✔
1129
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
×
1130
    if (check_for_node(ww_checkpoints, "collision")) {
×
1131
      weight_window_checkpoint_collision =
×
1132
        get_node_value_bool(ww_checkpoints, "collision");
×
1133
    }
1134
    if (check_for_node(ww_checkpoints, "surface")) {
×
1135
      weight_window_checkpoint_surface =
×
1136
        get_node_value_bool(ww_checkpoints, "surface");
×
1137
    }
1138
  }
1139

1140
  if (check_for_node(root, "use_decay_photons")) {
6,236✔
1141
    settings::use_decay_photons =
11✔
1142
      get_node_value_bool(root, "use_decay_photons");
11✔
1143
  }
1144
}
6,236✔
1145

1146
void free_memory_settings()
6,382✔
1147
{
1148
  settings::statepoint_batch.clear();
6,382✔
1149
  settings::sourcepoint_batch.clear();
6,382✔
1150
  settings::source_write_surf_id.clear();
6,382✔
1151
  settings::res_scat_nuclides.clear();
6,382✔
1152
}
6,382✔
1153

1154
//==============================================================================
1155
// C API functions
1156
//==============================================================================
1157

1158
extern "C" int openmc_set_n_batches(
55✔
1159
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1160
{
1161
  if (settings::n_inactive >= n_batches) {
55✔
1162
    set_errmsg("Number of active batches must be greater than zero.");
11✔
1163
    return OPENMC_E_INVALID_ARGUMENT;
11✔
1164
  }
1165

1166
  if (simulation::current_batch >= n_batches) {
44✔
1167
    set_errmsg("Number of batches must be greater than current batch.");
11✔
1168
    return OPENMC_E_INVALID_ARGUMENT;
11✔
1169
  }
1170

1171
  if (!settings::trigger_on) {
33✔
1172
    // Set n_batches and n_max_batches to same value
1173
    settings::n_batches = n_batches;
11✔
1174
    settings::n_max_batches = n_batches;
11✔
1175
  } else {
1176
    // Set n_batches and n_max_batches based on value of set_max_batches
1177
    if (set_max_batches) {
22✔
1178
      settings::n_max_batches = n_batches;
11✔
1179
    } else {
1180
      settings::n_batches = n_batches;
11✔
1181
    }
1182
  }
1183

1184
  // Update size of k_generation and entropy
1185
  int m = settings::n_max_batches * settings::gen_per_batch;
33✔
1186
  simulation::k_generation.reserve(m);
33✔
1187
  simulation::entropy.reserve(m);
33✔
1188

1189
  // Add value of n_batches to statepoint_batch
1190
  if (add_statepoint_batch &&
55✔
1191
      !(contains(settings::statepoint_batch, n_batches)))
22✔
1192
    settings::statepoint_batch.insert(n_batches);
22✔
1193

1194
  return 0;
33✔
1195
}
1196

1197
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,530✔
1198
{
1199
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,530✔
1200

1201
  return 0;
2,530✔
1202
}
1203

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