mirror of
https://github.com/CoolProp/CoolProp.git
synced 2026-02-10 05:45:14 -05:00
Renamed python wrapper files for now to CoolProp5 - python wrapper is coming together. Dropped xdress and building it manually.
Signed-off-by: Ian bell <ian.h.bell@gmail.com>
This commit is contained in:
@@ -1,475 +0,0 @@
|
||||
from libcpp.string cimport string
|
||||
import cython
|
||||
cimport cython
|
||||
|
||||
# Default string in Python 3.x is a unicode string (type str)
|
||||
# Default string in Python 2.x is a byte string(type bytes)
|
||||
#
|
||||
# Create a fused type that allows for either unicode string or bytestring
|
||||
# We encode unicode strings using the ASCII encoding since we know they are all
|
||||
# ASCII strings
|
||||
ctypedef fused string_like:
|
||||
cython.bytes
|
||||
cython.unicode
|
||||
|
||||
cdef extern from "CPState.h":
|
||||
cdef cppclass CoolPropStateClass:
|
||||
|
||||
bint flag_SinglePhase, flag_TwoPhase
|
||||
|
||||
## Bulk values
|
||||
double _rho,_T,_p,_Q,_h,_s, tau, delta
|
||||
|
||||
## Phase flags
|
||||
bint TwoPhase, SinglePhase
|
||||
|
||||
## Nullary Constructor
|
||||
CoolPropStateClass() except +
|
||||
|
||||
## Constructor with fluid name
|
||||
CoolPropStateClass(string FluidName) except +
|
||||
|
||||
## Property updater
|
||||
## Uses the indices in CoolProp for the input parameters
|
||||
void update(long iInput1, double Value1, long iInput2, double Value2) except +ValueError
|
||||
|
||||
## Property accessors for saturation parameters directly
|
||||
## These all must be calculated every time if the state is saturated or two-phase
|
||||
double rhoL() except +
|
||||
double rhoV() except +
|
||||
double pL() except +
|
||||
double pV() except +
|
||||
double TL() except +
|
||||
double TV() except +
|
||||
## Derived parameters for the saturation states
|
||||
double hL() except +
|
||||
double hV() except +
|
||||
double sL() except +
|
||||
double sV() except +
|
||||
|
||||
## Bulk properties accessors - temperature and density are directly calculated every time
|
||||
## All other parameters are calculated on an as-needed basis
|
||||
## If single-phase, just plug into the EOS, otherwise need to do two-phase analysis
|
||||
double T() except +
|
||||
double rho() except +
|
||||
double p() except +
|
||||
double h() except +
|
||||
double s() except +
|
||||
double cp() except +
|
||||
double cv() except +
|
||||
double speed_sound() except +
|
||||
double keyed_output(long iOutput) except +
|
||||
long phase() except +
|
||||
|
||||
## ----------------------------------------
|
||||
## TTSE LUT things
|
||||
## ----------------------------------------
|
||||
|
||||
## Enable the TTSE
|
||||
void enable_TTSE_LUT() except +
|
||||
## Check if TTSE is enabled
|
||||
bint isenabled_TTSE_LUT() except +
|
||||
## Disable the TTSE
|
||||
void disable_TTSE_LUT() except +
|
||||
## Interpolate within the TTSE LUT
|
||||
double interpolate_in_TTSE_LUT(long iParam, long iInput1, double Input1, long iInput2, double Input2) except +
|
||||
|
||||
## ----------------------------------------
|
||||
## Derivatives of properties
|
||||
## ----------------------------------------
|
||||
|
||||
double dvdp_constT() except +
|
||||
double dvdT_constp() except +
|
||||
|
||||
double drhodT_constp() except +
|
||||
double drhodh_constp() except +
|
||||
double drhodp_consth() except +
|
||||
double drhodp_constT() except +
|
||||
double d2rhodp2_constT() except +
|
||||
double d2rhodTdp() except +
|
||||
double d2rhodhdQ() except +
|
||||
double d2rhodpdQ() except +
|
||||
double d2rhodhdp() except +
|
||||
double d2rhodh2_constp() except +
|
||||
double d2rhodT2_constp() except +
|
||||
|
||||
double dpdrho_constT() except +
|
||||
double dpdrho_consth() except +
|
||||
double dpdT_constrho() except +
|
||||
double dpdT_consth() except +
|
||||
double d2pdrho2_constT() except +
|
||||
double d2pdrhodT() except +
|
||||
double d2pdT2_constrho() except +
|
||||
|
||||
double dhdrho_constT() except +
|
||||
double dhdrho_constp() except +
|
||||
double dhdT_constrho() except +
|
||||
double dhdT_constp() except +
|
||||
double dhdp_constT() except +
|
||||
double d2hdrho2_constT() except +
|
||||
double d2hdrhodT() except +
|
||||
double d2hdT2_constrho() except +
|
||||
double d2hdT2_constp() except +
|
||||
double d2hdp2_constT() except +
|
||||
double d2hdTdp() except +
|
||||
|
||||
double dsdrho_constT() except +
|
||||
double dsdT_constrho() except +
|
||||
double dsdrho_constp() except +
|
||||
double dsdT_constp() except +
|
||||
double dsdp_constT() except +
|
||||
double d2sdrho2_constT() except +
|
||||
double d2sdrhodT() except +
|
||||
double d2sdT2_constrho() except +
|
||||
double d2sdT2_constp() except +
|
||||
double d2sdp2_constT() except +
|
||||
double d2sdTdp() except +
|
||||
|
||||
## ----------------------------------------
|
||||
## Derivatives along the saturation curve
|
||||
## ----------------------------------------
|
||||
|
||||
## Derivative of temperature w.r.t. pressure along saturation curve
|
||||
double dTdp_along_sat() except +ValueError
|
||||
## Second derivative of temperature w.r.t. pressure along saturation curve
|
||||
double d2Tdp2_along_sat() except +ValueError
|
||||
## Partial derivative w.r.t. pressure of dTdp along saturation curve
|
||||
double ddp_dTdp_along_sat() except +ValueError
|
||||
## Partial derivative w.r.t. temperature of dTdp along saturation curve
|
||||
double ddT_dTdp_along_sat() except +ValueError
|
||||
|
||||
double dhdp_along_sat_vapor() except +ValueError
|
||||
double dhdp_along_sat_liquid() except +ValueError
|
||||
double d2hdp2_along_sat_vapor() except +ValueError
|
||||
double d2hdp2_along_sat_liquid() except +ValueError
|
||||
|
||||
double dsdp_along_sat_vapor() except +ValueError
|
||||
double dsdp_along_sat_liquid() except +ValueError
|
||||
double d2sdp2_along_sat_vapor() except +ValueError
|
||||
double d2sdp2_along_sat_liquid() except +ValueError
|
||||
|
||||
double drhodp_along_sat_vapor() except +ValueError
|
||||
double drhodp_along_sat_liquid() except +ValueError
|
||||
double d2rhodp2_along_sat_vapor() except +ValueError
|
||||
double d2rhodp2_along_sat_liquid() except +ValueError
|
||||
|
||||
double drhodT_along_sat_vapor() except +ValueError
|
||||
double drhodT_along_sat_liquid() except +ValueError
|
||||
|
||||
## Clear out all the cached values
|
||||
void clear_cache()
|
||||
|
||||
## ----------------------------------------
|
||||
## Helmholtz Energy Derivatives
|
||||
## ----------------------------------------
|
||||
|
||||
double phi0(double tau, double delta)
|
||||
double dphi0_dDelta(double tau, double delta)
|
||||
double dphi0_dTau(double tau, double delta)
|
||||
double d2phi0_dDelta2(double tau, double delta)
|
||||
double d2phi0_dDelta_dTau(double tau, double delta)
|
||||
double d2phi0_dTau2(double tau, double delta)
|
||||
double d3phi0_dDelta3(double tau, double delta)
|
||||
double d3phi0_dDelta2_dTau(double tau, double delta)
|
||||
double d3phi0_dDelta_dTau2(double tau, double delta)
|
||||
double d3phi0_dTau3(double tau, double delta)
|
||||
|
||||
double phir(double tau, double delta)
|
||||
double dphir_dDelta(double tau, double delta)
|
||||
double dphir_dTau(double tau, double delta)
|
||||
double d2phir_dDelta2(double tau, double delta)
|
||||
double d2phir_dDelta_dTau(double tau, double delta)
|
||||
double d2phir_dTau2(double tau, double delta)
|
||||
double d3phir_dDelta3(double tau, double delta)
|
||||
double d3phir_dDelta2_dTau(double tau, double delta)
|
||||
double d3phir_dDelta_dTau2(double tau, double delta)
|
||||
double d3phir_dTau3(double tau, double delta)
|
||||
|
||||
cdef cppclass CoolPropStateClassSI:
|
||||
|
||||
bint flag_SinglePhase, flag_TwoPhase
|
||||
|
||||
## Bulk values
|
||||
double _rho,_T,_p,_Q,_h,_s, tau, delta
|
||||
|
||||
## Phase flags
|
||||
bint TwoPhase, SinglePhase
|
||||
|
||||
## Nullary Constructor
|
||||
CoolPropStateClassSI() except +
|
||||
|
||||
## Constructor with fluid name
|
||||
CoolPropStateClassSI(string FluidName) except +
|
||||
|
||||
## Property updater
|
||||
## Uses the indices in CoolProp for the input parameters
|
||||
void update(long iInput1, double Value1, long iInput2, double Value2) except +ValueError
|
||||
|
||||
## Property accessors for saturation parameters directly
|
||||
## These all must be calculated every time if the state is saturated or two-phase
|
||||
double rhoL() except +
|
||||
double rhoV() except +
|
||||
double pL() except +
|
||||
double pV() except +
|
||||
double TL() except +
|
||||
double TV() except +
|
||||
## Derived parameters for the saturation states
|
||||
double hL() except +
|
||||
double hV() except +
|
||||
double sL() except +
|
||||
double sV() except +
|
||||
|
||||
## Bulk properties accessors - temperature and density are directly calculated every time
|
||||
## All other parameters are calculated on an as-needed basis
|
||||
## If single-phase, just plug into the EOS, otherwise need to do two-phase analysis
|
||||
double T() except +
|
||||
double rho() except +
|
||||
double p() except +
|
||||
double h() except +
|
||||
double s() except +
|
||||
double cp() except +
|
||||
double cv() except +
|
||||
double speed_sound() except +
|
||||
double keyed_output(long iOutput) except +
|
||||
long phase() except +
|
||||
|
||||
## ----------------------------------------
|
||||
## TTSE LUT things
|
||||
## ----------------------------------------
|
||||
|
||||
## Enable the TTSE
|
||||
void enable_TTSE_LUT() except +
|
||||
## Check if TTSE is enabled
|
||||
bint isenabled_TTSE_LUT() except +
|
||||
## Disable the TTSE
|
||||
void disable_TTSE_LUT() except +
|
||||
## Interpolate within the TTSE LUT
|
||||
double interpolate_in_TTSE_LUT(long iParam, long iInput1, double Input1, long iInput2, double Input2) except +
|
||||
|
||||
## ----------------------------------------
|
||||
## Derivatives of properties
|
||||
## ----------------------------------------
|
||||
|
||||
double dvdp_constT() except +
|
||||
double dvdT_constp() except +
|
||||
|
||||
double drhodT_constp() except +
|
||||
double drhodh_constp() except +
|
||||
double drhodp_consth() except +
|
||||
double drhodp_constT() except +
|
||||
double d2rhodp2_constT() except +
|
||||
double d2rhodTdp() except +
|
||||
double d2rhodhdQ() except +
|
||||
double d2rhodpdQ() except +
|
||||
double d2rhodhdp() except +
|
||||
double d2rhodh2_constp() except +
|
||||
double d2rhodT2_constp() except +
|
||||
|
||||
double dpdrho_constT() except +
|
||||
double dpdrho_consth() except +
|
||||
double dpdT_constrho() except +
|
||||
double dpdT_consth() except +
|
||||
double d2pdrho2_constT() except +
|
||||
double d2pdrhodT() except +
|
||||
double d2pdT2_constrho() except +
|
||||
|
||||
double dhdrho_constT() except +
|
||||
double dhdrho_constp() except +
|
||||
double dhdT_constrho() except +
|
||||
double dhdT_constp() except +
|
||||
double dhdp_constT() except +
|
||||
double d2hdrho2_constT() except +
|
||||
double d2hdrhodT() except +
|
||||
double d2hdT2_constrho() except +
|
||||
double d2hdT2_constp() except +
|
||||
double d2hdp2_constT() except +
|
||||
double d2hdTdp() except +
|
||||
|
||||
double dsdrho_constT() except +
|
||||
double dsdT_constrho() except +
|
||||
double dsdrho_constp() except +
|
||||
double dsdT_constp() except +
|
||||
double dsdp_constT() except +
|
||||
double d2sdrho2_constT() except +
|
||||
double d2sdrhodT() except +
|
||||
double d2sdT2_constrho() except +
|
||||
double d2sdT2_constp() except +
|
||||
double d2sdp2_constT() except +
|
||||
double d2sdTdp() except +
|
||||
|
||||
## ----------------------------------------
|
||||
## Derivatives along the saturation curve
|
||||
## ----------------------------------------
|
||||
|
||||
## Derivative of temperature w.r.t. pressure along saturation curve
|
||||
double dTdp_along_sat() except +ValueError
|
||||
## Second derivative of temperature w.r.t. pressure along saturation curve
|
||||
double d2Tdp2_along_sat() except +ValueError
|
||||
## Partial derivative w.r.t. pressure of dTdp along saturation curve
|
||||
double ddp_dTdp_along_sat() except +ValueError
|
||||
## Partial derivative w.r.t. temperature of dTdp along saturation curve
|
||||
double ddT_dTdp_along_sat() except +ValueError
|
||||
|
||||
double dhdp_along_sat_vapor() except +ValueError
|
||||
double dhdp_along_sat_liquid() except +ValueError
|
||||
double d2hdp2_along_sat_vapor() except +ValueError
|
||||
double d2hdp2_along_sat_liquid() except +ValueError
|
||||
|
||||
double dsdp_along_sat_vapor() except +ValueError
|
||||
double dsdp_along_sat_liquid() except +ValueError
|
||||
double d2sdp2_along_sat_vapor() except +ValueError
|
||||
double d2sdp2_along_sat_liquid() except +ValueError
|
||||
|
||||
double drhodp_along_sat_vapor() except +ValueError
|
||||
double drhodp_along_sat_liquid() except +ValueError
|
||||
double d2rhodp2_along_sat_vapor() except +ValueError
|
||||
double d2rhodp2_along_sat_liquid() except +ValueError
|
||||
|
||||
double drhodT_along_sat_vapor() except +ValueError
|
||||
double drhodT_along_sat_liquid() except +ValueError
|
||||
|
||||
## Clear out all the cached values
|
||||
void clear_cache()
|
||||
|
||||
## ----------------------------------------
|
||||
## Helmholtz Energy Derivatives
|
||||
## ----------------------------------------
|
||||
|
||||
double phi0(double tau, double delta)
|
||||
double dphi0_dDelta(double tau, double delta)
|
||||
double dphi0_dTau(double tau, double delta)
|
||||
double d2phi0_dDelta2(double tau, double delta)
|
||||
double d2phi0_dDelta_dTau(double tau, double delta)
|
||||
double d2phi0_dTau2(double tau, double delta)
|
||||
double d3phi0_dDelta3(double tau, double delta)
|
||||
double d3phi0_dDelta2_dTau(double tau, double delta)
|
||||
double d3phi0_dDelta_dTau2(double tau, double delta)
|
||||
double d3phi0_dTau3(double tau, double delta)
|
||||
|
||||
double phir(double tau, double delta)
|
||||
double dphir_dDelta(double tau, double delta)
|
||||
double dphir_dTau(double tau, double delta)
|
||||
double d2phir_dDelta2(double tau, double delta)
|
||||
double d2phir_dDelta_dTau(double tau, double delta)
|
||||
double d2phir_dTau2(double tau, double delta)
|
||||
double d3phir_dDelta3(double tau, double delta)
|
||||
double d3phir_dDelta2_dTau(double tau, double delta)
|
||||
double d3phir_dDelta_dTau2(double tau, double delta)
|
||||
double d3phir_dTau3(double tau, double delta)
|
||||
|
||||
cdef extern from "CoolPropDLL.h":
|
||||
int _set_reference_stateS "set_reference_stateS"(char *, char *)
|
||||
int _set_reference_stateD "set_reference_stateD"(char *, double T, double rho, double h0, double s0)
|
||||
int _get_standard_unit_system "get_standard_unit_system"()
|
||||
|
||||
cdef extern from "CoolPropTools.h":
|
||||
bint _ValidNumber "ValidNumber"(double)
|
||||
|
||||
cdef extern from "Units.h":
|
||||
double _fromSIints "convert_from_SI_to_unit_system"(long input, double value, int new_system)
|
||||
double _toSIints "convert_from_unit_system_to_SI"(long input, double value, int old_system)
|
||||
double _fromSI "convert_from_SI_to_unit_system"(string input, double value, string new_system)
|
||||
double _toSI "convert_from_unit_system_to_SI"(string input, double value, string old_system)
|
||||
|
||||
cdef extern from "CoolProp.h":
|
||||
void _set_standard_unit_system "set_standard_unit_system"(int unit_system)
|
||||
|
||||
double _PropsSI "PropsSI"(string Output, string Name1, double Prop1, string Name2, double Prop2, string Ref)
|
||||
double _Props1SI "Props1SI"(string Ref, string Output)
|
||||
|
||||
double _IProps "IProps"(long Output, long Name1, double Prop1, long Name2, double Prop2, long Ref)
|
||||
|
||||
double _Props "Props"(string Output, string Name1, double Prop1, string Name2, double Prop2, string Ref)
|
||||
double _Props1 "Props1"(string Ref, string Output)
|
||||
|
||||
string _Phase "Phase"(char *Fluid, double T, double p)
|
||||
string _Phase_Tp "Phase_Tp"(string Fluid, double T, double p)
|
||||
string _Phase_Trho "Phase_Trho"(string Fluid, double T, double rho)
|
||||
double _DerivTerms "DerivTerms"(char* Term, double T, double rho, char* Ref)
|
||||
|
||||
# Conversion functions
|
||||
double _F2K "F2K"(double T_F)
|
||||
double _K2F "K2F"(double T)
|
||||
|
||||
string _get_global_param_string "get_global_param_string"(string ParamName)
|
||||
string _get_fluid_param_string "get_fluid_param_string"(string ParamName, string FluidName)
|
||||
|
||||
long _set_phase "set_phase" (string phase)
|
||||
long _get_Fluid_index "get_Fluid_index" (string Fluid)
|
||||
long _get_param_index "get_param_index" (string param)
|
||||
|
||||
string _get_TTSE_mode "get_TTSE_mode"(string Fluid)
|
||||
int _set_TTSE_mode "set_TTSE_mode"(char* Fluid, char* Value)
|
||||
|
||||
string _add_REFPROP_fluid "add_REFPROP_fluid"(string FluidName) except +
|
||||
|
||||
int _get_debug_level "get_debug_level"()
|
||||
void _set_debug_level "set_debug_level"(int level)
|
||||
|
||||
string _get_BibTeXKey "get_BibTeXKey"(string Ref, string key)
|
||||
|
||||
# Convenience functions
|
||||
int _IsFluidType "IsFluidType"(char* Ref, char* Type)
|
||||
|
||||
# Enable the TTSE
|
||||
bint _enable_TTSE_LUT "enable_TTSE_LUT"(char *FluidName)
|
||||
# Check if TTSE is enabled
|
||||
bint _isenabled_TTSE_LUT "isenabled_TTSE_LUT"(char *FluidName)
|
||||
# Disable the TTSE
|
||||
bint _disable_TTSE_LUT "disable_TTSE_LUT"(char *FluidName)
|
||||
|
||||
# Enable the writing of TTSE tables to file for this fluid
|
||||
bint _enable_TTSE_LUT_writing "enable_TTSE_LUT_writing"(char *FluidName)
|
||||
# Check if the writing of TTSE tables to file is enabled
|
||||
bint _isenabled_TTSE_LUT_writing "isenabled_TTSE_LUT_writing"(char *FluidName)
|
||||
# Disable the writing of TTSE tables to file for this fluid
|
||||
bint _disable_TTSE_LUT_writing "disable_TTSE_LUT_writing"(char *FluidName)
|
||||
|
||||
# Over-ride the default size of both of the saturation LUT
|
||||
bint _set_TTSESat_LUT_size "set_TTSESat_LUT_size"(char *FluidName, int)
|
||||
# Over-ride the default size of the single-phase LUT
|
||||
bint _set_TTSESinglePhase_LUT_size "set_TTSESinglePhase_LUT_size"(char *FluidName, int Np, int Nh)
|
||||
# Over-ride the default range of the single-phase LUT
|
||||
bint _set_TTSESinglePhase_LUT_range "set_TTSESinglePhase_LUT_range"(char *FluidName, double hmin, double hmax, double pmin, double pmax)
|
||||
# Get the current range of the single-phase LUT
|
||||
bint _get_TTSESinglePhase_LUT_range "get_TTSESinglePhase_LUT_range"(char *FluidName, double *hmin, double *hmax, double *pmin, double *pmax)
|
||||
|
||||
cdef extern from "HumidAirProp.h":
|
||||
double _HAProps "HAProps"(char *OutputName, char *Input1Name, double Input1, char *Input2Name, double Input2, char *Input3Name, double Input3)
|
||||
double _HAProps_Aux "HAProps_Aux"(char* Name,double T, double p, double W, char *units)
|
||||
double _cair_sat "cair_sat"(double T)
|
||||
|
||||
cdef class State:
|
||||
cdef CoolPropStateClassSI CPS
|
||||
cdef readonly string Fluid, phase
|
||||
cdef int iFluid,iParam1,iParam2,iOutput
|
||||
cdef double T_, rho_, p_
|
||||
cdef readonly bint is_CPFluid
|
||||
|
||||
cpdef set_Fluid(self, string_like Fluid)
|
||||
cpdef speed_test(self, int N)
|
||||
cpdef update(self, dict params)
|
||||
cpdef update_ph(self, double p, double h)
|
||||
cpdef update_Trho(self, double T, double rho)
|
||||
cpdef State copy(self)
|
||||
cpdef double Props(self, long iOutput) except *
|
||||
cpdef long Phase(self) except *
|
||||
|
||||
cpdef double get_Q(self) except *
|
||||
cpdef double get_T(self) except *
|
||||
cpdef double get_p(self) except *
|
||||
cpdef double get_h(self) except *
|
||||
cpdef double get_rho(self) except *
|
||||
cpdef double get_s(self) except *
|
||||
cpdef double get_u(self) except *
|
||||
cpdef double get_visc(self) except *
|
||||
cpdef double get_cond(self) except *
|
||||
cpdef double get_cp(self) except *
|
||||
cpdef double get_cp0(self) except *
|
||||
cpdef double get_cv(self) except *
|
||||
cpdef double get_MM(self) except *
|
||||
cpdef double get_dpdT(self) except *
|
||||
cpdef double get_speed_sound(self) except *
|
||||
cpdef get_Tsat(self, double Q = *)
|
||||
cpdef get_subcooling(self)
|
||||
cpdef get_superheat(self)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,101 +0,0 @@
|
||||
from libcpp cimport bool
|
||||
from libcpp.string cimport string
|
||||
|
||||
cdef class PureFluidClass:
|
||||
cdef CoolPropStateClass CPS # hold a C++ instance which we're wrapping
|
||||
cpdef update(self, long iInput1, double Value1, long iInput2, double Value2)
|
||||
cpdef double rhoL(self)
|
||||
cpdef double rhoV(self)
|
||||
cpdef double pL(self)
|
||||
cpdef double pV(self)
|
||||
cpdef double TL(self)
|
||||
cpdef double TV(self)
|
||||
cpdef double sL(self)
|
||||
cpdef double sV(self)
|
||||
cpdef double hL(self)
|
||||
cpdef double hV(self)
|
||||
|
||||
## ----------------------------------------
|
||||
## Fluid property accessors
|
||||
## ----------------------------------------
|
||||
|
||||
cpdef double T(self)
|
||||
cpdef double rho(self)
|
||||
cpdef double p(self)
|
||||
cpdef double h(self)
|
||||
cpdef double s(self)
|
||||
cpdef double cp(self)
|
||||
cpdef double cv(self)
|
||||
cpdef double speed_sound(self)
|
||||
|
||||
## ----------------------------------------
|
||||
## TTSE LUT things
|
||||
## ----------------------------------------
|
||||
|
||||
|
||||
cpdef enable_TTSE_LUT(self) # Enable the TTSE
|
||||
cpdef bool isenabled_TTSE_LUT(self) # Check if TTSE is enabled
|
||||
cpdef disable_TTSE_LUT(self) # Disable the TTSE
|
||||
|
||||
cpdef double dTdp_along_sat(self)
|
||||
cpdef double d2Tdp2_along_sat(self)
|
||||
|
||||
cpdef double dhdp_along_sat_vapor(self)
|
||||
cpdef double dhdp_along_sat_liquid(self)
|
||||
cpdef double d2hdp2_along_sat_vapor(self)
|
||||
cpdef double d2hdp2_along_sat_liquid(self)
|
||||
|
||||
cpdef double dsdp_along_sat_vapor(self)
|
||||
cpdef double dsdp_along_sat_liquid(self)
|
||||
cpdef double d2sdp2_along_sat_vapor(self)
|
||||
cpdef double d2sdp2_along_sat_liquid(self)
|
||||
|
||||
cpdef double drhodp_along_sat_vapor(self)
|
||||
cpdef double drhodp_along_sat_liquid(self)
|
||||
cpdef double d2rhodp2_along_sat_vapor(self)
|
||||
cpdef double d2rhodp2_along_sat_liquid(self)
|
||||
|
||||
cpdef double drhodT_along_sat_vapor(self)
|
||||
cpdef double drhodT_along_sat_liquid(self)
|
||||
|
||||
cpdef double drhodT_constp(self)
|
||||
cpdef double drhodp_constT(self)
|
||||
cpdef double d2rhodp2_constT(self)
|
||||
cpdef double d2rhodTdp(self)
|
||||
cpdef double d2rhodT2_constp(self)
|
||||
cpdef double d2rhodhdQ(self)
|
||||
cpdef double d2rhodpdQ(self)
|
||||
cpdef double d2rhodhdp(self)
|
||||
cpdef double d2rhodh2_constp(self)
|
||||
|
||||
cpdef double dpdrho_constT(self)
|
||||
cpdef double dpdrho_consth(self)
|
||||
cpdef double dpdT_constrho(self)
|
||||
cpdef double dpdT_consth(self)
|
||||
cpdef double d2pdrho2_constT(self)
|
||||
cpdef double d2pdrhodT(self)
|
||||
cpdef double d2pdT2_constrho(self)
|
||||
|
||||
cpdef double dhdrho_constT(self)
|
||||
cpdef double dhdrho_constp(self)
|
||||
cpdef double dhdT_constrho(self)
|
||||
cpdef double dhdT_constp(self)
|
||||
cpdef double dhdp_constT(self)
|
||||
cpdef double d2hdrho2_constT(self)
|
||||
cpdef double d2hdrhodT(self)
|
||||
cpdef double d2hdT2_constrho(self)
|
||||
cpdef double d2hdT2_constp(self)
|
||||
cpdef double d2hdp2_constT(self)
|
||||
cpdef double d2hdTdp(self)
|
||||
|
||||
cpdef double dsdrho_constT(self)
|
||||
cpdef double dsdT_constrho(self)
|
||||
cpdef double dsdrho_constp(self)
|
||||
cpdef double dsdT_constp(self)
|
||||
cpdef double dsdp_constT(self)
|
||||
cpdef double d2sdrho2_constT(self)
|
||||
cpdef double d2sdrhodT(self)
|
||||
cpdef double d2sdT2_constrho(self)
|
||||
cpdef double d2sdT2_constp(self)
|
||||
cpdef double d2sdp2_constT(self)
|
||||
cpdef double d2sdTdp(self)
|
||||
@@ -1,189 +0,0 @@
|
||||
|
||||
cdef class PureFluidClass:
|
||||
def __cinit__(self, string name):
|
||||
self.CPS = CoolPropStateClass(name)
|
||||
|
||||
cpdef update(self, long iInput1, double Value1, long iInput2, double Value2):
|
||||
self.CPS.update(iInput1,Value1,iInput2,Value2)
|
||||
|
||||
cpdef double rhoL(self):
|
||||
return self.CPS.rhoL()
|
||||
cpdef double rhoV(self):
|
||||
return self.CPS.rhoV()
|
||||
cpdef double pL(self):
|
||||
return self.CPS.pL()
|
||||
cpdef double pV(self):
|
||||
return self.CPS.pV()
|
||||
cpdef double TL(self):
|
||||
return self.CPS.TL()
|
||||
cpdef double TV(self):
|
||||
return self.CPS.TV()
|
||||
cpdef double sL(self):
|
||||
return self.CPS.sL()
|
||||
cpdef double sV(self):
|
||||
return self.CPS.sV()
|
||||
cpdef double hL(self):
|
||||
return self.CPS.hL()
|
||||
cpdef double hV(self):
|
||||
return self.CPS.hV()
|
||||
|
||||
## ----------------------------------------
|
||||
## Fluid property accessors
|
||||
## ----------------------------------------
|
||||
|
||||
cpdef double T(self) except *:
|
||||
return self.CPS.T()
|
||||
cpdef double rho(self) except *:
|
||||
return self.CPS.rho()
|
||||
cpdef double p(self) except *:
|
||||
return self.CPS.p()
|
||||
cpdef double h(self) except *:
|
||||
return self.CPS.h()
|
||||
cpdef double s(self) except *:
|
||||
return self.CPS.s()
|
||||
cpdef double cp(self) except *:
|
||||
return self.CPS.cp()
|
||||
cpdef double cv(self) except *:
|
||||
return self.CPS.cv()
|
||||
cpdef double speed_sound(self) except *:
|
||||
return self.CPS.speed_sound()
|
||||
|
||||
cpdef double keyed_output(self, long iOutput) except *:
|
||||
return self.CPS.keyed_output(iOutput)
|
||||
cpdef long phase(self) except *:
|
||||
return self.CPS.phase()
|
||||
|
||||
## ----------------------------------------
|
||||
## TTSE LUT things
|
||||
## ----------------------------------------
|
||||
|
||||
# Enable the TTSE
|
||||
cpdef enable_TTSE_LUT(self):
|
||||
self.CPS.enable_TTSE_LUT()
|
||||
|
||||
# Check if TTSE is enabled
|
||||
cpdef bint isenabled_TTSE_LUT(self):
|
||||
return self.CPS.isenabled_TTSE_LUT()
|
||||
|
||||
# Disable the TTSE
|
||||
cpdef disable_TTSE_LUT(self):
|
||||
self.CPS.disable_TTSE_LUT()
|
||||
|
||||
cpdef double dTdp_along_sat(self):
|
||||
return self.CPS.dTdp_along_sat()
|
||||
cpdef double d2Tdp2_along_sat(self):
|
||||
return self.CPS.d2Tdp2_along_sat()
|
||||
|
||||
cpdef double dhdp_along_sat_vapor(self):
|
||||
return self.CPS.dhdp_along_sat_vapor()
|
||||
cpdef double dhdp_along_sat_liquid(self):
|
||||
return self.CPS.dhdp_along_sat_liquid()
|
||||
cpdef double d2hdp2_along_sat_vapor(self):
|
||||
return self.CPS.d2hdp2_along_sat_vapor()
|
||||
cpdef double d2hdp2_along_sat_liquid(self):
|
||||
return self.CPS.d2hdp2_along_sat_liquid()
|
||||
|
||||
cpdef double dsdp_along_sat_vapor(self) except *:
|
||||
return self.CPS.dsdp_along_sat_vapor()
|
||||
cpdef double dsdp_along_sat_liquid(self) except *:
|
||||
return self.CPS.dsdp_along_sat_liquid()
|
||||
cpdef double d2sdp2_along_sat_vapor(self) except *:
|
||||
print self.CPS.d2sdp2_along_sat_vapor()
|
||||
return self.CPS.d2sdp2_along_sat_vapor()
|
||||
cpdef double d2sdp2_along_sat_liquid(self) except *:
|
||||
return self.CPS.d2sdp2_along_sat_liquid()
|
||||
|
||||
cpdef double drhodp_along_sat_vapor(self) except *:
|
||||
return self.CPS.drhodp_along_sat_vapor()
|
||||
cpdef double drhodp_along_sat_liquid(self) except *:
|
||||
return self.CPS.drhodp_along_sat_liquid()
|
||||
cpdef double d2rhodp2_along_sat_vapor(self) except *:
|
||||
return self.CPS.d2rhodp2_along_sat_vapor()
|
||||
cpdef double d2rhodp2_along_sat_liquid(self) except *:
|
||||
return self.CPS.d2rhodp2_along_sat_liquid()
|
||||
|
||||
cpdef double drhodT_along_sat_vapor(self) except *:
|
||||
return self.CPS.drhodT_along_sat_vapor()
|
||||
cpdef double drhodT_along_sat_liquid(self) except *:
|
||||
return self.CPS.drhodT_along_sat_liquid()
|
||||
|
||||
cpdef double drhodT_constp(self) except *:
|
||||
return self.CPS.drhodT_constp()
|
||||
cpdef double drhodp_constT(self) except *:
|
||||
return self.CPS.drhodp_constT()
|
||||
cpdef double d2rhodp2_constT(self) except *:
|
||||
return self.CPS.d2rhodp2_constT()
|
||||
cpdef double d2rhodTdp(self) except *:
|
||||
return self.CPS.d2rhodTdp()
|
||||
cpdef double d2rhodT2_constp(self) except *:
|
||||
return self.CPS.d2rhodT2_constp()
|
||||
cpdef double d2rhodhdQ(self) except *:
|
||||
return self.CPS.d2rhodhdQ()
|
||||
cpdef double d2rhodpdQ(self) except *:
|
||||
return self.CPS.d2rhodpdQ()
|
||||
cpdef double d2rhodhdp(self) except *:
|
||||
return self.CPS.d2rhodhdp()
|
||||
cpdef double d2rhodh2_constp(self) except *:
|
||||
return self.CPS.d2rhodh2_constp()
|
||||
|
||||
cpdef double dpdrho_constT(self) except *:
|
||||
return self.CPS.dpdrho_constT()
|
||||
cpdef double dpdrho_consth(self) except *:
|
||||
return self.CPS.dpdrho_consth()
|
||||
cpdef double dpdT_constrho(self) except *:
|
||||
return self.CPS.dpdT_constrho()
|
||||
cpdef double dpdT_consth(self) except *:
|
||||
return self.CPS.dpdT_consth()
|
||||
cpdef double d2pdrho2_constT(self) except *:
|
||||
return self.CPS.d2pdrho2_constT()
|
||||
cpdef double d2pdrhodT(self) except *:
|
||||
return self.CPS.d2pdrhodT()
|
||||
cpdef double d2pdT2_constrho(self) except *:
|
||||
return self.CPS.d2pdT2_constrho()
|
||||
|
||||
cpdef double dhdrho_constT(self) except *:
|
||||
return self.CPS.dhdrho_constT()
|
||||
cpdef double dhdrho_constp(self) except *:
|
||||
return self.CPS.dhdrho_constp()
|
||||
cpdef double dhdT_constrho(self) except *:
|
||||
return self.CPS.dhdT_constrho()
|
||||
cpdef double dhdT_constp(self) except *:
|
||||
return self.CPS.dhdT_constp()
|
||||
cpdef double dhdp_constT(self) except *:
|
||||
return self.CPS.dhdp_constT()
|
||||
cpdef double d2hdrho2_constT(self) except *:
|
||||
return self.CPS.d2hdrho2_constT()
|
||||
cpdef double d2hdrhodT(self) except *:
|
||||
return self.CPS.d2hdrhodT()
|
||||
cpdef double d2hdT2_constrho(self) except *:
|
||||
return self.CPS.d2hdT2_constrho()
|
||||
cpdef double d2hdT2_constp(self) except *:
|
||||
return self.CPS.d2hdT2_constp()
|
||||
cpdef double d2hdp2_constT(self) except *:
|
||||
return self.CPS.d2hdp2_constT()
|
||||
cpdef double d2hdTdp(self) except *:
|
||||
return self.CPS.d2hdTdp()
|
||||
|
||||
cpdef double dsdrho_constT(self) except *:
|
||||
return self.CPS.dsdrho_constT()
|
||||
cpdef double dsdT_constrho(self) except *:
|
||||
return self.CPS.dsdT_constrho()
|
||||
cpdef double dsdrho_constp(self) except *:
|
||||
return self.CPS.dsdrho_constp()
|
||||
cpdef double dsdT_constp(self) except *:
|
||||
return self.CPS.dsdT_constp()
|
||||
cpdef double dsdp_constT(self) except *:
|
||||
return self.CPS.dsdp_constT()
|
||||
cpdef double d2sdrho2_constT(self) except *:
|
||||
return self.CPS.d2sdrho2_constT()
|
||||
cpdef double d2sdrhodT(self) except *:
|
||||
return self.CPS.d2sdrhodT()
|
||||
cpdef double d2sdT2_constrho(self) except *:
|
||||
return self.CPS.d2sdT2_constrho()
|
||||
cpdef double d2sdT2_constp(self) except *:
|
||||
return self.CPS.d2sdT2_constp()
|
||||
cpdef double d2sdp2_constT(self) except *:
|
||||
return self.CPS.d2sdp2_constT()
|
||||
cpdef double d2sdTdp(self) except *:
|
||||
return self.CPS.d2sdTdp()
|
||||
|
||||
@@ -1,470 +0,0 @@
|
||||
import wx
|
||||
import wx.grid
|
||||
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as WXCanvas
|
||||
from matplotlib.backends.backend_wxagg import NavigationToolbar2Wx as WXToolbar
|
||||
import matplotlib as mpl
|
||||
import CoolProp as CP
|
||||
from CoolProp.Plots.Plots import Ph, Ts
|
||||
from CoolProp.Plots import PsychChart
|
||||
import numpy as np
|
||||
|
||||
# Munge the system path if necessary to add the lib folder (only really needed
|
||||
# for packaging using cx_Freeze)
|
||||
#if os.path.exists('lib') and os.path.abspath(os.path.join(os.curdir,'lib')) not in os.:
|
||||
|
||||
class PlotPanel(wx.Panel):
|
||||
def __init__(self, parent, **kwargs):
|
||||
wx.Panel.__init__(self, parent, **kwargs)
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
self.figure = mpl.figure.Figure(dpi=100)
|
||||
self.canvas = WXCanvas(self, -1, self.figure)
|
||||
self.ax = self.figure.add_axes((0.15,0.15,0.8,0.8))
|
||||
#self.toolbar = WXToolbar(self.canvas)
|
||||
#self.toolbar.Realize()
|
||||
sizer.Add(self.canvas,1,wx.EXPAND)
|
||||
#sizer.Add(self.toolbar)
|
||||
self.SetSizer(sizer)
|
||||
sizer.Layout()
|
||||
|
||||
class TSPlotFrame(wx.Frame):
|
||||
def __init__(self, Fluid):
|
||||
wx.Frame.__init__(self, None,title='T-s plot: '+Fluid)
|
||||
|
||||
sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
self.PP = PlotPanel(self, size = (-1,-1))
|
||||
|
||||
sizer.Add(self.PP, 1, wx.EXPAND)
|
||||
self.SetSizer(sizer)
|
||||
Ts(str(Fluid),
|
||||
axis = self.PP.ax,
|
||||
Tmin = CP.CoolProp.Props(str(Fluid),'Ttriple')+0.01)
|
||||
sizer.Layout()
|
||||
|
||||
self.add_menu()
|
||||
|
||||
def add_menu(self):
|
||||
# Menu Bar
|
||||
self.MenuBar = wx.MenuBar()
|
||||
self.File = wx.Menu()
|
||||
|
||||
mnuItem = wx.MenuItem(self.File, -1, "Edit...", "", wx.ITEM_NORMAL)
|
||||
|
||||
self.File.AppendItem(mnuItem)
|
||||
self.MenuBar.Append(self.File, "File")
|
||||
|
||||
self.SetMenuBar(self.MenuBar)
|
||||
|
||||
class PsychOptions(wx.Dialog):
|
||||
def __init__(self,parent):
|
||||
wx.Dialog.__init__(self,parent)
|
||||
|
||||
self.build_contents()
|
||||
self.layout()
|
||||
|
||||
def build_contents(self):
|
||||
self.p_label = wx.StaticText(self,label='Pressure [kPa (absolute)]')
|
||||
self.p = wx.TextCtrl(self,value = '101.325')
|
||||
self.Tmin_label = wx.StaticText(self,label='Minimum dry bulb temperature [\xb0 C]')
|
||||
self.Tmin = wx.TextCtrl(self,value = '-10')
|
||||
self.Tmax_label = wx.StaticText(self,label='Maximum dry bulb temperature [\xb0 C]')
|
||||
self.Tmax = wx.TextCtrl(self,value = '60')
|
||||
self.GoButton = wx.Button(self,label='Accept')
|
||||
self.GoButton.Bind(wx.EVT_BUTTON,self.OnAccept)
|
||||
|
||||
def OnAccept(self, event):
|
||||
self.EndModal(wx.ID_OK)
|
||||
|
||||
def layout(self):
|
||||
sizer = wx.FlexGridSizer(cols = 2)
|
||||
sizer.AddMany([self.p_label,self.p,self.Tmin_label,self.Tmin,self.Tmax_label,self.Tmax])
|
||||
sizer.Add(self.GoButton)
|
||||
sizer.Layout()
|
||||
self.Fit()
|
||||
|
||||
class PsychPlotFrame(wx.Frame):
|
||||
def __init__(self,Tmin = 263.15,Tmax=333.15,p = 101.325, **kwargs):
|
||||
|
||||
wx.Frame.__init__(self, None, title='Psychrometric plot', **kwargs)
|
||||
|
||||
sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
self.PP = PlotPanel(self)
|
||||
|
||||
self.PP.figure.delaxes(self.PP.ax)
|
||||
self.PP.ax = self.PP.figure.add_axes((0.1,0.1,0.85,0.85))
|
||||
|
||||
sizer.Add(self.PP, 1, wx.EXPAND)
|
||||
self.SetSizer(sizer)
|
||||
|
||||
PsychChart.p = p
|
||||
PsychChart.Tdb = np.linspace(Tmin,Tmax)
|
||||
|
||||
SL = PsychChart.SaturationLine()
|
||||
SL.plot(self.PP.ax)
|
||||
|
||||
RHL = PsychChart.HumidityLines([0.05,0.1,0.15,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9])
|
||||
RHL.plot(self.PP.ax)
|
||||
|
||||
HL = PsychChart.EnthalpyLines(range(-20,100,10))
|
||||
HL.plot(self.PP.ax)
|
||||
|
||||
PF = PsychChart.PlotFormatting()
|
||||
PF.plot(self.PP.ax)
|
||||
|
||||
sizer.Layout()
|
||||
|
||||
self.add_menu()
|
||||
|
||||
self.PP.toolbar = WXToolbar(self.PP.canvas)
|
||||
self.PP.toolbar.Realize()
|
||||
self.PP.GetSizer().Add(self.PP.toolbar)
|
||||
|
||||
self.PP.Layout()
|
||||
|
||||
def add_menu(self):
|
||||
# Menu Bar
|
||||
self.MenuBar = wx.MenuBar()
|
||||
self.File = wx.Menu()
|
||||
|
||||
mnuItem = wx.MenuItem(self.File, -1, "Edit...", "", wx.ITEM_NORMAL)
|
||||
|
||||
self.File.AppendItem(mnuItem)
|
||||
self.MenuBar.Append(self.File, "File")
|
||||
|
||||
self.SetMenuBar(self.MenuBar)
|
||||
|
||||
class PHPlotFrame(wx.Frame):
|
||||
def __init__(self, Fluid):
|
||||
wx.Frame.__init__(self, None,title='p-h plot: '+Fluid)
|
||||
|
||||
sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
self.PP = PlotPanel(self, size = (-1,-1))
|
||||
|
||||
sizer.Add(self.PP, 1, wx.EXPAND)
|
||||
self.SetSizer(sizer)
|
||||
Ph(str(Fluid),
|
||||
axis = self.PP.ax,
|
||||
Tmin = CP.CoolProp.Props(str(Fluid),'Ttriple')+0.01)
|
||||
sizer.Layout()
|
||||
|
||||
self.add_menu()
|
||||
|
||||
def add_menu(self):
|
||||
# Menu Bar
|
||||
self.MenuBar = wx.MenuBar()
|
||||
self.File = wx.Menu()
|
||||
|
||||
mnuItem = wx.MenuItem(self.File, -1, "Edit...", "", wx.ITEM_NORMAL)
|
||||
|
||||
self.File.AppendItem(mnuItem)
|
||||
self.MenuBar.Append(self.File, "File")
|
||||
|
||||
self.SetMenuBar(self.MenuBar)
|
||||
|
||||
def overlay_points(self):
|
||||
pass
|
||||
|
||||
def overlay_cycle(self):
|
||||
pass
|
||||
|
||||
class SimpleGrid(wx.grid.Grid):
|
||||
def __init__(self, parent, ncol = 20, nrow = 8):
|
||||
wx.grid.Grid.__init__(self, parent)
|
||||
|
||||
self.CreateGrid(ncol, nrow)
|
||||
[self.SetCellValue(i,j,'0.0') for i in range(20) for j in range(8)]
|
||||
|
||||
class SaturationTableDialog(wx.Dialog):
|
||||
def __init__(self, parent):
|
||||
wx.Dialog.__init__(self,parent)
|
||||
|
||||
self.FluidLabel = wx.StaticText(self,label = "Fluid")
|
||||
self.FluidCombo = wx.ComboBox(self)
|
||||
self.FluidCombo.AppendItems(sorted(CP.__fluids__))
|
||||
self.FluidCombo.SetEditable(False)
|
||||
self.TtripleLabel = wx.StaticText(self,label = "Critical Temperature [K]")
|
||||
self.TtripleValue = wx.TextCtrl(self)
|
||||
self.TtripleValue.Enable(False)
|
||||
self.TcritLabel = wx.StaticText(self,label = "Critical Temperature [K]")
|
||||
self.TcritValue = wx.TextCtrl(self)
|
||||
self.TcritValue.Enable(False)
|
||||
self.NvalsLabel = wx.StaticText(self,label = "Number of values")
|
||||
self.NvalsValue = wx.TextCtrl(self)
|
||||
self.TminLabel = wx.StaticText(self,label = "Minimum Temperature [K]")
|
||||
self.TminValue = wx.TextCtrl(self)
|
||||
self.TmaxLabel = wx.StaticText(self,label = "Maximum Temperature [K]")
|
||||
self.TmaxValue = wx.TextCtrl(self)
|
||||
|
||||
self.Accept = wx.Button(self, label ="Accept")
|
||||
|
||||
sizer = wx.FlexGridSizer(cols = 2)
|
||||
sizer.AddMany([self.FluidLabel,self.FluidCombo,
|
||||
self.TtripleLabel,self.TtripleValue,
|
||||
self.TcritLabel, self.TcritValue])
|
||||
sizer.AddSpacer(10)
|
||||
sizer.AddSpacer(10)
|
||||
sizer.AddMany([self.NvalsLabel,self.NvalsValue,
|
||||
self.TminLabel, self.TminValue,
|
||||
self.TmaxLabel, self.TmaxValue])
|
||||
sizer.Add(self.Accept)
|
||||
|
||||
self.Bind(wx.EVT_COMBOBOX, self.OnSelectFluid)
|
||||
self.Bind(wx.EVT_BUTTON, self.OnAccept)
|
||||
|
||||
self.SetSizer(sizer)
|
||||
sizer.Layout()
|
||||
self.Fit()
|
||||
|
||||
#Bind a key-press event to all objects to get Esc
|
||||
children = self.GetChildren()
|
||||
for child in children:
|
||||
child.Bind(wx.EVT_KEY_UP, self.OnKeyPress)
|
||||
|
||||
def OnKeyPress(self,event = None):
|
||||
""" cancel if Escape key is pressed """
|
||||
event.Skip()
|
||||
if event.GetKeyCode() == wx.WXK_ESCAPE:
|
||||
self.EndModal(wx.ID_CANCEL)
|
||||
|
||||
def get_values(self):
|
||||
Fluid = str(self.FluidCombo.GetStringSelection())
|
||||
if Fluid:
|
||||
N = float(self.NvalsValue.GetValue())
|
||||
Tmin = float(self.TminValue.GetValue())
|
||||
Tmax = float(self.TmaxValue.GetValue())
|
||||
Tvals = np.linspace(Tmin, Tmax, N)
|
||||
return Fluid, Tvals
|
||||
else:
|
||||
return '',[]
|
||||
|
||||
def OnCheckTmin(self):
|
||||
pass
|
||||
|
||||
def OnCheckTmax(self):
|
||||
pass
|
||||
|
||||
def OnAccept(self, event = None):
|
||||
self.EndModal(wx.ID_OK)
|
||||
|
||||
def OnSelectFluid(self, event = None):
|
||||
Fluid = str(self.FluidCombo.GetStringSelection())
|
||||
if Fluid:
|
||||
Tcrit = CP.CoolProp.Props(Fluid,'Tcrit')
|
||||
Ttriple = CP.CoolProp.Props(Fluid,'Ttriple')
|
||||
self.TcritValue.SetValue(str(Tcrit))
|
||||
self.TtripleValue.SetValue(str(Ttriple))
|
||||
self.NvalsValue.SetValue('100')
|
||||
self.TminValue.SetValue(str(Ttriple + 0.01))
|
||||
self.TmaxValue.SetValue(str(Tcrit - 0.01))
|
||||
|
||||
class SaturationTable(wx.Frame):
|
||||
def __init__(self, parent):
|
||||
wx.Frame.__init__(self, parent)
|
||||
self.Fluid, self.Tvals = self.OnSelect()
|
||||
if self.Fluid:
|
||||
self.tbl = SimpleGrid(self,
|
||||
ncol = len(self.Tvals)
|
||||
)
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
sizer.Add(self.tbl,1,wx.EXPAND)
|
||||
self.SetSizer(sizer)
|
||||
sizer.Layout()
|
||||
self.build()
|
||||
self.add_menu()
|
||||
else:
|
||||
self.Destroy()
|
||||
|
||||
|
||||
def OnSelect(self, event = None):
|
||||
dlg = SaturationTableDialog(None)
|
||||
if dlg.ShowModal() == wx.ID_OK:
|
||||
Fluid,Tvals = dlg.get_values()
|
||||
cancel = False
|
||||
else:
|
||||
cancel = True
|
||||
dlg.Destroy()
|
||||
if not cancel:
|
||||
return Fluid,Tvals
|
||||
else:
|
||||
return None,None
|
||||
|
||||
def build(self):
|
||||
self.SetTitle('Saturation Table: '+self.Fluid)
|
||||
self.tbl.SetColLabelValue(0, "Temperature\n[K]")
|
||||
self.tbl.SetColLabelValue(1, "Liquid Pressure\n[kPa]")
|
||||
self.tbl.SetColLabelValue(2, "Vapor Pressure\n[kPa]")
|
||||
self.tbl.SetColLabelValue(3, "Liquid Density\n[kg/m3]")
|
||||
self.tbl.SetColLabelValue(4, "Vapor Density\n[kg/m3]")
|
||||
|
||||
for i,T in enumerate(self.Tvals):
|
||||
Fluid = self.Fluid
|
||||
pL = CP.CoolProp.Props('P','T',T,'Q',0,Fluid)
|
||||
pV = CP.CoolProp.Props('P','T',T,'Q',1,Fluid)
|
||||
rhoL = CP.CoolProp.Props('D','T',T,'Q',0,Fluid)
|
||||
rhoV = CP.CoolProp.Props('D','T',T,'Q',1,Fluid)
|
||||
|
||||
self.tbl.SetCellValue(i,0,str(T))
|
||||
self.tbl.SetCellValue(i,1,str(pL))
|
||||
self.tbl.SetCellValue(i,2,str(pV))
|
||||
self.tbl.SetCellValue(i,3,str(rhoL))
|
||||
self.tbl.SetCellValue(i,4,str(rhoV))
|
||||
|
||||
def add_menu(self):
|
||||
# Menu Bar
|
||||
self.MenuBar = wx.MenuBar()
|
||||
self.File = wx.Menu()
|
||||
|
||||
mnuItem0 = wx.MenuItem(self.File, -1, "Select All \tCtrl+A", "", wx.ITEM_NORMAL)
|
||||
mnuItem1 = wx.MenuItem(self.File, -1, "Copy selected data \tCtrl+C", "", wx.ITEM_NORMAL)
|
||||
mnuItem2 = wx.MenuItem(self.File, -1, "Copy table w/ headers \tCtrl+H", "", wx.ITEM_NORMAL)
|
||||
|
||||
|
||||
self.File.AppendItem(mnuItem0)
|
||||
self.File.AppendItem(mnuItem1)
|
||||
self.File.AppendItem(mnuItem2)
|
||||
self.MenuBar.Append(self.File, "Edit")
|
||||
self.Bind(wx.EVT_MENU, lambda event: self.tbl.SelectAll(), mnuItem0)
|
||||
self.Bind(wx.EVT_MENU, self.OnCopy, mnuItem1)
|
||||
self.Bind(wx.EVT_MENU, self.OnCopyHeaders, mnuItem2)
|
||||
|
||||
self.SetMenuBar(self.MenuBar)
|
||||
|
||||
def OnCopy(self, event = None):
|
||||
|
||||
# Number of rows and cols
|
||||
rows = self.tbl.GetSelectionBlockBottomRight()[0][0] - self.tbl.GetSelectionBlockTopLeft()[0][0] + 1
|
||||
cols = self.tbl.GetSelectionBlockBottomRight()[0][1] - self.tbl.GetSelectionBlockTopLeft()[0][1] + 1
|
||||
|
||||
# data variable contain text that must be set in the clipboard
|
||||
data = ''
|
||||
|
||||
# For each cell in selected range append the cell value in the data variable
|
||||
# Tabs '\t' for cols and '\r' for rows
|
||||
for r in range(rows):
|
||||
for c in range(cols):
|
||||
data = data + str(self.tbl.GetCellValue(self.tbl.GetSelectionBlockTopLeft()[0][0] + r, self.tbl.GetSelectionBlockTopLeft()[0][1] + c))
|
||||
if c < cols - 1:
|
||||
data = data + '\t'
|
||||
data = data + '\n'
|
||||
# Create text data object
|
||||
clipboard = wx.TextDataObject()
|
||||
# Set data object value
|
||||
clipboard.SetText(data)
|
||||
# Put the data in the clipboard
|
||||
if wx.TheClipboard.Open():
|
||||
wx.TheClipboard.SetData(clipboard)
|
||||
wx.TheClipboard.Close()
|
||||
else:
|
||||
wx.MessageBox("Can't open the clipboard", "Error")
|
||||
event.Skip()
|
||||
|
||||
def OnCopyHeaders(self, event = None):
|
||||
self.tbl.SelectAll()
|
||||
# Number of rows and cols
|
||||
rows = self.tbl.GetSelectionBlockBottomRight()[0][0] - self.tbl.GetSelectionBlockTopLeft()[0][0] + 1
|
||||
cols = self.tbl.GetSelectionBlockBottomRight()[0][1] - self.tbl.GetSelectionBlockTopLeft()[0][1] + 1
|
||||
|
||||
# data variable contain text that must be set in the clipboard
|
||||
data = ''
|
||||
|
||||
#Add the headers
|
||||
for c in range(cols):
|
||||
data += str(self.tbl.GetColLabelValue(c).replace('\n',' ') )
|
||||
if c < cols - 1:
|
||||
data += '\t'
|
||||
data = data + '\n'
|
||||
# For each cell in selected range append the cell value in the data variable
|
||||
# Tabs '\t' for cols and '\r' for rows
|
||||
for r in range(rows):
|
||||
for c in range(cols):
|
||||
data = data + str(self.tbl.GetCellValue(self.tbl.GetSelectionBlockTopLeft()[0][0] + r, self.tbl.GetSelectionBlockTopLeft()[0][1] + c))
|
||||
if c < cols - 1:
|
||||
data = data + '\t'
|
||||
data = data + '\n'
|
||||
# Create text data object
|
||||
clipboard = wx.TextDataObject()
|
||||
# Set data object value
|
||||
clipboard.SetText(data)
|
||||
# Put the data in the clipboard
|
||||
if wx.TheClipboard.Open():
|
||||
wx.TheClipboard.SetData(clipboard)
|
||||
wx.TheClipboard.Close()
|
||||
else:
|
||||
wx.MessageBox("Can't open the clipboard", "Error")
|
||||
event.Skip()
|
||||
|
||||
class MainFrame(wx.Frame):
|
||||
|
||||
def __init__(self):
|
||||
wx.Frame.__init__(self,None)
|
||||
|
||||
self.build()
|
||||
|
||||
def build(self):
|
||||
# Menu Bar
|
||||
self.MenuBar = wx.MenuBar()
|
||||
|
||||
self.plots = wx.Menu()
|
||||
self.PHPlot = wx.Menu()
|
||||
self.TSPlot = wx.Menu()
|
||||
self.tables = wx.Menu()
|
||||
self.PsychPlot = wx.MenuItem(self.plots,-1,'Psychrometric Plot')
|
||||
self.SatTable = wx.MenuItem(self.tables, -1,' Saturation Table', "", wx.ITEM_NORMAL)
|
||||
|
||||
for Fluid in sorted(CP.__fluids__):
|
||||
mnuItem = wx.MenuItem(self.PHPlot, -1, Fluid, "", wx.ITEM_NORMAL)
|
||||
self.PHPlot.AppendItem(mnuItem)
|
||||
self.Bind(wx.EVT_MENU, lambda event: self.OnPHPlot(event, mnuItem), mnuItem)
|
||||
|
||||
mnuItem = wx.MenuItem(self.TSPlot, -1, Fluid, "", wx.ITEM_NORMAL)
|
||||
self.TSPlot.AppendItem(mnuItem)
|
||||
self.Bind(wx.EVT_MENU, lambda event: self.OnTSPlot(event, mnuItem), mnuItem)
|
||||
|
||||
self.MenuBar.Append(self.plots, "Plots")
|
||||
self.plots.AppendItem(self.PsychPlot)
|
||||
self.plots.AppendMenu(-1,'p-h plot', self.PHPlot)
|
||||
self.plots.AppendMenu(-1,'T-s plot', self.TSPlot)
|
||||
self.MenuBar.Append(self.tables, "Tables")
|
||||
self.tables.AppendItem(self.SatTable)
|
||||
self.Bind(wx.EVT_MENU, self.OnSatTable, self.SatTable)
|
||||
self.Bind(wx.EVT_MENU, self.OnPsychPlot, self.PsychPlot)
|
||||
|
||||
self.SetMenuBar(self.MenuBar)
|
||||
|
||||
def OnPsychPlot(self, event=None):
|
||||
|
||||
#Load the options
|
||||
dlg = PsychOptions(None)
|
||||
if dlg.ShowModal() == wx.ID_OK:
|
||||
Tmin = float(dlg.Tmin.GetValue())+273.15
|
||||
Tmax = float(dlg.Tmax.GetValue())+273.15
|
||||
p = float(dlg.p.GetValue())
|
||||
PPF = PsychPlotFrame(Tmin = Tmin, Tmax = Tmax, p = p, size = (1000,700))
|
||||
PPF.Show()
|
||||
dlg.Destroy()
|
||||
|
||||
|
||||
def OnSatTable(self,event):
|
||||
TBL = SaturationTable(None)
|
||||
TBL.Show()
|
||||
|
||||
def OnPHPlot(self, event, mnuItem):
|
||||
#Make a p-h plot instance in a new frame
|
||||
#Get the label (Fluid name)
|
||||
Fluid = self.PHPlot.FindItemById(event.Id).Label
|
||||
PH = PHPlotFrame(Fluid)
|
||||
PH.Show()
|
||||
|
||||
def OnTSPlot(self, event, mnuItem):
|
||||
#Make a p-h plot instance in a new frame
|
||||
#Get the label (Fluid name)
|
||||
Fluid = self.TSPlot.FindItemById(event.Id).Label
|
||||
TS = TSPlotFrame(Fluid)
|
||||
TS.Show()
|
||||
|
||||
if __name__=='__main__':
|
||||
app = wx.App(False)
|
||||
wx.InitAllImageHandlers()
|
||||
|
||||
frame = MainFrame()
|
||||
frame.Show(True)
|
||||
app.MainLoop()
|
||||
@@ -1,35 +0,0 @@
|
||||
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from CoolProp.HumidAirProp import HAProps
|
||||
|
||||
Tdb = np.linspace(-10,55,100)+273.15
|
||||
|
||||
#Make the figure and the axes
|
||||
fig=plt.figure(figsize=(10,8))
|
||||
ax=fig.add_axes((0.15,0.15,0.8,0.8))
|
||||
ax.set_xlim(Tdb[0]-273.15,Tdb[-1]-273.15)
|
||||
ax.set_ylim(0,0.03)
|
||||
ax.set_xlabel(r"Dry bulb temperature [$^{\circ}$C]")
|
||||
ax.set_ylabel(r"Humidity ratio ($m_{water}/m_{dry\ air}$) [-]")
|
||||
|
||||
# Saturation line
|
||||
w = [HAProps('W','T',T,'P',101.325,'R',1.0) for T in Tdb]
|
||||
ax.plot(Tdb-273.15,w,lw=2)
|
||||
|
||||
# Humidity lines
|
||||
RHValues = [0.05, 0.1, 0.15, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
|
||||
for RH in RHValues:
|
||||
w = [HAProps('W','T',T,'P',101.325,'R',RH) for T in Tdb]
|
||||
ax.plot(Tdb-273.15,w,'r',lw=1)
|
||||
|
||||
# Humidity lines
|
||||
for H in [-20, -10, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90]:
|
||||
#Line goes from saturation to zero humidity ratio for this enthalpy
|
||||
T1 = HAProps('T','H',H,'P',101.325,'R',1.0)-273.15
|
||||
T0 = HAProps('T','H',H,'P',101.325,'R',0.0)-273.15
|
||||
w1 = HAProps('W','H',H,'P',101.325,'R',1.0)
|
||||
w0 = HAProps('W','H',H,'P',101.325,'R',0.0)
|
||||
ax.plot(np.r_[T1,T0],np.r_[w1,w0],'r',lw=1)
|
||||
|
||||
plt.show()
|
||||
@@ -1,2 +0,0 @@
|
||||
from __future__ import absolute_import
|
||||
from .CoolProp import HAProps, HAProps_Aux, cair_sat
|
||||
@@ -1,150 +0,0 @@
|
||||
#This file gets directly included in CoolProp.pyx, separate here for cleanness of code
|
||||
|
||||
cpdef HAProps(str OutputName, str Input1Name, Input1, str Input2Name, Input2, str Input3Name, Input3):
|
||||
"""
|
||||
Copyright Ian Bell, 2011 email: ian.h.bell@gmail.com
|
||||
|
||||
The function is called like
|
||||
|
||||
HAProps('H','T',298.15,'P',101.325,'R',0.5)
|
||||
|
||||
which will return the enthalpy of the air for a set of inputs of dry bulb temperature of 25C, atmospheric pressure, and a relative humidity of 50%.
|
||||
|
||||
This function implements humid air properties based on the analysis in ASHRAE RP-1845 which is available online: http://rp.ashrae.biz/page/ASHRAE-D-RP-1485-20091216.pdf
|
||||
|
||||
It employs real gas properties for both air and water, as well as the most accurate interaction parameters and enhancement factors. The IAPWS-95 formulation for the properties of water is used throughout in preference to the industrial formulation. It is unclear why the industrial formulation is used in the first place.
|
||||
|
||||
Since humid air is nominally a binary mixture, three variables are needed to fix the state. At least one of the input parameters must be dry-bulb temperature, relative humidity, dew-point temperature, or humidity ratio. The others will be calculated. If the output variable is a transport property (conductivity or viscosity), the state must be able to be found directly - i.e. make sure you give temperature and relative humidity or humidity ratio. The list of possible input variables are
|
||||
|
||||
======== ======== ========================================
|
||||
String Aliases Description
|
||||
======== ======== ========================================
|
||||
T Tdb Dry-Bulb Temperature [K]
|
||||
B Twb Wet-Bulb Temperature [K]
|
||||
D Tdp Dew-Point Temperature [K]
|
||||
P Pressure [kPa]
|
||||
V Vda Mixture volume [m3/kg dry air]
|
||||
R RH Relative humidity in (0,1) [-]
|
||||
W Omega Humidity Ratio [kg water/kg dry air]
|
||||
H Hda Mixture enthalpy [kJ/kg dry air]
|
||||
S Sda Mixture entropy [kJ/kg dry air/K]
|
||||
C cp Mixture specific heat [kJ/kg dry air/K]
|
||||
M Visc Mixture viscosity [Pa-s]
|
||||
K Mixture thermal conductivity [kW/m/K]
|
||||
======== ======== ========================================
|
||||
|
||||
There are also strings for the mixture volume and mixture enthalpy that will return the properties on a total humid air flow rate basis, they are given by 'Vha' [units of m^3/kg humid air] and 'Cha' [units of kJ/kg humid air/K] and 'Hha' [units of kJ/kg humid air] respectively.
|
||||
|
||||
For more information, go to http://coolprop.sourceforge.net
|
||||
"""
|
||||
#Convert all strings to byte-strings
|
||||
cdef bytes _OutputName = OutputName.encode('ascii')
|
||||
cdef bytes _Input1Name = Input1Name.encode('ascii')
|
||||
cdef bytes _Input2Name = Input2Name.encode('ascii')
|
||||
cdef bytes _Input3Name = Input3Name.encode('ascii')
|
||||
|
||||
if isinstance(Input1, (int, long, float, complex)) and isinstance(Input2, (int, long, float, complex)) and isinstance(Input3, (int, long, float, complex)):
|
||||
val = _HAProps(_OutputName,_Input1Name,Input1,_Input2Name,Input2,_Input3Name,Input3)
|
||||
|
||||
if math.isinf(val) or math.isnan(val):
|
||||
err_string = _get_global_param_string('errstring')
|
||||
if not len(err_string) == 0:
|
||||
raise ValueError("{err:s} :: inputs were:\"{out:s}\",\'{in1n:s}\',{in1:0.16e},\'{in2n:s}\',{in2:0.16e},\'{in3n:s}\',{in3:0.16e} ".format(err=err_string,out=_OutputName,in1n=_Input1Name,in1=Input1,in2n=_Input2Name,in2=Input2,in3n=_Input3Name,in3=Input3))
|
||||
else:
|
||||
raise ValueError("HAProps failed ungracefully with inputs: \"{out:s}\",\'{in1n:s}\',{in1:0.16e},\'{in2n:s}\',{in2:0.16e},\'{in3n:s}\',{in3:0.16e} ".format(out=_OutputName,in1n=_Input1Name,in1=Input1,in2n=_Input2Name,in2=Input2,in3n=_Input3Name,in3=Input3))
|
||||
|
||||
return val #Error raised by HAProps on failure
|
||||
|
||||
# At least one is iterable, convert non-iterable to a list of the same length
|
||||
elif isinstance(Input1, (int, long, float, complex)) or isinstance(Input2, (int, long, float, complex)):
|
||||
|
||||
iterable_lengths = []
|
||||
if not isinstance(Input1, (int, long, float, complex)):
|
||||
iterable_lengths.append(len(Input1))
|
||||
if not isinstance(Input2, (int, long, float, complex)):
|
||||
iterable_lengths.append(len(Input2))
|
||||
if not isinstance(Input3, (int, long, float, complex)):
|
||||
iterable_lengths.append(len(Input3))
|
||||
|
||||
if not len(set(iterable_lengths)) == 1:
|
||||
raise TypeError("Iterable inputs are not all the same length. Lengths: "+str(iterable_lengths))
|
||||
else:
|
||||
L = iterable_lengths[0]
|
||||
|
||||
|
||||
if isinstance(Input1, (int, long, float, complex)):
|
||||
Input1vec = [Input1]*L
|
||||
else:
|
||||
Input1vec = Input1
|
||||
|
||||
if isinstance(Input2, (int, long, float, complex)):
|
||||
Input2vec = [Input2]*L
|
||||
else:
|
||||
Input2vec = Input2
|
||||
|
||||
if isinstance(Input3, (int, long, float, complex)):
|
||||
Input3vec = [Input3]*L
|
||||
else:
|
||||
Input3vec = Input3
|
||||
|
||||
vals = []
|
||||
|
||||
for _Input1, _Input2, _Input3 in zip(Input1vec, Input2vec, Input3vec):
|
||||
val = _HAProps(_OutputName,_Input1Name,_Input1,_Input2Name,_Input2,_Input3Name,_Input3)
|
||||
|
||||
if math.isinf(val) or math.isnan(val):
|
||||
err_string = _get_global_param_string('errstring')
|
||||
if not len(err_string) == 0:
|
||||
raise ValueError("{err:s} :: inputs were:\"{out:s}\",\'{in1n:s}\',{in1:0.16e},\'{in2n:s}\',{in2:0.16e},\'{in3n:s}\',{in3:0.16e}".format(err=err_string,out=_OutputName,in1n=_Input1Name,in1=_Input1,in2n=_Input2Name,in2=_Input2,in3n=_Input3Name,in3=_Input3))
|
||||
else:
|
||||
raise ValueError("HAProps failed ungracefully with inputs: \"{out:s}\",\'{in1n:s}\',{in1:0.16e},\'{in2n:s}\',{in2:0.16e},\'{in3n:s}\',{in3:0.16e} ".format(out=_OutputName,in1n=_Input1Name,in1=Input1,in2n=_Input2Name,in2=Input2,in3n=_Input3Name,in3=Input3))
|
||||
|
||||
vals.append(val)
|
||||
|
||||
if _numpy_supported and isinstance(Input1, np.ndarray):
|
||||
return np.array(vals).reshape(Input1.shape)
|
||||
elif _numpy_supported and isinstance(Input2, np.ndarray):
|
||||
return np.array(vals).reshape(Input2.shape)
|
||||
elif _numpy_supported and isinstance(Input3, np.ndarray):
|
||||
return np.array(vals).reshape(Input3.shape)
|
||||
else:
|
||||
return vals
|
||||
|
||||
else:
|
||||
raise TypeError('Numerical inputs to Props must be ints, floats, lists, or 1D numpy arrays.')
|
||||
|
||||
cpdef tuple HAProps_Aux(str OutputName, double T, double p, double w):
|
||||
"""
|
||||
Allows low-level access to some of the routines employed in HumidAirProps
|
||||
|
||||
Returns tuples of the form ``(Value, Units)`` where ``Value`` is the actual value and ``Units`` is a string that describes the units
|
||||
|
||||
The list of possible inputs is
|
||||
|
||||
* Baa [First virial air-air coefficient]
|
||||
* Caaa [Second virial air coefficient]
|
||||
* Bww [First virial water-water coefficient]
|
||||
* Cwww [Second virial water coefficient]
|
||||
* Baw [First cross virial coefficient]
|
||||
* Caww [Second air-water-water virial coefficient]
|
||||
* Caaw [Second air-air-water virial coefficient]
|
||||
* beta_H
|
||||
* kT
|
||||
* vbar_ws [Molar saturated volume of water vapor]
|
||||
* p_ws [Saturated vapor pressure of pure water (>=0.01C) or ice (<0.01 C)]
|
||||
* f [Enhancement factor]
|
||||
"""
|
||||
#Convert all strings to byte-strings
|
||||
cdef bytes units = (' '*100).encode('ascii')
|
||||
cdef bytes _OutputName = OutputName.encode('ascii')
|
||||
|
||||
output = _HAProps_Aux(_OutputName,T,p,w,units)
|
||||
units = units.strip()
|
||||
units = units[0:len(units)-1] #Leave off the null character
|
||||
return output, units
|
||||
|
||||
cpdef double cair_sat(double T):
|
||||
"""
|
||||
The derivative of the saturation enthalpy cair_sat = d(hsat)/dT
|
||||
"""
|
||||
return _cair_sat(T)
|
||||
@@ -1,250 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import matplotlib
|
||||
import numpy
|
||||
|
||||
import CoolProp.CoolProp as CP
|
||||
|
||||
SMALL = 1E-5
|
||||
|
||||
|
||||
class BasePlot(object):
|
||||
#TODO: Simplify / Consolidate dictionary maps
|
||||
AXIS_LABELS = {'T': ["Temperature", r"[K]"],
|
||||
'P': ["Pressure", r"[kPa]"],
|
||||
'S': ["Entropy", r"[kJ/kg/K]"],
|
||||
'H': ["Enthalpy", r"[kJ/kg]"],
|
||||
'V': [],
|
||||
'D': ["Density", r"[kg/m$^3$]"]}
|
||||
|
||||
COLOR_MAP = {'T': 'Darkred',
|
||||
'P': 'DarkCyan',
|
||||
'H': 'DarkGreen',
|
||||
'D': 'DarkBlue',
|
||||
'S': 'DarkOrange',
|
||||
'Q': 'black'}
|
||||
|
||||
SYMBOL_MAP = {'T' : [r'$T = ', r'$ K'],
|
||||
'P' : [r'$p = ', r'$ kPa'],
|
||||
'H' : [r'$h = ', r'$ kJ/kg'],
|
||||
'D' : [r'$\rho = ', r'$ kg/m$^3$'],
|
||||
'S' : [r'$s = ', r'$ kJ/kg-K'],
|
||||
'Q' : [r'$x = ', r'$']}
|
||||
|
||||
LINE_IDS = {'TS': ['P', 'D'], #'H'],
|
||||
'PH': ['S', 'T', 'D'],
|
||||
'HS': ['P'], #'T', 'D'],
|
||||
'PS': ['H', 'T', 'D'],
|
||||
'PD': ['T', 'S', 'H'],
|
||||
'TD': ['P'], #'S', 'H'],
|
||||
'PT': ['D', 'P', 'S'],}
|
||||
|
||||
def __init__(self, fluid_ref, graph_type, **kwargs):
|
||||
if not isinstance(graph_type, str):
|
||||
raise TypeError("Invalid graph_type input, expeceted a string")
|
||||
|
||||
graph_type = graph_type.upper()
|
||||
if len(graph_type) >= 2 and graph_type[1:len(graph_type)] == 'RHO':
|
||||
graph_type = graph_type[0] + graph_type[1:len(graph_type)]
|
||||
|
||||
if graph_type.upper() not in self.LINE_IDS.keys():
|
||||
raise ValueError(''.join(["You have to specify the kind of ",
|
||||
"plot, use ",
|
||||
str(self.LINE_IDS.keys())]))
|
||||
|
||||
self.graph_drawn = False
|
||||
self.fluid_ref = fluid_ref
|
||||
self.graph_type = graph_type.upper()
|
||||
|
||||
self.axis = kwargs.get('axis', None)
|
||||
if self.axis is None:
|
||||
self.axis = matplotlib.pyplot.gca()
|
||||
|
||||
def __sat_bounds(self, kind, smin=None, smax=None):
|
||||
"""
|
||||
Generates limits for the saturation line in either T or p determined
|
||||
by 'kind'. If xmin or xmax are provided, values will be checked
|
||||
against the allowable range for the EOS and an error might be
|
||||
generated.
|
||||
|
||||
Returns a tuple containing (xmin, xmax)
|
||||
"""
|
||||
if kind == 'P':
|
||||
name = 'pressure'
|
||||
min_key = 'ptriple'
|
||||
elif kind == 'T':
|
||||
name = 'temperature'
|
||||
min_key = 'Tmin'
|
||||
|
||||
fluid_min = CP.Props(self.fluid_ref, min_key)
|
||||
fluid_crit = CP.Props(self.fluid_ref, ''.join([kind, 'crit']))
|
||||
|
||||
if smin is None:
|
||||
smin = fluid_min + SMALL
|
||||
elif smin > fluid_crit:
|
||||
raise ValueError(''.join(['Minimum ', name,
|
||||
' cannot be greater than fluid critical ',
|
||||
name, '.']))
|
||||
|
||||
if smax is None:
|
||||
smax = fluid_crit - SMALL
|
||||
elif smax > fluid_crit:
|
||||
raise ValueError(''.join(['Maximum ', name,
|
||||
' cannot be greater than fluid critical ',
|
||||
name, '.']))
|
||||
|
||||
smin = max(smin, fluid_min + SMALL)
|
||||
smax = min(smax, fluid_crit - SMALL)
|
||||
|
||||
return (smin, smax)
|
||||
|
||||
def _get_fluid_data(self, req_prop,
|
||||
prop1_name, prop1_vals,
|
||||
prop2_name, prop2_vals):
|
||||
"""
|
||||
Calculates lines for constant iName (iVal) over an interval of xName
|
||||
(xVal). Returns (x[],y[]) - a tuple of arrays containing the values
|
||||
in x and y dimensions.
|
||||
"""
|
||||
if len(prop1_vals) != len(prop2_vals):
|
||||
raise ValueError(''.join(['We need the same number of x value ',
|
||||
'arrays as iso quantities.']))
|
||||
|
||||
y_vals = []
|
||||
x_vals = []
|
||||
|
||||
for i, p1_val in enumerate(prop1_vals):
|
||||
x_vals.append(prop2_vals[i])
|
||||
y_vals.append(CP.Props(req_prop,
|
||||
prop1_name, p1_val,
|
||||
prop2_name, prop2_vals[i],
|
||||
self.fluid_ref))
|
||||
|
||||
return numpy.array([x_vals, y_vals])
|
||||
|
||||
def _get_sat_lines(self, kind='T', smin=None,
|
||||
smax=None, num=500, x=[0., 1.]):
|
||||
"""
|
||||
Calculates bubble and dew line in the quantities for your plot.
|
||||
You can specify if you need evenly spaced entries in either
|
||||
pressure or temperature by supplying kind='p' and kind='T'
|
||||
(default), respectively.
|
||||
Limits can be set with kmin (default: minimum from EOS) and
|
||||
kmax (default: critical value).
|
||||
Returns lines[] - a 2D array of dicts containing 'x' and 'y'
|
||||
coordinates for bubble and dew line. Additionally, the dict holds
|
||||
the keys 'kmax', 'label' and 'opts', those can be used for plotting
|
||||
as well.
|
||||
"""
|
||||
if not kind.upper() in ['T', 'P']:
|
||||
raise ValueError(''.join(["Invalid input for determining the ",
|
||||
"saturation lines... Expected either ",
|
||||
"'T' or 'P'"]))
|
||||
|
||||
smin, smax = self.__sat_bounds(kind, smin=smin, smax=smax)
|
||||
sat_range = numpy.linspace(smin, smax, num)
|
||||
sat_mesh = numpy.array([sat_range for i in x])
|
||||
|
||||
x_vals = sat_mesh
|
||||
y_vals = sat_mesh
|
||||
if self.graph_type[1] != kind:
|
||||
_, x_vals = self._get_fluid_data(self.graph_type[1],
|
||||
'Q', x,
|
||||
kind, sat_mesh)
|
||||
|
||||
if self.graph_type[0] != kind:
|
||||
_, y_vals = self._get_fluid_data(self.graph_type[0],
|
||||
'Q', x,
|
||||
kind, sat_mesh)
|
||||
|
||||
# Merge the two lines, capital Y holds important information.
|
||||
# We merge on X values
|
||||
# Every entry, eg. Xy, contains two arrays of values.
|
||||
sat_lines = []
|
||||
for i in range(len(x_vals)): # two dimensions: i = {0,1}
|
||||
line = {'x': x_vals[i],
|
||||
'y': y_vals[i],
|
||||
'smax': smax}
|
||||
|
||||
line['label'] = self.SYMBOL_MAP['Q'][0] + str(x[i])
|
||||
line['type'] = 'Q'
|
||||
line['value'] = x[i]
|
||||
line['unit'] = self.SYMBOL_MAP['Q'][1]
|
||||
line['opts'] = {'color': self.COLOR_MAP['Q'],
|
||||
'lw': 1.0}
|
||||
|
||||
if x[i] == 0.:
|
||||
line['label'] = 'bubble line'
|
||||
elif x[i] == 1.:
|
||||
line['label'] = 'dew line'
|
||||
else:
|
||||
line['opts']['lw'] = 0.75
|
||||
line['opts']['alpha'] = 0.5
|
||||
|
||||
sat_lines.append(line)
|
||||
|
||||
return sat_lines
|
||||
|
||||
def _plot_default_annotations(self):
|
||||
def filter_fluid_ref(fluid_ref):
|
||||
fluid_ref_string = fluid_ref
|
||||
if fluid_ref.startswith('REFPROP-MIX'):
|
||||
end = 0
|
||||
fluid_ref_string = ''
|
||||
while fluid_ref.find('[', end + 1) != -1:
|
||||
start = fluid_ref.find('&', end + 1)
|
||||
if end == 0:
|
||||
start = fluid_ref.find(':', end + 1)
|
||||
end = fluid_ref.find('[', end + 1)
|
||||
fluid_ref_string = ' '.join([fluid_ref_string,
|
||||
fluid_ref[start+1:end], '+'])
|
||||
fluid_ref_string = fluid_ref_string[0:len(fluid_ref_string)-2]
|
||||
return fluid_ref_string
|
||||
|
||||
if len(self.graph_type) == 2:
|
||||
y_axis_id = self.graph_type[0]
|
||||
x_axis_id = self.graph_type[1]
|
||||
else:
|
||||
y_axis_id = self.graph_type[0]
|
||||
x_axis_id = self.graph_type[1:len(self.graph_type)]
|
||||
|
||||
tl_str = "%s - %s Graph for %s"
|
||||
if not self.axis.get_title():
|
||||
self.axis.set_title(tl_str % (self.AXIS_LABELS[y_axis_id][0],
|
||||
self.AXIS_LABELS[x_axis_id][0],
|
||||
filter_fluid_ref(self.fluid_ref)))
|
||||
if not self.axis.get_xlabel():
|
||||
self.axis.set_xlabel(' '.join(self.AXIS_LABELS[x_axis_id]))
|
||||
if not self.axis.get_ylabel():
|
||||
self.axis.set_ylabel(' '.join(self.AXIS_LABELS[y_axis_id]))
|
||||
|
||||
def _draw_graph(self):
|
||||
return
|
||||
|
||||
def title(self, title):
|
||||
self.axis.set_title(title)
|
||||
|
||||
def xlabel(self, xlabel):
|
||||
self.axis.set_xlabel(xlabel)
|
||||
|
||||
def ylabel(self, ylabel):
|
||||
self.axis.set_ylabel(ylabel)
|
||||
|
||||
def grid(self, b=None, **kwargs):
|
||||
g_map = {'on': True, 'off': False}
|
||||
if b is not None:
|
||||
b = g_map[b.lower()]
|
||||
if len(kwargs) == 0:
|
||||
self.axis.grid(b)
|
||||
else:
|
||||
self.axis.grid(kwargs)
|
||||
|
||||
def set_axis_limits(self, limits):
|
||||
self.axis.set_xlim([limits[0], limits[1]])
|
||||
self.axis.set_ylim([limits[2], limits[3]])
|
||||
|
||||
def show(self):
|
||||
self._draw_graph()
|
||||
matplotlib.pyplot.show()
|
||||
@@ -1,842 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
|
||||
import numpy, matplotlib, matplotlib.pyplot, math, re
|
||||
from scipy.interpolate import interp1d
|
||||
|
||||
import CoolProp.CoolProp as CP
|
||||
|
||||
from .Common import BasePlot
|
||||
from scipy import interpolate
|
||||
from scipy.spatial.kdtree import KDTree
|
||||
|
||||
class IsoLine(object):
|
||||
def __init__(self):
|
||||
self.DEBUG = False
|
||||
|
||||
# direct geometry
|
||||
self.X = None #
|
||||
self.Y = None #
|
||||
self.type = None #
|
||||
self.value = None #
|
||||
self.unit = None #
|
||||
self.opts = None #
|
||||
|
||||
|
||||
def InlineLabel(xv,yv,x = None, y= None, axis = None, fig = None):
|
||||
"""
|
||||
This will give the coordinates and rotation required to align a label with
|
||||
a line on a plot
|
||||
"""
|
||||
|
||||
def ToPixelCoords(xv,yv,axis,fig):
|
||||
[Axmin,Axmax]=axis.get_xlim()
|
||||
[Aymin,Aymax]=axis.get_ylim()
|
||||
DELTAX_axis=Axmax-Axmin
|
||||
DELTAY_axis=Aymax-Aymin
|
||||
|
||||
width=fig.get_figwidth()
|
||||
height=fig.get_figheight()
|
||||
pos=axis.get_position().get_points()
|
||||
[[Fxmin,Fymin],[Fxmax,Fymax]]=pos
|
||||
DELTAX_fig=width*(Fxmax-Fxmin)
|
||||
DELTAY_fig=height*(Fymax-Fymin)
|
||||
|
||||
#Convert coords to pixels
|
||||
x=(xv-Axmin)/DELTAX_axis*DELTAX_fig+Fxmin
|
||||
y=(yv-Aymin)/DELTAY_axis*DELTAY_fig+Fymin
|
||||
|
||||
return x,y
|
||||
|
||||
def ToDataCoords(xv,yv,axis,fig):
|
||||
[Axmin,Axmax]=axis.get_xlim()
|
||||
[Aymin,Aymax]=axis.get_ylim()
|
||||
DELTAX_axis=Axmax-Axmin
|
||||
DELTAY_axis=Aymax-Aymin
|
||||
|
||||
width=fig.get_figwidth()
|
||||
height=fig.get_figheight()
|
||||
pos=axis.get_position().get_points()
|
||||
[[Fxmin,Fymin],[Fxmax,Fymax]]=pos
|
||||
DELTAX_fig=(Fxmax-Fxmin)*width
|
||||
DELTAY_fig=(Fymax-Fymin)*height
|
||||
|
||||
#Convert back to measurements
|
||||
x=(xv-Fxmin)/DELTAX_fig*DELTAX_axis+Axmin
|
||||
y=(yv-Fymin)/DELTAY_fig*DELTAY_axis+Aymin
|
||||
|
||||
return x,y
|
||||
|
||||
def get_x_y_dydx(xv,yv,x):
|
||||
"""Get x and y coordinates and the linear interpolation derivative"""
|
||||
# Old implementation:
|
||||
##Get the rotation angle
|
||||
#f = interp1d(xv, yv)
|
||||
#y = f(x)
|
||||
#h = 0.00001*x
|
||||
#dy_dx = (f(x+h)-f(x-h))/(2*h)
|
||||
#return x,y,dy_dx
|
||||
if len(xv)==len(yv)>1: # assure same length
|
||||
if len(xv)==len(yv)==2: # only two points
|
||||
if numpy.min(xv)<x<numpy.max(xv):
|
||||
dx = xv[1] - xv[0]
|
||||
dy = yv[1] - yv[0]
|
||||
dydx = dy/dx
|
||||
y = yv[0] + dydx * (x-xv[0])
|
||||
return x,y,dydx
|
||||
else:
|
||||
raise ValueError("Your coordinate has to be between the input values.")
|
||||
else:
|
||||
limit = 1e-10 # avoid hitting a point directly
|
||||
diff = numpy.array(xv)-x # get differences
|
||||
index = numpy.argmin(diff*diff) # nearest neighbour
|
||||
if (xv[index]<x<xv[index+1] # nearest below, positive inclination
|
||||
or xv[index]>x>xv[index+1]): # nearest above, negative inclination
|
||||
if diff[index]<limit:
|
||||
index = [index-1,index+1]
|
||||
else:
|
||||
index = [index, index+1]
|
||||
elif (xv[index-1]<x<xv[index] # nearest above, positive inclination
|
||||
or xv[index-1]>x>xv[index]): # nearest below, negative inclination
|
||||
if diff[index]<limit:
|
||||
index = [index-1,index+1]
|
||||
else:
|
||||
index = [index-1,index]
|
||||
xvnew = xv[index]
|
||||
yvnew = yv[index]
|
||||
return get_x_y_dydx(xvnew,yvnew,x) # Allow for a single recursion
|
||||
else:
|
||||
raise ValueError("You have to provide the same amount of x- and y-pairs with at least two entries each.")
|
||||
|
||||
|
||||
if axis is None:
|
||||
axis=matplotlib.pyplot.gca()
|
||||
|
||||
if fig is None:
|
||||
fig=matplotlib.pyplot.gcf()
|
||||
|
||||
|
||||
|
||||
if y is None and x is not None:
|
||||
trash=0
|
||||
(xv,yv)=ToPixelCoords(xv,yv,axis,fig)
|
||||
#x is provided but y isn't
|
||||
(x,trash)=ToPixelCoords(x,trash,axis,fig)
|
||||
|
||||
#Get the rotation angle and y-value
|
||||
x,y,dy_dx = get_x_y_dydx(xv,yv,x)
|
||||
rot = numpy.arctan(dy_dx)/numpy.pi*180.
|
||||
|
||||
elif x is None and y is not None:
|
||||
#y is provided, but x isn't
|
||||
|
||||
_xv = xv[::-1]
|
||||
_yv = yv[::-1]
|
||||
#Find x by interpolation
|
||||
x = interp1d(yv, xv)(y)
|
||||
trash=0
|
||||
(xv,yv)=ToPixelCoords(xv,yv,axis,fig)
|
||||
(x,trash)=ToPixelCoords(x,trash,axis,fig)
|
||||
|
||||
#Get the rotation angle and y-value
|
||||
x,y,dy_dx = get_x_y_dydx(xv,yv,x)
|
||||
rot = numpy.arctan(dy_dx)/numpy.pi*180.
|
||||
|
||||
(x,y)=ToDataCoords(x,y,axis,fig)
|
||||
return (x,y,rot)
|
||||
|
||||
|
||||
def drawLines(Ref,lines,axis,plt_kwargs=None):
|
||||
"""
|
||||
Just an internal method to systematically plot values from
|
||||
the generated 'line' dicts, method is able to cover the whole
|
||||
saturation curve. Closes the gap at the critical point and
|
||||
adds a marker between the two last points of bubble and
|
||||
dew line if they reach up to critical point.
|
||||
Returns the an array of line objects that can be used to change
|
||||
the colour or style afterwards.
|
||||
"""
|
||||
if not plt_kwargs is None:
|
||||
for line in lines:
|
||||
line['opts'] = plt_kwargs
|
||||
plottedLines = []
|
||||
if len(lines)==2 and (
|
||||
'q' in str(lines[0]['type']).lower() and 'q' in str(lines[1]['type']).lower()
|
||||
) and (
|
||||
( 0 == lines[0]['value'] and 1 == lines[1]['type'] ) or ( 1 == lines[0]['value'] and 0 == lines[1]['type'] ) ):
|
||||
# We plot the saturation curve
|
||||
bubble = lines[0]
|
||||
dew = lines[1]
|
||||
line, = axis.plot(bubble['x'],bubble['y'],**bubble['opts'])
|
||||
plottedLines.extend([line])
|
||||
line, = axis.plot(dew['x'], dew['y'], **dew['opts'])
|
||||
plottedLines.extend([line])
|
||||
# Do we need to test if this is T or p?
|
||||
Tmax = min(bubble['kmax'],dew['kmax'])
|
||||
if Tmax>CP.Props(Ref,'Tcrit')-2e-5:
|
||||
axis.plot(numpy.r_[bubble['x'][-1],dew['x'][-1]],numpy.r_[bubble['y'][-1],dew['y'][-1]],**bubble['opts'])
|
||||
#axis.plot((bubble['x'][-1]+dew['x'][-1])/2.,(bubble['y'][-1]+dew['y'][-1])/2.,'o',color='Tomato')
|
||||
else:
|
||||
for line in lines:
|
||||
line, = axis.plot(line['x'],line['y'],**line['opts'])
|
||||
plottedLines.extend([line])
|
||||
|
||||
return plottedLines
|
||||
|
||||
|
||||
class IsoLines(BasePlot):
|
||||
def __init__(self, fluid_ref, graph_type, iso_type, **kwargs):
|
||||
BasePlot.__init__(self, fluid_ref, graph_type, **kwargs)
|
||||
|
||||
if not isinstance(iso_type, str):
|
||||
raise TypeError("Invalid iso_type input, expected a string")
|
||||
|
||||
iso_type = iso_type.upper()
|
||||
if iso_type not in self.COLOR_MAP.keys() and iso_type != 'Q':
|
||||
raise ValueError('This kind of isoline is not supported for a ' \
|
||||
+ str(graph_type) + \
|
||||
' plot. Please choose from '\
|
||||
+ str(self.COLOR_MAP.keys()) + ' or Q.')
|
||||
|
||||
self.iso_type = iso_type
|
||||
|
||||
def __set_axis_limits(self, swap_xy):
|
||||
"""
|
||||
Generates limits for the axes in terms of x,y defined by 'plot'
|
||||
based on temperature and pressure.
|
||||
|
||||
Returns a tuple containing ((xmin, xmax), (ymin, ymax))
|
||||
"""
|
||||
# Get current axis limits, be sure to set those before drawing isolines
|
||||
# if no limits are set, use triple point and critical conditions
|
||||
X = [CP.Props(self.graph_type[1],
|
||||
'T', 1.5*CP.Props(self.fluid_ref, 'Tcrit'),
|
||||
'P', CP.Props(self.fluid_ref, 'ptriple'),
|
||||
self.fluid_ref),
|
||||
CP.Props(self.graph_type[1],
|
||||
'T', 1.1*CP.Props(self.fluid_ref, 'Tmin'),
|
||||
'P', 1.5*CP.Props(self.fluid_ref, 'pcrit'),
|
||||
self.fluid_ref),
|
||||
CP.Props(self.graph_type[1],
|
||||
'T', 1.5*CP.Props(self.fluid_ref, 'Tcrit'),
|
||||
'P', 1.5*CP.Props(self.fluid_ref, 'pcrit'),
|
||||
self.fluid_ref),
|
||||
CP.Props(self.graph_type[1],
|
||||
'T', 1.1*CP.Props(self.fluid_ref, 'Tmin'),
|
||||
'P', CP.Props(self.fluid_ref, 'ptriple'),
|
||||
self.fluid_ref)]
|
||||
|
||||
Y = [CP.Props(self.graph_type[0],
|
||||
'T', 1.5*CP.Props(self.fluid_ref, 'Tcrit'),
|
||||
'P', CP.Props(self.fluid_ref, 'ptriple'),
|
||||
self.fluid_ref),
|
||||
CP.Props(self.graph_type[0],
|
||||
'T', 1.1*CP.Props(self.fluid_ref, 'Tmin') ,
|
||||
'P', 1.5*CP.Props(self.fluid_ref, 'pcrit'),
|
||||
self.fluid_ref),
|
||||
CP.Props(self.graph_type[0],
|
||||
'T', 1.1*CP.Props(self.fluid_ref, 'Tcrit'),
|
||||
'P', 1.5*CP.Props(self.fluid_ref, 'pcrit'),
|
||||
self.fluid_ref),
|
||||
CP.Props(self.graph_type[0],
|
||||
'T', 1.5*CP.Props(self.fluid_ref, 'Tmin') ,
|
||||
'P', CP.Props(self.fluid_ref, 'ptriple'),
|
||||
self.fluid_ref)]
|
||||
|
||||
limits = [[min(X), max(X)], [min(Y), max(Y)]]
|
||||
if not self.axis.get_autoscalex_on():
|
||||
limits[0][0] = max([limits[0][0], min(self.axis.get_xlim())])
|
||||
limits[0][1] = min([limits[0][1], max(self.axis.get_xlim())])
|
||||
limits[1][0] = max([limits[1][0], min(self.axis.get_ylim())])
|
||||
limits[1][1] = min([limits[1][1], max(self.axis.get_ylim())])
|
||||
|
||||
self.axis.set_xlim(limits[0])
|
||||
self.axis.set_ylim(limits[1])
|
||||
return limits
|
||||
|
||||
def __plotRound(self, values):
|
||||
"""
|
||||
A function round an array-like object while maintaining the
|
||||
amount of entries. This is needed for the isolines since we
|
||||
want the labels to look pretty (=rounding), but we do not
|
||||
know the spacing of the lines. A fixed number of digits after
|
||||
rounding might lead to reduced array size.
|
||||
"""
|
||||
inVal = numpy.unique(numpy.sort(numpy.array(values)))
|
||||
output = inVal[1:] * 0.0
|
||||
digits = -1
|
||||
limit = 10
|
||||
lim = inVal * 0.0 + 10
|
||||
# remove less from the numbers until same length,
|
||||
# more than 10 significant digits does not really
|
||||
# make sense, does it?
|
||||
while len(inVal) > len(output) and digits < limit:
|
||||
digits += 1
|
||||
val = ( numpy.around(numpy.log10(numpy.abs(inVal))) * -1) + digits + 1
|
||||
val = numpy.where(val < lim, val, lim)
|
||||
val = numpy.where(val >-lim, val, -lim)
|
||||
output = numpy.zeros(inVal.shape)
|
||||
for i in range(len(inVal)):
|
||||
output[i] = numpy.around(inVal[i],decimals=int(val[i]))
|
||||
output = numpy.unique(output)
|
||||
return output
|
||||
|
||||
def get_isolines(self, iso_range=[], num=None, rounding=False):
|
||||
"""
|
||||
This is the core method to obtain lines in the dimensions defined
|
||||
by 'plot' that describe the behaviour of fluid 'Ref'. The constant
|
||||
value is determined by 'iName' and has the values of 'iValues'.
|
||||
|
||||
'iValues' is an array-like object holding at least one element. Lines
|
||||
are calculated for every entry in 'iValues'. If the input 'num' is
|
||||
larger than the amount of entries in 'iValues', an internally defined
|
||||
pattern is used to calculate an appropriate line spacing between the maximum
|
||||
and minimum values provided in 'iValues'.
|
||||
|
||||
Returns lines[num] - an array of dicts containing 'x' and 'y'
|
||||
coordinates for bubble and dew line. Additionally, the dict holds
|
||||
the keys 'label' and 'opts', those can be used for plotting as well.
|
||||
"""
|
||||
if iso_range is None or (len(iso_range) == 1 and num != 1):
|
||||
raise ValueError('Automatic interval detection for isoline \
|
||||
boundaries is not supported yet, use the \
|
||||
iso_range=[min, max] parameter.')
|
||||
|
||||
if len(iso_range) == 2 and num is None:
|
||||
raise ValueError('Please specify the number of isoline you want \
|
||||
e.g. num=10')
|
||||
|
||||
iso_range = numpy.sort(numpy.unique(iso_range))
|
||||
|
||||
def generate_ranges(xmin, xmax, num):
|
||||
if self.iso_type in ['P', 'D']:
|
||||
return numpy.logspace(math.log(xmin, 2.),
|
||||
math.log(xmax, 2.),
|
||||
num=num,
|
||||
base=2.)
|
||||
return numpy.linspace(xmin, xmax, num=num)
|
||||
|
||||
# Generate iso ranges
|
||||
if len(iso_range) == 2:
|
||||
iso_range = generate_ranges(iso_range[0], iso_range[1], num)
|
||||
#iso_range = plotRound(iso_range)
|
||||
#else:
|
||||
# TODO: Automatic interval detection
|
||||
# iVal = [CP.Props(iName,'T',T_c[i],'D',rho_c[i],Ref) for i in range(len(T_c))]
|
||||
# iVal = patterns[iName]([numpy.min(iVal),numpy.max(iVal),num])
|
||||
|
||||
if rounding:
|
||||
iso_range = self.__plotRound(iso_range)
|
||||
|
||||
switch_xy_map = {'D': ['TS', 'PH', 'PS'],
|
||||
'S': ['PH', 'PD', 'PT'],
|
||||
'T': ['PH', 'PS'],
|
||||
'H': ['PD']}
|
||||
#TS: TD is defined, SD is not
|
||||
#PH: PD is defined, HD is not
|
||||
#PS: PD is defined, SD is not
|
||||
#PH: PS is more stable than HS
|
||||
#PD: PS is defined, DS is not
|
||||
#PT: PS is defined, TS is not
|
||||
#PH: PT is defined, HT is not
|
||||
#PS: PT is defined, ST is not
|
||||
#PD: PH is defined, DH is not
|
||||
|
||||
iso_error_map = {'TD': ['S', 'H'],
|
||||
'HS': ['T', 'D'],}
|
||||
|
||||
switch_xy = False
|
||||
if self.iso_type in ['D', 'S', 'T', 'H']:
|
||||
if self.graph_type in switch_xy_map[self.iso_type]:
|
||||
switch_xy = True
|
||||
|
||||
if self.graph_type in ['TD', 'HS']:
|
||||
if self.iso_type in iso_error_map[self.graph_type]:
|
||||
raise ValueError('You should not reach this point!')
|
||||
|
||||
axis_limits = self.__set_axis_limits(switch_xy)
|
||||
req_prop = self.graph_type[0]
|
||||
prop2_name = self.graph_type[1]
|
||||
if switch_xy:
|
||||
axis_limits.reverse()
|
||||
req_prop = self.graph_type[1]
|
||||
prop2_name = self.graph_type[0]
|
||||
|
||||
# Calculate the points
|
||||
if self.iso_type == 'Q':
|
||||
lines = self._get_sat_lines(x=iso_range)
|
||||
return lines
|
||||
|
||||
# TODO: Determine saturation state if two phase region present
|
||||
x_range = numpy.linspace(axis_limits[0][0], axis_limits[0][1], 1000.)
|
||||
x_mesh = [x_range for i in iso_range]
|
||||
|
||||
plot_data = self._get_fluid_data(req_prop,
|
||||
self.iso_type, iso_range,
|
||||
prop2_name, x_mesh)
|
||||
|
||||
if switch_xy:
|
||||
plot_data = plot_data[::-1]
|
||||
|
||||
lines = []
|
||||
for j in range(len(plot_data[0])):
|
||||
line = {
|
||||
'x': plot_data[0][j],
|
||||
'y': plot_data[1][j],
|
||||
# TODO
|
||||
'label': "", #_getIsoLineLabel(self.iso_type, iso_range[j]),
|
||||
'type': self.iso_type,
|
||||
'opts': {'color': self.COLOR_MAP[self.iso_type], 'lw':0.75, 'alpha':0.5 }
|
||||
}
|
||||
lines.append(line)
|
||||
|
||||
return lines
|
||||
|
||||
def draw_isolines(self, iso_range, num=None, rounding=False):
|
||||
"""
|
||||
Draw lines with constant values of type 'which' in terms of x and y as
|
||||
defined by 'plot'. 'iMin' and 'iMax' are minimum and maximum value between
|
||||
which 'num' get drawn.
|
||||
|
||||
There should also be helpful error messages...
|
||||
"""
|
||||
if iso_range is None or (len(iso_range) == 1 and num != 1):
|
||||
raise ValueError('Automatic interval detection for isoline \
|
||||
boundaries is not supported yet, use the \
|
||||
iso_range=[min, max] parameter.')
|
||||
|
||||
if len(iso_range) == 2 and num is None:
|
||||
raise ValueError('Please specify the number of isoline you want \
|
||||
e.g. num=10')
|
||||
|
||||
if self.iso_type == 'all':
|
||||
raise ValueError('Plotting all lines automatically is not \
|
||||
supported, yet..')
|
||||
|
||||
if self.iso_type != 'all':
|
||||
lines = self.get_isolines(iso_range, num, rounding)
|
||||
drawn_lines = drawLines(self.fluid_ref, lines, self.axis)
|
||||
self._plot_default_annotations()
|
||||
return drawn_lines
|
||||
#else:
|
||||
# # TODO: assign limits to values automatically
|
||||
# ll = _getIsoLineIds(plot)
|
||||
# if not len(ll)==len(iValues):
|
||||
# raise ValueError('Please provide a properly sized array of bounds.')
|
||||
# for c,l in enumerate(ll):
|
||||
# drawIsoLines(Ref, plot, l, iValues=iValues[c], num=num, axis=axis, fig=fig)
|
||||
|
||||
|
||||
class PropsPlot(BasePlot):
|
||||
def __init__(self, fluid_ref, graph_type, **kwargs):
|
||||
"""
|
||||
Create graph for the specified fluid properties
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
fluid_ref : str
|
||||
The refence fluid
|
||||
graph_type : str
|
||||
The graph type to be plotted
|
||||
axis : :func:`matplotlib.pyplot.gca()`, Optional
|
||||
The current axis system to be plotted to.
|
||||
Default: create a new axis system
|
||||
fig : :func:`matplotlib.pyplot.figure()`, Optional
|
||||
The current figure to be plotted to.
|
||||
Default: create a new figure
|
||||
|
||||
Examples
|
||||
---------
|
||||
>>> from CoolProp.Plots import PropsPlot
|
||||
>>> plt = PropsPlot('Water', 'Ph')
|
||||
>>> plt.show()
|
||||
|
||||
>>> plt = PropsPlot('n-Pentane', 'Ts')
|
||||
>>> plt.set_axis_limits([-0.5, 1.5, 300, 530])
|
||||
>>> plt.draw_isolines('Q', [0.1, 0.9])
|
||||
>>> plt.draw_isolines('P', [100, 2000])
|
||||
>>> plt.draw_isolines('D', [2, 600])
|
||||
>>> plt.show()
|
||||
|
||||
.. note::
|
||||
|
||||
See the online documentation for a the available fluids and
|
||||
graph types
|
||||
"""
|
||||
BasePlot.__init__(self, fluid_ref, graph_type, **kwargs)
|
||||
|
||||
self.smin = kwargs.get('smin', None)
|
||||
self.smax = kwargs.get('smax', None)
|
||||
|
||||
def __draw_region_lines(self):
|
||||
lines = self._get_sat_lines(kind='T',
|
||||
smin=self.smin,
|
||||
smax=self.smax)
|
||||
drawLines(self.fluid_ref, lines, self.axis)
|
||||
|
||||
def _draw_graph(self):
|
||||
self.__draw_region_lines()
|
||||
self._plot_default_annotations()
|
||||
|
||||
def draw_isolines(self, iso_type, iso_range, num=10, rounding=False):
|
||||
iso_lines = IsoLines(self.fluid_ref,
|
||||
self.graph_type,
|
||||
iso_type,
|
||||
axis=self.axis)
|
||||
iso_lines.draw_isolines(iso_range, num, rounding)
|
||||
|
||||
|
||||
def Ts(Ref, Tmin=None, Tmax=None, show=False, axis=None, *args, **kwargs):
|
||||
"""
|
||||
Make a temperature-entropy plot for the given fluid
|
||||
|
||||
:Note:
|
||||
:func:`CoolProps.Plots.Ts` will be deprecated in future releases
|
||||
and replaced with :func:`CoolProps.Plots.PropsPlot`
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
Ref : str
|
||||
The given reference fluid
|
||||
Tmin : float, Optional
|
||||
Minimum limit for the saturation line
|
||||
Tmax : float, Optional
|
||||
Maximum limit for the saturation line
|
||||
show : bool, Optional
|
||||
Show the current plot
|
||||
(Default: False)
|
||||
axis : :func:`matplotlib.pyplot.gca()`, Optional
|
||||
The current axis system to be plotted to.
|
||||
(Default: create a new axis system)
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from CoolProp.Plots import Ts
|
||||
>>> Ts('R290', show=True)
|
||||
|
||||
>>> from CoolProp.Plots import Ts
|
||||
>>> Ts('R290', show=True, Tmin=200, Tmax=300)
|
||||
|
||||
>>> from matplotlib import pyplot
|
||||
>>> fig = pyplot.figure(1)
|
||||
>>> ax = fig.gca()
|
||||
>>> Ts('R290', show=True, axis=ax)
|
||||
"""
|
||||
plt = PropsPlot(Ref, 'Ts', smin=Tmin, smax=Tmax, axis=axis)
|
||||
plt._draw_graph()
|
||||
if show:
|
||||
plt.show()
|
||||
else:
|
||||
plt._draw_graph()
|
||||
return plt.axis
|
||||
|
||||
|
||||
def Ph(Ref, Tmin=None, Tmax=None, show=False, axis=None, *args, **kwargs):
|
||||
"""
|
||||
Make a pressure-enthalpy plot for the given fluid
|
||||
|
||||
:Note:
|
||||
:func:`CoolProps.Plots.Ph` will be deprecated in future releases
|
||||
and replaced with :func:`CoolProps.Plots.PropsPlot`
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
Ref : str
|
||||
The given reference fluid
|
||||
Tmin : float, Optional
|
||||
Minimum limit for the saturation line
|
||||
Tmax : float, Optional
|
||||
Maximum limit for the saturation line
|
||||
show : bool, Optional
|
||||
Show the current plot
|
||||
(Default: False)
|
||||
axis : :func:`matplotlib.pyplot.gca()`, Optional
|
||||
The current axis system to be plotted to.
|
||||
(Default: create a new axis system)
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from CoolProp.Plots import Ph
|
||||
>>> Ph('R290', show=True)
|
||||
|
||||
>>> from CoolProp.Plots import Ph
|
||||
>>> Ph('R290', show=True, Tmin=200, Tmax=300)
|
||||
|
||||
>>> from matplotlib import pyplot
|
||||
>>> fig = pyplot.figure(1)
|
||||
>>> ax = fig.gca()
|
||||
>>> Ph('R290', show=True, axis=ax)
|
||||
"""
|
||||
plt = PropsPlot(Ref, 'Ph', smin=Tmin, smax=Tmax, axis=axis)
|
||||
if show:
|
||||
plt.show()
|
||||
else:
|
||||
plt._draw_graph()
|
||||
return plt.axis
|
||||
|
||||
|
||||
def Ps(Ref, Tmin=None, Tmax=None, show=False, axis=None, *args, **kwargs):
|
||||
"""
|
||||
Make a pressure-entropy plot for the given fluid
|
||||
|
||||
:Note:
|
||||
:func:`CoolProps.Plots.Ps` will be deprecated in future releases
|
||||
and replaced with :func:`CoolProps.Plots.PropsPlot`
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
Ref : str
|
||||
The given reference fluid
|
||||
Tmin : float, Optional
|
||||
Minimum limit for the saturation line
|
||||
Tmax : float, Optional
|
||||
Maximum limit for the saturation line
|
||||
show : bool, Optional
|
||||
Show the current plot
|
||||
(Default: False)
|
||||
axis : :func:`matplotlib.pyplot.gca()`, Optional
|
||||
The current axis system to be plotted to.
|
||||
(Default: create a new axis system)
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from CoolProp.Plots import Ps
|
||||
>>> Ps('R290', show=True)
|
||||
|
||||
>>> from CoolProp.Plots import Ps
|
||||
>>> Ps('R290', show=True, Tmin=200, Tmax=300)
|
||||
|
||||
>>> from matplotlib import pyplot
|
||||
>>> fig = pyplot.figure(1)
|
||||
>>> ax = fig.gca()
|
||||
>>> Ps('R290', show=True, axis=ax)
|
||||
"""
|
||||
plt = PropsPlot(Ref, 'Ps', smin=Tmin, smax=Tmax, axis=axis)
|
||||
if show:
|
||||
plt.show()
|
||||
else:
|
||||
plt._draw_graph()
|
||||
return plt.axis
|
||||
|
||||
def PT(Ref, Tmin=None, Tmax=None, show=False, axis=None, *args, **kwargs):
|
||||
"""
|
||||
Make a pressure-temperature plot for the given fluid
|
||||
|
||||
:Note:
|
||||
:func:`CoolProps.Plots.PT` will be deprecated in future releases
|
||||
and replaced with :func:`CoolProps.Plots.PropsPlot`
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
Ref : str
|
||||
The given reference fluid
|
||||
Tmin : float, Optional
|
||||
Minimum limit for the saturation line
|
||||
Tmax : float, Optional
|
||||
Maximum limit for the saturation line
|
||||
show : bool, Optional
|
||||
Show the current plot
|
||||
(Default: False)
|
||||
axis : :func:`matplotlib.pyplot.gca()`, Optional
|
||||
The current axis system to be plotted to.
|
||||
(Default: create a new axis system)
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from CoolProp.Plots import PT
|
||||
>>> PT('R290', show=True)
|
||||
|
||||
>>> from CoolProp.Plots import PT
|
||||
>>> PT('R290', show=True, Tmin=200, Tmax=300)
|
||||
|
||||
>>> from matplotlib import pyplot
|
||||
>>> fig = pyplot.figure(1)
|
||||
>>> ax = fig.gca()
|
||||
>>> PT('R290', show=True, axis=ax)
|
||||
"""
|
||||
plt = PropsPlot(Ref, 'PT', smin=Tmin, smax=Tmax, axis=axis)
|
||||
if show:
|
||||
plt.show()
|
||||
else:
|
||||
plt._draw_graph()
|
||||
return plt.axis
|
||||
|
||||
def Prho(Ref, Tmin=None, Tmax=None, show=False, axis=None, *args, **kwargs):
|
||||
"""
|
||||
Make a pressure-density plot for the given fluid
|
||||
|
||||
:Note:
|
||||
:func:`CoolProps.Plots.Prho` will be deprecated in future releases
|
||||
and replaced with :func:`CoolProps.Plots.PropsPlot`
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
Ref : str
|
||||
The given reference fluid
|
||||
Tmin : float, Optional
|
||||
Minimum limit for the saturation line
|
||||
Tmax : float, Optional
|
||||
Maximum limit for the saturation line
|
||||
show : bool, Optional
|
||||
Show the current plot
|
||||
(Default: False)
|
||||
axis : :func:`matplotlib.pyplot.gca()`, Optional
|
||||
The current axis system to be plotted to.
|
||||
(Default: create a new axis system)
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from CoolProp.Plots import Prho
|
||||
>>> Prho('R290', show=True)
|
||||
|
||||
>>> from CoolProp.Plots import Prho
|
||||
>>> Prho('R290', show=True, Tmin=200, Tmax=300)
|
||||
|
||||
>>> from matplotlib import pyplot
|
||||
>>> fig = pyplot.figure(1)
|
||||
>>> ax = fig.gca()
|
||||
>>> Prho('R290', show=True, axis=ax)
|
||||
"""
|
||||
plt = PropsPlot(Ref, 'PD', smin=Tmin, smax=Tmax, axis=axis)
|
||||
if show:
|
||||
plt.show()
|
||||
else:
|
||||
plt._draw_graph()
|
||||
return plt.axis
|
||||
|
||||
def Trho(Ref, Tmin=None, Tmax=None, show=False, axis=None, *args, **kwargs):
|
||||
"""
|
||||
Make a temperature-density plot for the given fluid
|
||||
|
||||
:Note:
|
||||
:func:`CoolProps.Plots.Trho` will be deprecated in future releases
|
||||
and replaced with :func:`CoolProps.Plots.PropsPlot`
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
Ref : str
|
||||
The given reference fluid
|
||||
Tmin : float, Optional
|
||||
Minimum limit for the saturation line
|
||||
Tmax : float, Optional
|
||||
Maximum limit for the saturation line
|
||||
show : bool, Optional
|
||||
Show the current plot
|
||||
(Default: False)
|
||||
axis : :func:`matplotlib.pyplot.gca()`, Optional
|
||||
The current axis system to be plotted to.
|
||||
(Default: create a new axis system)
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from CoolProp.Plots import Trho
|
||||
>>> Trho('R290', show=True)
|
||||
|
||||
>>> from CoolProp.Plots import Trho
|
||||
>>> Trho('R290', show=True, Tmin=200, Tmax=300)
|
||||
|
||||
>>> from matplotlib import pyplot
|
||||
>>> fig = pyplot.figure(1)
|
||||
>>> ax = fig.gca()
|
||||
>>> Trho('R290', show=True, axis=ax)
|
||||
"""
|
||||
plt = PropsPlot(Ref, 'TD', smin=Tmin, smax=Tmax, axis=axis)
|
||||
if show:
|
||||
plt.show()
|
||||
else:
|
||||
plt._draw_graph()
|
||||
return plt.axis
|
||||
|
||||
def hs(Ref, Tmin=None, Tmax=None, show=False, axis=None, *args, **kwargs):
|
||||
"""
|
||||
Make a enthalpy-entropy plot for the given fluid
|
||||
|
||||
:Note:
|
||||
:func:`CoolProps.Plots.hs` will be deprecated in future releases
|
||||
and replaced with :func:`CoolProps.Plots.PropsPlot`
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
Ref : str
|
||||
The given reference fluid
|
||||
Tmin : float, Optional
|
||||
Minimum limit for the saturation line
|
||||
Tmax : float, Optional
|
||||
Maximum limit for the saturation line
|
||||
show : bool, Optional
|
||||
Show the current plot
|
||||
(Default: False)
|
||||
axis : :func:`matplotlib.pyplot.gca()`, Optional
|
||||
The current axis system to be plotted to.
|
||||
(Default: create a new axis system)
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from CoolProp.Plots import hs
|
||||
>>> hs('R290', show=True)
|
||||
|
||||
>>> from CoolProp.Plots import hs
|
||||
>>> hs('R290', show=True, Tmin=200, Tmax=300)
|
||||
|
||||
>>> from matplotlib import pyplot
|
||||
>>> fig = pyplot.figure(1)
|
||||
>>> ax = fig.gca()
|
||||
>>> hs('R290', show=True, axis=ax)
|
||||
"""
|
||||
plt = PropsPlot(Ref, 'hs', smin=Tmin, smax=Tmax, axis=axis)
|
||||
if show:
|
||||
plt.show()
|
||||
else:
|
||||
plt._draw_graph()
|
||||
return plt.axis
|
||||
|
||||
def drawIsoLines(Ref, plot, which, iValues=[], num=0, show=False, axis=None):
|
||||
"""
|
||||
Draw lines with constant values of type 'which' in terms of x and y as
|
||||
defined by 'plot'. 'iMin' and 'iMax' are minimum and maximum value
|
||||
between which 'num' get drawn.
|
||||
|
||||
:Note:
|
||||
:func:`CoolProps.Plots.drawIsoLines` will be depreciated in future
|
||||
releases and replaced with :func:`CoolProps.Plots.IsoLines`
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
Ref : str
|
||||
The given reference fluid
|
||||
plot : str
|
||||
The plot type used
|
||||
which : str
|
||||
The iso line type
|
||||
iValues : list
|
||||
The list of constant iso line values
|
||||
num : int, Optional
|
||||
The number of iso lines
|
||||
(Default: 0 - Use iValues list only)
|
||||
show : bool, Optional
|
||||
Show the current plot
|
||||
(Default: False)
|
||||
axis : :func:`matplotlib.pyplot.gca()`, Optional
|
||||
The current axis system to be plotted to.
|
||||
(Default: create a new axis system)
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from matplotlib import pyplot
|
||||
>>> from CoolProp.Plots import Ts, drawIsoLines
|
||||
>>>
|
||||
>>> Ref = 'n-Pentane'
|
||||
>>> ax = Ts(Ref)
|
||||
>>> ax.set_xlim([-0.5, 1.5])
|
||||
>>> ax.set_ylim([300, 530])
|
||||
>>> quality = drawIsoLines(Ref, 'Ts', 'Q', [0.3, 0.5, 0.7, 0.8], axis=ax)
|
||||
>>> isobars = drawIsoLines(Ref, 'Ts', 'P', [100, 2000], num=5, axis=ax)
|
||||
>>> isochores = drawIsoLines(Ref, 'Ts', 'D', [2, 600], num=7, axis=ax)
|
||||
>>> pyplot.show()
|
||||
"""
|
||||
isolines = IsoLines(Ref, plot, which, axis=axis)
|
||||
lines = isolines.draw_isolines(iValues, num)
|
||||
if show:
|
||||
isolines.show()
|
||||
return lines
|
||||
@@ -1,168 +0,0 @@
|
||||
"""
|
||||
This file implements a psychrometric chart for air at 1 atm
|
||||
"""
|
||||
|
||||
from CoolProp.HumidAirProp import HAProps
|
||||
from CoolProp.Plots.Plots import InlineLabel
|
||||
import matplotlib, numpy, textwrap
|
||||
|
||||
import_template=(
|
||||
"""
|
||||
import numpy, matplotlib
|
||||
from CoolProp.HumidAirProp import HAProps
|
||||
from CoolProp.Plots.Plots import InlineLabel
|
||||
|
||||
p = 101.325
|
||||
Tdb = numpy.linspace(-10,60,100)+273.15
|
||||
|
||||
#Make the figure and the axes
|
||||
fig=matplotlib.pyplot.figure(figsize=(10,8))
|
||||
ax=fig.add_axes((0.1,0.1,0.85,0.85))
|
||||
"""
|
||||
)
|
||||
|
||||
closure_template=(
|
||||
"""
|
||||
matplotlib.pyplot.show()
|
||||
"""
|
||||
)
|
||||
|
||||
Tdb = numpy.linspace(-10,60,100)+273.15
|
||||
p = 101.325
|
||||
|
||||
class PlotFormatting(object):
|
||||
|
||||
def plot(self,ax):
|
||||
ax.set_xlim(Tdb[0]-273.15,Tdb[-1]-273.15)
|
||||
ax.set_ylim(0,0.03)
|
||||
ax.set_xlabel(r"Dry bulb temperature [$^{\circ}$C]")
|
||||
ax.set_ylabel(r"Humidity ratio ($m_{water}/m_{dry\ air}$) [-]")
|
||||
|
||||
def __str__(self):
|
||||
return textwrap.dedent("""
|
||||
ax.set_xlim(Tdb[0]-273.15,Tdb[-1]-273.15)
|
||||
ax.set_ylim(0,0.03)
|
||||
ax.set_xlabel(r"Dry bulb temperature [$^{\circ}$C]")
|
||||
ax.set_ylabel(r"Humidity ratio ($m_{water}/m_{dry\ air}$) [-]")
|
||||
""")
|
||||
|
||||
class SaturationLine(object):
|
||||
|
||||
def plot(self,ax):
|
||||
w = [HAProps('W','T',T,'P',p,'R',1.0) for T in Tdb]
|
||||
ax.plot(Tdb-273.15,w,lw=2)
|
||||
|
||||
def __str__(self):
|
||||
return textwrap.dedent("""
|
||||
# Saturation line
|
||||
w = [HAProps('W','T',T,'P',p,'R',1.0) for T in Tdb]
|
||||
ax.plot(Tdb-273.15,w,lw=2)
|
||||
"""
|
||||
)
|
||||
|
||||
class HumidityLabels(object):
|
||||
def __init__(self,RH_values,h):
|
||||
self.RH_values = RH_values
|
||||
self.h = h
|
||||
|
||||
def plot(self,ax):
|
||||
xv = Tdb #[K]
|
||||
for RH in self.RH_values:
|
||||
yv = [HAProps('W','T',T,'P',p,'R',RH) for T in Tdb]
|
||||
y = HAProps('W','P',p,'H',self.h,'R',RH)
|
||||
T_K,w,rot = InlineLabel(xv, yv, y=y, axis = ax)
|
||||
string = r'$\phi$='+str(RH*100)+'%'
|
||||
#Make a temporary label to get its bounding box
|
||||
bbox_opts = dict(boxstyle='square,pad=0.0',fc='white',ec='None',alpha = 0.5)
|
||||
ax.text(T_K-273.15,w,string,rotation = rot,ha ='center',va='center',bbox=bbox_opts)
|
||||
|
||||
def __str__(self):
|
||||
return textwrap.dedent("""
|
||||
xv = Tdb #[K]
|
||||
for RH in {RHValues:s}:
|
||||
yv = [HAProps('W','T',T,'P',p,'R',RH) for T in Tdb]
|
||||
y = HAProps('W','P',p,'H',{h:f},'R',RH)
|
||||
T_K,w,rot = InlineLabel(xv, yv, y=y, axis = ax)
|
||||
string = r'$\phi$='+str(RH*100)+'%'
|
||||
bbox_opts = dict(boxstyle='square,pad=0.0',fc='white',ec='None',alpha = 0.5)
|
||||
ax.text(T_K-273.15,w,string,rotation = rot,ha ='center',va='center',bbox=bbox_opts)
|
||||
""".format(h=self.h, RHValues=str(self.RH_values))
|
||||
)
|
||||
|
||||
class HumidityLines(object):
|
||||
|
||||
def __init__(self,RH_values):
|
||||
self.RH_values = RH_values
|
||||
|
||||
def plot(self,ax):
|
||||
for RH in self.RH_values:
|
||||
w = [HAProps('W','T',T,'P',p,'R',RH) for T in Tdb]
|
||||
ax.plot(Tdb-273.15,w,'r',lw=1)
|
||||
|
||||
def __str__(self):
|
||||
return textwrap.dedent("""
|
||||
# Humidity lines
|
||||
RHValues = {RHValues:s}
|
||||
for RH in RHValues:
|
||||
w = [HAProps('W','T',T,'P',p,'R',RH) for T in Tdb]
|
||||
ax.plot(Tdb-273.15,w,'r',lw=1)
|
||||
""".format(RHValues=str(self.RH_values))
|
||||
)
|
||||
|
||||
class EnthalpyLines(object):
|
||||
|
||||
def __init__(self,H_values):
|
||||
self.H_values = H_values
|
||||
|
||||
def plot(self,ax):
|
||||
for H in self.H_values:
|
||||
#Line goes from saturation to zero humidity ratio for this enthalpy
|
||||
T1 = HAProps('T','H',H,'P',p,'R',1.0)-273.15
|
||||
T0 = HAProps('T','H',H,'P',p,'R',0.0)-273.15
|
||||
w1 = HAProps('W','H',H,'P',p,'R',1.0)
|
||||
w0 = HAProps('W','H',H,'P',p,'R',0.0)
|
||||
ax.plot(numpy.r_[T1,T0],numpy.r_[w1,w0],'r',lw=1)
|
||||
|
||||
def __str__(self):
|
||||
return textwrap.dedent("""
|
||||
# Humidity lines
|
||||
for H in {HValues:s}:
|
||||
#Line goes from saturation to zero humidity ratio for this enthalpy
|
||||
T1 = HAProps('T','H',H,'P',p,'R',1.0)-273.15
|
||||
T0 = HAProps('T','H',H,'P',p,'R',0.0)-273.15
|
||||
w1 = HAProps('W','H',H,'P',p,'R',1.0)
|
||||
w0 = HAProps('W','H',H,'P',p,'R',0.0)
|
||||
ax.plot(numpy.r_[T1,T0],numpy.r_[w1,w0],'r',lw=1)
|
||||
""".format(HValues=str(self.H_values))
|
||||
)
|
||||
|
||||
if __name__=='__main__':
|
||||
fig=matplotlib.pyplot.figure(figsize=(10,8))
|
||||
ax=fig.add_axes((0.1,0.1,0.85,0.85))
|
||||
ax.set_xlim(Tdb[0]-273.15,Tdb[-1]-273.15)
|
||||
ax.set_ylim(0,0.03)
|
||||
ax.set_xlabel(r"Dry bulb temperature [$^{\circ}$C]")
|
||||
ax.set_ylabel(r"Humidity ratio ($m_{water}/m_{dry\ air}$) [-]")
|
||||
|
||||
SL = SaturationLine()
|
||||
SL.plot(ax)
|
||||
|
||||
RHL = HumidityLines([0.05,0.1,0.15,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9])
|
||||
RHL.plot(ax)
|
||||
|
||||
RHLabels = HumidityLabels([0.05,0.1,0.15,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9], h=65)
|
||||
RHLabels.plot(ax)
|
||||
|
||||
HL = EnthalpyLines(range(-20,100,10))
|
||||
HL.plot(ax)
|
||||
|
||||
PF = PlotFormatting()
|
||||
PF.plot(ax)
|
||||
|
||||
matplotlib.pyplot.show()
|
||||
|
||||
fp = open('PsychScript.py','w')
|
||||
for chunk in [import_template,SL,RHL,HL,PF,RHLabels,closure_template]:
|
||||
fp.write(str(chunk))
|
||||
fp.close()
|
||||
execfile('PsychScript.py')
|
||||
@@ -1,46 +0,0 @@
|
||||
|
||||
import numpy, matplotlib
|
||||
from CoolProp.HumidAirProp import HAProps
|
||||
from CoolProp.Plots.Plots import InlineLabel
|
||||
|
||||
p = 101.325
|
||||
Tdb = numpy.linspace(-10,60,100)+273.15
|
||||
|
||||
#Make the figure and the axes
|
||||
fig=matplotlib.pyplot.figure(figsize=(10,8))
|
||||
ax=fig.add_axes((0.1,0.1,0.85,0.85))
|
||||
|
||||
# Saturation line
|
||||
w = [HAProps('W','T',T,'P',p,'R',1.0) for T in Tdb]
|
||||
ax.plot(Tdb-273.15,w,lw=2)
|
||||
|
||||
# Humidity lines
|
||||
RHValues = [0.05, 0.1, 0.15, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
|
||||
for RH in RHValues:
|
||||
w = [HAProps('W','T',T,'P',p,'R',RH) for T in Tdb]
|
||||
ax.plot(Tdb-273.15,w,'r',lw=1)
|
||||
|
||||
# Humidity lines
|
||||
for H in [-20, -10, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90]:
|
||||
#Line goes from saturation to zero humidity ratio for this enthalpy
|
||||
T1 = HAProps('T','H',H,'P',p,'R',1.0)-273.15
|
||||
T0 = HAProps('T','H',H,'P',p,'R',0.0)-273.15
|
||||
w1 = HAProps('W','H',H,'P',p,'R',1.0)
|
||||
w0 = HAProps('W','H',H,'P',p,'R',0.0)
|
||||
ax.plot(numpy.r_[T1,T0],numpy.r_[w1,w0],'r',lw=1)
|
||||
|
||||
ax.set_xlim(Tdb[0]-273.15,Tdb[-1]-273.15)
|
||||
ax.set_ylim(0,0.03)
|
||||
ax.set_xlabel(r"Dry bulb temperature [$^{\circ}$C]")
|
||||
ax.set_ylabel(r"Humidity ratio ($m_{water}/m_{dry\ air}$) [-]")
|
||||
|
||||
xv = Tdb #[K]
|
||||
for RH in [0.05, 0.1, 0.15, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]:
|
||||
yv = [HAProps('W','T',T,'P',p,'R',RH) for T in Tdb]
|
||||
y = HAProps('W','P',p,'H',65.000000,'R',RH)
|
||||
T_K,w,rot = InlineLabel(xv, yv, y=y, axis = ax)
|
||||
string = r'$\phi$='+str(RH*100)+'%'
|
||||
bbox_opts = dict(boxstyle='square,pad=0.0',fc='white',ec='None',alpha = 0.5)
|
||||
ax.text(T_K-273.15,w,string,rotation = rot,ha ='center',va='center',bbox=bbox_opts)
|
||||
|
||||
matplotlib.pyplot.show()
|
||||
@@ -1,423 +0,0 @@
|
||||
import matplotlib,numpy
|
||||
|
||||
from CoolProp.CoolProp import Props
|
||||
from scipy.optimize import newton
|
||||
|
||||
|
||||
def SimpleCycle(Ref,Te,Tc,DTsh,DTsc,eta_a,Ts_Ph='Ph',skipPlot=False,axis=None):
|
||||
"""
|
||||
This function plots a simple four-component cycle, on the current axis, or that given by the optional parameter *axis*
|
||||
|
||||
Required parameters:
|
||||
|
||||
* Ref : A string for the refrigerant
|
||||
* Te : Evap Temperature in K
|
||||
* Tc : Condensing Temperature in K
|
||||
* DTsh : Evaporator outlet superheat in K
|
||||
* DTsc : Condenser outlet subcooling in K
|
||||
* eta_a : Adiabatic efficiency of compressor (no units) in range [0,1]
|
||||
|
||||
Optional parameters:
|
||||
|
||||
* Ts_Ph : 'Ts' for a Temperature-Entropy plot, 'Ph' for a Pressure-Enthalpy
|
||||
* axis : An axis to use instead of the active axis
|
||||
* skipPlot : If True, won't actually plot anything, just print COP
|
||||
|
||||
"""
|
||||
T=numpy.zeros((6))
|
||||
h=numpy.zeros_like(T)
|
||||
p=numpy.zeros_like(T)
|
||||
s=numpy.zeros_like(T)
|
||||
T[1]=Te+DTsh
|
||||
pe=Props('P','T',Te,'Q',1.0,Ref)
|
||||
pc=Props('P','T',Tc,'Q',1.0,Ref)
|
||||
h[1]=Props('H','T',T[1],'P',pe,Ref)
|
||||
s[1]=Props('S','T',T[1],'P',pe,Ref)
|
||||
T2s=newton(lambda T: Props('S','T',T,'P',pc,Ref)-s[1],T[1]+30)
|
||||
h2s=Props('H','T',T2s,'P',pc,Ref)
|
||||
h[2]=(h2s-h[1])/eta_a+h[1]
|
||||
T[2]=Props('T','H',h[2],'P',pc,Ref)
|
||||
s[2]=Props('S','T',T[2],'P',pc,Ref)
|
||||
|
||||
sbubble_c=Props('S','P',pc,'Q',0,Ref)
|
||||
sdew_c=Props('S','P',pc,'Q',1,Ref)
|
||||
sbubble_e=Props('S','P',pe,'Q',0,Ref)
|
||||
sdew_e=Props('S','P',pe,'Q',1,Ref)
|
||||
T[3]=Tc-DTsc
|
||||
h[3]=Props('H','T',T[3],'P',pc,Ref)
|
||||
s[3]=Props('S','T',T[3],'P',pc,Ref)
|
||||
h[4]=h[3]
|
||||
h[5]=h[1]
|
||||
s[5]=s[1]
|
||||
T[5]=T[1]
|
||||
p=[numpy.nan,pe,pc,pc,pe,pe]
|
||||
COP=(h[1]-h[4])/(h[2]-h[1])
|
||||
COPH=(h[2]-h[3])/(h[2]-h[1])
|
||||
|
||||
hsatL=Props('H','T',Te,'Q',0,Ref)
|
||||
hsatV=Props('H','T',Te,'Q',1,Ref)
|
||||
ssatL=Props('S','T',Te,'Q',0,Ref)
|
||||
ssatV=Props('S','T',Te,'Q',1,Ref)
|
||||
vsatL=1/Props('D','T',Te,'Q',0,Ref)
|
||||
vsatV=1/Props('D','T',Te,'Q',1,Ref)
|
||||
x=(h[4]-hsatL)/(hsatV-hsatL)
|
||||
s[4]=x*ssatV+(1-x)*ssatL
|
||||
T[4]=x*Te+(1-x)*Te
|
||||
|
||||
print(COP,COPH)
|
||||
if skipPlot==False:
|
||||
if axis==None:
|
||||
ax=matplotlib.pyplot.gca()
|
||||
if Ts_Ph in ['ph','Ph']:
|
||||
ax.plot(h,p)
|
||||
elif Ts_Ph in ['Ts','ts']:
|
||||
s=list(s)
|
||||
T=list(T)
|
||||
s.insert(5,sdew_e)
|
||||
T.insert(5,Te)
|
||||
s.insert(3,sbubble_c)
|
||||
T.insert(3,Tc)
|
||||
s.insert(3,sdew_c)
|
||||
T.insert(3,Tc)
|
||||
ax.plot(s[1::],T[1::],'b')
|
||||
else:
|
||||
raise TypeError('Type of Ts_Ph invalid')
|
||||
|
||||
def TwoStage(Ref,Q,Te,Tc,DTsh,DTsc,eta_oi,f_p,Tsat_ic,DTsh_ic,Ts_Ph='Ph',prints=False,skipPlot=False,axis=None,**kwargs):
|
||||
"""
|
||||
This function plots a two-stage cycle, on the current axis, or that given by the optional parameter *axis*
|
||||
|
||||
Required parameters:
|
||||
|
||||
* Ref : Refrigerant [string]
|
||||
* Q : Cooling capacity [W]
|
||||
* Te : Evap Temperature [K]
|
||||
* Tc : Condensing Temperature [K]
|
||||
* DTsh : Evaporator outlet superheat [K]
|
||||
* DTsc : Condenser outlet subcooling [K]
|
||||
* eta_oi : Adiabatic efficiency of compressor (no units) in range [0,1]
|
||||
* f_p : fraction of compressor power lost as ambient heat transfer in range [0,1]
|
||||
* Tsat_ic : Saturation temperature corresponding to intermediate pressure [K]
|
||||
* DTsh_ic : Superheating at outlet of intermediate stage [K]
|
||||
|
||||
Optional parameters:
|
||||
|
||||
* Ts_Ph : 'Ts' for a Temperature-Entropy plot, 'Ph' for a Pressure-Enthalpy
|
||||
* prints : True to print out some values
|
||||
* axis : An axis to use instead of the active axis
|
||||
* skipPlot : If True, won't actually plot anything, just print COP
|
||||
|
||||
"""
|
||||
|
||||
T=numpy.zeros((8))
|
||||
h=numpy.zeros_like(T)
|
||||
p=numpy.zeros_like(T)
|
||||
s=numpy.zeros_like(T)
|
||||
rho=numpy.zeros_like(T)
|
||||
T[0]=numpy.NAN
|
||||
s[0]=numpy.NAN
|
||||
T[1]=Te+DTsh
|
||||
pe=Props('P','T',Te,'Q',1.0,Ref)
|
||||
pc=Props('P','T',Tc,'Q',1.0,Ref)
|
||||
pic=Props('P','T',Tsat_ic,'Q',1.0,Ref)
|
||||
Tbubble_c=Props('T','P',pc,'Q',0,Ref)
|
||||
Tbubble_e=Props('T','P',pe,'Q',0,Ref)
|
||||
|
||||
h[1]=Props('H','T',T[1],'P',pe,Ref)
|
||||
s[1]=Props('S','T',T[1],'P',pe,Ref)
|
||||
rho[1]=Props('D','T',T[1],'P',pe,Ref)
|
||||
T[5]=Tbubble_c-DTsc
|
||||
h[5]=Props('H','T',T[5],'P',pc,Ref)
|
||||
s[5]=Props('S','T',T[5],'P',pc,Ref)
|
||||
rho[5]=Props('D','T',T[5],'P',pc,Ref)
|
||||
mdot=Q/(h[1]-h[5])
|
||||
|
||||
rho1=Props('D','T',T[1],'P',pe,Ref)
|
||||
h2s=Props('H','S',s[1],'P',pic,Ref)
|
||||
Wdot1=mdot*(h2s-h[1])/eta_oi
|
||||
h[2]=h[1]+(1-f_p)*Wdot1/mdot
|
||||
T[2]=Props('T','H',h[2],'P',pic,Ref)
|
||||
s[2]=Props('S','T',T[2],'P',pic,Ref)
|
||||
rho[2]=Props('D','T',T[2],'P',pic,Ref)
|
||||
T[3]=288
|
||||
p[3]=pic
|
||||
h[3]=Props('H','T',T[3],'P',pic,Ref)
|
||||
s[3]=Props('S','T',T[3],'P',pic,Ref)
|
||||
rho[3]=Props('D','T',T[3],'P',pic,Ref)
|
||||
rho3=Props('D','T',T[3],'P',pic,Ref)
|
||||
h4s=Props('H','T',s[3],'P',pc,Ref)
|
||||
Wdot2=mdot*(h4s-h[3])/eta_oi
|
||||
h[4]=h[3]+(1-f_p)*Wdot2/mdot
|
||||
T[4]=Props('T','H',h[4],'P',pc,Ref)
|
||||
s[4]=Props('S','T',T[4],'P',pc,Ref)
|
||||
rho[4]=Props('D','T',T[4],'P',pc,Ref)
|
||||
|
||||
sbubble_e=Props('S','T',Tbubble_e,'Q',0,Ref)
|
||||
sbubble_c=Props('S','T',Tbubble_c,'Q',0,Ref)
|
||||
sdew_e=Props('S','T',Te,'Q',1,Ref)
|
||||
sdew_c=Props('S','T',Tc,'Q',1,Ref)
|
||||
|
||||
hsatL=Props('H','T',Tbubble_e,'Q',0,Ref)
|
||||
hsatV=Props('H','T',Te,'Q',1,Ref)
|
||||
ssatL=Props('S','T',Tbubble_e,'Q',0,Ref)
|
||||
ssatV=Props('S','T',Te,'Q',1,Ref)
|
||||
vsatL=1/Props('D','T',Tbubble_e,'Q',0,Ref)
|
||||
vsatV=1/Props('D','T',Te,'Q',1,Ref)
|
||||
x=(h[5]-hsatL)/(hsatV-hsatL)
|
||||
s[6]=x*ssatV+(1-x)*ssatL
|
||||
T[6]=x*Te+(1-x)*Tbubble_e
|
||||
rho[6]=1.0/(x*vsatV+(1-x)*vsatL)
|
||||
|
||||
h[6]=h[5]
|
||||
h[7]=h[1]
|
||||
s[7]=s[1]
|
||||
T[7]=T[1]
|
||||
p=[numpy.nan,pe,pic,pic,pc,pc,pe,pe]
|
||||
COP=Q/(Wdot1+Wdot2)
|
||||
RE=h[1]-h[6]
|
||||
|
||||
if prints==True:
|
||||
print('x5:',x)
|
||||
print('COP:', COP)
|
||||
print('COPH', (Q+Wdot1+Wdot2)/(Wdot1+Wdot2))
|
||||
print(T[2]-273.15,T[4]-273.15,p[2]/p[1],p[4]/p[3])
|
||||
print(mdot,mdot*(h[4]-h[5]),pic)
|
||||
print('Vdot1',mdot/rho1,'Vdisp',mdot/rho1/(3500/60.)*1e6/0.7)
|
||||
print('Vdot2',mdot/rho3,'Vdisp',mdot/rho3/(3500/60.)*1e6/0.7)
|
||||
print(mdot*(h[4]-h[5]),Tc-273.15)
|
||||
for i in range(1,len(T)-1):
|
||||
print('%d & %g & %g & %g & %g & %g \\\\' %(i,T[i]-273.15,p[i],h[i],s[i],rho[i]))
|
||||
else:
|
||||
print(Tsat_ic,COP)
|
||||
|
||||
if skipPlot==False:
|
||||
if axis==None:
|
||||
ax=matplotlib.pyplot.gca()
|
||||
else:
|
||||
ax=axis
|
||||
if Ts_Ph in ['ph','Ph']:
|
||||
ax.plot(h,p)
|
||||
elif Ts_Ph in ['Ts','ts']:
|
||||
s_copy=s.copy()
|
||||
T_copy=T.copy()
|
||||
for i in range(1,len(s)-1):
|
||||
ax.plot(s[i],T[i],'bo',mfc='b',mec='b')
|
||||
dT=[0,-5,5,-20,5,5,5]
|
||||
ds=[0,0.05,0,0,0,0,0]
|
||||
ax.text(s[i]+ds[i],T[i]+dT[i],str(i))
|
||||
|
||||
s=list(s)
|
||||
T=list(T)
|
||||
s.insert(7,sdew_e)
|
||||
T.insert(7,Te)
|
||||
s.insert(5,sbubble_c)
|
||||
T.insert(5,Tbubble_c)
|
||||
s.insert(5,sdew_c)
|
||||
T.insert(5,Tc)
|
||||
|
||||
ax.plot(s,T)
|
||||
s=s_copy
|
||||
T=T_copy
|
||||
else:
|
||||
raise TypeError('Type of Ts_Ph invalid')
|
||||
return COP
|
||||
|
||||
def EconomizedCycle(Ref,Qin,Te,Tc,DTsh,DTsc,eta_oi,f_p,Ti,Ts_Ph='Ts',skipPlot=False,axis=None,**kwargs):
|
||||
"""
|
||||
This function plots an economized cycle, on the current axis, or that given by the optional parameter *axis*
|
||||
|
||||
Required parameters:
|
||||
|
||||
* Ref : Refrigerant [string]
|
||||
* Qin : Cooling capacity [W]
|
||||
* Te : Evap Temperature [K]
|
||||
* Tc : Condensing Temperature [K]
|
||||
* DTsh : Evaporator outlet superheat [K]
|
||||
* DTsc : Condenser outlet subcooling [K]
|
||||
* eta_oi : Adiabatic efficiency of compressor (no units) in range [0,1]
|
||||
* f_p : fraction of compressor power lost as ambient heat transfer in range [0,1]
|
||||
* Ti : Saturation temperature corresponding to intermediate pressure [K]
|
||||
|
||||
Optional parameters:
|
||||
|
||||
* Ts_Ph : 'Ts' for a Temperature-Entropy plot, 'Ph' for a Pressure-Enthalpy
|
||||
* axis : An axis to use instead of the active axis
|
||||
* skipPlot : If True, won't actually plot anything, just print COP
|
||||
|
||||
"""
|
||||
|
||||
m=1
|
||||
|
||||
T=numpy.zeros((11))
|
||||
h=numpy.zeros_like(T)
|
||||
p=numpy.zeros_like(T)
|
||||
s=numpy.zeros_like(T)
|
||||
rho=numpy.zeros_like(T)
|
||||
|
||||
T[0]=numpy.NAN
|
||||
s[0]=numpy.NAN
|
||||
T[1]=Te+DTsh
|
||||
pe=Props('P','T',Te,'Q',1.0,Ref)
|
||||
pc=Props('P','T',Tc,'Q',1.0,Ref)
|
||||
pi=Props('P','T',Ti,'Q',1.0,Ref)
|
||||
p[1]=pe
|
||||
h[1]=Props('H','T',T[1],'P',pe,Ref)
|
||||
s[1]=Props('S','T',T[1],'P',pe,Ref)
|
||||
rho[1]=Props('D','T',T[1],'P',pe,Ref)
|
||||
h2s=Props('H','S',s[1],'P',pi,Ref)
|
||||
wdot1=(h2s-h[1])/eta_oi
|
||||
h[2]=h[1]+(1-f_p[0])*wdot1
|
||||
p[2]=pi
|
||||
T[2]=T_hp(Ref,h[2],pi,T2s)
|
||||
s[2]=Props('S','T',T[2],'P',pi,Ref)
|
||||
rho[2]=Props('D','T',T[2],'P',pi,Ref)
|
||||
|
||||
T[5]=Tc-DTsc
|
||||
h[5]=Props('H','T',T[5],'P',pc,Ref)
|
||||
s[5]=Props('S','T',T[5],'P',pc,Ref)
|
||||
rho[5]=Props('D','T',T[5],'P',pc,Ref)
|
||||
|
||||
p[5]=pc
|
||||
p[6]=pi
|
||||
h[6]=h[5]
|
||||
|
||||
p[7]=pi
|
||||
p[8]=pi
|
||||
p[6]=pi
|
||||
T[7]=Ti
|
||||
h[7]=Props('H','T',Ti,'Q',1,Ref)
|
||||
s[7]=Props('S','T',Ti,'Q',1,Ref)
|
||||
rho[7]=Props('D','T',Ti,'Q',1,Ref)
|
||||
T[8]=Ti
|
||||
h[8]=Props('H','T',Ti,'Q',0,Ref)
|
||||
s[8]=Props('S','T',Ti,'Q',0,Ref)
|
||||
rho[8]=Props('D','T',Ti,'Q',0,Ref)
|
||||
x6=(h[6]-h[8])/(h[7]-h[8]) #Vapor Quality
|
||||
s[6]=s[7]*x6+s[8]*(1-x6)
|
||||
rho[6]=1.0/(x6/rho[7]+(1-x6)/rho[8])
|
||||
T[6]=Ti
|
||||
|
||||
#Injection mass flow rate
|
||||
x=m*(h[6]-h[8])/(h[7]-h[6])
|
||||
|
||||
|
||||
p[3]=pi
|
||||
h[3]=(m*h[2]+x*h[7])/(m+x)
|
||||
T[3]=T_hp(Ref,h[3],pi,T[2])
|
||||
s[3]=Props('S','T',T[3],'P',pi,Ref)
|
||||
rho[3]=Props('D','T',T[3],'P',pi,Ref)
|
||||
T4s=newton(lambda T: Props('S','T',T,'P',pc,Ref)-s[3],T[2]+30)
|
||||
h4s=Props('H','T',T4s,'P',pc,Ref)
|
||||
p[4]=pc
|
||||
wdot2=(h4s-h[3])/eta_oi
|
||||
h[4]=h[3]+(1-f_p[1])*wdot2
|
||||
T[4]=T_hp(Ref,h[4],pc,T4s)
|
||||
s[4]=Props('S','T',T[4],'P',pc,Ref)
|
||||
rho[4]=Props('D','T',T[4],'P',pc,Ref)
|
||||
|
||||
p[9]=pe
|
||||
h[9]=h[8]
|
||||
T[9]=Te
|
||||
hsatL_e=Props('H','T',Te,'Q',0,Ref)
|
||||
hsatV_e=Props('H','T',Te,'Q',1,Ref)
|
||||
ssatL_e=Props('S','T',Te,'Q',0,Ref)
|
||||
ssatV_e=Props('S','T',Te,'Q',1,Ref)
|
||||
vsatL_e=1/Props('D','T',Te,'Q',0,Ref)
|
||||
vsatV_e=1/Props('D','T',Te,'Q',1,Ref)
|
||||
x9=(h[9]-hsatL_e)/(hsatV_e-hsatL_e) #Vapor Quality
|
||||
s[9]=ssatV_e*x9+ssatL_e*(1-x9)
|
||||
rho[9]=1.0/(x9*vsatV_e+(1-x9)*vsatL_e)
|
||||
|
||||
s[10]=s[1]
|
||||
T[10]=T[1]
|
||||
h[10]=h[1]
|
||||
p[10]=p[1]
|
||||
|
||||
Tbubble_e=Te
|
||||
Tbubble_c=Tc
|
||||
sbubble_e=Props('S','T',Tbubble_e,'Q',0,Ref)
|
||||
sbubble_c=Props('S','T',Tbubble_c,'Q',0,Ref)
|
||||
sdew_e=Props('S','T',Te,'Q',1,Ref)
|
||||
sdew_c=Props('S','T',Tc,'Q',1,Ref)
|
||||
|
||||
Wdot1=m*wdot1
|
||||
Wdot2=(m+x)*wdot2
|
||||
if skipPlot==False:
|
||||
if axis==None:
|
||||
ax=matplotlib.pyplot.gca()
|
||||
else:
|
||||
ax=axis
|
||||
if Ts_Ph in ['ph','Ph']:
|
||||
ax.plot(h,p)
|
||||
ax.set_yscale('log')
|
||||
elif Ts_Ph in ['Ts','ts']:
|
||||
ax.plot(numpy.r_[s[7],s[3]],numpy.r_[T[7],T[3]],'b')
|
||||
s_copy=s.copy()
|
||||
T_copy=T.copy()
|
||||
dT=[0,-5,5,-12,5,12,-12,0,0,0]
|
||||
ds=[0,0.05,0.05,0,0.05,0,0.0,0.05,-0.05,-0.05]
|
||||
for i in range(1,len(s)-1):
|
||||
ax.plot(s[i],T[i],'bo',mfc='b',mec='b')
|
||||
ax.text(s[i]+ds[i],T[i]+dT[i],str(i),ha='center',va='center')
|
||||
|
||||
s=list(s)
|
||||
T=list(T)
|
||||
s.insert(10,sdew_e)
|
||||
T.insert(10,Te)
|
||||
s.insert(5,sbubble_c)
|
||||
T.insert(5,Tbubble_c)
|
||||
s.insert(5,sdew_c)
|
||||
T.insert(5,Tc)
|
||||
ax.plot(s,T,'b')
|
||||
|
||||
s=s_copy
|
||||
T=T_copy
|
||||
else:
|
||||
raise TypeError('Type of Ts_Ph invalid')
|
||||
|
||||
COP=m*(h[1]-h[9])/(m*(h[2]-h[1])+(m+x)*(h[4]-h[3]))
|
||||
for i in range(1,len(T)-1):
|
||||
print('%d & %g & %g & %g & %g & %g \\\\' %(i,T[i]-273.15,p[i],h[i],s[i],rho[i]))
|
||||
print(x,m*(h[1]-h[9]),(m*(h[2]-h[1])+(m+x)*(h[4]-h[3])),COP)
|
||||
mdot=Qin/(h[1]-h[9])
|
||||
mdot_inj=x*mdot
|
||||
print('x9',x9,)
|
||||
print('Qcond',(mdot+mdot_inj)*(h[4]-h[5]),'T4',T[4]-273.15)
|
||||
print(mdot,mdot+mdot_inj)
|
||||
f=3500/60.
|
||||
eta_v=0.7
|
||||
print('Vdisp1: ',mdot/(rho[1]*f*eta_v)*1e6,'cm^3')
|
||||
print('Vdisp2: ',(mdot+mdot_inj)/(rho[1]*f*eta_v)*1e6,'cm^3')
|
||||
return COP
|
||||
|
||||
if __name__=='__main__':
|
||||
from CoolProp.Plots import Ph,Ts
|
||||
|
||||
Ref='R290'
|
||||
fig=matplotlib.pyplot.figure(figsize=(4,3))
|
||||
ax=fig.add_axes((0.15,0.15,0.8,0.8))
|
||||
Ph(Ref,Tmin=273.15-30,hbounds=[0,600],axis=ax)
|
||||
COP=TwoStage('Propane',10000,273.15-5,273.15+43.3,5,7,0.7,0.3,15+273.15,3,prints = True)
|
||||
matplotlib.pyplot.show()
|
||||
|
||||
Ref='R290'
|
||||
fig=matplotlib.pyplot.figure(figsize=(4,3))
|
||||
ax=fig.add_axes((0.15,0.15,0.8,0.8))
|
||||
Ph(Ref,Tmin=273.15-30,hbounds=[0,600],axis=ax)
|
||||
COP=SimpleCycle(Ref,273.15-5,273.15+45,5,7,0.7,Ts_Ph='Ph')
|
||||
matplotlib.pyplot.show()
|
||||
|
||||
Ref='R410A'
|
||||
fig=matplotlib.pyplot.figure(figsize=(4,3))
|
||||
ax=fig.add_axes((0.15,0.15,0.8,0.8))
|
||||
Ts(Ref,Tmin=273.15-100,sbounds=[0,600],axis=ax)
|
||||
COP=SimpleCycle(Ref,273.15-5,273.15+45,5,7,0.7,Ts_Ph='Ts')
|
||||
matplotlib.pyplot.show()
|
||||
|
||||
|
||||
|
||||
|
||||
## for x in numpy.linspace(0,1):
|
||||
## Ref='REFPROP-MIX:R152A[%g]&R32[%g]' %(x,1-x)
|
||||
## COP=SimpleCycle(273.15+8,273.15+44,5,7,0.7,skipPlot=True,Ts_Ph='Ph')
|
||||
## matplotlib.pyplot.show()
|
||||
@@ -1,22 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Thu Sep 12 18:39:22 2013
|
||||
|
||||
@author: logan
|
||||
"""
|
||||
|
||||
from Plots import PropsPlot #TODO: Change to absolute import
|
||||
|
||||
|
||||
def main():
|
||||
fluid_ref = 'n-Pentane'
|
||||
for plot_type in ['Ts']: #['pt', 'ph', 'ps', 'ts', 'pt', 'prho', 'trho']:
|
||||
plt = PropsPlot(fluid_ref, plot_type)
|
||||
plt.set_axis_limits([-0.5, 1.5, 300, 530])
|
||||
plt.draw_isolines('Q', [0.1, 0.9])
|
||||
plt.draw_isolines('P', [100, 2000])
|
||||
plt.draw_isolines('D', [2, 600])
|
||||
plt.show()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,7 +0,0 @@
|
||||
#Bring some functions into the Plots namespace for code concision
|
||||
from __future__ import absolute_import
|
||||
|
||||
from .Plots import PropsPlot, IsoLines, drawIsoLines
|
||||
from .Plots import Ph, Ts, Ps, PT, Prho, Trho, hs
|
||||
from .SimpleCycles import SimpleCycle, TwoStage, EconomizedCycle
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
|
||||
from CoolProp cimport State as State
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
from __future__ import absolute_import
|
||||
# We made everything build into one module for simplicity as it makes the code much nicer to compile
|
||||
from .CoolProp import State, get_debug_level, set_debug_level, Props
|
||||
|
||||
@@ -1,365 +0,0 @@
|
||||
#cython: embedsignature = True
|
||||
|
||||
cdef extern from "CoolProp.h":
|
||||
double _Props "Props" (char* ,char,double,char,double,char*)
|
||||
double _Props1 "Props" (char*,char*)
|
||||
void UseSinglePhaseLUT(bool)
|
||||
double DerivTerms(char *, double, double, char*)
|
||||
char * get_errstringc()
|
||||
void get_errstring(char*)
|
||||
void _debug "debug" (int)
|
||||
double _IProps "IProps" (long,long,double,long,double,long)
|
||||
long _get_param_index "get_param_index" (string param)
|
||||
long _get_Fluid_index "get_Fluid_index" (string param)
|
||||
void _set_phase "set_phase"(string Phase_str)
|
||||
|
||||
from libc.math cimport pow, sin, cos, exp
|
||||
from math import pow as pow_
|
||||
cdef bint _LUT_Enabled
|
||||
import CoolProp as CP
|
||||
cimport cython
|
||||
|
||||
## Variables for each of the possible variables
|
||||
cdef long iMM = _get_param_index('M')
|
||||
cdef long iT = _get_param_index('T')
|
||||
cdef long iD = _get_param_index('D')
|
||||
cdef long iH = _get_param_index('H')
|
||||
cdef long iP = _get_param_index('P')
|
||||
cdef long iC = _get_param_index('C')
|
||||
cdef long iC0 = _get_param_index('C0')
|
||||
cdef long iO = _get_param_index('O')
|
||||
cdef long iV = _get_param_index('V')
|
||||
cdef long iL = _get_param_index('L')
|
||||
cdef long iS = _get_param_index('S')
|
||||
cdef long iU = _get_param_index('U')
|
||||
cdef long iDpdT = _get_param_index('dpdT')
|
||||
|
||||
#A dictionary mapping parameter index to string for use with non-CoolProp fluids
|
||||
cdef dict paras = {iMM : 'M',
|
||||
iT : 'T',
|
||||
iH : 'H',
|
||||
iP : 'P',
|
||||
iC : 'C',
|
||||
iC0 : 'C0',
|
||||
iO : 'O',
|
||||
iV : 'V',
|
||||
iL : 'L',
|
||||
iS : 'S',
|
||||
iU : 'U',
|
||||
iDpdT : 'dpdT'}
|
||||
|
||||
cpdef int debug(int level):
|
||||
"""
|
||||
Sets the debug level
|
||||
|
||||
Parameters
|
||||
----------
|
||||
level : int
|
||||
Flag indicating how verbose the debugging should be.
|
||||
0 : no debugging output
|
||||
...
|
||||
...
|
||||
10 : very annoying debugging output - every function call debugged
|
||||
"""
|
||||
_debug(level)
|
||||
|
||||
cpdef int LUT(bint LUTval):
|
||||
"""
|
||||
|
||||
LUTval : boolean
|
||||
If ``True``, turn on the use of lookup table. Parameters must have
|
||||
already been set through the use of set_1phase_LUT_params
|
||||
|
||||
"""
|
||||
if LUTval:
|
||||
_LUT_Enabled = True
|
||||
print 'Turning on singlephase LUT'
|
||||
UseSinglePhaseLUT(True)
|
||||
else:
|
||||
_LUT_Enabled = False
|
||||
UseSinglePhaseLUT(False)
|
||||
|
||||
cpdef double Props(bytes Parameter, bytes param1, float value1, bytes param2, float value2, bytes Fluid):
|
||||
"""
|
||||
Expose the Props() function. Uses the same call signature as the Props() function in CoolProp.CoolProp
|
||||
"""
|
||||
cdef char _param1 = param1[0]
|
||||
cdef char _param2 = param2[0]
|
||||
return _Props(Parameter, _param1, value1, _param2, value2, Fluid)
|
||||
|
||||
@cython.final
|
||||
cdef class State:
|
||||
"""
|
||||
A class that contains all the code that represents a thermodynamic state
|
||||
"""
|
||||
|
||||
def __init__(self,bytes Fluid, dict StateDict, double xL=-1.0, bytes Liquid=str(''), phase = str('Gas')):
|
||||
self.Fluid = Fluid
|
||||
self.iFluid = _get_Fluid_index(Fluid)
|
||||
#Try to get the fluid from CoolProp
|
||||
if self.iFluid >= 0:
|
||||
#It is a CoolProp Fluid so we can use the faster integer passing function
|
||||
self.is_CPFluid = True
|
||||
else:
|
||||
self.is_CPFluid = False
|
||||
self.xL = xL
|
||||
self.Liquid = Liquid
|
||||
self.phase = phase
|
||||
#Parse the inputs provided
|
||||
self.update(StateDict)
|
||||
#Set the phase flag
|
||||
if self.phase == str('Gas') or self.phase == str('Liquid') or self.phase == str('Supercritical'):
|
||||
_set_phase(self.phase)
|
||||
|
||||
def __reduce__(self):
|
||||
d={}
|
||||
d['xL']=self.xL
|
||||
d['Liquid']=self.Liquid
|
||||
d['Fluid']=self.Fluid
|
||||
d['T']=self.T_
|
||||
d['rho']=self.rho_
|
||||
return rebuildState,(d,)
|
||||
|
||||
|
||||
cpdef update_Trho(self, double T, double rho):
|
||||
"""
|
||||
Just use the temperature and density directly
|
||||
"""
|
||||
self.T_ = T
|
||||
self.rho_ = rho
|
||||
cdef double p
|
||||
|
||||
if self.is_CPFluid:
|
||||
p = _IProps(iP,iT,T,iD,rho,self.iFluid)
|
||||
else:
|
||||
p = _Props('P','T',T,'D',rho,self.Fluid)
|
||||
|
||||
if abs(p)<1e90:
|
||||
self.p_=p
|
||||
else:
|
||||
errstr = get_errstringc()
|
||||
raise ValueError(errstr)
|
||||
|
||||
cpdef update(self,dict params, double xL=-1.0):
|
||||
"""
|
||||
*params* is a list(or tuple) of strings that represent the parameters
|
||||
that have been updated and will be used to fix the rest of the state.
|
||||
['T','P'] for temperature and pressure for instance
|
||||
"""
|
||||
|
||||
cdef double p
|
||||
cdef bytes errstr
|
||||
|
||||
# If no value for xL is provided, it will have a value of -1 which is
|
||||
# impossible, so don't update xL
|
||||
if xL > 0:
|
||||
#There is liquid
|
||||
self.xL=xL
|
||||
self.hasLiquid=True
|
||||
else:
|
||||
#There's no liquid
|
||||
self.xL=0.0
|
||||
self.hasLiquid=False
|
||||
|
||||
#You passed in a dictionary, use the values to update the state
|
||||
if 'T' not in params:
|
||||
raise AttributeError('T must be provided in params dict in State.update')
|
||||
|
||||
#Consume the 'T' key since it is required (TODO?)
|
||||
self.T_=float(params.pop('T'))
|
||||
|
||||
#Given temperature and pressure, determine density of gas
|
||||
# (or gas and oil if xL is provided)
|
||||
if abs(self.xL)<=1e-15:
|
||||
#Get the density if T,P provided, or pressure if T,rho provided
|
||||
if 'P' in params:
|
||||
self.p_=params['P']
|
||||
|
||||
if self.is_CPFluid:
|
||||
rho = _IProps(iD,iT,self.T_,iP,self.p_,self.iFluid)
|
||||
else:
|
||||
rho = _Props('D','T',self.T_,'P',self.p_,self.Fluid)
|
||||
|
||||
if abs(rho)<1e90:
|
||||
self.rho_=rho
|
||||
else:
|
||||
errstr = get_errstringc()
|
||||
raise ValueError(errstr)
|
||||
elif 'D' in params:
|
||||
|
||||
self.rho_=params['D']
|
||||
|
||||
if self.is_CPFluid:
|
||||
p = _IProps(iP,iT,self.T_,iD,self.rho_,self.iFluid)
|
||||
else:
|
||||
p = _Props('P','T',self.T_,'D',self.rho_,self.Fluid)
|
||||
|
||||
if abs(p)<1e90:
|
||||
self.p_=p
|
||||
else:
|
||||
errstr = get_errstringc()
|
||||
raise ValueError(errstr+str(params))
|
||||
else:
|
||||
raise KeyError("Dictionary must contain the key 'T' and one of 'P' or 'D'")
|
||||
|
||||
elif self.xL>0 and self.xL<=1:
|
||||
raise ValueError('xL is out of range - value for xL is [0,1]')
|
||||
else:
|
||||
raise ValueError('xL must be between 0 and 1')
|
||||
|
||||
cpdef double Props(self, long iOutput):
|
||||
if iOutput<0:
|
||||
raise ValueError('Your output is invalid')
|
||||
|
||||
if self.is_CPFluid:
|
||||
return _IProps(iOutput,iT,self.T_,iD,self.rho_,self.iFluid)
|
||||
else:
|
||||
return _Props(paras[iOutput],'T',self.T_,'D',self.rho_,self.Fluid)
|
||||
|
||||
cpdef double get_MM(self):
|
||||
return _Props1(self.Fluid,'molemass')
|
||||
|
||||
cpdef double get_rho(self):
|
||||
return self.rho_
|
||||
property rho:
|
||||
def __get__(self):
|
||||
return self.rho_
|
||||
|
||||
cpdef double get_p(self):
|
||||
return self.p_
|
||||
property p:
|
||||
def __get__(self):
|
||||
return self.p_
|
||||
|
||||
cpdef double get_T(self):
|
||||
return self.T_
|
||||
property T:
|
||||
def __get__(self):
|
||||
return self.T_
|
||||
|
||||
cpdef double get_h(self):
|
||||
return self.Props(iH)
|
||||
property h:
|
||||
def __get__(self):
|
||||
return self.get_h()
|
||||
|
||||
cpdef double get_u(self):
|
||||
return self.Props(iU)
|
||||
property u:
|
||||
def __get__(self):
|
||||
return self.get_u()
|
||||
|
||||
cpdef double get_s(self):
|
||||
return self.Props(iS)
|
||||
property s:
|
||||
def __get__(self):
|
||||
return self.get_s()
|
||||
|
||||
cpdef double get_cp0(self):
|
||||
return self.Props(iC0)
|
||||
|
||||
cpdef double get_cp(self):
|
||||
return self.Props(iC)
|
||||
property cp:
|
||||
def __get__(self):
|
||||
return self.get_cp()
|
||||
|
||||
cpdef double get_cv(self):
|
||||
return self.Props(iO)
|
||||
property cv:
|
||||
def __get__(self):
|
||||
return self.get_cv()
|
||||
|
||||
cpdef double get_visc(self):
|
||||
return self.Props(iV)
|
||||
property visc:
|
||||
def __get__(self):
|
||||
return self.get_visc()
|
||||
|
||||
cpdef double get_cond(self):
|
||||
return self.Props(iL)
|
||||
property k:
|
||||
def __get__(self):
|
||||
return self.get_cond()
|
||||
|
||||
property Prandtl:
|
||||
def __get__(self):
|
||||
return self.cp * self.visc / self.k
|
||||
|
||||
cpdef double get_dpdT(self):
|
||||
return self.Props(iDpdT)
|
||||
property dpdT:
|
||||
def __get__(self):
|
||||
return self.get_dpdT()
|
||||
|
||||
cpdef speed_test(self, int N):
|
||||
from time import clock
|
||||
cdef int i
|
||||
cdef char * k
|
||||
cdef char * Fluid = self.Fluid
|
||||
cdef long IT = 'T'
|
||||
cdef long ID = 'D'
|
||||
|
||||
print 'Direct c++ call to CoolProp without the Python call layer'
|
||||
print "'M' involves basically no computational effort and is a good measure of the function call overhead"
|
||||
keys = ['H','P','S','U','C','O','V','L','M','C0']
|
||||
for key in keys:
|
||||
t1=clock()
|
||||
for i in range(N):
|
||||
_Props(key,'T',self.T_,'D',self.rho_,Fluid)
|
||||
t2=clock()
|
||||
print 'Elapsed time for {0:d} calls for "{1:s}" at {2:g} us/call'.format(N,key,(t2-t1)/N*1e6)
|
||||
|
||||
print 'Call to the c++ layer using integers'
|
||||
keys = [iH,iP,iS,iU,iC,iO,iV,iL,iMM,iC0]
|
||||
for key in keys:
|
||||
t1=clock()
|
||||
for i in range(N):
|
||||
_IProps(key,iT,self.T_,iD,self.rho_,self.iFluid)
|
||||
t2=clock()
|
||||
print 'Elapsed time for {0:d} calls for "{1:s}" at {2:g} us/call'.format(N,paras[key],(t2-t1)/N*1e6)
|
||||
|
||||
print 'Call to the Python call layer'
|
||||
print "'M' involves basically no computational effort and is a good measure of the function call overhead"
|
||||
keys = ['H','P','S','U','C','O','V','L','M','C0']
|
||||
for key in keys:
|
||||
t1=clock()
|
||||
for i in range(N):
|
||||
CP.Props(key,'T',self.T_,'D',self.rho_,Fluid)
|
||||
t2=clock()
|
||||
print 'Elapsed time for {0:d} calls for "{1:s}" at {2:g} us/call'.format(N,key,(t2-t1)/N*1e6)
|
||||
|
||||
def __str__(self):
|
||||
"""
|
||||
Return a string representation of the state
|
||||
"""
|
||||
units={'T': 'K',
|
||||
'p': 'kPa',
|
||||
'rho': 'kg/m^3',
|
||||
'h':'kJ/kg',
|
||||
'u':'kJ/kg',
|
||||
's':'kJ/kg/K',
|
||||
'visc':'Pa-s',
|
||||
'k':'kW/m/K',
|
||||
'cp':'kJ/kg/K',
|
||||
'cv':'kJ/kg/K',
|
||||
'dpdT':'kPa/K'}
|
||||
s=''
|
||||
for k in ['T','p','rho','h','u','s','visc','k','cp','cv','dpdT','Prandtl']:
|
||||
if k in units:
|
||||
s+=k+' = '+str(getattr(self,k))+' '+units[k]+'\n'
|
||||
else:
|
||||
s+=k+' = '+str(getattr(self,k))+' NO UNITS'+'\n'
|
||||
return s.rstrip()
|
||||
|
||||
cpdef copy(self):
|
||||
cdef double T = self.T_*(1.0+1e-20)
|
||||
cdef double rho = self.rho_*(1.0+1e-20)
|
||||
ST=State(self.Fluid,{'T':T,'D':rho})
|
||||
return ST
|
||||
|
||||
def rebuildState(d):
|
||||
S=State(d['Fluid'],{'T':d['T'],'D':d['rho']})
|
||||
S.xL = d['xL']
|
||||
S.Liquid=d['Liquid']
|
||||
return S
|
||||
@@ -1,88 +0,0 @@
|
||||
#This file is automatically generated by the generate_constants_module.py script in dev/scripts.
|
||||
#DO NOT MODIFY THE CONTENTS OF THIS FILE!
|
||||
cimport param_constants_header
|
||||
|
||||
iB = param_constants_header.iB
|
||||
iT = param_constants_header.iT
|
||||
iP = param_constants_header.iP
|
||||
iD = param_constants_header.iD
|
||||
iC = param_constants_header.iC
|
||||
iC0 = param_constants_header.iC0
|
||||
iO = param_constants_header.iO
|
||||
iU = param_constants_header.iU
|
||||
iH = param_constants_header.iH
|
||||
iS = param_constants_header.iS
|
||||
iA = param_constants_header.iA
|
||||
iG = param_constants_header.iG
|
||||
iQ = param_constants_header.iQ
|
||||
iV = param_constants_header.iV
|
||||
iL = param_constants_header.iL
|
||||
iTfreeze = param_constants_header.iTfreeze
|
||||
iPsat = param_constants_header.iPsat
|
||||
iI = param_constants_header.iI
|
||||
iDpdT = param_constants_header.iDpdT
|
||||
iDrhodT_p = param_constants_header.iDrhodT_p
|
||||
iCritSplineT = param_constants_header.iCritSplineT
|
||||
iPrandtl = param_constants_header.iPrandtl
|
||||
iMM = param_constants_header.iMM
|
||||
iTmax = param_constants_header.iTmax
|
||||
iTmin = param_constants_header.iTmin
|
||||
iAccentric = param_constants_header.iAccentric
|
||||
iDipole = param_constants_header.iDipole
|
||||
iODP = param_constants_header.iODP
|
||||
iGWP20 = param_constants_header.iGWP20
|
||||
iGWP100 = param_constants_header.iGWP100
|
||||
iGWP500 = param_constants_header.iGWP500
|
||||
iRhoreduce = param_constants_header.iRhoreduce
|
||||
iTreduce = param_constants_header.iTreduce
|
||||
iPtriple = param_constants_header.iPtriple
|
||||
iTtriple = param_constants_header.iTtriple
|
||||
iHcrit = param_constants_header.iHcrit
|
||||
iPcrit = param_constants_header.iPcrit
|
||||
iRhocrit = param_constants_header.iRhocrit
|
||||
iScrit = param_constants_header.iScrit
|
||||
iTcrit = param_constants_header.iTcrit
|
||||
iPhase = param_constants_header.iPhase
|
||||
iPHASE_LIQUID = param_constants_header.iPHASE_LIQUID
|
||||
iPHASE_GAS = param_constants_header.iPHASE_GAS
|
||||
iPHASE_SUPERCRITICAL = param_constants_header.iPHASE_SUPERCRITICAL
|
||||
iPHASE_TWOPHASE = param_constants_header.iPHASE_TWOPHASE
|
||||
iDERdh_dp__rho = param_constants_header.iDERdh_dp__rho
|
||||
iDERdh_dp__v = param_constants_header.iDERdh_dp__v
|
||||
iDERZ = param_constants_header.iDERZ
|
||||
iDERdZ_dDelta = param_constants_header.iDERdZ_dDelta
|
||||
iDERdZ_dTau = param_constants_header.iDERdZ_dTau
|
||||
iDERB = param_constants_header.iDERB
|
||||
iDERdB_dT = param_constants_header.iDERdB_dT
|
||||
iDERC = param_constants_header.iDERC
|
||||
iDERdC_dT = param_constants_header.iDERdC_dT
|
||||
iDERphir = param_constants_header.iDERphir
|
||||
iDERdphir_dTau = param_constants_header.iDERdphir_dTau
|
||||
iDERdphir_dDelta = param_constants_header.iDERdphir_dDelta
|
||||
iDERd2phir_dTau2 = param_constants_header.iDERd2phir_dTau2
|
||||
iDERd2phir_dDelta2 = param_constants_header.iDERd2phir_dDelta2
|
||||
iDERd2phir_dDelta_dTau = param_constants_header.iDERd2phir_dDelta_dTau
|
||||
iDERd3phir_dDelta3 = param_constants_header.iDERd3phir_dDelta3
|
||||
iDERd3phir_dDelta2_dTau = param_constants_header.iDERd3phir_dDelta2_dTau
|
||||
iDERd3phir_dDelta_dTau2 = param_constants_header.iDERd3phir_dDelta_dTau2
|
||||
iDERd3phir_dTau3 = param_constants_header.iDERd3phir_dTau3
|
||||
iDERphi0 = param_constants_header.iDERphi0
|
||||
iDERdphi0_dTau = param_constants_header.iDERdphi0_dTau
|
||||
iDERd2phi0_dTau2 = param_constants_header.iDERd2phi0_dTau2
|
||||
iDERdphi0_dDelta = param_constants_header.iDERdphi0_dDelta
|
||||
iDERd2phi0_dDelta2 = param_constants_header.iDERd2phi0_dDelta2
|
||||
iDERd2phi0_dDelta_dTau = param_constants_header.iDERd2phi0_dDelta_dTau
|
||||
iDERd3phi0_dTau3 = param_constants_header.iDERd3phi0_dTau3
|
||||
iDERdp_dT__rho = param_constants_header.iDERdp_dT__rho
|
||||
iDERdp_drho__T = param_constants_header.iDERdp_drho__T
|
||||
iDERdh_dT__rho = param_constants_header.iDERdh_dT__rho
|
||||
iDERdh_drho__T = param_constants_header.iDERdh_drho__T
|
||||
iDERdrho_dT__p = param_constants_header.iDERdrho_dT__p
|
||||
iDERdrho_dh__p = param_constants_header.iDERdrho_dh__p
|
||||
iDERdrho_dp__h = param_constants_header.iDERdrho_dp__h
|
||||
iDERrho_smoothed = param_constants_header.iDERrho_smoothed
|
||||
iDERdrho_smoothed_dh = param_constants_header.iDERdrho_smoothed_dh
|
||||
iDERdrho_smoothed_dp = param_constants_header.iDERdrho_smoothed_dp
|
||||
iDERdrhodh_constp_smoothed = param_constants_header.iDERdrhodh_constp_smoothed
|
||||
iDERdrhodp_consth_smoothed = param_constants_header.iDERdrhodp_consth_smoothed
|
||||
iDERIsothermalCompressibility = param_constants_header.iDERIsothermalCompressibility
|
||||
@@ -1,89 +0,0 @@
|
||||
#This file is automatically generated by the generate_constants_module.py script in dev/scripts.
|
||||
#DO NOT MODIFY THE CONTENTS OF THIS FILE!
|
||||
|
||||
cdef extern from "CoolProp.h":
|
||||
enum params:
|
||||
iB
|
||||
iT
|
||||
iP
|
||||
iD
|
||||
iC
|
||||
iC0
|
||||
iO
|
||||
iU
|
||||
iH
|
||||
iS
|
||||
iA
|
||||
iG
|
||||
iQ
|
||||
iV
|
||||
iL
|
||||
iTfreeze
|
||||
iPsat
|
||||
iI
|
||||
iDpdT
|
||||
iDrhodT_p
|
||||
iCritSplineT
|
||||
iPrandtl
|
||||
iMM
|
||||
iTmax
|
||||
iTmin
|
||||
iAccentric
|
||||
iDipole
|
||||
iODP
|
||||
iGWP20
|
||||
iGWP100
|
||||
iGWP500
|
||||
iRhoreduce
|
||||
iTreduce
|
||||
iPtriple
|
||||
iTtriple
|
||||
iHcrit
|
||||
iPcrit
|
||||
iRhocrit
|
||||
iScrit
|
||||
iTcrit
|
||||
iPhase
|
||||
iPHASE_LIQUID
|
||||
iPHASE_GAS
|
||||
iPHASE_SUPERCRITICAL
|
||||
iPHASE_TWOPHASE
|
||||
iDERdh_dp__rho
|
||||
iDERdh_dp__v
|
||||
iDERZ
|
||||
iDERdZ_dDelta
|
||||
iDERdZ_dTau
|
||||
iDERB
|
||||
iDERdB_dT
|
||||
iDERC
|
||||
iDERdC_dT
|
||||
iDERphir
|
||||
iDERdphir_dTau
|
||||
iDERdphir_dDelta
|
||||
iDERd2phir_dTau2
|
||||
iDERd2phir_dDelta2
|
||||
iDERd2phir_dDelta_dTau
|
||||
iDERd3phir_dDelta3
|
||||
iDERd3phir_dDelta2_dTau
|
||||
iDERd3phir_dDelta_dTau2
|
||||
iDERd3phir_dTau3
|
||||
iDERphi0
|
||||
iDERdphi0_dTau
|
||||
iDERd2phi0_dTau2
|
||||
iDERdphi0_dDelta
|
||||
iDERd2phi0_dDelta2
|
||||
iDERd2phi0_dDelta_dTau
|
||||
iDERd3phi0_dTau3
|
||||
iDERdp_dT__rho
|
||||
iDERdp_drho__T
|
||||
iDERdh_dT__rho
|
||||
iDERdh_drho__T
|
||||
iDERdrho_dT__p
|
||||
iDERdrho_dh__p
|
||||
iDERdrho_dp__h
|
||||
iDERrho_smoothed
|
||||
iDERdrho_smoothed_dh
|
||||
iDERdrho_smoothed_dp
|
||||
iDERdrhodh_constp_smoothed
|
||||
iDERdrhodp_consth_smoothed
|
||||
iDERIsothermalCompressibility
|
||||
@@ -1,8 +0,0 @@
|
||||
#This file is automatically generated by the generate_constants_module.py script in dev/scripts.
|
||||
#DO NOT MODIFY THE CONTENTS OF THIS FILE!
|
||||
cimport phase_constants_header
|
||||
|
||||
iLiquid = phase_constants_header.iLiquid
|
||||
iSupercritical = phase_constants_header.iSupercritical
|
||||
iGas = phase_constants_header.iGas
|
||||
iTwoPhase = phase_constants_header.iTwoPhase
|
||||
@@ -1,9 +0,0 @@
|
||||
#This file is automatically generated by the generate_constants_module.py script in dev/scripts.
|
||||
#DO NOT MODIFY THE CONTENTS OF THIS FILE!
|
||||
|
||||
cdef extern from "CoolProp.h":
|
||||
enum phase:
|
||||
iLiquid
|
||||
iSupercritical
|
||||
iGas
|
||||
iTwoPhase
|
||||
@@ -1,11 +0,0 @@
|
||||
from __future__ import print_function
|
||||
|
||||
def run():
|
||||
import nose, os
|
||||
|
||||
print('about to run the tests, please be patient')
|
||||
this_path, file = os.path.split(os.path.abspath(__file__))
|
||||
nose.run(argv = ['--where',this_path])
|
||||
|
||||
if __name__=='__main__':
|
||||
run()
|
||||
@@ -1,148 +0,0 @@
|
||||
from __future__ import division, print_function
|
||||
import CoolProp.CoolProp as CP
|
||||
import CoolProp.unit_systems_constants
|
||||
from CoolProp import param_constants
|
||||
from CoolProp.State import State
|
||||
|
||||
def first_derivative(S, func, iVal, Val, iConstant, Constant, epsilon = 1e-3):
|
||||
|
||||
S.update({iVal:Val,iConstant:Constant})
|
||||
val1 = func()
|
||||
|
||||
S.update({iVal:Val+epsilon,iConstant:Constant})
|
||||
val2 = func()
|
||||
|
||||
S.update({iVal:Val,iConstant:Constant})
|
||||
|
||||
return (val2-val1)/epsilon
|
||||
|
||||
def second_derivative(S, func, iVal, Val, iConstant, Constant, epsilon = 2):
|
||||
|
||||
S.update({iVal:Val-epsilon,iConstant:Constant})
|
||||
val1 = func()
|
||||
|
||||
S.update({iVal:Val,iConstant:Constant})
|
||||
val2 = func()
|
||||
|
||||
S.update({iVal:Val+epsilon,iConstant:Constant})
|
||||
val3 = func()
|
||||
|
||||
S.update({iVal:Val,iConstant:Constant})
|
||||
|
||||
print(val1, val2, val3, S.T, S.p, S.rho, (val1-2*val2+val3))
|
||||
|
||||
return (val1-2*val2+val3)/(epsilon*epsilon)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def teest_1phase_first_derivatives():
|
||||
|
||||
for US in [CoolProp.UNIT_SYSTEM_SI, CoolProp.UNIT_SYSTEM_KSI]:
|
||||
CP.set_standard_unit_system(US)
|
||||
|
||||
S = State('R134a',dict(T=300,D=1))
|
||||
|
||||
l = [(S.get_rho,'T',S.T,'P',S.p,S.PFC.drhodT_constp),
|
||||
(S.get_rho,'P',S.p,'T',S.T,S.PFC.drhodp_constT),
|
||||
(S.get_p,'D',S.rho,'T',S.T,S.PFC.dpdrho_constT),
|
||||
#(S.get_p,'D',S.rho,'H',S.h,S.PFC.dpdrho_consth), #(these inputs not supported)
|
||||
(S.get_p,'T',S.T,'D',S.rho,S.PFC.dpdT_constrho),
|
||||
#(S.get_p,'T',S.T,'H',S.h,S.PFC.dpdT_consth), #(these inputs not supported)
|
||||
(S.get_h,'D',S.rho,'T',S.T,S.PFC.dhdrho_constT),
|
||||
(S.get_h,'D',S.rho,'P',S.p,S.PFC.dhdrho_constp),
|
||||
(S.get_h,'T',S.T,'D',S.rho,S.PFC.dhdT_constrho),
|
||||
(S.get_h,'T',S.T,'P',S.p,S.PFC.dhdT_constp),
|
||||
(S.get_h,'P',S.p,'T',S.T,S.PFC.dhdp_constT),
|
||||
(S.get_s,'D',S.rho,'T',S.T,S.PFC.dsdrho_constT),
|
||||
(S.get_s,'T',S.T,'D',S.rho,S.PFC.dsdT_constrho),
|
||||
(S.get_s,'D',S.rho,'P',S.p,S.PFC.dsdrho_constp),
|
||||
(S.get_s,'T',S.T,'P',S.p,S.PFC.dsdT_constp),
|
||||
(S.get_s,'P',S.p,'T',S.T,S.PFC.dsdp_constT),
|
||||
|
||||
]
|
||||
for args in l:
|
||||
yield (check_1phase_first_derivatives,)+(S,)+args
|
||||
|
||||
def check_1phase_first_derivatives(S, func, iVal, Val, iConstant, Constant, deriv_func):
|
||||
|
||||
Deriv_val = first_derivative(S, func, iVal, Val, iConstant, Constant)
|
||||
EOS_val = deriv_func()
|
||||
if abs(EOS_val/Deriv_val-1) > 1e-2:
|
||||
raise ValueError('Finite Diff: ' + str(Deriv_val) + ' EOS: ' +str(EOS_val))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def teest_sat_first_derivatives():
|
||||
|
||||
for US in [CoolProp.UNIT_SYSTEM_SI, CoolProp.UNIT_SYSTEM_KSI]:
|
||||
CP.set_standard_unit_system(US)
|
||||
|
||||
S = State('R134a',dict(T=300,Q=1))
|
||||
|
||||
l = [(S.get_T,'P',S.p,'Q',0,S.PFC.dTdp_along_sat),
|
||||
(S.get_rho,'P',S.p,'Q',0,S.PFC.drhodp_along_sat_liquid),
|
||||
(S.get_rho,'P',S.p,'Q',1,S.PFC.drhodp_along_sat_vapor),
|
||||
(S.get_rho,'T',S.T,'Q',0,S.PFC.drhodT_along_sat_liquid),
|
||||
(S.get_rho,'T',S.T,'Q',1,S.PFC.drhodT_along_sat_vapor),
|
||||
(S.get_h,'P',S.p,'Q',0,S.PFC.dhdp_along_sat_liquid),
|
||||
(S.get_h,'P',S.p,'Q',1,S.PFC.dhdp_along_sat_vapor),
|
||||
(S.get_s,'P',S.p,'Q',0,S.PFC.dsdp_along_sat_liquid),
|
||||
(S.get_s,'P',S.p,'Q',1,S.PFC.dsdp_along_sat_vapor),
|
||||
]
|
||||
for args in l:
|
||||
yield (check_sat_first_derivatives,)+(S,)+args
|
||||
|
||||
def check_sat_first_derivatives(S, func, iVal, Val, iConstant, Constant, deriv_func):
|
||||
|
||||
Deriv_val = first_derivative(S, func, iVal, Val, iConstant, Constant)
|
||||
EOS_val = deriv_func()
|
||||
if abs(EOS_val/Deriv_val-1) > 1e-2:
|
||||
raise ValueError('Finite Diff: ' + str(Deriv_val) + ' EOS: ' +str(EOS_val))
|
||||
|
||||
|
||||
|
||||
|
||||
def teest_sat_second_derivatives():
|
||||
for US in [CoolProp.UNIT_SYSTEM_SI, CoolProp.UNIT_SYSTEM_KSI]:
|
||||
CP.set_standard_unit_system(US)
|
||||
|
||||
S = State('R134a',dict(T=290,Q=1))
|
||||
|
||||
l = [(S.get_T,'P',S.p,'Q',0,S.PFC.d2Tdp2_along_sat),
|
||||
(S.get_rho,'P',S.p,'Q',0,S.PFC.d2rhodp2_along_sat_liquid),
|
||||
(S.get_rho,'P',S.p,'Q',1,S.PFC.d2rhodp2_along_sat_vapor),
|
||||
(S.get_h,'P',S.p,'Q',0,S.PFC.d2hdp2_along_sat_liquid),
|
||||
(S.get_h,'P',S.p,'Q',1,S.PFC.d2hdp2_along_sat_vapor),
|
||||
(S.get_s,'P',S.p,'Q',0,S.PFC.d2sdp2_along_sat_liquid),
|
||||
(S.get_s,'P',S.p,'Q',1,S.PFC.d2sdp2_along_sat_vapor),
|
||||
]
|
||||
for args in l:
|
||||
yield (check_sat_second_derivatives,)+(S,)+args
|
||||
|
||||
def check_sat_second_derivatives(S, func, iVal, Val, iConstant, Constant, deriv_func):
|
||||
|
||||
Deriv_val = second_derivative(S, func, iVal, Val, iConstant, Constant)
|
||||
EOS_val = deriv_func()
|
||||
if abs(EOS_val/Deriv_val-1) > 1e-2:
|
||||
raise ValueError('Finite Diff: ' + str(Deriv_val) + ' EOS: ' +str(EOS_val))
|
||||
|
||||
if __name__=='__main__':
|
||||
import nose
|
||||
nose.runmodule()
|
||||
@@ -1,38 +0,0 @@
|
||||
import unittest
|
||||
import CoolProp
|
||||
from CoolProp.HumidAirProp import HAProps
|
||||
import numpy as np
|
||||
|
||||
def test_TRP():
|
||||
for R in np.linspace(0, 1, 11):
|
||||
for p in [101.325]:#np.linspace(0.1, 1000, 10):
|
||||
for T in np.linspace(220,370.15,10):
|
||||
for o in ['W','H','S','V']:
|
||||
yield check_HAProps,o,'T',T,'R',R,'P',p
|
||||
|
||||
def check_HAProps(*args):
|
||||
val = HAProps(*args)
|
||||
|
||||
def test_input_types():
|
||||
|
||||
pairs = [
|
||||
[300, 0.003],
|
||||
[[300,305],0.003],
|
||||
[np.linspace(300,305,6), 0.003],
|
||||
[300, [0.003, 0.0034]],
|
||||
[300, np.linspace(0.003,0.0034)]
|
||||
]
|
||||
|
||||
for T,w in pairs:
|
||||
yield check_type, T, w
|
||||
|
||||
def check_type(Tvals, wvals):
|
||||
HAProps('H','T',Tvals,'P',101.325,'W', wvals)
|
||||
|
||||
class PropsFailures(unittest.TestCase):
|
||||
def testUnmatchedLengths(self):
|
||||
self.assertRaises(TypeError,HAProps,'H','T',[300,301,302],'P',101.325,'W', [0.003,0.004])
|
||||
|
||||
if __name__=='__main__':
|
||||
import nose
|
||||
nose.runmodule()
|
||||
@@ -1,25 +0,0 @@
|
||||
import unittest
|
||||
from CoolProp.CoolProp import Props
|
||||
import CoolProp
|
||||
import numpy as np
|
||||
|
||||
def test_input_types():
|
||||
for Fluid in ['Water']:
|
||||
for Tvals in [0.5*Props(Fluid,'Tmin')+0.5*Props(Fluid,'Tcrit'),
|
||||
[Props(Fluid,'Tmin')+1e-5,Props(Fluid,'Tcrit')-1e-5],
|
||||
np.linspace(Props(Fluid,'Tmin')+1e-5, Props(Fluid,'Tcrit')-1e-5,30)
|
||||
]:
|
||||
yield check_type, Fluid, Tvals
|
||||
|
||||
def check_type(fluid, Tvals):
|
||||
Props('P','T',Tvals,'Q',0,fluid)
|
||||
|
||||
class PropsFailures(unittest.TestCase):
|
||||
def testUnmatchedLengths(self):
|
||||
self.assertRaises(TypeError,Props,'P','T',[280,290,300],'Q',[0,1],'R134a')
|
||||
def testMatrix(self):
|
||||
self.assertRaises(TypeError,Props,'P','T',np.array([280,290,300,280,290,300]).reshape(2,3),'Q',np.array([0,0.5,1,0.0,0.5,1]).reshape(2,3),'R134a')
|
||||
|
||||
if __name__=='__main__':
|
||||
import nose
|
||||
nose.runmodule()
|
||||
@@ -1,34 +0,0 @@
|
||||
import unittest
|
||||
from CoolProp.CoolProp import Props
|
||||
import CoolProp
|
||||
|
||||
class Props1BadInputParameters(unittest.TestCase):
|
||||
""" All fluids, all parameters """
|
||||
def testEmptyFluid(self):
|
||||
self.assertRaises(ValueError,Props,'','Tcrit')
|
||||
def testIntegerFluid(self):
|
||||
self.assertRaises(TypeError,Props,1,'Tcrit')
|
||||
def testFloatFluid(self):
|
||||
self.assertRaises(TypeError,Props,1.0,'Tcrit')
|
||||
|
||||
def testEmptyParam(self):
|
||||
self.assertRaises(ValueError,Props,'R134a','')
|
||||
def testBadParam(self):
|
||||
self.assertRaises(ValueError,Props,'R134a','R134a')
|
||||
|
||||
def testAllCoolPropPairs():
|
||||
for fluid in CoolProp.__fluids__:
|
||||
for param in ["Ttriple","Tcrit","pcrit","ptriple","Tmin",
|
||||
"molemass","rhocrit","accentric","PHASE_LIQUID",
|
||||
"PHASE_GAS","PHASE_SUPERCRITICAL","PHASE_TWOPHASE",
|
||||
"ODP","GWP100"]:
|
||||
yield check_param,fluid,param
|
||||
|
||||
def check_param(fluid, param):
|
||||
val = Props(fluid,param)
|
||||
assert val > -2
|
||||
assert val < 1e9
|
||||
|
||||
if __name__=='__main__':
|
||||
import nose
|
||||
nose.runmodule()
|
||||
@@ -1,47 +0,0 @@
|
||||
from __future__ import print_function
|
||||
import CoolProp
|
||||
from CoolProp.CoolProp import Props
|
||||
from math import log10
|
||||
import random
|
||||
import numpy as np
|
||||
#
|
||||
def test_p():
|
||||
for Fluid in CoolProp.__fluids__:
|
||||
for p in np.linspace(Props(Fluid,'ptriple')+1e-5, Props(Fluid,'pcrit')-1e-4,50):
|
||||
yield check_p,Fluid,p
|
||||
|
||||
def check_p(Fluid, p):
|
||||
Tmin = Props(Fluid,'Tmin')
|
||||
Tcrit = Props(Fluid,'Tcrit')
|
||||
Tsat = Props('T', 'P', p, 'Q', 1, Fluid)
|
||||
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
|
||||
def test_T():
|
||||
for Fluid in CoolProp.__fluids__:
|
||||
for T in np.linspace(Props(Fluid,'Tmin')+1e-5, Props(Fluid,'Tcrit')-1e-5,5):
|
||||
yield check_T,Fluid,T
|
||||
|
||||
def check_T(Fluid, T):
|
||||
pmin = Props(Fluid,'ptriple')
|
||||
pmax = Props('P','T',Props(Fluid,'Tcrit'),'D',Props(Fluid,'rhocrit'),Fluid)
|
||||
psat = Props('P', 'T', T, 'Q', 1, Fluid)
|
||||
|
||||
|
||||
def test_consistency():
|
||||
for Fluid in CoolProp.__fluids__:
|
||||
for T in np.linspace(Props(Fluid,'Tmin')+1e-5, Props(Fluid,'Tcrit')-1,50):
|
||||
yield check_consistency,Fluid,T
|
||||
|
||||
def check_consistency(Fluid, T):
|
||||
pmin = Props(Fluid,'ptriple')
|
||||
pmax = Props('P','T',Props(Fluid,'Tcrit'),'D',Props(Fluid,'rhocrit'),Fluid)
|
||||
psat = Props('P', 'T', T, 'Q', 1, Fluid)
|
||||
Tnew = Props('T', 'P', psat, 'Q', 1, Fluid)
|
||||
print(Fluid,T,Tnew)
|
||||
assert (abs(Tnew/T-1) < 0.001)
|
||||
|
||||
if __name__=='__main__':
|
||||
import nose
|
||||
nose.runmodule()
|
||||
@@ -1,103 +0,0 @@
|
||||
from __future__ import division, print_function
|
||||
import CoolProp.CoolProp as CP
|
||||
import CoolProp.unit_systems_constants
|
||||
from CoolProp import param_constants
|
||||
from CoolProp.State import State
|
||||
|
||||
S = State('R134a',dict(T=300,D=1))
|
||||
|
||||
# factor is SI / kSI value
|
||||
State_listing = [('T',1),
|
||||
('get_speed_sound',1),
|
||||
('rho',1),
|
||||
('p',1000),
|
||||
('h',1000),
|
||||
('s',1000),
|
||||
('cv',1000),
|
||||
('cp',1000),
|
||||
('visc',1),
|
||||
('k',1000),
|
||||
]
|
||||
|
||||
def test_State():
|
||||
for parameter,SI_over_kSI in State_listing:
|
||||
|
||||
CP.set_standard_unit_system(CoolProp.unit_systems_constants.UNIT_SYSTEM_SI)
|
||||
val_SI = getattr(S, parameter)
|
||||
|
||||
CP.set_standard_unit_system(CoolProp.unit_systems_constants.UNIT_SYSTEM_KSI)
|
||||
val_kSI = getattr(S, parameter)
|
||||
|
||||
yield check, val_SI, val_kSI, SI_over_kSI
|
||||
|
||||
Props_listing = [('T',1),
|
||||
('A',1),
|
||||
('D',1),
|
||||
('P',1000),
|
||||
('H',1000),
|
||||
('S',1000),
|
||||
('C',1000),
|
||||
('C0',1000),
|
||||
('O',1000),
|
||||
('V',1),
|
||||
('L',1000),
|
||||
]
|
||||
def test_PROPS():
|
||||
for parameter, SI_over_kSI in Props_listing:
|
||||
yield check_Props, parameter, SI_over_kSI
|
||||
|
||||
def check_Props(parameter, SI_over_kSI):
|
||||
|
||||
CP.set_standard_unit_system(CoolProp.unit_systems_constants.UNIT_SYSTEM_SI)
|
||||
val_SI = CP.Props(parameter,'T',300.0,'D',1.0,'R134a')
|
||||
|
||||
CP.set_standard_unit_system(CoolProp.unit_systems_constants.UNIT_SYSTEM_KSI)
|
||||
val_kSI = CP.Props(parameter,'T',300.0,'D',1.0,'R134a')
|
||||
|
||||
try:
|
||||
val_SI = val_SI()
|
||||
val_kSI = val_kSI()
|
||||
except:
|
||||
pass
|
||||
|
||||
print(val_SI,val_kSI, val_SI/val_kSI - SI_over_kSI)
|
||||
if abs(val_SI/val_kSI - SI_over_kSI) > 1e-12:
|
||||
raise ValueError(val_SI/val_kSI-SI_over_kSI)
|
||||
|
||||
State_Props_listing = [(param_constants.iT,1),
|
||||
(param_constants.iA,1),
|
||||
(param_constants.iD,1),
|
||||
(param_constants.iP,1000),
|
||||
(param_constants.iH,1000),
|
||||
(param_constants.iS,1000),
|
||||
(param_constants.iC,1000),
|
||||
(param_constants.iC0,1000),
|
||||
(param_constants.iO,1000),
|
||||
(param_constants.iV,1),
|
||||
(param_constants.iL,1000),
|
||||
]
|
||||
def test_State_PROPS():
|
||||
for parameter, SI_over_kSI in State_Props_listing:
|
||||
|
||||
CP.set_standard_unit_system(CoolProp.unit_systems_constants.UNIT_SYSTEM_SI)
|
||||
val_SI = S.Props(parameter)
|
||||
|
||||
CP.set_standard_unit_system(CoolProp.unit_systems_constants.UNIT_SYSTEM_KSI)
|
||||
val_kSI = S.Props(parameter)
|
||||
|
||||
yield check, val_SI, val_kSI, SI_over_kSI
|
||||
|
||||
def check(val_SI, val_kSI, SI_over_kSI):
|
||||
|
||||
try:
|
||||
val_SI = val_SI()
|
||||
val_kSI = val_kSI()
|
||||
except:
|
||||
pass
|
||||
|
||||
if abs(val_SI/val_kSI - SI_over_kSI) > 1e-12:
|
||||
raise ValueError(val_SI/val_kSI-SI_over_kSI)
|
||||
|
||||
if __name__=='__main__':
|
||||
import nose
|
||||
nose.runmodule()
|
||||
@@ -1,92 +0,0 @@
|
||||
from __future__ import division, print_function
|
||||
import CoolProp
|
||||
from CoolProp import unit_systems_constants
|
||||
from CoolProp.CoolProp import Props, get_REFPROPname, IsFluidType, set_standard_unit_system
|
||||
import CoolProp.CoolProp as CP
|
||||
import numpy as np
|
||||
|
||||
modes = []
|
||||
modes.append('pure')
|
||||
#modes.append('pseudo-pure')
|
||||
|
||||
# Check if REFPROP is supported, the Props call should work without throwing exception if it is supported
|
||||
## try:
|
||||
## Props('D','T',300,'Q',1,'REFPROP-Propane')
|
||||
## modes.append('REFPROP')
|
||||
## except ValueError:
|
||||
## pass
|
||||
|
||||
twophase_inputs = [('T','D'),('T','Q'),('P','Q'),('P','H'),('P','S'),('P','D'),('T','S'),('H','S')] #
|
||||
singlephase_inputs = [('T','D'),('T','P'),('P','H'),('P','S'),('P','D'),('H','S'),('T','S')]
|
||||
singlephase_outputs = ['T','P','H','S','A','O','C','G','V','L','C0','U']
|
||||
|
||||
## def test_subcrit_singlephase_consistency():
|
||||
## for Fluid in sorted(CoolProp.__fluids__):
|
||||
## T = (Props(Fluid,'Tmin')+Props(Fluid,'Tcrit'))/2.0
|
||||
## for mode in modes:
|
||||
## rhoL = Props('D','T',T,'Q',0,Fluid)
|
||||
## rhoV = Props('D','T',T,'Q',1,Fluid)
|
||||
## for rho in [rhoL+0.1, rhoV*0.9]:
|
||||
## for inputs in singlephase_inputs:
|
||||
## for unit_system in ['SI','kSI']:
|
||||
## yield check_consistency,Fluid,mode,unit_system,T,rho,inputs
|
||||
|
||||
def test_subcrit_twophase_consistency():
|
||||
|
||||
for Fluid in reversed(sorted(CoolProp.__fluids__)):
|
||||
Tmin = Props(Fluid,'Tmin')
|
||||
Tcrit = Props(Fluid,'Tcrit')
|
||||
for T in [Tmin + 1, (Tmin+Tcrit)/2.0, 0.95*Tcrit]:
|
||||
for mode in modes:
|
||||
rhoL = Props('D','T',T,'Q',0,Fluid)
|
||||
rhoV = Props('D','T',T,'Q',1,Fluid)
|
||||
for Q in [0.0, 0.5, 1.0]:
|
||||
rho = 1/((1-Q)/rhoL+Q/rhoV)
|
||||
for inputs in twophase_inputs:
|
||||
for unit_system in ['kSI','SI']:
|
||||
yield check_consistency,Fluid,mode,unit_system, T,rho,inputs
|
||||
|
||||
def check_consistency(Fluid,mode,unit_system,T,rho,inputs):
|
||||
|
||||
if unit_system == 'SI':
|
||||
set_standard_unit_system(unit_systems_constants.UNIT_SYSTEM_SI)
|
||||
elif unit_system == 'kSI':
|
||||
set_standard_unit_system(unit_systems_constants.UNIT_SYSTEM_KSI)
|
||||
else:
|
||||
raise ValueError('invalid unit_system:'+str(unit_system))
|
||||
|
||||
if get_REFPROPname(Fluid) == 'N/A':
|
||||
return
|
||||
|
||||
if mode == 'REFPROP':
|
||||
Fluid = 'REFPROP-' + get_REFPROPname(Fluid)
|
||||
|
||||
if mode == 'pure' and not IsFluidType(Fluid,'PureFluid'):
|
||||
return
|
||||
|
||||
# Evaluate the inputs; if inputs is ('T','P'), calculate the temperature and the pressure
|
||||
Input1 = Props(inputs[0],'T',T,'D',rho,Fluid)
|
||||
Input2 = Props(inputs[1],'T',T,'D',rho,Fluid)
|
||||
|
||||
# Evaluate using the inputs given --> back to T,rho
|
||||
TEOS = Props('T',inputs[0],Input1,inputs[1],Input2,Fluid)
|
||||
DEOS = Props('D',inputs[0],Input1,inputs[1],Input2,Fluid)
|
||||
|
||||
print('T',inputs[0],Input1,inputs[1],Input2,Fluid)
|
||||
# Check they are consistent
|
||||
if abs(TEOS -T) > 1e-1 or abs(DEOS/rho-1) > 0.05:
|
||||
raise AssertionError("{T:g} K {D:g} kg/m^3 inputs: \"D\",'{ins1:s}',{in1:.12g},'{ins2:s}',{in2:.12g},\"{fluid:s}\" || T: {TEOS:g} D: {DEOS:g}".format(T = T,
|
||||
D = rho,
|
||||
TEOS = TEOS,
|
||||
DEOS = DEOS,
|
||||
inputs = str(inputs),
|
||||
in1 = Input1,
|
||||
in2 = Input2,
|
||||
ins1 = inputs[0],
|
||||
ins2 = inputs[1],
|
||||
fluid = Fluid)
|
||||
)
|
||||
|
||||
if __name__=='__main__':
|
||||
import nose
|
||||
nose.runmodule()
|
||||
@@ -1,23 +0,0 @@
|
||||
import CoolProp.CoolProp as CP
|
||||
import CoolProp.unit_systems_constants
|
||||
from CoolProp import param_constants
|
||||
from CoolProp.State import State
|
||||
|
||||
def test_global_param_strings():
|
||||
for p in ['version','errstring','gitrevision','FluidsList']:
|
||||
yield check_global, p
|
||||
|
||||
def check_global(p):
|
||||
CP.get_global_param_string(p)
|
||||
|
||||
def test_fluid_param_strings():
|
||||
for fluid in CoolProp.__fluids__:
|
||||
for p in ['aliases','CAS','ASHRAE34','REFPROPName','TTSE_mode']:
|
||||
yield check_fluid, fluid, p
|
||||
|
||||
def check_fluid(fluid, p):
|
||||
CP.get_fluid_param_string(fluid,p)
|
||||
|
||||
if __name__=='__main__':
|
||||
import nose
|
||||
nose.runmodule()
|
||||
@@ -1,161 +0,0 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
def test_back_compatibility():
|
||||
fluid_ref = 'R290'
|
||||
|
||||
def Ts_plot_tests():
|
||||
from CoolProp.Plots import Ts
|
||||
Ts(fluid_ref, show=False)
|
||||
|
||||
from matplotlib import pyplot
|
||||
fig = pyplot.figure(2)
|
||||
ax = fig.gca()
|
||||
Ts(fluid_ref, show=False, axis=ax)
|
||||
plt.close()
|
||||
Ts(fluid_ref, show=False, Tmin=200, Tmax=300)
|
||||
plt.close()
|
||||
|
||||
def Ph_plot_tests():
|
||||
from CoolProp.Plots import Ph
|
||||
Ph(fluid_ref, show=False)
|
||||
|
||||
from matplotlib import pyplot
|
||||
fig = pyplot.figure(2)
|
||||
ax = fig.gca()
|
||||
Ph(fluid_ref, show=False, axis=ax)
|
||||
plt.close()
|
||||
Ph(fluid_ref, show=False, Tmin=200, Tmax=300)
|
||||
plt.close()
|
||||
|
||||
def PT_plot_tests():
|
||||
from CoolProp.Plots import PT
|
||||
PT(fluid_ref, show=False)
|
||||
|
||||
from matplotlib import pyplot
|
||||
fig = pyplot.figure(2)
|
||||
ax = fig.gca()
|
||||
PT(fluid_ref, show=False, axis=ax)
|
||||
plt.close()
|
||||
PT(fluid_ref, show=False, Tmin=200, Tmax=300)
|
||||
plt.close()
|
||||
|
||||
def Ps_plot_tests():
|
||||
from CoolProp.Plots import Ps
|
||||
Ps(fluid_ref, show=False)
|
||||
|
||||
from matplotlib import pyplot
|
||||
fig = pyplot.figure(2)
|
||||
ax = fig.gca()
|
||||
Ps(fluid_ref, show=False, axis=ax)
|
||||
plt.close()
|
||||
Ps(fluid_ref, show=False, Tmin=200, Tmax=300)
|
||||
plt.close()
|
||||
|
||||
def Prho_plot_tests():
|
||||
from CoolProp.Plots import Prho
|
||||
Prho(fluid_ref, show=False)
|
||||
|
||||
from matplotlib import pyplot
|
||||
fig = pyplot.figure(2)
|
||||
ax = fig.gca()
|
||||
Prho(fluid_ref, show=False, axis=ax)
|
||||
plt.close()
|
||||
Prho(fluid_ref, show=False, Tmin=200, Tmax=300)
|
||||
plt.close()
|
||||
|
||||
def Trho_plot_tests():
|
||||
from CoolProp.Plots import Trho
|
||||
Trho(fluid_ref, show=False)
|
||||
|
||||
from matplotlib import pyplot
|
||||
fig = pyplot.figure(2)
|
||||
ax = fig.gca()
|
||||
Trho(fluid_ref, show=False, axis=ax)
|
||||
plt.close()
|
||||
Trho(fluid_ref, show=False, Tmin=200, Tmax=300)
|
||||
plt.close()
|
||||
|
||||
def hs_plot_tests():
|
||||
from CoolProp.Plots import hs
|
||||
hs(fluid_ref, show=False)
|
||||
|
||||
from matplotlib import pyplot
|
||||
fig = pyplot.figure(2)
|
||||
ax = fig.gca()
|
||||
hs(fluid_ref, show=False, axis=ax)
|
||||
plt.close()
|
||||
hs(fluid_ref, show=False, Tmin=200, Tmax=300)
|
||||
plt.close()
|
||||
|
||||
def Isolines_plot_tests():
|
||||
from matplotlib import pyplot
|
||||
from CoolProp.Plots import Ts, drawIsoLines
|
||||
ax = Ts(fluid_ref)
|
||||
#ax.set_xlim([-0.5, 1.5])
|
||||
#ax.set_ylim([300, 530])
|
||||
quality = drawIsoLines(fluid_ref, 'Ts', 'Q', [0.3, 0.5, 0.7, 0.8], axis=ax)
|
||||
isobars = drawIsoLines(fluid_ref, 'Ts', 'P', [100, 2000], num=5, axis=ax)
|
||||
isochores = drawIsoLines(fluid_ref, 'Ts', 'D', [2, 600], num=7, axis=ax)
|
||||
pyplot.close()
|
||||
|
||||
Ts_plot_tests()
|
||||
Ph_plot_tests()
|
||||
Ps_plot_tests()
|
||||
PT_plot_tests()
|
||||
Prho_plot_tests()
|
||||
Trho_plot_tests()
|
||||
hs_plot_tests()
|
||||
Isolines_plot_tests()
|
||||
|
||||
|
||||
def test_new_code():
|
||||
fluid_ref = 'Water'
|
||||
|
||||
def Ts_plot_tests():
|
||||
from CoolProp.Plots import PropsPlot
|
||||
PP = PropsPlot(fluid_ref, 'Ts')
|
||||
plt.close()
|
||||
|
||||
def Ph_plot_tests():
|
||||
from CoolProp.Plots import PropsPlot
|
||||
PP = PropsPlot(fluid_ref, 'Ph')
|
||||
plt.close()
|
||||
|
||||
def Isolines_plot_tests():
|
||||
from CoolProp.Plots import PropsPlot
|
||||
PP = PropsPlot(fluid_ref, 'Ts')
|
||||
#plt.set_axis_limits([-0.5, 1.5, 300, 530])
|
||||
PP.draw_isolines('Q', [0.3, 0.5, 0.7, 0.8])
|
||||
PP.draw_isolines('P', [100, 2000], num=5)
|
||||
PP.draw_isolines('D', [2, 600], num=7)
|
||||
plt.close()
|
||||
|
||||
def Graph_annotations():
|
||||
from CoolProp.Plots import PropsPlot, IsoLines
|
||||
PP = PropsPlot(fluid_ref, 'Ts')
|
||||
PP.draw_isolines('Q', [0.3, 0.5, 0.7, 0.8])
|
||||
PP.draw_isolines('P', [100, 2000], num=5)
|
||||
PP.draw_isolines('D', [2, 600], num=7)
|
||||
plt.title('New Title')
|
||||
PP.xlabel('New x label')
|
||||
PP.ylabel('New y label')
|
||||
PP = IsoLines(fluid_ref, 'Ts', 'P')
|
||||
PP.draw_isolines([100, 2000], num=5)
|
||||
plt.close()
|
||||
|
||||
def Mixture():
|
||||
from CoolProp.Plots import PropsPlot
|
||||
PP = PropsPlot('REFPROP-MIX:R32[0.47319469]&R125[0.2051091]&R134a[0.32169621]', 'TD')
|
||||
PP._plot_default_annotations()
|
||||
plt.close()
|
||||
|
||||
Ts_plot_tests()
|
||||
Ph_plot_tests()
|
||||
Isolines_plot_tests()
|
||||
Graph_annotations()
|
||||
Mixture()
|
||||
|
||||
if __name__=='__main__':
|
||||
import nose
|
||||
nose.runmodule()
|
||||
@@ -1,8 +0,0 @@
|
||||
#This file is automatically generated by the generate_constants_module.py script in dev/scripts.
|
||||
#DO NOT MODIFY THE CONTENTS OF THIS FILE!
|
||||
cimport unit_systems_constants_header
|
||||
|
||||
UNIT_SYSTEM_SI = unit_systems_constants_header.UNIT_SYSTEM_SI
|
||||
UNIT_SYSTEM_KSI = unit_systems_constants_header.UNIT_SYSTEM_KSI
|
||||
UNIT_SYSTEM_KSI_MOLAR = unit_systems_constants_header.UNIT_SYSTEM_KSI_MOLAR
|
||||
UNIT_SYSTEM_SI_MOLAR = unit_systems_constants_header.UNIT_SYSTEM_SI_MOLAR
|
||||
@@ -1,9 +0,0 @@
|
||||
#This file is automatically generated by the generate_constants_module.py script in dev/scripts.
|
||||
#DO NOT MODIFY THE CONTENTS OF THIS FILE!
|
||||
|
||||
cdef extern from "CoolProp.h":
|
||||
enum unit_systems:
|
||||
UNIT_SYSTEM_SI
|
||||
UNIT_SYSTEM_KSI
|
||||
UNIT_SYSTEM_KSI_MOLAR
|
||||
UNIT_SYSTEM_SI_MOLAR
|
||||
Reference in New Issue
Block a user