diff --git a/include/teqp/json_builder.hpp b/include/teqp/json_builder.hpp index e57809249d8e174b906bf4ce7ef593433659c91c..0e1f4bc23e68e88dc9716b5838703fbcd230149e 100644 --- a/include/teqp/json_builder.hpp +++ b/include/teqp/json_builder.hpp @@ -2,13 +2,15 @@ #include "teqp/models/vdW.hpp" #include "teqp/models/cubics.hpp" +#include "teqp/models/CPA.hpp" #include "nlohmann/json.hpp" using vad = std::valarray<double>; using cub = decltype(canonical_PR(vad{}, vad{}, vad{})); +using cpatype = decltype(CPA::CPAfactory(nlohmann::json{})); // The type returned by the factory function -using AllowedModels = std::variant<vdWEOS1, cub>; +using AllowedModels = std::variant<vdWEOS1, cub, cpatype>; AllowedModels build_model(const nlohmann::json& json) { @@ -27,6 +29,9 @@ AllowedModels build_model(const nlohmann::json& json) { std::valarray<double> Tc_K = spec.at("Tcrit / K"), pc_Pa = spec.at("pcrit / Pa"), acentric = spec.at("acentric"); return canonical_SRK(Tc_K, pc_Pa, acentric); } + else if (kind == "CPA") { + return CPA::CPAfactory(spec); + } else { throw teqpcException(30, "Unknown kind:" + kind); } diff --git a/interface/C/teqpc.cpp b/interface/C/teqpc.cpp index e678f8fc65829738a4ad0b5e04567d2469db86d2..d72f2ba8386e86c9cd85826d8fca1bf3da041af3 100644 --- a/interface/C/teqpc.cpp +++ b/interface/C/teqpc.cpp @@ -168,6 +168,30 @@ TEST_CASE("Use of C interface with simple models") { REQUIRE(e3 == 0); return val; }; + + BENCHMARK("CPA") { + nlohmann::json water = { + {"a0i / Pa m^6/mol^2",0.12277 }, {"bi / m^3/mol", 0.000014515}, {"c1", 0.67359}, {"Tc / K", 647.096}, + {"epsABi / J/mol", 16655.0}, {"betaABi", 0.0692}, {"class", "4C"} + }; + nlohmann::json jCPA = { + {"cubic","SRK"}, + {"pures", {water}}, + {"R_gas / J/mol/K", 8.3144598} + }; + nlohmann::json j = { + {"kind", "CPA"}, + {"model", jCPA} + }; + std::string jstring = j.dump(); + int e1 = build_model(jstring.c_str(), uuid, errmsg, errmsg_length); + int e2 = get_Arxy(uuid, 0, 1, 300, 3.0e-6, &(molefrac[0]), molefrac.size(), &val, errmsg, errmsg_length); + int e3 = free_model(uuid, errmsg, errmsg_length); + REQUIRE(e1 == 0); + REQUIRE(e2 == 0); + REQUIRE(e3 == 0); + return val; + }; } #else int main() {