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

openmc-dev / openmc / 24423844846

14 Apr 2026 09:28PM UTC coverage: 81.358% (+0.03%) from 81.326%
24423844846

Pull #3717

github

web-flow
Merge ab2a8c80d into fd1bc26af
Pull Request #3717: Local adjoint source for Random Ray

17727 of 25604 branches covered (69.24%)

Branch coverage included in aggregate %.

366 of 401 new or added lines in 10 files covered. (91.27%)

307 existing lines in 10 files now uncovered.

58414 of 67984 relevant lines covered (85.92%)

44852399.71 hits per line

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

76.33
/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 atomic_relaxation {true};
66
bool reduce_tallies {true};
67
bool res_scat_on {false};
68
bool restart_run {false};
69
bool run_CE {true};
70
bool source_latest {false};
71
bool source_separate {false};
72
bool source_write {true};
73
bool source_mcpl_write {false};
74
bool surf_source_write {false};
75
bool surf_mcpl_write {false};
76
bool surf_source_read {false};
77
bool survival_biasing {false};
78
bool survival_normalization {false};
79
bool temperature_multipole {false};
80
bool trigger_on {false};
81
bool trigger_predict {false};
82
bool uniform_source_sampling {false};
83
bool ufs_on {false};
84
bool urr_ptables_on {true};
85
bool use_decay_photons {false};
86
bool weight_windows_on {false};
87
bool weight_window_checkpoint_surface {false};
88
bool weight_window_checkpoint_collision {true};
89
bool write_all_tracks {false};
90
bool write_initial_source {false};
91

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

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

109
int64_t max_particles_in_flight {100000};
110
int max_particle_events {1000000};
111

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

156
} // namespace settings
157

158
//==============================================================================
159
// Functions
160
//==============================================================================
161

162
void get_run_parameters(pugi::xml_node node_base)
7,477✔
163
{
164
  using namespace settings;
7,477✔
165
  using namespace pugi;
7,477✔
166

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

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

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

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

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

196
  // Get max number of lost particles
197
  if (check_for_node(node_base, "max_lost_particles")) {
7,477✔
198
    max_lost_particles =
92✔
199
      std::stoi(get_node_value(node_base, "max_lost_particles"));
46✔
200
  }
201

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

208
  // Get relative number of lost particles
209
  if (check_for_node(node_base, "max_write_lost_particles")) {
7,477✔
210
    max_write_lost_particles =
30✔
211
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
15✔
212
  }
213

214
  // Get number of inactive batches
215
  if (run_mode == RunMode::EIGENVALUE ||
7,477✔
216
      solver_type == SolverType::RANDOM_RAY) {
2,907✔
217
    if (check_for_node(node_base, "inactive")) {
5,006✔
218
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,795✔
219
    }
220
    if (check_for_node(node_base, "generations_per_batch")) {
5,006✔
221
      gen_per_batch =
30✔
222
        std::stoi(get_node_value(node_base, "generations_per_batch"));
15✔
223
    }
224

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

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

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

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

261
  // Random ray variables
262
  if (solver_type == SolverType::RANDOM_RAY) {
7,477✔
263
    xml_node random_ray_node = node_base.child("random_ray");
792✔
264
    if (check_for_node(random_ray_node, "distance_active")) {
792!
265
      RandomRay::distance_active_ =
1,584✔
266
        std::stod(get_node_value(random_ray_node, "distance_active"));
1,584✔
267
      if (RandomRay::distance_active_ <= 0.0) {
792!
268
        fatal_error("Random ray active distance must be greater than 0");
×
269
      }
270
    } else {
271
      fatal_error("Specify random ray active distance in settings XML");
×
272
    }
273
    if (check_for_node(random_ray_node, "distance_inactive")) {
792!
274
      RandomRay::distance_inactive_ =
1,584✔
275
        std::stod(get_node_value(random_ray_node, "distance_inactive"));
1,584✔
276
      if (RandomRay::distance_inactive_ < 0) {
792!
277
        fatal_error(
×
278
          "Random ray inactive distance must be greater than or equal to 0");
279
      }
280
    } else {
281
      fatal_error("Specify random ray inactive distance in settings XML");
×
282
    }
283
    if (check_for_node(random_ray_node, "ray_source")) {
792!
284
      xml_node ray_source_node = random_ray_node.child("ray_source");
792✔
285
      xml_node source_node = ray_source_node.child("source");
792✔
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);
1,584✔
289
    } else {
290
      fatal_error("Specify random ray source in settings XML");
×
291
    }
292
    if (check_for_node(random_ray_node, "volume_estimator")) {
792✔
293
      std::string temp_str =
151✔
294
        get_node_value(random_ray_node, "volume_estimator", true, true);
151✔
295
      if (temp_str == "simulation_averaged") {
151✔
296
        FlatSourceDomain::volume_estimator_ =
30✔
297
          RandomRayVolumeEstimator::SIMULATION_AVERAGED;
298
      } else if (temp_str == "naive") {
121✔
299
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::NAIVE;
91✔
300
      } else if (temp_str == "hybrid") {
30!
301
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::HYBRID;
30✔
302
      } else {
303
        fatal_error("Unrecognized volume estimator: " + temp_str);
×
304
      }
305
    }
151✔
306
    if (check_for_node(random_ray_node, "source_shape")) {
792✔
307
      std::string temp_str =
450✔
308
        get_node_value(random_ray_node, "source_shape", true, true);
450✔
309
      if (temp_str == "flat") {
450✔
310
        RandomRay::source_shape_ = RandomRaySourceShape::FLAT;
75✔
311
      } else if (temp_str == "linear") {
375✔
312
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR;
330✔
313
      } else if (temp_str == "linear_xy") {
45!
314
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR_XY;
45✔
315
      } else {
316
        fatal_error("Unrecognized source shape: " + temp_str);
×
317
      }
318
    }
450✔
319
    if (check_for_node(random_ray_node, "volume_normalized_flux_tallies")) {
792✔
320
      FlatSourceDomain::volume_normalized_flux_tallies_ =
551✔
321
        get_node_value_bool(random_ray_node, "volume_normalized_flux_tallies");
551✔
322
    }
323
    if (check_for_node(random_ray_node, "adjoint")) {
792✔
324
      FlatSourceDomain::adjoint_ =
45✔
325
        get_node_value_bool(random_ray_node, "adjoint");
45✔
326
    }
327
    if (check_for_node(random_ray_node, "sample_method")) {
792✔
328
      std::string temp_str =
30✔
329
        get_node_value(random_ray_node, "sample_method", true, true);
30✔
330
      if (temp_str == "prng") {
30!
331
        RandomRay::sample_method_ = RandomRaySampleMethod::PRNG;
×
332
      } else if (temp_str == "halton") {
30✔
333
        RandomRay::sample_method_ = RandomRaySampleMethod::HALTON;
15✔
334
      } else if (temp_str == "s2") {
15!
335
        RandomRay::sample_method_ = RandomRaySampleMethod::S2;
15✔
336
      } else {
337
        fatal_error("Unrecognized sample method: " + temp_str);
×
338
      }
339
    }
30✔
340
    if (check_for_node(random_ray_node, "source_region_meshes")) {
792✔
341
      pugi::xml_node node_source_region_meshes =
346✔
342
        random_ray_node.child("source_region_meshes");
346✔
343
      for (pugi::xml_node node_mesh :
752✔
344
        node_source_region_meshes.children("mesh")) {
752✔
345
        int mesh_id = std::stoi(node_mesh.attribute("id").value());
812✔
346
        for (pugi::xml_node node_domain : node_mesh.children("domain")) {
812✔
347
          int domain_id = std::stoi(node_domain.attribute("id").value());
812✔
348
          std::string domain_type = node_domain.attribute("type").value();
406✔
349
          Source::DomainType type;
406✔
350
          if (domain_type == "material") {
406✔
351
            type = Source::DomainType::MATERIAL;
30✔
352
          } else if (domain_type == "cell") {
376✔
353
            type = Source::DomainType::CELL;
30✔
354
          } else if (domain_type == "universe") {
346!
355
            type = Source::DomainType::UNIVERSE;
346✔
356
          } else {
357
            throw std::runtime_error("Unknown domain type: " + domain_type);
×
358
          }
359
          FlatSourceDomain::mesh_domain_map_[mesh_id].emplace_back(
406✔
360
            type, domain_id);
361
        }
406✔
362
      }
363
    }
364
    if (check_for_node(random_ray_node, "diagonal_stabilization_rho")) {
792✔
365
      FlatSourceDomain::diagonal_stabilization_rho_ = std::stod(
15✔
366
        get_node_value(random_ray_node, "diagonal_stabilization_rho"));
15✔
367
      if (FlatSourceDomain::diagonal_stabilization_rho_ < 0.0 ||
15!
368
          FlatSourceDomain::diagonal_stabilization_rho_ > 1.0) {
369
        fatal_error("Random ray diagonal stabilization rho factor must be "
×
370
                    "between 0 and 1");
371
      }
372
    }
373
    if (check_for_node(random_ray_node, "adjoint_source")) {
792✔
374
      pugi::xml_node adj_source_node = random_ray_node.child("adjoint_source");
15✔
375
      for (pugi::xml_node source_node : adj_source_node.children("source")) {
30✔
376
        // Find any local adjoint sources
377
        model::adjoint_sources.push_back(Source::create(source_node));
30✔
378
      }
379
    }
380
  }
381
}
7,477✔
382

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

