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

openmc-dev / openmc / 29167401541

11 Jul 2026 08:38PM UTC coverage: 80.762% (-0.5%) from 81.295%
29167401541

Pull #4010

github

web-flow
Merge 612540872 into e783e0147
Pull Request #4010: Implementation of surfaces with custom implicit function

18489 of 27369 branches covered (67.55%)

Branch coverage included in aggregate %.

1041 of 1330 new or added lines in 13 files covered. (78.27%)

76 existing lines in 3 files now uncovered.

60486 of 70418 relevant lines covered (85.9%)

53343422.58 hits per line

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

73.99
/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 use_shared_secondary_bank {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
std::string properties_file;
102

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

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

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

157
// implicit surface
158
int implicit_maxiter {1000000};
159
std::string implicit_solver {"fast"};
160
double implicit_atol {1.e-9};
161
double implicit_ftol {1.e-9};
162
double implicit_margin {1.e-6};
163

164
} // namespace settings
165

166
//==============================================================================
167
// Functions
168
//==============================================================================
169

170
void get_run_parameters(pugi::xml_node node_base)
8,112✔
171
{
172
  using namespace settings;
8,112✔
173
  using namespace pugi;
8,112✔
174

175
  // Check number of particles
176
  if (!check_for_node(node_base, "particles")) {
8,112!
177
    fatal_error("Need to specify number of particles.");
×
178
  }
179

180
  // Get number of particles if it wasn't specified as a command-line argument
181
  if (n_particles == -1) {
8,112✔
182
    n_particles = std::stoll(get_node_value(node_base, "particles"));
8,101✔
183
  }
184

185
  // Get maximum number of in flight particles for event-based mode
186
  if (check_for_node(node_base, "max_particles_in_flight")) {
8,112!
187
    max_particles_in_flight =
×
188
      std::stoll(get_node_value(node_base, "max_particles_in_flight"));
×
189
  }
190

191
  // Get maximum number of events allowed per particle
192
  if (check_for_node(node_base, "max_particle_events")) {
8,112!
193
    max_particle_events =
×
194
      std::stoll(get_node_value(node_base, "max_particle_events"));
×
195
  }
196

197
  // Get number of basic batches
198
  if (check_for_node(node_base, "batches")) {
8,112!
199
    n_batches = std::stoi(get_node_value(node_base, "batches"));
8,112✔
200
  }
201
  if (!trigger_on)
8,112✔
202
    n_max_batches = n_batches;
7,971✔
203

204
  // Get max number of lost particles
205
  if (check_for_node(node_base, "max_lost_particles")) {
8,112✔
206
    max_lost_particles =
92✔
207
      std::stoi(get_node_value(node_base, "max_lost_particles"));
46✔
208
  }
209

210
  // Get relative number of lost particles
211
  if (check_for_node(node_base, "rel_max_lost_particles")) {
8,112!
212
    rel_max_lost_particles =
×
213
      std::stod(get_node_value(node_base, "rel_max_lost_particles"));
×
214
  }
215

216
  // Get relative number of lost particles
217
  if (check_for_node(node_base, "max_write_lost_particles")) {
8,112✔
218
    max_write_lost_particles =
30✔
219
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
15✔
220
  }
221

222
  // Get number of inactive batches
223
  if (run_mode == RunMode::EIGENVALUE ||
8,112✔
224
      solver_type == SolverType::RANDOM_RAY) {
3,313✔
225
    if (check_for_node(node_base, "inactive")) {
5,235✔
226
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,980✔
227
    }
228
    if (check_for_node(node_base, "generations_per_batch")) {
5,235✔
229
      gen_per_batch =
30✔
230
        std::stoi(get_node_value(node_base, "generations_per_batch"));
15✔
231
    }
232

233
    // Preallocate space for keff and entropy by generation
234
    int m = settings::n_max_batches * settings::gen_per_batch;
5,235✔
235
    simulation::k_generation.reserve(m);
5,235✔
236
    simulation::entropy.reserve(m);
5,235✔
237

238
    // Get the trigger information for keff
239
    if (check_for_node(node_base, "keff_trigger")) {
5,235✔
240
      xml_node node_keff_trigger = node_base.child("keff_trigger");
101✔
241

242
      if (check_for_node(node_keff_trigger, "type")) {
101!
243
        auto temp = get_node_value(node_keff_trigger, "type", true, true);
101✔
244
        if (temp == "std_dev") {
101!
245
          keff_trigger.metric = TriggerMetric::standard_deviation;
101✔
246
        } else if (temp == "variance") {
×
247
          keff_trigger.metric = TriggerMetric::variance;
×
248
        } else if (temp == "rel_err") {
×
249
          keff_trigger.metric = TriggerMetric::relative_error;
×
250
        } else {
251
          fatal_error("Unrecognized keff trigger type " + temp);
×
252
        }
253
      } else {
×
254
        fatal_error("Specify keff trigger type in settings XML");
×
255
      }
256

257
      if (check_for_node(node_keff_trigger, "threshold")) {
101!
258
        keff_trigger.threshold =
202✔
259
          std::stod(get_node_value(node_keff_trigger, "threshold"));
202✔
260
        if (keff_trigger.threshold <= 0) {
101!
261
          fatal_error("keff trigger threshold must be positive");
×
262
        }
263
      } else {
264
        fatal_error("Specify keff trigger threshold in settings XML");
×
265
      }
266
    }
267
  }
268

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

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

410
  // Parse settings.xml file
411
  xml_document doc;
1,387✔
412
  auto result = doc.load_file(filename.c_str());
1,387✔
413
  if (!result) {
1,387!
414
    fatal_error("Error processing settings.xml file.");
×
415
  }
416

417
  // Get root element
418
  xml_node root = doc.document_element();
1,387✔
419

420
  // Verbosity
421
  if (check_for_node(root, "verbosity") && verbosity == -1) {
1,387!
422
    verbosity = std::stoi(get_node_value(root, "verbosity"));
428✔
423
  } else if (verbosity == -1) {
1,173!
424
    verbosity = 7;
1,173✔
425
  }
426

427
  // To this point, we haven't displayed any output since we didn't know what
428
  // the verbosity is. Now that we checked for it, show the title if necessary
429
  if (mpi::master) {
1,387✔
430
    if (verbosity >= 2)
1,199✔
431
      title();
993✔
432
  }
433

434
  write_message("Reading settings XML file...", 5);
1,387✔
435

436
  read_settings_xml(root);
1,387✔
437
}
1,399✔
438

