Skip to content
Snippets Groups Projects
Commit f30e4669 authored by Ian Bell's avatar Ian Bell
Browse files

Add CPA to json builder

parent 75d4530f
No related branches found
No related tags found
No related merge requests found
...@@ -2,13 +2,15 @@ ...@@ -2,13 +2,15 @@
#include "teqp/models/vdW.hpp" #include "teqp/models/vdW.hpp"
#include "teqp/models/cubics.hpp" #include "teqp/models/cubics.hpp"
#include "teqp/models/CPA.hpp"
#include "nlohmann/json.hpp" #include "nlohmann/json.hpp"
using vad = std::valarray<double>; using vad = std::valarray<double>;
using cub = decltype(canonical_PR(vad{}, vad{}, vad{})); 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) { AllowedModels build_model(const nlohmann::json& json) {
...@@ -27,6 +29,9 @@ 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"); 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); return canonical_SRK(Tc_K, pc_Pa, acentric);
} }
else if (kind == "CPA") {
return CPA::CPAfactory(spec);
}
else { else {
throw teqpcException(30, "Unknown kind:" + kind); throw teqpcException(30, "Unknown kind:" + kind);
} }
......
...@@ -168,6 +168,30 @@ TEST_CASE("Use of C interface with simple models") { ...@@ -168,6 +168,30 @@ TEST_CASE("Use of C interface with simple models") {
REQUIRE(e3 == 0); REQUIRE(e3 == 0);
return val; 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 #else
int main() { int main() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment