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

openmc-dev / openmc / 21043561037

15 Jan 2026 07:23PM UTC coverage: 81.388% (-0.7%) from 82.044%
21043561037

Pull #3734

github

web-flow
Merge 5e79b7b6f into 179048b80
Pull Request #3734: Specify temperature from a field (structured mesh only)

16703 of 22995 branches covered (72.64%)

Branch coverage included in aggregate %.

156 of 179 new or added lines in 12 files covered. (87.15%)

843 existing lines in 36 files now uncovered.

54487 of 64475 relevant lines covered (84.51%)

27592585.27 hits per line

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

75.52
/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/field.h"
23
#include "openmc/file_utils.h"
24
#include "openmc/mcpl_interface.h"
25
#include "openmc/mesh.h"
26
#include "openmc/message_passing.h"
27
#include "openmc/output.h"
28
#include "openmc/plot.h"
29
#include "openmc/random_lcg.h"
30
#include "openmc/random_ray/random_ray.h"
31
#include "openmc/reaction.h"
32
#include "openmc/simulation.h"
33
#include "openmc/source.h"
34
#include "openmc/string_utils.h"
35
#include "openmc/tallies/trigger.h"
36
#include "openmc/volume_calc.h"
37
#include "openmc/weight_windows.h"
38
#include "openmc/xml_interface.h"
39

40
namespace openmc {
41

42
//==============================================================================
43
// Global variables
44
//==============================================================================
45

46
namespace settings {
47

48
// Default values for boolean flags
49
bool assume_separate {false};
50
bool check_overlaps {false};
51
bool collision_track {false};
52
bool cmfd_run {false};
53
bool confidence_intervals {false};
54
bool create_delayed_neutrons {true};
55
bool create_fission_neutrons {true};
56
bool delayed_photon_scaling {true};
57
bool entropy_on {false};
58
bool event_based {false};
59
bool ifp_on {false};
60
bool legendre_to_tabular {true};
61
bool material_cell_offsets {true};
62
bool output_summary {true};
63
bool output_tallies {true};
64
bool particle_restart_run {false};
65
bool photon_transport {false};
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_field_on {false};
80
bool temperature_multipole {false};
81
bool trigger_on {false};
82
bool trigger_predict {false};
83
bool uniform_source_sampling {false};
84
bool ufs_on {false};
85
bool urr_ptables_on {true};
86
bool use_decay_photons {false};
87
bool weight_windows_on {false};
88
bool weight_window_checkpoint_surface {false};
89
bool weight_window_checkpoint_collision {true};
90
bool write_all_tracks {false};
91
bool write_initial_source {false};
92

93
std::string path_cross_sections;
94
std::string path_input;
95
std::string path_output;
96
std::string path_particle_restart;
97
std::string path_sourcepoint;
98
std::string path_statepoint;
99
const char* path_statepoint_c {path_statepoint.c_str()};
100
std::string weight_windows_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
TemperatureMethod temperature_method {TemperatureMethod::NEAREST};
142
double temperature_tolerance {10.0};
143
double temperature_default {293.6};
144
array<double, 2> temperature_range {0.0, 0.0};
145
int trace_batch;
146
int trace_gen;
147
int64_t trace_particle;
148
vector<array<int, 3>> track_identifiers;
149
int trigger_batch_interval {1};
150
int verbosity {-1};
151
double weight_cutoff {0.25};
152
double weight_survive {1.0};
153

154
} // namespace settings
155

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

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

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

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

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

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

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

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

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

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

212
  // Get number of inactive batches
213
  if (run_mode == RunMode::EIGENVALUE ||
3,202✔
214
      solver_type == SolverType::RANDOM_RAY) {
1,194✔
215
    if (check_for_node(node_base, "inactive")) {
2,190✔
216
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
2,100✔
217
    }
218
    if (check_for_node(node_base, "generations_per_batch")) {
2,190✔
219
      gen_per_batch =
7✔
220
        std::stoi(get_node_value(node_base, "generations_per_batch"));
7✔
221
    }
222

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

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

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

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

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

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

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

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

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

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

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

416
  read_settings_xml(root);
600✔
417
}
607✔
418

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

598
  // Check for photon transport
599
  if (check_for_node(root, "photon_transport")) {
3,545✔
600
    photon_transport = get_node_value_bool(root, "photon_transport");
88✔
601

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

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

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

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

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

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

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

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

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

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

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

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

681
  // Survival biasing
682
  if (check_for_node(root, "survival_biasing")) {
3,542✔
683
    survival_biasing = get_node_value_bool(root, "survival_biasing");
79✔
684
  }
685

686
  // Probability tables
687
  if (check_for_node(root, "ptables")) {
3,542✔
688
    urr_ptables_on = get_node_value_bool(root, "ptables");
7✔
689
  }
690

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

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

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

761
    // Reshape into track_identifiers
762
    int n_tracks = temp.size() / 3;
21✔
763
    for (int i = 0; i < n_tracks; ++i) {
84✔
764
      track_identifiers.push_back(
63✔
765
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
63✔
766
    }
767
  }
21✔
768

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

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

790
      // Turn on Shannon entropy calculation
791
      entropy_on = true;
152✔
792

793
    } else if (check_for_node(root, "entropy")) {
3,096!
NEW
794
      fatal_error(
×
795
        "Specifying a Shannon entropy mesh via the <entropy> element "
796
        "is deprecated. Please create a mesh using <mesh> and then reference "
797
        "it by specifying its ID in an <entropy_mesh> element.");
798
    }
799
  }
