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

openmc-dev / openmc / 12776996362

14 Jan 2025 09:49PM UTC coverage: 84.938% (+0.2%) from 84.729%
12776996362

Pull #3133

github

web-flow
Merge 0495246d9 into 549cc0973
Pull Request #3133: Kinetics parameters using Iterated Fission Probability

318 of 330 new or added lines in 10 files covered. (96.36%)

1658 existing lines in 66 files now uncovered.

50402 of 59340 relevant lines covered (84.94%)

33987813.96 hits per line

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

78.88
/src/settings.cpp
1
#include "openmc/settings.h"
2

3
#include <cmath>  // for ceil, pow
4
#include <limits> // for numeric_limits
5
#include <string>
6

7
#include <fmt/core.h>
8
#ifdef _OPENMP
9
#include <omp.h>
10
#endif
11

12
#include "openmc/capi.h"
13
#include "openmc/constants.h"
14
#include "openmc/container_util.h"
15
#include "openmc/distribution.h"
16
#include "openmc/distribution_multi.h"
17
#include "openmc/distribution_spatial.h"
18
#include "openmc/eigenvalue.h"
19
#include "openmc/error.h"
20
#include "openmc/file_utils.h"
21
#include "openmc/mcpl_interface.h"
22
#include "openmc/mesh.h"
23
#include "openmc/message_passing.h"
24
#include "openmc/output.h"
25
#include "openmc/plot.h"
26
#include "openmc/random_lcg.h"
27
#include "openmc/random_ray/random_ray.h"
28
#include "openmc/simulation.h"
29
#include "openmc/source.h"
30
#include "openmc/string_utils.h"
31
#include "openmc/tallies/trigger.h"
32
#include "openmc/volume_calc.h"
33
#include "openmc/weight_windows.h"
34
#include "openmc/xml_interface.h"
35

