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/source.h"
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
#define HAS_DYNAMIC_LINKING
#endif
@ -10,8 +10,8 @@
#include <dlfcn.h> // for dlopen, dlsym, dlclose, dlerror
#endif
#include <fmt/core.h>
#include "xtensor/xadapt.hpp"
#include <fmt/core.h>
#include "openmc/bank.h"
#include "openmc/capi.h"
@ -46,8 +46,11 @@ vector<unique_ptr<Source>> external_sources;
// IndependentSource implementation
//==============================================================================
IndependentSource::IndependentSource(UPtrSpace space, UPtrAngle angle, UPtrDist energy)
: space_{std::move(space)}, angle_{std::move(angle)}, energy_{std::move(energy)} { }
IndependentSource::IndependentSource(
UPtrSpace space, UPtrAngle angle, UPtrDist energy)
: space_ {std::move(space)}, angle_ {std::move(angle)}, energy_ {
std::move(energy)}
{}
IndependentSource::IndependentSource(pugi::xml_node node)
{
@ -84,17 +87,17 @@ IndependentSource::IndependentSource(pugi::xml_node node)
if (check_for_node(node_space, "type"))
type = get_node_value(node_space, "type", true, true);
if (type == "cartesian") {
space_ = UPtrSpace{new CartesianIndependent(node_space)};
space_ = UPtrSpace {new CartesianIndependent(node_space)};
} else if (type == "cylindrical") {
space_ = UPtrSpace{new CylindricalIndependent(node_space)};
space_ = UPtrSpace {new CylindricalIndependent(node_space)};
} else if (type == "spherical") {
space_ = UPtrSpace{new SphericalIndependent(node_space)};
space_ = UPtrSpace {new SphericalIndependent(node_space)};
} else if (type == "box") {
space_ = UPtrSpace{new SpatialBox(node_space)};
space_ = UPtrSpace {new SpatialBox(node_space)};
} else if (type == "fission") {
space_ = UPtrSpace{new SpatialBox(node_space, true)};
space_ = UPtrSpace {new SpatialBox(node_space, true)};
} else if (type == "point") {
space_ = UPtrSpace{new SpatialPoint(node_space)};
space_ = UPtrSpace {new SpatialPoint(node_space)};
} else {
fatal_error(fmt::format(
"Invalid spatial distribution for external source: {}", type));
@ -102,7 +105,7 @@ IndependentSource::IndependentSource(pugi::xml_node node)
} else {
// If no spatial distribution specified, make it a point source
space_ = UPtrSpace{new SpatialPoint()};
space_ = UPtrSpace {new SpatialPoint()};
}
// Determine external source angular distribution
@ -115,18 +118,18 @@ IndependentSource::IndependentSource(pugi::xml_node node)
if (check_for_node(node_angle, "type"))
type = get_node_value(node_angle, "type", true, true);
if (type == "isotropic") {
angle_ = UPtrAngle{new Isotropic()};
angle_ = UPtrAngle {new Isotropic()};
} else if (type == "monodirectional") {
angle_ = UPtrAngle{new Monodirectional(node_angle)};
angle_ = UPtrAngle {new Monodirectional(node_angle)};
} else if (type == "mu-phi") {
angle_ = UPtrAngle{new PolarAzimuthal(node_angle)};
angle_ = UPtrAngle {new PolarAzimuthal(node_angle)};
} else {
fatal_error(fmt::format(
"Invalid angular distribution for external source: {}", type));
}
} else {
angle_ = UPtrAngle{new Isotropic()};
angle_ = UPtrAngle {new Isotropic()};
}
// Determine external source energy distribution
@ -135,7 +138,7 @@ IndependentSource::IndependentSource(pugi::xml_node node)
energy_ = distribution_from_xml(node_dist);
} else {
// Default to a Watt spectrum with parameters 0.988 MeV and 2.249 MeV^-1
energy_ = UPtrDist{new Watt(0.988e6, 2.249e-6)};
energy_ = UPtrDist {new Watt(0.988e6, 2.249e-6)};
}
}
}
@ -171,13 +174,14 @@ SourceSite IndependentSource::sample(uint64_t* seed) const
if (space_box->only_fissionable()) {
// Determine material
const auto& c = model::cells[cell_index];
auto mat_index = c->material_.size() == 1
? c->material_[0] : c->material_[instance];
auto mat_index =
c->material_.size() == 1 ? c->material_[0] : c->material_[instance];
if (mat_index == MATERIAL_VOID) {
found = false;
} else {
if (!model::materials[mat_index]->fissionable_) found = false;
if (!model::materials[mat_index]->fissionable_)
found = false;
}
}
}
@ -187,7 +191,7 @@ SourceSite IndependentSource::sample(uint64_t* seed) const
if (!found) {
++n_reject;
if (n_reject >= EXTSRC_REJECT_THRESHOLD &&
static_cast<double>(n_accept)/n_reject <= EXTSRC_REJECT_FRACTION) {
static_cast<double>(n_accept) / n_reject <= EXTSRC_REJECT_FRACTION) {
fatal_error("More than 95% of external source sites sampled were "
"rejected. Please check your external source definition.");
}
@ -219,7 +223,8 @@ SourceSite IndependentSource::sample(uint64_t* seed) const
site.E = energy_->sample(seed);
// Resample if energy falls outside minimum or maximum particle energy
if (site.E < data::energy_max[p] && site.E > data::energy_min[p]) break;
if (site.E < data::energy_max[p] && site.E > data::energy_min[p])
break;
}
// Set delayed group
@ -264,7 +269,7 @@ FileSource::FileSource(std::string path)
SourceSite FileSource::sample(uint64_t* seed) const
{
size_t i_site = sites_.size()*prn(seed);
size_t i_site = sites_.size() * prn(seed);
return sites_[i_site];
}
@ -272,7 +277,8 @@ SourceSite FileSource::sample(uint64_t* seed) const
// CustomSourceWrapper implementation
//==============================================================================
CustomSourceWrapper::CustomSourceWrapper(std::string path, std::string parameters)
CustomSourceWrapper::CustomSourceWrapper(
std::string path, std::string parameters)
{
#ifdef HAS_DYNAMIC_LINKING
// Open the library
@ -291,7 +297,8 @@ CustomSourceWrapper::CustomSourceWrapper(std::string path, std::string parameter
// check for any dlsym errors
auto dlsym_error = dlerror();
if (dlsym_error) {
std::string error_msg = fmt::format("Couldn't open the openmc_create_source symbol: {}", dlsym_error);
std::string error_msg = fmt::format(
"Couldn't open the openmc_create_source symbol: {}", dlsym_error);
dlclose(shared_library_);
fatal_error(error_msg);
}
@ -301,14 +308,15 @@ CustomSourceWrapper::CustomSourceWrapper(std::string path, std::string parameter
#else
fatal_error("Custom source libraries have not yet been implemented for "
"non-POSIX systems");
"non-POSIX systems");
#endif
}
CustomSourceWrapper::~CustomSourceWrapper()
{
// Make sure custom source is cleared before closing shared library
if (custom_source_.get()) custom_source_.reset();
if (custom_source_.get())
custom_source_.reset();
#ifdef HAS_DYNAMIC_LINKING
dlclose(shared_library_);
@ -326,12 +334,12 @@ void initialize_source()
{
write_message("Initializing source particles...", 5);
// Generation source sites from specified distribution in user input
#pragma omp parallel for
// Generation source sites from specified distribution in user input
#pragma omp parallel for
for (int64_t i = 0; i < simulation::work_per_rank; ++i) {
// initialize random number seed
int64_t id = simulation::total_gen*settings::n_particles +
simulation::work_index[mpi::rank] + i + 1;
int64_t id = simulation::total_gen * settings::n_particles +
simulation::work_index[mpi::rank] + i + 1;
uint64_t seed = init_seed(id, STREAM_SOURCE);
// sample external source distribution
@ -358,11 +366,12 @@ SourceSite sample_external_source(uint64_t* seed)
// Sample from among multiple source distributions
int i = 0;
if (model::external_sources.size() > 1) {
double xi = prn(seed)*total_strength;
double xi = prn(seed) * total_strength;
double c = 0.0;
for (; i < model::external_sources.size(); ++i) {
c += model::external_sources[i]->strength();
if (xi < c) break;
if (xi < c)
break;
}
}