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

openmc-dev / openmc / 21238587645

22 Jan 2026 06:32AM UTC coverage: 81.983% (-0.02%) from 81.998%
21238587645

Pull #3742

github

web-flow
Merge e4350a61f into c5df2bf62
Pull Request #3742: Implement surface flux tallies

17249 of 24020 branches covered (71.81%)

Branch coverage included in aggregate %.

77 of 102 new or added lines in 5 files covered. (75.49%)

99 existing lines in 1 file now uncovered.

55704 of 64966 relevant lines covered (85.74%)

43385886.01 hits per line

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

76.02
/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
double surface_grazing_cutoff {0.01};
140
double surface_grazing_ratio {0.5};
141
TemperatureMethod temperature_method {TemperatureMethod::NEAREST};
142
double temperature_tolerance {10.0};
143
double temperature_default {293.6};
144
array<double, 2> temperature_range {0.0, 0.0};
145
int trace_batch;
146
int trace_gen;
147
int64_t trace_particle;
148
vector<array<int, 3>> track_identifiers;
149
int trigger_batch_interval {1};
150
int verbosity {-1};
151
double weight_cutoff {0.25};
152
double weight_survive {1.0};
153

154
} // namespace settings
155

156
//==============================================================================
157
// Functions
158
//==============================================================================
159

