Merge pull request #72 from tboudreaux/hotfix/gcc/CompositionRefactor

[Hotfix] updated to compile on gcc and clang
This commit is contained in:
2025-06-17 10:18:40 -04:00
committed by GitHub
5 changed files with 10 additions and 14 deletions

View File

@@ -357,7 +357,7 @@ namespace serif::composition {
for (const auto& mass_fraction : mass_fractions) {
sum += mass_fraction;
}
for (int i = 0; i < mass_fractions.size(); ++i) {
for (int i = 0; i < static_cast<int>(mass_fractions.size()); ++i) {
mass_fractions[i] /= sum;
}
for (auto& [symbol, entry] : m_compositions) {
@@ -594,10 +594,10 @@ namespace serif::composition {
throw std::runtime_error("Composition has not been finalized (Consider running .finalize()).");
}
CanonicalComposition canonicalComposition;
constexpr std::array<std::string, 7> canonicalH = {
const std::array<std::string, 7> canonicalH = {
"H-1", "H-2", "H-3", "H-4", "H-5", "H-6", "H-7"
};
constexpr std::array<std::string, 8> canonicalHe = {
const std::array<std::string, 8> canonicalHe = {
"He-3", "He-4", "He-5", "He-6", "He-7", "He-8", "He-9", "He-10"
};
for (const auto& symbol : canonicalH) {

View File

@@ -148,12 +148,6 @@ namespace serif::eos {
*/
double specificHeatCapacityAtConstantPressure();
/**
* @brief Returns the format of the EOS data used to generate this output.
* @return The EOSFormat enum value (currently only EOSFormat::HELM).
*/
EOSFormat EOSFormat() const;
friend std::ostream& operator<<(std::ostream& os, const EOSOutput& output) {
os << "EOSOutput:\n"
<< "\tElectron Fraction: " << output.electronFraction << "\n"

View File

@@ -61,13 +61,13 @@ TEST_F(compositionTest, setGetComposition) {
EXPECT_THROW(comp.setMassFraction("He-3", 0.3), std::runtime_error);
EXPECT_NO_THROW(comp.setMassFraction({"H-1", "He-4"}, {0.5, 0.5}));
EXPECT_THROW(comp.getComposition("H-1"), std::runtime_error);
EXPECT_THROW(auto r = comp.getComposition("H-1"), std::runtime_error);
EXPECT_TRUE(comp.finalize());
EXPECT_DOUBLE_EQ(comp.getComposition("H-1").first.mass_fraction(), 0.5);
EXPECT_NO_THROW(comp.setMassFraction({"H-1", "He-4"}, {0.6, 0.6}));
EXPECT_FALSE(comp.finalize());
EXPECT_THROW(comp.getComposition("H-1"), std::runtime_error);
EXPECT_THROW(auto r = comp.getComposition("H-1"), std::runtime_error);
}
TEST_F(compositionTest, setGetNumberFraction) {

View File

@@ -123,6 +123,8 @@ TEST_F(eosTest, eos_using_composition) {
serif::eos::EOSOutput eosOutput;
EXPECT_NO_THROW(eosOutput = EOS.get(eosInput));
eosOutput = EOS.get(eosInput);
constexpr double absErr = 1e-8;
EXPECT_NEAR(eosOutput.pressure.total, 6.9548533046915791E+22, absErr);
const double pressureFraction = eosOutput.pressure.total / 6.9548533046915791E+22;
constexpr double relError = 1e-6;
EXPECT_NEAR(pressureFraction, 1.0, relError);
}

View File

@@ -56,7 +56,7 @@ TEST_F(approx8Test, evaluate) {
double H1MassFraction = netOut.composition.getMassFraction("H-1")/ 0.50166262445895604;
double He4MassFraction = netOut.composition.getMassFraction("He-4") / 0.48172273720971226;
double relError = 1e-8;
double relError = 1e-6;
EXPECT_NEAR(H1MassFraction, 1.0, relError);
EXPECT_NEAR(He4MassFraction, 1.0, relError);
EXPECT_NEAR(energyFraction, 1.0, relError);