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

openmc-dev / openmc / 20197979645

13 Dec 2025 09:16PM UTC coverage: 82.118% (+0.008%) from 82.11%
20197979645

Pull #3675

github

web-flow
Merge 3fafce82c into bbfa18d72
Pull Request #3675: Extend level scattering to support incident photons

17013 of 23594 branches covered (72.11%)

Branch coverage included in aggregate %.

55 of 76 new or added lines in 4 files covered. (72.37%)

193 existing lines in 7 files now uncovered.

55125 of 64253 relevant lines covered (85.79%)

43453609.56 hits per line

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

76.59
/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
} // namespace settings
153

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

412
  write_message("Reading settings XML file...", 5);
1,359✔
413

414
  read_settings_xml(root);
1,359✔
415
}
1,371✔
416

417
void read_settings_xml(pugi::xml_node root)
7,631✔
418
{
419
  using namespace settings;
420
  using namespace pugi;
421

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

432
  // Check for user meshes and allocate
433
  read_meshes(root);
7,631✔
434

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

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

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

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

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

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

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

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

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

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

533
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
7,631✔
534
    // Read run parameters
535
    get_run_parameters(node_mode);
7,032✔
536

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

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

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

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

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

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

596
  // Check for photon transport
597
  if (check_for_node(root, "photon_transport")) {
7,622✔
598
    photon_transport = get_node_value_bool(root, "photon_transport");
199✔
599

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

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

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

623
  // ==========================================================================
624
  // EXTERNAL SOURCE
625

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

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

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

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

657
  // Build probability mass function for sampling external sources
658
  vector<double> source_strengths;
7,612✔
659
  for (auto& s : model::external_sources) {
16,721✔
660
    source_strengths.push_back(s->strength());
9,109✔
661
  }
662
  model::external_sources_probability.assign(source_strengths);
7,612✔
663

664
  // Check if we want to write out source
665
  if (check_for_node(root, "write_initial_source")) {
7,612!
UNCOV
666
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
667
  }
668

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

675
  if (check_for_node(root, "free_gas_threshold")) {
7,612!
UNCOV
676
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
677
  }
678

679
  // Survival biasing
680
  if (check_for_node(root, "survival_biasing")) {
7,612✔
681
    survival_biasing = get_node_value_bool(root, "survival_biasing");
177✔
682
  }
683

684
  // Probability tables
685
  if (check_for_node(root, "ptables")) {
7,612✔
686
    urr_ptables_on = get_node_value_bool(root, "ptables");
16✔
687
  }
688

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

736
  // Particle trace
737
  if (check_for_node(root, "trace")) {
7,612✔
738
    auto temp = get_node_array<int64_t>(root, "trace");
16✔
739
    if (temp.size() != 3) {
16!
UNCOV
740
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
741
                  "batch, generation, and particle number.");
742
    }
743
    trace_batch = temp.at(0);
16✔
744
    trace_gen = temp.at(1);
16✔
745
    trace_particle = temp.at(2);
16✔
746
  }
16✔
747

748
  // Particle tracks
749
  if (check_for_node(root, "track")) {
7,612✔
750
    // Get values and make sure there are three per particle
751
    auto temp = get_node_array<int>(root, "track");
48✔
752
    if (temp.size() % 3 != 0) {
48!
UNCOV
753
      fatal_error(
×
754
        "Number of integers specified in 'track' is not "
755
        "divisible by 3.  Please provide 3 integers per particle to be "
756
        "tracked.");
757
    }
758

759
    // Reshape into track_identifiers
760
    int n_tracks = temp.size() / 3;
48✔
761
    for (int i = 0; i < n_tracks; ++i) {
192✔
762
      track_identifiers.push_back(
144✔
763
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
144✔
764
    }
765
  }
48✔
766

767
  // Shannon entropy
768
  if (solver_type == SolverType::RANDOM_RAY) {
7,612✔
769
    if (check_for_node(root, "entropy_mesh")) {
641!
UNCOV
770
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
771
                  "No user-defined entropy mesh is supported.");
772
    }
773
    entropy_on = true;
641✔
774
  } else if (solver_type == SolverType::MONTE_CARLO) {
6,971!
775
    if (check_for_node(root, "entropy_mesh")) {
6,971✔
776
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
335✔
777
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
335!
UNCOV
778
        fatal_error(fmt::format(
×
779
          "Mesh {} specified for Shannon entropy does not exist.", temp));
780
      }
781

782
      auto* m = dynamic_cast<RegularMesh*>(
335!
783
        model::meshes[model::mesh_map.at(temp)].get());
335✔
784
      if (!m)
335!
UNCOV
785
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
786
      simulation::entropy_mesh = m;
335✔
787

788
      // Turn on Shannon entropy calculation
789
      entropy_on = true;
335✔
790

791
    } else if (check_for_node(root, "entropy")) {
6,636!
UNCOV
792
      fatal_error(
×
793
        "Specifying a Shannon entropy mesh via the <entropy> element "
794
        "is deprecated. Please create a mesh using <mesh> and then reference "
795
        "it by specifying its ID in an <entropy_mesh> element.");
796
    }
797
  }
