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

openmc-dev / openmc / 17852533892

19 Sep 2025 08:10AM UTC coverage: 85.197% (-0.004%) from 85.201%
17852533892

push

github

web-flow
Combing for fission site sampling, and delayed neutron emission time (#2992)

Co-authored-by: Gavin Ridley <gavin.keith.ridley@gmail.com>
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>

54 of 58 new or added lines in 7 files covered. (93.1%)

4 existing lines in 3 files now uncovered.

53173 of 62412 relevant lines covered (85.2%)

38753013.29 hits per line

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

81.38
/src/settings.cpp
1
#include "openmc/settings.h"
2
#include "openmc/random_ray/flat_source_domain.h"
3

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

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

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

37
namespace openmc {
38

39
//==============================================================================
40
// Global variables
41
//==============================================================================
42

43
namespace settings {
44

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

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

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

104
int64_t max_particles_in_flight {100000};
105
int max_particle_events {1000000};
106

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

147
} // namespace settings
148

149
//==============================================================================
150
// Functions
151
//==============================================================================
152

153
void get_run_parameters(pugi::xml_node node_base)
6,940✔
154
{
155
  using namespace settings;
156
  using namespace pugi;
157

158
  // Check number of particles
159
  if (!check_for_node(node_base, "particles")) {
6,940✔
160
    fatal_error("Need to specify number of particles.");
×
161
  }
162

163
  // Get number of particles if it wasn't specified as a command-line argument
164
  if (n_particles == -1) {
6,940✔
165
    n_particles = std::stoll(get_node_value(node_base, "particles"));
6,940✔
166
  }
167

168
  // Get maximum number of in flight particles for event-based mode
169
  if (check_for_node(node_base, "max_particles_in_flight")) {
6,940✔
170
    max_particles_in_flight =
×
171
      std::stoll(get_node_value(node_base, "max_particles_in_flight"));
×
172
  }
173

174
  // Get maximum number of events allowed per particle
175
  if (check_for_node(node_base, "max_particle_events")) {
6,940✔
176
    max_particle_events =
×
177
      std::stoll(get_node_value(node_base, "max_particle_events"));
×
178
  }
179

180
  // Get number of basic batches
181
  if (check_for_node(node_base, "batches")) {
6,940✔
182
    n_batches = std::stoi(get_node_value(node_base, "batches"));
6,940✔
183
  }
184
  if (!trigger_on)
6,940✔
185
    n_max_batches = n_batches;
6,792✔
186

187
  // Get max number of lost particles
188
  if (check_for_node(node_base, "max_lost_particles")) {
6,940✔
189
    max_lost_particles =
48✔
190
      std::stoi(get_node_value(node_base, "max_lost_particles"));
48✔
191
  }
192

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

199
  // Get relative number of lost particles
200
  if (check_for_node(node_base, "max_write_lost_particles")) {
6,940✔
201
    max_write_lost_particles =
16✔
202
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
16✔
203
  }
204

205
  // Get number of inactive batches
206
  if (run_mode == RunMode::EIGENVALUE ||
6,940✔
207
      solver_type == SolverType::RANDOM_RAY) {
2,543✔
208
    if (check_for_node(node_base, "inactive")) {
4,782✔
209
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,555✔
210
    }
211
    if (check_for_node(node_base, "generations_per_batch")) {
4,782✔
212
      gen_per_batch =
16✔
213
        std::stoi(get_node_value(node_base, "generations_per_batch"));
16✔
214
    }
215

216
    // Preallocate space for keff and entropy by generation
217
    int m = settings::n_max_batches * settings::gen_per_batch;
4,782✔
218
    simulation::k_generation.reserve(m);
4,782✔
219
    simulation::entropy.reserve(m);
4,782✔
220

221
    // Get the trigger information for keff
222
    if (check_for_node(node_base, "keff_trigger")) {
4,782✔
223
      xml_node node_keff_trigger = node_base.child("keff_trigger");
109✔
224

225
      if (check_for_node(node_keff_trigger, "type")) {
109✔
226
        auto temp = get_node_value(node_keff_trigger, "type", true, true);
109✔
227
        if (temp == "std_dev") {
109✔
228
          keff_trigger.metric = TriggerMetric::standard_deviation;
109✔
229
        } else if (temp == "variance") {
×
230
          keff_trigger.metric = TriggerMetric::variance;
×
231
        } else if (temp == "rel_err") {
×
232
          keff_trigger.metric = TriggerMetric::relative_error;
×
233
        } else {
234
          fatal_error("Unrecognized keff trigger type " + temp);
×
235
        }
236
      } else {
109✔
237
        fatal_error("Specify keff trigger type in settings XML");
×
238
      }
239

240
      if (check_for_node(node_keff_trigger, "threshold")) {
109✔
241
        keff_trigger.threshold =
109✔
242
          std::stod(get_node_value(node_keff_trigger, "threshold"));
109✔
243
        if (keff_trigger.threshold <= 0) {
109✔
244
          fatal_error("keff trigger threshold must be positive");
×
245
        }
246
      } else {
247
        fatal_error("Specify keff trigger threshold in settings XML");
×
248
      }
249
    }
250
  }
251

252
  // Random ray variables
253
  if (solver_type == SolverType::RANDOM_RAY) {
6,940✔
254
    xml_node random_ray_node = node_base.child("random_ray");
561✔
255
    if (check_for_node(random_ray_node, "distance_active")) {
561✔
256
      RandomRay::distance_active_ =
561✔
257
        std::stod(get_node_value(random_ray_node, "distance_active"));
561✔
258
      if (RandomRay::distance_active_ <= 0.0) {
561✔
259
        fatal_error("Random ray active distance must be greater than 0");
×
260
      }
261
    } else {
262
      fatal_error("Specify random ray active distance in settings XML");
×
263
    }
264
    if (check_for_node(random_ray_node, "distance_inactive")) {
561✔
265
      RandomRay::distance_inactive_ =
561✔
266
        std::stod(get_node_value(random_ray_node, "distance_inactive"));
561✔
267
      if (RandomRay::distance_inactive_ < 0) {
561✔
268
        fatal_error(
×
269
          "Random ray inactive distance must be greater than or equal to 0");
270
      }
271
    } else {
272
      fatal_error("Specify random ray inactive distance in settings XML");
×
273
    }
274
    if (check_for_node(random_ray_node, "source")) {
561✔
275
      xml_node source_node = random_ray_node.child("source");
561✔
276
      // Get point to list of <source> elements and make sure there is at least
277
      // one
278
      RandomRay::ray_source_ = Source::create(source_node);
561✔
279
    } else {
280
      fatal_error("Specify random ray source in settings XML");
×
281
    }
282
    if (check_for_node(random_ray_node, "volume_estimator")) {
561✔
283
      std::string temp_str =
284
        get_node_value(random_ray_node, "volume_estimator", true, true);
129✔
285
      if (temp_str == "simulation_averaged") {
129✔
286
        FlatSourceDomain::volume_estimator_ =
32✔
287
          RandomRayVolumeEstimator::SIMULATION_AVERAGED;
288
      } else if (temp_str == "naive") {
97✔
289
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::NAIVE;
65✔
290
      } else if (temp_str == "hybrid") {
32✔
291
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::HYBRID;
32✔
292
      } else {
293
        fatal_error("Unrecognized volume estimator: " + temp_str);
×
294
      }
295
    }
129✔
296
    if (check_for_node(random_ray_node, "source_shape")) {
561✔
297
      std::string temp_str =
298
        get_node_value(random_ray_node, "source_shape", true, true);
304✔
299
      if (temp_str == "flat") {
304✔
300
        RandomRay::source_shape_ = RandomRaySourceShape::FLAT;
64✔
301
      } else if (temp_str == "linear") {
240✔
302
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR;
192✔
303
      } else if (temp_str == "linear_xy") {
48✔
304
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR_XY;
48✔
305
      } else {
306
        fatal_error("Unrecognized source shape: " + temp_str);
×
307
      }
308
    }
304✔
309
    if (check_for_node(random_ray_node, "volume_normalized_flux_tallies")) {
561✔
310
      FlatSourceDomain::volume_normalized_flux_tallies_ =
480✔
311
        get_node_value_bool(random_ray_node, "volume_normalized_flux_tallies");
480✔
312
    }
313
    if (check_for_node(random_ray_node, "adjoint")) {
561✔
314
      FlatSourceDomain::adjoint_ =
32✔
315
        get_node_value_bool(random_ray_node, "adjoint");
32✔
316
    }
317
    if (check_for_node(random_ray_node, "sample_method")) {
561✔
318
      std::string temp_str =
319
        get_node_value(random_ray_node, "sample_method", true, true);
16✔
320
      if (temp_str == "prng") {
16✔
321
        RandomRay::sample_method_ = RandomRaySampleMethod::PRNG;
×
322
      } else if (temp_str == "halton") {
16✔
323
        RandomRay::sample_method_ = RandomRaySampleMethod::HALTON;
16✔
324
      } else {
325
        fatal_error("Unrecognized sample method: " + temp_str);
×
326
      }
327
    }
16✔
328
    if (check_for_node(random_ray_node, "source_region_meshes")) {
561✔
329
      pugi::xml_node node_source_region_meshes =
330
        random_ray_node.child("source_region_meshes");
161✔
331
      for (pugi::xml_node node_mesh :
161✔
332
        node_source_region_meshes.children("mesh")) {
547✔
333
        int mesh_id = std::stoi(node_mesh.attribute("id").value());
225✔
334
        for (pugi::xml_node node_domain : node_mesh.children("domain")) {
450✔
335
          int domain_id = std::stoi(node_domain.attribute("id").value());
225✔
336
          std::string domain_type = node_domain.attribute("type").value();
225✔
337
          Source::DomainType type;
338
          if (domain_type == "material") {
225✔
339
            type = Source::DomainType::MATERIAL;
32✔
340
          } else if (domain_type == "cell") {
193✔
341
            type = Source::DomainType::CELL;
32✔
342
          } else if (domain_type == "universe") {
161✔
343
            type = Source::DomainType::UNIVERSE;
161✔
344
          } else {
345
            throw std::runtime_error("Unknown domain type: " + domain_type);
×
346
          }
347
          FlatSourceDomain::mesh_domain_map_[mesh_id].emplace_back(
225✔
348
            type, domain_id);
349
          RandomRay::mesh_subdivision_enabled_ = true;
225✔
350
        }
225✔
351
      }
352
    }
353
    if (check_for_node(random_ray_node, "diagonal_stabilization_rho")) {
561✔
354
      FlatSourceDomain::diagonal_stabilization_rho_ = std::stod(
16✔
355
        get_node_value(random_ray_node, "diagonal_stabilization_rho"));
32✔
356
      if (FlatSourceDomain::diagonal_stabilization_rho_ < 0.0 ||
16✔
357
          FlatSourceDomain::diagonal_stabilization_rho_ > 1.0) {
16✔
358
        fatal_error("Random ray diagonal stabilization rho factor must be "
×
359
                    "between 0 and 1");
360
      }
361
    }
362
  }
363
}
6,940✔
364

365
void read_settings_xml()
1,703✔
366
{
367
  using namespace settings;
368
  using namespace pugi;
369
  // Check if settings.xml exists
370
  std::string filename = settings::path_input + "settings.xml";
1,703✔
371
  if (!file_exists(filename)) {
1,703✔
372
    if (run_mode != RunMode::PLOTTING) {
22✔
373
      fatal_error("Could not find any XML input files! In order to run OpenMC, "
×
374
                  "you first need a set of input files; at a minimum, this "
375
                  "includes settings.xml, geometry.xml, and materials.xml or a "
376
                  "single model XML file. Please consult the user's guide at "
377
                  "https://docs.openmc.org for further information.");
378
    } else {
379
      // The settings.xml file is optional if we just want to make a plot.
380
      return;
22✔
381
    }
382
  }
383

384
  // Parse settings.xml file
385
  xml_document doc;
1,681✔
386
  auto result = doc.load_file(filename.c_str());
1,681✔
387
  if (!result) {
1,681✔
388
    fatal_error("Error processing settings.xml file.");
×
389
  }
390

391
  // Get root element
392
  xml_node root = doc.document_element();
1,681✔
393

394
  // Verbosity
395
  if (check_for_node(root, "verbosity")) {
1,681✔
396
    verbosity = std::stoi(get_node_value(root, "verbosity"));
333✔
397
  }
398

399
  // To this point, we haven't displayed any output since we didn't know what
400
  // the verbosity is. Now that we checked for it, show the title if necessary
401
  if (mpi::master) {
1,681✔
402
    if (verbosity >= 2)
1,456✔
403
      title();
1,133✔
404
  }
405

406
  write_message("Reading settings XML file...", 5);
1,681✔
407

408
  read_settings_xml(root);
1,681✔
409
}
1,693✔
410

411
void read_settings_xml(pugi::xml_node root)
7,541✔
412
{
413
  using namespace settings;
414
  using namespace pugi;
415

416
  // Find if a multi-group or continuous-energy simulation is desired
417
  if (check_for_node(root, "energy_mode")) {
7,541✔
418
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
1,095✔
419
    if (temp_str == "mg" || temp_str == "multi-group") {
1,095✔
420
      run_CE = false;
1,095✔
421
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
422
      run_CE = true;
×
423
    }
424
  }
1,095✔
425

426
  // Check for user meshes and allocate
427
  read_meshes(root);
7,541✔
428

429
  // Look for deprecated cross_sections.xml file in settings.xml
430
  if (check_for_node(root, "cross_sections")) {
7,541✔
431
    warning(
×
432
      "Setting cross_sections in settings.xml has been deprecated."
433
      " The cross_sections are now set in materials.xml and the "
434
      "cross_sections input to materials.xml and the OPENMC_CROSS_SECTIONS"
435
      " environment variable will take precendent over setting "
436
      "cross_sections in settings.xml.");
437
    path_cross_sections = get_node_value(root, "cross_sections");
×
438
  }
439

440
  if (!run_CE) {
7,541✔
441
    // Scattering Treatments
442
    if (check_for_node(root, "max_order")) {
1,095✔
443
      max_order = std::stoi(get_node_value(root, "max_order"));
16✔
444
    } else {
445
      // Set to default of largest int - 1, which means to use whatever is
446
      // contained in library. This is largest int - 1 because for legendre
447
      // scattering, a value of 1 is added to the order; adding 1 to the largest
448
      // int gets you the largest negative integer, which is not what we want.
449
      max_order = std::numeric_limits<int>::max() - 1;
1,079✔
450
    }
451
  }
452

453
  // Check for a trigger node and get trigger information
454
  if (check_for_node(root, "trigger")) {
7,541✔
455
    xml_node node_trigger = root.child("trigger");
164✔
456

457
    // Check if trigger(s) are to be turned on
458
    trigger_on = get_node_value_bool(node_trigger, "active");
164✔
459

460
    if (trigger_on) {
164✔
461
      if (check_for_node(node_trigger, "max_batches")) {
148✔
462
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
148✔
463
      } else {
464
        fatal_error("<max_batches> must be specified with triggers");
×
465
      }
466

467
      // Get the batch interval to check triggers
468
      if (!check_for_node(node_trigger, "batch_interval")) {
148✔
469
        trigger_predict = true;
16✔
470
      } else {
471
        trigger_batch_interval =
132✔
472
          std::stoi(get_node_value(node_trigger, "batch_interval"));
132✔
473
        if (trigger_batch_interval <= 0) {
132✔
474
          fatal_error("Trigger batch interval must be greater than zero");
×
475
        }
476
      }
477
    }
478
  }
479

480
  // Check run mode if it hasn't been set from the command line
481
  xml_node node_mode;
7,541✔
482
  if (run_mode == RunMode::UNSET) {
7,541✔
483
    if (check_for_node(root, "run_mode")) {
6,972✔
484
      std::string temp_str = get_node_value(root, "run_mode", true, true);
6,940✔
485
      if (temp_str == "eigenvalue") {
6,940✔
486
        run_mode = RunMode::EIGENVALUE;
4,365✔
487
      } else if (temp_str == "fixed source") {
2,575✔
488
        run_mode = RunMode::FIXED_SOURCE;
2,543✔
489
      } else if (temp_str == "plot") {
32✔
490
        run_mode = RunMode::PLOTTING;
×
491
      } else if (temp_str == "particle restart") {
32✔
492
        run_mode = RunMode::PARTICLE;
×
493
      } else if (temp_str == "volume") {
32✔
494
        run_mode = RunMode::VOLUME;
32✔
495
      } else {
496
        fatal_error("Unrecognized run mode: " + temp_str);
×
497
      }
498

499
      // Assume XML specifies <particles>, <batches>, etc. directly
500
      node_mode = root;
6,940✔
501
    } else {
6,940✔
502
      warning("<run_mode> should be specified.");
32✔
503

504
      // Make sure that either eigenvalue or fixed source was specified
505
      node_mode = root.child("eigenvalue");
32✔
506
      if (node_mode) {
32✔
507
        run_mode = RunMode::EIGENVALUE;
32✔
508
      } else {
509
        node_mode = root.child("fixed_source");
×
510
        if (node_mode) {
×
511
          run_mode = RunMode::FIXED_SOURCE;
×
512
        } else {
513
          fatal_error("<eigenvalue> or <fixed_source> not specified.");
×
514
        }
515
      }
516
    }
517
  }
518

519
  // Check solver type
520
  if (check_for_node(root, "random_ray")) {
7,541✔
521
    solver_type = SolverType::RANDOM_RAY;
561✔
522
    if (run_CE)
561✔
523
      fatal_error("multi-group energy mode must be specified in settings XML "
×
524
                  "when using the random ray solver.");
525
  }
526

527
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
7,541✔
528
    // Read run parameters
529
    get_run_parameters(node_mode);
6,940✔
530

531
    // Check number of active batches, inactive batches, max lost particles and
532
    // particles
533
    if (n_batches <= n_inactive) {
6,940✔
534
      fatal_error("Number of active batches must be greater than zero.");
×
535
    } else if (n_inactive < 0) {
6,940✔
536
      fatal_error("Number of inactive batches must be non-negative.");
×
537
    } else if (n_particles <= 0) {
6,940✔
538
      fatal_error("Number of particles must be greater than zero.");
×
539
    } else if (max_lost_particles <= 0) {
6,940✔
540
      fatal_error("Number of max lost particles must be greater than zero.");
×
541
    } else if (rel_max_lost_particles <= 0.0 || rel_max_lost_particles >= 1.0) {
6,940✔
542
      fatal_error("Relative max lost particles must be between zero and one.");
×
543
    }
544
  }
545

546
  // Copy plotting random number seed if specified
547
  if (check_for_node(root, "plot_seed")) {
7,541✔
548
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
549
    model::plotter_seed = seed;
×
550
  }
551

552
  // Copy random number seed if specified
553
  if (check_for_node(root, "seed")) {
7,541✔
554
    auto seed = std::stoll(get_node_value(root, "seed"));
439✔
555
    openmc_set_seed(seed);
439✔
556
  }
557

558
  // Copy random number stride if specified
559
  if (check_for_node(root, "stride")) {
7,541✔
560
    auto stride = std::stoull(get_node_value(root, "stride"));
16✔
561
    openmc_set_stride(stride);
16✔
562
  }
563

564
  // Check for electron treatment
565
  if (check_for_node(root, "electron_treatment")) {
7,541✔
566
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
70✔
567
    if (temp_str == "led") {
70✔
568
      electron_treatment = ElectronTreatment::LED;
11✔
569
    } else if (temp_str == "ttb") {
59✔
570
      electron_treatment = ElectronTreatment::TTB;
59✔
571
    } else {
572
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
573
    }
574
  }
70✔
575

576
  // Check for photon transport
577
  if (check_for_node(root, "photon_transport")) {
7,541✔
578
    photon_transport = get_node_value_bool(root, "photon_transport");
200✔
579

580
    if (!run_CE && photon_transport) {
200✔
581
      fatal_error("Photon transport is not currently supported in "
×
582
                  "multigroup mode");
583
    }
584
  }
585

586
  // Number of bins for logarithmic grid
587
  if (check_for_node(root, "log_grid_bins")) {
7,541✔
588
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
16✔
589
    if (n_log_bins < 1) {
16✔
590
      fatal_error("Number of bins for logarithmic grid must be greater "
×
591
                  "than zero.");
592
    }
593
  }
594

595
  // Number of OpenMP threads
596
  if (check_for_node(root, "threads")) {
7,541✔
597
    if (mpi::master)
×
598
      warning("The <threads> element has been deprecated. Use "
×
599
              "the OMP_NUM_THREADS environment variable to set the number of "
600
              "threads.");
601
  }
602

603
  // ==========================================================================
604
  // EXTERNAL SOURCE
605

606
  // Get point to list of <source> elements and make sure there is at least one
607
  for (pugi::xml_node node : root.children("source")) {
14,358✔
608
    model::external_sources.push_back(Source::create(node));
6,827✔
609
  }
610

611
  // Check if the user has specified to read surface source
612
  if (check_for_node(root, "surf_source_read")) {
7,531✔
613
    surf_source_read = true;
32✔
614
    // Get surface source read node
615
    xml_node node_ssr = root.child("surf_source_read");
32✔
616

617
    std::string path = "surface_source.h5";
32✔
618
    // Check if the user has specified different file for surface source reading
619
    if (check_for_node(node_ssr, "path")) {
32✔
620
      path = get_node_value(node_ssr, "path", false, true);
32✔
621
    }
622
    model::external_sources.push_back(make_unique<FileSource>(path));
32✔
623
  }
32✔
624

625
  // If no source specified, default to isotropic point source at origin with
626
  // Watt spectrum. No default source is needed in random ray mode.
627
  if (model::external_sources.empty() &&
9,669✔
628
      settings::solver_type != SolverType::RANDOM_RAY) {
2,138✔
629
    double T[] {0.0};
2,026✔
630
    double p[] {1.0};
2,026✔
631
    model::external_sources.push_back(make_unique<IndependentSource>(
2,026✔
632
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
4,052✔
633
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
4,052✔
634
      UPtrDist {new Discrete(T, p, 1)}));
4,052✔
635
  }
636

637
  // Build probability mass function for sampling external sources
638
  vector<double> source_strengths;
7,531✔
639
  for (auto& s : model::external_sources) {
16,406✔
640
    source_strengths.push_back(s->strength());
8,875✔
641
  }
642
  model::external_sources_probability.assign(source_strengths);
7,531✔
643

644
  // Check if we want to write out source
645
  if (check_for_node(root, "write_initial_source")) {
7,531✔
646
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
647
  }
648

649
  // Get relative number of lost particles
650
  if (check_for_node(root, "source_rejection_fraction")) {
7,531✔
651
    source_rejection_fraction =
6✔
652
      std::stod(get_node_value(root, "source_rejection_fraction"));
6✔
653
  }
654

655
  // Survival biasing
656
  if (check_for_node(root, "survival_biasing")) {
7,531✔
657
    survival_biasing = get_node_value_bool(root, "survival_biasing");
189✔
658
  }
659

660
  // Probability tables
661
  if (check_for_node(root, "ptables")) {
7,531✔
662
    urr_ptables_on = get_node_value_bool(root, "ptables");
16✔
663
  }
664

665
  // Cutoffs
666
  if (check_for_node(root, "cutoff")) {
7,531✔
667
    xml_node node_cutoff = root.child("cutoff");
129✔
668
    if (check_for_node(node_cutoff, "weight")) {
129✔
669
      weight_cutoff = std::stod(get_node_value(node_cutoff, "weight"));
16✔
670
    }
671
    if (check_for_node(node_cutoff, "weight_avg")) {
129✔
672
      weight_survive = std::stod(get_node_value(node_cutoff, "weight_avg"));
16✔
673
    }
674
    if (check_for_node(node_cutoff, "survival_normalization")) {
129✔
675
      survival_normalization =
×
676
        get_node_value_bool(node_cutoff, "survival_normalization");
×
677
    }
678
    if (check_for_node(node_cutoff, "energy_neutron")) {
129✔
679
      energy_cutoff[0] =
32✔
680
        std::stod(get_node_value(node_cutoff, "energy_neutron"));
16✔
681
    } else if (check_for_node(node_cutoff, "energy")) {
113✔
682
      warning("The use of an <energy> cutoff is deprecated and should "
×
683
              "be replaced by <energy_neutron>.");
684
      energy_cutoff[0] = std::stod(get_node_value(node_cutoff, "energy"));
×
685
    }
686
    if (check_for_node(node_cutoff, "energy_photon")) {
129✔
687
      energy_cutoff[1] =
140✔
688
        std::stod(get_node_value(node_cutoff, "energy_photon"));
70✔
689
    }
690
    if (check_for_node(node_cutoff, "energy_electron")) {
129✔
691
      energy_cutoff[2] =
×
692
        std::stof(get_node_value(node_cutoff, "energy_electron"));
×
693
    }
694
    if (check_for_node(node_cutoff, "energy_positron")) {
129✔
695
      energy_cutoff[3] =
×
696
        std::stod(get_node_value(node_cutoff, "energy_positron"));
×
697
    }
698
    if (check_for_node(node_cutoff, "time_neutron")) {
129✔
699
      time_cutoff[0] = std::stod(get_node_value(node_cutoff, "time_neutron"));
27✔
700
    }
701
    if (check_for_node(node_cutoff, "time_photon")) {
129✔
702
      time_cutoff[1] = std::stod(get_node_value(node_cutoff, "time_photon"));
×
703
    }
704
    if (check_for_node(node_cutoff, "time_electron")) {
129✔
705
      time_cutoff[2] = std::stod(get_node_value(node_cutoff, "time_electron"));
×
706
    }
707
    if (check_for_node(node_cutoff, "time_positron")) {
129✔
708
      time_cutoff[3] = std::stod(get_node_value(node_cutoff, "time_positron"));
×
709
    }
710
  }
711

712
  // Particle trace
713
  if (check_for_node(root, "trace")) {
7,531✔
714
    auto temp = get_node_array<int64_t>(root, "trace");
16✔
715
    if (temp.size() != 3) {
16✔
716
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
717
                  "batch, generation, and particle number.");
718
    }
719
    trace_batch = temp.at(0);
16✔
720
    trace_gen = temp.at(1);
16✔
721
    trace_particle = temp.at(2);
16✔
722
  }
16✔
723

724
  // Particle tracks
725
  if (check_for_node(root, "track")) {
7,531✔
726
    // Get values and make sure there are three per particle
727
    auto temp = get_node_array<int>(root, "track");
48✔
728
    if (temp.size() % 3 != 0) {
48✔
729
      fatal_error(
×
730
        "Number of integers specified in 'track' is not "
731
        "divisible by 3.  Please provide 3 integers per particle to be "
732
        "tracked.");
733
    }
734

735
    // Reshape into track_identifiers
736
    int n_tracks = temp.size() / 3;
48✔
737
    for (int i = 0; i < n_tracks; ++i) {
192✔
738
      track_identifiers.push_back(
144✔
739
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
144✔
740
    }
741
  }
48✔
742

743
  // Shannon entropy
744
  if (solver_type == SolverType::RANDOM_RAY) {
7,531✔
745
    if (check_for_node(root, "entropy_mesh")) {
561✔
746
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
747
                  "No user-defined entropy mesh is supported.");
748
    }
749
    entropy_on = true;
561✔
750
  } else if (solver_type == SolverType::MONTE_CARLO) {
6,970✔
751
    if (check_for_node(root, "entropy_mesh")) {
6,970✔
752
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
364✔
753
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
364✔
754
        fatal_error(fmt::format(
×
755
          "Mesh {} specified for Shannon entropy does not exist.", temp));
756
      }
757

758
      auto* m = dynamic_cast<RegularMesh*>(
364✔
759
        model::meshes[model::mesh_map.at(temp)].get());
364✔
760
      if (!m)
364✔
761
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
762
      simulation::entropy_mesh = m;
364✔
763

764
      // Turn on Shannon entropy calculation
765
      entropy_on = true;
364✔
766

767
    } else if (check_for_node(root, "entropy")) {
6,606✔
768
      fatal_error(
×
769
        "Specifying a Shannon entropy mesh via the <entropy> element "
770
        "is deprecated. Please create a mesh using <mesh> and then reference "
771
        "it by specifying its ID in an <entropy_mesh> element.");
772
    }
773
  }
