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

openmc-dev / openmc / 18537555145

15 Oct 2025 05:37PM UTC coverage: 81.983% (-3.2%) from 85.194%
18537555145

Pull #3417

github

web-flow
Merge 3615a1fcc into e9077b137
Pull Request #3417: Addition of a collision tracking feature

16802 of 23354 branches covered (71.94%)

Branch coverage included in aggregate %.

480 of 522 new or added lines in 13 files covered. (91.95%)

483 existing lines in 53 files now uncovered.

54134 of 63171 relevant lines covered (85.69%)

43199115.04 hits per line

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

76.44
/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/collision_track.h"
15
#include "openmc/constants.h"
16
#include "openmc/container_util.h"
17
#include "openmc/distribution.h"
18
#include "openmc/distribution_multi.h"
19
#include "openmc/distribution_spatial.h"
20
#include "openmc/eigenvalue.h"
21
#include "openmc/error.h"
22
#include "openmc/file_utils.h"
23
#include "openmc/mcpl_interface.h"
24
#include "openmc/mesh.h"
25
#include "openmc/message_passing.h"
26
#include "openmc/output.h"
27
#include "openmc/plot.h"
28
#include "openmc/random_lcg.h"
29
#include "openmc/random_ray/random_ray.h"
30
#include "openmc/reaction.h"
31
#include "openmc/simulation.h"
32
#include "openmc/source.h"
33
#include "openmc/string_utils.h"
34
#include "openmc/tallies/trigger.h"
35
#include "openmc/volume_calc.h"
36
#include "openmc/weight_windows.h"
37
#include "openmc/xml_interface.h"
38

