Skip to content

Commit

Permalink
unify concatenate function
Browse files Browse the repository at this point in the history
  • Loading branch information
zoeprieto committed Aug 7, 2024
1 parent 56f9ecc commit f7f56a6
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 25 deletions.
12 changes: 9 additions & 3 deletions include/openmc/string_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ bool ends_with(const std::string& value, const std::string& ending);

bool starts_with(const std::string& value, const std::string& beginning);

std::string concatenate_vec(const std::vector<double>& temps);

std::string concatenate_xt(const xt::xarray<double>& temps);
template<typename T>
inline std::string concatenate(const T& temps)
{
std::ostringstream oss;
for (const auto& temp : temps) {
oss << temp << " ";
}
return oss.str();
}

} // namespace openmc
#endif // OPENMC_STRING_UTILS_H
2 changes: 1 addition & 1 deletion src/mgxs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void Mgxs::metadata_from_hdf5(hid_t xs_id, const vector<double>& temperature,
"for {} at or near {} K. Available temperatures "
"are {} K consider making use of openmc.Settings.temperature "
"to specify how intermediate temperatures are treated.",
in_name, std::round(T), concatenate_xt(temps_available)));
in_name, std::round(T), concatenate(temps_available)));
}
}
break;
Expand Down
2 changes: 1 addition & 1 deletion src/nuclide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ Nuclide::Nuclide(hid_t group, const vector<double>& temperature)
"for {} at or near {} K. Available temperatures "
"are {} K consider making use of openmc.Settings.temperature "
"to specify how intermediate temperatures are treated.",
name_, std::to_string(T_desired), concatenate_vec(temps_available)));
name_, std::to_string(T_desired), concatenate(temps_available)));
}
}
break;
Expand Down
18 changes: 0 additions & 18 deletions src/string_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,4 @@ bool starts_with(const std::string& value, const std::string& beginning)
return std::equal(beginning.begin(), beginning.end(), value.begin());
}

std::string concatenate_vec(const std::vector<double>& temps)
{
std::ostringstream oss;
for (const auto& temp : temps) {
oss << temp << " ";
}
return oss.str();
}

std::string concatenate_xt(const xt::xarray<double>& temps)
{
std::ostringstream oss;
for (const auto& temp : temps) {
oss << temp << " ";
}
return oss.str();
}

} // namespace openmc
3 changes: 1 addition & 2 deletions src/thermal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ ThermalScattering::ThermalScattering(
"for {} at or near {} K. Available temperatures "
"are {} K consider making use of openmc.Settings.temperature "
"to specify how intermediate temperatures are treated.",
name_, std::to_string(std::round(T)),
concatenate_xt(temps_available)));
name_, std::to_string(std::round(T)), concatenate(temps_available)));
}
}
break;
Expand Down

0 comments on commit f7f56a6

Please sign in to comment.