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(
"ResidualHelmholtzExponential")) {
128 assert(n.size() == d.size());
129 assert(n.size() == t.size());
130 assert(n.size() == g.size());
131 assert(n.size() == l.size());
133 }
else if (!type.compare(
"ResidualHelmholtzAssociating")) {
144 throw ValueError(
format(
"Unsupported Residual helmholtz type: %s", type.c_str()));
156 if (!jsonalpha0.IsArray()) {
162 for (rapidjson::Value::ConstValueIterator itr = jsonalpha0.Begin(); itr != jsonalpha0.End(); ++itr) {
164 const rapidjson::Value& contribution = *itr;
167 std::string type = contribution[
"type"].GetString();
169 if (!type.compare(
"IdealGasHelmholtzLead")) {
177 }
else if (!type.compare(
"IdealGasHelmholtzPower")) {
185 }
else if (!type.compare(
"IdealGasHelmholtzLogTau")) {
192 }
else if (!type.compare(
"IdealGasHelmholtzPlanckEinsteinGeneralized")) {
205 }
else if (!type.compare(
"IdealGasHelmholtzPlanckEinstein")) {
210 for (std::size_t i = 0; i < t.size(); ++i) {
213 std::vector<CoolPropDbl> c(n.size(), 1);
214 std::vector<CoolPropDbl> d(c.size(), -1);
221 }
else if (!type.compare(
"IdealGasHelmholtzPlanckEinsteinFunctionT")) {
227 for (std::size_t i = 0; i < v.size(); ++i) {
228 theta[i] = -v[i] / Tc;
230 std::vector<CoolPropDbl> c(n.size(), 1);
231 std::vector<CoolPropDbl> d(c.size(), -1);
238 }
else if (!type.compare(
"IdealGasHelmholtzGERG2004Cosh")) {
248 }
else if (!type.compare(
"IdealGasHelmholtzGERG2004Sinh")) {
258 }
else if (!type.compare(
"IdealGasHelmholtzCP0Constant")) {
260 throw ValueError(
"Cannot add another IdealGasHelmholtzCP0Constant term; join them together");
266 }
else if (!type.compare(
"IdealGasHelmholtzCP0PolyT")) {
268 throw ValueError(
"Cannot add another CP0PolyT term; join them together");
275 }
else if (!type.compare(
"IdealGasHelmholtzCP0AlyLee")) {
282 if (std::abs(constants[0]) > 1e-14) {
283 std::vector<CoolPropDbl> c(1, constants[0]), t(1, 0);
290 std::vector<CoolPropDbl> n, c, d, t;
291 if (std::abs(constants[1]) > 1e-14) {
293 n.push_back(constants[1]);
294 t.push_back(-2 * constants[2] / Tc);
298 if (std::abs(constants[3]) > 1e-14) {
300 n.push_back(-constants[3]);
301 t.push_back(-2 * constants[4] / Tc);
310 }
else if (!type.compare(
"IdealGasHelmholtzEnthalpyEntropyOffset")) {
316 std::cout <<
format(
"Unsupported ideal-gas Helmholtz type: %s\n", type.c_str());
352 rapidjson::Value& reducing_state = EOS_json[
"STATES"][
"reducing"];
353 rapidjson::Value& satminL_state = EOS_json[
"STATES"][
"sat_min_liquid"];
354 rapidjson::Value& satminV_state = EOS_json[
"STATES"][
"sat_min_vapor"];
383 if (EOS_json.HasMember(
"alpha0_prefactor")) {
386 if (EOS_json[
"STATES"].HasMember(
"hs_anchor")) {
387 rapidjson::Value& hs_anchor = EOS_json[
"STATES"][
"hs_anchor"];
395 if (EOS_json[
"STATES"].HasMember(
"pressure_max_sat")) {
396 rapidjson::Value& s = EOS_json[
"STATES"][
"pressure_max_sat"];
400 if (s.HasMember(
"hmolar")) {
406 if (EOS_json[
"STATES"].HasMember(
"temperature_max_sat")) {
407 rapidjson::Value& s = EOS_json[
"STATES"][
"temperature_max_sat"];
411 if (s.HasMember(
"hmolar")) {
417 if (EOS_json.HasMember(
"critical_region_splines")) {
418 rapidjson::Value& spline = EOS_json[
"critical_region_splines"];
434 for (rapidjson::Value::ValueIterator itr = EOS_array.Begin(); itr != EOS_array.End(); ++itr) {
441 if (dilute.HasMember(
"hardcoded")) {
443 if (!target.compare(
"Ethane")) {
446 }
else if (!target.compare(
"Cyclohexane")) {
449 }
else if (!target.compare(
"CarbonDioxideLaeseckeJPCRD2017")) {
453 throw ValueError(
format(
"hardcoded dilute viscosity [%s] is not understood for fluid %s", target.c_str(), fluid.
name.c_str()));
457 if (!type.compare(
"collision_integral")) {
469 }
else if (!type.compare(
"kinetic_theory")) {
471 }
else if (!type.compare(
"powers_of_T")) {
480 }
else if (!type.compare(
"powers_of_Tr")) {
488 }
else if (!type.compare(
"collision_integral_powers_of_Tstar")) {
500 throw ValueError(
format(
"type [%s] is not understood for fluid %s", type.c_str(), fluid.
name.c_str()));
507 if (!type.compare(
"Rainwater-Friend")) {
517 }
else if (!type.compare(
"empirical")) {
531 throw ValueError(
format(
"type [%s] is not understood for fluid %s", type.c_str(), fluid.
name.c_str()));
538 if (higher.HasMember(
"hardcoded")) {
540 if (!target.compare(
"Hydrogen")) {
543 }
else if (!target.compare(
"n-Hexane")) {
546 }
else if (!target.compare(
"n-Heptane")) {
549 }
else if (!target.compare(
"Toluene")) {
552 }
else if (!target.compare(
"Ethane")) {
555 }
else if (!target.compare(
"Benzene")) {
558 }
else if (!target.compare(
"CarbonDioxideLaeseckeJPCRD2017")) {
563 format(
"hardcoded higher order viscosity term [%s] is not understood for fluid %s", target.c_str(), fluid.
name.c_str()));
568 if (!type.compare(
"modified_Batschinski_Hildebrand")) {
583 assert(BH.
a.size() == BH.
t1.size());
584 assert(BH.
a.size() == BH.
d1.size());
585 assert(BH.
a.size() == BH.
gamma.size());
586 assert(BH.
a.size() == BH.
l.size());
590 assert(BH.
f.size() == BH.
t2.size());
591 assert(BH.
f.size() == BH.
d2.size());
594 assert(BH.
g.size() == BH.
h.size());
597 assert(BH.
p.size() == BH.
q.size());
598 }
else if (!type.compare(
"friction_theory")) {
617 assert(F.
Aa.size() == 3);
618 assert(F.
Aaa.size() == 3);
619 assert(F.
Ar.size() == 3);
623 if (higher.HasMember(
"Arr") && !higher.HasMember(
"Adrdr")) {
625 assert(F.
Arr.size() == 3);
626 }
else if (higher.HasMember(
"Adrdr") && !higher.HasMember(
"Arr")) {
628 assert(F.
Adrdr.size() == 3);
630 throw ValueError(
format(
"can only provide one of Arr or Adrdr for fluid %s", fluid.
name.c_str()));
632 if (higher.HasMember(
"Aii")) {
636 if (higher.HasMember(
"Aaaa") && higher.HasMember(
"Arrr")) {
644 throw ValueError(
format(
"type [%s] is not understood for fluid %s", type.c_str(), fluid.
name.c_str()));
695 if (viscosity.IsArray()) {
696 rapidjson::Value::ValueIterator itr = viscosity.Begin();
705 if (!viscosity.HasMember(
"sigma_eta") || !viscosity.HasMember(
"epsilon_over_k")) {
713 if (viscosity.HasMember(
"type") && !
cpjson::get_string(viscosity,
"type").compare(
"ECS")) {
719 if (viscosity.HasMember(
"type") && !
cpjson::get_string(viscosity,
"type").compare(
"rhosr-CS")) {
726 if (viscosity.HasMember(
"type") && !
cpjson::get_string(viscosity,
"type").compare(
"Chung")) {
731 if (viscosity.HasMember(
"hardcoded")) {
733 if (!target.compare(
"Water")) {
736 }
else if (!target.compare(
"HeavyWater")) {
739 }
else if (!target.compare(
"Helium")) {
742 }
else if (!target.compare(
"R23")) {
745 }
else if (!target.compare(
"Methanol")) {
748 }
else if (!target.compare(
"m-Xylene")) {
751 }
else if (!target.compare(
"o-Xylene")) {
754 }
else if (!target.compare(
"p-Xylene")) {
758 throw ValueError(
format(
"hardcoded viscosity [%s] is not understood for fluid %s", target.c_str(), fluid.
name.c_str()));
763 if (viscosity.HasMember(
"dilute")) {
767 if (viscosity.HasMember(
"initial_density")) {
771 if (viscosity.HasMember(
"higher_order")) {
778 if (dilute.HasMember(
"hardcoded")) {
780 if (!target.compare(
"CO2")) {
784 else if (!target.compare(
"CarbonDioxideHuberJPCRD2016")) {
787 }
else if (!target.compare(
"Ethane")) {
790 }
else if (!target.compare(
"none")) {
795 format(
"hardcoded dilute conductivity term [%s] is not understood for fluid %s", target.c_str(), fluid.
name.c_str()));
799 if (!type.compare(
"ratio_of_polynomials")) {
812 }
else if (!type.compare(
"eta0_and_poly")) {
823 throw ValueError(
format(
"type [%s] is not understood for fluid %s", type.c_str(), fluid.
name.c_str()));
829 if (dilute.HasMember(
"hardcoded")) {
831 if (!target.compare(
"CO2")) {
836 format(
"hardcoded residual conductivity term [%s] is not understood for fluid %s", target.c_str(), fluid.
name.c_str()));
840 if (!type.compare(
"polynomial")) {
853 }
else if (!type.compare(
"polynomial_and_exponential")) {
867 throw ValueError(
format(
"type [%s] is not understood for fluid %s", type.c_str(), fluid.
name.c_str()));
872 if (critical.HasMember(
"hardcoded")) {
874 if (!target.compare(
"R123")) {
877 }
else if (!target.compare(
"Ammonia")) {
880 }
else if (!target.compare(
"CarbonDioxideScalabrinJPCRD2006")) {
884 }
else if (!target.compare(
"None")) {
888 throw ValueError(
format(
"critical conductivity term [%s] is not understood for fluid %s", target.c_str(), fluid.
name.c_str()));
892 if (!type.compare(
"simplified_Olchowy_Sengers")) {
900 if (critical.HasMember(
"qD")) {
903 if (critical.HasMember(
"zeta0")) {
906 if (critical.HasMember(
"GAMMA")) {
909 if (critical.HasMember(
"gamma")) {
912 if (critical.HasMember(
"R0")) {
915 if (critical.HasMember(
"T_ref")) {
919 throw ValueError(
format(
"type [%s] is not understood for fluid %s", type.c_str(), fluid.
name.c_str()));
929 if (conductivity.HasMember(
"type") && !
cpjson::get_string(conductivity,
"type").compare(
"ECS")) {
934 if (conductivity.HasMember(
"hardcoded")) {
936 if (!target.compare(
"Water")) {
939 }
else if (!target.compare(
"HeavyWater")) {
942 }
else if (!target.compare(
"Methane")) {
945 }
else if (!target.compare(
"R23")) {
948 }
else if (!target.compare(
"Helium")) {
953 format(
"hardcoded residual conductivity term [%s] is not understood for fluid %s", target.c_str(), fluid.
name.c_str()));
958 if (conductivity.HasMember(
"dilute")) {
962 if (conductivity.HasMember(
"residual")) {
966 if (conductivity.HasMember(
"critical")) {
975 if (transport.HasMember(
"viscosity")) {
981 if (transport.HasMember(
"conductivity")) {
1001 if (melting_line.HasMember(
"type")) {
1003 if (!type.compare(
"Simon")) {
1004 rapidjson::Value& parts = melting_line[
"parts"];
1006 for (rapidjson::Value::ValueIterator itr = parts.Begin(); itr != parts.End(); ++itr) {
1016 }
else if (!type.compare(
"polynomial_in_Tr")) {
1017 rapidjson::Value& parts = melting_line[
"parts"];
1019 for (rapidjson::Value::ValueIterator itr = parts.Begin(); itr != parts.End(); ++itr) {
1029 }
else if (!type.compare(
"polynomial_in_Theta")) {
1030 rapidjson::Value& parts = melting_line[
"parts"];
1032 for (rapidjson::Value::ValueIterator itr = parts.Begin(); itr != parts.End(); ++itr) {
1043 throw ValueError(
format(
"melting line type [%s] is not understood for fluid %s", type.c_str(), fluid.
name.c_str()));
1048 throw ValueError(
format(
"melting line does not have \"type\" for fluid %s", fluid.
name.c_str()));
1054 if (!states.HasMember(
"critical")) {
1055 throw ValueError(
format(
"fluid[\"STATES\"] [%s] does not have \"critical\" member", fluid.
name.c_str()));
1057 rapidjson::Value& crit = states[
"critical"];
1064 if (!states.HasMember(
"triple_liquid")) {
1065 throw ValueError(
format(
"fluid[\"STATES\"] [%s] does not have \"triple_liquid\" member", fluid.
name.c_str()));
1067 rapidjson::Value& triple_liquid = states[
"triple_liquid"];
1068 if (triple_liquid.ObjectEmpty()) {
1083 if (!states.HasMember(
"triple_vapor")) {
1084 throw ValueError(
format(
"fluid[\"STATES\"] [%s] does not have \"triple_vapor\" member", fluid.
name.c_str()));
1086 rapidjson::Value& triple_vapor = states[
"triple_vapor"];
1087 if (triple_vapor.ObjectEmpty()) {
1105 if (!ancillaries.HasMember(
"rhoL") || !ancillaries.HasMember(
"rhoV")) {
1106 throw ValueError(
"Ancillary curves for either rhoL or rhoV are missing");
1112 if (ancillaries.HasMember(
"pL") && ancillaries.HasMember(
"pV")) {
1117 else if (!ancillaries.HasMember(
"pL") && !ancillaries.HasMember(
"pV") && ancillaries.HasMember(
"pS")) {
1121 throw ValueError(
"Pressure ancillary curves are missing or invalid");
1124 if (ancillaries.HasMember(
"hL")) {
1128 std::cout <<
"Missing hL ancillary for fluid " << fluid.
name;
1131 if (ancillaries.HasMember(
"hLV")) {
1135 std::cout <<
"Missing hLV ancillary for fluid " << fluid.
name;
1139 if (ancillaries.HasMember(
"sL")) {
1143 std::cout <<
"Missing sL ancillary for fluid " << fluid.
name;
1146 if (ancillaries.HasMember(
"sLV")) {
1150 std::cout <<
"Missing sLV ancillary for fluid " << fluid.
name;
1154 std::cout <<
"Tmin invalid for sL for " << fluid.
name << std::endl;
1166 assert(fluid.
CAS.length() > 0);
1167 assert(fluid.
name.length() > 0);
1180 static void add_many(
const std::string& JSON_string);
1183 void add_many(rapidjson::Value& listing);
1185 void add_one(rapidjson::Value& fluid_json);
1189 std::map<std::string, std::size_t>::const_iterator it = string_to_index_map.find(key);
1190 if (it != string_to_index_map.end()) {
1192 std::map<std::size_t, std::string>::const_iterator it2 = JSONstring_map.find(it->second);
1193 if (it2 != JSONstring_map.end()) {
1195 rapidjson::Document doc;
1197 rapidjson::Document doc2;
1199 doc2.PushBack(doc, doc.GetAllocator());
1202 throw ValueError(
format(
"Unable to obtain JSON string for this identifier [%d]", it->second));
1205 throw ValueError(
format(
"Unable to obtain index for this identifier [%s]", key.c_str()));
1215 std::map<std::string, std::size_t>::const_iterator it = string_to_index_map.find(key);
1217 if (it != string_to_index_map.end()) {
1218 return get(it->second);
1221 std::vector<std::string>
endings;
1223 endings.push_back(
"-PengRobinson");
1224 for (std::vector<std::string>::const_iterator end =
endings.begin(); end !=
endings.end(); ++end) {
1226 std::string used_name = key.substr(0, key.size() - (*end).size());
1227 it = string_to_index_map.find(used_name);
1228 if (it != string_to_index_map.end()) {
1235 fluid.
EOSVector[0].alphar.empty_the_EOS();
1243 shared_ptr<AbstractCubic> ac;
1244 if (*end ==
"-SRK") {
1245 ac.reset(
new SRK(Tc, pc, acentric, R));
1246 }
else if (*end ==
"-PengRobinson") {
1252 ac->set_rhor(rhomolarc);
1259 shared_ptr<AbstractCubic> ac;
1260 if (*end ==
"-SRK") {
1262 }
else if (*end ==
"-PengRobinson") {
1267 ac->set_Tr(vals.
Tc);
1272 double v_c_Lmol = 2.14107171795 * (vals.
Tc / vals.
pc * 1000) + 0.00773144012514;
1273 ac->set_rhor(1 / (v_c_Lmol / 1000.0));
1277 ac->set_C_Twu(0, c[0], c[1], c[2]);
1299 throw ValueError(
format(
"key [%s] was not found in string_to_index_map in JSONFluidLibrary", key.c_str()));
1309 std::map<std::size_t, CoolPropFluid>::iterator it = fluid_map.find(key);
1311 if (it != fluid_map.end()) {
1314 throw ValueError(
format(
"key [%d] was not found in JSONFluidLibrary", key));
1331 CoolPropFluid
get_fluid(
const std::string& fluid_string);