8 static JSONFluidLibrary library;
11 rapidjson::Document dd;
14 if (dd.HasParseError()) {
15 throw ValueError(
"Unable to load all_fluids.json");
19 }
catch (std::exception& e) {
20 std::cout << e.what() << std::endl;
27 std::map<std::string, std::size_t>::const_iterator it = string_to_index_map.find(fluid);
28 if (it != string_to_index_map.end()) {
29 std::map<std::size_t, CoolPropFluid>::iterator it2 = fluid_map.find(it->second);
31 if (it2 != fluid_map.end()) {
33 throw ValueError(
format(
"Not possible to set reference state for fluid %s because offset values are NAN", fluid.c_str()));
35 it2->second.EOS().alpha0.EnthalpyEntropyOffset.set(delta_a1, delta_a2, ref);
40 HEOS->update(
DmolarT_INPUTS, it2->second.EOS().hs_anchor.rhomolar, it2->second.EOS().hs_anchor.T);
41 it2->second.EOS().hs_anchor.hmolar = HEOS->hmolar();
42 it2->second.EOS().hs_anchor.smolar = HEOS->smolar();
44 double f = (HEOS->name() ==
"Water" || HEOS->name() ==
"CarbonDioxide") ? 1.00001 : 1.0;
47 HEOS->update(
DmolarT_INPUTS, it2->second.EOS().reduce.rhomolar * f, it2->second.EOS().reduce.T * f);
48 it2->second.EOS().reduce.hmolar = HEOS->hmolar();
49 it2->second.EOS().reduce.smolar = HEOS->smolar();
52 HEOS->update(
DmolarT_INPUTS, it2->second.crit.rhomolar * f, it2->second.crit.T * f);
53 it2->second.crit.hmolar = HEOS->hmolar();
54 it2->second.crit.smolar = HEOS->smolar();
57 HEOS->update(
DmolarT_INPUTS, it2->second.triple_liquid.rhomolar, it2->second.triple_liquid.T);
58 it2->second.triple_liquid.hmolar = HEOS->hmolar();
59 it2->second.triple_liquid.smolar = HEOS->smolar();
62 HEOS->update(
DmolarT_INPUTS, it2->second.triple_vapor.rhomolar, it2->second.triple_vapor.T);
63 it2->second.triple_vapor.hmolar = HEOS->hmolar();
64 it2->second.triple_vapor.smolar = HEOS->smolar();
66 if (!HEOS->is_pure()) {
68 HEOS->update(
DmolarT_INPUTS, it2->second.EOS().max_sat_T.rhomolar, it2->second.EOS().max_sat_T.T);
69 it2->second.EOS().max_sat_T.hmolar = HEOS->hmolar();
70 it2->second.EOS().max_sat_T.smolar = HEOS->smolar();
72 HEOS->update(
DmolarT_INPUTS, it2->second.EOS().max_sat_p.rhomolar, it2->second.EOS().max_sat_p.T);
73 it2->second.EOS().max_sat_p.hmolar = HEOS->hmolar();
74 it2->second.EOS().max_sat_p.smolar = HEOS->smolar();
77 throw ValueError(
format(
"fluid [%s] was not found in JSONFluidLibrary", fluid.c_str()));
91 rapidjson::Document doc;
97 if (!listing.IsArray()) {
101 for (rapidjson::Value::ValueIterator itr = listing.Begin(); itr != listing.End(); ++itr) {
112 std::size_t index = fluid_map.size();
119 fluid.
name = fluid_json[
"INFO"][
"NAME"].GetString();
123 name_vector.push_back(fluid.
name);
127 if (!fluid_json[
"INFO"].HasMember(
"CAS")) {
130 fluid.
CAS = fluid_json[
"INFO"][
"CAS"].GetString();
133 if (!fluid_json[
"INFO"].HasMember(
"REFPROP_NAME")) {
134 throw ValueError(
format(
"fluid [%s] does not have \"REFPROP_NAME\" member", fluid.
name.c_str()));
136 fluid.
REFPROPname = fluid_json[
"INFO"][
"REFPROP_NAME"].GetString();
139 if (fluid_json[
"INFO"].HasMember(
"FORMULA")) {
146 if (fluid_json[
"INFO"].HasMember(
"INCHI_STRING")) {
152 if (fluid_json[
"INFO"].HasMember(
"INCHI_KEY")) {
158 if (fluid_json[
"INFO"].HasMember(
"SMILES")) {
164 if (fluid_json[
"INFO"].HasMember(
"CHEMSPIDER_ID")) {
170 if (fluid_json[
"INFO"].HasMember(
"2DPNG_URL")) {
177 if (!(fluid_json[
"INFO"].HasMember(
"ENVIRONMENTAL"))) {
179 std::cout <<
format(
"Environmental data are missing for fluid [%s]\n", fluid.
name.c_str());
189 if (!fluid_json.HasMember(
"STATES")) {
195 std::cout <<
format(
"Loading fluid %s with CAS %s; %d fluids loaded\n", fluid.
name.c_str(), fluid.
CAS.c_str(), index);
205 if (!fluid_json.HasMember(
"ANCILLARIES")) {
211 if (!(fluid_json[
"ANCILLARIES"].HasMember(
"surface_tension"))) {
213 std::cout <<
format(
"Surface tension curves are missing for fluid [%s]\n", fluid.
name.c_str());
220 if (!(fluid_json[
"ANCILLARIES"].HasMember(
"melting_line"))) {
222 std::cout <<
format(
"Melting line curves are missing for fluid [%s]\n", fluid.
name.c_str());
229 if (!(fluid_json.HasMember(
"TRANSPORT"))) {
243 if (string_to_index_map.find(fluid.
CAS) != string_to_index_map.end()) {
244 index = string_to_index_map.find(fluid.
CAS)->second;
245 }
else if (string_to_index_map.find(fluid.
name) != string_to_index_map.end()) {
246 index = string_to_index_map.find(fluid.
name)->second;
247 }
else if (string_to_index_map.find(
upper(fluid.
name)) != string_to_index_map.end()) {
248 index = string_to_index_map.find(
upper(fluid.
name))->second;
251 for (std::size_t i = 0; i < fluid.
aliases.size(); ++i) {
252 if (string_to_index_map.find(fluid.
aliases[i]) != string_to_index_map.end()) {
253 index = string_to_index_map.find(fluid.
aliases[i])->second;
256 if (string_to_index_map.find(
upper(fluid.
aliases[i])) != string_to_index_map.end()) {
257 index = string_to_index_map.find(
upper(fluid.
aliases[i]))->second;
263 bool fluid_exists =
false;
265 if (index != fluid_map.size()) {
267 name_vector.pop_back();
269 throw ValueError(
format(
"Cannot load fluid [%s:%s] because it is already in library; index = [%i] of [%i]; Consider enabling the "
270 "config boolean variable OVERWRITE_FLUIDS",
271 fluid.
name.c_str(), fluid.
CAS.c_str(), index, fluid_map.size()));
283 if (fluid_exists) fluid_map.erase(fluid_map.find(index));
285 fluid_map[index] = fluid;
292 if (fluid_exists) JSONstring_map.erase(JSONstring_map.find(index));
300 string_to_index_map[fluid.
CAS] = index;
305 string_to_index_map[fluid.
name] = index;
310 for (std::size_t i = 0; i < fluid.
aliases.size(); ++i) {
311 string_to_index_map[fluid.
aliases[i]] = index;
319 std::cout <<
format(
"Loaded fluid: %s - Number of fluids = %d\n", fluid.
name, fluid_map.size());
322 }
catch (
const std::exception& e) {
323 throw ValueError(
format(
"Unable to load fluid [%s] due to error: %s", fluid.
name.c_str(), e.what()));
338 return library.
get(fluid_string);