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

Make the multifluid example compile again

parent 1f98587d
No related branches found
No related tags found
No related merge requests found
...@@ -4,146 +4,88 @@ ...@@ -4,146 +4,88 @@
#include "teqp/models/multifluid.hpp" #include "teqp/models/multifluid.hpp"
#include <optional> #include <optional>
//
//class Timer {
//private:
// int N; template<typename J>
// decltype(std::chrono::steady_clock::now()) tic; void time_calls(const std::string &coolprop_root, const J &BIPcollection) {
//public: auto model = build_multifluid_model({ "methane", "ethane" }, coolprop_root, BIPcollection);
// Timer(int N) : N(N), tic(std::chrono::steady_clock::now()){} Eigen::ArrayXd rhovec(2); rhovec << 1.0, 2.0;
// ~Timer() { double T = 300;
// auto elap = std::chrono::duration<double>(std::chrono::steady_clock::now()-tic).count(); {
// std::cout << elap/N*1e6 << " us/call" << std::endl; const auto molefrac = (Eigen::ArrayXd(2) << rhovec[0] / rhovec.sum(), rhovec[1] / rhovec.sum()).finished();
// }
//}; using vd = VirialDerivatives<decltype(model)>;
// auto B12 = vd::get_B12vir(model, T, molefrac);
//void trace_critical_loci(const std::string &coolprop_root, const nlohmann::json &BIPcollection) {
// std::vector<std::vector<std::string>> pairs = { using id = IsochoricDerivatives<decltype(model), double, Eigen::ArrayXd>;
// { "CarbonDioxide", "R1234YF" }, { "CarbonDioxide","R1234ZE(E)" }, { "ETHYLENE","R1243ZF" }, auto mu = id::get_chempotVLE_autodiff(model, T, rhovec);
// { "R1234YF","R1234ZE(E)" }, { "R134A","R1234YF" }, { "R23","R1234YF" },
// { "R32","R1123" }, { "R32","R1234YF" }, { "R32","R1234ZE(E)" } const double rho = rhovec.sum();
// }; double T = 300.0;
// for (auto &pp : pairs) { constexpr int N = 10000;
// using ModelType = decltype(build_multifluid_model(pp, coolprop_root, BIPcollection)); volatile double alphar;
// std::optional<ModelType> optmodel{std::nullopt}; using tdx = TDXDerivatives<decltype(model)>;
// try { double rrrr = tdx::get_Ar01(model, T, rho, molefrac);
// optmodel.emplace(build_multifluid_model(pp, coolprop_root, BIPcollection)); double rrrr2 = tdx::get_Ar02(model, T, rho, molefrac);
// } {
// catch (std::exception &e) { Timer t(N);
// std::cout << e.what() << std::endl; for (auto i = 0; i < N; ++i) {
// std::cout << pp[0] << "&" << pp[1] << std::endl; alphar = model.alphar(T, rho, molefrac);
// continue; }
// } std::cout << alphar << " function call" << std::endl;
// for (int i : {0, 1}){ }
// const auto &model = optmodel.value(); {
// auto rhoc0 = 1.0 / model.redfunc.vc[i]; Timer t(N);
// auto T0 = model.redfunc.Tc[i]; for (auto i = 0; i < N; ++i) {
// Eigen::ArrayXd rhovec(2); rhovec[i] = { rhoc0 }; rhovec[1L - i] = 0.0; alphar = tdx::get_Ar01<ADBackends::complex_step>(model, T, rho, molefrac);
// }
// using ct = CriticalTracing<ModelType>; std::cout << alphar << "; 1st CSD" << std::endl;
// }
// // Non-analytic terms make it impossible to initialize AT the pure components {
// if (pp[0] == "CarbonDioxide" || pp[1] == "CarbonDioxide") { Timer t(N);
// if (i == 0) { for (auto i = 0; i < N; ++i) {
// rhovec[i] *= 0.9999; alphar = tdx::get_Ar01<ADBackends::autodiff>(model, T, rho, molefrac);
// rhovec[1L - i] = 0.9999; }
// } std::cout << alphar << "; 1st autodiff::autodiff" << std::endl;
// else { }
// rhovec[i] *= 1.0001; {
// rhovec[1L - i] = 1.0001; Timer t(N);
// } for (auto i = 0; i < N; ++i) {
// double zi = rhovec[i] / rhovec.sum(); alphar = tdx::get_Ar01<ADBackends::multicomplex>(model, T, rho, molefrac);
// double T = zi * model.redfunc.Tc[i] + (1 - zi) * model.redfunc.Tc[1L - i]; }
// double z0 = (i == 0) ? zi : 1-zi; std::cout << alphar << "; 1st MCX" << std::endl;
// auto [Tnew, rhonew] = ct::critical_polish_molefrac(model, T, rhovec, z0); }
// T0 = Tnew; {
// rhoc0 = rhovec.sum(); Timer t(N);
// } for (auto i = 0; i < N; ++i) {
// std::string filename = pp[0] + "_" + pp[1] + ".csv"; alphar = tdx::get_Ar02(model, T, rho, molefrac);
// ct::trace_critical_arclength_binary(model, T0, rhovec, filename); }
// } std::cout << alphar << "; 2nd autodiff" << std::endl;
// } }
//} {
// Timer t(N);
//template<typename J> for (auto i = 0; i < N; ++i) {
//void time_calls(const std::string &coolprop_root, const J &BIPcollection) { auto o = vd::template get_Bnvir<3, ADBackends::autodiff>(model, T, molefrac)[3];
// auto model = build_multifluid_model({ "methane", "ethane" }, coolprop_root, BIPcollection); }
// Eigen::ArrayXd rhovec(2); rhovec << 1.0, 2.0; std::cout << alphar << "; 3 derivs" << std::endl;
// double T = 300; }
// { {
// const auto molefrac = (Eigen::ArrayXd(2) << rhovec[0] / rhovec.sum(), rhovec[1] / rhovec.sum()).finished(); Timer t(N);
// for (auto i = 0; i < N; ++i) {
// using vd = VirialDerivatives<decltype(model)>; auto o = vd::template get_Bnvir<4, ADBackends::autodiff>(model, T, molefrac)[4];
// auto B12 = vd::get_B12vir(model, T, molefrac); }
// std::cout << alphar << "; 4 derivs" << std::endl;
// using id = IsochoricDerivatives<decltype(model)>; }
// auto mu = id::get_chempot_autodiff(model, T, rhovec); {
// Timer t(N);
// const double rho = rhovec.sum(); for (auto i = 0; i < N; ++i) {
// double T = 300.0; auto o = vd::template get_Bnvir<5, ADBackends::autodiff>(model, T, molefrac)[5];
// constexpr int N = 10000; }
// volatile double alphar; std::cout << alphar << "; 5 derivs" << std::endl;
// using tdx = TDXDerivatives<decltype(model)>; }
// double rrrr = tdx::get_Ar01(model, T, rho, molefrac); }
// double rrrr2 = tdx::get_Ar02(model, T, rho, molefrac); }
// {
// Timer t(N);
// for (auto i = 0; i < N; ++i) {
// alphar = model.alphar(T, rho, molefrac);
// }
// std::cout << alphar << " function call" << std::endl;
// }
// {
// Timer t(N);
// for (auto i = 0; i < N; ++i) {
// alphar = tdx::get_Ar01<ADBackends::complex_step>(model, T, rho, molefrac);
// }
// std::cout << alphar << "; 1st CSD" << std::endl;
// }
// {
// Timer t(N);
// for (auto i = 0; i < N; ++i) {
// alphar = tdx::get_Ar01<ADBackends::autodiff>(model, T, rho, molefrac);
// }
// std::cout << alphar << "; 1st autodiff::autodiff" << std::endl;
// }
// {
// Timer t(N);
// for (auto i = 0; i < N; ++i) {
// alphar = tdx::get_Ar01<ADBackends::multicomplex>(model, T, rho, molefrac);
// }
// std::cout << alphar << "; 1st MCX" << std::endl;
// }
// {
// Timer t(N);
// for (auto i = 0; i < N; ++i) {
// alphar = tdx::get_Ar02(model, T, rho, molefrac);
// }
// std::cout << alphar << "; 2nd autodiff" << std::endl;
// }
// {
// Timer t(N);
// for (auto i = 0; i < N; ++i) {
// auto o = vd::template get_Bnvir<3, ADBackends::autodiff>(model, T, molefrac)[3];
// }
// std::cout << alphar << "; 3 derivs" << std::endl;
// }
// {
// Timer t(N);
// for (auto i = 0; i < N; ++i) {
// auto o = vd::template get_Bnvir<4, ADBackends::autodiff>(model, T, molefrac)[4];
// }
// std::cout << alphar << "; 4 derivs" << std::endl;
// }
// {
// Timer t(N);
// for (auto i = 0; i < N; ++i) {
// auto o = vd::template get_Bnvir<5, ADBackends::autodiff>(model, T, molefrac)[5];
// }
// std::cout << alphar << "; 5 derivs" << std::endl;
// }
// }
//}
int main(){ int main(){
...@@ -151,20 +93,25 @@ int main(){ ...@@ -151,20 +93,25 @@ int main(){
coolprop_root = "../mycp"; coolprop_root = "../mycp";
auto BIPcollection = coolprop_root + "/dev/mixtures/mixture_binary_pairs.json"; auto BIPcollection = coolprop_root + "/dev/mixtures/mixture_binary_pairs.json";
// Critical curves
/* {
Timer t(1);
trace_critical_loci(coolprop_root, BIPcollection);
}*/
//time_calls(coolprop_root, BIPcollection);
{ {
nlohmann::json flags = { {"estimate", true},{"another","key"} };
auto model = build_multifluid_model({ "CarbonDioxide", "Water" }, coolprop_root, BIPcollection, flags);
}
// // Critical curves
//{
// Timer t(1);
// trace_critical_loci(coolprop_root, BIPcollection);
// }*/
time_calls(coolprop_root, BIPcollection);
/*{
nlohmann::json flags = { {"estimate", true},{"another","key"} }; nlohmann::json flags = { {"estimate", true},{"another","key"} };
auto model = build_multifluid_model({ "Ethane", "R1234ze(E)" }, coolprop_root, BIPcollection, flags); auto model = build_multifluid_model({ "Ethane", "R1234ze(E)" }, coolprop_root, BIPcollection, flags);
nlohmann::json j = { {"betaT", 1.0},{"gammaT", 1.0},{"betaV", 1.0},{"gammaV", 1.0},{"Fij", 0.0} }; nlohmann::json j = { {"betaT", 1.0},{"gammaT", 1.0},{"betaV", 1.0},{"gammaV", 1.0},{"Fij", 0.0} };
auto mutant = build_mutant(model, j); auto mutant = build_mutant(model, j);
} }*/
{ {
auto model = build_multifluid_model({ "methane", "ethane" }, coolprop_root, BIPcollection); auto model = build_multifluid_model({ "methane", "ethane" }, coolprop_root, BIPcollection);
Eigen::ArrayXd rhovec(2); rhovec << 1.0, 2.0; Eigen::ArrayXd rhovec(2); rhovec << 1.0, 2.0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment