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")){
405 if (EOS_json.HasMember(
"alpha0_prefactor")) {
408 if (EOS_json[
"STATES"].HasMember(
"hs_anchor")) {
409 rapidjson::Value& hs_anchor = EOS_json[
"STATES"][
"hs_anchor"];
417 if (EOS_json[
"STATES"].HasMember(
"pressure_max_sat")) {
418 rapidjson::Value& s = EOS_json[
"STATES"][
"pressure_max_sat"];
422 if (s.HasMember(
"hmolar")) {
428 if (EOS_json[
"STATES"].HasMember(
"temperature_max_sat")) {
429 rapidjson::Value& s = EOS_json[
"STATES"][
"temperature_max_sat"];
433 if (s.HasMember(
"hmolar")) {
439 if (EOS_json.HasMember(
"critical_region_splines")) {
440 rapidjson::Value& spline = EOS_json[
"critical_region_splines"];
456 for (rapidjson::Value::ValueIterator itr = EOS_array.Begin(); itr != EOS_array.End(); ++itr) {
463 if (dilute.HasMember(
"hardcoded")) {
465 if (!target.compare(
"Ethane")) {
468 }
else if (!target.compare(
"Cyclohexane")) {
471 }
else if (!target.compare(
"CarbonDioxideLaeseckeJPCRD2017")) {
475 throw ValueError(
format(
"hardcoded dilute viscosity [%s] is not understood for fluid %s", target.c_str(), fluid.
name.c_str()));
479 if (!type.compare(
"collision_integral")) {
491 }
else if (!type.compare(
"kinetic_theory")) {
493 }
else if (!type.compare(
"powers_of_T")) {
502 }
else if (!type.compare(
"powers_of_Tr")) {
510 }
else if (!type.compare(
"collision_integral_powers_of_Tstar")) {
522 throw ValueError(
format(
"type [%s] is not understood for fluid %s", type.c_str(), fluid.
name.c_str()));
529 if (!type.compare(
"Rainwater-Friend")) {
539 }
else if (!type.compare(
"empirical")) {
553 throw ValueError(
format(
"type [%s] is not understood for fluid %s", type.c_str(), fluid.
name.c_str()));
560 if (higher.HasMember(
"hardcoded")) {
562 if (!target.compare(
"Hydrogen")) {
565 }
else if (!target.compare(
"n-Hexane")) {
568 }
else if (!target.compare(
"n-Heptane")) {
571 }
else if (!target.compare(
"Toluene")) {
574 }
else if (!target.compare(
"Ethane")) {
577 }
else if (!target.compare(
"Benzene")) {
580 }
else if (!target.compare(
"CarbonDioxideLaeseckeJPCRD2017")) {
585 format(
"hardcoded higher order viscosity term [%s] is not understood for fluid %s", target.c_str(), fluid.
name.c_str()));
590 if (!type.compare(
"modified_Batschinski_Hildebrand")) {
605 assert(BH.
a.size() == BH.
t1.size());
606 assert(BH.
a.size() == BH.
d1.size());
607 assert(BH.
a.size() == BH.
gamma.size());
608 assert(BH.
a.size() == BH.
l.size());
612 assert(BH.
f.size() == BH.
t2.size());
613 assert(BH.
f.size() == BH.
d2.size());
616 assert(BH.
g.size() == BH.
h.size());
619 assert(BH.
p.size() == BH.
q.size());
620 }
else if (!type.compare(
"friction_theory")) {
639 assert(F.
Aa.size() == 3);
640 assert(F.
Aaa.size() == 3);
641 assert(F.
Ar.size() == 3);
645 if (higher.HasMember(
"Arr") && !higher.HasMember(
"Adrdr")) {
647 assert(F.
Arr.size() == 3);
648 }
else if (higher.HasMember(
"Adrdr") && !higher.HasMember(
"Arr")) {
650 assert(F.
Adrdr.size() == 3);
652 throw ValueError(
format(
"can only provide one of Arr or Adrdr for fluid %s", fluid.
name.c_str()));
654 if (higher.HasMember(
"Aii")) {
658 if (higher.HasMember(
"Aaaa") && higher.HasMember(
"Arrr")) {
666 throw ValueError(
format(
"type [%s] is not understood for fluid %s", type.c_str(), fluid.
name.c_str()));
717 if (viscosity.IsArray()) {
718 rapidjson::Value::ValueIterator itr = viscosity.Begin();
727 if (!viscosity.HasMember(
"sigma_eta") || !viscosity.HasMember(
"epsilon_over_k")) {
735 if (viscosity.HasMember(
"type") && !
cpjson::get_string(viscosity,
"type").compare(
"ECS")) {
741 if (viscosity.HasMember(
"type") && !
cpjson::get_string(viscosity,
"type").compare(
"rhosr-CS")) {
748 if (viscosity.HasMember(
"type") && !
cpjson::get_string(viscosity,
"type").compare(
"Chung")) {
753 if (viscosity.HasMember(
"hardcoded")) {
755 if (!target.compare(
"Water")) {
758 }
else if (!target.compare(
"HeavyWater")) {
761 }
else if (!target.compare(
"Helium")) {
764 }
else if (!target.compare(
"R23")) {
767 }
else if (!target.compare(
"Methanol")) {
770 }
else if (!target.compare(
"m-Xylene")) {
773 }
else if (!target.compare(
"o-Xylene")) {
776 }
else if (!target.compare(
"p-Xylene")) {
780 throw ValueError(
format(
"hardcoded viscosity [%s] is not understood for fluid %s", target.c_str(), fluid.
name.c_str()));
785 if (viscosity.HasMember(
"dilute")) {
789 if (viscosity.HasMember(
"initial_density")) {
793 if (viscosity.HasMember(
"higher_order")) {
800 if (dilute.HasMember(
"hardcoded")) {
802 if (!target.compare(
"CO2")) {
806 else if (!target.compare(
"CarbonDioxideHuberJPCRD2016")) {
809 }
else if (!target.compare(
"Ethane")) {
812 }
else if (!target.compare(
"none")) {
817 format(
"hardcoded dilute conductivity term [%s] is not understood for fluid %s", target.c_str(), fluid.
name.c_str()));
821 if (!type.compare(
"ratio_of_polynomials")) {
834 }
else if (!type.compare(
"eta0_and_poly")) {
845 throw ValueError(
format(
"type [%s] is not understood for fluid %s", type.c_str(), fluid.
name.c_str()));
851 if (dilute.HasMember(
"hardcoded")) {
853 if (!target.compare(
"CO2")) {
858 format(
"hardcoded residual conductivity term [%s] is not understood for fluid %s", target.c_str(), fluid.
name.c_str()));
862 if (!type.compare(
"polynomial")) {
875 }
else if (!type.compare(
"polynomial_and_exponential")) {
889 throw ValueError(
format(
"type [%s] is not understood for fluid %s", type.c_str(), fluid.
name.c_str()));
894 if (critical.HasMember(
"hardcoded")) {
896 if (!target.compare(
"R123")) {
899 }
else if (!target.compare(
"Ammonia")) {
902 }
else if (!target.compare(
"CarbonDioxideScalabrinJPCRD2006")) {
906 }
else if (!target.compare(
"None")) {
910 throw ValueError(
format(
"critical conductivity term [%s] is not understood for fluid %s", target.c_str(), fluid.
name.c_str()));
914 if (!type.compare(
"simplified_Olchowy_Sengers")) {
922 if (critical.HasMember(
"qD")) {
925 if (critical.HasMember(
"zeta0")) {
928 if (critical.HasMember(
"GAMMA")) {
931 if (critical.HasMember(
"gamma")) {
934 if (critical.HasMember(
"R0")) {
937 if (critical.HasMember(
"T_ref")) {
941 throw ValueError(
format(
"type [%s] is not understood for fluid %s", type.c_str(), fluid.
name.c_str()));
951 if (conductivity.HasMember(
"type") && !
cpjson::get_string(conductivity,
"type").compare(
"ECS")) {
956 if (conductivity.HasMember(
"hardcoded")) {
958 if (!target.compare(
"Water")) {
961 }
else if (!target.compare(
"HeavyWater")) {
964 }
else if (!target.compare(
"Methane")) {
967 }
else if (!target.compare(
"R23")) {
970 }
else if (!target.compare(
"Helium")) {
975 format(
"hardcoded residual conductivity term [%s] is not understood for fluid %s", target.c_str(), fluid.
name.c_str()));
980 if (conductivity.HasMember(
"dilute")) {
984 if (conductivity.HasMember(
"residual")) {
988 if (conductivity.HasMember(
"critical")) {
997 if (transport.HasMember(
"viscosity")) {
1003 if (transport.HasMember(
"conductivity")) {
1023 if (melting_line.HasMember(
"type")) {
1025 if (!type.compare(
"Simon")) {
1026 rapidjson::Value& parts = melting_line[
"parts"];
1028 for (rapidjson::Value::ValueIterator itr = parts.Begin(); itr != parts.End(); ++itr) {
1038 }
else if (!type.compare(
"polynomial_in_Tr")) {
1039 rapidjson::Value& parts = melting_line[
"parts"];
1041 for (rapidjson::Value::ValueIterator itr = parts.Begin(); itr != parts.End(); ++itr) {
1051 }
else if (!type.compare(
"polynomial_in_Theta")) {
1052 rapidjson::Value& parts = melting_line[
"parts"];
1054 for (rapidjson::Value::ValueIterator itr = parts.Begin(); itr != parts.End(); ++itr) {
1065 throw ValueError(
format(
"melting line type [%s] is not understood for fluid %s", type.c_str(), fluid.
name.c_str()));
1070 throw ValueError(
format(
"melting line does not have \"type\" for fluid %s", fluid.
name.c_str()));
1076 if (!states.HasMember(
"critical")) {
1077 throw ValueError(
format(
"fluid[\"STATES\"] [%s] does not have \"critical\" member", fluid.
name.c_str()));
1079 rapidjson::Value& crit = states[
"critical"];
1086 if (!states.HasMember(
"triple_liquid")) {
1087 throw ValueError(
format(
"fluid[\"STATES\"] [%s] does not have \"triple_liquid\" member", fluid.
name.c_str()));
1089 rapidjson::Value& triple_liquid = states[
"triple_liquid"];
1090 if (triple_liquid.ObjectEmpty()) {
1105 if (!states.HasMember(
"triple_vapor")) {
1106 throw ValueError(
format(
"fluid[\"STATES\"] [%s] does not have \"triple_vapor\" member", fluid.
name.c_str()));
1108 rapidjson::Value& triple_vapor = states[
"triple_vapor"];
1109 if (triple_vapor.ObjectEmpty()) {
1127 if (!ancillaries.HasMember(
"rhoL") || !ancillaries.HasMember(
"rhoV")) {
1128 throw ValueError(
"Ancillary curves for either rhoL or rhoV are missing");
1134 if (ancillaries.HasMember(
"pL") && ancillaries.HasMember(
"pV")) {
1139 else if (!ancillaries.HasMember(
"pL") && !ancillaries.HasMember(
"pV") && ancillaries.HasMember(
"pS")) {
1143 throw ValueError(
"Pressure ancillary curves are missing or invalid");
1146 if (ancillaries.HasMember(
"hL")) {
1150 std::cout <<
"Missing hL ancillary for fluid " << fluid.
name;
1153 if (ancillaries.HasMember(
"hLV")) {
1157 std::cout <<
"Missing hLV ancillary for fluid " << fluid.
name;
1161 if (ancillaries.HasMember(
"sL")) {
1165 std::cout <<
"Missing sL ancillary for fluid " << fluid.
name;
1168 if (ancillaries.HasMember(
"sLV")) {
1172 std::cout <<
"Missing sLV ancillary for fluid " << fluid.
name;
1176 std::cout <<
"Tmin invalid for sL for " << fluid.
name << std::endl;
1188 assert(fluid.
CAS.length() > 0);
1189 assert(fluid.
name.length() > 0);
1202 static void add_many(
const std::string& JSON_string);
1205 void add_many(rapidjson::Value& listing);
1207 void add_one(rapidjson::Value& fluid_json);
1211 std::map<std::string, std::size_t>::const_iterator it = string_to_index_map.find(key);
1212 if (it != string_to_index_map.end()) {
1214 std::map<std::size_t, std::string>::const_iterator it2 = JSONstring_map.find(it->second);
1215 if (it2 != JSONstring_map.end()) {
1217 rapidjson::Document doc;
1219 rapidjson::Document doc2;
1221 doc2.PushBack(doc, doc.GetAllocator());
1224 throw ValueError(
format(
"Unable to obtain JSON string for this identifier [%d]", it->second));
1227 throw ValueError(
format(
"Unable to obtain index for this identifier [%s]", key.c_str()));
1237 std::map<std::string, std::size_t>::const_iterator it = string_to_index_map.find(key);
1239 if (it != string_to_index_map.end()) {
1240 return get(it->second);
1243 std::vector<std::string>
endings;
1245 endings.push_back(
"-PengRobinson");
1246 for (std::vector<std::string>::const_iterator end =
endings.begin(); end !=
endings.end(); ++end) {
1248 std::string used_name = key.substr(0, key.size() - (*end).size());
1249 it = string_to_index_map.find(used_name);
1250 if (it != string_to_index_map.end()) {
1257 fluid.
EOSVector[0].alphar.empty_the_EOS();
1265 shared_ptr<AbstractCubic> ac;
1266 if (*end ==
"-SRK") {
1267 ac.reset(
new SRK(Tc, pc, acentric, R));
1268 }
else if (*end ==
"-PengRobinson") {
1274 ac->set_rhor(rhomolarc);
1281 shared_ptr<AbstractCubic> ac;
1282 if (*end ==
"-SRK") {
1284 }
else if (*end ==
"-PengRobinson") {
1289 ac->set_Tr(vals.
Tc);
1294 double v_c_Lmol = 2.14107171795 * (vals.
Tc / vals.
pc * 1000) + 0.00773144012514;
1295 ac->set_rhor(1 / (v_c_Lmol / 1000.0));
1299 ac->set_C_Twu(0, c[0], c[1], c[2]);
1321 throw ValueError(
format(
"key [%s] was not found in string_to_index_map in JSONFluidLibrary", key.c_str()));
1331 std::map<std::size_t, CoolPropFluid>::iterator it = fluid_map.find(key);
1333 if (it != fluid_map.end()) {
1336 throw ValueError(
format(
"key [%d] was not found in JSONFluidLibrary", key));
1353CoolPropFluid
get_fluid(
const std::string& fluid_string);