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

openmc-dev / openmc / 13703779155

06 Mar 2025 04:45PM UTC coverage: 85.674% (+0.5%) from 85.129%
13703779155

Pull #3087

github

web-flow
Merge 20c292e2a into e360cb467
Pull Request #3087: wheel building with scikit build core

47261 of 55164 relevant lines covered (85.67%)

29624867.19 hits per line

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

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

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

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

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

36
namespace openmc {
37

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

42
namespace settings {
43

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

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

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

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

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

140
} // namespace settings
141

142
//==============================================================================
143
// Functions
144
//==============================================================================
145

146
void get_run_parameters(pugi::xml_node node_base)
4,881✔
147
{
148
  using namespace settings;
149
  using namespace pugi;
150

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

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

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

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

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

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

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

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

198
  // Get number of inactive batches
199
  if (run_mode == RunMode::EIGENVALUE ||
4,881✔
200
      solver_type == SolverType::RANDOM_RAY) {
1,827✔
201
    if (check_for_node(node_base, "inactive")) {
3,358✔
202
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
3,349✔
203
    }
204
    if (check_for_node(node_base, "generations_per_batch")) {
3,358✔
205
      gen_per_batch =
16✔
206
        std::stoi(get_node_value(node_base, "generations_per_batch"));
16✔
207
    }
208

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

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

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

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

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

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

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

350
  // Get root element
351
  xml_node root = doc.document_element();
856✔
352

353
  // Verbosity
354
  if (check_for_node(root, "verbosity")) {
856✔
355
    verbosity = std::stoi(get_node_value(root, "verbosity"));
32✔
356
  }
357

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

365
  write_message("Reading settings XML file...", 5);
856✔
366

367
  read_settings_xml(root);
856✔
368
}
868✔
369

370
void read_settings_xml(pugi::xml_node root)
5,246✔
371
{
372
  using namespace settings;
373
  using namespace pugi;
374

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

385
  // Check for user meshes and allocate
386
  read_meshes(root);
5,246✔
387

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

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

412
  // Check for a trigger node and get trigger information
413
  if (check_for_node(root, "trigger")) {
5,246✔
414
    xml_node node_trigger = root.child("trigger");
151✔
415

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

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

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

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

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

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

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

486
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
5,246✔
487
    // Read run parameters
488
    get_run_parameters(node_mode);
4,881✔
489

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

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

511
  // Copy random number seed if specified
512
  if (check_for_node(root, "seed")) {
5,246✔
513
    auto seed = std::stoll(get_node_value(root, "seed"));
379✔
514
    openmc_set_seed(seed);
379✔
515
  }
516

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

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

535
  // Check for photon transport
536
  if (check_for_node(root, "photon_transport")) {
5,246✔
537
    photon_transport = get_node_value_bool(root, "photon_transport");
177✔
538

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

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

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

562
  // ==========================================================================
563
  // EXTERNAL SOURCE
564

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

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

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

584
  // Build probability mass function for sampling external sources
585
  vector<double> source_strengths;
5,236✔
586
  for (auto& s : model::external_sources) {
10,524✔
587
    source_strengths.push_back(s->strength());
5,288✔
588
  }
589
  model::external_sources_probability.assign(source_strengths);
5,236✔
590

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

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

608
  // Survival biasing
609
  if (check_for_node(root, "survival_biasing")) {
5,236✔
610
    survival_biasing = get_node_value_bool(root, "survival_biasing");
32✔
611
  }
612

613
  // Probability tables
614
  if (check_for_node(root, "ptables")) {
5,236✔
615
    urr_ptables_on = get_node_value_bool(root, "ptables");
16✔
616
  }
617

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

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

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

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

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

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

713
      // Turn on Shannon entropy calculation
714
      entropy_on = true;
93✔
715

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

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

738
    // Turn on uniform fission source weighting
739
    ufs_on = true;
16✔
740

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

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

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

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

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

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

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

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

815
  // Check is the user specified to convert strength to statistical weight
816
  if (check_for_node(root, "uniform_source_sampling")) {
5,236✔
817
    uniform_source_sampling =
44✔
818
      get_node_value_bool(root, "uniform_source_sampling");
44✔
819
  }
820

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

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

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

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

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

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

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

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

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

909
  // Check for output options
910
  if (check_for_node(root, "output")) {
5,191✔
911
    // Get pointer to output node
912
    pugi::xml_node node_output = root.child("output");
306✔
913

914
    // Check for summary option
915
    if (check_for_node(node_output, "summary")) {
306✔
916
      output_summary = get_node_value_bool(node_output, "summary");
290✔
917
    }
918

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

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

933
  // Resonance scattering parameters
934
  if (check_for_node(root, "resonance_scattering")) {
5,191✔
935
    xml_node node_res_scat = root.child("resonance_scattering");
16✔
936

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

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

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

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

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

983
  // Get volume calculations
984
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
5,476✔
985
    model::volume_calcs.emplace_back(node_vol);
285✔
986
  }
987

988
  // Get temperature settings
989
  if (check_for_node(root, "temperature_default")) {
5,191✔
990
    temperature_default =
172✔
991
      std::stod(get_node_value(root, "temperature_default"));
172✔
992
  }
993
  if (check_for_node(root, "temperature_method")) {
5,191✔
994
    auto temp = get_node_value(root, "temperature_method", true, true);
325✔
995
    if (temp == "nearest") {
325✔
996
      temperature_method = TemperatureMethod::NEAREST;
140✔
997
    } else if (temp == "interpolation") {
185✔
998
      temperature_method = TemperatureMethod::INTERPOLATION;
185✔
999
    } else {
1000
      fatal_error("Unknown temperature method: " + temp);
×
1001
    }
1002
  }
325✔
1003
  if (check_for_node(root, "temperature_tolerance")) {
5,191✔
1004
    temperature_tolerance =
170✔
1005
      std::stod(get_node_value(root, "temperature_tolerance"));
170✔
1006
  }
1007
  if (check_for_node(root, "temperature_multipole")) {
5,191✔
1008
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
32✔
1009

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

1022
  // Check for tabular_legendre options
1023
  if (check_for_node(root, "tabular_legendre")) {
5,191✔
1024
    // Get pointer to tabular_legendre node
1025
    xml_node node_tab_leg = root.child("tabular_legendre");
96✔
1026

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

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

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

1050
  // Check whether create fission sites
1051
  if (run_mode == RunMode::FIXED_SOURCE) {
5,191✔
1052
    if (check_for_node(root, "create_fission_neutrons")) {
1,781✔
1053
      create_fission_neutrons =
16✔
1054
        get_node_value_bool(root, "create_fission_neutrons");
16✔
1055
    }
1056
  }
1057

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

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

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

1074
  // Weight window information
1075
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
5,259✔
1076
    variance_reduction::weight_windows.emplace_back(
68✔
1077
      std::make_unique<WeightWindows>(node_ww));
136✔
1078
  }
1079

1080
  // Enable weight windows by default if one or more are present
1081
  if (variance_reduction::weight_windows.size() > 0)
5,191✔
1082
    settings::weight_windows_on = true;
41✔
1083

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

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

1095
  if (check_for_node(root, "max_history_splits")) {
5,191✔
1096
    settings::max_history_splits =
60✔
1097
      std::stoi(get_node_value(root, "max_history_splits"));
60✔
1098
  }
1099

1100
  if (check_for_node(root, "max_tracks")) {
5,191✔
1101
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
48✔
1102
  }
1103

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

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

1135
  if (check_for_node(root, "use_decay_photons")) {
5,191✔
1136
    settings::use_decay_photons =
11✔
1137
      get_node_value_bool(root, "use_decay_photons");
11✔
1138
  }
1139
}
5,191✔
1140

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

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

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

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

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

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

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

1189
  return 0;
×
1190
}
1191

1192
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
×
1193
{
1194
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
×
1195

1196
  return 0;
×
1197
}
1198

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