160
void get_run_parameters(pugi::xml_node node_base)
7,199✔
161
{
162
  using namespace settings;
163
  using namespace pugi;
164

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

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

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

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

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

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

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

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

212
  // Get number of inactive batches
213
  if (run_mode == RunMode::EIGENVALUE ||
7,199✔
214
      solver_type == SolverType::RANDOM_RAY) {
2,676✔
215
    if (check_for_node(node_base, "inactive")) {
4,940✔
216
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,755✔
217
    }
218
    if (check_for_node(node_base, "generations_per_batch")) {
4,940✔
219
      gen_per_batch =
16✔
220
        std::stoi(get_node_value(node_base, "generations_per_batch"));
16✔
221
    }
222

223
    // Preallocate space for keff and entropy by generation
224
    int m = settings::n_max_batches * settings::gen_per_batch;
4,940✔
225
    simulation::k_generation.reserve(m);
4,940✔
226
    simulation::entropy.reserve(m);
4,940✔
227

228
    // Get the trigger information for keff
229
    if (check_for_node(node_base, "keff_trigger")) {
4,940✔
230
      xml_node node_keff_trigger = node_base.child("keff_trigger");
107✔
231

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

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

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

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

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

397
  // Get root element
398
  xml_node root = doc.document_element();
1,359✔
399

400
  // Verbosity
401
  if (check_for_node(root, "verbosity") && verbosity == -1) {
1,359!
402
    verbosity = std::stoi(get_node_value(root, "verbosity"));
182✔
403
  } else if (verbosity == -1) {
1,177!
404
    verbosity = 7;
1,177✔
405
  }
406

407
  // To this point, we haven't displayed any output since we didn't know what
408
  // the verbosity is. Now that we checked for it, show the title if necessary
409
  if (mpi::master) {
1,359✔
410
    if (verbosity >= 2)
1,134✔
411
      title();
962✔
412
  }
413

414
  write_message("Reading settings XML file...", 5);
1,359✔
415

416
  read_settings_xml(root);
1,359✔
417
}
1,371✔
418

419
void read_settings_xml(pugi::xml_node root)
7,974✔
420
{
421
  using namespace settings;
422
  using namespace pugi;
423

424
  // Find if a multi-group or continuous-energy simulation is desired
425
  if (check_for_node(root, "energy_mode")) {
7,974✔
426
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
1,207✔
427
    if (temp_str == "mg" || temp_str == "multi-group") {
1,207!
428
      run_CE = false;
1,207✔
429
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
430
      run_CE = true;
×
431
    }
432
  }
1,207✔
433

434
  // Check for user meshes and allocate
435
  read_meshes(root);
7,974✔
436

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

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

461
  // Check for a trigger node and get trigger information
462
  if (check_for_node(root, "trigger")) {
7,974✔
463
    xml_node node_trigger = root.child("trigger");
162✔
464

465
    // Check if trigger(s) are to be turned on
466
    trigger_on = get_node_value_bool(node_trigger, "active");
162✔
467

468
    if (trigger_on) {
162✔
469
      if (check_for_node(node_trigger, "max_batches")) {
146!
470
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
146✔
471
      } else {
472
        fatal_error("<max_batches> must be specified with triggers");
×
473
      }
474

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

488
  // Check run mode if it hasn't been set from the command line
489
  xml_node node_mode;
7,974✔
490
  if (run_mode == RunMode::UNSET) {
7,974✔
491
    if (check_for_node(root, "run_mode")) {
7,231✔
492
      std::string temp_str = get_node_value(root, "run_mode", true, true);
7,199✔
493
      if (temp_str == "eigenvalue") {
7,199✔
494
        run_mode = RunMode::EIGENVALUE;
4,491✔
495
      } else if (temp_str == "fixed source") {
2,708✔
496
        run_mode = RunMode::FIXED_SOURCE;
2,676✔
497
      } else if (temp_str == "plot") {
32!
498
        run_mode = RunMode::PLOTTING;
×
499
      } else if (temp_str == "particle restart") {
32!
500
        run_mode = RunMode::PARTICLE;
×
501
      } else if (temp_str == "volume") {
32!
502
        run_mode = RunMode::VOLUME;
32✔
503
      } else {
504
        fatal_error("Unrecognized run mode: " + temp_str);
×
505
      }
506

507
      // Assume XML specifies <particles>, <batches>, etc. directly
508
      node_mode = root;
7,199✔
509
    } else {
7,199✔
510
      warning("<run_mode> should be specified.");
32✔
511

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

527
  // Check solver type
528
  if (check_for_node(root, "random_ray")) {
7,974✔
529
    solver_type = SolverType::RANDOM_RAY;
673✔
530
    if (run_CE)
673!
531
      fatal_error("multi-group energy mode must be specified in settings XML "
×
532
                  "when using the random ray solver.");
533
  }
534

535
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
7,974✔
536
    // Read run parameters
537
    get_run_parameters(node_mode);
7,199✔
538

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

553
    // Check for user value for the number of generation of the Iterated Fission
554
    // Probability (IFP) method
555
    if (check_for_node(root, "ifp_n_generation")) {
7,199✔
556
      ifp_n_generation = std::stoi(get_node_value(root, "ifp_n_generation"));
85✔
557
      if (ifp_n_generation <= 0) {
85!
558
        fatal_error("'ifp_n_generation' must be greater than 0.");
×
559
      }
560
      // Avoid tallying 0 if IFP logs are not complete when active cycles start
561
      if (ifp_n_generation > n_inactive) {
85✔
562
        fatal_error("'ifp_n_generation' must be lower than or equal to the "
9✔
563
                    "number of inactive cycles.");
564
      }
565
    }
566
  }
567

568
  // Copy plotting random number seed if specified
569
  if (check_for_node(root, "plot_seed")) {
7,965!
570
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
571
    model::plotter_seed = seed;
×
572
  }
573

574
  // Copy random number seed if specified
575
  if (check_for_node(root, "seed")) {
7,965✔
576
    auto seed = std::stoll(get_node_value(root, "seed"));
589✔
577
    openmc_set_seed(seed);
589✔
578
  }
579

580
  // Copy random number stride if specified
581
  if (check_for_node(root, "stride")) {
7,965✔
582
    auto stride = std::stoull(get_node_value(root, "stride"));
16✔
583
    openmc_set_stride(stride);
16✔
584
  }
585

586
  // Check for electron treatment
587
  if (check_for_node(root, "electron_treatment")) {
7,965✔
588
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
70✔
589
    if (temp_str == "led") {
70✔
590
      electron_treatment = ElectronTreatment::LED;
11✔
591
    } else if (temp_str == "ttb") {
59!
592
      electron_treatment = ElectronTreatment::TTB;
59✔
593
    } else {
594
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
595
    }
596
  }
70✔
597

598
  // Check for photon transport
599
  if (check_for_node(root, "photon_transport")) {
7,965✔
600
    photon_transport = get_node_value_bool(root, "photon_transport");
199✔
601

602
    if (!run_CE && photon_transport) {
199!
603
      fatal_error("Photon transport is not currently supported in "
×
604
                  "multigroup mode");
605
    }
606
  }
607

608
  // Number of bins for logarithmic grid
609
  if (check_for_node(root, "log_grid_bins")) {
7,965✔
610
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
16✔
611
    if (n_log_bins < 1) {
16!
612
      fatal_error("Number of bins for logarithmic grid must be greater "
×
613
                  "than zero.");
614
    }
615
  }
616

617
  // Number of OpenMP threads
618
  if (check_for_node(root, "threads")) {
7,965!
619
    if (mpi::master)
×
620
      warning("The <threads> element has been deprecated. Use "
×
621
              "the OMP_NUM_THREADS environment variable to set the number of "
622
              "threads.");
623
  }
624

625
  // ==========================================================================
626
  // EXTERNAL SOURCE
627

628
  // Get point to list of <source> elements and make sure there is at least one
629
  for (pugi::xml_node node : root.children("source")) {
15,363✔
630
    model::external_sources.push_back(Source::create(node));
7,408✔
631
  }
632

633
  // Check if the user has specified to read surface source
634
  if (check_for_node(root, "surf_source_read")) {
7,955✔
635
    surf_source_read = true;
32✔
636
    // Get surface source read node
637
    xml_node node_ssr = root.child("surf_source_read");
32✔
638

639
    std::string path = "surface_source.h5";
32✔
640
    // Check if the user has specified different file for surface source reading
641
    if (check_for_node(node_ssr, "path")) {
32!
642
      path = get_node_value(node_ssr, "path", false, true);
32✔
643
    }
644
    model::external_sources.push_back(make_unique<FileSource>(path));
32✔
645
  }
32✔
646

647
  // If no source specified, default to isotropic point source at origin with
648
  // Watt spectrum. No default source is needed in random ray mode.
649
  if (model::external_sources.empty() &&
10,089✔
650
      settings::solver_type != SolverType::RANDOM_RAY) {
2,134✔
651
    double T[] {0.0};
2,006✔
652
    double p[] {1.0};
2,006✔
653
    model::external_sources.push_back(make_unique<IndependentSource>(
2,006✔
654
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
4,012✔
655
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
4,012✔
656
      UPtrDist {new Discrete(T, p, 1)}));
4,012✔
657
  }
658

659
  // Build probability mass function for sampling external sources
660
  vector<double> source_strengths;
7,955✔
661
  for (auto& s : model::external_sources) {
17,391✔
662
    source_strengths.push_back(s->strength());
9,436✔
663
  }
664
  model::external_sources_probability.assign(source_strengths);
7,955✔
665

666
  // Check if we want to write out source
667
  if (check_for_node(root, "write_initial_source")) {
7,955!
668
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
669
  }
670

671
  // Get relative number of lost particles
672
  if (check_for_node(root, "source_rejection_fraction")) {
7,955✔
673
    source_rejection_fraction =
6✔
674
      std::stod(get_node_value(root, "source_rejection_fraction"));
6!
675
  }
676

677
  if (check_for_node(root, "free_gas_threshold")) {
7,955!
678
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
679
  }
680

681
  // Surface grazing
682
  if (check_for_node(root, "surface_grazing_cutoff"))
7,955!
NEW
683
    surface_grazing_cutoff =
×
NEW
684
      std::stod(get_node_value(root, "surface_grazing_cutoff"));
×
685
  if (check_for_node(root, "surface_grazing_ratio"))
7,955!
NEW
686
    surface_grazing_ratio =
×
NEW
687
      std::stod(get_node_value(root, "surface_grazing_ratio"));
×
688

689
  // Survival biasing
690
  if (check_for_node(root, "survival_biasing")) {
7,955✔
691
    survival_biasing = get_node_value_bool(root, "survival_biasing");
177✔
692
  }
693

694
  // Probability tables
695
  if (check_for_node(root, "ptables")) {
7,955✔
696
    urr_ptables_on = get_node_value_bool(root, "ptables");
16✔
697
  }
698

699
  // Cutoffs
700
  if (check_for_node(root, "cutoff")) {
7,955✔
701
    xml_node node_cutoff = root.child("cutoff");
145✔
702
    if (check_for_node(node_cutoff, "weight")) {
145✔
703
      weight_cutoff = std::stod(get_node_value(node_cutoff, "weight"));
16✔
704
    }
705
    if (check_for_node(node_cutoff, "weight_avg")) {
145✔
706
      weight_survive = std::stod(get_node_value(node_cutoff, "weight_avg"));
16✔
707
    }
708
    if (check_for_node(node_cutoff, "survival_normalization")) {
145!
709
      survival_normalization =
×
710
        get_node_value_bool(node_cutoff, "survival_normalization");
×
711
    }
712
    if (check_for_node(node_cutoff, "energy_neutron")) {
145✔
713
      energy_cutoff[0] =
32✔
714
        std::stod(get_node_value(node_cutoff, "energy_neutron"));
16✔
715
    } else if (check_for_node(node_cutoff, "energy")) {
129!
716
      warning("The use of an <energy> cutoff is deprecated and should "
×
717
              "be replaced by <energy_neutron>.");
718
      energy_cutoff[0] = std::stod(get_node_value(node_cutoff, "energy"));
×
719
    }
720
    if (check_for_node(node_cutoff, "energy_photon")) {
145✔
721
      energy_cutoff[1] =
172✔
722
        std::stod(get_node_value(node_cutoff, "energy_photon"));
86✔
723
    }
724
    if (check_for_node(node_cutoff, "energy_electron")) {
145!
725
      energy_cutoff[2] =
×
726
        std::stof(get_node_value(node_cutoff, "energy_electron"));
×
727
    }
728
    if (check_for_node(node_cutoff, "energy_positron")) {
145!
729
      energy_cutoff[3] =
×
730
        std::stod(get_node_value(node_cutoff, "energy_positron"));
×
731
    }
732
    if (check_for_node(node_cutoff, "time_neutron")) {
145✔
733
      time_cutoff[0] = std::stod(get_node_value(node_cutoff, "time_neutron"));
27✔
734
    }
735
    if (check_for_node(node_cutoff, "time_photon")) {
145!
736
      time_cutoff[1] = std::stod(get_node_value(node_cutoff, "time_photon"));
×
737
    }
738
    if (check_for_node(node_cutoff, "time_electron")) {
145!
739
      time_cutoff[2] = std::stod(get_node_value(node_cutoff, "time_electron"));
×
740
    }
741
    if (check_for_node(node_cutoff, "time_positron")) {
145!
742
      time_cutoff[3] = std::stod(get_node_value(node_cutoff, "time_positron"));
×
743
    }
744
  }
745

746
  // Particle trace
747
  if (check_for_node(root, "trace")) {
7,955✔
748
    auto temp = get_node_array<int64_t>(root, "trace");
16✔
749
    if (temp.size() != 3) {
16!
750
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
751
                  "batch, generation, and particle number.");
752
    }
753
    trace_batch = temp.at(0);
16✔
754
    trace_gen = temp.at(1);
16✔
755
    trace_particle = temp.at(2);
16✔
756
  }
16✔
757

758
  // Particle tracks
759
  if (check_for_node(root, "track")) {
7,955✔
760
    // Get values and make sure there are three per particle
761
    auto temp = get_node_array<int>(root, "track");
48✔
762
    if (temp.size() % 3 != 0) {
48!
763
      fatal_error(
×
764
        "Number of integers specified in 'track' is not "
765
        "divisible by 3.  Please provide 3 integers per particle to be "
766
        "tracked.");
767
    }
768

769
    // Reshape into track_identifiers
770
    int n_tracks = temp.size() / 3;
48✔
771
    for (int i = 0; i < n_tracks; ++i) {
192✔
772
      track_identifiers.push_back(
144✔
773
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
144✔
774
    }
775
  }
48✔
776

777
  // Shannon entropy
778
  if (solver_type == SolverType::RANDOM_RAY) {
7,955✔
779
    if (check_for_node(root, "entropy_mesh")) {
673!
780
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
781
                  "No user-defined entropy mesh is supported.");
782
    }
783
    entropy_on = true;
673✔
784
  } else if (solver_type == SolverType::MONTE_CARLO) {
7,282!
785
    if (check_for_node(root, "entropy_mesh")) {
7,282✔
786
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
335✔
787
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
335!
788
        fatal_error(fmt::format(
×
789
          "Mesh {} specified for Shannon entropy does not exist.", temp));
790
      }
791

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

798
      // Turn on Shannon entropy calculation
799
      entropy_on = true;
335✔
800

801
    } else if (check_for_node(root, "entropy")) {
6,947!
802
      fatal_error(
×
803
        "Specifying a Shannon entropy mesh via the <entropy> element "
804
        "is deprecated. Please create a mesh using <mesh> and then reference "
805
        "it by specifying its ID in an <entropy_mesh> element.");
806
    }
807
  }
808
  // Uniform fission source weighting mesh
809
  if (check_for_node(root, "ufs_mesh")) {
7,955✔
810
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
16✔
811
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
16!
812
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
813
                              "method does not exist.",
814
        temp));
815
    }
816

817
    auto* m =
818
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
16!
819
    if (!m)
16!
820
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
821
    simulation::ufs_mesh = m;
16✔
822

823
    // Turn on uniform fission source weighting
824
    ufs_on = true;
16✔
825

826
  } else if (check_for_node(root, "uniform_fs")) {
7,939!
827
    fatal_error(
×
828
      "Specifying a UFS mesh via the <uniform_fs> element "
829
      "is deprecated. Please create a mesh using <mesh> and then reference "
830
      "it by specifying its ID in a <ufs_mesh> element.");
831
  }
832

833
  // Check if the user has specified to write state points
834
  if (check_for_node(root, "state_point")) {
7,955✔
835

836
    // Get pointer to state_point node
837
    auto node_sp = root.child("state_point");
167✔
838

839
    // Determine number of batches at which to store state points
840
    if (check_for_node(node_sp, "batches")) {
167!
841
      // User gave specific batches to write state points
842
      auto temp = get_node_array<int>(node_sp, "batches");
167✔
843
      for (const auto& b : temp) {
512✔
844
        statepoint_batch.insert(b);
345✔
845
      }
846
    } else {
167✔
847
      // If neither were specified, write state point at last batch
848
      statepoint_batch.insert(n_batches);
×
849
    }
850
  } else {
851
    // If no <state_point> tag was present, by default write state point at
852
    // last batch only
853
    statepoint_batch.insert(n_batches);
7,788✔
854
  }
855

856
  // Check if the user has specified to write source points
857
  if (check_for_node(root, "source_point")) {
7,955✔
858
    // Get source_point node
859
    xml_node node_sp = root.child("source_point");
107✔
860

861
    // Determine batches at which to store source points
862
    if (check_for_node(node_sp, "batches")) {
107✔
863
      // User gave specific batches to write source points
864
      auto temp = get_node_array<int>(node_sp, "batches");
48✔
865
      for (const auto& b : temp) {
128✔
866
        sourcepoint_batch.insert(b);
80✔
867
      }
868
    } else {
48✔
869
      // If neither were specified, write source points with state points
870
      sourcepoint_batch = statepoint_batch;
59✔
871
    }
872

873
    // Check if the user has specified to write binary source file
874
    if (check_for_node(node_sp, "separate")) {
107✔
875
      source_separate = get_node_value_bool(node_sp, "separate");
75✔
876
    }
877
    if (check_for_node(node_sp, "write")) {
107!
878
      source_write = get_node_value_bool(node_sp, "write");
×
879
    }
880
    if (check_for_node(node_sp, "mcpl")) {
107✔
881
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
27✔
882
    }
883
    if (check_for_node(node_sp, "overwrite_latest")) {
107✔
884
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
16✔
885
      source_separate = source_latest;
16✔
886
    }
887
  } else {
888
    // If no <source_point> tag was present, by default we keep source bank in
889
    // statepoint file and write it out at statepoints intervals
890
    source_separate = false;
7,848✔
891
    sourcepoint_batch = statepoint_batch;
7,848✔
892
  }
893

894
  // Check is the user specified to convert strength to statistical weight
895
  if (check_for_node(root, "uniform_source_sampling")) {
7,955✔
896
    uniform_source_sampling =
55✔
897
      get_node_value_bool(root, "uniform_source_sampling");
55✔
898
  }
899

900
  // Check if the user has specified to write surface source
901
  if (check_for_node(root, "surf_source_write")) {
7,955✔
902
    surf_source_write = true;
412✔
903
    // Get surface source write node
904
    xml_node node_ssw = root.child("surf_source_write");
412✔
905

906
    // Determine surface ids at which crossing particles are to be banked.
907
    // If no surfaces are specified, all surfaces in the model will be used
908
    // to bank source points.
909
    if (check_for_node(node_ssw, "surface_ids")) {
412✔
910
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
202✔
911
      for (const auto& b : temp) {
994✔
912
        source_write_surf_id.insert(b);
792✔
913
      }
914
    }
202✔
915

916
    // Get maximum number of particles to be banked per surface
917
    if (check_for_node(node_ssw, "max_particles")) {
412✔
918
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
403✔
919
    } else {
920
      fatal_error("A maximum number of particles needs to be specified "
9✔
921
                  "using the 'max_particles' parameter to store surface "
922
                  "source points.");
923
    }
924

925
    // Get maximum number of surface source files to be created
926
    if (check_for_node(node_ssw, "max_source_files")) {
403✔
927
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
33✔
928
    } else {
929
      ssw_max_files = 1;
370✔
930
    }
931

932
    if (check_for_node(node_ssw, "mcpl")) {
403✔
933
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
11✔
934
    }
935
    // Get cell information
936
    if (check_for_node(node_ssw, "cell")) {
403✔
937
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
104✔
938
      ssw_cell_type = SSWCellType::Both;
104✔
939
    }
940
    if (check_for_node(node_ssw, "cellfrom")) {
403✔
941
      if (ssw_cell_id != C_NONE) {
90✔
942
        fatal_error(
18✔
943
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
944
      }
945
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
72✔
946
      ssw_cell_type = SSWCellType::From;
72✔
947
    }
948
    if (check_for_node(node_ssw, "cellto")) {
385✔
949
      if (ssw_cell_id != C_NONE) {
71✔
950
        fatal_error(
18✔
951
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
952
      }
953
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
53✔
954
      ssw_cell_type = SSWCellType::To;
53✔
955
    }
956
  }
957

958
  // Check if the user has specified to write specific collisions
959
  if (check_for_node(root, "collision_track")) {
7,910✔
960
    settings::collision_track = true;
155✔
961
    // Get collision track node
962
    xml_node node_ct = root.child("collision_track");
155✔
963
    collision_track_config = CollisionTrackConfig {};
155✔
964

965
    // Determine cell ids at which crossing particles are to be banked
966
    if (check_for_node(node_ct, "cell_ids")) {
155✔
967
      auto temp = get_node_array<int>(node_ct, "cell_ids");
81✔
968
      for (const auto& b : temp) {
211✔
969
        collision_track_config.cell_ids.insert(b);
130✔
970
      }
971
    }
81✔
972
    if (check_for_node(node_ct, "reactions")) {
155✔
973
      auto temp = get_node_array<std::string>(node_ct, "reactions");
65✔
974
      for (const auto& b : temp) {
178✔
975
        int reaction_int = reaction_type(b);
113✔
976
        if (reaction_int > 0) {
113!
977
          collision_track_config.mt_numbers.insert(reaction_int);
113✔
978
        }
979
      }
980
    }
65✔
981
    if (check_for_node(node_ct, "universe_ids")) {
155✔
982
      auto temp = get_node_array<int>(node_ct, "universe_ids");
32✔
983
      for (const auto& b : temp) {
64✔
984
        collision_track_config.universe_ids.insert(b);
32✔
985
      }
986
    }
32✔
987
    if (check_for_node(node_ct, "material_ids")) {
155✔
988
      auto temp = get_node_array<int>(node_ct, "material_ids");
32✔
989
      for (const auto& b : temp) {
80✔
990
        collision_track_config.material_ids.insert(b);
48✔
991
      }
992
    }
32✔
993
    if (check_for_node(node_ct, "nuclides")) {
155✔
994
      auto temp = get_node_array<std::string>(node_ct, "nuclides");
32✔
995
      for (const auto& b : temp) {
128✔
996
        collision_track_config.nuclides.insert(b);
96✔
997
      }
998
    }
32✔
999
    if (check_for_node(node_ct, "deposited_E_threshold")) {
155✔
1000
      collision_track_config.deposited_energy_threshold =
32✔
1001
        std::stod(get_node_value(node_ct, "deposited_E_threshold"));
32✔
1002
    }
1003
    // Get maximum number of particles to be banked per collision
1004
    if (check_for_node(node_ct, "max_collisions")) {
155!
1005
      collision_track_config.max_collisions =
155✔
1006
        std::stoll(get_node_value(node_ct, "max_collisions"));
155✔
1007
    } else {
1008
      warning("A maximum number of collisions needs to be specified. "
×
1009
              "By default the code sets 'max_collisions' parameter equals to "
1010
              "1000.");
1011
    }
1012
    // Get maximum number of collision_track files to be created
1013
    if (check_for_node(node_ct, "max_collision_track_files")) {
155!
1014
      collision_track_config.max_files =
×
1015
        std::stoll(get_node_value(node_ct, "max_collision_track_files"));
×
1016
    }
1017
    if (check_for_node(node_ct, "mcpl")) {
155✔
1018
      collision_track_config.mcpl_write = get_node_value_bool(node_ct, "mcpl");
22✔
1019
    }
1020
  }
1021

1022
  // If source is not separate and is to be written out in the statepoint
1023
  // file, make sure that the sourcepoint batch numbers are contained in the
1024
  // statepoint list
1025
  if (!source_separate) {
7,910✔
1026
    for (const auto& b : sourcepoint_batch) {
15,768✔
1027
      if (!contains(statepoint_batch, b)) {
7,949!
1028
        fatal_error(
×
1029
          "Sourcepoint batches are not a subset of statepoint batches.");
1030
      }
1031
    }
1032
  }
1033

1034
  // Check if the user has specified to not reduce tallies at the end of every
1035
  // batch
1036
  if (check_for_node(root, "no_reduce")) {
7,910✔
1037
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
32✔
1038
  }
1039

1040
  // Check if the user has specified to use confidence intervals for
1041
  // uncertainties rather than standard deviations
1042
  if (check_for_node(root, "confidence_intervals")) {
7,910✔
1043
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
16✔
1044
  }
1045

1046
  // Check for output options
1047
  if (check_for_node(root, "output")) {
7,910✔
1048
    // Get pointer to output node
1049
    pugi::xml_node node_output = root.child("output");
606✔
1050

1051
    // Check for summary option
1052
    if (check_for_node(node_output, "summary")) {
606✔
1053
      output_summary = get_node_value_bool(node_output, "summary");
579✔
1054
    }
1055

1056
    // Check for ASCII tallies output option
1057
    if (check_for_node(node_output, "tallies")) {
606✔
1058
      output_tallies = get_node_value_bool(node_output, "tallies");
184✔
1059
    }
1060

1061
    // Set output directory if a path has been specified
1062
    if (check_for_node(node_output, "path")) {
606!
1063
      path_output = get_node_value(node_output, "path");
×
1064
      if (!ends_with(path_output, "/")) {
×
1065
        path_output += "/";
×
1066
      }
1067
    }
1068
  }
1069

1070
  // Resonance scattering parameters
1071
  if (check_for_node(root, "resonance_scattering")) {
7,910✔
1072
    xml_node node_res_scat = root.child("resonance_scattering");
16✔
1073

1074
    // See if resonance scattering is enabled
1075
    if (check_for_node(node_res_scat, "enable")) {
16!
1076
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
16✔
1077
    } else {
1078
      res_scat_on = true;
×
1079
    }
1080

1081
    // Determine what method is used
1082
    if (check_for_node(node_res_scat, "method")) {
16!
1083
      auto temp = get_node_value(node_res_scat, "method", true, true);
16✔
1084
      if (temp == "rvs") {
16!
1085
        res_scat_method = ResScatMethod::rvs;
16✔
1086
      } else if (temp == "dbrc") {
×
1087
        res_scat_method = ResScatMethod::dbrc;
×
1088
      } else {
1089
        fatal_error(
×
1090
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1091
      }
1092
    }
16✔
1093

1094
    // Minimum energy for resonance scattering
1095
    if (check_for_node(node_res_scat, "energy_min")) {
16!
1096
      res_scat_energy_min =
16✔
1097
        std::stod(get_node_value(node_res_scat, "energy_min"));
16✔
1098
    }
1099
    if (res_scat_energy_min < 0.0) {
16!
1100
      fatal_error("Lower resonance scattering energy bound is negative");
×
1101
    }
1102

1103
    // Maximum energy for resonance scattering
1104
    if (check_for_node(node_res_scat, "energy_max")) {
16!
1105
      res_scat_energy_max =
16✔
1106
        std::stod(get_node_value(node_res_scat, "energy_max"));
16✔
1107
    }
1108
    if (res_scat_energy_max < res_scat_energy_min) {
16!
1109
      fatal_error("Upper resonance scattering energy bound is below the "
×
1110
                  "lower resonance scattering energy bound.");
1111
    }
1112

1113
    // Get resonance scattering nuclides
1114
    if (check_for_node(node_res_scat, "nuclides")) {
16!
1115
      res_scat_nuclides =
1116
        get_node_array<std::string>(node_res_scat, "nuclides");
16✔
1117
    }
1118
  }
1119

1120
  // Get volume calculations
1121
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
8,236✔
1122
    model::volume_calcs.emplace_back(node_vol);
326✔
1123
  }
1124

1125
  // Get temperature settings
1126
  if (check_for_node(root, "temperature_default")) {
7,910✔
1127
    temperature_default =
172✔
1128
      std::stod(get_node_value(root, "temperature_default"));
172✔
1129
  }
1130
  if (check_for_node(root, "temperature_method")) {
7,910✔
1131
    auto temp = get_node_value(root, "temperature_method", true, true);
325✔
1132
    if (temp == "nearest") {
325✔
1133
      temperature_method = TemperatureMethod::NEAREST;
140✔
1134
    } else if (temp == "interpolation") {
185!
1135
      temperature_method = TemperatureMethod::INTERPOLATION;
185✔
1136
    } else {
1137
      fatal_error("Unknown temperature method: " + temp);
×
1138
    }
1139
  }
325✔
1140
  if (check_for_node(root, "temperature_tolerance")) {
7,910✔
1141
    temperature_tolerance =
171✔
1142
      std::stod(get_node_value(root, "temperature_tolerance"));
171✔
1143
  }
1144
  if (check_for_node(root, "temperature_multipole")) {
7,910✔
1145
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
32✔
1146

1147
    // Multipole currently doesn't work with photon transport
1148
    if (temperature_multipole && photon_transport) {
32!
1149
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1150
                  "photon transport.");
1151
    }
1152
  }
1153
  if (check_for_node(root, "temperature_range")) {
7,910!
1154
    auto range = get_node_array<double>(root, "temperature_range");
×
1155
    temperature_range[0] = range.at(0);
×
1156
    temperature_range[1] = range.at(1);
×
1157
  }
×
1158

1159
  // Check for tabular_legendre options
1160
  if (check_for_node(root, "tabular_legendre")) {
7,910✔
1161
    // Get pointer to tabular_legendre node
1162
    xml_node node_tab_leg = root.child("tabular_legendre");
96✔
1163

1164
    // Check for enable option
1165
    if (check_for_node(node_tab_leg, "enable")) {
96!
1166
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
96✔
1167
    }
1168

1169
    // Check for the number of points
1170
    if (check_for_node(node_tab_leg, "num_points")) {
96!
1171
      legendre_to_tabular_points =
×
1172
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
1173
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
1174
        fatal_error(
×
1175
          "The 'num_points' subelement/attribute of the "
1176
          "<tabular_legendre> element must contain a value greater than 1");
1177
      }
1178
    }
1179
  }
1180

1181
  // Check whether create delayed neutrons in fission
1182
  if (check_for_node(root, "create_delayed_neutrons")) {
7,910!
1183
    create_delayed_neutrons =
×
1184
      get_node_value_bool(root, "create_delayed_neutrons");
×
1185
  }
1186

1187
  // Check whether create fission sites
1188
  if (run_mode == RunMode::FIXED_SOURCE) {
7,910✔
1189
    if (check_for_node(root, "create_fission_neutrons")) {
2,630✔
1190
      create_fission_neutrons =
149✔
1191
        get_node_value_bool(root, "create_fission_neutrons");
149✔
1192
    }
1193
  }
1194

1195
  // Check whether to scale fission photon yields
1196
  if (check_for_node(root, "delayed_photon_scaling")) {
7,910!
1197
    delayed_photon_scaling =
×
1198
      get_node_value_bool(root, "delayed_photon_scaling");
×
1199
  }
1200

1201
  // Check whether to use event-based parallelism
1202
  if (check_for_node(root, "event_based")) {
7,910!
1203
    event_based = get_node_value_bool(root, "event_based");
×
1204
  }
1205

1206
  // Check whether material cell offsets should be generated
1207
  if (check_for_node(root, "material_cell_offsets")) {
7,910!
1208
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1209
  }
1210

1211
  // Weight window information
1212
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
8,002✔
1213
    variance_reduction::weight_windows.emplace_back(
92✔
1214
      std::make_unique<WeightWindows>(node_ww));
184✔
1215
  }