774
  // Uniform fission source weighting mesh
775
  if (check_for_node(root, "ufs_mesh")) {
7,531✔
776
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
16✔
777
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
16✔
778
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
779
                              "method does not exist.",
780
        temp));
781
    }
782

783
    auto* m =
784
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
16✔
785
    if (!m)
16✔
786
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
787
    simulation::ufs_mesh = m;
16✔
788

789
    // Turn on uniform fission source weighting
790
    ufs_on = true;
16✔
791

792
  } else if (check_for_node(root, "uniform_fs")) {
7,515✔
793
    fatal_error(
×
794
      "Specifying a UFS mesh via the <uniform_fs> element "
795
      "is deprecated. Please create a mesh using <mesh> and then reference "
796
      "it by specifying its ID in a <ufs_mesh> element.");
797
  }
798

799
  // Check if the user has specified to write state points
800
  if (check_for_node(root, "state_point")) {
7,531✔
801

802
    // Get pointer to state_point node
803
    auto node_sp = root.child("state_point");
169✔
804

805
    // Determine number of batches at which to store state points
806
    if (check_for_node(node_sp, "batches")) {
169✔
807
      // User gave specific batches to write state points
808
      auto temp = get_node_array<int>(node_sp, "batches");
169✔
809
      for (const auto& b : temp) {
518✔
810
        statepoint_batch.insert(b);
349✔
811
      }
812
    } else {
169✔
813
      // If neither were specified, write state point at last batch
814
      statepoint_batch.insert(n_batches);
×
815
    }
816
  } else {
817
    // If no <state_point> tag was present, by default write state point at
818
    // last batch only
819
    statepoint_batch.insert(n_batches);
7,362✔
820
  }
