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()))
def plotIsentrops(self): fState = FluidState(self.fluid) sArr = np.linspace(self.sMin, self.sMax, num=20) for s in sArr: try: hArr = [] pArr = [] fState.update_ps(self.pMax, s) if (fState.T > self.TMax): fState.update_Ts(self.TMax, s) T = fState.T hArr.append(fState.h) pArr.append(fState.p) # Calculated v v_res = fState.v while (T > self.TMin): _dvdT_s = -fState.dsdT_v / fState.dpdT_v if math.isnan(_dvdT_s): break TStep = -(self.critical.T / 200.) / (np.abs(_dvdT_s) + 1) T = T + TStep if T < self.TMin: break v_res += _dvdT_s * TStep fState.update_Trho(T, 1. / v_res) p = fState.p # If it goes out of the screen through the bottom if (p < self.pMin): break # Calculated s s_res = fState.s # Correcting v ds = s - s_res sigma = ds * fState.dvds_T v = v_res + sigma fState.update_Trho(T, 1. / v) hArr.append(fState.h) pArr.append(fState.p) ################## # Putting labels i = len(hArr) - 1 b = np.log10(self.pMax / 1e5) - self.majDiagonalSlope * self.hMin / 1e3 if (np.log10(pArr[i-1] / 1e5) - self.majDiagonalSlope * hArr[i-1] / 1e3 - b) * \ (np.log10(pArr[i] / 1e5) - self.majDiagonalSlope * hArr[i] / 1e3 - b) <= 0: 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(s / 1e3, sig=3), xy=(hArr[i - 1] / 1e3, pArr[i - 1] / 1e5), xytext=(-offset_x, -offset_y), textcoords='offset points', color='m', size="small", rotation=angle) ####################### hArr = np.array(hArr) pArr = np.array(pArr) if (s == sArr[0]): self.ax.semilogy(hArr / 1e3, pArr / 1e5, 'm', label="entropy [kJ/kg-K]") else: self.ax.semilogy(hArr / 1e3, pArr / 1e5, 'm') except RuntimeError, e: print '------------------' print 'Runtime Warning for s=%e' % s print e
def plotIsentrops(self): fState = FluidState(self.fluid) sArr = np.linspace(self.sMin, self.sMax, num = 20) for s in sArr: try: hArr = [] pArr = [] fState.update_ps(self.pMax, s) if (fState.T > self.TMax): fState.update_Ts(self.TMax, s) T = fState.T hArr.append(fState.h) pArr.append(fState.p) # Calculated v v_res = fState.v while (T > self.TMin): _dvdT_s = - fState.dsdT_v / fState.dpdT_v if math.isnan(_dvdT_s ): break TStep = - (self.critical.T / 200.) / (np.abs(_dvdT_s) + 1) T = T + TStep if T < self.TMin: break v_res += _dvdT_s * TStep fState.update_Trho(T, 1. / v_res) p = fState.p # If it goes out of the screen through the bottom if (p < self.pMin): break # Calculated s s_res = fState.s # Correcting v ds = s - s_res sigma = ds * fState.dvds_T v = v_res + sigma fState.update_Trho(T, 1. / v) hArr.append(fState.h) pArr.append(fState.p) ################## # Putting labels i = len(hArr) - 1 b = np.log10(self.pMax / 1e5) - self.majDiagonalSlope * self.hMin / 1e3 if (np.log10(pArr[i-1] / 1e5) - self.majDiagonalSlope * hArr[i-1] / 1e3 - b) * \ (np.log10(pArr[i] / 1e5) - self.majDiagonalSlope * hArr[i] / 1e3 - b) <= 0: 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(s/1e3, sig = 3), xy = (hArr[i-1]/1e3, pArr[i-1]/1e5), xytext=(-offset_x, -offset_y), textcoords='offset points', color='m', size="small", rotation = angle) ####################### hArr = np.array(hArr) pArr = np.array(pArr) if (s == sArr[0]): self.ax.semilogy(hArr/1e3, pArr/1e5, 'm', label = "entropy [kJ/kg-K]") else: self.ax.semilogy(hArr/1e3, pArr/1e5, 'm') except RuntimeError, e: print '------------------' print 'Runtime Warning for s=%e'%s print e