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) {
747 R = AS.
gas_constant(), delta = rho / rhor, tau = Tr / T;
813 double dTau_dT = 1 / dT_dtau;
817 double dDelta_drho = 1 / rhor;
851 dT = R / T * pow(tau, 2)
860 dT -= ((R / rho * delta
868 drho = R / rho * delta
896 dT = 1.0 / 2.0 / w / T
900 - (2 * aa / bb * daa_dTau - pow(aa / bb, 2) * dbb_dTau)));
905 drho = R * T / 2.0 / AS.
molar_mass() / w / rhor
908 - (2 * aa / bb * daa_dDelta - pow(aa / bb, 2) * dbb_dDelta));
931 dT2 = 2 * Tr / pow(T, 3);
954 dT2 = R / T * pow(tau, 2)
958 drho_dT = R / rho * delta
1003 CoolPropDbl dOf_dT, dOf_drho, dWrt_dT, dWrt_drho, dConstant_dT, dConstant_drho;
1007 get_dT_drho(*
this, Constant, dConstant_dT, dConstant_drho);
1009 return (dOf_dT * dConstant_drho - dOf_drho * dConstant_dT) / (dWrt_dT * dConstant_drho - dWrt_drho * dConstant_dT);
1012 CoolPropDbl dOf1_dT, dOf1_drho, dWrt1_dT, dWrt1_drho, dConstant1_dT, dConstant1_drho, d2Of1_dT2, d2Of1_drhodT, d2Of1_drho2, d2Wrt1_dT2,
1013 d2Wrt1_drhodT, d2Wrt1_drho2, d2Constant1_dT2, d2Constant1_drhodT, d2Constant1_drho2, dWrt2_dT, dWrt2_drho, dConstant2_dT, dConstant2_drho, N, D,
1014 dNdrho__T, dDdrho__T, dNdT__rho, dDdT__rho, dderiv1_drho, dderiv1_dT, second;
1019 get_dT_drho(*
this, Constant1, dConstant1_dT, dConstant1_drho);
1026 get_dT_drho(*
this, Constant2, dConstant2_dT, dConstant2_drho);
1029 N = dOf1_dT * dConstant1_drho - dOf1_drho * dConstant1_dT;
1030 D = dWrt1_dT * dConstant1_drho - dWrt1_drho * dConstant1_dT;
1034 dNdrho__T = dOf1_dT * d2Constant1_drho2 + d2Of1_drhodT * dConstant1_drho - dOf1_drho * d2Constant1_drhodT - d2Of1_drho2 * dConstant1_dT;
1035 dDdrho__T = dWrt1_dT * d2Constant1_drho2 + d2Wrt1_drhodT * dConstant1_drho - dWrt1_drho * d2Constant1_drhodT - d2Wrt1_drho2 * dConstant1_dT;
1039 dNdT__rho = dOf1_dT * d2Constant1_drhodT + d2Of1_dT2 * dConstant1_drho - dOf1_drho * d2Constant1_dT2 - d2Of1_drhodT * dConstant1_dT;
1040 dDdT__rho = dWrt1_dT * d2Constant1_drhodT + d2Wrt1_dT2 * dConstant1_drho - dWrt1_drho * d2Constant1_dT2 - d2Wrt1_drhodT * dConstant1_dT;
1043 dderiv1_drho = (D * dNdrho__T - N * dDdrho__T) / pow(D, 2);
1046 dderiv1_dT = (D * dNdT__rho - N * dDdT__rho) / pow(D, 2);
1049 second = (dderiv1_dT * dConstant2_drho - dderiv1_drho * dConstant2_dT) / (dWrt2_dT * dConstant2_drho - dWrt2_drho * dConstant2_dT);
1067 #include <catch2/catch_all.hpp>
1069 TEST_CASE(
"Check AbstractState",
"[AbstractState]") {
1070 SECTION(
"bad backend") {
1073 SECTION(
"good backend - bad fluid") {
1076 SECTION(
"good backend - helmholtz") {
1079 SECTION(
"good backend - incomp") {
1082 SECTION(
"good backend - REFPROP") {
1087 TEST_CASE(
"Check derivatives in first_partial_deriv",
"[derivs_in_first_partial_deriv]") {
1094 double dT = 1e-3, drho = 1;
1102 CoolPropDbl dP_dT_num = (WaterplusT->p() - WaterminusT->p()) / (2 * dT);
1103 CoolPropDbl dP_drho_num = (Waterplusrho->p() - Waterminusrho->p()) / (2 * drho);
1105 CoolPropDbl dHmolar_dT_num = (WaterplusT->hmolar() - WaterminusT->hmolar()) / (2 * dT);
1106 CoolPropDbl dHmolar_drho_num = (Waterplusrho->hmolar() - Waterminusrho->hmolar()) / (2 * drho);
1107 CoolPropDbl dHmass_dT_num = (WaterplusT->hmass() - WaterminusT->hmass()) / (2 * dT);
1108 CoolPropDbl dHmass_drho_num = (Waterplusrho->hmass() - Waterminusrho->hmass()) / (2 * drho);
1110 CoolPropDbl dSmolar_dT_num = (WaterplusT->smolar() - WaterminusT->smolar()) / (2 * dT);
1111 CoolPropDbl dSmolar_drho_num = (Waterplusrho->smolar() - Waterminusrho->smolar()) / (2 * drho);
1112 CoolPropDbl dSmass_dT_num = (WaterplusT->smass() - WaterminusT->smass()) / (2 * dT);
1113 CoolPropDbl dSmass_drho_num = (Waterplusrho->smass() - Waterminusrho->smass()) / (2 * drho);
1115 CoolPropDbl dUmolar_dT_num = (WaterplusT->umolar() - WaterminusT->umolar()) / (2 * dT);
1116 CoolPropDbl dUmolar_drho_num = (Waterplusrho->umolar() - Waterminusrho->umolar()) / (2 * drho);
1117 CoolPropDbl dUmass_dT_num = (WaterplusT->umass() - WaterminusT->umass()) / (2 * dT);
1118 CoolPropDbl dUmass_drho_num = (Waterplusrho->umass() - Waterminusrho->umass()) / (2 * drho);
1120 CoolPropDbl dGmolar_dT_num = (WaterplusT->gibbsmolar() - WaterminusT->gibbsmolar()) / (2 * dT);
1121 CoolPropDbl dGmolar_drho_num = (Waterplusrho->gibbsmolar() - Waterminusrho->gibbsmolar()) / (2 * drho);
1122 CoolPropDbl dGmass_dT_num = (WaterplusT->gibbsmass() - WaterminusT->gibbsmass()) / (2 * dT);
1123 CoolPropDbl dGmass_drho_num = (Waterplusrho->gibbsmass() - Waterminusrho->gibbsmass()) / (2 * drho);
1125 CoolPropDbl dCvmolar_dT_num = (WaterplusT->cvmolar() - WaterminusT->cvmolar()) / (2 * dT);
1126 CoolPropDbl dCvmolar_drho_num = (Waterplusrho->cvmolar() - Waterminusrho->cvmolar()) / (2 * drho);
1127 CoolPropDbl dCvmass_dT_num = (WaterplusT->cvmass() - WaterminusT->cvmass()) / (2 * dT);
1128 CoolPropDbl dCvmass_drho_num = (Waterplusrho->cvmass() - Waterminusrho->cvmass()) / (2 * drho);
1130 CoolPropDbl dCpmolar_dT_num = (WaterplusT->cpmolar() - WaterminusT->cpmolar()) / (2 * dT);
1131 CoolPropDbl dCpmolar_drho_num = (Waterplusrho->cpmolar() - Waterminusrho->cpmolar()) / (2 * drho);
1132 CoolPropDbl dCpmass_dT_num = (WaterplusT->cpmass() - WaterminusT->cpmass()) / (2 * dT);
1133 CoolPropDbl dCpmass_drho_num = (Waterplusrho->cpmass() - Waterminusrho->cpmass()) / (2 * drho);
1135 CoolPropDbl dspeed_sound_dT_num = (WaterplusT->speed_sound() - WaterminusT->speed_sound()) / (2 * dT);
1136 CoolPropDbl dspeed_sound_drho_num = (Waterplusrho->speed_sound() - Waterminusrho->speed_sound()) / (2 * drho);
1142 CoolPropDbl dHmolar_dT_analyt, dHmolar_drho_analyt;
1147 CoolPropDbl dSmolar_dT_analyt, dSmolar_drho_analyt;
1152 CoolPropDbl dUmolar_dT_analyt, dUmolar_drho_analyt;
1157 CoolPropDbl dGmolar_dT_analyt, dGmolar_drho_analyt;
1162 CoolPropDbl dCvmolar_dT_analyt, dCvmolar_drho_analyt;
1164 CoolPropDbl dCvmass_dT_analyt, dCvmass_drho_analyt;
1167 CoolPropDbl dCpmolar_dT_analyt, dCpmolar_drho_analyt;
1169 CoolPropDbl dCpmass_dT_analyt, dCpmass_drho_analyt;
1172 CoolPropDbl dspeed_sound_dT_analyt, dspeed_sound_drho_analyt;
1177 CHECK(std::abs(dP_dT_analyt / dP_dT_num - 1) < eps);
1178 CHECK(std::abs(dP_drho_analyt / dP_drho_num - 1) < eps);
1180 CHECK(std::abs(dHmolar_dT_analyt / dHmolar_dT_num - 1) < eps);
1181 CHECK(std::abs(dHmolar_drho_analyt / dHmolar_drho_num - 1) < eps);
1182 CHECK(std::abs(dHmass_dT_analyt / dHmass_dT_num - 1) < eps);
1183 CHECK(std::abs(dHmass_drho_analyt / dHmass_drho_num - 1) < eps);
1185 CHECK(std::abs(dSmolar_dT_analyt / dSmolar_dT_num - 1) < eps);
1186 CHECK(std::abs(dSmolar_drho_analyt / dSmolar_drho_num - 1) < eps);
1187 CHECK(std::abs(dSmass_dT_analyt / dSmass_dT_num - 1) < eps);
1188 CHECK(std::abs(dSmass_drho_analyt / dSmass_drho_num - 1) < eps);
1190 CHECK(std::abs(dUmolar_dT_analyt / dUmolar_dT_num - 1) < eps);
1191 CHECK(std::abs(dUmolar_drho_analyt / dUmolar_drho_num - 1) < eps);
1192 CHECK(std::abs(dUmass_dT_analyt / dUmass_dT_num - 1) < eps);
1193 CHECK(std::abs(dUmass_drho_analyt / dUmass_drho_num - 1) < eps);
1195 CHECK(std::abs(dGmolar_dT_analyt / dGmolar_dT_num - 1) < eps);
1196 CHECK(std::abs(dGmolar_drho_analyt / dGmolar_drho_num - 1) < eps);
1197 CHECK(std::abs(dGmass_dT_analyt / dGmass_dT_num - 1) < eps);
1198 CHECK(std::abs(dGmass_drho_analyt / dGmass_drho_num - 1) < eps);
1200 CHECK(std::abs(dCvmolar_dT_analyt / dCvmolar_dT_num - 1) < eps);
1201 CHECK(std::abs(dCvmolar_drho_analyt / dCvmolar_drho_num - 1) < eps);
1202 CHECK(std::abs(dCvmass_dT_analyt / dCvmass_dT_num - 1) < eps);
1203 CHECK(std::abs(dCvmass_drho_analyt / dCvmass_drho_num - 1) < eps);
1205 CHECK(std::abs(dCpmolar_dT_analyt / dCpmolar_dT_num - 1) < eps);
1206 CHECK(std::abs(dCpmolar_drho_analyt / dCpmolar_drho_num - 1) < eps);
1207 CHECK(std::abs(dCpmass_dT_analyt / dCpmass_dT_num - 1) < eps);
1208 CHECK(std::abs(dCpmass_drho_analyt / dCpmass_drho_num - 1) < eps);
1210 CHECK(std::abs(dspeed_sound_dT_analyt / dspeed_sound_dT_num - 1) < eps);
1211 CHECK(std::abs(dspeed_sound_drho_analyt / dspeed_sound_drho_num - 1) < eps);