821

822
  // Check if the user has specified to write source points
823
  if (check_for_node(root, "source_point")) {
7,531✔
824
    // Get source_point node
825
    xml_node node_sp = root.child("source_point");
107✔
826

827
    // Determine batches at which to store source points
828
    if (check_for_node(node_sp, "batches")) {
107✔
829
      // User gave specific batches to write source points
830
      auto temp = get_node_array<int>(node_sp, "batches");
48✔
831
      for (const auto& b : temp) {
128✔
832
        sourcepoint_batch.insert(b);
80✔
833
      }
834
    } else {
48✔
835
      // If neither were specified, write source points with state points
836
      sourcepoint_batch = statepoint_batch;
59✔
837
    }
838

839
    // Check if the user has specified to write binary source file
840
    if (check_for_node(node_sp, "separate")) {
107✔
841
      source_separate = get_node_value_bool(node_sp, "separate");
75✔
842
    }
843
    if (check_for_node(node_sp, "write")) {
107✔
844
      source_write = get_node_value_bool(node_sp, "write");
×
845
    }
846
    if (check_for_node(node_sp, "mcpl")) {
107✔
847
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
27✔
848
    }
849
    if (check_for_node(node_sp, "overwrite_latest")) {
107✔
850
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
16✔
851
      source_separate = source_latest;
16✔
852
    }
853
  } else {
854
    // If no <source_point> tag was present, by default we keep source bank in
855
    // statepoint file and write it out at statepoints intervals
856
    source_separate = false;
7,424✔
857
    sourcepoint_batch = statepoint_batch;
7,424✔
858
  }