36
namespace openmc {
37

38
//==============================================================================
39
// Global variables
40
//==============================================================================
41

42
namespace settings {
43

44
// Default values for boolean flags
45
bool assume_separate {false};
46
bool check_overlaps {false};
47
bool cmfd_run {false};
48
bool confidence_intervals {false};
49
bool create_delayed_neutrons {true};
50
bool create_fission_neutrons {true};
51
bool delayed_photon_scaling {true};
52
bool entropy_on {false};
53
bool event_based {false};
54
bool ifp {false};
55
bool legendre_to_tabular {true};
56
bool material_cell_offsets {true};
57
bool output_summary {true};
58
bool output_tallies {true};
59
bool particle_restart_run {false};
60
bool photon_transport {false};
61
bool reduce_tallies {true};
62
bool res_scat_on {false};
63
bool restart_run {false};
64
bool run_CE {true};
65
bool source_latest {false};
66
bool source_separate {false};
67
bool source_write {true};
68
bool source_mcpl_write {false};
69
bool surf_source_write {false};
70
bool surf_mcpl_write {false};
71
bool surf_source_read {false};
72
bool survival_biasing {false};
73
bool temperature_multipole {false};
74
bool trigger_on {false};
75
bool trigger_predict {false};
76
bool uniform_source_sampling {false};
77
bool ufs_on {false};
78
bool urr_ptables_on {true};
79
bool weight_windows_on {false};
80
bool weight_window_checkpoint_surface {false};
81
bool weight_window_checkpoint_collision {true};
82
bool write_all_tracks {false};
83
bool write_initial_source {false};
84

85
std::string path_cross_sections;
86
std::string path_input;
87
std::string path_output;
88
std::string path_particle_restart;
89
std::string path_sourcepoint;
90
std::string path_statepoint;
91
const char* path_statepoint_c {path_statepoint.c_str()};
92
std::string weight_windows_file;
93

94
int32_t n_inactive {0};
95
int32_t max_lost_particles {10};
96
double rel_max_lost_particles {1.0e-6};
97
int32_t max_write_lost_particles {-1};
98
int32_t gen_per_batch {1};
99
int64_t n_particles {-1};
100

101
int64_t max_particles_in_flight {100000};
102
int max_particle_events {1000000};
103

104
ElectronTreatment electron_treatment {ElectronTreatment::TTB};
105
array<double, 4> energy_cutoff {0.0, 1000.0, 0.0, 0.0};
106
array<double, 4> time_cutoff {INFTY, INFTY, INFTY, INFTY};
107
int ifp_n_generation {0};
108
IFPParameter ifp_parameter {IFPParameter::None};
109
int legendre_to_tabular_points {C_NONE};
110
int max_order {0};
111
int n_log_bins {8000};
112
int n_batches;
113
int n_max_batches;
114
int max_history_splits {10'000'000};
115
int max_tracks {1000};
116
ResScatMethod res_scat_method {ResScatMethod::rvs};
117
double res_scat_energy_min {0.01};
118
double res_scat_energy_max {1000.0};
119
vector<std::string> res_scat_nuclides;
120
RunMode run_mode {RunMode::UNSET};
121
SolverType solver_type {SolverType::MONTE_CARLO};
122
std::unordered_set<int> sourcepoint_batch;
123
std::unordered_set<int> statepoint_batch;
124
std::unordered_set<int> source_write_surf_id;
125
int64_t ssw_max_particles;
126
int64_t ssw_max_files;
127
int64_t ssw_cell_id {C_NONE};
128
SSWCellType ssw_cell_type {SSWCellType::None};
129
TemperatureMethod temperature_method {TemperatureMethod::NEAREST};
130
double temperature_tolerance {10.0};
131
double temperature_default {293.6};
132
array<double, 2> temperature_range {0.0, 0.0};
133
int trace_batch;
134
int trace_gen;
135
int64_t trace_particle;
136
vector<array<int, 3>> track_identifiers;
137
int trigger_batch_interval {1};
138
int verbosity {7};
139
double weight_cutoff {0.25};
140
double weight_survive {1.0};
141

142
} // namespace settings
143

144
//==============================================================================
145
// Functions
146
//==============================================================================
147

148
void get_run_parameters(pugi::xml_node node_base)
6,410✔
149
{
150
  using namespace settings;
151
  using namespace pugi;
152

153
  // Check number of particles
154
  if (!check_for_node(node_base, "particles")) {
6,410✔
UNCOV
155
    fatal_error("Need to specify number of particles.");
×
156
  }
157

158
  // Get number of particles if it wasn't specified as a command-line argument
159
  if (n_particles == -1) {
6,410✔
160
    n_particles = std::stoll(get_node_value(node_base, "particles"));
6,410✔
161
  }
162

163
  // Get maximum number of in flight particles for event-based mode
164
  if (check_for_node(node_base, "max_particles_in_flight")) {
6,410✔
UNCOV
165
    max_particles_in_flight =
×
UNCOV
166
      std::stoll(get_node_value(node_base, "max_particles_in_flight"));
×
167
  }
168

169
  // Get maximum number of events allowed per particle
170
  if (check_for_node(node_base, "max_particle_events")) {
6,410✔
UNCOV
171
    max_particle_events =
×
UNCOV
172
      std::stoll(get_node_value(node_base, "max_particle_events"));
×
173
  }
174

175
  // Get number of basic batches
176
  if (check_for_node(node_base, "batches")) {
6,410✔
177
    n_batches = std::stoi(get_node_value(node_base, "batches"));
6,410✔
178
  }
179
  if (!trigger_on)
6,410✔
180
    n_max_batches = n_batches;
6,253✔
181

182
  // Get max number of lost particles
183
  if (check_for_node(node_base, "max_lost_particles")) {
6,410✔
184
    max_lost_particles =
17✔
185
      std::stoi(get_node_value(node_base, "max_lost_particles"));
17✔
186
  }
187

188
  // Get relative number of lost particles
189
  if (check_for_node(node_base, "rel_max_lost_particles")) {
6,410✔
UNCOV
190
    rel_max_lost_particles =
×
UNCOV
191
      std::stod(get_node_value(node_base, "rel_max_lost_particles"));
×
192
  }
193

194
  // Get relative number of lost particles
195
  if (check_for_node(node_base, "max_write_lost_particles")) {
6,410✔
196
    max_write_lost_particles =
17✔
197
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
17✔
198
  }
199

200
  // Get number of inactive batches
201
  if (run_mode == RunMode::EIGENVALUE ||
6,410✔
202
      solver_type == SolverType::RANDOM_RAY) {
2,151✔
203
    if (check_for_node(node_base, "inactive")) {
4,531✔
204
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,391✔
205
    }
206
    if (check_for_node(node_base, "generations_per_batch")) {
4,531✔
207
      gen_per_batch =
17✔
208
        std::stoi(get_node_value(node_base, "generations_per_batch"));
17✔
209
    }
210

211
    // Preallocate space for keff and entropy by generation
212
    int m = settings::n_max_batches * settings::gen_per_batch;
4,531✔
213
    simulation::k_generation.reserve(m);
4,531✔
214
    simulation::entropy.reserve(m);
4,531✔
215

216
    // Get the trigger information for keff
217
    if (check_for_node(node_base, "keff_trigger")) {
4,531✔
218
      xml_node node_keff_trigger = node_base.child("keff_trigger");
114✔
219

220
      if (check_for_node(node_keff_trigger, "type")) {
114✔
221
        auto temp = get_node_value(node_keff_trigger, "type", true, true);
114✔
222
        if (temp == "std_dev") {
114✔
223
          keff_trigger.metric = TriggerMetric::standard_deviation;
114✔
224
        } else if (temp == "variance") {
×
225
          keff_trigger.metric = TriggerMetric::variance;
×
UNCOV
226
        } else if (temp == "rel_err") {
×
227
          keff_trigger.metric = TriggerMetric::relative_error;
×
228
        } else {
UNCOV
229
          fatal_error("Unrecognized keff trigger type " + temp);
×
230
        }
231
      } else {
114✔
UNCOV
232
        fatal_error("Specify keff trigger type in settings XML");
×
233
      }
234

235
      if (check_for_node(node_keff_trigger, "threshold")) {
114✔
236
        keff_trigger.threshold =
114✔
237
          std::stod(get_node_value(node_keff_trigger, "threshold"));
114✔
238
        if (keff_trigger.threshold <= 0) {
114✔
UNCOV
239
          fatal_error("keff trigger threshold must be positive");
×
240
        }
241
      } else {
UNCOV
242
        fatal_error("Specify keff trigger threshold in settings XML");
×
243
      }
244
    }
245
  }
246

247
  // Random ray variables
248
  if (solver_type == SolverType::RANDOM_RAY) {
6,410✔
249
    xml_node random_ray_node = node_base.child("random_ray");
357✔
250
    if (check_for_node(random_ray_node, "distance_active")) {
357✔
251
      RandomRay::distance_active_ =
357✔
252
        std::stod(get_node_value(random_ray_node, "distance_active"));
357✔
253
      if (RandomRay::distance_active_ <= 0.0) {
357✔
UNCOV
254
        fatal_error("Random ray active distance must be greater than 0");
×
255
      }
256
    } else {
UNCOV
257
      fatal_error("Specify random ray active distance in settings XML");
×
258
    }
259
    if (check_for_node(random_ray_node, "distance_inactive")) {
357✔
260
      RandomRay::distance_inactive_ =
357✔
261
        std::stod(get_node_value(random_ray_node, "distance_inactive"));
357✔
262
      if (RandomRay::distance_inactive_ < 0) {
357✔
UNCOV
263
        fatal_error(
×
264
          "Random ray inactive distance must be greater than or equal to 0");
265
      }
266
    } else {
UNCOV
267
      fatal_error("Specify random ray inactive distance in settings XML");
×
268
    }
269
    if (check_for_node(random_ray_node, "source")) {
357✔
270
      xml_node source_node = random_ray_node.child("source");
357✔
271
      // Get point to list of <source> elements and make sure there is at least
272
      // one
273
      RandomRay::ray_source_ = Source::create(source_node);
357✔
274
    } else {
UNCOV
275
      fatal_error("Specify random ray source in settings XML");
×
276
    }
277
    if (check_for_node(random_ray_node, "volume_estimator")) {
357✔
278
      std::string temp_str =
279
        get_node_value(random_ray_node, "volume_estimator", true, true);
102✔
280
      if (temp_str == "simulation_averaged") {
102✔
281
        FlatSourceDomain::volume_estimator_ =
34✔
282
          RandomRayVolumeEstimator::SIMULATION_AVERAGED;
283
      } else if (temp_str == "naive") {
68✔
284
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::NAIVE;
34✔
285
      } else if (temp_str == "hybrid") {
34✔
286
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::HYBRID;
34✔
287
      } else {
UNCOV
288
        fatal_error("Unrecognized volume estimator: " + temp_str);
×
289
      }
290
    }
102✔
291
    if (check_for_node(random_ray_node, "source_shape")) {
357✔
292
      std::string temp_str =
293
        get_node_value(random_ray_node, "source_shape", true, true);
153✔
294
      if (temp_str == "flat") {
153✔
295
        RandomRay::source_shape_ = RandomRaySourceShape::FLAT;
17✔
296
      } else if (temp_str == "linear") {
136✔
297
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR;
85✔
298
      } else if (temp_str == "linear_xy") {
51✔
299
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR_XY;
51✔
300
      } else {
UNCOV
301
        fatal_error("Unrecognized source shape: " + temp_str);
×
302
      }
303
    }
153✔
304
    if (check_for_node(random_ray_node, "volume_normalized_flux_tallies")) {
357✔
305
      FlatSourceDomain::volume_normalized_flux_tallies_ =
340✔
306
        get_node_value_bool(random_ray_node, "volume_normalized_flux_tallies");
340✔
307
    }
308
    if (check_for_node(random_ray_node, "adjoint")) {
357✔
309
      FlatSourceDomain::adjoint_ =
34✔
310
        get_node_value_bool(random_ray_node, "adjoint");
34✔
311
    }
312
  }
313
}
6,410✔
314

315
void read_settings_xml()
1,552✔
316
{
317
  using namespace settings;
318
  using namespace pugi;
319
  // Check if settings.xml exists
320
  std::string filename = settings::path_input + "settings.xml";
1,552✔
321
  if (!file_exists(filename)) {
1,552✔
322
    if (run_mode != RunMode::PLOTTING) {
24✔
UNCOV
323
      fatal_error("Could not find any XML input files! In order to run OpenMC, "
×
324
                  "you first need a set of input files; at a minimum, this "
325
                  "includes settings.xml, geometry.xml, and materials.xml or a "
326
                  "single model XML file. Please consult the user's guide at "
327
                  "https://docs.openmc.org for further information.");
328
    } else {
329
      // The settings.xml file is optional if we just want to make a plot.
330
      return;
24✔
331
    }
332
  }
333

334
  // Parse settings.xml file
335
  xml_document doc;
1,528✔
336
  auto result = doc.load_file(filename.c_str());
1,528✔
337
  if (!result) {
1,528✔
UNCOV
338
    fatal_error("Error processing settings.xml file.");
×
339
  }
340

341
  // Get root element
342
  xml_node root = doc.document_element();
1,528✔
343

344
  // Verbosity
345
  if (check_for_node(root, "verbosity")) {
1,528✔
346
    verbosity = std::stoi(get_node_value(root, "verbosity"));
216✔
347
  }
348

349
  // To this point, we haven't displayed any output since we didn't know what
350
  // the verbosity is. Now that we checked for it, show the title if necessary
351
  if (mpi::master) {
1,528✔
352
    if (verbosity >= 2)
1,298✔
353
      title();
1,092✔
354
  }
355

356
  write_message("Reading settings XML file...", 5);
1,528✔
357

358
  read_settings_xml(root);
1,528✔
359
}
1,541✔
360

361
void read_settings_xml(pugi::xml_node root)
6,868✔
362
{
363
  using namespace settings;
364
  using namespace pugi;
365

366
  // Find if a multi-group or continuous-energy simulation is desired
367
  if (check_for_node(root, "energy_mode")) {
6,868✔
368
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
901✔
369
    if (temp_str == "mg" || temp_str == "multi-group") {
901✔
370
      run_CE = false;
901✔
UNCOV
371
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
UNCOV
372
      run_CE = true;
×
373
    }
374
  }
901✔
375

376
  // Check for user meshes and allocate
377
  read_meshes(root);
6,868✔
378

379
  // Look for deprecated cross_sections.xml file in settings.xml
380
  if (check_for_node(root, "cross_sections")) {
6,868✔
381
    warning(
×
382
      "Setting cross_sections in settings.xml has been deprecated."
383
      " The cross_sections are now set in materials.xml and the "
384
      "cross_sections input to materials.xml and the OPENMC_CROSS_SECTIONS"
385
      " environment variable will take precendent over setting "
386
      "cross_sections in settings.xml.");
UNCOV
387
    path_cross_sections = get_node_value(root, "cross_sections");
×
388
  }
389

390
  if (!run_CE) {
6,868✔
391
    // Scattering Treatments
392
    if (check_for_node(root, "max_order")) {
901✔
393
      max_order = std::stoi(get_node_value(root, "max_order"));
17✔
394
    } else {
395
      // Set to default of largest int - 1, which means to use whatever is
396
      // contained in library. This is largest int - 1 because for legendre
397
      // scattering, a value of 1 is added to the order; adding 1 to the largest
398
      // int gets you the largest negative integer, which is not what we want.
399
      max_order = std::numeric_limits<int>::max() - 1;
884✔
400
    }
401
  }
402

403
  // Check for a trigger node and get trigger information
404
  if (check_for_node(root, "trigger")) {
6,868✔
405
    xml_node node_trigger = root.child("trigger");
174✔
406

407
    // Check if trigger(s) are to be turned on
408
    trigger_on = get_node_value_bool(node_trigger, "active");
174✔
409

410
    if (trigger_on) {
174✔
411
      if (check_for_node(node_trigger, "max_batches")) {
157✔
412
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
157✔
413
      } else {
UNCOV
414
        fatal_error("<max_batches> must be specified with triggers");
×
415
      }
416

417
      // Get the batch interval to check triggers
418
      if (!check_for_node(node_trigger, "batch_interval")) {
157✔
419
        trigger_predict = true;
17✔
420
      } else {
421
        trigger_batch_interval =
140✔
422
          std::stoi(get_node_value(node_trigger, "batch_interval"));
140✔
423
        if (trigger_batch_interval <= 0) {
140✔
UNCOV
424
          fatal_error("Trigger batch interval must be greater than zero");
×
425
        }
426
      }
427
    }
428
  }
429

430
  // Check run mode if it hasn't been set from the command line
431
  xml_node node_mode;
6,868✔
432
  if (run_mode == RunMode::UNSET) {
6,868✔
433
    if (check_for_node(root, "run_mode")) {
6,444✔
434
      std::string temp_str = get_node_value(root, "run_mode", true, true);
6,376✔
435
      if (temp_str == "eigenvalue") {
6,376✔
436
        run_mode = RunMode::EIGENVALUE;
4,191✔
437
      } else if (temp_str == "fixed source") {
2,185✔
438
        run_mode = RunMode::FIXED_SOURCE;
2,151✔
439
      } else if (temp_str == "plot") {
34✔
440
        run_mode = RunMode::PLOTTING;
×
441
      } else if (temp_str == "particle restart") {
34✔
UNCOV
442
        run_mode = RunMode::PARTICLE;
×
443
      } else if (temp_str == "volume") {
34✔
444
        run_mode = RunMode::VOLUME;
34✔
445
      } else {
UNCOV
446
        fatal_error("Unrecognized run mode: " + temp_str);
×
447
      }
448

449
      // Assume XML specifies <particles>, <batches>, etc. directly
450
      node_mode = root;
6,376✔
451
    } else {
6,376✔
452
      warning("<run_mode> should be specified.");
68✔
453

454
      // Make sure that either eigenvalue or fixed source was specified
455
      node_mode = root.child("eigenvalue");
68✔
456
      if (node_mode) {
68✔
457
        run_mode = RunMode::EIGENVALUE;
68✔
458
      } else {
UNCOV
459
        node_mode = root.child("fixed_source");
×
UNCOV
460
        if (node_mode) {
×
UNCOV
461
          run_mode = RunMode::FIXED_SOURCE;
×
462
        } else {
UNCOV
463
          fatal_error("<eigenvalue> or <fixed_source> not specified.");
×
464
        }
465
      }
466
    }
467
  }
468

469
  // Check solver type
470
  if (check_for_node(root, "random_ray")) {
6,868✔
471
    solver_type = SolverType::RANDOM_RAY;
357✔
472
    if (run_CE)
357✔
UNCOV
473
      fatal_error("multi-group energy mode must be specified in settings XML "
×
474
                  "when using the random ray solver.");
475
  }
476

477
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
6,868✔
478
    // Read run parameters
479
    get_run_parameters(node_mode);
6,410✔
480

481
    // Check number of active batches, inactive batches, max lost particles and
482
    // particles
483
    if (n_batches <= n_inactive) {
6,410✔
484
      fatal_error("Number of active batches must be greater than zero.");
×
485
    } else if (n_inactive < 0) {
6,410✔
486
      fatal_error("Number of inactive batches must be non-negative.");
×
487
    } else if (n_particles <= 0) {
6,410✔
UNCOV
488
      fatal_error("Number of particles must be greater than zero.");
×
489
    } else if (max_lost_particles <= 0) {
6,410✔
UNCOV
490
      fatal_error("Number of max lost particles must be greater than zero.");
×
491
    } else if (rel_max_lost_particles <= 0.0 || rel_max_lost_particles >= 1.0) {
6,410✔
492
      fatal_error("Relative max lost particles must be between zero and one.");
×
493
    }
494
  }
495

496
  // Copy plotting random number seed if specified
497
  if (check_for_node(root, "plot_seed")) {
6,868✔
UNCOV
498
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
UNCOV
499
    model::plotter_seed = seed;
×
500
  }
501

502
  // Copy random number seed if specified
503
  if (check_for_node(root, "seed")) {
6,868✔
504
    auto seed = std::stoll(get_node_value(root, "seed"));
449✔
505
    openmc_set_seed(seed);
449✔
506
  }
507

508
  // Check for electron treatment
509
  if (check_for_node(root, "electron_treatment")) {
6,868✔
510
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
51✔
511
    if (temp_str == "led") {
51✔
UNCOV
512
      electron_treatment = ElectronTreatment::LED;
×
513
    } else if (temp_str == "ttb") {
51✔
514
      electron_treatment = ElectronTreatment::TTB;
51✔
515
    } else {
UNCOV
516
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
517
    }
518
  }
51✔
519

520
  // Check for photon transport
521
  if (check_for_node(root, "photon_transport")) {
6,868✔
522
    photon_transport = get_node_value_bool(root, "photon_transport");
206✔
523

524
    if (!run_CE && photon_transport) {
206✔
UNCOV
525
      fatal_error("Photon transport is not currently supported in "
×
526
                  "multigroup mode");
527
    }
528
  }
529

530
  // Number of bins for logarithmic grid
531
  if (check_for_node(root, "log_grid_bins")) {
6,868✔
532
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
17✔
533
    if (n_log_bins < 1) {
17✔
UNCOV
534
      fatal_error("Number of bins for logarithmic grid must be greater "
×
535
                  "than zero.");
536
    }
537
  }
538

539
  // Number of OpenMP threads
540
  if (check_for_node(root, "threads")) {
6,868✔
UNCOV
541
    if (mpi::master)
×
UNCOV
542
      warning("The <threads> element has been deprecated. Use "
×
543
              "the OMP_NUM_THREADS environment variable to set the number of "
544
              "threads.");
545
  }
546

547
  // ==========================================================================
548
  // EXTERNAL SOURCE
549

550
  // Get point to list of <source> elements and make sure there is at least one
551
  for (pugi::xml_node node : root.children("source")) {
13,416✔
552
    model::external_sources.push_back(Source::create(node));
6,559✔
553
  }
554

555
  // Check if the user has specified to read surface source
556
  if (check_for_node(root, "surf_source_read")) {
6,857✔
557
    surf_source_read = true;
17✔
558
    // Get surface source read node
559
    xml_node node_ssr = root.child("surf_source_read");
17✔
560

561
    std::string path = "surface_source.h5";
17✔
562
    // Check if the user has specified different file for surface source reading
563
    if (check_for_node(node_ssr, "path")) {
17✔
564
      path = get_node_value(node_ssr, "path", false, true);
17✔
565
    }
566
    model::external_sources.push_back(make_unique<FileSource>(path));
17✔
567
  }
17✔
568

569
  // Build probability mass function for sampling external sources
570
  vector<double> source_strengths;
6,857✔
571
  for (auto& s : model::external_sources) {
13,422✔
572
    source_strengths.push_back(s->strength());
6,565✔
573
  }
574
  model::external_sources_probability.assign(source_strengths);
6,857✔
575

576
  // If no source specified, default to isotropic point source at origin with
577
  // Watt spectrum. No default source is needed in random ray mode.
578
  if (model::external_sources.empty() &&
8,696✔
579
      settings::solver_type != SolverType::RANDOM_RAY) {
1,839✔
580
    double T[] {0.0};
1,754✔
581
    double p[] {1.0};
1,754✔
582
    model::external_sources.push_back(make_unique<IndependentSource>(
1,754✔
583
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
3,508✔
584
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
3,508✔
585
      UPtrDist {new Discrete(T, p, 1)}));
3,508✔
586
  }
587

588
  // Check if we want to write out source
589
  if (check_for_node(root, "write_initial_source")) {
6,857✔
UNCOV
590
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
591
  }
592

593
  // Survival biasing
594
  if (check_for_node(root, "survival_biasing")) {
6,857✔
595
    survival_biasing = get_node_value_bool(root, "survival_biasing");
190✔
596
  }
597

598
  // Probability tables
599
  if (check_for_node(root, "ptables")) {
6,857✔
600
    urr_ptables_on = get_node_value_bool(root, "ptables");
17✔
601
  }
602

603
  // Cutoffs
604
  if (check_for_node(root, "cutoff")) {
6,857✔
605
    xml_node node_cutoff = root.child("cutoff");
114✔
606
    if (check_for_node(node_cutoff, "weight")) {
114✔
607
      weight_cutoff = std::stod(get_node_value(node_cutoff, "weight"));
17✔
608
    }
609
    if (check_for_node(node_cutoff, "weight_avg")) {
114✔
610
      weight_survive = std::stod(get_node_value(node_cutoff, "weight_avg"));
17✔
611
    }
612
    if (check_for_node(node_cutoff, "energy_neutron")) {
114✔
613
      energy_cutoff[0] =
34✔
614
        std::stod(get_node_value(node_cutoff, "energy_neutron"));
17✔
615
    } else if (check_for_node(node_cutoff, "energy")) {
97✔
616
      warning("The use of an <energy> cutoff is deprecated and should "
×
617
              "be replaced by <energy_neutron>.");
UNCOV
618
      energy_cutoff[0] = std::stod(get_node_value(node_cutoff, "energy"));
×
619
    }
620
    if (check_for_node(node_cutoff, "energy_photon")) {
114✔
621
      energy_cutoff[1] =
126✔
622
        std::stod(get_node_value(node_cutoff, "energy_photon"));
63✔
623
    }
624
    if (check_for_node(node_cutoff, "energy_electron")) {
114✔
UNCOV
625
      energy_cutoff[2] =
×
626
        std::stof(get_node_value(node_cutoff, "energy_electron"));
×
627
    }
628
    if (check_for_node(node_cutoff, "energy_positron")) {
114✔
629
      energy_cutoff[3] =
×
UNCOV
630
        std::stod(get_node_value(node_cutoff, "energy_positron"));
×
631
    }
632
    if (check_for_node(node_cutoff, "time_neutron")) {
114✔
633
      time_cutoff[0] = std::stod(get_node_value(node_cutoff, "time_neutron"));
17✔
634
    }
635
    if (check_for_node(node_cutoff, "time_photon")) {
114✔
UNCOV
636
      time_cutoff[1] = std::stod(get_node_value(node_cutoff, "time_photon"));
×
637
    }
638
    if (check_for_node(node_cutoff, "time_electron")) {
114✔
UNCOV
639
      time_cutoff[2] = std::stod(get_node_value(node_cutoff, "time_electron"));
×
640
    }
641
    if (check_for_node(node_cutoff, "time_positron")) {
114✔
UNCOV
642
      time_cutoff[3] = std::stod(get_node_value(node_cutoff, "time_positron"));
×
643
    }
644
  }
645

646
  // Particle trace
647
  if (check_for_node(root, "trace")) {
6,857✔
648
    auto temp = get_node_array<int64_t>(root, "trace");
17✔
649
    if (temp.size() != 3) {
17✔
650
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
651
                  "batch, generation, and particle number.");
652
    }
653
    trace_batch = temp.at(0);
17✔
654
    trace_gen = temp.at(1);
17✔
655
    trace_particle = temp.at(2);
17✔
656
  }