1216

1217
  // Enable weight windows by default if one or more are present
1218
  if (variance_reduction::weight_windows.size() > 0)
7,910✔
1219
    settings::weight_windows_on = true;
65✔
1220

1221
  // read weight windows from file
1222
  if (check_for_node(root, "weight_windows_file")) {
7,910!
1223
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1224
  }
1225

1226
  // read settings for weight windows value, this will override
1227
  // the automatic setting even if weight windows are present
1228
  if (check_for_node(root, "weight_windows_on")) {
7,910✔
1229
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
38✔
1230
  }
1231

1232
  if (check_for_node(root, "max_secondaries")) {
7,910!
1233
    settings::max_secondaries =
×
1234
      std::stoi(get_node_value(root, "max_secondaries"));
×
1235
  }
1236

1237
  if (check_for_node(root, "max_history_splits")) {
7,910✔
1238
    settings::max_history_splits =
215✔
1239
      std::stoi(get_node_value(root, "max_history_splits"));
215✔
1240
  }
1241

1242
  if (check_for_node(root, "max_tracks")) {
7,910✔
1243
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
48✔
1244
  }
1245

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

1264
  // Set up weight window checkpoints
1265
  if (check_for_node(root, "weight_window_checkpoints")) {
7,910✔
1266
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
2!
1267
    if (check_for_node(ww_checkpoints, "collision")) {
2!
1268
      weight_window_checkpoint_collision =
2✔
1269
        get_node_value_bool(ww_checkpoints, "collision");
2!
1270
    }
1271
    if (check_for_node(ww_checkpoints, "surface")) {
2!
1272
      weight_window_checkpoint_surface =
2✔
1273
        get_node_value_bool(ww_checkpoints, "surface");
2!
1274
    }
1275
  }
