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

openmc-dev / openmc / 13690911561

06 Mar 2025 04:01AM UTC coverage: 85.295% (+0.3%) from 85.042%
13690911561

Pull #3333

github

web-flow
Merge 5a02f7edf into 557b714d8
Pull Request #3333: Random Ray Source Region Mesh Subdivision (Cell-Under-Voxel Geometry)

585 of 659 new or added lines in 12 files covered. (88.77%)

386 existing lines in 16 files now uncovered.

51770 of 60695 relevant lines covered (85.3%)

36974725.8 hits per line

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

79.75
/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/constants.h"
15
#include "openmc/container_util.h"
16
#include "openmc/distribution.h"
17
#include "openmc/distribution_multi.h"
18
#include "openmc/distribution_spatial.h"
19
#include "openmc/eigenvalue.h"
20
#include "openmc/error.h"
21
#include "openmc/file_utils.h"
22
#include "openmc/mcpl_interface.h"
23
#include "openmc/mesh.h"
24
#include "openmc/message_passing.h"
25
#include "openmc/output.h"
26
#include "openmc/plot.h"
27
#include "openmc/random_lcg.h"
28
#include "openmc/random_ray/random_ray.h"
29
#include "openmc/simulation.h"
30
#include "openmc/source.h"
31
#include "openmc/string_utils.h"
32
#include "openmc/tallies/trigger.h"
33
#include "openmc/volume_calc.h"
34
#include "openmc/weight_windows.h"
35
#include "openmc/xml_interface.h"
36