17✔
657

658
  // Particle tracks
659
  if (check_for_node(root, "track")) {
6,857✔
660
    // Get values and make sure there are three per particle
661
    auto temp = get_node_array<int>(root, "track");
51✔
662
    if (temp.size() % 3 != 0) {
51✔
UNCOV
663
      fatal_error(
×
664
        "Number of integers specified in 'track' is not "
665
        "divisible by 3.  Please provide 3 integers per particle to be "
666
        "tracked.");
667
    }
668

669
    // Reshape into track_identifiers
670
    int n_tracks = temp.size() / 3;
51✔
671
    for (int i = 0; i < n_tracks; ++i) {
204✔
672
      track_identifiers.push_back(
153✔
673
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
153✔
674
    }
675
  }
51✔
676

677
  // Shannon entropy
678
  if (solver_type == SolverType::RANDOM_RAY) {
6,857✔
679
    if (check_for_node(root, "entropy_mesh")) {
357✔
UNCOV
680
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
681
                  "No user-defined entropy mesh is supported.");
682
    }
683
    entropy_on = true;
357✔
684
  } else if (solver_type == SolverType::MONTE_CARLO) {
6,500✔
685
    if (check_for_node(root, "entropy_mesh")) {
6,500✔
686
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
560✔
687
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
560✔
UNCOV
688
        fatal_error(fmt::format(
×
689
          "Mesh {} specified for Shannon entropy does not exist.", temp));
690
      }
691

692
      auto* m = dynamic_cast<RegularMesh*>(
560✔
693
        model::meshes[model::mesh_map.at(temp)].get());
560✔
694
      if (!m)
560✔
UNCOV
695
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
696
      simulation::entropy_mesh = m;
560✔
697

698
      // Turn on Shannon entropy calculation
699
      entropy_on = true;
560✔
700

701
    } else if (check_for_node(root, "entropy")) {
5,940✔
UNCOV
702
      fatal_error(
×
703
        "Specifying a Shannon entropy mesh via the <entropy> element "
704
        "is deprecated. Please create a mesh using <mesh> and then reference "
705
        "it by specifying its ID in an <entropy_mesh> element.");
706
    }
