def test(): test_instance = DerivativeTest("Water") _drhodT_s = test_instance.numerical_derivative('rho', 'T', 633.15, 'S', 4000) print ('Numerical: ' + str(_drhodT_s)) fState = FluidState("Water") fState.update_Ts(633.15, 4000) print ('Analytical: ' + str(fState.rho**2 * fState.dsdT_v / fState.dpdT_v)) print ('q = {}'.format(fState.q))
def test(): test_instance = DerivativeTest("Water") _drhodT_s = test_instance.numerical_derivative('rho', 'T', 633.15, 'S', 4000) print('Numerical: ' + str(_drhodT_s)) fState = FluidState("Water") fState.update_Ts(633.15, 4000) print('Analytical: ' + str(fState.rho**2 * fState.dsdT_v / fState.dpdT_v)) print('q = {}'.format(fState.q))
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