131 lines
4.5 KiB
C++
131 lines
4.5 KiB
C++
#include <gtest/gtest.h>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <sstream>
|
|
|
|
#include "helm.h"
|
|
#include "resourceManager.h"
|
|
#include "config.h"
|
|
#include "composition.h"
|
|
#include "EOS.h"
|
|
|
|
/**
|
|
* @file eosTest.cpp
|
|
* @brief Unit tests for the const class.
|
|
*/
|
|
|
|
/**
|
|
* @brief Test suite for the const class.
|
|
*/
|
|
class eosTest : public ::testing::Test {};
|
|
|
|
std::string TEST_CONFIG = std::string(getenv("MESON_SOURCE_ROOT")) + "/tests/testsConfig.yaml";
|
|
|
|
/**
|
|
* @test Verify default constructor initializes correctly.
|
|
*/
|
|
|
|
TEST_F(eosTest, read_helm_table) {
|
|
fourdst::config::Config::getInstance().loadConfig(TEST_CONFIG);
|
|
const serif::resource::ResourceManager& rm = serif::resource::ResourceManager::getInstance();
|
|
auto& eos = std::get<std::unique_ptr<serif::eos::EOSio>>(rm.getResource("eos:helm"));
|
|
const auto& table = eos->getTable();
|
|
const auto& helmTable = *std::get<std::unique_ptr<serif::eos::helmholtz::HELMTable>>(table);
|
|
std::stringstream ss;
|
|
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");
|
|
}
|
|
|
|
TEST_F(eosTest, get_helm_EOS) {
|
|
constexpr int nel=3;
|
|
double xMass[nel], aIon[nel], zIon[nel];
|
|
serif::eos::helmholtz::HELMEOSInput eos1;
|
|
|
|
xMass[0] = 0.75; aIon[0] = 1.0; zIon[0] = 1.0;
|
|
xMass[1] = 0.23; aIon[1] = 4.0; zIon[1] = 2.0;
|
|
xMass[2] = 0.02; aIon[2] = 12.0; zIon[2] = 6.0;
|
|
|
|
eos1.T = 1.0e8;
|
|
eos1.rho = 1.0e6;
|
|
|
|
double aSum = 0.0;
|
|
double zSum = 0.0;
|
|
for (int i=0; i<nel; i++) {
|
|
aSum += xMass[i]/aIon[i];
|
|
zSum += xMass[i]*zIon[i]/aIon[i];
|
|
}
|
|
eos1.abar = 1.0/aSum;
|
|
eos1.zbar = eos1.abar*zSum;
|
|
|
|
serif::resource::ResourceManager& rm = serif::resource::ResourceManager::getInstance();
|
|
auto& eos = std::get<std::unique_ptr<serif::eos::EOSio>>(rm.getResource("eos:helm"));
|
|
auto& table = eos->getTable();
|
|
auto& helmTable = *std::get<std::unique_ptr<serif::eos::helmholtz::HELMTable>>(table);
|
|
serif::eos::helmholtz::HELMEOSOutput helmEos = get_helm_EOS(eos1, helmTable);
|
|
|
|
constexpr double absErr = 1e-12;
|
|
|
|
//Check composition info
|
|
EXPECT_NEAR( helmEos.ye, 8.75e-01, absErr);
|
|
|
|
//Check E, P, S and derivatives of each wrt Rho and T
|
|
EXPECT_NEAR( helmEos.etaele, 2.3043348231021554e+01, absErr);
|
|
EXPECT_NEAR( helmEos.etot, 1.1586558190936826e+17, 1e3);
|
|
EXPECT_NEAR(helmEos.denerdd, 6.1893000468285858e+10, 1e-2);
|
|
EXPECT_NEAR(helmEos.denerdt, 1.2129708972542575e+08, 1e-7);
|
|
EXPECT_NEAR( helmEos.ptot, 6.9610135220017030e+22, 1e10);
|
|
EXPECT_NEAR(helmEos.dpresdd, 1.0296440482849070e+17, 1e3);
|
|
EXPECT_NEAR(helmEos.dpresdt, 7.7171347517311625e+13, 1.0);
|
|
EXPECT_NEAR( helmEos.stot, 6.0647461970567346e+08, 1e-7);
|
|
EXPECT_NEAR(helmEos.dentrdd,-7.7171347517311645e+01, absErr);
|
|
EXPECT_NEAR(helmEos.dentrdt, 1.2129708972542577e+00, absErr);
|
|
|
|
// Maxwell relations, should always be zero
|
|
EXPECT_NEAR( helmEos.dse, 0, absErr);
|
|
EXPECT_NEAR( helmEos.dpe, 0, absErr);
|
|
EXPECT_NEAR( helmEos.dsp, 0, absErr);
|
|
}
|
|
|
|
TEST_F(eosTest, eos_using_composition) {
|
|
fourdst::composition::Composition composition;
|
|
composition.registerSymbol({
|
|
"H-1",
|
|
"He-4",
|
|
"C-12",
|
|
"O-16",
|
|
"Ne-20",
|
|
"Fe-56",
|
|
"N-14",
|
|
"Si-28",
|
|
"Mg-24"
|
|
}, true);
|
|
composition.setMassFraction("H-1", 0.75);
|
|
composition.setMassFraction("He-4", 0.23);
|
|
composition.setMassFraction("C-12", 0.0044);
|
|
composition.setMassFraction("O-16", 0.0096);
|
|
composition.setMassFraction("Ne-20", 0.002);
|
|
composition.setMassFraction("Fe-56", 0.0018);
|
|
composition.setMassFraction("N-14", 0.001);
|
|
composition.setMassFraction("Si-28", 0.0008);
|
|
composition.setMassFraction("Mg-24", 0.0004);
|
|
composition.finalize();
|
|
|
|
serif::resource::ResourceManager& rm = serif::resource::ResourceManager::getInstance();
|
|
auto& EOSio = std::get<std::unique_ptr<serif::eos::EOSio>>(rm.getResource("eos:helm"));
|
|
|
|
serif::eos::EOS EOS(*EOSio);
|
|
|
|
serif::eos::EOSInput eosInput;
|
|
eosInput.temperature = 1.0e8; // Temperature in K
|
|
eosInput.density = 1.0e6; // Density in g/cm^3
|
|
eosInput.composition = composition; // Set the composition
|
|
|
|
serif::eos::EOSOutput eosOutput;
|
|
EXPECT_NO_THROW(eosOutput = EOS.get(eosInput));
|
|
eosOutput = EOS.get(eosInput);
|
|
|
|
const double pressureFraction = eosOutput.pressure.total / 6.9548533046915791E+22;
|
|
constexpr double relError = 1e-6;
|
|
EXPECT_NEAR(pressureFraction, 1.0, relError);
|
|
}
|