439
void read_settings_xml(pugi::xml_node root)
9,063✔
440
{
441
  using namespace settings;
9,063✔
442
  using namespace pugi;
9,063✔
443

444
  // Find if a multi-group or continuous-energy simulation is desired
445
  if (check_for_node(root, "energy_mode")) {
9,063✔
446
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
1,357✔
447
    if (temp_str == "mg" || temp_str == "multi-group") {
2,714!
448
      run_CE = false;
1,357✔
449
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
450
      run_CE = true;
×
451
    }
452
  }
1,357✔
453

454
  // Check for user meshes and allocate
455
  read_meshes(root);
9,063✔
456

457
  // Look for deprecated cross_sections.xml file in settings.xml
458
  if (check_for_node(root, "cross_sections")) {
9,063!
459
    warning(
×
460
      "Setting cross_sections in settings.xml has been deprecated."
461
      " The cross_sections are now set in materials.xml and the "
462
      "cross_sections input to materials.xml and the OPENMC_CROSS_SECTIONS"
463
      " environment variable will take precendent over setting "
464
      "cross_sections in settings.xml.");
465
    path_cross_sections = get_node_value(root, "cross_sections");
×
466
  }
467

468
  if (!run_CE) {
9,063✔
469
    // Scattering Treatments
470
    if (check_for_node(root, "max_order")) {
1,357✔
471
      max_order = std::stoi(get_node_value(root, "max_order"));
30✔
472
    } else {
473
      // Set to default of largest int - 1, which means to use whatever is
474
      // contained in library. This is largest int - 1 because for legendre
475
      // scattering, a value of 1 is added to the order; adding 1 to the largest
476
      // int gets you the largest negative integer, which is not what we want.
477
      max_order = std::numeric_limits<int>::max() - 1;
1,342✔
478
    }
479
  }
480

481
  // Check for a trigger node and get trigger information
482
  if (check_for_node(root, "trigger")) {
9,063✔
483
    xml_node node_trigger = root.child("trigger");
156✔
484

485
    // Check if trigger(s) are to be turned on
486
    trigger_on = get_node_value_bool(node_trigger, "active");
156✔
487

488
    if (trigger_on) {
156✔
489
      if (check_for_node(node_trigger, "max_batches")) {
141!
490
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
282✔
491
      } else {
492
        fatal_error("<max_batches> must be specified with triggers");
×
493
      }
494

495
      // Get the batch interval to check triggers
496
      if (!check_for_node(node_trigger, "batch_interval")) {
141✔
497
        trigger_predict = true;
15✔
498
      } else {
499
        trigger_batch_interval =
252✔
500
          std::stoi(get_node_value(node_trigger, "batch_interval"));
252✔
501
        if (trigger_batch_interval <= 0) {
126!
502
          fatal_error("Trigger batch interval must be greater than zero");
×
503
        }
504
      }
505
    }
506
  }
507

508
  // Check run mode if it hasn't been set from the command line
509
  xml_node node_mode;
9,063✔
510
  if (run_mode == RunMode::UNSET) {
9,063✔
511
    if (check_for_node(root, "run_mode")) {
8,144✔
512
      std::string temp_str = get_node_value(root, "run_mode", true, true);
8,114✔
513
      if (temp_str == "eigenvalue") {
8,114✔
514
        run_mode = RunMode::EIGENVALUE;
4,769✔
515
      } else if (temp_str == "fixed source") {
3,345✔
516
        run_mode = RunMode::FIXED_SOURCE;
3,313✔
517
      } else if (temp_str == "plot") {
32!
518
        run_mode = RunMode::PLOTTING;
×
519
      } else if (temp_str == "particle restart") {
32!
520
        run_mode = RunMode::PARTICLE;
×
521
      } else if (temp_str == "volume") {
32!
522
        run_mode = RunMode::VOLUME;
32✔
523
      } else {
524
        fatal_error("Unrecognized run mode: " + temp_str);
×
525
      }
526

527
      // Assume XML specifies <particles>, <batches>, etc. directly
528
      node_mode = root;
8,114✔
529
    } else {
8,114✔
530
      warning("<run_mode> should be specified.");
30✔
531

532
      // Make sure that either eigenvalue or fixed source was specified
533
      node_mode = root.child("eigenvalue");
30✔
534
      if (node_mode) {
30!
535
        run_mode = RunMode::EIGENVALUE;
30✔
536
      } else {
537
        node_mode = root.child("fixed_source");
×
538
        if (node_mode) {
×
539
          run_mode = RunMode::FIXED_SOURCE;
×
540
        } else {
541
          fatal_error("<eigenvalue> or <fixed_source> not specified.");
×
542
        }
543
      }
544
    }
545
  }
546

547
  // Check solver type
548
  if (check_for_node(root, "random_ray")) {
9,063✔
549
    solver_type = SolverType::RANDOM_RAY;
792✔
550
    if (run_CE)
792!
551
      fatal_error("multi-group energy mode must be specified in settings XML "
×
552
                  "when using the random ray solver.");
553
  }
554

555
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
9,063✔
556
    // Read run parameters
557
    get_run_parameters(node_mode);
8,112✔
558

559
    // Check number of active batches, inactive batches, max lost particles and
560
    // particles
561
    if (n_batches <= n_inactive) {
8,112!
562
      fatal_error("Number of active batches must be greater than zero.");
×
563
    } else if (n_inactive < 0) {
8,112!
564
      fatal_error("Number of inactive batches must be non-negative.");
×
565
    } else if (n_particles <= 0) {
8,112!
566
      fatal_error("Number of particles must be greater than zero.");
×
567
    } else if (max_lost_particles <= 0) {
8,112!
568
      fatal_error("Number of max lost particles must be greater than zero.");
×
569
    } else if (rel_max_lost_particles <= 0.0 || rel_max_lost_particles >= 1.0) {
8,112!
570
      fatal_error("Relative max lost particles must be between zero and one.");
×
571
    }
572

573
    // Check for user value for the number of generation of the Iterated Fission
574
    // Probability (IFP) method
575
    if (check_for_node(root, "ifp_n_generation")) {
8,112✔
576
      ifp_n_generation = std::stoi(get_node_value(root, "ifp_n_generation"));
166✔
577
      if (ifp_n_generation <= 0) {
83!
578
        fatal_error("'ifp_n_generation' must be greater than 0.");
×
579
      }
580
      // Avoid tallying 0 if IFP logs are not complete when active cycles start
581
      if (ifp_n_generation > n_inactive) {
83✔
582
        fatal_error("'ifp_n_generation' must be lower than or equal to the "
9✔
583
                    "number of inactive cycles.");
584
      }
585
    }
586
  }