402
  // Parse settings.xml file
403
  xml_document doc;
1,327✔
404
  auto result = doc.load_file(filename.c_str());
1,327✔
405
  if (!result) {
1,327!
406
    fatal_error("Error processing settings.xml file.");
×
407
  }
408

409
  // Get root element
410
  xml_node root = doc.document_element();
1,327✔
411

412
  // Verbosity
413
  if (check_for_node(root, "verbosity") && verbosity == -1) {
1,327!
414
    verbosity = std::stoi(get_node_value(root, "verbosity"));
362✔
415
  } else if (verbosity == -1) {
1,146!
416
    verbosity = 7;
1,146✔
417
  }
418

419
  // To this point, we haven't displayed any output since we didn't know what
420
  // the verbosity is. Now that we checked for it, show the title if necessary
421
  if (mpi::master) {
1,327✔
422
    if (verbosity >= 2)
1,147✔
423
      title();
974✔
424
  }
425

426
  write_message("Reading settings XML file...", 5);
1,327✔
427

428
  read_settings_xml(root);
1,327✔
429
}
1,339✔
430

431
void read_settings_xml(pugi::xml_node root)
8,285✔
432
{
433
  using namespace settings;
8,285✔
434
  using namespace pugi;
8,285✔
435

436
  // Find if a multi-group or continuous-energy simulation is desired
437
  if (check_for_node(root, "energy_mode")) {
8,285✔
438
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
1,327✔
439
    if (temp_str == "mg" || temp_str == "multi-group") {
2,654!
440
      run_CE = false;
1,327✔
441
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
442
      run_CE = true;
×
443
    }
444
  }
1,327✔
445

446
  // Check for user meshes and allocate
447
  read_meshes(root);
8,285✔
448

449
  // Look for deprecated cross_sections.xml file in settings.xml
450
  if (check_for_node(root, "cross_sections")) {
8,285!
451
    warning(
×
452
      "Setting cross_sections in settings.xml has been deprecated."
453
      " The cross_sections are now set in materials.xml and the "
454
      "cross_sections input to materials.xml and the OPENMC_CROSS_SECTIONS"
455
      " environment variable will take precendent over setting "
456
      "cross_sections in settings.xml.");
457
    path_cross_sections = get_node_value(root, "cross_sections");
×
458
  }
459

460
  if (!run_CE) {
8,285✔
461
    // Scattering Treatments
462
    if (check_for_node(root, "max_order")) {
1,327✔
463
      max_order = std::stoi(get_node_value(root, "max_order"));
30✔
464
    } else {
465
      // Set to default of largest int - 1, which means to use whatever is
466
      // contained in library. This is largest int - 1 because for legendre
467
      // scattering, a value of 1 is added to the order; adding 1 to the largest
468
      // int gets you the largest negative integer, which is not what we want.
469
      max_order = std::numeric_limits<int>::max() - 1;
1,312✔
470
    }
471
  }
472

473
  // Check for a trigger node and get trigger information
474
  if (check_for_node(root, "trigger")) {
8,285✔
475
    xml_node node_trigger = root.child("trigger");
156✔
476

477
    // Check if trigger(s) are to be turned on
478
    trigger_on = get_node_value_bool(node_trigger, "active");
156✔
479

480
    if (trigger_on) {
156✔
481
      if (check_for_node(node_trigger, "max_batches")) {
141!
482
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
282✔
483
      } else {
484
        fatal_error("<max_batches> must be specified with triggers");
×
485
      }
486

487
      // Get the batch interval to check triggers
488
      if (!check_for_node(node_trigger, "batch_interval")) {
141✔
489
        trigger_predict = true;
15✔
490
      } else {
491
        trigger_batch_interval =
252✔
492
          std::stoi(get_node_value(node_trigger, "batch_interval"));
252✔
493
        if (trigger_batch_interval <= 0) {
126!
494
          fatal_error("Trigger batch interval must be greater than zero");
×
495
        }
496
      }
497
    }
498
  }
499

500
  // Check run mode if it hasn't been set from the command line
501
  xml_node node_mode;
8,285✔
502
  if (run_mode == RunMode::UNSET) {
8,285✔
503
    if (check_for_node(root, "run_mode")) {
7,509✔
504
      std::string temp_str = get_node_value(root, "run_mode", true, true);
7,479✔
505
      if (temp_str == "eigenvalue") {
7,479✔
506
        run_mode = RunMode::EIGENVALUE;
4,540✔
507
      } else if (temp_str == "fixed source") {
2,939✔
508
        run_mode = RunMode::FIXED_SOURCE;
2,907✔
509
      } else if (temp_str == "plot") {
32!
510
        run_mode = RunMode::PLOTTING;
×
511
      } else if (temp_str == "particle restart") {
32!
512
        run_mode = RunMode::PARTICLE;
×
513
      } else if (temp_str == "volume") {
32!
514
        run_mode = RunMode::VOLUME;
32✔
515
      } else {
516
        fatal_error("Unrecognized run mode: " + temp_str);
×
517
      }
518

519
      // Assume XML specifies <particles>, <batches>, etc. directly
520
      node_mode = root;
7,479✔
521
    } else {
7,479✔
522
      warning("<run_mode> should be specified.");
30✔
523

524
      // Make sure that either eigenvalue or fixed source was specified
525
      node_mode = root.child("eigenvalue");
30✔
526
      if (node_mode) {
30!
527
        run_mode = RunMode::EIGENVALUE;
30✔
528
      } else {
529
        node_mode = root.child("fixed_source");
×
530
        if (node_mode) {
×
531
          run_mode = RunMode::FIXED_SOURCE;
×
532
        } else {
533
          fatal_error("<eigenvalue> or <fixed_source> not specified.");
×
534
        }
535
      }
536
    }
537
  }
538

539
  // Check solver type
540
  if (check_for_node(root, "random_ray")) {
8,285✔
541
    solver_type = SolverType::RANDOM_RAY;
792✔
542
    if (run_CE)
792!
543
      fatal_error("multi-group energy mode must be specified in settings XML "
×
544
                  "when using the random ray solver.");
545
  }
546

547
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
8,285✔
548
    // Read run parameters
549
    get_run_parameters(node_mode);
7,477✔
550

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

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

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

586
  // Copy random number seed if specified
587
  if (check_for_node(root, "seed")) {
8,276✔
588
    auto seed = std::stoll(get_node_value(root, "seed"));
1,154✔
589
    openmc_set_seed(seed);
577✔
590
  }
591

592
  // Copy random number stride if specified
593
  if (check_for_node(root, "stride")) {
8,276✔
594
    auto stride = std::stoull(get_node_value(root, "stride"));
30✔
595
    openmc_set_stride(stride);
15✔
596
  }
597

598
  // Check for electron treatment
599
  if (check_for_node(root, "electron_treatment")) {
8,276✔
600
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
82✔
601
    if (temp_str == "led") {
82✔
602
      electron_treatment = ElectronTreatment::LED;
26✔
603
    } else if (temp_str == "ttb") {
56!
604
      electron_treatment = ElectronTreatment::TTB;
56✔
605
    } else {
606
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
607
    }
608
  }
82✔
609

610
  // Check for photon transport
611
  if (check_for_node(root, "photon_transport")) {
8,276✔
612
    photon_transport = get_node_value_bool(root, "photon_transport");
205✔
613

614
    if (!run_CE && photon_transport) {
205!
615
      fatal_error("Photon transport is not currently supported in "
×
616
                  "multigroup mode");
617
    }
618
  }
619

620
  // Check for atomic relaxation
621
  if (check_for_node(root, "atomic_relaxation")) {
8,276✔
622
    atomic_relaxation = get_node_value_bool(root, "atomic_relaxation");
15✔
623
  }
624

625
  // Number of bins for logarithmic grid
626
  if (check_for_node(root, "log_grid_bins")) {
8,276✔
627
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
30✔
628
    if (n_log_bins < 1) {
15!
629
      fatal_error("Number of bins for logarithmic grid must be greater "
×
630
                  "than zero.");
631
    }
632
  }
633

634
  // Number of OpenMP threads
635
  if (check_for_node(root, "threads")) {
8,276!
636
    if (mpi::master)
×
637
      warning("The <threads> element has been deprecated. Use "
×
638
              "the OMP_NUM_THREADS environment variable to set the number of "
639
              "threads.");
640
  }
641

642
  // ==========================================================================
643
  // EXTERNAL SOURCE
644

645
  // Get point to list of <source> elements and make sure there is at least one
646
  for (pugi::xml_node node : root.children("source")) {
16,008✔
647
    model::external_sources.push_back(Source::create(node));
15,474✔
648
  }
649

650
  // Check if the user has specified to read surface source
651
  if (check_for_node(root, "surf_source_read")) {
8,266✔
652
    surf_source_read = true;
30✔
653
    // Get surface source read node
654
    xml_node node_ssr = root.child("surf_source_read");
30✔
655

656
    std::string path = "surface_source.h5";
30✔
657
    // Check if the user has specified different file for surface source reading
658
    if (check_for_node(node_ssr, "path")) {
30!
659
      path = get_node_value(node_ssr, "path", false, true);
30✔
660
    }
661
    model::external_sources.push_back(make_unique<FileSource>(path));
30✔
662
  }
30✔
663

664
  // If no source specified, default to isotropic point source at origin with
665
  // Watt spectrum. No default source is needed in random ray mode.
666
  if (model::external_sources.empty() &&
8,266✔
667
      settings::solver_type != SolverType::RANDOM_RAY) {
2,227✔
668
    double T[] {0.0};
2,081✔
669
    double p[] {1.0};
2,081✔
670
    model::external_sources.push_back(make_unique<IndependentSource>(
2,081✔
671
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
4,162✔
672
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
4,162✔
673
      UPtrDist {new Discrete(T, p, 1)}));
4,162✔
674
  }
675

676
  // Build probability mass function for sampling external sources
677
  vector<double> source_strengths;
8,266✔
678
  for (auto& s : model::external_sources) {
18,109✔
679
    source_strengths.push_back(s->strength());
9,843✔
680
  }
681
  model::external_sources_probability.assign(source_strengths);
8,266✔
682

683
  // Check if we want to write out source
684
  if (check_for_node(root, "write_initial_source")) {
8,266!
685
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
686
  }
687

688
  // Get relative number of lost particles
689
  if (check_for_node(root, "source_rejection_fraction")) {
8,266✔
690
    source_rejection_fraction =
14✔
691
      std::stod(get_node_value(root, "source_rejection_fraction"));
14!
692
  }
693

694
  if (check_for_node(root, "free_gas_threshold")) {
8,266!
695
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
696
  }
697

698
  // Surface grazing
699
  if (check_for_node(root, "surface_grazing_cutoff"))
8,266!
700
    surface_grazing_cutoff =
×
701
      std::stod(get_node_value(root, "surface_grazing_cutoff"));
×
702
  if (check_for_node(root, "surface_grazing_ratio"))
8,266!
703
    surface_grazing_ratio =
×
704
      std::stod(get_node_value(root, "surface_grazing_ratio"));
×
705

706
  // Survival biasing
707
  if (check_for_node(root, "survival_biasing")) {
8,266✔
708
    survival_biasing = get_node_value_bool(root, "survival_biasing");
190✔
709
  }
710

711
  // Probability tables
712
  if (check_for_node(root, "ptables")) {
8,266✔
713
    urr_ptables_on = get_node_value_bool(root, "ptables");
15✔
714
  }
715

716
  // Cutoffs
717
  if (check_for_node(root, "cutoff")) {
8,266✔
718
    xml_node node_cutoff = root.child("cutoff");
138✔
719
    if (check_for_node(node_cutoff, "weight")) {
138✔
720
      weight_cutoff = std::stod(get_node_value(node_cutoff, "weight"));
30✔
721
    }
722
    if (check_for_node(node_cutoff, "weight_avg")) {
138✔
723
      weight_survive = std::stod(get_node_value(node_cutoff, "weight_avg"));
30✔
724
    }
725
    if (check_for_node(node_cutoff, "survival_normalization")) {
138!
726
      survival_normalization =
×
727
        get_node_value_bool(node_cutoff, "survival_normalization");
×
728
    }
729
    if (check_for_node(node_cutoff, "energy_neutron")) {
138✔
730
      energy_cutoff[0] =
15✔
731
        std::stod(get_node_value(node_cutoff, "energy_neutron"));
30✔
732
    } else if (check_for_node(node_cutoff, "energy")) {
123!
733
      warning("The use of an <energy> cutoff is deprecated and should "
×
734
              "be replaced by <energy_neutron>.");
735
      energy_cutoff[0] = std::stod(get_node_value(node_cutoff, "energy"));
×
736
    }
737
    if (check_for_node(node_cutoff, "energy_photon")) {
138✔
738
      energy_cutoff[1] =
82✔
739
        std::stod(get_node_value(node_cutoff, "energy_photon"));
164✔
740
    }
741
    if (check_for_node(node_cutoff, "energy_electron")) {
138!
742
      energy_cutoff[2] =
×
743
        std::stof(get_node_value(node_cutoff, "energy_electron"));
×
744
    }
745
    if (check_for_node(node_cutoff, "energy_positron")) {
138!
746
      energy_cutoff[3] =
×
747
        std::stod(get_node_value(node_cutoff, "energy_positron"));
×
748
    }
749
    if (check_for_node(node_cutoff, "time_neutron")) {
138✔
750
      time_cutoff[0] = std::stod(get_node_value(node_cutoff, "time_neutron"));
26✔
751
    }
752
    if (check_for_node(node_cutoff, "time_photon")) {
138!
753
      time_cutoff[1] = std::stod(get_node_value(node_cutoff, "time_photon"));
×
754
    }
755
    if (check_for_node(node_cutoff, "time_electron")) {
138!
756
      time_cutoff[2] = std::stod(get_node_value(node_cutoff, "time_electron"));
×
757
    }
758
    if (check_for_node(node_cutoff, "time_positron")) {
138!
759
      time_cutoff[3] = std::stod(get_node_value(node_cutoff, "time_positron"));
×
760
    }
761
  }
762

763
  // read properties from file
764
  if (check_for_node(root, "properties_file")) {
8,266✔
765
    properties_file = get_node_value(root, "properties_file");
11✔
766
    if (!file_exists(properties_file)) {
11!
767
      fatal_error(fmt::format("File '{}' does not exist.", properties_file));
×
768
    }
769
  }
770

771
  // Particle trace
772
  if (check_for_node(root, "trace")) {
8,266✔
773
    auto temp = get_node_array<int64_t>(root, "trace");
15✔
774
    if (temp.size() != 3) {
15!
775
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
776
                  "batch, generation, and particle number.");
777
    }
778
    trace_batch = temp.at(0);
15✔
779
    trace_gen = temp.at(1);
15✔
780
    trace_particle = temp.at(2);
15✔
781
  }
