10#if defined(ENABLE_CATCH)
12# include <catch2/catch_all.hpp>
16# include "../Backends/Cubics/CubicBackend.h"
17# include "../Backends/Cubics/GeneralizedCubic.h"
33std::uint64_t bits_of(
double d) {
35 std::memcpy(&u, &d,
sizeof(u));
46TEST_CASE(
"Cubic u(T,rho) forward-eval timing",
"[cubic][!benchmark]") {
47 const std::string fluid =
"Methane";
48 const double T = 300.0;
49 const double rho_molar = 5000.0;
56 for (
auto c : {Case{
"SRK",
false}, Case{
"SRK",
true}, Case{
"PR",
false}, Case{
"PR",
true}, Case{
"HEOS",
false}}) {
57 auto AS = std::shared_ptr<AbstractState>(AbstractState::factory(c.backend, fluid));
62 const std::string label = std::string(c.backend) + (c.impose_phase ?
" (phase)" :
"");
63 BENCHMARK(std::string(
"u(T,rho): ") + label) {
71 for (
const char* backend : {
"SRK",
"PR"}) {
72 auto AS = std::shared_ptr<AbstractState>(AbstractState::factory(backend, fluid));
74 REQUIRE(cb !=
nullptr);
75 auto& cubic = cb->get_cubic();
76 const std::vector<double> z = {1.0};
77 const double tau = cubic->get_Tr() /
T;
78 const double delta = rho_molar / cubic->get_rhor();
79 BENCHMARK(std::string(
"raw alphar itau=1: ") + backend) {
80 return cubic->alphar(tau, delta, z, 1, 0);
91TEST_CASE(
"Cubic shared-intermediate all() is bit-exact vs 15 alphar() calls",
"[cubic]") {
92 for (
const char* backend : {
"SRK",
"PR"}) {
93 auto AS = std::shared_ptr<AbstractState>(AbstractState::factory(backend,
"Methane"));
95 REQUIRE(cb !=
nullptr);
96 auto& cubic = cb->get_cubic();
98 const std::vector<CoolPropDbl> z = {1.0};
99 for (
int it_tau = 0; it_tau <= 10; ++it_tau) {
100 const double tau = 0.7 + 0.13 * it_tau;
101 for (
int it_del = 0; it_del <= 10; ++it_del) {
102 const double delta = 0.2 + 0.27 * it_del;
105 for (std::size_t it = 0; it <= 4; ++it) {
106 for (std::size_t
id = 0;
id + it <= 4; ++id) {
107 const double direct = cubic->alphar(tau, delta, z, it,
id);
108 CHECK(bits_of(assembled.
get(it,
id)) == bits_of(direct));