587

588
  // Copy plotting random number seed if specified
589
  if (check_for_node(root, "plot_seed")) {
9,054!
590
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
591
    model::plotter_seed = seed;
×
592
  }
593

594
  // Copy random number seed if specified
595
  if (check_for_node(root, "seed")) {
9,054✔
596
    auto seed = std::stoll(get_node_value(root, "seed"));
1,178✔
597
    openmc_set_seed(seed);
589✔
598
  }
599

600
  // Copy random number stride if specified
601
  if (check_for_node(root, "stride")) {
9,054✔
602
    auto stride = std::stoull(get_node_value(root, "stride"));
30✔
603
    openmc_set_stride(stride);
15✔
604
  }
605

606
  // Check for electron treatment
607
  if (check_for_node(root, "electron_treatment")) {
9,054✔
608
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
82✔
609
    if (temp_str == "led") {
82✔
610
      electron_treatment = ElectronTreatment::LED;
26✔
611
    } else if (temp_str == "ttb") {
56!
612
      electron_treatment = ElectronTreatment::TTB;
56✔
613
    } else {
614
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
615
    }
616
  }
82✔
617

618
  // Check for photon transport
619
  if (check_for_node(root, "photon_transport")) {
9,054✔
620
    photon_transport = get_node_value_bool(root, "photon_transport");
416✔
621

622
    if (!run_CE && photon_transport) {
416!
623
      fatal_error("Photon transport is not currently supported in "
×
624
                  "multigroup mode");
625
    }
626
  }
627

628
  // Check for atomic relaxation
629
  if (check_for_node(root, "atomic_relaxation")) {
9,054✔
630
    atomic_relaxation = get_node_value_bool(root, "atomic_relaxation");
15✔
631
  }
