From b05c30dc9cf56cde94edbf7e84b67c872b98fab2 Mon Sep 17 00:00:00 2001
From: Ian Bell <ian.bell@nist.gov>
Date: Wed, 2 Aug 2023 09:39:48 -0400
Subject: [PATCH] Check water evaluation at critical point

---
 src/tests/catch_test_multifluid.cxx | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/src/tests/catch_test_multifluid.cxx b/src/tests/catch_test_multifluid.cxx
index 884b7c3..15a51ae 100644
--- a/src/tests/catch_test_multifluid.cxx
+++ b/src/tests/catch_test_multifluid.cxx
@@ -324,6 +324,27 @@ TEST_CASE("Trace a VLE isotherm for acetone + water", "[isothermacetonebenzene]"
     auto o = trace_VLE_isotherm_binary(model, T, rhovecL, rhovecV);
 }
 
+TEST_CASE("Calculate water at critical point", "[WATERcrit]") {
+    std::string root = "../mycp";
+    const auto model = build_multifluid_model({ "Water" }, root);
+    
+    using tdx = TDXDerivatives<decltype(model)>;
+    auto Tc = model.redfunc.Tc[0];
+    auto rhoc = 1/model.redfunc.vc[0];
+    auto z = (Eigen::ArrayXd(1) << 1.0).finished();
+    auto a1 = tdx::get_Ar0n<1>(model, Tc, rhoc, z);
+    CHECK(std::isfinite(a1[1]));
+    auto a2 = tdx::get_Ar0n<2>(model, Tc, rhoc, z);
+    auto a3 = tdx::get_Ar0n<3>(model, Tc, rhoc, z);
+    auto a4 = tdx::get_Ar0n<3>(model, Tc, rhoc, z);
+    CHECK(a3[1] == a1[1]);
+    auto R = model.R(z);
+    auto dpdrho = R*Tc*(1 + 2*a4[1] + a4[2]);
+    auto d2pdrho2 = R*Tc/(rhoc)*(2*a4[1] + 4*a4[2] + a4[3]);
+    CHECK(dpdrho == Approx(0).margin(1e-9));
+    CHECK(d2pdrho2 == Approx(0).margin(1e-9));
+}
+
 TEST_CASE("Calculate partial molar volume for a CO2 containing mixture", "[partial_molar_volume]") {
     std::string root = "../mycp";
     const auto model = build_multifluid_model({ "CarbonDioxide", "Heptane" }, root);
-- 
GitLab