fork download
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. # Constants
  5. T_c = 647.096 # K, critical temperature of water
  6. T_ref = 373.15 # K, reference temp (100°C)
  7. L_ref = 2257e3 # J/kg, latent heat at T_ref
  8.  
  9. # Temperature range: from 0.1°C to just below critical
  10. T = np.linspace(274, 645, 500) # in K
  11.  
  12. # Latent heat using Watson's correlation
  13. def latent_heat(T):
  14. return L_ref * ((T_c - T) / (T_c - T_ref))**0.38 # J/kg
  15.  
  16. # Saturated liquid entropy (assume simple polynomial fit)
  17. def s_liquid(T):
  18. return 0.5 + 0.001 * (T - 273.15) # crude estimate in kJ/kg·K
  19.  
  20. # Entropy of vaporization
  21. def delta_s(T):
  22. return latent_heat(T) / T / 1000 # Convert J to kJ
  23.  
  24. # Saturated vapor entropy
  25. def s_vapor(T):
  26. return s_liquid(T) + delta_s(T)
  27.  
  28. # Convert T to °C for x-axis
  29. T_C = T - 273.15
  30.  
  31. # Compute values
  32. s_l = s_liquid(T)
  33. s_v = s_vapor(T)
  34.  
  35. # Plotting
  36. plt.figure(figsize=(8, 6))
  37. plt.plot(s_l, T_C, label='Saturated Liquid', color='blue')
  38. plt.plot(s_v, T_C, label='Saturated Vapor', color='red')
  39. plt.fill_betweenx(T_C, s_l, s_v, color='lightgray', alpha=0.5, label='Wet Region')
  40.  
  41. plt.xlabel('Entropy (kJ/kg·K)')
  42. plt.ylabel('Temperature (°C)')
  43. plt.title('T–S Diagram of Water (Physics-Based Model)')
  44. plt.legend()
  45. plt.grid(True)
  46. plt.tight_layout()
  47. plt.show()
Success #stdin #stdout 0.96s 60804KB
stdin
Standard input is empty
stdout
Standard output is empty