632

633
  // Number of bins for logarithmic grid
634
  if (check_for_node(root, "log_grid_bins")) {
9,054✔
635
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
30✔
636
    if (n_log_bins < 1) {
15!
637
      fatal_error("Number of bins for logarithmic grid must be greater "
×
638
                  "than zero.");
639
    }
640
  }
641

642
  // Number of OpenMP threads
643
  if (check_for_node(root, "threads")) {
9,054!
644
    if (mpi::master)
×
645
      warning("The <threads> element has been deprecated. Use "
×
646
              "the OMP_NUM_THREADS environment variable to set the number of "
647
              "threads.");
648
  }
649

650
  // ==========================================================================
651
  // EXTERNAL SOURCE
652

653
  // Get point to list of <source> elements and make sure there is at least one
654
  for (pugi::xml_node node : root.children("source")) {
17,440✔
655
    model::external_sources.push_back(Source::create(node));
16,782✔
656
  }
657

658
  // Check if the user has specified to read surface source
659
  if (check_for_node(root, "surf_source_read")) {
9,044✔
660
    surf_source_read = true;
30✔
661
    // Get surface source read node
662
    xml_node node_ssr = root.child("surf_source_read");
30✔
663

664
    std::string path = "surface_source.h5";
30✔
665
    // Check if the user has specified different file for surface source reading
666
    if (check_for_node(node_ssr, "path")) {
30!
667
      path = get_node_value(node_ssr, "path", false, true);
30✔
668
    }
669
    model::external_sources.push_back(make_unique<FileSource>(path));
30✔
670
  }
30✔
671

672
  // If no source specified, default to isotropic point source at origin with
673
  // Watt spectrum. No default source is needed in random ray mode.
674
  if (model::external_sources.empty() &&
9,044✔
675
      settings::solver_type != SolverType::RANDOM_RAY) {
2,351✔
676
    double T[] {0.0};
2,205✔
677
    double p[] {1.0};
2,205✔
678
    model::external_sources.push_back(make_unique<IndependentSource>(
2,205✔
679
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
4,410✔
680
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
4,410✔
681
      UPtrDist {new Discrete(T, p, 1)}));
4,410✔
682
  }
683

684
  // Build probability mass function for sampling external sources
685
  vector<double> source_strengths;
9,044✔
686
  for (auto& s : model::external_sources) {
19,665✔
687
    source_strengths.push_back(s->strength());
10,621✔
688
  }
689
  model::external_sources_probability.assign(source_strengths);
9,044✔
690

691
  // Check if we want to write out source
692
  if (check_for_node(root, "write_initial_source")) {
9,044!
693
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
694
  }
695

696
  // Get relative number of lost particles
697
  if (check_for_node(root, "source_rejection_fraction")) {
9,044✔
698
    source_rejection_fraction =
14✔
699
      std::stod(get_node_value(root, "source_rejection_fraction"));
14!
700
  }
701

702
  if (check_for_node(root, "free_gas_threshold")) {
9,044!
703
    free_gas_threshold = std::stod(get_node_value(root, "free_gas_threshold"));
×
704
  }
705

706
  // Surface grazing
707
  if (check_for_node(root, "surface_grazing_cutoff"))
9,044!
708
    surface_grazing_cutoff =
×
709
      std::stod(get_node_value(root, "surface_grazing_cutoff"));
×
710
  if (check_for_node(root, "surface_grazing_ratio"))
9,044!
711
    surface_grazing_ratio =
×
712
      std::stod(get_node_value(root, "surface_grazing_ratio"));
×
713

714
  // Survival biasing
715
  if (check_for_node(root, "survival_biasing")) {
9,044✔
716
    survival_biasing = get_node_value_bool(root, "survival_biasing");
205✔
717
  }
718

719
  // Probability tables
720
  if (check_for_node(root, "ptables")) {
9,044✔
721
    urr_ptables_on = get_node_value_bool(root, "ptables");
15✔
722
  }
723

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

771
  // read properties from file
772
  if (check_for_node(root, "properties_file")) {
9,044✔
773
    properties_file = get_node_value(root, "properties_file");
11✔
774
    if (!file_exists(properties_file)) {
11!
775
      fatal_error(fmt::format("File '{}' does not exist.", properties_file));
×
776
    }
777
  }
778

779
  // Particle trace
780
  if (check_for_node(root, "trace")) {
9,044✔
781
    auto temp = get_node_array<int64_t>(root, "trace");
15✔
782
    if (temp.size() != 3) {
15!
783
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
784
                  "batch, generation, and particle number.");
785
    }
786
    trace_batch = temp.at(0);
15✔
787
    trace_gen = temp.at(1);
15✔
788
    trace_particle = temp.at(2);
15✔
789
  }
15✔
790

791
  // Particle tracks