37
namespace openmc {
38

39
//==============================================================================
40
// Global variables
41
//==============================================================================
42

43
namespace settings {
44

45
// Default values for boolean flags
46
bool assume_separate {false};
47
bool check_overlaps {false};
48
bool cmfd_run {false};
49
bool confidence_intervals {false};
50
bool create_delayed_neutrons {true};
51
bool create_fission_neutrons {true};
52
bool delayed_photon_scaling {true};
53
bool entropy_on {false};
54
bool event_based {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 use_decay_photons {false};
80
bool weight_windows_on {false};
81
bool weight_window_checkpoint_surface {false};
82
bool weight_window_checkpoint_collision {true};
83
bool write_all_tracks {false};
84
bool write_initial_source {false};
85

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

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

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

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

141
} // namespace settings
142

143
//==============================================================================
144
// Functions
145
//==============================================================================
146

147
void get_run_parameters(pugi::xml_node node_base)
5,875✔
148
{
149
  using namespace settings;
150
  using namespace pugi;
151

152
  // Check number of particles
153
  if (!check_for_node(node_base, "particles")) {
5,875✔
154
    fatal_error("Need to specify number of particles.");
×
155
  }
156

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

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

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

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

181
  // Get max number of lost particles
182
  if (check_for_node(node_base, "max_lost_particles")) {
5,875✔
183
    max_lost_particles =
16✔
184
      std::stoi(get_node_value(node_base, "max_lost_particles"));
16✔
185
  }
186

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

193
  // Get relative number of lost particles
194
  if (check_for_node(node_base, "max_write_lost_particles")) {
5,875✔
195
    max_write_lost_particles =
16✔
196
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
16✔
197
  }
198

199
  // Get number of inactive batches
200
  if (run_mode == RunMode::EIGENVALUE ||
5,875✔
201
      solver_type == SolverType::RANDOM_RAY) {
2,175✔
202
    if (check_for_node(node_base, "inactive")) {
4,068✔
203
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
3,982✔
204
    }
205
    if (check_for_node(node_base, "generations_per_batch")) {
4,068✔
206
      gen_per_batch =
16✔
207
        std::stoi(get_node_value(node_base, "generations_per_batch"));
16✔
208
    }
209

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

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

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

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

246
  // Random ray variables
247
  if (solver_type == SolverType::RANDOM_RAY) {
5,875✔
248
    xml_node random_ray_node = node_base.child("random_ray");
480✔
249
    if (check_for_node(random_ray_node, "distance_active")) {
480✔
250
      RandomRay::distance_active_ =
480✔
251
        std::stod(get_node_value(random_ray_node, "distance_active"));
480✔
252
      if (RandomRay::distance_active_ <= 0.0) {
480✔
253
        fatal_error("Random ray active distance must be greater than 0");
×
254
      }
255
    } else {
256
      fatal_error("Specify random ray active distance in settings XML");
×
257
    }
258
    if (check_for_node(random_ray_node, "distance_inactive")) {
480✔
259
      RandomRay::distance_inactive_ =
480✔
260
        std::stod(get_node_value(random_ray_node, "distance_inactive"));
480✔
261
      if (RandomRay::distance_inactive_ < 0) {
480✔
262
        fatal_error(
×
263
          "Random ray inactive distance must be greater than or equal to 0");
264
      }
265
    } else {
266
      fatal_error("Specify random ray inactive distance in settings XML");
×
267
    }
268
    if (check_for_node(random_ray_node, "source")) {
480✔
269
      xml_node source_node = random_ray_node.child("source");
480✔
270
      // Get point to list of <source> elements and make sure there is at least
271
      // one
272
      RandomRay::ray_source_ = Source::create(source_node);
480✔
273
    } else {
274
      fatal_error("Specify random ray source in settings XML");
×
275
    }
276
    if (check_for_node(random_ray_node, "volume_estimator")) {
480✔
277
      std::string temp_str =
278
        get_node_value(random_ray_node, "volume_estimator", true, true);
128✔
279
      if (temp_str == "simulation_averaged") {
128✔
280
        FlatSourceDomain::volume_estimator_ =
32✔
281
          RandomRayVolumeEstimator::SIMULATION_AVERAGED;
282
      } else if (temp_str == "naive") {
96✔
283
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::NAIVE;
64✔
284
      } else if (temp_str == "hybrid") {
32✔
285
        FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::HYBRID;
32✔
286
      } else {
287
        fatal_error("Unrecognized volume estimator: " + temp_str);
×
288
      }
289
    }
128✔
290
    if (check_for_node(random_ray_node, "source_shape")) {
480✔
291
      std::string temp_str =
292
        get_node_value(random_ray_node, "source_shape", true, true);
240✔
293
      if (temp_str == "flat") {
240✔
294
        RandomRay::source_shape_ = RandomRaySourceShape::FLAT;
64✔
295
      } else if (temp_str == "linear") {
176✔
296
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR;
128✔
297
      } else if (temp_str == "linear_xy") {
48✔
298
        RandomRay::source_shape_ = RandomRaySourceShape::LINEAR_XY;
48✔
299
      } else {
300
        fatal_error("Unrecognized source shape: " + temp_str);
×
301
      }
302
    }
240✔
303
    if (check_for_node(random_ray_node, "volume_normalized_flux_tallies")) {
480✔
304
      FlatSourceDomain::volume_normalized_flux_tallies_ =
464✔
305
        get_node_value_bool(random_ray_node, "volume_normalized_flux_tallies");
464✔
306
    }
307
    if (check_for_node(random_ray_node, "adjoint")) {
480✔
308
      FlatSourceDomain::adjoint_ =
32✔
309
        get_node_value_bool(random_ray_node, "adjoint");
32✔
310
    }
311
    if (check_for_node(random_ray_node, "sample_method")) {
480✔
312
      std::string temp_str =
313
        get_node_value(random_ray_node, "sample_method", true, true);
16✔
314
      if (temp_str == "prng") {
16✔
315
        RandomRay::sample_method_ = RandomRaySampleMethod::PRNG;
×
316
      } else if (temp_str == "halton") {
16✔
317
        RandomRay::sample_method_ = RandomRaySampleMethod::HALTON;
16✔
318
      } else {
319
        fatal_error("Unrecognized sample method: " + temp_str);
×
320
      }
321
    }
16✔
322
    if (check_for_node(random_ray_node, "source_region_meshes")) {
480✔
323
      pugi::xml_node node_source_region_meshes =
324
        random_ray_node.child("source_region_meshes");
80✔
325
      for (pugi::xml_node node_mesh :
80✔
326
        node_source_region_meshes.children("mesh")) {
304✔
327
        int mesh_id = std::stoi(node_mesh.attribute("id").value());
144✔
328
        for (pugi::xml_node node_domain : node_mesh.children("domain")) {
288✔
329
          int domain_id = std::stoi(node_domain.attribute("id").value());
144✔
330
          std::string domain_type = node_domain.attribute("type").value();
144✔
331
          Source::DomainType type;
332
          if (domain_type == "material") {
144✔
333
            type = Source::DomainType::MATERIAL;
32✔
334
          } else if (domain_type == "cell") {
112✔
335
            type = Source::DomainType::CELL;
32✔
336
          } else if (domain_type == "universe") {
80✔
337
            type = Source::DomainType::UNIVERSE;
80✔
338
          } else {
NEW
339
            throw std::runtime_error("Unknown domain type: " + domain_type);
×
340
          }
341
          FlatSourceDomain::mesh_domain_map_[mesh_id].emplace_back(
144✔
342
            type, domain_id);
343
          RandomRay::mesh_subdivision_enabled_ = true;
144✔
344
        }
144✔
345
      }
346
    }
347
  }
348
}
5,875✔
349

350
void read_settings_xml()
1,334✔
351
{
352
  using namespace settings;
353
  using namespace pugi;
354
  // Check if settings.xml exists
355
  std::string filename = settings::path_input + "settings.xml";
1,334✔
356
  if (!file_exists(filename)) {
1,334✔
357
    if (run_mode != RunMode::PLOTTING) {
22✔
358
      fatal_error("Could not find any XML input files! In order to run OpenMC, "
×
359
                  "you first need a set of input files; at a minimum, this "
360
                  "includes settings.xml, geometry.xml, and materials.xml or a "
361
                  "single model XML file. Please consult the user's guide at "
362
                  "https://docs.openmc.org for further information.");
363
    } else {
364
      // The settings.xml file is optional if we just want to make a plot.
365
      return;
22✔
366
    }
367
  }
368

369
  // Parse settings.xml file
370
  xml_document doc;
1,312✔
371
  auto result = doc.load_file(filename.c_str());
1,312✔
372
  if (!result) {
1,312✔
373
    fatal_error("Error processing settings.xml file.");
×
374
  }
375

376
  // Get root element
377
  xml_node root = doc.document_element();
1,312✔
378

379
  // Verbosity
380
  if (check_for_node(root, "verbosity")) {
1,312✔
381
    verbosity = std::stoi(get_node_value(root, "verbosity"));
188✔
382
  }
383

384
  // To this point, we haven't displayed any output since we didn't know what
385
  // the verbosity is. Now that we checked for it, show the title if necessary
386
  if (mpi::master) {
1,312✔
387
    if (verbosity >= 2)
1,082✔
388
      title();
904✔
389
  }
390

391
  write_message("Reading settings XML file...", 5);
1,312✔
392

393
  read_settings_xml(root);
1,312✔
394
}
1,324✔
395

396
void read_settings_xml(pugi::xml_node root)
6,394✔
397
{
398
  using namespace settings;
399
  using namespace pugi;
400

401
  // Find if a multi-group or continuous-energy simulation is desired
402
  if (check_for_node(root, "energy_mode")) {
6,394✔
403
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
1,014✔
404
    if (temp_str == "mg" || temp_str == "multi-group") {
1,014✔
405
      run_CE = false;
1,014✔
406
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
407
      run_CE = true;
×
408
    }
409
  }
1,014✔
410

411
  // Check for user meshes and allocate
412
  read_meshes(root);
6,394✔
413

414
  // Look for deprecated cross_sections.xml file in settings.xml
415
  if (check_for_node(root, "cross_sections")) {
6,394✔
416
    warning(
×
417
      "Setting cross_sections in settings.xml has been deprecated."
418
      " The cross_sections are now set in materials.xml and the "
419
      "cross_sections input to materials.xml and the OPENMC_CROSS_SECTIONS"
420
      " environment variable will take precendent over setting "
421
      "cross_sections in settings.xml.");
422
    path_cross_sections = get_node_value(root, "cross_sections");
×
423
  }
424

425
  if (!run_CE) {
6,394✔
426
    // Scattering Treatments
427
    if (check_for_node(root, "max_order")) {
1,014✔
428
      max_order = std::stoi(get_node_value(root, "max_order"));
16✔
429
    } else {
430
      // Set to default of largest int - 1, which means to use whatever is
431
      // contained in library. This is largest int - 1 because for legendre
432
      // scattering, a value of 1 is added to the order; adding 1 to the largest
433
      // int gets you the largest negative integer, which is not what we want.
434
      max_order = std::numeric_limits<int>::max() - 1;
998✔
435
    }
436
  }
437

438
  // Check for a trigger node and get trigger information
439
  if (check_for_node(root, "trigger")) {
6,394✔
440
    xml_node node_trigger = root.child("trigger");
162✔
441

442
    // Check if trigger(s) are to be turned on
443
    trigger_on = get_node_value_bool(node_trigger, "active");
162✔
444

445
    if (trigger_on) {
162✔
446
      if (check_for_node(node_trigger, "max_batches")) {
146✔
447
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
146✔
448
      } else {
449
        fatal_error("<max_batches> must be specified with triggers");
×
450
      }
451

452
      // Get the batch interval to check triggers
453
      if (!check_for_node(node_trigger, "batch_interval")) {
146✔
454
        trigger_predict = true;
16✔
455
      } else {
456
        trigger_batch_interval =
130✔
457
          std::stoi(get_node_value(node_trigger, "batch_interval"));
130✔
458
        if (trigger_batch_interval <= 0) {
130✔
459
          fatal_error("Trigger batch interval must be greater than zero");
×
460
        }
461
      }
462
    }
463
  }
464

465
  // Check run mode if it hasn't been set from the command line
466
  xml_node node_mode;
6,394✔
467
  if (run_mode == RunMode::UNSET) {
6,394✔
468
    if (check_for_node(root, "run_mode")) {
5,907✔
469
      std::string temp_str = get_node_value(root, "run_mode", true, true);
5,843✔
470
      if (temp_str == "eigenvalue") {
5,843✔
471
        run_mode = RunMode::EIGENVALUE;
3,636✔
472
      } else if (temp_str == "fixed source") {
2,207✔
473
        run_mode = RunMode::FIXED_SOURCE;
2,175✔
474
      } else if (temp_str == "plot") {
32✔
475
        run_mode = RunMode::PLOTTING;
×
476
      } else if (temp_str == "particle restart") {
32✔
477
        run_mode = RunMode::PARTICLE;
×
478
      } else if (temp_str == "volume") {
32✔
479
        run_mode = RunMode::VOLUME;
32✔
480
      } else {
481
        fatal_error("Unrecognized run mode: " + temp_str);
×
482
      }
483

484
      // Assume XML specifies <particles>, <batches>, etc. directly
485
      node_mode = root;
5,843✔
486
    } else {
5,843✔
487
      warning("<run_mode> should be specified.");
64✔
488

489
      // Make sure that either eigenvalue or fixed source was specified
490
      node_mode = root.child("eigenvalue");
64✔
491
      if (node_mode) {
64✔
492
        run_mode = RunMode::EIGENVALUE;
64✔
493
      } else {
494
        node_mode = root.child("fixed_source");
×
495
        if (node_mode) {
×
496
          run_mode = RunMode::FIXED_SOURCE;
×
497
        } else {
498
          fatal_error("<eigenvalue> or <fixed_source> not specified.");
×
499
        }
500
      }
501
    }
502
  }
503

504
  // Check solver type
505
  if (check_for_node(root, "random_ray")) {
6,394✔
506
    solver_type = SolverType::RANDOM_RAY;
480✔
507
    if (run_CE)
480✔
508
      fatal_error("multi-group energy mode must be specified in settings XML "
×
509
                  "when using the random ray solver.");
510
  }
511

512
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
6,394✔
513
    // Read run parameters
514
    get_run_parameters(node_mode);
5,875✔
515

516
    // Check number of active batches, inactive batches, max lost particles and
517
    // particles
518
    if (n_batches <= n_inactive) {
5,875✔
519
      fatal_error("Number of active batches must be greater than zero.");
×
520
    } else if (n_inactive < 0) {
5,875✔
521
      fatal_error("Number of inactive batches must be non-negative.");
×
522
    } else if (n_particles <= 0) {
5,875✔
523
      fatal_error("Number of particles must be greater than zero.");
×
524
    } else if (max_lost_particles <= 0) {
5,875✔
525
      fatal_error("Number of max lost particles must be greater than zero.");
×
526
    } else if (rel_max_lost_particles <= 0.0 || rel_max_lost_particles >= 1.0) {
5,875✔
527
      fatal_error("Relative max lost particles must be between zero and one.");
×
528
    }
529
  }
530

531
  // Copy plotting random number seed if specified
532
  if (check_for_node(root, "plot_seed")) {
6,394✔
533
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
534
    model::plotter_seed = seed;
×
535
  }
536

537
  // Copy random number seed if specified
538
  if (check_for_node(root, "seed")) {
6,394✔
539
    auto seed = std::stoll(get_node_value(root, "seed"));
402✔
540
    openmc_set_seed(seed);
402✔
541
  }
542

543
  // Copy random number stride if specified
544
  if (check_for_node(root, "stride")) {
6,394✔
545
    auto stride = std::stoull(get_node_value(root, "stride"));
16✔
546
    openmc_set_stride(stride);
16✔
547
  }
548

549
  // Check for electron treatment
550
  if (check_for_node(root, "electron_treatment")) {
6,394✔
551
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
48✔
552
    if (temp_str == "led") {
48✔
UNCOV
553
      electron_treatment = ElectronTreatment::LED;
×
554
    } else if (temp_str == "ttb") {
48✔
555
      electron_treatment = ElectronTreatment::TTB;
48✔
556
    } else {
UNCOV
557
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
558
    }
559
  }
48✔
560

561
  // Check for photon transport
562
  if (check_for_node(root, "photon_transport")) {
6,394✔
563
    photon_transport = get_node_value_bool(root, "photon_transport");
188✔
564

565
    if (!run_CE && photon_transport) {
188✔
UNCOV
566
      fatal_error("Photon transport is not currently supported in "
×
567
                  "multigroup mode");
568
    }
569
  }
570

571
  // Number of bins for logarithmic grid
572
  if (check_for_node(root, "log_grid_bins")) {
6,394✔
573
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
16✔
574
    if (n_log_bins < 1) {
16✔
UNCOV
575
      fatal_error("Number of bins for logarithmic grid must be greater "
×
576
                  "than zero.");
577
    }
578
  }
579

580
  // Number of OpenMP threads
581
  if (check_for_node(root, "threads")) {
6,394✔
UNCOV
582
    if (mpi::master)
×
UNCOV
583
      warning("The <threads> element has been deprecated. Use "
×
584
              "the OMP_NUM_THREADS environment variable to set the number of "
585
              "threads.");
586
  }
587

588
  // ==========================================================================
589
  // EXTERNAL SOURCE
590

591
  // Get point to list of <source> elements and make sure there is at least one
592
  for (pugi::xml_node node : root.children("source")) {
12,526✔
593
    model::external_sources.push_back(Source::create(node));
6,142✔
594
  }
595

596
  // Check if the user has specified to read surface source
597
  if (check_for_node(root, "surf_source_read")) {
6,384✔
598
    surf_source_read = true;
16✔
599
    // Get surface source read node
600
    xml_node node_ssr = root.child("surf_source_read");
16✔
601

602
    std::string path = "surface_source.h5";
16✔
603
    // Check if the user has specified different file for surface source reading
604
    if (check_for_node(node_ssr, "path")) {
16✔
605
      path = get_node_value(node_ssr, "path", false, true);
16✔
606
    }
607
    model::external_sources.push_back(make_unique<FileSource>(path));
16✔
608
  }
16✔
609

610
  // Build probability mass function for sampling external sources
611
  vector<double> source_strengths;
6,384✔
612
  for (auto& s : model::external_sources) {
12,532✔
613
    source_strengths.push_back(s->strength());
6,148✔
614
  }
615
  model::external_sources_probability.assign(source_strengths);
6,384✔
616

617
  // If no source specified, default to isotropic point source at origin with
618
  // Watt spectrum. No default source is needed in random ray mode.
619
  if (model::external_sources.empty() &&
8,041✔
620
      settings::solver_type != SolverType::RANDOM_RAY) {
1,657✔
621
    double T[] {0.0};
1,545✔
622
    double p[] {1.0};
1,545✔
623
    model::external_sources.push_back(make_unique<IndependentSource>(
1,545✔
624
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
3,090✔
625
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
3,090✔
626
      UPtrDist {new Discrete(T, p, 1)}));
3,090✔
627
  }
628

629
  // Check if we want to write out source
630
  if (check_for_node(root, "write_initial_source")) {
6,384✔
UNCOV
631
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
632
  }
633

634
  // Survival biasing
635
  if (check_for_node(root, "survival_biasing")) {
6,384✔
636
    survival_biasing = get_node_value_bool(root, "survival_biasing");
175✔
637
  }
638

639
  // Probability tables
640
  if (check_for_node(root, "ptables")) {
6,384✔
641
    urr_ptables_on = get_node_value_bool(root, "ptables");
16✔
642
  }
643

644
  // Cutoffs
645
  if (check_for_node(root, "cutoff")) {
6,384✔
646
    xml_node node_cutoff = root.child("cutoff");
107✔
647
    if (check_for_node(node_cutoff, "weight")) {
107✔
648
      weight_cutoff = std::stod(get_node_value(node_cutoff, "weight"));
16✔
649
    }
650
    if (check_for_node(node_cutoff, "weight_avg")) {
107✔
651
      weight_survive = std::stod(get_node_value(node_cutoff, "weight_avg"));
16✔
652
    }
653
    if (check_for_node(node_cutoff, "energy_neutron")) {
107✔
654
      energy_cutoff[0] =
32✔
655
        std::stod(get_node_value(node_cutoff, "energy_neutron"));
16✔
656
    } else if (check_for_node(node_cutoff, "energy")) {
91✔
UNCOV
657
      warning("The use of an <energy> cutoff is deprecated and should "
×
658
              "be replaced by <energy_neutron>.");
UNCOV
659
      energy_cutoff[0] = std::stod(get_node_value(node_cutoff, "energy"));
×
660
    }
661
    if (check_for_node(node_cutoff, "energy_photon")) {
107✔
662
      energy_cutoff[1] =
118✔
663
        std::stod(get_node_value(node_cutoff, "energy_photon"));
59✔
664
    }
665
    if (check_for_node(node_cutoff, "energy_electron")) {
107✔
UNCOV
666
      energy_cutoff[2] =
×
UNCOV
667
        std::stof(get_node_value(node_cutoff, "energy_electron"));
×
668
    }
669
    if (check_for_node(node_cutoff, "energy_positron")) {
107✔
UNCOV
670
      energy_cutoff[3] =
×
671
        std::stod(get_node_value(node_cutoff, "energy_positron"));
×
672
    }
673
    if (check_for_node(node_cutoff, "time_neutron")) {
107✔
674
      time_cutoff[0] = std::stod(get_node_value(node_cutoff, "time_neutron"));
16✔
675
    }
676
    if (check_for_node(node_cutoff, "time_photon")) {
107✔
677
      time_cutoff[1] = std::stod(get_node_value(node_cutoff, "time_photon"));
×
678
    }
679
    if (check_for_node(node_cutoff, "time_electron")) {
107✔
UNCOV
680
      time_cutoff[2] = std::stod(get_node_value(node_cutoff, "time_electron"));
×
681
    }
682
    if (check_for_node(node_cutoff, "time_positron")) {
107✔
UNCOV
683
      time_cutoff[3] = std::stod(get_node_value(node_cutoff, "time_positron"));
×
684
    }
685
  }
686

687
  // Particle trace
688
  if (check_for_node(root, "trace")) {
6,384✔
689
    auto temp = get_node_array<int64_t>(root, "trace");
16✔
690
    if (temp.size() != 3) {
16✔
UNCOV
691
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
692
                  "batch, generation, and particle number.");
693
    }
694
    trace_batch = temp.at(0);
16✔
695
    trace_gen = temp.at(1);
16✔
696
    trace_particle = temp.at(2);
16✔
697
  }
16✔
698

699
  // Particle tracks
700
  if (check_for_node(root, "track")) {
6,384✔
701
    // Get values and make sure there are three per particle
702
    auto temp = get_node_array<int>(root, "track");
48✔
703
    if (temp.size() % 3 != 0) {
48✔
UNCOV
704
      fatal_error(
×
705
        "Number of integers specified in 'track' is not "
706
        "divisible by 3.  Please provide 3 integers per particle to be "
707
        "tracked.");
708
    }
709

710
    // Reshape into track_identifiers
711
    int n_tracks = temp.size() / 3;
48✔
712
    for (int i = 0; i < n_tracks; ++i) {
192✔
713
      track_identifiers.push_back(
144✔
714
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
144✔
715
    }
716
  }
48✔
717

718
  // Shannon entropy
719
  if (solver_type == SolverType::RANDOM_RAY) {
6,384✔
720
    if (check_for_node(root, "entropy_mesh")) {
480✔
UNCOV
721
      fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
×
722
                  "No user-defined entropy mesh is supported.");
723
    }
724
    entropy_on = true;
480✔
725
  } else if (solver_type == SolverType::MONTE_CARLO) {
5,904✔
726
    if (check_for_node(root, "entropy_mesh")) {
5,904✔
727
      int temp = std::stoi(get_node_value(root, "entropy_mesh"));
350✔
728
      if (model::mesh_map.find(temp) == model::mesh_map.end()) {
350✔
UNCOV
729
        fatal_error(fmt::format(
×
730
          "Mesh {} specified for Shannon entropy does not exist.", temp));
731
      }
732

733
      auto* m = dynamic_cast<RegularMesh*>(
350✔
734
        model::meshes[model::mesh_map.at(temp)].get());
350✔
735
      if (!m)
350✔
UNCOV
736
        fatal_error("Only regular meshes can be used as an entropy mesh");
×
737
      simulation::entropy_mesh = m;
350✔
738

739
      // Turn on Shannon entropy calculation
740
      entropy_on = true;
350✔
741

742
    } else if (check_for_node(root, "entropy")) {
5,554✔
UNCOV
743
      fatal_error(
×
744
        "Specifying a Shannon entropy mesh via the <entropy> element "
745
        "is deprecated. Please create a mesh using <mesh> and then reference "
746
        "it by specifying its ID in an <entropy_mesh> element.");
747
    }
748
  }
749
  // Uniform fission source weighting mesh
750
  if (check_for_node(root, "ufs_mesh")) {
6,384✔
751
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
16✔
752
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
16✔
UNCOV
753
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
754
                              "method does not exist.",
755
        temp));
756
    }