39
namespace openmc {
40

41
//==============================================================================
42
// Global variables
43
//==============================================================================
44

45
namespace settings {
46

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

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

100
int32_t n_inactive {0};
101
int32_t max_lost_particles {10};
102
double rel_max_lost_particles {1.0e-6};
103
int32_t max_write_lost_particles {-1};
104
int32_t gen_per_batch {1};
105
int64_t n_particles {-1};
106

107
int64_t max_particles_in_flight {100000};
108
int max_particle_events {1000000};
109

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

152
} // namespace settings
153

154
//==============================================================================
155
// Functions
156
//==============================================================================
157

158
void get_run_parameters(pugi::xml_node node_base)
7,322✔
159
{
160
  using namespace settings;
161
  using namespace pugi;
162

163
  // Check number of particles
164
  if (!check_for_node(node_base, "particles")) {
7,322!
165
    fatal_error("Need to specify number of particles.");
×
166
  }
167

168
  // Get number of particles if it wasn't specified as a command-line argument
169
  if (n_particles == -1) {
7,322!
170
    n_particles = std::stoll(get_node_value(node_base, "particles"));
7,322✔
171
  }
172

173
  // Get maximum number of in flight particles for event-based mode
174
  if (check_for_node(node_base, "max_particles_in_flight")) {
7,322!
175
    max_particles_in_flight =
×
176
      std::stoll(get_node_value(node_base, "max_particles_in_flight"));
×
177
  }
178

179
  // Get maximum number of events allowed per particle
180
  if (check_for_node(node_base, "max_particle_events")) {
7,322!
181
    max_particle_events =
×
182
      std::stoll(get_node_value(node_base, "max_particle_events"));
×
183
  }
184

185
  // Get number of basic batches
186
  if (check_for_node(node_base, "batches")) {
7,322!
187
    n_batches = std::stoi(get_node_value(node_base, "batches"));
7,322✔
188
  }
189
  if (!trigger_on)
7,322✔
190
    n_max_batches = n_batches;
7,174✔
191

192
  // Get max number of lost particles
193
  if (check_for_node(node_base, "max_lost_particles")) {
7,322✔
194
    max_lost_particles =
48✔
195
      std::stoi(get_node_value(node_base, "max_lost_particles"));
48✔
196
  }
197

198
  // Get relative number of lost particles
199
  if (check_for_node(node_base, "rel_max_lost_particles")) {
7,322!
200
    rel_max_lost_particles =
×
201
      std::stod(get_node_value(node_base, "rel_max_lost_particles"));
×
202
  }
203

204
  // Get relative number of lost particles
205
  if (check_for_node(node_base, "max_write_lost_particles")) {
7,322✔
206
    max_write_lost_particles =
16✔
207
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
16✔
208
  }
209

210
  // Get number of inactive batches
211
  if (run_mode == RunMode::EIGENVALUE ||
7,322✔
212
      solver_type == SolverType::RANDOM_RAY) {
2,624✔
213
    if (check_for_node(node_base, "inactive")) {
5,099✔
214
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,865✔
215
    }
216
    if (check_for_node(node_base, "generations_per_batch")) {
5,099✔
217
      gen_per_batch =
16✔
218
        std::stoi(get_node_value(node_base, "generations_per_batch"));
16✔
219
    }
220

221
    // Preallocate space for keff and entropy by generation
222
    int m = settings::n_max_batches * settings::gen_per_batch;
5,099✔
223
    simulation::k_generation.reserve(m);
5,099✔
224
    simulation::entropy.reserve(m);
5,099✔
225

226
    // Get the trigger information for keff
227
    if (check_for_node(node_base, "keff_trigger")) {
5,099✔
228
      xml_node node_keff_trigger = node_base.child("keff_trigger");
109✔
229

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

245
      if (check_for_node(node_keff_trigger, "threshold")) {
109!
246
        keff_trigger.threshold =
109✔
247
          std::stod(get_node_value(node_keff_trigger, "threshold"));
109✔
248
        if (keff_trigger.threshold <= 0) {
109!
249
          fatal_error("keff trigger threshold must be positive");
×
250
        }
251
      } else {
252
        fatal_error("Specify keff trigger threshold in settings XML");
×
253
      }
254
    }
255
  }
256

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

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

388
  // Parse settings.xml file
389
  xml_document doc;
1,775✔
390
  auto result = doc.load_file(filename.c_str());
1,775✔
391
  if (!result) {
1,775!
392
    fatal_error("Error processing settings.xml file.");
×
393
  }
394

395
  // Get root element
396
  xml_node root = doc.document_element();
1,775✔
397

398
  // Verbosity
399
  if (check_for_node(root, "verbosity")) {
1,775✔
400
    verbosity = std::stoi(get_node_value(root, "verbosity"));
355✔
401
  }
402

403
  // To this point, we haven't displayed any output since we didn't know what
404
  // the verbosity is. Now that we checked for it, show the title if necessary
405
  if (mpi::master) {
1,775✔
406
    if (verbosity >= 2)
1,550✔
407
      title();
1,205✔
408
  }
409

410
  write_message("Reading settings XML file...", 5);
1,775✔
411

412
  read_settings_xml(root);
1,775✔
413
}
1,787✔
414

415
void read_settings_xml(pugi::xml_node root)
7,924✔
416
{
417
  using namespace settings;
418
  using namespace pugi;
419

420
  // Find if a multi-group or continuous-energy simulation is desired
421
  if (check_for_node(root, "energy_mode")) {
7,924✔
422
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
1,111✔
423
    if (temp_str == "mg" || temp_str == "multi-group") {
1,111!
424
      run_CE = false;
1,111✔
425
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
426
      run_CE = true;
×
427
    }
428
  }
1,111✔
429

430
  // Check for user meshes and allocate
431
  read_meshes(root);
7,924✔
432

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

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

457
  // Check for a trigger node and get trigger information
458
  if (check_for_node(root, "trigger")) {
7,924✔
459
    xml_node node_trigger = root.child("trigger");
164✔
460

461
    // Check if trigger(s) are to be turned on
462
    trigger_on = get_node_value_bool(node_trigger, "active");
164✔
463

464
    if (trigger_on) {
164✔
465
      if (check_for_node(node_trigger, "max_batches")) {
148!
466
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
148✔
467
      } else {
468
        fatal_error("<max_batches> must be specified with triggers");
×
469
      }
470

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

484
  // Check run mode if it hasn't been set from the command line
485
  xml_node node_mode;
7,924✔
486
  if (run_mode == RunMode::UNSET) {
7,924✔
487
    if (check_for_node(root, "run_mode")) {
7,354✔
488
      std::string temp_str = get_node_value(root, "run_mode", true, true);
7,322✔
489
      if (temp_str == "eigenvalue") {
7,322✔
490
        run_mode = RunMode::EIGENVALUE;
4,666✔
491
      } else if (temp_str == "fixed source") {
2,656✔
492
        run_mode = RunMode::FIXED_SOURCE;
2,624✔
493
      } else if (temp_str == "plot") {
32!
494
        run_mode = RunMode::PLOTTING;
×
495
      } else if (temp_str == "particle restart") {
32!
496
        run_mode = RunMode::PARTICLE;
×
497
      } else if (temp_str == "volume") {
32!
498
        run_mode = RunMode::VOLUME;
32✔
499
      } else {
500
        fatal_error("Unrecognized run mode: " + temp_str);
×
501
      }
502

503
      // Assume XML specifies <particles>, <batches>, etc. directly
504
      node_mode = root;
7,322✔
505
    } else {
7,322✔
506
      warning("<run_mode> should be specified.");
32✔
507

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

523
  // Check solver type
524
  if (check_for_node(root, "random_ray")) {
7,924✔
525
    solver_type = SolverType::RANDOM_RAY;
577✔
526
    if (run_CE)
577!
527
      fatal_error("multi-group energy mode must be specified in settings XML "
×
528
                  "when using the random ray solver.");
529
  }
530

531
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
7,924✔
532
    // Read run parameters
533
    get_run_parameters(node_mode);
7,322✔
534

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

550
  // Copy plotting random number seed if specified
551
  if (check_for_node(root, "plot_seed")) {
7,924!
552
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
553
    model::plotter_seed = seed;
×
554
  }
555

556
  // Copy random number seed if specified
557
  if (check_for_node(root, "seed")) {
7,924✔
558
    auto seed = std::stoll(get_node_value(root, "seed"));
596✔
559
    openmc_set_seed(seed);
596✔
560
  }
561

562
  // Copy random number stride if specified
563
  if (check_for_node(root, "stride")) {
7,924✔
564
    auto stride = std::stoull(get_node_value(root, "stride"));
16✔
565
    openmc_set_stride(stride);
16✔
566
  }
567

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

580
  // Check for photon transport
581
  if (check_for_node(root, "photon_transport")) {
7,924✔
582
    photon_transport = get_node_value_bool(root, "photon_transport");
201✔
583

584
    if (!run_CE && photon_transport) {
201!
585
      fatal_error("Photon transport is not currently supported in "
×
586
                  "multigroup mode");
587
    }
588
  }
589

590
  // Number of bins for logarithmic grid
591
  if (check_for_node(root, "log_grid_bins")) {
7,924✔
592
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
16✔
593
    if (n_log_bins < 1) {
16!
594
      fatal_error("Number of bins for logarithmic grid must be greater "
×
595
                  "than zero.");
596
    }
597
  }
598

599
  // Number of OpenMP threads
600
  if (check_for_node(root, "threads")) {
7,924!
601
    if (mpi::master)
×
602
      warning("The <threads> element has been deprecated. Use "
×
603
              "the OMP_NUM_THREADS environment variable to set the number of "
604
              "threads.");
605
  }
606

607
  // ==========================================================================
608
  // EXTERNAL SOURCE
609

610
  // Get point to list of <source> elements and make sure there is at least one
611
  for (pugi::xml_node node : root.children("source")) {
14,986✔
612
    model::external_sources.push_back(Source::create(node));
7,072✔
613
  }
614

615
  // Check if the user has specified to read surface source
616
  if (check_for_node(root, "surf_source_read")) {
7,914✔
617
    surf_source_read = true;
32✔
618
    // Get surface source read node
619
    xml_node node_ssr = root.child("surf_source_read");
32✔
620

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

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

641
  // Build probability mass function for sampling external sources
642
  vector<double> source_strengths;
7,914✔
643
  for (auto& s : model::external_sources) {
17,174✔
644
    source_strengths.push_back(s->strength());
9,260✔
645
  }
646
  model::external_sources_probability.assign(source_strengths);
7,914✔
647

648
  // Check if we want to write out source
649
  if (check_for_node(root, "write_initial_source")) {
7,914!
650
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
651
  }
652

653
  // Get relative number of lost particles
654
  if (check_for_node(root, "source_rejection_fraction")) {
7,914✔
655
    source_rejection_fraction =
6✔
656
      std::stod(get_node_value(root, "source_rejection_fraction"));
6!
657
  }
658

659
  if (check_for_node(root, "free_gas_threshold")) {
7,914!
660
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
661
  }
662

663
  // Survival biasing
664
  if (check_for_node(root, "survival_biasing")) {
7,914✔
665
    survival_biasing = get_node_value_bool(root, "survival_biasing");
202✔
666
  }
667

668
  // Probability tables
669
  if (check_for_node(root, "ptables")) {
7,914✔
670
    urr_ptables_on = get_node_value_bool(root, "ptables");
16✔
671
  }
672

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

720
  // Particle trace
721
  if (check_for_node(root, "trace")) {
7,914✔
722
    auto temp = get_node_array<int64_t>(root, "trace");
16✔
723
    if (temp.size() != 3) {
16!
724
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
725
                  "batch, generation, and particle number.");
726
    }
727
    trace_batch = temp.at(0);
16✔
728
    trace_gen = temp.at(1);
16✔
729
    trace_particle = temp.at(2);
16✔
730
  }
16✔
731

732
  // Particle tracks
733
  if (check_for_node(root, "track")) {
7,914✔
734
    // Get values and make sure there are three per particle
735
    auto temp = get_node_array<int>(root, "track");
48✔
736
    if (temp.size() % 3 != 0) {
48!
737
      fatal_error(
×
738
        "Number of integers specified in 'track' is not "
739
        "divisible by 3.  Please provide 3 integers per particle to be "
740
        "tracked.");
741
    }
742

743
    // Reshape into track_identifiers
744
    int n_tracks = temp.size() / 3;
48✔
745
    for (int i = 0; i < n_tracks; ++i) {
192✔
746
      track_identifiers.push_back(
144✔
747
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
144✔
748
    }
749
  }
48✔
750

751
  // Shannon entropy
752
  if (solver_type == SolverType::RANDOM_RAY) {
7,914✔
753
    if (check_for_node(root, "entropy_mesh")) {
577!
754
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
755
                  "No user-defined entropy mesh is supported.");
756
    }
757
    entropy_on = true;
577✔
758
  } else if (solver_type == SolverType::MONTE_CARLO) {
7,337!
759
    if (check_for_node(root, "entropy_mesh")) {
7,337✔
760
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
379✔
761
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
379!
762
        fatal_error(fmt::format(
×
763
          "Mesh {} specified for Shannon entropy does not exist.", temp));
764
      }
765

766
      auto* m = dynamic_cast<RegularMesh*>(
379!
767
        model::meshes[model::mesh_map.at(temp)].get());
379✔
768
      if (!m)
379!
769
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
770
      simulation::entropy_mesh = m;
379✔
771

772
      // Turn on Shannon entropy calculation
773
      entropy_on = true;
379✔
774

775
    } else if (check_for_node(root, "entropy")) {
6,958!
776
      fatal_error(
×
777
        "Specifying a Shannon entropy mesh via the <entropy> element "
778
        "is deprecated. Please create a mesh using <mesh> and then reference "
779
        "it by specifying its ID in an <entropy_mesh> element.");
780
    }
781
  }
782
  // Uniform fission source weighting mesh
783
  if (check_for_node(root, "ufs_mesh")) {
7,914✔
784
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
16✔
785
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
16!
786
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
787
                              "method does not exist.",
788
        temp));
789
    }
790

791
    auto* m =
792
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
16!
793
    if (!m)
16!
794
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
795
    simulation::ufs_mesh = m;
16✔
796

797
    // Turn on uniform fission source weighting
798
    ufs_on = true;
16✔
799

800
  } else if (check_for_node(root, "uniform_fs")) {
7,898!
801
    fatal_error(
×
802
      "Specifying a UFS mesh via the <uniform_fs> element "
803
      "is deprecated. Please create a mesh using <mesh> and then reference "
804
      "it by specifying its ID in a <ufs_mesh> element.");
805
  }
806

807
  // Check if the user has specified to write state points
808
  if (check_for_node(root, "state_point")) {
7,914✔
809

810
    // Get pointer to state_point node
811
    auto node_sp = root.child("state_point");
171✔
812

813
    // Determine number of batches at which to store state points
814
    if (check_for_node(node_sp, "batches")) {
171!
815
      // User gave specific batches to write state points
816
      auto temp = get_node_array<int>(node_sp, "batches");
171✔
817
      for (const auto& b : temp) {
524✔
818
        statepoint_batch.insert(b);
353✔
819
      }
820
    } else {
171✔
821
      // If neither were specified, write state point at last batch
822
      statepoint_batch.insert(n_batches);
×
823
    }
824
  } else {
825
    // If no <state_point> tag was present, by default write state point at
826
    // last batch only
827
    statepoint_batch.insert(n_batches);
7,743✔
828
  }
829

830
  // Check if the user has specified to write source points
831
  if (check_for_node(root, "source_point")) {
7,914✔
832
    // Get source_point node
833
    xml_node node_sp = root.child("source_point");
107✔
834

835
    // Determine batches at which to store source points
836
    if (check_for_node(node_sp, "batches")) {
107✔
837
      // User gave specific batches to write source points
838
      auto temp = get_node_array<int>(node_sp, "batches");
48✔
839
      for (const auto& b : temp) {
128✔
840
        sourcepoint_batch.insert(b);
80✔
841
      }
842
    } else {
48✔
843
      // If neither were specified, write source points with state points
844
      sourcepoint_batch = statepoint_batch;
59✔
845
    }
846

847
    // Check if the user has specified to write binary source file
848
    if (check_for_node(node_sp, "separate")) {
107✔
849
      source_separate = get_node_value_bool(node_sp, "separate");
75✔
850
    }
851
    if (check_for_node(node_sp, "write")) {
107!
852
      source_write = get_node_value_bool(node_sp, "write");
×
853
    }
854
    if (check_for_node(node_sp, "mcpl")) {
107✔
855
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
27✔
856
    }
857
    if (check_for_node(node_sp, "overwrite_latest")) {
107✔
858
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
16✔
859
      source_separate = source_latest;
16✔
860
    }
861
  } else {
862
    // If no <source_point> tag was present, by default we keep source bank in
863
    // statepoint file and write it out at statepoints intervals
864
    source_separate = false;
7,807✔
865
    sourcepoint_batch = statepoint_batch;
7,807✔
866
  }
867

868
  // Check is the user specified to convert strength to statistical weight
869
  if (check_for_node(root, "uniform_source_sampling")) {
7,914✔
870
    uniform_source_sampling =
57✔
871
      get_node_value_bool(root, "uniform_source_sampling");
57✔
872
  }
873

874
  // Check if the user has specified to write surface source
875
  if (check_for_node(root, "surf_source_write")) {
7,914✔
876
    surf_source_write = true;
414✔
877
    // Get surface source write node
878
    xml_node node_ssw = root.child("surf_source_write");
414✔
879

880
    // Determine surface ids at which crossing particles are to be banked.
881
    // If no surfaces are specified, all surfaces in the model will be used
882
    // to bank source points.
883
    if (check_for_node(node_ssw, "surface_ids")) {
414✔
884
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
202✔
885
      for (const auto& b : temp) {
994✔
886
        source_write_surf_id.insert(b);
792✔
887
      }
888
    }
202✔
889

890
    // Get maximum number of particles to be banked per surface
891
    if (check_for_node(node_ssw, "max_particles")) {
414✔
892
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
405✔
893
    } else {
894
      fatal_error("A maximum number of particles needs to be specified "
9✔
895
                  "using the 'max_particles' parameter to store surface "
896
                  "source points.");
897
    }
898

899
    // Get maximum number of surface source files to be created
900
    if (check_for_node(node_ssw, "max_source_files")) {
405✔
901
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
33✔
902
    } else {
903
      ssw_max_files = 1;
372✔
904
    }
905

906
    if (check_for_node(node_ssw, "mcpl")) {
405✔
907
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
11✔
908
    }
909
    // Get cell information
910
    if (check_for_node(node_ssw, "cell")) {
405✔
911
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
104✔
912
      ssw_cell_type = SSWCellType::Both;
104✔
913
    }
914
    if (check_for_node(node_ssw, "cellfrom")) {
405✔
915
      if (ssw_cell_id != C_NONE) {
90✔
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, "cellfrom"));
72✔
920
      ssw_cell_type = SSWCellType::From;
72✔
921
    }
922
    if (check_for_node(node_ssw, "cellto")) {
387✔
923
      if (ssw_cell_id != C_NONE) {
71✔
924
        fatal_error(
18✔
925
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
926
      }
927
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
53✔
928
      ssw_cell_type = SSWCellType::To;
53✔
929
    }
930
  }
931

932
  // Check if the user has specified to write specific collisions
933
  if (check_for_node(root, "collision_track")) {
7,869✔
934
    settings::collision_track = true;
155✔
935
    // Get collision track node
936
    xml_node node_ct = root.child("collision_track");
155✔
937
    collision_track_config = CollisionTrackConfig {};
155✔
938

939
    // Determine cell ids at which crossing particles are to be banked
940
    if (check_for_node(node_ct, "cell_ids")) {
155✔
941
      auto temp = get_node_array<int>(node_ct, "cell_ids");
81✔
942
      for (const auto& b : temp) {
211✔
943
        collision_track_config.cell_ids.insert(b);
130✔
944
      }
945
    }
81✔
946
    if (check_for_node(node_ct, "reactions")) {
155✔
947
      auto temp = get_node_array<std::string>(node_ct, "reactions");
65✔
948
      for (const auto& b : temp) {
178✔
949
        int reaction_int = reaction_type(b);
113✔
950
        if (reaction_int > 0) {
113!
951
          collision_track_config.mt_numbers.insert(reaction_int);
113✔
952
        }
953
      }
954
    }
65✔
955
    if (check_for_node(node_ct, "universe_ids")) {
155✔
956
      auto temp = get_node_array<int>(node_ct, "universe_ids");
32✔
957
      for (const auto& b : temp) {
64✔
958
        collision_track_config.universe_ids.insert(b);
32✔
959
      }
960
    }
32✔
961
    if (check_for_node(node_ct, "material_ids")) {
155✔
962
      auto temp = get_node_array<int>(node_ct, "material_ids");
32✔
963
      for (const auto& b : temp) {
80✔
964
        collision_track_config.material_ids.insert(b);
48✔
965
      }
966
    }
32✔
967
    if (check_for_node(node_ct, "nuclides")) {
155✔
968
      auto temp = get_node_array<std::string>(node_ct, "nuclides");
32✔
969
      for (const auto& b : temp) {
128✔
970
        // if (openmc::data::nuclide_map.find(b) ==
971
        // openmc::data::nuclide_map.end()) {
972
        //   fatal_error("Could not find nuclide " + b + " in the nuclear data
973
        //   library.");
974
        // }
975
        collision_track_config.nuclides.insert(b);
96✔
976
      }
977
    }
32✔
978
    if (check_for_node(node_ct, "deposited_E_threshold")) {
155✔
979
      collision_track_config.deposited_energy_threshold =
32✔
980
        std::stod(get_node_value(node_ct, "deposited_E_threshold"));
32✔
981
    }
982
    // Get maximum number of particles to be banked per collision
983
    if (check_for_node(node_ct, "max_collisions")) {
155!
984
      collision_track_config.max_collisions =
155✔
985
        std::stoll(get_node_value(node_ct, "max_collisions"));
155✔
986
    } else {
NEW
987
      warning("A maximum number of collisions needs to be specified. "
×
988
              "By default the code sets 'max_collisions' parameter equals to "
989
              "1000.");
990
    }
991
    // Get maximum number of collision_track files to be created
992
    if (check_for_node(node_ct, "max_collision_track_files")) {
155!
NEW
993
      collision_track_config.max_files =
×
NEW
994
        std::stoll(get_node_value(node_ct, "max_collision_track_files"));
×
995
    }
996
    if (check_for_node(node_ct, "mcpl")) {
155✔
997
      collision_track_config.mcpl_write = get_node_value_bool(node_ct, "mcpl");
22✔
998
    }
999
  }
1000

1001
  // If source is not separate and is to be written out in the statepoint
1002
  // file, make sure that the sourcepoint batch numbers are contained in the
1003
  // statepoint list
1004
  if (!source_separate) {
7,869✔
1005
    for (const auto& b : sourcepoint_batch) {
15,690✔
1006
      if (!contains(statepoint_batch, b)) {
7,912!
1007
        fatal_error(
×
1008
          "Sourcepoint batches are not a subset of statepoint batches.");
1009
      }
1010
    }
1011
  }
1012

1013
  // Check if the user has specified to not reduce tallies at the end of every
1014
  // batch
1015
  if (check_for_node(root, "no_reduce")) {
7,869!
1016
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
×
1017
  }
1018

1019
  // Check if the user has specified to use confidence intervals for
1020
  // uncertainties rather than standard deviations
1021
  if (check_for_node(root, "confidence_intervals")) {
7,869✔
1022
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
16✔
1023
  }
1024

1025
  // Check for output options
1026
  if (check_for_node(root, "output")) {
7,869✔
1027
    // Get pointer to output node
1028
    pugi::xml_node node_output = root.child("output");
572✔
1029

1030
    // Check for summary option
1031
    if (check_for_node(node_output, "summary")) {
572✔
1032
      output_summary = get_node_value_bool(node_output, "summary");
545✔
1033
    }
1034

1035
    // Check for ASCII tallies output option
1036
    if (check_for_node(node_output, "tallies")) {
572✔
1037
      output_tallies = get_node_value_bool(node_output, "tallies");
95✔
1038
    }
1039

1040
    // Set output directory if a path has been specified
1041
    if (check_for_node(node_output, "path")) {
572!
1042
      path_output = get_node_value(node_output, "path");
×
1043
      if (!ends_with(path_output, "/")) {
×
1044
        path_output += "/";
×
1045
      }
1046
    }
1047
  }
1048

1049
  // Resonance scattering parameters
1050
  if (check_for_node(root, "resonance_scattering")) {
7,869✔
1051
    xml_node node_res_scat = root.child("resonance_scattering");
16✔
1052

1053
    // See if resonance scattering is enabled
1054
    if (check_for_node(node_res_scat, "enable")) {
16!
1055
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
16✔
1056
    } else {
1057
      res_scat_on = true;
×
1058
    }
1059

1060
    // Determine what method is used
1061
    if (check_for_node(node_res_scat, "method")) {
16!
1062
      auto temp = get_node_value(node_res_scat, "method", true, true);
16✔
1063
      if (temp == "rvs") {
16!
1064
        res_scat_method = ResScatMethod::rvs;
16✔
1065
      } else if (temp == "dbrc") {
×
1066
        res_scat_method = ResScatMethod::dbrc;
×
1067
      } else {
1068
        fatal_error(
×
1069
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1070
      }
1071
    }
16✔
1072

1073
    // Minimum energy for resonance scattering
1074
    if (check_for_node(node_res_scat, "energy_min")) {
16!
1075
      res_scat_energy_min =
16✔
1076
        std::stod(get_node_value(node_res_scat, "energy_min"));
16✔
1077
    }
1078
    if (res_scat_energy_min < 0.0) {
16!
1079
      fatal_error("Lower resonance scattering energy bound is negative");
×
1080
    }
1081

1082
    // Maximum energy for resonance scattering
1083
    if (check_for_node(node_res_scat, "energy_max")) {
16!
1084
      res_scat_energy_max =
16✔
1085
        std::stod(get_node_value(node_res_scat, "energy_max"));
16✔
1086
    }
1087
    if (res_scat_energy_max < res_scat_energy_min) {
16!
1088
      fatal_error("Upper resonance scattering energy bound is below the "
×
1089
                  "lower resonance scattering energy bound.");
1090
    }
1091

1092
    // Get resonance scattering nuclides
1093
    if (check_for_node(node_res_scat, "nuclides")) {
16!
1094
      res_scat_nuclides =
1095
        get_node_array<std::string>(node_res_scat, "nuclides");
16✔
1096
    }
1097
  }
1098

1099
  // Get volume calculations
1100
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
8,408✔
1101
    model::volume_calcs.emplace_back(node_vol);
539✔
1102
  }
1103

1104
  // Get temperature settings
1105
  if (check_for_node(root, "temperature_default")) {
7,869✔
1106
    temperature_default =
172✔
1107
      std::stod(get_node_value(root, "temperature_default"));
172✔
1108
  }
1109
  if (check_for_node(root, "temperature_method")) {
7,869✔
1110
    auto temp = get_node_value(root, "temperature_method", true, true);
325✔
1111
    if (temp == "nearest") {
325✔
1112
      temperature_method = TemperatureMethod::NEAREST;
140✔
1113
    } else if (temp == "interpolation") {
185!
1114
      temperature_method = TemperatureMethod::INTERPOLATION;
185✔
1115
    } else {
1116
      fatal_error("Unknown temperature method: " + temp);
×
1117
    }
1118
  }
325✔
1119
  if (check_for_node(root, "temperature_tolerance")) {
7,869✔
1120
    temperature_tolerance =
182✔
1121
      std::stod(get_node_value(root, "temperature_tolerance"));
182✔
1122
  }
1123
  if (check_for_node(root, "temperature_multipole")) {
7,869✔
1124
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
32✔
1125

1126
    // Multipole currently doesn't work with photon transport
1127
    if (temperature_multipole && photon_transport) {
32!
1128
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1129
                  "photon transport.");
1130
    }
1131
  }
1132
  if (check_for_node(root, "temperature_range")) {
7,869!
1133
    auto range = get_node_array<double>(root, "temperature_range");
×
1134
    temperature_range[0] = range.at(0);
×
1135
    temperature_range[1] = range.at(1);
×
UNCOV
1136
  }
×
1137

1138
  // Check for user value for the number of generation of the Iterated Fission
1139
  // Probability (IFP) method
1140
  if (check_for_node(root, "ifp_n_generation")) {
7,869✔
1141
    ifp_n_generation = std::stoi(get_node_value(root, "ifp_n_generation"));
85✔
1142
    if (ifp_n_generation <= 0) {
85!
1143
      fatal_error("'ifp_n_generation' must be greater than 0.");
×
1144
    }
1145
    // Avoid tallying 0 if IFP logs are not complete when active cycles start
1146
    if (ifp_n_generation > n_inactive) {
85✔
1147
      fatal_error("'ifp_n_generation' must be lower than or equal to the "
9✔
1148
                  "number of inactive cycles.");
1149
    }
1150
  }
1151

1152
  // Check for tabular_legendre options
1153
  if (check_for_node(root, "tabular_legendre")) {
7,860✔
1154
    // Get pointer to tabular_legendre node
1155
    xml_node node_tab_leg = root.child("tabular_legendre");
96✔
1156

1157
    // Check for enable option
1158
    if (check_for_node(node_tab_leg, "enable")) {
96!
1159
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
96✔
1160
    }
1161

1162
    // Check for the number of points
1163
    if (check_for_node(node_tab_leg, "num_points")) {
96!
1164
      legendre_to_tabular_points =
×
1165
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
1166
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
1167
        fatal_error(
×
1168
          "The 'num_points' subelement/attribute of the "
1169
          "<tabular_legendre> element must contain a value greater than 1");
1170
      }
1171
    }
1172
  }