15✔
782

783
  // Particle tracks
784
  if (check_for_node(root, "track")) {
8,266✔
785
    // Get values and make sure there are three per particle
786
    auto temp = get_node_array<int>(root, "track");
45✔
787
    if (temp.size() % 3 != 0) {
45!
788
      fatal_error(
×
789
        "Number of integers specified in 'track' is not "
790
        "divisible by 3.  Please provide 3 integers per particle to be "
791
        "tracked.");
792
    }
793

794
    // Reshape into track_identifiers
795
    int n_tracks = temp.size() / 3;
45✔
796
    for (int i = 0; i < n_tracks; ++i) {
180✔
797
      track_identifiers.push_back(
135✔
798
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
135✔
799
    }
800
  }
45✔
801

802
  // Shannon entropy
803
  if (solver_type == SolverType::RANDOM_RAY) {
8,266✔
804
    if (check_for_node(root, "entropy_mesh")) {
792!
805
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
806
                  "No user-defined entropy mesh is supported.");
807
    }
808
    entropy_on = true;
792✔
809
  } else if (solver_type == SolverType::MONTE_CARLO) {
7,474!
810
    if (check_for_node(root, "entropy_mesh")) {
7,474✔
811
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
668✔
812
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
334!
813
        fatal_error(fmt::format(
×
814
          "Mesh {} specified for Shannon entropy does not exist.", temp));
815
      }
816

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

823
      // Turn on Shannon entropy calculation
824
      entropy_on = true;
334✔
825

826
    } else if (check_for_node(root, "entropy")) {
7,140!
827
      fatal_error(
×
828
        "Specifying a Shannon entropy mesh via the <entropy> element "
829
        "is deprecated. Please create a mesh using <mesh> and then reference "
830
        "it by specifying its ID in an <entropy_mesh> element.");
831
    }