757

758
    auto* m =
759
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
16✔
760
    if (!m)
16✔
UNCOV
761
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
762
    simulation::ufs_mesh = m;
16✔
763

764
    // Turn on uniform fission source weighting
765
    ufs_on = true;
16✔
766

767
  } else if (check_for_node(root, "uniform_fs")) {
6,368✔
UNCOV
768
    fatal_error(
×
769
      "Specifying a UFS mesh via the <uniform_fs> element "
770
      "is deprecated. Please create a mesh using <mesh> and then reference "
771
      "it by specifying its ID in a <ufs_mesh> element.");
772
  }
773

774
  // Check if the user has specified to write state points
775
  if (check_for_node(root, "state_point")) {
6,384✔
776

777
    // Get pointer to state_point node
778
    auto node_sp = root.child("state_point");
174✔
779

780
    // Determine number of batches at which to store state points
781
    if (check_for_node(node_sp, "batches")) {
174✔
782
      // User gave specific batches to write state points
783
      auto temp = get_node_array<int>(node_sp, "batches");
174✔
784
      for (const auto& b : temp) {
538✔
785
        statepoint_batch.insert(b);
364✔
786
      }
787
    } else {
174✔
788
      // If neither were specified, write state point at last batch
UNCOV
789
      statepoint_batch.insert(n_batches);
×
790
    }
791
  } else {
792
    // If no <state_point> tag was present, by default write state point at
793
    // last batch only
794
    statepoint_batch.insert(n_batches);
6,210✔
795
  }
