Reduce number of string concats with fmt::format

This commit is contained in:
Andrew Johnson 2020-08-02 22:10:26 -04:00
parent c9120bafbc
commit b6276ea9e4
No known key found for this signature in database
GPG key ID: 253418E91B7F6FEB
4 changed files with 15 additions and 14 deletions

View file

@ -3,6 +3,8 @@
#include <string>
#include <unordered_set>
#include <fmt/format.h>
#include "openmc/cell.h"
#include "openmc/cross_sections.h"
#include "openmc/container_util.h"
@ -57,8 +59,7 @@ void MgxsInterface::init()
// Check if MGXS Library exists
if (!file_exists(cross_sections_path_)) {
// Could not find MGXS Library file
fatal_error("Cross sections HDF5 file '" + cross_sections_path_ +
"' does not exist.");
fatal_error(fmt::format("Cross sections HDF5 file '{}' does not exist!", cross_sections_path_));
}
write_message("Loading cross section data...", 5);
@ -98,15 +99,14 @@ void
MgxsInterface::add_mgxs(hid_t file_id, const std::string& name,
const std::vector<double>& temperature)
{
write_message("Loading " + std::string(name) + " data...", 6);
write_message(fmt::format("Loading {} data...", name), 6);
// Check to make sure cross section set exists in the library
hid_t xs_grp;
if (object_exists(file_id, name.c_str())) {
xs_grp = open_group(file_id, name.c_str());
} else {
fatal_error("Data for " + std::string(name) + " does not exist in "
+ "provided MGXS Library");
fatal_error(fmt::format("Data for {} does not exist in provided MGXS Library", name));
}
nuclides_.emplace_back(xs_grp, temperature, num_energy_groups_,
@ -187,8 +187,7 @@ void MgxsInterface::read_header(const std::string& path_cross_sections)
// Check if MGXS Library exists
if (!file_exists(cross_sections_path_)) {
// Could not find MGXS Library file
fatal_error("Cross sections HDF5 file '" + cross_sections_path_ +
"' does not exist.");
fatal_error(fmt::format("Cross section HDF5 file '{}' does not exist", cross_sections_path_));
}
write_message("Reading cross sections HDF5 file...", 5);

View file

@ -410,7 +410,7 @@ Particle::cross_surface()
// TODO: off-by-one
const auto& surf {model::surfaces[i_surface - 1].get()};
if (settings::verbosity >= 10 || trace_) {
write_message(" Crossing surface " + std::to_string(surf->id_));
write_message(fmt::format(" Crossing surface {}", surf->id_));
}
if (surf->bc_ == Surface::BoundaryType::VACUUM && (settings::run_mode != RunMode::PLOTTING)) {
@ -437,7 +437,7 @@ Particle::cross_surface()
// Display message
if (settings::verbosity >= 10 || trace_) {
write_message(" Leaked out of surface " + std::to_string(surf->id_));
write_message(fmt::format(" Leaked out of surface {}", surf->id_));
}
return;
@ -502,7 +502,7 @@ Particle::cross_surface()
// Diagnostic message
if (settings::verbosity >= 10 || trace_) {
write_message(" Reflected from surface " + std::to_string(surf->id_));
write_message(fmt::format(" Reflected from surface {}", surf->id_));
}
return;
@ -556,8 +556,8 @@ Particle::cross_surface()
// Diagnostic message
if (settings::verbosity >= 10 || trace_) {
write_message(" Hit periodic boundary on surface " +
std::to_string(surf->id_));
write_message(fmt::format(" Hit periodic boundary on surface {}",
surf->id_));
}
return;
}

View file

@ -114,7 +114,7 @@ void read_plots_xml()
// Check if plots.xml exists
std::string filename = settings::path_input + "plots.xml";
if (!file_exists(filename)) {
fatal_error("Plots XML file '" + filename + "' does not exist!");
fatal_error(fmt::format("Plots XML file '{}' does not exist!", filename));
}
write_message("Reading plot XML file...", 5);

View file

@ -33,6 +33,8 @@
#include <mpi.h>
#endif
#include <fmt/format.h>
#include <algorithm>
#include <cmath>
#include <string>
@ -500,7 +502,7 @@ void initialize_history(Particle& p, int64_t index_source)
// Display message if high verbosity or trace is on
if (settings::verbosity >= 9 || p.trace_) {
write_message("Simulating Particle " + std::to_string(p.id_));
write_message(fmt::format("Simulating Particle {}", p.id_));
}
// Add paricle's starting weight to count for normalizing tallies later