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

openmc-dev / openmc / 14515233533

17 Apr 2025 12:06PM UTC coverage: 83.16% (-2.3%) from 85.414%
14515233533

Pull #3087

github

web-flow
Merge 6ed397e9d into 47ca2916a
Pull Request #3087: wheel building with scikit build core

140769 of 169274 relevant lines covered (83.16%)

11830168.1 hits per line

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

75.61
/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_history_splits {10'000'000};
118
int max_tracks {1000};
119
ResScatMethod res_scat_method {ResScatMethod::rvs};
120
double res_scat_energy_min {0.01};
121
double res_scat_energy_max {1000.0};
122
vector<std::string> res_scat_nuclides;
123
RunMode run_mode {RunMode::UNSET};
124
SolverType solver_type {SolverType::MONTE_CARLO};
125
std::unordered_set<int> sourcepoint_batch;
126
std::unordered_set<int> statepoint_batch;
127
std::unordered_set<int> source_write_surf_id;
128
int64_t ssw_max_particles;
129
int64_t ssw_max_files;
130
int64_t ssw_cell_id {C_NONE};
131
SSWCellType ssw_cell_type {SSWCellType::None};
132
TemperatureMethod temperature_method {TemperatureMethod::NEAREST};
133
double temperature_tolerance {10.0};
134
double temperature_default {293.6};
135
array<double, 2> temperature_range {0.0, 0.0};
136
int trace_batch;
137
int trace_gen;
138
int64_t trace_particle;
139
vector<array<int, 3>> track_identifiers;
140
int trigger_batch_interval {1};
141
int verbosity {7};
142
double weight_cutoff {0.25};
143
double weight_survive {1.0};
144

145
} // namespace settings
146

147
//==============================================================================
148
// Functions
149
//==============================================================================
150