1276

1277
  if (check_for_node(root, "use_decay_photons")) {
7,910✔
1278
    settings::use_decay_photons =
11✔
1279
      get_node_value_bool(root, "use_decay_photons");
11✔
1280
  }
1281
}
7,910✔
1282

1283
void free_memory_settings()
8,050✔
1284
{
1285
  settings::statepoint_batch.clear();
8,050✔
1286
  settings::sourcepoint_batch.clear();
8,050✔
1287
  settings::source_write_surf_id.clear();
8,050✔
1288
  settings::res_scat_nuclides.clear();
8,050✔
1289
}
8,050✔
1290

1291
//==============================================================================
1292
// C API functions
1293
//==============================================================================
1294

1295
extern "C" int openmc_set_n_batches(
44✔
1296
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1297
{
1298
  if (settings::n_inactive >= n_batches) {
44✔
1299
    set_errmsg("Number of active batches must be greater than zero.");
11✔
1300
    return OPENMC_E_INVALID_ARGUMENT;
11✔
1301
  }
1302

1303
  if (!settings::trigger_on) {
33✔
1304
    // Set n_batches and n_max_batches to same value
1305
    settings::n_batches = n_batches;
11✔
1306
    settings::n_max_batches = n_batches;
11✔
1307
  } else {
1308
    // Set n_batches and n_max_batches based on value of set_max_batches
1309
    if (set_max_batches) {
22✔
1310
      settings::n_max_batches = n_batches;
11✔
1311
    } else {
1312
      settings::n_batches = n_batches;
11✔
1313
    }
1314
  }
1315

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

1321
  // Add value of n_batches to statepoint_batch
1322
  if (add_statepoint_batch &&
55✔
1323
      !(contains(settings::statepoint_batch, n_batches)))
22!
1324
    settings::statepoint_batch.insert(n_batches);
22✔
1325

1326
  return 0;
33✔
1327
}
1328

1329
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,530✔
1330
{
1331
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,530✔
1332

1333
  return 0;
2,530✔
1334
}
1335

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

© 2026 Coveralls, Inc