859

860
  // Check is the user specified to convert strength to statistical weight
861
  if (check_for_node(root, "uniform_source_sampling")) {
7,531✔
862
    uniform_source_sampling =
56✔
863
      get_node_value_bool(root, "uniform_source_sampling");
56✔
864
  }
865

866
  // Check if the user has specified to write surface source
867
  if (check_for_node(root, "surf_source_write")) {
7,531✔
868
    surf_source_write = true;
413✔
869
    // Get surface source write node
870
    xml_node node_ssw = root.child("surf_source_write");
413✔
871

872
    // Determine surface ids at which crossing particles are to be banked.
873
    // If no surfaces are specified, all surfaces in the model will be used
874
    // to bank source points.
875
    if (check_for_node(node_ssw, "surface_ids")) {
413✔
876
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
202✔
877
      for (const auto& b : temp) {
994✔
878
        source_write_surf_id.insert(b);
792✔
879
      }
880
    }
202✔
881

882
    // Get maximum number of particles to be banked per surface
883
    if (check_for_node(node_ssw, "max_particles")) {
413✔
884
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
404✔
885
    } else {
886
      fatal_error("A maximum number of particles needs to be specified "
9✔
887
                  "using the 'max_particles' parameter to store surface "
888
                  "source points.");
889
    }
890

891
    // Get maximum number of surface source files to be created
892
    if (check_for_node(node_ssw, "max_source_files")) {
404✔
893
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
33✔
894
    } else {
895
      ssw_max_files = 1;
371✔
896
    }
897

898
    if (check_for_node(node_ssw, "mcpl")) {
404✔
899
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
11✔
900
    }
901
    // Get cell information
902
    if (check_for_node(node_ssw, "cell")) {
404✔
903
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
104✔
904
      ssw_cell_type = SSWCellType::Both;
104✔
905
    }
906
    if (check_for_node(node_ssw, "cellfrom")) {
404✔
907
      if (ssw_cell_id != C_NONE) {
90✔
908
        fatal_error(
18✔
909
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
910
      }
911
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
72✔
912
      ssw_cell_type = SSWCellType::From;
72✔
913
    }
914
    if (check_for_node(node_ssw, "cellto")) {
386✔
915
      if (ssw_cell_id != C_NONE) {
71✔
916
        fatal_error(
18✔
917
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
918
      }
919
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
53✔
920
      ssw_cell_type = SSWCellType::To;
53✔
921
    }
922
  }
923

924
  // If source is not separate and is to be written out in the statepoint file,
925
  // make sure that the sourcepoint batch numbers are contained in the
926
  // statepoint list
927
  if (!source_separate) {
7,486✔
928
    for (const auto& b : sourcepoint_batch) {
14,922✔
929
      if (!contains(statepoint_batch, b)) {
7,527✔
930
        fatal_error(
×
931
          "Sourcepoint batches are not a subset of statepoint batches.");
932
      }
933
    }
934
  }
935

936
  // Check if the user has specified to not reduce tallies at the end of every
937
  // batch
938
  if (check_for_node(root, "no_reduce")) {
7,486✔
939
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
×
940
  }
941

942
  // Check if the user has specified to use confidence intervals for
943
  // uncertainties rather than standard deviations
944
  if (check_for_node(root, "confidence_intervals")) {
7,486✔
945
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
16✔
946
  }
947

948
  // Check for output options
949
  if (check_for_node(root, "output")) {
7,486✔
950
    // Get pointer to output node
951
    pugi::xml_node node_output = root.child("output");
566✔
952

953
    // Check for summary option
954
    if (check_for_node(node_output, "summary")) {
566✔
955
      output_summary = get_node_value_bool(node_output, "summary");
539✔
956
    }
957

958
    // Check for ASCII tallies output option
959
    if (check_for_node(node_output, "tallies")) {
566✔
960
      output_tallies = get_node_value_bool(node_output, "tallies");
95✔
961
    }
962

963
    // Set output directory if a path has been specified
964
    if (check_for_node(node_output, "path")) {
566✔
965
      path_output = get_node_value(node_output, "path");
×
966
      if (!ends_with(path_output, "/")) {
×
967
        path_output += "/";
×
968
      }
969
    }
970
  }
971

972
  // Resonance scattering parameters
973
  if (check_for_node(root, "resonance_scattering")) {
7,486✔
974
    xml_node node_res_scat = root.child("resonance_scattering");
16✔
975

976
    // See if resonance scattering is enabled
977
    if (check_for_node(node_res_scat, "enable")) {
16✔
978
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
16✔
979
    } else {
980
      res_scat_on = true;
×
981
    }
982

983
    // Determine what method is used
984
    if (check_for_node(node_res_scat, "method")) {
16✔
985
      auto temp = get_node_value(node_res_scat, "method", true, true);
16✔
986
      if (temp == "rvs") {
16✔
987
        res_scat_method = ResScatMethod::rvs;
16✔
988
      } else if (temp == "dbrc") {
×
989
        res_scat_method = ResScatMethod::dbrc;
×
990
      } else {
991
        fatal_error(
×
992
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
993
      }
994
    }
16✔
995

996
    // Minimum energy for resonance scattering
997
    if (check_for_node(node_res_scat, "energy_min")) {
16✔
998
      res_scat_energy_min =
16✔
999
        std::stod(get_node_value(node_res_scat, "energy_min"));
16✔
1000
    }
1001
    if (res_scat_energy_min < 0.0) {
16✔
1002
      fatal_error("Lower resonance scattering energy bound is negative");
×
1003
    }
1004

1005
    // Maximum energy for resonance scattering
1006
    if (check_for_node(node_res_scat, "energy_max")) {
16✔
1007
      res_scat_energy_max =
16✔
1008
        std::stod(get_node_value(node_res_scat, "energy_max"));
16✔
1009
    }
1010
    if (res_scat_energy_max < res_scat_energy_min) {
16✔
1011
      fatal_error("Upper resonance scattering energy bound is below the "
×
1012
                  "lower resonance scattering energy bound.");
1013
    }
1014

1015
    // Get resonance scattering nuclides
1016
    if (check_for_node(node_res_scat, "nuclides")) {
16✔
1017
      res_scat_nuclides =
1018
        get_node_array<std::string>(node_res_scat, "nuclides");
16✔
1019
    }
1020
  }
1021

1022
  // Get volume calculations
1023
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
7,949✔
1024
    model::volume_calcs.emplace_back(node_vol);
463✔
1025
  }
1026

1027
  // Get temperature settings
1028
  if (check_for_node(root, "temperature_default")) {
7,486✔
1029
    temperature_default =
172✔
1030
      std::stod(get_node_value(root, "temperature_default"));
172✔
1031
  }
1032
  if (check_for_node(root, "temperature_method")) {
7,486✔
1033
    auto temp = get_node_value(root, "temperature_method", true, true);
325✔
1034
    if (temp == "nearest") {
325✔
1035
      temperature_method = TemperatureMethod::NEAREST;
140✔
1036
    } else if (temp == "interpolation") {
185✔
1037
      temperature_method = TemperatureMethod::INTERPOLATION;
185✔
1038
    } else {
1039
      fatal_error("Unknown temperature method: " + temp);
×
1040
    }
1041
  }
325✔
1042
  if (check_for_node(root, "temperature_tolerance")) {
7,486✔
1043
    temperature_tolerance =
178✔
1044
      std::stod(get_node_value(root, "temperature_tolerance"));
178✔
1045
  }
1046
  if (check_for_node(root, "temperature_multipole")) {
7,486✔
1047
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
32✔
1048

1049
    // Multipole currently doesn't work with photon transport
1050
    if (temperature_multipole && photon_transport) {
32✔
1051
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1052
                  "photon transport.");
1053
    }
1054
  }
1055
  if (check_for_node(root, "temperature_range")) {
7,486✔
1056
    auto range = get_node_array<double>(root, "temperature_range");
×
1057
    temperature_range[0] = range.at(0);
×
1058
    temperature_range[1] = range.at(1);
×
1059
  }
1060

1061
  // Check for user value for the number of generation of the Iterated Fission
1062
  // Probability (IFP) method
1063
  if (check_for_node(root, "ifp_n_generation")) {
7,486✔
1064
    ifp_n_generation = std::stoi(get_node_value(root, "ifp_n_generation"));
25✔
1065
    if (ifp_n_generation <= 0) {
25✔
1066
      fatal_error("'ifp_n_generation' must be greater than 0.");
×
1067
    }
1068
    // Avoid tallying 0 if IFP logs are not complete when active cycles start
1069
    if (ifp_n_generation > n_inactive) {
25✔
1070
      fatal_error("'ifp_n_generation' must be lower than or equal to the "
9✔
1071
                  "number of inactive cycles.");
1072
    }
1073
  }
1074

1075
  // Check for tabular_legendre options
1076
  if (check_for_node(root, "tabular_legendre")) {
7,477✔
1077
    // Get pointer to tabular_legendre node
1078
    xml_node node_tab_leg = root.child("tabular_legendre");
96✔
1079

1080
    // Check for enable option
1081
    if (check_for_node(node_tab_leg, "enable")) {
96✔
1082
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
96✔
1083
    }
1084

1085
    // Check for the number of points
1086
    if (check_for_node(node_tab_leg, "num_points")) {
96✔
1087
      legendre_to_tabular_points =
×
1088
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
1089
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
1090
        fatal_error(
×
1091
          "The 'num_points' subelement/attribute of the "
1092
          "<tabular_legendre> element must contain a value greater than 1");
1093
      }
1094
    }
1095
  }