707
  }
708
  // Uniform fission source weighting mesh
709
  if (check_for_node(root, "ufs_mesh")) {
6,857✔
710
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
17✔
711
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
17✔
UNCOV
712
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
713
                              "method does not exist.",
714
        temp));
715
    }
716

717
    auto* m =
718
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
17✔
719
    if (!m)
17✔
UNCOV
720
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
721
    simulation::ufs_mesh = m;
17✔
722

723
    // Turn on uniform fission source weighting
724
    ufs_on = true;
17✔
725

726
  } else if (check_for_node(root, "uniform_fs")) {
6,840✔
UNCOV
727
    fatal_error(
×
728
      "Specifying a UFS mesh via the <uniform_fs> element "
729
      "is deprecated. Please create a mesh using <mesh> and then reference "
730
      "it by specifying its ID in a <ufs_mesh> element.");
731
  }
732

733
  // Check if the user has specified to write state points
734
  if (check_for_node(root, "state_point")) {
6,857✔
735

736
    // Get pointer to state_point node
737
    auto node_sp = root.child("state_point");
210✔
738

739
    // Determine number of batches at which to store state points
740
    if (check_for_node(node_sp, "batches")) {
210✔
741
      // User gave specific batches to write state points
742
      auto temp = get_node_array<int>(node_sp, "batches");
210✔
743
      for (const auto& b : temp) {
647✔
744
        statepoint_batch.insert(b);
437✔
745
      }
746
    } else {
210✔
747
      // If neither were specified, write state point at last batch
UNCOV
748
      statepoint_batch.insert(n_batches);
×
749
    }
750
  } else {
751
    // If no <state_point> tag was present, by default write state point at
752
    // last batch only
753
    statepoint_batch.insert(n_batches);
6,647✔
754
  }