800

801
  // Temperature field
802
  if (check_for_node(root, "temperature_field")) {
3,542✔
803
    temperature_field_on = true;
7✔
804

805
    // Get pointer to temperature_field node
806
    auto node_tf = root.child("temperature_field");
7✔
807

808
    // Mesh parameter
809
    Mesh* tf_mesh_ptr;
810
    if (check_for_node(node_tf, "mesh")) {
7!
811
      int temp = std::stoi(get_node_value(node_tf, "mesh"));
7✔
812
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
7!
NEW
813
        fatal_error(fmt::format(
×
814
          "Mesh {} specified for the temperature field does not exist.", temp));
815
      }
816
      tf_mesh_ptr = model::meshes[model::mesh_map.at(temp)].get();
7✔
817
    } else {
NEW
818
      fatal_error("A mesh should be given for the temperature field.");
×
819
    }
820

821
    // Values parameter
822
    vector<double> tf_values;
7✔
823
    if (check_for_node(node_tf, "values")) {
7!
824
      auto temp = get_node_array<double>(node_tf, "values");
7✔
825
      for (const auto& b : temp) {
63✔
826
        tf_values.push_back(b);
56✔
827
      }
828
    } else {
7✔
UNCOV
829
      fatal_error(
×
830
        "Temperature values should be given for the temperature field.");
831
    }
832

833
    // Instantiate the temperature field
834
    simulation::temperature_field = TemperatureField(tf_mesh_ptr, tf_values);
7✔
835
  }
7✔
836

837
  // Uniform fission source weighting mesh
838
  if (check_for_node(root, "ufs_mesh")) {
3,542✔
839
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
7✔
840
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
7!
841
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
842
                              "method does not exist.",
843
        temp));
844
    }
845

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

852
    // Turn on uniform fission source weighting
853
    ufs_on = true;
7✔
854

855
  } else if (check_for_node(root, "uniform_fs")) {
3,535!
856
    fatal_error(
×
857
      "Specifying a UFS mesh via the <uniform_fs> element "
858
      "is deprecated. Please create a mesh using <mesh> and then reference "
859
      "it by specifying its ID in a <ufs_mesh> element.");
860
  }
861

862
  // Check if the user has specified to write state points