832
  }
833
  // Uniform fission source weighting mesh
834
  if (check_for_node(root, "ufs_mesh")) {
8,266✔
835
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
30✔
836
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
15!
837
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
838
                              "method does not exist.",
839
        temp));
840
    }
841

842
    auto* m =
15✔
843
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
15!
844
    if (!m)
15!
845
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
846
    simulation::ufs_mesh = m;
15✔
847

848
    // Turn on uniform fission source weighting
849
    ufs_on = true;
15✔
850

851
  } else if (check_for_node(root, "uniform_fs")) {
8,251!
852
    fatal_error(
×
853
      "Specifying a UFS mesh via the <uniform_fs> element "
854
      "is deprecated. Please create a mesh using <mesh> and then reference "
855
      "it by specifying its ID in a <ufs_mesh> element.");
856
  }
857

858
  // Check if the user has specified to write state points
859
  if (check_for_node(root, "state_point")) {
8,266✔
860

861
    // Get pointer to state_point node
862
    auto node_sp = root.child("state_point");
160✔
863

864
    // Determine number of batches at which to store state points
865
    if (check_for_node(node_sp, "batches")) {
160!
866
      // User gave specific batches to write state points
867
      auto temp = get_node_array<int>(node_sp, "batches");
160✔
868
      for (const auto& b : temp) {
491✔
869
        statepoint_batch.insert(b);
331✔
870
      }
871
    } else {
160✔
872
      // If neither were specified, write state point at last batch
873
      statepoint_batch.insert(n_batches);
×
874
    }
875
  } else {
876
    // If no <state_point> tag was present, by default write state point at
877
    // last batch only
878
    statepoint_batch.insert(n_batches);
8,106✔
879
  }