755

756
  // Check if the user has specified to write source points
757
  if (check_for_node(root, "source_point")) {
6,857✔
758
    // Get source_point node
759
    xml_node node_sp = root.child("source_point");
102✔
760

761
    // Determine batches at which to store source points
762
    if (check_for_node(node_sp, "batches")) {
102✔
763
      // User gave specific batches to write source points
764
      auto temp = get_node_array<int>(node_sp, "batches");
51✔
765
      for (const auto& b : temp) {
136✔
766
        sourcepoint_batch.insert(b);
85✔
767
      }
768
    } else {
51✔
769
      // If neither were specified, write source points with state points
770
      sourcepoint_batch = statepoint_batch;
51✔
771
    }
772

773
    // Check if the user has specified to write binary source file
774
    if (check_for_node(node_sp, "separate")) {
102✔
775
      source_separate = get_node_value_bool(node_sp, "separate");
68✔
776
    }
777
    if (check_for_node(node_sp, "write")) {
102✔
UNCOV
778
      source_write = get_node_value_bool(node_sp, "write");
×
779
    }
780
    if (check_for_node(node_sp, "mcpl")) {
102✔
781
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
17✔
782

783
      // Make sure MCPL support is enabled
784
      if (source_mcpl_write && !MCPL_ENABLED) {
17✔
UNCOV
785
        fatal_error(
×
786
          "Your build of OpenMC does not support writing MCPL source files.");
787
      }
788
    }
789
    if (check_for_node(node_sp, "overwrite_latest")) {
102✔
790
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
17✔
791
      source_separate = source_latest;
17✔
792
    }
793
  } else {
794
    // If no <source_point> tag was present, by default we keep source bank in
795
    // statepoint file and write it out at statepoints intervals
796
    source_separate = false;
6,755✔
797
    sourcepoint_batch = statepoint_batch;
6,755✔
798
  }
