teqp 0.22.0
Loading...
Searching...
No Matches
bench_teqpcpp.cpp
Go to the documentation of this file.
1#include <catch2/catch_test_macros.hpp>
2#include <catch2/benchmark/catch_benchmark_all.hpp>
3
4#include "teqpcpp.hpp"
5
6using namespace teqp::cppinterface;
7
8#include "teqp/derivs.hpp"
10
11using namespace teqp;
12
13TEST_CASE("Test C++ interface", "[C++]")
14{
15 auto modelnovar = teqp::build_multifluid_model({ "Methane","Ethane" }, "../mycp");
16 auto model = teqp::cppinterface::make_multifluid_model({ "Methane","Ethane" }, "../mycp");
17 auto z = (Eigen::ArrayXd(2) << 0.5, 0.5).finished();
18 SECTION("Ar01") {
19 double Ar01 = model->get_Arxy(0, 1, 300, 3, z);
20 }
21 SECTION("critical trace") {
22 double Tc1 = modelnovar.redfunc.Tc(0);
23 auto rhovec0 = (Eigen::ArrayXd(2) << 1/modelnovar.redfunc.vc(0), 0).finished();
24 auto cr = model->trace_critical_arclength_binary(Tc1, rhovec0);
25 std::cout << cr.dump(1) << std::endl;
26 }
27}
28
29TEST_CASE("Benchmark C++ interface", "[C++]")
30{
31 auto model = teqp::cppinterface::make_multifluid_model({ "Methane", "Ethane"}, "../mycp");
32 auto z = (Eigen::ArrayXd(2) << 0.5, 0.5).finished();
33
34 auto model1novar = teqp::build_multifluid_model({ "Methane" }, "../mycp");
35 auto model1 = teqp::cppinterface::make_multifluid_model({ "Methane" }, "../mycp");
36 auto z1 = (Eigen::ArrayXd(1) << 1).finished();
37
38 BENCHMARK("Ar01 two components") {
39 return model->get_Arxy(0, 1, 300, 3, z);
40 };
41 BENCHMARK("Ar01 one component w/ Arxy (C++ interface, runtime lookup)") {
42 return model->get_Arxy(0, 1, 300, 3, z1);
43 };
44 BENCHMARK("Ar01 one component w/ Ar01 directly") {
45 return TDXDerivatives<decltype(model1novar)>::get_Arxy<0,1,ADBackends::autodiff>(model1novar, 300, 3, z1);
46 };
47}
TEST_CASE("Test C++ interface", "[C++]")
std::unique_ptr< AbstractModel > make_multifluid_model(const std::vector< std::string > &components, const std::string &coolprop_root, const std::string &BIPcollectionpath={}, const nlohmann::json &flags={}, const std::string &departurepath={})
auto build_multifluid_model(const std::vector< std::string > &components, const std::string &root, const std::string &BIPcollectionpath={}, const nlohmann::json &flags={}, const std::string &departurepath={})