| 8 | d = cpjson::parse(s); |
| 9 | } |
| 10 | void UNIFACParameterLibrary::populate(const nlohmann::json& group_data, const nlohmann::json& interaction_data, const nlohmann::json& comp_data) { |
| 11 | if (CoolProp::get_config_bool(VTPR_ALWAYS_RELOAD_LIBRARY)) { |
| 12 | groups.clear(); |
| 13 | interaction_parameters.clear(); |
| 14 | components.clear(); |
| 15 | } |
| 16 | // Callers are expected to validate against the UNIFAC schema before calling populate; the cpjson::get_* helpers below still throw CoolProp::ValueError on missing/mistyped fields as a safety net. |
| 17 | for (const auto& el : group_data) { |
| 18 | Group g; |
| 19 | g.sgi = cpjson::get_integer(el, "sgi"); |
| 20 | g.mgi = cpjson::get_integer(el, "mgi"); |
| 21 | g.R_k = cpjson::get_double(el, "R_k"); |
| 22 | g.Q_k = cpjson::get_double(el, "Q_k"); |
| 23 | groups.push_back(g); |
| 24 | } |
| 25 | for (const auto& el : interaction_data) { |
| 26 | InteractionParameters ip; |
| 27 | ip.mgi1 = cpjson::get_integer(el, "mgi1"); |
| 28 | ip.mgi2 = cpjson::get_integer(el, "mgi2"); |
| 29 | ip.a_ij = cpjson::get_double(el, "a_ij"); |
| 30 | ip.a_ji = cpjson::get_double(el, "a_ji"); |
| 31 | ip.b_ij = cpjson::get_double(el, "b_ij"); |
| 32 | ip.b_ji = cpjson::get_double(el, "b_ji"); |
| 33 | ip.c_ij = cpjson::get_double(el, "c_ij"); |
| 34 | ip.c_ji = cpjson::get_double(el, "c_ji"); |
| 35 | interaction_parameters.push_back(ip); |
| 36 | } |
| 37 | for (const auto& el : comp_data) { |
| 38 | Component c; |
| 39 | c.inchikey = cpjson::get_string(el, "inchikey"); |
| 40 | c.registry_number = cpjson::get_string(el, "registry_number"); |
| 41 | c.name = cpjson::get_string(el, "name"); |
| 42 | c.Tc = cpjson::get_double(el, "Tc"); |
| 43 | c.pc = cpjson::get_double(el, "pc"); |
| 44 | c.acentric = cpjson::get_double(el, "acentric"); |
| 45 | c.molemass = cpjson::get_double(el, "molemass"); |
| 46 | // userid is an optional user identifier |
| 47 | if (el.contains("userid")) { |
| 48 | c.userid = cpjson::get_string(el, "userid"); |
| 49 | } |
| 50 | // If provided, store information about the alpha function in use |
| 51 | if (el.contains("alpha") && el.at("alpha").is_object()) { |
| 52 | const nlohmann::json& alpha = el.at("alpha"); |
| 53 | c.alpha_type = cpjson::get_string(alpha, "type"); |
| 54 | c.alpha_coeffs = cpjson::get_double_array(alpha, "c"); |
| 55 | } else { |
| 56 | c.alpha_type = "default"; |
| 57 | } |
| 58 | if (el.contains("alpha0") && el.at("alpha0").is_array()) { |
| 59 | c.alpha0 = CoolProp::JSONFluidLibrary::parse_alpha0(el.at("alpha0")); |
| 60 | } |
| 61 | const nlohmann::json& comp_groups = el.at("groups"); |
| 62 | for (const auto& g : comp_groups) { |
| 63 | int count = cpjson::get_integer(g, "count"); |
| 64 | int sgi = cpjson::get_integer(g, "sgi"); |
| 65 | if (has_group(sgi)) { |
| 66 | ComponentGroup cg(count, get_group(sgi)); |
| 67 | c.groups.push_back(cg); |
no test coverage detected