forked from openmc-dev/openmc
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsettings.cpp
1151 lines (1020 loc) · 39.5 KB
/
settings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "openmc/settings.h"
#include <cmath> // for ceil, pow
#include <limits> // for numeric_limits
#include <string>
#include <fmt/core.h>
#ifdef _OPENMP
#include <omp.h>
#endif
#include "openmc/capi.h"
#include "openmc/constants.h"
#include "openmc/container_util.h"
#include "openmc/distribution.h"
#include "openmc/distribution_multi.h"
#include "openmc/distribution_spatial.h"
#include "openmc/eigenvalue.h"
#include "openmc/error.h"
#include "openmc/file_utils.h"
#include "openmc/mcpl_interface.h"
#include "openmc/mesh.h"
#include "openmc/message_passing.h"
#include "openmc/output.h"
#include "openmc/plot.h"
#include "openmc/random_lcg.h"
#include "openmc/random_ray/random_ray.h"
#include "openmc/simulation.h"
#include "openmc/source.h"
#include "openmc/string_utils.h"
#include "openmc/tallies/trigger.h"
#include "openmc/volume_calc.h"
#include "openmc/weight_windows.h"
#include "openmc/xml_interface.h"
namespace openmc {
//==============================================================================
// Global variables
//==============================================================================
namespace settings {
// Default values for boolean flags
bool assume_separate {false};
bool check_overlaps {false};
bool cmfd_run {false};
bool confidence_intervals {false};
bool create_delayed_neutrons {true};
bool create_fission_neutrons {true};
bool delayed_photon_scaling {true};
bool entropy_on {false};
bool event_based {false};
bool legendre_to_tabular {true};
bool material_cell_offsets {true};
bool output_summary {true};
bool output_tallies {true};
bool particle_restart_run {false};
bool photon_transport {false};
bool reduce_tallies {true};
bool res_scat_on {false};
bool restart_run {false};
bool run_CE {true};
bool source_latest {false};
bool source_separate {false};
bool source_write {true};
bool source_mcpl_write {false};
bool surf_source_write {false};
bool surf_mcpl_write {false};
bool surf_source_read {false};
bool survival_biasing {false};
bool temperature_multipole {false};
bool trigger_on {false};
bool trigger_predict {false};
bool ufs_on {false};
bool urr_ptables_on {true};
bool weight_windows_on {false};
bool weight_window_checkpoint_surface {false};
bool weight_window_checkpoint_collision {true};
bool write_all_tracks {false};
bool write_initial_source {false};
std::string path_cross_sections;
std::string path_input;
std::string path_output;
std::string path_particle_restart;
std::string path_sourcepoint;
std::string path_statepoint;
const char* path_statepoint_c {path_statepoint.c_str()};
std::string weight_windows_file;
int32_t n_inactive {0};
int32_t max_lost_particles {10};
double rel_max_lost_particles {1.0e-6};
int32_t max_write_lost_particles {-1};
int32_t gen_per_batch {1};
int64_t n_particles {-1};
int64_t max_particles_in_flight {100000};
int max_particle_events {1000000};
ElectronTreatment electron_treatment {ElectronTreatment::TTB};
array<double, 4> energy_cutoff {0.0, 1000.0, 0.0, 0.0};
array<double, 4> time_cutoff {INFTY, INFTY, INFTY, INFTY};
int legendre_to_tabular_points {C_NONE};
int max_order {0};
int n_log_bins {8000};
int n_batches;
int n_max_batches;
int max_history_splits {10'000'000};
int max_tracks {1000};
ResScatMethod res_scat_method {ResScatMethod::rvs};
double res_scat_energy_min {0.01};
double res_scat_energy_max {1000.0};
vector<std::string> res_scat_nuclides;
RunMode run_mode {RunMode::UNSET};
SolverType solver_type {SolverType::MONTE_CARLO};
std::unordered_set<int> sourcepoint_batch;
std::unordered_set<int> statepoint_batch;
std::unordered_set<int> source_write_surf_id;
int64_t max_surface_particles;
int64_t ssw_cell_id {C_NONE};
SSWCellType ssw_cell_type {SSWCellType::None};
TemperatureMethod temperature_method {TemperatureMethod::NEAREST};
double temperature_tolerance {10.0};
double temperature_default {293.6};
array<double, 2> temperature_range {0.0, 0.0};
int trace_batch;
int trace_gen;
int64_t trace_particle;
vector<array<int, 3>> track_identifiers;
int trigger_batch_interval {1};
int verbosity {7};
double weight_cutoff {0.25};
double weight_survive {1.0};
} // namespace settings
//==============================================================================
// Functions
//==============================================================================
void get_run_parameters(pugi::xml_node node_base)
{
using namespace settings;
using namespace pugi;
// Check number of particles
if (!check_for_node(node_base, "particles")) {
fatal_error("Need to specify number of particles.");
}
// Get number of particles if it wasn't specified as a command-line argument
if (n_particles == -1) {
n_particles = std::stoll(get_node_value(node_base, "particles"));
}
// Get maximum number of in flight particles for event-based mode
if (check_for_node(node_base, "max_particles_in_flight")) {
max_particles_in_flight =
std::stoll(get_node_value(node_base, "max_particles_in_flight"));
}
// Get maximum number of events allowed per particle
if (check_for_node(node_base, "max_particle_events")) {
max_particle_events =
std::stoll(get_node_value(node_base, "max_particle_events"));
}
// Get number of basic batches
if (check_for_node(node_base, "batches")) {
n_batches = std::stoi(get_node_value(node_base, "batches"));
}
if (!trigger_on)
n_max_batches = n_batches;
// Get max number of lost particles
if (check_for_node(node_base, "max_lost_particles")) {
max_lost_particles =
std::stoi(get_node_value(node_base, "max_lost_particles"));
}
// Get relative number of lost particles
if (check_for_node(node_base, "rel_max_lost_particles")) {
rel_max_lost_particles =
std::stod(get_node_value(node_base, "rel_max_lost_particles"));
}
// Get relative number of lost particles
if (check_for_node(node_base, "max_write_lost_particles")) {
max_write_lost_particles =
std::stoi(get_node_value(node_base, "max_write_lost_particles"));
}
// Get number of inactive batches
if (run_mode == RunMode::EIGENVALUE ||
solver_type == SolverType::RANDOM_RAY) {
if (check_for_node(node_base, "inactive")) {
n_inactive = std::stoi(get_node_value(node_base, "inactive"));
}
if (check_for_node(node_base, "generations_per_batch")) {
gen_per_batch =
std::stoi(get_node_value(node_base, "generations_per_batch"));
}
// Preallocate space for keff and entropy by generation
int m = settings::n_max_batches * settings::gen_per_batch;
simulation::k_generation.reserve(m);
simulation::entropy.reserve(m);
// Get the trigger information for keff
if (check_for_node(node_base, "keff_trigger")) {
xml_node node_keff_trigger = node_base.child("keff_trigger");
if (check_for_node(node_keff_trigger, "type")) {
auto temp = get_node_value(node_keff_trigger, "type", true, true);
if (temp == "std_dev") {
keff_trigger.metric = TriggerMetric::standard_deviation;
} else if (temp == "variance") {
keff_trigger.metric = TriggerMetric::variance;
} else if (temp == "rel_err") {
keff_trigger.metric = TriggerMetric::relative_error;
} else {
fatal_error("Unrecognized keff trigger type " + temp);
}
} else {
fatal_error("Specify keff trigger type in settings XML");
}
if (check_for_node(node_keff_trigger, "threshold")) {
keff_trigger.threshold =
std::stod(get_node_value(node_keff_trigger, "threshold"));
if (keff_trigger.threshold <= 0) {
fatal_error("keff trigger threshold must be positive");
}
} else {
fatal_error("Specify keff trigger threshold in settings XML");
}
}
}
// Random ray variables
if (solver_type == SolverType::RANDOM_RAY) {
xml_node random_ray_node = node_base.child("random_ray");
if (check_for_node(random_ray_node, "distance_active")) {
RandomRay::distance_active_ =
std::stod(get_node_value(random_ray_node, "distance_active"));
if (RandomRay::distance_active_ <= 0.0) {
fatal_error("Random ray active distance must be greater than 0");
}
} else {
fatal_error("Specify random ray active distance in settings XML");
}
if (check_for_node(random_ray_node, "distance_inactive")) {
RandomRay::distance_inactive_ =
std::stod(get_node_value(random_ray_node, "distance_inactive"));
if (RandomRay::distance_inactive_ < 0) {
fatal_error(
"Random ray inactive distance must be greater than or equal to 0");
}
} else {
fatal_error("Specify random ray inactive distance in settings XML");
}
if (check_for_node(random_ray_node, "source")) {
xml_node source_node = random_ray_node.child("source");
// Get point to list of <source> elements and make sure there is at least
// one
RandomRay::ray_source_ = Source::create(source_node);
} else {
fatal_error("Specify random ray source in settings XML");
}
if (check_for_node(random_ray_node, "volume_estimator")) {
std::string temp_str =
get_node_value(random_ray_node, "volume_estimator", true, true);
if (temp_str == "simulation_averaged") {
FlatSourceDomain::volume_estimator_ =
RandomRayVolumeEstimator::SIMULATION_AVERAGED;
} else if (temp_str == "naive") {
FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::NAIVE;
} else if (temp_str == "hybrid") {
FlatSourceDomain::volume_estimator_ = RandomRayVolumeEstimator::HYBRID;
} else {
fatal_error("Unrecognized volume estimator: " + temp_str);
}
}
if (check_for_node(random_ray_node, "source_shape")) {
std::string temp_str =
get_node_value(random_ray_node, "source_shape", true, true);
if (temp_str == "flat") {
RandomRay::source_shape_ = RandomRaySourceShape::FLAT;
} else if (temp_str == "linear") {
RandomRay::source_shape_ = RandomRaySourceShape::LINEAR;
} else if (temp_str == "linear_xy") {
RandomRay::source_shape_ = RandomRaySourceShape::LINEAR_XY;
} else {
fatal_error("Unrecognized source shape: " + temp_str);
}
}
if (check_for_node(random_ray_node, "volume_normalized_flux_tallies")) {
FlatSourceDomain::volume_normalized_flux_tallies_ =
get_node_value_bool(random_ray_node, "volume_normalized_flux_tallies");
}
}
}
void read_settings_xml()
{
using namespace settings;
using namespace pugi;
// Check if settings.xml exists
std::string filename = settings::path_input + "settings.xml";
if (!file_exists(filename)) {
if (run_mode != RunMode::PLOTTING) {
fatal_error("Could not find any XML input files! In order to run OpenMC, "
"you first need a set of input files; at a minimum, this "
"includes settings.xml, geometry.xml, and materials.xml or a "
"single model XML file. Please consult the user's guide at "
"https://docs.openmc.org for further information.");
} else {
// The settings.xml file is optional if we just want to make a plot.
return;
}
}
// Parse settings.xml file
xml_document doc;
auto result = doc.load_file(filename.c_str());
if (!result) {
fatal_error("Error processing settings.xml file.");
}
// Get root element
xml_node root = doc.document_element();
// Verbosity
if (check_for_node(root, "verbosity")) {
verbosity = std::stoi(get_node_value(root, "verbosity"));
}
// To this point, we haven't displayed any output since we didn't know what
// the verbosity is. Now that we checked for it, show the title if necessary
if (mpi::master) {
if (verbosity >= 2)
title();
}
write_message("Reading settings XML file...", 5);
read_settings_xml(root);
}
void read_settings_xml(pugi::xml_node root)
{
using namespace settings;
using namespace pugi;
// Find if a multi-group or continuous-energy simulation is desired
if (check_for_node(root, "energy_mode")) {
std::string temp_str = get_node_value(root, "energy_mode", true, true);
if (temp_str == "mg" || temp_str == "multi-group") {
run_CE = false;
} else if (temp_str == "ce" || temp_str == "continuous-energy") {
run_CE = true;
}
}
// Check for user meshes and allocate
read_meshes(root);
// Look for deprecated cross_sections.xml file in settings.xml
if (check_for_node(root, "cross_sections")) {
warning(
"Setting cross_sections in settings.xml has been deprecated."
" The cross_sections are now set in materials.xml and the "
"cross_sections input to materials.xml and the OPENMC_CROSS_SECTIONS"
" environment variable will take precendent over setting "
"cross_sections in settings.xml.");
path_cross_sections = get_node_value(root, "cross_sections");
}
if (!run_CE) {
// Scattering Treatments
if (check_for_node(root, "max_order")) {
max_order = std::stoi(get_node_value(root, "max_order"));
} else {
// Set to default of largest int - 1, which means to use whatever is
// contained in library. This is largest int - 1 because for legendre
// scattering, a value of 1 is added to the order; adding 1 to the largest
// int gets you the largest negative integer, which is not what we want.
max_order = std::numeric_limits<int>::max() - 1;
}
}
// Check for a trigger node and get trigger information
if (check_for_node(root, "trigger")) {
xml_node node_trigger = root.child("trigger");
// Check if trigger(s) are to be turned on
trigger_on = get_node_value_bool(node_trigger, "active");
if (trigger_on) {
if (check_for_node(node_trigger, "max_batches")) {
n_max_batches = std::stoi(get_node_value(node_trigger, "max_batches"));
} else {
fatal_error("<max_batches> must be specified with triggers");
}
// Get the batch interval to check triggers
if (!check_for_node(node_trigger, "batch_interval")) {
trigger_predict = true;
} else {
trigger_batch_interval =
std::stoi(get_node_value(node_trigger, "batch_interval"));
if (trigger_batch_interval <= 0) {
fatal_error("Trigger batch interval must be greater than zero");
}
}
}
}
// Check run mode if it hasn't been set from the command line
xml_node node_mode;
if (run_mode == RunMode::UNSET) {
if (check_for_node(root, "run_mode")) {
std::string temp_str = get_node_value(root, "run_mode", true, true);
if (temp_str == "eigenvalue") {
run_mode = RunMode::EIGENVALUE;
} else if (temp_str == "fixed source") {
run_mode = RunMode::FIXED_SOURCE;
} else if (temp_str == "plot") {
run_mode = RunMode::PLOTTING;
} else if (temp_str == "particle restart") {
run_mode = RunMode::PARTICLE;
} else if (temp_str == "volume") {
run_mode = RunMode::VOLUME;
} else {
fatal_error("Unrecognized run mode: " + temp_str);
}
// Assume XML specifies <particles>, <batches>, etc. directly
node_mode = root;
} else {
warning("<run_mode> should be specified.");
// Make sure that either eigenvalue or fixed source was specified
node_mode = root.child("eigenvalue");
if (node_mode) {
run_mode = RunMode::EIGENVALUE;
} else {
node_mode = root.child("fixed_source");
if (node_mode) {
run_mode = RunMode::FIXED_SOURCE;
} else {
fatal_error("<eigenvalue> or <fixed_source> not specified.");
}
}
}
}
// Check solver type
if (check_for_node(root, "random_ray")) {
solver_type = SolverType::RANDOM_RAY;
if (run_CE)
fatal_error("multi-group energy mode must be specified in settings XML "
"when using the random ray solver.");
}
if (run_mode == RunMode::EIGENVALUE || run_mode == RunMode::FIXED_SOURCE) {
// Read run parameters
get_run_parameters(node_mode);
// Check number of active batches, inactive batches, max lost particles and
// particles
if (n_batches <= n_inactive) {
fatal_error("Number of active batches must be greater than zero.");
} else if (n_inactive < 0) {
fatal_error("Number of inactive batches must be non-negative.");
} else if (n_particles <= 0) {
fatal_error("Number of particles must be greater than zero.");
} else if (max_lost_particles <= 0) {
fatal_error("Number of max lost particles must be greater than zero.");
} else if (rel_max_lost_particles <= 0.0 || rel_max_lost_particles >= 1.0) {
fatal_error("Relative max lost particles must be between zero and one.");
}
}
// Copy plotting random number seed if specified
if (check_for_node(root, "plot_seed")) {
auto seed = std::stoll(get_node_value(root, "plot_seed"));
model::plotter_seed = seed;
}
// Copy random number seed if specified
if (check_for_node(root, "seed")) {
auto seed = std::stoll(get_node_value(root, "seed"));
openmc_set_seed(seed);
}
// Check for electron treatment
if (check_for_node(root, "electron_treatment")) {
auto temp_str = get_node_value(root, "electron_treatment", true, true);
if (temp_str == "led") {
electron_treatment = ElectronTreatment::LED;
} else if (temp_str == "ttb") {
electron_treatment = ElectronTreatment::TTB;
} else {
fatal_error("Unrecognized electron treatment: " + temp_str + ".");
}
}
// Check for photon transport
if (check_for_node(root, "photon_transport")) {
photon_transport = get_node_value_bool(root, "photon_transport");
if (!run_CE && photon_transport) {
fatal_error("Photon transport is not currently supported in "
"multigroup mode");
}
}
// Number of bins for logarithmic grid
if (check_for_node(root, "log_grid_bins")) {
n_log_bins = std::stoi(get_node_value(root, "log_grid_bins"));
if (n_log_bins < 1) {
fatal_error("Number of bins for logarithmic grid must be greater "
"than zero.");
}
}
// Number of OpenMP threads
if (check_for_node(root, "threads")) {
if (mpi::master)
warning("The <threads> element has been deprecated. Use "
"the OMP_NUM_THREADS environment variable to set the number of "
"threads.");
}
// ==========================================================================
// EXTERNAL SOURCE
// Get point to list of <source> elements and make sure there is at least one
for (pugi::xml_node node : root.children("source")) {
model::external_sources.push_back(Source::create(node));
}
// Check if the user has specified to read surface source
if (check_for_node(root, "surf_source_read")) {
surf_source_read = true;
// Get surface source read node
xml_node node_ssr = root.child("surf_source_read");
std::string path = "surface_source.h5";
// Check if the user has specified different file for surface source reading
if (check_for_node(node_ssr, "path")) {
path = get_node_value(node_ssr, "path", false, true);
}
model::external_sources.push_back(make_unique<FileSource>(path));
}
// If no source specified, default to isotropic point source at origin with
// Watt spectrum. No default source is needed in random ray mode.
if (model::external_sources.empty() &&
settings::solver_type != SolverType::RANDOM_RAY) {
double T[] {0.0};
double p[] {1.0};
model::external_sources.push_back(make_unique<IndependentSource>(
UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
UPtrAngle {new Isotropic()}, UPtrDist {new Watt(0.988e6, 2.249e-6)},
UPtrDist {new Discrete(T, p, 1)}));
}
// Check if we want to write out source
if (check_for_node(root, "write_initial_source")) {
write_initial_source = get_node_value_bool(root, "write_initial_source");
}
// Survival biasing
if (check_for_node(root, "survival_biasing")) {
survival_biasing = get_node_value_bool(root, "survival_biasing");
}
// Probability tables
if (check_for_node(root, "ptables")) {
urr_ptables_on = get_node_value_bool(root, "ptables");
}
// Cutoffs
if (check_for_node(root, "cutoff")) {
xml_node node_cutoff = root.child("cutoff");
if (check_for_node(node_cutoff, "weight")) {
weight_cutoff = std::stod(get_node_value(node_cutoff, "weight"));
}
if (check_for_node(node_cutoff, "weight_avg")) {
weight_survive = std::stod(get_node_value(node_cutoff, "weight_avg"));
}
if (check_for_node(node_cutoff, "energy_neutron")) {
energy_cutoff[0] =
std::stod(get_node_value(node_cutoff, "energy_neutron"));
} else if (check_for_node(node_cutoff, "energy")) {
warning("The use of an <energy> cutoff is deprecated and should "
"be replaced by <energy_neutron>.");
energy_cutoff[0] = std::stod(get_node_value(node_cutoff, "energy"));
}
if (check_for_node(node_cutoff, "energy_photon")) {
energy_cutoff[1] =
std::stod(get_node_value(node_cutoff, "energy_photon"));
}
if (check_for_node(node_cutoff, "energy_electron")) {
energy_cutoff[2] =
std::stof(get_node_value(node_cutoff, "energy_electron"));
}
if (check_for_node(node_cutoff, "energy_positron")) {
energy_cutoff[3] =
std::stod(get_node_value(node_cutoff, "energy_positron"));
}
if (check_for_node(node_cutoff, "time_neutron")) {
time_cutoff[0] = std::stod(get_node_value(node_cutoff, "time_neutron"));
}
if (check_for_node(node_cutoff, "time_photon")) {
time_cutoff[1] = std::stod(get_node_value(node_cutoff, "time_photon"));
}
if (check_for_node(node_cutoff, "time_electron")) {
time_cutoff[2] = std::stod(get_node_value(node_cutoff, "time_electron"));
}
if (check_for_node(node_cutoff, "time_positron")) {
time_cutoff[3] = std::stod(get_node_value(node_cutoff, "time_positron"));
}
}
// Particle trace
if (check_for_node(root, "trace")) {
auto temp = get_node_array<int64_t>(root, "trace");
if (temp.size() != 3) {
fatal_error("Must provide 3 integers for <trace> that specify the "
"batch, generation, and particle number.");
}
trace_batch = temp.at(0);
trace_gen = temp.at(1);
trace_particle = temp.at(2);
}
// Particle tracks
if (check_for_node(root, "track")) {
// Get values and make sure there are three per particle
auto temp = get_node_array<int>(root, "track");
if (temp.size() % 3 != 0) {
fatal_error(
"Number of integers specified in 'track' is not "
"divisible by 3. Please provide 3 integers per particle to be "
"tracked.");
}
// Reshape into track_identifiers
int n_tracks = temp.size() / 3;
for (int i = 0; i < n_tracks; ++i) {
track_identifiers.push_back(
{temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
}
}
// Shannon entropy
if (solver_type == SolverType::RANDOM_RAY) {
if (check_for_node(root, "entropy_mesh")) {
fatal_error("Random ray uses FSRs to compute the Shannon entropy. "
"No user-defined entropy mesh is supported.");
}
entropy_on = true;
} else if (solver_type == SolverType::MONTE_CARLO) {
if (check_for_node(root, "entropy_mesh")) {
int temp = std::stoi(get_node_value(root, "entropy_mesh"));
if (model::mesh_map.find(temp) == model::mesh_map.end()) {
fatal_error(fmt::format(
"Mesh {} specified for Shannon entropy does not exist.", temp));
}
auto* m = dynamic_cast<RegularMesh*>(
model::meshes[model::mesh_map.at(temp)].get());
if (!m)
fatal_error("Only regular meshes can be used as an entropy mesh");
simulation::entropy_mesh = m;
// Turn on Shannon entropy calculation
entropy_on = true;
} else if (check_for_node(root, "entropy")) {
fatal_error(
"Specifying a Shannon entropy mesh via the <entropy> element "
"is deprecated. Please create a mesh using <mesh> and then reference "
"it by specifying its ID in an <entropy_mesh> element.");
}
}
// Uniform fission source weighting mesh
if (check_for_node(root, "ufs_mesh")) {
auto temp = std::stoi(get_node_value(root, "ufs_mesh"));
if (model::mesh_map.find(temp) == model::mesh_map.end()) {
fatal_error(fmt::format("Mesh {} specified for uniform fission site "
"method does not exist.",
temp));
}
auto* m =
dynamic_cast<RegularMesh*>(model::meshes[model::mesh_map.at(temp)].get());
if (!m)
fatal_error("Only regular meshes can be used as a UFS mesh");
simulation::ufs_mesh = m;
// Turn on uniform fission source weighting
ufs_on = true;
} else if (check_for_node(root, "uniform_fs")) {
fatal_error(
"Specifying a UFS mesh via the <uniform_fs> element "
"is deprecated. Please create a mesh using <mesh> and then reference "
"it by specifying its ID in a <ufs_mesh> element.");
}
// Check if the user has specified to write state points
if (check_for_node(root, "state_point")) {
// Get pointer to state_point node
auto node_sp = root.child("state_point");
// Determine number of batches at which to store state points
if (check_for_node(node_sp, "batches")) {
// User gave specific batches to write state points
auto temp = get_node_array<int>(node_sp, "batches");
for (const auto& b : temp) {
statepoint_batch.insert(b);
}
} else {
// If neither were specified, write state point at last batch
statepoint_batch.insert(n_batches);
}
} else {
// If no <state_point> tag was present, by default write state point at
// last batch only
statepoint_batch.insert(n_batches);
}
// Check if the user has specified to write source points
if (check_for_node(root, "source_point")) {
// Get source_point node
xml_node node_sp = root.child("source_point");
// Determine batches at which to store source points
if (check_for_node(node_sp, "batches")) {
// User gave specific batches to write source points
auto temp = get_node_array<int>(node_sp, "batches");
for (const auto& b : temp) {
sourcepoint_batch.insert(b);
}
} else {
// If neither were specified, write source points with state points
sourcepoint_batch = statepoint_batch;
}
// Check if the user has specified to write binary source file
if (check_for_node(node_sp, "separate")) {
source_separate = get_node_value_bool(node_sp, "separate");
}
if (check_for_node(node_sp, "write")) {
source_write = get_node_value_bool(node_sp, "write");
}
if (check_for_node(node_sp, "mcpl")) {
source_mcpl_write = get_node_value_bool(node_sp, "mcpl");
// Make sure MCPL support is enabled
if (source_mcpl_write && !MCPL_ENABLED) {
fatal_error(
"Your build of OpenMC does not support writing MCPL source files.");
}
}
if (check_for_node(node_sp, "overwrite_latest")) {
source_latest = get_node_value_bool(node_sp, "overwrite_latest");
source_separate = source_latest;
}
} else {
// If no <source_point> tag was present, by default we keep source bank in
// statepoint file and write it out at statepoints intervals
source_separate = false;
sourcepoint_batch = statepoint_batch;
}
// Check if the user has specified to write surface source
if (check_for_node(root, "surf_source_write")) {
surf_source_write = true;
// Get surface source write node
xml_node node_ssw = root.child("surf_source_write");
// Determine surface ids at which crossing particles are to be banked.
// If no surfaces are specified, all surfaces in the model will be used
// to bank source points.
if (check_for_node(node_ssw, "surface_ids")) {
auto temp = get_node_array<int>(node_ssw, "surface_ids");
for (const auto& b : temp) {
source_write_surf_id.insert(b);
}
}
// Get maximum number of particles to be banked per surface
if (check_for_node(node_ssw, "max_particles")) {
max_surface_particles =
std::stoll(get_node_value(node_ssw, "max_particles"));
} else {
fatal_error("A maximum number of particles needs to be specified "
"using the 'max_particles' parameter to store surface "
"source points.");
}
if (check_for_node(node_ssw, "mcpl")) {
surf_mcpl_write = get_node_value_bool(node_ssw, "mcpl");
// Make sure MCPL support is enabled
if (surf_mcpl_write && !MCPL_ENABLED) {
fatal_error("Your build of OpenMC does not support writing MCPL "
"surface source files.");
}
}
// Get cell information
if (check_for_node(node_ssw, "cell")) {
ssw_cell_id = std::stoll(get_node_value(node_ssw, "cell"));
ssw_cell_type = SSWCellType::Both;
}
if (check_for_node(node_ssw, "cellfrom")) {
if (ssw_cell_id != C_NONE) {
fatal_error(
"'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
}
ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellfrom"));
ssw_cell_type = SSWCellType::From;
}
if (check_for_node(node_ssw, "cellto")) {
if (ssw_cell_id != C_NONE) {
fatal_error(
"'cell', 'cellfrom' and 'cellto' cannot be used at the same time.");
}
ssw_cell_id = std::stoll(get_node_value(node_ssw, "cellto"));
ssw_cell_type = SSWCellType::To;
}
}
// If source is not separate and is to be written out in the statepoint file,
// make sure that the sourcepoint batch numbers are contained in the
// statepoint list
if (!source_separate) {
for (const auto& b : sourcepoint_batch) {
if (!contains(statepoint_batch, b)) {
fatal_error(
"Sourcepoint batches are not a subset of statepoint batches.");
}
}
}
// Check if the user has specified to not reduce tallies at the end of every
// batch
if (check_for_node(root, "no_reduce")) {
reduce_tallies = !get_node_value_bool(root, "no_reduce");
}
// Check if the user has specified to use confidence intervals for
// uncertainties rather than standard deviations
if (check_for_node(root, "confidence_intervals")) {
confidence_intervals = get_node_value_bool(root, "confidence_intervals");
}
// Check for output options
if (check_for_node(root, "output")) {
// Get pointer to output node
pugi::xml_node node_output = root.child("output");
// Check for summary option
if (check_for_node(node_output, "summary")) {
output_summary = get_node_value_bool(node_output, "summary");
}
// Check for ASCII tallies output option
if (check_for_node(node_output, "tallies")) {
output_tallies = get_node_value_bool(node_output, "tallies");
}
// Set output directory if a path has been specified
if (check_for_node(node_output, "path")) {
path_output = get_node_value(node_output, "path");
if (!ends_with(path_output, "/")) {
path_output += "/";
}
}
}
// Resonance scattering parameters
if (check_for_node(root, "resonance_scattering")) {
xml_node node_res_scat = root.child("resonance_scattering");
// See if resonance scattering is enabled
if (check_for_node(node_res_scat, "enable")) {
res_scat_on = get_node_value_bool(node_res_scat, "enable");
} else {
res_scat_on = true;
}
// Determine what method is used
if (check_for_node(node_res_scat, "method")) {
auto temp = get_node_value(node_res_scat, "method", true, true);
if (temp == "rvs") {
res_scat_method = ResScatMethod::rvs;
} else if (temp == "dbrc") {
res_scat_method = ResScatMethod::dbrc;
} else {
fatal_error(
"Unrecognized resonance elastic scattering method: " + temp + ".");
}
}
// Minimum energy for resonance scattering
if (check_for_node(node_res_scat, "energy_min")) {
res_scat_energy_min =
std::stod(get_node_value(node_res_scat, "energy_min"));
}
if (res_scat_energy_min < 0.0) {
fatal_error("Lower resonance scattering energy bound is negative");
}
// Maximum energy for resonance scattering
if (check_for_node(node_res_scat, "energy_max")) {
res_scat_energy_max =
std::stod(get_node_value(node_res_scat, "energy_max"));
}
if (res_scat_energy_max < res_scat_energy_min) {
fatal_error("Upper resonance scattering energy bound is below the "
"lower resonance scattering energy bound.");
}
// Get resonance scattering nuclides
if (check_for_node(node_res_scat, "nuclides")) {
res_scat_nuclides =
get_node_array<std::string>(node_res_scat, "nuclides");
}
}
// Get volume calculations
for (pugi::xml_node node_vol : root.children("volume_calc")) {
model::volume_calcs.emplace_back(node_vol);
}
// Get temperature settings
if (check_for_node(root, "temperature_default")) {
temperature_default =
std::stod(get_node_value(root, "temperature_default"));
}
if (check_for_node(root, "temperature_method")) {
auto temp = get_node_value(root, "temperature_method", true, true);
if (temp == "nearest") {
temperature_method = TemperatureMethod::NEAREST;
} else if (temp == "interpolation") {
temperature_method = TemperatureMethod::INTERPOLATION;
} else {
fatal_error("Unknown temperature method: " + temp);
}
}
if (check_for_node(root, "temperature_tolerance")) {
temperature_tolerance =
std::stod(get_node_value(root, "temperature_tolerance"));
}
if (check_for_node(root, "temperature_multipole")) {
temperature_multipole = get_node_value_bool(root, "temperature_multipole");
// Multipole currently doesn't work with photon transport
if (temperature_multipole && photon_transport) {
fatal_error("Multipole data cannot currently be used in conjunction with "
"photon transport.");
}
}
if (check_for_node(root, "temperature_range")) {
auto range = get_node_array<double>(root, "temperature_range");
temperature_range[0] = range.at(0);
temperature_range[1] = range.at(1);
}
// Check for tabular_legendre options
if (check_for_node(root, "tabular_legendre")) {
// Get pointer to tabular_legendre node
xml_node node_tab_leg = root.child("tabular_legendre");
// Check for enable option
if (check_for_node(node_tab_leg, "enable")) {
legendre_to_tabular = get_node_value_bool(node_tab_leg, "enable");
}
// Check for the number of points
if (check_for_node(node_tab_leg, "num_points")) {
legendre_to_tabular_points =
std::stoi(get_node_value(node_tab_leg, "num_points"));
if (legendre_to_tabular_points <= 1 && !run_CE) {
fatal_error(
"The 'num_points' subelement/attribute of the "
"<tabular_legendre> element must contain a value greater than 1");
}
}
}