SERiF 0.0.1a
3+1D Stellar Structure and Evolution
Loading...
Searching...
No Matches
eosTest.cpp
Go to the documentation of this file.
1#include <gtest/gtest.h>
2#include <memory>
3#include <string>
4#include <sstream>
5
6#include "helm.h"
7#include "resourceManager.h"
8#include "config.h"
9#include "composition.h"
10#include "EOS.h"
11
16
20class eosTest : public ::testing::Test {};
21
22std::string TEST_CONFIG = std::string(getenv("MESON_SOURCE_ROOT")) + "/tests/testsConfig.yaml";
23
27
28TEST_F(eosTest, read_helm_table) {
29 serif::config::Config::getInstance().loadConfig(TEST_CONFIG);
31 auto& eos = std::get<std::unique_ptr<serif::eos::EOSio>>(rm.getResource("eos:helm"));
32 const auto& table = eos->getTable();
33 const auto& helmTable = *std::get<std::unique_ptr<serif::eos::helmholtz::HELMTable>>(table);
34 std::stringstream ss;
35 ss << helmTable;
36 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");
37}
38
39TEST_F(eosTest, get_helm_EOS) {
40 constexpr int nel=3;
41 double xMass[nel], aIon[nel], zIon[nel];
43
44 xMass[0] = 0.75; aIon[0] = 1.0; zIon[0] = 1.0;
45 xMass[1] = 0.23; aIon[1] = 4.0; zIon[1] = 2.0;
46 xMass[2] = 0.02; aIon[2] = 12.0; zIon[2] = 6.0;
47
48 eos1.T = 1.0e8;
49 eos1.rho = 1.0e6;
50
51 double aSum = 0.0;
52 double zSum = 0.0;
53 for (int i=0; i<nel; i++) {
54 aSum += xMass[i]/aIon[i];
55 zSum += xMass[i]*zIon[i]/aIon[i];
56 }
57 eos1.abar = 1.0/aSum;
58 eos1.zbar = eos1.abar*zSum;
59
61 auto& eos = std::get<std::unique_ptr<serif::eos::EOSio>>(rm.getResource("eos:helm"));
62 auto& table = eos->getTable();
63 auto& helmTable = *std::get<std::unique_ptr<serif::eos::helmholtz::HELMTable>>(table);
64 serif::eos::helmholtz::HELMEOSOutput helmEos = get_helm_EOS(eos1, helmTable);
65
66 constexpr double absErr = 1e-12;
67
68 //Check composition info
69 EXPECT_NEAR( helmEos.ye, 8.75e-01, absErr);
70
71 //Check E, P, S and derivatives of each wrt Rho and T
72 EXPECT_NEAR( helmEos.etaele, 2.3043348231021554e+01, absErr);
73 EXPECT_NEAR( helmEos.etot, 1.1586558190936826e+17, 1e3);
74 EXPECT_NEAR(helmEos.denerdd, 6.1893000468285858e+10, 1e-2);
75 EXPECT_NEAR(helmEos.denerdt, 1.2129708972542575e+08, 1e-7);
76 EXPECT_NEAR( helmEos.ptot, 6.9610135220017030e+22, 1e10);
77 EXPECT_NEAR(helmEos.dpresdd, 1.0296440482849070e+17, 1e3);
78 EXPECT_NEAR(helmEos.dpresdt, 7.7171347517311625e+13, 1.0);
79 EXPECT_NEAR( helmEos.stot, 6.0647461970567346e+08, 1e-7);
80 EXPECT_NEAR(helmEos.dentrdd,-7.7171347517311645e+01, absErr);
81 EXPECT_NEAR(helmEos.dentrdt, 1.2129708972542577e+00, absErr);
82
83 // Maxwell relations, should always be zero
84 EXPECT_NEAR( helmEos.dse, 0, absErr);
85 EXPECT_NEAR( helmEos.dpe, 0, absErr);
86 EXPECT_NEAR( helmEos.dsp, 0, absErr);
87}
88
89TEST_F(eosTest, eos_using_composition) {
91 composition.registerSymbol({
92 "H-1",
93 "He-4",
94 "C-12",
95 "O-16",
96 "Ne-20",
97 "Fe-56",
98 "N-14",
99 "Si-28",
100 "Mg-24"
101 }, true);
102 composition.setMassFraction("H-1", 0.75);
103 composition.setMassFraction("He-4", 0.23);
104 composition.setMassFraction("C-12", 0.0044);
105 composition.setMassFraction("O-16", 0.0096);
106 composition.setMassFraction("Ne-20", 0.002);
107 composition.setMassFraction("Fe-56", 0.0018);
108 composition.setMassFraction("N-14", 0.001);
109 composition.setMassFraction("Si-28", 0.0008);
110 composition.setMassFraction("Mg-24", 0.0004);
111 composition.finalize();
112
114 auto& EOSio = std::get<std::unique_ptr<serif::eos::EOSio>>(rm.getResource("eos:helm"));
115
116 serif::eos::EOS EOS(*EOSio);
117
118 serif::eos::EOSInput eosInput;
119 eosInput.temperature = 1.0e8; // Temperature in K
120 eosInput.density = 1.0e6; // Density in g/cm^3
121 eosInput.composition = composition; // Set the composition
122
123 serif::eos::EOSOutput eosOutput;
124 EXPECT_NO_THROW(eosOutput = EOS.get(eosInput));
125 eosOutput = EOS.get(eosInput);
126
127 const double pressureFraction = eosOutput.pressure.total / 6.9548533046915791E+22;
128 constexpr double relError = 1e-6;
129 EXPECT_NEAR(pressureFraction, 1.0, relError);
130}
Test suite for the const class.
Definition eosTest.cpp:20
Manages the composition of elements.
Main class for accessing Equation of State data.
Definition EOS.h:216
const types::Resource & getResource(const std::string &name) const
Gets a resource by name.
static ResourceManager & getInstance()
Gets the singleton instance of the ResourceManager.
TEST_F(eosTest, read_helm_table)
Definition eosTest.cpp:28
std::string TEST_CONFIG
Definition eosTest.cpp:22
Structure to hold the output parameters and derivatives of the EOS calculation.
Input parameters for an EOS calculation.
Definition EOS.h:17
serif::composition::Composition composition
The composition of the system.
Definition EOS.h:18
double density
The density of the system in cgs (g/cm^3).
Definition EOS.h:19
double temperature
The temperature of the system in cgs (K).
Definition EOS.h:20
Output from an EOS calculation.
Definition EOS.h:78
EOSParameter pressure
Pressure output data, including total, gas, radiation, and derivatives.
Definition EOS.h:83
double total
Total value of the parameter (gas + radiation) (cgs).
Definition EOS.h:45
Structure to hold the input parameters for the EOS calculation.
Definition helm.h:176
double abar
Mean atomic mass.
Definition helm.h:179
double zbar
Mean atomic number.
Definition helm.h:180