Improvements to mixture pair management (#2579)

* Improvements to mixture pair management

Add C++ function declarations for functions that are exposed to Python but not C++.

Update apply_simple_mixing_rule to not break default rules.  This has caused confusion and bugs in the past; see, e.g., https://github.com/CoolProp/CoolProp/issues/1874, https://github.com/CoolProp/CoolProp/issues/2082.

* Delete no longer applicable docs

See #1875
This commit is contained in:
Josh Kelley
2025-10-04 12:34:21 -04:00
committed by GitHub
parent 21c4a18f13
commit 1b5096de6c
3 changed files with 17 additions and 12 deletions

View File

@@ -34,8 +34,6 @@ The two schemes available are
* ``linear`` - :math:`T_r` and :math:`v_r` are a linear function of molar composition between the two pure fluid values
* ``Lorentz-Berthelot`` - all interaction parameters are 1.0
Note that if ``apply_simple_mixing_rule`` is called first in a programme before any property calculation function, the interaction parameter library is initialized with just the binary mixture that was specified, and other binary mixtures will raise an error. To augment the built-in database, call a property calculation function before calling ``apply_simple_mixing_rule``.
Here is a sample of using this in python:
.. ipython::

View File

@@ -428,6 +428,9 @@ const std::string& get_input_pair_long_desc(input_pairs pair);
/// Split an input pair into parameters for the two parts that form the pair
void split_input_pair(input_pairs pair, parameters& p1, parameters& p2);
extern void apply_simple_mixing_rule(const std::string& identifier1, const std::string& identifier2, const std::string& rule);
extern void set_interaction_parameters(const std::string& string_data);
extern std::string get_mixture_binary_pair_data(const std::string& CAS1, const std::string& CAS2, const std::string& param);
extern void set_mixture_binary_pair_data(const std::string& CAS1, const std::string& CAS2, const std::string& param, const double val);
extern std::string get_mixture_binary_pair_pcsaft(const std::string& CAS1, const std::string& CAS2, const std::string& param);

View File

@@ -88,10 +88,7 @@ class MixtureBinaryPairLibrary
public:
std::map<std::vector<std::string>, std::vector<Dictionary>>& binary_pair_map() {
// Set the default departure functions if none have been provided yet
if (m_binary_pair_map.size() == 0) {
load_defaults();
}
load_defaults_if_needed();
return m_binary_pair_map;
};
@@ -105,6 +102,12 @@ class MixtureBinaryPairLibrary
load_from_JSON(doc);
}
void load_defaults_if_needed() {
if (m_binary_pair_map.size() == 0) {
load_defaults();
}
}
// Load the defaults that come from the JSON-encoded string compiled into library
// as the variable mixture_departure_functions_JSON
void load_defaults() {
@@ -284,11 +287,10 @@ class MixtureBinaryPairLibrary
};
// The modifiable parameter library
static MixtureBinaryPairLibrary mixturebinarypairlibrary;
// A fixed parameter library containing the default values
static MixtureBinaryPairLibrary mixturebinarypairlibrary_default;
/// Add a simple mixing rule
void apply_simple_mixing_rule(const std::string& identifier1, const std::string& identifier2, const std::string& rule) {
mixturebinarypairlibrary.load_defaults_if_needed();
mixturebinarypairlibrary.add_simple_mixing_rule(identifier1, identifier2, rule);
}
@@ -410,10 +412,7 @@ class MixtureDepartureFunctionsLibrary
public:
std::map<std::string, Dictionary>& departure_function_map() {
// Set the default departure functions if none have been provided yet
if (m_departure_function_map.size() == 0) {
load_defaults();
}
load_defaults_if_needed();
return m_departure_function_map;
};
@@ -507,6 +506,11 @@ class MixtureDepartureFunctionsLibrary
}
}
}
void load_defaults_if_needed() {
if (m_departure_function_map.size() == 0) {
load_defaults();
}
}
// Load the defaults that come from the JSON-encoded string compiled into library
// as the variable mixture_departure_functions_JSON
void load_defaults() {