8 #ifndef _CRT_SECURE_NO_WARNINGS
9 #define _CRT_SECURE_NO_WARNINGS
22 #if !defined(NO_TABULAR_BACKENDS)
35 std::map<backend_families, shared_ptr<AbstractStateGenerator>>
backends;
42 std::map<
backend_families, shared_ptr<AbstractStateGenerator>>::const_iterator& generator,
43 std::map<
backend_families, shared_ptr<AbstractStateGenerator>>::const_iterator& end) {
64 if (fluid_names.size() == 1) {
65 std::string str = fluid_names[0];
66 if ((
upper(str) ==
"WATER") || (
upper(str) ==
"H2O")) {
69 throw ValueError(
format(
"The IF97 backend returns Water props only; fluid name [%s] not allowed", fluid_names[0].c_str()));
72 throw ValueError(
format(
"The IF97 backend does not support mixtures, only Water"));
98 if (fluid_names.size() != 1) {
99 throw ValueError(
format(
"For INCOMP backend, name vector must be one element long"));
135 std::map<backend_families, shared_ptr<AbstractStateGenerator>>::const_iterator gen, end;
144 return gen->second->get_AbstractState(
fluid_names);
146 #if !defined(NO_TABULAR_BACKENDS)
157 else if (!backend.compare(
"?") || backend.empty()) {
160 if (idel == std::string::npos)
170 throw ValueError(
format(
"Invalid backend name [%s] to factory function", backend.c_str()));
281 switch (input_pair) {
303 switch (input_pair) {
621 return -3.0*(Ar01-Ar11)/Ar20;
755 R = AS.
gas_constant(), delta = rho / rhor, tau = Tr / T;
821 double dTau_dT = 1 / dT_dtau;
825 double dDelta_drho = 1 / rhor;
859 dT = R / T * pow(tau, 2)
868 dT -= ((R / rho * delta
876 drho = R / rho * delta
904 dT = 1.0 / 2.0 / w / T
908 - (2 * aa / bb * daa_dTau - pow(aa / bb, 2) * dbb_dTau)));
913 drho = R * T / 2.0 / AS.
molar_mass() / w / rhor
916 - (2 * aa / bb * daa_dDelta - pow(aa / bb, 2) * dbb_dDelta));
939 dT2 = 2 * Tr / pow(T, 3);
962 dT2 = R / T * pow(tau, 2)
966 drho_dT = R / rho * delta
1011 CoolPropDbl dOf_dT, dOf_drho, dWrt_dT, dWrt_drho, dConstant_dT, dConstant_drho;
1015 get_dT_drho(*
this, Constant, dConstant_dT, dConstant_drho);
1017 return (dOf_dT * dConstant_drho - dOf_drho * dConstant_dT) / (dWrt_dT * dConstant_drho - dWrt_drho * dConstant_dT);
1020 CoolPropDbl dOf1_dT, dOf1_drho, dWrt1_dT, dWrt1_drho, dConstant1_dT, dConstant1_drho, d2Of1_dT2, d2Of1_drhodT, d2Of1_drho2, d2Wrt1_dT2,
1021 d2Wrt1_drhodT, d2Wrt1_drho2, d2Constant1_dT2, d2Constant1_drhodT, d2Constant1_drho2, dWrt2_dT, dWrt2_drho, dConstant2_dT, dConstant2_drho, N, D,
1022 dNdrho__T, dDdrho__T, dNdT__rho, dDdT__rho, dderiv1_drho, dderiv1_dT, second;
1027 get_dT_drho(*
this, Constant1, dConstant1_dT, dConstant1_drho);
1034 get_dT_drho(*
this, Constant2, dConstant2_dT, dConstant2_drho);
1037 N = dOf1_dT * dConstant1_drho - dOf1_drho * dConstant1_dT;
1038 D = dWrt1_dT * dConstant1_drho - dWrt1_drho * dConstant1_dT;
1042 dNdrho__T = dOf1_dT * d2Constant1_drho2 + d2Of1_drhodT * dConstant1_drho - dOf1_drho * d2Constant1_drhodT - d2Of1_drho2 * dConstant1_dT;
1043 dDdrho__T = dWrt1_dT * d2Constant1_drho2 + d2Wrt1_drhodT * dConstant1_drho - dWrt1_drho * d2Constant1_drhodT - d2Wrt1_drho2 * dConstant1_dT;
1047 dNdT__rho = dOf1_dT * d2Constant1_drhodT + d2Of1_dT2 * dConstant1_drho - dOf1_drho * d2Constant1_dT2 - d2Of1_drhodT * dConstant1_dT;
1048 dDdT__rho = dWrt1_dT * d2Constant1_drhodT + d2Wrt1_dT2 * dConstant1_drho - dWrt1_drho * d2Constant1_dT2 - d2Wrt1_drhodT * dConstant1_dT;
1051 dderiv1_drho = (D * dNdrho__T - N * dDdrho__T) / pow(D, 2);
1054 dderiv1_dT = (D * dNdT__rho - N * dDdT__rho) / pow(D, 2);
1057 second = (dderiv1_dT * dConstant2_drho - dderiv1_drho * dConstant2_dT) / (dWrt2_dT * dConstant2_drho - dWrt2_drho * dConstant2_dT);
1075 #include <catch2/catch_all.hpp>
1077 TEST_CASE(
"Check AbstractState",
"[AbstractState]") {
1078 SECTION(
"bad backend") {
1081 SECTION(
"good backend - bad fluid") {
1084 SECTION(
"good backend - helmholtz") {
1087 SECTION(
"good backend - incomp") {
1090 SECTION(
"good backend - REFPROP") {
1095 TEST_CASE(
"Check derivatives in first_partial_deriv",
"[derivs_in_first_partial_deriv]") {
1102 double dT = 1e-3, drho = 1;
1110 CoolPropDbl dP_dT_num = (WaterplusT->p() - WaterminusT->p()) / (2 * dT);
1111 CoolPropDbl dP_drho_num = (Waterplusrho->p() - Waterminusrho->p()) / (2 * drho);
1113 CoolPropDbl dHmolar_dT_num = (WaterplusT->hmolar() - WaterminusT->hmolar()) / (2 * dT);
1114 CoolPropDbl dHmolar_drho_num = (Waterplusrho->hmolar() - Waterminusrho->hmolar()) / (2 * drho);
1115 CoolPropDbl dHmass_dT_num = (WaterplusT->hmass() - WaterminusT->hmass()) / (2 * dT);
1116 CoolPropDbl dHmass_drho_num = (Waterplusrho->hmass() - Waterminusrho->hmass()) / (2 * drho);
1118 CoolPropDbl dSmolar_dT_num = (WaterplusT->smolar() - WaterminusT->smolar()) / (2 * dT);
1119 CoolPropDbl dSmolar_drho_num = (Waterplusrho->smolar() - Waterminusrho->smolar()) / (2 * drho);
1120 CoolPropDbl dSmass_dT_num = (WaterplusT->smass() - WaterminusT->smass()) / (2 * dT);
1121 CoolPropDbl dSmass_drho_num = (Waterplusrho->smass() - Waterminusrho->smass()) / (2 * drho);
1123 CoolPropDbl dUmolar_dT_num = (WaterplusT->umolar() - WaterminusT->umolar()) / (2 * dT);
1124 CoolPropDbl dUmolar_drho_num = (Waterplusrho->umolar() - Waterminusrho->umolar()) / (2 * drho);
1125 CoolPropDbl dUmass_dT_num = (WaterplusT->umass() - WaterminusT->umass()) / (2 * dT);
1126 CoolPropDbl dUmass_drho_num = (Waterplusrho->umass() - Waterminusrho->umass()) / (2 * drho);
1128 CoolPropDbl dGmolar_dT_num = (WaterplusT->gibbsmolar() - WaterminusT->gibbsmolar()) / (2 * dT);
1129 CoolPropDbl dGmolar_drho_num = (Waterplusrho->gibbsmolar() - Waterminusrho->gibbsmolar()) / (2 * drho);
1130 CoolPropDbl dGmass_dT_num = (WaterplusT->gibbsmass() - WaterminusT->gibbsmass()) / (2 * dT);
1131 CoolPropDbl dGmass_drho_num = (Waterplusrho->gibbsmass() - Waterminusrho->gibbsmass()) / (2 * drho);
1133 CoolPropDbl dCvmolar_dT_num = (WaterplusT->cvmolar() - WaterminusT->cvmolar()) / (2 * dT);
1134 CoolPropDbl dCvmolar_drho_num = (Waterplusrho->cvmolar() - Waterminusrho->cvmolar()) / (2 * drho);
1135 CoolPropDbl dCvmass_dT_num = (WaterplusT->cvmass() - WaterminusT->cvmass()) / (2 * dT);
1136 CoolPropDbl dCvmass_drho_num = (Waterplusrho->cvmass() - Waterminusrho->cvmass()) / (2 * drho);
1138 CoolPropDbl dCpmolar_dT_num = (WaterplusT->cpmolar() - WaterminusT->cpmolar()) / (2 * dT);
1139 CoolPropDbl dCpmolar_drho_num = (Waterplusrho->cpmolar() - Waterminusrho->cpmolar()) / (2 * drho);
1140 CoolPropDbl dCpmass_dT_num = (WaterplusT->cpmass() - WaterminusT->cpmass()) / (2 * dT);
1141 CoolPropDbl dCpmass_drho_num = (Waterplusrho->cpmass() - Waterminusrho->cpmass()) / (2 * drho);
1143 CoolPropDbl dspeed_sound_dT_num = (WaterplusT->speed_sound() - WaterminusT->speed_sound()) / (2 * dT);
1144 CoolPropDbl dspeed_sound_drho_num = (Waterplusrho->speed_sound() - Waterminusrho->speed_sound()) / (2 * drho);
1150 CoolPropDbl dHmolar_dT_analyt, dHmolar_drho_analyt;
1155 CoolPropDbl dSmolar_dT_analyt, dSmolar_drho_analyt;
1160 CoolPropDbl dUmolar_dT_analyt, dUmolar_drho_analyt;
1165 CoolPropDbl dGmolar_dT_analyt, dGmolar_drho_analyt;
1170 CoolPropDbl dCvmolar_dT_analyt, dCvmolar_drho_analyt;
1172 CoolPropDbl dCvmass_dT_analyt, dCvmass_drho_analyt;
1175 CoolPropDbl dCpmolar_dT_analyt, dCpmolar_drho_analyt;
1177 CoolPropDbl dCpmass_dT_analyt, dCpmass_drho_analyt;
1180 CoolPropDbl dspeed_sound_dT_analyt, dspeed_sound_drho_analyt;
1185 CHECK(std::abs(dP_dT_analyt / dP_dT_num - 1) < eps);
1186 CHECK(std::abs(dP_drho_analyt / dP_drho_num - 1) < eps);
1188 CHECK(std::abs(dHmolar_dT_analyt / dHmolar_dT_num - 1) < eps);
1189 CHECK(std::abs(dHmolar_drho_analyt / dHmolar_drho_num - 1) < eps);
1190 CHECK(std::abs(dHmass_dT_analyt / dHmass_dT_num - 1) < eps);
1191 CHECK(std::abs(dHmass_drho_analyt / dHmass_drho_num - 1) < eps);
1193 CHECK(std::abs(dSmolar_dT_analyt / dSmolar_dT_num - 1) < eps);
1194 CHECK(std::abs(dSmolar_drho_analyt / dSmolar_drho_num - 1) < eps);
1195 CHECK(std::abs(dSmass_dT_analyt / dSmass_dT_num - 1) < eps);
1196 CHECK(std::abs(dSmass_drho_analyt / dSmass_drho_num - 1) < eps);
1198 CHECK(std::abs(dUmolar_dT_analyt / dUmolar_dT_num - 1) < eps);
1199 CHECK(std::abs(dUmolar_drho_analyt / dUmolar_drho_num - 1) < eps);
1200 CHECK(std::abs(dUmass_dT_analyt / dUmass_dT_num - 1) < eps);
1201 CHECK(std::abs(dUmass_drho_analyt / dUmass_drho_num - 1) < eps);
1203 CHECK(std::abs(dGmolar_dT_analyt / dGmolar_dT_num - 1) < eps);
1204 CHECK(std::abs(dGmolar_drho_analyt / dGmolar_drho_num - 1) < eps);
1205 CHECK(std::abs(dGmass_dT_analyt / dGmass_dT_num - 1) < eps);
1206 CHECK(std::abs(dGmass_drho_analyt / dGmass_drho_num - 1) < eps);
1208 CHECK(std::abs(dCvmolar_dT_analyt / dCvmolar_dT_num - 1) < eps);
1209 CHECK(std::abs(dCvmolar_drho_analyt / dCvmolar_drho_num - 1) < eps);
1210 CHECK(std::abs(dCvmass_dT_analyt / dCvmass_dT_num - 1) < eps);
1211 CHECK(std::abs(dCvmass_drho_analyt / dCvmass_drho_num - 1) < eps);
1213 CHECK(std::abs(dCpmolar_dT_analyt / dCpmolar_dT_num - 1) < eps);
1214 CHECK(std::abs(dCpmolar_drho_analyt / dCpmolar_drho_num - 1) < eps);
1215 CHECK(std::abs(dCpmass_dT_analyt / dCpmass_dT_num - 1) < eps);
1216 CHECK(std::abs(dCpmass_drho_analyt / dCpmass_drho_num - 1) < eps);
1218 CHECK(std::abs(dspeed_sound_dT_analyt / dspeed_sound_dT_num - 1) < eps);
1219 CHECK(std::abs(dspeed_sound_drho_analyt / dspeed_sound_drho_num - 1) < eps);