PageRenderTime 81ms CodeModel.GetById 40ms RepoModel.GetById 0ms app.codeStats 1ms

/wrfv2_fire/phys/module_mp_wsm3.F

http://github.com/jbeezley/wrf-fire
FORTRAN Legacy | 1420 lines | 1023 code | 1 blank | 396 comment | 74 complexity | 0129a2020876822b6ce3d11a8e777a7a MD5 | raw file
Possible License(s): AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  1. #ifdef _ACCEL
  2. # include "module_mp_wsm3_accel.F"
  3. #else
  4. #if ( RWORDSIZE == 4 )
  5. # define VREC vsrec
  6. # define VSQRT vssqrt
  7. #else
  8. # define VREC vrec
  9. # define VSQRT vsqrt
  10. #endif
  11. MODULE module_mp_wsm3
  12. !
  13. !
  14. REAL, PARAMETER, PRIVATE :: dtcldcr = 120. ! maximum time step for minor loops
  15. REAL, PARAMETER, PRIVATE :: n0r = 8.e6 ! intercept parameter rain
  16. REAL, PARAMETER, PRIVATE :: avtr = 841.9 ! a constant for terminal velocity of rain
  17. REAL, PARAMETER, PRIVATE :: bvtr = 0.8 ! a constant for terminal velocity of rain
  18. REAL, PARAMETER, PRIVATE :: r0 = .8e-5 ! 8 microm in contrast to 10 micro m
  19. REAL, PARAMETER, PRIVATE :: peaut = .55 ! collection efficiency
  20. REAL, PARAMETER, PRIVATE :: xncr = 3.e8 ! maritime cloud in contrast to 3.e8 in tc80
  21. REAL, PARAMETER, PRIVATE :: xmyu = 1.718e-5 ! the dynamic viscosity kgm-1s-1
  22. REAL, PARAMETER, PRIVATE :: avts = 11.72 ! a constant for terminal velocity of snow
  23. REAL, PARAMETER, PRIVATE :: bvts = .41 ! a constant for terminal velocity of snow
  24. REAL, PARAMETER, PRIVATE :: n0smax = 1.e11 ! maximum n0s (t=-90C unlimited)
  25. REAL, PARAMETER, PRIVATE :: lamdarmax = 8.e4 ! limited maximum value for slope parameter of rain
  26. REAL, PARAMETER, PRIVATE :: lamdasmax = 1.e5 ! limited maximum value for slope parameter of snow
  27. REAL, PARAMETER, PRIVATE :: lamdagmax = 6.e4 ! limited maximum value for slope parameter of graupel
  28. REAL, PARAMETER, PRIVATE :: dicon = 11.9 ! constant for the cloud-ice diamter
  29. REAL, PARAMETER, PRIVATE :: dimax = 500.e-6 ! limited maximum value for the cloud-ice diamter
  30. REAL, PARAMETER, PRIVATE :: n0s = 2.e6 ! temperature dependent intercept parameter snow
  31. REAL, PARAMETER, PRIVATE :: alpha = .12 ! .122 exponen factor for n0s
  32. REAL, PARAMETER, PRIVATE :: qcrmin = 1.e-9 ! minimun values for qr, qs, and qg
  33. REAL, SAVE :: &
  34. qc0, qck1,bvtr1,bvtr2,bvtr3,bvtr4,g1pbr, &
  35. g3pbr,g4pbr,g5pbro2,pvtr,eacrr,pacrr, &
  36. precr1,precr2,xmmax,roqimax,bvts1, &
  37. bvts2,bvts3,bvts4,g1pbs,g3pbs,g4pbs, &
  38. g5pbso2,pvts,pacrs,precs1,precs2,pidn0r, &
  39. pidn0s,xlv1,pi, &
  40. rslopermax,rslopesmax,rslopegmax, &
  41. rsloperbmax,rslopesbmax,rslopegbmax, &
  42. rsloper2max,rslopes2max,rslopeg2max, &
  43. rsloper3max,rslopes3max,rslopeg3max
  44. !
  45. ! Specifies code-inlining of fpvs function in WSM32D below. JM 20040507
  46. !
  47. CONTAINS
  48. !===================================================================
  49. !
  50. SUBROUTINE wsm3(th, q, qci, qrs &
  51. , w, den, pii, p, delz &
  52. , delt,g, cpd, cpv, rd, rv, t0c &
  53. , ep1, ep2, qmin &
  54. , XLS, XLV0, XLF0, den0, denr &
  55. , cliq,cice,psat &
  56. , rain, rainncv &
  57. , snow, snowncv &
  58. , sr &
  59. , ids,ide, jds,jde, kds,kde &
  60. , ims,ime, jms,jme, kms,kme &
  61. , its,ite, jts,jte, kts,kte &
  62. )
  63. !-------------------------------------------------------------------
  64. IMPLICIT NONE
  65. !-------------------------------------------------------------------
  66. !
  67. INTEGER, INTENT(IN ) :: ids,ide, jds,jde, kds,kde , &
  68. ims,ime, jms,jme, kms,kme , &
  69. its,ite, jts,jte, kts,kte
  70. REAL, DIMENSION( ims:ime , kms:kme , jms:jme ), &
  71. INTENT(INOUT) :: &
  72. th, &
  73. q, &
  74. qci, &
  75. qrs
  76. REAL, DIMENSION( ims:ime , kms:kme , jms:jme ), &
  77. INTENT(IN ) :: w, &
  78. den, &
  79. pii, &
  80. p, &
  81. delz
  82. REAL, INTENT(IN ) :: delt, &
  83. g, &
  84. rd, &
  85. rv, &
  86. t0c, &
  87. den0, &
  88. cpd, &
  89. cpv, &
  90. ep1, &
  91. ep2, &
  92. qmin, &
  93. XLS, &
  94. XLV0, &
  95. XLF0, &
  96. cliq, &
  97. cice, &
  98. psat, &
  99. denr
  100. REAL, DIMENSION( ims:ime , jms:jme ), &
  101. INTENT(INOUT) :: rain, &
  102. rainncv
  103. REAL, DIMENSION( ims:ime , jms:jme ), OPTIONAL, &
  104. INTENT(INOUT) :: snow, &
  105. snowncv, &
  106. sr
  107. ! LOCAL VAR
  108. REAL, DIMENSION( its:ite , kts:kte ) :: t
  109. INTEGER :: i,j,k
  110. !-------------------------------------------------------------------
  111. DO j=jts,jte
  112. DO k=kts,kte
  113. DO i=its,ite
  114. t(i,k)=th(i,k,j)*pii(i,k,j)
  115. ENDDO
  116. ENDDO
  117. CALL wsm32D(t, q(ims,kms,j), qci(ims,kms,j) &
  118. ,qrs(ims,kms,j),w(ims,kms,j), den(ims,kms,j) &
  119. ,p(ims,kms,j), delz(ims,kms,j) &
  120. ,delt,g, cpd, cpv, rd, rv, t0c &
  121. ,ep1, ep2, qmin &
  122. ,XLS, XLV0, XLF0, den0, denr &
  123. ,cliq,cice,psat &
  124. ,j &
  125. ,rain(ims,j), rainncv(ims,j) &
  126. ,snow(ims,j),snowncv(ims,j) &
  127. ,sr(ims,j) &
  128. ,ids,ide, jds,jde, kds,kde &
  129. ,ims,ime, jms,jme, kms,kme &
  130. ,its,ite, jts,jte, kts,kte &
  131. )
  132. DO K=kts,kte
  133. DO I=its,ite
  134. th(i,k,j)=t(i,k)/pii(i,k,j)
  135. ENDDO
  136. ENDDO
  137. ENDDO
  138. END SUBROUTINE wsm3
  139. !===================================================================
  140. !
  141. SUBROUTINE wsm32D(t, q &
  142. ,qci, qrs,w, den, p, delz &
  143. ,delt,g, cpd, cpv, rd, rv, t0c &
  144. ,ep1, ep2, qmin &
  145. ,XLS, XLV0, XLF0, den0, denr &
  146. ,cliq,cice,psat &
  147. ,lat &
  148. ,rain, rainncv &
  149. ,snow,snowncv &
  150. ,sr &
  151. ,ids,ide, jds,jde, kds,kde &
  152. ,ims,ime, jms,jme, kms,kme &
  153. ,its,ite, jts,jte, kts,kte &
  154. )
  155. !-------------------------------------------------------------------
  156. IMPLICIT NONE
  157. !-------------------------------------------------------------------
  158. !
  159. ! This code is a 3-class simple ice microphyiscs scheme (WSM3) of the
  160. ! Single-Moment MicroPhyiscs (WSMMP). The WSMMP assumes that ice nuclei
  161. ! number concentration is a function of temperature, and seperate assumption
  162. ! is developed, in which ice crystal number concentration is a function
  163. ! of ice amount. A theoretical background of the ice-microphysics and related
  164. ! processes in the WSMMPs are described in Hong et al. (2004).
  165. ! Production terms in the WSM6 scheme are described in Hong and Lim (2006).
  166. ! All units are in m.k.s. and source/sink terms in kgkg-1s-1.
  167. !
  168. ! WSM3 cloud scheme
  169. !
  170. ! Developed by Song-You Hong (Yonsei Univ.), Jimy Dudhia (NCAR)
  171. ! and Shu-Hua Chen (UC Davis)
  172. ! Summer 2002
  173. !
  174. ! Implemented by Song-You Hong (Yonsei Univ.) and Jimy Dudhia (NCAR)
  175. ! Summer 2003
  176. !
  177. ! History : semi-lagrangian scheme sedimentation(JH), and clean up
  178. ! Hong, August 2009
  179. !
  180. ! Reference) Hong, Dudhia, Chen (HDC, 2004) Mon. Wea. Rev.
  181. ! Dudhia (D89, 1989) J. Atmos. Sci.
  182. ! Hong and Lim (HL, 2006) J. Korean Meteor. Soc.
  183. ! Juang and Hong (JH, 2010) Mon. Wea. Rev.
  184. !
  185. INTEGER, INTENT(IN ) :: ids,ide, jds,jde, kds,kde, &
  186. ims,ime, jms,jme, kms,kme, &
  187. its,ite, jts,jte, kts,kte, &
  188. lat
  189. REAL, DIMENSION( its:ite , kts:kte ), &
  190. INTENT(INOUT) :: &
  191. t
  192. REAL, DIMENSION( ims:ime , kms:kme ), &
  193. INTENT(INOUT) :: &
  194. q, &
  195. qci, &
  196. qrs
  197. REAL, DIMENSION( ims:ime , kms:kme ), &
  198. INTENT(IN ) :: w, &
  199. den, &
  200. p, &
  201. delz
  202. REAL, INTENT(IN ) :: delt, &
  203. g, &
  204. cpd, &
  205. cpv, &
  206. t0c, &
  207. den0, &
  208. rd, &
  209. rv, &
  210. ep1, &
  211. ep2, &
  212. qmin, &
  213. XLS, &
  214. XLV0, &
  215. XLF0, &
  216. cliq, &
  217. cice, &
  218. psat, &
  219. denr
  220. REAL, DIMENSION( ims:ime ), &
  221. INTENT(INOUT) :: rain, &
  222. rainncv
  223. REAL, DIMENSION( ims:ime ), OPTIONAL, &
  224. INTENT(INOUT) :: snow, &
  225. snowncv, &
  226. sr
  227. ! LOCAL VAR
  228. REAL, DIMENSION( its:ite , kts:kte ) :: &
  229. rh, &
  230. qs, &
  231. denfac, &
  232. rslope, &
  233. rslope2, &
  234. rslope3, &
  235. qrs_tmp, &
  236. den_tmp, &
  237. delz_tmp, &
  238. rslopeb
  239. REAL, DIMENSION( its:ite , kts:kte ) :: &
  240. pgen, &
  241. pisd, &
  242. paut, &
  243. pacr, &
  244. pres, &
  245. pcon
  246. REAL, DIMENSION( its:ite , kts:kte ) :: &
  247. fall, &
  248. falk, &
  249. xl, &
  250. cpm, &
  251. work1, &
  252. work2, &
  253. xni, &
  254. qs0, &
  255. denqci, &
  256. denqrs, &
  257. n0sfac, &
  258. falkc, &
  259. work1c, &
  260. work2c, &
  261. fallc
  262. REAL, DIMENSION( its:ite ) :: delqrs,&
  263. delqi
  264. REAL, DIMENSION(its:ite) :: tstepsnow
  265. INTEGER, DIMENSION( its:ite ) :: kwork1,&
  266. kwork2
  267. INTEGER, DIMENSION( its:ite ) :: mstep, &
  268. numdt
  269. LOGICAL, DIMENSION( its:ite ) :: flgcld
  270. REAL :: &
  271. cpmcal, xlcal, diffus, &
  272. viscos, xka, venfac, conden, diffac, &
  273. x, y, z, a, b, c, d, e, &
  274. fallsum, fallsum_qsi, vt2i,vt2s,acrfac, &
  275. qdt, pvt, qik, delq, facq, qrsci, frzmlt, &
  276. snomlt, hold, holdrs, facqci, supcol, coeres, &
  277. supsat, dtcld, xmi, qciik, delqci, eacrs, satdt, &
  278. qimax, diameter, xni0, roqi0, supice,holdc, holdci
  279. INTEGER :: i, j, k, mstepmax, &
  280. iprt, latd, lond, loop, loops, ifsat, kk, n, idim, kdim
  281. ! Temporaries used for inlining fpvs function
  282. REAL :: dldti, xb, xai, tr, xbi, xa, hvap, cvap, hsub, dldt, ttp
  283. ! variables for optimization
  284. REAL, DIMENSION( its:ite ) :: tvec1
  285. !
  286. !=================================================================
  287. ! compute internal functions
  288. !
  289. cpmcal(x) = cpd*(1.-max(x,qmin))+max(x,qmin)*cpv
  290. xlcal(x) = xlv0-xlv1*(x-t0c)
  291. !----------------------------------------------------------------
  292. ! diffus: diffusion coefficient of the water vapor
  293. ! viscos: kinematic viscosity(m2s-1)
  294. ! Optimizatin : A**B => exp(log(A)*(B))
  295. !
  296. diffus(x,y) = 8.794e-5 * exp(log(x)*(1.81)) / y ! 8.794e-5*x**1.81/y
  297. viscos(x,y) = 1.496e-6 * (x*sqrt(x)) /(x+120.)/y ! 1.496e-6*x**1.5/(x+120.)/y
  298. xka(x,y) = 1.414e3*viscos(x,y)*y
  299. diffac(a,b,c,d,e) = d*a*a/(xka(c,d)*rv*c*c)+1./(e*diffus(c,b))
  300. venfac(a,b,c) = exp(log((viscos(b,c)/diffus(b,a)))*((.3333333))) &
  301. /sqrt(viscos(b,c))*sqrt(sqrt(den0/c))
  302. conden(a,b,c,d,e) = (max(b,qmin)-c)/(1.+d*d/(rv*e)*c/(a*a))
  303. !
  304. idim = ite-its+1
  305. kdim = kte-kts+1
  306. !
  307. !----------------------------------------------------------------
  308. ! paddint 0 for negative values generated by dynamics
  309. !
  310. do k = kts, kte
  311. do i = its, ite
  312. qci(i,k) = max(qci(i,k),0.0)
  313. qrs(i,k) = max(qrs(i,k),0.0)
  314. enddo
  315. enddo
  316. !
  317. !----------------------------------------------------------------
  318. ! latent heat for phase changes and heat capacity. neglect the
  319. ! changes during microphysical process calculation
  320. ! emanuel(1994)
  321. !
  322. do k = kts, kte
  323. do i = its, ite
  324. cpm(i,k) = cpmcal(q(i,k))
  325. xl(i,k) = xlcal(t(i,k))
  326. enddo
  327. enddo
  328. do k = kts, kte
  329. do i = its, ite
  330. delz_tmp(i,k) = delz(i,k)
  331. den_tmp(i,k) = den(i,k)
  332. enddo
  333. enddo
  334. !
  335. !----------------------------------------------------------------
  336. ! initialize the surface rain, snow
  337. !
  338. do i = its, ite
  339. rainncv(i) = 0.
  340. if(PRESENT (snowncv) .AND. PRESENT (snow)) snowncv(i) = 0.
  341. sr(i) = 0.
  342. ! new local array to catch step snow
  343. tstepsnow(i) = 0.
  344. enddo
  345. !
  346. !----------------------------------------------------------------
  347. ! compute the minor time steps.
  348. !
  349. loops = max(nint(delt/dtcldcr),1)
  350. dtcld = delt/loops
  351. if(delt.le.dtcldcr) dtcld = delt
  352. !
  353. do loop = 1,loops
  354. !
  355. !----------------------------------------------------------------
  356. ! initialize the large scale variables
  357. !
  358. do i = its, ite
  359. flgcld(i) = .true.
  360. enddo
  361. !
  362. do k = kts, kte
  363. CALL VREC( tvec1(its), den(its,k), ite-its+1)
  364. do i = its, ite
  365. tvec1(i) = tvec1(i)*den0
  366. enddo
  367. CALL VSQRT( denfac(its,k), tvec1(its), ite-its+1)
  368. enddo
  369. !
  370. ! Inline expansion for fpvs
  371. ! qs(i,k) = fpvs(t(i,k),1,rd,rv,cpv,cliq,cice,xlv0,xls,psat,t0c)
  372. ! qs0(i,k) = fpvs(t(i,k),0,rd,rv,cpv,cliq,cice,xlv0,xls,psat,t0c)
  373. cvap = cpv
  374. hvap=xlv0
  375. hsub=xls
  376. ttp=t0c+0.01
  377. dldt=cvap-cliq
  378. xa=-dldt/rv
  379. xb=xa+hvap/(rv*ttp)
  380. dldti=cvap-cice
  381. xai=-dldti/rv
  382. xbi=xai+hsub/(rv*ttp)
  383. do k = kts, kte
  384. do i = its, ite
  385. tr=ttp/t(i,k)
  386. if(t(i,k).lt.ttp) then
  387. qs(i,k) =psat*(exp(log(tr)*(xai)))*exp(xbi*(1.-tr))
  388. else
  389. qs(i,k) =psat*(exp(log(tr)*(xa)))*exp(xb*(1.-tr))
  390. endif
  391. qs0(i,k) =psat*(exp(log(tr)*(xa)))*exp(xb*(1.-tr))
  392. qs0(i,k) = (qs0(i,k)-qs(i,k))/qs(i,k)
  393. qs(i,k) = min(qs(i,k),0.99*p(i,k))
  394. qs(i,k) = ep2 * qs(i,k) / (p(i,k) - qs(i,k))
  395. qs(i,k) = max(qs(i,k),qmin)
  396. rh(i,k) = max(q(i,k) / qs(i,k),qmin)
  397. enddo
  398. enddo
  399. !
  400. !----------------------------------------------------------------
  401. ! initialize the variables for microphysical physics
  402. !
  403. !
  404. do k = kts, kte
  405. do i = its, ite
  406. pres(i,k) = 0.
  407. paut(i,k) = 0.
  408. pacr(i,k) = 0.
  409. pgen(i,k) = 0.
  410. pisd(i,k) = 0.
  411. pcon(i,k) = 0.
  412. fall(i,k) = 0.
  413. falk(i,k) = 0.
  414. fallc(i,k) = 0.
  415. falkc(i,k) = 0.
  416. xni(i,k) = 1.e3
  417. enddo
  418. enddo
  419. !-------------------------------------------------------------
  420. ! Ni: ice crystal number concentraiton [HDC 5c]
  421. !-------------------------------------------------------------
  422. do k = kts, kte
  423. do i = its, ite
  424. xni(i,k) = min(max(5.38e7 &
  425. *exp(log((den(i,k)*max(qci(i,k),qmin)))*(0.75)),1.e3),1.e6)
  426. enddo
  427. enddo
  428. !
  429. !----------------------------------------------------------------
  430. ! compute the fallout term:
  431. ! first, vertical terminal velosity for minor loops
  432. !---------------------------------------------------------------
  433. do k = kts, kte
  434. do i = its, ite
  435. qrs_tmp(i,k) = qrs(i,k)
  436. enddo
  437. enddo
  438. call slope_wsm3(qrs_tmp,den_tmp,denfac,t,rslope,rslopeb,rslope2,rslope3, &
  439. work1,its,ite,kts,kte)
  440. !
  441. !
  442. ! forward semi-laglangian scheme (JH), PCM (piecewise constant), (linear)
  443. !
  444. do k = kte, kts, -1
  445. do i = its, ite
  446. denqrs(i,k) = den(i,k)*qrs(i,k)
  447. enddo
  448. enddo
  449. call nislfv_rain_plm(idim,kdim,den_tmp,denfac,t,delz_tmp,work1,denqrs, &
  450. delqrs,dtcld,1,1)
  451. do k = kts, kte
  452. do i = its, ite
  453. qrs(i,k) = max(denqrs(i,k)/den(i,k),0.)
  454. fall(i,k) = denqrs(i,k)*work1(i,k)/delz(i,k)
  455. enddo
  456. enddo
  457. do i = its, ite
  458. fall(i,1) = delqrs(i)/delz(i,1)/dtcld
  459. enddo
  460. !---------------------------------------------------------------
  461. ! Vice [ms-1] : fallout of ice crystal [HDC 5a]
  462. !---------------------------------------------------------------
  463. do k = kte, kts, -1
  464. do i = its, ite
  465. if(t(i,k).lt.t0c.and.qci(i,k).gt.0.) then
  466. xmi = den(i,k)*qci(i,k)/xni(i,k)
  467. diameter = max(dicon * sqrt(xmi), 1.e-25)
  468. work1c(i,k) = 1.49e4*exp(log(diameter)*(1.31))
  469. else
  470. work1c(i,k) = 0.
  471. endif
  472. enddo
  473. enddo
  474. !
  475. ! forward semi-laglangian scheme (JH), PCM (piecewise constant), (linear)
  476. !
  477. do k = kte, kts, -1
  478. do i = its, ite
  479. denqci(i,k) = den(i,k)*qci(i,k)
  480. enddo
  481. enddo
  482. call nislfv_rain_plm(idim,kdim,den_tmp,denfac,t,delz_tmp,work1c,denqci, &
  483. delqi,dtcld,1,0)
  484. do k = kts, kte
  485. do i = its, ite
  486. qci(i,k) = max(denqci(i,k)/den(i,k),0.)
  487. enddo
  488. enddo
  489. do i = its, ite
  490. fallc(i,1) = delqi(i)/delz(i,1)/dtcld
  491. enddo
  492. !
  493. !----------------------------------------------------------------
  494. ! compute the freezing/melting term. [D89 B16-B17]
  495. ! freezing occurs one layer above the melting level
  496. !
  497. do i = its, ite
  498. mstep(i) = 0
  499. enddo
  500. do k = kts, kte
  501. !
  502. do i = its, ite
  503. if(t(i,k).ge.t0c) then
  504. mstep(i) = k
  505. endif
  506. enddo
  507. enddo
  508. !
  509. do i = its, ite
  510. kwork2(i) = mstep(i)
  511. kwork1(i) = mstep(i)
  512. if(mstep(i).ne.0) then
  513. if (w(i,mstep(i)).gt.0.) then
  514. kwork1(i) = mstep(i) + 1
  515. endif
  516. endif
  517. enddo
  518. !
  519. do i = its, ite
  520. k = kwork1(i)
  521. kk = kwork2(i)
  522. if(k*kk.ge.1) then
  523. qrsci = qrs(i,k) + qci(i,k)
  524. if(qrsci.gt.0..or.fall(i,kk).gt.0.) then
  525. frzmlt = min(max(-w(i,k)*qrsci/delz(i,k),-qrsci/dtcld), &
  526. qrsci/dtcld)
  527. snomlt = min(max(fall(i,kk)/den(i,kk),-qrs(i,k)/dtcld), &
  528. qrs(i,k)/dtcld)
  529. if(k.eq.kk) then
  530. t(i,k) = t(i,k) - xlf0/cpm(i,k)*(frzmlt+snomlt)*dtcld
  531. else
  532. t(i,k) = t(i,k) - xlf0/cpm(i,k)*frzmlt*dtcld
  533. t(i,kk) = t(i,kk) - xlf0/cpm(i,kk)*snomlt*dtcld
  534. endif
  535. endif
  536. endif
  537. enddo
  538. !
  539. !----------------------------------------------------------------
  540. ! rain (unit is mm/sec;kgm-2s-1: /1000*delt ===> m)==> mm for wrf
  541. !
  542. do i = its, ite
  543. fallsum = fall(i,1)
  544. fallsum_qsi = 0.
  545. if((t0c-t(i,1)).gt.0) then
  546. fallsum = fallsum+fallc(i,1)
  547. fallsum_qsi = fall(i,1)+fallc(i,1)
  548. endif
  549. if(fallsum.gt.0.) then
  550. rainncv(i) = fallsum*delz(i,1)/denr*dtcld*1000. + rainncv(i)
  551. rain(i) = fallsum*delz(i,1)/denr*dtcld*1000. + rain(i)
  552. endif
  553. if(fallsum_qsi.gt.0.) then
  554. tstepsnow(i) = fallsum_qsi*delz(i,kts)/denr*dtcld*1000. &
  555. +tstepsnow(i)
  556. IF ( PRESENT (snowncv) .AND. PRESENT (snow)) THEN
  557. snowncv(i) = fallsum_qsi*delz(i,kts)/denr*dtcld*1000. + snowncv(i)
  558. snow(i) = fallsum_qsi*delz(i,kts)/denr*dtcld*1000. + snow(i)
  559. ENDIF
  560. endif
  561. ! if(fallsum.gt.0.) sr(i) = snowncv(i)/(rainncv(i)+1.e-12)
  562. if(fallsum.gt.0.) sr(i) = tstepsnow(i)/(rainncv(i)+1.e-12)
  563. enddo
  564. !
  565. !----------------------------------------------------------------
  566. ! update the slope parameters for microphysics computation
  567. !
  568. do k = kts, kte
  569. do i = its, ite
  570. qrs_tmp(i,k) = qrs(i,k)
  571. enddo
  572. enddo
  573. call slope_wsm3(qrs_tmp,den_tmp,denfac,t,rslope,rslopeb,rslope2,rslope3, &
  574. work1,its,ite,kts,kte)
  575. !
  576. ! work1: the thermodynamic term in the denominator associated with
  577. ! heat conduction and vapor diffusion
  578. ! work2: parameter associated with the ventilation effects(y93)
  579. !
  580. do k = kts, kte
  581. do i = its, ite
  582. if(t(i,k).ge.t0c) then
  583. work1(i,k) = diffac(xl(i,k),p(i,k),t(i,k),den(i,k),qs(i,k))
  584. else
  585. work1(i,k) = diffac(xls,p(i,k),t(i,k),den(i,k),qs(i,k))
  586. endif
  587. work2(i,k) = venfac(p(i,k),t(i,k),den(i,k))
  588. enddo
  589. enddo
  590. !
  591. do k = kts, kte
  592. do i = its, ite
  593. supsat = max(q(i,k),qmin)-qs(i,k)
  594. satdt = supsat/dtcld
  595. if(t(i,k).ge.t0c) then
  596. !
  597. !===============================================================
  598. !
  599. ! warm rain processes
  600. !
  601. ! - follows the processes in RH83 and LFO except for autoconcersion
  602. !
  603. !===============================================================
  604. !---------------------------------------------------------------
  605. ! praut: auto conversion rate from cloud to rain [HDC 16]
  606. ! (C->R)
  607. !---------------------------------------------------------------
  608. if(qci(i,k).gt.qc0) then
  609. ! paut(i,k) = qck1*qci(i,k)**(7./3.)
  610. paut(i,k) = qck1*exp(log(qci(i,k))*((7./3.)))
  611. paut(i,k) = min(paut(i,k),qci(i,k)/dtcld)
  612. endif
  613. !---------------------------------------------------------------
  614. ! pracw: accretion of cloud water by rain [HL A40] [D89 B15]
  615. ! (C->R)
  616. !---------------------------------------------------------------
  617. if(qrs(i,k).gt.qcrmin.and.qci(i,k).gt.qmin) then
  618. pacr(i,k) = min(pacrr*rslope3(i,k)*rslopeb(i,k) &
  619. *qci(i,k)*denfac(i,k),qci(i,k)/dtcld)
  620. endif
  621. !---------------------------------------------------------------
  622. ! prevp: evaporation/condensation rate of rain [HDC 14]
  623. ! (V->R or R->V)
  624. !---------------------------------------------------------------
  625. if(qrs(i,k).gt.0.) then
  626. coeres = rslope2(i,k)*sqrt(rslope(i,k)*rslopeb(i,k))
  627. pres(i,k) = (rh(i,k)-1.)*(precr1*rslope2(i,k) &
  628. +precr2*work2(i,k)*coeres)/work1(i,k)
  629. if(pres(i,k).lt.0.) then
  630. pres(i,k) = max(pres(i,k),-qrs(i,k)/dtcld)
  631. pres(i,k) = max(pres(i,k),satdt/2)
  632. else
  633. pres(i,k) = min(pres(i,k),satdt/2)
  634. endif
  635. endif
  636. else
  637. !
  638. !===============================================================
  639. !
  640. ! cold rain processes
  641. !
  642. ! - follows the revised ice microphysics processes in HDC
  643. ! - the processes same as in RH83 and LFO behave
  644. ! following ice crystal hapits defined in HDC, inclduing
  645. ! intercept parameter for snow (n0s), ice crystal number
  646. ! concentration (ni), ice nuclei number concentration
  647. ! (n0i), ice diameter (d)
  648. !
  649. !===============================================================
  650. !
  651. supcol = t0c-t(i,k)
  652. n0sfac(i,k) = max(min(exp(alpha*supcol),n0smax/n0s),1.)
  653. ifsat = 0
  654. !-------------------------------------------------------------
  655. ! Ni: ice crystal number concentraiton [HDC 5c]
  656. !-------------------------------------------------------------
  657. xni(i,k) = min(max(5.38e7 &
  658. *exp(log((den(i,k)*max(qci(i,k),qmin)))*(0.75)),1.e3),1.e6)
  659. eacrs = exp(0.07*(-supcol))
  660. if(qrs(i,k).gt.qcrmin.and.qci(i,k).gt.qmin) then
  661. xmi = den(i,k)*qci(i,k)/xni(i,k)
  662. diameter = min(dicon * sqrt(xmi),dimax)
  663. vt2i = 1.49e4*diameter**1.31
  664. vt2s = pvts*rslopeb(i,k)*denfac(i,k)
  665. !-------------------------------------------------------------
  666. ! praci: Accretion of cloud ice by rain [HL A15] [LFO 25]
  667. ! (T<T0: I->R)
  668. !-------------------------------------------------------------
  669. acrfac = 2.*rslope3(i,k)+2.*diameter*rslope2(i,k) &
  670. +diameter**2*rslope(i,k)
  671. pacr(i,k) = min(pi*qci(i,k)*eacrs*n0s*n0sfac(i,k) &
  672. *abs(vt2s-vt2i)*acrfac/4.,qci(i,k)/dtcld)
  673. endif
  674. !-------------------------------------------------------------
  675. ! pidep: Deposition/Sublimation rate of ice [HDC 9]
  676. ! (T<T0: V->I or I->V)
  677. !-------------------------------------------------------------
  678. if(qci(i,k).gt.0.) then
  679. xmi = den(i,k)*qci(i,k)/xni(i,k)
  680. diameter = dicon * sqrt(xmi)
  681. pisd(i,k) = 4.*diameter*xni(i,k)*(rh(i,k)-1.)/work1(i,k)
  682. if(pisd(i,k).lt.0.) then
  683. pisd(i,k) = max(pisd(i,k),satdt/2)
  684. pisd(i,k) = max(pisd(i,k),-qci(i,k)/dtcld)
  685. else
  686. pisd(i,k) = min(pisd(i,k),satdt/2)
  687. endif
  688. if(abs(pisd(i,k)).ge.abs(satdt)) ifsat = 1
  689. endif
  690. !-------------------------------------------------------------
  691. ! psdep: deposition/sublimation rate of snow [HDC 14]
  692. ! (V->S or S->V)
  693. !-------------------------------------------------------------
  694. if(qrs(i,k).gt.0..and.ifsat.ne.1) then
  695. coeres = rslope2(i,k)*sqrt(rslope(i,k)*rslopeb(i,k))
  696. pres(i,k) = (rh(i,k)-1.)*n0sfac(i,k)*(precs1*rslope2(i,k) &
  697. +precs2*work2(i,k)*coeres)/work1(i,k)
  698. supice = satdt-pisd(i,k)
  699. if(pres(i,k).lt.0.) then
  700. pres(i,k) = max(pres(i,k),-qrs(i,k)/dtcld)
  701. pres(i,k) = max(max(pres(i,k),satdt/2),supice)
  702. else
  703. pres(i,k) = min(min(pres(i,k),satdt/2),supice)
  704. endif
  705. if(abs(pisd(i,k)+pres(i,k)).ge.abs(satdt)) ifsat = 1
  706. endif
  707. !-------------------------------------------------------------
  708. ! pigen: generation(nucleation) of ice from vapor [HDC 7-8]
  709. ! (T<T0: V->I)
  710. !-------------------------------------------------------------
  711. if(supsat.gt.0.and.ifsat.ne.1) then
  712. supice = satdt-pisd(i,k)-pres(i,k)
  713. xni0 = 1.e3*exp(0.1*supcol)
  714. roqi0 = 4.92e-11*exp(log(xni0)*(1.33))
  715. pgen(i,k) = max(0.,(roqi0/den(i,k)-max(qci(i,k),0.))/dtcld)
  716. pgen(i,k) = min(min(pgen(i,k),satdt),supice)
  717. endif
  718. !-------------------------------------------------------------
  719. ! psaut: conversion(aggregation) of ice to snow [HDC 12]
  720. ! (T<T0: I->S)
  721. !-------------------------------------------------------------
  722. if(qci(i,k).gt.0.) then
  723. qimax = roqimax/den(i,k)
  724. paut(i,k) = max(0.,(qci(i,k)-qimax)/dtcld)
  725. endif
  726. endif
  727. enddo
  728. enddo
  729. !
  730. !----------------------------------------------------------------
  731. ! check mass conservation of generation terms and feedback to the
  732. ! large scale
  733. !
  734. do k = kts, kte
  735. do i = its, ite
  736. qciik = max(qmin,qci(i,k))
  737. delqci = (paut(i,k)+pacr(i,k)-pgen(i,k)-pisd(i,k))*dtcld
  738. if(delqci.ge.qciik) then
  739. facqci = qciik/delqci
  740. paut(i,k) = paut(i,k)*facqci
  741. pacr(i,k) = pacr(i,k)*facqci
  742. pgen(i,k) = pgen(i,k)*facqci
  743. pisd(i,k) = pisd(i,k)*facqci
  744. endif
  745. qik = max(qmin,q(i,k))
  746. delq = (pres(i,k)+pgen(i,k)+pisd(i,k))*dtcld
  747. if(delq.ge.qik) then
  748. facq = qik/delq
  749. pres(i,k) = pres(i,k)*facq
  750. pgen(i,k) = pgen(i,k)*facq
  751. pisd(i,k) = pisd(i,k)*facq
  752. endif
  753. work2(i,k) = -pres(i,k)-pgen(i,k)-pisd(i,k)
  754. q(i,k) = q(i,k)+work2(i,k)*dtcld
  755. qci(i,k) = max(qci(i,k)-(paut(i,k)+pacr(i,k)-pgen(i,k)-pisd(i,k)) &
  756. *dtcld,0.)
  757. qrs(i,k) = max(qrs(i,k)+(paut(i,k)+pacr(i,k)+pres(i,k))*dtcld,0.)
  758. if(t(i,k).lt.t0c) then
  759. t(i,k) = t(i,k)-xls*work2(i,k)/cpm(i,k)*dtcld
  760. else
  761. t(i,k) = t(i,k)-xl(i,k)*work2(i,k)/cpm(i,k)*dtcld
  762. endif
  763. enddo
  764. enddo
  765. !
  766. cvap = cpv
  767. hvap = xlv0
  768. hsub = xls
  769. ttp=t0c+0.01
  770. dldt=cvap-cliq
  771. xa=-dldt/rv
  772. xb=xa+hvap/(rv*ttp)
  773. dldti=cvap-cice
  774. xai=-dldti/rv
  775. xbi=xai+hsub/(rv*ttp)
  776. do k = kts, kte
  777. do i = its, ite
  778. tr=ttp/t(i,k)
  779. qs(i,k)=psat*(exp(log(tr)*(xa)))*exp(xb*(1.-tr))
  780. qs(i,k) = min(qs(i,k),0.99*p(i,k))
  781. qs(i,k) = ep2 * qs(i,k) / (p(i,k) - qs(i,k))
  782. qs(i,k) = max(qs(i,k),qmin)
  783. denfac(i,k) = sqrt(den0/den(i,k))
  784. enddo
  785. enddo
  786. !
  787. !----------------------------------------------------------------
  788. ! pcond: condensational/evaporational rate of cloud water [HL A46] [RH83 A6]
  789. ! if there exists additional water vapor condensated/if
  790. ! evaporation of cloud water is not enough to remove subsaturation
  791. !
  792. do k = kts, kte
  793. do i = its, ite
  794. work1(i,k) = conden(t(i,k),q(i,k),qs(i,k),xl(i,k),cpm(i,k))
  795. work2(i,k) = qci(i,k)+work1(i,k)
  796. pcon(i,k) = min(max(work1(i,k),0.),max(q(i,k),0.))/dtcld
  797. if(qci(i,k).gt.0..and.work1(i,k).lt.0.and.t(i,k).gt.t0c) &
  798. pcon(i,k) = max(work1(i,k),-qci(i,k))/dtcld
  799. q(i,k) = q(i,k)-pcon(i,k)*dtcld
  800. qci(i,k) = max(qci(i,k)+pcon(i,k)*dtcld,0.)
  801. t(i,k) = t(i,k)+pcon(i,k)*xl(i,k)/cpm(i,k)*dtcld
  802. enddo
  803. enddo
  804. !
  805. !----------------------------------------------------------------
  806. ! padding for small values
  807. !
  808. do k = kts, kte
  809. do i = its, ite
  810. if(qci(i,k).le.qmin) qci(i,k) = 0.0
  811. if(qrs(i,k).le.qcrmin) qrs(i,k) = 0.0
  812. enddo
  813. enddo
  814. !
  815. enddo ! big loops
  816. END SUBROUTINE wsm32D
  817. ! ...................................................................
  818. REAL FUNCTION rgmma(x)
  819. !-------------------------------------------------------------------
  820. IMPLICIT NONE
  821. !-------------------------------------------------------------------
  822. ! rgmma function: use infinite product form
  823. REAL :: euler
  824. PARAMETER (euler=0.577215664901532)
  825. REAL :: x, y
  826. INTEGER :: i
  827. if(x.eq.1.)then
  828. rgmma=0.
  829. else
  830. rgmma=x*exp(euler*x)
  831. do i=1,10000
  832. y=float(i)
  833. rgmma=rgmma*(1.000+x/y)*exp(-x/y)
  834. enddo
  835. rgmma=1./rgmma
  836. endif
  837. END FUNCTION rgmma
  838. !
  839. !--------------------------------------------------------------------------
  840. REAL FUNCTION fpvs(t,ice,rd,rv,cvap,cliq,cice,hvap,hsub,psat,t0c)
  841. !--------------------------------------------------------------------------
  842. IMPLICIT NONE
  843. !--------------------------------------------------------------------------
  844. REAL t,rd,rv,cvap,cliq,cice,hvap,hsub,psat,t0c,dldt,xa,xb,dldti, &
  845. xai,xbi,ttp,tr
  846. INTEGER ice
  847. ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  848. ttp=t0c+0.01
  849. dldt=cvap-cliq
  850. xa=-dldt/rv
  851. xb=xa+hvap/(rv*ttp)
  852. dldti=cvap-cice
  853. xai=-dldti/rv
  854. xbi=xai+hsub/(rv*ttp)
  855. tr=ttp/t
  856. if(t.lt.ttp.and.ice.eq.1) then
  857. fpvs=psat*(tr**xai)*exp(xbi*(1.-tr))
  858. else
  859. fpvs=psat*(tr**xa)*exp(xb*(1.-tr))
  860. endif
  861. ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  862. END FUNCTION fpvs
  863. !-------------------------------------------------------------------
  864. SUBROUTINE wsm3init(den0,denr,dens,cl,cpv,allowed_to_read)
  865. !-------------------------------------------------------------------
  866. IMPLICIT NONE
  867. !-------------------------------------------------------------------
  868. !.... constants which may not be tunable
  869. REAL, INTENT(IN) :: den0,denr,dens,cl,cpv
  870. LOGICAL, INTENT(IN) :: allowed_to_read
  871. !
  872. pi = 4.*atan(1.)
  873. xlv1 = cl-cpv
  874. !
  875. qc0 = 4./3.*pi*denr*r0**3*xncr/den0 ! 0.419e-3 -- .61e-3
  876. qck1 = .104*9.8*peaut/(xncr*denr)**(1./3.)/xmyu*den0**(4./3.) ! 7.03
  877. !
  878. bvtr1 = 1.+bvtr
  879. bvtr2 = 2.5+.5*bvtr
  880. bvtr3 = 3.+bvtr
  881. bvtr4 = 4.+bvtr
  882. g1pbr = rgmma(bvtr1)
  883. g3pbr = rgmma(bvtr3)
  884. g4pbr = rgmma(bvtr4) ! 17.837825
  885. g5pbro2 = rgmma(bvtr2) ! 1.8273
  886. pvtr = avtr*g4pbr/6.
  887. eacrr = 1.0
  888. pacrr = pi*n0r*avtr*g3pbr*.25*eacrr
  889. precr1 = 2.*pi*n0r*.78
  890. precr2 = 2.*pi*n0r*.31*avtr**.5*g5pbro2
  891. xmmax = (dimax/dicon)**2
  892. roqimax = 2.08e22*dimax**8
  893. !
  894. bvts1 = 1.+bvts
  895. bvts2 = 2.5+.5*bvts
  896. bvts3 = 3.+bvts
  897. bvts4 = 4.+bvts
  898. g1pbs = rgmma(bvts1) !.8875
  899. g3pbs = rgmma(bvts3)
  900. g4pbs = rgmma(bvts4) ! 12.0786
  901. g5pbso2 = rgmma(bvts2)
  902. pvts = avts*g4pbs/6.
  903. pacrs = pi*n0s*avts*g3pbs*.25
  904. precs1 = 4.*n0s*.65
  905. precs2 = 4.*n0s*.44*avts**.5*g5pbso2
  906. pidn0r = pi*denr*n0r
  907. pidn0s = pi*dens*n0s
  908. !
  909. rslopermax = 1./lamdarmax
  910. rslopesmax = 1./lamdasmax
  911. rsloperbmax = rslopermax ** bvtr
  912. rslopesbmax = rslopesmax ** bvts
  913. rsloper2max = rslopermax * rslopermax
  914. rslopes2max = rslopesmax * rslopesmax
  915. rsloper3max = rsloper2max * rslopermax
  916. rslopes3max = rslopes2max * rslopesmax
  917. !
  918. END SUBROUTINE wsm3init
  919. !
  920. subroutine slope_wsm3(qrs,den,denfac,t,rslope,rslopeb,rslope2,rslope3,vt,its,ite,kts,kte)
  921. IMPLICIT NONE
  922. INTEGER :: its,ite, jts,jte, kts,kte
  923. REAL, DIMENSION( its:ite , kts:kte ) :: &
  924. qrs, &
  925. den, &
  926. denfac, &
  927. t, &
  928. rslope, &
  929. rslopeb, &
  930. rslope2, &
  931. rslope3, &
  932. vt
  933. REAL, PARAMETER :: t0c = 273.15
  934. REAL, DIMENSION( its:ite , kts:kte ) :: &
  935. n0sfac
  936. REAL :: lamdar,lamdas,x, y, z, supcol, pvt
  937. integer :: i, j, k
  938. !----------------------------------------------------------------
  939. ! size distributions: (x=mixing ratio, y=air density):
  940. ! valid for mixing ratio > 1.e-9 kg/kg.
  941. !
  942. lamdar(x,y)= sqrt(sqrt(pidn0r/(x*y))) ! (pidn0r/(x*y))**.25
  943. lamdas(x,y,z)= sqrt(sqrt(pidn0s*z/(x*y))) ! (pidn0s*z/(x*y))**.25
  944. !
  945. do k = kts, kte
  946. do i = its, ite
  947. if(t(i,k).ge.t0c) then
  948. pvt = pvtr
  949. if(qrs(i,k).le.qcrmin)then
  950. rslope(i,k) = rslopermax
  951. rslopeb(i,k) = rsloperbmax
  952. rslope2(i,k) = rsloper2max
  953. rslope3(i,k) = rsloper3max
  954. else
  955. rslope(i,k) = 1./lamdar(qrs(i,k),den(i,k))
  956. rslopeb(i,k) = exp(log(rslope(i,k))*(bvtr))
  957. rslope2(i,k) = rslope(i,k)*rslope(i,k)
  958. rslope3(i,k) = rslope2(i,k)*rslope(i,k)
  959. endif
  960. else
  961. supcol = t0c-t(i,k)
  962. n0sfac(i,k) = max(min(exp(alpha*supcol),n0smax/n0s),1.)
  963. pvt = pvts
  964. if(qrs(i,k).le.qcrmin)then
  965. rslope(i,k) = rslopesmax
  966. rslopeb(i,k) = rslopesbmax
  967. rslope2(i,k) = rslopes2max
  968. rslope3(i,k) = rslopes3max
  969. else
  970. rslope(i,k) = 1./lamdas(qrs(i,k),den(i,k),n0sfac(i,k))
  971. rslopeb(i,k) = exp(log(rslope(i,k))*(bvts))
  972. rslope2(i,k) = rslope(i,k)*rslope(i,k)
  973. rslope3(i,k) = rslope2(i,k)*rslope(i,k)
  974. endif
  975. endif
  976. vt(i,k) = pvt*rslopeb(i,k)*denfac(i,k)
  977. if(qrs(i,k).le.0.0) vt(i,k) = 0.0
  978. enddo
  979. enddo
  980. END subroutine slope_wsm3
  981. !-------------------------------------------------------------------
  982. SUBROUTINE nislfv_rain_pcm(im,km,denl,denfacl,tkl,dzl,wwl,rql,precip,dt,id,iter)
  983. !-------------------------------------------------------------------
  984. !
  985. ! for non-iteration semi-Lagrangain forward advection for cloud
  986. ! with mass conservation and positive definite advection
  987. ! 2nd order interpolation with monotonic piecewise linear method
  988. ! this routine is under assumption of decfl < 1 for semi_Lagrangian
  989. !
  990. ! dzl depth of model layer in meter
  991. ! wwl terminal velocity at model layer m/s
  992. ! rql cloud density*mixing ration
  993. ! precip precipitation
  994. ! dt time step
  995. ! id kind of precip: 0 test case; 1 raindrop
  996. ! iter how many time to guess mean terminal velocity: 0 pure forward.
  997. ! 0 : use departure wind for advection
  998. ! 1 : use mean wind for advection
  999. ! > 1 : use mean wind after iter-1 iterations
  1000. !
  1001. ! author: hann-ming henry juang <henry.juang@noaa.gov>
  1002. ! implemented by song-you hong
  1003. !
  1004. implicit none
  1005. integer im,km,id
  1006. real dt
  1007. real dzl(im,km),wwl(im,km),rql(im,km),precip(im)
  1008. real denl(im,km),denfacl(im,km),tkl(im,km)
  1009. !
  1010. integer i,k,n,m,kk,kb,kt,iter
  1011. real tl,tl2,qql,dql,qqd
  1012. real th,th2,qqh,dqh
  1013. real zsum,qsum,dim,dip,c1,con1,fa1,fa2
  1014. real zsumt,qsumt,zsumb,qsumb
  1015. real allold, allnew, zz, dzamin, cflmax, decfl
  1016. real dz(km), ww(km), qq(km), wd(km), wa(km), was(km)
  1017. real den(km), denfac(km), tk(km)
  1018. real wi(km+1), zi(km+1), za(km+1)
  1019. real qn(km), qr(km),tmp(km),tmp1(km),tmp2(km),tmp3(km)
  1020. real dza(km+1), qa(km+1), qmi(km+1), qpi(km+1)
  1021. !
  1022. precip(:) = 0.0
  1023. !
  1024. i_loop : do i=1,im
  1025. ! -----------------------------------
  1026. dz(:) = dzl(i,:)
  1027. qq(:) = rql(i,:)
  1028. ww(:) = wwl(i,:)
  1029. den(:) = denl(i,:)
  1030. denfac(:) = denfacl(i,:)
  1031. tk(:) = tkl(i,:)
  1032. ! skip for no precipitation for all layers
  1033. allold = 0.0
  1034. do k=1,km
  1035. allold = allold + qq(k)
  1036. enddo
  1037. if(allold.le.0.0) then
  1038. cycle i_loop
  1039. endif
  1040. !
  1041. ! compute interface values
  1042. zi(1)=0.0
  1043. do k=1,km
  1044. zi(k+1) = zi(k)+dz(k)
  1045. enddo
  1046. !
  1047. ! save departure wind
  1048. wd(:) = ww(:)
  1049. n=1
  1050. 100 continue
  1051. ! pcm is 1st order, we should use 2nd order wi
  1052. ! 2nd order interpolation to get wi
  1053. wi(1) = ww(1)
  1054. do k=2,km
  1055. wi(k) = (ww(k)*dz(k-1)+ww(k-1)*dz(k))/(dz(k-1)+dz(k))
  1056. enddo
  1057. wi(km+1) = ww(km)
  1058. !
  1059. ! terminate of top of raingroup
  1060. do k=2,km
  1061. if( ww(k).eq.0.0 ) wi(k)=ww(k-1)
  1062. enddo
  1063. !
  1064. ! diffusivity of wi
  1065. con1 = 0.05
  1066. do k=km,1,-1
  1067. decfl = (wi(k+1)-wi(k))*dt/dz(k)
  1068. if( decfl .gt. con1 ) then
  1069. wi(k) = wi(k+1) - con1*dz(k)/dt
  1070. endif
  1071. enddo
  1072. ! compute arrival point
  1073. do k=1,km+1
  1074. za(k) = zi(k) - wi(k)*dt
  1075. enddo
  1076. !
  1077. do k=1,km
  1078. dza(k) = za(k+1)-za(k)
  1079. enddo
  1080. dza(km+1) = zi(km+1) - za(km+1)
  1081. !
  1082. ! computer deformation at arrival point
  1083. do k=1,km
  1084. qa(k) = qq(k)*dz(k)/dza(k)
  1085. qr(k) = qa(k)/den(k)
  1086. enddo
  1087. qa(km+1) = 0.0
  1088. ! call maxmin(km,1,qa,' arrival points ')
  1089. !
  1090. ! compute arrival terminal velocity, and estimate mean terminal velocity
  1091. ! then back to use mean terminal velocity
  1092. if( n.le.iter ) then
  1093. call slope_wsm3(qr,den,denfac,tk,tmp,tmp1,tmp2,tmp3,wa,1,1,1,km)
  1094. if( n.eq.2 ) wa(1:km) = 0.5*(wa(1:km)+was(1:km))
  1095. do k=1,km
  1096. !#ifdef DEBUG
  1097. ! print*,' slope_wsm3 ',qr(k)*1000.,den(k),denfac(k),tk(k),tmp(k),tmp1(k),tmp2(k),ww(k),wa(k)
  1098. !#endif
  1099. ! mean wind is average of departure and new arrival winds
  1100. ww(k) = 0.5* ( wd(k)+wa(k) )
  1101. enddo
  1102. was(:) = wa(:)
  1103. n=n+1
  1104. go to 100
  1105. endif
  1106. !
  1107. !
  1108. ! interpolation to regular point
  1109. qn = 0.0
  1110. kb=1
  1111. kt=1
  1112. intp : do k=1,km
  1113. kb=max(kb-1,1)
  1114. kt=max(kt-1,1)
  1115. ! find kb and kt
  1116. if( zi(k).ge.za(km+1) ) then
  1117. exit intp
  1118. else
  1119. find_kb : do kk=kb,km
  1120. if( zi(k).le.za(kk+1) ) then
  1121. kb = kk
  1122. exit find_kb
  1123. else
  1124. cycle find_kb
  1125. endif
  1126. enddo find_kb
  1127. find_kt : do kk=kt,km
  1128. if( zi(k+1).le.za(kk) ) then
  1129. kt = kk
  1130. exit find_kt
  1131. else
  1132. cycle find_kt
  1133. endif
  1134. enddo find_kt
  1135. ! compute q with piecewise constant method
  1136. if( kt-kb.eq.1 ) then
  1137. qn(k) = qa(kb)
  1138. else if( kt-kb.ge.2 ) then
  1139. zsumb = za(kb+1)-zi(k)
  1140. qsumb = qa(kb) * zsumb
  1141. zsumt = zi(k+1)-za(kt-1)
  1142. qsumt = qa(kt-1) * zsumt
  1143. qsum = 0.0
  1144. zsum = 0.0
  1145. if( kt-kb.ge.3 ) then
  1146. do m=kb+1,kt-2
  1147. qsum = qsum + qa(m) * dza(m)
  1148. zsum = zsum + dza(m)
  1149. enddo
  1150. endif
  1151. qn(k) = (qsumb+qsum+qsumt)/(zsumb+zsum+zsumt)
  1152. endif
  1153. cycle intp
  1154. endif
  1155. !
  1156. enddo intp
  1157. !
  1158. ! rain out
  1159. sum_precip: do k=1,km
  1160. if( za(k).lt.0.0 .and. za(k+1).lt.0.0 ) then
  1161. precip(i) = precip(i) + qa(k)*dza(k)
  1162. cycle sum_precip
  1163. else if ( za(k).lt.0.0 .and. za(k+1).ge.0.0 ) then
  1164. precip(i) = precip(i) + qa(k)*(0.0-za(k))
  1165. exit sum_precip
  1166. endif
  1167. exit sum_precip
  1168. enddo sum_precip
  1169. !
  1170. ! replace the new values
  1171. rql(i,:) = qn(:)
  1172. !
  1173. ! -------------------------------

Large files files are truncated, but you can click here to view the full file