799

800
  // Check is the user specified to convert strength to statistical weight
801
  if (check_for_node(root, "uniform_source_sampling")) {
6,857✔
802
    uniform_source_sampling =
60✔
803
      get_node_value_bool(root, "uniform_source_sampling");
60✔
804
  }
805

806
  // Check if the user has specified to write surface source
807
  if (check_for_node(root, "surf_source_write")) {
6,857✔
808
    surf_source_write = true;
439✔
809
    // Get surface source write node
810
    xml_node node_ssw = root.child("surf_source_write");
439✔
811

812
    // Determine surface ids at which crossing particles are to be banked.
813
    // If no surfaces are specified, all surfaces in the model will be used
814
    // to bank source points.
815
    if (check_for_node(node_ssw, "surface_ids")) {
439✔
816
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
209✔
817
      for (const auto& b : temp) {
1,065✔
818
        source_write_surf_id.insert(b);
856✔
819
      }
820
    }
209✔
821

822
    // Get maximum number of particles to be banked per surface
823
    if (check_for_node(node_ssw, "max_particles")) {
439✔
824
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
429✔
825
    } else {
826
      fatal_error("A maximum number of particles needs to be specified "
10✔
827
                  "using the 'max_particles' parameter to store surface "
828
                  "source points.");
829
    }
830

831
    // Get maximum number of surface source files to be created
832
    if (check_for_node(node_ssw, "max_source_files")) {
429✔
833
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
36✔
834
    } else {
835
      ssw_max_files = 1;
393✔
836
    }
837

838
    if (check_for_node(node_ssw, "mcpl")) {
429✔
UNCOV
839
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
×
840

841
      // Make sure MCPL support is enabled
UNCOV
842
      if (surf_mcpl_write && !MCPL_ENABLED) {
×
UNCOV
843
        fatal_error("Your build of OpenMC does not support writing MCPL "
×
844
                    "surface source files.");
845
      }
846
    }
847
    // Get cell information
848
    if (check_for_node(node_ssw, "cell")) {
429✔
849
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
114✔
850
      ssw_cell_type = SSWCellType::Both;
114✔
851
    }
852
    if (check_for_node(node_ssw, "cellfrom")) {
429✔
853
      if (ssw_cell_id != C_NONE) {
99✔
854
        fatal_error(
20✔
855
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
856
      }
857
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
79✔
858
      ssw_cell_type = SSWCellType::From;
79✔
859
    }
860
    if (check_for_node(node_ssw, "cellto")) {
409✔
861
      if (ssw_cell_id != C_NONE) {
78✔
862
        fatal_error(
20✔
863
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
864
      }
865
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
58✔
866
      ssw_cell_type = SSWCellType::To;
58✔
867
    }
868
  }
869

870
  // If source is not separate and is to be written out in the statepoint file,
871
  // make sure that the sourcepoint batch numbers are contained in the
872
  // statepoint list
873
  if (!source_separate) {
6,807✔
874
    for (const auto& b : sourcepoint_batch) {
13,620✔
875
      if (!contains(statepoint_batch, b)) {
6,898✔
UNCOV
876
        fatal_error(
×
877
          "Sourcepoint batches are not a subset of statepoint batches.");
878
      }
879
    }
880
  }
881

882
  // Check if the user has specified to not reduce tallies at the end of every
883
  // batch
884
  if (check_for_node(root, "no_reduce")) {
6,807✔
UNCOV
885
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
×
886
  }
887

888
  // Check if the user has specified to use confidence intervals for
889
  // uncertainties rather than standard deviations
890
  if (check_for_node(root, "confidence_intervals")) {
6,807✔
891
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
17✔
892
  }
893

894
  // Check for output options
895
  if (check_for_node(root, "output")) {
6,807✔
896
    // Get pointer to output node
897
    pugi::xml_node node_output = root.child("output");
397✔
898

899
    // Check for summary option
900
    if (check_for_node(node_output, "summary")) {
397✔
901
      output_summary = get_node_value_bool(node_output, "summary");
380✔
902
    }
903

904
    // Check for ASCII tallies output option
905
    if (check_for_node(node_output, "tallies")) {
397✔
906
      output_tallies = get_node_value_bool(node_output, "tallies");
17✔
907
    }
908

909
    // Set output directory if a path has been specified
910
    if (check_for_node(node_output, "path")) {
397✔
UNCOV
911
      path_output = get_node_value(node_output, "path");
×
912
      if (!ends_with(path_output, "/")) {
×
913
        path_output += "/";
×
914
      }
915
    }
916
  }
917

918
  // Resonance scattering parameters
919
  if (check_for_node(root, "resonance_scattering")) {
6,807✔
920
    xml_node node_res_scat = root.child("resonance_scattering");
17✔
921

922
    // See if resonance scattering is enabled
923
    if (check_for_node(node_res_scat, "enable")) {
17✔
924
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
17✔
925
    } else {
UNCOV
926
      res_scat_on = true;
×
927
    }
928

929
    // Determine what method is used
930
    if (check_for_node(node_res_scat, "method")) {
17✔
931
      auto temp = get_node_value(node_res_scat, "method", true, true);
17✔
932
      if (temp == "rvs") {
17✔
933
        res_scat_method = ResScatMethod::rvs;
17✔
UNCOV
934
      } else if (temp == "dbrc") {
×
UNCOV
935
        res_scat_method = ResScatMethod::dbrc;
×
936
      } else {
UNCOV
937
        fatal_error(
×
UNCOV
938
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
939
      }
940
    }
17✔
941

942
    // Minimum energy for resonance scattering
943
    if (check_for_node(node_res_scat, "energy_min")) {
17✔
944
      res_scat_energy_min =
17✔
945
        std::stod(get_node_value(node_res_scat, "energy_min"));
17✔
946
    }
947
    if (res_scat_energy_min < 0.0) {
17✔
UNCOV
948
      fatal_error("Lower resonance scattering energy bound is negative");
×
949
    }
950

951
    // Maximum energy for resonance scattering
952
    if (check_for_node(node_res_scat, "energy_max")) {
17✔
953
      res_scat_energy_max =
17✔
954
        std::stod(get_node_value(node_res_scat, "energy_max"));
17✔
955
    }
956
    if (res_scat_energy_max < res_scat_energy_min) {
17✔
UNCOV
957
      fatal_error("Upper resonance scattering energy bound is below the "
×
958
                  "lower resonance scattering energy bound.");
959
    }
960

961
    // Get resonance scattering nuclides
962
    if (check_for_node(node_res_scat, "nuclides")) {
17✔
963
      res_scat_nuclides =
964
        get_node_array<std::string>(node_res_scat, "nuclides");
17✔
965
    }
966
  }
967

968
  // Get volume calculations
969
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
7,156✔
970
    model::volume_calcs.emplace_back(node_vol);
349✔
971
  }
972

973
  // Get temperature settings
974
  if (check_for_node(root, "temperature_default")) {
6,807✔
975
    temperature_default =
187✔
976
      std::stod(get_node_value(root, "temperature_default"));
187✔
977
  }
978
  if (check_for_node(root, "temperature_method")) {
6,807✔
979
    auto temp = get_node_value(root, "temperature_method", true, true);
350✔
980
    if (temp == "nearest") {
350✔
981
      temperature_method = TemperatureMethod::NEAREST;
150✔
982
    } else if (temp == "interpolation") {
200✔
983
      temperature_method = TemperatureMethod::INTERPOLATION;
200✔
984
    } else {
NEW
985
      fatal_error("Unknown temperature method: " + temp);
×
986
    }
987
  }
350✔
988
  if (check_for_node(root, "temperature_tolerance")) {
6,807✔
989
    temperature_tolerance =
186✔
990
      std::stod(get_node_value(root, "temperature_tolerance"));
186✔
991
  }
992
  if (check_for_node(root, "temperature_multipole")) {
6,807✔
993
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
34✔
994

995
    // Multipole currently doesn't work with photon transport
996
    if (temperature_multipole && photon_transport) {
34✔
NEW
997
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
998
                  "photon transport.");
999
    }
1000
  }
1001
  if (check_for_node(root, "temperature_range")) {
6,807✔
NEW
1002
    auto range = get_node_array<double>(root, "temperature_range");
×
NEW
1003
    temperature_range[0] = range.at(0);
×
NEW
1004
    temperature_range[1] = range.at(1);
×
1005
  }
1006

1007
  // Check for Iterated Fission Probability (IFP)
1008
  if (check_for_node(root, "iterated_fission_probability")) {
6,807✔
1009

1010
    // IFP only works with eigenvalue calculations
1011
    if (run_mode == RunMode::EIGENVALUE) {
37✔
1012
      ifp = true;
27✔
1013
      // Get iterated_fission_probability write node
1014
      xml_node node_ifp = root.child("iterated_fission_probability");
27✔
1015

1016
      // Parameter to compute
1017
      if (check_for_node(node_ifp, "parameter")) {
27✔
1018
        std::string temp_str =
1019
          get_node_value(node_ifp, "parameter", true, true);
17✔
1020
        if (temp_str == "beta_effective") {
17✔
NEW
1021
          ifp_parameter = IFPParameter::BetaEffective;
×
1022
        } else if (temp_str == "generation_time") {
17✔
NEW
1023
          ifp_parameter = IFPParameter::GenerationTime;
×
1024
        } else if (temp_str == "both") {
17✔
1025
          ifp_parameter = IFPParameter::Both;
17✔
1026
        } else {
NEW
1027
          fatal_error("Unrecognized parameter for IFP: " + temp_str);
×
1028
        }
1029
      } else {
17✔
1030
        fatal_error("<parameter> should be declared for ifp.");
10✔
1031
      }
1032

1033
      // Number of generation
1034
      if (check_for_node(node_ifp, "n_generation")) {
17✔
1035
        ifp_n_generation = std::stoi(get_node_value(node_ifp, "n_generation"));
17✔
1036
        if (ifp_n_generation <= 0) {
17✔
UNCOV
1037
          fatal_error("<n_generation> must be greater than 0.");
×
1038
        }
1039
        // Avoid tallying 0 if IFP logs are not complete when active cycles
1040
        // start
1041
        if (ifp_n_generation > n_inactive) {
17✔
UNCOV
1042
          fatal_error("<n_generation> must be lower than or equal to the "
×
1043
                      "number of inactive cycles.");
1044
        }
1045
      } else {
1046
        fatal_error("<n_generation> must be specified as a subelement of "
×
1047
                    "<iterated_fission_probability>.");
1048
      }
1049
    } else {
1050
      fatal_error(
10✔
1051
        "Iterated Fission Probability can only be used in an eigenvalue "
1052
        "calculation.");
1053
    }
1054
  }
1055

1056
  // Check for tabular_legendre options
1057
  if (check_for_node(root, "tabular_legendre")) {
6,787✔
1058
    // Get pointer to tabular_legendre node
1059
    xml_node node_tab_leg = root.child("tabular_legendre");
102✔
1060

1061
    // Check for enable option
1062
    if (check_for_node(node_tab_leg, "enable")) {
102✔
1063
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
102✔
1064
    }
1065

1066
    // Check for the number of points
1067
    if (check_for_node(node_tab_leg, "num_points")) {
102✔
UNCOV
1068
      legendre_to_tabular_points =
×
1069
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
1070
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
UNCOV
1071
        fatal_error(
×
1072
          "The 'num_points' subelement/attribute of the "
1073
          "<tabular_legendre> element must contain a value greater than 1");
1074
      }
1075
    }
1076
  }
