CoolProp 8.0.0
An open-source fluid property and humid air property database
CoolProp-Tests-CubicAlpha.cpp
Go to the documentation of this file.
1// Catch2 tests for cubic EOS alpha-function implementations.
2// Verifies that the vectorised calc_all_terms() path produces bit-identical
3// results to the scalar term() path for BasicMathiasCopeman, MathiasCopeman,
4// and Twu alpha functions across a representative set of tau values.
5
6#if defined(ENABLE_CATCH)
7
8# include <catch2/catch_all.hpp>
9
10# include "../Backends/Cubics/GeneralizedCubic.h"
11
12# include <array>
13# include <cmath>
14# include <vector>
15
16using namespace CoolProp;
17
18TEST_CASE("calc_all_terms matches term() for non-default alpha functions", "[cubic_alpha]") {
19 const std::vector<double> tau_vals = {0.5, 0.7, 1.0, 1.3, 2.0};
20
21 SECTION("BasicMathiasCopemanAlphaFunction") {
22 // Arbitrary non-degenerate coefficients; values chosen to exercise all terms
23 const double omega = 0.152;
24 const double m = 0.37464 + 1.54226 * omega - 0.26992 * omega * omega;
25 const double a0 = 1.0;
26 const double Tr_over_Tci = 1.0;
27 BasicMathiasCopemanAlphaFunction alpha(a0, m, Tr_over_Tci);
28 for (double tau : tau_vals) {
29 CAPTURE(tau);
30 std::array<double, 5> terms;
31 alpha.calc_all_terms(tau, terms);
32 for (int k = 0; k < 5; ++k) {
33 CAPTURE(k);
34 double ref = alpha.term(tau, k);
35 double rel = (ref != 0.0) ? std::abs(terms[k] - ref) / std::abs(ref) : std::abs(terms[k]);
36 CHECK(rel < 1e-12);
37 }
38 }
39 }
40
41 SECTION("MathiasCopemanAlphaFunction") {
42 // Arbitrary non-degenerate coefficients; values chosen to exercise all terms.
43 const double c1 = 0.8240, c2 = -0.4800, c3 = 0.6200;
44 const double a0 = 1.0;
45 const double Tr_over_Tci = 0.95;
46 MathiasCopemanAlphaFunction alpha(a0, c1, c2, c3, Tr_over_Tci);
47 for (double tau : tau_vals) {
48 CAPTURE(tau);
49 std::array<double, 5> terms;
50 alpha.calc_all_terms(tau, terms);
51 for (int k = 0; k < 5; ++k) {
52 CAPTURE(k);
53 double ref = alpha.term(tau, k);
54 double rel = (ref != 0.0) ? std::abs(terms[k] - ref) / std::abs(ref) : std::abs(terms[k]);
55 CHECK(rel < 1e-12);
56 }
57 }
58 }
59
60 SECTION("TwuAlphaFunction") {
61 // Arbitrary non-degenerate coefficients; values chosen to exercise all terms
62 const double L = 0.4692, M = 0.8610, N = 1.9127;
63 const double a0 = 1.0;
64 const double Tr_over_Tci = 1.0;
65 TwuAlphaFunction alpha(a0, L, M, N, Tr_over_Tci);
66 for (double tau : tau_vals) {
67 CAPTURE(tau);
68 std::array<double, 5> terms;
69 alpha.calc_all_terms(tau, terms);
70 for (int k = 0; k < 5; ++k) {
71 CAPTURE(k);
72 double ref = alpha.term(tau, k);
73 double rel = (ref != 0.0) ? std::abs(terms[k] - ref) / std::abs(ref) : std::abs(terms[k]);
74 CHECK(rel < 1e-12);
75 }
76 }
77 }
78
79 SECTION("TwuAlphaFunction - Tr_over_Tci != 1") {
80 const double L = 0.3000, M = 0.9200, N = 2.1000;
81 const double a0 = 1.5;
82 const double Tr_over_Tci = 0.85;
83 TwuAlphaFunction alpha(a0, L, M, N, Tr_over_Tci);
84 for (double tau : tau_vals) {
85 CAPTURE(tau);
86 std::array<double, 5> terms;
87 alpha.calc_all_terms(tau, terms);
88 for (int k = 0; k < 5; ++k) {
89 CAPTURE(k);
90 double ref = alpha.term(tau, k);
91 double rel = (ref != 0.0) ? std::abs(terms[k] - ref) / std::abs(ref) : std::abs(terms[k]);
92 CHECK(rel < 1e-12);
93 }
94 }
95 }
96}
97
98#endif