refactor(network): updated network and network::approx8 to use composition module
This is a very basic wrapper implimentation currently. This is sufficient to lock the interface down so that other code can target it. However, internally there is just a "convert" function. Eventually we should rework the code itself to use the composition module more directly.
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "approx8.h"
|
||||
#include "config.h"
|
||||
#include "network.h"
|
||||
#include "composition.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
@@ -32,19 +33,31 @@ TEST_F(approx8Test, evaluate) {
|
||||
serif::network::NetIn netIn;
|
||||
|
||||
std::vector<double> comp = {0.708, 2.94e-5, 0.276, 0.003, 0.0011, 9.62e-3, 1.62e-3, 5.16e-4};
|
||||
std::vector<std::string> symbols = {"H-1", "He-3", "He-4", "C-12", "N-14", "O-16", "Ne-20", "Mg-24"};
|
||||
|
||||
netIn.composition = comp;
|
||||
serif::composition::Composition composition;
|
||||
composition.registerSymbol(symbols, true);
|
||||
composition.setMassFraction(symbols, comp);
|
||||
bool isFinalized = composition.finalize(true);
|
||||
EXPECT_TRUE(isFinalized);
|
||||
|
||||
netIn.composition = composition;
|
||||
netIn.temperature = 1e7;
|
||||
netIn.density = 1e2;
|
||||
netIn.energy = 0.0;
|
||||
|
||||
netIn.tmax = 3.15e17;
|
||||
netIn.tMax = 3.15e17;
|
||||
netIn.dt0 = 1e12;
|
||||
|
||||
serif::network::NetOut netOut;
|
||||
EXPECT_NO_THROW(netOut = network.evaluate(netIn));
|
||||
|
||||
EXPECT_DOUBLE_EQ(netOut.composition[serif::network::approx8::Net::ih1], 0.50166260916650918);
|
||||
EXPECT_DOUBLE_EQ(netOut.composition[serif::network::approx8::Net::ihe4],0.48172270591286032);
|
||||
EXPECT_DOUBLE_EQ(netOut.energy, 1.6433049870528356e+18);
|
||||
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;
|
||||
|
||||
double relError = 1e-8;
|
||||
EXPECT_NEAR(H1MassFraction, 1.0, relError);
|
||||
EXPECT_NEAR(He4MassFraction, 1.0, relError);
|
||||
EXPECT_NEAR(energyFraction, 1.0, relError);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user