1096

1097
  // Check whether create delayed neutrons in fission
1098
  if (check_for_node(root, "create_delayed_neutrons")) {
7,477✔
1099
    create_delayed_neutrons =
×
1100
      get_node_value_bool(root, "create_delayed_neutrons");
×
1101
  }
1102

1103
  // Check whether create fission sites
1104
  if (run_mode == RunMode::FIXED_SOURCE) {
7,477✔
1105
    if (check_for_node(root, "create_fission_neutrons")) {
2,497✔
1106
      create_fission_neutrons =
16✔
1107
        get_node_value_bool(root, "create_fission_neutrons");
16✔
1108
    }
1109
  }
1110

1111
  // Check whether to scale fission photon yields
1112
  if (check_for_node(root, "delayed_photon_scaling")) {
7,477✔
1113
    delayed_photon_scaling =
×
1114
      get_node_value_bool(root, "delayed_photon_scaling");
×
1115
  }
1116

1117
  // Check whether to use event-based parallelism
1118
  if (check_for_node(root, "event_based")) {
7,477✔
1119
    event_based = get_node_value_bool(root, "event_based");
×
1120
  }
1121

1122
  // Check whether material cell offsets should be generated
1123
  if (check_for_node(root, "material_cell_offsets")) {
7,477✔
1124
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1125
  }
