def testState(): s1 = FluidState('ParaHydrogen') s1.update('P', 700e5, 'T', 288) print("p={0}".format(s1.p())) print("T={0}".format(s1.T())) print("rho={0}".format(s1.rho())) print("h={0}".format(s1.h())) print("s={0}".format(s1.s())) print("cp={0}".format(s1.cp())) print("cv={0}".format(s1.cv())) print("gamma={0}".format(s1.gamma())) print("dpdt_v={0}".format(s1.dpdt_v())) print("dpdv_t={0}".format(s1.dpdv_t())) print("beta={0}".format(s1.beta())) print("mu={0}".format(s1.mu())) print("lambfa={0}".format(s1.cond())) print("Pr={0}".format(s1.Pr())) s2 = FluidState('ParaHydrogen') s2.update_Tp(s1.T(), s1.p()) print("update_Tp rho={0}".format(s2.rho())) s3 = FluidState('ParaHydrogen') s3.update_Trho(s1.T(), s1.rho()) print("update_Trho p={0}".format(s3.p())) s4 = FluidState('ParaHydrogen') s4.update_prho(s1.p(), s1.rho()) print("update_prho T={0}".format(s4.T())) s5 = FluidState('ParaHydrogen') s5.update_ph(s1.p(), s1.h()) print("update_ph ={0}".format(s5.T())) s6 = FluidState('ParaHydrogen') s6.update_ps(s1.p(), s1.s()) print("update_ps T={0}".format(s6.T())) s7 = FluidState('ParaHydrogen') s7.update_pq(1e5, 0) print("update_pq T={0}".format(s7.T())) s8 = FluidState('ParaHydrogen') s8.update_Tq(25, 0) print("update_Tq p={0}".format(s8.p())) print('--------------------') print('Initialize state from fluid') h2 = Fluid('ParaHydrogen') s9 = FluidState(h2) s9.update_Tp(s1.T(), s1.p()) print("rho={0}".format(s9.rho()))
@author: Atanas Pavlov ''' import numpy as np from smo.media.CoolProp.CoolProp import FluidState, Fluid fluid = Fluid('Water') dT = 1e-4 dq = 1e-3 f1 = FluidState(fluid) f2 = FluidState(fluid) f1.update_Tq(273.15 + 150, 0.5) # dqdT_v f2.update_Trho(f1.T + dT, f1.rho) dqdT_v = (f2.q - f1.q) / (f2.T - f1.T) print ("dqdT_v() numerical: {:e}, analytical: {:e}".format(dqdT_v, f1.dqdT_v)) # dvdT_q f2.update_Tq(f1.T + dT, f1.q) dvdT_q = (f2.v - f1.v) / (f2.T - f1.T) dvdT_q_1 = f1.q * f1.SatV.dvdT + (1 - f1.q) * f1.SatL.dvdT print ("dvdT_q() numerical: {:e}, analytical: {:e}, analytical2: {:e}".format(dvdT_q, f1.dvdT_q, dvdT_q_1)) # dvdq_T f2.update_Tq(f1.T, f1.q + dq) dvdq_T = (f2.v - f1.v) / (f2.q - f1.q)
def plotIsotherms(self): fState = FluidState(self.fluid) TArr = np.logspace(np.log10(self.TMin), np.log10(self.TMax), num = 20) TOrders = np.floor(np.log10(TArr)) TArr = np.ceil(TArr / 10**(TOrders - 2)) * 10**(TOrders - 2) fSatL = FluidState(self.fluidName) fSatV = FluidState(self.fluidName) f1 = FluidState(self.fluidName) for T in TArr: if self.temperatureUnit == 'degC': T_label = T - 273.15 else: T_label = T try: f1.update_Tp(T, self.pMax) if (T > self.critical.T): rhoArr1 = np.logspace(np.log10(self.rhoMin), np.log10(self.critical.rho), num = 100) rhoArr2 = np.logspace(np.log10(self.critical.rho), np.log10(f1.rho), num = 100) else: fSatL.update_Tq(T, 0) fSatV.update_Tq(T, 1) rhoArr1 = np.logspace(np.log10(self.rhoMin), np.log10(fSatV.rho), num = 100) rhoArr2 = np.logspace(np.log10(fSatL.rho), np.log10(f1.rho), num = 100) rhoArr = np.hstack((rhoArr1, rhoArr2)) hArr = np.zeros(len(rhoArr)) pArr = np.zeros(len(rhoArr)) for i in range(len(rhoArr)): fState.update_Trho(T, rhoArr[i]) hArr[i] = fState.h pArr[i] = fState.p # Determining label location if (T < self.critical.T): if (i == len(rhoArr1)): self.ax.annotate(formatNumber(T_label, sig = 3), xy = ((fSatL.h + fSatV.h) / 2. / 1e3, pArr[i] / 1e5), xytext=(0, 3), textcoords='offset points', color='r', size="small") else: if (i>0): b = np.log10(self.pMin / 1e5) - self.minDiagonalSlope * self.hMin / 1e3 if (np.log10(pArr[i-1] / 1e5) - self.minDiagonalSlope * hArr[i-1] / 1e3 - b) * \ (np.log10(pArr[i] / 1e5) - self.minDiagonalSlope * hArr[i] / 1e3 - b) <= 0: # Getting label rotation angle angle, offset_x, offset_y = self.getLabelPlacement(x1 = hArr[i-1], x2 = hArr[i], y1 = pArr[i-1], y2 = pArr[i]) self.ax.annotate(formatNumber(T_label, sig = 3), xy = (hArr[i]/1e3, pArr[i]/1e5), xytext=(offset_x, offset_y), textcoords='offset points', color='r', size="small", rotation = angle) if (T == TArr[0]): if self.temperatureUnit == 'degC': label = "temperature [C]" else: label = "temperature [K]" self.ax.semilogy(hArr/1e3, pArr/1e5, 'r', label = label) else: self.ax.semilogy(hArr/1e3, pArr/1e5, 'r') except RuntimeError, e: print '------------------' print 'Runtime Warning for T=%e'%T print(e)
def plotIsotherms(self): fState = FluidState(self.fluid) TArr = np.logspace(np.log10(self.TMin), np.log10(self.TMax), num=20) TOrders = np.floor(np.log10(TArr)) TArr = np.ceil(TArr / 10**(TOrders - 2)) * 10**(TOrders - 2) fSatL = FluidState(self.fluidName) fSatV = FluidState(self.fluidName) f1 = FluidState(self.fluidName) for T in TArr: if self.temperatureUnit == 'degC': T_label = T - 273.15 else: T_label = T try: f1.update_Tp(T, self.pMax) if (T > self.critical.T): rhoArr1 = np.logspace(np.log10(self.rhoMin), np.log10(self.critical.rho), num=100) rhoArr2 = np.logspace(np.log10(self.critical.rho), np.log10(f1.rho), num=100) else: fSatL.update_Tq(T, 0) fSatV.update_Tq(T, 1) rhoArr1 = np.logspace(np.log10(self.rhoMin), np.log10(fSatV.rho), num=100) rhoArr2 = np.logspace(np.log10(fSatL.rho), np.log10(f1.rho), num=100) rhoArr = np.hstack((rhoArr1, rhoArr2)) hArr = np.zeros(len(rhoArr)) pArr = np.zeros(len(rhoArr)) for i in range(len(rhoArr)): fState.update_Trho(T, rhoArr[i]) hArr[i] = fState.h pArr[i] = fState.p # Determining label location if (T < self.critical.T): if (i == len(rhoArr1)): self.ax.annotate(formatNumber(T_label, sig=3), xy=((fSatL.h + fSatV.h) / 2. / 1e3, pArr[i] / 1e5), xytext=(0, 3), textcoords='offset points', color='r', size="small") else: if (i > 0): b = np.log10( self.pMin / 1e5) - self.minDiagonalSlope * self.hMin / 1e3 if (np.log10(pArr[i-1] / 1e5) - self.minDiagonalSlope * hArr[i-1] / 1e3 - b) * \ (np.log10(pArr[i] / 1e5) - self.minDiagonalSlope * hArr[i] / 1e3 - b) <= 0: # Getting label rotation angle angle, offset_x, offset_y = self.getLabelPlacement( x1=hArr[i - 1], x2=hArr[i], y1=pArr[i - 1], y2=pArr[i]) self.ax.annotate(formatNumber(T_label, sig=3), xy=(hArr[i] / 1e3, pArr[i] / 1e5), xytext=(offset_x, offset_y), textcoords='offset points', color='r', size="small", rotation=angle) if (T == TArr[0]): if self.temperatureUnit == 'degC': label = "temperature [C]" else: label = "temperature [K]" self.ax.semilogy(hArr / 1e3, pArr / 1e5, 'r', label=label) else: self.ax.semilogy(hArr / 1e3, pArr / 1e5, 'r') except RuntimeError, e: print '------------------' print 'Runtime Warning for T=%e' % T print(e)
@author: Atanas Pavlov ''' import numpy as np from smo.media.CoolProp.CoolProp import FluidState, Fluid fluid = Fluid('Water') dT = 1e-4 dq = 1e-3 f1 = FluidState(fluid) f2 = FluidState(fluid) f1.update_Tq(273.15 + 150, 0.5) # dqdT_v f2.update_Trho(f1.T + dT, f1.rho) dqdT_v = (f2.q - f1.q) / (f2.T - f1.T) print("dqdT_v() numerical: {:e}, analytical: {:e}".format(dqdT_v, f1.dqdT_v)) # dvdT_q f2.update_Tq(f1.T + dT, f1.q) dvdT_q = (f2.v - f1.v) / (f2.T - f1.T) dvdT_q_1 = f1.q * f1.SatV.dvdT + (1 - f1.q) * f1.SatL.dvdT print("dvdT_q() numerical: {:e}, analytical: {:e}, analytical2: {:e}".format( dvdT_q, f1.dvdT_q, dvdT_q_1)) # dvdq_T f2.update_Tq(f1.T, f1.q + dq)