barakuda_thermo.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. # Misc :
  2. import sys
  3. import numpy as nmp
  4. import math
  5. rt0 = 273.16
  6. grav = 9.8 # gravity
  7. Rgas = 287.04
  8. Patm = 101000.
  9. ctv = 0.608 # for virtual temperature
  10. eps = 0.62197 # humidity constant
  11. cte = 0.622
  12. kappa = 0.4 # Von Karman's constant
  13. Cp = 1000.5
  14. Pi = 3.141592654
  15. eps_w = 0.987 # emissivity of water
  16. sigma = 5.67E-8 # Stefan Boltzman constamt
  17. alfa = 0.066 # Surface albedo over ocean
  18. sensit = 0.1
  19. def Lvap(zsst):
  20. #
  21. # INPUT : zsst => water temperature in [K]
  22. # OUTPUT : Lvap => Latent Heat of Vaporization [J/Kg]
  23. return ( 2.501 - 0.00237*(zsst - rt0) )*1.E6
  24. def e_sat(rt):
  25. # vapour pressure at saturation [Pa]
  26. # rt ! temperature (K)
  27. zrtrt0 = rt/rt0
  28. return 100*( nmp.power(10.,(10.79574*(1. - rt0/rt) - 5.028*nmp.log10(zrtrt0)
  29. + 1.50475*0.0001*(1. - nmp.power(10.,(-8.2969*(zrtrt0 - 1.))) )
  30. + 0.42873*0.001 *(nmp.power(10.,(4.76955*(1. - rt0/rt))) - 1.) + 0.78614 ) ) )
  31. def e_air(q_air, zslp):
  32. #
  33. #--------------------------------------------------------------------
  34. # **** Function e_air ****
  35. #
  36. # Gives vapour pressure of air from pressure and specific humidity
  37. #
  38. #--------------------------------------------------------------------
  39. #
  40. diff = 1.E8
  41. e_old = q_air*zslp/eps
  42. while diff > 1.:
  43. #print "Again... diff = ", diff
  44. ee = q_air/eps*(zslp - (1. - eps)*e_old)
  45. diff = nmp.sum(abs( ee - e_old ))
  46. e_old = ee
  47. return ee
  48. #def rh_air(q_air, t_air, zslp)
  49. # #
  50. # REAL :: rh_air #: relative humidity [%]
  51. # REAL, INTENT(in) :: &
  52. # & q_air, & #: specific humidity of air [kg/kg]
  53. # & t_air, & #: air temperature [K]
  54. # & zslp #: atmospheric pressure [Pa]
  55. # #
  56. # REAL :: ea, es
  57. # #
  58. # #
  59. # ea = e_air(q_air, zslp)
  60. # es = e_sat(t_air)
  61. # #
  62. # rh_air = ea/es
  63. # #
  64. # END FUNCTION rh_air
  65. #def q_air_rh(rha, ta, zslp)
  66. # # Specific humidity from RH
  67. # REAL, DIMENSION(ni,nj) :: q_air_rh
  68. # INTEGER, INTENT(in) :: ni, nj
  69. #
  70. # REAL, DIMENSION(ni,nj), INTENT(in) :: &
  71. # & rha, & !: relative humidity [fraction, not %#!]
  72. # & ta, & !: air temperature [K]
  73. # & zslp !: atmospheric pressure [Pa]
  74. #
  75. # REAL, DIMENSION(ni,nj) :: ea
  76. #
  77. # ea = rha*e_sat(ni,nj, ta)
  78. ##
  79. # q_air_rh = ea*eps/(zslp - (1. - eps)*ea)
  80. # END FUNCTION q_air_rh
  81. #def q_air_dp(da, zslp)
  82. #
  83. # Air specific humidity from dew point temperature
  84. #
  85. # INTEGER, INTENT(in) :: ni, nj
  86. # REAL, DIMENSION(ni,nj) :: q_air_dp !: kg/kg
  87. #
  88. # REAL, DIMENSION(ni,nj), INTENT(in) :: &
  89. # & da, & !: dew-point temperature [K]
  90. # & zslp !: atmospheric pressure [Pa]
  91. #
  92. # q_air_dp = e_sat(da)*eps/(zslp - (1. - eps)*e_sat(da))
  93. #
  94. #
  95. #
  96. #
  97. # Humidity :
  98. # ----------
  99. # - ea is the water vapour pressure (h.Pa)
  100. # - qa is the specific hymidity (g/kg)
  101. # rqa = rqa/1000. ! puts specific humidity in kg/kg instead of g/kg
  102. # rea = (rqa*rpa)/(0.378*rqa + cte)
  103. #
  104. # Virtual temperature :
  105. #
  106. #
  107. # Tv = T*(1 + 0.608*q)
  108. #
  109. # eps = 0.622 --> 0.608 = (1 - eps) / eps
  110. #
  111. def rho_air(zt, zq, zP):
  112. #
  113. #INTEGER, INTENT(in) :: ni, nj
  114. #REAL, DIMENSION(ni,nj) :: rho_air !: density of air [kg/m^3]
  115. #REAL, DIMENSION(ni,nj), INTENT(in) :: &
  116. # & zt, & !: air temperature in (K)
  117. # & zq, & !: air spec. hum. (kg/kg)
  118. # & zP !: pressure in (Pa)
  119. #
  120. rho_air = zP/(Rgas*zt*(1. + ctv*zq))
  121. return rho_air
  122. def q_sat(zsst, zslp):
  123. #
  124. #REAL, DIMENSION(ni,nj) :: q_sat
  125. #INTEGER, INTENT(in) :: ni, nj
  126. #REAL, DIMENSION(ni,nj), INTENT(in) :: &
  127. # & zsst, & !: sea surface temperature [K]
  128. # & zslp !: sea level atmospheric pressure [Pa]
  129. #
  130. #
  131. # Local :
  132. # -------
  133. #REAL, DIMENSION(ni,nj) :: &
  134. # & e_s
  135. #
  136. #
  137. #
  138. # Specific humidity at saturation
  139. # -------------------------------
  140. #
  141. # Vapour pressure at saturation :
  142. e_s = 100*(10.^(10.79574*(1-rt0/zsst)-5.028*math.log10(zsst/rt0) \
  143. + 1.50475*10.^(-4)*(1 - 10.^(-8.2969*(zsst/rt0 - 1)) ) \
  144. + 0.42873*10.^(-3)*(10.^(4.76955*(1 - rt0/zsst)) - 1) + 0.78614) )
  145. #
  146. return eps*e_s/(zslp - (1. - eps)*e_s)
  147. #def e_sat_ice(ni,nj, zrt)
  148. #
  149. # INTEGER, INTENT(in) :: ni, nj
  150. # REAL, DIMENSION(ni,nj) :: e_sat_ice !: vapour pressure at saturation in presence of ice [Pa]
  151. # REAL, DIMENSION(ni,nj), INTENT(in) :: zrt
  152. # #
  153. # e_sat_ice = 100.*(10.^( -9.09718*(273.16/zrt - 1.) - 3.56654*math.log10(273.16/zrt) &
  154. # & + 0.876793*(1. - zrt/273.16) + math.log10(6.1071) ) )
  155. # #
  156. #def q_sat_simple(zsst)
  157. # REAL, DIMENSION(ni,nj) :: q_sat_simple
  158. # INTEGER, INTENT(in) :: ni, nj
  159. # REAL, DIMENSION(ni,nj), INTENT(in) :: &
  160. # & zsst !: sea surface temperature [K]
  161. #
  162. # q_sat_simple = 640380./1.22 * exp(-5107.4/zsst)
  163. #
  164. #def q_sat_simple_with_rho(zsst, zslp)
  165. # REAL, DIMENSION(ni,nj) :: q_sat_simple_with_rho
  166. # INTEGER, INTENT(in) :: ni, nj
  167. # REAL, DIMENSION(ni,nj), INTENT(in) :: &
  168. # & zsst, & !: sea surface temperature [K]
  169. # & zslp !: sea level atmospheric pressure [Pa]
  170. # REAL, DIMENSION(ni,nj) :: ztmp, ztmp2
  171. # ! we need to know specific humidity to get a good estimate of density:
  172. # ztmp2 = 0.99 ! RH! air is saturated #!
  173. # ztmp = 0.98 * q_air_rh(ztmp2, zsst, zslp)
  174. #
  175. # ztmp2 = 0.0
  176. #
  177. # ztmp2 = rho_air(zsst, ztmp, zslp) ! rho_air
  178. #
  179. # q_sat_simple_with_rho = 640380./ztmp2 * exp(-5107.4/zsst)
  180. #def e_sat(rt):
  181. # # Vapour pressure at saturation for a given temperature [Pa]
  182. # #
  183. # # * rt ! temperature (K)
  184. # #
  185. # rt0 = 273.16
  186. # #
  187. # e_sat = 100*( 10**(10.79574*(1 - rt0/rt) - 5.028*log10(rt/rt0)
  188. # + 1.50475*10**(-4)*(1 - 10**(-8.2969*(rt/rt0 - 1)) )
  189. # + 0.42873*10**(-3)*(10**(4.76955*(1 - rt0/rt)) - 1) + 0.78614) )
  190. # return e_sat
  191. def qa_e_p(res, rp):
  192. # Specific humidity from pressure and vapour pressure at saturation
  193. #
  194. # * res : vapour pressure at saturation [Pa]
  195. # * rp : atmospheric pressure [Pa]
  196. #
  197. reps = 0.62197
  198. #
  199. qa_e_p = reps*res / ( rp - (1. - reps)*res )
  200. #
  201. return qa_e_p