FV3 Bundle
convection.F90
Go to the documentation of this file.
1 module convection
2 
3 IMPLICIT NONE
4 
5 PRIVATE
7 
8 CONTAINS
9 
10  SUBROUTINE rase( IDIM, IRUN, K0, ICMIN, DT, &
11  CONS_CP, CONS_ALHL, CONS_GRAV, CONS_RGAS, &
12  CONS_H2OMW, CONS_AIRMW, CONS_VIREPS, &
13  SEEDRAS, SIGE, &
14  KCBL, WGT0, WGT1, FRLAND, TS, &
15  THO, QHO, UHO, VHO, &
16  CO_AUTO, PLE, &
17  CLW, FLXD, CNV_PRC3, CNV_UPDFRC, &
18  RASPARAMS, ESTBLX )
19 
20  IMPLICIT NONE
21 
22  !INPUTS
23  INTEGER, INTENT(IN ) :: idim, irun, k0, icmin
24  REAL(8), DIMENSION (IDIM,K0+1), INTENT(IN ) :: ple
25  REAL(8), DIMENSION ( K0+1), INTENT(IN ) :: sige
26  REAL(8), INTENT(IN ) :: dt, cons_cp, cons_alhl, cons_grav, cons_rgas
27  REAL(8), INTENT(IN ) :: cons_h2omw,cons_airmw,cons_vireps
28  INTEGER, DIMENSION (IDIM) , INTENT(IN ) :: seedras
29  INTEGER, DIMENSION (IDIM ), INTENT(IN ) :: kcbl
30  REAL(8), DIMENSION (IDIM ), INTENT(IN ) :: ts, frland
31  REAL(8), DIMENSION (IDIM ), INTENT(IN ) :: co_auto
32  REAL(8), DIMENSION (IDIM,K0 ), INTENT(IN ) :: wgt0,wgt1
33  REAL(8), DIMENSION(:), INTENT(IN ) :: rasparams
34  REAL(8), DIMENSION(:), INTENT(IN ) :: estblx
35 
36  !OUTPUTS
37  REAL(8), DIMENSION (IDIM,K0 ), INTENT( OUT) :: clw , flxd
38  REAL(8), DIMENSION (IDIM,K0 ), INTENT( OUT) :: cnv_prc3
39  REAL(8), DIMENSION (IDIM,K0 ), INTENT( OUT) :: cnv_updfrc
40 
41  !PROGNOSTIC
42  REAL(8), DIMENSION (IDIM,K0 ), INTENT(INOUT) :: tho, qho, uho, vho
43 
44  !LOCALS
45  INTEGER :: i, ic, l, kk, k
46 
47  !Parameters
48  REAL(8), PARAMETER :: onepkap = 1.+ 2./7., daylen = 86400.0
49  REAL(8), PARAMETER :: rhmax = 0.9999
50  REAL(8), PARAMETER :: cbl_qpert = 0.0, cbl_tpert = 1.0
51  REAL(8), PARAMETER :: cbl_tpert_mxocn = 2.0, cbl_tpert_mxlnd = 4.0
52 
53  !Constants
54  REAL(8) :: grav, cp, alhl, cpbg, alhi, cpi, gravi, ddt, lbcp
55 
56  !Rasparams
57  REAL(8) :: fricfac, cli_crit, rasal1, rasal2
58  REAL(8) :: friclambda
59  REAL(8) :: sdqv2, sdqv3, sdqvt1
60  REAL(8) :: acritfac, pblfrac, autorampb
61  REAL(8) :: maxdallowed, rhmn, rhmx
62 
63  REAL(8) :: mxdiam
64  REAL(8) :: tx2, tx3, akm, acr, alm, tth, qqh, dqx
65  REAL(8) :: wfn, tem, trg, trgexp, evp, wlq, qcc
66  REAL(8) :: cli, te_a, c00_x, cli_crit_x, toki
67  REAL(8) :: dt_lyr, rate, cvw_x, closs, f2, f3, f4
68  REAL(8) :: wght0, prcbl, rndu
69  REAL(8) :: lambda_min, lambda_max
70  REAL(8) :: tpert, qpert
71  REAL(8) :: uht, vht
72 
73  REAL(8), DIMENSION(K0) :: poi_sv, qoi_sv, uoi_sv, voi_sv
74  REAL(8), DIMENSION(K0) :: poi, qoi, uoi, voi, dqq, bet, gam, cll
75  REAL(8), DIMENSION(K0) :: poi_c, qoi_c
76  REAL(8), DIMENSION(K0) :: prh, pri, ght, dpt, dpb, pki
77  REAL(8), DIMENSION(K0) :: ucu, vcu
78  REAL(8), DIMENSION(K0) :: cln, rns, pol
79  REAL(8), DIMENSION(K0) :: qst, ssl, rmf, rnn, rn1, rmfc, rmfp
80  REAL(8), DIMENSION(K0) :: gms, eta, gmh, eht, gm1, hcc, rmfd
81  REAL(8), DIMENSION(K0) :: hol, hst, qol, zol, hcld, cll0,cllx,clli
82  REAL(8), DIMENSION(K0) :: bke , cvw, updfrc
83  REAL(8), DIMENSION(K0) :: rasal, updfrp,bk2,dll0,dllx
84  REAL(8), DIMENSION(K0) :: wght, massf
85  REAL(8), DIMENSION(K0) :: qss, dqs, pf, pk, tempf, zlo
86  REAL(8), DIMENSION(K0+1) :: prj, prs, qht, sht ,zet, zle, pke
87 
88  !Initialize Local Arrays
89  poi = 0.0
90  qoi = 0.0
91  uoi = 0.0
92  voi = 0.0
93  dqq = 0.0
94  bet = 0.0
95  gam = 0.0
96  poi_c = 0.0
97  qoi_c = 0.0
98  prh = 0.0
99  pri = 0.0
100  ght = 0.0
101  dpt = 0.0
102  dpb = 0.0
103  pki = 0.0
104  ucu = 0.0
105  vcu = 0.0
106  cln = 0.0
107  pol = 0.0
108  qst = 0.0
109  ssl = 0.0
110  rmf = 0.0
111  rnn = 0.0
112  rn1 = 0.0
113  gms = 0.0
114  eta = 0.0
115  gmh = 0.0
116  eht = 0.0
117  gm1 = 0.0
118  hcc = 0.0
119  hol = 0.0
120  hst = 0.0
121  qol = 0.0
122  zol = 0.0
123  hcld = 0.0
124  bke = 0.0
125  cvw = 0.0
126  updfrc = 0.0
127  rasal = 0.0
128  updfrp = 0.0
129  bk2 = 0.0
130  wght = 0.0
131  massf = 0.0
132  qss = 0.0
133  dqs = 0.0
134  pf = 0.0
135  pk = 0.0
136  tempf = 0.0
137  zlo = 0.0
138  prj = 0.0
139  prs = 0.0
140  qht = 0.0
141  sht = 0.0
142  zet = 0.0
143  zle = 0.0
144  pke = 0.0
145 
146  !Initialize Outputs
147  cnv_prc3 =0.
148  cnv_updfrc=0.
149  flxd = 0.
150  clw = 0.
151 
152  fricfac = rasparams(1) ! --- 1
153  cli_crit = rasparams(4) ! --- 4
154  rasal1 = rasparams(5) ! --- 5
155  rasal2 = rasparams(6) ! --- 6
156  friclambda = rasparams(11) ! --- 11
157  sdqv2 = rasparams(14) ! --- 14
158  sdqv3 = rasparams(15) ! --- 15
159  sdqvt1 = rasparams(16) ! --- 16
160  acritfac = rasparams(17) ! --- 17
161  pblfrac = rasparams(20) ! --- 20
162  autorampb = rasparams(21) ! --- 21
163  rhmn = rasparams(24) ! --- 24
164  maxdallowed = rasparams(23) ! --- 24
165  rhmx = rasparams(25) ! --- 25
166 
167  grav = cons_grav
168  alhl = cons_alhl
169  cp = cons_cp
170  cpi = 1.0/cp
171  alhi = 1.0/alhl
172  gravi = 1.0/grav
173  cpbg = cp*gravi
174  ddt = daylen/dt
175  lbcp = alhl*cpi
176 
177 i = 1
178 
179  !CALL FINDBASE
180  k = kcbl(i)
181 
182  IF ( k > 0 ) THEN
183 
184  !Get saturation specific humidity and gradient wrt to T
185  pke = (ple(i,:)/1000.)**(cons_rgas/cons_cp)
186  pf = 0.5*(ple(i,1:k0) + ple(i,2:k0+1 ) )
187  pk = (pf/1000.)**(cons_rgas/cons_cp)
188  tempf = tho(i,:)*pk
189 
190  zle = 0.0
191  zlo = 0.0
192  zle(k0+1) = 0.
193  do l=k0,1,-1
194  zle(l) = tho(i,l) * (1.+cons_vireps*qho(i,l))
195  zlo(l) = zle(l+1) + (cons_cp/cons_grav)*( pke(l+1)-pk(l ) ) * zle(l)
196  zle(l) = zlo(l) + (cons_cp/cons_grav)*( pk(l) -pke(l) ) * zle(l)
197  end do
198 
199  tpert = cbl_tpert * ( ts(i) - ( tempf(k0)+ cons_grav*zlo(k0)/cons_cp ) )
200  qpert = cbl_qpert !* ( QSSFC - Q(:,:,K0) ) [CBL_QPERT = 0.0]
201  tpert = max( tpert , 0.0 )
202  qpert = max( qpert , 0.0 )
203 
204  if (frland(i) < 0.1) then
205  tpert = min( tpert , cbl_tpert_mxocn ) ! ocean
206  else
207  tpert = min( tpert , cbl_tpert_mxlnd ) ! land
208  endif
209 
210  call dqsat_ras(dqs,qss,tempf,pf,k0,estblx,cons_h2omw,cons_airmw)
211 
212  do kk=icmin,k+1
213  prj(kk) = pke(kk)
214  enddo
215 
216  prs(icmin:k0+1) = ple(i,icmin:k0+1)
217  poi(icmin:k) = tho(i,icmin:k)
218  qoi(icmin:k) = qho(i,icmin:k)
219  uoi(icmin:k) = uho(i,icmin:k)
220  voi(icmin:k) = vho(i,icmin:k)
221 
222  qst(icmin:k) = qss(icmin:k)
223  dqq(icmin:k) = dqs(icmin:k)
224 
225  !Mass fraction of each layer below cloud base
226  massf(:) = wgt0(i,:)
227 
228  !RESET PRESSURE at bottom edge of CBL
229  prcbl = prs(k)
230  do l= k,k0
231  prcbl = prcbl + massf(l)*( prs(l+1)-prs(l) )
232  end do
233  prs(k+1) = prcbl
234  prj(k+1) = (prs(k+1)/1000.)**(cons_rgas/cons_cp)
235 
236  DO l=k,icmin,-1
237  pol(l) = 0.5*(prs(l)+prs(l+1))
238  prh(l) = (prs(l+1)*prj(l+1)-prs(l)*prj(l)) / (onepkap*(prs(l+1)-prs(l)))
239  pki(l) = 1.0 / prh(l)
240  dpt(l) = prh(l ) - prj(l)
241  dpb(l) = prj(l+1) - prh(l)
242  pri(l) = .01 / (prs(l+1)-prs(l))
243  ENDDO
244 
245  !RECALCULATE PROFILE QUAN. IN LOWEST STRAPPED LAYER
246  if ( k<=k0) then
247  poi(k) = 0.
248  qoi(k) = 0.
249  uoi(k) = 0.
250  voi(k) = 0.
251 
252  !SPECIFY WEIGHTS GIVEN TO EACH LAYER WITHIN SUBCLOUD "SUPERLAYER"
253  wght = 0.
254  DO l=k,k0
255  wght(l) = massf(l) * ( ple(i,l+1) - ple(i,l) ) / ( prs(k+1) - prs(k) )
256  END DO
257 
258  DO l=k,k0
259  poi(k) = poi(k) + wght(l)*tho(i,l)
260  qoi(k) = qoi(k) + wght(l)*qho(i,l)
261  uoi(k) = uoi(k) + wght(l)*uho(i,l)
262  voi(k) = voi(k) + wght(l)*vho(i,l)
263  ENDDO
264 
265  call dqsats_ras(dqq(k), qst(k), poi(k)*prh(k),pol(k),estblx,cons_h2omw,cons_airmw)
266 
267  endif
268 
269  rndu = max( seedras(i)/1000000., 1e-6 )
270  mxdiam = maxdallowed*( rndu**(-1./2.) )
271 
272  DO l=k,icmin,-1
273  bet(l) = dqq(l)*pki(l) !*
274  gam(l) = pki(l)/(1.0+lbcp*dqq(l)) !*
275  IF (l<k) THEN
276  ght(l+1) = gam(l)*dpb(l) + gam(l+1)*dpt(l+1)
277  gm1(l+1) = 0.5*lbcp*(dqq(l )/(alhl*(1.0+lbcp*dqq(l ))) + dqq(l+1)/(alhl*(1.0+lbcp*dqq(l+1))) )
278  ENDIF
279  ENDDO
280 
281  rns = 0.
282  cll = 0.
283  rmf = 0.
284  rmfd = 0.
285  rmfc = 0.
286  rmfp = 0.
287  cll0 = 0.
288  dll0 = 0.
289  cllx = 0.
290  dllx = 0.
291  clli = 0.
292 
293  poi_sv = poi
294  qoi_sv = qoi
295  uoi_sv = uoi
296  voi_sv = voi
297 
298  cvw = 0.0
299  updfrc = 0.0
300  updfrp = 0.0
301 
302  hol=0. ! HOL initialized here in order not to confuse Valgrind debugger
303  zet(k+1) = 0
304  sht(k+1) = cp*poi(k)*prj(k+1)
305  DO l=k,icmin,-1
306  qol(l) = min(qst(l)*rhmax,qoi(l))
307  qol(l) = max( 0.000, qol(l) ) ! GUARDIAN/NEG.PREC.
308  ssl(l) = cp*prj(l+1)*poi(l) + grav*zet(l+1)
309  hol(l) = ssl(l) + qol(l)*alhl
310  hst(l) = ssl(l) + qst(l)*alhl
311  tem = poi(l)*(prj(l+1)-prj(l))*cpbg
312  zet(l) = zet(l+1) + tem
313  zol(l) = zet(l+1) + (prj(l+1)-prh(l))*poi(l)*cpbg
314  ENDDO
315 
316  DO ic = k,icmin+1,-1
317 
318  ucu(icmin:) = 0.
319  vcu(icmin:) = 0.
320 
321  alm = 0.
322  trg = min(1.,(qoi(k)/qst(k)-rhmn)/(rhmx-rhmn))
323 
324  f4 = min( 1.0, max( 0.0 , (autorampb-sige(ic))/0.2 ) )
325 
326  IF (trg <= 1.0e-5) THEN
327  cycle !================>>
328  ENDIF
329 
330  !RECOMPUTE SOUNDING UP TO DETRAINMENT LEVEL
331  poi_c = poi
332  qoi_c = qoi
333  poi_c(k) = poi_c(k) + tpert
334  qoi_c(k) = qoi_c(k) + qpert
335 
336  zet(k+1) = 0.
337  sht(k+1) = cp*poi_c(k)*prj(k+1)
338  DO l=k,ic,-1
339  qol(l) = min(qst(l)*rhmax,qoi_c(l))
340  qol(l) = max( 0.000, qol(l) ) ! GUARDIAN/NEG.PREC.
341  ssl(l) = cp*prj(l+1)*poi_c(l) + grav*zet(l+1)
342  hol(l) = ssl(l) + qol(l)*alhl
343  hst(l) = ssl(l) + qst(l)*alhl
344  tem = poi_c(l)*(prj(l+1)-prj(l))*cpbg
345  zet(l) = zet(l+1) + tem
346  zol(l) = zet(l+1) + (prj(l+1)-prh(l))*poi_c(l)*cpbg
347  ENDDO
348 
349  DO l=ic+1,k
350  tem = (prj(l)-prh(l-1))/(prh(l)-prh(l-1))
351  sht(l) = ssl(l-1) + tem*(ssl(l)-ssl(l-1))
352  qht(l) = .5*(qol(l)+qol(l-1))
353  ENDDO
354 
355  !CALCULATE LAMBDA, ETA, AND WORKFUNCTION
356  lambda_min = .2/mxdiam
357  lambda_max = .2/ 200.
358 
359  IF (hol(k) <= hst(ic)) THEN
360  cycle !================>>
361  ENDIF
362 
363  !LAMBDA CALCULATION: MS-A18
364 
365  tem = (hst(ic)-hol(ic))*(zol(ic)-zet(ic+1))
366  DO l=ic+1,k-1
367  tem = tem + (hst(ic)-hol(l ))*(zet(l )-zet(l +1))
368  ENDDO
369 
370  IF (tem <= 0.0) THEN
371  cycle !================>>
372  ENDIF
373 
374  alm = (hol(k)-hst(ic)) / tem
375 
376  IF (alm > lambda_max) THEN
377  cycle !================>>
378  ENDIF
379 
380  toki=1.0
381 
382  IF (alm < lambda_min) THEN
383  toki = ( alm/lambda_min )**2
384  ENDIF
385 
386  !ETA CALCULATION: MS-A2
387  DO l=ic+1,k
388  eta(l) = 1.0 + alm * (zet(l )-zet(k))
389  ENDDO
390  eta(ic) = 1.0 + alm * (zol(ic)-zet(k))
391 
392  !WORKFUNCTION CALCULATION: MS-A22
393  wfn = 0.0
394  hcc(k) = hol(k)
395  DO l=k-1,ic+1,-1
396  hcc(l) = hcc(l+1) + (eta(l) - eta(l+1))*hol(l)
397  tem = hcc(l+1)*dpb(l) + hcc(l)*dpt(l)
398  eht(l) = eta(l+1)*dpb(l) + eta(l)*dpt(l)
399  wfn = wfn + (tem - eht(l)*hst(l))*gam(l)
400  ENDDO
401  hcc(ic) = hst(ic)*eta(ic)
402  wfn = wfn + (hcc(ic+1)-hst(ic)*eta(ic+1))*gam(ic)*dpb(ic)
403 
404  !VERTICAL VELOCITY/KE CALCULATION (ADDED 12/2001 JTB)
405  bk2(k) = 0.0
406  bke(k) = 0.0
407  hcld(k) = hol(k)
408  DO l=k-1,ic,-1
409  hcld(l) = ( eta(l+1)*hcld(l+1) + (eta(l) - eta(l+1))*hol(l) ) / eta(l)
410  tem = (hcld(l)-hst(l) )*(zet(l)-zet(l+1))/ (1.0+lbcp*dqq(l))
411  bke(l) = bke(l+1) + grav * tem / ( cp*prj(l+1)*poi(l) )
412  bk2(l) = bk2(l+1) + grav * max(tem,0.0) / ( cp*prj(l+1)*poi(l) )
413  cvw(l) = sqrt( 2.0* max( bk2(l) , 0.0 ) )
414  ENDDO
415 
416  !ALPHA CALCULATION
417  IF ( zet(ic) < 2000. ) THEN
418  rasal(ic) = rasal1
419  ENDIF
420  IF ( zet(ic) >= 2000. ) THEN
421  rasal(ic) = rasal1 + (rasal2-rasal1)*(zet(ic) - 2000.)/8000.
422  ENDIF
423  rasal(ic) = min( rasal(ic) , 1.0e5 )
424 
425  rasal(ic) = dt / rasal(ic)
426 
427  DO l = ic,k
428  cvw(l) = max( cvw(l) , 1.00 )
429  ENDDO
430 
431  CALL acritn(pol(ic), prs(k), acr, acritfac)
432 
433  IF (wfn <= acr) THEN
434  cycle !================>>
435  ENDIF
436 
437  wlq = qol(k)
438  uht = uoi(k)
439  vht = voi(k)
440  rnn(k) = 0.
441  cll0(k) = 0.
442 
443  DO l=k-1,ic,-1
444  tem = eta(l) - eta(l+1)
445  wlq = wlq + tem * qol(l)
446  uht = uht + tem * uoi(l)
447  vht = vht + tem * voi(l)
448 
449  IF (l>ic) THEN
450  tx2 = 0.5*(qst(l)+qst(l-1))*eta(l)
451  tx3 = 0.5*(hst(l)+hst(l-1))*eta(l)
452  qcc = tx2 + gm1(l)*(hcc(l)-tx3)
453  cll0(l) = (wlq-qcc)
454  ELSE
455  cll0(l) = (wlq-qst(ic)*eta(ic))
456  ENDIF
457 
458  cll0(l) = max( cll0(l) , 0.00 )
459 
460  cli = cll0(l) / eta(l)
461  te_a = poi(l)*prh(l)
462 
463  CALL sundq3_ice( te_a, sdqv2, sdqv3, sdqvt1, f2 , f3 )
464 
465  c00_x = co_auto(i) * f2 * f3 * f4
466  cli_crit_x = cli_crit / ( f2 * f3 )
467 
468  rate = c00_x * ( 1.0 - exp( -(cli)**2 / cli_crit_x**2 ) )
469 
470  cvw_x = max( cvw(l) , 1.00 )
471 
472  dt_lyr = ( zet(l)-zet(l+1) )/cvw_x
473 
474  closs = cll0(l) * rate * dt_lyr
475  closs = min( closs , cll0(l) )
476 
477  cll0(l) = cll0(l) - closs
478  dll0(l) = closs
479 
480  IF (closs>0.) then
481  wlq = wlq - closs
482  rnn(l) = closs
483  else
484  rnn(l) = 0.
485  ENDIF
486 
487  ENDDO
488 
489  wlq = wlq - qst(ic)*eta(ic)
490 
491  !CALCULATE GAMMAS AND KERNEL
492  gms(k) = (sht(k)-ssl(k))*pri(k)
493  gmh(k) = gms(k) + (qht(k)-qol(k))*pri(k)*alhl
494  akm = gmh(k)*gam(k-1)*dpb(k-1)
495 
496  tx2 = gmh(k)
497  DO l=k-1,ic+1,-1
498  gms(l) = ( eta(l )*(sht(l)-ssl(l )) + eta(l+1)*(ssl(l)-sht(l+1)) ) *pri(l)
499  gmh(l) = gms(l) + ( eta(l )*(qht(l)-qol(l )) + eta(l+1)*(qol(l)-qht(l+1)) )*alhl*pri(l)
500  tx2 = tx2 + (eta(l) - eta(l+1)) * gmh(l)
501  akm = akm - gms(l)*eht(l)*pki(l) + tx2*ght(l)
502  ENDDO
503 
504  gms(ic) = eta(ic+1)*(ssl(ic)-sht(ic+1))*pri(ic)
505  akm = akm - gms(ic)*eta(ic+1)*dpb(ic)*pki(ic)
506 
507  gmh(ic) = gms(ic) + ( eta(ic+1)*(qol(ic)-qht(ic+1))*alhl + eta(ic)*(hst(ic)-hol(ic)))*pri(ic)
508 
509  !CLOUD BASE MASS FLUX
510  IF (akm >= 0.0 .OR. wlq < 0.0) THEN
511  cycle !================>>
512  ENDIF
513 
514  wfn = - (wfn-acr)/akm
515  wfn = min( ( rasal(ic)*trg*toki )*wfn , (prs(k+1)-prs(k) )*(100.*pblfrac))
516 
517  !CUMULATIVE PRECIP AND CLOUD-BASE MASS FLUX FOR OUTPUT
518  tem = wfn*gravi
519  cll(ic) = cll(ic) + wlq*tem
520  rmf(ic) = rmf(ic) + tem
521  rmfd(ic) = rmfd(ic) + tem * eta(ic)
522 
523  DO l=ic+1,k
524  rmfp(l) = tem * eta(l)
525  rmfc(l) = rmfc(l) + rmfp(l)
526 
527  dllx(l) = dllx(l) + tem*dll0(l)
528 
529  IF ( cvw(l) > 0.0 ) THEN
530  updfrp(l) = rmfp(l) * (ddt/daylen) * 1000. / ( cvw(l) * prs(l) )
531  ELSE
532  updfrp(l) = 0.0
533  ENDIF
534 
535  clli(l) = cll0(l)/eta(l)
536 
537  updfrc(l) = updfrc(l) + updfrp(l)
538 
539  ENDDO
540 
541  !THETA AND Q CHANGE DUE TO CLOUD TYPE IC
542  DO l=ic,k
543  rns(l) = rns(l) + rnn(l)*tem
544  gmh(l) = gmh(l) * wfn
545  gms(l) = gms(l) * wfn
546  qoi(l) = qoi(l) + (gmh(l) - gms(l)) * alhi
547  poi(l) = poi(l) + gms(l)*pki(l)*cpi
548  qst(l) = qst(l) + gms(l)*bet(l)*cpi
549  ENDDO
550 
551  wfn = wfn*0.5 *1.0 !*FRICFAC*0.5
552 
553  !CUMULUS FRICTION
554  IF (fricfac <= 0.0) THEN
555  cycle !================>>
556  ENDIF
557 
558  wfn = wfn*fricfac*exp( -alm / friclambda )
559  tem = wfn*pri(k)
560 
561  ucu(k) = ucu(k) + tem * (uoi(k-1) - uoi(k))
562  vcu(k) = vcu(k) + tem * (voi(k-1) - voi(k))
563 
564  DO l=k-1,ic+1,-1
565  tem = wfn*pri(l)
566  ucu(l) = ucu(l) + tem * ( (uoi(l-1) - uoi(l)) * eta(l) + (uoi(l) - uoi(l+1)) * eta(l+1) )
567  vcu(l) = vcu(l) + tem * ( (voi(l-1) - voi(l)) * eta(l) + (voi(l) - voi(l+1)) * eta(l+1) )
568  ENDDO
569 
570  tem = wfn*pri(ic)
571  ucu(ic) = ucu(ic) + (2.*(uht-uoi(ic)*(eta(ic)-eta(ic+1))) - (uoi(ic)+uoi(ic+1))*eta(ic+1))*tem
572  vcu(ic) = vcu(ic) + (2.*(vht-voi(ic)*(eta(ic)-eta(ic+1))) - (voi(ic)+voi(ic+1))*eta(ic+1))*tem
573 
574  DO l=ic,k
575  uoi(l) = uoi(l) + ucu(l)
576  voi(l) = voi(l) + vcu(l)
577  ENDDO
578 
579  ENDDO !CLOUD LOOP
580 
581  IF ( sum( rmf(icmin:k) ) > 0.0 ) THEN
582 
583  DO l=icmin,k
584  tem = pri(l)*grav
585  cnv_prc3(i,l) = rns(l)*tem
586  ENDDO
587 
588  tho(i,icmin:k-1) = poi(icmin:k-1)
589  qho(i,icmin:k-1) = qoi(icmin:k-1)
590  uho(i,icmin:k-1) = uoi(icmin:k-1)
591  vho(i,icmin:k-1) = voi(icmin:k-1)
592  cnv_updfrc(i,icmin:k-1) = updfrc(icmin:k-1)
593 
594  !De-strap tendencies from RAS
595  wght = wgt1(i,:)
596 
597  !Scale properly by layer masses
598  wght0 = 0.
599  DO l=k,k0
600  wght0 = wght0 + wght(l)* ( ple(i,l+1) - ple(i,l) )
601  END DO
602 
603  wght0 = ( prs(k+1) - prs(k) )/wght0
604  wght = wght0 * wght
605 
606  DO l=k,k0
607  tho(i,l) = tho(i,l) + wght(l)*(poi(k) - poi_sv(k))
608  qho(i,l) = qho(i,l) + wght(l)*(qoi(k) - qoi_sv(k))
609  uho(i,l) = uho(i,l) + wght(l)*(uoi(k) - uoi_sv(k))
610  vho(i,l) = vho(i,l) + wght(l)*(voi(k) - voi_sv(k))
611  END DO
612 
613  flxd(i,icmin:k) = rmfd(icmin:k) * ddt/daylen
614  clw(i,icmin:k) = cll(icmin:k) * ddt/daylen
615 
616  flxd(i,1:icmin-1) = 0.
617  clw(i,1:icmin-1) = 0.
618 
619  IF ( k < k0 ) THEN
620  flxd(i,k:k0) = 0.
621  clw(i,k:k0) = 0.
622  END IF
623 
624  ELSE
625 
626  flxd(i,:) = 0.
627  clw(i,:) = 0.
628 
629  ENDIF
630 
631  ELSE
632 
633  flxd(i,:) = 0.
634  clw(i,:) = 0.
635 
636  ENDIF
637 
638 END SUBROUTINE rase
639 
640 SUBROUTINE acritn( PL, PLB, ACR, ACRITFAC )
641 
642  IMPLICIT NONE
643 
644  REAL(8), INTENT(IN ) :: pl, plb, acritfac
645  REAL(8), INTENT(OUT) :: acr
646 
647  INTEGER :: iwk
648 
649  REAL(8), PARAMETER :: ph(15)=(/150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 450.0, 500.0, &
650  550.0, 600.0, 650.0, 700.0, 750.0, 800.0, 850.0/)
651 
652  REAL(8), PARAMETER :: a(15)=(/ 1.6851, 1.1686, 0.7663, 0.5255, 0.4100, 0.3677, &
653  0.3151, 0.2216, 0.1521, 0.1082, 0.0750, 0.0664, &
654  0.0553, 0.0445, 0.0633 /)
655 
656  iwk = int(pl * 0.02 - 0.999999999)
657 
658  IF (iwk .GT. 1 .AND. iwk .LE. 15) THEN
659  acr = a(iwk-1) + (pl-ph(iwk-1))*.02*(a(iwk)-a(iwk-1))
660  ELSEIF(iwk > 15) THEN
661  acr = a(15)
662  ELSE
663  acr = a(1)
664  ENDIF
665 
666  acr = acritfac * acr * (plb - pl)
667 
668 ENDSUBROUTINE acritn
669 
670 SUBROUTINE sundq3_ice( TEMP,RATE2,RATE3,TE1, F2, F3)
672 IMPLICIT NONE
673 
674 REAL(8), INTENT( IN) :: temp,rate2,rate3,te1
675 REAL(8), INTENT(OUT) :: f2, f3
676 
677 REAL(8) :: xx, yy,te0,te2,jump1 !,RATE2,RATE3,TE1
678 
679  te0=273.
680  te2=200.
681  jump1= (rate2-1.0) / ( ( te0-te1 )**0.333 )
682 
683  ! Ice - phase treatment
684  IF ( temp .GE. te0 ) THEN
685  f2 = 1.0
686  f3 = 1.0
687  ENDIF
688 
689  IF ( ( temp .GE. te1 ) .AND. ( temp .LT. te0 ) )THEN
690  f2 = 1.0 + jump1 * (( te0 - temp )**0.3333)
691  f3 = 1.0
692  ENDIF
693 
694  IF ( temp .LT. te1 ) THEN
695  f2 = rate2 + (rate3-rate2)*(te1-temp)/(te1-te2)
696  f3 = 1.0
697  ENDIF
698 
699  IF ( f2 .GT. 27.0 ) THEN
700  f2 = 27.0
701  ENDIF
702 
703 endsubroutine sundq3_ice
704 
705 subroutine dqsat_ras(DQSi,QSSi,TEMP,PLO,lm,ESTBLX,CONS_H2OMW,CONS_AIRMW)
706 !COMPUTES SATURATION VAPOUR PRESSURE QSSi AND GRADIENT w.r.t TEMPERATURE DQSi.
707 !INPUTS ARE TEMPERATURE AND PLO (PRESSURE AT T-LEVELS)
708 !VALES ARE COMPUTED FROM LOOK-UP TALBE (PIECEWISE LINEAR)
709 
710  IMPLICIT NONE
711 
712  !Inputs
713  INTEGER :: lm
714  REAL(8), dimension(lm) :: temp, plo
715  REAL(8) :: estblx(:)
716  REAL(8) :: cons_h2omw, cons_airmw
717 
718  !Outputs
719  REAL(8), dimension(lm) :: dqsi, qssi
720 
721  !Locals
722  REAL(8), parameter :: max_mixing_ratio = 1.0
723  REAL(8) :: esfac
724 
725  INTEGER :: k
726 
727  REAL(8) :: tl, tt, ti, dqsat, qsat, dqq, qq, pl, pp, dd
728  INTEGER :: it
729 
730  INTEGER, parameter :: degsubs = 100
731  REAL(8), parameter :: tmintbl = 150.0, tmaxtbl = 333.0
732  INTEGER, parameter :: tablesize = nint(tmaxtbl-tmintbl)*degsubs + 1
733 
734  esfac = cons_h2omw/cons_airmw
735 
736  do k=1,lm
737 
738  tl = temp(k)
739  pl = plo(k)
740 
741  pp = pl*100.0
742 
743  if (tl<=tmintbl) then
744  ti = tmintbl
745  elseif(tl>=tmaxtbl-.001) then
746  ti = tmaxtbl-.001
747  else
748  ti = tl
749  end if
750 
751  tt = (ti - tmintbl)*degsubs+1
752  it = int(tt)
753 
754  dqq = estblx(it+1) - estblx(it)
755  qq = (tt-it)*dqq + estblx(it)
756 
757  if (pp <= qq) then
758  qsat = max_mixing_ratio
759  dqsat = 0.0
760  else
761  dd = 1.0/(pp - (1.0-esfac)*qq)
762  qsat = esfac*qq*dd
763  dqsat = (esfac*degsubs)*dqq*pp*(dd*dd)
764  end if
765 
766  dqsi(k) = dqsat
767  qssi(k) = qsat
768 
769  end do
770 
771 end subroutine dqsat_ras
772 
773 subroutine dqsats_ras(DQSi,QSSi,TEMP,PLO,ESTBLX,CONS_H2OMW,CONS_AIRMW)
774 !COMPUTES SATURATION VAPOUR PRESSURE QSSi AND GRADIENT w.r.t TEMPERATURE DQSi.
775 !INPUTS ARE TEMPERATURE AND PLO (PRESSURE AT T-LEVELS)
776 !VALES ARE COMPUTED FROM LOOK-UP TALBE (PIECEWISE LINEAR)
777 
778  IMPLICIT NONE
779 
780  !Inputs
781  REAL(8) :: temp, plo
782  REAL(8) :: estblx(:)
783  REAL(8) :: cons_h2omw, cons_airmw
784 
785  !Outputs
786  REAL(8) :: dqsi, qssi
787 
788  !Locals
789  REAL(8), parameter :: max_mixing_ratio = 1.0
790  REAL(8) :: esfac
791 
792  REAL(8) :: tl, tt, ti, dqsat, qsat, dqq, qq, pl, pp, dd
793  INTEGER :: it
794 
795  INTEGER, parameter :: degsubs = 100
796  REAL(8), parameter :: tmintbl = 150.0, tmaxtbl = 333.0
797  INTEGER, parameter :: tablesize = nint(tmaxtbl-tmintbl)*degsubs + 1
798 
799  esfac = cons_h2omw/cons_airmw
800 
801  tl = temp
802  pl = plo
803 
804  pp = pl*100.0
805 
806  if (tl<=tmintbl) then
807  ti = tmintbl
808  elseif(tl>=tmaxtbl-.001) then
809  ti = tmaxtbl-.001
810  else
811  ti = tl
812  end if
813 
814  tt = (ti - tmintbl)*degsubs+1
815  it = int(tt)
816 
817  dqq = estblx(it+1) - estblx(it)
818  qq = (tt-it)*dqq + estblx(it)
819 
820  if (pp <= qq) then
821  qsat = max_mixing_ratio
822  dqsat = 0.0
823  else
824  dd = 1.0/(pp - (1.0-esfac)*qq)
825  qsat = esfac*qq*dd
826  dqsat = (esfac*degsubs)*dqq*pp*(dd*dd)
827  end if
828 
829  dqsi = dqsat
830  qssi = qsat
831 
832 end subroutine dqsats_ras
833 
834  SUBROUTINE rase0(IDIM, IRUN, K0, ICMIN, DT, &
835  CONS_CP, CONS_ALHL, CONS_GRAV, CONS_RGAS, &
836  CONS_H2OMW, CONS_AIRMW, CONS_VIREPS, &
837  SEEDRAS, SIGE, &
838  KCBL, WGT0, WGT1, FRLAND, TS, &
839  THO, QHO, &
840  CO_AUTO, PLE, &
841  CLW, FLXD, CNV_PRC3, CNV_UPDFRC, &
842  RASPARAMS, ESTBLX )
844  IMPLICIT NONE
845 
846  !INPUTS
847  INTEGER, INTENT(IN ) :: idim, irun, k0, icmin
848  REAL(8), DIMENSION (IDIM,K0+1), INTENT(IN ) :: ple
849  REAL(8), DIMENSION ( K0+1), INTENT(IN ) :: sige
850  REAL(8), INTENT(IN ) :: dt, cons_cp, cons_alhl, cons_grav, cons_rgas
851  REAL(8), INTENT(IN ) :: cons_h2omw,cons_airmw,cons_vireps
852  INTEGER, DIMENSION (IDIM) , INTENT(IN ) :: seedras
853  INTEGER, DIMENSION (IDIM ), INTENT(IN ) :: kcbl
854  REAL(8), DIMENSION (IDIM ), INTENT(IN ) :: ts, frland
855  REAL(8), DIMENSION (IDIM ), INTENT(IN ) :: co_auto
856  REAL(8), DIMENSION (IDIM,K0 ), INTENT(IN ) :: wgt0,wgt1
857  REAL(8), DIMENSION(:), INTENT(IN ) :: rasparams
858  REAL(8), DIMENSION(:), INTENT(IN ) :: estblx
859 
860  !OUTPUTS
861  REAL(8), DIMENSION (IDIM,K0 ), INTENT( OUT) :: clw , flxd
862  REAL(8), DIMENSION (IDIM,K0 ), INTENT( OUT) :: cnv_prc3
863  REAL(8), DIMENSION (IDIM,K0 ), INTENT( OUT) :: cnv_updfrc
864 
865  !PROGNOSTIC
866  REAL(8), DIMENSION (IDIM,K0 ), INTENT(INOUT) :: tho, qho
867 
868  !LOCALS
869  INTEGER :: i, ic, l, kk, k
870 
871  !Parameters
872  REAL(8), PARAMETER :: onepkap = 1.+ 2./7., daylen = 86400.0
873  REAL(8), PARAMETER :: rhmax = 0.9999
874  REAL(8), PARAMETER :: cbl_qpert = 0.0, cbl_tpert = 1.0
875  REAL(8), PARAMETER :: cbl_tpert_mxocn = 2.0, cbl_tpert_mxlnd = 4.0
876 
877  !Constants
878  REAL(8) :: grav, cp, alhl, cpbg, alhi, cpi, gravi, ddt, lbcp
879 
880  !Rasparams
881  REAL(8) :: fricfac, cli_crit, rasal1, rasal2
882  REAL(8) :: friclambda
883  REAL(8) :: sdqv2, sdqv3, sdqvt1
884  REAL(8) :: acritfac, pblfrac, autorampb
885  REAL(8) :: maxdallowed, rhmn, rhmx
886 
887  REAL(8) :: mxdiam
888  REAL(8) :: tx2, tx3, akm, acr, alm, tth, qqh, dqx
889  REAL(8) :: wfn, tem, trg, trgexp, evp, wlq, qcc
890  REAL(8) :: cli, te_a, c00_x, cli_crit_x, toki
891  REAL(8) :: dt_lyr, rate, cvw_x, closs, f2, f3, f4
892  REAL(8) :: wght0, prcbl, rndu
893  REAL(8) :: lambda_min, lambda_max
894  REAL(8) :: tpert,qpert
895 
896  REAL(8), DIMENSION(K0) :: poi_sv, qoi_sv
897  REAL(8), DIMENSION(K0) :: poi, qoi, dqq, bet, gam, cll
898  REAL(8), DIMENSION(K0) :: poi_c, qoi_c
899  REAL(8), DIMENSION(K0) :: prh, pri, ght, dpt, dpb, pki
900  REAL(8), DIMENSION(K0) :: cln, rns, pol,dm
901  REAL(8), DIMENSION(K0) :: qst, ssl, rmf, rnn, rn1, rmfc, rmfp
902  REAL(8), DIMENSION(K0) :: gms, eta, gmh, eht, gm1, hcc, rmfd
903  REAL(8), DIMENSION(K0) :: hol, hst, qol, zol, hcld, cll0,cllx,clli
904  REAL(8), DIMENSION(K0) :: bke , cvw, updfrc
905  REAL(8), DIMENSION(K0) :: rasal, updfrp,bk2,dll0,dllx
906  REAL(8), DIMENSION(K0) :: wght, massf
907  REAL(8), DIMENSION(K0) :: qss, dqs, pf, pk, tempf, zlo
908  REAL(8), DIMENSION(K0+1) :: prj, prs, qht, sht ,zet, zle, pke
909 
910  cnv_prc3 =0.
911  cnv_updfrc=0.
912  flxd = 0.
913  clw = 0.
914 
915  fricfac = rasparams(1) ! --- 1
916  cli_crit = rasparams(4) ! --- 4
917  rasal1 = rasparams(5) ! --- 5
918  rasal2 = rasparams(6) ! --- 6
919  friclambda = rasparams(11) ! --- 11
920  sdqv2 = rasparams(14) ! --- 14
921  sdqv3 = rasparams(15) ! --- 15
922  sdqvt1 = rasparams(16) ! --- 16
923  acritfac = rasparams(17) ! --- 17
924  pblfrac = rasparams(20) ! --- 20
925  autorampb = rasparams(21) ! --- 21
926  rhmn = rasparams(24) ! --- 24
927  maxdallowed = rasparams(23) ! --- 24
928  rhmx = rasparams(25) ! --- 25
929 
930  grav = cons_grav
931  alhl = cons_alhl
932  cp = cons_cp
933  cpi = 1.0/cp
934  alhi = 1.0/alhl
935  gravi = 1.0/grav
936  cpbg = cp*gravi
937  ddt = daylen/dt
938  lbcp = alhl*cpi
939 
940  DO i = 1,irun
941 
942  !CALL FINDBASE
943  k = kcbl(i)
944 
945  IF ( k > 0 ) THEN
946 
947  !Get saturation specific humidity and gradient wrt to T
948  pke = (ple(i,:)/1000.)**(cons_rgas/cons_cp)
949  pf = 0.5*(ple(i,1:k0) + ple(i,2:k0+1 ) )
950  pk = (pf/1000.)**(cons_rgas/cons_cp)
951  tempf = tho(i,:)*pk
952 
953  zle = 0.0
954  zlo = 0.0
955  zle(k0+1) = 0.
956  do l=k0,1,-1
957  zle(l) = tho(i,l) * (1.+cons_vireps*qho(i,l))
958  zlo(l) = zle(l+1) + (cons_cp/cons_grav)*( pke(l+1)-pk(l ) ) * zle(l)
959  zle(l) = zlo(l) + (cons_cp/cons_grav)*( pk(l) -pke(l) ) * zle(l)
960  end do
961 
962  tpert = cbl_tpert * ( ts(i) - ( tempf(k0)+ cons_grav*zlo(k0)/cons_cp ) )
963  qpert = cbl_qpert !* ( QSSFC - Q(:,:,K0) ) [CBL_QPERT = 0.0]
964  tpert = max( tpert , 0.0 )
965  qpert = max( qpert , 0.0 )
966 
967  if (frland(i) < 0.1) then
968  tpert = min( tpert , cbl_tpert_mxocn ) ! ocean
969  else
970  tpert = min( tpert , cbl_tpert_mxlnd ) ! land
971  endif
972 
973  call dqsat_ras(dqs,qss,tempf,pf,k0,estblx,cons_h2omw,cons_airmw)
974 
975  do kk=icmin,k+1
976  prj(kk) = pke(kk)
977  enddo
978 
979  poi=0. ! These initialized here in order not to confuse Valgrind debugger
980  qoi=0. ! Do not believe it actually makes any difference.
981 
982  prs(icmin:k0+1) = ple(i,icmin:k0+1)
983  poi(icmin:k) = tho(i,icmin:k)
984  qoi(icmin:k) = qho(i,icmin:k)
985 
986  qst(icmin:k) = qss(icmin:k)
987  dqq(icmin:k) = dqs(icmin:k)
988 
989  !Mass fraction of each layer below cloud base
990  massf(:) = wgt0(i,:)
991 
992  !RESET PRESSURE at bottom edge of CBL
993  prcbl = prs(k)
994  do l= k,k0
995  prcbl = prcbl + massf(l)*( prs(l+1)-prs(l) )
996  end do
997  prs(k+1) = prcbl
998  prj(k+1) = (prs(k+1)/1000.)**(cons_rgas/cons_cp)
999 
1000  DO l=k,icmin,-1
1001  pol(l) = 0.5*(prs(l)+prs(l+1))
1002  prh(l) = (prs(l+1)*prj(l+1)-prs(l)*prj(l)) / (onepkap*(prs(l+1)-prs(l)))
1003  pki(l) = 1.0 / prh(l)
1004  dpt(l) = prh(l ) - prj(l)
1005  dpb(l) = prj(l+1) - prh(l)
1006  pri(l) = .01 / (prs(l+1)-prs(l))
1007  ENDDO
1008 
1009  !RECALCULATE PROFILE QUAN. IN LOWEST STRAPPED LAYER
1010  if ( k<=k0) then
1011  poi(k) = 0.
1012  qoi(k) = 0.
1013 
1014  !SPECIFY WEIGHTS GIVEN TO EACH LAYER WITHIN SUBCLOUD "SUPERLAYER"
1015  wght = 0.
1016  DO l=k,k0
1017  wght(l) = massf(l) * ( ple(i,l+1) - ple(i,l) ) / ( prs(k+1) - prs(k) )
1018  END DO
1019 
1020  DO l=k,k0
1021  poi(k) = poi(k) + wght(l)*tho(i,l)
1022  qoi(k) = qoi(k) + wght(l)*qho(i,l)
1023  ENDDO
1024 
1025  call dqsats_ras(dqq(k), qst(k), poi(k)*prh(k),pol(k),estblx,cons_h2omw,cons_airmw)
1026 
1027  endif
1028 
1029  rndu = max( seedras(i)/1000000., 1e-6 )
1030  mxdiam = maxdallowed*( rndu**(-1./2.) )
1031 
1032  DO l=k,icmin,-1
1033  bet(l) = dqq(l)*pki(l) !*
1034  gam(l) = pki(l)/(1.0+lbcp*dqq(l)) !*
1035  IF (l<k) THEN
1036  ght(l+1) = gam(l)*dpb(l) + gam(l+1)*dpt(l+1)
1037  gm1(l+1) = 0.5*lbcp*(dqq(l )/(alhl*(1.0+lbcp*dqq(l ))) + dqq(l+1)/(alhl*(1.0+lbcp*dqq(l+1))) )
1038  ENDIF
1039  ENDDO
1040 
1041  rns = 0.
1042  cll = 0.
1043  rmf = 0.
1044  rmfd = 0.
1045  rmfc = 0.
1046  rmfp = 0.
1047  cll0 = 0.
1048  dll0 = 0.
1049  cllx = 0.
1050  dllx = 0.
1051  clli = 0.
1052 
1053  poi_sv = poi
1054  qoi_sv = qoi
1055 
1056  cvw = 0.0
1057  updfrc = 0.0
1058  updfrp = 0.0
1059 
1060  hol=0. ! HOL initialized here in order not to confuse Valgrind debugger
1061  zet(k+1) = 0
1062  sht(k+1) = cp*poi(k)*prj(k+1)
1063  DO l=k,icmin,-1
1064  qol(l) = min(qst(l)*rhmax,qoi(l))
1065  qol(l) = max( 0.000, qol(l) ) ! GUARDIAN/NEG.PREC.
1066  ssl(l) = cp*prj(l+1)*poi(l) + grav*zet(l+1)
1067  hol(l) = ssl(l) + qol(l)*alhl
1068  hst(l) = ssl(l) + qst(l)*alhl
1069  tem = poi(l)*(prj(l+1)-prj(l))*cpbg
1070  zet(l) = zet(l+1) + tem
1071  zol(l) = zet(l+1) + (prj(l+1)-prh(l))*poi(l)*cpbg
1072  ENDDO
1073 
1074  DO ic = k,icmin+1,-1
1075 
1076  alm = 0.
1077  trg = min(1.,(qoi(k)/qst(k)-rhmn)/(rhmx-rhmn))
1078 
1079  f4 = min( 1.0, max( 0.0 , (autorampb-sige(ic))/0.2 ) )
1080 
1081  IF (trg <= 1.0e-5) THEN
1082  cycle !================>>
1083  ENDIF
1084 
1085  !RECOMPUTE SOUNDING UP TO DETRAINMENT LEVEL
1086  poi_c = poi
1087  qoi_c = qoi
1088  poi_c(k) = poi_c(k) + tpert
1089  qoi_c(k) = qoi_c(k) + qpert
1090 
1091  zet(k+1) = 0.
1092  sht(k+1) = cp*poi_c(k)*prj(k+1)
1093  DO l=k,ic,-1
1094  qol(l) = min(qst(l)*rhmax,qoi_c(l))
1095  qol(l) = max( 0.000, qol(l) ) ! GUARDIAN/NEG.PREC.
1096  ssl(l) = cp*prj(l+1)*poi_c(l) + grav*zet(l+1)
1097  hol(l) = ssl(l) + qol(l)*alhl
1098  hst(l) = ssl(l) + qst(l)*alhl
1099  tem = poi_c(l)*(prj(l+1)-prj(l))*cpbg
1100  zet(l) = zet(l+1) + tem
1101  zol(l) = zet(l+1) + (prj(l+1)-prh(l))*poi_c(l)*cpbg
1102  ENDDO
1103 
1104  DO l=ic+1,k
1105  tem = (prj(l)-prh(l-1))/(prh(l)-prh(l-1))
1106  sht(l) = ssl(l-1) + tem*(ssl(l)-ssl(l-1))
1107  qht(l) = .5*(qol(l)+qol(l-1))
1108  ENDDO
1109 
1110  !CALCULATE LAMBDA, ETA, AND WORKFUNCTION
1111  lambda_min = .2/mxdiam
1112  lambda_max = .2/ 200.
1113 
1114  IF (hol(k) <= hst(ic)) THEN
1115  cycle !================>>
1116  ENDIF
1117 
1118  !LAMBDA CALCULATION: MS-A18
1119 
1120  tem = (hst(ic)-hol(ic))*(zol(ic)-zet(ic+1))
1121  DO l=ic+1,k-1
1122  tem = tem + (hst(ic)-hol(l ))*(zet(l )-zet(l +1))
1123  ENDDO
1124 
1125  IF (tem <= 0.0) THEN
1126  cycle !================>>
1127  ENDIF
1128 
1129  alm = (hol(k)-hst(ic)) / tem
1130 
1131  IF (alm > lambda_max) THEN
1132  cycle !================>>
1133  ENDIF
1134 
1135  toki=1.0
1136 
1137  IF (alm < lambda_min) THEN
1138  toki = ( alm/lambda_min )**2
1139  ENDIF
1140 
1141  !ETA CALCULATION: MS-A2
1142  DO l=ic+1,k
1143  eta(l) = 1.0 + alm * (zet(l )-zet(k))
1144  ENDDO
1145  eta(ic) = 1.0 + alm * (zol(ic)-zet(k))
1146 
1147  !WORKFUNCTION CALCULATION: MS-A22
1148  wfn = 0.0
1149  hcc(k) = hol(k)
1150  DO l=k-1,ic+1,-1
1151  hcc(l) = hcc(l+1) + (eta(l) - eta(l+1))*hol(l)
1152  tem = hcc(l+1)*dpb(l) + hcc(l)*dpt(l)
1153  eht(l) = eta(l+1)*dpb(l) + eta(l)*dpt(l)
1154  wfn = wfn + (tem - eht(l)*hst(l))*gam(l)
1155  ENDDO
1156  hcc(ic) = hst(ic)*eta(ic)
1157  wfn = wfn + (hcc(ic+1)-hst(ic)*eta(ic+1))*gam(ic)*dpb(ic)
1158 
1159  !VERTICAL VELOCITY/KE CALCULATION (ADDED 12/2001 JTB)
1160  bk2(k) = 0.0
1161  bke(k) = 0.0
1162  hcld(k) = hol(k)
1163  DO l=k-1,ic,-1
1164  hcld(l) = ( eta(l+1)*hcld(l+1) + (eta(l) - eta(l+1))*hol(l) ) / eta(l)
1165  tem = (hcld(l)-hst(l) )*(zet(l)-zet(l+1))/ (1.0+lbcp*dqq(l))
1166  bke(l) = bke(l+1) + grav * tem / ( cp*prj(l+1)*poi(l) )
1167  bk2(l) = bk2(l+1) + grav * max(tem,0.0) / ( cp*prj(l+1)*poi(l) )
1168  cvw(l) = sqrt( 2.0* max( bk2(l) , 0.0 ) )
1169  ENDDO
1170 
1171  !ALPHA CALCULATION
1172  IF ( zet(ic) < 2000. ) THEN
1173  rasal(ic) = rasal1
1174  ENDIF
1175  IF ( zet(ic) >= 2000. ) THEN
1176  rasal(ic) = rasal1 + (rasal2-rasal1)*(zet(ic) - 2000.)/8000.
1177  ENDIF
1178  rasal(ic) = min( rasal(ic) , 1.0e5 )
1179 
1180  rasal(ic) = dt / rasal(ic)
1181 
1182  cvw(ic:k) = max( cvw(ic:k) , 1.00 )
1183 
1184  CALL acritn(pol(ic), prs(k), acr, acritfac)
1185 
1186  IF (wfn <= acr) THEN
1187  cycle !================>>
1188  ENDIF
1189 
1190  wlq = qol(k)
1191  rnn(k) = 0.
1192  cll0(k) = 0.
1193 
1194  DO l=k-1,ic,-1
1195  tem = eta(l) - eta(l+1)
1196  wlq = wlq + tem * qol(l)
1197 
1198  IF (l>ic) THEN
1199  tx2 = 0.5*(qst(l)+qst(l-1))*eta(l)
1200  tx3 = 0.5*(hst(l)+hst(l-1))*eta(l)
1201  qcc = tx2 + gm1(l)*(hcc(l)-tx3)
1202  cll0(l) = (wlq-qcc)
1203  ELSE
1204  cll0(l) = (wlq-qst(ic)*eta(ic))
1205  ENDIF
1206 
1207  cll0(l) = max( cll0(l) , 0.00 )
1208 
1209  cli = cll0(l) / eta(l)
1210  te_a = poi(l)*prh(l)
1211 
1212  CALL sundq3_ice( te_a, sdqv2, sdqv3, sdqvt1, f2 , f3 )
1213 
1214  c00_x = co_auto(i) * f2 * f3 * f4
1215  cli_crit_x = cli_crit / ( f2 * f3 )
1216 
1217  rate = c00_x * ( 1.0 - exp( -(cli)**2 / cli_crit_x**2 ) )
1218 
1219  cvw_x = max( cvw(l) , 1.00 )
1220 
1221  dt_lyr = ( zet(l)-zet(l+1) )/cvw_x
1222 
1223  closs = cll0(l) * rate * dt_lyr
1224  closs = min( closs , cll0(l) )
1225 
1226  cll0(l) = cll0(l) - closs
1227  dll0(l) = closs
1228 
1229  IF (closs>0.) then
1230  wlq = wlq - closs
1231  rnn(l) = closs
1232  else
1233  rnn(l) = 0.
1234  ENDIF
1235 
1236  ENDDO
1237 
1238  wlq = wlq - qst(ic)*eta(ic)
1239 
1240  !CALCULATE GAMMAS AND KERNEL
1241  gms(k) = (sht(k)-ssl(k))*pri(k)
1242  gmh(k) = gms(k) + (qht(k)-qol(k))*pri(k)*alhl
1243  akm = gmh(k)*gam(k-1)*dpb(k-1)
1244 
1245  tx2 = gmh(k)
1246  DO l=k-1,ic+1,-1
1247  gms(l) = ( eta(l )*(sht(l)-ssl(l )) + eta(l+1)*(ssl(l)-sht(l+1)) ) *pri(l)
1248  gmh(l) = gms(l) + ( eta(l )*(qht(l)-qol(l )) + eta(l+1)*(qol(l)-qht(l+1)) )*alhl*pri(l)
1249  tx2 = tx2 + (eta(l) - eta(l+1)) * gmh(l)
1250  akm = akm - gms(l)*eht(l)*pki(l) + tx2*ght(l)
1251  ENDDO
1252 
1253  gms(ic) = eta(ic+1)*(ssl(ic)-sht(ic+1))*pri(ic)
1254  akm = akm - gms(ic)*eta(ic+1)*dpb(ic)*pki(ic)
1255 
1256  gmh(ic) = gms(ic) + ( eta(ic+1)*(qol(ic)-qht(ic+1))*alhl + eta(ic)*(hst(ic)-hol(ic)))*pri(ic)
1257 
1258  !CLOUD BASE MASS FLUX
1259  IF (akm >= 0.0 .OR. wlq < 0.0) THEN
1260  cycle !================>>
1261  ENDIF
1262 
1263  wfn = - (wfn-acr)/akm
1264  wfn = min( ( rasal(ic)*trg*toki )*wfn , (prs(k+1)-prs(k) )*(100.*pblfrac))
1265 
1266  !CUMULATIVE PRECIP AND CLOUD-BASE MASS FLUX FOR OUTPUT
1267  tem = wfn*gravi
1268  cll(ic) = cll(ic) + wlq*tem
1269  rmf(ic) = rmf(ic) + tem
1270  rmfd(ic) = rmfd(ic) + tem * eta(ic)
1271 
1272  DO l=ic+1,k
1273  rmfp(l) = tem * eta(l)
1274  rmfc(l) = rmfc(l) + rmfp(l)
1275 
1276  dllx(l) = dllx(l) + tem*dll0(l)
1277 
1278  IF ( cvw(l) > 0.0 ) THEN
1279  updfrp(l) = rmfp(l) * (ddt/daylen) * 1000. / ( cvw(l) * prs(l) )
1280  ELSE
1281  updfrp(l) = 0.0
1282  ENDIF
1283 
1284  clli(l) = cll0(l)/eta(l)
1285 
1286  updfrc(l) = updfrc(l) + updfrp(l)
1287 
1288  ENDDO
1289 
1290  !THETA AND Q CHANGE DUE TO CLOUD TYPE IC
1291  DO l=ic,k
1292  rns(l) = rns(l) + rnn(l)*tem
1293  gmh(l) = gmh(l) * wfn
1294  gms(l) = gms(l) * wfn
1295  qoi(l) = qoi(l) + (gmh(l) - gms(l)) * alhi
1296  poi(l) = poi(l) + gms(l)*pki(l)*cpi
1297  qst(l) = qst(l) + gms(l)*bet(l)*cpi
1298  ENDDO
1299 
1300  ENDDO !CLOUD LOOP
1301 
1302  IF ( sum( rmf(icmin:k) ) > 0.0 ) THEN
1303 
1304  DO l=icmin,k
1305  tem = pri(l)*grav
1306  cnv_prc3(i,l) = rns(l)*tem
1307  ENDDO
1308 
1309  tho(i,icmin:k-1) = poi(icmin:k-1)
1310  qho(i,icmin:k-1) = qoi(icmin:k-1)
1311  cnv_updfrc(i,icmin:k-1) = updfrc(icmin:k-1)
1312 
1313  !De-strap tendencies from RAS
1314  wght = wgt1(i,:)
1315 
1316  !Scale properly by layer masses
1317  wght0 = 0.
1318  DO l=k,k0
1319  wght0 = wght0 + wght(l)* ( ple(i,l+1) - ple(i,l) )
1320  END DO
1321 
1322  wght0 = ( prs(k+1) - prs(k) )/wght0
1323  wght = wght0 * wght
1324 
1325  DO l=k,k0
1326  tho(i,l) = tho(i,l) + wght(l)*(poi(k) - poi_sv(k))
1327  qho(i,l) = qho(i,l) + wght(l)*(qoi(k) - qoi_sv(k))
1328  END DO
1329 
1330  flxd(i,icmin:k) = rmfd(icmin:k) * ddt/daylen
1331  clw(i,icmin:k) = cll(icmin:k) * ddt/daylen
1332 
1333  flxd(i,1:icmin-1) = 0.
1334  clw(i,1:icmin-1) = 0.
1335 
1336  IF ( k < k0 ) THEN
1337  flxd(i,k:k0) = 0.
1338  clw(i,k:k0) = 0.
1339  END IF
1340 
1341  ELSE
1342 
1343  flxd(i,:) = 0.
1344  clw(i,:) = 0.
1345 
1346  ENDIF
1347 
1348  ELSE
1349 
1350  flxd(i,:) = 0.
1351  clw(i,:) = 0.
1352 
1353  ENDIF
1354 
1355  ENDDO
1356 
1357 END SUBROUTINE rase0
1358 
1359 END MODULE convection
subroutine, public acritn(PL, PLB, ACR, ACRITFAC)
Definition: convection.F90:641
subroutine, public dqsat_ras(DQSi, QSSi, TEMP, PLO, lm, ESTBLX, CONS_H2OMW, CONS_AIRMW)
Definition: convection.F90:706
subroutine, public dqsats_ras(DQSi, QSSi, TEMP, PLO, ESTBLX, CONS_H2OMW, CONS_AIRMW)
Definition: convection.F90:774
subroutine, public rase0(IDIM, IRUN, K0, ICMIN, DT, CONS_CP, CONS_ALHL, CONS_GRAV, CONS_RGAS, CONS_H2OMW, CONS_AIRMW, CONS_VIREPS, SEEDRAS, SIGE, KCBL, WGT0, WGT1, FRLAND, TS, THO, QHO, CO_AUTO, PLE, CLW, FLXD, CNV_PRC3, CNV_UPDFRC, RASPARAMS, ESTBLX)
Definition: convection.F90:843
subroutine, public rase(IDIM, IRUN, K0, ICMIN, DT, CONS_CP, CONS_ALHL, CONS_GRAV, CONS_RGAS, CONS_H2OMW, CONS_AIRMW, CONS_VIREPS, SEEDRAS, SIGE, KCBL, WGT0, WGT1, FRLAND, TS, THO, QHO, UHO, VHO, CO_AUTO, PLE, CLW, FLXD, CNV_PRC3, CNV_UPDFRC, RASPARAMS, ESTBLX)
Definition: convection.F90:19
subroutine, public sundq3_ice(TEMP, RATE2, RATE3, TE1, F2, F3)
Definition: convection.F90:671
#define max(a, b)
Definition: mosaic_util.h:33
#define min(a, b)
Definition: mosaic_util.h:32