def create_Ts_diagram(T, S, T1, S1, T3, S3, P1, P2, P3, dome1, dome2, criticalisobar): stator_inlet = PropsSI("T", "P", P1, "S", S, 'Toluene') stator_outlet = PropsSI("T", "P", P2, "S", S, 'Toluene') rotor_outlet = PropsSI("T", "P", P3, "S", S, 'Toluene') dftemp = pd.DataFrame(T, columns=['T']) dfentr = pd.DataFrame(S, columns=['S']) dftemp['key'] = 1 dfentr['key'] = 1 df = dftemp.merge(dfentr, how='outer')[['S', 'T']] df['Z'] = df.apply( lambda x: PropsSI('Z', 'T', x['T'], 'S', x['S'], 'Toluene'), axis=1) df['phase'] = df.apply( lambda x: PropsSI('Phase', 'T', x['T'], 'S', x['S'], 'Toluene'), axis=1) gas = df['phase'] == CP.get_phase_index('phase_gas') supercritical_gas = df['phase'] == CP.get_phase_index( 'phase_supercritical_gas') df_filter = df[gas | supercritical_gas][['T', "S", "Z"]] hdfpivot = df_filter.pivot('T', 'S') X = hdfpivot.columns.levels[1].values Y = hdfpivot.index.values Z = hdfpivot.values Xi, Yi = np.meshgrid(X, Y) fig, ax = plt.subplots(figsize=(10, 7)) # isobars ax.plot(S, stator_inlet, color='black', linestyle='--') fig.text(0.3, 0.80, "{:4.2f}".format(P1 / 1e5) + ' [Bar]') ax.plot(S, stator_outlet, color='black', linestyle='--') fig.text(0.3, 0.42, "{:4.2f}".format(P2 / 1e5) + ' [Bar]') ax.plot(S, rotor_outlet, color='black', linestyle='--') fig.text(0.3, 0.29, "{:4.2f}".format(P3 / 1e5) + ' [Bar]') # ax.plot(S, condenser_inlet, color='black', linestyle='--') # dome ax.plot(dome1, T, color='black') ax.plot(dome2, T, color='black') # process ax.plot([S1, S3], [T1, T3], color='black', marker="X") # compressibility fig = ax.contourf(Xi, Yi, Z, 25, alpha=0.7, cmap=plt.cm.jet) ax.set_xlim([850, 1500]) ax.ticklabel_format(fontsize=20) ax.set_ylim([273.15, 600]) ax.set_xlabel(r'Entropy [J/kgK]', fontsize=15) ax.set_ylabel(r'Temperature [K]', fontsize=15) cb = plt.colorbar(fig) cb.set_label(r"Compressibility factor [-]", fontsize=15) return fig, ax
def __init__(self, fluid, T=None, V=None, P=None, Q=None): if (not P and not Q) and (T and V): self.T = T self.V = V self.P = CP.PropsSI("P", "T", T, "D",1/V, fluid.name) self.D = 1.0/self.V elif (not T and not Q) and (P and V): self.P = P self.V = V self.D = 1/self.V self.T = CP.PropsSI("T", "P", P, "D", self.D, fluid.name) self.C = CP.PropsSI("C", "P", P, "D", self.D, fluid.name) self.Phase = CP.PropsSI("Phase", "P", P, "D", self.D, fluid.name) if self.Phase == CP.get_phase_index('phase_twophase'): self.Q = CP.PropsSI("Q", "P", P, "D", self.D, fluid.name) self.Z = np.nan elif self.Phase == CP.get_phase_index('phase_liquid'): self.Q = 0 self.Z = CP.PropsSI("Z", "P", P, "D", self.D, fluid.name) elif self.Phase == CP.get_phase_index('phase_supercritical_gas'): self.Q = 1 self.Z = CP.PropsSI("Z", "P", P, "D", self.D, fluid.name) elif self.Phase == CP.get_phase_index('phase_gas'): self.Q = 1 self.Z = CP.PropsSI("Z", "P", P, "D", self.D, fluid.name) elif self.Phase == CP.get_phase_index('phase_supercritical'): self.Q = 1 self.Z = CP.PropsSI("Z", "P", P, "D", self.D, fluid.name) elif self.Phase == CP.get_phase_index('phase_supercritical_liquid'): self.Q = 0 self.Z = CP.PropsSI("Z", "P", P, "D", self.D, fluid.name) else: raise NotImplementedError self.H = CP.PropsSI("H", "P", P, "D", self.D, fluid.name) self.S = CP.PropsSI("S", "P", P, "D", self.D, fluid.name) elif (V is None and Q is None) and (P and T): self.P = P self.T = T self.D = CP.PropsSI("D", "P", P, "T",T, fluid.name) self.V = 1./self.D elif (not V and not T) and (P and (Q is not None)): self.P = P self.T = CP.PropsSI("T", "P", P, "Q", Q, fluid.name) self.D = CP.PropsSI("D", "P", P, "Q", Q, fluid.name) self.V = 1./self.D else: raise NotImplementedError
def phase_dict(): res = [] res.append(cp.get_phase_index('phase_twophase')) res.append('phase_twophase') res.append(cp.get_phase_index('phase_liquid')) res.append('phase_liquid') res.append(cp.get_phase_index('phase_gas')) res.append('phase_gas') res.append(cp.get_phase_index('phase_supercritical_liquid')) res.append('phase_supercritical_liquid') res.append(cp.get_phase_index('phase_supercritical')) res.append('phase_supercritical') res.append(cp.get_phase_index('phase_supercritical_gas')) res.append('phase_supercritical_gas') return res
def create_Hs_diagram(H, S, H1, H01, S1, H2, H02, S2, H2s, S2s, H3, H03, S3, H3s, S3s, H4, H04, S4, P1, P2, P3, P4, dome1h, dome2h, dome1, dome2, criticalisobar): #creating isobars stator_inlet = PropsSI("H", "P", P1, "S", S, 'Toluene') * 1e-3 stator_outlet = PropsSI("H", "P", P2, "S", S, 'Toluene') * 1e-3 rotor_outlet = PropsSI("H", "P", P3, "S", S, 'Toluene') * 1e-3 condenser_inlet = PropsSI("H", "P", P4, "S", S, 'Toluene') * 1e-3 #creating contour dftemp = pd.DataFrame(H, columns=['H']) dfentr = pd.DataFrame(S, columns=['S']) dftemp['key'] = 1 dfentr['key'] = 1 df = dftemp.merge(dfentr, how='outer')[['S', 'H']] df['Z'] = df.apply( lambda x: PropsSI('Z', 'H', x['H'], 'S', x['S'], 'Toluene'), axis=1) df['phase'] = df.apply( lambda x: PropsSI('Phase', 'H', x['H'], 'S', x['S'], 'Toluene'), axis=1) gas = df['phase'] == CP.get_phase_index('phase_gas') supercritical_gas = df['phase'] == CP.get_phase_index( 'phase_supercritical_gas') df_filter = df[gas | supercritical_gas][['H', "S", "Z"]] df_filter['H'] = df_filter['H'] * 1e-3 df_filter['S'] = df_filter['S'] * 1e-3 hdfpivot = df_filter.pivot('H', 'S') X = hdfpivot.columns.levels[1].values Y = hdfpivot.index.values Z = hdfpivot.values Xi, Yi = np.meshgrid(X, Y) fig, ax = plt.subplots(figsize=(10, 7)) # isobars ax.plot(S * 1e-3, H01 * np.ones(np.size(S)) * 1e-3, color='black', linestyle=':') fig.text(0.15, 0.77, "$\displaystyle h_{01}$", fontsize=20) ax.plot(S * 1e-3, H03 * np.ones(np.size(S)) * 1e-3, color='black', linestyle=':') fig.text(0.15, 0.5, "$\displaystyle h_{03}$", fontsize=20) #isobars ax.plot(S * 1e-3, stator_inlet, color='black', linestyle='--') fig.text(0.3, 0.65, "{:4.2f}".format(P1 / 1e5) + ' [Bar]') ax.plot(S * 1e-3, stator_outlet, color='black', linestyle='--') fig.text(0.3, 0.42, "{:4.2f}".format(P2 / 1e5) + ' [Bar]') ax.plot(S * 1e-3, rotor_outlet, color='black', linestyle='--') fig.text(0.3, 0.29, "{:4.2f}".format(P3 / 1e5) + ' [Bar]') ax.plot(S * 1e-3, condenser_inlet, color='black', linestyle='--') fig.text(0.3, 0.33, "{:4.2f}".format(P4 / 1e5) + ' [Bar]') # ax.plot(S, condenser_inlet, color='black', linestyle='--') # dome ax.plot(dome1 * 1e-3, dome1h * 1e-3, color='black') ax.plot(dome2 * 1e-3, dome2h * 1e-3, color='black') # process ax.plot([S1 * 1e-3, S2 * 1e-3, S3 * 1e-3, S4 * 1e-3], [H1 * 1e-3, H2 * 1e-3, H3 * 1e-3, H4 * 1e-3], color='black', marker="X") #isentropic process ax.plot([S1 * 1e-3, S2s * 1e-3], [H1 * 1e-3, H2s * 1e-3], color='black', marker="o") ax.plot([S2 * 1e-3, S3s * 1e-3], [H2 * 1e-3, H3s * 1e-3], color='black', marker="o") # compressibility fig = ax.contourf(Xi, Yi, Z, 25, alpha=0.7, cmap=plt.cm.jet) ax.set_xlim([.850, 1.5]) ax.ticklabel_format(fontsize=20) ax.set_ylim([200, 700]) ax.set_xlabel(r'Entropy [KJ/kgK]', fontsize=15) ax.set_ylabel(r'Enthalpy [KJ/kg]', fontsize=15) cb = plt.colorbar(fig) cb.set_label(r"Compressibility factor [-]", fontsize=15) return fig, ax