1077

1078
  // Check whether create delayed neutrons in fission
1079
  if (check_for_node(root, "create_delayed_neutrons")) {
6,787✔
1080
    create_delayed_neutrons =
×
UNCOV
1081
      get_node_value_bool(root, "create_delayed_neutrons");
×
1082
  }
1083

1084
  // Check whether create fission sites
1085
  if (run_mode == RunMode::FIXED_SOURCE) {
6,787✔
1086
    if (check_for_node(root, "create_fission_neutrons")) {
2,090✔
1087
      create_fission_neutrons =
17✔
1088
        get_node_value_bool(root, "create_fission_neutrons");
17✔
1089
    }
1090
  }
1091

1092
  // Check whether to scale fission photon yields
1093
  if (check_for_node(root, "delayed_photon_scaling")) {
6,787✔
UNCOV
1094
    delayed_photon_scaling =
×
1095
      get_node_value_bool(root, "delayed_photon_scaling");
×
1096
  }
1097

1098
  // Check whether to use event-based parallelism
1099
  if (check_for_node(root, "event_based")) {
6,787✔
UNCOV
1100
    event_based = get_node_value_bool(root, "event_based");
×
1101
  }
1102

1103
  // Check whether material cell offsets should be generated
1104
  if (check_for_node(root, "material_cell_offsets")) {
6,787✔
UNCOV
1105
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1106
  }