796

797
  // Check if the user has specified to write source points
798
  if (check_for_node(root, "source_point")) {
6,384✔
799
    // Get source_point node
800
    xml_node node_sp = root.child("source_point");
96✔
801

802
    // Determine batches at which to store source points
803
    if (check_for_node(node_sp, "batches")) {
96✔
804
      // User gave specific batches to write source points
805
      auto temp = get_node_array<int>(node_sp, "batches");
48✔
806
      for (const auto& b : temp) {
128✔
807
        sourcepoint_batch.insert(b);
80✔
808
      }
809
    } else {
48✔
810
      // If neither were specified, write source points with state points
811
      sourcepoint_batch = statepoint_batch;
48✔
812
    }
813

814
    // Check if the user has specified to write binary source file
815
    if (check_for_node(node_sp, "separate")) {
96✔
816
      source_separate = get_node_value_bool(node_sp, "separate");
64✔
817
    }
818
    if (check_for_node(node_sp, "write")) {
96✔
UNCOV
819
      source_write = get_node_value_bool(node_sp, "write");
×
820
    }
821
    if (check_for_node(node_sp, "mcpl")) {
96✔
822
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
16✔
823

824
      // Make sure MCPL support is enabled
825
      if (source_mcpl_write && !MCPL_ENABLED) {
16✔
UNCOV
826
        fatal_error(
×
827
          "Your build of OpenMC does not support writing MCPL source files.");
828
      }
829
    }
830
    if (check_for_node(node_sp, "overwrite_latest")) {
96✔
831
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
16✔
832
      source_separate = source_latest;
16✔
833
    }
834
  } else {
835
    // If no <source_point> tag was present, by default we keep source bank in
836
    // statepoint file and write it out at statepoints intervals
837
    source_separate = false;
6,288✔
838
    sourcepoint_batch = statepoint_batch;
6,288✔
839
  }