880

881
  // Check if the user has specified to write source points
882
  if (check_for_node(root, "source_point")) {
8,266✔
883
    // Get source_point node
884
    xml_node node_sp = root.child("source_point");
101✔
885

886
    // Determine batches at which to store source points
887
    if (check_for_node(node_sp, "batches")) {
101✔
888
      // User gave specific batches to write source points
889
      auto temp = get_node_array<int>(node_sp, "batches");
45✔
890
      for (const auto& b : temp) {
120✔
891
        sourcepoint_batch.insert(b);
75✔
892
      }
893
    } else {
45✔
894
      // If neither were specified, write source points with state points
895
      sourcepoint_batch = statepoint_batch;
56!
896
    }
897

898
    // Check if the user has specified to write binary source file
899
    if (check_for_node(node_sp, "separate")) {
101✔
900
      source_separate = get_node_value_bool(node_sp, "separate");
71✔
901
    }
902
    if (check_for_node(node_sp, "write")) {
101!
903
      source_write = get_node_value_bool(node_sp, "write");
×
904
    }
905
    if (check_for_node(node_sp, "mcpl")) {
101✔
906
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
26✔
907
    }
908
    if (check_for_node(node_sp, "overwrite_latest")) {
101✔
909
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
15✔
910
      source_separate = source_latest;
15✔
911
    }
912
  } else {
913
    // If no <source_point> tag was present, by default we keep source bank in
914
    // statepoint file and write it out at statepoints intervals
915
    source_separate = false;
8,165✔
916
    sourcepoint_batch = statepoint_batch;
8,165!
917
  }
918

919
  // Check is the user specified to convert strength to statistical weight
920
  if (check_for_node(root, "uniform_source_sampling")) {
8,266✔
921
    uniform_source_sampling =
55✔
922
      get_node_value_bool(root, "uniform_source_sampling");
55✔
923
  }
924

925
  // Check if the user has specified to write surface source
