Skip to content

Commit

Permalink
Merge pull request #8 from zoeprieto/nuclide_temperatures
Browse files Browse the repository at this point in the history
generalize concatenate function and minor changes
  • Loading branch information
zoeprieto authored Aug 8, 2024
2 parents b0da8a4 + 1a9f2bb commit 2dfb210
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
11 changes: 8 additions & 3 deletions include/openmc/string_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ bool ends_with(const std::string& value, const std::string& ending);
bool starts_with(const std::string& value, const std::string& beginning);

template<typename T>
inline std::string concatenate(const T& temps)
inline std::string concatenate(const T& values, const std::string& del = " ")
{
std::ostringstream oss;
for (const auto& temp : temps) {
oss << temp << " ";
auto it = values.begin();
if (it != values.end()) {
oss << *it; // Insert the first element without a delimiter
++it;
}
for (; it != values.end(); ++it) {
oss << del << *it;
}
return oss.str();
}
Expand Down
4 changes: 2 additions & 2 deletions src/mgxs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ void Mgxs::metadata_from_hdf5(hid_t xs_id, const vector<double>& temperature,
fatal_error(fmt::format(
"MGXS library does not contain cross sections "
"for {} at or near {} K. Available temperatures "
"are {} K consider making use of openmc.Settings.temperature "
"are {} K. Consider making use of openmc.Settings.temperature "
"to specify how intermediate temperatures are treated.",
in_name, std::round(T), concatenate(temps_available)));
in_name, std::round(T), concatenate(temps_available, ", ")));
}
}
break;
Expand Down
5 changes: 3 additions & 2 deletions src/nuclide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,10 @@ Nuclide::Nuclide(hid_t group, const vector<double>& temperature)
fatal_error(fmt::format(
"Nuclear data library does not contain cross sections "
"for {} at or near {} K. Available temperatures "
"are {} K consider making use of openmc.Settings.temperature "
"are {} K. Consider making use of openmc.Settings.temperature "
"to specify how intermediate temperatures are treated.",
name_, std::to_string(T_desired), concatenate(temps_available)));
name_, std::to_string(T_desired),
concatenate(temps_available, ", ")));
}
}
break;
Expand Down
4 changes: 2 additions & 2 deletions src/thermal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ ThermalScattering::ThermalScattering(
fatal_error(fmt::format(
"Nuclear data library does not contain cross sections "
"for {} at or near {} K. Available temperatures "
"are {} K consider making use of openmc.Settings.temperature "
"are {} K. Consider making use of openmc.Settings.temperature "
"to specify how intermediate temperatures are treated.",
name_, std::to_string(std::round(T)), concatenate(temps_available)));
name_, std::round(T), concatenate(temps_available, ", ")));
}
}
break;
Expand Down

0 comments on commit 2dfb210

Please sign in to comment.