840

841
  // Check is the user specified to convert strength to statistical weight
842
  if (check_for_node(root, "uniform_source_sampling")) {
6,384✔
843
    uniform_source_sampling =
55✔
844
      get_node_value_bool(root, "uniform_source_sampling");
55✔
845
  }
846

847
  // Check if the user has specified to write surface source
848
  if (check_for_node(root, "surf_source_write")) {
6,384✔
849
    surf_source_write = true;
401✔
850
    // Get surface source write node
851
    xml_node node_ssw = root.child("surf_source_write");
401✔
852

853
    // Determine surface ids at which crossing particles are to be banked.
854
    // If no surfaces are specified, all surfaces in the model will be used
855
    // to bank source points.
856
    if (check_for_node(node_ssw, "surface_ids")) {
401✔
857
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
191✔
858
      for (const auto& b : temp) {
972✔
859
        source_write_surf_id.insert(b);
781✔
860
      }
861
    }
191✔
862

863
    // Get maximum number of particles to be banked per surface
864
    if (check_for_node(node_ssw, "max_particles")) {
401✔
865
      ssw_max_particles = std::stoll(get_node_value(node_ssw, "max_particles"));
392✔
866
    } else {
867
      fatal_error("A maximum number of particles needs to be specified "
9✔
868
                  "using the 'max_particles' parameter to store surface "
869
                  "source points.");
870
    }
871

872
    // Get maximum number of surface source files to be created
873
    if (check_for_node(node_ssw, "max_source_files")) {
392✔
874
      ssw_max_files = std::stoll(get_node_value(node_ssw, "max_source_files"));
33✔
875
    } else {
876
      ssw_max_files = 1;
359✔
877
    }
878

879
    if (check_for_node(node_ssw, "mcpl")) {
392✔
UNCOV
880
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
×
881

882
      // Make sure MCPL support is enabled
UNCOV
883
      if (surf_mcpl_write && !MCPL_ENABLED) {
×
UNCOV
884
        fatal_error("Your build of OpenMC does not support writing MCPL "
×
885
                    "surface source files.");
886
      }
887
    }
888
    // Get cell information
889
    if (check_for_node(node_ssw, "cell")) {
392✔
890
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
104✔
891
      ssw_cell_type = SSWCellType::Both;
104✔
892
    }
893
    if (check_for_node(node_ssw, "cellfrom")) {
392✔
894
      if (ssw_cell_id != C_NONE) {
90✔
895
        fatal_error(
18✔
896
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
897
      }
898
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
72✔
899
      ssw_cell_type = SSWCellType::From;
72✔
900
    }
901
    if (check_for_node(node_ssw, "cellto")) {
374✔
902
      if (ssw_cell_id != C_NONE) {
71✔
903
        fatal_error(
18✔
904
          "'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
905
      }
906
      ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
53✔
907
      ssw_cell_type = SSWCellType::To;
53✔
908
    }
909
  }
910

911
  // If source is not separate and is to be written out in the statepoint file,
912
  // make sure that the sourcepoint batch numbers are contained in the
913
  // statepoint list
914
  if (!source_separate) {
6,339✔
915
    for (const auto& b : sourcepoint_batch) {
12,660✔
916
      if (!contains(statepoint_batch, b)) {
6,401✔
UNCOV
917
        fatal_error(
×
918
          "Sourcepoint batches are not a subset of statepoint batches.");
919
      }
920
    }
921
  }
922

923
  // Check if the user has specified to not reduce tallies at the end of every
924
  // batch
925
  if (check_for_node(root, "no_reduce")) {
6,339✔
UNCOV
926
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
×
927
  }
928

929
  // Check if the user has specified to use confidence intervals for
930
  // uncertainties rather than standard deviations
931
  if (check_for_node(root, "confidence_intervals")) {
6,339✔
932
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
16✔
933
  }
934

935
  // Check for output options
936
  if (check_for_node(root, "output")) {
6,339✔
937
    // Get pointer to output node
938
    pugi::xml_node node_output = root.child("output");
372✔
939

940
    // Check for summary option
941
    if (check_for_node(node_output, "summary")) {
372✔
942
      output_summary = get_node_value_bool(node_output, "summary");
356✔
943
    }
944

945
    // Check for ASCII tallies output option
946
    if (check_for_node(node_output, "tallies")) {
372✔
947
      output_tallies = get_node_value_bool(node_output, "tallies");
16✔
948
    }
949

950
    // Set output directory if a path has been specified
951
    if (check_for_node(node_output, "path")) {
372✔
UNCOV
952
      path_output = get_node_value(node_output, "path");
×
UNCOV
953
      if (!ends_with(path_output, "/")) {
×
UNCOV
954
        path_output += "/";
×
955
      }
956
    }
957
  }
958

959
  // Resonance scattering parameters
960
  if (check_for_node(root, "resonance_scattering")) {
6,339✔
961
    xml_node node_res_scat = root.child("resonance_scattering");
16✔
962

963
    // See if resonance scattering is enabled
964
    if (check_for_node(node_res_scat, "enable")) {
16✔
965
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
16✔
966
    } else {
UNCOV
967
      res_scat_on = true;
×
968
    }
969

970
    // Determine what method is used
971
    if (check_for_node(node_res_scat, "method")) {
16✔
972
      auto temp = get_node_value(node_res_scat, "method", true, true);
16✔
973
      if (temp == "rvs") {
16✔
974
        res_scat_method = ResScatMethod::rvs;
16✔
UNCOV
975
      } else if (temp == "dbrc") {
×
UNCOV
976
        res_scat_method = ResScatMethod::dbrc;
×
977
      } else {
UNCOV
978
        fatal_error(
×
UNCOV
979
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
980
      }
981
    }
16✔
982

983
    // Minimum energy for resonance scattering
984
    if (check_for_node(node_res_scat, "energy_min")) {
16✔
985
      res_scat_energy_min =
16✔
986
        std::stod(get_node_value(node_res_scat, "energy_min"));
16✔
987
    }
988
    if (res_scat_energy_min < 0.0) {
16✔
UNCOV
989
      fatal_error("Lower resonance scattering energy bound is negative");
×
990
    }
991

992
    // Maximum energy for resonance scattering
993
    if (check_for_node(node_res_scat, "energy_max")) {
16✔
994
      res_scat_energy_max =
16✔
995
        std::stod(get_node_value(node_res_scat, "energy_max"));
16✔
996
    }
997
    if (res_scat_energy_max < res_scat_energy_min) {
16✔
UNCOV
998
      fatal_error("Upper resonance scattering energy bound is below the "
×
999
                  "lower resonance scattering energy bound.");
1000
    }
1001

1002
    // Get resonance scattering nuclides
1003
    if (check_for_node(node_res_scat, "nuclides")) {
16✔
1004
      res_scat_nuclides =
1005
        get_node_array<std::string>(node_res_scat, "nuclides");
16✔
1006
    }
1007
  }
1008

1009
  // Get volume calculations
1010
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
6,665✔
1011
    model::volume_calcs.emplace_back(node_vol);
326✔
1012
  }
1013

1014
  // Get temperature settings
1015
  if (check_for_node(root, "temperature_default")) {
6,339✔
1016
    temperature_default =
172✔
1017
      std::stod(get_node_value(root, "temperature_default"));
172✔
1018
  }
1019
  if (check_for_node(root, "temperature_method")) {
6,339✔
1020
    auto temp = get_node_value(root, "temperature_method", true, true);
325✔
1021
    if (temp == "nearest") {
325✔
1022
      temperature_method = TemperatureMethod::NEAREST;
140✔
1023
    } else if (temp == "interpolation") {
185✔
1024
      temperature_method = TemperatureMethod::INTERPOLATION;
185✔
1025
    } else {
UNCOV
1026
      fatal_error("Unknown temperature method: " + temp);
×
1027
    }
1028
  }
325✔
1029
  if (check_for_node(root, "temperature_tolerance")) {
6,339✔
1030
    temperature_tolerance =
171✔
1031
      std::stod(get_node_value(root, "temperature_tolerance"));
171✔
1032
  }
1033
  if (check_for_node(root, "temperature_multipole")) {
6,339✔
1034
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
32✔
1035

1036
    // Multipole currently doesn't work with photon transport
1037
    if (temperature_multipole && photon_transport) {
32✔
1038
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
1039
                  "photon transport.");
1040
    }
1041
  }
1042
  if (check_for_node(root, "temperature_range")) {
6,339✔
UNCOV
1043
    auto range = get_node_array<double>(root, "temperature_range");
×
UNCOV
1044
    temperature_range[0] = range.at(0);
×
UNCOV
1045
    temperature_range[1] = range.at(1);
×
1046
  }
1047

1048
  // Check for tabular_legendre options
1049
  if (check_for_node(root, "tabular_legendre")) {
6,339✔
1050
    // Get pointer to tabular_legendre node
1051
    xml_node node_tab_leg = root.child("tabular_legendre");
96✔
1052

1053
    // Check for enable option
1054
    if (check_for_node(node_tab_leg, "enable")) {
96✔
1055
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
96✔
1056
    }
1057

1058
    // Check for the number of points
1059
    if (check_for_node(node_tab_leg, "num_points")) {
96✔
UNCOV
1060
      legendre_to_tabular_points =
×
UNCOV
1061
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
UNCOV
1062
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
UNCOV
1063
        fatal_error(
×
1064
          "The 'num_points' subelement/attribute of the "
1065
          "<tabular_legendre> element must contain a value greater than 1");
1066
      }
1067
    }
1068
  }