1173

1174
  // Check whether create delayed neutrons in fission
1175
  if (check_for_node(root, "create_delayed_neutrons")) {
7,860!
1176
    create_delayed_neutrons =
×
1177
      get_node_value_bool(root, "create_delayed_neutrons");
×
1178
  }
1179

1180
  // Check whether create fission sites
1181
  if (run_mode == RunMode::FIXED_SOURCE) {
7,860✔
1182
    if (check_for_node(root, "create_fission_neutrons")) {
2,578✔
1183
      create_fission_neutrons =
16✔
1184
        get_node_value_bool(root, "create_fission_neutrons");
16✔
1185
    }
1186
  }
1187

1188
  // Check whether to scale fission photon yields
1189
  if (check_for_node(root, "delayed_photon_scaling")) {
7,860!
1190
    delayed_photon_scaling =
×
1191
      get_node_value_bool(root, "delayed_photon_scaling");
×
1192
  }
1193

1194
  // Check whether to use event-based parallelism
1195
  if (check_for_node(root, "event_based")) {
7,860!
1196
    event_based = get_node_value_bool(root, "event_based");
×
1197
  }
1198

1199
  // Check whether material cell offsets should be generated
1200
  if (check_for_node(root, "material_cell_offsets")) {
7,860!
1201
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1202
  }