1126

1127
  // Weight window information
1128
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
7,570✔
1129
    variance_reduction::weight_windows.emplace_back(
93✔
1130
      std::make_unique<WeightWindows>(node_ww));
186✔
1131
  }
1132

1133
  // Enable weight windows by default if one or more are present
1134
  if (variance_reduction::weight_windows.size() > 0)
7,477✔
1135
    settings::weight_windows_on = true;
66✔
1136

1137
  // read weight windows from file
1138
  if (check_for_node(root, "weight_windows_file")) {
7,477✔
1139
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1140
  }
1141

1142
  // read settings for weight windows value, this will override
1143
  // the automatic setting even if weight windows are present
1144
  if (check_for_node(root, "weight_windows_on")) {
7,477✔
1145
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
37✔
1146
  }
1147

1148
  if (check_for_node(root, "max_secondaries")) {
7,477✔
NEW
1149
    settings::max_secondaries =
×
NEW
1150
      std::stoi(get_node_value(root, "max_secondaries"));
×
1151
  }
1152

1153
  if (check_for_node(root, "max_history_splits")) {
7,477✔
1154
    settings::max_history_splits =
228✔
1155
      std::stoi(get_node_value(root, "max_history_splits"));
228✔
1156
  }
1157

1158
  if (check_for_node(root, "max_tracks")) {
7,477✔
1159
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
48✔
1160
  }
