33 std::map<std::size_t, CoolPropFluid> fluid_map;
35 std::map<std::size_t, std::string> JSONstring_map;
36 std::vector<std::string> name_vector;
37 std::map<std::string, std::size_t> string_to_index_map;
45 for (
const auto& contribution : jsonalphar) {
49 if (!type.compare(
"ResidualHelmholtzPower")) {
54 assert(n.size() == d.size());
55 assert(n.size() == t.size());
56 assert(n.size() == l.size());
59 }
else if (!type.compare(
"ResidualHelmholtzGaussian")) {
67 assert(n.size() == d.size());
68 assert(n.size() == t.size());
69 assert(n.size() == eta.size());
70 assert(n.size() == epsilon.size());
71 assert(n.size() == beta.size());
72 assert(n.size() == gamma.size());
74 }
else if (!type.compare(
"ResidualHelmholtzGaoB")) {
83 assert(n.size() == t.size());
84 assert(n.size() == d.size());
85 assert(n.size() == eta.size());
86 assert(n.size() == epsilon.size());
87 assert(n.size() == beta.size());
88 assert(n.size() == gamma.size());
89 assert(n.size() == b.size());
91 }
else if (!type.compare(
"ResidualHelmholtzNonAnalytic")) {
103 assert(n.size() == a.size());
104 assert(n.size() == b.size());
105 assert(n.size() == beta.size());
106 assert(n.size() == A.size());
107 assert(n.size() == B.size());
108 assert(n.size() == C.size());
109 assert(n.size() == D.size());
111 }
else if (!type.compare(
"ResidualHelmholtzLemmon2005")) {
117 assert(n.size() == d.size());
118 assert(n.size() == t.size());
119 assert(n.size() == l.size());
120 assert(n.size() == m.size());
122 }
else if (!type.compare(
"ResidualHelmholtzDoubleExponential")) {
131 assert(n.size() == d.size());
132 assert(n.size() == t.size());
133 assert(n.size() == gt.size());
134 assert(n.size() == lt.size());
135 assert(n.size() == gd.size());
136 assert(n.size() == ld.size());
138 }
else if (!type.compare(
"ResidualHelmholtzExponential")) {
144 assert(n.size() == d.size());
145 assert(n.size() == t.size());
146 assert(n.size() == g.size());
147 assert(n.size() == l.size());
149 }
else if (!type.compare(
"ResidualHelmholtzAssociating")) {
160 throw ValueError(
format(
"Unsupported Residual helmholtz type: %s", type.c_str()));
172 if (!jsonalpha0.is_array()) {
178 for (
const auto& contribution : jsonalpha0) {
182 if (!type.compare(
"IdealGasHelmholtzLead")) {
190 }
else if (!type.compare(
"IdealGasHelmholtzPower")) {
198 }
else if (!type.compare(
"IdealGasHelmholtzLogTau")) {
205 }
else if (!type.compare(
"IdealGasHelmholtzPlanckEinsteinGeneralized")) {
218 }
else if (!type.compare(
"IdealGasHelmholtzPlanckEinstein")) {
226 std::vector<CoolPropDbl> c(n.size(), 1);
227 std::vector<CoolPropDbl> d(c.size(), -1);
234 }
else if (!type.compare(
"IdealGasHelmholtzPlanckEinsteinFunctionT")) {
240 for (std::size_t i = 0; i < v.size(); ++i) {
241 theta[i] = -v[i] / Tc;
243 std::vector<CoolPropDbl> c(n.size(), 1);
244 std::vector<CoolPropDbl> d(c.size(), -1);
251 }
else if (!type.compare(
"IdealGasHelmholtzGERG2004Cosh")) {
261 }
else if (!type.compare(
"IdealGasHelmholtzGERG2004Sinh")) {
271 }
else if (!type.compare(
"IdealGasHelmholtzCP0Constant")) {
273 throw ValueError(
"Cannot add another IdealGasHelmholtzCP0Constant term; join them together");
279 }
else if (!type.compare(
"IdealGasHelmholtzCP0PolyT")) {
281 throw ValueError(
"Cannot add another CP0PolyT term; join them together");
288 }
else if (!type.compare(
"IdealGasHelmholtzCP0AlyLee")) {
295 if (std::abs(constants[0]) > 1e-14) {
296 std::vector<CoolPropDbl> c(1, constants[0]), t(1, 0);
303 std::vector<CoolPropDbl> n, c, d, t;
304 if (std::abs(constants[1]) > 1e-14) {
306 n.push_back(constants[1]);
307 t.push_back(-2 * constants[2] / Tc);
311 if (std::abs(constants[3]) > 1e-14) {
313 n.push_back(-constants[3]);
314 t.push_back(-2 * constants[4] / Tc);
323 }
else if (!type.compare(
"IdealGasHelmholtzEnthalpyEntropyOffset")) {
329 std::cout <<
format(
"Unsupported ideal-gas Helmholtz type: %s\n", type.c_str());
365 const nlohmann::json& reducing_state = EOS_json.at(
"STATES").at(
"reducing");
366 const nlohmann::json& satminL_state = EOS_json.at(
"STATES").at(
"sat_min_liquid");
367 const nlohmann::json& satminV_state = EOS_json.at(
"STATES").at(
"sat_min_vapor");
392 if (EOS_json.contains(
"SUPERANCILLARY")) {
393 if (getenv(
"COOLPROP_DISABLE_SUPERANCILLARIES_ENTIRELY")) {
403 if (EOS_json.contains(
"alpha0_prefactor")) {
406 if (EOS_json.at(
"STATES").contains(
"hs_anchor")) {
407 const nlohmann::json& hs_anchor = EOS_json.at(
"STATES").at(
"hs_anchor");
415 if (EOS_json.at(
"STATES").contains(
"pressure_max_sat")) {
416 const nlohmann::json& s = EOS_json.at(
"STATES").at(
"pressure_max_sat");
420 if (s.contains(
"hmolar")) {
426 if (EOS_json.at(
"STATES").contains(
"temperature_max_sat")) {
427 const nlohmann::json& s = EOS_json.at(
"STATES").at(
"temperature_max_sat");
431 if (s.contains(
"hmolar")) {
437 if (EOS_json.contains(
"critical_region_splines")) {
438 const nlohmann::json& spline = EOS_json.at(
"critical_region_splines");
454 for (
const auto& EOS_json : EOS_array) {
461 if (dilute.contains(
"hardcoded")) {
463 if (!target.compare(
"Ethane")) {
466 }
else if (!target.compare(
"Cyclohexane")) {
469 }
else if (!target.compare(
"CarbonDioxideLaeseckeJPCRD2017")) {
473 throw ValueError(
format(
"hardcoded dilute viscosity [%s] is not understood for fluid %s", target.c_str(), fluid.
name.c_str()));
477 if (!type.compare(
"collision_integral")) {
489 }
else if (!type.compare(
"kinetic_theory")) {
491 }
else if (!type.compare(
"powers_of_T")) {
500 }
else if (!type.compare(
"powers_of_Tr")) {
508 }
else if (!type.compare(
"collision_integral_powers_of_Tstar")) {
520 throw ValueError(
format(
"type [%s] is not understood for fluid %s", type.c_str(), fluid.
name.c_str()));
527 if (!type.compare(
"Rainwater-Friend")) {
537 }
else if (!type.compare(
"empirical")) {
551 throw ValueError(
format(
"type [%s] is not understood for fluid %s", type.c_str(), fluid.
name.c_str()));
558 if (higher.contains(
"hardcoded")) {
560 if (!target.compare(
"Hydrogen")) {
563 }
else if (!target.compare(
"n-Hexane")) {
566 }
else if (!target.compare(
"n-Heptane")) {
569 }
else if (!target.compare(
"Toluene")) {
572 }
else if (!target.compare(
"Ethane")) {
575 }
else if (!target.compare(
"Benzene")) {
578 }
else if (!target.compare(
"CarbonDioxideLaeseckeJPCRD2017")) {
583 format(
"hardcoded higher order viscosity term [%s] is not understood for fluid %s", target.c_str(), fluid.
name.c_str()));
588 if (!type.compare(
"modified_Batschinski_Hildebrand")) {
603 assert(BH.
a.size() == BH.
t1.size());
604 assert(BH.
a.size() == BH.
d1.size());
605 assert(BH.
a.size() == BH.
gamma.size());
606 assert(BH.
a.size() == BH.
l.size());
610 assert(BH.
f.size() == BH.
t2.size());
611 assert(BH.
f.size() == BH.
d2.size());
614 assert(BH.
g.size() == BH.
h.size());
617 assert(BH.
p.size() == BH.
q.size());
618 }
else if (!type.compare(
"friction_theory")) {
637 assert(F.
Aa.size() == 3);
638 assert(F.
Aaa.size() == 3);
639 assert(F.
Ar.size() == 3);
643 if (higher.contains(
"Arr") && !higher.contains(
"Adrdr")) {
645 assert(F.
Arr.size() == 3);
646 }
else if (higher.contains(
"Adrdr") && !higher.contains(
"Arr")) {
648 assert(F.
Adrdr.size() == 3);
650 throw ValueError(
format(
"can only provide one of Arr or Adrdr for fluid %s", fluid.
name.c_str()));
652 if (higher.contains(
"Aii")) {
656 if (higher.contains(
"Aaaa") && higher.contains(
"Arrr")) {
664 throw ValueError(
format(
"type [%s] is not understood for fluid %s", type.c_str(), fluid.
name.c_str()));
715 if (viscosity.is_array()) {
724 if (!viscosity.contains(
"sigma_eta") || !viscosity.contains(
"epsilon_over_k")) {
732 if (viscosity.contains(
"type") && !
cpjson::get_string(viscosity,
"type").compare(
"ECS")) {
738 if (viscosity.contains(
"type") && !
cpjson::get_string(viscosity,
"type").compare(
"rhosr-CS")) {
745 if (viscosity.contains(
"type") && !
cpjson::get_string(viscosity,
"type").compare(
"Chung")) {
750 if (viscosity.contains(
"hardcoded")) {
752 if (!target.compare(
"Water")) {
755 }
else if (!target.compare(
"HeavyWater")) {
758 }
else if (!target.compare(
"Helium")) {
761 }
else if (!target.compare(
"R23")) {
764 }
else if (!target.compare(
"Methanol")) {
767 }
else if (!target.compare(
"m-Xylene")) {
770 }
else if (!target.compare(
"o-Xylene")) {
773 }
else if (!target.compare(
"p-Xylene")) {
777 throw ValueError(
format(
"hardcoded viscosity [%s] is not understood for fluid %s", target.c_str(), fluid.
name.c_str()));
782 if (viscosity.contains(
"dilute")) {
786 if (viscosity.contains(
"initial_density")) {
790 if (viscosity.contains(
"higher_order")) {
797 if (dilute.contains(
"hardcoded")) {
799 if (!target.compare(
"CO2")) {
802 }
else if (!target.compare(
"CarbonDioxideHuberJPCRD2016")) {
805 }
else if (!target.compare(
"Ethane")) {
808 }
else if (!target.compare(
"none")) {
813 format(
"hardcoded dilute conductivity term [%s] is not understood for fluid %s", target.c_str(), fluid.
name.c_str()));
817 if (!type.compare(
"ratio_of_polynomials")) {
830 }
else if (!type.compare(
"eta0_and_poly")) {
841 throw ValueError(
format(
"type [%s] is not understood for fluid %s", type.c_str(), fluid.
name.c_str()));
847 if (dilute.contains(
"hardcoded")) {
849 if (!target.compare(
"CO2")) {
854 format(
"hardcoded residual conductivity term [%s] is not understood for fluid %s", target.c_str(), fluid.
name.c_str()));
858 if (!type.compare(
"polynomial")) {
871 }
else if (!type.compare(
"polynomial_and_exponential")) {
885 throw ValueError(
format(
"type [%s] is not understood for fluid %s", type.c_str(), fluid.
name.c_str()));
890 if (critical.contains(
"hardcoded")) {
892 if (!target.compare(
"R123")) {
895 }
else if (!target.compare(
"Ammonia")) {
898 }
else if (!target.compare(
"CarbonDioxideScalabrinJPCRD2006")) {
902 }
else if (!target.compare(
"None")) {
906 throw ValueError(
format(
"critical conductivity term [%s] is not understood for fluid %s", target.c_str(), fluid.
name.c_str()));
910 if (!type.compare(
"simplified_Olchowy_Sengers")) {
918 if (critical.contains(
"qD")) {
921 if (critical.contains(
"zeta0")) {
924 if (critical.contains(
"GAMMA")) {
927 if (critical.contains(
"gamma")) {
930 if (critical.contains(
"R0")) {
933 if (critical.contains(
"T_ref")) {
937 throw ValueError(
format(
"type [%s] is not understood for fluid %s", type.c_str(), fluid.
name.c_str()));
947 if (conductivity.contains(
"type") && !
cpjson::get_string(conductivity,
"type").compare(
"ECS")) {
952 if (conductivity.contains(
"hardcoded")) {
954 if (!target.compare(
"Water")) {
957 }
else if (!target.compare(
"HeavyWater")) {
960 }
else if (!target.compare(
"Methane")) {
963 }
else if (!target.compare(
"R23")) {
966 }
else if (!target.compare(
"Helium")) {
971 format(
"hardcoded residual conductivity term [%s] is not understood for fluid %s", target.c_str(), fluid.
name.c_str()));
976 if (conductivity.contains(
"dilute")) {
980 if (conductivity.contains(
"residual")) {
984 if (conductivity.contains(
"critical")) {
993 if (transport.contains(
"viscosity")) {
999 if (transport.contains(
"conductivity")) {
1019 if (melting_line.contains(
"type")) {
1021 if (!type.compare(
"Simon")) {
1022 const nlohmann::json& parts = melting_line.at(
"parts");
1024 for (
const auto& part : parts) {
1034 }
else if (!type.compare(
"polynomial_in_Tr")) {
1035 const nlohmann::json& parts = melting_line.at(
"parts");
1037 for (
const auto& part : parts) {
1047 }
else if (!type.compare(
"polynomial_in_Theta")) {
1048 const nlohmann::json& parts = melting_line.at(
"parts");
1050 for (
const auto& part : parts) {
1061 throw ValueError(
format(
"melting line type [%s] is not understood for fluid %s", type.c_str(), fluid.
name.c_str()));
1066 throw ValueError(
format(
"melting line does not have \"type\" for fluid %s", fluid.
name.c_str()));
1072 if (!states.contains(
"critical")) {
1073 throw ValueError(
format(R
"(fluid["STATES"] [%s] does not have "critical" member)", fluid.name.c_str()));
1075 const nlohmann::json& crit = states.at(
"critical");
1082 if (!states.contains(
"triple_liquid")) {
1083 throw ValueError(
format(R
"(fluid["STATES"] [%s] does not have "triple_liquid" member)", fluid.name.c_str()));
1085 const nlohmann::json& triple_liquid = states.at(
"triple_liquid");
1086 if (triple_liquid.empty()) {
1101 if (!states.contains(
"triple_vapor")) {
1102 throw ValueError(
format(R
"(fluid["STATES"] [%s] does not have "triple_vapor" member)", fluid.name.c_str()));
1104 const nlohmann::json& triple_vapor = states.at(
"triple_vapor");
1105 if (triple_vapor.empty()) {
1123 if (!ancillaries.contains(
"rhoL") || !ancillaries.contains(
"rhoV")) {
1124 throw ValueError(
"Ancillary curves for either rhoL or rhoV are missing");
1130 if (ancillaries.contains(
"pL") && ancillaries.contains(
"pV")) {
1135 else if (!ancillaries.contains(
"pL") && !ancillaries.contains(
"pV") && ancillaries.contains(
"pS")) {
1139 throw ValueError(
"Pressure ancillary curves are missing or invalid");
1142 if (ancillaries.contains(
"hL")) {
1146 std::cout <<
"Missing hL ancillary for fluid " << fluid.
name;
1149 if (ancillaries.contains(
"hLV")) {
1153 std::cout <<
"Missing hLV ancillary for fluid " << fluid.
name;
1157 if (ancillaries.contains(
"sL")) {
1161 std::cout <<
"Missing sL ancillary for fluid " << fluid.
name;
1164 if (ancillaries.contains(
"sLV")) {
1168 std::cout <<
"Missing sLV ancillary for fluid " << fluid.
name;
1172 std::cout <<
"Tmin invalid for sL for " << fluid.
name <<
'\n';
1184 assert(fluid.
CAS.length() > 0);
1185 assert(fluid.
name.length() > 0);
1199 static void add_many(
const std::string& JSON_string);
1202 void add_many(
const nlohmann::json& listing);
1204 void add_one(
const nlohmann::json& fluid_json);
1208 auto it = string_to_index_map.find(key);
1209 if (it != string_to_index_map.end()) {
1211 auto it2 = JSONstring_map.find(it->second);
1212 if (it2 != JSONstring_map.end()) {
1214 nlohmann::json doc2 = nlohmann::json::array();
1218 throw ValueError(
format(
"Unable to obtain JSON string for this identifier [%d]", it->second));
1221 throw ValueError(
format(
"Unable to obtain index for this identifier [%s]", key.c_str()));
1231 auto it = string_to_index_map.find(key);
1233 if (it != string_to_index_map.end()) {
1234 return get(it->second);
1237 std::vector<std::string>
endings;
1239 endings.emplace_back(
"-PengRobinson");
1240 for (
const auto& ending :
endings) {
1242 std::string used_name = key.substr(0, key.size() - ending.size());
1243 it = string_to_index_map.find(used_name);
1244 if (it != string_to_index_map.end()) {
1251 fluid.
EOSVector[0].alphar.empty_the_EOS();
1259 shared_ptr<AbstractCubic> ac;
1260 if (ending ==
"-SRK") {
1261 ac = std::make_shared<SRK>(Tc, pc, acentric, R);
1262 }
else if (ending ==
"-PengRobinson") {
1263 ac = std::make_shared<PengRobinson>(Tc, pc, acentric, R);
1268 ac->set_rhor(rhomolarc);
1275 shared_ptr<AbstractCubic> ac;
1276 if (ending ==
"-SRK") {
1278 }
else if (ending ==
"-PengRobinson") {
1283 ac->set_Tr(vals.
Tc);
1288 double v_c_Lmol = 2.14107171795 * (vals.
Tc / vals.
pc * 1000) + 0.00773144012514;
1289 ac->set_rhor(1 / (v_c_Lmol / 1000.0));
1293 ac->set_C_Twu(0, c[0], c[1], c[2]);
1315 throw ValueError(
format(
"key [%s] was not found in string_to_index_map in JSONFluidLibrary", key.c_str()));
1325 auto it = fluid_map.find(key);
1327 if (it != fluid_map.end()) {
1330 throw ValueError(
format(
"key [%d] was not found in JSONFluidLibrary", key));
1347CoolPropFluid
get_fluid(
const std::string& fluid_string);