1069

1070
  // Check whether create delayed neutrons in fission
1071
  if (check_for_node(root, "create_delayed_neutrons")) {
6,339✔
UNCOV
1072
    create_delayed_neutrons =
×
UNCOV
1073
      get_node_value_bool(root, "create_delayed_neutrons");
×
1074
  }
1075

1076
  // Check whether create fission sites
1077
  if (run_mode == RunMode::FIXED_SOURCE) {
6,339✔
1078
    if (check_for_node(root, "create_fission_neutrons")) {
2,129✔
1079
      create_fission_neutrons =
16✔
1080
        get_node_value_bool(root, "create_fission_neutrons");
16✔
1081
    }
1082
  }
1083

1084
  // Check whether to scale fission photon yields
1085
  if (check_for_node(root, "delayed_photon_scaling")) {
6,339✔
1086
    delayed_photon_scaling =
×
UNCOV
1087
      get_node_value_bool(root, "delayed_photon_scaling");
×
1088
  }
1089

1090
  // Check whether to use event-based parallelism
1091
  if (check_for_node(root, "event_based")) {
6,339✔
UNCOV
1092
    event_based = get_node_value_bool(root, "event_based");
×
1093
  }
1094

1095
  // Check whether material cell offsets should be generated
1096
  if (check_for_node(root, "material_cell_offsets")) {
6,339✔
UNCOV
1097
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
1098
  }