798
  // Uniform fission source weighting mesh
799
  if (check_for_node(root, "ufs_mesh")) {
7,612✔
800
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
16✔
801
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
16!
UNCOV
802
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
803
                              "method does not exist.",
804
        temp));
805
    }
806

807
    auto* m =
808
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
16!
809
    if (!m)
16!
UNCOV
810
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
811
    simulation::ufs_mesh = m;
16✔
812

813
    // Turn on uniform fission source weighting
814
    ufs_on = true;
16✔
815

816
  } else if (check_for_node(root, "uniform_fs")) {
7,596!
UNCOV
817
    fatal_error(
×
818
      "Specifying a UFS mesh via the <uniform_fs> element "
819
      "is deprecated. Please create a mesh using <mesh> and then reference "
820
      "it by specifying its ID in a <ufs_mesh> element.");
821
  }
822

823
  // Check if the user has specified to write state points
824
  if (check_for_node(root, "state_point")) {
7,612✔
825

826
    // Get pointer to state_point node
827
    auto node_sp = root.child("state_point");
167✔
828

829
    // Determine number of batches at which to store state points
830
    if (check_for_node(node_sp, "batches")) {
167!
831
      // User gave specific batches to write state points
832
      auto temp = get_node_array<int>(node_sp, "batches");
167✔
833
      for (const auto& b : temp) {
512✔
834
        statepoint_batch.insert(b);
345✔
835
      }
836
    } else {
167✔
837
      // If neither were specified, write state point at last batch
UNCOV
838
      statepoint_batch.insert(n_batches);
×
839
    }
840
  } else {
841
    // If no <state_point> tag was present, by default write state point at
842
    // last batch only
843
    statepoint_batch.insert(n_batches);
7,445✔
844
  }
845

846
  // Check if the user has specified to write source points
847
  if (check_for_node(root, "source_point")) {
7,612✔
848
    // Get source_point node
849
    xml_node node_sp = root.child("source_point");
107✔
850

851
    // Determine batches at which to store source points
852
    if (check_for_node(node_sp, "batches")) {
107✔
853
      // User gave specific batches to write source points
854
      auto temp = get_node_array<int>(node_sp, "batches");
48✔
855
      for (const auto& b : temp) {
128✔
856
        sourcepoint_batch.insert(b);
80✔
857
      }
858
    } else {
48✔
859
      // If neither were specified, write source points with state points
860
      sourcepoint_batch = statepoint_batch;
59✔
861
    }
862

863
    // Check if the user has specified to write binary source file
864
    if (check_for_node(node_sp, "separate")) {
107✔
865
      source_separate = get_node_value_bool(node_sp, "separate");
75✔
866
    }
867
    if (check_for_node(node_sp, "write")) {
107!
UNCOV
868
      source_write = get_node_value_bool(node_sp, "write");
×
869
    }
870
    if (check_for_node(node_sp, "mcpl")) {
107✔
871
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
27✔
872
    }
873
    if (check_for_node(node_sp, "overwrite_latest")) {
107✔
874
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
16✔
875
      source_separate = source_latest;
16✔
876
    }
877
  } else {
878
    // If no <source_point> tag was present, by default we keep source bank in
879
    // statepoint file and write it out at statepoints intervals
880
    source_separate = false;
7,505✔
881
    sourcepoint_batch = statepoint_batch;
7,505✔
882
  }
883

884
  // Check is the user specified to convert strength to statistical weight
885
  if (check_for_node(root, "uniform_source_sampling")) {
7,612✔
886
    uniform_source_sampling =
55✔
887
      get_node_value_bool(root, "uniform_source_sampling");
55✔
888
  }
889

890
  // Check if the user has specified to write surface source
