FV3DYCORE  Version 2.0.0
fv_sg.F90
Go to the documentation of this file.
1 
2 !***********************************************************************
3 !* GNU Lesser General Public License
4 !*
5 !* This file is part of the FV3 dynamical core.
6 !*
7 !* The FV3 dynamical core is free software: you can redistribute it
8 !* and/or modify it under the terms of the
9 !* GNU Lesser General Public License as published by the
10 !* Free Software Foundation, either version 3 of the License, or
11 !* (at your option) any later version.
12 !*
13 !* The FV3 dynamical core is distributed in the hope that it will be
14 !* useful, but WITHOUT ANYWARRANTY; without even the implied warranty
15 !* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 !* See the GNU General Public License for more details.
17 !*
18 !* You should have received a copy of the GNU Lesser General Public
19 !* License along with the FV3 dynamical core.
20 !* If not, see <http://www.gnu.org/licenses/>.
21 !***********************************************************************
22 
24 
25 ! Modules Included:
26 ! <table>
27 ! <tr>
28 ! <th>Module Name</th>
29 ! <th>Functions Included</th>
30 ! </tr>
31 ! <tr>
32 ! <td>constants_mod</td>
33 ! <td>rdgas, rvgas, cp_air, cp_vapor, hlv, hlf, kappa, grav</td>
34 ! </tr>
35 ! <tr>
36 ! <td>field_manager_mod</td>
37 ! <td>MODEL_ATMOS</td>
38 ! </tr>
39 ! <tr>
40 ! <tr>
41 ! <td>fv_mp_mod</td>
42 ! <td>mp_reduce_min, is_master</td>
43 ! </tr>
44 ! <tr>
45 ! <td>gfdl_cloud_microphys_mod</td>
46 ! <td>wqs1, wqs2, wqsat2_moist</td>
47 ! </tr>
48 ! <tr>
49 ! <td>tracer_manager_mod</td>
50 ! <td>get_tracer_index</td>
51 ! </tr>
52 ! </table>
53 
54 module fv_sg_mod
55 
56 !-----------------------------------------------------------------------
57 ! FV sub-grid mixing
58 !-----------------------------------------------------------------------
59  use constants_mod, only: rdgas, rvgas, cp_air, cp_vapor, hlv, hlf, kappa, grav
60  use tracer_manager_mod, only: get_tracer_index
61  use field_manager_mod, only: model_atmos
62 #ifndef GFS_PHYS
63  use gfdl_cloud_microphys_mod, only: wqs1, wqs2, wqsat2_moist
64 #endif
65  use fv_mp_mod, only: mp_reduce_min, is_master
66 #ifdef MULTI_GASES
68 #endif
69 implicit none
70 private
71 
73 
74  real, parameter:: esl = 0.621971831
75  real, parameter:: tice = 273.16
76 ! real, parameter:: c_ice = 2106. !< \cite emanuel1994atmospheric table, page 566
77  real, parameter:: c_ice = 1972.
78  real, parameter:: c_liq = 4.1855e+3
79 ! real, parameter:: c_liq = 4218. !< ECMWF-IFS
80  real, parameter:: cv_vap = cp_vapor - rvgas
81  real, parameter:: c_con = c_ice
82 
83 ! real, parameter:: dc_vap = cp_vapor - c_liq ! = -2368.
84  real, parameter:: dc_vap = cv_vap - c_liq
85  real, parameter:: dc_ice = c_liq - c_ice
86 ! Values at 0 Deg C
87  real, parameter:: hlv0 = 2.5e6
88  real, parameter:: hlf0 = 3.3358e5
89 ! real, parameter:: hlv0 = 2.501e6 ! \cite emanuel1994atmospheri Appendix-2
90 ! real, parameter:: hlf0 = 3.337e5 ! \cite emanuel1994atmospheri
91  real, parameter:: t_ice = 273.16
92  real, parameter:: ri_max = 1.
93  real, parameter:: ri_min = 0.25
94  real, parameter:: t1_min = 160.
95  real, parameter:: t2_min = 165.
96  real, parameter:: t2_max = 315.
97  real, parameter:: t3_max = 325.
98  real, parameter:: lv0 = hlv0 - dc_vap*t_ice
99  real, parameter:: li0 = hlf0 - dc_ice*t_ice
100 
101  real, parameter:: zvir = rvgas/rdgas - 1.
102  real, allocatable:: table(:),des(:)
103  real:: lv00, d0_vap
104 
105 contains
106 
107 
108 #ifdef GFS_PHYS
109 
113  subroutine fv_subgrid_z( isd, ied, jsd, jed, is, ie, js, je, km, nq, dt, &
114  tau, nwat, delp, pe, peln, pkz, ta, qa, ua, va, &
115  hydrostatic, w, delz, u_dt, v_dt, t_dt, k_bot )
116 ! Dry convective adjustment-mixing
117 !-------------------------------------------
118  integer, intent(in):: is, ie, js, je, km, nq, nwat
119  integer, intent(in):: isd, ied, jsd, jed
120  integer, intent(in):: tau
121  real, intent(in):: dt
122  real, intent(in):: pe(is-1:ie+1,km+1,js-1:je+1)
123  real, intent(in):: peln(is :ie, km+1,js :je)
124  real, intent(in):: delp(isd:ied,jsd:jed,km)
125  real, intent(in):: delz(is:,js:,1:)
126  real, intent(in):: pkz(is:ie,js:je,km)
127  logical, intent(in):: hydrostatic
128  integer, intent(in), optional:: k_bot
129 !
130  real, intent(inout):: ua(isd:ied,jsd:jed,km)
131  real, intent(inout):: va(isd:ied,jsd:jed,km)
132  real, intent(inout):: w(isd:,jsd:,1:)
133  real, intent(inout):: ta(isd:ied,jsd:jed,km)
134  real, intent(inout):: qa(isd:ied,jsd:jed,km,nq)
135  real, intent(inout):: u_dt(isd:ied,jsd:jed,km)
136  real, intent(inout):: v_dt(isd:ied,jsd:jed,km)
137  real, intent(inout):: t_dt(is:ie,js:je,km)
138 !---------------------------Local variables-----------------------------
139  real, dimension(is:ie,km):: u0, v0, w0, t0, hd, te, gz, tvm, pm, den
140  real q0(is:ie,km,nq), qcon(is:ie,km)
141  real, dimension(is:ie):: gzh, lcp2, icp2, cvm, cpm, qs
142 #ifdef MULTI_GASES
143  real :: rkx, rdx, rzx, c_air
144 #endif
145  real ri_ref, ri, pt1, pt2, ratio, tv, cv, tmp, q_liq, q_sol
146  real tv1, tv2, g2, h0, mc, fra, rk, rz, rdt, tvd, tv_surf
147  real dh, dq, qsw, dqsdt, tcp3, t_max, t_min
148  integer i, j, k, kk, n, m, iq, km1, im, kbot, l
149  real, parameter:: ustar2 = 1.e-4
150  real:: cv_air, xvir
151  integer :: sphum, liq_wat, rainwat, snowwat, graupel, ice_wat, cld_amt
152 
153  cv_air = cp_air - rdgas ! = rdgas * (7/2-1) = 2.5*rdgas=717.68
154  rk = cp_air/rdgas + 1.
155  cv = cp_air - rdgas
156 
157  g2 = 0.5*grav
158 
159  rdt = 1./ dt
160  im = ie-is+1
161 
162  if ( present(k_bot) ) then
163  if ( k_bot < 3 ) return
164  kbot = k_bot
165  else
166  kbot = km
167  endif
168  if ( pe(is,1,js) < 2. ) then
169  t_min = t1_min
170  else
171  t_min = t2_min
172  endif
173 
174  if ( k_bot < min(km,24) ) then
175  t_max = t2_max
176  else
177  t_max = t3_max
178  endif
179 
180  sphum = get_tracer_index(model_atmos, 'sphum')
181  if ( nwat == 0 ) then
182  xvir = 0.
183  rz = 0.
184  else
185  xvir = zvir
186  rz = rvgas - rdgas ! rz = zvir * rdgas
187  liq_wat = get_tracer_index(model_atmos, 'liq_wat')
188  ice_wat = get_tracer_index(model_atmos, 'ice_wat')
189  rainwat = get_tracer_index(model_atmos, 'rainwat')
190  snowwat = get_tracer_index(model_atmos, 'snowwat')
191  graupel = get_tracer_index(model_atmos, 'graupel')
192  cld_amt = get_tracer_index(model_atmos, 'cld_amt')
193  endif
194 
195 !------------------------------------------------------------------------
196 ! The nonhydrostatic pressure changes if there is heating (under constant
197 ! volume and mass is locally conserved).
198 !------------------------------------------------------------------------
199  m = 3
200  fra = dt/real(tau)
201 
202 !$OMP parallel do default(none) shared(im,is,ie,js,je,nq,kbot,qa,ta,sphum,ua,va,delp,peln, &
203 !$OMP hydrostatic,pe,delz,g2,w,liq_wat,rainwat,ice_wat, &
204 !$OMP snowwat,cv_air,m,graupel,pkz,rk,rz,fra, t_max, t_min, &
205 #ifdef MULTI_GASES
206 !$OMP u_dt,rdt,v_dt,xvir,nwat,km) &
207 #else
208 !$OMP u_dt,rdt,v_dt,xvir,nwat) &
209 #endif
210 !$OMP private(kk,lcp2,icp2,tcp3,dh,dq,den,qs,qsw,dqsdt,qcon,q0, &
211 !$OMP t0,u0,v0,w0,h0,pm,gzh,tvm,tmp,cpm,cvm,q_liq,q_sol, &
212 #ifdef MULTI_GASES
213 !$OMP rkx,rdx,rzx,c_air, &
214 #endif
215 !$OMP tv,gz,hd,te,ratio,pt1,pt2,tv1,tv2,ri_ref, ri,mc,km1)
216  do 1000 j=js,je
217 
218  do iq=1, nq
219  do k=1,kbot
220  do i=is,ie
221  q0(i,k,iq) = qa(i,j,k,iq)
222  enddo
223  enddo
224  enddo
225 
226  do k=1,kbot
227  do i=is,ie
228  t0(i,k) = ta(i,j,k)
229 #ifdef MULTI_GASES
230  tvm(i,k) = t0(i,k)*virq(q0(i,k,:))
231 #else
232  tvm(i,k) = t0(i,k)*(1.+xvir*q0(i,k,sphum))
233 #endif
234  u0(i,k) = ua(i,j,k)
235  v0(i,k) = va(i,j,k)
236  pm(i,k) = delp(i,j,k)/(peln(i,k+1,j)-peln(i,k,j))
237  enddo
238  enddo
239 
240  do i=is,ie
241  gzh(i) = 0.
242  enddo
243 
244  if( hydrostatic ) then
245  do k=kbot, 1,-1
246  do i=is,ie
247  tv = rdgas*tvm(i,k)
248  den(i,k) = pm(i,k)/tv
249  gz(i,k) = gzh(i) + tv*(1.-pe(i,k,j)/pm(i,k))
250  hd(i,k) = cp_air*tvm(i,k)+gz(i,k)+0.5*(u0(i,k)**2+v0(i,k)**2)
251  gzh(i) = gzh(i) + tv*(peln(i,k+1,j)-peln(i,k,j))
252  enddo
253  enddo
254  else
255  do k=kbot, 1, -1
256  if ( nwat == 0 ) then
257  do i=is,ie
258 #ifdef MULTI_GASES
259  cpm(i) = cp_air*vicpqd(q0(i,k,:))
260  cvm(i) = cv_air*vicvqd(q0(i,k,:))
261 #else
262  cpm(i) = cp_air
263  cvm(i) = cv_air
264 #endif
265  enddo
266  elseif ( nwat==1 ) then
267  do i=is,ie
268 #ifdef MULTI_GASES
269  cpm(i) = (1.-q0(i,k,sphum))*cp_air*vicpqd(q0(i,k,:)) + q0(i,k,sphum)*cp_vapor
270  cvm(i) = (1.-q0(i,k,sphum))*cv_air*vicvqd(q0(i,k,:)) + q0(i,k,sphum)*cv_vap
271 #else
272  cpm(i) = (1.-q0(i,k,sphum))*cp_air + q0(i,k,sphum)*cp_vapor
273  cvm(i) = (1.-q0(i,k,sphum))*cv_air + q0(i,k,sphum)*cv_vap
274 #endif
275  enddo
276  elseif ( nwat==2 ) then ! GFS
277  do i=is,ie
278 #ifdef MULTI_GASES
279  c_air = cp_air*vicpqd(q0(i,k,:))
280  cpm(i) = c_air + (cp_vapor-c_air)*q0(i,k,sphum)/(1.0-q0(i,k,nwat))
281  c_air = cv_air*vicvqd(q0(i,k,:))
282  cvm(i) = c_air + (cv_vap-c_air)*q0(i,k,sphum)/(1.0-q0(i,k,nwat))
283 #else
284  cpm(i) = (1.-q0(i,k,sphum))*cp_air + q0(i,k,sphum)*cp_vapor
285  cvm(i) = (1.-q0(i,k,sphum))*cv_air + q0(i,k,sphum)*cv_vap
286 #endif
287  enddo
288  elseif ( nwat==3 ) then
289  do i=is,ie
290  q_liq = q0(i,k,liq_wat)
291  q_sol = q0(i,k,ice_wat)
292 #ifdef MULTI_GASES
293  cpm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cp_air*vicpqd(q0(i,k,:)) + q0(i,k,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
294  cvm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cv_air*vicvqd(q0(i,k,:)) + q0(i,k,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
295 #else
296  cpm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cp_air + q0(i,k,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
297  cvm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cv_air + q0(i,k,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
298 #endif
299  enddo
300  elseif ( nwat==4 ) then
301  do i=is,ie
302 #ifndef CCPP
303  q_liq = q0(i,k,liq_wat) + q0(i,k,rainwat)
304 #ifdef MULTI_GASES
305  cpm(i) = (1.-(q0(i,k,sphum)+q_liq))*cp_air*vicpqd(q0(i,k,:)) + q0(i,k,sphum)*cp_vapor + q_liq*c_liq
306  cvm(i) = (1.-(q0(i,k,sphum)+q_liq))*cv_air*vicvqd(q0(i,k,:)) + q0(i,k,sphum)*cv_vap + q_liq*c_liq
307 #else
308  cpm(i) = (1.-(q0(i,k,sphum)+q_liq))*cp_air + q0(i,k,sphum)*cp_vapor + q_liq*c_liq
309  cvm(i) = (1.-(q0(i,k,sphum)+q_liq))*cv_air + q0(i,k,sphum)*cv_vap + q_liq*c_liq
310 #endif
311 
312 #else
313  q_liq = q0(i,k,liq_wat) + q0(i,k,rainwat)
314  q_sol = q0(i,k,ice_wat)
315 #ifdef MULTI_GASES
316  cpm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cp_air*vicpqd(q0(i,k,:)) + q0(i,k,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
317  cvm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cv_air*vicvqd(q0(i,k,:)) + q0(i,k,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
318 #else
319  cpm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cp_air + q0(i,k,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
320  cvm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cv_air + q0(i,k,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
321 #endif
322 
323 
324 #endif
325  enddo
326  elseif ( nwat==5 ) then
327  do i=is,ie
328  q_liq = q0(i,k,liq_wat) + q0(i,k,rainwat)
329  q_sol = q0(i,k,ice_wat) + q0(i,k,snowwat)
330 #ifdef MULTI_GASES
331  cpm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cp_air*vicpqd(q0(i,k,:)) + q0(i,k,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
332  cvm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cv_air*vicvqd(q0(i,k,:)) + q0(i,k,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
333 #else
334  cpm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cp_air + q0(i,k,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
335  cvm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cv_air + q0(i,k,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
336 #endif
337  enddo
338  else
339  do i=is,ie
340  q_liq = q0(i,k,liq_wat) + q0(i,k,rainwat)
341  q_sol = q0(i,k,ice_wat) + q0(i,k,snowwat) + q0(i,k,graupel)
342 #ifdef MULTI_GASES
343  cpm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cp_air*vicpqd(q0(i,k,:)) + q0(i,k,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
344  cvm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cv_air*vicvqd(q0(i,k,:)) + q0(i,k,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
345 #else
346  cpm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cp_air + q0(i,k,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
347  cvm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cv_air + q0(i,k,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
348 #endif
349  enddo
350  endif
351 
352  do i=is,ie
353  den(i,k) = -delp(i,j,k)/(grav*delz(i,j,k))
354  w0(i,k) = w(i,j,k)
355  gz(i,k) = gzh(i) - g2*delz(i,j,k)
356  tmp = gz(i,k) + 0.5*(u0(i,k)**2+v0(i,k)**2+w0(i,k)**2)
357  hd(i,k) = cpm(i)*t0(i,k) + tmp
358  te(i,k) = cvm(i)*t0(i,k) + tmp
359  gzh(i) = gzh(i) - grav*delz(i,j,k)
360  enddo
361  enddo
362  endif
363 
364  do n=1,m
365 
366  if ( m==3 ) then
367  if ( n==1) ratio = 0.25
368  if ( n==2) ratio = 0.5
369  if ( n==3) ratio = 0.999
370  else
371  ratio = real(n)/real(m)
372  endif
373 
374  do i=is,ie
375  gzh(i) = 0.
376  enddo
377 
378 ! Compute total condensate
379  if ( nwat<2 ) then
380  do k=1,kbot
381  do i=is,ie
382  qcon(i,k) = 0.
383  enddo
384  enddo
385  elseif ( nwat==2 ) then ! GFS_2015
386  do k=1,kbot
387  do i=is,ie
388  qcon(i,k) = q0(i,k,liq_wat)
389  enddo
390  enddo
391  elseif ( nwat==3 ) then
392  do k=1,kbot
393  do i=is,ie
394  qcon(i,k) = q0(i,k,liq_wat) + q0(i,k,ice_wat)
395  enddo
396  enddo
397  elseif ( nwat==4 ) then
398  do k=1,kbot
399  do i=is,ie
400 #ifndef CCPP
401  qcon(i,k) = q0(i,k,liq_wat) + q0(i,k,rainwat)
402 #else
403  qcon(i,k) = q0(i,k,liq_wat) + q0(i,k,rainwat) + q0(i,k,ice_wat)
404 #endif
405  enddo
406  enddo
407  elseif ( nwat==5 ) then
408  do k=1,kbot
409  do i=is,ie
410  qcon(i,k) = q0(i,k,liq_wat)+q0(i,k,ice_wat)+q0(i,k,snowwat)+q0(i,k,rainwat)
411  enddo
412  enddo
413  else
414  do k=1,kbot
415  do i=is,ie
416  qcon(i,k) = q0(i,k,liq_wat)+q0(i,k,ice_wat)+q0(i,k,snowwat)+q0(i,k,rainwat)+q0(i,k,graupel)
417  enddo
418  enddo
419  endif
420 
421  do k=kbot, 2, -1
422  km1 = k-1
423  do i=is,ie
424 ! Richardson number = g*delz * del_theta/theta / (del_u**2 + del_v**2)
425 ! Use exact form for "density temperature"
426 #ifdef MULTI_GASES
427  tv1 = t0(i,km1)*virq_qpz(q0(i,km1,:),qcon(i,km1))
428  tv2 = t0(i,k )*virq_qpz(q0(i,k, :),qcon(i,k ))
429 #else
430  tv1 = t0(i,km1)*(1.+xvir*q0(i,km1,sphum)-qcon(i,km1))
431  tv2 = t0(i,k )*(1.+xvir*q0(i,k ,sphum)-qcon(i,k))
432 #endif
433  pt1 = tv1 / pkz(i,j,km1)
434  pt2 = tv2 / pkz(i,j,k )
435 !
436  ri = (gz(i,km1)-gz(i,k))*(pt1-pt2)/( 0.5*(pt1+pt2)* &
437  ((u0(i,km1)-u0(i,k))**2+(v0(i,km1)-v0(i,k))**2+ustar2) )
438  if ( tv1>t_max .and. tv1>tv2 ) then
439 ! top layer unphysically warm
440  ri = 0.
441  elseif ( tv2<t_min ) then
442  ri = min(ri, 0.1)
443  endif
444 ! Adjustment for K-H instability:
445 ! Compute equivalent mass flux: mc
446 ! Add moist 2-dz instability consideration:
447 !!! ri_ref = min(ri_max, ri_min + (ri_max-ri_min)*dim(500.e2,pm(i,k))/250.e2 )
448  ri_ref = min(ri_max, ri_min + (ri_max-ri_min)*dim(400.e2,pm(i,k))/200.e2 )
449 ! Enhancing mixing at the model top
450  if ( k==2 ) then
451  ri_ref = 4.*ri_ref
452  elseif ( k==3 ) then
453  ri_ref = 2.*ri_ref
454  elseif ( k==4 ) then
455  ri_ref = 1.5*ri_ref
456  endif
457 
458  if ( ri < ri_ref ) then
459  mc = ratio*delp(i,j,km1)*delp(i,j,k)/(delp(i,j,km1)+delp(i,j,k))*(1.-max(0.0,ri/ri_ref))**2
460  do iq=1,nq
461  h0 = mc*(q0(i,k,iq)-q0(i,km1,iq))
462  q0(i,km1,iq) = q0(i,km1,iq) + h0/delp(i,j,km1)
463  q0(i,k ,iq) = q0(i,k ,iq) - h0/delp(i,j,k )
464  enddo
465 ! Recompute qcon
466  if ( nwat<2 ) then
467  qcon(i,km1) = 0.
468  elseif ( nwat==2 ) then ! GFS_2015
469  qcon(i,km1) = q0(i,km1,liq_wat)
470  elseif ( nwat==3 ) then ! AM3/AM4
471  qcon(i,km1) = q0(i,km1,liq_wat) + q0(i,km1,ice_wat)
472  elseif ( nwat==4 ) then ! K_warm_rain scheme with fake ice
473 #ifndef CCPP
474  qcon(i,km1) = q0(i,km1,liq_wat) + q0(i,km1,rainwat)
475 #else
476  qcon(i,km1) = q0(i,km1,liq_wat) + q0(i,km1,ice_wat) + &
477  q0(i,km1,rainwat)
478 #endif
479  elseif ( nwat==5 ) then ! K_warm_rain scheme with fake ice
480  qcon(i,km1) = q0(i,km1,liq_wat) + q0(i,km1,ice_wat) + &
481  q0(i,km1,snowwat) + q0(i,km1,rainwat)
482  else
483  qcon(i,km1) = q0(i,km1,liq_wat) + q0(i,km1,ice_wat) + &
484  q0(i,km1,snowwat) + q0(i,km1,rainwat) + q0(i,km1,graupel)
485  endif
486 ! u:
487  h0 = mc*(u0(i,k)-u0(i,k-1))
488  u0(i,k-1) = u0(i,k-1) + h0/delp(i,j,k-1)
489  u0(i,k ) = u0(i,k ) - h0/delp(i,j,k )
490 ! v:
491  h0 = mc*(v0(i,k)-v0(i,k-1))
492  v0(i,k-1) = v0(i,k-1) + h0/delp(i,j,k-1)
493  v0(i,k ) = v0(i,k ) - h0/delp(i,j,k )
494 
495  if ( hydrostatic ) then
496 ! Static energy
497  h0 = mc*(hd(i,k)-hd(i,k-1))
498  hd(i,k-1) = hd(i,k-1) + h0/delp(i,j,k-1)
499  hd(i,k ) = hd(i,k ) - h0/delp(i,j,k )
500  else
501 ! Total energy
502  h0 = mc*(hd(i,k)-hd(i,k-1))
503  te(i,k-1) = te(i,k-1) + h0/delp(i,j,k-1)
504  te(i,k ) = te(i,k ) - h0/delp(i,j,k )
505 ! w:
506  h0 = mc*(w0(i,k)-w0(i,k-1))
507  w0(i,k-1) = w0(i,k-1) + h0/delp(i,j,k-1)
508  w0(i,k ) = w0(i,k ) - h0/delp(i,j,k )
509  endif
510  endif
511  enddo
512 
513 !--------------
514 ! Retrive Temp:
515 !--------------
516  if ( hydrostatic ) then
517  kk = k
518  do i=is,ie
519 #ifdef MULTI_GASES
520  rkx = cp_air/rdgas * (vicpqd(q0(i,kk,:))/virqd(q0(i,kk,:))) + 1
521  rdx = rdgas*virqd(q0(i,kk,:))
522  rzx = rvgas - rdx
523  t0(i,kk) = (hd(i,kk)-gzh(i)-0.5*(u0(i,kk)**2+v0(i,kk)**2)) &
524  / ( rkx - pe(i,kk,j)/pm(i,kk) )
525  gzh(i) = gzh(i) + t0(i,kk)*(peln(i,kk+1,j)-peln(i,kk,j))
526  rdx = rdx + rzx*q0(i,kk,sphum)/(1.0-sum(q0(i,kk,sphum+1:sphum+nwat-1)))
527  t0(i,kk) = t0(i,kk) / rdx
528 #else
529  t0(i,kk) = (hd(i,kk)-gzh(i)-0.5*(u0(i,kk)**2+v0(i,kk)**2)) &
530  / ( rk - pe(i,kk,j)/pm(i,kk) )
531  gzh(i) = gzh(i) + t0(i,kk)*(peln(i,kk+1,j)-peln(i,kk,j))
532  t0(i,kk) = t0(i,kk) / ( rdgas + rz*q0(i,kk,sphum) )
533 #endif
534  enddo
535  kk = k-1
536  do i=is,ie
537 #ifdef MULTI_GASES
538  rkx = cp_air/rdgas * (vicpqd(q0(i,kk,:))/virqd(q0(i,kk,:))) + 1
539  rdx = rdgas*virqd(q0(i,kk,:))
540  rzx = rvgas - rdx
541  rdx = rdx + rzx*q0(i,kk,sphum)/(1.0-sum(q0(i,kk,sphum+1:sphum+nwat-1)))
542  t0(i,kk) = (hd(i,kk)-gzh(i)-0.5*(u0(i,kk)**2+v0(i,kk)**2)) &
543  / ((rkx-pe(i,kk,j)/pm(i,kk))*rdx)
544 #else
545  t0(i,kk) = (hd(i,kk)-gzh(i)-0.5*(u0(i,kk)**2+v0(i,kk)**2)) &
546  / ((rk-pe(i,kk,j)/pm(i,kk))*(rdgas+rz*q0(i,kk,sphum)))
547 #endif
548  enddo
549  else
550 ! Non-hydrostatic under constant volume heating/cooling
551  do kk=k-1,k
552  if ( nwat == 0 ) then
553  do i=is,ie
554 #ifdef MULTI_GASES
555  cpm(i) = cp_air*vicpqd(q0(i,kk,:))
556  cvm(i) = cv_air*vicvqd(q0(i,kk,:))
557 #else
558  cpm(i) = cp_air
559  cvm(i) = cv_air
560 #endif
561  enddo
562  elseif ( nwat == 1 ) then
563  do i=is,ie
564 #ifdef MULTI_GASES
565  cpm(i) = (1.-q0(i,kk,sphum))*cp_air*vicpqd(q0(i,kk,:)) + q0(i,kk,sphum)*cp_vapor
566  cvm(i) = (1.-q0(i,kk,sphum))*cv_air*vicvqd(q0(i,kk,:)) + q0(i,kk,sphum)*cv_vap
567 #else
568  cpm(i) = (1.-q0(i,kk,sphum))*cp_air + q0(i,kk,sphum)*cp_vapor
569  cvm(i) = (1.-q0(i,kk,sphum))*cv_air + q0(i,kk,sphum)*cv_vap
570 #endif
571  enddo
572  elseif ( nwat == 2 ) then
573  do i=is,ie
574 #ifdef MULTI_GASES
575  q_liq = q0(i,kk,liq_wat)
576  c_air = cp_air*vicpqd(q0(i,kk,:))
577  cpm(i) = c_air + (cp_vapor-c_air)*q0(i,kk,sphum)/(1.0-q_liq)
578  c_air = cv_air*vicvqd(q0(i,kk,:))
579  cvm(i) = c_air + (cv_vap-c_air)*q0(i,kk,sphum)/(1.0-q_liq)
580 #else
581  cpm(i) = (1.-q0(i,kk,sphum))*cp_air + q0(i,kk,sphum)*cp_vapor
582  cvm(i) = (1.-q0(i,kk,sphum))*cv_air + q0(i,kk,sphum)*cv_vap
583 #endif
584  enddo
585  elseif ( nwat == 3 ) then
586  do i=is,ie
587  q_liq = q0(i,kk,liq_wat)
588  q_sol = q0(i,kk,ice_wat)
589 #ifdef MULTI_GASES
590  cpm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cp_air*vicpqd(q0(i,kk,:)) + q0(i,kk,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
591  cvm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cv_air*vicvqd(q0(i,kk,:)) + q0(i,kk,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
592 #else
593  cpm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cp_air + q0(i,kk,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
594  cvm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cv_air + q0(i,kk,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
595 #endif
596  enddo
597  elseif ( nwat == 4 ) then
598  do i=is,ie
599 #ifndef CCPP
600  q_liq = q0(i,kk,liq_wat) + q0(i,kk,rainwat)
601 #ifdef MULTI_GASES
602  cpm(i) = (1.-(q0(i,kk,sphum)+q_liq))*cp_air*vicpqd(q0(i,kk,:)) + q0(i,kk,sphum)*cp_vapor + q_liq*c_liq
603  cvm(i) = (1.-(q0(i,kk,sphum)+q_liq))*cv_air*vicvqd(q0(i,kk,:)) + q0(i,kk,sphum)*cv_vap + q_liq*c_liq
604 #else
605  cpm(i) = (1.-(q0(i,kk,sphum)+q_liq))*cp_air + q0(i,kk,sphum)*cp_vapor + q_liq*c_liq
606  cvm(i) = (1.-(q0(i,kk,sphum)+q_liq))*cv_air + q0(i,kk,sphum)*cv_vap + q_liq*c_liq
607 #endif
608 #else
609  q_liq = q0(i,kk,liq_wat) + q0(i,kk,rainwat)
610  q_sol = q0(i,kk,ice_wat)
611 #ifdef MULTI_GASES
612  cpm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cp_air*vicpqd(q0(i,kk,:)) + q0(i,kk,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
613  cvm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cv_air*vicvqd(q0(i,kk,:)) + q0(i,kk,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
614 #else
615  cpm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cp_air + q0(i,kk,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
616  cvm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cv_air + q0(i,kk,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
617 #endif
618 
619 
620 #endif
621  enddo
622  elseif ( nwat == 5 ) then
623  do i=is,ie
624  q_liq = q0(i,kk,liq_wat) + q0(i,kk,rainwat)
625  q_sol = q0(i,kk,ice_wat) + q0(i,kk,snowwat)
626 #ifdef MULTI_GASES
627  cpm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cp_air*vicpqd(q0(i,kk,:)) + q0(i,kk,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
628  cvm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cv_air*vicvqd(q0(i,kk,:)) + q0(i,kk,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
629 #else
630  cpm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cp_air + q0(i,kk,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
631  cvm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cv_air + q0(i,kk,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
632 #endif
633  enddo
634  else
635  do i=is,ie
636  q_liq = q0(i,kk,liq_wat) + q0(i,kk,rainwat)
637  q_sol = q0(i,kk,ice_wat) + q0(i,kk,snowwat) + q0(i,kk,graupel)
638 #ifdef MULTI_GASES
639  cpm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cp_air*vicpqd(q0(i,kk,:)) + q0(i,kk,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
640  cvm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cv_air*vicvqd(q0(i,kk,:)) + q0(i,kk,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
641 #else
642  cpm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cp_air + q0(i,kk,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
643  cvm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cv_air + q0(i,kk,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
644 #endif
645  enddo
646  endif
647 
648  do i=is,ie
649  tv = gz(i,kk) + 0.5*(u0(i,kk)**2+v0(i,kk)**2+w0(i,kk)**2)
650  t0(i,kk) = (te(i,kk)- tv) / cvm(i)
651  hd(i,kk) = cpm(i)*t0(i,kk) + tv
652  enddo
653  enddo
654  endif
655  enddo ! k-loop
656  enddo ! n-loop
657 
658 !--------------------
659  if ( fra < 1. ) then
660  do k=1, kbot
661  do i=is,ie
662  t0(i,k) = ta(i,j,k) + (t0(i,k) - ta(i,j,k))*fra
663  u0(i,k) = ua(i,j,k) + (u0(i,k) - ua(i,j,k))*fra
664  v0(i,k) = va(i,j,k) + (v0(i,k) - va(i,j,k))*fra
665  enddo
666  enddo
667 
668  if ( .not. hydrostatic ) then
669  do k=1,kbot
670  do i=is,ie
671  w0(i,k) = w(i,j,k) + (w0(i,k) - w(i,j,k))*fra
672  enddo
673  enddo
674  endif
675 
676  do iq=1,nq
677  do k=1,kbot
678  do i=is,ie
679  q0(i,k,iq) = qa(i,j,k,iq) + (q0(i,k,iq) - qa(i,j,k,iq))*fra
680  enddo
681  enddo
682  enddo
683  endif
684 
685  do k=1,kbot
686  do i=is,ie
687  u_dt(i,j,k) = rdt*(u0(i,k) - ua(i,j,k))
688  v_dt(i,j,k) = rdt*(v0(i,k) - va(i,j,k))
689  ta(i,j,k) = t0(i,k) ! *** temperature updated ***
690 #ifdef GFS_PHYS
691  ua(i,j,k) = u0(i,k)
692  va(i,j,k) = v0(i,k)
693 #endif
694  enddo
695  do iq=1,nq
696  do i=is,ie
697  qa(i,j,k,iq) = q0(i,k,iq)
698  enddo
699  enddo
700  enddo
701 
702  if ( .not. hydrostatic ) then
703  do k=1,kbot
704  do i=is,ie
705  w(i,j,k) = w0(i,k) ! w updated
706  enddo
707  enddo
708  endif
709 
710 1000 continue
711 
712  end subroutine fv_subgrid_z
713 
714 #else
715  subroutine fv_subgrid_z( isd, ied, jsd, jed, is, ie, js, je, km, nq, dt, &
716  tau, nwat, delp, pe, peln, pkz, ta, qa, ua, va, &
717  hydrostatic, w, delz, u_dt, v_dt, t_dt, q_dt, k_bot )
718 ! Dry convective adjustment-mixing
719 !-------------------------------------------
720  integer, intent(in):: is, ie, js, je, km, nq, nwat
721  integer, intent(in):: isd, ied, jsd, jed
722  integer, intent(in):: tau
723  real, intent(in):: dt
724  real, intent(in):: pe(is-1:ie+1,km+1,js-1:je+1)
725  real, intent(in):: peln(is :ie, km+1,js :je)
726  real, intent(in):: delp(isd:ied,jsd:jed,km)
727  real, intent(in):: delz(is:,js:,1:)
728  real, intent(in):: pkz(is:ie,js:je,km)
729  logical, intent(in):: hydrostatic
730  integer, intent(in), optional:: k_bot
731 !
732  real, intent(inout):: ua(isd:ied,jsd:jed,km)
733  real, intent(inout):: va(isd:ied,jsd:jed,km)
734  real, intent(inout):: w(isd:,jsd:,1:)
735  real, intent(inout):: ta(isd:ied,jsd:jed,km)
736  real, intent(inout):: qa(isd:ied,jsd:jed,km,nq)
737  real, intent(inout):: u_dt(isd:ied,jsd:jed,km)
738  real, intent(inout):: v_dt(isd:ied,jsd:jed,km)
739  real, intent(inout):: t_dt(is:ie,js:je,km)
740  real, intent(inout):: q_dt(is:ie,js:je,km,nq)
741 !---------------------------Local variables-----------------------------
742  real, dimension(is:ie,km):: u0, v0, w0, t0, hd, te, gz, tvm, pm, den
743  real q0(is:ie,km,nq), qcon(is:ie,km)
744  real, dimension(is:ie):: gzh, lcp2, icp2, cvm, cpm, qs
745 #ifdef MULTI_GASES
746  real :: rkx, rdx, rzx, c_air
747 #endif
748  real ri_ref, ri, pt1, pt2, ratio, tv, cv, tmp, q_liq, q_sol
749  real tv1, tv2, g2, h0, mc, fra, rk, rz, rdt, tvd, tv_surf
750  real dh, dq, qsw, dqsdt, tcp3
751  integer i, j, k, kk, n, m, iq, km1, im, kbot
752  real, parameter:: ustar2 = 1.e-4
753  real:: cv_air, xvir
754  integer :: sphum, liq_wat, rainwat, snowwat, graupel, ice_wat, cld_amt
755 
756  cv_air = cp_air - rdgas ! = rdgas * (7/2-1) = 2.5*rdgas=717.68
757  rk = cp_air/rdgas + 1.
758  cv = cp_air - rdgas
759 
760  g2 = 0.5*grav
761 
762  rdt = 1./ dt
763  im = ie-is+1
764 
765  if ( present(k_bot) ) then
766  if ( k_bot < 3 ) return
767  kbot = k_bot
768  else
769  kbot = km
770  endif
771 
772  sphum = get_tracer_index(model_atmos, 'sphum')
773  if ( nwat == 0 ) then
774  xvir = 0.
775  rz = 0.
776  else
777  xvir = zvir
778  rz = rvgas - rdgas ! rz = zvir * rdgas
779  liq_wat = get_tracer_index(model_atmos, 'liq_wat')
780  ice_wat = get_tracer_index(model_atmos, 'ice_wat')
781  rainwat = get_tracer_index(model_atmos, 'rainwat')
782  snowwat = get_tracer_index(model_atmos, 'snowwat')
783  graupel = get_tracer_index(model_atmos, 'graupel')
784  cld_amt = get_tracer_index(model_atmos, 'cld_amt')
785  endif
786 
787 !------------------------------------------------------------------------
788 ! The nonhydrostatic pressure changes if there is heating (under constant
789 ! volume and mass is locally conserved).
790 !------------------------------------------------------------------------
791  m = 3
792  fra = dt/real(tau)
793 
794 !$OMP parallel do default(none) shared(im,is,ie,js,je,nq,kbot,qa,ta,sphum,ua,va,delp,peln, &
795 !$OMP hydrostatic,pe,delz,g2,w,liq_wat,rainwat,ice_wat, &
796 !$OMP snowwat,cv_air,m,graupel,pkz,rk,rz,fra,cld_amt, &
797 !$OMP u_dt,rdt,v_dt,xvir,nwat) &
798 !$OMP private(kk,lcp2,icp2,tcp3,dh,dq,den,qs,qsw,dqsdt,qcon,q0, &
799 !$OMP t0,u0,v0,w0,h0,pm,gzh,tvm,tmp,cpm,cvm, q_liq,q_sol,&
800 #ifdef MULTI_GASES
801 !$OMP rkx,rdx,rzx,c_air &
802 #endif
803 !$OMP tv,gz,hd,te,ratio,pt1,pt2,tv1,tv2,ri_ref, ri,mc,km1)
804  do 1000 j=js,je
805 
806  do iq=1, nq
807  do k=1,kbot
808  do i=is,ie
809  q0(i,k,iq) = qa(i,j,k,iq)
810  enddo
811  enddo
812  enddo
813 
814  do k=1,kbot
815  do i=is,ie
816  t0(i,k) = ta(i,j,k)
817 #ifdef MULTI_GASES
818  tvm(i,k) = t0(i,k)*virq(q0(i,k,:))
819 #else
820  tvm(i,k) = t0(i,k)*(1.+xvir*q0(i,k,sphum))
821 #endif
822  u0(i,k) = ua(i,j,k)
823  v0(i,k) = va(i,j,k)
824  pm(i,k) = delp(i,j,k)/(peln(i,k+1,j)-peln(i,k,j))
825  enddo
826  enddo
827 
828  do i=is,ie
829  gzh(i) = 0.
830  enddo
831 
832  if( hydrostatic ) then
833  do k=kbot, 1,-1
834  do i=is,ie
835  tv = rdgas*tvm(i,k)
836  den(i,k) = pm(i,k)/tv
837  gz(i,k) = gzh(i) + tv*(1.-pe(i,k,j)/pm(i,k))
838  hd(i,k) = cp_air*tvm(i,k)+gz(i,k)+0.5*(u0(i,k)**2+v0(i,k)**2)
839  gzh(i) = gzh(i) + tv*(peln(i,k+1,j)-peln(i,k,j))
840  enddo
841  enddo
842  else
843  do k=kbot, 1, -1
844  if ( nwat == 0 ) then
845  do i=is,ie
846 #ifdef MULTI_GASES
847  cpm(i) = cp_air*vicpqd(q0(i,k,:))
848  cvm(i) = cv_air*vicvqd(q0(i,k,:))
849 #else
850  cpm(i) = cp_air
851  cvm(i) = cv_air
852 #endif
853  enddo
854  elseif ( nwat==1 ) then
855  do i=is,ie
856 #ifdef MULTI_GASES
857  cpm(i) = (1.-q0(i,k,sphum))*cp_air*vicpqd(q0(i,k,:)) + q0(i,k,sphum)*cp_vapor
858  cvm(i) = (1.-q0(i,k,sphum))*cv_air*vicvqd(q0(i,k,:)) + q0(i,k,sphum)*cv_vap
859 #else
860  cpm(i) = (1.-q0(i,k,sphum))*cp_air + q0(i,k,sphum)*cp_vapor
861  cvm(i) = (1.-q0(i,k,sphum))*cv_air + q0(i,k,sphum)*cv_vap
862 #endif
863  enddo
864  elseif ( nwat==2 ) then ! GFS
865  do i=is,ie
866  q_sol = q0(i,k,liq_wat)
867 #ifdef MULTI_GASES
868  c_air = cp_air*vicpqd(q0(i,k,:))
869  cpm(i) = c_air + (cp_vapor-c_air)*q0(i,k,sphum)/(1.0-q0(i,k,nwat))
870  c_air = cv_air*vicvqd(q0(i,k,:))
871  cvm(i) = c_air + (cv_vap-c_air)*q0(i,k,sphum)/(1.0-q0(i,k,nwat))
872 #else
873  cpm(i) = (1.-q0(i,k,sphum))*cp_air + q0(i,k,sphum)*cp_vapor
874  cvm(i) = (1.-q0(i,k,sphum))*cv_air + q0(i,k,sphum)*cv_vap
875 #endif
876  enddo
877  elseif ( nwat==3 ) then
878  do i=is,ie
879  q_liq = q0(i,k,liq_wat)
880  q_sol = q0(i,k,ice_wat)
881 #ifdef MULTI_GASES
882  cpm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cp_air*vicpqd(q0(i,k,:)) + q0(i,k,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
883  cvm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cv_air*vicvqd(q0(i,k,:)) + q0(i,k,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
884 #else
885  cpm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cp_air + q0(i,k,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
886  cvm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cv_air + q0(i,k,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
887 #endif
888  enddo
889  elseif ( nwat==4 ) then
890  do i=is,ie
891 #ifndef CCPP
892  q_liq = q0(i,k,liq_wat) + q0(i,k,rainwat)
893 #ifdef MULTI_GASES
894  cpm(i) = (1.-(q0(i,k,sphum)+q_liq))*cp_air*vicpqd(q0(i,k,:)) + q0(i,k,sphum)*cp_vapor + q_liq*c_liq
895  cvm(i) = (1.-(q0(i,k,sphum)+q_liq))*cv_air*vicvqd(q0(i,k,:)) + q0(i,k,sphum)*cv_vap + q_liq*c_liq
896 #else
897  cpm(i) = (1.-(q0(i,k,sphum)+q_liq))*cp_air + q0(i,k,sphum)*cp_vapor + q_liq*c_liq
898  cvm(i) = (1.-(q0(i,k,sphum)+q_liq))*cv_air + q0(i,k,sphum)*cv_vap + q_liq*c_liq
899 #endif
900 #else
901  q_liq = q0(i,k,liq_wat) + q0(i,k,rainwat)
902  q_sol = q0(i,k,ice_wat)
903 #ifdef MULTI_GASES
904  cpm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cp_air*vicpqd(q0(i,k,:)) + q0(i,k,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
905  cvm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cv_air*vicvqd(q0(i,k,:)) + q0(i,k,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
906 #else
907  cpm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cp_air + q0(i,k,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
908  cvm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cv_air + q0(i,k,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
909 #endif
910 
911 #endif
912  enddo
913  elseif ( nwat==5 ) then
914  do i=is,ie
915  q_liq = q0(i,k,liq_wat) + q0(i,k,rainwat)
916  q_sol = q0(i,k,ice_wat) + q0(i,k,snowwat)
917 #ifdef MULTI_GASES
918  cpm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cp_air*vicpqd(q0(i,k,:)) + q0(i,k,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
919  cvm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cv_air*vicvqd(q0(i,k,:)) + q0(i,k,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
920 #else
921  cpm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cp_air + q0(i,k,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
922  cvm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cv_air + q0(i,k,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
923 #endif
924  enddo
925  else
926  do i=is,ie
927  q_liq = q0(i,k,liq_wat) + q0(i,k,rainwat)
928  q_sol = q0(i,k,ice_wat) + q0(i,k,snowwat) + q0(i,k,graupel)
929 #ifdef MULTI_GASES
930  cpm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cp_air*vicpqd(q0(i,k,:)) + q0(i,k,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
931  cvm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cv_air*vicvqd(q0(i,k,:)) + q0(i,k,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
932 #else
933  cpm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cp_air + q0(i,k,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
934  cvm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cv_air + q0(i,k,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
935 #endif
936  enddo
937  endif
938 
939  do i=is,ie
940  den(i,k) = -delp(i,j,k)/(grav*delz(i,j,k))
941  w0(i,k) = w(i,j,k)
942  gz(i,k) = gzh(i) - g2*delz(i,j,k)
943  tmp = gz(i,k) + 0.5*(u0(i,k)**2+v0(i,k)**2+w0(i,k)**2)
944  hd(i,k) = cpm(i)*t0(i,k) + tmp
945  te(i,k) = cvm(i)*t0(i,k) + tmp
946  gzh(i) = gzh(i) - grav*delz(i,j,k)
947  enddo
948  enddo
949  endif
950 
951  do n=1,m
952 
953  if ( m==3 ) then
954  if ( n==1) ratio = 0.25
955  if ( n==2) ratio = 0.5
956  if ( n==3) ratio = 0.999
957  else
958  ratio = real(n)/real(m)
959  endif
960 
961  do i=is,ie
962  gzh(i) = 0.
963  enddo
964 
965 ! Compute total condensate
966  if ( nwat<2 ) then
967  do k=1,kbot
968  do i=is,ie
969  qcon(i,k) = 0.
970  enddo
971  enddo
972  elseif ( nwat==2 ) then ! GFS_2015
973  do k=1,kbot
974  do i=is,ie
975  qcon(i,k) = q0(i,k,liq_wat)
976  enddo
977  enddo
978  elseif ( nwat==3 ) then
979  do k=1,kbot
980  do i=is,ie
981  qcon(i,k) = q0(i,k,liq_wat) + q0(i,k,ice_wat)
982  enddo
983  enddo
984  elseif ( nwat==4 ) then
985  do k=1,kbot
986  do i=is,ie
987 #ifndef CCPP
988  qcon(i,k) = q0(i,k,liq_wat) + q0(i,k,rainwat)
989 #else
990  qcon(i,k) = q0(i,k,liq_wat) + q0(i,k,rainwat) + q0(i,k,ice_wat)
991 #endif
992  enddo
993  enddo
994  elseif ( nwat==5 ) then
995  do k=1,kbot
996  do i=is,ie
997  qcon(i,k) = q0(i,k,liq_wat)+q0(i,k,ice_wat)+q0(i,k,snowwat)+q0(i,k,rainwat)
998  enddo
999  else
1000  do k=1,kbot
1001  do i=is,ie
1002  qcon(i,k) = q0(i,k,liq_wat)+q0(i,k,ice_wat)+q0(i,k,snowwat)+q0(i,k,rainwat)+q0(i,k,graupel)
1003  enddo
1004  enddo
1005  endif
1006 
1007  do k=kbot, 2, -1
1008  km1 = k-1
1009 #ifdef TEST_MQ
1010 #ifdef MULTI_GASES
1011  if(nwat>0) call qsmith(im, km, im, 1, t0(is,km1), pm(is,km1), q0(is,km1,sphum), qs)
1012 #else
1013  if(nwat>0) call qsmith(im, 1, 1, t0(is,km1), pm(is,km1), q0(is,km1,sphum), qs)
1014 #endif
1015 #endif
1016  do i=is,ie
1017 ! Richardson number = g*delz * del_theta/theta / (del_u**2 + del_v**2)
1018 ! Use exact form for "density temperature"
1019 #ifdef MULTI_GASES
1020  tv1 = t0(i,km1)*virq_qpz(q0(i,km1,:),qcon(i,km1))
1021  tv2 = t0(i,k )*virq_qpz(q0(i,k ,:),qcon(i,k ))
1022 #else
1023  tv1 = t0(i,km1)*(1.+xvir*q0(i,km1,sphum)-qcon(i,km1))
1024  tv2 = t0(i,k )*(1.+xvir*q0(i,k ,sphum)-qcon(i,k))
1025 #endif
1026  pt1 = tv1 / pkz(i,j,km1)
1027  pt2 = tv2 / pkz(i,j,k )
1028  ri = (gz(i,km1)-gz(i,k))*(pt1-pt2)/( 0.5*(pt1+pt2)* &
1029  ((u0(i,km1)-u0(i,k))**2+(v0(i,km1)-v0(i,k))**2+ustar2) )
1030 
1031 ! Adjustment for K-H instability:
1032 ! Compute equivalent mass flux: mc
1033 ! Add moist 2-dz instability consideration:
1034  ri_ref = min(ri_max, ri_min + (ri_max-ri_min)*dim(500.e2,pm(i,k))/250.e2 )
1035 #ifdef TEST_MQ
1036  if ( nwat > 0 ) then
1037  h0 = hd(i,k)-hd(i,km1) + hlv0*(q0(i,k,sphum)-qs(i))
1038  if ( h0 > 0. ) ri_ref = 5.*ri_ref
1039  endif
1040 #endif
1041  if ( ri < ri_ref ) then
1042  mc = ratio*delp(i,j,km1)*delp(i,j,k)/(delp(i,j,km1)+delp(i,j,k))*(1.-max(0.0,ri/ri_ref))**2
1043  do iq=1,nq
1044  h0 = mc*(q0(i,k,iq)-q0(i,km1,iq))
1045  q0(i,km1,iq) = q0(i,km1,iq) + h0/delp(i,j,km1)
1046  q0(i,k ,iq) = q0(i,k ,iq) - h0/delp(i,j,k )
1047  enddo
1048 ! Recompute qcon
1049  if ( nwat<2 ) then
1050  qcon(i,km1) = 0.
1051  elseif ( nwat==2 ) then ! GFS_2015
1052  qcon(i,km1) = q0(i,km1,liq_wat)
1053  elseif ( nwat==3 ) then ! AM3/AM4
1054  qcon(i,km1) = q0(i,km1,liq_wat) + q0(i,km1,ice_wat)
1055  elseif ( nwat==4 ) then ! K_warm_rain scheme with fake ice
1056 #ifndef CCPP
1057  qcon(i,km1) = q0(i,km1,liq_wat) + q0(i,km1,rainwat)
1058 #else
1059  qcon(i,km1) = q0(i,km1,liq_wat) + q0(i,km1,rainwat) + q0(i,km1,ice_wat)
1060 #endif
1061  elseif ( nwat==5 ) then
1062  qcon(i,km1) = q0(i,km1,liq_wat) + q0(i,km1,ice_wat) + &
1063  q0(i,km1,snowwat) + q0(i,km1,rainwat)
1064  else
1065  qcon(i,km1) = q0(i,km1,liq_wat) + q0(i,km1,ice_wat) + &
1066  q0(i,km1,snowwat) + q0(i,km1,rainwat) + q0(i,km1,graupel)
1067  endif
1068 ! u:
1069  h0 = mc*(u0(i,k)-u0(i,k-1))
1070  u0(i,k-1) = u0(i,k-1) + h0/delp(i,j,k-1)
1071  u0(i,k ) = u0(i,k ) - h0/delp(i,j,k )
1072 ! v:
1073  h0 = mc*(v0(i,k)-v0(i,k-1))
1074  v0(i,k-1) = v0(i,k-1) + h0/delp(i,j,k-1)
1075  v0(i,k ) = v0(i,k ) - h0/delp(i,j,k )
1076 
1077  if ( hydrostatic ) then
1078 ! Static energy
1079  h0 = mc*(hd(i,k)-hd(i,k-1))
1080  hd(i,k-1) = hd(i,k-1) + h0/delp(i,j,k-1)
1081  hd(i,k ) = hd(i,k ) - h0/delp(i,j,k )
1082  else
1083 ! Total energy
1084  h0 = mc*(hd(i,k)-hd(i,k-1))
1085  te(i,k-1) = te(i,k-1) + h0/delp(i,j,k-1)
1086  te(i,k ) = te(i,k ) - h0/delp(i,j,k )
1087 ! w:
1088  h0 = mc*(w0(i,k)-w0(i,k-1))
1089  w0(i,k-1) = w0(i,k-1) + h0/delp(i,j,k-1)
1090  w0(i,k ) = w0(i,k ) - h0/delp(i,j,k )
1091  endif
1092  endif
1093  enddo
1094 
1095 !--------------
1096 ! Retrive Temp:
1097 !--------------
1098  if ( hydrostatic ) then
1099  kk = k
1100  do i=is,ie
1101 #ifdef MULTI_GASES
1102  rkx = cp_air/rdgas * (vicpqd(q0(i,kk,:))/virqd(q0(i,kk,:))) + 1
1103  rdx = rdgas*virqd(q0(i,kk,:))
1104  rzx = rvgas - rdx
1105  rdx = rdx + rzx*q0(i,kk,sphum)/(1.0-sum(q0(i,kk,sphum+1:sphum+nwat-1)))
1106  t0(i,kk) = (hd(i,kk)-gzh(i)-0.5*(u0(i,kk)**2+v0(i,kk)**2)) &
1107  / ( rkx - pe(i,kk,j)/pm(i,kk) )
1108  gzh(i) = gzh(i) + t0(i,kk)*(peln(i,kk+1,j)-peln(i,kk,j))
1109  t0(i,kk) = t0(i,kk) / ( rdx + rzx*q0(i,kk,sphum) )
1110 #else
1111  t0(i,kk) = (hd(i,kk)-gzh(i)-0.5*(u0(i,kk)**2+v0(i,kk)**2)) &
1112  / ( rk - pe(i,kk,j)/pm(i,kk) )
1113  gzh(i) = gzh(i) + t0(i,kk)*(peln(i,kk+1,j)-peln(i,kk,j))
1114  t0(i,kk) = t0(i,kk) / ( rdgas + rz*q0(i,kk,sphum) )
1115 #endif
1116  enddo
1117  kk = k-1
1118  do i=is,ie
1119 #ifdef MULTI_GASES
1120  rkx = cp_air/rdgas * (vicpqd(q0(i,kk,:))/virqd(q0(i,kk,:))) + 1
1121  rdx = rdgas*virqd(i)
1122  rzx = rvgas - rdx
1123  rdx = rdx + rzx*q0(i,kk,sphum)/(1.0-sum(q0(i,kk,sphum+1:sphum+nwat-1)))
1124  t0(i,kk) = (hd(i,kk)-gzh(i)-0.5*(u0(i,kk)**2+v0(i,kk)**2)) &
1125  / ((rkx-pe(i,kk,j)/pm(i,kk))*rdx)
1126 #else
1127  t0(i,kk) = (hd(i,kk)-gzh(i)-0.5*(u0(i,kk)**2+v0(i,kk)**2)) &
1128  / ((rk-pe(i,kk,j)/pm(i,kk))*(rdgas+rz*q0(i,kk,sphum)))
1129 #endif
1130  enddo
1131  else
1132 ! Non-hydrostatic under constant volume heating/cooling
1133  do kk=k-1,k
1134  if ( nwat == 0 ) then
1135  do i=is,ie
1136 #ifdef MULTI_GASES
1137  cpm(i) = cp_air*vicpqd(q0(i,kk,:))
1138  cvm(i) = cv_air*vicvqd(q0(i,kk,:))
1139 #else
1140  cpm(i) = cp_air
1141  cvm(i) = cv_air
1142 #endif
1143  enddo
1144  elseif ( nwat == 1 ) then
1145  do i=is,ie
1146 #ifdef MULTI_GASES
1147  cpm(i) = (1.-q0(i,kk,sphum))*cp_air*vicpqd(q0(i,kk,:)) + q0(i,kk,sphum)*cp_vapor
1148  cvm(i) = (1.-q0(i,kk,sphum))*cv_air*vicvqd(q0(i,kk,:)) + q0(i,kk,sphum)*cv_vap
1149 #else
1150  cpm(i) = (1.-q0(i,kk,sphum))*cp_air + q0(i,kk,sphum)*cp_vapor
1151  cvm(i) = (1.-q0(i,kk,sphum))*cv_air + q0(i,kk,sphum)*cv_vap
1152 #endif
1153  enddo
1154  elseif ( nwat == 2 ) then
1155  do i=is,ie
1156 #ifdef MULTI_GASES
1157  c_air = cp_air*vicpqd(q0(i,kk,:))
1158  cpm(i) = c_air+(cp_vapor-c_air)*q0(i,kk,sphum)/(1.0-q0(i,kk,sphum+nwat-1))
1159  c_air = cv_air*vicvqd(q0(i,kk,:))
1160  cvm(i) = c_air+(cv_vap -c_air)*q0(i,kk,sphum)/(1.0-q0(i,kk,sphum+nwat-1))
1161 #else
1162  cpm(i) = (1.-q0(i,kk,sphum))*cp_air + q0(i,kk,sphum)*cp_vapor
1163  cvm(i) = (1.-q0(i,kk,sphum))*cv_air + q0(i,kk,sphum)*cv_vap
1164 #endif
1165  enddo
1166  elseif ( nwat == 3 ) then
1167  do i=is,ie
1168  q_liq = q0(i,kk,liq_wat)
1169  q_sol = q0(i,kk,ice_wat)
1170 #ifdef MULTI_GASES
1171  cpm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cp_air*vicpqd(q0(i,kk,:)) + q0(i,kk,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
1172  cvm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cv_air*vicvqd(q0(i,kk,:)) + q0(i,kk,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
1173 #else
1174  cpm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cp_air + q0(i,kk,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
1175  cvm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cv_air + q0(i,kk,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
1176 #endif
1177  enddo
1178  elseif ( nwat == 4 ) then
1179  do i=is,ie
1180 #ifndef CCPP
1181  q_liq = q0(i,kk,liq_wat) + q0(i,kk,rainwat)
1182 #ifdef MULTI_GASES
1183  cpm(i) = (1.-(q0(i,kk,sphum)+q_liq))*cp_air*vicpqd(q0(i,kk,:)) + q0(i,kk,sphum)*cp_vapor + q_liq*c_liq
1184  cvm(i) = (1.-(q0(i,kk,sphum)+q_liq))*cv_air*vicvqd(q0(i,kk,:)) + q0(i,kk,sphum)*cv_vap + q_liq*c_liq
1185 #else
1186  cpm(i) = (1.-(q0(i,kk,sphum)+q_liq))*cp_air + q0(i,kk,sphum)*cp_vapor + q_liq*c_liq
1187  cvm(i) = (1.-(q0(i,kk,sphum)+q_liq))*cv_air + q0(i,kk,sphum)*cv_vap + q_liq*c_liq
1188 #endif
1189 #else
1190  q_liq = q0(i,kk,liq_wat) + q0(i,kk,rainwat)
1191  q_sol = q0(i,kk,ice_wat)
1192 #ifdef MULTI_GASES
1193  cpm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cp_air*vicpqd(q0(i,kk,:)) + q0(i,kk,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
1194  cvm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cv_air*vicvqd(q0(i,kk,:)) + q0(i,kk,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
1195 #else
1196  cpm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cp_air + q0(i,kk,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
1197  cvm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cv_air + q0(i,kk,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
1198 #endif
1199 
1200 #endif
1201  enddo
1202  elseif ( nwat == 5 ) then
1203  do i=is,ie
1204  q_liq = q0(i,kk,liq_wat) + q0(i,kk,rainwat)
1205  q_sol = q0(i,kk,ice_wat) + q0(i,kk,snowwat)
1206 #ifdef MULTI_GASES
1207  cpm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cp_air*vicpqd(q0(i,kk,:)) + q0(i,kk,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
1208  cvm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cv_air*vicvqd(q0(i,kk,:)) + q0(i,kk,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
1209 #else
1210  cpm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cp_air + q0(i,kk,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
1211  cvm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cv_air + q0(i,kk,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
1212 #endif
1213  enddo
1214  else
1215  do i=is,ie
1216  q_liq = q0(i,kk,liq_wat) + q0(i,kk,rainwat)
1217  q_sol = q0(i,kk,ice_wat) + q0(i,kk,snowwat) + q0(i,kk,graupel)
1218 #ifdef MULTI_GASES
1219  cpm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cp_air*vicpqd(q0(i,kk,:)) + q0(i,kk,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
1220  cvm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cv_air*vicvqd(q0(i,kk,:)) + q0(i,kk,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
1221 #else
1222  cpm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cp_air + q0(i,kk,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
1223  cvm(i) = (1.-(q0(i,kk,sphum)+q_liq+q_sol))*cv_air + q0(i,kk,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
1224 #endif
1225  enddo
1226  endif
1227 
1228 
1229  do i=is,ie
1230  tv = gz(i,kk) + 0.5*(u0(i,kk)**2+v0(i,kk)**2+w0(i,kk)**2)
1231  t0(i,kk) = (te(i,kk)- tv) / cvm(i)
1232  hd(i,kk) = cpm(i)*t0(i,kk) + tv
1233  enddo
1234  enddo
1235  endif
1236  enddo ! k-loop
1237  enddo ! n-loop
1238 
1239 !--------------------
1240  if ( fra < 1. ) then
1241  do k=1, kbot
1242  do i=is,ie
1243  t0(i,k) = ta(i,j,k) + (t0(i,k) - ta(i,j,k))*fra
1244  u0(i,k) = ua(i,j,k) + (u0(i,k) - ua(i,j,k))*fra
1245  v0(i,k) = va(i,j,k) + (v0(i,k) - va(i,j,k))*fra
1246  enddo
1247  enddo
1248 
1249  if ( .not. hydrostatic ) then
1250  do k=1,kbot
1251  do i=is,ie
1252  w0(i,k) = w(i,j,k) + (w0(i,k) - w(i,j,k))*fra
1253  enddo
1254  enddo
1255  endif
1256 
1257  do iq=1,nq
1258  do k=1,kbot
1259  do i=is,ie
1260  q0(i,k,iq) = qa(i,j,k,iq) + (q0(i,k,iq) - qa(i,j,k,iq))*fra
1261  enddo
1262  enddo
1263  enddo
1264  endif
1265 
1266 !----------------------
1267 ! Saturation adjustment
1268 !----------------------
1269 #ifndef GFS_PHYS
1270  if ( nwat > 5 ) then
1271  do k=1, kbot
1272  if ( hydrostatic ) then
1273  do i=is, ie
1274 ! Compute pressure hydrostatically
1275 #ifdef MULTI_GASES
1276  den(i,k) = pm(i,k)/(rdgas*t0(i,k)*virq(q0(i,k,:)))
1277 #else
1278  den(i,k) = pm(i,k)/(rdgas*t0(i,k)*(1.+xvir*q0(i,k,sphum)))
1279 #endif
1280  q_liq = q0(i,k,liq_wat) + q0(i,k,rainwat)
1281  q_sol = q0(i,k,ice_wat) + q0(i,k,snowwat) + q0(i,k,graupel)
1282 #ifdef MULTI_GASES
1283  cpm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cp_air*vicpqd(q0(i,k,:)) + q0(i,k,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
1284 #else
1285  cpm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cp_air + q0(i,k,sphum)*cp_vapor + q_liq*c_liq + q_sol*c_ice
1286 #endif
1287  lcp2(i) = hlv / cpm(i)
1288  icp2(i) = hlf / cpm(i)
1289  enddo
1290  else
1291  do i=is, ie
1292  den(i,k) = -delp(i,j,k)/(grav*delz(i,j,k))
1293  q_liq = q0(i,k,liq_wat) + q0(i,k,rainwat)
1294  q_sol = q0(i,k,ice_wat) + q0(i,k,snowwat) + q0(i,k,graupel)
1295 #ifdef MULTI_GASES
1296  cvm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cv_air*vicvqd(q0(i,k,:)) + q0(i,k,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
1297 #else
1298  cvm(i) = (1.-(q0(i,k,sphum)+q_liq+q_sol))*cv_air + q0(i,k,sphum)*cv_vap + q_liq*c_liq + q_sol*c_ice
1299 #endif
1300  lcp2(i) = (lv0+dc_vap*t0(i,k)) / cvm(i)
1301  icp2(i) = (li0+dc_ice*t0(i,k)) / cvm(i)
1302  enddo
1303  endif
1304 
1305 ! Prevent super saturation over water:
1306  do i=is, ie
1307  qsw = wqs2(t0(i,k), den(i,k), dqsdt)
1308  dq = q0(i,k,sphum) - qsw
1309  if ( dq > 0. ) then ! remove super-saturation
1310  tcp3 = lcp2(i) + icp2(i)*min(1., dim(tice,t0(i,k))/40.)
1311  tmp = dq/(1.+tcp3*dqsdt)
1312  t0(i,k) = t0(i,k) + tmp*lcp2(i)
1313  q0(i,k, sphum) = q0(i,k, sphum) - tmp
1314  q0(i,k,liq_wat) = q0(i,k,liq_wat) + tmp
1315 ! Grid box mean is saturated; 50% or higher cloud cover
1316  if (cld_amt .gt. 0) then
1317  qa(i,j,k,cld_amt) = max(0.5, min(1., qa(i,j,k,cld_amt)+25.*tmp/qsw))
1318  end if
1319  endif
1320 ! Freezing
1321  tmp = tice-40. - t0(i,k)
1322  if( tmp>0.0 .and. q0(i,k,liq_wat)>0. ) then
1323  dh = min( q0(i,k,liq_wat), q0(i,k,liq_wat)*tmp*0.125, tmp/icp2(i) )
1324  q0(i,k,liq_wat) = q0(i,k,liq_wat) - dh
1325  q0(i,k,ice_wat) = q0(i,k,ice_wat) + dh
1326  t0(i,k) = t0(i,k) + dh*icp2(i)
1327  endif
1328  enddo
1329  enddo
1330  endif
1331 #endif
1332 
1333  do k=1,kbot
1334  do i=is,ie
1335  u_dt(i,j,k) = rdt*(u0(i,k) - ua(i,j,k))
1336  v_dt(i,j,k) = rdt*(v0(i,k) - va(i,j,k))
1337  ta(i,j,k) = t0(i,k) ! *** temperature updated ***
1338 #ifdef GFS_PHYS
1339  ua(i,j,k) = u0(i,k)
1340  va(i,j,k) = v0(i,k)
1341 #endif
1342  enddo
1343  do iq=1,nq
1344  if (iq .ne. cld_amt ) then
1345  do i=is,ie
1346  qa(i,j,k,iq) = q0(i,k,iq)
1347  enddo
1348  endif
1349  enddo
1350  enddo
1351 
1352  if ( .not. hydrostatic ) then
1353  do k=1,kbot
1354  do i=is,ie
1355  w(i,j,k) = w0(i,k) ! w updated
1356  enddo
1357  enddo
1358  endif
1359 
1360 1000 continue
1361 
1362 
1363  end subroutine fv_subgrid_z
1364 #endif
1365 
1366 
1367  subroutine qsmith_init
1368  integer, parameter:: length=2621
1369  integer i
1370 
1371  if( .not. allocated(table) ) then
1372 ! Generate es table (dT = 0.1 deg. C)
1373 
1374  allocate ( table(length) )
1375  allocate ( des(length) )
1376 
1377  call qs_table(length, table)
1378 
1379  do i=1,length-1
1380  des(i) = table(i+1) - table(i)
1381  enddo
1382  des(length) = des(length-1)
1383  endif
1384 
1385  end subroutine qsmith_init
1386 
1387 
1388 #ifdef MULTI_GASES
1389  subroutine qsmith(im, km, imx, kmx, t, p, q, qs, dqdt)
1390 #else
1391  subroutine qsmith(im, km, k1, t, p, q, qs, dqdt)
1392 #endif
1393 ! input T in deg K; p (Pa)
1394  real, intent(in),dimension(im,km):: t, p
1395 #ifdef MULTI_GASES
1396  real, intent(in),dimension(im,km,*):: q
1397  integer, intent(in):: im, km, imx, kmx
1398 #else
1399  integer, intent(in):: im, km, k1
1400  real, intent(in),dimension(im,km):: q
1401 #endif
1402  real, intent(out),dimension(im,km):: qs
1403  real, intent(out), optional:: dqdt(im,km)
1404 ! Local:
1405  real es(im,km)
1406  real ap1, eps10
1407  real Tmin
1408  integer i, k, it, n
1409 
1410  tmin = tice-160.
1411  eps10 = 10.*esl
1412 
1413  if( .not. allocated(table) ) call qsmith_init
1414 
1415 #ifdef MULTI_GASES
1416  do k=1,kmx
1417  do i=1,imx
1418 #else
1419  do k=k1,km
1420  do i=1,im
1421 #endif
1422  ap1 = 10.*dim(t(i,k), tmin) + 1.
1423  ap1 = min(2621., ap1)
1424  it = ap1
1425  es(i,k) = table(it) + (ap1-it)*des(it)
1426 #ifdef MULTI_GASES
1427  qs(i,k) = esl*es(i,k)*virq(q(i,k,1:num_gas))/p(i,k)
1428 #else
1429  qs(i,k) = esl*es(i,k)*(1.+zvir*q(i,k))/p(i,k)
1430 #endif
1431  enddo
1432  enddo
1433 
1434  if ( present(dqdt) ) then
1435 #ifdef MULTI_GASES
1436  do k=1,kmx
1437  do i=1,imx
1438 #else
1439  do k=k1,km
1440  do i=1,im
1441 #endif
1442  ap1 = 10.*dim(t(i,k), tmin) + 1.
1443  ap1 = min(2621., ap1) - 0.5
1444  it = ap1
1445 #ifdef MULTI_GASES
1446  dqdt(i,k) = eps10*(des(it)+(ap1-it)*(des(it+1)-des(it)))*virq(q(i,k,1:num_gas))/p(i,k)
1447 #else
1448  dqdt(i,k) = eps10*(des(it)+(ap1-it)*(des(it+1)-des(it)))*(1.+zvir*q(i,k))/p(i,k)
1449 #endif
1450  enddo
1451  enddo
1452  endif
1453 
1454  end subroutine qsmith
1455 
1456 
1457  subroutine qs_table(n,table)
1458  integer, intent(in):: n
1459  real table (n)
1460  real:: dt=0.1
1461  real esbasw, tbasw, esbasi, tbasi, Tmin, tem, aa, b, c, d, e, esh20
1462  real wice, wh2o
1463  integer i
1464 ! Constants
1465  esbasw = 1013246.0
1466  tbasw = 373.16
1467  tbasi = 273.16
1468  tmin = tbasi - 160.
1469 ! Compute es over water
1470 ! see smithsonian meteorological tables page 350.
1471  do i=1,n
1472  tem = tmin+dt*real(i-1)
1473  aa = -7.90298*(tbasw/tem-1)
1474  b = 5.02808*alog10(tbasw/tem)
1475  c = -1.3816e-07*(10**((1-tem/tbasw)*11.344)-1)
1476  d = 8.1328e-03*(10**((tbasw/tem-1)*(-3.49149))-1)
1477  e = alog10(esbasw)
1478  table(i) = 0.1*10**(aa+b+c+d+e)
1479  enddo
1480 
1481  end subroutine qs_table
1482 
1483  subroutine qs_table_m(n,table)
1484 ! Mixed (blended) table
1485  integer, intent(in):: n
1486  real table (n)
1487  real esupc(200)
1488  real:: dt=0.1
1489  real esbasw, tbasw, esbasi, tbasi, Tmin, tem, aa, b, c, d, e, esh20
1490  real wice, wh2o
1491  integer i
1492 
1493 ! Constants
1494  esbasw = 1013246.0
1495  tbasw = 373.16
1496  esbasi = 6107.1
1497  tbasi = 273.16
1498 ! ****************************************************
1499 ! Compute es over ice between -160c and 0 c.
1500  tmin = tbasi - 160.
1501 ! see smithsonian meteorological tables page 350.
1502  do i=1,1600
1503  tem = tmin+dt*real(i-1)
1504  aa = -9.09718 *(tbasi/tem-1.0)
1505  b = -3.56654 *alog10(tbasi/tem)
1506  c = 0.876793*(1.0-tem/tbasi)
1507  e = alog10(esbasi)
1508  table(i)=10**(aa+b+c+e)
1509  enddo
1510 ! *****************************************************
1511 ! Compute es over water between -20c and 102c.
1512 ! see smithsonian meteorological tables page 350.
1513  do i=1,1221
1514  tem = 253.16+dt*real(i-1)
1515  aa = -7.90298*(tbasw/tem-1)
1516  b = 5.02808*alog10(tbasw/tem)
1517  c = -1.3816e-07*(10**((1-tem/tbasw)*11.344)-1)
1518  d = 8.1328e-03*(10**((tbasw/tem-1)*(-3.49149))-1)
1519  e = alog10(esbasw)
1520  esh20 = 10**(aa+b+c+d+e)
1521  if (i <= 200) then
1522  esupc(i) = esh20
1523  else
1524  table(i+1400) = esh20
1525  endif
1526  enddo
1527 !********************************************************************
1528 ! Derive blended es over ice and supercooled water between -20c and 0c
1529  do i=1,200
1530  tem = 253.16+dt*real(i-1)
1531  wice = 0.05*(273.16-tem)
1532  wh2o = 0.05*(tem-253.16)
1533  table(i+1400) = wice*table(i+1400)+wh2o*esupc(i)
1534  enddo
1535 
1536  do i=1,n
1537  table(i) = table(i)*0.1
1538  enddo
1539 
1540  end subroutine qs_table_m
1541 
1542  subroutine neg_adj3(is, ie, js, je, ng, kbot, hydrostatic, peln, delz, pt, dp, &
1543 #ifdef MULTI_GASES
1544  qvi, &
1545 #else
1546  qv, &
1547 #endif
1548  ql, qr, qi, qs, qg, qa, check_negative)
1550 ! This is designed for 6-class micro-physics schemes
1551  integer, intent(in):: is, ie, js, je, ng, kbot
1552  logical, intent(in):: hydrostatic
1553  real, intent(in):: dp(is-ng:ie+ng,js-ng:je+ng,kbot)
1554  real, intent(in):: delz(is:,js:,1:)
1555  real, intent(in):: peln(is:ie,kbot+1,js:je)
1556  logical, intent(in), OPTIONAL :: check_negative
1557 #ifdef MULTI_GASES
1558  real, intent(inout), dimension(is-ng:ie+ng,js-ng:je+ng,kbot,*):: qvi
1559 #else
1560  real, intent(inout), dimension(is-ng:ie+ng,js-ng:je+ng,kbot):: qv
1561 #endif
1562  real, intent(inout), dimension(is-ng:ie+ng,js-ng:je+ng,kbot):: &
1563  pt, ql, qr, qi, qs, qg
1564  real, intent(inout), OPTIONAL, dimension(is-ng:ie+ng,js-ng:je+ng,kbot):: qa
1565 ! Local:
1566  logical:: sat_adj = .false.
1567  real, parameter :: t48 = tice - 48.
1568 #ifdef MULTI_GASES
1569  real, dimension(is-ng:ie+ng,js-ng:je+ng,kbot):: qv
1570 #endif
1571  real, dimension(is:ie,kbot):: dpk, q2
1572  real, dimension(is:ie,js:je):: pt2, qv2, ql2, qi2, qs2, qr2, qg2, dp2, p2, icpk, lcpk
1573  real:: cv_air
1574  real:: dq, qsum, dq1, q_liq, q_sol, cpm, sink, qsw, dwsdt
1575  integer i, j, k
1576 
1577  cv_air = cp_air - rdgas ! = rdgas * (7/2-1) = 2.5*rdgas=717.68
1578 
1579 #ifdef MULTI_GASES
1580  qv(:,:,:) = qvi(:,:,:,1)
1581 #endif
1582 
1583  if ( present(check_negative) ) then
1584  if ( check_negative ) then
1585  call prt_negative('Temperature', pt, is, ie, js, je, ng, kbot, 165.)
1586  call prt_negative('sphum', qv, is, ie, js, je, ng, kbot, -1.e-8)
1587  call prt_negative('liq_wat', ql, is, ie, js, je, ng, kbot, -1.e-7)
1588  call prt_negative('rainwat', qr, is, ie, js, je, ng, kbot, -1.e-7)
1589  call prt_negative('ice_wat', qi, is, ie, js, je, ng, kbot, -1.e-7)
1590  call prt_negative('snowwat', qs, is, ie, js, je, ng, kbot, -1.e-7)
1591  call prt_negative('graupel', qg, is, ie, js, je, ng, kbot, -1.e-7)
1592 #ifdef MULTI_GASES
1593  qvi(:,:,:,1) = qv(:,:,:)
1594 #endif
1595  endif
1596  endif
1597 
1598  if ( hydrostatic ) then
1599  d0_vap = cp_vapor - c_liq
1600  else
1601  d0_vap = cv_vap - c_liq
1602  endif
1603  lv00 = hlv0 - d0_vap*t_ice
1604 
1605 !$OMP parallel do default(none) shared(is,ie,js,je,kbot,qv,ql,qi,qs,qr,qg,dp,pt, &
1606 #ifdef MULTI_GASES
1607 !$OMP qvi, num_gas, &
1608 #endif
1609 !$OMP lv00, d0_vap,hydrostatic,peln,delz,cv_air,sat_adj) &
1610 !$OMP private(dq,dq1,qsum,dp2,p2,pt2,qv2,ql2,qi2,qs2,qg2,qr2, &
1611 !$OMP lcpk,icpk,qsw,dwsdt,sink,q_liq,q_sol,cpm)
1612  do k=1, kbot
1613  do j=js, je
1614  do i=is, ie
1615  qv2(i,j) = qv(i,j,k)
1616  ql2(i,j) = ql(i,j,k)
1617  qi2(i,j) = qi(i,j,k)
1618  qs2(i,j) = qs(i,j,k)
1619  qr2(i,j) = qr(i,j,k)
1620  qg2(i,j) = qg(i,j,k)
1621  dp2(i,j) = dp(i,j,k)
1622  pt2(i,j) = pt(i,j,k)
1623  enddo
1624  enddo
1625 
1626  if ( hydrostatic ) then
1627  do j=js, je
1628  do i=is, ie
1629  p2(i,j) = dp2(i,j)/(peln(i,k+1,j)-peln(i,k,j))
1630  q_liq = max(0., ql2(i,j) + qr2(i,j))
1631  q_sol = max(0., qi2(i,j) + qs2(i,j))
1632 #ifdef MULTI_GASES
1633  cpm = (1.-(qv2(i,j)+q_liq+q_sol))*cp_air*vicpqd_qpz(qvi(i,j,k,1:num_gas),qv2(i,j)+q_liq+q_sol) + &
1634  qv2(i,j)*cp_vapor + q_liq*c_liq + q_sol*c_ice
1635 #else
1636  cpm = (1.-(qv2(i,j)+q_liq+q_sol))*cp_air + qv2(i,j)*cp_vapor + q_liq*c_liq + q_sol*c_ice
1637 #endif
1638  lcpk(i,j) = hlv / cpm
1639  icpk(i,j) = hlf / cpm
1640  enddo
1641  enddo
1642  else
1643  do j=js, je
1644  do i=is, ie
1645  q_liq = max(0., ql2(i,j) + qr2(i,j))
1646  q_sol = max(0., qi2(i,j) + qs2(i,j))
1647 #ifdef MULTI_GASES
1648  p2(i,j) = -dp2(i,j)/(grav*delz(i,j,k))*rdgas*pt2(i,j)*virq(qvi(i,j,k,1:num_gas))
1649  cpm = (1.-(qv2(i,j)+q_liq+q_sol))*cv_air*vicvqd_qpz(qvi(i,j,k,1:num_gas),qv2(i,j)+q_liq+q_sol) + &
1650  qv2(i,j)*cv_vap + q_liq*c_liq + q_sol*c_ice
1651 #else
1652  p2(i,j) = -dp2(i,j)/(grav*delz(i,j,k))*rdgas*pt2(i,j)*(1.+zvir*qv2(i,j))
1653  cpm = (1.-(qv2(i,j)+q_liq+q_sol))*cv_air + qv2(i,j)*cv_vap + q_liq*c_liq + q_sol*c_ice
1654 #endif
1655  lcpk(i,j) = (lv00+d0_vap*pt2(i,j)) / cpm
1656  icpk(i,j) = (li0+dc_ice*pt2(i,j)) / cpm
1657  enddo
1658  enddo
1659  endif
1660 
1661 ! Fix the negatives:
1662 !-----------
1663 ! Ice-phase:
1664 !-----------
1665  do j=js, je
1666  do i=is, ie
1667  qsum = qi2(i,j) + qs2(i,j)
1668  if ( qsum > 0. ) then
1669  if ( qi2(i,j) < 0. ) then
1670  qi2(i,j) = 0.
1671  qs2(i,j) = qsum
1672  elseif ( qs2(i,j) < 0. ) then
1673  qs2(i,j) = 0.
1674  qi2(i,j) = qsum
1675  endif
1676  else
1677 ! borrow froom graupel
1678  qi2(i,j) = 0.
1679  qs2(i,j) = 0.
1680  qg2(i,j) = qg2(i,j) + qsum
1681  endif
1682 
1683 ! At this stage qi and qs should be positive definite
1684 ! If graupel < 0 then borrow from qs then qi
1685  if ( qg2(i,j) < 0. ) then
1686  dq = min( qs2(i,j), -qg2(i,j) )
1687  qs2(i,j) = qs2(i,j) - dq
1688  qg2(i,j) = qg2(i,j) + dq
1689  if ( qg2(i,j) < 0. ) then
1690 ! if qg is still negative
1691  dq = min( qi2(i,j), -qg2(i,j) )
1692  qi2(i,j) = qi2(i,j) - dq
1693  qg2(i,j) = qg2(i,j) + dq
1694  endif
1695  endif
1696 
1697 ! If qg is still negative then borrow from rain water: phase change
1698  if ( qg2(i,j)<0. .and. qr2(i,j)>0. ) then
1699  dq = min( qr2(i,j), -qg2(i,j) )
1700  qg2(i,j) = qg2(i,j) + dq
1701  qr2(i,j) = qr2(i,j) - dq
1702  pt2(i,j) = pt2(i,j) + dq*icpk(i,j) ! conserve total energy
1703  endif
1704 ! If qg is still negative then borrow from cloud water: phase change
1705  if ( qg2(i,j)<0. .and. ql2(i,j)>0. ) then
1706  dq = min( ql2(i,j), -qg2(i,j) )
1707  qg2(i,j) = qg2(i,j) + dq
1708  ql2(i,j) = ql2(i,j) - dq
1709  pt2(i,j) = pt2(i,j) + dq*icpk(i,j)
1710  endif
1711 ! Last resort; borrow from water vapor
1712  if ( qg2(i,j)<0. .and. qv2(i,j)>0. ) then
1713  dq = min( 0.999*qv2(i,j), -qg2(i,j) )
1714  qg2(i,j) = qg2(i,j) + dq
1715  qv2(i,j) = qv2(i,j) - dq
1716  pt2(i,j) = pt2(i,j) + dq*(icpk(i,j)+lcpk(i,j))
1717  endif
1718 
1719 !--------------
1720 ! Liquid phase:
1721 !--------------
1722  qsum = ql2(i,j) + qr2(i,j)
1723  if ( qsum > 0. ) then
1724  if ( qr2(i,j) < 0. ) then
1725  qr2(i,j) = 0.
1726  ql2(i,j) = qsum
1727  elseif ( ql2(i,j) < 0. ) then
1728  ql2(i,j) = 0.
1729  qr2(i,j) = qsum
1730  endif
1731  else
1732  ql2(i,j) = 0.
1733  qr2(i,j) = qsum ! rain water is still negative
1734 ! fill negative rain with qg first
1735  dq = min( max(0.0, qg2(i,j)), -qr2(i,j) )
1736  qr2(i,j) = qr2(i,j) + dq
1737  qg2(i,j) = qg2(i,j) - dq
1738  pt2(i,j) = pt2(i,j) - dq*icpk(i,j)
1739  if ( qr(i,j,k) < 0. ) then
1740 ! fill negative rain with available qi & qs (cooling)
1741  dq = min( qi2(i,j)+qs2(i,j), -qr2(i,j) )
1742  qr2(i,j) = qr2(i,j) + dq
1743  dq1 = min( dq, qs2(i,j) )
1744  qs2(i,j) = qs2(i,j) - dq1
1745  qi2(i,j) = qi2(i,j) + dq1 - dq
1746  pt2(i,j) = pt2(i,j) - dq*icpk(i,j)
1747  endif
1748 ! fix negative rain water with available vapor
1749  if ( qr2(i,j)<0. .and. qv2(i,j)>0. ) then
1750  dq = min( 0.999*qv2(i,j), -qr2(i,j) )
1751  qv2(i,j) = qv2(i,j) - dq
1752  qr2(i,j) = qr2(i,j) + dq
1753  pt2(i,j) = pt2(i,j) + dq*lcpk(i,j)
1754  endif
1755  endif
1756  enddo
1757  enddo
1758 
1759 !******************************************
1760 ! Fast moist physics: Saturation adjustment
1761 !******************************************
1762 #ifndef GFS_PHYS
1763  if ( sat_adj ) then
1764 
1765  do j=js, je
1766  do i=is, ie
1767 ! Melting of cloud ice into cloud water ********
1768  if ( qi2(i,j)>1.e-8 .and. pt2(i,j) > tice ) then
1769  sink = min( qi2(i,j), (pt2(i,j)-tice)/icpk(i,j) )
1770  ql2(i,j) = ql2(i,j) + sink
1771  qi2(i,j) = qi2(i,j) - sink
1772  pt2(i,j) = pt2(i,j) - sink*icpk(i,j)
1773  endif
1774 
1775 ! vapor <---> liquid water --------------------------------
1776  qsw = wqsat2_moist(pt2(i,j), qv2(i,j), p2(i,j), dwsdt)
1777  sink = min( ql2(i,j), (qsw-qv2(i,j))/(1.+lcpk(i,j)*dwsdt) )
1778  qv2(i,j) = qv2(i,j) + sink
1779  ql2(i,j) = ql2(i,j) - sink
1780  pt2(i,j) = pt2(i,j) - sink*lcpk(i,j)
1781 !-----------------------------------------------------------
1782 
1783 ! freezing of cloud water ********
1784  if( ql2(i,j)>1.e-8 .and. pt2(i,j) < t48 ) then
1785 ! Enforce complete freezing below t_00 (-48 C)
1786  sink = min( ql2(i,j), (t48-pt2(i,j))/icpk(i,j) )
1787  ql2(i,j) = ql2(i,j) - sink
1788  qi2(i,j) = qi2(i,j) + sink
1789  pt2(i,j) = pt2(i,j) + sink*icpk(i,j)
1790  endif ! significant ql existed
1791  enddo
1792  enddo
1793  endif
1794 #endif
1795 
1796 !----------------------------------------------------------------
1797 ! Update fields:
1798  do j=js, je
1799  do i=is, ie
1800  qv(i,j,k) = qv2(i,j)
1801  ql(i,j,k) = ql2(i,j)
1802  qi(i,j,k) = qi2(i,j)
1803  qs(i,j,k) = qs2(i,j)
1804  qr(i,j,k) = qr2(i,j)
1805  qg(i,j,k) = qg2(i,j)
1806  pt(i,j,k) = pt2(i,j)
1807  enddo
1808  enddo
1809 #ifdef MULTI_GASES
1810  qvi(:,:,k,1) = qv(:,:,k)
1811 #endif
1812 
1813  enddo
1814 
1815 !$OMP parallel do default(none) shared(is,ie,js,je,kbot,dp,qg,qr) &
1816 !$OMP private(dpk, q2)
1817  do j=js, je
1818 ! Graupel:
1819  do k=1,kbot
1820  do i=is,ie
1821  dpk(i,k) = dp(i,j,k)
1822  q2(i,k) = qg(i,j,k)
1823  enddo
1824  enddo
1825  call fillq(ie-is+1, kbot, q2, dpk)
1826  do k=1,kbot
1827  do i=is,ie
1828  qg(i,j,k) = q2(i,k)
1829  enddo
1830  enddo
1831 ! Rain water:
1832  do k=1,kbot
1833  do i=is,ie
1834  q2(i,k) = qr(i,j,k)
1835  enddo
1836  enddo
1837  call fillq(ie-is+1, kbot, q2, dpk)
1838  do k=1,kbot
1839  do i=is,ie
1840  qr(i,j,k) = q2(i,k)
1841  enddo
1842  enddo
1843  enddo
1844 
1845 !-----------------------------------
1846 ! Fix water vapor
1847 !-----------------------------------
1848 ! Top layer: borrow from below
1849  k = 1
1850 !$OMP parallel do default(none) shared(is,ie,js,je,k,qv,dp)
1851  do j=js, je
1852  do i=is, ie
1853  if( qv(i,j,k) < 0. ) then
1854  qv(i,j,k+1) = qv(i,j,k+1) + qv(i,j,k)*dp(i,j,k)/dp(i,j,k+1)
1855  qv(i,j,k ) = 0.
1856  endif
1857  enddo
1858  enddo
1859 
1860 ! this OpenMP do-loop cannot be parallelized with recursion on k/k-1
1861 !$OMP parallel do default(none) shared(is,ie,js,je,kbot,qv,dp) &
1862 !$OMP private(dq)
1863  do j=js, je
1864  do k=2,kbot-1
1865  do i=is, ie
1866  if( qv(i,j,k) < 0. .and. qv(i,j,k-1) > 0. ) then
1867  dq = min(-qv(i,j,k)*dp(i,j,k), qv(i,j,k-1)*dp(i,j,k-1))
1868  qv(i,j,k-1) = qv(i,j,k-1) - dq/dp(i,j,k-1)
1869  qv(i,j,k ) = qv(i,j,k ) + dq/dp(i,j,k )
1870  endif
1871  if( qv(i,j,k) < 0. ) then
1872  qv(i,j,k+1) = qv(i,j,k+1) + qv(i,j,k)*dp(i,j,k)/dp(i,j,k+1)
1873  qv(i,j,k ) = 0.
1874  endif
1875  enddo
1876  enddo
1877  enddo
1878 
1879 ! Bottom layer; Borrow from above
1880 !$OMP parallel do default(none) shared(is,ie,js,je,kbot,qv,dp) private(dq)
1881  do j=js, je
1882  do i=is, ie
1883  if( qv(i,j,kbot) < 0. ) then
1884  do k=kbot-1,1,-1
1885  if ( qv(i,j,kbot)>=0. ) goto 123
1886  if ( qv(i,j,k) > 0. ) then
1887  dq = min(-qv(i,j,kbot)*dp(i,j,kbot), qv(i,j,k)*dp(i,j,k))
1888  qv(i,j,k ) = qv(i,j,k ) - dq/dp(i,j,k)
1889  qv(i,j,kbot) = qv(i,j,kbot) + dq/dp(i,j,kbot)
1890  endif
1891  enddo ! k-loop
1892 123 continue
1893  endif
1894  enddo ! i-loop
1895  enddo ! j-loop
1896 #ifdef MULTI_GASES
1897  qvi(:,:,:,1) = qv(:,:,:)
1898 #endif
1899 
1900 
1901  if (present(qa)) then
1902 !-----------------------------------
1903 ! Fix negative cloud fraction
1904 !-----------------------------------
1905 ! this OpenMP do-loop cannot be parallelized by the recursion on k/k+1
1906 !$OMP parallel do default(none) shared(is,ie,js,je,kbot,qa,dp)
1907  do j=js, je
1908  do k=1,kbot-1
1909  do i=is, ie
1910  if( qa(i,j,k) < 0. ) then
1911  qa(i,j,k+1) = qa(i,j,k+1) + qa(i,j,k)*dp(i,j,k)/dp(i,j,k+1)
1912  qa(i,j,k ) = 0.
1913  endif
1914  enddo
1915  enddo
1916  enddo
1917 
1918 ! Bottom layer; Borrow from above
1919 !$OMP parallel do default(none) shared(is,ie,js,je,qa,kbot,dp) &
1920 !$OMP private(dq)
1921  do j=js, je
1922  do i=is, ie
1923  if( qa(i,j,kbot) < 0. .and. qa(i,j,kbot-1)>0.) then
1924  dq = min(-qa(i,j,kbot)*dp(i,j,kbot), qa(i,j,kbot-1)*dp(i,j,kbot-1))
1925  qa(i,j,kbot-1) = qa(i,j,kbot-1) - dq/dp(i,j,kbot-1)
1926  qa(i,j,kbot ) = qa(i,j,kbot ) + dq/dp(i,j,kbot )
1927  endif
1928 ! if qa is still < 0
1929  qa(i,j,kbot) = max(0., qa(i,j,kbot))
1930  enddo
1931  enddo
1932 
1933  endif
1934 
1935  end subroutine neg_adj3
1936 
1937  subroutine neg_adj2(is, ie, js, je, ng, kbot, hydrostatic, &
1938  peln, delz, pt, dp, qv, ql, qr, qi, qs, qa, check_negative)
1940 ! This is designed for 6-class micro-physics schemes
1941  integer, intent(in):: is, ie, js, je, ng, kbot
1942  logical, intent(in):: hydrostatic
1943  real, intent(in):: dp(is-ng:ie+ng,js-ng:je+ng,kbot)
1944  real, intent(in):: delz(is-ng:,js-ng:,1:)
1945  real, intent(in):: peln(is:ie,kbot+1,js:je)
1946  logical, intent(in), OPTIONAL :: check_negative
1947  real, intent(inout), dimension(is-ng:ie+ng,js-ng:je+ng,kbot):: &
1948  pt, qv, ql, qr, qi, qs
1949  real, intent(inout), OPTIONAL, dimension(is-ng:ie+ng,js-ng:je+ng,kbot):: qa
1950 ! Local:
1951  logical:: sat_adj = .false.
1952  real, parameter :: t48 = tice - 48.
1953  real, dimension(is:ie,kbot):: dpk, q2
1954  real, dimension(is:ie,js:je):: pt2, qv2, ql2, qi2, qs2, qr2, dp2, p2, icpk, lcpk
1955  real:: cv_air
1956  real:: dq, qsum, dq1, q_liq, q_sol, oneocpm, sink, qsw, dwsdt, tx1
1957  integer i, j, k
1958 
1959  cv_air = cp_air - rdgas ! = rdgas * (7/2-1) = 2.5*rdgas=717.68
1960 
1961  if ( present(check_negative) ) then
1962  if ( check_negative ) then
1963  call prt_negative('Temperature', pt, is, ie, js, je, ng, kbot, 165.)
1964  call prt_negative('sphum', qv, is, ie, js, je, ng, kbot, -1.e-8)
1965  call prt_negative('liq_wat', ql, is, ie, js, je, ng, kbot, -1.e-7)
1966  call prt_negative('rainwat', qr, is, ie, js, je, ng, kbot, -1.e-7)
1967  call prt_negative('ice_wat', qi, is, ie, js, je, ng, kbot, -1.e-7)
1968  call prt_negative('snowwat', qs, is, ie, js, je, ng, kbot, -1.e-7)
1969  endif
1970  endif
1971 
1972  if ( hydrostatic ) then
1973  d0_vap = cp_vapor - c_liq
1974  else
1975  d0_vap = cv_vap - c_liq
1976  endif
1977  lv00 = hlv0 - d0_vap*t_ice
1978 
1979 !$OMP parallel do default(none) shared(is,ie,js,je,kbot,qv,ql,qi,qs,qr,dp,pt, &
1980 !$OMP lv00, d0_vap,hydrostatic,peln,delz,cv_air,sat_adj) &
1981 !$OMP private(dq,dq1,qsum,dp2,p2,pt2,qv2,ql2,qi2,qs2,qr2, &
1982 !$OMP lcpk,icpk,qsw,dwsdt,sink,q_liq,q_sol,oneocpm)
1983  do k=1, kbot
1984  do j=js, je
1985  do i=is, ie
1986  qv2(i,j) = qv(i,j,k)
1987  ql2(i,j) = ql(i,j,k)
1988  qi2(i,j) = qi(i,j,k)
1989  qs2(i,j) = qs(i,j,k)
1990  qr2(i,j) = qr(i,j,k)
1991  dp2(i,j) = dp(i,j,k)
1992  pt2(i,j) = pt(i,j,k)
1993  enddo
1994  enddo
1995 
1996  if ( hydrostatic ) then
1997  do j=js, je
1998  do i=is, ie
1999  p2(i,j) = dp2(i,j)/(peln(i,k+1,j)-peln(i,k,j))
2000  q_liq = max(0., ql2(i,j) + qr2(i,j))
2001  q_sol = max(0., qi2(i,j) + qs2(i,j))
2002  oneocpm = 1.0 / ((1.-(qv2(i,j)+q_liq+q_sol))*cp_air + qv2(i,j)*cp_vapor + q_liq*c_liq + q_sol*c_ice)
2003  lcpk(i,j) = hlv * oneocpm
2004  icpk(i,j) = hlf * oneocpm
2005  enddo
2006  enddo
2007  else
2008  do j=js, je
2009  do i=is, ie
2010  p2(i,j) = -dp2(i,j)/(grav*delz(i,j,k))*rdgas*pt2(i,j)*(1.+zvir*qv2(i,j))
2011  q_liq = max(0., ql2(i,j) + qr2(i,j))
2012  q_sol = max(0., qi2(i,j) + qs2(i,j))
2013  oneocpm = 1.0 / ((1.-(qv2(i,j)+q_liq+q_sol))*cv_air + qv2(i,j)*cv_vap + q_liq*c_liq + q_sol*c_ice)
2014  lcpk(i,j) = (lv00+d0_vap*pt2(i,j)) * oneocpm
2015  icpk(i,j) = (li0+dc_ice*pt2(i,j)) * oneocpm
2016  enddo
2017  enddo
2018  endif
2019 
2020 ! Fix the negatives:
2021 !-----------
2022 ! Ice-phase:
2023 !-----------
2024  do j=js, je
2025  do i=is, ie
2026  qsum = qi2(i,j) + qs2(i,j)
2027  if ( qsum > 0. ) then
2028  if ( qi2(i,j) < 0. ) then
2029  qi2(i,j) = 0.
2030  qs2(i,j) = qsum
2031  elseif ( qs2(i,j) < 0. ) then
2032  qs2(i,j) = 0.
2033  qi2(i,j) = qsum
2034  endif
2035  else
2036  qi2(i,j) = 0.
2037  qs2(i,j) = qsum
2038 
2039 ! If qsum is negative then borrow from rain water: phase change
2040  if ( qs2(i,j) < 0. .and. qr2(i,j) > 0. ) then
2041  dq = min( qr2(i,j), -qs2(i,j) )
2042  qs2(i,j) = qs2(i,j) + dq
2043  qr2(i,j) = qr2(i,j) - dq
2044  pt2(i,j) = pt2(i,j) + dq*icpk(i,j) ! conserve total energy
2045  endif
2046 ! If qs2 is still negative then borrow from cloud water: phase change
2047  if ( qs2(i,j) < 0. .and. ql2(i,j) > 0. ) then
2048  dq = min( ql2(i,j), -qs2(i,j) )
2049  qs2(i,j) = qs2(i,j) + dq
2050  ql2(i,j) = ql2(i,j) - dq
2051  pt2(i,j) = pt2(i,j) + dq*icpk(i,j)
2052  endif
2053 ! Last resort; borrow from water vapor
2054  if ( qs2(i,j) < 0. .and. qv2(i,j) > 0. ) then
2055  dq = min( 0.999*qv2(i,j), -qs2(i,j) )
2056  qs2(i,j) = qs2(i,j) + dq
2057  qv2(i,j) = qv2(i,j) - dq
2058  pt2(i,j) = pt2(i,j) + dq*(icpk(i,j)+lcpk(i,j))
2059  endif
2060  endif
2061 
2062 !--------------
2063 ! Liquid phase:
2064 !--------------
2065  qsum = ql2(i,j) + qr2(i,j)
2066  if ( qsum > 0. ) then
2067  if ( qr2(i,j) < 0. ) then
2068  qr2(i,j) = 0.
2069  ql2(i,j) = qsum
2070  elseif ( ql2(i,j) < 0. ) then
2071  ql2(i,j) = 0.
2072  qr2(i,j) = qsum
2073  endif
2074  else
2075  ql2(i,j) = 0.
2076  qr2(i,j) = qsum ! rain water is still negative
2077  if ( qr(i,j,k) < 0. ) then
2078 ! fill negative rain with available qi & qs (cooling)
2079  dq = min( qi2(i,j)+qs2(i,j), -qr2(i,j) )
2080  qr2(i,j) = qr2(i,j) + dq
2081  dq1 = min( dq, qs2(i,j) )
2082  qs2(i,j) = qs2(i,j) - dq1
2083  qi2(i,j) = qi2(i,j) + dq1 - dq
2084  pt2(i,j) = pt2(i,j) - dq*icpk(i,j)
2085  endif
2086 ! fix negative rain water with available vapor
2087  if ( qr2(i,j) < 0. .and. qv2(i,j) > 0. ) then
2088  dq = min( 0.999*qv2(i,j), -qr2(i,j) )
2089  qv2(i,j) = qv2(i,j) - dq
2090  qr2(i,j) = qr2(i,j) + dq
2091  pt2(i,j) = pt2(i,j) + dq*lcpk(i,j)
2092  endif
2093  endif
2094  enddo
2095  enddo
2096 
2097 !******************************************
2098 ! Fast moist physics: Saturation adjustment
2099 !******************************************
2100 #ifndef GFS_PHYS
2101  if ( sat_adj ) then
2102 
2103  do j=js, je
2104  do i=is, ie
2105 ! Melting of cloud ice into cloud water ********
2106  if ( qi2(i,j)>1.e-8 .and. pt2(i,j) > tice ) then
2107  sink = min( qi2(i,j), (pt2(i,j)-tice)/icpk(i,j) )
2108  ql2(i,j) = ql2(i,j) + sink
2109  qi2(i,j) = qi2(i,j) - sink
2110  pt2(i,j) = pt2(i,j) - sink*icpk(i,j)
2111  endif
2112 
2113 ! vapor <---> liquid water --------------------------------
2114  qsw = wqsat2_moist(pt2(i,j), qv2(i,j), p2(i,j), dwsdt)
2115  sink = min( ql2(i,j), (qsw-qv2(i,j))/(1.+lcpk(i,j)*dwsdt) )
2116  qv2(i,j) = qv2(i,j) + sink
2117  ql2(i,j) = ql2(i,j) - sink
2118  pt2(i,j) = pt2(i,j) - sink*lcpk(i,j)
2119 !-----------------------------------------------------------
2120 
2121 ! freezing of cloud water ********
2122  if( ql2(i,j)>1.e-8 .and. pt2(i,j) < t48 ) then
2123 ! Enforce complete freezing below t_00 (-48 C)
2124  sink = min( ql2(i,j), (t48-pt2(i,j))/icpk(i,j) )
2125  ql2(i,j) = ql2(i,j) - sink
2126  qi2(i,j) = qi2(i,j) + sink
2127  pt2(i,j) = pt2(i,j) + sink*icpk(i,j)
2128  endif ! significant ql existed
2129  enddo
2130  enddo
2131  endif
2132 #endif
2133 
2134 !----------------------------------------------------------------
2135 ! Update fields:
2136  do j=js, je
2137  do i=is, ie
2138  qv(i,j,k) = qv2(i,j)
2139  ql(i,j,k) = ql2(i,j)
2140  qi(i,j,k) = qi2(i,j)
2141  qs(i,j,k) = qs2(i,j)
2142  qr(i,j,k) = qr2(i,j)
2143  pt(i,j,k) = pt2(i,j)
2144  enddo
2145  enddo
2146 
2147  enddo
2148 
2149 !$OMP parallel do default(none) shared(is,ie,js,je,kbot,dp,qr) &
2150 !$OMP private(dpk, q2)
2151  do j=js, je
2152 ! Rain water:
2153  do k=1,kbot
2154  do i=is,ie
2155  dpk(i,k) = dp(i,j,k)
2156  q2(i,k) = qr(i,j,k)
2157  enddo
2158  enddo
2159  call fillq(ie-is+1, kbot, q2, dpk)
2160  do k=1,kbot
2161  do i=is,ie
2162  qr(i,j,k) = q2(i,k)
2163  enddo
2164  enddo
2165  enddo
2166 
2167 !-----------------------------------
2168 ! Fix water vapor
2169 !-----------------------------------
2170 ! Top layer: borrow from below
2171  k = 1
2172 !$OMP parallel do default(none) shared(is,ie,js,je,k,qv,dp)
2173  do j=js, je
2174  do i=is, ie
2175  if( qv(i,j,k) < 0. ) then
2176  qv(i,j,k+1) = qv(i,j,k+1) + qv(i,j,k)*dp(i,j,k)/dp(i,j,k+1)
2177  qv(i,j,k ) = 0.
2178  endif
2179  enddo
2180  enddo
2181 
2182 ! this OpenMP do-loop cannot be parallelized with recursion on k/k-1
2183 !$OMP parallel do default(none) shared(is,ie,js,je,kbot,qv,dp) &
2184 !$OMP private(dq)
2185  do j=js, je
2186  do k=2,kbot-1
2187  do i=is, ie
2188  if( qv(i,j,k) < 0. .and. qv(i,j,k-1) > 0. ) then
2189  dq = min(-qv(i,j,k)*dp(i,j,k), qv(i,j,k-1)*dp(i,j,k-1))
2190  qv(i,j,k-1) = qv(i,j,k-1) - dq/dp(i,j,k-1)
2191  qv(i,j,k ) = qv(i,j,k ) + dq/dp(i,j,k )
2192  endif
2193  if( qv(i,j,k) < 0. ) then
2194  qv(i,j,k+1) = qv(i,j,k+1) + qv(i,j,k)*dp(i,j,k)/dp(i,j,k+1)
2195  qv(i,j,k ) = 0.
2196  endif
2197  enddo
2198  enddo
2199  enddo
2200 
2201 ! Bottom layer; Borrow from above
2202 !$OMP parallel do default(none) shared(is,ie,js,je,kbot,qv,dp) private(dq,tx1)
2203  do j=js, je
2204  do i=is, ie
2205  if( qv(i,j,kbot) < 0. ) then
2206  tx1 = 1.0 / dp(i,j,kbot)
2207  do k=kbot-1,1,-1
2208  if ( qv(i,j,kbot)>= 0. ) goto 123
2209  if ( qv(i,j,k) > 0. ) then
2210  dq = min(-qv(i,j,kbot)*dp(i,j,kbot), qv(i,j,k)*dp(i,j,k))
2211  qv(i,j,k ) = qv(i,j,k ) - dq / dp(i,j,k)
2212  qv(i,j,kbot) = qv(i,j,kbot) + dq * tx1
2213  endif
2214  enddo ! k-loop
2215 123 continue
2216  endif
2217  enddo ! i-loop
2218  enddo ! j-loop
2219 
2220 
2221  if (present(qa)) then
2222 !-----------------------------------
2223 ! Fix negative cloud fraction
2224 !-----------------------------------
2225 ! this OpenMP do-loop cannot be parallelized by the recursion on k/k+1
2226 !$OMP parallel do default(none) shared(is,ie,js,je,kbot,qa,dp)
2227  do j=js, je
2228  do k=1,kbot-1
2229  do i=is, ie
2230  if( qa(i,j,k) < 0. ) then
2231  qa(i,j,k+1) = qa(i,j,k+1) + qa(i,j,k)*dp(i,j,k)/dp(i,j,k+1)
2232  qa(i,j,k ) = 0.
2233  endif
2234  enddo
2235  enddo
2236  enddo
2237 
2238 ! Bottom layer; Borrow from above
2239 !$OMP parallel do default(none) shared(is,ie,js,je,qa,kbot,dp) &
2240 !$OMP private(dq)
2241  do j=js, je
2242  do i=is, ie
2243  if( qa(i,j,kbot) < 0. .and. qa(i,j,kbot-1)>0.) then
2244  dq = min(-qa(i,j,kbot)*dp(i,j,kbot), qa(i,j,kbot-1)*dp(i,j,kbot-1))
2245  qa(i,j,kbot-1) = qa(i,j,kbot-1) - dq/dp(i,j,kbot-1)
2246  qa(i,j,kbot ) = qa(i,j,kbot ) + dq/dp(i,j,kbot )
2247  endif
2248 ! if qa is still < 0
2249  qa(i,j,kbot) = max(0., qa(i,j,kbot))
2250  enddo
2251  enddo
2252 
2253  endif
2254 
2255  end subroutine neg_adj2
2256 
2257  subroutine fillq(im, km, q, dp)
2258 ! Aggresive 1D filling algorithm for qr and qg
2259  integer, intent(in):: im, km
2260  real, intent(inout), dimension(im,km):: q, dp
2261  integer:: i, k
2262  real:: sum1, sum2, dq
2263 
2264  do 500 i=1,im
2265  sum1 = 0.
2266  do k=1,km
2267  if ( q(i,k)>0. ) then
2268  sum1 = sum1 + q(i,k)*dp(i,k)
2269  endif
2270  enddo
2271  if ( sum1<1.e-12 ) goto 500
2272  sum2 = 0.
2273  do k=km,1,-1
2274  if ( q(i,k)<0.0 .and. sum1>0. ) then
2275  dq = min( sum1, -q(i,k)*dp(i,k) )
2276  sum1 = sum1 - dq
2277  sum2 = sum2 + dq
2278  q(i,k) = q(i,k) + dq/dp(i,k)
2279  endif
2280  enddo
2281  do k=km,1,-1
2282  if ( q(i,k)>0.0 .and. sum2>0. ) then
2283  dq = min( sum2, q(i,k)*dp(i,k) )
2284  sum2 = sum2 - dq
2285  q(i,k) = q(i,k) - dq/dp(i,k)
2286  endif
2287  enddo
2288 500 continue
2289 
2290  end subroutine fillq
2291 
2292  subroutine prt_negative(qname, q, is, ie, js, je, n_g, km, threshold)
2293  character(len=*), intent(in):: qname
2294  integer, intent(in):: is, ie, js, je
2295  integer, intent(in):: n_g, km
2296  real, intent(in):: q(is-n_g:ie+n_g, js-n_g:je+n_g, km)
2297  real, intent(in):: threshold
2298  real qmin
2299  integer i,j,k
2300 
2301  qmin = q(is,js,1)
2302  do k=1,km
2303  do j=js,je
2304  do i=is,ie
2305  qmin = min(qmin, q(i,j,k))
2306  enddo
2307  enddo
2308  enddo
2309  call mp_reduce_min(qmin)
2310  if(is_master() .and. qmin<threshold) write(6,*) qname, ' min (negative) = ', qmin
2311 
2312  end subroutine prt_negative
2313 
2314 
2315 end module fv_sg_mod
real, parameter t3_max
Definition: fv_sg.F90:97
real, parameter dc_ice
= 2112.
Definition: fv_sg.F90:85
subroutine qsmith_init
Definition: fv_sg.F90:1368
pure real function, public vicpqd(q)
The module &#39;fv_mp_mod&#39; is a single program multiple data (SPMD) parallel decompostion/communication m...
Definition: fv_mp_mod.F90:24
subroutine, public neg_adj3(is, ie, js, je, ng, kbot, hydrostatic, peln, delz, pt, dp, qv, ql, qr, qi, qs, qg, qa, check_negative)
Definition: fv_sg.F90:1549
real, parameter li0
= -2.431928e5
Definition: fv_sg.F90:99
integer, public num_gas
Definition: multi_gases.F90:46
real, parameter c_ice
-15 C
Definition: fv_sg.F90:77
The module &#39;multi_gases&#39; peforms multi constitutents computations.
Definition: multi_gases.F90:25
real, parameter cv_vap
1384.5
Definition: fv_sg.F90:80
pure real function, public vicvqd_qpz(q, qpz)
pure real function, public virq_qpz(q, qpz)
real lv00
Definition: fv_sg.F90:103
The module &#39;fv_sg&#39; performs FV sub-grid mixing.
Definition: fv_sg.F90:54
pure real function, public virqd(q)
pure real function, public virq(q)
real, parameter zvir
= 0.607789855
Definition: fv_sg.F90:101
real d0_vap
Definition: fv_sg.F90:103
real, parameter tice
Definition: fv_sg.F90:75
real, parameter ri_min
Definition: fv_sg.F90:93
subroutine fillq(im, km, q, dp)
Definition: fv_sg.F90:2258
subroutine, public qsmith(im, km, k1, t, p, q, qs, dqdt)
Definition: fv_sg.F90:1392
real, parameter c_con
Definition: fv_sg.F90:81
real, parameter t2_min
Definition: fv_sg.F90:95
real, parameter hlv0
Definition: fv_sg.F90:87
real, parameter c_liq
GFS.
Definition: fv_sg.F90:78
real, parameter t1_min
Definition: fv_sg.F90:94
real, parameter lv0
= 3.147782e6
Definition: fv_sg.F90:98
real, parameter t2_max
Definition: fv_sg.F90:96
real, parameter hlf0
Definition: fv_sg.F90:88
subroutine prt_negative(qname, q, is, ie, js, je, n_g, km, threshold)
Definition: fv_sg.F90:2293
real, parameter t_ice
Definition: fv_sg.F90:91
subroutine, public fv_subgrid_z(isd, ied, jsd, jed, is, ie, js, je, km, nq, dt, tau, nwat, delp, pe, peln, pkz, ta, qa, ua, va, hydrostatic, w, delz, u_dt, v_dt, t_dt, q_dt, k_bot)
Definition: fv_sg.F90:718
pure real function, public vicpqd_qpz(q, qpz)
subroutine qs_table(n, table)
Definition: fv_sg.F90:1458
real, dimension(:), allocatable table
Definition: fv_sg.F90:102
real, dimension(:), allocatable des
Definition: fv_sg.F90:102
real, parameter ri_max
Definition: fv_sg.F90:92
subroutine, public neg_adj2(is, ie, js, je, ng, kbot, hydrostatic, peln, delz, pt, dp, qv, ql, qr, qi, qs, qa, check_negative)
Definition: fv_sg.F90:1939
subroutine qs_table_m(n, table)
Definition: fv_sg.F90:1484
real, parameter esl
Definition: fv_sg.F90:74
pure real function, public vicvqd(q)
real, parameter dc_vap
= -2368.
Definition: fv_sg.F90:84