30 std::map<std::size_t, CoolPropFluid> fluid_map;
32 std::map<std::size_t, std::string> JSONstring_map;
33 std::vector<std::string> name_vector;
34 std::map<std::string, std::size_t> string_to_index_map;
42 for (rapidjson::Value::ValueIterator itr = jsonalphar.Begin(); itr != jsonalphar.End(); ++itr) {
44 rapidjson::Value& contribution = *itr;
47 std::string type = contribution[
"type"].GetString();
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.IsArray()) {
178 for (rapidjson::Value::ConstValueIterator itr = jsonalpha0.Begin(); itr != jsonalpha0.End(); ++itr) {
180 const rapidjson::Value& contribution = *itr;
183 std::string type = contribution[
"type"].GetString();
185 if (!type.compare(
"IdealGasHelmholtzLead")) {
193 }
else if (!type.compare(
"IdealGasHelmholtzPower")) {
201 }
else if (!type.compare(
"IdealGasHelmholtzLogTau")) {
208 }
else if (!type.compare(
"IdealGasHelmholtzPlanckEinsteinGeneralized")) {
221 }
else if (!type.compare(
"IdealGasHelmholtzPlanckEinstein")) {
226 for (std::size_t i = 0; i < t.size(); ++i) {
229 std::vector<CoolPropDbl> c(n.size(), 1);
230 std::vector<CoolPropDbl> d(c.size(), -1);
237 }
else if (!type.compare(
"IdealGasHelmholtzPlanckEinsteinFunctionT")) {
243 for (std::size_t i = 0; i < v.size(); ++i) {
244 theta[i] = -v[i] / Tc;
246 std::vector<CoolPropDbl> c(n.size(), 1);
247 std::vector<CoolPropDbl> d(c.size(), -1);
254 }
else if (!type.compare(
"IdealGasHelmholtzGERG2004Cosh")) {
264 }
else if (!type.compare(
"IdealGasHelmholtzGERG2004Sinh")) {
274 }
else if (!type.compare(
"IdealGasHelmholtzCP0Constant")) {
276 throw ValueError(
"Cannot add another IdealGasHelmholtzCP0Constant term; join them together");
282 }
else if (!type.compare(
"IdealGasHelmholtzCP0PolyT")) {
284 throw ValueError(
"Cannot add another CP0PolyT term; join them together");
291 }
else if (!type.compare(
"IdealGasHelmholtzCP0AlyLee")) {
298 if (std::abs(constants[0]) > 1e-14) {
299 std::vector<CoolPropDbl> c(1, constants[0]), t(1, 0);
306 std::vector<CoolPropDbl> n, c, d, t;
307 if (std::abs(constants[1]) > 1e-14) {
309 n.push_back(constants[1]);
310 t.push_back(-2 * constants[2] / Tc);
314 if (std::abs(constants[3]) > 1e-14) {
316 n.push_back(-constants[3]);
317 t.push_back(-2 * constants[4] / Tc);
326 }
else if (!type.compare(
"IdealGasHelmholtzEnthalpyEntropyOffset")) {
332 std::cout <<
format(
"Unsupported ideal-gas Helmholtz type: %s\n", type.c_str());
368 rapidjson::Value& reducing_state = EOS_json[
"STATES"][
"reducing"];
369 rapidjson::Value& satminL_state = EOS_json[
"STATES"][
"sat_min_liquid"];
370 rapidjson::Value& satminV_state = EOS_json[
"STATES"][
"sat_min_vapor"];
395 if (EOS_json.HasMember(
"SUPERANCILLARY")){
396 if (getenv(
"COOLPROP_DISABLE_SUPERANCILLARIES_ENTIRELY")){
409 if (EOS_json.HasMember(
"alpha0_prefactor")) {
412 if (EOS_json[
"STATES"].HasMember(
"hs_anchor")) {
413 rapidjson::Value& hs_anchor = EOS_json[
"STATES"][
"hs_anchor"];
421 if (EOS_json[
"STATES"].HasMember(
"pressure_max_sat")) {
422 rapidjson::Value& s = EOS_json[
"STATES"][
"pressure_max_sat"];
426 if (s.HasMember(
"hmolar")) {
432 if (EOS_json[
"STATES"].HasMember(
"temperature_max_sat")) {
433 rapidjson::Value& s = EOS_json[
"STATES"][
"temperature_max_sat"];
437 if (s.HasMember(
"hmolar")) {
443 if (EOS_json.HasMember(
"critical_region_splines")) {
444 rapidjson::Value& spline = EOS_json[
"critical_region_splines"];
460 for (rapidjson::Value::ValueIterator itr = EOS_array.Begin(); itr != EOS_array.End(); ++itr) {
467 if (dilute.HasMember(
"hardcoded")) {
469 if (!target.compare(
"Ethane")) {
472 }
else if (!target.compare(
"Cyclohexane")) {
475 }
else if (!target.compare(
"CarbonDioxideLaeseckeJPCRD2017")) {
479 throw ValueError(
format(
"hardcoded dilute viscosity [%s] is not understood for fluid %s", target.c_str(), fluid.
name.c_str()));
483 if (!type.compare(
"collision_integral")) {
495 }
else if (!type.compare(
"kinetic_theory")) {
497 }
else if (!type.compare(
"powers_of_T")) {
506 }
else if (!type.compare(
"powers_of_Tr")) {
514 }
else if (!type.compare(
"collision_integral_powers_of_Tstar")) {
526 throw ValueError(
format(
"type [%s] is not understood for fluid %s", type.c_str(), fluid.
name.c_str()));
533 if (!type.compare(
"Rainwater-Friend")) {
543 }
else if (!type.compare(
"empirical")) {
557 throw ValueError(
format(
"type [%s] is not understood for fluid %s", type.c_str(), fluid.
name.c_str()));
564 if (higher.HasMember(
"hardcoded")) {
566 if (!target.compare(
"Hydrogen")) {
569 }
else if (!target.compare(
"n-Hexane")) {
572 }
else if (!target.compare(
"n-Heptane")) {
575 }
else if (!target.compare(
"Toluene")) {
578 }
else if (!target.compare(
"Ethane")) {
581 }
else if (!target.compare(
"Benzene")) {
584 }
else if (!target.compare(
"CarbonDioxideLaeseckeJPCRD2017")) {
589 format(
"hardcoded higher order viscosity term [%s] is not understood for fluid %s", target.c_str(), fluid.
name.c_str()));
594 if (!type.compare(
"modified_Batschinski_Hildebrand")) {
609 assert(BH.
a.size() == BH.
t1.size());
610 assert(BH.
a.size() == BH.
d1.size());
611 assert(BH.
a.size() == BH.
gamma.size());
612 assert(BH.
a.size() == BH.
l.size());
616 assert(BH.
f.size() == BH.
t2.size());
617 assert(BH.
f.size() == BH.
d2.size());
620 assert(BH.
g.size() == BH.
h.size());
623 assert(BH.
p.size() == BH.
q.size());
624 }
else if (!type.compare(
"friction_theory")) {
643 assert(F.
Aa.size() == 3);
644 assert(F.
Aaa.size() == 3);
645 assert(F.
Ar.size() == 3);
649 if (higher.HasMember(
"Arr") && !higher.HasMember(
"Adrdr")) {
651 assert(F.
Arr.size() == 3);
652 }
else if (higher.HasMember(
"Adrdr") && !higher.HasMember(
"Arr")) {
654 assert(F.
Adrdr.size() == 3);
656 throw ValueError(
format(
"can only provide one of Arr or Adrdr for fluid %s", fluid.
name.c_str()));
658 if (higher.HasMember(
"Aii")) {
662 if (higher.HasMember(
"Aaaa") && higher.HasMember(
"Arrr")) {
670 throw ValueError(
format(
"type [%s] is not understood for fluid %s", type.c_str(), fluid.
name.c_str()));
721 if (viscosity.IsArray()) {
722 rapidjson::Value::ValueIterator itr = viscosity.Begin();
731 if (!viscosity.HasMember(
"sigma_eta") || !viscosity.HasMember(
"epsilon_over_k")) {
739 if (viscosity.HasMember(
"type") && !
cpjson::get_string(viscosity,
"type").compare(
"ECS")) {
745 if (viscosity.HasMember(
"type") && !
cpjson::get_string(viscosity,
"type").compare(
"rhosr-CS")) {
752 if (viscosity.HasMember(
"type") && !
cpjson::get_string(viscosity,
"type").compare(
"Chung")) {
757 if (viscosity.HasMember(
"hardcoded")) {
759 if (!target.compare(
"Water")) {
762 }
else if (!target.compare(
"HeavyWater")) {
765 }
else if (!target.compare(
"Helium")) {
768 }
else if (!target.compare(
"R23")) {
771 }
else if (!target.compare(
"Methanol")) {
774 }
else if (!target.compare(
"m-Xylene")) {
777 }
else if (!target.compare(
"o-Xylene")) {
780 }
else if (!target.compare(
"p-Xylene")) {
784 throw ValueError(
format(
"hardcoded viscosity [%s] is not understood for fluid %s", target.c_str(), fluid.
name.c_str()));
789 if (viscosity.HasMember(
"dilute")) {
793 if (viscosity.HasMember(
"initial_density")) {
797 if (viscosity.HasMember(
"higher_order")) {
804 if (dilute.HasMember(
"hardcoded")) {
806 if (!target.compare(
"CO2")) {
810 else if (!target.compare(
"CarbonDioxideHuberJPCRD2016")) {
813 }
else if (!target.compare(
"Ethane")) {
816 }
else if (!target.compare(
"none")) {
821 format(
"hardcoded dilute conductivity term [%s] is not understood for fluid %s", target.c_str(), fluid.
name.c_str()));
825 if (!type.compare(
"ratio_of_polynomials")) {
838 }
else if (!type.compare(
"eta0_and_poly")) {
849 throw ValueError(
format(
"type [%s] is not understood for fluid %s", type.c_str(), fluid.
name.c_str()));
855 if (dilute.HasMember(
"hardcoded")) {
857 if (!target.compare(
"CO2")) {
862 format(
"hardcoded residual conductivity term [%s] is not understood for fluid %s", target.c_str(), fluid.
name.c_str()));
866 if (!type.compare(
"polynomial")) {
879 }
else if (!type.compare(
"polynomial_and_exponential")) {
893 throw ValueError(
format(
"type [%s] is not understood for fluid %s", type.c_str(), fluid.
name.c_str()));
898 if (critical.HasMember(
"hardcoded")) {
900 if (!target.compare(
"R123")) {
903 }
else if (!target.compare(
"Ammonia")) {
906 }
else if (!target.compare(
"CarbonDioxideScalabrinJPCRD2006")) {
910 }
else if (!target.compare(
"None")) {
914 throw ValueError(
format(
"critical conductivity term [%s] is not understood for fluid %s", target.c_str(), fluid.
name.c_str()));
918 if (!type.compare(
"simplified_Olchowy_Sengers")) {
926 if (critical.HasMember(
"qD")) {
929 if (critical.HasMember(
"zeta0")) {
932 if (critical.HasMember(
"GAMMA")) {
935 if (critical.HasMember(
"gamma")) {
938 if (critical.HasMember(
"R0")) {
941 if (critical.HasMember(
"T_ref")) {
945 throw ValueError(
format(
"type [%s] is not understood for fluid %s", type.c_str(), fluid.
name.c_str()));
955 if (conductivity.HasMember(
"type") && !
cpjson::get_string(conductivity,
"type").compare(
"ECS")) {
960 if (conductivity.HasMember(
"hardcoded")) {
962 if (!target.compare(
"Water")) {
965 }
else if (!target.compare(
"HeavyWater")) {
968 }
else if (!target.compare(
"Methane")) {
971 }
else if (!target.compare(
"R23")) {
974 }
else if (!target.compare(
"Helium")) {
979 format(
"hardcoded residual conductivity term [%s] is not understood for fluid %s", target.c_str(), fluid.
name.c_str()));
984 if (conductivity.HasMember(
"dilute")) {
988 if (conductivity.HasMember(
"residual")) {
992 if (conductivity.HasMember(
"critical")) {
1001 if (transport.HasMember(
"viscosity")) {
1007 if (transport.HasMember(
"conductivity")) {
1027 if (melting_line.HasMember(
"type")) {
1029 if (!type.compare(
"Simon")) {
1030 rapidjson::Value& parts = melting_line[
"parts"];
1032 for (rapidjson::Value::ValueIterator itr = parts.Begin(); itr != parts.End(); ++itr) {
1042 }
else if (!type.compare(
"polynomial_in_Tr")) {
1043 rapidjson::Value& parts = melting_line[
"parts"];
1045 for (rapidjson::Value::ValueIterator itr = parts.Begin(); itr != parts.End(); ++itr) {
1055 }
else if (!type.compare(
"polynomial_in_Theta")) {
1056 rapidjson::Value& parts = melting_line[
"parts"];
1058 for (rapidjson::Value::ValueIterator itr = parts.Begin(); itr != parts.End(); ++itr) {
1069 throw ValueError(
format(
"melting line type [%s] is not understood for fluid %s", type.c_str(), fluid.
name.c_str()));
1074 throw ValueError(
format(
"melting line does not have \"type\" for fluid %s", fluid.
name.c_str()));
1080 if (!states.HasMember(
"critical")) {
1081 throw ValueError(
format(
"fluid[\"STATES\"] [%s] does not have \"critical\" member", fluid.
name.c_str()));
1083 rapidjson::Value& crit = states[
"critical"];
1090 if (!states.HasMember(
"triple_liquid")) {
1091 throw ValueError(
format(
"fluid[\"STATES\"] [%s] does not have \"triple_liquid\" member", fluid.
name.c_str()));
1093 rapidjson::Value& triple_liquid = states[
"triple_liquid"];
1094 if (triple_liquid.ObjectEmpty()) {
1109 if (!states.HasMember(
"triple_vapor")) {
1110 throw ValueError(
format(
"fluid[\"STATES\"] [%s] does not have \"triple_vapor\" member", fluid.
name.c_str()));
1112 rapidjson::Value& triple_vapor = states[
"triple_vapor"];
1113 if (triple_vapor.ObjectEmpty()) {
1131 if (!ancillaries.HasMember(
"rhoL") || !ancillaries.HasMember(
"rhoV")) {
1132 throw ValueError(
"Ancillary curves for either rhoL or rhoV are missing");
1138 if (ancillaries.HasMember(
"pL") && ancillaries.HasMember(
"pV")) {
1143 else if (!ancillaries.HasMember(
"pL") && !ancillaries.HasMember(
"pV") && ancillaries.HasMember(
"pS")) {
1147 throw ValueError(
"Pressure ancillary curves are missing or invalid");
1150 if (ancillaries.HasMember(
"hL")) {
1154 std::cout <<
"Missing hL ancillary for fluid " << fluid.
name;
1157 if (ancillaries.HasMember(
"hLV")) {
1161 std::cout <<
"Missing hLV ancillary for fluid " << fluid.
name;
1165 if (ancillaries.HasMember(
"sL")) {
1169 std::cout <<
"Missing sL ancillary for fluid " << fluid.
name;
1172 if (ancillaries.HasMember(
"sLV")) {
1176 std::cout <<
"Missing sLV ancillary for fluid " << fluid.
name;
1180 std::cout <<
"Tmin invalid for sL for " << fluid.
name << std::endl;
1192 assert(fluid.
CAS.length() > 0);
1193 assert(fluid.
name.length() > 0);
1206 static void add_many(
const std::string& JSON_string);
1209 void add_many(rapidjson::Value& listing);
1211 void add_one(rapidjson::Value& fluid_json);
1215 std::map<std::string, std::size_t>::const_iterator it = string_to_index_map.find(key);
1216 if (it != string_to_index_map.end()) {
1218 std::map<std::size_t, std::string>::const_iterator it2 = JSONstring_map.find(it->second);
1219 if (it2 != JSONstring_map.end()) {
1221 rapidjson::Document doc;
1223 rapidjson::Document doc2;
1225 doc2.PushBack(doc, doc.GetAllocator());
1228 throw ValueError(
format(
"Unable to obtain JSON string for this identifier [%d]", it->second));
1231 throw ValueError(
format(
"Unable to obtain index for this identifier [%s]", key.c_str()));
1241 std::map<std::string, std::size_t>::const_iterator it = string_to_index_map.find(key);
1243 if (it != string_to_index_map.end()) {
1244 return get(it->second);
1247 std::vector<std::string>
endings;
1249 endings.push_back(
"-PengRobinson");
1250 for (std::vector<std::string>::const_iterator end =
endings.begin(); end !=
endings.end(); ++end) {
1252 std::string used_name = key.substr(0, key.size() - (*end).size());
1253 it = string_to_index_map.find(used_name);
1254 if (it != string_to_index_map.end()) {
1261 fluid.
EOSVector[0].alphar.empty_the_EOS();
1269 shared_ptr<AbstractCubic> ac;
1270 if (*end ==
"-SRK") {
1271 ac.reset(
new SRK(Tc, pc, acentric, R));
1272 }
else if (*end ==
"-PengRobinson") {
1278 ac->set_rhor(rhomolarc);
1285 shared_ptr<AbstractCubic> ac;
1286 if (*end ==
"-SRK") {
1288 }
else if (*end ==
"-PengRobinson") {
1293 ac->set_Tr(vals.
Tc);
1298 double v_c_Lmol = 2.14107171795 * (vals.
Tc / vals.
pc * 1000) + 0.00773144012514;
1299 ac->set_rhor(1 / (v_c_Lmol / 1000.0));
1303 ac->set_C_Twu(0, c[0], c[1], c[2]);
1325 throw ValueError(
format(
"key [%s] was not found in string_to_index_map in JSONFluidLibrary", key.c_str()));
1335 std::map<std::size_t, CoolPropFluid>::iterator it = fluid_map.find(key);
1337 if (it != fluid_map.end()) {
1340 throw ValueError(
format(
"key [%d] was not found in JSONFluidLibrary", key));
1357CoolPropFluid
get_fluid(
const std::string& fluid_string);