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

openmc-dev / openmc / 21883244533

10 Feb 2026 09:34PM UTC coverage: 81.91% (+0.005%) from 81.905%
21883244533

Pull #3790

github

web-flow
Merge f540c8373 into 3f20a5e22
Pull Request #3790: Subcritical Multiplication Run Mode

17414 of 24353 branches covered (71.51%)

Branch coverage included in aggregate %.

74 of 85 new or added lines in 14 files covered. (87.06%)

56216 of 65538 relevant lines covered (85.78%)

47169664.29 hits per line

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

77.37
/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 {-1};
149
double weight_cutoff {0.25};
150
double weight_survive {1.0};
151

152
bool eigenvalue_like()
2,147,483,647✔
153
{
154
  return run_mode == RunMode::EIGENVALUE ||
2,147,483,647✔
155
         run_mode == RunMode::SUBCRITICAL_MULTIPLICATION;
2,147,483,647✔
156
}
157

158
} // namespace settings
159

160
//==============================================================================
161
// Functions
162
//==============================================================================
163

164
void get_run_parameters(pugi::xml_node node_base)
7,505✔
165
{
166
  using namespace settings;
167
  using namespace pugi;
168

169
  // Check number of particles
170
  if (!check_for_node(node_base, "particles")) {
7,505!
171
    fatal_error("Need to specify number of particles.");
×
172
  }
173

174
  // Get number of particles if it wasn't specified as a command-line argument
175
  if (n_particles == -1) {
7,505!
176
    n_particles = std::stoll(get_node_value(node_base, "particles"));
7,505✔
177
  }
178

179
  // Get maximum number of in flight particles for event-based mode
180
  if (check_for_node(node_base, "max_particles_in_flight")) {
7,505!
181
    max_particles_in_flight =
×
182
      std::stoll(get_node_value(node_base, "max_particles_in_flight"));
×
183
  }
184

185
  // Get maximum number of events allowed per particle
186
  if (check_for_node(node_base, "max_particle_events")) {
7,505!
187
    max_particle_events =
×
188
      std::stoll(get_node_value(node_base, "max_particle_events"));
×
189
  }
190

191
  // Get number of basic batches
192
  if (check_for_node(node_base, "batches")) {
7,505!
193
    n_batches = std::stoi(get_node_value(node_base, "batches"));
7,505✔
194
  }
195
  if (!trigger_on)
7,505✔
196
    n_max_batches = n_batches;
7,359✔
197

198
  // Get max number of lost particles
199
  if (check_for_node(node_base, "max_lost_particles")) {
7,505✔
200
    max_lost_particles =
49✔
201
      std::stoi(get_node_value(node_base, "max_lost_particles"));
49✔
202
  }
203

204
  // Get relative number of lost particles
205
  if (check_for_node(node_base, "rel_max_lost_particles")) {
7,505!
206
    rel_max_lost_particles =
×
207
      std::stod(get_node_value(node_base, "rel_max_lost_particles"));
×
208
  }
209

210
  // Get relative number of lost particles
211
  if (check_for_node(node_base, "max_write_lost_particles")) {
7,505✔
212
    max_write_lost_particles =
16✔
213
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
16✔
214
  }
215

216
  // Get number of inactive batches
217
  if (settings::eigenvalue_like() || solver_type == SolverType::RANDOM_RAY) {
7,505✔
218
    if (check_for_node(node_base, "inactive")) {
5,112✔
219
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,927✔
220
    }
221
    if (check_for_node(node_base, "generations_per_batch")) {
5,112✔
222
      gen_per_batch =
16✔
223
        std::stoi(get_node_value(node_base, "generations_per_batch"));
16✔
224
    }
225

226
    // Preallocate space for keff and entropy by generation
227
    int m = settings::n_max_batches * settings::gen_per_batch;
5,112✔
228
    simulation::k_generation.reserve(m);
5,112✔
229
    simulation::entropy.reserve(m);
5,112✔
230

231
    // Get the trigger information for keff
232
    if (check_for_node(node_base, "keff_trigger")) {
5,112✔
233
      xml_node node_keff_trigger = node_base.child("keff_trigger");
107✔
234

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

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

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

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

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

400
  // Get root element
401
  xml_node root = doc.document_element();
1,370✔
402

403
  // Verbosity
404
  if (check_for_node(root, "verbosity") && verbosity == -1) {
1,370!
405
    verbosity = std::stoi(get_node_value(root, "verbosity"));
182✔
406
  } else if (verbosity == -1) {
1,188!
407
    verbosity = 7;
1,188✔
408
  }
409

410
  // To this point, we haven't displayed any output since we didn't know what
411
  // the verbosity is. Now that we checked for it, show the title if necessary
412
  if (mpi::master) {
1,370✔
413
    if (verbosity >= 2)
1,145✔
414
      title();
973✔
415
  }
416

417
  write_message("Reading settings XML file...", 5);
1,370✔
418

419
  read_settings_xml(root);
1,370✔
420
}
1,382✔
421

422
void read_settings_xml(pugi::xml_node root)
8,314✔
423
{
424
  using namespace settings;
425
  using namespace pugi;
426

427
  // Find if a multi-group or continuous-energy simulation is desired
428
  if (check_for_node(root, "energy_mode")) {
8,314✔
429
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
1,368✔
430
    if (temp_str == "mg" || temp_str == "multi-group") {
1,368!
431
      run_CE = false;
1,368✔
432
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
433
      run_CE = true;
×
434
    }
435
  }
1,368✔
436

437
  // Check for user meshes and allocate
438
  read_meshes(root);
8,314✔
439

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

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

464
  // Check for a trigger node and get trigger information
465
  if (check_for_node(root, "trigger")) {
8,314✔
466
    xml_node node_trigger = root.child("trigger");
162✔
467

468
    // Check if trigger(s) are to be turned on
469
    trigger_on = get_node_value_bool(node_trigger, "active");
162✔
470

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

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

491
  // Check run mode if it hasn't been set from the command line
492
  xml_node node_mode;
8,314✔
493
  if (run_mode == RunMode::UNSET) {
8,314✔
494
    if (check_for_node(root, "run_mode")) {
7,537✔
495
      std::string temp_str = get_node_value(root, "run_mode", true, true);
7,505✔
496
      if (temp_str == "eigenvalue") {
7,505✔
497
        run_mode = RunMode::EIGENVALUE;
4,647✔
498
      } else if (temp_str == "subcritical multiplication") {
2,858✔
499
        run_mode = RunMode::SUBCRITICAL_MULTIPLICATION;
16✔
500
      } else if (temp_str == "fixed source") {
2,842✔
501
        run_mode = RunMode::FIXED_SOURCE;
2,810✔
502
      } else if (temp_str == "plot") {
32!
503
        run_mode = RunMode::PLOTTING;
×
504
      } else if (temp_str == "particle restart") {
32!
505
        run_mode = RunMode::PARTICLE;
×
506
      } else if (temp_str == "volume") {
32!
507
        run_mode = RunMode::VOLUME;
32✔
508
      } else {
509
        fatal_error("Unrecognized run mode: " + temp_str);
×
510
      }
511

512
      // Assume XML specifies <particles>, <batches>, etc. directly
513
      node_mode = root;
7,505✔
514
    } else {
7,505✔
515
      warning("<run_mode> should be specified.");
32✔
516

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

532
  // Check solver type
533
  if (check_for_node(root, "random_ray")) {
8,314✔
534
    solver_type = SolverType::RANDOM_RAY;
796✔
535
    if (run_mode == RunMode::SUBCRITICAL_MULTIPLICATION) {
796!
NEW
536
      fatal_error("random ray solver not currently supported in subcritical "
×
537
                  "multiplication mode");
538
    }
539
    if (run_CE)
796!
540
      fatal_error("multi-group energy mode must be specified in settings XML "
×
541
                  "when using the random ray solver.");
542
  }
543

544
  if (settings::eigenvalue_like() || run_mode == RunMode::FIXED_SOURCE) {
8,314✔
545
    // Read run parameters
546
    get_run_parameters(node_mode);
7,505✔
547

548
    // Check number of active batches, inactive batches, max lost particles and
549
    // particles
550
    if (n_batches <= n_inactive) {
7,505!
551
      fatal_error("Number of active batches must be greater than zero.");
×
552
    } else if (n_inactive < 0) {
7,505!
553
      fatal_error("Number of inactive batches must be non-negative.");
×
554
    } else if (n_particles <= 0) {
7,505!
555
      fatal_error("Number of particles must be greater than zero.");
×
556
    } else if (max_lost_particles <= 0) {
7,505!
557
      fatal_error("Number of max lost particles must be greater than zero.");
×
558
    } else if (rel_max_lost_particles <= 0.0 || rel_max_lost_particles >= 1.0) {
7,505!
559
      fatal_error("Relative max lost particles must be between zero and one.");
×
560
    }
561

562
    // Check for user value for the number of generation of the Iterated Fission
563
    // Probability (IFP) method
564
    if (check_for_node(root, "ifp_n_generation")) {
7,505✔
565
      ifp_n_generation = std::stoi(get_node_value(root, "ifp_n_generation"));
85✔
566
      if (ifp_n_generation <= 0) {
85!
567
        fatal_error("'ifp_n_generation' must be greater than 0.");
×
568
      }
569
      // Avoid tallying 0 if IFP logs are not complete when active cycles start
570
      if (ifp_n_generation > n_inactive) {
85✔
571
        fatal_error("'ifp_n_generation' must be lower than or equal to the "
9✔
572
                    "number of inactive cycles.");
573
      }
574
    }
575
  }
576

577
  // Copy plotting random number seed if specified
578
  if (check_for_node(root, "plot_seed")) {
8,305!
579
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
580
    model::plotter_seed = seed;
×
581
  }
582

583
  // Copy random number seed if specified
584
  if (check_for_node(root, "seed")) {
8,305✔
585
    auto seed = std::stoll(get_node_value(root, "seed"));
589✔
586
    openmc_set_seed(seed);
589✔
587
  }
588

589
  // Copy random number stride if specified
590
  if (check_for_node(root, "stride")) {
8,305✔
591
    auto stride = std::stoull(get_node_value(root, "stride"));
16✔
592
    openmc_set_stride(stride);
16✔
593
  }
594

595
  // Check for electron treatment
596
  if (check_for_node(root, "electron_treatment")) {
8,305✔
597
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
70✔
598
    if (temp_str == "led") {
70✔
599
      electron_treatment = ElectronTreatment::LED;
11✔
600
    } else if (temp_str == "ttb") {
59!
601
      electron_treatment = ElectronTreatment::TTB;
59✔
602
    } else {
603
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
604
    }
605
  }
70✔
606

607
  // Check for photon transport
608
  if (check_for_node(root, "photon_transport")) {
8,305✔
609
    photon_transport = get_node_value_bool(root, "photon_transport");
199✔
610

611
    if (!run_CE && photon_transport) {
199!
612
      fatal_error("Photon transport is not currently supported in "
×
613
                  "multigroup mode");
614
    }
615
  }
616

617
  // Number of bins for logarithmic grid
618
  if (check_for_node(root, "log_grid_bins")) {
8,305✔
619
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
16✔
620
    if (n_log_bins < 1) {
16!
621
      fatal_error("Number of bins for logarithmic grid must be greater "
×
622
                  "than zero.");
623
    }
624
  }
625

626
  // Number of OpenMP threads
627
  if (check_for_node(root, "threads")) {
8,305!
628
    if (mpi::master)
×
629
      warning("The <threads> element has been deprecated. Use "
×
630
              "the OMP_NUM_THREADS environment variable to set the number of "
631
              "threads.");
632
  }
633

634
  // ==========================================================================
635
  // EXTERNAL SOURCE
636

637
  // Get point to list of <source> elements and make sure there is at least one
638
  for (pugi::xml_node node : root.children("source")) {
16,093✔
639
    model::external_sources.push_back(Source::create(node));
7,798✔
640
  }
641

642
  // Check if the user has specified to read surface source
643
  if (check_for_node(root, "surf_source_read")) {
8,295✔
644
    surf_source_read = true;
32✔
645
    // Get surface source read node
646
    xml_node node_ssr = root.child("surf_source_read");
32✔
647

648
    std::string path = "surface_source.h5";
32✔
649
    // Check if the user has specified different file for surface source reading
650
    if (check_for_node(node_ssr, "path")) {
32!
651
      path = get_node_value(node_ssr, "path", false, true);
32✔
652
    }
653
    model::external_sources.push_back(make_unique<FileSource>(path));
32✔
654
  }
32✔
655

656
  // If no source specified, default to isotropic point source at origin with
657
  // Watt spectrum. No default source is needed in random ray mode.
658
  if (model::external_sources.empty() &&
10,500✔
659
      settings::solver_type != SolverType::RANDOM_RAY) {
2,205✔
660
    double T[] {0.0};
2,050✔
661
    double p[] {1.0};
2,050✔
662
    model::external_sources.push_back(make_unique<IndependentSource>(
2,050✔
663
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
4,100✔
664
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
4,100✔
665
      UPtrDist {new Discrete(T, p, 1)}));
4,100✔
666
  }
667

668
  // Build probability mass function for sampling external sources
669
  vector<double> source_strengths;
8,295✔
670
  for (auto& s : model::external_sources) {
18,165✔
671
    source_strengths.push_back(s->strength());
9,870✔
672
  }
673
  model::external_sources_probability.assign(source_strengths);
8,295✔
674

675
  // Check if we want to write out source
676
  if (check_for_node(root, "write_initial_source")) {
8,295!
677
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
678
  }
679

680
  // Get relative number of lost particles
681
  if (check_for_node(root, "source_rejection_fraction")) {
8,295✔
682
    source_rejection_fraction =
6✔
683
      std::stod(get_node_value(root, "source_rejection_fraction"));
6!
684
  }
685

686
  if (check_for_node(root, "free_gas_threshold")) {
8,295!
687
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
688
  }
689

690
  // Survival biasing
691
  if (check_for_node(root, "survival_biasing")) {
8,295✔
692
    survival_biasing = get_node_value_bool(root, "survival_biasing");
177✔
693
  }
694

695
  // Probability tables
696
  if (check_for_node(root, "ptables")) {
8,295✔
697
    urr_ptables_on = get_node_value_bool(root, "ptables");
16✔
698
  }
699

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

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

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

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

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

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

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

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

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

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

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

834
  // Check if the user has specified to write state points
835
  if (check_for_node(root, "state_point")) {
8,295✔
836

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1047
  // Check for output options
1048
  if (check_for_node(root, "output")) {
8,250✔
1049
    // Get pointer to output node
1050
    pugi::xml_node node_output = root.child("output");
787✔
1051

1052
    // Check for summary option
1053
    if (check_for_node(node_output, "summary")) {
787✔
1054
      output_summary = get_node_value_bool(node_output, "summary");
760✔
1055
    }
1056

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

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

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

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

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

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

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

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

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

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

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

1160
  // Check for tabular_legendre options
1161
  if (check_for_node(root, "tabular_legendre")) {
8,250✔
1162
    // Get pointer to tabular_legendre node
1163
    xml_node node_tab_leg = root.child("tabular_legendre");
112✔
1164

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

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

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

1188
  // Check whether create fission sites
1189
  if (run_mode == RunMode::FIXED_SOURCE) {
8,250✔
1190
    if (check_for_node(root, "create_fission_neutrons")) {
2,764✔
1191
      create_fission_neutrons =
281✔
1192
        get_node_value_bool(root, "create_fission_neutrons");
281✔
1193
    }
1194
  }
1195

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

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

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

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

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

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

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

1233
  if (check_for_node(root, "max_secondaries")) {
8,250!
1234
    settings::max_secondaries =
×
1235
      std::stoi(get_node_value(root, "max_secondaries"));
×
1236
  }
1237

1238
  if (check_for_node(root, "max_history_splits")) {
8,250✔
1239
    settings::max_history_splits =
215✔
1240
      std::stoi(get_node_value(root, "max_history_splits"));
215✔
1241
  }
1242

1243
  if (check_for_node(root, "max_tracks")) {
8,250✔
1244
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
48✔
1245
  }
1246

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

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

1278
  if (check_for_node(root, "use_decay_photons")) {
8,250✔
1279
    settings::use_decay_photons =
11✔
1280
      get_node_value_bool(root, "use_decay_photons");
11✔
1281
  }
1282
}
8,250✔
1283

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

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

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

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

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

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

1327
  return 0;
33✔
1328
}
1329

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

1334
  return 0;
2,530✔
1335
}
1336

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