mirror of
https://github.com/CoolProp/CoolProp.git
synced 2026-04-01 03:00:13 -04:00
Added generate_update_pair function to python
Signed-off-by: Ian Bell <ian.h.bell@gmail.com>
This commit is contained in:
@@ -46,16 +46,16 @@ The phase index (as floating point number) can also be obtained using the PropsS
|
||||
|
||||
In [5]: CoolProp.CoolProp.PropsSI('Phase','P',101325,'Q',0,'Water')
|
||||
|
||||
where you can obtain the integer indices corresponding to the phase flags using the ``get_parameter_index`` function:
|
||||
where you can obtain the integer indices corresponding to the phase flags using the ``get_phase_index`` function:
|
||||
|
||||
.. ipython::
|
||||
|
||||
In [1]: import CoolProp
|
||||
|
||||
In [6]: CoolProp.CoolProp.get_parameter_index('phase_twophase')
|
||||
In [6]: CoolProp.CoolProp.get_phase_index('phase_twophase')
|
||||
|
||||
# Or for liquid
|
||||
In [6]: CoolProp.CoolProp.get_parameter_index('phase_liquid')
|
||||
In [6]: CoolProp.CoolProp.get_phase_index('phase_liquid')
|
||||
|
||||
For a given fluid, the phase can be plotted in T-p coordinates:
|
||||
|
||||
|
||||
@@ -131,13 +131,27 @@ enum parameters{
|
||||
};
|
||||
// !! If you add a parameter, update the map in the corresponding CPP file !!
|
||||
|
||||
/// These are constants for the phases of the fluid
|
||||
enum phases{iphase_liquid, ///< Subcritical liquid
|
||||
iphase_supercritical, ///< Supercritical (p > pc, T > Tc)
|
||||
iphase_supercritical_gas, ///< Supercritical gas (p < pc, T > Tc)
|
||||
iphase_supercritical_liquid, ///< Supercritical liquid (p > pc, T < Tc)
|
||||
iphase_critical_point, ///< At the critical point
|
||||
iphase_gas, ///< Subcritical gas
|
||||
iphase_twophase, ///< Twophase
|
||||
iphase_unknown, ///< Unknown phase
|
||||
iphase_not_imposed}; ///< Phase is not imposed
|
||||
|
||||
/// Return information about the parameter
|
||||
/// @param key The key, one of iT, iP, etc.
|
||||
/// @param info The thing you want, one of "IO" ("IO" if input/output, "O" if output only), "short" (very short description), "long" (a longer description), "units"
|
||||
std::string get_parameter_information(int key, std::string info);
|
||||
|
||||
/// Return the integer key corresponding to the parameter name ("Dmolar" for instance)
|
||||
int get_parameter_index(const std::string ¶m_name);
|
||||
/// Return the enum key corresponding to the parameter name ("Dmolar" for instance)
|
||||
parameters get_parameter_index(const std::string ¶m_name);
|
||||
|
||||
/// Return the enum key corresponding to the phase name ("phase_liquid" for instance)
|
||||
phases get_phase_index(const std::string ¶m_name);
|
||||
|
||||
/// Returns true if the input is trivial (constants, critical parameters, etc.)
|
||||
bool is_trivial_parameter(int key);
|
||||
@@ -156,17 +170,6 @@ enum composition_types{IFRAC_MASS, IFRAC_MOLE, IFRAC_VOLUME, IFRAC_UNDEFINED, IF
|
||||
|
||||
const long double R_u_CODATA = 8.3144621; ///< The value for the ideal gas constant in J/mol/K according to CODATA 2010. This value is used to harmonize all the ideal gas constants. This is especially important in the critical region.
|
||||
|
||||
/// These are constants for the phases of the fluid
|
||||
enum phases{iphase_liquid, ///< Subcritical liquid
|
||||
iphase_supercritical, ///< Supercritical (p > pc, T > Tc)
|
||||
iphase_supercritical_gas, ///< Supercritical gas (p < pc, T > Tc)
|
||||
iphase_supercritical_liquid, ///< Supercritical liquid (p > pc, T < Tc)
|
||||
iphase_critical_point, ///< At the critical point
|
||||
iphase_gas, ///< Subcritical gas
|
||||
iphase_twophase, ///< Twophase
|
||||
iphase_unknown, ///< Unknown phase
|
||||
iphase_not_imposed}; ///< Phase is not imposed
|
||||
|
||||
/// These are unit types for the fluid
|
||||
enum fluid_types{FLUID_TYPE_PURE, FLUID_TYPE_PSEUDOPURE, FLUID_TYPE_REFPROP, FLUID_TYPE_INCOMPRESSIBLE_LIQUID, FLUID_TYPE_INCOMPRESSIBLE_SOLUTION, FLUID_TYPE_UNDEFINED};
|
||||
|
||||
@@ -214,12 +217,12 @@ enum input_pairs{
|
||||
};
|
||||
// !! If you add or remove a parameter, update the map in the corresponding CPP file !!
|
||||
|
||||
inline bool match_pair(long key1, long key2, long x1, long x2, bool &swap)
|
||||
inline bool match_pair(parameters key1, parameters key2, parameters x1, parameters x2, bool &swap)
|
||||
{
|
||||
swap = !(key1 == x1);
|
||||
return ((key1 == x1 && key2 == x2) || (key2 == x1 && key1 == x2));
|
||||
};
|
||||
template<class T> CoolProp::input_pairs generate_update_pair(long key1, T value1, long key2, T value2, T &out1, T&out2)
|
||||
template<class T> CoolProp::input_pairs generate_update_pair(parameters key1, T value1, parameters key2, T value2, T &out1, T &out2)
|
||||
{
|
||||
CoolProp::input_pairs pair;
|
||||
bool swap;
|
||||
|
||||
@@ -384,8 +384,8 @@ double _PropsSI(const std::string &Output, const std::string &Name1, double Prop
|
||||
return val;
|
||||
}
|
||||
|
||||
long iName1 = get_parameter_index(Name1);
|
||||
long iName2 = get_parameter_index(Name2);
|
||||
parameters iName1 = get_parameter_index(Name1);
|
||||
parameters iName2 = get_parameter_index(Name2);
|
||||
|
||||
if (State->using_mole_fractions()){
|
||||
State->set_mole_fractions(fractions);
|
||||
|
||||
@@ -256,8 +256,8 @@ public:
|
||||
}
|
||||
void set_pair(std::string &in1, double v1, std::string &in2, double v2){
|
||||
double o1, o2;
|
||||
long iin1 = CoolProp::get_parameter_index(in1);
|
||||
long iin2 = CoolProp::get_parameter_index(in2);
|
||||
parameters iin1 = CoolProp::get_parameter_index(in1);
|
||||
parameters iin2 = CoolProp::get_parameter_index(in2);
|
||||
CoolProp::input_pairs pair = CoolProp::generate_update_pair(iin1, v1, iin2, v2, o1, o2);
|
||||
pState->update(pair, o1, o2);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,8 @@ cdef extern from "Configuration.h" namespace "CoolProp":
|
||||
cdef extern from "DataStructures.h" namespace "CoolProp":
|
||||
string _get_parameter_information "CoolProp::get_parameter_information"(int, string) except +
|
||||
int _get_parameter_index "CoolProp::get_parameter_index"(string) except +
|
||||
constants_header.input_pairs _generate_update_pair "CoolProp::generate_update_pair"(long key1, double value1, long key2, double value2, double &out1, double &out2) except +
|
||||
int _get_phase_index "CoolProp::get_phase_index"(string) except +
|
||||
constants_header.input_pairs _generate_update_pair "CoolProp::generate_update_pair"(constants_header.parameters key1, double value1, constants_header.parameters key2, double value2, double &out1, double &out2) except +
|
||||
|
||||
cdef extern from "CoolPropLib.h":
|
||||
double _Props "Props"(const char* Output, const char Name1, double Prop1, const char Name2, double Prop2, const char* Ref)
|
||||
|
||||
@@ -117,14 +117,36 @@ def set_reference_state(string FluidName, *args):
|
||||
# else:
|
||||
# return val
|
||||
|
||||
cpdef tuple generate_update_pair(constants_header.parameters key1, double value1, constants_header.parameters key2, double value2):
|
||||
"""
|
||||
This function will generate an input pair to the update() function given the key, value pairs for both inputs
|
||||
"""
|
||||
cdef constants_header.input_pairs pair
|
||||
cdef double out1, out2
|
||||
pair = _generate_update_pair(key1, value1, key2, value2, out1, out2)
|
||||
return pair, out1, out2
|
||||
|
||||
cpdef string get_config_as_json_string():
|
||||
"""
|
||||
Obtain a json formulation of the internal configuration in CoolProp
|
||||
|
||||
Values can be set by passing a modified json library (converted to string) to set_config_as_json_string
|
||||
"""
|
||||
return _get_config_as_json_string()
|
||||
|
||||
cpdef set_config_as_json_string(string s):
|
||||
"""
|
||||
Set the internal configuration in CoolProp from a json data string
|
||||
|
||||
Current state can be obtained by calling get_config_as_json_string
|
||||
"""
|
||||
_set_config_as_json_string(s)
|
||||
|
||||
cpdef int get_parameter_index(string key):
|
||||
return _get_parameter_index(key)
|
||||
|
||||
cpdef int get_phase_index(string key):
|
||||
return _get_phase_index(key)
|
||||
|
||||
cpdef string get_parameter_information(int key, string info):
|
||||
return _get_parameter_information(key, info)
|
||||
|
||||
Reference in New Issue
Block a user