1203

1204
  // Weight window information
1205
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
7,955✔
1206
    variance_reduction::weight_windows.emplace_back(
95✔
1207
      std::make_unique<WeightWindows>(node_ww));
190✔
1208
  }
1209

1210
  // Enable weight windows by default if one or more are present
1211
  if (variance_reduction::weight_windows.size() > 0)
7,860✔
1212
    settings::weight_windows_on = true;
68✔
1213

1214
  // read weight windows from file
1215
  if (check_for_node(root, "weight_windows_file")) {
7,860!
1216
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1217
  }
1218

1219
  // read settings for weight windows value, this will override
1220
  // the automatic setting even if weight windows are present
1221
  if (check_for_node(root, "weight_windows_on")) {
7,860✔
1222
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
37✔
1223
  }
1224

1225
  if (check_for_node(root, "max_secondaries")) {
7,860!
1226
    settings::max_secondaries =
×
1227
      std::stoi(get_node_value(root, "max_secondaries"));
×
1228
  }
1229

1230
  if (check_for_node(root, "max_history_splits")) {
7,860✔
1231
    settings::max_history_splits =
242✔
1232
      std::stoi(get_node_value(root, "max_history_splits"));
242✔
1233
  }
1234

1235
  if (check_for_node(root, "max_tracks")) {
7,860✔
1236
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
48✔
1237
  }