1099

1100
  // Weight window information
1101
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
6,418✔
1102
    variance_reduction::weight_windows.emplace_back(
79✔
1103
      std::make_unique<WeightWindows>(node_ww));
158✔
1104
  }
1105

1106
  // Enable weight windows by default if one or more are present
1107
  if (variance_reduction::weight_windows.size() > 0)
6,339✔
1108
    settings::weight_windows_on = true;
52✔
1109

1110
  // read weight windows from file
1111
  if (check_for_node(root, "weight_windows_file")) {
6,339✔
UNCOV
1112
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
1113
  }
1114

1115
  // read settings for weight windows value, this will override
1116
  // the automatic setting even if weight windows are present
1117
  if (check_for_node(root, "weight_windows_on")) {
6,339✔
1118
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
36✔
1119
  }
1120

1121
  if (check_for_node(root, "max_history_splits")) {
6,339✔
1122
    settings::max_history_splits =
214✔
1123
      std::stoi(get_node_value(root, "max_history_splits"));
214✔
1124
  }
1125

1126
  if (check_for_node(root, "max_tracks")) {
6,339✔
1127
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
48✔
1128
  }
1129

1130
  // Create weight window generator objects
1131
  if (check_for_node(root, "weight_window_generators")) {
6,339✔
1132
    auto wwgs_node = root.child("weight_window_generators");
81✔
1133
    for (pugi::xml_node node_wwg :
81✔
1134
      wwgs_node.children("weight_windows_generator")) {
243✔
1135
      variance_reduction::weight_windows_generators.emplace_back(
81✔
1136
        std::make_unique<WeightWindowsGenerator>(node_wwg));
162✔
1137
    }
1138
    // if any of the weight windows are intended to be generated otf, make sure
1139
    // they're applied
1140
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
81✔
1141
      if (wwg->on_the_fly_) {
81✔
1142
        settings::weight_windows_on = true;
81✔
1143
        break;
81✔
1144
      }
1145
    }