926
  if (check_for_node(root, "surf_source_write")) {
8,266✔
927
    surf_source_write = true;
412✔
928
    // Get surface source write node
929
    xml_node node_ssw = root.child("surf_source_write");
412✔
930

931
    // Determine surface ids at which crossing particles are to be banked.
932
    // If no surfaces are specified, all surfaces in the model will be used
933
    // to bank source points.
934
    if (check_for_node(node_ssw, "surface_ids")) {
412✔
935
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
202✔
936
      for (const auto& b : temp) {
994✔
937
        source_write_surf_id.insert(b);
792✔
938
      }
939
    }
202✔
940

941
    // Get maximum number of particles to be banked per surface
942
    if (check_for_node(node_ssw, "max_particles")) {
412✔
943
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
806✔
944
    } else {
945
      fatal_error("A maximum number of particles needs to be specified "
9✔
946
                  "using the 'max_particles' parameter to store surface "
947
                  "source points.");
948
    }
949

950
    // Get maximum number of surface source files to be created
951
    if (check_for_node(node_ssw, "max_source_files")) {
403✔
952
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
66✔
953
    } else {
954
      ssw_max_files = 1;
370✔
955
    }
956

957
    if (check_for_node(node_ssw, "mcpl")) {
403✔
958
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
11✔
959
    }
960
    // Get cell information
961
    if (check_for_node(node_ssw, "cell")) {
403✔
962
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
208✔
963
      ssw_cell_type = SSWCellType::Both;
104✔
964
    }
965
    if (check_for_node(node_ssw, "cellfrom")) {
403✔
966
      if (ssw_cell_id != C_NONE) {
90✔
967
        fatal_error(
18✔
968
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
969
      }
970
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
144✔
971
      ssw_cell_type = SSWCellType::From;
72✔
972
    }
973
    if (check_for_node(node_ssw, "cellto")) {
385✔
974
      if (ssw_cell_id != C_NONE) {
71✔
975
        fatal_error(
18✔
976
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
977
      }
978
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
106✔
979
      ssw_cell_type = SSWCellType::To;
53✔
980
    }
981
  }
982

983
  // Check if the user has specified to write specific collisions
984
  if (check_for_node(root, "collision_track")) {
8,221✔
985
    settings::collision_track = true;
148✔
986
    // Get collision track node
987
    xml_node node_ct = root.child("collision_track");
148✔
988
    collision_track_config = CollisionTrackConfig {};
148✔
989

990
    // Determine cell ids at which crossing particles are to be banked
991
    if (check_for_node(node_ct, "cell_ids")) {
148✔
992
      auto temp = get_node_array<int>(node_ct, "cell_ids");
78✔
993
      for (const auto& b : temp) {
204✔
994
        collision_track_config.cell_ids.insert(b);
126✔
995
      }
996
    }
78✔
997
    if (check_for_node(node_ct, "reactions")) {
148✔
998
      auto temp = get_node_array<std::string>(node_ct, "reactions");
63✔
999
      for (const auto& b : temp) {
171✔
1000
        int reaction_int = reaction_mt(b);
108✔
1001
        if (reaction_int > 0) {
108!
1002
          collision_track_config.mt_numbers.insert(reaction_int);
108✔
1003
        }
1004
      }
1005
    }
63✔
1006
    if (check_for_node(node_ct, "universe_ids")) {
148✔
1007
      auto temp = get_node_array<int>(node_ct, "universe_ids");
30✔
1008
      for (const auto& b : temp) {
60✔
1009
        collision_track_config.universe_ids.insert(b);
30✔
1010
      }
1011
    }
30✔
1012
    if (check_for_node(node_ct, "material_ids")) {
148✔
1013
      auto temp = get_node_array<int>(node_ct, "material_ids");
30✔
1014
      for (const auto& b : temp) {
75✔
1015
        collision_track_config.material_ids.insert(b);
45✔
1016
      }
1017
    }
30✔
1018
    if (check_for_node(node_ct, "nuclides")) {
148✔
1019
      auto temp = get_node_array<std::string>(node_ct, "nuclides");
30✔
1020
      for (const auto& b : temp) {
120✔
1021
        collision_track_config.nuclides.insert(b);
90✔
1022
      }
1023
    }
30✔
1024
    if (check_for_node(node_ct, "deposited_E_threshold")) {
148✔
1025
      collision_track_config.deposited_energy_threshold =
60✔
1026
        std::stod(get_node_value(node_ct, "deposited_E_threshold"));
60✔
1027
    }
1028
    // Get maximum number of particles to be banked per collision
1029
    if (check_for_node(node_ct, "max_collisions")) {
148!
1030
      collision_track_config.max_collisions =
296✔
1031
        std::stoll(get_node_value(node_ct, "max_collisions"));
296✔
1032
    } else {
1033
      warning("A maximum number of collisions needs to be specified. "
×
1034
              "By default the code sets 'max_collisions' parameter equals to "
1035
              "1000.");
1036
    }
1037
    // Get maximum number of collision_track files to be created
1038
    if (check_for_node(node_ct, "max_collision_track_files")) {
148!
1039
      collision_track_config.max_files =
×
1040
        std::stoll(get_node_value(node_ct, "max_collision_track_files"));
×
1041
    }
1042
    if (check_for_node(node_ct, "mcpl")) {
148✔
1043
      collision_track_config.mcpl_write = get_node_value_bool(node_ct, "mcpl");
22✔
1044
    }
1045
  }
1046

1047
  // If source is not separate and is to be written out in the statepoint
1048
  // file, make sure that the sourcepoint batch numbers are contained in the
1049
  // statepoint list
1050
  if (!source_separate) {
8,221✔
1051
    for (const auto& b : sourcepoint_batch) {
16,396✔
1052
      if (!contains(statepoint_batch, b)) {
16,522!
1053
        fatal_error(
×
1054
          "Sourcepoint batches are not a subset of statepoint batches.");
1055
      }
1056
    }
1057
  }
1058

1059
  // Check if the user has specified to not reduce tallies at the end of every
1060
  // batch
1061
  if (check_for_node(root, "no_reduce")) {
8,221✔
1062
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
30✔
1063
  }
1064

1065
  // Check if the user has specified to use confidence intervals for
1066
  // uncertainties rather than standard deviations
1067
  if (check_for_node(root, "confidence_intervals")) {
8,221✔
1068
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
15✔
1069
  }
1070

1071
  // Check for output options
1072
  if (check_for_node(root, "output")) {
8,221✔
1073
    // Get pointer to output node
1074
    pugi::xml_node node_output = root.child("output");
764✔
1075

1076
    // Check for summary option
1077
    if (check_for_node(node_output, "summary")) {
764✔
1078
      output_summary = get_node_value_bool(node_output, "summary");
738✔
1079
    }
1080

1081
    // Check for ASCII tallies output option
1082
    if (check_for_node(node_output, "tallies")) {
764✔
1083
      output_tallies = get_node_value_bool(node_output, "tallies");
349✔
1084
    }
1085

1086
    // Set output directory if a path has been specified
1087
    if (check_for_node(node_output, "path")) {
764!
1088
      path_output = get_node_value(node_output, "path");
×
1089
      if (!ends_with(path_output, "/")) {
×
1090
        path_output += "/";
764!
1091
      }
1092
    }
1093
  }
1094

1095
  // Resonance scattering parameters
1096
  if (check_for_node(root, "resonance_scattering")) {
8,221✔
1097
    xml_node node_res_scat = root.child("resonance_scattering");
15✔
1098

1099
    // See if resonance scattering is enabled
1100
    if (check_for_node(node_res_scat, "enable")) {
15!
1101
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
15✔
1102
    } else {
1103
      res_scat_on = true;
×
1104
    }
1105

1106
    // Determine what method is used
1107
    if (check_for_node(node_res_scat, "method")) {
15!
1108
      auto temp = get_node_value(node_res_scat, "method", true, true);
15✔
1109
      if (temp == "rvs") {
15!
1110
        res_scat_method = ResScatMethod::rvs;
15✔
1111
      } else if (temp == "dbrc") {
×
1112
        res_scat_method = ResScatMethod::dbrc;
×
1113
      } else {
1114
        fatal_error(
×
1115
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
1116
      }
1117
    }
15✔
1118

1119
    // Minimum energy for resonance scattering
1120
    if (check_for_node(node_res_scat, "energy_min")) {
15!
1121
      res_scat_energy_min =
30✔
1122
        std::stod(get_node_value(node_res_scat, "energy_min"));
30✔
1123
    }
1124
    if (res_scat_energy_min < 0.0) {
15!
1125
      fatal_error("Lower resonance scattering energy bound is negative");
×
1126
    }
1127

1128
    // Maximum energy for resonance scattering
1129
    if (check_for_node(node_res_scat, "energy_max")) {
15!
1130
      res_scat_energy_max =
30✔
1131
        std::stod(get_node_value(node_res_scat, "energy_max"));
30✔
1132
    }
1133
    if (res_scat_energy_max < res_scat_energy_min) {
15!
1134
      fatal_error("Upper resonance scattering energy bound is below the "
×
1135
                  "lower resonance scattering energy bound.");
1136
    }
1137

1138
    // Get resonance scattering nuclides
1139
    if (check_for_node(node_res_scat, "nuclides")) {
15!
1140
      res_scat_nuclides =
15✔
1141
        get_node_array<std::string>(node_res_scat, "nuclides");
30✔
1142
    }
1143
  }
1144

1145
  // Get volume calculations
1146
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
8,535✔
1147
    model::volume_calcs.emplace_back(node_vol);
314✔
1148
  }
1149

1150
  // Get temperature settings
1151
  if (check_for_node(root, "temperature_default")) {
8,221✔
1152
    temperature_default =
342✔
1153
      std::stod(get_node_value(root, "temperature_default"));
342✔
1154
  }
1155
  if (check_for_node(root, "temperature_method")) {
8,221✔
1156
    auto temp = get_node_value(root, "temperature_method", true, true);
485✔
1157
    if (temp == "nearest") {
485✔
1158
      temperature_method = TemperatureMethod::NEAREST;
304✔
1159
    } else if (temp == "interpolation") {
181!
1160
      temperature_method = TemperatureMethod::INTERPOLATION;
181✔
1161
    } else {
1162
      fatal_error("Unknown temperature method: " + temp);
×
1163
    }
1164
  }
485✔
1165
  if (check_for_node(root, "temperature_tolerance")) {
8,221✔
1166
    temperature_tolerance =
680✔
1167
      std::stod(get_node_value(root, "temperature_tolerance"));
680✔
1168
  }
1169
  if (check_for_node(root, "temperature_multipole")) {
8,221✔
1170
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
185✔
1171

1172
    // Multipole currently doesn't work with photon transport
1173
    if (temperature_multipole && photon_transport) {
185!
1174
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1175
                  "photon transport.");
1176
    }
1177
  }
1178
  if (check_for_node(root, "temperature_range")) {
8,221✔
1179
    auto range = get_node_array<double>(root, "temperature_range");
170✔
1180
    temperature_range[0] = range.at(0);
170✔
1181
    temperature_range[1] = range.at(1);
170✔
1182
  }
170✔
1183

1184
  // Check for tabular_legendre options
1185
  if (check_for_node(root, "tabular_legendre")) {
8,221✔
1186
    // Get pointer to tabular_legendre node
1187
    xml_node node_tab_leg = root.child("tabular_legendre");
90✔
1188

1189
    // Check for enable option
1190
    if (check_for_node(node_tab_leg, "enable")) {
90!
1191
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
90✔
1192
    }
1193

1194
    // Check for the number of points
1195
    if (check_for_node(node_tab_leg, "num_points")) {
90!
1196
      legendre_to_tabular_points =
×
1197
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
1198
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
1199
        fatal_error(
×
1200
          "The 'num_points' subelement/attribute of the "
1201
          "<tabular_legendre> element must contain a value greater than 1");
1202
      }
1203
    }
1204
  }
