Apply clang-format on entire source

This commit is contained in:
Paul Romano 2021-08-11 11:41:49 -05:00
parent 4c17061a1d
commit 1bc2bd8460
181 changed files with 7372 additions and 6952 deletions

View file

@ -1,6 +1,6 @@
#include "openmc/settings.h"
#include <cmath> // for ceil, pow
#include <cmath> // for ceil, pow
#include <limits> // for numeric_limits
#include <string>
@ -38,38 +38,38 @@ namespace openmc {
namespace settings {
// Default values for boolean flags
bool assume_separate {false};
bool check_overlaps {false};
bool cmfd_run {false};
bool confidence_intervals {false};
bool assume_separate {false};
bool check_overlaps {false};
bool cmfd_run {false};
bool confidence_intervals {false};
bool create_fission_neutrons {true};
bool dagmc {false};
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 surf_source_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 write_all_tracks {false};
bool write_initial_source {false};
bool dagmc {false};
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 surf_source_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 write_all_tracks {false};
bool write_initial_source {false};
std::string path_cross_sections;
std::string path_input;
@ -138,24 +138,27 @@ void get_run_parameters(pugi::xml_node node_base)
// 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"));
max_particles_in_flight =
std::stoll(get_node_value(node_base, "max_particles_in_flight"));
}
// 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;
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"));
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"));
rel_max_lost_particles =
std::stod(get_node_value(node_base, "rel_max_lost_particles"));
}
// Get number of inactive batches
@ -164,7 +167,8 @@ void get_run_parameters(pugi::xml_node node_base)
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"));
gen_per_batch =
std::stoi(get_node_value(node_base, "generations_per_batch"));
}
// Preallocate space for keff and entropy by generation
@ -192,8 +196,8 @@ void get_run_parameters(pugi::xml_node node_base)
}
if (check_for_node(node_keff_trigger, "threshold")) {
keff_trigger.threshold = std::stod(get_node_value(
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");
}
@ -213,13 +217,15 @@ void read_settings_xml()
std::string filename = path_input + "settings.xml";
if (!file_exists(filename)) {
if (run_mode != RunMode::PLOTTING) {
fatal_error(fmt::format(
"Settings XML file '{}' does not exist! 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. Please consult "
"the user's guide at https://docs.openmc.org for further "
"information.", filename
));
fatal_error(
fmt::format("Settings XML file '{}' does not exist! 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. "
"Please consult "
"the user's guide at https://docs.openmc.org for further "
"information.",
filename));
} else {
// The settings.xml file is optional if we just want to make a plot.
return;
@ -255,7 +261,8 @@ void read_settings_xml()
// 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();
if (verbosity >= 2)
title();
}
write_message("Reading settings XML file...", 5);
@ -271,11 +278,12 @@ void read_settings_xml()
// 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.");
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");
}
@ -300,17 +308,18 @@ void read_settings_xml()
trigger_on = get_node_value_bool(node_trigger, "active");
if (trigger_on) {
if (check_for_node(node_trigger, "max_batches") ){
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")){
if (!check_for_node(node_trigger, "batch_interval")) {
trigger_predict = true;
} else {
trigger_batch_interval = std::stoi(get_node_value(node_trigger, "batch_interval"));
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");
}
@ -361,7 +370,8 @@ void read_settings_xml()
// Read run parameters
get_run_parameters(node_mode);
// Check number of active batches, inactive batches, max lost particles and particles
// 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) {
@ -399,7 +409,7 @@ void read_settings_xml()
if (!run_CE && photon_transport) {
fatal_error("Photon transport is not currently supported in "
"multigroup mode");
"multigroup mode");
}
}
@ -408,14 +418,16 @@ void read_settings_xml()
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.");
"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.");
if (mpi::master)
warning("The <threads> element has been deprecated. Use "
"the OMP_NUM_THREADS environment variable to set the number of "
"threads.");
}
// ==========================================================================
@ -456,7 +468,8 @@ void read_settings_xml()
model::external_sources.push_back(make_unique<FileSource>(path));
}
// If no source specified, default to isotropic point source at origin with Watt spectrum
// If no source specified, default to isotropic point source at origin with
// Watt spectrum
if (model::external_sources.empty()) {
model::external_sources.push_back(make_unique<IndependentSource>(
UPtrSpace {new SpatialPoint({0.0, 0.0, 0.0})},
@ -488,20 +501,24 @@ void read_settings_xml()
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"));
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>.");
"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"));
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"));
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"));
energy_cutoff[3] =
std::stod(get_node_value(node_cutoff, "energy_positron"));
}
}
@ -510,10 +527,10 @@ void read_settings_xml()
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.");
"batch, generation, and particle number.");
}
trace_batch = temp.at(0);
trace_gen = temp.at(1);
trace_batch = temp.at(0);
trace_gen = temp.at(1);
trace_particle = temp.at(2);
}
@ -522,7 +539,8 @@ void read_settings_xml()
// 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 "
fatal_error(
"Number of integers specified in 'track' is not "
"divisible by 3. Please provide 3 integers per particle to be "
"tracked.");
}
@ -530,8 +548,8 @@ void read_settings_xml()
// 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]});
track_identifiers.push_back(
{temp[3 * i], temp[3 * i + 1], temp[3 * i + 2]});
}
}
@ -546,16 +564,18 @@ void read_settings_xml()
"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");
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 "
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.");
}
@ -565,18 +585,22 @@ void read_settings_xml()
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));
"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");
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 "
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.");
}
@ -655,7 +679,8 @@ void read_settings_xml()
// 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"));
max_surface_particles =
std::stoll(get_node_value(node_ssw, "max_particles"));
}
}
@ -665,7 +690,8 @@ void read_settings_xml()
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.");
fatal_error(
"Sourcepoint batches are not a subset of statepoint batches.");
}
}
}
@ -725,14 +751,15 @@ void read_settings_xml()
} else if (temp == "dbrc") {
res_scat_method = ResScatMethod::dbrc;
} else {
fatal_error("Unrecognized resonance elastic scattering method: "
+ temp + ".");
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"));
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");
@ -740,16 +767,18 @@ void read_settings_xml()
// 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"));
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.");
"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");
res_scat_nuclides =
get_node_array<std::string>(node_res_scat, "nuclides");
}
}
@ -760,7 +789,8 @@ void read_settings_xml()
// Get temperature settings
if (check_for_node(root, "temperature_default")) {
temperature_default = std::stod(get_node_value(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);
@ -773,7 +803,8 @@ void read_settings_xml()
}
}
if (check_for_node(root, "temperature_tolerance")) {
temperature_tolerance = std::stod(get_node_value(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");
@ -796,10 +827,11 @@ void read_settings_xml()
// 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"));
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 "
fatal_error(
"The 'num_points' subelement/attribute of the "
"<tabular_legendre> element must contain a value greater than 1");
}
}
@ -808,13 +840,15 @@ void read_settings_xml()
// Check whether create fission sites
if (run_mode == RunMode::FIXED_SOURCE) {
if (check_for_node(root, "create_fission_neutrons")) {
create_fission_neutrons = get_node_value_bool(root, "create_fission_neutrons");
create_fission_neutrons =
get_node_value_bool(root, "create_fission_neutrons");
}
}
// Check whether to scale fission photon yields
if (check_for_node(root, "delayed_photon_scaling")) {
delayed_photon_scaling = get_node_value_bool(root, "delayed_photon_scaling");
delayed_photon_scaling =
get_node_value_bool(root, "delayed_photon_scaling");
}
// Check whether to use event-based parallelism
@ -828,7 +862,8 @@ void read_settings_xml()
}
}
void free_memory_settings() {
void free_memory_settings()
{
settings::statepoint_batch.clear();
settings::sourcepoint_batch.clear();
settings::source_write_surf_id.clear();
@ -839,9 +874,8 @@ void free_memory_settings() {
// C API functions
//==============================================================================
extern "C" int
openmc_set_n_batches(int32_t n_batches, bool set_max_batches,
bool add_statepoint_batch)
extern "C" int openmc_set_n_batches(
int32_t n_batches, bool set_max_batches, bool add_statepoint_batch)
{
if (settings::n_inactive >= n_batches) {
set_errmsg("Number of active batches must be greater than zero.");
@ -879,8 +913,7 @@ openmc_set_n_batches(int32_t n_batches, bool set_max_batches,
return 0;
}
extern "C" int
openmc_get_n_batches(int* n_batches, bool get_max_batches)
extern "C" int openmc_get_n_batches(int* n_batches, bool get_max_batches)
{
*n_batches = get_max_batches ? settings::n_max_batches : settings::n_batches;