1238

1239
  // Create weight window generator objects
1240
  if (check_for_node(root, "weight_window_generators")) {
7,860✔
1241
    auto wwgs_node = root.child("weight_window_generators");
82✔
1242
    for (pugi::xml_node node_wwg :
82✔
1243
      wwgs_node.children("weight_windows_generator")) {
246✔
1244
      variance_reduction::weight_windows_generators.emplace_back(
82✔
1245
        std::make_unique<WeightWindowsGenerator>(node_wwg));
164✔
1246
    }
1247
    // if any of the weight windows are intended to be generated otf, make
1248
    // sure they're applied
1249
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
82!
1250
      if (wwg->on_the_fly_) {
82!
1251
        settings::weight_windows_on = true;
82✔
1252
        break;
82✔
1253
      }
1254
    }
1255
  }
1256

1257
  // Set up weight window checkpoints
1258
  if (check_for_node(root, "weight_window_checkpoints")) {
7,860✔
1259
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
1!
1260
    if (check_for_node(ww_checkpoints, "collision")) {
1!
1261
      weight_window_checkpoint_collision =
1✔
1262
        get_node_value_bool(ww_checkpoints, "collision");
1!
1263
    }
1264
    if (check_for_node(ww_checkpoints, "surface")) {
1!
1265
      weight_window_checkpoint_surface =
1✔
1266
        get_node_value_bool(ww_checkpoints, "surface");
1!
1267
    }
1268
  }