863
  if (check_for_node(root, "state_point")) {
3,542✔
864

865
    // Get pointer to state_point node
866
    auto node_sp = root.child("state_point");
74✔
867

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

885
  // Check if the user has specified to write source points
886
  if (check_for_node(root, "source_point")) {
3,542✔
887
    // Get source_point node
888
    xml_node node_sp = root.child("source_point");
47✔
889

890
    // Determine batches at which to store source points
891
    if (check_for_node(node_sp, "batches")) {
47✔
892
      // User gave specific batches to write source points
893
      auto temp = get_node_array<int>(node_sp, "batches");
21✔
894
      for (const auto& b : temp) {
56✔
895
        sourcepoint_batch.insert(b);
35✔
896
      }
897
    } else {
21✔
898
      // If neither were specified, write source points with state points
899
      sourcepoint_batch = statepoint_batch;
26✔
900
    }
901

902
    // Check if the user has specified to write binary source file
903
    if (check_for_node(node_sp, "separate")) {
47✔
904
      source_separate = get_node_value_bool(node_sp, "separate");
33✔
905
    }
906
    if (check_for_node(node_sp, "write")) {
47!
907
      source_write = get_node_value_bool(node_sp, "write");
×
908
    }
909
    if (check_for_node(node_sp, "mcpl")) {
47✔
910
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
12✔
911
    }
912
    if (check_for_node(node_sp, "overwrite_latest")) {
47✔
913
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
7✔
914
      source_separate = source_latest;
7✔
915
    }
916
  } else {
917
    // If no <source_point> tag was present, by default we keep source bank in
918
    // statepoint file and write it out at statepoints intervals
919
    source_separate = false;
3,495✔
920
    sourcepoint_batch = statepoint_batch;
3,495✔
921
  }
922

923
  // Check is the user specified to convert strength to statistical weight
924
  if (check_for_node(root, "uniform_source_sampling")) {
3,542✔
925
    uniform_source_sampling =
25✔
926
      get_node_value_bool(root, "uniform_source_sampling");
25✔
927
  }
928

929
  // Check if the user has specified to write surface source
930
  if (check_for_node(root, "surf_source_write")) {
3,542✔
931
    surf_source_write = true;
185✔
932
    // Get surface source write node
933
    xml_node node_ssw = root.child("surf_source_write");
185✔
934

935
    // Determine surface ids at which crossing particles are to be banked.
936
    // If no surfaces are specified, all surfaces in the model will be used
937
    // to bank source points.
938
    if (check_for_node(node_ssw, "surface_ids")) {
185✔
939
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
95✔
940
      for (const auto& b : temp) {
475✔
941
        source_write_surf_id.insert(b);
380✔
942
      }
943
    }
95✔
944

945
    // Get maximum number of particles to be banked per surface
946
    if (check_for_node(node_ssw, "max_particles")) {
185✔
947
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
182✔
948
    } else {
949
      fatal_error("A maximum number of particles needs to be specified "
3✔
950
                  "using the 'max_particles' parameter to store surface "
951
                  "source points.");
952
    }
953

954
    // Get maximum number of surface source files to be created
955
    if (check_for_node(node_ssw, "max_source_files")) {
182✔
956
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
15✔
957
    } else {
958
      ssw_max_files = 1;
167✔
959
    }
960

961
    if (check_for_node(node_ssw, "mcpl")) {
182✔
962
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
5✔
963
    }
964
    // Get cell information
965
    if (check_for_node(node_ssw, "cell")) {
182✔
966
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
44✔
967
      ssw_cell_type = SSWCellType::Both;
44✔
968
    }
969
    if (check_for_node(node_ssw, "cellfrom")) {
182✔
970
      if (ssw_cell_id != C_NONE) {
39✔
971
        fatal_error(
6✔
972
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
973
      }
974
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
33✔
975
      ssw_cell_type = SSWCellType::From;
33✔
976
    }
977
    if (check_for_node(node_ssw, "cellto")) {
176✔
978
      if (ssw_cell_id != C_NONE) {
31✔
979
        fatal_error(
6✔
980
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
981
      }
982
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
25✔
983
      ssw_cell_type = SSWCellType::To;
25✔
984
    }
985
  }
986

987
  // Check if the user has specified to write specific collisions
988
  if (check_for_node(root, "collision_track")) {
3,527✔
989
    settings::collision_track = true;
69✔
990
    // Get collision track node
991
    xml_node node_ct = root.child("collision_track");
69✔
992
    collision_track_config = CollisionTrackConfig {};
69✔
993

994
    // Determine cell ids at which crossing particles are to be banked
995
    if (check_for_node(node_ct, "cell_ids")) {
69✔
996
      auto temp = get_node_array<int>(node_ct, "cell_ids");
36✔
997
      for (const auto& b : temp) {
94✔
998
        collision_track_config.cell_ids.insert(b);
58✔
999
      }
1000
    }
36✔
1001
    if (check_for_node(node_ct, "reactions")) {
69✔
1002
      auto temp = get_node_array<std::string>(node_ct, "reactions");
29✔
1003
      for (const auto& b : temp) {
79✔
1004
        int reaction_int = reaction_type(b);
50✔
1005
        if (reaction_int > 0) {
50!
1006
          collision_track_config.mt_numbers.insert(reaction_int);
50✔
1007
        }
1008
      }
1009
    }
29✔
1010
    if (check_for_node(node_ct, "universe_ids")) {
69✔
1011
      auto temp = get_node_array<int>(node_ct, "universe_ids");
14✔
1012
      for (const auto& b : temp) {
28✔
1013
        collision_track_config.universe_ids.insert(b);
14✔
1014
      }
1015
    }
14✔
1016
    if (check_for_node(node_ct, "material_ids")) {
69✔
1017
      auto temp = get_node_array<int>(node_ct, "material_ids");
14✔
1018
      for (const auto& b : temp) {
35✔
1019
        collision_track_config.material_ids.insert(b);
21✔
1020
      }
1021
    }
14✔
1022
    if (check_for_node(node_ct, "nuclides")) {
69✔
1023
      auto temp = get_node_array<std::string>(node_ct, "nuclides");
14✔
1024
      for (const auto& b : temp) {
56✔
1025
        collision_track_config.nuclides.insert(b);
42✔
1026
      }
1027
    }
14✔
1028
    if (check_for_node(node_ct, "deposited_E_threshold")) {
69✔
1029
      collision_track_config.deposited_energy_threshold =
14✔
1030
        std::stod(get_node_value(node_ct, "deposited_E_threshold"));
14✔
1031
    }
1032
    // Get maximum number of particles to be banked per collision
1033
    if (check_for_node(node_ct, "max_collisions")) {
69!
1034
      collision_track_config.max_collisions =
69✔
1035
        std::stoll(get_node_value(node_ct, "max_collisions"));
69✔
1036
    } else {
1037
      warning("A maximum number of collisions needs to be specified. "
×
1038
              "By default the code sets 'max_collisions' parameter equals to "
1039
              "1000.");
1040
    }
1041
    // Get maximum number of collision_track files to be created
1042
    if (check_for_node(node_ct, "max_collision_track_files")) {
69!
1043
      collision_track_config.max_files =
×
1044
        std::stoll(get_node_value(node_ct, "max_collision_track_files"));
×
1045
    }
1046
    if (check_for_node(node_ct, "mcpl")) {
69✔
1047
      collision_track_config.mcpl_write = get_node_value_bool(node_ct, "mcpl");
10✔
1048
    }
1049
  }
1050

1051
  // If source is not separate and is to be written out in the statepoint
1052
  // file, make sure that the sourcepoint batch numbers are contained in the
1053
  // statepoint list
1054
  if (!source_separate) {
3,527✔
1055
    for (const auto& b : sourcepoint_batch) {
7,032✔
1056
      if (!contains(statepoint_batch, b)) {
3,545!
1057
        fatal_error(
×
1058
          "Sourcepoint batches are not a subset of statepoint batches.");
1059
      }
1060
    }
1061
  }
1062

1063
  // Check if the user has specified to not reduce tallies at the end of every
1064
  // batch
1065
  if (check_for_node(root, "no_reduce")) {
3,527✔
1066
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
14✔
1067
  }
1068

1069
  // Check if the user has specified to use confidence intervals for
1070
  // uncertainties rather than standard deviations
1071
  if (check_for_node(root, "confidence_intervals")) {
3,527✔
1072
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
7✔
1073
  }
1074

1075
  // Check for output options
1076
  if (check_for_node(root, "output")) {
3,527✔
1077
    // Get pointer to output node
1078
    pugi::xml_node node_output = root.child("output");
268✔
1079

1080
    // Check for summary option
1081
    if (check_for_node(node_output, "summary")) {
268✔
1082
      output_summary = get_node_value_bool(node_output, "summary");
256✔
1083
    }
1084

1085
    // Check for ASCII tallies output option
1086
    if (check_for_node(node_output, "tallies")) {
268✔
1087
      output_tallies = get_node_value_bool(node_output, "tallies");
82✔
1088
    }
1089

1090
    // Set output directory if a path has been specified
1091
    if (check_for_node(node_output, "path")) {
268!
1092
      path_output = get_node_value(node_output, "path");
×
1093
      if (!ends_with(path_output, "/")) {
×
1094
        path_output += "/";
×
1095
      }
1096
    }
1097
  }
1098

1099
  // Resonance scattering parameters
1100
  if (check_for_node(root, "resonance_scattering")) {
3,527✔
1101
    xml_node node_res_scat = root.child("resonance_scattering");
7✔
1102

1103
    // See if resonance scattering is enabled
1104
    if (check_for_node(node_res_scat, "enable")) {
7!
1105
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
7✔
1106
    } else {
1107
      res_scat_on = true;
×
1108
    }
1109

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

1123
    // Minimum energy for resonance scattering
1124
    if (check_for_node(node_res_scat, "energy_min")) {
7!
1125
      res_scat_energy_min =
7✔
1126
        std::stod(get_node_value(node_res_scat, "energy_min"));
7✔
1127
    }
1128
    if (res_scat_energy_min < 0.0) {
7!
1129
      fatal_error("Lower resonance scattering energy bound is negative");
×
1130
    }
1131

1132
    // Maximum energy for resonance scattering
1133
    if (check_for_node(node_res_scat, "energy_max")) {
7!
1134
      res_scat_energy_max =
7✔
1135
        std::stod(get_node_value(node_res_scat, "energy_max"));
7✔
1136
    }
1137
    if (res_scat_energy_max < res_scat_energy_min) {
7!
1138
      fatal_error("Upper resonance scattering energy bound is below the "
×
1139
                  "lower resonance scattering energy bound.");
1140
    }
1141

1142
    // Get resonance scattering nuclides
1143
    if (check_for_node(node_res_scat, "nuclides")) {
7!
1144
      res_scat_nuclides =
1145
        get_node_array<std::string>(node_res_scat, "nuclides");
7✔
1146
    }
1147
  }
1148

1149
  // Get volume calculations
1150
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
3,660✔
1151
    model::volume_calcs.emplace_back(node_vol);
133✔
1152
  }
1153

1154
  // Get temperature settings
1155
  if (check_for_node(root, "temperature_default")) {
3,527✔
1156
    temperature_default =
77✔
1157
      std::stod(get_node_value(root, "temperature_default"));
77✔
1158
  }
1159
  if (check_for_node(root, "temperature_method")) {
3,527✔
1160
    auto temp = get_node_value(root, "temperature_method", true, true);
145✔
1161
    if (temp == "nearest") {
145✔
1162
      temperature_method = TemperatureMethod::NEAREST;
62✔
1163
    } else if (temp == "interpolation") {
83!
1164
      temperature_method = TemperatureMethod::INTERPOLATION;
83✔
1165
    } else {
1166
      fatal_error("Unknown temperature method: " + temp);
×
1167
    }
1168
  }
145✔
1169
  if (check_for_node(root, "temperature_tolerance")) {
3,527✔
1170
    temperature_tolerance =
84✔
1171
      std::stod(get_node_value(root, "temperature_tolerance"));
84✔
1172
  }
1173
  if (check_for_node(root, "temperature_multipole")) {
3,527✔
1174
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
21✔
1175

1176
    // Multipole currently doesn't work with photon transport
1177
    if (temperature_multipole && photon_transport) {
21!
1178
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1179
                  "photon transport.");
1180
    }
1181
  }
1182
  if (check_for_node(root, "temperature_range")) {
3,527!
1183
    auto range = get_node_array<double>(root, "temperature_range");
×
1184
    temperature_range[0] = range.at(0);
×
1185
    temperature_range[1] = range.at(1);
×
1186
  }
×
1187

1188
  // Check for tabular_legendre options
1189
  if (check_for_node(root, "tabular_legendre")) {
3,527✔
1190
    // Get pointer to tabular_legendre node
1191
    xml_node node_tab_leg = root.child("tabular_legendre");
42✔
1192

1193
    // Check for enable option
1194
    if (check_for_node(node_tab_leg, "enable")) {
42!
1195
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
42✔
1196
    }
1197

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

1210
  // Check whether create delayed neutrons in fission
1211
  if (check_for_node(root, "create_delayed_neutrons")) {
3,527!
1212
    create_delayed_neutrons =
×
1213
      get_node_value_bool(root, "create_delayed_neutrons");
×
1214
  }
1215

1216
  // Check whether create fission sites
1217
  if (run_mode == RunMode::FIXED_SOURCE) {
3,527✔
1218
    if (check_for_node(root, "create_fission_neutrons")) {
1,179✔
1219
      create_fission_neutrons =
67✔
1220
        get_node_value_bool(root, "create_fission_neutrons");
67✔
1221
    }
1222
  }
1223

1224
  // Check whether to scale fission photon yields
1225
  if (check_for_node(root, "delayed_photon_scaling")) {
3,527!
1226
    delayed_photon_scaling =
×
1227
      get_node_value_bool(root, "delayed_photon_scaling");
×
1228
  }
1229

1230
  // Check whether to use event-based parallelism
1231
  if (check_for_node(root, "event_based")) {
3,527!
NEW
1232
    event_based = get_node_value_bool(root, "event_based");
×
NEW
1233
    if (temperature_field_on && event_based) {
×
NEW
1234
      fatal_error(
×
1235
        "Event-based transport is not yet compatible with temperature fields.");
1236
    }
1237
  }
1238

1239
  // Check whether material cell offsets should be generated
1240
  if (check_for_node(root, "material_cell_offsets")) {
3,527!
1241
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1242
  }
1243

1244
  // Weight window information
1245
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
3,568✔
1246
    variance_reduction::weight_windows.emplace_back(
41✔
1247
      std::make_unique<WeightWindows>(node_ww));
82✔
1248
  }
1249

1250
  // Enable weight windows by default if one or more are present
1251
  if (variance_reduction::weight_windows.size() > 0)
3,527✔
1252
    settings::weight_windows_on = true;
29✔
1253

1254
  // read weight windows from file
1255
  if (check_for_node(root, "weight_windows_file")) {
3,527!
1256
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1257
  }
1258

1259
  // read settings for weight windows value, this will override
1260
  // the automatic setting even if weight windows are present
1261
  if (check_for_node(root, "weight_windows_on")) {
3,527✔
1262
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
17✔
1263
  }
1264

1265
  if (check_for_node(root, "max_secondaries")) {
3,527!
1266
    settings::max_secondaries =
×
1267
      std::stoi(get_node_value(root, "max_secondaries"));
×
1268
  }
1269

1270
  if (check_for_node(root, "max_history_splits")) {
3,527✔
1271
    settings::max_history_splits =
97✔
1272
      std::stoi(get_node_value(root, "max_history_splits"));
97✔
1273
  }
1274

1275
  if (check_for_node(root, "max_tracks")) {
3,527✔
1276
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
21✔
1277
  }
1278

1279
  // Create weight window generator objects
1280
  if (check_for_node(root, "weight_window_generators")) {
3,527✔
1281
    auto wwgs_node = root.child("weight_window_generators");
36✔
1282
    for (pugi::xml_node node_wwg :
36✔
1283
      wwgs_node.children("weight_windows_generator")) {
108✔
1284
      variance_reduction::weight_windows_generators.emplace_back(
36✔
1285
        std::make_unique<WeightWindowsGenerator>(node_wwg));
72✔
1286
    }
1287
    // if any of the weight windows are intended to be generated otf, make
1288
    // sure they're applied
1289
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
36!
1290
      if (wwg->on_the_fly_) {
36!
1291
        settings::weight_windows_on = true;
36✔
1292
        break;
36✔
1293
      }
1294
    }
1295
  }