891
  if (check_for_node(root, "surf_source_write")) {
7,612✔
892
    surf_source_write = true;
412✔
893
    // Get surface source write node
894
    xml_node node_ssw = root.child("surf_source_write");
412✔
895

896
    // Determine surface ids at which crossing particles are to be banked.
897
    // If no surfaces are specified, all surfaces in the model will be used
898
    // to bank source points.
899
    if (check_for_node(node_ssw, "surface_ids")) {
412✔
900
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
202✔
901
      for (const auto& b : temp) {
994✔
902
        source_write_surf_id.insert(b);
792✔
903
      }
904
    }
202✔
905

906
    // Get maximum number of particles to be banked per surface
907
    if (check_for_node(node_ssw, "max_particles")) {
412✔
908
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
403✔
909
    } else {
910
      fatal_error("A maximum number of particles needs to be specified "
9✔
911
                  "using the 'max_particles' parameter to store surface "
912
                  "source points.");
913
    }
914

915
    // Get maximum number of surface source files to be created
916
    if (check_for_node(node_ssw, "max_source_files")) {
403✔
917
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
33✔
918
    } else {
919
      ssw_max_files = 1;
370✔
920
    }
921

922
    if (check_for_node(node_ssw, "mcpl")) {
403✔
923
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
11✔
924
    }
925
    // Get cell information
926
    if (check_for_node(node_ssw, "cell")) {
403✔
927
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
104✔
928
      ssw_cell_type = SSWCellType::Both;
104✔
929
    }
930
    if (check_for_node(node_ssw, "cellfrom")) {
403✔
931
      if (ssw_cell_id != C_NONE) {
90✔
932
        fatal_error(
18✔
933
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
934
      }
935
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
72✔
936
      ssw_cell_type = SSWCellType::From;
72✔
937
    }
938
    if (check_for_node(node_ssw, "cellto")) {
385✔
939
      if (ssw_cell_id != C_NONE) {
71✔
940
        fatal_error(
18✔
941
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
942
      }
943
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
53✔
944
      ssw_cell_type = SSWCellType::To;
53✔
945
    }
946
  }
947

948
  // Check if the user has specified to write specific collisions
949
  if (check_for_node(root, "collision_track")) {
7,567✔
950
    settings::collision_track = true;
155✔
951
    // Get collision track node
952
    xml_node node_ct = root.child("collision_track");
155✔
953
    collision_track_config = CollisionTrackConfig {};
155✔
954

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

1012
  // If source is not separate and is to be written out in the statepoint
1013
  // file, make sure that the sourcepoint batch numbers are contained in the
1014
  // statepoint list
1015
  if (!source_separate) {
7,567✔
1016
    for (const auto& b : sourcepoint_batch) {
15,082✔
1017
      if (!contains(statepoint_batch, b)) {
7,606!
UNCOV
1018
        fatal_error(
×
1019
          "Sourcepoint batches are not a subset of statepoint batches.");
1020
      }
1021
    }
1022
  }
1023

1024
  // Check if the user has specified to not reduce tallies at the end of every
1025
  // batch
1026
  if (check_for_node(root, "no_reduce")) {
7,567✔
1027
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
32✔
1028
  }
1029

1030
  // Check if the user has specified to use confidence intervals for
1031
  // uncertainties rather than standard deviations
1032
  if (check_for_node(root, "confidence_intervals")) {
7,567✔
1033
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
16✔
1034
  }
1035

1036
  // Check for output options
1037
  if (check_for_node(root, "output")) {
7,567✔
1038
    // Get pointer to output node
1039
    pugi::xml_node node_output = root.child("output");
606✔
1040

1041
    // Check for summary option
1042
    if (check_for_node(node_output, "summary")) {
606✔
1043
      output_summary = get_node_value_bool(node_output, "summary");
579✔
1044
    }
1045

1046
    // Check for ASCII tallies output option
1047
    if (check_for_node(node_output, "tallies")) {
606✔
1048
      output_tallies = get_node_value_bool(node_output, "tallies");
184✔
1049
    }
1050

1051
    // Set output directory if a path has been specified
1052
    if (check_for_node(node_output, "path")) {
606!
1053
      path_output = get_node_value(node_output, "path");
×
UNCOV
1054
      if (!ends_with(path_output, "/")) {
×
UNCOV
1055
        path_output += "/";
×
1056
      }
1057
    }
1058
  }
1059

1060
  // Resonance scattering parameters
1061
  if (check_for_node(root, "resonance_scattering")) {
7,567✔
1062
    xml_node node_res_scat = root.child("resonance_scattering");
16✔
1063

1064
    // See if resonance scattering is enabled
1065
    if (check_for_node(node_res_scat, "enable")) {
16!
1066
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
16✔
1067
    } else {
UNCOV
1068
      res_scat_on = true;
×
1069
    }
1070

1071
    // Determine what method is used
1072
    if (check_for_node(node_res_scat, "method")) {
16!
1073
      auto temp = get_node_value(node_res_scat, "method", true, true);
16✔
1074
      if (temp == "rvs") {
16!
1075
        res_scat_method = ResScatMethod::rvs;
16✔
UNCOV
1076
      } else if (temp == "dbrc") {
×
1077
        res_scat_method = ResScatMethod::dbrc;
×
1078
      } else {
UNCOV
1079
        fatal_error(
×
UNCOV
1080
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1081
      }
1082
    }
16✔
1083

1084
    // Minimum energy for resonance scattering
1085
    if (check_for_node(node_res_scat, "energy_min")) {
16!
1086
      res_scat_energy_min =
16✔
1087
        std::stod(get_node_value(node_res_scat, "energy_min"));
16✔
1088
    }
1089
    if (res_scat_energy_min < 0.0) {
16!
UNCOV
1090
      fatal_error("Lower resonance scattering energy bound is negative");
×
1091
    }
1092

1093
    // Maximum energy for resonance scattering
1094
    if (check_for_node(node_res_scat, "energy_max")) {
16!
1095
      res_scat_energy_max =
16✔
1096
        std::stod(get_node_value(node_res_scat, "energy_max"));
16✔
1097
    }
1098
    if (res_scat_energy_max < res_scat_energy_min) {
16!
UNCOV
1099
      fatal_error("Upper resonance scattering energy bound is below the "
×
1100
                  "lower resonance scattering energy bound.");
1101
    }
1102

1103
    // Get resonance scattering nuclides
1104
    if (check_for_node(node_res_scat, "nuclides")) {
16!
1105
      res_scat_nuclides =
1106
        get_node_array<std::string>(node_res_scat, "nuclides");
16✔
1107
    }
1108
  }
1109

1110
  // Get volume calculations
1111
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
7,893✔
1112
    model::volume_calcs.emplace_back(node_vol);
326✔
1113
  }
1114

1115
  // Get temperature settings
1116
  if (check_for_node(root, "temperature_default")) {
7,567✔
1117
    temperature_default =
172✔
1118
      std::stod(get_node_value(root, "temperature_default"));
172✔
1119
  }
1120
  if (check_for_node(root, "temperature_method")) {
7,567✔
1121
    auto temp = get_node_value(root, "temperature_method", true, true);
325✔
1122
    if (temp == "nearest") {
325✔
1123
      temperature_method = TemperatureMethod::NEAREST;
140✔
1124
    } else if (temp == "interpolation") {
185!
1125
      temperature_method = TemperatureMethod::INTERPOLATION;
185✔
1126
    } else {
UNCOV
1127
      fatal_error("Unknown temperature method: " + temp);
×
1128
    }
1129
  }
325✔
1130
  if (check_for_node(root, "temperature_tolerance")) {
7,567✔
1131
    temperature_tolerance =
171✔
1132
      std::stod(get_node_value(root, "temperature_tolerance"));
171✔
1133
  }
1134
  if (check_for_node(root, "temperature_multipole")) {
7,567✔
1135
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
32✔
1136

1137
    // Multipole currently doesn't work with photon transport
1138
    if (temperature_multipole && photon_transport) {
32!
UNCOV
1139
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1140
                  "photon transport.");
1141
    }
1142
  }
1143
  if (check_for_node(root, "temperature_range")) {
7,567!
1144
    auto range = get_node_array<double>(root, "temperature_range");
×
1145
    temperature_range[0] = range.at(0);
×
UNCOV
1146
    temperature_range[1] = range.at(1);
×
UNCOV
1147
  }
×
1148

1149
  // Check for tabular_legendre options
1150
  if (check_for_node(root, "tabular_legendre")) {
7,567✔
1151
    // Get pointer to tabular_legendre node
1152
    xml_node node_tab_leg = root.child("tabular_legendre");
96✔
1153

1154
    // Check for enable option
1155
    if (check_for_node(node_tab_leg, "enable")) {
96!
1156
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
96✔
1157
    }
1158

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

1171
  // Check whether create delayed neutrons in fission
1172
  if (check_for_node(root, "create_delayed_neutrons")) {
7,567!
UNCOV
1173
    create_delayed_neutrons =
×
UNCOV
1174
      get_node_value_bool(root, "create_delayed_neutrons");
×
1175
  }
1176

1177
  // Check whether create fission sites
1178
  if (run_mode == RunMode::FIXED_SOURCE) {
7,567✔
1179
    if (check_for_node(root, "create_fission_neutrons")) {
2,598✔
1180
      create_fission_neutrons =
149✔
1181
        get_node_value_bool(root, "create_fission_neutrons");
149✔
1182
    }
1183
  }
1184

1185
  // Check whether to scale fission photon yields
1186
  if (check_for_node(root, "delayed_photon_scaling")) {
7,567!
UNCOV
1187
    delayed_photon_scaling =
×
UNCOV
1188
      get_node_value_bool(root, "delayed_photon_scaling");
×
1189
  }
1190

1191
  // Check whether to use event-based parallelism
1192
  if (check_for_node(root, "event_based")) {
7,567!
UNCOV
1193
    event_based = get_node_value_bool(root, "event_based");
×
1194
  }
1195

1196
  // Check whether material cell offsets should be generated
1197
  if (check_for_node(root, "material_cell_offsets")) {
7,567!
UNCOV
1198
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1199
  }
1200

1201
  // Weight window information
1202
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
7,659✔
1203
    variance_reduction::weight_windows.emplace_back(
92✔
1204
      std::make_unique<WeightWindows>(node_ww));
184✔
1205
  }
1206

1207
  // Enable weight windows by default if one or more are present
1208
  if (variance_reduction::weight_windows.size() > 0)
7,567✔
1209
    settings::weight_windows_on = true;
65✔
1210

1211
  // read weight windows from file
1212
  if (check_for_node(root, "weight_windows_file")) {
7,567!
UNCOV
1213
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1214
  }
1215

1216
  // read settings for weight windows value, this will override
1217
  // the automatic setting even if weight windows are present
1218
  if (check_for_node(root, "weight_windows_on")) {
7,567✔
1219
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
38✔
1220
  }
1221

1222
  if (check_for_node(root, "max_secondaries")) {
7,567!
UNCOV
1223
    settings::max_secondaries =
×
UNCOV
1224
      std::stoi(get_node_value(root, "max_secondaries"));
×
1225
  }
1226

1227
  if (check_for_node(root, "max_history_splits")) {
7,567✔
1228
    settings::max_history_splits =
215✔
1229
      std::stoi(get_node_value(root, "max_history_splits"));
215✔
1230
  }
1231

1232
  if (check_for_node(root, "max_tracks")) {
7,567✔
1233
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
48✔
1234
  }
1235

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

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

1267
  if (check_for_node(root, "use_decay_photons")) {
7,567✔
1268
    settings::use_decay_photons =
11✔
1269
      get_node_value_bool(root, "use_decay_photons");
11✔
1270
  }
1271
}
7,567✔
1272

1273
void free_memory_settings()
7,707✔
1274
{
1275
  settings::statepoint_batch.clear();
7,707✔
1276
  settings::sourcepoint_batch.clear();
7,707✔
1277
  settings::source_write_surf_id.clear();
7,707✔
1278
  settings::res_scat_nuclides.clear();
7,707✔
1279
}
7,707✔
1280

1281
//==============================================================================
1282
// C API functions
1283
//==============================================================================
1284

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

1293
  if (!settings::trigger_on) {
33✔
1294
    // Set n_batches and n_max_batches to same value
1295
    settings::n_batches = n_batches;
11✔
1296
    settings::n_max_batches = n_batches;
11✔
1297
  } else {
1298
    // Set n_batches and n_max_batches based on value of set_max_batches
1299
    if (set_max_batches) {
22✔
1300
      settings::n_max_batches = n_batches;
11✔
1301
    } else {
1302
      settings::n_batches = n_batches;
11✔
1303
    }
1304
  }
1305

1306
  // Update size of k_generation and entropy
1307
  int m = settings::n_max_batches * settings::gen_per_batch;
33✔
1308
  simulation::k_generation.reserve(m);
33✔
1309
  simulation::entropy.reserve(m);
33✔
1310

1311
  // Add value of n_batches to statepoint_batch
1312
  if (add_statepoint_batch &&
55✔
1313
      !(contains(settings::statepoint_batch, n_batches)))
22!
1314
    settings::statepoint_batch.insert(n_batches);
22✔
1315

1316
  return 0;
33✔
1317
}
1318

1319
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,530✔
1320
{
1321
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,530✔
1322

1323
  return 0;
2,530✔
1324
}
1325

1326
} // namespace openmc
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc