test(tests/eos): updated eos test to use resource manager instead of env variable

This commit is contained in:
2025-03-20 14:27:11 -04:00
parent 08075f5108
commit 041a5a592c
2 changed files with 33 additions and 29 deletions

View File

@@ -1,11 +1,12 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <iostream> #include <iostream>
#include <memory>
#include <string> #include <string>
#include <vector>
#include <set>
#include <sstream> #include <sstream>
#include "helm.h" #include "helm.h"
#include "resourceManager.h"
#include "config.h"
/** /**
* @file constTest.cpp * @file constTest.cpp
@@ -17,21 +18,21 @@
*/ */
class eosTest : public ::testing::Test {}; class eosTest : public ::testing::Test {};
std::string HELM_FILENAME = std::string(getenv("MESON_SOURCE_ROOT")) + "/assets/eos/helm_table.dat"; std::string TEST_CONFIG = std::string(getenv("MESON_SOURCE_ROOT")) + "/tests/testsConfig.yaml";
/** /**
* @test Verify default constructor initializes correctly. * @test Verify default constructor initializes correctly.
*/ */
TEST_F(eosTest, constructor) {
using namespace helmholtz;
EXPECT_NO_THROW(HELMTable table = read_helm_table(HELM_FILENAME));
}
TEST_F(eosTest, read_helm_table) { TEST_F(eosTest, read_helm_table) {
using namespace helmholtz; Config::getInstance().loadConfig(TEST_CONFIG);
HELMTable table = read_helm_table(HELM_FILENAME);
// Capture the << operator output as a string // Capture the << operator output as a string
ResourceManager& rm = ResourceManager::getInstance();
auto& eos = std::get<std::unique_ptr<EosIO>>(rm.getResource("eos:helm"));
auto& table = eos->getTable();
auto& helmTable = *std::get<std::unique_ptr<helmholtz::HELMTable>>(table);
std::stringstream ss; std::stringstream ss;
ss << table; ss << helmTable;
EXPECT_EQ(ss.str(), "HELMTable Data:\n imax: 541, jmax: 201\n Temperature Range: [1000, 1e+13]\n Density Range: [1e-12, 1e+15]\n"); EXPECT_EQ(ss.str(), "HELMTable Data:\n imax: 541, jmax: 201\n Temperature Range: [1000, 1e+13]\n Density Range: [1e-12, 1e+15]\n");
} }
@@ -58,28 +59,31 @@ TEST_F(eosTest, get_helm_EOS) {
eos1.abar = 1.0/asum; eos1.abar = 1.0/asum;
eos1.zbar = eos1.abar*zsum; eos1.zbar = eos1.abar*zsum;
HELMTable table = read_helm_table(HELM_FILENAME); ResourceManager& rm = ResourceManager::getInstance();
EOS eos = get_helm_EOS(eos1, table); auto& eos = std::get<std::unique_ptr<EosIO>>(rm.getResource("eos:helm"));
// std::cout << eos << std::endl; auto& table = eos->getTable();
auto& helmTable = *std::get<std::unique_ptr<helmholtz::HELMTable>>(table);
EOS helmEos = get_helm_EOS(eos1, helmTable);
const double absErr = 1e-12;
//Check composition info //Check composition info
EXPECT_DOUBLE_EQ( eos.ye, 8.75e-01); EXPECT_NEAR( helmEos.ye, 8.75e-01, absErr);
//Check E, P, S and derivatives of each wrt Rho and T //Check E, P, S and derivatives of each wrt Rho and T
EXPECT_DOUBLE_EQ( eos.etaele, 2.3043348231021554e+01); EXPECT_NEAR( helmEos.etaele, 2.3043348231021554e+01, absErr);
EXPECT_DOUBLE_EQ( eos.etot, 1.1586558190936826e+17); EXPECT_NEAR( helmEos.etot, 1.1586558190936826e+17, 1e3);
EXPECT_DOUBLE_EQ(eos.denerdd, 6.1893000468285858e+10); EXPECT_NEAR(helmEos.denerdd, 6.1893000468285858e+10, 1e-2);
EXPECT_DOUBLE_EQ(eos.denerdt, 1.2129708972542575e+08); EXPECT_NEAR(helmEos.denerdt, 1.2129708972542575e+08, 1e-7);
EXPECT_DOUBLE_EQ( eos.ptot, 6.9610135220017030e+22); EXPECT_NEAR( helmEos.ptot, 6.9610135220017030e+22, 1e10);
EXPECT_DOUBLE_EQ(eos.dpresdd, 1.0296440482849070e+17); EXPECT_NEAR(helmEos.dpresdd, 1.0296440482849070e+17, 1e3);
EXPECT_DOUBLE_EQ(eos.dpresdt, 7.7171347517311625e+13); EXPECT_NEAR(helmEos.dpresdt, 7.7171347517311625e+13, 1.0);
EXPECT_DOUBLE_EQ( eos.stot, 6.0647461970567346e+08); EXPECT_NEAR( helmEos.stot, 6.0647461970567346e+08, 1e-7);
EXPECT_DOUBLE_EQ(eos.dentrdd,-7.7171347517311645e+01); EXPECT_NEAR(helmEos.dentrdd,-7.7171347517311645e+01, absErr);
EXPECT_DOUBLE_EQ(eos.dentrdt, 1.2129708972542577e+00); EXPECT_NEAR(helmEos.dentrdt, 1.2129708972542577e+00, absErr);
const double abs_err = 1.0e-12;
// Maxwell relations, should always be zero // Maxwell relations, should always be zero
EXPECT_NEAR( eos.dse, 0, abs_err); EXPECT_NEAR( helmEos.dse, 0, absErr);
EXPECT_NEAR( eos.dpe, 0, abs_err); EXPECT_NEAR( helmEos.dpe, 0, absErr);
EXPECT_NEAR( eos.dsp, 0, abs_err); EXPECT_NEAR( helmEos.dsp, 0, absErr);
} }

View File

@@ -11,7 +11,7 @@ foreach test_file : test_sources
test_exe = executable( test_exe = executable(
exe_name, exe_name,
test_file, test_file,
dependencies: [gtest_dep, eos_dep, gtest_main], dependencies: [gtest_dep, eos_dep, gtest_main, resourceManager_dep, config_dep],
install_rpath: '@loader_path/../../src' # Ensure runtime library path resolves correctly install_rpath: '@loader_path/../../src' # Ensure runtime library path resolves correctly
) )