/tools/generate_ideal_table.f

https://bitbucket.org/NeilMiller/h5tbuilder · FORTRAN Legacy · 164 lines · 106 code · 35 blank · 23 comment · 0 complexity · f88e17aa8ee57a3059e12358c42886f5 MD5 · raw file

  1. !! This simple procedure is necessary to generate the h5 table
  2. program generate_water_table
  3. use aneos_access
  4. use ideal_water
  5. implicit none
  6. integer :: i, j, NRho, NT, outid, outid2, ios
  7. double precision :: logRho, logT, lnRho, lnT, Rho, T, Fvect(num_free_derivs)
  8. double precision, pointer, dimension(:) :: logRhovect, logTvect
  9. double precision, pointer, dimension(:,:) :: Fr, dfdrho, dfdt, d2fdrho2, &
  10. d2fdt2, d2fdrhodt, d3fdrho2dt, d3fdrhodt2, d4fdrho2dt2
  11. double precision :: logRhoLow, logRhoHi, dlogRho
  12. double precision :: logTLow, logTHi, dlogT
  13. character (len=256) :: filename
  14. double precision :: f_val, df_drho, df_dt, d2f_drho2, d2f_dt2, d2f_drhodt, &
  15. d3f_drho3, d3f_drho2dt, d3f_drhodt2, d3f_dt3, d4f_drho2dt2
  16. NRho = 81
  17. NT = 31
  18. allocate(Fr(NRho, NT))
  19. allocate(dfdrho(NRho, NT))
  20. allocate(dfdt(NRho, NT))
  21. allocate(d2fdrho2(NRho, NT))
  22. allocate(d2fdt2(NRho, NT))
  23. allocate(d2fdrhodt(NRho, NT))
  24. allocate(d3fdrho2dt(NRho, NT))
  25. allocate(d3fdrhodt2(NRho, NT))
  26. allocate(d4fdrho2dt2(NRho, NT))
  27. allocate(logRhovect(NRho))
  28. allocate(logTvect(NT))
  29. logRhoLow = -5.
  30. logRhoHi = 3.
  31. logTLow = 2.8
  32. logTHi = 6.8
  33. dlogRho = (logRhoHi - logRhoLow) / (NRho - 1)
  34. dlogT = (logTHi - logTLow) / (NT - 1)
  35. !! Write out both formatted and unformatted data
  36. !! I am trying to shift to the unformatted approach since it
  37. !! 1. takes up less space
  38. !! 2. Doesn't introduce more numerical errors
  39. outid = 51
  40. outid2 = 52
  41. open(unit=outid,file='data/wateridealfe.bin', form='unformatted')
  42. open(unit=outid2,file='data/wateridealfe.dat')
  43. do i=1,NRho
  44. do j=1,NT
  45. logRho = logRhoLow + (i-1) * dlogRho
  46. logT = logTLow + (j-1) * dlogT
  47. logRhovect(i) = logRho
  48. logTvect(j) = logT
  49. Rho = 10.d0**logRho
  50. T = 10.d0**logT
  51. lnRho = log(Rho)
  52. lnT = log(T)
  53. call get_IG_EOS(lnRho, lnT, f_val, df_drho, df_dt, &
  54. d2f_drho2, d2f_dt2, d2f_drhodt, &
  55. d3f_drho3, d3f_drho2dt, d3f_drhodt2, d3f_dt3, &
  56. d4f_drho2dt2)
  57. Fvect(a_val) = f_val
  58. Fvect(a_dRho) = df_drho
  59. Fvect(a_dT) = df_dt
  60. Fvect(a_dRho2) = d2f_drho2
  61. Fvect(a_dT2) = d2f_dt2
  62. Fvect(a_dRhodT) = d2f_drhodt
  63. Fvect(a_dRho2dT) = d3f_drho2dt
  64. Fvect(a_dRhodT2) = d3f_drhodt2
  65. Fvect(a_dRho2dT2) = d4f_drho2dt2
  66. write(outid) lnRho, lnT, Fvect
  67. write(outid2,*) lnRho, lnT, Fvect
  68. Fr(i,j) = Fvect(a_val)
  69. dfdrho(i,j) = Fvect(a_dRho)
  70. dfdt(i,j) = Fvect(a_dT)
  71. d2fdrho2(i,j) = Fvect(a_dRho2)
  72. d2fdt2(i,j) = Fvect(a_dT2)
  73. d2fdrhodt(i,j) = Fvect(a_dRhodT)
  74. d3fdrho2dt(i,j) = Fvect(a_dRho2dT)
  75. d3fdrhodt2(i,j) = Fvect(a_dRhodT2)
  76. d4fdrho2dt2(i,j) = Fvect(a_dRho2dT2)
  77. enddo
  78. enddo
  79. filename = "h5tdata/fr_logRhovect.data"
  80. open(unit=19,file=trim(filename),status='replace', &
  81. iostat=ios,action='write',form='formatted')
  82. write(19,'(e20.6)') logRhovect
  83. close(unit=19)
  84. filename = "h5tdata/fr_logTvect.data"
  85. open(unit=19,file=trim(filename),status='replace', &
  86. iostat=ios,action='write',form='formatted')
  87. write(19,'(e20.6)') logTvect
  88. close(unit=19)
  89. filename = "h5tdata/fr.data"
  90. call write_matrix(Fr, filename)
  91. filename = "h5tdata/dfdrho.data"
  92. call write_matrix(dfdrho, filename)
  93. filename = "h5tdata/dfdt.data"
  94. call write_matrix(dfdt, filename)
  95. filename = "h5tdata/d2fdrho2.data"
  96. call write_matrix(d2fdrho2, filename)
  97. filename = "h5tdata/d2fdt2.data"
  98. call write_matrix(d2fdt2, filename)
  99. filename = "h5tdata/d2fdRhodT.data"
  100. call write_matrix(d2fdrhodt, filename)
  101. filename = "h5tdata/d3fdRho2dT.data"
  102. call write_matrix(d3fdrho2dt, filename)
  103. filename = "h5tdata/d3fdRhodT2.data"
  104. call write_matrix(d3fdrhodt2, filename)
  105. filename = "h5tdata/d4fdRho2dT2.data"
  106. call write_matrix(d4fdrho2dt2, filename)
  107. close(unit=outid)
  108. close(unit=outid2)
  109. deallocate(Fr)
  110. deallocate(dfdrho)
  111. deallocate(dfdt)
  112. deallocate(d2fdrho2)
  113. deallocate(d2fdt2)
  114. deallocate(d2fdrhodt)
  115. deallocate(d3fdrho2dt)
  116. deallocate(d3fdrhodt2)
  117. deallocate(d4fdrho2dt2)
  118. deallocate(logRhovect)
  119. deallocate(logTvect)
  120. contains
  121. subroutine write_matrix(matrix, filename)
  122. double precision, intent(in), dimension(:,:), pointer :: matrix
  123. character (len=256) :: filename
  124. open(unit=19,file=trim(filename),status='replace', &
  125. iostat=ios,action='write',form='formatted')
  126. write(19,'(e20.6)') matrix
  127. close(unit=19)
  128. end subroutine write_matrix
  129. end program generate_water_table