1161

1162
  // Create weight window generator objects
1163
  if (check_for_node(root, "weight_window_generators")) {
7,477✔
1164
    auto wwgs_node = root.child("weight_window_generators");
82✔
1165
    for (pugi::xml_node node_wwg :
82✔
1166
      wwgs_node.children("weight_windows_generator")) {
246✔
1167
      variance_reduction::weight_windows_generators.emplace_back(
82✔
1168
        std::make_unique<WeightWindowsGenerator>(node_wwg));
164✔
1169
    }
1170
    // if any of the weight windows are intended to be generated otf, make sure
1171
    // they're applied
1172
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
82✔
1173
      if (wwg->on_the_fly_) {
82✔
1174
        settings::weight_windows_on = true;
82✔
1175
        break;
82✔
1176
      }
1177
    }
1178
  }
1179

1180
  // Set up weight window checkpoints
1181
  if (check_for_node(root, "weight_window_checkpoints")) {
7,477✔
1182
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
1✔
1183
    if (check_for_node(ww_checkpoints, "collision")) {
1✔
1184
      weight_window_checkpoint_collision =
1✔
1185
        get_node_value_bool(ww_checkpoints, "collision");
1✔
1186
    }
1187
    if (check_for_node(ww_checkpoints, "surface")) {
1✔
1188
      weight_window_checkpoint_surface =
1✔
1189
        get_node_value_bool(ww_checkpoints, "surface");
1✔
1190
    }
1191
  }
