self.omega = omega self.HEOS = HEOS # Store the propoerties in a dict of CP_fluid instances coolprop_fluids = {} if has_CoolProp: for CASRN in coolprop_dict: HEOS = AbstractState("HEOS", CASRN) coolprop_fluids[CASRN] = CP_fluid( Tmin=HEOS.Tmin(), Tmax=HEOS.Tmax(), Pmax=HEOS.pmax(), has_melting_line=HEOS.has_melting_line(), Tc=HEOS.T_critical(), Pc=HEOS.p_critical(), Tt=HEOS.Ttriple(), omega=HEOS.acentric_factor(), HEOS=HEOS) def CoolProp_T_dependent_property(T, CASRN, prop, phase): r'''Calculates a property of a chemical in either the liquid or gas phase as a function of temperature only. This means that the property is either at 1 atm or along the saturation curve. Parameters ---------- T : float Temperature of the fluid [K] CASRN : str
self.Pmax = Pmax self.has_melting_line = has_melting_line self.Tc = Tc self.Pc = Pc self.Tt = Tt self.omega = omega self.HEOS = HEOS # Store the propoerties in a dict of CP_fluid instances coolprop_fluids = {} if has_CoolProp: for CASRN in coolprop_dict: HEOS = AbstractState("HEOS", CASRN) coolprop_fluids[CASRN] = CP_fluid(Tmin=HEOS.Tmin(), Tmax=HEOS.Tmax(), Pmax=HEOS.pmax(), has_melting_line=HEOS.has_melting_line(), Tc=HEOS.T_critical(), Pc=HEOS.p_critical(), Tt=HEOS.Ttriple(), omega=HEOS.acentric_factor(), HEOS=HEOS) def CoolProp_T_dependent_property(T, CASRN, prop, phase): r'''Calculates a property of a chemical in either the liquid or gas phase as a function of temperature only. This means that the property is either at 1 atm or along the saturation curve. Parameters ---------- T : float Temperature of the fluid [K] CASRN : str CAS number of the fluid prop : str
self.omega = omega self.HEOS = HEOS # Store the propoerties in a dict of CP_fluid instances coolprop_fluids = {} if has_CoolProp: for CASRN in coolprop_dict: HEOS = AbstractState("HEOS", CASRN) coolprop_fluids[CASRN] = CP_fluid( Tmin=HEOS.Tmin(), Tmax=HEOS.Tmax(), Pmax=HEOS.pmax(), has_melting_line=HEOS.has_melting_line(), Tc=HEOS.T_critical(), Pc=HEOS.p_critical(), Tt=HEOS.Ttriple(), omega=HEOS.acentric_factor(), HEOS=HEOS) class MultiCheb1D(object): '''Simple class to store set of coefficients for multiple chebshev approximations and perform calculations from them. ''' def __init__(self, points, coeffs): self.points = points self.coeffs = coeffs self.N = len(points) - 1 def __call__(self, x):
def __init__(self, symbol="N2", T=530.0, P=1000.0, child=1): '''Init generic Fluid''' self.symbol = symbol.upper() # http://www.coolprop.org/_static/doxygen/html/class_cool_prop_1_1_abstract_state.html AS = AbstractState("HEOS", self.symbol) self.AS = AS self.name = AS.name() self.T = T self.P = P self.child = child Tsi = TSI_fromEng(T) Psi = PSI_fromEng(P) AS.update(CP.PT_INPUTS, Psi, Tsi) self.WtMol = AS.molar_mass() * 1000.0 self.Tc = Teng_fromSI(AS.T_critical()) self.Pc = Peng_fromSI(AS.p_critical()) self.Dc = Deng_fromSI(AS.rhomass_critical()) self.Ttriple = Teng_fromSI(AS.Ttriple()) try: self.Tfreeze = Teng_fromSI(AS.T_freeze()) except: self.Tfreeze = self.Ttriple self.Tmin = Teng_fromSI(AS.Tmin()) self.Tmax = Teng_fromSI(AS.Tmax()) #self.Pmin = Peng_fromSI( AS.pmin() ) # missing from AbstractState self.Pmax = Peng_fromSI(AS.pmax()) dcIdeal = self.Pc * self.WtMol / self.Tc / 10.729 self.Zc = dcIdeal / self.Dc try: TnbpSI = PropsSI("T", "P", 101325, "Q", Q_LIQUID, self.symbol) self.good_nbp = True self.Tnbp = Teng_fromSI(TnbpSI) except: #print('WARNING... "%s" failed Normal Boiling Point Calculation.'%self.symbol) Ttriple = PropsSI(self.symbol, 'Ttriple') #print(' Using Triple Point = %g degK as Tref'%Ttriple) self.good_nbp = False self.Tnbp = 'N/A' if self.good_nbp: if self.Tnbp < 536.67: self.Tref = self.Tnbp # if NBP is low, use NBP as ref else: self.Tref = 536.67 # 536.67R = (SATP, Standard Ambient T P) = 77F, 25C else: self.Tref = Teng_fromSI(Ttriple) + 0.1 self.Pref = 14.7 #print( 'About to call setTP #1 with Tref, Pref=',self.Tref,self.Pref ) self.setTP(self.Tref, self.Pref) #print( 'Back from call setTP') self.Href = self.H #print( 'About to call setTP #2') self.setTP(T, P) #print( 'Back from call setTP') if child == 1: self.dup = EC_Fluid(symbol=self.symbol, T=self.T, P=self.P, child=0) self.calcdFreezePt = 0
#fluid = "R407C" #fluid = "R32[0.381109419953993]&R125[0.179558888662016]&R134A[0.439331691383991]" #fluid = "R32[0.40]&R125[0.15]&R134A[0.45]" fluids = ["R32","R125","R134a"] moles = [0.381109419953993,0.179558888662016,0.439331691383991] for backend in ["HEOS","REFPROP"]: state = AbstractState(backend, '&'.join(fluids)) state.set_mole_fractions(moles) print(state.get_mole_fractions()) print(state.get_mass_fractions()) try: print("Normal routines") print(state.T_critical()) print(state.p_critical()) print(True) except: try: print("Routine for all points") states = state.all_critical_points() for crit_state in states: print(crit_state.T) print(crit_state.p) print(crit_state.stable) except: print("All failed") print("\n-----------------\n") # import numpy as np
#fluid = "R407C" #fluid = "R32[0.381109419953993]&R125[0.179558888662016]&R134A[0.439331691383991]" #fluid = "R32[0.40]&R125[0.15]&R134A[0.45]" fluids = ["R32", "R125", "R134a"] moles = [0.381109419953993, 0.179558888662016, 0.439331691383991] for backend in ["HEOS", "REFPROP"]: state = AbstractState(backend, '&'.join(fluids)) state.set_mole_fractions(moles) print(state.get_mole_fractions()) print(state.get_mass_fractions()) try: print("Normal routines") print(state.T_critical()) print(state.p_critical()) print(True) except: try: print("Routine for all points") states = state.all_critical_points() for crit_state in states: print(crit_state.T) print(crit_state.p) print(crit_state.stable) except: print("All failed") print("\n-----------------\n") # import numpy as np
def get_critical_state( state: CoolProp.AbstractState) -> CoolProp.AbstractState: """Create a new state instance and update it with the critical point data Parameters ---------- state : CoolProp.AbstractState Returns ------- CoolProp.AbstractState """ crit_state = CP.PyCriticalState() crit_state.T = np.nan crit_state.p = np.nan crit_state.rhomolar = np.nan crit_state.stable = False try: crit_state.T = state.T_critical() crit_state.p = state.p_critical() crit_state.rhomolar = state.rhomolar_critical() crit_state.stable = True except: try: for crit_state_tmp in state.all_critical_points(): if crit_state_tmp.stable and (crit_state_tmp.T > crit_state.T or not np.isfinite(crit_state.T)): crit_state.T = crit_state_tmp.T crit_state.p = crit_state_tmp.p crit_state.rhomolar = crit_state_tmp.rhomolar crit_state.stable = crit_state_tmp.stable except: raise ValueError("Could not calculate the critical point data.") new_state = CoolProp.AbstractState(state.backend_name(), '&'.join(state.fluid_names())) masses = state.get_mass_fractions() if len(masses) > 1: new_state.set_mass_fractions(masses) # Uses mass fraction to work with incompressible fluids # try: new_state.build_phase_envelope("dummy") # except: pass # TODO: Remove this hack ASAP # Avoid problems with https://github.com/CoolProp/CoolProp/issues/1962 BE = state.backend_name() FL = '&'.join(state.fluid_names()) if BE == "HelmholtzEOSBackend" and FL == "Ammonia": crit_state.T *= 1.001 msg = "" if np.isfinite(crit_state.rhomolar) and np.isfinite(crit_state.T): try: new_state.specify_phase(CoolProp.iphase_critical_point) new_state.update(CoolProp.DmolarT_INPUTS, crit_state.rhomolar, crit_state.T) return new_state except Exception as e: msg += str(e) + " - " pass try: new_state.update(CoolProp.DmolarT_INPUTS, crit_state.rhomolar, crit_state.T) return new_state except Exception as e: msg += str(e) + " - " pass if np.isfinite(crit_state.p) and np.isfinite(crit_state.T): try: new_state.specify_phase(CoolProp.iphase_critical_point) new_state.update(CoolProp.PT_INPUTS, crit_state.p, crit_state.T) return new_state except Exception as e: msg += str(e) + " - " pass try: new_state.update(CoolProp.PT_INPUTS, crit_state.p, crit_state.T) return new_state except Exception as e: msg += str(e) + " - " pass raise ValueError("Could not calculate the critical point data. " + msg)