1296

1297
  // Set up weight window checkpoints
1298
  if (check_for_node(root, "weight_window_checkpoints")) {
3,527!
UNCOV
1299
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
×
UNCOV
1300
    if (check_for_node(ww_checkpoints, "collision")) {
×
UNCOV
1301
      weight_window_checkpoint_collision =
×
UNCOV
1302
        get_node_value_bool(ww_checkpoints, "collision");
×
1303
    }
UNCOV
1304
    if (check_for_node(ww_checkpoints, "surface")) {
×
UNCOV
1305
      weight_window_checkpoint_surface =
×
UNCOV
1306
        get_node_value_bool(ww_checkpoints, "surface");
×
1307
    }
1308
  }
1309

1310
  if (check_for_node(root, "use_decay_photons")) {
3,527✔
1311
    settings::use_decay_photons =
5✔
1312
      get_node_value_bool(root, "use_decay_photons");
5✔
1313
  }
1314
}
3,527✔
1315

1316
void free_memory_settings()
3,594✔
1317
{
1318
  settings::statepoint_batch.clear();
3,594✔
1319
  settings::sourcepoint_batch.clear();
3,594✔
1320
  settings::source_write_surf_id.clear();
3,594✔
1321
  settings::res_scat_nuclides.clear();
3,594✔
1322
}
3,594✔
1323