1192

1193
  if (check_for_node(root, "use_decay_photons")) {
7,477✔
1194
    settings::use_decay_photons =
11✔
1195
      get_node_value_bool(root, "use_decay_photons");
11✔
1196
  }
1197
}
7,477✔
1198

1199
void free_memory_settings()
7,810✔
1200
{
1201
  settings::statepoint_batch.clear();
7,810✔
1202
  settings::sourcepoint_batch.clear();
7,810✔
1203
  settings::source_write_surf_id.clear();
7,810✔
1204
  settings::res_scat_nuclides.clear();
7,810✔
1205
}
7,810✔
1206

1207
//==============================================================================
1208
// C API functions
1209
//==============================================================================
1210

1211
extern "C" int openmc_set_n_batches(
65✔
1212
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1213
{
1214
  if (settings::n_inactive >= n_batches) {
65✔
1215
    set_errmsg("Number of active batches must be greater than zero.");
13✔
1216
    return OPENMC_E_INVALID_ARGUMENT;
13✔
1217
  }
1218

1219
  if (simulation::current_batch >= n_batches) {
52✔
1220
    set_errmsg("Number of batches must be greater than current batch.");
13✔
1221
    return OPENMC_E_INVALID_ARGUMENT;
13✔
1222
  }
1223

1224
  if (!settings::trigger_on) {
39✔
1225
    // Set n_batches and n_max_batches to same value
1226
    settings::n_batches = n_batches;
13✔
1227
    settings::n_max_batches = n_batches;
13✔
1228
  } else {
1229
    // Set n_batches and n_max_batches based on value of set_max_batches
1230
    if (set_max_batches) {
26✔
1231
      settings::n_max_batches = n_batches;
13✔
1232
    } else {
1233
      settings::n_batches = n_batches;
13✔
1234
    }
1235
  }
1236

1237
  // Update size of k_generation and entropy
1238
  int m = settings::n_max_batches * settings::gen_per_batch;
39✔
1239
  simulation::k_generation.reserve(m);
39✔
1240
  simulation::entropy.reserve(m);
39✔
1241

1242
  // Add value of n_batches to statepoint_batch
1243
  if (add_statepoint_batch &&
65✔
1244
      !(contains(settings::statepoint_batch, n_batches)))
26✔
1245
    settings::statepoint_batch.insert(n_batches);
26✔
1246

1247
  return 0;
39✔
1248
}
1249

1250
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,765✔
1251
{
1252
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,765✔
1253

1254
  return 0;
2,765✔
1255
}
1256

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