1269

1270
  if (check_for_node(root, "use_decay_photons")) {
7,860✔
1271
    settings::use_decay_photons =
11✔
1272
      get_node_value_bool(root, "use_decay_photons");
11✔
1273
  }
1274
}
7,860✔
1275

1276
void free_memory_settings()
8,237✔
1277
{
1278
  settings::statepoint_batch.clear();
8,237✔
1279
  settings::sourcepoint_batch.clear();
8,237✔
1280
  settings::source_write_surf_id.clear();
8,237✔
1281
  settings::res_scat_nuclides.clear();
8,237✔
1282
}
8,237✔
1283

1284
//==============================================================================
1285
// C API functions
1286
//==============================================================================
1287

1288
extern "C" int openmc_set_n_batches(
65✔
1289
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1290
{
1291
  if (settings::n_inactive >= n_batches) {
65✔
1292
    set_errmsg("Number of active batches must be greater than zero.");
13✔
1293
    return OPENMC_E_INVALID_ARGUMENT;
13✔
1294
  }
1295

1296
  if (simulation::current_batch >= n_batches) {
52✔
1297
    set_errmsg("Number of batches must be greater than current batch.");
13✔
1298
    return OPENMC_E_INVALID_ARGUMENT;
13✔
1299
  }
1300

1301
  if (!settings::trigger_on) {
39✔
1302
    // Set n_batches and n_max_batches to same value
1303
    settings::n_batches = n_batches;
13✔
1304
    settings::n_max_batches = n_batches;
13✔
1305
  } else {
1306
    // Set n_batches and n_max_batches based on value of set_max_batches
1307
    if (set_max_batches) {
26✔
1308
      settings::n_max_batches = n_batches;
13✔
1309
    } else {
1310
      settings::n_batches = n_batches;
13✔
1311
    }
1312
  }
1313

1314
  // Update size of k_generation and entropy
1315
  int m = settings::n_max_batches * settings::gen_per_batch;
39✔
1316
  simulation::k_generation.reserve(m);
39✔
1317
  simulation::entropy.reserve(m);
39✔
1318

1319
  // Add value of n_batches to statepoint_batch
1320
  if (add_statepoint_batch &&
65✔
1321
      !(contains(settings::statepoint_batch, n_batches)))
26!
1322
    settings::statepoint_batch.insert(n_batches);
26✔
1323

1324
  return 0;
39✔
1325
}
1326

1327
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,990✔
1328
{
1329
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,990✔
1330

1331
  return 0;
2,990✔
1332
}
1333

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