1324
//==============================================================================
1325
// C API functions
1326
//==============================================================================
1327

1328
extern "C" int openmc_set_n_batches(
20✔
1329
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1330
{
1331
  if (settings::n_inactive >= n_batches) {
20✔
1332
    set_errmsg("Number of active batches must be greater than zero.");
5✔
1333
    return OPENMC_E_INVALID_ARGUMENT;
5✔
1334
  }
1335

1336
  if (!settings::trigger_on) {
15✔
1337
    // Set n_batches and n_max_batches to same value
1338
    settings::n_batches = n_batches;
5✔
1339
    settings::n_max_batches = n_batches;
5✔
1340
  } else {
1341
    // Set n_batches and n_max_batches based on value of set_max_batches
1342
    if (set_max_batches) {
10✔
1343
      settings::n_max_batches = n_batches;
5✔
1344
    } else {
1345
      settings::n_batches = n_batches;
5✔
1346
    }
1347
  }
1348

1349
  // Update size of k_generation and entropy
1350
  int m = settings::n_max_batches * settings::gen_per_batch;
15✔
1351
  simulation::k_generation.reserve(m);
15✔
1352
  simulation::entropy.reserve(m);
15✔
1353

1354
  // Add value of n_batches to statepoint_batch
1355
  if (add_statepoint_batch &&
25✔
1356
      !(contains(settings::statepoint_batch, n_batches)))
10!
1357
    settings::statepoint_batch.insert(n_batches);
10✔
1358

1359
  return 0;
15✔
1360
}
1361

1362
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
1,150✔
1363
{
1364
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
1,150✔
1365

1366
  return 0;
1,150✔
1367
}
1368

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