151
void get_run_parameters(pugi::xml_node node_base)
5,150✔
152
{
153
  using namespace settings;
154
  using namespace pugi;
155

156
  // Check number of particles
157
  if (!check_for_node(node_base, "particles")) {
5,150✔
158
    fatal_error("Need to specify number of particles.");
×
159
  }
160

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

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

172
  // Get maximum number of events allowed per particle
173
  if (check_for_node(node_base, "max_particle_events")) {
5,150✔
174
    max_particle_events =
×
175
      std::stoll(get_node_value(node_base, "max_particle_events"));
×
176
  }
177

178
  // Get number of basic batches
179
  if (check_for_node(node_base, "batches")) {
5,150✔
180
    n_batches = std::stoi(get_node_value(node_base, "batches"));
5,150✔
181
  }
182
  if (!trigger_on)
5,150✔
183
    n_max_batches = n_batches;
5,015✔
184

185
  // Get max number of lost particles
186
  if (check_for_node(node_base, "max_lost_particles")) {
5,150✔
187
    max_lost_particles =
16✔
188
      std::stoi(get_node_value(node_base, "max_lost_particles"));
16✔
189
  }
190

191
  // Get relative number of lost particles
192
  if (check_for_node(node_base, "rel_max_lost_particles")) {
5,150✔
193
    rel_max_lost_particles =
×
194
      std::stod(get_node_value(node_base, "rel_max_lost_particles"));
×
195
  }
196

197
  // Get relative number of lost particles
198
  if (check_for_node(node_base, "max_write_lost_particles")) {
5,150✔
199
    max_write_lost_particles =
16✔
200
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
16✔
201
  }
202

203
  // Get number of inactive batches
204
  if (run_mode == RunMode::EIGENVALUE ||
5,150✔
205
      solver_type == SolverType::RANDOM_RAY) {
1,949✔
206
    if (check_for_node(node_base, "inactive")) {
3,585✔
207
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
3,576✔
208
    }
209
    if (check_for_node(node_base, "generations_per_batch")) {
3,585✔
210
      gen_per_batch =
16✔
211
        std::stoi(get_node_value(node_base, "generations_per_batch"));
16✔
212
    }
213

214
    // Preallocate space for keff and entropy by generation
215
    int m = settings::n_max_batches * settings::gen_per_batch;
3,585✔
216
    simulation::k_generation.reserve(m);
3,585✔
217
    simulation::entropy.reserve(m);
3,585✔
218

219
    // Get the trigger information for keff
220
    if (check_for_node(node_base, "keff_trigger")) {
3,585✔
221
      xml_node node_keff_trigger = node_base.child("keff_trigger");
96✔
222

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

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

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

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

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

389
  // Get root element
390
  xml_node root = doc.document_element();
856✔
391

392
  // Verbosity
393
  if (check_for_node(root, "verbosity")) {
856✔
394
    verbosity = std::stoi(get_node_value(root, "verbosity"));
32✔
395
  }
396

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

404
  write_message("Reading settings XML file...", 5);
856✔
405

406
  read_settings_xml(root);
856✔
407
}
868✔
408

409
void read_settings_xml(pugi::xml_node root)
5,515✔
410
{
411
  using namespace settings;
412
  using namespace pugi;
413

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

424
  // Check for user meshes and allocate
425
  read_meshes(root);
5,515✔
426

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

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

451
  // Check for a trigger node and get trigger information
452
  if (check_for_node(root, "trigger")) {
5,515✔
453
    xml_node node_trigger = root.child("trigger");
151✔
454

455
    // Check if trigger(s) are to be turned on
456
    trigger_on = get_node_value_bool(node_trigger, "active");
151✔
457

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

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

478
  // Check run mode if it hasn't been set from the command line
479
  xml_node node_mode;
5,515✔
480
  if (run_mode == RunMode::UNSET) {
5,515✔
481
    if (check_for_node(root, "run_mode")) {
5,182✔
482
      std::string temp_str = get_node_value(root, "run_mode", true, true);
5,118✔
483
      if (temp_str == "eigenvalue") {
5,118✔
484
        run_mode = RunMode::EIGENVALUE;
3,137✔
485
      } else if (temp_str == "fixed source") {
1,981✔
486
        run_mode = RunMode::FIXED_SOURCE;
1,949✔
487
      } else if (temp_str == "plot") {
32✔
488
        run_mode = RunMode::PLOTTING;
×
489
      } else if (temp_str == "particle restart") {
32✔
490
        run_mode = RunMode::PARTICLE;
×
491
      } else if (temp_str == "volume") {
32✔
492
        run_mode = RunMode::VOLUME;
32✔
493
      } else {
494
        fatal_error("Unrecognized run mode: " + temp_str);
×
495
      }
496

497
      // Assume XML specifies <particles>, <batches>, etc. directly
498
      node_mode = root;
5,118✔
499
    } else {
5,118✔
500
      warning("<run_mode> should be specified.");
64✔
501

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

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

525
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
5,515✔
526
    // Read run parameters
527
    get_run_parameters(node_mode);
5,150✔
528

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

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

550
  // Copy random number seed if specified
551
  if (check_for_node(root, "seed")) {
5,515✔
552
    auto seed = std::stoll(get_node_value(root, "seed"));
379✔
553
    openmc_set_seed(seed);
379✔
554
  }
555

556
  // Copy random number stride if specified
557
  if (check_for_node(root, "stride")) {
5,515✔
558
    auto stride = std::stoull(get_node_value(root, "stride"));
16✔
559
    openmc_set_stride(stride);
16✔
560
  }
561

562
  // Check for electron treatment
563
  if (check_for_node(root, "electron_treatment")) {
5,515✔
564
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
48✔
565
    if (temp_str == "led") {
48✔
566
      electron_treatment = ElectronTreatment::LED;
×
567
    } else if (temp_str == "ttb") {
48✔
568
      electron_treatment = ElectronTreatment::TTB;
48✔
569
    } else {
570
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
571
    }
572
  }
48✔
573

574
  // Check for photon transport
575
  if (check_for_node(root, "photon_transport")) {
5,515✔
576
    photon_transport = get_node_value_bool(root, "photon_transport");
177✔
577

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

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

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

601
  // ==========================================================================
602
  // EXTERNAL SOURCE
603

604
  // Get point to list of <source> elements and make sure there is at least one
605
  for (pugi::xml_node node : root.children("source")) {
11,013✔
606
    model::external_sources.push_back(Source::create(node));
5,508✔
607
  }
608

609
  // Check if the user has specified to read surface source
610
  if (check_for_node(root, "surf_source_read")) {
5,505✔
611
    surf_source_read = true;
16✔
612
    // Get surface source read node
613
    xml_node node_ssr = root.child("surf_source_read");
16✔
614

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

623
  // Build probability mass function for sampling external sources
624
  vector<double> source_strengths;
5,505✔
625
  for (auto& s : model::external_sources) {
11,019✔
626
    source_strengths.push_back(s->strength());
5,514✔
627
  }
628
  model::external_sources_probability.assign(source_strengths);
5,505✔
629

630
  // If no source specified, default to isotropic point source at origin with
631
  // Watt spectrum. No default source is needed in random ray mode.
632
  if (model::external_sources.empty() &&
6,906✔
633
      settings::solver_type != SolverType::RANDOM_RAY) {
1,401✔
634
    double T[] {0.0};
1,289✔
635
    double p[] {1.0};
1,289✔
636
    model::external_sources.push_back(make_unique<IndependentSource>(
1,289✔
637
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
2,578✔
638
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
2,578✔
639
      UPtrDist {new Discrete(T, p, 1)}));
2,578✔
640
  }
641

642
  // Check if we want to write out source
643
  if (check_for_node(root, "write_initial_source")) {
5,505✔
644
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
645
  }
646

647
  // Survival biasing
648
  if (check_for_node(root, "survival_biasing")) {
5,505✔
649
    survival_biasing = get_node_value_bool(root, "survival_biasing");
32✔
650
  }
651

652
  // Probability tables
653
  if (check_for_node(root, "ptables")) {
5,505✔
654
    urr_ptables_on = get_node_value_bool(root, "ptables");
16✔
655
  }
656

657
  // Cutoffs
658
  if (check_for_node(root, "cutoff")) {
5,505✔
659
    xml_node node_cutoff = root.child("cutoff");
107✔
660
    if (check_for_node(node_cutoff, "weight")) {
107✔
661
      weight_cutoff = std::stod(get_node_value(node_cutoff, "weight"));
16✔
662
    }
663
    if (check_for_node(node_cutoff, "weight_avg")) {
107✔
664
      weight_survive = std::stod(get_node_value(node_cutoff, "weight_avg"));
16✔
665
    }
666
    if (check_for_node(node_cutoff, "survival_normalization")) {
107✔
667
      survival_normalization =
×
668
        get_node_value_bool(node_cutoff, "survival_normalization");
×
669
    }
670
    if (check_for_node(node_cutoff, "energy_neutron")) {
107✔
671
      energy_cutoff[0] =
32✔
672
        std::stod(get_node_value(node_cutoff, "energy_neutron"));
16✔
673
    } else if (check_for_node(node_cutoff, "energy")) {
91✔
674
      warning("The use of an <energy> cutoff is deprecated and should "
×
675
              "be replaced by <energy_neutron>.");
676
      energy_cutoff[0] = std::stod(get_node_value(node_cutoff, "energy"));
×
677
    }
678
    if (check_for_node(node_cutoff, "energy_photon")) {
107✔
679
      energy_cutoff[1] =
118✔
680
        std::stod(get_node_value(node_cutoff, "energy_photon"));
59✔
681
    }
682
    if (check_for_node(node_cutoff, "energy_electron")) {
107✔
683
      energy_cutoff[2] =
×
684
        std::stof(get_node_value(node_cutoff, "energy_electron"));
×
685
    }
686
    if (check_for_node(node_cutoff, "energy_positron")) {
107✔
687
      energy_cutoff[3] =
×
688
        std::stod(get_node_value(node_cutoff, "energy_positron"));
×
689
    }
690
    if (check_for_node(node_cutoff, "time_neutron")) {
107✔
691
      time_cutoff[0] = std::stod(get_node_value(node_cutoff, "time_neutron"));
16✔
692
    }
693
    if (check_for_node(node_cutoff, "time_photon")) {
107✔
694
      time_cutoff[1] = std::stod(get_node_value(node_cutoff, "time_photon"));
×
695
    }
696
    if (check_for_node(node_cutoff, "time_electron")) {
107✔
697
      time_cutoff[2] = std::stod(get_node_value(node_cutoff, "time_electron"));
×
698
    }
699
    if (check_for_node(node_cutoff, "time_positron")) {
107✔
700
      time_cutoff[3] = std::stod(get_node_value(node_cutoff, "time_positron"));
×
701
    }
702
  }
703

704
  // Particle trace
705
  if (check_for_node(root, "trace")) {
5,505✔
706
    auto temp = get_node_array<int64_t>(root, "trace");
16✔
707
    if (temp.size() != 3) {
16✔
708
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
709
                  "batch, generation, and particle number.");
710
    }
711
    trace_batch = temp.at(0);
16✔
712
    trace_gen = temp.at(1);
16✔
713
    trace_particle = temp.at(2);
16✔
714
  }
16✔
715

716
  // Particle tracks
717
  if (check_for_node(root, "track")) {
5,505✔
718
    // Get values and make sure there are three per particle
719
    auto temp = get_node_array<int>(root, "track");
48✔
720
    if (temp.size() % 3 != 0) {
48✔
721
      fatal_error(
×
722
        "Number of integers specified in 'track' is not "
723
        "divisible by 3.  Please provide 3 integers per particle to be "
724
        "tracked.");
725
    }
726

727
    // Reshape into track_identifiers
728
    int n_tracks = temp.size() / 3;
48✔
729
    for (int i = 0; i < n_tracks; ++i) {
192✔
730
      track_identifiers.push_back(
144✔
731
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
144✔
732
    }
733
  }
48✔
734

735
  // Shannon entropy
736
  if (solver_type == SolverType::RANDOM_RAY) {
5,505✔
737
    if (check_for_node(root, "entropy_mesh")) {
560✔
738
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
739
                  "No user-defined entropy mesh is supported.");
740
    }
741
    entropy_on = true;
560✔
742
  } else if (solver_type == SolverType::MONTE_CARLO) {
4,945✔
743
    if (check_for_node(root, "entropy_mesh")) {
4,945✔
744
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
93✔
745
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
93✔
746
        fatal_error(fmt::format(
×
747
          "Mesh {} specified for Shannon entropy does not exist.", temp));
748
      }
749

750
      auto* m = dynamic_cast<RegularMesh*>(
93✔
751
        model::meshes[model::mesh_map.at(temp)].get());
93✔
752
      if (!m)
93✔
753
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
754
      simulation::entropy_mesh = m;
93✔
755

756
      // Turn on Shannon entropy calculation
757
      entropy_on = true;
93✔
758

759
    } else if (check_for_node(root, "entropy")) {
4,852✔
760
      fatal_error(
×
761
        "Specifying a Shannon entropy mesh via the <entropy> element "
762
        "is deprecated. Please create a mesh using <mesh> and then reference "
763
        "it by specifying its ID in an <entropy_mesh> element.");
764
    }
765
  }
766
  // Uniform fission source weighting mesh
767
  if (check_for_node(root, "ufs_mesh")) {
5,505✔
768
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
16✔
769
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
16✔
770
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
771
                              "method does not exist.",
772
        temp));
773
    }
774

775
    auto* m =
776
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
16✔
777
    if (!m)
16✔
778
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
779
    simulation::ufs_mesh = m;
16✔
780

781
    // Turn on uniform fission source weighting
782
    ufs_on = true;
16✔
783

784
  } else if (check_for_node(root, "uniform_fs")) {
5,489✔
785
    fatal_error(
×
786
      "Specifying a UFS mesh via the <uniform_fs> element "
787
      "is deprecated. Please create a mesh using <mesh> and then reference "
788
      "it by specifying its ID in a <ufs_mesh> element.");
789
  }
790

791
  // Check if the user has specified to write state points
792
  if (check_for_node(root, "state_point")) {
5,505✔
793

794
    // Get pointer to state_point node
795
    auto node_sp = root.child("state_point");
150✔
796

797
    // Determine number of batches at which to store state points
798
    if (check_for_node(node_sp, "batches")) {
150✔
799
      // User gave specific batches to write state points
800
      auto temp = get_node_array<int>(node_sp, "batches");
150✔
801
      for (const auto& b : temp) {
466✔
802
        statepoint_batch.insert(b);
316✔
803
      }
804
    } else {
150✔
805
      // If neither were specified, write state point at last batch
806
      statepoint_batch.insert(n_batches);
×
807
    }
808
  } else {
809
    // If no <state_point> tag was present, by default write state point at
810
    // last batch only
811
    statepoint_batch.insert(n_batches);
5,355✔
812
  }
813

814
  // Check if the user has specified to write source points
815
  if (check_for_node(root, "source_point")) {
5,505✔
816
    // Get source_point node
817
    xml_node node_sp = root.child("source_point");
96✔
818

819
    // Determine batches at which to store source points
820
    if (check_for_node(node_sp, "batches")) {
96✔
821
      // User gave specific batches to write source points
822
      auto temp = get_node_array<int>(node_sp, "batches");
48✔
823
      for (const auto& b : temp) {
128✔
824
        sourcepoint_batch.insert(b);
80✔
825
      }
826
    } else {
48✔
827
      // If neither were specified, write source points with state points
828
      sourcepoint_batch = statepoint_batch;
48✔
829
    }
830

831
    // Check if the user has specified to write binary source file
832
    if (check_for_node(node_sp, "separate")) {
96✔
833
      source_separate = get_node_value_bool(node_sp, "separate");
64✔
834
    }
835
    if (check_for_node(node_sp, "write")) {
96✔
836
      source_write = get_node_value_bool(node_sp, "write");
×
837
    }
838
    if (check_for_node(node_sp, "mcpl")) {
96✔
839
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
16✔
840

841
      // Make sure MCPL support is enabled
842
      if (source_mcpl_write && !MCPL_ENABLED) {
16✔
843
        fatal_error(
×
844
          "Your build of OpenMC does not support writing MCPL source files.");
845
      }
846
    }
847
    if (check_for_node(node_sp, "overwrite_latest")) {
96✔
848
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
16✔
849
      source_separate = source_latest;
16✔
850
    }
851
  } else {
852
    // If no <source_point> tag was present, by default we keep source bank in
853
    // statepoint file and write it out at statepoints intervals
854
    source_separate = false;
5,409✔
855
    sourcepoint_batch = statepoint_batch;
5,409✔
856
  }
857

858
  // Check is the user specified to convert strength to statistical weight
859
  if (check_for_node(root, "uniform_source_sampling")) {
5,505✔
860
    uniform_source_sampling =
44✔
861
      get_node_value_bool(root, "uniform_source_sampling");
44✔
862
  }
863

864
  // Check if the user has specified to write surface source
865
  if (check_for_node(root, "surf_source_write")) {
5,505✔
866
    surf_source_write = true;
390✔
867
    // Get surface source write node
868
    xml_node node_ssw = root.child("surf_source_write");
390✔
869

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

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

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

896
    if (check_for_node(node_ssw, "mcpl")) {
381✔
897
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
×
898

899
      // Make sure MCPL support is enabled
900
      if (surf_mcpl_write && !MCPL_ENABLED) {
×
901
        fatal_error("Your build of OpenMC does not support writing MCPL "
×
902
                    "surface source files.");
903
      }
904
    }
905
    // Get cell information
906
    if (check_for_node(node_ssw, "cell")) {
381✔
907
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
104✔
908
      ssw_cell_type = SSWCellType::Both;
104✔
909
    }
910
    if (check_for_node(node_ssw, "cellfrom")) {
381✔
911
      if (ssw_cell_id != C_NONE) {
90✔
912
        fatal_error(
18✔
913
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
914
      }
915
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
72✔
916
      ssw_cell_type = SSWCellType::From;
72✔
917
    }
918
    if (check_for_node(node_ssw, "cellto")) {
363✔
919
      if (ssw_cell_id != C_NONE) {
71✔
920
        fatal_error(
18✔
921
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
922
      }
923
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
53✔
924
      ssw_cell_type = SSWCellType::To;
53✔
925
    }
926
  }
927

928
  // If source is not separate and is to be written out in the statepoint file,
929
  // make sure that the sourcepoint batch numbers are contained in the
930
  // statepoint list
931
  if (!source_separate) {
5,460✔
932
    for (const auto& b : sourcepoint_batch) {
10,878✔
933
      if (!contains(statepoint_batch, b)) {
5,498✔
934
        fatal_error(
×
935
          "Sourcepoint batches are not a subset of statepoint batches.");
936
      }
937
    }
938
  }
939

940
  // Check if the user has specified to not reduce tallies at the end of every
941
  // batch
942
  if (check_for_node(root, "no_reduce")) {
5,460✔
943
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
×
944
  }
945

946
  // Check if the user has specified to use confidence intervals for
947
  // uncertainties rather than standard deviations
948
  if (check_for_node(root, "confidence_intervals")) {
5,460✔
949
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
16✔
950
  }
951

952
  // Check for output options
953
  if (check_for_node(root, "output")) {
5,460✔
954
    // Get pointer to output node
955
    pugi::xml_node node_output = root.child("output");
372✔
956

957
    // Check for summary option
958
    if (check_for_node(node_output, "summary")) {
372✔
959
      output_summary = get_node_value_bool(node_output, "summary");
356✔
960
    }
961

962
    // Check for ASCII tallies output option
963
    if (check_for_node(node_output, "tallies")) {
372✔
964
      output_tallies = get_node_value_bool(node_output, "tallies");
82✔
965
    }
966

967
    // Set output directory if a path has been specified
968
    if (check_for_node(node_output, "path")) {
372✔
969
      path_output = get_node_value(node_output, "path");
×
970
      if (!ends_with(path_output, "/")) {
×
971
        path_output += "/";
×
972
      }
973
    }
974
  }
975

976
  // Resonance scattering parameters
977
  if (check_for_node(root, "resonance_scattering")) {
5,460✔
978
    xml_node node_res_scat = root.child("resonance_scattering");
16✔
979

980
    // See if resonance scattering is enabled
981
    if (check_for_node(node_res_scat, "enable")) {
16✔
982
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
16✔
983
    } else {
984
      res_scat_on = true;
×
985
    }
986

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

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

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

1019
    // Get resonance scattering nuclides
1020
    if (check_for_node(node_res_scat, "nuclides")) {
16✔
1021
      res_scat_nuclides =
1022
        get_node_array<std::string>(node_res_scat, "nuclides");
16✔
1023
    }
1024
  }
1025

1026
  // Get volume calculations
1027
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
5,745✔
1028
    model::volume_calcs.emplace_back(node_vol);
285✔
1029
  }
1030

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

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

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

1079
  // Check for tabular_legendre options
1080
  if (check_for_node(root, "tabular_legendre")) {
5,451✔
1081
    // Get pointer to tabular_legendre node
1082
    xml_node node_tab_leg = root.child("tabular_legendre");
96✔
1083

1084
    // Check for enable option
1085
    if (check_for_node(node_tab_leg, "enable")) {
96✔
1086
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
96✔
1087
    }
1088

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

1101
  // Check whether create delayed neutrons in fission
1102
  if (check_for_node(root, "create_delayed_neutrons")) {
5,451✔
1103
    create_delayed_neutrons =
×
1104
      get_node_value_bool(root, "create_delayed_neutrons");
×
1105
  }
1106

1107
  // Check whether create fission sites
1108
  if (run_mode == RunMode::FIXED_SOURCE) {
5,451✔
1109
    if (check_for_node(root, "create_fission_neutrons")) {
1,903✔
1110
      create_fission_neutrons =
16✔
1111
        get_node_value_bool(root, "create_fission_neutrons");
16✔
1112
    }
1113
  }
1114

1115
  // Check whether to scale fission photon yields
1116
  if (check_for_node(root, "delayed_photon_scaling")) {
5,451✔
1117
    delayed_photon_scaling =
×
1118
      get_node_value_bool(root, "delayed_photon_scaling");
×
1119
  }
1120

1121
  // Check whether to use event-based parallelism
1122
  if (check_for_node(root, "event_based")) {
5,451✔
1123
    event_based = get_node_value_bool(root, "event_based");
×
1124
  }
1125

1126
  // Check whether material cell offsets should be generated
1127
  if (check_for_node(root, "material_cell_offsets")) {
5,451✔
1128
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1129
  }
1130

1131
  // Weight window information
1132
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
5,519✔
1133
    variance_reduction::weight_windows.emplace_back(
68✔
1134
      std::make_unique<WeightWindows>(node_ww));
136✔
1135
  }
1136

1137
  // Enable weight windows by default if one or more are present
1138
  if (variance_reduction::weight_windows.size() > 0)
5,451✔
1139
    settings::weight_windows_on = true;
41✔
1140

1141
  // read weight windows from file
1142
  if (check_for_node(root, "weight_windows_file")) {
5,451✔
1143
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1144
  }
1145

1146
  // read settings for weight windows value, this will override
1147
  // the automatic setting even if weight windows are present
1148
  if (check_for_node(root, "weight_windows_on")) {
5,451✔
1149
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
36✔
1150
  }
1151

1152
  if (check_for_node(root, "max_history_splits")) {
5,451✔
1153
    settings::max_history_splits =
60✔
1154
      std::stoi(get_node_value(root, "max_history_splits"));
60✔
1155
  }
1156

1157
  if (check_for_node(root, "max_tracks")) {
5,451✔
1158
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
48✔
1159
  }
1160

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

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

1192
  if (check_for_node(root, "use_decay_photons")) {
5,451✔
1193
    settings::use_decay_photons =
11✔
1194
      get_node_value_bool(root, "use_decay_photons");
11✔
1195
  }
1196
}
5,451✔
1197

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

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

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

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

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

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

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

1246
  return 0;
×
1247
}
1248

1249
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
×
1250
{
1251
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
×
1252

1253
  return 0;
×
1254
}
1255

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