1107

1108
  // Weight window information
1109
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
6,860✔
1110
    variance_reduction::weight_windows.emplace_back(
73✔
1111
      std::make_unique<WeightWindows>(node_ww));
146✔
1112
  }
1113

1114
  // Enable weight windows by default if one or more are present
1115
  if (variance_reduction::weight_windows.size() > 0)
6,787✔
1116
    settings::weight_windows_on = true;
44✔
1117

1118
  // read weight windows from file
1119
  if (check_for_node(root, "weight_windows_file")) {
6,787✔
UNCOV
1120
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1121
  }
1122

1123
  // read settings for weight windows value, this will override
1124
  // the automatic setting even if weight windows are present
1125
  if (check_for_node(root, "weight_windows_on")) {
6,787✔
1126
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
27✔
1127
  }
1128

1129
  if (check_for_node(root, "max_history_splits")) {
6,787✔
1130
    settings::max_history_splits =
233✔
1131
      std::stoi(get_node_value(root, "max_history_splits"));
233✔
1132
  }
1133

1134
  if (check_for_node(root, "max_tracks")) {
6,787✔
1135
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
51✔
1136
  }
1137

1138
  // Create weight window generator objects
1139
  if (check_for_node(root, "weight_window_generators")) {
6,787✔
1140
    auto wwgs_node = root.child("weight_window_generators");
24✔
1141
    for (pugi::xml_node node_wwg :
24✔
1142
      wwgs_node.children("weight_windows_generator")) {
72✔
1143
      variance_reduction::weight_windows_generators.emplace_back(
24✔
1144
        std::make_unique<WeightWindowsGenerator>(node_wwg));
48✔
1145
    }
1146
    // if any of the weight windows are intended to be generated otf, make sure
1147
    // they're applied
1148
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
24✔
1149
      if (wwg->on_the_fly_) {
24✔
1150
        settings::weight_windows_on = true;
24✔
1151
        break;
24✔
1152
      }
1153
    }
1154
  }
1155

1156
  // Set up weight window checkpoints
1157
  if (check_for_node(root, "weight_window_checkpoints")) {
6,787✔
UNCOV
1158
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
×
UNCOV
1159
    if (check_for_node(ww_checkpoints, "collision")) {
×
UNCOV
1160
      weight_window_checkpoint_collision =
×
UNCOV
1161
        get_node_value_bool(ww_checkpoints, "collision");
×
1162
    }
UNCOV
1163
    if (check_for_node(ww_checkpoints, "surface")) {
×
UNCOV
1164
      weight_window_checkpoint_surface =
×
UNCOV
1165
        get_node_value_bool(ww_checkpoints, "surface");
×
1166
    }
1167
  }
1168
}
6,787✔
1169

1170
void free_memory_settings()
6,931✔
1171
{
1172
  settings::statepoint_batch.clear();
6,931✔
1173
  settings::sourcepoint_batch.clear();
6,931✔
1174
  settings::source_write_surf_id.clear();
6,931✔
1175
  settings::res_scat_nuclides.clear();
6,931✔
1176
}
6,931✔
1177

1178
//==============================================================================
1179
// C API functions
1180
//==============================================================================
1181

1182
extern "C" int openmc_set_n_batches(
60✔
1183
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
1184
{
1185
  if (settings::n_inactive >= n_batches) {
60✔
1186
    set_errmsg("Number of active batches must be greater than zero.");
12✔
1187
    return OPENMC_E_INVALID_ARGUMENT;
12✔
1188
  }
1189

1190
  if (simulation::current_batch >= n_batches) {
48✔
1191
    set_errmsg("Number of batches must be greater than current batch.");
12✔
1192
    return OPENMC_E_INVALID_ARGUMENT;
12✔
1193
  }
1194

1195
  if (!settings::trigger_on) {
36✔
1196
    // Set n_batches and n_max_batches to same value
1197
    settings::n_batches = n_batches;
12✔
1198
    settings::n_max_batches = n_batches;
12✔
1199
  } else {
1200
    // Set n_batches and n_max_batches based on value of set_max_batches
1201
    if (set_max_batches) {
24✔
1202
      settings::n_max_batches = n_batches;
12✔
1203
    } else {
1204
      settings::n_batches = n_batches;
12✔
1205
    }
1206
  }
1207

1208
  // Update size of k_generation and entropy
1209
  int m = settings::n_max_batches * settings::gen_per_batch;
36✔
1210
  simulation::k_generation.reserve(m);
36✔
1211
  simulation::entropy.reserve(m);
36✔
1212

1213
  // Add value of n_batches to statepoint_batch
1214
  if (add_statepoint_batch &&
60✔
1215
      !(contains(settings::statepoint_batch, n_batches)))
24✔
1216
    settings::statepoint_batch.insert(n_batches);
24✔
1217

1218
  return 0;
36✔
1219
}
1220

1221
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
5,685✔
1222
{
1223
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
5,685✔
1224

1225
  return 0;
5,685✔
1226
}
1227

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