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

openmc-dev / openmc / 8705531778

16 Apr 2024 12:23PM UTC coverage: 84.842% (+0.2%) from 84.639%
8705531778

Pull #2693

github

web-flow
Merge 75ca1f251 into 2974d53b3
Pull Request #2693: Add reactivity control to coupled transport-depletion analyses

328 of 389 new or added lines in 5 files covered. (84.32%)

815 existing lines in 28 files now uncovered.

48199 of 56810 relevant lines covered (84.84%)

43871786.95 hits per line

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

77.38
/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/simulation.h"
28
#include "openmc/source.h"
29
#include "openmc/string_utils.h"
30
#include "openmc/tallies/trigger.h"
31
#include "openmc/volume_calc.h"
32
#include "openmc/weight_windows.h"
33
#include "openmc/xml_interface.h"
34

35
namespace openmc {
36

37
//==============================================================================
38
// Global variables
39
//==============================================================================
40

41
namespace settings {
42

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

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

91
int32_t n_inactive {0};
92
int32_t max_lost_particles {10};
93
double rel_max_lost_particles {1.0e-6};
94
int32_t max_write_lost_particles {-1};
95
int32_t gen_per_batch {1};
96
int64_t n_particles {-1};
97

98
int64_t max_particles_in_flight {100000};
99
int max_particle_events {1000000};
100

101
ElectronTreatment electron_treatment {ElectronTreatment::TTB};
102
array<double, 4> energy_cutoff {0.0, 1000.0, 0.0, 0.0};
103
array<double, 4> time_cutoff {INFTY, INFTY, INFTY, INFTY};
104
int legendre_to_tabular_points {C_NONE};
105
int max_order {0};
106
int n_log_bins {8000};
107
int n_batches;
108
int n_max_batches;
109
int max_splits {1000};
110
int max_tracks {1000};
111
ResScatMethod res_scat_method {ResScatMethod::rvs};
112
double res_scat_energy_min {0.01};
113
double res_scat_energy_max {1000.0};
114
vector<std::string> res_scat_nuclides;
115
RunMode run_mode {RunMode::UNSET};
116
std::unordered_set<int> sourcepoint_batch;
117
std::unordered_set<int> statepoint_batch;
118
std::unordered_set<int> source_write_surf_id;
119
int64_t max_surface_particles;
120
TemperatureMethod temperature_method {TemperatureMethod::NEAREST};
121
double temperature_tolerance {10.0};
122
double temperature_default {293.6};
123
array<double, 2> temperature_range {0.0, 0.0};
124
int trace_batch;
125
int trace_gen;
126
int64_t trace_particle;
127
vector<array<int, 3>> track_identifiers;
128
int trigger_batch_interval {1};
129
int verbosity {7};
130
double weight_cutoff {0.25};
131
double weight_survive {1.0};
132

133
} // namespace settings
134

135
//==============================================================================
136
// Functions
137
//==============================================================================
138

139
void get_run_parameters(pugi::xml_node node_base)
6,113✔
140
{
141
  using namespace settings;
142
  using namespace pugi;
143

144
  // Check number of particles
145
  if (!check_for_node(node_base, "particles")) {
6,113✔
UNCOV
146
    fatal_error("Need to specify number of particles.");
×
147
  }
148

149
  // Get number of particles if it wasn't specified as a command-line argument
150
  if (n_particles == -1) {
6,113✔
151
    n_particles = std::stoll(get_node_value(node_base, "particles"));
6,113✔
152
  }
153

154
  // Get maximum number of in flight particles for event-based mode
155
  if (check_for_node(node_base, "max_particles_in_flight")) {
6,113✔
156
    max_particles_in_flight =
×
UNCOV
157
      std::stoll(get_node_value(node_base, "max_particles_in_flight"));
×
158
  }
159

160
  // Get maximum number of events allowed per particle
161
  if (check_for_node(node_base, "max_particle_events")) {
6,113✔
UNCOV
162
    max_particle_events =
×
UNCOV
163
      std::stoll(get_node_value(node_base, "max_particle_events"));
×
164
  }
165

166
  // Get number of basic batches
167
  if (check_for_node(node_base, "batches")) {
6,113✔
168
    n_batches = std::stoi(get_node_value(node_base, "batches"));
6,113✔
169
  }
170
  if (!trigger_on)
6,113✔
171
    n_max_batches = n_batches;
5,962✔
172

173
  // Get max number of lost particles
174
  if (check_for_node(node_base, "max_lost_particles")) {
6,113✔
175
    max_lost_particles =
19✔
176
      std::stoi(get_node_value(node_base, "max_lost_particles"));
19✔
177
  }
178

179
  // Get relative number of lost particles
180
  if (check_for_node(node_base, "rel_max_lost_particles")) {
6,113✔
UNCOV
181
    rel_max_lost_particles =
×
UNCOV
182
      std::stod(get_node_value(node_base, "rel_max_lost_particles"));
×
183
  }
184

185
  // Get relative number of lost particles
186
  if (check_for_node(node_base, "max_write_lost_particles")) {
6,113✔
187
    max_write_lost_particles =
19✔
188
      std::stoi(get_node_value(node_base, "max_write_lost_particles"));
19✔
189
  }
190

191
  // Get number of inactive batches
192
  if (run_mode == RunMode::EIGENVALUE) {
6,113✔
193
    if (check_for_node(node_base, "inactive")) {
4,247✔
194
      n_inactive = std::stoi(get_node_value(node_base, "inactive"));
4,137✔
195
    }
196
    if (check_for_node(node_base, "generations_per_batch")) {
4,247✔
197
      gen_per_batch =
19✔
198
        std::stoi(get_node_value(node_base, "generations_per_batch"));
19✔
199
    }
200

201
    // Preallocate space for keff and entropy by generation
202
    int m = settings::n_max_batches * settings::gen_per_batch;
4,247✔
203
    simulation::k_generation.reserve(m);
4,247✔
204
    simulation::entropy.reserve(m);
4,247✔
205

206
    // Get the trigger information for keff
207
    if (check_for_node(node_base, "keff_trigger")) {
4,247✔
208
      xml_node node_keff_trigger = node_base.child("keff_trigger");
128✔
209

210
      if (check_for_node(node_keff_trigger, "type")) {
128✔
211
        auto temp = get_node_value(node_keff_trigger, "type", true, true);
128✔
212
        if (temp == "std_dev") {
128✔
213
          keff_trigger.metric = TriggerMetric::standard_deviation;
128✔
UNCOV
214
        } else if (temp == "variance") {
×
215
          keff_trigger.metric = TriggerMetric::variance;
×
UNCOV
216
        } else if (temp == "rel_err") {
×
UNCOV
217
          keff_trigger.metric = TriggerMetric::relative_error;
×
218
        } else {
UNCOV
219
          fatal_error("Unrecognized keff trigger type " + temp);
×
220
        }
221
      } else {
128✔
222
        fatal_error("Specify keff trigger type in settings XML");
×
223
      }
224

225
      if (check_for_node(node_keff_trigger, "threshold")) {
128✔
226
        keff_trigger.threshold =
128✔
227
          std::stod(get_node_value(node_keff_trigger, "threshold"));
128✔
228
        if (keff_trigger.threshold <= 0) {
128✔
UNCOV
229
          fatal_error("keff trigger threshold must be positive");
×
230
        }
231
      } else {
UNCOV
232
        fatal_error("Specify keff trigger threshold in settings XML");
×
233
      }
234
    }
235
  }
236
}
6,113✔
237

238
void read_settings_xml()
1,933✔
239
{
240
  using namespace settings;
241
  using namespace pugi;
242
  // Check if settings.xml exists
243
  std::string filename = settings::path_input + "settings.xml";
1,933✔
244
  if (!file_exists(filename)) {
1,933✔
245
    if (run_mode != RunMode::PLOTTING) {
28✔
UNCOV
246
      fatal_error("Could not find any XML input files! In order to run OpenMC, "
×
247
                  "you first need a set of input files; at a minimum, this "
248
                  "includes settings.xml, geometry.xml, and materials.xml or a "
249
                  "single model XML file. Please consult the user's guide at "
250
                  "https://docs.openmc.org for further information.");
251
    } else {
252
      // The settings.xml file is optional if we just want to make a plot.
253
      return;
28✔
254
    }
255
  }
256

257
  // Parse settings.xml file
258
  xml_document doc;
1,905✔
259
  auto result = doc.load_file(filename.c_str());
1,905✔
260
  if (!result) {
1,905✔
UNCOV
261
    fatal_error("Error processing settings.xml file.");
×
262
  }
263

264
  // Get root element
265
  xml_node root = doc.document_element();
1,905✔
266

267
  // Verbosity
268
  if (check_for_node(root, "verbosity")) {
1,905✔
269
    verbosity = std::stoi(get_node_value(root, "verbosity"));
243✔
270
  }
271

272
  // To this point, we haven't displayed any output since we didn't know what
273
  // the verbosity is. Now that we checked for it, show the title if necessary
274
  if (mpi::master) {
1,905✔
275
    if (verbosity >= 2)
1,680✔
276
      title();
1,447✔
277
  }
278

279
  write_message("Reading settings XML file...", 5);
1,905✔
280

281
  read_settings_xml(root);
1,905✔
282
}
1,920✔
283

284
void read_settings_xml(pugi::xml_node root)
6,467✔
285
{
286
  using namespace settings;
287
  using namespace pugi;
288

289
  // Find if a multi-group or continuous-energy simulation is desired
290
  if (check_for_node(root, "energy_mode")) {
6,467✔
291
    std::string temp_str = get_node_value(root, "energy_mode", true, true);
608✔
292
    if (temp_str == "mg" || temp_str == "multi-group") {
608✔
293
      run_CE = false;
608✔
UNCOV
294
    } else if (temp_str == "ce" || temp_str == "continuous-energy") {
×
UNCOV
295
      run_CE = true;
×
296
    }
297
  }
608✔
298

299
  // Check for user meshes and allocate
300
  read_meshes(root);
6,467✔
301

302
  // Look for deprecated cross_sections.xml file in settings.xml
303
  if (check_for_node(root, "cross_sections")) {
6,467✔
UNCOV
304
    warning(
×
305
      "Setting cross_sections in settings.xml has been deprecated."
306
      " The cross_sections are now set in materials.xml and the "
307
      "cross_sections input to materials.xml and the OPENMC_CROSS_SECTIONS"
308
      " environment variable will take precendent over setting "
309
      "cross_sections in settings.xml.");
UNCOV
310
    path_cross_sections = get_node_value(root, "cross_sections");
×
311
  }
312

313
  if (!run_CE) {
6,467✔
314
    // Scattering Treatments
315
    if (check_for_node(root, "max_order")) {
608✔
316
      max_order = std::stoi(get_node_value(root, "max_order"));
19✔
317
    } else {
318
      // Set to default of largest int - 1, which means to use whatever is
319
      // contained in library. This is largest int - 1 because for legendre
320
      // scattering, a value of 1 is added to the order; adding 1 to the largest
321
      // int gets you the largest negative integer, which is not what we want.
322
      max_order = std::numeric_limits<int>::max() - 1;
589✔
323
    }
324
  }
325

326
  // Check for a trigger node and get trigger information
327
  if (check_for_node(root, "trigger")) {
6,467✔
328
    xml_node node_trigger = root.child("trigger");
170✔
329

330
    // Check if trigger(s) are to be turned on
331
    trigger_on = get_node_value_bool(node_trigger, "active");
170✔
332

333
    if (trigger_on) {
170✔
334
      if (check_for_node(node_trigger, "max_batches")) {
151✔
335
        n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
151✔
336
      } else {
UNCOV
337
        fatal_error("<max_batches> must be specified with triggers");
×
338
      }
339

340
      // Get the batch interval to check triggers
341
      if (!check_for_node(node_trigger, "batch_interval")) {
151✔
342
        trigger_predict = true;
19✔
343
      } else {
344
        trigger_batch_interval =
132✔
345
          std::stoi(get_node_value(node_trigger, "batch_interval"));
132✔
346
        if (trigger_batch_interval <= 0) {
132✔
UNCOV
347
          fatal_error("Trigger batch interval must be greater than zero");
×
348
        }
349
      }
350
    }
351
  }
352

353
  // Check run mode if it hasn't been set from the command line
354
  xml_node node_mode;
6,467✔
355
  if (run_mode == RunMode::UNSET) {
6,467✔
356
    if (check_for_node(root, "run_mode")) {
6,151✔
357
      std::string temp_str = get_node_value(root, "run_mode", true, true);
6,075✔
358
      if (temp_str == "eigenvalue") {
6,075✔
359
        run_mode = RunMode::EIGENVALUE;
4,171✔
360
      } else if (temp_str == "fixed source") {
1,904✔
361
        run_mode = RunMode::FIXED_SOURCE;
1,866✔
362
      } else if (temp_str == "plot") {
38✔
UNCOV
363
        run_mode = RunMode::PLOTTING;
×
364
      } else if (temp_str == "particle restart") {
38✔
UNCOV
365
        run_mode = RunMode::PARTICLE;
×
366
      } else if (temp_str == "volume") {
38✔
367
        run_mode = RunMode::VOLUME;
38✔
368
      } else {
UNCOV
369
        fatal_error("Unrecognized run mode: " + temp_str);
×
370
      }
371

372
      // Assume XML specifies <particles>, <batches>, etc. directly
373
      node_mode = root;
6,075✔
374
    } else {
6,075✔
375
      warning("<run_mode> should be specified.");
76✔
376

377
      // Make sure that either eigenvalue or fixed source was specified
378
      node_mode = root.child("eigenvalue");
76✔
379
      if (node_mode) {
76✔
380
        run_mode = RunMode::EIGENVALUE;
76✔
381
      } else {
UNCOV
382
        node_mode = root.child("fixed_source");
×
UNCOV
383
        if (node_mode) {
×
UNCOV
384
          run_mode = RunMode::FIXED_SOURCE;
×
385
        } else {
UNCOV
386
          fatal_error("<eigenvalue> or <fixed_source> not specified.");
×
387
        }
388
      }
389
    }
390
  }
391

392
  if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
6,467✔
393
    // Read run parameters
394
    get_run_parameters(node_mode);
6,113✔
395

396
    // Check number of active batches, inactive batches, max lost particles and
397
    // particles
398
    if (n_batches <= n_inactive) {
6,113✔
UNCOV
399
      fatal_error("Number of active batches must be greater than zero.");
×
400
    } else if (n_inactive < 0) {
6,113✔
UNCOV
401
      fatal_error("Number of inactive batches must be non-negative.");
×
402
    } else if (n_particles <= 0) {
6,113✔
UNCOV
403
      fatal_error("Number of particles must be greater than zero.");
×
404
    } else if (max_lost_particles <= 0) {
6,113✔
UNCOV
405
      fatal_error("Number of max lost particles must be greater than zero.");
×
406
    } else if (rel_max_lost_particles <= 0.0 || rel_max_lost_particles >= 1.0) {
6,113✔
407
      fatal_error("Relative max lost particles must be between zero and one.");
×
408
    }
409
  }
410

411
  // Copy plotting random number seed if specified
412
  if (check_for_node(root, "plot_seed")) {
6,467✔
UNCOV
413
    auto seed = std::stoll(get_node_value(root, "plot_seed"));
×
UNCOV
414
    model::plotter_seed = seed;
×
415
  }
416

417
  // Copy random number seed if specified
418
  if (check_for_node(root, "seed")) {
6,467✔
419
    auto seed = std::stoll(get_node_value(root, "seed"));
126✔
420
    openmc_set_seed(seed);
126✔
421
  }
422

423
  // Check for electron treatment
424
  if (check_for_node(root, "electron_treatment")) {
6,467✔
425
    auto temp_str = get_node_value(root, "electron_treatment", true, true);
57✔
426
    if (temp_str == "led") {
57✔
UNCOV
427
      electron_treatment = ElectronTreatment::LED;
×
428
    } else if (temp_str == "ttb") {
57✔
429
      electron_treatment = ElectronTreatment::TTB;
57✔
430
    } else {
UNCOV
431
      fatal_error("Unrecognized electron treatment: " + temp_str + ".");
×
432
    }
433
  }
57✔
434

435
  // Check for photon transport
436
  if (check_for_node(root, "photon_transport")) {
6,467✔
437
    photon_transport = get_node_value_bool(root, "photon_transport");
213✔
438

439
    if (!run_CE && photon_transport) {
213✔
UNCOV
440
      fatal_error("Photon transport is not currently supported in "
×
441
                  "multigroup mode");
442
    }
443
  }
444

445
  // Number of bins for logarithmic grid
446
  if (check_for_node(root, "log_grid_bins")) {
6,467✔
447
    n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
19✔
448
    if (n_log_bins < 1) {
19✔
449
      fatal_error("Number of bins for logarithmic grid must be greater "
×
450
                  "than zero.");
451
    }
452
  }
453

454
  // Number of OpenMP threads
455
  if (check_for_node(root, "threads")) {
6,467✔
UNCOV
456
    if (mpi::master)
×
UNCOV
457
      warning("The <threads> element has been deprecated. Use "
×
458
              "the OMP_NUM_THREADS environment variable to set the number of "
459
              "threads.");
460
  }
461

462
  // ==========================================================================
463
  // EXTERNAL SOURCE
464

465
  // Get point to list of <source> elements and make sure there is at least one
466
  for (pugi::xml_node node : root.children("source")) {
12,834✔
467
    model::external_sources.push_back(Source::create(node));
6,380✔
468
  }
469

470
  // Check if the user has specified to read surface source
471
  if (check_for_node(root, "surf_source_read")) {
6,454✔
472
    surf_source_read = true;
19✔
473
    // Get surface source read node
474
    xml_node node_ssr = root.child("surf_source_read");
19✔
475

476
    std::string path = "surface_source.h5";
19✔
477
    // Check if the user has specified different file for surface source reading
478
    if (check_for_node(node_ssr, "path")) {
19✔
479
      path = get_node_value(node_ssr, "path", false, true);
19✔
480
    }
481
    model::external_sources.push_back(make_unique<FileSource>(path));
19✔
482
  }
19✔
483

484
  // If no source specified, default to isotropic point source at origin with
485
  // Watt spectrum
486
  if (model::external_sources.empty()) {
6,454✔
487
    double T[] {0.0};
1,853✔
488
    double p[] {1.0};
1,853✔
489
    model::external_sources.push_back(make_unique<IndependentSource>(
1,853✔
490
      UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
3,706✔
491
      UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
3,706✔
492
      UPtrDist {new Discrete(T, p, 1)}));
3,706✔
493
  }
494

495
  // Check if we want to write out source
496
  if (check_for_node(root, "write_initial_source")) {
6,454✔
UNCOV
497
    write_initial_source = get_node_value_bool(root, "write_initial_source");
×
498
  }
499

500
  // Survival biasing
501
  if (check_for_node(root, "survival_biasing")) {
6,454✔
502
    survival_biasing = get_node_value_bool(root, "survival_biasing");
220✔
503
  }
504

505
  // Probability tables
506
  if (check_for_node(root, "ptables")) {
6,454✔
507
    urr_ptables_on = get_node_value_bool(root, "ptables");
19✔
508
  }
509

510
  // Cutoffs
511
  if (check_for_node(root, "cutoff")) {
6,454✔
512
    xml_node node_cutoff = root.child("cutoff");
128✔
513
    if (check_for_node(node_cutoff, "weight")) {
128✔
514
      weight_cutoff = std::stod(get_node_value(node_cutoff, "weight"));
19✔
515
    }
516
    if (check_for_node(node_cutoff, "weight_avg")) {
128✔
517
      weight_survive = std::stod(get_node_value(node_cutoff, "weight_avg"));
19✔
518
    }
519
    if (check_for_node(node_cutoff, "energy_neutron")) {
128✔
520
      energy_cutoff[0] =
38✔
521
        std::stod(get_node_value(node_cutoff, "energy_neutron"));
19✔
522
    } else if (check_for_node(node_cutoff, "energy")) {
109✔
UNCOV
523
      warning("The use of an <energy> cutoff is deprecated and should "
×
524
              "be replaced by <energy_neutron>.");
525
      energy_cutoff[0] = std::stod(get_node_value(node_cutoff, "energy"));
×
526
    }
527
    if (check_for_node(node_cutoff, "energy_photon")) {
128✔
528
      energy_cutoff[1] =
142✔
529
        std::stod(get_node_value(node_cutoff, "energy_photon"));
71✔
530
    }
531
    if (check_for_node(node_cutoff, "energy_electron")) {
128✔
UNCOV
532
      energy_cutoff[2] =
×
UNCOV
533
        std::stof(get_node_value(node_cutoff, "energy_electron"));
×
534
    }
535
    if (check_for_node(node_cutoff, "energy_positron")) {
128✔
536
      energy_cutoff[3] =
×
UNCOV
537
        std::stod(get_node_value(node_cutoff, "energy_positron"));
×
538
    }
539
    if (check_for_node(node_cutoff, "time_neutron")) {
128✔
540
      time_cutoff[0] = std::stod(get_node_value(node_cutoff, "time_neutron"));
19✔
541
    }
542
    if (check_for_node(node_cutoff, "time_photon")) {
128✔
UNCOV
543
      time_cutoff[1] = std::stod(get_node_value(node_cutoff, "time_photon"));
×
544
    }
545
    if (check_for_node(node_cutoff, "time_electron")) {
128✔
UNCOV
546
      time_cutoff[2] = std::stod(get_node_value(node_cutoff, "time_electron"));
×
547
    }
548
    if (check_for_node(node_cutoff, "time_positron")) {
128✔
UNCOV
549
      time_cutoff[3] = std::stod(get_node_value(node_cutoff, "time_positron"));
×
550
    }
551
  }
552

553
  // Particle trace
554
  if (check_for_node(root, "trace")) {
6,454✔
555
    auto temp = get_node_array<int64_t>(root, "trace");
19✔
556
    if (temp.size() != 3) {
19✔
UNCOV
557
      fatal_error("Must provide 3 integers for <trace> that specify the "
×
558
                  "batch, generation, and particle number.");
559
    }
560
    trace_batch = temp.at(0);
19✔
561
    trace_gen = temp.at(1);
19✔
562
    trace_particle = temp.at(2);
19✔
563
  }
19✔
564

565
  // Particle tracks
566
  if (check_for_node(root, "track")) {
6,454✔
567
    // Get values and make sure there are three per particle
568
    auto temp = get_node_array<int>(root, "track");
57✔
569
    if (temp.size() % 3 != 0) {
57✔
UNCOV
570
      fatal_error(
×
571
        "Number of integers specified in 'track' is not "
572
        "divisible by 3.  Please provide 3 integers per particle to be "
573
        "tracked.");
574
    }
575

576
    // Reshape into track_identifiers
577
    int n_tracks = temp.size() / 3;
57✔
578
    for (int i = 0; i < n_tracks; ++i) {
228✔
579
      track_identifiers.push_back(
171✔
580
        {temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
171✔
581
    }
582
  }
57✔
583

584
  // Shannon Entropy mesh
585
  if (check_for_node(root, "entropy_mesh")) {
6,454✔
586
    int temp = std::stoi(get_node_value(root, "entropy_mesh"));
545✔
587
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
545✔
588
      fatal_error(fmt::format(
×
589
        "Mesh {} specified for Shannon entropy does not exist.", temp));
590
    }
591

592
    auto* m =
593
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
545✔
594
    if (!m)
545✔
595
      fatal_error("Only regular meshes can be used as an entropy mesh");
×
596
    simulation::entropy_mesh = m;
545✔
597

598
    // Turn on Shannon entropy calculation
599
    entropy_on = true;
545✔
600

601
  } else if (check_for_node(root, "entropy")) {
5,909✔
UNCOV
602
    fatal_error(
×
603
      "Specifying a Shannon entropy mesh via the <entropy> element "
604
      "is deprecated. Please create a mesh using <mesh> and then reference "
605
      "it by specifying its ID in an <entropy_mesh> element.");
606
  }
607

608
  // Uniform fission source weighting mesh
609
  if (check_for_node(root, "ufs_mesh")) {
6,454✔
610
    auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
19✔
611
    if (model::mesh_map.find(temp) == model::mesh_map.end()) {
19✔
UNCOV
612
      fatal_error(fmt::format("Mesh {} specified for uniform fission site "
×
613
                              "method does not exist.",
614
        temp));
615
    }
616

617
    auto* m =
618
      dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
19✔
619
    if (!m)
19✔
620
      fatal_error("Only regular meshes can be used as a UFS mesh");
×
621
    simulation::ufs_mesh = m;
19✔
622

623
    // Turn on uniform fission source weighting
624
    ufs_on = true;
19✔
625

626
  } else if (check_for_node(root, "uniform_fs")) {
6,435✔
UNCOV
627
    fatal_error(
×
628
      "Specifying a UFS mesh via the <uniform_fs> element "
629
      "is deprecated. Please create a mesh using <mesh> and then reference "
630
      "it by specifying its ID in a <ufs_mesh> element.");
631
  }
632

633
  // Check if the user has specified to write state points
634
  if (check_for_node(root, "state_point")) {
6,454✔
635

636
    // Get pointer to state_point node
637
    auto node_sp = root.child("state_point");
222✔
638

639
    // Determine number of batches at which to store state points
640
    if (check_for_node(node_sp, "batches")) {
222✔
641
      // User gave specific batches to write state points
642
      auto temp = get_node_array<int>(node_sp, "batches");
222✔
643
      for (const auto& b : temp) {
685✔
644
        statepoint_batch.insert(b);
463✔
645
      }
646
    } else {
222✔
647
      // If neither were specified, write state point at last batch
UNCOV
648
      statepoint_batch.insert(n_batches);
×
649
    }
650
  } else {
651
    // If no <state_point> tag was present, by default write state point at
652
    // last batch only
653
    statepoint_batch.insert(n_batches);
6,232✔
654
  }
655

656
  // Check if the user has specified to write source points
657
  if (check_for_node(root, "source_point")) {
6,454✔
658
    // Get source_point node
659
    xml_node node_sp = root.child("source_point");
114✔
660

661
    // Determine batches at which to store source points
662
    if (check_for_node(node_sp, "batches")) {
114✔
663
      // User gave specific batches to write source points
664
      auto temp = get_node_array<int>(node_sp, "batches");
57✔
665
      for (const auto& b : temp) {
152✔
666
        sourcepoint_batch.insert(b);
95✔
667
      }
668
    } else {
57✔
669
      // If neither were specified, write source points with state points
670
      sourcepoint_batch = statepoint_batch;
57✔
671
    }
672

673
    // Check if the user has specified to write binary source file
674
    if (check_for_node(node_sp, "separate")) {
114✔
675
      source_separate = get_node_value_bool(node_sp, "separate");
76✔
676
    }
677
    if (check_for_node(node_sp, "write")) {
114✔
678
      source_write = get_node_value_bool(node_sp, "write");
×
679
    }
680
    if (check_for_node(node_sp, "mcpl")) {
114✔
681
      source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
19✔
682

683
      // Make sure MCPL support is enabled
684
      if (source_mcpl_write && !MCPL_ENABLED) {
19✔
UNCOV
685
        fatal_error(
×
686
          "Your build of OpenMC does not support writing MCPL source files.");
687
      }
688
    }
689
    if (check_for_node(node_sp, "overwrite_latest")) {
114✔
690
      source_latest = get_node_value_bool(node_sp, "overwrite_latest");
19✔
691
      source_separate = source_latest;
19✔
692
    }
693
  } else {
694
    // If no <source_point> tag was present, by default we keep source bank in
695
    // statepoint file and write it out at statepoints intervals
696
    source_separate = false;
6,340✔
697
    sourcepoint_batch = statepoint_batch;
6,340✔
698
  }
699

700
  // Check if the user has specified to write surface source
701
  if (check_for_node(root, "surf_source_write")) {
6,454✔
702
    surf_source_write = true;
16✔
703
    // Get surface source write node
704
    xml_node node_ssw = root.child("surf_source_write");
16✔
705

706
    // Determine surface ids at which crossing particles are to be banked
707
    if (check_for_node(node_ssw, "surface_ids")) {
16✔
708
      auto temp = get_node_array<int>(node_ssw, "surface_ids");
16✔
709
      for (const auto& b : temp) {
32✔
710
        source_write_surf_id.insert(b);
16✔
711
      }
712
    }
16✔
713

714
    // Get maximum number of particles to be banked per surface
715
    if (check_for_node(node_ssw, "max_particles")) {
16✔
716
      max_surface_particles =
16✔
717
        std::stoll(get_node_value(node_ssw, "max_particles"));
16✔
718
    }
719
    if (check_for_node(node_ssw, "mcpl")) {
16✔
UNCOV
720
      surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
×
721

722
      // Make sure MCPL support is enabled
UNCOV
723
      if (surf_mcpl_write && !MCPL_ENABLED) {
×
UNCOV
724
        fatal_error("Your build of OpenMC does not support writing MCPL "
×
725
                    "surface source files.");
726
      }
727
    }
728
  }
729

730
  // If source is not separate and is to be written out in the statepoint file,
731
  // make sure that the sourcepoint batch numbers are contained in the
732
  // statepoint list
733
  if (!source_separate) {
6,454✔
734
    for (const auto& b : sourcepoint_batch) {
12,902✔
735
      if (!contains(statepoint_batch, b)) {
6,543✔
UNCOV
736
        fatal_error(
×
737
          "Sourcepoint batches are not a subset of statepoint batches.");
738
      }
739
    }
740
  }
741

742
  // Check if the user has specified to not reduce tallies at the end of every
743
  // batch
744
  if (check_for_node(root, "no_reduce")) {
6,454✔
UNCOV
745
    reduce_tallies = !get_node_value_bool(root, "no_reduce");
×
746
  }
747

748
  // Check if the user has specified to use confidence intervals for
749
  // uncertainties rather than standard deviations
750
  if (check_for_node(root, "confidence_intervals")) {
6,454✔
751
    confidence_intervals = get_node_value_bool(root, "confidence_intervals");
19✔
752
  }
753

754
  // Check for output options
755
  if (check_for_node(root, "output")) {
6,454✔
756
    // Get pointer to output node
757
    pugi::xml_node node_output = root.child("output");
447✔
758

759
    // Check for summary option
760
    if (check_for_node(node_output, "summary")) {
447✔
761
      output_summary = get_node_value_bool(node_output, "summary");
428✔
762
    }
763

764
    // Check for ASCII tallies output option
765
    if (check_for_node(node_output, "tallies")) {
447✔
766
      output_tallies = get_node_value_bool(node_output, "tallies");
19✔
767
    }
768

769
    // Set output directory if a path has been specified
770
    if (check_for_node(node_output, "path")) {
447✔
UNCOV
771
      path_output = get_node_value(node_output, "path");
×
UNCOV
772
      if (!ends_with(path_output, "/")) {
×
UNCOV
773
        path_output += "/";
×
774
      }
775
    }
776
  }
777

778
  // Resonance scattering parameters
779
  if (check_for_node(root, "resonance_scattering")) {
6,454✔
780
    xml_node node_res_scat = root.child("resonance_scattering");
19✔
781

782
    // See if resonance scattering is enabled
783
    if (check_for_node(node_res_scat, "enable")) {
19✔
784
      res_scat_on = get_node_value_bool(node_res_scat, "enable");
19✔
785
    } else {
UNCOV
786
      res_scat_on = true;
×
787
    }
788

789
    // Determine what method is used
790
    if (check_for_node(node_res_scat, "method")) {
19✔
791
      auto temp = get_node_value(node_res_scat, "method", true, true);
19✔
792
      if (temp == "rvs") {
19✔
793
        res_scat_method = ResScatMethod::rvs;
19✔
UNCOV
794
      } else if (temp == "dbrc") {
×
UNCOV
795
        res_scat_method = ResScatMethod::dbrc;
×
796
      } else {
UNCOV
797
        fatal_error(
×
UNCOV
798
          "Unrecognized resonance elastic scattering method: " + temp + ".");
×
799
      }
800
    }
19✔
801

802
    // Minimum energy for resonance scattering
803
    if (check_for_node(node_res_scat, "energy_min")) {
19✔
804
      res_scat_energy_min =
19✔
805
        std::stod(get_node_value(node_res_scat, "energy_min"));
19✔
806
    }
807
    if (res_scat_energy_min < 0.0) {
19✔
UNCOV
808
      fatal_error("Lower resonance scattering energy bound is negative");
×
809
    }
810

811
    // Maximum energy for resonance scattering
812
    if (check_for_node(node_res_scat, "energy_max")) {
19✔
813
      res_scat_energy_max =
19✔
814
        std::stod(get_node_value(node_res_scat, "energy_max"));
19✔
815
    }
816
    if (res_scat_energy_max < res_scat_energy_min) {
19✔
UNCOV
817
      fatal_error("Upper resonance scattering energy bound is below the "
×
818
                  "lower resonance scattering energy bound.");
819
    }
820

821
    // Get resonance scattering nuclides
822
    if (check_for_node(node_res_scat, "nuclides")) {
19✔
823
      res_scat_nuclides =
824
        get_node_array<std::string>(node_res_scat, "nuclides");
19✔
825
    }
826
  }
827

828
  // Get volume calculations
829
  for (pugi::xml_node node_vol : root.children("volume_calc")) {
6,858✔
830
    model::volume_calcs.emplace_back(node_vol);
404✔
831
  }
832

833
  // Get temperature settings
834
  if (check_for_node(root, "temperature_default")) {
6,454✔
835
    temperature_default =
217✔
836
      std::stod(get_node_value(root, "temperature_default"));
217✔
837
  }
838
  if (check_for_node(root, "temperature_method")) {
6,454✔
839
    auto temp = get_node_value(root, "temperature_method", true, true);
400✔
840
    if (temp == "nearest") {
400✔
841
      temperature_method = TemperatureMethod::NEAREST;
170✔
842
    } else if (temp == "interpolation") {
230✔
843
      temperature_method = TemperatureMethod::INTERPOLATION;
230✔
844
    } else {
UNCOV
845
      fatal_error("Unknown temperature method: " + temp);
×
846
    }
847
  }
400✔
848
  if (check_for_node(root, "temperature_tolerance")) {
6,454✔
849
    temperature_tolerance =
216✔
850
      std::stod(get_node_value(root, "temperature_tolerance"));
216✔
851
  }
852
  if (check_for_node(root, "temperature_multipole")) {
6,454✔
853
    temperature_multipole = get_node_value_bool(root, "temperature_multipole");
38✔
854

855
    // Multipole currently doesn't work with photon transport
856
    if (temperature_multipole && photon_transport) {
38✔
857
      fatal_error("Multipole data cannot currently be used in conjunction with "
×
858
                  "photon transport.");
859
    }
860
  }
861
  if (check_for_node(root, "temperature_range")) {
6,454✔
UNCOV
862
    auto range = get_node_array<double>(root, "temperature_range");
×
UNCOV
863
    temperature_range[0] = range.at(0);
×
UNCOV
864
    temperature_range[1] = range.at(1);
×
865
  }
866

867
  // Check for tabular_legendre options
868
  if (check_for_node(root, "tabular_legendre")) {
6,454✔
869
    // Get pointer to tabular_legendre node
870
    xml_node node_tab_leg = root.child("tabular_legendre");
114✔
871

872
    // Check for enable option
873
    if (check_for_node(node_tab_leg, "enable")) {
114✔
874
      legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
114✔
875
    }
876

877
    // Check for the number of points
878
    if (check_for_node(node_tab_leg, "num_points")) {
114✔
UNCOV
879
      legendre_to_tabular_points =
×
UNCOV
880
        std::stoi(get_node_value(node_tab_leg, "num_points"));
×
UNCOV
881
      if (legendre_to_tabular_points <= 1 && !run_CE) {
×
UNCOV
882
        fatal_error(
×
883
          "The 'num_points' subelement/attribute of the "
884
          "<tabular_legendre> element must contain a value greater than 1");
885
      }
886
    }
887
  }
888

889
  // Check whether create delayed neutrons in fission
890
  if (check_for_node(root, "create_delayed_neutrons")) {
6,454✔
UNCOV
891
    create_delayed_neutrons =
×
UNCOV
892
      get_node_value_bool(root, "create_delayed_neutrons");
×
893
  }
894

895
  // Check whether create fission sites
896
  if (run_mode == RunMode::FIXED_SOURCE) {
6,454✔
897
    if (check_for_node(root, "create_fission_neutrons")) {
1,865✔
898
      create_fission_neutrons =
19✔
899
        get_node_value_bool(root, "create_fission_neutrons");
19✔
900
    }
901
  }
902

903
  // Check whether to scale fission photon yields
904
  if (check_for_node(root, "delayed_photon_scaling")) {
6,454✔
UNCOV
905
    delayed_photon_scaling =
×
UNCOV
906
      get_node_value_bool(root, "delayed_photon_scaling");
×
907
  }
908

909
  // Check whether to use event-based parallelism
910
  if (check_for_node(root, "event_based")) {
6,454✔
UNCOV
911
    event_based = get_node_value_bool(root, "event_based");
×
912
  }
913

914
  // Check whether material cell offsets should be generated
915
  if (check_for_node(root, "material_cell_offsets")) {
6,454✔
UNCOV
916
    material_cell_offsets = get_node_value_bool(root, "material_cell_offsets");
×
917
  }
918

919
  // Weight window information
920
  for (pugi::xml_node node_ww : root.children("weight_windows")) {
6,534✔
921
    variance_reduction::weight_windows.emplace_back(
80✔
922
      std::make_unique<WeightWindows>(node_ww));
160✔
923
  }
924

925
  // Enable weight windows by default if one or more are present
926
  if (variance_reduction::weight_windows.size() > 0)
6,454✔
927
    settings::weight_windows_on = true;
47✔
928

929
  // read weight windows from file
930
  if (check_for_node(root, "weight_windows_file")) {
6,454✔
UNCOV
931
    weight_windows_file = get_node_value(root, "weight_windows_file");
×
932
  }
933

934
  // read settings for weight windows value, this will override
935
  // the automatic setting even if weight windows are present
936
  if (check_for_node(root, "weight_windows_on")) {
6,454✔
937
    weight_windows_on = get_node_value_bool(root, "weight_windows_on");
28✔
938
  }
939

940
  if (check_for_node(root, "max_splits")) {
6,454✔
941
    settings::max_splits = std::stoi(get_node_value(root, "max_splits"));
271✔
942
  }
943

944
  if (check_for_node(root, "max_tracks")) {
6,454✔
945
    settings::max_tracks = std::stoi(get_node_value(root, "max_tracks"));
57✔
946
  }
947

948
  // Create weight window generator objects
949
  if (check_for_node(root, "weight_window_generators")) {
6,454✔
950
    auto wwgs_node = root.child("weight_window_generators");
28✔
951
    for (pugi::xml_node node_wwg :
28✔
952
      wwgs_node.children("weight_windows_generator")) {
84✔
953
      variance_reduction::weight_windows_generators.emplace_back(
28✔
954
        std::make_unique<WeightWindowsGenerator>(node_wwg));
56✔
955
    }
956
    // if any of the weight windows are intended to be generated otf, make sure
957
    // they're applied
958
    for (const auto& wwg : variance_reduction::weight_windows_generators) {
28✔
959
      if (wwg->on_the_fly_) {
28✔
960
        settings::weight_windows_on = true;
28✔
961
        break;
28✔
962
      }
963
    }
964
  }
965

966
  // Set up weight window checkpoints
967
  if (check_for_node(root, "weight_window_checkpoints")) {
6,454✔
968
    xml_node ww_checkpoints = root.child("weight_window_checkpoints");
×
UNCOV
969
    if (check_for_node(ww_checkpoints, "collision")) {
×
UNCOV
970
      weight_window_checkpoint_collision =
×
UNCOV
971
        get_node_value_bool(ww_checkpoints, "collision");
×
972
    }
UNCOV
973
    if (check_for_node(ww_checkpoints, "surface")) {
×
UNCOV
974
      weight_window_checkpoint_surface =
×
UNCOV
975
        get_node_value_bool(ww_checkpoints, "surface");
×
976
    }
977
  }
978
}
6,454✔
979

980
void free_memory_settings()
6,620✔
981
{
982
  settings::statepoint_batch.clear();
6,620✔
983
  settings::sourcepoint_batch.clear();
6,620✔
984
  settings::source_write_surf_id.clear();
6,620✔
985
  settings::res_scat_nuclides.clear();
6,620✔
986
}
6,620✔
987

988
//==============================================================================
989
// C API functions
990
//==============================================================================
991

992
extern "C" int openmc_set_n_batches(
70✔
993
  int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
994
{
995
  if (settings::n_inactive >= n_batches) {
70✔
996
    set_errmsg("Number of active batches must be greater than zero.");
14✔
997
    return OPENMC_E_INVALID_ARGUMENT;
14✔
998
  }
999

1000
  if (simulation::current_batch >= n_batches) {
56✔
1001
    set_errmsg("Number of batches must be greater than current batch.");
14✔
1002
    return OPENMC_E_INVALID_ARGUMENT;
14✔
1003
  }
1004

1005
  if (!settings::trigger_on) {
42✔
1006
    // Set n_batches and n_max_batches to same value
1007
    settings::n_batches = n_batches;
14✔
1008
    settings::n_max_batches = n_batches;
14✔
1009
  } else {
1010
    // Set n_batches and n_max_batches based on value of set_max_batches
1011
    if (set_max_batches) {
28✔
1012
      settings::n_max_batches = n_batches;
14✔
1013
    } else {
1014
      settings::n_batches = n_batches;
14✔
1015
    }
1016
  }
1017

1018
  // Update size of k_generation and entropy
1019
  int m = settings::n_max_batches * settings::gen_per_batch;
42✔
1020
  simulation::k_generation.reserve(m);
42✔
1021
  simulation::entropy.reserve(m);
42✔
1022

1023
  // Add value of n_batches to statepoint_batch
1024
  if (add_statepoint_batch &&
70✔
1025
      !(contains(settings::statepoint_batch, n_batches)))
28✔
1026
    settings::statepoint_batch.insert(n_batches);
28✔
1027

1028
  return 0;
42✔
1029
}
1030

1031
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
5,020✔
1032
{
1033
  *n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;
5,020✔
1034

1035
  return 0;
5,020✔
1036
}
1037

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