Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. import numpy as np
  2. import re
  3. import gzip
  4.  
  5. EOS2_HEADER = "cccccccccccc"
  6.  
  7. CE = 1.78266E12
  8. M_U = 931.494
  9.  
  10. # Index for HShen EOS table, V2
  11. IDX_Log_Baryon_Density_EOS2 = 0
  12. IDX_Baryon_Number_Density_EOS2 = 1
  13. IDX_Proton_Fraction_EOS2 = 2
  14. IDX_Free_Energy_EOS2 = 3
  15. IDX_Internal_Energy_EOS2 = 4
  16. IDX_Entropy_EOS2 = 5
  17. IDX_MU_NP_EOS2 = 6
  18. IDX_Pressure_EOS2 = 13
  19. IDX_MU_N_EOS2 = 14
  20. IDX_MU_P_EOS2 = 15
  21.  
  22. # EOS2
  23. NB_MESH_EOS2 = np.logspace(5.1, 16.0, num=110, dtype=np.float64)
  24. XP_MESH_EOS2 = np.linspace(0.01, 0.65, num=65, dtype=np.float64)
  25. T_MESH_EOS2 = np.logspace(-1.0, 2.6, num=91, dtype=np.float64)
  26.  
  27. def skip_line(f):
  28. f.readline()
  29.  
  30. def read_numbers(f):
  31. return [float(x) for x in re.split(r'\s+', f.readline().strip())]
  32.  
  33. def read_eos(file:str):
  34. eos_open = gzip.open if file.endswith('.gz') else open
  35. with eos_open(file) as f:
  36. for temp in T_MESH_EOS2:
  37. assert f.readline().strip() == EOS2_HEADER
  38. skip_line(f)
  39. (_, temp_r) = read_numbers(f)
  40. assert np.allclose(temp_r, temp)
  41. skip_line(f)
  42.  
  43. for xp in XP_MESH_EOS2:
  44. pressures = np.zeros(NB_MESH_EOS2.size)
  45. for idx, nb in enumerate(NB_MESH_EOS2):
  46. pressures[idx] = read_numbers(f)[IDX_Pressure_EOS2]
  47. if idx > 0 and nb/CE/M_U >= 0.08 and pressures[idx] < pressures[idx-1]:
  48. print(pressures[idx], pressures[idx-1])
  49. print("Warning: pressure non-monotonic detected at temp={:.2f}, rho={:.2E} and xp={:.2f}...".format(temp_r, nb/CE/M_U, xp))
  50. skip_line(f)
  51.  
  52.  
  53. if __name__ == "__main__":
  54. # read_eos("/mnt/c/Users/megrez/Downloads/eos2.tab/eos2.tab")
  55. read_eos("/path/to/eos2_LU2018_V18.tab")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement