diff --git a/include/teqp/models/multifluid.hpp b/include/teqp/models/multifluid.hpp index 139739084afa258af84e8eb5d0bbe6a130b851b0..0735d9737be420842b380aa05d6446ce967381ff 100644 --- a/include/teqp/models/multifluid.hpp +++ b/include/teqp/models/multifluid.hpp @@ -901,8 +901,18 @@ inline auto build_alias_map(const std::string& root) { std::map<std::string, std::string> aliasmap; for (auto path : get_files_in_folder(root + "/dev/fluids", ".json")) { auto j = load_a_JSON_file(path.string()); + std::string REFPROP_name = j.at("INFO").at("REFPROP_NAME"); + std::string name = j.at("INFO").at("NAME"); for (std::string k : {"NAME", "CAS", "REFPROP_NAME"}) { - std::string val = j.at("INFO").at(k); + std::string val = j.at("INFO").at(k); + // Skip REFPROP names that match the fluid itself + if (k == "REFPROP_NAME" && val == name) { + continue; + } + // Skip invalid REFPROP names + if (k == "REFPROP_NAME" && val == "N/A") { + continue; + } if (aliasmap.count(val) > 0) { throw std::invalid_argument("Duplicated reverse lookup identifier ["+k+"] found in file:" + path.string()); } @@ -911,12 +921,15 @@ inline auto build_alias_map(const std::string& root) { } } std::vector<std::string> aliases = j.at("INFO").at("ALIASES"); + for (std::string alias : aliases) { - if (aliasmap.count(alias) > 0) { - throw std::invalid_argument("Duplicated alias [" + alias + "] found in file:" + path.string()); - } - else { - aliasmap[alias] = std::filesystem::absolute(path).string(); + if (alias != REFPROP_name && alias != name) { // Don't add REFPROP name or base name, were already above to list of aliases + if (aliasmap.count(alias) > 0) { + throw std::invalid_argument("Duplicated alias [" + alias + "] found in file:" + path.string()); + } + else { + aliasmap[alias] = std::filesystem::absolute(path).string(); + } } } } @@ -942,7 +955,13 @@ inline auto build_multifluid_model(const std::vector<std::string>& components, c auto aliasmap = build_alias_map(coolprop_root); std::vector<std::string> abspaths; for (auto c : components) { - abspaths.push_back(aliasmap[c]); + // Allow matching of absolute paths first + if (std::filesystem::exists(c)) { + abspaths.push_back(c); + } + else { + abspaths.push_back(aliasmap[c]); + } } // Backup lookup with absolute paths resolved for each component pureJSON = collect_component_json(abspaths, coolprop_root); diff --git a/src/tests/catch_test_multifluid.cxx b/src/tests/catch_test_multifluid.cxx index 634e898053787f0852daedb9fbe2121ac9e643ae..c878ea4cd95a6841d19376058aa0d204c339fcef 100644 --- a/src/tests/catch_test_multifluid.cxx +++ b/src/tests/catch_test_multifluid.cxx @@ -82,6 +82,18 @@ TEST_CASE("Check that mixtures can also do absolute paths", "[multifluid],[abspa } } +TEST_CASE("Check mixing absolute and relative paths and fluid names", "[multifluid],[abspath]") { + std::string root = "../mycp"; + SECTION("With correct name of fluid") { + std::vector<std::string> paths = { std::filesystem::absolute(root + "/dev/fluids/Methane.json").string(), "Ethane" }; + auto model = build_multifluid_model(paths, root, root + "/dev/mixtures/mixture_binary_pairs.json"); + } + SECTION("Needing a reverse lookup for one fluid") { + std::vector<std::string> paths = { std::filesystem::absolute(root + "/dev/fluids/Methane.json").string(), "PROPANE" }; + auto model = build_multifluid_model(paths, root, root + "/dev/mixtures/mixture_binary_pairs.json"); + } +} + TEST_CASE("Check that all binary pairs specified in the binary pair file can be instantiated", "[multifluid],[binaries]") { std::string root = "../mycp"; REQUIRE_NOTHROW(build_alias_map(root));