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 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 plotIsochores(self): fState = FluidState(self.fluid) rhoArr1 = np.logspace(np.log10(self.rhoMin), np.log10(self.critical.rho), num=20, endpoint=False) rhoArr2 = np.logspace(np.log10(self.critical.rho), np.log10(self.rhoMax), num=5) rhoArr = np.zeros(len(rhoArr1) + len(rhoArr2)) rhoArr[:len(rhoArr1)] = rhoArr1[:] rhoArr[len(rhoArr1):] = rhoArr2[:] TArr = np.logspace(np.log10(self.TMin), np.log10(self.TMax), num=100) # For label location purposes h_level_low = self.hMin + (self.critical.h - self.hMin) * 3 / 4. h_level_high = self.critical.h + (self.hMax - self.critical.h) * 1 / 2. for rho in rhoArr: try: hArr = np.zeros(len(TArr)) pArr = np.zeros(len(TArr)) for i in range(len(TArr)): fState.update_Trho(TArr[i], rho) hArr[i] = fState.h pArr[i] = fState.p # Putting labels # Determining annotated point and label text offest if (pArr[i - 1] < self.pMax and pArr[i] > self.pMax): if (hArr[i] < h_level_low): 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(rho, sig=2), xy=(hArr[i - 1] / 1e3, pArr[i - 1] / 1e5), xytext=(0, -10), textcoords='offset points', color='g', size="small", rotation=angle) elif (hArr[i] > h_level_low and hArr[i] < h_level_high): angle, offset_x, offset_y = self.getLabelPlacement( x1=hArr[i - 2], x2=hArr[i - 1], y1=pArr[i - 2], y2=pArr[i - 1]) self.ax.annotate(formatNumber(rho, sig=2), xy=(hArr[i - 2] / 1e3, pArr[i - 2] / 1e5), xytext=(5, -5), textcoords='offset points', color='g', size="small", rotation=angle) elif (hArr[i] > h_level_high): angle, offset_x, offset_y = self.getLabelPlacement( x1=hArr[i - 10], x2=hArr[i - 9], y1=pArr[i - 10], y2=pArr[i - 9]) self.ax.annotate(formatNumber(rho, sig=2), xy=(hArr[i - 10] / 1e3, pArr[i - 10] / 1e5), xytext=(0, -5), textcoords='offset points', color='g', size="small", rotation=angle) elif (i == len(TArr) - 1 and pArr[i] < self.pMax and pArr[i - 1] > self.pMin): 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(rho, sig=2), xy=(hArr[i] / 1e3, pArr[i] / 1e5), xytext=(-30, -12), textcoords='offset points', color='g', size="small", rotation=angle) if (rho == rhoArr[0]): self.ax.semilogy(hArr / 1e3, pArr / 1e5, 'g', label='density [kg/m3]') else: self.ax.semilogy(hArr / 1e3, pArr / 1e5, 'g') except RuntimeError, e: print '------------------' print 'Runtime Warning for rho=%e' % rho 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
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 plotIsochores(self): fState = FluidState(self.fluid) rhoArr1 = np.logspace(np.log10(self.rhoMin), np.log10(self.critical.rho), num = 20, endpoint = False) rhoArr2 = np.logspace(np.log10(self.critical.rho), np.log10(self.rhoMax), num = 5) rhoArr = np.zeros(len(rhoArr1) + len(rhoArr2)) rhoArr[:len(rhoArr1)] = rhoArr1[:] rhoArr[len(rhoArr1):] = rhoArr2[:] TArr = np.logspace(np.log10(self.TMin), np.log10(self.TMax), num = 100) # For label location purposes h_level_low = self.hMin + (self.critical.h - self.hMin) * 3 / 4. h_level_high = self.critical.h + (self.hMax - self.critical.h) * 1 / 2. for rho in rhoArr: try: hArr = np.zeros(len(TArr)) pArr = np.zeros(len(TArr)) for i in range(len(TArr)): fState.update_Trho(TArr[i], rho) hArr[i] = fState.h pArr[i] = fState.p # Putting labels # Determining annotated point and label text offest if (pArr[i-1] < self.pMax and pArr[i] > self.pMax): if (hArr[i] < h_level_low): 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(rho, sig = 2), xy = (hArr[i-1] / 1e3, pArr[i-1] / 1e5), xytext=(0, -10), textcoords='offset points', color='g', size="small", rotation = angle) elif (hArr[i] > h_level_low and hArr[i] < h_level_high): angle, offset_x, offset_y = self.getLabelPlacement(x1 = hArr[i-2], x2 = hArr[i-1], y1 = pArr[i-2], y2 = pArr[i-1]) self.ax.annotate(formatNumber(rho, sig = 2), xy = (hArr[i-2] / 1e3, pArr[i-2] / 1e5), xytext=(5, -5), textcoords='offset points', color='g', size="small", rotation = angle) elif (hArr[i] > h_level_high): angle, offset_x, offset_y = self.getLabelPlacement(x1 = hArr[i-10], x2 = hArr[i-9], y1 = pArr[i-10], y2 = pArr[i-9]) self.ax.annotate(formatNumber(rho, sig = 2), xy = (hArr[i-10] / 1e3, pArr[i-10] / 1e5), xytext=(0, -5), textcoords='offset points', color='g', size="small", rotation = angle) elif (i == len(TArr) - 1 and pArr[i] < self.pMax and pArr[i-1] > self.pMin): 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(rho, sig = 2), xy = (hArr[i] / 1e3, pArr[i] / 1e5), xytext=(-30, -12), textcoords='offset points', color='g', size="small", rotation = angle) if (rho == rhoArr[0]): self.ax.semilogy(hArr/1e3, pArr/1e5, 'g', label = 'density [kg/m3]') else: self.ax.semilogy(hArr/1e3, pArr/1e5, 'g') except RuntimeError, e: print '------------------' print 'Runtime Warning for rho=%e'%rho print(e)