2025-03-21 14:03:46 -04:00
|
|
|
#include <string>
|
2025-06-23 15:18:56 -04:00
|
|
|
#include <gtest/gtest.h>
|
2025-03-21 14:03:46 -04:00
|
|
|
|
2025-06-23 15:18:56 -04:00
|
|
|
#include "fourdst/composition/composition.h"
|
|
|
|
|
#include "fourdst/config/config.h"
|
2025-06-26 15:13:46 -04:00
|
|
|
#include "../../src/network/include/gridfire/engine/engine_approx8.h"
|
|
|
|
|
#include "../../src/network/include/gridfire/engine/engine_graph.h"
|
2025-06-23 15:18:56 -04:00
|
|
|
#include "gridfire/network.h"
|
2025-03-21 14:03:46 -04:00
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2025-06-23 15:18:56 -04:00
|
|
|
#include "gridfire/reactions.h"
|
2025-06-18 15:25:41 -04:00
|
|
|
|
2025-03-21 14:03:46 -04:00
|
|
|
std::string TEST_CONFIG = std::string(getenv("MESON_SOURCE_ROOT")) + "/tests/testsConfig.yaml";
|
|
|
|
|
class approx8Test : public ::testing::Test {};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Test the constructor of the Config class.
|
|
|
|
|
*/
|
|
|
|
|
TEST_F(approx8Test, constructor) {
|
2025-06-21 13:18:38 -04:00
|
|
|
fourdst::config::Config& config = fourdst::config::Config::getInstance();
|
2025-03-21 14:03:46 -04:00
|
|
|
config.loadConfig(TEST_CONFIG);
|
2025-06-21 13:18:38 -04:00
|
|
|
EXPECT_NO_THROW(gridfire::approx8::Approx8Network());
|
2025-03-21 14:03:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(approx8Test, setStiff) {
|
2025-06-21 13:18:38 -04:00
|
|
|
gridfire::approx8::Approx8Network network;
|
2025-03-21 14:03:46 -04:00
|
|
|
EXPECT_NO_THROW(network.setStiff(true));
|
|
|
|
|
EXPECT_TRUE(network.isStiff());
|
|
|
|
|
EXPECT_NO_THROW(network.setStiff(false));
|
|
|
|
|
EXPECT_FALSE(network.isStiff());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(approx8Test, evaluate) {
|
2025-06-21 13:18:38 -04:00
|
|
|
gridfire::approx8::Approx8Network network;
|
|
|
|
|
gridfire::NetIn netIn;
|
2025-06-12 11:22:25 -04:00
|
|
|
|
2025-03-21 14:03:46 -04:00
|
|
|
std::vector<double> comp = {0.708, 2.94e-5, 0.276, 0.003, 0.0011, 9.62e-3, 1.62e-3, 5.16e-4};
|
2025-06-17 09:43:43 -04:00
|
|
|
std::vector<std::string> symbols = {"H-1", "He-3", "He-4", "C-12", "N-14", "O-16", "Ne-20", "Mg-24"};
|
2025-03-21 14:03:46 -04:00
|
|
|
|
2025-06-21 13:18:38 -04:00
|
|
|
fourdst::composition::Composition composition;
|
2025-06-17 09:43:43 -04:00
|
|
|
composition.registerSymbol(symbols, true);
|
|
|
|
|
composition.setMassFraction(symbols, comp);
|
|
|
|
|
bool isFinalized = composition.finalize(true);
|
|
|
|
|
EXPECT_TRUE(isFinalized);
|
|
|
|
|
|
|
|
|
|
netIn.composition = composition;
|
2025-03-21 14:03:46 -04:00
|
|
|
netIn.temperature = 1e7;
|
|
|
|
|
netIn.density = 1e2;
|
|
|
|
|
netIn.energy = 0.0;
|
2025-06-12 11:22:25 -04:00
|
|
|
|
2025-06-17 09:43:43 -04:00
|
|
|
netIn.tMax = 3.15e17;
|
2025-03-21 14:03:46 -04:00
|
|
|
netIn.dt0 = 1e12;
|
|
|
|
|
|
2025-06-21 13:18:38 -04:00
|
|
|
gridfire::NetOut netOut;
|
2025-03-21 14:03:46 -04:00
|
|
|
EXPECT_NO_THROW(netOut = network.evaluate(netIn));
|
|
|
|
|
|
2025-06-17 09:43:43 -04:00
|
|
|
double energyFraction = netOut.energy / 1.6433051127589775E+18;
|
|
|
|
|
double H1MassFraction = netOut.composition.getMassFraction("H-1")/ 0.50166262445895604;
|
|
|
|
|
double He4MassFraction = netOut.composition.getMassFraction("He-4") / 0.48172273720971226;
|
|
|
|
|
|
2025-06-17 10:17:46 -04:00
|
|
|
double relError = 1e-6;
|
2025-06-17 09:43:43 -04:00
|
|
|
EXPECT_NEAR(H1MassFraction, 1.0, relError);
|
|
|
|
|
EXPECT_NEAR(He4MassFraction, 1.0, relError);
|
|
|
|
|
EXPECT_NEAR(energyFraction, 1.0, relError);
|
2025-03-21 14:03:46 -04:00
|
|
|
}
|
2025-06-18 15:25:41 -04:00
|
|
|
|
|
|
|
|
TEST_F(approx8Test, reaclib) {
|
2025-06-21 13:18:38 -04:00
|
|
|
using namespace gridfire;
|
2025-06-23 15:18:56 -04:00
|
|
|
const std::vector<double> comp = {0.708, 0.0, 2.94e-5, 0.276, 0.003, 0.0011, 9.62e-3, 1.62e-3, 5.16e-4};
|
|
|
|
|
const std::vector<std::string> symbols = {"H-1", "H-2", "He-3", "He-4", "C-12", "N-14", "O-16", "Ne-20", "Mg-24"};
|
2025-06-18 15:25:41 -04:00
|
|
|
|
2025-06-21 13:18:38 -04:00
|
|
|
fourdst::composition::Composition composition;
|
2025-06-18 15:25:41 -04:00
|
|
|
composition.registerSymbol(symbols, true);
|
|
|
|
|
composition.setMassFraction(symbols, comp);
|
2025-06-20 13:52:09 -04:00
|
|
|
composition.finalize(true);
|
|
|
|
|
|
2025-06-23 15:18:56 -04:00
|
|
|
|
2025-06-20 13:52:09 -04:00
|
|
|
NetIn netIn;
|
|
|
|
|
netIn.composition = composition;
|
|
|
|
|
netIn.temperature = 1e7;
|
|
|
|
|
netIn.density = 1e2;
|
|
|
|
|
netIn.energy = 0.0;
|
|
|
|
|
|
|
|
|
|
netIn.tMax = 3.15e17;
|
|
|
|
|
netIn.dt0 = 1e12;
|
2025-06-18 15:25:41 -04:00
|
|
|
|
2025-06-26 15:13:46 -04:00
|
|
|
GraphEngine network(composition);
|
2025-06-20 13:52:09 -04:00
|
|
|
NetOut netOut;
|
|
|
|
|
netOut = network.evaluate(netIn);
|
|
|
|
|
std::cout << netOut << std::endl;
|
2025-06-18 15:25:41 -04:00
|
|
|
}
|