7#if defined(COOLPROP_NO_INCBIN)
20INCBIN(all_fluids_JSON_z,
"all_fluids.json.z");
26static JSONFluidLibrary library;
30 uLong outlen =
static_cast<uLong>(outbuffer.size());
32 std::string buf(outbuffer.begin(), outbuffer.begin() + outlen);
34 throw ValueError(
"Unable to uncompress the fluid data from z compressed form");
37 if (getenv(
"COOLPROP_DISABLE_SUPERANCILLARIES_ENTIRELY")) {
38 std::cout <<
"CoolProp: superancillaries have been disabled because the COOLPROP_DISABLE_SUPERANCILLARIES_ENTIRELY environment variable has "
43 rapidjson::Document dd;
45 dd.Parse<0>(buf.c_str());
46 if (dd.HasParseError()) {
47 throw ValueError(
"Unable to load all_fluids.json");
51 }
catch (std::exception& e) {
52 std::cout << e.what() << std::endl;
59 std::map<std::string, std::size_t>::const_iterator it = string_to_index_map.find(fluid);
60 if (it != string_to_index_map.end()) {
61 std::map<std::size_t, CoolPropFluid>::iterator it2 = fluid_map.find(it->second);
63 if (it2 != fluid_map.end()) {
65 throw ValueError(
format(
"Not possible to set reference state for fluid %s because offset values are NAN", fluid.c_str()));
67 it2->second.EOS().alpha0.EnthalpyEntropyOffset.set(delta_a1, delta_a2, ref);
72 HEOS->update(
DmolarT_INPUTS, it2->second.EOS().hs_anchor.rhomolar, it2->second.EOS().hs_anchor.T);
73 it2->second.EOS().hs_anchor.hmolar = HEOS->hmolar();
74 it2->second.EOS().hs_anchor.smolar = HEOS->smolar();
76 double f = (HEOS->name() ==
"Water" || HEOS->name() ==
"CarbonDioxide") ? 1.00001 : 1.0;
79 HEOS->update(
DmolarT_INPUTS, it2->second.EOS().reduce.rhomolar * f, it2->second.EOS().reduce.T * f);
80 it2->second.EOS().reduce.hmolar = HEOS->hmolar();
81 it2->second.EOS().reduce.smolar = HEOS->smolar();
84 HEOS->update(
DmolarT_INPUTS, it2->second.crit.rhomolar * f, it2->second.crit.T * f);
85 it2->second.crit.hmolar = HEOS->hmolar();
86 it2->second.crit.smolar = HEOS->smolar();
89 HEOS->update(
DmolarT_INPUTS, it2->second.triple_liquid.rhomolar, it2->second.triple_liquid.T);
90 it2->second.triple_liquid.hmolar = HEOS->hmolar();
91 it2->second.triple_liquid.smolar = HEOS->smolar();
94 HEOS->update(
DmolarT_INPUTS, it2->second.triple_vapor.rhomolar, it2->second.triple_vapor.T);
95 it2->second.triple_vapor.hmolar = HEOS->hmolar();
96 it2->second.triple_vapor.smolar = HEOS->smolar();
98 if (!HEOS->is_pure()) {
100 HEOS->update(
DmolarT_INPUTS, it2->second.EOS().max_sat_T.rhomolar, it2->second.EOS().max_sat_T.T);
101 it2->second.EOS().max_sat_T.hmolar = HEOS->hmolar();
102 it2->second.EOS().max_sat_T.smolar = HEOS->smolar();
104 HEOS->update(
DmolarT_INPUTS, it2->second.EOS().max_sat_p.rhomolar, it2->second.EOS().max_sat_p.T);
105 it2->second.EOS().max_sat_p.hmolar = HEOS->hmolar();
106 it2->second.EOS().max_sat_p.smolar = HEOS->smolar();
109 throw ValueError(
format(
"fluid [%s] was not found in JSONFluidLibrary", fluid.c_str()));
123 rapidjson::Document doc;
129 if (!listing.IsArray()) {
133 for (rapidjson::Value::ValueIterator itr = listing.Begin(); itr != listing.End(); ++itr) {
144 std::size_t index = fluid_map.size();
151 fluid.
name = fluid_json[
"INFO"][
"NAME"].GetString();
155 name_vector.push_back(fluid.
name);
159 if (!fluid_json[
"INFO"].HasMember(
"CAS")) {
162 fluid.
CAS = fluid_json[
"INFO"][
"CAS"].GetString();
165 if (!fluid_json[
"INFO"].HasMember(
"REFPROP_NAME")) {
166 throw ValueError(
format(
"fluid [%s] does not have \"REFPROP_NAME\" member", fluid.
name.c_str()));
168 fluid.
REFPROPname = fluid_json[
"INFO"][
"REFPROP_NAME"].GetString();
171 if (fluid_json[
"INFO"].HasMember(
"FORMULA")) {
178 if (fluid_json[
"INFO"].HasMember(
"INCHI_STRING")) {
184 if (fluid_json[
"INFO"].HasMember(
"INCHI_KEY")) {
190 if (fluid_json[
"INFO"].HasMember(
"SMILES")) {
196 if (fluid_json[
"INFO"].HasMember(
"CHEMSPIDER_ID")) {
202 if (fluid_json[
"INFO"].HasMember(
"2DPNG_URL")) {
209 if (!(fluid_json[
"INFO"].HasMember(
"ENVIRONMENTAL"))) {
211 std::cout <<
format(
"Environmental data are missing for fluid [%s]\n", fluid.
name.c_str());
221 if (!fluid_json.HasMember(
"STATES")) {
227 std::cout <<
format(
"Loading fluid %s with CAS %s; %d fluids loaded\n", fluid.
name.c_str(), fluid.
CAS.c_str(), index);
237 if (!fluid_json.HasMember(
"ANCILLARIES")) {
243 if (!(fluid_json[
"ANCILLARIES"].HasMember(
"surface_tension"))) {
245 std::cout <<
format(
"Surface tension curves are missing for fluid [%s]\n", fluid.
name.c_str());
252 if (!(fluid_json[
"ANCILLARIES"].HasMember(
"melting_line"))) {
254 std::cout <<
format(
"Melting line curves are missing for fluid [%s]\n", fluid.
name.c_str());
261 if (!(fluid_json.HasMember(
"TRANSPORT"))) {
275 if (string_to_index_map.find(fluid.
CAS) != string_to_index_map.end()) {
276 index = string_to_index_map.find(fluid.
CAS)->second;
277 }
else if (string_to_index_map.find(fluid.
name) != string_to_index_map.end()) {
278 index = string_to_index_map.find(fluid.
name)->second;
279 }
else if (string_to_index_map.find(
upper(fluid.
name)) != string_to_index_map.end()) {
280 index = string_to_index_map.find(
upper(fluid.
name))->second;
283 for (std::size_t i = 0; i < fluid.
aliases.size(); ++i) {
284 if (string_to_index_map.find(fluid.
aliases[i]) != string_to_index_map.end()) {
285 index = string_to_index_map.find(fluid.
aliases[i])->second;
288 if (string_to_index_map.find(
upper(fluid.
aliases[i])) != string_to_index_map.end()) {
289 index = string_to_index_map.find(
upper(fluid.
aliases[i]))->second;
295 bool fluid_exists =
false;
297 if (index != fluid_map.size()) {
299 name_vector.pop_back();
301 throw ValueError(
format(
"Cannot load fluid [%s:%s] because it is already in library; index = [%i] of [%i]; Consider enabling the "
302 "config boolean variable OVERWRITE_FLUIDS",
303 fluid.
name.c_str(), fluid.
CAS.c_str(), index, fluid_map.size()));
315 if (fluid_exists) fluid_map.erase(fluid_map.find(index));
317 fluid_map[index] = fluid;
324 if (fluid_exists) JSONstring_map.erase(JSONstring_map.find(index));
332 string_to_index_map[fluid.
CAS] = index;
337 string_to_index_map[fluid.
name] = index;
342 for (std::size_t i = 0; i < fluid.
aliases.size(); ++i) {
343 string_to_index_map[fluid.
aliases[i]] = index;
351 std::cout <<
format(
"Loaded fluid: %s - Number of fluids = %d\n", fluid.
name, fluid_map.size());
354 }
catch (
const std::exception& e) {
355 throw ValueError(
format(
"Unable to load fluid [%s] due to error: %s", fluid.
name.c_str(), e.what()));
370 return library.
get(fluid_string);