1146
  }
1147

1148
  // Set up weight window checkpoints
1149
  if (check_for_node(root, "weight_window_checkpoints")) {
6,339✔
1150
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
×
1151
    if (check_for_node(ww_checkpoints, "collision")) {
×
UNCOV
1152
      weight_window_checkpoint_collision =
×
UNCOV
1153
        get_node_value_bool(ww_checkpoints, "collision");
×
1154
    }
UNCOV
1155
    if (check_for_node(ww_checkpoints, "surface")) {
×
UNCOV
1156
      weight_window_checkpoint_surface =
×
UNCOV
1157
        get_node_value_bool(ww_checkpoints, "surface");
×
1158
    }
1159
  }
1160

1161
  if (check_for_node(root, "use_decay_photons")) {
6,339✔
1162
    settings::use_decay_photons =
11✔
1163
      get_node_value_bool(root, "use_decay_photons");
11✔
1164
  }
1165
}
6,339✔
1166

1167
void free_memory_settings()
6,484✔
1168
{
1169
  settings::statepoint_batch.clear();
6,484✔
1170
  settings::sourcepoint_batch.clear();
6,484✔
1171
  settings::source_write_surf_id.clear();
6,484✔
1172
  settings::res_scat_nuclides.clear();
6,484✔
1173
}
6,484✔
1174

1175
//==============================================================================
1176
// C API functions
1177
//==============================================================================
1178

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

1187
  if (simulation::current_batch >= n_batches) {
44✔
1188
    set_errmsg("Number of batches must be greater than current batch.");
11✔
1189
    return OPENMC_E_INVALID_ARGUMENT;
11✔
1190
  }
1191

1192
  if (!settings::trigger_on) {
33✔
1193
    // Set n_batches and n_max_batches to same value
1194
    settings::n_batches = n_batches;
11✔
1195
    settings::n_max_batches = n_batches;
11✔
1196
  } else {
1197
    // Set n_batches and n_max_batches based on value of set_max_batches
1198
    if (set_max_batches) {
22✔
1199
      settings::n_max_batches = n_batches;
11✔
1200
    } else {
1201
      settings::n_batches = n_batches;
11✔
1202
    }
1203
  }
1204

1205
  // Update size of k_generation and entropy
1206
  int m = settings::n_max_batches * settings::gen_per_batch;
33✔
1207
  simulation::k_generation.reserve(m);
33✔
1208
  simulation::entropy.reserve(m);
33✔
1209

1210
  // Add value of n_batches to statepoint_batch
1211
  if (add_statepoint_batch &&
55✔
1212
      !(contains(settings::statepoint_batch, n_batches)))
22✔
1213
    settings::statepoint_batch.insert(n_batches);
22✔
1214

1215
  return 0;
33✔
1216
}
1217

1218
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
2,755✔
1219
{
1220
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
2,755✔
1221

1222
  return 0;
2,755✔
1223
}
1224

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

© 2025 Coveralls, Inc