1205

1206
  // Check whether create delayed neutrons in fission
1207
  if (check_for_node(root, "create_delayed_neutrons")) {
8,221!
1208
    create_delayed_neutrons =
×
1209
      get_node_value_bool(root, "create_delayed_neutrons");
×
1210
  }
1211

1212
  // Check whether create fission sites
1213
  if (run_mode == RunMode::FIXED_SOURCE) {
8,221✔
1214
    if (check_for_node(root, "create_fission_neutrons")) {
2,861✔
1215
      create_fission_neutrons =
280✔
1216
        get_node_value_bool(root, "create_fission_neutrons");
280✔
1217
    }
1218
  }
1219

1220
  // Check whether to scale fission photon yields
1221
  if (check_for_node(root, "delayed_photon_scaling")) {
8,221!
1222
    delayed_photon_scaling =
×
1223
      get_node_value_bool(root, "delayed_photon_scaling");
×
1224
  }
1225

1226
  // Check whether to use event-based parallelism
1227
  if (check_for_node(root, "event_based")) {
8,221!
1228
    event_based = get_node_value_bool(root, "event_based");
×
1229
  }
1230

1231
  // Check whether material cell offsets should be generated
1232
  if (check_for_node(root, "material_cell_offsets")) {
8,221!
1233
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1234
  }