792
  if (check_for_node(root, "track")) {
9,044✔
793
    // Get values and make sure there are three per particle
794
    auto temp = get_node_array<int>(root, "track");
45✔
795
    if (temp.size() % 3 != 0) {
45!
796
      fatal_error(
×
797
        "Number of integers specified in 'track' is not "
798
        "divisible by 3.  Please provide 3 integers per particle to be "
799
        "tracked.");
800
    }
801

802
    // Reshape into track_identifiers
803
    int n_tracks = temp.size() / 3;
45✔
804
    for (int i = 0; i < n_tracks; ++i) {
180✔
805
      track_identifiers.push_back(
135✔
806
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
135✔
807
    }
808
  }
45✔
809

810
  // Shannon entropy
811
  if (solver_type == SolverType::RANDOM_RAY) {
9,044✔
812
    if (check_for_node(root, "entropy_mesh")) {
792!
813
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
814
                  "No user-defined entropy mesh is supported.");
815
    }
816
    entropy_on = true;
792✔
817
  } else if (solver_type == SolverType::MONTE_CARLO) {
8,252!
818
    if (check_for_node(root, "entropy_mesh")) {
8,252✔
819
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
668✔
820
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
334!
821
        fatal_error(fmt::format(
×
822
          "Mesh {} specified for Shannon entropy does not exist.", temp));
823
      }
824

825
      auto* m = dynamic_cast<RegularMesh*>(
334!
826
        model::meshes[model::mesh_map.at(temp)].get());
334!
827
      if (!m)
334!
828
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
829
      simulation::entropy_mesh = m;
334✔
830

831
      // Turn on Shannon entropy calculation
832
      entropy_on = true;
334✔
833

834
    } else if (check_for_node(root, "entropy")) {
7,918!
835
      fatal_error(
×
836
        "Specifying a Shannon entropy mesh via the <entropy> element "
837
        "is deprecated. Please create a mesh using <mesh> and then reference "
838
        "it by specifying its ID in an <entropy_mesh> element.");
839
    }
840
  }
841
  // Uniform fission source weighting mesh
842
  if (check_for_node(root, "ufs_mesh")) {
9,044✔
843
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
30✔
844
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
15!
845
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
846
                              "method does not exist.",
847
        temp));
848
    }
849

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

856
    // Turn on uniform fission source weighting
857
    ufs_on = true;
15✔
858

859
  } else if (check_for_node(root, "uniform_fs")) {
9,029!
860
    fatal_error(
×
861
      "Specifying a UFS mesh via the <uniform_fs> element "
862
      "is deprecated. Please create a mesh using <mesh> and then reference "
863
      "it by specifying its ID in a <ufs_mesh> element.");
864
  }
865

866
  // Check if the user has specified to write state points
