From 592313804d921a9fba1190cf2103c0a9dff24392 Mon Sep 17 00:00:00 2001 From: Ian Bell <ian.bell@nist.gov> Date: Wed, 2 Nov 2022 19:31:26 -0400 Subject: [PATCH] Test and bench new methods --- interface/CPP/test_teqpcpp.cpp | 11 ++++++++++- src/bench_AbstractModel.cpp | 15 ++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/interface/CPP/test_teqpcpp.cpp b/interface/CPP/test_teqpcpp.cpp index 76c23b6..a9d0161 100644 --- a/interface/CPP/test_teqpcpp.cpp +++ b/interface/CPP/test_teqpcpp.cpp @@ -10,6 +10,7 @@ #include "teqpcpp.hpp" #include <iostream> +#include "teqp/cpp/derivs.hpp" int main() { nlohmann::json j = { @@ -34,10 +35,18 @@ int main() { auto vhat = am->get_partial_molar_volumes(300.0, z*300.0); std::cout << vhat << std::endl; + auto mat = am->get_deriv_mat2(300.0, 300.0, z); + std::cout << mat << std::endl; + + const std::vector<char> vars = {'T','D','P','S'}; + auto im = teqp::cppinterface::build_iteration_Jv(vars, mat, mat, 8.3144, 300.0, 300.0, z); + std::cout << im.J << std::endl; + try{ std::cout << am->get_m() << std::endl; } - catch(...){ + catch(std::exception&e){ + std::cout << e.what() << std::endl; std::cout << "This fails, as it should because the model is not a PCSAFT one" << std::endl; } } diff --git a/src/bench_AbstractModel.cpp b/src/bench_AbstractModel.cpp index 7ad0b1c..89896ac 100644 --- a/src/bench_AbstractModel.cpp +++ b/src/bench_AbstractModel.cpp @@ -2,16 +2,16 @@ #include <catch2/benchmark/catch_benchmark_all.hpp> #include "../interface/CPP/teqpcpp.hpp" +#include "teqp/cpp/derivs.hpp" using namespace teqp; TEST_CASE("multifluid derivatives", "[mf]") { - nlohmann::json j = { {"kind", "multifluid"}, {"model", { - {"components", {"../mycp/dev/fluids/Methane.json","../mycp/dev/fluids/Ethane.json"}}, + {"components", {"../mycp/dev/fluids/Methane.json"}}, {"BIP", "../mycp/dev/mixtures/mixture_binary_pairs.json"}, {"departure", "../mycp/dev/mixtures/mixture_departure_functions.json"} } @@ -20,7 +20,7 @@ TEST_CASE("multifluid derivatives", "[mf]") auto am = teqp::cppinterface::make_model(j); auto am2 = teqp::cppinterface::make_vdW1(2, 3); - auto z = (Eigen::ArrayXd(2) << 0.5, 0.5).finished(); + auto z = (Eigen::ArrayXd(1) << 1.0).finished(); auto rhovec = 300.0*z; BENCHMARK("alphar") { @@ -35,4 +35,13 @@ TEST_CASE("multifluid derivatives", "[mf]") BENCHMARK("partial_molar_volumes") { return am->get_partial_molar_volumes(300.0, rhovec); }; + BENCHMARK("get_deriv_mat2") { + return am->get_deriv_mat2(300.0, 3.0, z); + }; + BENCHMARK("build_iteration_Jv") { + auto mat = am->get_deriv_mat2(300.0, 3.0, z); + auto mat2 = am->get_deriv_mat2(300.0, 3.0, z); + const std::vector<char> vars = {'T','D','P','S'}; + return teqp::cppinterface::build_iteration_Jv(vars, mat, mat2, 8.3144, 300.0, 300.0, z); + }; } -- GitLab