1235

1236
  // Weight window information
1237
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
8,326✔
1238
    variance_reduction::weight_windows.emplace_back(
105✔
1239
      std::make_unique<WeightWindows>(node_ww));
210✔
1240
  }
1241

1242
  // Enable weight windows by default if one or more are present
1243
  if (variance_reduction::weight_windows.size() > 0)
8,221✔
1244
    settings::weight_windows_on = true;
79✔
1245

1246
  // read weight windows from file
1247
  if (check_for_node(root, "weight_windows_file")) {
8,221!
1248
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1249
  }
1250

1251
  // read settings for weight windows value, this will override
1252
  // the automatic setting even if weight windows are present
1253
  if (check_for_node(root, "weight_windows_on")) {
8,221✔
1254
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
38✔
1255
  }
1256

1257
  if (check_for_node(root, "max_secondaries")) {
8,221!
1258
    settings::max_secondaries =
×
1259
      std::stoi(get_node_value(root, "max_secondaries"));
×
1260
  }
1261

1262
  if (check_for_node(root, "max_history_splits")) {
8,221✔
1263
    settings::max_history_splits =
428✔
1264
      std::stoi(get_node_value(root, "max_history_splits"));
428✔
1265
  }
1266

1267
  if (check_for_node(root, "max_tracks")) {
8,221✔
1268
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
90✔
1269
  }
1270

1271
  // Create weight window generator objects
1272
  if (check_for_node(root, "weight_window_generators")) {
8,221✔
1273
    auto wwgs_node = root.child("weight_window_generators");
94✔
1274
    for (pugi::xml_node node_wwg :
188✔
1275
      wwgs_node.children("weight_windows_generator")) {
188✔
1276
      variance_reduction::weight_windows_generators.emplace_back(
94✔
1277
        std::make_unique<WeightWindowsGenerator>(node_wwg));
188✔
1278
    }
1279
    // if any of the weight windows are intended to be generated otf, make
1280
    // sure they're applied
1281
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
94!
1282
      if (wwg->on_the_fly_) {
94!
1283
        settings::weight_windows_on = true;
94✔
1284
        break;
94✔
1285
      }
1286
    }
1287
    // If any weight window generators have local FW-CADIS target tallies,
1288
    // user-defined adjoint sources cannot be used at the same time.
1289
    if (!model::adjoint_sources.empty()) {
94!
NEW
1290
      for (const auto& wwg : variance_reduction::weight_windows_generators) {
×
NEW
1291
        if (!wwg->targets_.empty()) {
×
NEW
1292
          fatal_error("Cannot use both user-defined adjoint sources and "
×
1293
                      "FW-CADIS target tallies at the same time.");
1294
        }
1295
      }
1296
    }
1297
  }
1298

1299
  // Set up weight window checkpoints
1300
  if (check_for_node(root, "weight_window_checkpoints")) {
8,221✔
1301
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
32✔
1302
    if (check_for_node(ww_checkpoints, "collision")) {
32!
1303
      weight_window_checkpoint_collision =
32✔
1304
        get_node_value_bool(ww_checkpoints, "collision");
32✔
1305
    }
1306
    if (check_for_node(ww_checkpoints, "surface")) {
32!
1307
      weight_window_checkpoint_surface =
32✔
1308
        get_node_value_bool(ww_checkpoints, "surface");
32✔
1309
    }
1310
  }
1311

1312
  if (weight_windows_on) {
8,221✔
1313
    if (!weight_window_checkpoint_surface &&
173✔
1314
        !weight_window_checkpoint_collision)
141!
1315
      fatal_error(
×
1316
        "Weight Windows are enabled but there are no valid checkpoints.");
1317
  }
1318

1319
  if (check_for_node(root, "use_decay_photons")) {
8,221✔
1320
    settings::use_decay_photons =
11✔
1321
      get_node_value_bool(root, "use_decay_photons");
11✔
1322
  }
1323
}
8,221✔
1324

1325
void free_memory_settings()
8,372✔
1326
{
1327
  settings::statepoint_batch.clear();
8,372✔
1328
  settings::sourcepoint_batch.clear();
8,372✔
1329
  settings::source_write_surf_id.clear();
8,372✔
1330
  settings::res_scat_nuclides.clear();
8,372✔
1331
}
8,372✔
1332

1333
//==============================================================================
1334
// C API functions
1335
//==============================================================================
1336

1337
extern "C" int openmc_set_n_batches(
44✔
1338
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1339
{
1340
  if (settings::n_inactive >= n_batches) {
44✔
1341
    set_errmsg("Number of active batches must be greater than zero.");
11✔
1342
    return OPENMC_E_INVALID_ARGUMENT;
11✔
1343
  }
1344

1345
  if (!settings::trigger_on) {
33✔
1346
    // Set n_batches and n_max_batches to same value
1347
    settings::n_batches = n_batches;
11✔
1348
    settings::n_max_batches = n_batches;
11✔
1349
  } else {
1350
    // Set n_batches and n_max_batches based on value of set_max_batches
1351
    if (set_max_batches) {
22✔
1352
      settings::n_max_batches = n_batches;
11✔
1353
    } else {
1354
      settings::n_batches = n_batches;
11✔
1355
    }
1356
  }
1357

1358
  // Update size of k_generation and entropy
1359
  int m = settings::n_max_batches * settings::gen_per_batch;
33✔
1360
  simulation::k_generation.reserve(m);
33✔
1361
  simulation::entropy.reserve(m);
33✔
1362

1363
  // Add value of n_batches to statepoint_batch
1364
  if (add_statepoint_batch &&
33✔
1365
      !(contains(settings::statepoint_batch, n_batches)))
22!
1366
    settings::statepoint_batch.insert(n_batches);
22✔
1367

1368
  return 0;
1369
}
1370

1371
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,530✔
1372
{
1373
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,530✔
1374

1375
  return 0;
2,530✔
1376
}
1377

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