867
  if (check_for_node(root, "state_point")) {
9,044✔
868

869
    // Get pointer to state_point node
870
    auto node_sp = root.child("state_point");
160✔
871

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

889
  // Check if the user has specified to write source points
890
  if (check_for_node(root, "source_point")) {
9,044✔
891
    // Get source_point node
892
    xml_node node_sp = root.child("source_point");
101✔
893

894
    // Determine batches at which to store source points
895
    if (check_for_node(node_sp, "batches")) {
101✔
896
      // User gave specific batches to write source points
897
      auto temp = get_node_array<int>(node_sp, "batches");
45✔
898
      for (const auto& b : temp) {
120✔
899
        sourcepoint_batch.insert(b);
75✔
900
      }
901
    } else {
45✔
902
      // If neither were specified, write source points with state points
903
      sourcepoint_batch = statepoint_batch;
56!
904
    }
905

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

927
  // Check is the user specified to convert strength to statistical weight
928
  if (check_for_node(root, "uniform_source_sampling")) {
9,044✔
929
    uniform_source_sampling =
55✔
930
      get_node_value_bool(root, "uniform_source_sampling");
55✔
931
  }
932

933
  // Check if the user has specified to write surface source
934
  if (check_for_node(root, "surf_source_write")) {
9,044✔
935
    surf_source_write = true;
412✔
936
    // Get surface source write node
937
    xml_node node_ssw = root.child("surf_source_write");
412✔
938

939
    // Determine surface ids at which crossing particles are to be banked.
940
    // If no surfaces are specified, all surfaces in the model will be used
941
    // to bank source points.
942
    if (check_for_node(node_ssw, "surface_ids")) {
412✔
943
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
202✔
944
      for (const auto& b : temp) {
994✔
945
        source_write_surf_id.insert(b);
792✔
946
      }
947
    }
202✔
948

949
    // Get maximum number of particles to be banked per surface
950
    if (check_for_node(node_ssw, "max_particles")) {
412✔
951
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
806✔
952
    } else {
953
      fatal_error("A maximum number of particles needs to be specified "
9✔
954
                  "using the 'max_particles' parameter to store surface "
955
                  "source points.");
956
    }
957

958
    // Get maximum number of surface source files to be created
959
    if (check_for_node(node_ssw, "max_source_files")) {
403✔
960
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
66✔
961
    } else {
962
      ssw_max_files = 1;
370✔
963
    }
964

965
    if (check_for_node(node_ssw, "mcpl")) {
403✔
966
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
11✔
967
    }
968
    // Get cell information
969
    if (check_for_node(node_ssw, "cell")) {
403✔
970
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
208✔
971
      ssw_cell_type = SSWCellType::Both;
104✔
972
    }
973
    if (check_for_node(node_ssw, "cellfrom")) {
403✔
974
      if (ssw_cell_id != C_NONE) {
90✔
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, "cellfrom"));
144✔
979
      ssw_cell_type = SSWCellType::From;
72✔
980
    }
981
    if (check_for_node(node_ssw, "cellto")) {
385✔
982
      if (ssw_cell_id != C_NONE) {
71✔
983
        fatal_error(
18✔
984
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
985
      }
986
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
106✔
987
      ssw_cell_type = SSWCellType::To;
53✔
988
    }
989
  }
990

991
  // Check if the user has specified to write specific collisions
992
  if (check_for_node(root, "collision_track")) {
8,999✔
993
    settings::collision_track = true;
160✔
994
    // Get collision track node
995
    xml_node node_ct = root.child("collision_track");
160✔
996
    collision_track_config = CollisionTrackConfig {};
160✔
997

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

1055
  // If source is not separate and is to be written out in the statepoint
1056
  // file, make sure that the sourcepoint batch numbers are contained in the
1057
  // statepoint list
1058
  if (!source_separate) {
8,999✔
1059
    for (const auto& b : sourcepoint_batch) {
17,952✔
1060
      if (!contains(statepoint_batch, b)) {
18,078!
1061
        fatal_error(
×
1062
          "Sourcepoint batches are not a subset of statepoint batches.");
1063
      }
1064
    }
1065
  }
1066

1067
  // Check if the user has specified to not reduce tallies at the end of every
1068
  // batch
1069
  if (check_for_node(root, "no_reduce")) {
8,999✔
1070
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
30✔
1071
  }
1072

1073
  // Check if the user has specified to use confidence intervals for
1074
  // uncertainties rather than standard deviations
1075
  if (check_for_node(root, "confidence_intervals")) {
8,999✔
1076
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
15✔
1077
  }
1078

1079
  // Check for output options
1080
  if (check_for_node(root, "output")) {
8,999✔
1081
    // Get pointer to output node
1082
    pugi::xml_node node_output = root.child("output");
823✔
1083

1084
    // Check for summary option
1085
    if (check_for_node(node_output, "summary")) {
823✔
1086
      output_summary = get_node_value_bool(node_output, "summary");
797✔
1087
    }
1088

1089
    // Check for ASCII tallies output option
1090
    if (check_for_node(node_output, "tallies")) {
823✔
1091
      output_tallies = get_node_value_bool(node_output, "tallies");
349✔
1092
    }
1093

1094
    // Set output directory if a path has been specified
1095
    if (check_for_node(node_output, "path")) {
823!
1096
      path_output = get_node_value(node_output, "path");
×
1097
      if (!ends_with(path_output, "/")) {
×
1098
        path_output += "/";
823!
1099
      }
1100
    }
1101
  }
1102

1103
  // Resonance scattering parameters
1104
  if (check_for_node(root, "resonance_scattering")) {
8,999✔
1105
    xml_node node_res_scat = root.child("resonance_scattering");
15✔
1106

1107
    // See if resonance scattering is enabled
1108
    if (check_for_node(node_res_scat, "enable")) {
15!
1109
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
15✔
1110
    } else {
1111
      res_scat_on = true;
×
1112
    }
1113

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

1127
    // Minimum energy for resonance scattering
1128
    if (check_for_node(node_res_scat, "energy_min")) {
15!
1129
      res_scat_energy_min =
30✔
1130
        std::stod(get_node_value(node_res_scat, "energy_min"));
30✔
1131
    }
1132
    if (res_scat_energy_min < 0.0) {
15!
1133
      fatal_error("Lower resonance scattering energy bound is negative");
×
1134
    }
1135

1136
    // Maximum energy for resonance scattering
1137
    if (check_for_node(node_res_scat, "energy_max")) {
15!
1138
      res_scat_energy_max =
30✔
1139
        std::stod(get_node_value(node_res_scat, "energy_max"));
30✔
1140
    }
1141
    if (res_scat_energy_max < res_scat_energy_min) {
15!
1142
      fatal_error("Upper resonance scattering energy bound is below the "
×
1143
                  "lower resonance scattering energy bound.");
1144
    }
1145

1146
    // Get resonance scattering nuclides
1147
    if (check_for_node(node_res_scat, "nuclides")) {
15!
1148
      res_scat_nuclides =
15✔
1149
        get_node_array<std::string>(node_res_scat, "nuclides");
30✔
1150
    }
1151
  }
1152

1153
  // Get volume calculations
1154
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
9,307✔
1155
    model::volume_calcs.emplace_back(node_vol);
308✔
1156
  }
1157

1158
  // Get temperature settings
1159
  if (check_for_node(root, "temperature_default")) {
8,999✔
1160
    temperature_default =
342✔
1161
      std::stod(get_node_value(root, "temperature_default"));
342✔
1162
  }
1163
  if (check_for_node(root, "temperature_method")) {
8,999✔
1164
    auto temp = get_node_value(root, "temperature_method", true, true);
485✔
1165
    if (temp == "nearest") {
485✔
1166
      temperature_method = TemperatureMethod::NEAREST;
304✔
1167
    } else if (temp == "interpolation") {
181!
1168
      temperature_method = TemperatureMethod::INTERPOLATION;
181✔
1169
    } else {
1170
      fatal_error("Unknown temperature method: " + temp);
×
1171
    }
1172
  }
485✔
1173
  if (check_for_node(root, "temperature_tolerance")) {
8,999✔
1174
    temperature_tolerance =
680✔
1175
      std::stod(get_node_value(root, "temperature_tolerance"));
680✔
1176
  }
1177
  if (check_for_node(root, "temperature_multipole")) {
8,999✔
1178
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
185✔
1179

1180
    // Multipole currently doesn't work with photon transport
1181
    if (temperature_multipole && photon_transport) {
185!
1182
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1183
                  "photon transport.");
1184
    }
1185
  }
1186
  if (check_for_node(root, "temperature_range")) {
8,999✔
1187
    auto range = get_node_array<double>(root, "temperature_range");
170✔
1188
    temperature_range[0] = range.at(0);
170✔
1189
    temperature_range[1] = range.at(1);
170✔
1190
  }
170✔
1191

1192
  // Check for tabular_legendre options
1193
  if (check_for_node(root, "tabular_legendre")) {
8,999✔
1194
    // Get pointer to tabular_legendre node
1195
    xml_node node_tab_leg = root.child("tabular_legendre");
105✔
1196

1197
    // Check for enable option
1198
    if (check_for_node(node_tab_leg, "enable")) {
105!
1199
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
105✔
1200
    }
1201

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

1214
  // Check whether create delayed neutrons in fission
1215
  if (check_for_node(root, "create_delayed_neutrons")) {
8,999!
1216
    create_delayed_neutrons =
×
1217
      get_node_value_bool(root, "create_delayed_neutrons");
×
1218
  }
1219

1220
  // Check whether create fission sites
1221
  if (run_mode == RunMode::FIXED_SOURCE) {
8,999✔
1222
    if (check_for_node(root, "create_fission_neutrons")) {
3,267✔
1223
      create_fission_neutrons =
325✔
1224
        get_node_value_bool(root, "create_fission_neutrons");
325✔
1225
    }
1226
  }
1227

1228
  // Check whether to scale fission photon yields
1229
  if (check_for_node(root, "delayed_photon_scaling")) {
8,999!
1230
    delayed_photon_scaling =
×
1231
      get_node_value_bool(root, "delayed_photon_scaling");
×
1232
  }
1233

1234
  // Check whether to use event-based parallelism
1235
  if (check_for_node(root, "event_based")) {
8,999!
1236
    event_based = get_node_value_bool(root, "event_based");
×
1237
  }
1238

1239
  // Check whether material cell offsets should be generated
1240
  if (check_for_node(root, "material_cell_offsets")) {
8,999!
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")) {
9,304✔
1246
    variance_reduction::weight_windows.emplace_back(
305✔
1247
      std::make_unique<WeightWindows>(node_ww));
610✔
1248
  }
1249

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

1254
  // read weight windows from file
1255
  if (check_for_node(root, "weight_windows_file")) {
8,999!
1256
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1257
    weight_windows_on = true;
×
1258
  }
1259

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

1266
  if (check_for_node(root, "max_secondaries")) {
8,999!
1267
    settings::max_secondaries =
×
1268
      std::stoi(get_node_value(root, "max_secondaries"));
×
1269
  }
1270

1271
  if (check_for_node(root, "max_history_splits")) {
8,999✔
1272
    settings::max_history_splits =
680✔
1273
      std::stoi(get_node_value(root, "max_history_splits"));
680✔
1274
  }
1275

1276
  if (check_for_node(root, "max_tracks")) {
8,999✔
1277
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
90✔
1278
  }
1279

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

1308
  // Set up weight window checkpoints
1309
  if (check_for_node(root, "weight_window_checkpoints")) {
8,999✔
1310
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
136✔
1311
    if (check_for_node(ww_checkpoints, "collision")) {
136!
1312
      weight_window_checkpoint_collision =
136✔
1313
        get_node_value_bool(ww_checkpoints, "collision");
136✔
1314
    }
1315
    if (check_for_node(ww_checkpoints, "surface")) {
136!
1316
      weight_window_checkpoint_surface =
136✔
1317
        get_node_value_bool(ww_checkpoints, "surface");
136✔
1318
    }
1319
  }
1320

1321
  if (weight_windows_on) {
8,999✔
1322
    if (!weight_window_checkpoint_surface &&
303✔
1323
        !weight_window_checkpoint_collision)
178!
1324
      fatal_error(
×
1325
        "Weight Windows are enabled but there are no valid checkpoints.");
1326
  }
1327

1328
  if (check_for_node(root, "use_decay_photons")) {
8,999✔
1329
    settings::use_decay_photons =
11✔
1330
      get_node_value_bool(root, "use_decay_photons");
11✔
1331
  }
1332

1333
  // If weight windows are on, also enable shared secondary bank (unless
1334
  // explicitly disabled by user).
1335
  if (check_for_node(root, "shared_secondary_bank")) {
8,999✔
1336
    bool val = get_node_value_bool(root, "shared_secondary_bank");
335✔
1337
    if (val && run_mode == RunMode::EIGENVALUE) {
335!
1338
      warning(
×
1339
        "Shared secondary bank is not supported in eigenvalue calculations. "
1340
        "Setting will be ignored.");
1341
    } else {
1342
      settings::use_shared_secondary_bank = val;
335✔
1343
    }
1344
  } else if (settings::weight_windows_on) {
8,664✔
1345
    if (run_mode == RunMode::EIGENVALUE) {
121✔
1346
      warning(
22✔
1347
        "Shared secondary bank is not supported in eigenvalue calculations. "
1348
        "Particle local secondary banks will be used instead.");
1349
    } else if (run_mode == RunMode::FIXED_SOURCE) {
110!
1350
      settings::use_shared_secondary_bank = true;
110✔
1351
    }
1352
  }
1353
  // Implicit surfaces settings
1354
  if (check_for_node(root, "implicit")) {
8,999!
NEW
1355
    xml_node implicit_node = root.child("implicit");
×
NEW
1356
    if (check_for_node(implicit_node, "maxiter")) {
×
NEW
1357
      implicit_maxiter = std::stoi(get_node_value(implicit_node, "maxiter"));
×
1358
    }
NEW
1359
    if (check_for_node(implicit_node, "name")) {
×
NEW
1360
      implicit_solver = get_node_value(implicit_node, "name");
×
NEW
1361
      if (implicit_solver != "naive" && implicit_solver != "fast")
×
NEW
1362
        fatal_error("Unrecognized implicit solver name: " + implicit_solver);
×
1363
    }
NEW
1364
    if (check_for_node(implicit_node, "atol")) {
×
NEW
1365
      implicit_atol = std::stod(get_node_value(implicit_node, "atol"));
×
1366
    }
NEW
1367
    if (check_for_node(implicit_node, "ftol")) {
×
NEW
1368
      implicit_ftol = std::stod(get_node_value(implicit_node, "ftol"));
×
1369
    }
NEW
1370
    if (check_for_node(implicit_node, "margin")) {
×
NEW
1371
      implicit_margin = std::stod(get_node_value(implicit_node, "margin"));
×
1372
    }
1373
  }
1374
}
8,999✔
1375

1376
void free_memory_settings()
9,147✔
1377
{
1378
  settings::statepoint_batch.clear();
9,147✔
1379
  settings::sourcepoint_batch.clear();
9,147✔
1380
  settings::source_write_surf_id.clear();
9,147✔
1381
  settings::res_scat_nuclides.clear();
9,147✔
1382
}
9,147✔
1383

1384
//==============================================================================
1385
// C API functions
1386
//==============================================================================
1387

1388
extern "C" int openmc_set_n_batches(
220✔
1389
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1390
{
1391
  if (settings::n_inactive >= n_batches) {
220✔
1392
    set_errmsg("Number of active batches must be greater than zero.");
11✔
1393
    return OPENMC_E_INVALID_ARGUMENT;
11✔
1394
  }
1395

1396
  if (!settings::trigger_on) {
209✔
1397
    // Set n_batches and n_max_batches to same value
1398
    settings::n_batches = n_batches;
187✔
1399
    settings::n_max_batches = n_batches;
187✔
1400
  } else {
1401
    // Set n_batches and n_max_batches based on value of set_max_batches
1402
    if (set_max_batches) {
22✔
1403
      settings::n_max_batches = n_batches;
11✔
1404
    } else {
1405
      settings::n_batches = n_batches;
11✔
1406
    }
1407
  }
1408

1409
  // Update size of k_generation and entropy
1410
  int m = settings::n_max_batches * settings::gen_per_batch;
209✔
1411
  simulation::k_generation.reserve(m);
209✔
1412
  simulation::entropy.reserve(m);
209✔
1413

1414
  // Add value of n_batches to statepoint_batch
1415
  if (add_statepoint_batch &&
209✔
1416
      !(contains(settings::statepoint_batch, n_batches)))
198✔
1417
    settings::statepoint_batch.insert(n_batches);
33✔
1418

1419
  return 0;
1420
}
1421

1422
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,530✔
1423
{
1424
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,530✔
1425

1426
  return 0;
2,530✔
1427
}
1428

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