2 ! ======================================================================================
3 ! This file was generated by the version 5.3.6 of DFT on 08/10/2010. The differentiation
4 ! transforming system(DFT) was jointly developed and sponsored by LASG of IAP(1998-2010)
5 ! and LSEC of ICMSEC, AMSS(2001-2003)
6 ! The copyright of the DFT system was declared by Walls at LASG, 1998-2010
7 ! ======================================================================================
9 MODULE g_module_diffusion_em
11 USE g_module_bc, only: g_set_physical_bc3d
12 USE module_state_description, only: p_m23, p_m13, p_m22, p_m33, p_r23, p_r13, p_r12, p_m12, p_m11
13 USE g_module_big_step_utilities_em, only: grid_config_rec_type, param_first_scalar, p_qv, p_qi, p_qc
15 USE module_model_constants
19 SUBROUTINE g_cal_deform_and_div(config_flags,u,g_u,v,g_v,w,g_w,div, &
20 g_div,defor11,g_defor11,defor22,g_defor22,defor33,g_defor33,defor12, &
21 g_defor12,defor13,g_defor13,defor23,g_defor23,nba_rij,g_nba_rij, &
22 n_nba_rij,u_base,v_base,msfux,msfuy,msfvx,msfvy,msftx,msfty,rdx,rdy,dn,dnw,rdz, &
23 g_rdz,rdzw,g_rdzw,fnm,fnp,cf1,cf2,cf3,zx,g_zx,zy,g_zy,ids,ide,jds,jde, &
24 kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
28 REAL :: Tmpv1,g_Tmpv1,Tmpv2,g_Tmpv2,Tmpv3,g_Tmpv3,Tmpv4,g_Tmpv4,Tmpv5, &
30 TYPE(grid_config_rec_type) :: config_flags
31 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
32 REAL :: rdx,rdy,cf1,cf2,cf3
33 REAL,DIMENSION(kms:kme) :: fnm,fnp,dn,dnw,u_base,v_base
34 REAL,DIMENSION(ims:ime,jms:jme) :: msfux,msfuy,msfvx,msfvy,msftx,msfty
35 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: u,g_u,v,g_v,w,g_w,zx,g_zx,zy, &
36 g_zy,rdz,g_rdz,rdzw,g_rdzw
37 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor11,g_defor11,defor22,g_defor22, &
38 defor33,g_defor33,defor12,g_defor12,defor13,g_defor13,defor23,g_defor23, &
43 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_nba_rij) :: nba_rij,g_nba_rij
44 INTEGER :: i,j,k,ktf,ktes1,ktes2,i_start,i_end,j_start,j_end
45 REAL :: tmp,g_tmp,tmpzx,g_tmpzx,tmpzy,g_tmpzy,tmpzeta_z,g_tmpzeta_z,cft1, &
47 REAL,DIMENSION(its:ite,jts:jte) :: mm,g_mm,zzavg,g_zzavg,zeta_zd12,g_zeta_zd12
48 REAL,DIMENSION(its-2:ite+2,kts:kte,jts-2:jte+2) :: tmp1,g_tmp1,hat,g_hat, &
56 cft2 =-0.5 *dnw(ktes1)/dn(ktes1)
75 mm(i,j) =msftx(i,j) *msfty(i,j)
84 g_hat(i,k,j) =g_u(i,k,j)/msfuy(i,j)
85 hat(i,k,j) =u(i,k,j)/msfuy(i,j)
95 g_hatavg(i,k,j) =0.5*(fnm(k)*(g_hat(i,k,j) +g_hat(i+1,k,j)) +fnp(k) &
96 *(g_hat(i,k-1,j) +g_hat(i+1,k-1,j)))
97 hatavg(i,k,j) =0.5*(fnm(k)*(hat(i,k,j) +hat(i+1,k,j)) +fnp(k)*(hat(i,k-1,j) &
107 g_hatavg(i,1,j) =0.5*(cf1*g_hat(i,1,j) +cf2*g_hat(i,2,j) +cf3*g_hat(i,3, &
108 j) +cf1*g_hat(i+1,1,j) +cf2*g_hat(i+1,2,j) +cf3*g_hat(i+1,3,j))
109 hatavg(i,1,j) =0.5*(cf1*hat(i,1,j) +cf2*hat(i,2,j) +cf3*hat(i,3,j) +cf1*hat(i+1,1,j) &
110 +cf2*hat(i+1,2,j) +cf3*hat(i+1,3,j))
112 g_Tmpv1 =cft1*(g_hat(i,ktes1,j) +g_hat(i+1,ktes1,j)) +g_cft1*(hat(i, &
113 ktes1,j) +hat(i+1,ktes1,j))
114 Tmpv1 =cft1*(hat(i,ktes1,j) +hat(i+1,ktes1,j))
116 g_Tmpv2 =cft2*(g_hat(i,ktes2,j) +g_hat(i+1,ktes2,j)) +g_cft2*(hat(i, &
117 ktes2,j) +hat(i+1,ktes2,j))
118 Tmpv2 =cft2*(hat(i,ktes2,j) +hat(i+1,ktes2,j))
120 g_hatavg(i,kte,j) =0.5*(g_Tmpv1 +g_Tmpv2)
121 hatavg(i,kte,j) =0.5*(Tmpv1 +Tmpv2)
132 g_tmpzx =0.25*(g_zx(i,k,j) +g_zx(i+1,k,j) +g_zx(i,k+1,j) +g_zx(i+1,k+1,j))
133 tmpzx =0.25*(zx(i,k,j) +zx(i+1,k,j) +zx(i,k+1,j) +zx(i+1,k+1,j))
135 g_Tmpv1 =(hatavg(i,k+1,j) -hatavg(i,k,j))*g_tmpzx +(g_hatavg(i,k+1,j) &
136 -g_hatavg(i,k,j))*tmpzx
137 Tmpv1 =(hatavg(i,k+1,j) -hatavg(i,k,j))*tmpzx
139 g_Tmpv2 =Tmpv1*g_rdzw(i,k,j) +g_Tmpv1*rdzw(i,k,j)
140 Tmpv2 =Tmpv1*rdzw(i,k,j)
142 g_tmp1(i,k,j) =g_Tmpv2
155 g_Tmpv1 =mm(i,j)*(rdx*(g_hat(i+1,k,j) -g_hat(i,k,j)) -g_tmp1(i,k,j)) &
156 +g_mm(i,j)*(rdx*(hat(i+1,k,j) -hat(i,k,j)) -tmp1(i,k,j))
157 Tmpv1 =mm(i,j)*(rdx*(hat(i+1,k,j) -hat(i,k,j)) -tmp1(i,k,j))
159 g_tmp1(i,k,j) =g_Tmpv1
170 g_defor11(i,k,j) =2.0*g_tmp1(i,k,j)
171 defor11(i,k,j) =2.0*tmp1(i,k,j)
181 g_div(i,k,j) =g_tmp1(i,k,j)
182 div(i,k,j) =tmp1(i,k,j)
190 DO j =j_start,j_end+1
194 IF((config_flags%polar) .AND. ((j == jds) .OR. (j == jde))) THEN
201 g_hat(i,k,j) =g_v(i,k,j)/msfvx(i,j)
202 hat(i,k,j) =v(i,k,j)/msfvx(i,j)
215 g_hatavg(i,k,j) =0.5*(fnm(k)*(g_hat(i,k,j) +g_hat(i,k,j+1)) +fnp(k) &
216 *(g_hat(i,k-1,j) +g_hat(i,k-1,j+1)))
217 hatavg(i,k,j) =0.5*(fnm(k)*(hat(i,k,j) +hat(i,k,j+1)) +fnp(k)*(hat(i,k-1,j) &
229 g_hatavg(i,1,j) =0.5*(cf1*g_hat(i,1,j) +cf2*g_hat(i,2,j) +cf3*g_hat(i,3, &
230 j) +cf1*g_hat(i,1,j+1) +cf2*g_hat(i,2,j+1) +cf3*g_hat(i,3,j+1))
231 hatavg(i,1,j) =0.5*(cf1*hat(i,1,j) +cf2*hat(i,2,j) +cf3*hat(i,3,j) +cf1*hat(i,1,j+1) &
232 +cf2*hat(i,2,j+1) +cf3*hat(i,3,j+1))
234 g_Tmpv1 =cft1*(g_hat(i,ktes1,j) +g_hat(i,ktes1,j+1)) +g_cft1*(hat(i, &
235 ktes1,j) +hat(i,ktes1,j+1))
236 Tmpv1 =cft1*(hat(i,ktes1,j) +hat(i,ktes1,j+1))
238 g_Tmpv2 =cft2*(g_hat(i,ktes2,j) +g_hat(i,ktes2,j+1)) +g_cft2*(hat(i, &
239 ktes2,j) +hat(i,ktes2,j+1))
240 Tmpv2 =cft2*(hat(i,ktes2,j) +hat(i,ktes2,j+1))
242 g_hatavg(i,kte,j) =0.5*(g_Tmpv1 +g_Tmpv2)
243 hatavg(i,kte,j) =0.5*(Tmpv1 +Tmpv2)
254 g_tmpzy =0.25*(g_zy(i,k,j) +g_zy(i,k,j+1) +g_zy(i,k+1,j) +g_zy(i,k+1,j+1))
255 tmpzy =0.25*(zy(i,k,j) +zy(i,k,j+1) +zy(i,k+1,j) +zy(i,k+1,j+1))
257 g_Tmpv1 =(hatavg(i,k+1,j) -hatavg(i,k,j))*g_tmpzy +(g_hatavg(i,k+1,j) &
258 -g_hatavg(i,k,j))*tmpzy
259 Tmpv1 =(hatavg(i,k+1,j) -hatavg(i,k,j))*tmpzy
261 g_Tmpv2 =Tmpv1*g_rdzw(i,k,j) +g_Tmpv1*rdzw(i,k,j)
262 Tmpv2 =Tmpv1*rdzw(i,k,j)
264 g_tmp1(i,k,j) =g_Tmpv2
275 g_Tmpv1 =mm(i,j)*(rdy*(g_hat(i,k,j+1) -g_hat(i,k,j)) -g_tmp1(i,k,j)) &
276 +g_mm(i,j)*(rdy*(hat(i,k,j+1) -hat(i,k,j)) -tmp1(i,k,j))
277 Tmpv1 =mm(i,j)*(rdy*(hat(i,k,j+1) -hat(i,k,j)) -tmp1(i,k,j))
279 g_tmp1(i,k,j) =g_Tmpv1
290 g_defor22(i,k,j) =2.0*g_tmp1(i,k,j)
291 defor22(i,k,j) =2.0*tmp1(i,k,j)
302 g_div(i,k,j) =g_div(i,k,j) +g_tmp1(i,k,j)
303 div(i,k,j) =div(i,k,j) +tmp1(i,k,j)
313 g_Tmpv1 =(w(i,k+1,j) -w(i,k,j))*g_rdzw(i,k,j) +(g_w(i,k+1,j) -g_w(i,k, &
315 Tmpv1 =(w(i,k+1,j) -w(i,k,j))*rdzw(i,k,j)
317 g_tmp1(i,k,j) =g_Tmpv1
328 g_defor33(i,k,j) =2.0*g_tmp1(i,k,j)
329 defor33(i,k,j) =2.0*tmp1(i,k,j)
340 g_div(i,k,j) =g_div(i,k,j) +g_tmp1(i,k,j)
341 div(i,k,j) =div(i,k,j) +tmp1(i,k,j)
356 IF( config_flags%open_xs .OR. config_flags%specified .OR. &
357 config_flags%nested) i_start =max(ids+1,its)
359 IF( config_flags%open_xe .OR. config_flags%specified .OR. &
360 config_flags%nested) i_end =min(ide-1,ite)
362 IF( config_flags%open_ys .OR. config_flags%specified .OR. &
363 config_flags%nested) j_start =max(jds+1,jts)
365 IF( config_flags%open_ye .OR. config_flags%specified .OR. &
366 config_flags%nested) j_end =min(jde-1,jte)
368 IF( config_flags%periodic_x ) i_start =its
370 IF( config_flags%periodic_x ) i_end =ite
376 mm(i,j) =0.25 *(msfux(i,j-1)+msfux(i,j)) *(msfvy(i-1,j)+msfvy(i,j))
381 DO j =j_start-1,j_end
385 g_hat(i,k,j) =g_u(i,k,j)/msfux(i,j)
386 hat(i,k,j) =u(i,k,j)/msfux(i,j)
396 g_hatavg(i,k,j) =0.5*(fnm(k)*(g_hat(i,k,j-1) +g_hat(i,k,j)) +fnp(k) &
397 *(g_hat(i,k-1,j-1) +g_hat(i,k-1,j)))
398 hatavg(i,k,j) =0.5*(fnm(k)*(hat(i,k,j-1) +hat(i,k,j)) +fnp(k)*(hat(i,k-1,j-1) &
408 g_hatavg(i,1,j) =0.5*(cf1*g_hat(i,1,j-1) +cf2*g_hat(i,2,j-1) +cf3*g_hat( &
409 i,3,j-1) +cf1*g_hat(i,1,j) +cf2*g_hat(i,2,j) +cf3*g_hat(i,3,j))
410 hatavg(i,1,j) =0.5*(cf1*hat(i,1,j-1) +cf2*hat(i,2,j-1) +cf3*hat(i,3,j-1) &
411 +cf1*hat(i,1,j) +cf2*hat(i,2,j) +cf3*hat(i,3,j))
413 g_Tmpv1 =cft1*(g_hat(i,ktes1,j-1) +g_hat(i,ktes1,j)) +g_cft1*(hat(i, &
414 ktes1,j-1) +hat(i,ktes1,j))
415 Tmpv1 =cft1*(hat(i,ktes1,j-1) +hat(i,ktes1,j))
417 g_Tmpv2 =cft2*(g_hat(i,ktes2,j-1) +g_hat(i,ktes2,j)) +g_cft2*(hat(i, &
418 ktes2,j-1) +hat(i,ktes2,j))
419 Tmpv2 =cft2*(hat(i,ktes2,j-1) +hat(i,ktes2,j))
421 g_hatavg(i,kte,j) =0.5*(g_Tmpv1 +g_Tmpv2)
422 hatavg(i,kte,j) =0.5*(Tmpv1 +Tmpv2)
433 g_tmpzy =0.25*(g_zy(i-1,k,j) +g_zy(i,k,j) +g_zy(i-1,k+1,j) +g_zy(i,k+1,j))
434 tmpzy =0.25*(zy(i-1,k,j) +zy(i,k,j) +zy(i-1,k+1,j) +zy(i,k+1,j))
436 g_Tmpv1 =(hatavg(i,k+1,j) -hatavg(i,k,j))*0.25*g_tmpzy +(g_hatavg(i,k+1,j) &
437 -g_hatavg(i,k,j))*0.25*tmpzy
438 Tmpv1 =(hatavg(i,k+1,j) -hatavg(i,k,j))*0.25*tmpzy
440 g_Tmpv2 =Tmpv1*(g_rdzw(i,k,j) +g_rdzw(i-1,k,j) +g_rdzw(i-1,k,j-1) &
441 +g_rdzw(i,k,j-1)) +g_Tmpv1*(rdzw(i,k,j) +rdzw(i-1,k,j) +rdzw(i-1,k,j-1) +rdzw(i,k,j-1))
442 Tmpv2 =Tmpv1*(rdzw(i,k,j) +rdzw(i-1,k,j) +rdzw(i-1,k,j-1) +rdzw(i,k,j-1))
444 g_tmp1(i,k,j) =g_Tmpv2
455 g_Tmpv1 =mm(i,j)*(rdy*(g_hat(i,k,j) -g_hat(i,k,j-1)) -g_tmp1(i,k,j)) &
456 +g_mm(i,j)*(rdy*(hat(i,k,j) -hat(i,k,j-1)) -tmp1(i,k,j))
457 Tmpv1 =mm(i,j)*(rdy*(hat(i,k,j) -hat(i,k,j-1)) -tmp1(i,k,j))
459 g_defor12(i,k,j) =g_Tmpv1
460 defor12(i,k,j) =Tmpv1
469 DO i =i_start-1,i_end
471 g_hat(i,k,j) =g_v(i,k,j)/msfvy(i,j)
472 hat(i,k,j) =v(i,k,j)/msfvy(i,j)
482 g_hatavg(i,k,j) =0.5*(fnm(k)*(g_hat(i-1,k,j) +g_hat(i,k,j)) +fnp(k) &
483 *(g_hat(i-1,k-1,j) +g_hat(i,k-1,j)))
484 hatavg(i,k,j) =0.5*(fnm(k)*(hat(i-1,k,j) +hat(i,k,j)) +fnp(k)*(hat(i-1,k-1,j) &
494 g_hatavg(i,1,j) =0.5*(cf1*g_hat(i-1,1,j) +cf2*g_hat(i-1,2,j) +cf3*g_hat( &
495 i-1,3,j) +cf1*g_hat(i,1,j) +cf2*g_hat(i,2,j) +cf3*g_hat(i,3,j))
496 hatavg(i,1,j) =0.5*(cf1*hat(i-1,1,j) +cf2*hat(i-1,2,j) +cf3*hat(i-1,3,j) &
497 +cf1*hat(i,1,j) +cf2*hat(i,2,j) +cf3*hat(i,3,j))
499 g_Tmpv1 =cft1*(g_hat(i,ktes1,j) +g_hat(i-1,ktes1,j)) +g_cft1*(hat(i, &
500 ktes1,j) +hat(i-1,ktes1,j))
501 Tmpv1 =cft1*(hat(i,ktes1,j) +hat(i-1,ktes1,j))
503 g_Tmpv2 =cft2*(g_hat(i,ktes2,j) +g_hat(i-1,ktes2,j)) +g_cft2*(hat(i, &
504 ktes2,j) +hat(i-1,ktes2,j))
505 Tmpv2 =cft2*(hat(i,ktes2,j) +hat(i-1,ktes2,j))
507 g_hatavg(i,kte,j) =0.5*(g_Tmpv1 +g_Tmpv2)
508 hatavg(i,kte,j) =0.5*(Tmpv1 +Tmpv2)
518 g_tmpzx =0.25*(g_zx(i,k,j-1) +g_zx(i,k,j) +g_zx(i,k+1,j-1) +g_zx(i,k+1,j))
519 tmpzx =0.25*(zx(i,k,j-1) +zx(i,k,j) +zx(i,k+1,j-1) +zx(i,k+1,j))
521 g_Tmpv1 =(hatavg(i,k+1,j) -hatavg(i,k,j))*0.25*g_tmpzx +(g_hatavg(i,k+1,j) &
522 -g_hatavg(i,k,j))*0.25*tmpzx
523 Tmpv1 =(hatavg(i,k+1,j) -hatavg(i,k,j))*0.25*tmpzx
525 g_Tmpv2 =Tmpv1*(g_rdzw(i,k,j) +g_rdzw(i,k,j-1) +g_rdzw(i-1,k,j-1) &
526 +g_rdzw(i-1,k,j)) +g_Tmpv1*(rdzw(i,k,j) +rdzw(i,k,j-1) +rdzw(i-1,k,j-1) +rdzw(i-1,k,j))
527 Tmpv2 =Tmpv1*(rdzw(i,k,j) +rdzw(i,k,j-1) +rdzw(i-1,k,j-1) +rdzw(i-1,k,j))
529 g_tmp1(i,k,j) =g_Tmpv2
537 IF( config_flags%sfs_opt .GT. 0 ) THEN
543 g_Tmpv1 =mm(i,j)*(rdx*(g_hat(i,k,j) -g_hat(i-1,k,j)) -g_tmp1(i,k,j)) &
544 +g_mm(i,j)*(rdx*(hat(i,k,j) -hat(i-1,k,j)) -tmp1(i,k,j))
545 Tmpv1 =mm(i,j)*(rdx*(hat(i,k,j) -hat(i-1,k,j)) -tmp1(i,k,j))
547 g_nba_rij(i,k,j,P_r12) =g_defor12(i,k,j) -g_Tmpv1
548 nba_rij(i,k,j,P_r12) =defor12(i,k,j) -Tmpv1
550 g_Tmpv1 =mm(i,j)*(rdx*(g_hat(i,k,j) -g_hat(i-1,k,j)) -g_tmp1(i,k,j)) &
551 +g_mm(i,j)*(rdx*(hat(i,k,j) -hat(i-1,k,j)) -tmp1(i,k,j))
552 Tmpv1 =mm(i,j)*(rdx*(hat(i,k,j) -hat(i-1,k,j)) -tmp1(i,k,j))
554 g_defor12(i,k,j) =g_defor12(i,k,j) +g_Tmpv1
555 defor12(i,k,j) =defor12(i,k,j) +Tmpv1
561 IF( .NOT. config_flags%periodic_x .AND. i_start .EQ. ids+1 ) THEN
566 g_defor12(ids,k,j) =g_defor12(ids+1,k,j)
567 defor12(ids,k,j) =defor12(ids+1,k,j)
569 g_nba_rij(ids,k,j,P_r12) =g_nba_rij(ids+1,k,j,P_r12)
570 nba_rij(ids,k,j,P_r12) =nba_rij(ids+1,k,j,P_r12)
576 IF( .NOT. config_flags%periodic_y .AND. j_start .EQ. jds+1) THEN
581 g_defor12(i,k,jds) =g_defor12(i,k,jds+1)
582 defor12(i,k,jds) =defor12(i,k,jds+1)
584 g_nba_rij(i,k,jds,P_r12) =g_nba_rij(i,k,jds+1,P_r12)
585 nba_rij(i,k,jds,P_r12) =nba_rij(i,k,jds+1,P_r12)
591 IF( .NOT. config_flags%periodic_x .AND. i_end .EQ. ide-1) THEN
596 g_defor12(ide,k,j) =g_defor12(ide-1,k,j)
597 defor12(ide,k,j) =defor12(ide-1,k,j)
599 g_nba_rij(ide,k,j,P_r12) =g_nba_rij(ide-1,k,j,P_r12)
600 nba_rij(ide,k,j,P_r12) =nba_rij(ide-1,k,j,P_r12)
606 IF( .NOT. config_flags%periodic_y .AND. j_end .EQ. jde-1) THEN
611 g_defor12(i,k,jde) =g_defor12(i,k,jde-1)
612 defor12(i,k,jde) =defor12(i,k,jde-1)
614 g_nba_rij(i,k,jde,P_r12) =g_nba_rij(i,k,jde-1,P_r12)
615 nba_rij(i,k,jde,P_r12) =nba_rij(i,k,jde-1,P_r12)
627 g_Tmpv1 =mm(i,j)*(rdx*(g_hat(i,k,j) -g_hat(i-1,k,j)) -g_tmp1(i,k,j)) &
628 +g_mm(i,j)*(rdx*(hat(i,k,j) -hat(i-1,k,j)) -tmp1(i,k,j))
629 Tmpv1 =mm(i,j)*(rdx*(hat(i,k,j) -hat(i-1,k,j)) -tmp1(i,k,j))
631 g_defor12(i,k,j) =g_defor12(i,k,j) +g_Tmpv1
632 defor12(i,k,j) =defor12(i,k,j) +Tmpv1
638 IF( .NOT. config_flags%periodic_x .AND. i_start .EQ. ids+1 ) THEN
643 g_defor12(ids,k,j) =g_defor12(ids+1,k,j)
644 defor12(ids,k,j) =defor12(ids+1,k,j)
650 IF( .NOT. config_flags%periodic_y .AND. j_start .EQ. jds+1) THEN
655 g_defor12(i,k,jds) =g_defor12(i,k,jds+1)
656 defor12(i,k,jds) =defor12(i,k,jds+1)
662 IF( .NOT. config_flags%periodic_x .AND. i_end .EQ. ide-1) THEN
667 g_defor12(ide,k,j) =g_defor12(ide-1,k,j)
668 defor12(ide,k,j) =defor12(ide-1,k,j)
674 IF( .NOT. config_flags%periodic_y .AND. j_end .EQ. jde-1) THEN
679 g_defor12(i,k,jde) =g_defor12(i,k,jde-1)
680 defor12(i,k,jde) =defor12(i,k,jde-1)
690 i_end =min(ite,ide-1)
694 j_end =min(jte,jde-1)
696 IF( config_flags%open_xs .OR. config_flags%specified .OR. &
697 config_flags%nested) i_start =max(ids+1,its)
699 IF( config_flags%open_ys .OR. config_flags%specified .OR. &
700 config_flags%nested) j_start =max(jds+1,jts)
702 IF( config_flags%periodic_x ) i_start =its
704 IF( config_flags%periodic_x ) i_end =min(ite,ide)
706 IF( config_flags%periodic_y ) j_end =min(jte,jde)
712 mm(i,j) =msfux(i,j) *msfuy(i,j)
721 g_hat(i,k,j) =g_w(i,k,j)/msfty(i,j)
722 hat(i,k,j) =w(i,k,j)/msfty(i,j)
730 DO j =j_start,min(jte,jde-1)
733 g_hat(i,k,j) =g_w(i,k,j)/msfty(i,j)
734 hat(i,k,j) =w(i,k,j)/msfty(i,j)
742 DO i =i_start,min(ite,ide-1)
744 g_hat(i,k,j) =g_w(i,k,j)/msfty(i,j)
745 hat(i,k,j) =w(i,k,j)/msfty(i,j)
754 g_hatavg(i,k,j) =0.25*(g_hat(i,k,j) +g_hat(i,k+1,j) +g_hat(i-1,k,j) &
756 hatavg(i,k,j) =0.25*(hat(i,k,j) +hat(i,k+1,j) +hat(i-1,k,j) +hat(i-1,k+1,j))
766 g_Tmpv1 =(hatavg(i,k,j) -hatavg(i,k-1,j))*g_zx(i,k,j) +(g_hatavg(i,k,j) &
767 -g_hatavg(i,k-1,j))*zx(i,k,j)
768 Tmpv1 =(hatavg(i,k,j) -hatavg(i,k-1,j))*zx(i,k,j)
770 g_Tmpv2 =Tmpv1*0.5*(g_rdz(i,k,j) +g_rdz(i-1,k,j)) +g_Tmpv1*0.5*(rdz(i,k, &
772 Tmpv2 =Tmpv1*0.5*(rdz(i,k,j) +rdz(i-1,k,j))
774 g_tmp1(i,k,j) =g_Tmpv2
785 g_Tmpv1 =mm(i,j)*(rdx*(g_hat(i,k,j) -g_hat(i-1,k,j)) -g_tmp1(i,k,j)) &
786 +g_mm(i,j)*(rdx*(hat(i,k,j) -hat(i-1,k,j)) -tmp1(i,k,j))
787 Tmpv1 =mm(i,j)*(rdx*(hat(i,k,j) -hat(i-1,k,j)) -tmp1(i,k,j))
789 g_defor13(i,k,j) =g_Tmpv1
790 defor13(i,k,j) =Tmpv1
799 g_defor13(i,kts,j) =0.0
800 defor13(i,kts,j) =0.0
802 g_defor13(i,ktf+1,j) =0.0
803 defor13(i,ktf+1,j) =0.0
808 IF( config_flags%mix_full_fields ) THEN
814 g_Tmpv1 =(u(i,k,j) -u(i,k-1,j))*0.5*(g_rdz(i,k,j) +g_rdz(i-1,k,j)) &
815 +(g_u(i,k,j) -g_u(i,k-1,j))*0.5*(rdz(i,k,j) +rdz(i-1,k,j))
816 Tmpv1 =(u(i,k,j) -u(i,k-1,j))*0.5*(rdz(i,k,j) +rdz(i-1,k,j))
818 g_tmp1(i,k,j) =g_Tmpv1
830 g_Tmpv1 =(u(i,k,j) -u_base(k) -u(i,k-1,j) +u_base(k-1))*0.5*(g_rdz(i,k,j) &
831 +g_rdz(i-1,k,j)) +(g_u(i,k,j) -g_u(i,k-1,j))*0.5*(rdz(i,k,j) +rdz(i-1,k,j))
832 Tmpv1 =(u(i,k,j) -u_base(k) -u(i,k-1,j) +u_base(k-1))*0.5*(rdz(i,k,j) +rdz(i-1,k,j))
834 g_tmp1(i,k,j) =g_Tmpv1
844 IF( config_flags%sfs_opt .GT. 0 ) THEN
850 g_nba_rij(i,k,j,P_r13) =g_tmp1(i,k,j) -g_defor13(i,k,j)
851 nba_rij(i,k,j,P_r13) =tmp1(i,k,j) -defor13(i,k,j)
853 g_defor13(i,k,j) =g_defor13(i,k,j) +g_tmp1(i,k,j)
854 defor13(i,k,j) =defor13(i,k,j) +tmp1(i,k,j)
863 g_nba_rij(i,kts,j,P_r13) =0.0
864 nba_rij(i,kts,j,P_r13) =0.0
866 g_nba_rij(i,ktf+1,j,P_r13) =0.0
867 nba_rij(i,ktf+1,j,P_r13) =0.0
878 g_defor13(i,k,j) =g_defor13(i,k,j) +g_tmp1(i,k,j)
879 defor13(i,k,j) =defor13(i,k,j) +tmp1(i,k,j)
891 i_end =min(ite,ide-1)
895 j_end =min(jte,jde-1)
897 IF( config_flags%open_xs .OR. config_flags%specified .OR. &
898 config_flags%nested) i_start =max(ids+1,its)
900 IF( config_flags%open_ys .OR. config_flags%specified .OR. &
901 config_flags%nested) j_start =max(jds+1,jts)
903 IF( config_flags%periodic_y ) j_end =min(jte,jde)
905 IF( config_flags%periodic_x ) i_start =its
907 IF( config_flags%periodic_x ) i_end =min(ite,ide-1)
913 mm(i,j) =msfvx(i,j) *msfvy(i,j)
922 g_hat(i,k,j) =g_w(i,k,j)/msftx(i,j)
923 hat(i,k,j) =w(i,k,j)/msftx(i,j)
931 DO j =j_start,min(jte,jde-1)
934 g_hat(i,k,j) =g_w(i,k,j)/msftx(i,j)
935 hat(i,k,j) =w(i,k,j)/msftx(i,j)
943 DO i =i_start,min(ite,ide-1)
945 g_hat(i,k,j) =g_w(i,k,j)/msftx(i,j)
946 hat(i,k,j) =w(i,k,j)/msftx(i,j)
955 g_hatavg(i,k,j) =0.25*(g_hat(i,k,j) +g_hat(i,k+1,j) +g_hat(i,k,j-1) &
957 hatavg(i,k,j) =0.25*(hat(i,k,j) +hat(i,k+1,j) +hat(i,k,j-1) +hat(i,k+1,j-1))
967 g_Tmpv1 =(hatavg(i,k,j) -hatavg(i,k-1,j))*g_zy(i,k,j) +(g_hatavg(i,k,j) &
968 -g_hatavg(i,k-1,j))*zy(i,k,j)
969 Tmpv1 =(hatavg(i,k,j) -hatavg(i,k-1,j))*zy(i,k,j)
971 g_Tmpv2 =Tmpv1*0.5*(g_rdz(i,k,j) +g_rdz(i,k,j-1)) +g_Tmpv1*0.5*(rdz(i,k, &
973 Tmpv2 =Tmpv1*0.5*(rdz(i,k,j) +rdz(i,k,j-1))
975 g_tmp1(i,k,j) =g_Tmpv2
986 g_Tmpv1 =mm(i,j)*(rdy*(g_hat(i,k,j) -g_hat(i,k,j-1)) -g_tmp1(i,k,j)) &
987 +g_mm(i,j)*(rdy*(hat(i,k,j) -hat(i,k,j-1)) -tmp1(i,k,j))
988 Tmpv1 =mm(i,j)*(rdy*(hat(i,k,j) -hat(i,k,j-1)) -tmp1(i,k,j))
990 g_defor23(i,k,j) =g_Tmpv1
991 defor23(i,k,j) =Tmpv1
1000 g_defor23(i,kts,j) =0.0
1001 defor23(i,kts,j) =0.0
1003 g_defor23(i,ktf+1,j) =0.0
1004 defor23(i,ktf+1,j) =0.0
1009 IF( config_flags%mix_full_fields ) THEN
1015 g_Tmpv1 =(v(i,k,j) -v(i,k-1,j))*0.5*(g_rdz(i,k,j) +g_rdz(i,k,j-1)) &
1016 +(g_v(i,k,j) -g_v(i,k-1,j))*0.5*(rdz(i,k,j) +rdz(i,k,j-1))
1017 Tmpv1 =(v(i,k,j) -v(i,k-1,j))*0.5*(rdz(i,k,j) +rdz(i,k,j-1))
1019 g_tmp1(i,k,j) =g_Tmpv1
1031 g_Tmpv1 =(v(i,k,j) -v_base(k) -v(i,k-1,j) +v_base(k-1))*0.5*(g_rdz(i,k,j) &
1032 +g_rdz(i,k,j-1)) +(g_v(i,k,j) -g_v(i,k-1,j))*0.5*(rdz(i,k,j) +rdz(i,k,j-1))
1033 Tmpv1 =(v(i,k,j) -v_base(k) -v(i,k-1,j) +v_base(k-1))*0.5*(rdz(i,k,j) +rdz(i,k,j-1))
1035 g_tmp1(i,k,j) =g_Tmpv1
1043 IF( config_flags%sfs_opt .GT. 0 ) THEN
1049 g_nba_rij(i,k,j,P_r23) =g_tmp1(i,k,j) -g_defor23(i,k,j)
1050 nba_rij(i,k,j,P_r23) =tmp1(i,k,j) -defor23(i,k,j)
1052 g_defor23(i,k,j) =g_defor23(i,k,j) +g_tmp1(i,k,j)
1053 defor23(i,k,j) =defor23(i,k,j) +tmp1(i,k,j)
1062 g_nba_rij(i,kts,j,P_r23) =0.0
1063 nba_rij(i,kts,j,P_r23) =0.0
1065 g_nba_rij(i,ktf+1,j,P_r23) =0.0
1066 nba_rij(i,ktf+1,j,P_r23) =0.0
1071 IF( .NOT. config_flags%periodic_x .AND. i_start .EQ. ids+1) THEN
1076 g_defor13(ids,k,j) =g_defor13(ids+1,k,j)
1077 defor13(ids,k,j) =defor13(ids+1,k,j)
1079 g_defor23(ids,k,j) =g_defor23(ids+1,k,j)
1080 defor23(ids,k,j) =defor23(ids+1,k,j)
1082 g_nba_rij(ids,k,j,P_r13) =g_nba_rij(ids+1,k,j,P_r13)
1083 nba_rij(ids,k,j,P_r13) =nba_rij(ids+1,k,j,P_r13)
1085 g_nba_rij(ids,k,j,P_r23) =g_nba_rij(ids+1,k,j,P_r23)
1086 nba_rij(ids,k,j,P_r23) =nba_rij(ids+1,k,j,P_r23)
1092 IF( .NOT. config_flags%periodic_y .AND. j_start .EQ. jds+1) THEN
1097 g_defor13(i,k,jds) =g_defor13(i,k,jds+1)
1098 defor13(i,k,jds) =defor13(i,k,jds+1)
1100 g_defor23(i,k,jds) =g_defor23(i,k,jds+1)
1101 defor23(i,k,jds) =defor23(i,k,jds+1)
1103 g_nba_rij(i,k,jds,P_r13) =g_nba_rij(i,k,jds+1,P_r13)
1104 nba_rij(i,k,jds,P_r13) =nba_rij(i,k,jds+1,P_r13)
1106 g_nba_rij(i,k,jds,P_r23) =g_nba_rij(i,k,jds+1,P_r23)
1107 nba_rij(i,k,jds,P_r23) =nba_rij(i,k,jds+1,P_r23)
1113 IF( .NOT. config_flags%periodic_x .AND. i_end .EQ. ide-1) THEN
1118 g_defor13(ide,k,j) =g_defor13(ide-1,k,j)
1119 defor13(ide,k,j) =defor13(ide-1,k,j)
1121 g_defor23(ide,k,j) =g_defor23(ide-1,k,j)
1122 defor23(ide,k,j) =defor23(ide-1,k,j)
1124 g_nba_rij(ide,k,j,P_r13) =g_nba_rij(ide-1,k,j,P_r13)
1125 nba_rij(ide,k,j,P_r13) =nba_rij(ide-1,k,j,P_r13)
1127 g_nba_rij(ide,k,j,P_r23) =g_nba_rij(ide-1,k,j,P_r23)
1128 nba_rij(ide,k,j,P_r23) =nba_rij(ide-1,k,j,P_r23)
1134 IF( .NOT. config_flags%periodic_y .AND. j_end .EQ. jde-1) THEN
1139 g_defor13(i,k,jde) =g_defor13(i,k,jde-1)
1140 defor13(i,k,jde) =defor13(i,k,jde-1)
1142 g_defor23(i,k,jde) =g_defor23(i,k,jde-1)
1143 defor23(i,k,jde) =defor23(i,k,jde-1)
1145 g_nba_rij(i,k,jde,P_r13) =g_nba_rij(i,k,jde-1,P_r13)
1146 nba_rij(i,k,jde,P_r13) =nba_rij(i,k,jde-1,P_r13)
1148 g_nba_rij(i,k,jde,P_r23) =g_nba_rij(i,k,jde-1,P_r23)
1149 nba_rij(i,k,jde,P_r23) =nba_rij(i,k,jde-1,P_r23)
1161 g_defor23(i,k,j) =g_defor23(i,k,j) +g_tmp1(i,k,j)
1162 defor23(i,k,j) =defor23(i,k,j) +tmp1(i,k,j)
1168 IF( .NOT. config_flags%periodic_x .AND. i_start .EQ. ids+1) THEN
1173 g_defor13(ids,k,j) =g_defor13(ids+1,k,j)
1174 defor13(ids,k,j) =defor13(ids+1,k,j)
1176 g_defor23(ids,k,j) =g_defor23(ids+1,k,j)
1177 defor23(ids,k,j) =defor23(ids+1,k,j)
1183 IF( .NOT. config_flags%periodic_y .AND. j_start .EQ. jds+1) THEN
1188 g_defor13(i,k,jds) =g_defor13(i,k,jds+1)
1189 defor13(i,k,jds) =defor13(i,k,jds+1)
1191 g_defor23(i,k,jds) =g_defor23(i,k,jds+1)
1192 defor23(i,k,jds) =defor23(i,k,jds+1)
1198 IF( .NOT. config_flags%periodic_x .AND. i_end .EQ. ide-1) THEN
1203 g_defor13(ide,k,j) =g_defor13(ide-1,k,j)
1204 defor13(ide,k,j) =defor13(ide-1,k,j)
1206 g_defor23(ide,k,j) =g_defor23(ide-1,k,j)
1207 defor23(ide,k,j) =defor23(ide-1,k,j)
1213 IF( .NOT. config_flags%periodic_y .AND. j_end .EQ. jde-1) THEN
1218 g_defor13(i,k,jde) =g_defor13(i,k,jde-1)
1219 defor13(i,k,jde) =defor13(i,k,jde-1)
1221 g_defor23(i,k,jde) =g_defor23(i,k,jde-1)
1222 defor23(i,k,jde) =defor23(i,k,jde-1)
1230 END SUBROUTINE g_cal_deform_and_div
1232 SUBROUTINE g_calculate_km_kh(config_flags,dt,dampcoef,zdamp,damp_opt,xkmh, &
1233 g_xkmh,xkmv,g_xkmv,xkhh,g_xkhh,xkhv,g_xkhv,BN2,g_BN2,khdif,kvdif,div, &
1234 g_div,defor11,g_defor11,defor22,g_defor22,defor33,g_defor33,defor12, &
1235 g_defor12,defor13,g_defor13,defor23,g_defor23,tke,g_tke,p8w,g_p8w,t8w, &
1236 g_t8w,theta,g_theta,t,g_t,p,g_p,moist,g_moist,dn,dnw,dx,dy,rdz, &
1237 g_rdz,rdzw,g_rdzw,isotropic,n_moist,cf1,cf2,cf3,warm_rain,mix_upper_bound, &
1238 msftx,msfty,zx,g_zx,zy,g_zy,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
1242 REAL :: Tmpv1,g_Tmpv1
1243 TYPE(grid_config_rec_type) :: config_flags
1244 INTEGER :: n_moist,damp_opt,isotropic,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms, &
1245 kme,its,ite,jts,jte,kts,kte
1246 LOGICAL :: warm_rain
1247 REAL :: dx,dy,zdamp,dt,dampcoef,cf1,cf2,cf3,khdif,kvdif
1248 REAL,DIMENSION(kms:kme) :: dnw,dn
1249 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_moist) :: moist,g_moist
1250 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: xkmv,g_xkmv,xkmh,g_xkmh,xkhv, &
1251 g_xkhv,xkhh,g_xkhh,BN2,g_BN2
1252 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor11,g_defor11,defor22,g_defor22, &
1253 defor33,g_defor33,defor12,g_defor12,defor13,g_defor13,defor23,g_defor23, &
1254 div,g_div,rdz,g_rdz,rdzw,g_rdzw,p8w,g_p8w,t8w,g_t8w,theta,g_theta, &
1255 t,g_t,p,g_p,zx,g_zx,zy,g_zy
1256 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tke,g_tke
1257 REAL :: mix_upper_bound
1258 REAL,DIMENSION(ims:ime,jms:jme) :: msftx,msfty
1259 INTEGER :: i_start,i_end,j_start,j_end,ktf,i,j,k!,km_opt
1265 i_end =min(ite,ide-1)
1269 j_end =min(jte,jde-1)
1271 CALL g_calculate_N2(config_flags,BN2,g_BN2,moist,g_moist,theta,g_theta,t, &
1272 g_t,p,g_p,p8w,g_p8w,t8w,g_t8w,dnw,dn,rdz,g_rdz,rdzw,g_rdzw,n_moist, &
1273 cf1,cf2,cf3,warm_rain,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts, &
1276 !ALL THE FOLLOWING STRUNCTURE ARE REVISED BY WALLS
1277 !ALL THE FOLLOWING STRUNCTURE ARE REVISED BY WALLS
1279 !km_opt =config_flags%km_opt
1281 !PRINT*, 'km_opt =', km_opt
1283 !Select a scheme for calculating diffusion coefficients.
1284 km_coef: SELECT CASE( config_flags%km_opt )
1285 !km_coef: SELECT CASE( km_opt )
1289 CALL g_isotropic_km(config_flags,xkmh,g_xkmh,xkmv,g_xkmv,xkhh,g_xkhh, &
1290 xkhv,g_xkhv,khdif,kvdif,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite, &
1295 CALL g_tke_km(config_flags,xkmh,g_xkmh,xkmv,g_xkmv,xkhh,g_xkhh,xkhv, &
1296 g_xkhv,BN2,g_BN2,tke,g_tke,p8w,g_p8w,t8w,g_t8w,theta,g_theta,rdz, &
1297 g_rdz,rdzw,g_rdzw,dx,dy,dt,isotropic,mix_upper_bound,msftx,msfty,ids,ide,jds, &
1298 jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
1302 CALL g_smag_km(config_flags,xkmh,g_xkmh,xkmv,g_xkmv,xkhh,g_xkhh,xkhv, &
1303 g_xkhv,BN2,g_BN2,div,g_div,defor11,g_defor11,defor22,g_defor22, &
1304 defor33,g_defor33,defor12,g_defor12,defor13,g_defor13,defor23,g_defor23, &
1305 rdzw,g_rdzw,dx,dy,dt,isotropic,mix_upper_bound,msftx,msfty,ids,ide,jds,jde,kds, &
1306 kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
1310 CALL g_smag2d_km(config_flags,xkmh,g_xkmh,xkmv,g_xkmv,xkhh,g_xkhh,xkhv, &
1311 g_xkhv,defor11,g_defor11,defor22,g_defor22,defor12,g_defor12,rdzw, &
1312 g_rdzw,dx,dy,msftx,msfty,zx,g_zx,zy,g_zy,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite, &
1318 !CALL g_wrf_error_fatal('Please choose diffusion coefficient scheme')
1319 CALL wrf_error_fatal( 'Please choose diffusion coefficient scheme' )
1323 IF( damp_opt .eq. 1 ) THEN
1325 CALL g_cal_dampkm(config_flags,xkmh,g_xkmh,xkhh,g_xkhh,xkmv,g_xkmv,xkhv, &
1326 g_xkhv,dx,dy,dt,dampcoef,rdz,g_rdz,rdzw,g_rdzw,zdamp,msftx,msfty,ids,ide, &
1327 jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
1331 END SUBROUTINE g_calculate_km_kh
1333 SUBROUTINE g_cal_dampkm(config_flags,xkmh,g_xkmh,xkhh,g_xkhh,xkmv,g_xkmv, &
1334 xkhv,g_xkhv,dx,dy,dt,dampcoef,rdz,g_rdz,rdzw,g_rdzw,zdamp,msftx,msfty,ids, &
1335 ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
1339 REAL :: Tmpv1,g_Tmpv1,Tmpv2,g_Tmpv2,Tmpv3,g_Tmpv3,Tmpv4,g_Tmpv4,Tmpv5,g_Tmpv5
1340 TYPE(grid_config_rec_type) :: config_flags
1341 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
1342 REAL :: zdamp,dx,dy,dt,dampcoef
1343 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: xkmh,g_xkmh,xkhh,g_xkhh,xkmv, &
1345 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: rdz,g_rdz,rdzw,g_rdzw
1346 REAL,DIMENSION(ims:ime,jms:jme) :: msftx,msfty
1347 INTEGER :: i_start,i_end,j_start,j_end,ktf,ktfm1,i,j,k
1348 REAL :: kmmax,kmmvmax,g_kmmvmax,degrad90,dz,g_dz,tmp,g_tmp
1350 REAL,DIMENSION(its:ite) :: deltaz,g_deltaz
1351 REAL,DIMENSION(its:ite,kts:kte,jts:jte) :: dampk,g_dampk,dampkv,g_dampkv
1359 i_end =min(ite,ide-1)
1363 j_end =min(jte,jde-1)
1365 IF(config_flags%specified .OR. config_flags%nested) THEN
1367 i_start =max(i_start,ids +config_flags%spec_bdy_width -1)
1369 i_end =min(i_end,ide -config_flags%spec_bdy_width)
1371 j_start =max(j_start,jds +config_flags%spec_bdy_width -1)
1373 j_end =min(j_end,jde -config_flags%spec_bdy_width)
1378 degrad90 =DEGRAD *90.
1386 ds =min(dx/msftx(i,j),dy/msfty(i,j))
1390 g_dz =-1.*g_rdzw(i,k,j)/(rdzw(i,k,j)*rdzw(i,k,j))
1393 g_deltaz(i) =0.5*g_dz
1396 g_Tmpv1 =2.0*dz*g_dz
1399 g_kmmvmax =g_Tmpv1/dt
1402 g_tmp =(g_deltaz(i)/zdamp +0.0 -(g_deltaz(i)/zdamp -0.0)*sign(1.0, deltaz(i) &
1404 tmp =min(deltaz(i)/zdamp,1.)
1406 g_Tmpv1 =2.0*cos(degrad90*tmp)*(-degrad90*g_tmp*sin(degrad90*tmp))
1407 Tmpv1 =cos(degrad90*tmp)*cos(degrad90*tmp)
1409 g_dampk(i,k,j) =g_Tmpv1*kmmax*dampcoef
1410 dampk(i,k,j) =Tmpv1*kmmax*dampcoef
1412 g_Tmpv1 =2.0*cos(degrad90*tmp)*(-degrad90*g_tmp*sin(degrad90*tmp))
1413 Tmpv1 =cos(degrad90*tmp)*cos(degrad90*tmp)
1415 g_Tmpv2 =Tmpv1*g_kmmvmax +g_Tmpv1*kmmvmax
1416 Tmpv2 =Tmpv1*kmmvmax
1418 g_dampkv(i,k,j) =g_Tmpv2*dampcoef
1419 dampkv(i,k,j) =Tmpv2*dampcoef
1421 g_dampkv(i,k,j) =(g_dampkv(i,k,j) +g_dampk(i,k,j) -(g_dampkv(i,k,j) &
1422 -g_dampk(i,k,j))*sign(1.0, dampkv(i,k,j) -(dampk(i,k,j))))*0.5
1423 dampkv(i,k,j) =min(dampkv(i,k,j),dampk(i,k,j))
1430 ds =min(dx/msftx(i,j),dy/msfty(i,j))
1434 g_dz =-1.*g_rdz(i,k,j)/(rdz(i,k,j)*rdz(i,k,j))
1437 g_deltaz(i) =g_deltaz(i) +g_dz
1438 deltaz(i) =deltaz(i) +dz
1440 g_dz =-1.*g_rdzw(i,k,j)/(rdzw(i,k,j)*rdzw(i,k,j))
1443 g_Tmpv1 =2.0*dz*g_dz
1446 g_kmmvmax =g_Tmpv1/dt
1449 g_tmp =(g_deltaz(i)/zdamp +0.0 -(g_deltaz(i)/zdamp -0.0)*sign(1.0, deltaz(i) &
1451 tmp =min(deltaz(i)/zdamp,1.)
1453 g_Tmpv1 =2.0*cos(degrad90*tmp)*(-degrad90*g_tmp*sin(degrad90*tmp))
1454 Tmpv1 =cos(degrad90*tmp)*cos(degrad90*tmp)
1456 g_dampk(i,k,j) =g_Tmpv1*kmmax*dampcoef
1457 dampk(i,k,j) =Tmpv1*kmmax*dampcoef
1459 g_Tmpv1 =2.0*cos(degrad90*tmp)*(-degrad90*g_tmp*sin(degrad90*tmp))
1460 Tmpv1 =cos(degrad90*tmp)*cos(degrad90*tmp)
1462 g_Tmpv2 =Tmpv1*g_kmmvmax +g_Tmpv1*kmmvmax
1463 Tmpv2 =Tmpv1*kmmvmax
1465 g_dampkv(i,k,j) =g_Tmpv2*dampcoef
1466 dampkv(i,k,j) =Tmpv2*dampcoef
1468 g_dampkv(i,k,j) =(g_dampkv(i,k,j) +g_dampk(i,k,j) -(g_dampkv(i,k,j) &
1469 -g_dampk(i,k,j))*sign(1.0, dampkv(i,k,j) -(dampk(i,k,j))))*0.5
1470 dampkv(i,k,j) =min(dampkv(i,k,j),dampk(i,k,j))
1480 g_xkmh(i,k,j) =(g_xkmh(i,k,j) +g_dampk(i,k,j) +(g_xkmh(i,k,j) &
1481 -g_dampk(i,k,j))*sign(1.0, xkmh(i,k,j) -(dampk(i,k,j))))*0.5
1482 xkmh(i,k,j) =max(xkmh(i,k,j),dampk(i,k,j))
1484 g_xkhh(i,k,j) =(g_xkhh(i,k,j) +g_dampk(i,k,j) +(g_xkhh(i,k,j) &
1485 -g_dampk(i,k,j))*sign(1.0, xkhh(i,k,j) -(dampk(i,k,j))))*0.5
1486 xkhh(i,k,j) =max(xkhh(i,k,j),dampk(i,k,j))
1488 g_xkmv(i,k,j) =(g_xkmv(i,k,j) +g_dampkv(i,k,j) +(g_xkmv(i,k,j) &
1489 -g_dampkv(i,k,j))*sign(1.0, xkmv(i,k,j) -(dampkv(i,k,j))))*0.5
1490 xkmv(i,k,j) =max(xkmv(i,k,j),dampkv(i,k,j))
1492 g_xkhv(i,k,j) =(g_xkhv(i,k,j) +g_dampkv(i,k,j) +(g_xkhv(i,k,j) &
1493 -g_dampkv(i,k,j))*sign(1.0, xkhv(i,k,j) -(dampkv(i,k,j))))*0.5
1494 xkhv(i,k,j) =max(xkhv(i,k,j),dampkv(i,k,j))
1500 END SUBROUTINE g_cal_dampkm
1502 ! Generated by TAPENADE (INRIA, Tropics team)
1503 ! Tapenade 3.5 (r3785) - 22 Mar 2011 18:35
1505 ! Differentiation of calculate_n2 in forward (tangent) mode:
1506 ! variations of useful results: bn2
1507 ! with respect to varying inputs: p t t8w bn2 theta rdzw rdz
1509 ! RW status of diff variables: p:in t:in t8w:in bn2:in-out theta:in
1510 ! rdzw:in rdz:in moist:in p8w:in
1511 SUBROUTINE G_CALCULATE_N2(config_flags, bn2, bn2d, moist, moistd, theta&
1512 & , thetad, t, td, p, pd, p8w, p8wd, t8w, t8wd, dnw, dn, rdz, rdzd, rdzw&
1513 & , rdzwd, n_moist, cf1, cf2, cf3, warm_rain, ids, ide, jds, jde, kds, &
1514 & kde, ims, ime, jms, jme, kms, kme, its, ite, jts, jte, kts, kte)
1516 ! end of MARTA/WCS change
1517 TYPE(GRID_CONFIG_REC_TYPE), INTENT(IN) :: config_flags
1518 INTEGER, INTENT(IN) :: n_moist, ids, ide, jds, jde, kds, kde, ims, ime&
1519 & , jms, jme, kms, kme, its, ite, jts, jte, kts, kte
1520 LOGICAL, INTENT(IN) :: warm_rain
1521 REAL, INTENT(IN) :: cf1, cf2, cf3
1522 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: bn2
1523 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: bn2d
1524 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: rdz, rdzw, &
1525 & theta, t, p, p8w, t8w
1526 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: rdzd, rdzwd&
1527 & , thetad, td, pd, p8wd, t8wd
1528 REAL, DIMENSION(kms:kme), INTENT(IN) :: dnw, dn
1529 REAL, DIMENSION(ims:ime, kms:kme, jms:jme, n_moist), INTENT(INOUT) :: &
1531 REAL, DIMENSION(ims:ime, kms:kme, jms:jme, n_moist), INTENT(INOUT) :: &
1534 INTEGER :: i, j, k, ktf, ispe, ktes1, ktes2, i_start, i_end, j_start, &
1536 REAL :: coefa, thetaep1, thetaem1, qc_cr, es, tc, qlpqi, qsw, qsi, &
1537 & tmpdz, xlvqv, thetaesfc, thetasfc, qvtop, qvsfc, thetatop, thetaetop
1538 REAL :: coefad, thetaep1d, thetaem1d, esd, tcd, tmpdzd, xlvqvd, &
1539 & thetaesfcd, thetasfcd, qvsfcd
1540 REAL, DIMENSION(its:ite, jts:jte) :: tmp1sfc, tmp1top
1541 REAL, DIMENSION(its:ite, jts:jte) :: tmp1sfcd
1542 REAL, DIMENSION(its:ite, kts:kte, jts:jte) :: tmp1, qvs, qctmp
1543 REAL, DIMENSION(its:ite, kts:kte, jts:jte) :: tmp1d, qvsd
1552 !-----------------------------------------------------------------------
1555 IF (kte .GT. kde - 1) THEN
1563 IF (ite .GT. ide - 1) THEN
1569 IF (jte .GT. jde - 1) THEN
1574 IF ((config_flags%open_xs .OR. config_flags%specified) .OR. &
1575 & config_flags%nested) THEN
1576 IF (ids + 1 .LT. its) THEN
1582 IF ((config_flags%open_xe .OR. config_flags%specified) .OR. &
1583 & config_flags%nested) THEN
1584 IF (ide - 2 .GT. ite) THEN
1590 IF ((config_flags%open_ys .OR. config_flags%specified) .OR. &
1591 & config_flags%nested) THEN
1592 IF (jds + 1 .LT. jts) THEN
1598 IF ((config_flags%open_ye .OR. config_flags%specified) .OR. &
1599 & config_flags%nested) THEN
1600 IF (jde - 2 .GT. jte) THEN
1606 IF (config_flags%periodic_x) i_start = its
1607 IF (config_flags%periodic_x) THEN
1608 IF (ite .GT. ide - 1) THEN
1614 IF (p_qc .GT. param_first_scalar) THEN
1618 qctmp(i, k, j) = moist(i, k, j, p_qc)
1626 qctmp(i, k, j) = 0.0
1634 tmp1d(i, k, j) = 0.0
1641 tmp1sfcd(i, j) = 0.0
1648 DO ispe=param_first_scalar,n_moist
1649 IF ((ispe .EQ. p_qv .OR. ispe .EQ. p_qc) .OR. ispe .EQ. p_qi) THEN
1653 tmp1d(i, k, j) = tmp1d(i, k, j) + moistd(i, k, j, ispe)
1654 tmp1(i, k, j) = tmp1(i, k, j) + moist(i, k, j, ispe)
1660 tmp1sfcd(i, j) = tmp1sfcd(i, j) + cf1*moistd(i, 1, j, ispe) + &
1661 & cf2*moistd(i, 2, j, ispe) + cf3*moistd(i, 3, j, ispe)
1662 tmp1sfc(i, j) = tmp1sfc(i, j) + cf1*moist(i, 1, j, ispe) + cf2&
1663 & *moist(i, 2, j, ispe) + cf3*moist(i, 3, j, ispe)
1664 tmp1top(i, j) = tmp1top(i, j) + moist(i, ktes1, j, ispe) + (&
1665 & moist(i, ktes1, j, ispe)-moist(i, ktes2, j, ispe))*0.5*dnw(&
1672 ! Calculate saturation mixing ratio.
1677 tc = t(i, k, j) - svpt0
1678 arg1d = (svp2*tcd*(t(i, k, j)-svp3)-svp2*tc*td(i, k, j))/(t(i, k&
1680 arg1 = svp2*tc/(t(i, k, j)-svp3)
1681 esd = 1000.0*svp1*arg1d*EXP(arg1)
1682 es = 1000.0*svp1*EXP(arg1)
1683 qvsd(i, k, j) = (ep_2*esd*(p(i, k, j)-es)-ep_2*es*(pd(i, k, j)-&
1684 & esd))/(p(i, k, j)-es)**2
1685 qvs(i, k, j) = ep_2*es/(p(i, k, j)-es)
1692 tmpdzd = -(rdzd(i, k, j)/rdz(i, k, j)**2) - rdzd(i, k+1, j)/rdz(&
1694 tmpdz = 1.0/rdz(i, k, j) + 1.0/rdz(i, k+1, j)
1695 IF (moist(i, k, j, p_qv) .GE. qvs(i, k, j) .OR. qctmp(i, k, j) &
1697 xlvqvd = xlv*moistd(i, k, j, p_qv)
1698 xlvqv = xlv*moist(i, k, j, p_qv)
1699 coefad = (((xlvqvd*t(i, k, j)/r_d-xlvqv*td(i, k, j)/r_d)*(1.0+&
1700 & xlv*xlvqv/cp/r_v/t(i, k, j)/t(i, k, j))/t(i, k, j)**2-(1.0+&
1701 & xlvqv/r_d/t(i, k, j))*((xlv*xlvqvd*t(i, k, j)/(cp*r_v)-xlv*&
1702 & xlvqv*td(i, k, j)/(cp*r_v))/t(i, k, j)-xlv*xlvqv*td(i, k, j)&
1703 & /(cp*r_v*t(i, k, j)))/t(i, k, j)**2)*theta(i, k, j)/(1.0+xlv&
1704 & *xlvqv/cp/r_v/t(i, k, j)/t(i, k, j))**2-(1.0+xlvqv/r_d/t(i, &
1705 & k, j))*thetad(i, k, j)/(1.0+xlv*xlvqv/cp/r_v/t(i, k, j)/t(i&
1706 & , k, j)))/theta(i, k, j)**2
1707 coefa = (1.0+xlvqv/r_d/t(i, k, j))/(1.0+xlv*xlvqv/cp/r_v/t(i, &
1708 & k, j)/t(i, k, j))/theta(i, k, j)
1709 thetaep1d = thetad(i, k+1, j)*(1.0+xlv*qvs(i, k+1, j)/cp/t(i, &
1710 & k+1, j)) + theta(i, k+1, j)*(xlv*qvsd(i, k+1, j)*t(i, k+1, j&
1711 & )/cp-xlv*qvs(i, k+1, j)*td(i, k+1, j)/cp)/t(i, k+1, j)**2
1712 thetaep1 = theta(i, k+1, j)*(1.0+xlv*qvs(i, k+1, j)/cp/t(i, k+&
1714 thetaem1d = thetad(i, k-1, j)*(1.0+xlv*qvs(i, k-1, j)/cp/t(i, &
1715 & k-1, j)) + theta(i, k-1, j)*(xlv*qvsd(i, k-1, j)*t(i, k-1, j&
1716 & )/cp-xlv*qvs(i, k-1, j)*td(i, k-1, j)/cp)/t(i, k-1, j)**2
1717 thetaem1 = theta(i, k-1, j)*(1.0+xlv*qvs(i, k-1, j)/cp/t(i, k-&
1719 bn2d(i, k, j) = g*(((coefad*(thetaep1-thetaem1)+coefa*(&
1720 & thetaep1d-thetaem1d))*tmpdz-coefa*(thetaep1-thetaem1)*tmpdzd&
1721 & )/tmpdz**2-((tmp1d(i, k+1, j)-tmp1d(i, k-1, j))*tmpdz-(tmp1(&
1722 & i, k+1, j)-tmp1(i, k-1, j))*tmpdzd)/tmpdz**2)
1723 bn2(i, k, j) = g*(coefa*(thetaep1-thetaem1)/tmpdz-(tmp1(i, k+1&
1724 & , j)-tmp1(i, k-1, j))/tmpdz)
1726 bn2d(i, k, j) = g*((((thetad(i, k+1, j)-thetad(i, k-1, j))*&
1727 & theta(i, k, j)-(theta(i, k+1, j)-theta(i, k-1, j))*thetad(i&
1728 & , k, j))*tmpdz/theta(i, k, j)**2-(theta(i, k+1, j)-theta(i, &
1729 & k-1, j))*tmpdzd/theta(i, k, j))/tmpdz**2+(1.61*(moistd(i, k+&
1730 & 1, j, p_qv)-moistd(i, k-1, j, p_qv))*tmpdz-1.61*(moist(i, k+&
1731 & 1, j, p_qv)-moist(i, k-1, j, p_qv))*tmpdzd)/tmpdz**2-((tmp1d&
1732 & (i, k+1, j)-tmp1d(i, k-1, j))*tmpdz-(tmp1(i, k+1, j)-tmp1(i&
1733 & , k-1, j))*tmpdzd)/tmpdz**2)
1734 bn2(i, k, j) = g*((theta(i, k+1, j)-theta(i, k-1, j))/theta(i&
1735 & , k, j)/tmpdz+1.61*(moist(i, k+1, j, p_qv)-moist(i, k-1, j, &
1736 & p_qv))/tmpdz-(tmp1(i, k+1, j)-tmp1(i, k-1, j))/tmpdz)
1744 tmpdzd = -(rdzd(i, k+1, j)/rdz(i, k+1, j)**2) - 0.5*rdzwd(i, k, j)&
1746 tmpdz = 1.0/rdz(i, k+1, j) + 0.5/rdzw(i, k, j)
1747 pwx1d = p8wd(i, k, j)/p1000mb
1748 pwx1 = p8w(i, k, j)/p1000mb
1750 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pwy1 .EQ. INT(pwy1))) &
1752 pwr1d = pwy1*pwx1**(pwy1-1)*pwx1d
1753 ELSE IF (pwx1 .EQ. 0.0 .AND. pwy1 .EQ. 1.0) THEN
1759 thetasfcd = (t8wd(i, kts, j)*pwr1-t8w(i, kts, j)*pwr1d)/pwr1**2
1760 thetasfc = t8w(i, kts, j)/pwr1
1761 IF (moist(i, k, j, p_qv) .GE. qvs(i, k, j) .OR. qctmp(i, k, j) &
1763 qvsfcd = cf1*qvsd(i, 1, j) + cf2*qvsd(i, 2, j) + cf3*qvsd(i, 3, &
1765 qvsfc = cf1*qvs(i, 1, j) + cf2*qvs(i, 2, j) + cf3*qvs(i, 3, j)
1766 xlvqvd = xlv*moistd(i, k, j, p_qv)
1767 xlvqv = xlv*moist(i, k, j, p_qv)
1768 coefad = (((xlvqvd*t(i, k, j)/r_d-xlvqv*td(i, k, j)/r_d)*(1.0+&
1769 & xlv*xlvqv/cp/r_v/t(i, k, j)/t(i, k, j))/t(i, k, j)**2-(1.0+&
1770 & xlvqv/r_d/t(i, k, j))*((xlv*xlvqvd*t(i, k, j)/(cp*r_v)-xlv*&
1771 & xlvqv*td(i, k, j)/(cp*r_v))/t(i, k, j)-xlv*xlvqv*td(i, k, j)/(&
1772 & cp*r_v*t(i, k, j)))/t(i, k, j)**2)*theta(i, k, j)/(1.0+xlv*&
1773 & xlvqv/cp/r_v/t(i, k, j)/t(i, k, j))**2-(1.0+xlvqv/r_d/t(i, k, &
1774 & j))*thetad(i, k, j)/(1.0+xlv*xlvqv/cp/r_v/t(i, k, j)/t(i, k, j&
1775 & )))/theta(i, k, j)**2
1776 coefa = (1.0+xlvqv/r_d/t(i, k, j))/(1.0+xlv*xlvqv/cp/r_v/t(i, k&
1777 & , j)/t(i, k, j))/theta(i, k, j)
1778 thetaep1d = thetad(i, k+1, j)*(1.0+xlv*qvs(i, k+1, j)/cp/t(i, k+&
1779 & 1, j)) + theta(i, k+1, j)*(xlv*qvsd(i, k+1, j)*t(i, k+1, j)/cp&
1780 & -xlv*qvs(i, k+1, j)*td(i, k+1, j)/cp)/t(i, k+1, j)**2
1781 thetaep1 = theta(i, k+1, j)*(1.0+xlv*qvs(i, k+1, j)/cp/t(i, k+1&
1783 thetaesfcd = thetasfcd*(1.0+xlv*qvsfc/cp/t8w(i, kts, j)) + &
1784 & thetasfc*(xlv*qvsfcd*t8w(i, kts, j)/cp-xlv*qvsfc*t8wd(i, kts, &
1785 & j)/cp)/t8w(i, kts, j)**2
1786 thetaesfc = thetasfc*(1.0+xlv*qvsfc/cp/t8w(i, kts, j))
1787 bn2d(i, k, j) = g*(((coefad*(thetaep1-thetaesfc)+coefa*(&
1788 & thetaep1d-thetaesfcd))*tmpdz-coefa*(thetaep1-thetaesfc)*tmpdzd&
1789 & )/tmpdz**2-((tmp1d(i, k+1, j)-tmp1sfcd(i, j))*tmpdz-(tmp1(i, k&
1790 & +1, j)-tmp1sfc(i, j))*tmpdzd)/tmpdz**2)
1791 bn2(i, k, j) = g*(coefa*(thetaep1-thetaesfc)/tmpdz-(tmp1(i, k+1&
1792 & , j)-tmp1sfc(i, j))/tmpdz)
1794 qvsfcd = cf1*moistd(i, 1, j, p_qv) + cf2*moistd(i, 2, j, p_qv) +&
1795 & cf3*moistd(i, 3, j, p_qv)
1796 qvsfc = cf1*moist(i, 1, j, p_qv) + cf2*moist(i, 2, j, p_qv) + &
1797 & cf3*moist(i, 3, j, p_qv)
1798 ! BN2(i,k,j) = g * ( ( theta(i,k+1,j) - thetasfc ) / &
1799 ! theta(i,k,j) / tmpdz + &
1800 ! 1.61 * ( moist(i,k+1,j,P_QV) - qvsfc ) / &
1802 ! ( tmp1(i,k+1,j) - tmp1sfc(i,j) ) / tmpdz )
1803 !...... MARTA: change in computation of BN2 at the surface, WCS 040331
1804 ! controlare come calcola rdzw
1805 tmpdzd = -(rdzwd(i, k, j)/rdzw(i, k, j)**2)
1806 tmpdz = 1./rdzw(i, k, j)
1807 bn2d(i, k, j) = g*((((thetad(i, k+1, j)-thetad(i, k, j))*theta(i&
1808 & , k, j)-(theta(i, k+1, j)-theta(i, k, j))*thetad(i, k, j))*&
1809 & tmpdz/theta(i, k, j)**2-(theta(i, k+1, j)-theta(i, k, j))*&
1810 & tmpdzd/theta(i, k, j))/tmpdz**2+(1.61*(moistd(i, k+1, j, p_qv)&
1811 & -qvsfcd)*tmpdz-1.61*(moist(i, k+1, j, p_qv)-qvsfc)*tmpdzd)/&
1812 & tmpdz**2-((tmp1d(i, k+1, j)-tmp1sfcd(i, j))*tmpdz-(tmp1(i, k+1&
1813 & , j)-tmp1sfc(i, j))*tmpdzd)/tmpdz**2)
1814 bn2(i, k, j) = g*((theta(i, k+1, j)-theta(i, k, j))/theta(i, k, &
1815 & j)/tmpdz+1.61*(moist(i, k+1, j, p_qv)-qvsfc)/tmpdz-(tmp1(i, k+&
1816 & 1, j)-tmp1sfc(i, j))/tmpdz)
1817 ! end of MARTA/WCS change
1821 !...... MARTA: change in computation of BN2 at the top, WCS 040331
1824 bn2d(i, ktf, j) = bn2d(i, ktf-1, j)
1825 bn2(i, ktf, j) = bn2(i, ktf-1, j)
1828 END SUBROUTINE G_CALCULATE_N2
1830 SUBROUTINE g_isotropic_km(config_flags,xkmh,g_xkmh,xkmv,g_xkmv,xkhh, &
1831 g_xkhh,xkhv,g_xkhv,khdif,kvdif,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme, &
1832 its,ite,jts,jte,kts,kte)
1836 REAL :: Tmpv1,g_Tmpv1
1837 TYPE(grid_config_rec_type) :: config_flags
1838 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
1840 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: xkmh,g_xkmh,xkmv,g_xkmv,xkhh, &
1842 INTEGER :: i_start,i_end,j_start,j_end,ktf,i,j,k
1843 REAL :: khdif3,kvdif3
1849 i_end =min(ite,ide-1)
1853 j_end =min(jte,jde-1)
1855 khdif3 =khdif/prandtl
1857 kvdif3 =kvdif/prandtl
1879 END SUBROUTINE g_isotropic_km
1881 SUBROUTINE g_smag_km(config_flags,xkmh,g_xkmh,xkmv,g_xkmv,xkhh,g_xkhh, &
1882 xkhv,g_xkhv,BN2,g_BN2,div,g_div,defor11,g_defor11,defor22,g_defor22, &
1883 defor33,g_defor33,defor12,g_defor12,defor13,g_defor13,defor23,g_defor23, &
1884 rdzw,g_rdzw,dx,dy,dt,isotropic,mix_upper_bound,msftx,msfty,ids,ide,jds,jde,kds, &
1885 kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
1889 REAL :: Tmpv1,g_Tmpv1,Tmpv2,g_Tmpv2,Tmpv3,g_Tmpv3,Tmpv4,g_Tmpv4,Tmpv5,g_Tmpv5
1892 TYPE(grid_config_rec_type) :: config_flags
1893 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
1894 INTEGER :: isotropic
1895 REAL :: dx,dy,dt,mix_upper_bound
1896 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: BN2,g_BN2,rdzw,g_rdzw
1897 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: xkmh,g_xkmh,xkmv,g_xkmv,xkhh, &
1899 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor11,g_defor11,defor22,g_defor22, &
1900 defor33,g_defor33,defor12,g_defor12,defor13,g_defor13,defor23,g_defor23, &
1902 REAL,DIMENSION(ims:ime,jms:jme) :: msftx,msfty
1903 INTEGER :: i_start,i_end,j_start,j_end,ktf,i,j,k
1904 REAL :: deltas,g_deltas,tmp,g_tmp,pr,g_pr,mlen_h,g_mlen_h,mlen_v, &
1906 REAL,DIMENSION(its:ite,kts:kte,jts:jte) :: def2,g_def2
1912 i_end =min(ite,ide-1)
1916 j_end =min(jte,jde-1)
1918 IF( config_flags%open_xs .or. config_flags%specified .or. &
1919 config_flags%nested) i_start =max(ids+1,its)
1921 IF( config_flags%open_xe .or. config_flags%specified .or. &
1922 config_flags%nested) i_end =min(ide-2,ite)
1924 IF( config_flags%open_ys .or. config_flags%specified .or. &
1925 config_flags%nested) j_start =max(jds+1,jts)
1927 IF( config_flags%open_ye .or. config_flags%specified .or. &
1928 config_flags%nested) j_end =min(jde-2,jte)
1930 IF( config_flags%periodic_x ) i_start =its
1932 IF( config_flags%periodic_x ) i_end =min(ite,ide-1)
1938 !g_c_s =g_config_flags%c_s
1940 c_s =config_flags%c_s
1946 g_Tmpv1 =2.0*defor11(i,k,j)*g_defor11(i,k,j)
1947 Tmpv1 =defor11(i,k,j)*defor11(i,k,j)
1949 g_Tmpv2 =2.0*defor22(i,k,j)*g_defor22(i,k,j)
1950 Tmpv2 =defor22(i,k,j)*defor22(i,k,j)
1952 g_Tmpv3 =2.0*defor33(i,k,j)*g_defor33(i,k,j)
1953 Tmpv3 =defor33(i,k,j)*defor33(i,k,j)
1955 g_def2(i,k,j) =0.5*(g_Tmpv1 +g_Tmpv2 +g_Tmpv3)
1956 def2(i,k,j) =0.5*(Tmpv1 +Tmpv2 +Tmpv3)
1966 g_tmp =0.25*(g_defor12(i,k,j) +g_defor12(i,k,j+1) +g_defor12(i+1,k,j) &
1967 +g_defor12(i+1,k,j+1))
1968 tmp =0.25*(defor12(i,k,j) +defor12(i,k,j+1) +defor12(i+1,k,j) +defor12(i+1,k,j+1))
1970 g_Tmpv1 =2.0*tmp*g_tmp
1973 g_def2(i,k,j) =g_def2(i,k,j) +g_Tmpv1
1974 def2(i,k,j) =def2(i,k,j) +Tmpv1
1984 g_tmp =0.25*(g_defor13(i,k+1,j) +g_defor13(i,k,j) +g_defor13(i+1,k+1,j) &
1985 +g_defor13(i+1,k,j))
1986 tmp =0.25*(defor13(i,k+1,j) +defor13(i,k,j) +defor13(i+1,k+1,j) +defor13(i+1,k,j))
1988 g_Tmpv1 =2.0*tmp*g_tmp
1991 g_def2(i,k,j) =g_def2(i,k,j) +g_Tmpv1
1992 def2(i,k,j) =def2(i,k,j) +Tmpv1
2002 g_tmp =0.25*(g_defor23(i,k+1,j) +g_defor23(i,k,j) +g_defor23(i,k+1,j+1) &
2003 +g_defor23(i,k,j+1))
2004 tmp =0.25*(defor23(i,k+1,j) +defor23(i,k,j) +defor23(i,k+1,j+1) +defor23(i,k,j+1))
2006 g_Tmpv1 =2.0*tmp*g_tmp
2009 g_def2(i,k,j) =g_def2(i,k,j) +g_Tmpv1
2010 def2(i,k,j) =def2(i,k,j) +Tmpv1
2016 IF(isotropic .EQ. 0) THEN
2023 mlen_h =sqrt(dx/msftx(i,j) *dy/msfty(i,j))
2025 g_mlen_v =-1.*g_rdzw(i,k,j)/(rdzw(i,k,j)*rdzw(i,k,j))
2026 mlen_v =1./rdzw(i,k,j)
2028 g_Tmpv1 =(g_BN2(i,k,j)*pr -g_pr*BN2(i,k,j))/(pr*pr)
2029 Tmpv1 =BN2(i,k,j)/pr
2031 g_tmp =(0.0 +(g_def2(i,k,j) -g_Tmpv1) +(0.0 -(g_def2(i,k,j) -g_Tmpv1)) &
2032 *sign(1.0, 0. -(def2(i,k,j) -Tmpv1)))*0.5
2033 tmp =max(0.,def2(i,k,j) -Tmpv1)
2035 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2036 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2037 !REVISED AND ADDED BY WALLS
2039 g_tmp =0.5*g_tmp*tmp**(0.5 -1.0)
2041 ! Reivsed by Ning Pan, 2010-08-18
2043 ! g_tmp =0.5*g_tmp/(tmp**0.5+1.e-10)
2045 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2046 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2050 g_Tmpv1 =2.0*c_s*g_c_s
2053 g_Tmpv2 =Tmpv1*g_mlen_h +g_Tmpv1*mlen_h
2056 g_Tmpv3 =Tmpv2*g_mlen_h +g_Tmpv2*mlen_h
2059 g_Tmpv4 =Tmpv3*g_tmp +g_Tmpv3*tmp
2062 g_Tmpv5 =1.0E-6*mlen_h*g_mlen_h +1.0E-6*g_mlen_h*mlen_h
2063 Tmpv5 =1.0E-6*mlen_h*mlen_h
2065 g_xkmh(i,k,j) =(g_Tmpv4 +g_Tmpv5 +(g_Tmpv4 -g_Tmpv5)*sign(1.0, Tmpv4 - &
2067 xkmh(i,k,j) =max(Tmpv4,Tmpv5)
2069 g_Tmpv1 =mix_upper_bound*mlen_h*g_mlen_h +mix_upper_bound*g_mlen_h*mlen_h
2070 Tmpv1 =mix_upper_bound*mlen_h*mlen_h
2072 g_xkmh(i,k,j) =(g_xkmh(i,k,j) +(g_Tmpv1/dt) -(g_xkmh(i,k,j) &
2073 -(g_Tmpv1/dt))*sign(1.0, xkmh(i,k,j) -(Tmpv1/dt)))*0.5
2074 xkmh(i,k,j) =min(xkmh(i,k,j),Tmpv1/dt)
2076 g_Tmpv1 =2.0*c_s*g_c_s
2079 g_Tmpv2 =Tmpv1*g_mlen_v +g_Tmpv1*mlen_v
2082 g_Tmpv3 =Tmpv2*g_mlen_v +g_Tmpv2*mlen_v
2085 g_Tmpv4 =Tmpv3*g_tmp +g_Tmpv3*tmp
2088 g_Tmpv5 =1.0E-6*mlen_v*g_mlen_v +1.0E-6*g_mlen_v*mlen_v
2089 Tmpv5 =1.0E-6*mlen_v*mlen_v
2091 g_xkmv(i,k,j) =(g_Tmpv4 +g_Tmpv5 +(g_Tmpv4 -g_Tmpv5)*sign(1.0, Tmpv4 - &
2093 xkmv(i,k,j) =max(Tmpv4,Tmpv5)
2095 g_Tmpv1 =mix_upper_bound*mlen_v*g_mlen_v +mix_upper_bound*g_mlen_v*mlen_v
2096 Tmpv1 =mix_upper_bound*mlen_v*mlen_v
2098 g_xkmv(i,k,j) =(g_xkmv(i,k,j) +(g_Tmpv1/dt) -(g_xkmv(i,k,j) &
2099 -(g_Tmpv1/dt))*sign(1.0, xkmv(i,k,j) -(Tmpv1/dt)))*0.5
2100 xkmv(i,k,j) =min(xkmv(i,k,j),Tmpv1/dt)
2102 g_Tmpv1 =(g_xkmh(i,k,j)*pr -g_pr*xkmh(i,k,j))/(pr*pr)
2103 Tmpv1 =xkmh(i,k,j)/pr
2105 g_xkhh(i,k,j) =g_Tmpv1
2108 g_Tmpv1 =mix_upper_bound*mlen_h*g_mlen_h +mix_upper_bound*g_mlen_h*mlen_h
2109 Tmpv1 =mix_upper_bound*mlen_h*mlen_h
2111 g_xkhh(i,k,j) =(g_xkhh(i,k,j) +(g_Tmpv1/dt) -(g_xkhh(i,k,j) &
2112 -(g_Tmpv1/dt))*sign(1.0, xkhh(i,k,j) -(Tmpv1/dt)))*0.5
2113 xkhh(i,k,j) =min(xkhh(i,k,j),Tmpv1/dt)
2115 g_Tmpv1 =(g_xkmv(i,k,j)*pr -g_pr*xkmv(i,k,j))/(pr*pr)
2116 Tmpv1 =xkmv(i,k,j)/pr
2118 g_xkhv(i,k,j) =g_Tmpv1
2121 g_Tmpv1 =mix_upper_bound*mlen_v*g_mlen_v +mix_upper_bound*g_mlen_v*mlen_v
2122 Tmpv1 =mix_upper_bound*mlen_v*mlen_v
2124 g_xkhv(i,k,j) =(g_xkhv(i,k,j) +(g_Tmpv1/dt) -(g_xkhv(i,k,j) &
2125 -(g_Tmpv1/dt))*sign(1.0, xkhv(i,k,j) -(Tmpv1/dt)))*0.5
2126 xkhv(i,k,j) =min(xkhv(i,k,j),Tmpv1/dt)
2137 g_deltas =0.33333333*(-dx/msftx(i,j) *dy/msfty(i,j)*g_rdzw(i,k,j)/(rdzw(i,k,j) &
2138 *rdzw(i,k,j)))*(dx/msftx(i,j) *dy/msfty(i,j)/rdzw(i,k,j))**(0.33333333 -1.0)
2139 deltas =(dx/msftx(i,j) *dy/msfty(i,j)/rdzw(i,k,j))**0.33333333
2141 g_Tmpv1 =(g_BN2(i,k,j)*pr -g_pr*BN2(i,k,j))/(pr*pr)
2142 Tmpv1 =BN2(i,k,j)/pr
2144 g_tmp =(0.0 +(g_def2(i,k,j) -g_Tmpv1) +(0.0 -(g_def2(i,k,j) -g_Tmpv1)) &
2145 *sign(1.0, 0. -(def2(i,k,j) -Tmpv1)))*0.5
2146 tmp =max(0.,def2(i,k,j) -Tmpv1)
2148 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2149 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2150 !REVISED AND ADDED BY WALLS
2152 g_tmp =0.5*g_tmp*tmp**(0.5 -1.0)
2154 ! Revised by Ning Pan, 2010-08-18
2156 ! g_tmp =0.5*g_tmp/(tmp**0.5+1.e-10)
2158 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2159 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2160 tmp =tmp**0.5 ! Added by Ning Pan, 2010-08-18
2162 g_Tmpv1 =2.0*c_s*g_c_s
2165 g_Tmpv2 =Tmpv1*g_deltas +g_Tmpv1*deltas
2168 g_Tmpv3 =Tmpv2*g_deltas +g_Tmpv2*deltas
2171 g_Tmpv4 =Tmpv3*g_tmp +g_Tmpv3*tmp
2174 g_Tmpv5 =1.0E-6*deltas*g_deltas +1.0E-6*g_deltas*deltas
2175 Tmpv5 =1.0E-6*deltas*deltas
2177 g_xkmh(i,k,j) =(g_Tmpv4 +g_Tmpv5 +(g_Tmpv4 -g_Tmpv5)*sign(1.0, Tmpv4 - &
2179 xkmh(i,k,j) =max(Tmpv4,Tmpv5)
2181 g_xkmh(i,k,j) =(g_xkmh(i,k,j) +0.0 -(g_xkmh(i,k,j) -0.0)*sign(1.0, xkmh(i,k, &
2182 j) -(mix_upper_bound *dx/msftx(i,j) *dy/msfty(i,j)/dt)))*0.5
2183 xkmh(i,k,j) =min(xkmh(i,k,j),mix_upper_bound *dx/msftx(i,j) *dy/msfty(i,j)/dt)
2185 g_xkmv(i,k,j) =g_xkmh(i,k,j)
2186 xkmv(i,k,j) =xkmh(i,k,j)
2188 g_Tmpv1 =((-mix_upper_bound*g_rdzw(i,k,j)/(rdzw(i,k,j)*rdzw(i,k,j))) &
2189 *rdzw(i,k,j) -g_rdzw(i,k,j)*mix_upper_bound/rdzw(i,k,j))/(rdzw(i,k,j)*rdzw(i,k,j))
2190 Tmpv1 =mix_upper_bound/rdzw(i,k,j)/rdzw(i,k,j)
2192 g_xkmv(i,k,j) =(g_xkmv(i,k,j) +(g_Tmpv1/dt) -(g_xkmv(i,k,j) &
2193 -(g_Tmpv1/dt))*sign(1.0, xkmv(i,k,j) -(Tmpv1/dt)))*0.5
2194 xkmv(i,k,j) =min(xkmv(i,k,j),Tmpv1/dt)
2196 g_Tmpv1 =(g_xkmh(i,k,j)*pr -g_pr*xkmh(i,k,j))/(pr*pr)
2197 Tmpv1 =xkmh(i,k,j)/pr
2199 g_xkhh(i,k,j) =g_Tmpv1
2202 g_xkhh(i,k,j) =(g_xkhh(i,k,j) +0.0 -(g_xkhh(i,k,j) -0.0)*sign(1.0, xkhh(i,k, &
2203 j) -(mix_upper_bound *dx/msftx(i,j) *dy/msfty(i,j)/dt)))*0.5
2204 xkhh(i,k,j) =min(xkhh(i,k,j),mix_upper_bound *dx/msftx(i,j) *dy/msfty(i,j)/dt)
2206 g_Tmpv1 =(g_xkmv(i,k,j)*pr -g_pr*xkmv(i,k,j))/(pr*pr)
2207 Tmpv1 =xkmv(i,k,j)/pr
2209 g_xkhv(i,k,j) =g_Tmpv1
2212 g_Tmpv1 =((-mix_upper_bound*g_rdzw(i,k,j)/(rdzw(i,k,j)*rdzw(i,k,j))) &
2213 *rdzw(i,k,j) -g_rdzw(i,k,j)*mix_upper_bound/rdzw(i,k,j))/(rdzw(i,k,j)*rdzw(i,k,j))
2214 Tmpv1 =mix_upper_bound/rdzw(i,k,j)/rdzw(i,k,j)
2216 g_xkhv(i,k,j) =(g_xkhv(i,k,j) +(g_Tmpv1/dt) -(g_xkhv(i,k,j) &
2217 -(g_Tmpv1/dt))*sign(1.0, xkhv(i,k,j) -(Tmpv1/dt)))*0.5
2218 xkhv(i,k,j) =min(xkhv(i,k,j),Tmpv1/dt)
2225 END SUBROUTINE g_smag_km
2227 ! Generated by TAPENADE (INRIA, Tropics team)
2228 ! Tapenade 3.10 (r5363) - 9 Sep 2014 09:54
2230 ! Differentiation of smag2d_km in forward (tangent) mode:
2231 ! variations of useful results: xkmh xkmv xkhh xkhv
2232 ! with respect to varying inputs: defor11 defor12 zx zy xkmh
2233 ! defor22 xkmv rdzw xkhh xkhv
2234 ! RW status of diff variables: defor11:in defor12:in zx:in zy:in
2235 ! xkmh:in-out defor22:in xkmv:in-out rdzw:in xkhh:in-out
2237 SUBROUTINE G_SMAG2D_KM(config_flags, xkmh, xkmhd, xkmv, xkmvd, xkhh, &
2238 & xkhhd, xkhv, xkhvd, defor11, defor11d, defor22, defor22d, defor12, &
2239 & defor12d, rdzw, rdzwd, dx, dy, msftx, msfty, zx, zxd, zy, zyd, ids, &
2240 & ide, jds, jde, kds, kde, ims, ime, jms, jme, kms, kme, its, ite, jts, &
2243 TYPE(GRID_CONFIG_REC_TYPE), INTENT(IN) :: config_flags
2244 INTEGER, INTENT(IN) :: ids, ide, jds, jde, kds, kde, ims, ime, jms, &
2245 & jme, kms, kme, its, ite, jts, jte, kts, kte
2246 REAL, INTENT(IN) :: dx, dy
2247 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: rdzw, zx, zy
2248 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: rdzwd, zxd, &
2250 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: xkmh, &
2252 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: xkmhd, &
2253 & xkmvd, xkhhd, xkhvd
2254 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: defor11, &
2256 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: defor11d, &
2257 & defor22d, defor12d
2258 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: msftx, msfty
2260 INTEGER :: i_start, i_end, j_start, j_end, ktf, i, j, k
2261 REAL :: deltas, tmp, pr, mlen_h, c_s
2263 REAL :: dxm, dym, tmpzx, tmpzy, alpha, def_limit
2264 REAL :: tmpzxd, tmpzyd, alphad
2265 REAL, DIMENSION(its:ite, kts:kte, jts:jte) :: def2
2266 REAL, DIMENSION(its:ite, kts:kte, jts:jte) :: def2d
2287 IF (kte .GT. kde - 1) THEN
2293 IF (ite .GT. ide - 1) THEN
2299 IF (jte .GT. jde - 1) THEN
2304 IF ((config_flags%open_xs .OR. config_flags%specified) .OR. &
2305 & config_flags%nested) THEN
2306 IF (ids + 1 .LT. its) THEN
2312 IF ((config_flags%open_xe .OR. config_flags%specified) .OR. &
2313 & config_flags%nested) THEN
2314 IF (ide - 2 .GT. ite) THEN
2320 IF ((config_flags%open_ys .OR. config_flags%specified) .OR. &
2321 & config_flags%nested) THEN
2322 IF (jds + 1 .LT. jts) THEN
2328 IF ((config_flags%open_ye .OR. config_flags%specified) .OR. &
2329 & config_flags%nested) THEN
2330 IF (jde - 2 .GT. jte) THEN
2336 IF (config_flags%periodic_x) i_start = its
2337 IF (config_flags%periodic_x) THEN
2338 IF (ite .GT. ide - 1) THEN
2345 c_s = config_flags%c_s
2350 def2d(i, k, j) = 0.25*((defor11d(i, k, j)-defor22d(i, k, j))*(&
2351 & defor11(i, k, j)-defor22(i, k, j))+(defor11(i, k, j)-defor22(i&
2352 & , k, j))*(defor11d(i, k, j)-defor22d(i, k, j)))
2353 def2(i, k, j) = 0.25*((defor11(i, k, j)-defor22(i, k, j))*(&
2354 & defor11(i, k, j)-defor22(i, k, j)))
2355 tmpd = 0.25*(defor12d(i, k, j)+defor12d(i, k, j+1)+defor12d(i+1&
2356 & , k, j)+defor12d(i+1, k, j+1))
2357 tmp = 0.25*(defor12(i, k, j)+defor12(i, k, j+1)+defor12(i+1, k, &
2358 & j)+defor12(i+1, k, j+1))
2359 def2d(i, k, j) = def2d(i, k, j) + tmpd*tmp + tmp*tmpd
2360 def2(i, k, j) = def2(i, k, j) + tmp*tmp
2368 arg1 = dx/msftx(i, j)*dy/msfty(i, j)
2370 IF (def2(i, k, j) .EQ. 0.0_8) THEN
2373 tmpd = def2d(i, k, j)/(2.0*SQRT(def2(i, k, j)))
2375 tmp = SQRT(def2(i, k, j))
2376 ! xkmh(i,k,j)=max(c_s*c_s*mlen_h*mlen_h*tmp, 1.0E-6*mlen_h*mlen_h )
2377 xkmhd(i, k, j) = c_s**2*mlen_h**2*tmpd
2378 xkmh(i, k, j) = c_s*c_s*mlen_h*mlen_h*tmp
2379 IF (xkmh(i, k, j) .GT. 10.*mlen_h) THEN
2380 xkmhd(i, k, j) = 0.0_8
2381 xkmh(i, k, j) = 10.*mlen_h
2383 xkmh(i, k, j) = xkmh(i, k, j)
2385 xkmvd(i, k, j) = 0.0_8
2387 xkhhd(i, k, j) = xkmhd(i, k, j)/pr
2388 xkhh(i, k, j) = xkmh(i, k, j)/pr
2389 xkhvd(i, k, j) = 0.0_8
2391 IF (config_flags%diff_opt .EQ. 2) THEN
2392 ! jd: reduce diffusion coefficient by slope factor (modified by JB August 2014)
2393 dxm = dx/msftx(i, j)
2394 dym = dy/msfty(i, j)
2395 IF (zx(i, k, j) .GE. 0.0_8) THEN
2396 abs0d = zxd(i, k, j)
2399 abs0d = -zxd(i, k, j)
2402 IF (zx(i+1, k, j) .GE. 0.0_8) THEN
2403 abs2d = zxd(i+1, k, j)
2404 abs2 = zx(i+1, k, j)
2406 abs2d = -zxd(i+1, k, j)
2407 abs2 = -zx(i+1, k, j)
2409 IF (zx(i, k+1, j) .GE. 0.0_8) THEN
2410 abs4d = zxd(i, k+1, j)
2411 abs4 = zx(i, k+1, j)
2413 abs4d = -zxd(i, k+1, j)
2414 abs4 = -zx(i, k+1, j)
2416 IF (zx(i+1, k+1, j) .GE. 0.0_8) THEN
2417 abs6d = zxd(i+1, k+1, j)
2418 abs6 = zx(i+1, k+1, j)
2420 abs6d = -zxd(i+1, k+1, j)
2421 abs6 = -zx(i+1, k+1, j)
2423 tmpzxd = 0.25*dxm*((abs0d+abs2d+abs4d+abs6d)*rdzw(i, k, j)+(&
2424 & abs0+abs2+abs4+abs6)*rdzwd(i, k, j))
2425 tmpzx = 0.25*(abs0+abs2+abs4+abs6)*rdzw(i, k, j)*dxm
2426 IF (zy(i, k, j) .GE. 0.0_8) THEN
2427 abs1d = zyd(i, k, j)
2430 abs1d = -zyd(i, k, j)
2433 IF (zy(i, k, j+1) .GE. 0.0_8) THEN
2434 abs3d = zyd(i, k, j+1)
2435 abs3 = zy(i, k, j+1)
2437 abs3d = -zyd(i, k, j+1)
2438 abs3 = -zy(i, k, j+1)
2440 IF (zy(i, k+1, j) .GE. 0.0_8) THEN
2441 abs5d = zyd(i, k+1, j)
2442 abs5 = zy(i, k+1, j)
2444 abs5d = -zyd(i, k+1, j)
2445 abs5 = -zy(i, k+1, j)
2447 IF (zy(i, k+1, j+1) .GE. 0.0_8) THEN
2448 abs7d = zyd(i, k+1, j+1)
2449 abs7 = zy(i, k+1, j+1)
2451 abs7d = -zyd(i, k+1, j+1)
2452 abs7 = -zy(i, k+1, j+1)
2454 tmpzyd = 0.25*dym*((abs1d+abs3d+abs5d+abs7d)*rdzw(i, k, j)+(&
2455 & abs1+abs3+abs5+abs7)*rdzwd(i, k, j))
2456 tmpzy = 0.25*(abs1+abs3+abs5+abs7)*rdzw(i, k, j)*dym
2457 arg1d = tmpzxd*tmpzx + tmpzx*tmpzxd + tmpzyd*tmpzy + tmpzy*&
2459 arg1 = tmpzx*tmpzx + tmpzy*tmpzy
2460 IF (arg1 .EQ. 0.0_8) THEN
2463 x1d = arg1d/(2.0*SQRT(arg1))
2466 IF (x1 .LT. 1.0) THEN
2473 IF (10.0/mlen_h .LT. 1.e-3) THEN
2476 def_limit = 10.0/mlen_h
2478 IF (tmp .GT. def_limit) THEN
2479 xkmhd(i, k, j) = (xkmhd(i, k, j)*alpha**2-xkmh(i, k, j)*(&
2480 & alphad*alpha+alpha*alphad))/(alpha*alpha)**2
2481 xkmh(i, k, j) = xkmh(i, k, j)/(alpha*alpha)
2483 xkmhd(i, k, j) = (xkmhd(i, k, j)*alpha-xkmh(i, k, j)*alphad)&
2485 xkmh(i, k, j) = xkmh(i, k, j)/alpha
2487 xkhhd(i, k, j) = xkmhd(i, k, j)/pr
2488 xkhh(i, k, j) = xkmh(i, k, j)/pr
2493 END SUBROUTINE G_SMAG2D_KM
2495 SUBROUTINE g_phy_bc(config_flags,div,g_div,defor11,g_defor11,defor22, &
2496 g_defor22,defor33,g_defor33,defor12,g_defor12,defor13,g_defor13,defor23, &
2497 g_defor23,xkmh,g_xkmh,xkmv,g_xkmv,xkhh,g_xkhh,xkhv,g_xkhv,tke, &
2498 g_tke,RUBLTEN,g_RUBLTEN,RVBLTEN,g_RVBLTEN,RUCUTEN,g_RUCUTEN,RVCUTEN,g_RVCUTEN,&
2499 RUSHTEN,g_RUSHTEN,RVSHTEN,g_RVSHTEN,ids,ide,jds,jde,kds,kde,ims,ime, &
2500 jms,jme,kms,kme,ips,ipe,jps,jpe,kps,kpe,its,ite,jts,jte,kts,kte)
2504 REAL :: Tmpv1,g_Tmpv1
2505 TYPE(grid_config_rec_type) :: config_flags
2506 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,ips,ipe,jps,jpe,kps,kpe, &
2507 its,ite,jts,jte,kts,kte
2508 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: RUBLTEN,g_RUBLTEN,RVBLTEN,g_RVBLTEN, &
2509 RUCUTEN,g_RUCUTEN,RVCUTEN,g_RVCUTEN, RUSHTEN,g_RUSHTEN,RVSHTEN,g_RVSHTEN, &
2510 defor11,g_defor11,defor22,g_defor22,defor33,g_defor33,defor12,g_defor12, &
2511 defor13,g_defor13,defor23,g_defor23,xkmh,g_xkmh,xkmv,g_xkmv,xkhh, &
2512 g_xkhh,xkhv,g_xkhv,tke,g_tke,div,g_div
2514 IF(config_flags%bl_pbl_physics .GT. 0) THEN
2516 CALL g_set_physical_bc3d(RUBLTEN,g_RUBLTEN,'t',config_flags,ids,ide,jds,jde, &
2517 kds,kde,ims,ime,jms,jme,kms,kme,ips,ipe,jps,jpe,kps,kpe,its,ite,jts,jte,kts,kte)
2519 CALL g_set_physical_bc3d(RVBLTEN,g_RVBLTEN,'t',config_flags,ids,ide,jds,jde, &
2520 kds,kde,ims,ime,jms,jme,kms,kme,ips,ipe,jps,jpe,kps,kpe,its,ite,jts,jte,kts,kte)
2524 IF(config_flags%cu_physics .GT. 0) THEN
2526 CALL g_set_physical_bc3d(RUCUTEN,g_RUCUTEN,'t',config_flags,ids,ide,jds,jde, &
2527 kds,kde,ims,ime,jms,jme,kms,kme,ips,ipe,jps,jpe,kps,kpe,its,ite,jts,jte,kts,kte)
2529 CALL g_set_physical_bc3d(RVCUTEN,g_RVCUTEN,'t',config_flags,ids,ide,jds,jde, &
2530 kds,kde,ims,ime,jms,jme,kms,kme,ips,ipe,jps,jpe,kps,kpe,its,ite,jts,jte,kts,kte)
2533 IF(config_flags%shcu_physics .GT. 0) THEN
2535 CALL g_set_physical_bc3d( RUSHTEN, g_RUSHTEN,'t', config_flags, &
2536 ids, ide, jds, jde, kds, kde, &
2537 ims, ime, jms, jme, kms, kme, &
2538 ips, ipe, jps, jpe, kps, kpe, &
2539 its, ite, jts, jte, kts, kte )
2541 CALL g_set_physical_bc3d( RVSHTEN, g_RVSHTEN,'t', config_flags, &
2542 ids, ide, jds, jde, kds, kde, &
2543 ims, ime, jms, jme, kms, kme, &
2544 ips, ipe, jps, jpe, kps, kpe, &
2545 its, ite, jts, jte, kts, kte )
2549 CALL g_set_physical_bc3d(xkmh,g_xkmh,'t',config_flags,ids,ide,jds,jde,kds,kde, &
2550 ims,ime,jms,jme,kms,kme,ips,ipe,jps,jpe,kps,kpe,its,ite,jts,jte,kts,kte)
2552 CALL g_set_physical_bc3d(xkhh,g_xkhh,'t',config_flags,ids,ide,jds,jde,kds,kde, &
2553 ims,ime,jms,jme,kms,kme,ips,ipe,jps,jpe,kps,kpe,its,ite,jts,jte,kts,kte)
2555 IF(config_flags%diff_opt .eq. 2) THEN
2557 CALL g_set_physical_bc3d(xkmv,g_xkmv,'t',config_flags,ids,ide,jds,jde,kds,kde, &
2558 ims,ime,jms,jme,kms,kme,ips,ipe,jps,jpe,kps,kpe,its,ite,jts,jte,kts,kte)
2560 CALL g_set_physical_bc3d(xkhv,g_xkhv,'t',config_flags,ids,ide,jds,jde,kds,kde, &
2561 ims,ime,jms,jme,kms,kme,ips,ipe,jps,jpe,kps,kpe,its,ite,jts,jte,kts,kte)
2563 CALL g_set_physical_bc3d(div,g_div,'t',config_flags,ids,ide,jds,jde,kds,kde, &
2564 ims,ime,jms,jme,kms,kme,ips,ipe,jps,jpe,kps,kpe,its,ite,jts,jte,kts,kte)
2566 CALL g_set_physical_bc3d(defor11,g_defor11,'t',config_flags,ids,ide,jds,jde, &
2567 kds,kde,ims,ime,jms,jme,kms,kme,ips,ipe,jps,jpe,kps,kpe,its,ite,jts,jte,kts,kte)
2569 CALL g_set_physical_bc3d(defor22,g_defor22,'t',config_flags,ids,ide,jds,jde, &
2570 kds,kde,ims,ime,jms,jme,kms,kme,ips,ipe,jps,jpe,kps,kpe,its,ite,jts,jte,kts,kte)
2572 CALL g_set_physical_bc3d(defor33,g_defor33,'t',config_flags,ids,ide,jds,jde, &
2573 kds,kde,ims,ime,jms,jme,kms,kme,ips,ipe,jps,jpe,kps,kpe,its,ite,jts,jte,kts,kte)
2575 CALL g_set_physical_bc3d(defor12,g_defor12,'d',config_flags,ids,ide,jds,jde, &
2576 kds,kde,ims,ime,jms,jme,kms,kme,ips,ipe,jps,jpe,kps,kpe,its,ite,jts,jte,kts,kte)
2578 CALL g_set_physical_bc3d(defor13,g_defor13,'e',config_flags,ids,ide,jds,jde, &
2579 kds,kde,ims,ime,jms,jme,kms,kme,ips,ipe,jps,jpe,kps,kpe,its,ite,jts,jte,kts,kte)
2581 CALL g_set_physical_bc3d(defor23,g_defor23,'f',config_flags,ids,ide,jds,jde, &
2582 kds,kde,ims,ime,jms,jme,kms,kme,ips,ipe,jps,jpe,kps,kpe,its,ite,jts,jte,kts,kte)
2585 END SUBROUTINE g_phy_bc
2587 SUBROUTINE g_tke_km(config_flags,xkmh,g_xkmh,xkmv,g_xkmv,xkhh,g_xkhh, &
2588 xkhv,g_xkhv,bn2,g_bn2,tke,g_tke,p8w,g_p8w,t8w,g_t8w,theta,g_theta, &
2589 rdz,g_rdz,rdzw,g_rdzw,dx,dy,dt,isotropic,mix_upper_bound,msftx,msfty,ids,ide, &
2590 jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
2594 REAL :: Tmpv1,g_Tmpv1,Tmpv2,g_Tmpv2,Tmpv3,g_Tmpv3,Tmpv4,g_Tmpv4,Tmpv5, &
2595 g_Tmpv5,Tmpv6,g_Tmpv6
2598 TYPE(grid_config_rec_type) :: config_flags
2599 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
2600 INTEGER :: isotropic
2602 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tke,g_tke,p8w,g_p8w,t8w,g_t8w, &
2603 theta,g_theta,rdz,g_rdz,rdzw,g_rdzw,bn2,g_bn2
2604 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: xkmh,g_xkmh,xkmv,g_xkmv,xkhh, &
2606 REAL :: mix_upper_bound
2607 REAL,DIMENSION(ims:ime,jms:jme) :: msftx,msfty
2608 REAL,DIMENSION(its:ite,kts:kte,jts:jte) :: l_scale,g_l_scale
2609 REAL,DIMENSION(its:ite,kts:kte,jts:jte) :: dthrdn,g_dthrdn
2610 REAL :: deltas,g_deltas,tmp,g_tmp,mlen_s,g_mlen_s,mlen_h,g_mlen_h,mlen_v, &
2611 g_mlen_v,tmpdz,g_tmpdz,thetasfc,g_thetasfc,thetatop,g_thetatop,minkx, &
2612 g_minkx,pr_inv,g_pr_inv,pr_inv_h,g_pr_inv_h,pr_inv_v,g_pr_inv_v,c_k,g_c_k
2613 INTEGER :: i_start,i_end,j_start,j_end,ktf,i,j,k
2614 REAL,PARAMETER :: tke_seed_value =1.e-06
2616 REAL,PARAMETER :: epsilon =1.e-10
2622 i_end =min(ite,ide-1)
2626 j_end =min(jte,jde-1)
2628 IF( config_flags%open_xs .OR. config_flags%specified .OR. &
2629 config_flags%nested) i_start =max(ids+1,its)
2631 IF( config_flags%open_xe .OR. config_flags%specified .OR. &
2632 config_flags%nested) i_end =min(ide-2,ite)
2634 IF( config_flags%open_ys .OR. config_flags%specified .OR. &
2635 config_flags%nested) j_start =max(jds+1,jts)
2637 IF( config_flags%open_ye .OR. config_flags%specified .OR. &
2638 config_flags%nested) j_end =min(jde-2,jte)
2640 IF( config_flags%periodic_x ) i_start =its
2642 IF( config_flags%periodic_x ) i_end =min(ite,ide-1)
2646 c_k =config_flags%c_k
2650 IF (config_flags%isfflx .eq. 0) THEN
2651 IF ((config_flags%diff_opt .eq. 2) .and. (config_flags%bl_pbl_physics .eq. 0)) THEN
2652 IF( (config_flags%tke_drag_coefficient .lt. epsilon) .and. &
2653 (config_flags%tke_heat_flux .lt. epsilon) ) THEN
2654 tke_seed = tke_seed_value
2657 !tke_drag_coefficient and tke_heat_flux are irrelevant here
2658 tke_seed = tke_seed_value
2666 g_tmpdz = -(g_rdz(i,k+1,j)/(rdz(i,k+1,j)*rdz(i,k+1,j))) - &
2667 & g_rdz(i,k,j)/(rdz(i,k,j)*rdz(i,k,j))
2668 tmpdz = 1.0/rdz(i,k+1,j) + 1.0/rdz(i,k,j)
2670 g_Tmpv1 = ((g_theta(i,k+1,j)-g_theta(i,k-1,j))*tmpdz- &
2671 & g_tmpdz*(theta(i,k+1,j)-theta(i,k-1,j)))/(tmpdz*tmpdz)
2672 Tmpv1 = (theta(i,k+1,j)-theta(i,k-1,j))/tmpdz
2674 g_dthrdn(i,k,j) =g_Tmpv1
2675 dthrdn(i,k,j) =Tmpv1
2686 g_tmpdz = -(g_rdzw(i,k+1,j)/(rdzw(i,k+1,j)*rdzw(i,k+1,j))) - &
2687 & g_rdzw(i,k,j)/(rdzw(i,k,j)*rdzw(i,k,j))
2688 tmpdz = 1.0/rdzw(i,k+1,j) + 1.0/rdzw(i,k,j)
2690 g_Tmpv1 =(g_T8w(i,kts,j)*(p8w(i,k,j)/p1000mb)**(R_d/Cp) -(R_d/Cp) &
2691 *(g_p8w(i,k,j)/p1000mb)*(p8w(i,k,j)/p1000mb)**((R_d/Cp) -1.0)*T8w(i,kts,j)) &
2692 /((p8w(i,k,j)/p1000mb)**(R_d/Cp)*(p8w(i,k,j)/p1000mb)**(R_d/Cp))
2693 Tmpv1 =T8w(i,kts,j)/(p8w(i,k,j)/p1000mb)**(R_d/Cp)
2698 g_Tmpv1 =((g_theta(i,k+1,j) -g_thetasfc)*tmpdz -g_tmpdz*(theta(i,k+1,j) &
2699 -thetasfc))/(tmpdz*tmpdz)
2700 Tmpv1 =(theta(i,k+1,j) -thetasfc)/tmpdz
2702 g_dthrdn(i,k,j) =g_Tmpv1
2703 dthrdn(i,k,j) =Tmpv1
2713 g_tmpdz =-1.0*g_rdz(i,k,j)/(rdz(i,k,j)*rdz(i,k,j)) +(-0.5*g_rdzw(i,k,j) &
2714 /(rdzw(i,k,j)*rdzw(i,k,j)))
2715 tmpdz =1.0/rdz(i,k,j)+0.5/rdzw(i,k,j)
2717 g_Tmpv1 =(g_T8w(i,kde,j)*(p8w(i,kde,j)/p1000mb)**(R_d/Cp) -(R_d/Cp) &
2718 *(g_p8w(i,kde,j)/p1000mb)*(p8w(i,kde,j)/p1000mb)**((R_d/Cp) -1.0)*T8w(i,kde,j)) &
2719 /((p8w(i,kde,j)/p1000mb)**(R_d/Cp)*(p8w(i,kde,j)/p1000mb)**(R_d/Cp))
2720 Tmpv1 =T8w(i,kde,j)/(p8w(i,kde,j)/p1000mb)**(R_d/Cp)
2725 g_Tmpv1 =((g_thetatop -g_theta(i,k-1,j))*tmpdz -g_tmpdz*(thetatop - &
2726 theta(i,k-1,j)))/(tmpdz*tmpdz)
2727 Tmpv1 =(thetatop -theta(i,k-1,j))/tmpdz
2729 g_dthrdn(i,k,j) =g_Tmpv1
2730 dthrdn(i,k,j) =Tmpv1
2738 IF( isotropic .EQ. 0 ) THEN
2745 mlen_h =sqrt(dx/msftx(i,j) *dy/msfty(i,j))
2747 g_tmp =g_Sqrt((g_tke(i,k,j) +0.0 +(g_tke(i,k,j) -0.0)*sign(1.0, tke(i,k, &
2748 j) -(tke_seed)))*0.5, max(tke(i,k,j),tke_seed))
2749 tmp =sqrt(max(tke(i,k,j),tke_seed))
2751 g_deltas =-1.0*g_rdzw(i,k,j)/(rdzw(i,k,j)*rdzw(i,k,j))
2752 deltas =1.0/rdzw(i,k,j)
2757 IF( dthrdn(i,k,j) .GT. 0.) THEN
2759 g_Tmpv1 =g/theta(i,k,j)*g_dthrdn(i,k,j) +(-g*g_theta(i,k,j)/(theta(i,k,j) &
2760 *theta(i,k,j)))*dthrdn(i,k,j)
2761 Tmpv1 =g/theta(i,k,j)*dthrdn(i,k,j)
2763 g_Tmpv2 =(0.76*g_tmp*(abs(Tmpv1))**0.5 -0.5*(sign(1.0, Tmpv1)*g_Tmpv1) &
2764 *(abs(Tmpv1))**(0.5 -1.0)*0.76*tmp)/((abs(Tmpv1))**0.5*(abs(Tmpv1))**0.5)
2765 Tmpv2 =0.76*tmp/(abs(Tmpv1))**0.5
2770 g_mlen_v =(g_mlen_v +g_mlen_s -(g_mlen_v -g_mlen_s)*sign(1.0, mlen_v - &
2772 mlen_v =min(mlen_v,mlen_s)
2776 g_Tmpv1 =c_k*g_tmp +g_c_k*tmp
2779 g_Tmpv2 =Tmpv1*g_mlen_h +g_Tmpv1*mlen_h
2782 g_Tmpv3 =1.0E-6*mlen_h*g_mlen_h +1.0E-6*g_mlen_h*mlen_h
2783 Tmpv3 =1.0E-6*mlen_h*mlen_h
2785 g_xkmh(i,k,j) =(g_Tmpv2 +g_Tmpv3 +(g_Tmpv2 -g_Tmpv3)*sign(1.0, Tmpv2 - &
2787 xkmh(i,k,j) =max(Tmpv2,Tmpv3)
2789 g_Tmpv1 =mix_upper_bound*mlen_h*g_mlen_h +mix_upper_bound*g_mlen_h*mlen_h
2790 Tmpv1 =mix_upper_bound*mlen_h*mlen_h
2792 g_xkmh(i,k,j) =(g_xkmh(i,k,j) +(g_Tmpv1/dt) -(g_xkmh(i,k,j) &
2793 -(g_Tmpv1/dt))*sign(1.0, xkmh(i,k,j) -(Tmpv1/dt)))*0.5
2794 xkmh(i,k,j) =min(xkmh(i,k,j),Tmpv1/dt)
2796 g_Tmpv1 =c_k*g_tmp +g_c_k*tmp
2799 g_Tmpv2 =Tmpv1*g_mlen_v +g_Tmpv1*mlen_v
2802 g_Tmpv3 =1.0E-6*deltas*g_deltas +1.0E-6*g_deltas*deltas
2803 Tmpv3 =1.0E-6*deltas*deltas
2805 g_xkmv(i,k,j) =(g_Tmpv2 +g_Tmpv3 +(g_Tmpv2 -g_Tmpv3)*sign(1.0, Tmpv2 - &
2807 xkmv(i,k,j) =max(Tmpv2,Tmpv3)
2809 g_Tmpv1 =mix_upper_bound*deltas*g_deltas +mix_upper_bound*g_deltas*deltas
2810 Tmpv1 =mix_upper_bound*deltas*deltas
2812 g_xkmv(i,k,j) =(g_xkmv(i,k,j) +(g_Tmpv1/dt) -(g_xkmv(i,k,j) &
2813 -(g_Tmpv1/dt))*sign(1.0, xkmv(i,k,j) -(Tmpv1/dt)))*0.5
2814 xkmv(i,k,j) =min(xkmv(i,k,j),Tmpv1/dt)
2817 pr_inv_h =1./prandtl
2819 g_Tmpv1 =(2.0*g_mlen_v*deltas -g_deltas*2.0*mlen_v)/(deltas*deltas)
2820 Tmpv1 =2.0*mlen_v/deltas
2823 pr_inv_v =1.0 +Tmpv1
2825 g_Tmpv1 =xkmh(i,k,j)*g_pr_inv_h +g_xkmh(i,k,j)*pr_inv_h
2826 Tmpv1 =xkmh(i,k,j)*pr_inv_h
2828 g_xkhh(i,k,j) =g_Tmpv1
2831 g_Tmpv1 =xkmv(i,k,j)*g_pr_inv_v +g_xkmv(i,k,j)*pr_inv_v
2832 Tmpv1 =xkmv(i,k,j)*pr_inv_v
2834 g_xkhv(i,k,j) =g_Tmpv1
2842 CALL g_calc_l_scale(config_flags,tke,g_tke,BN2,g_BN2,l_scale,g_l_scale, &
2843 i_start,i_end,ktf,j_start,j_end,dx,dy,rdzw,g_rdzw,msftx,msfty,ids,ide,jds,jde,kds, &
2844 kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
2850 g_tmp =g_Sqrt((g_tke(i,k,j) +0.0 +(g_tke(i,k,j) -0.0)*sign(1.0, tke(i,k, &
2851 j) -(tke_seed)))*0.5, max(tke(i,k,j),tke_seed))
2852 tmp =sqrt(max(tke(i,k,j),tke_seed))
2854 g_deltas =0.33333333*(-dx/msftx(i,j) *dy/msfty(i,j)*g_rdzw(i,k,j)/(rdzw(i,k,j) &
2855 *rdzw(i,k,j)))*(dx/msftx(i,j) *dy/msfty(i,j)/rdzw(i,k,j))**(0.33333333 -1.0)
2856 deltas =(dx/msftx(i,j) *dy/msfty(i,j)/rdzw(i,k,j))**0.33333333
2858 g_Tmpv1 =c_k*g_tmp +g_c_k*tmp
2861 g_Tmpv2 =Tmpv1*g_l_scale(i,k,j) +g_Tmpv1*l_scale(i,k,j)
2862 Tmpv2 =Tmpv1*l_scale(i,k,j)
2864 g_xkmh(i,k,j) =g_Tmpv2
2867 g_xkmh(i,k,j) =(0.0 +g_xkmh(i,k,j) -(0.0 -g_xkmh(i,k,j))*sign(1.0, &
2868 mix_upper_bound *dx/msftx(i,j) *dy/msfty(i,j)/dt -(xkmh(i,k,j))))*0.5
2869 xkmh(i,k,j) =min(mix_upper_bound *dx/msftx(i,j) *dy/msfty(i,j)/dt,xkmh(i,k,j))
2871 g_Tmpv1 =c_k*g_tmp +g_c_k*tmp
2874 g_Tmpv2 =Tmpv1*g_l_scale(i,k,j) +g_Tmpv1*l_scale(i,k,j)
2875 Tmpv2 =Tmpv1*l_scale(i,k,j)
2877 g_xkmv(i,k,j) =g_Tmpv2
2880 g_Tmpv1 =((-mix_upper_bound*g_rdzw(i,k,j)/(rdzw(i,k,j)*rdzw(i,k,j))) &
2881 *rdzw(i,k,j) -g_rdzw(i,k,j)*mix_upper_bound/rdzw(i,k,j))/(rdzw(i,k,j)*rdzw(i,k,j))
2883 ! Added by Ning Pan, 2010-08-13
2884 Tmpv1 =mix_upper_bound/rdzw(i,k,j)/rdzw(i,k,j)
2885 g_xkmv(i,k,j) =(g_Tmpv1/dt +g_xkmv(i,k,j) -(g_Tmpv1/dt -g_xkmv(i,k,j)) &
2886 *sign(1.0, Tmpv1/dt -(xkmv(i,k,j))))*0.5
2888 xkmv(i,k,j) =min(mix_upper_bound/rdzw(i,k,j)/rdzw(i,k,j)/dt,xkmv(i,k,j))
2890 g_Tmpv1 =(2.0*g_l_scale(i,k,j)*deltas -g_deltas*2.0*l_scale(i,k,j))/(deltas*deltas)
2891 Tmpv1 =2.0*l_scale(i,k,j)/deltas
2896 g_Tmpv1 =xkmh(i,k,j)*g_pr_inv +g_xkmh(i,k,j)*pr_inv
2897 Tmpv1 =xkmh(i,k,j)*pr_inv
2899 g_xkhh(i,k,j) =(0.0 +g_Tmpv1 -(0.0 -g_Tmpv1)*sign(1.0, mix_upper_bound *dx/ &
2900 msftx(i,j) *dy/msfty(i,j)/dt -(Tmpv1)))*0.5
2901 xkhh(i,k,j) =min(mix_upper_bound *dx/msftx(i,j) *dy/msfty(i,j)/dt,Tmpv1)
2903 g_Tmpv1 =((-mix_upper_bound*g_rdzw(i,k,j)/(rdzw(i,k,j)*rdzw(i,k,j))) &
2904 *rdzw(i,k,j) -g_rdzw(i,k,j)*mix_upper_bound/rdzw(i,k,j))/(rdzw(i,k,j)*rdzw(i,k,j))
2905 Tmpv1 =mix_upper_bound/rdzw(i,k,j)/rdzw(i,k,j)
2907 g_Tmpv2 =xkmv(i,k,j)*g_pr_inv +g_xkmv(i,k,j)*pr_inv
2908 Tmpv2 =xkmv(i,k,j)*pr_inv
2910 g_xkhv(i,k,j) =(g_Tmpv1/dt +g_Tmpv2 -(g_Tmpv1/dt -g_Tmpv2) &
2911 *sign(1.0, Tmpv1/dt -(Tmpv2)))*0.5
2912 xkhv(i,k,j) =min(Tmpv1/dt,Tmpv2)
2919 END SUBROUTINE g_tke_km
2921 SUBROUTINE g_tke_rhs(tendency,g_tendency,BN2,g_BN2,config_flags,defor11, &
2922 g_defor11,defor22,g_defor22,defor33,g_defor33,defor12,g_defor12,defor13, &
2923 g_defor13,defor23,g_defor23,u,g_u,v,g_v,w,g_w,div,g_div,tke, &
2924 g_tke,mu,g_mu,theta,g_theta,p,g_p,p8w,g_p8w,t8w,g_t8w,z,g_z,fnm, &
2925 fnp,cf1,cf2,cf3,msftx,msfty,xkmh,g_xkmh,xkmv,g_xkmv,xkhv,g_xkhv,rdx,rdy,dx, &
2926 dy,dt,zx,g_zx,zy,g_zy,rdz,g_rdz,rdzw,g_rdzw,dn,dnw,isotropic,hfx, &
2927 g_hfx,qfx,g_qfx,qv,g_qv,ust,g_ust,rho,g_rho,ids,ide,jds,jde,kds,kde, &
2928 ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
2932 REAL :: Tmpv1,g_Tmpv1,Tmpv2,g_Tmpv2
2933 TYPE(grid_config_rec_type) :: config_flags
2934 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
2935 INTEGER :: isotropic
2936 REAL :: cf1,cf2,cf3,dt,rdx,rdy,dx,dy
2937 REAL,DIMENSION(kms:kme) :: fnm,fnp,dnw,dn
2938 REAL,DIMENSION(ims:ime,jms:jme) :: msftx,msfty
2939 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tendency,g_tendency
2940 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor11,g_defor11,defor22,g_defor22, &
2941 defor33,g_defor33,defor12,g_defor12,defor13,g_defor13,defor23,g_defor23, &
2942 div,g_div,BN2,g_BN2,tke,g_tke,xkmh,g_xkmh,xkmv,g_xkmv,xkhv,g_xkhv, &
2943 zx,g_zx,zy,g_zy,u,g_u,v,g_v,w,g_w,theta,g_theta,p,g_p,p8w, &
2944 g_p8w,t8w,g_t8w,z,g_z,rdz,g_rdz,rdzw,g_rdzw
2945 REAL,DIMENSION(ims:ime,jms:jme) :: mu,g_mu
2946 REAL,DIMENSION(ims:ime,jms:jme) :: hfx,g_hfx,ust,g_ust,qfx,g_qfx
2947 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: qv,g_qv,rho,g_rho
2948 INTEGER :: i,j,k,ktf,i_start,i_end,j_start,j_end
2950 CALL g_tke_shear(tendency,g_tendency,config_flags,defor11,g_defor11,defor22, &
2951 g_defor22,defor33,g_defor33,defor12,g_defor12,defor13,g_defor13,defor23, &
2952 g_defor23,u,g_u,v,g_v,w,g_w,tke,g_tke,ust,g_ust,mu,g_mu,fnm,fnp, &
2953 cf1,cf2,cf3,msftx,msfty,xkmh,g_xkmh,xkmv,g_xkmv,rdx,rdy,zx,g_zx,zy,g_zy, &
2954 rdz,g_rdz,rdzw,g_rdzw,dnw,dn,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme, &
2955 its,ite,jts,jte,kts,kte)
2957 CALL g_tke_buoyancy(tendency,g_tendency,config_flags,mu,g_mu,tke,g_tke, &
2958 xkhv,g_xkhv,BN2,g_BN2,theta,g_theta,dt,hfx,g_hfx,qfx,g_qfx,qv,g_qv, &
2959 rho,g_rho,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
2961 CALL g_tke_dissip(tendency,g_tendency,config_flags,mu,g_mu,tke,g_tke,bn2, &
2962 g_bn2,theta,g_theta,p8w,g_p8w,t8w,g_t8w,z,g_z,dx,dy,rdz,g_rdz,rdzw, &
2963 g_rdzw,isotropic,msftx,msfty,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its, &
2964 ite,jts,jte,kts,kte)
2970 i_end =min(ite,ide-1)
2974 j_end =min(jte,jde-1)
2976 IF( config_flags%open_xs .or. config_flags%specified .or. &
2977 config_flags%nested) i_start =max(ids+1,its)
2979 IF( config_flags%open_xe .or. config_flags%specified .or. &
2980 config_flags%nested) i_end =min(ide-2,ite)
2982 IF( config_flags%open_ys .or. config_flags%specified .or. &
2983 config_flags%nested) j_start =max(jds+1,jts)
2985 IF( config_flags%open_ye .or. config_flags%specified .or. &
2986 config_flags%nested) j_end =min(jde-2,jte)
2988 IF( config_flags%periodic_x ) i_start =its
2990 IF( config_flags%periodic_x ) i_end =min(ite,ide-1)
2996 g_Tmpv1 =-mu(i,j)*(0.0 +g_tke(i,k,j) +(0.0 -g_tke(i,k,j))*sign(1.0, 0.0 -( &
2997 tke(i,k,j))))*0.5 -g_mu(i,j)*max(0.0,tke(i,k,j))
2998 Tmpv1 =-mu(i,j)*max(0.0,tke(i,k,j))
3000 g_tendency(i,k,j) =(g_tendency(i,k,j) +(g_Tmpv1/dt) +(g_tendency(i,k,j) &
3001 -(g_Tmpv1/dt))*sign(1.0, tendency(i,k,j) -(Tmpv1/dt)))*0.5
3002 tendency(i,k,j) =max(tendency(i,k,j),Tmpv1/dt)
3008 END SUBROUTINE g_tke_rhs
3010 SUBROUTINE g_calc_l_scale(config_flags,tke,g_tke,BN2,g_BN2,l_scale, &
3011 g_l_scale,i_start,i_end,ktf,j_start,j_end,dx,dy,rdzw,g_rdzw,msftx,msfty,ids, &
3012 ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
3016 REAL :: Tmpv1,g_Tmpv1,Tmpv2,g_Tmpv2,Tmpv3,g_Tmpv3,Tmpv4,g_Tmpv4
3019 TYPE(grid_config_rec_type) :: config_flags
3020 INTEGER :: i_start,i_end,ktf,j_start,j_end,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme, &
3021 kms,kme,its,ite,jts,jte,kts,kte
3022 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: BN2,g_BN2,tke,g_tke,rdzw,g_rdzw
3024 REAL,DIMENSION(its:ite,kts:kte,jts:jte) :: l_scale,g_l_scale
3025 REAL,DIMENSION(ims:ime,jms:jme) :: msftx,msfty
3027 REAL :: deltas,g_deltas,tmp,g_tmp
3033 g_deltas =0.33333333*(-dx/msftx(i,j) *dy/msfty(i,j)*g_rdzw(i,k,j)/(rdzw(i,k,j) &
3034 *rdzw(i,k,j)))*(dx/msftx(i,j) *dy/msfty(i,j)/rdzw(i,k,j))**(0.33333333 -1.0)
3035 deltas =(dx/msftx(i,j) *dy/msfty(i,j)/rdzw(i,k,j))**0.33333333
3037 g_l_scale(i,k,j) =g_deltas
3038 l_scale(i,k,j) =deltas
3040 IF( BN2(i,k,j) .gt. 1.0e-6 ) THEN
3042 g_tmp =g_Sqrt((g_tke(i,k,j) +0.0 +(g_tke(i,k,j) -0.0)*sign(1.0, tke(i,k, &
3043 j) -(1.0e-6)))*0.5, max(tke(i,k,j),1.0e-6))
3044 tmp =sqrt(max(tke(i,k,j),1.0e-6))
3046 g_Tmpv1 =(0.76*g_tmp*sqrt(BN2(i,k,j)) -g_Sqrt(g_BN2(i,k,j), BN2(i,k,j)) &
3047 *0.76*tmp)/(sqrt(BN2(i,k,j))*sqrt(BN2(i,k,j)))
3048 Tmpv1 =0.76*tmp/sqrt(BN2(i,k,j))
3050 g_l_scale(i,k,j) =g_Tmpv1
3051 l_scale(i,k,j) =Tmpv1
3053 g_l_scale(i,k,j) =(g_l_scale(i,k,j) +g_deltas -(g_l_scale(i,k,j) &
3054 -g_deltas)*sign(1.0, l_scale(i,k,j) -(deltas)))*0.5
3055 l_scale(i,k,j) =min(l_scale(i,k,j),deltas)
3057 g_l_scale(i,k,j) =(g_l_scale(i,k,j) +0.001*g_deltas +(g_l_scale(i,k,j) &
3058 -0.001*g_deltas)*sign(1.0, l_scale(i,k,j) -(0.001*deltas)))*0.5
3059 l_scale(i,k,j) =max(l_scale(i,k,j),0.001*deltas)
3066 END SUBROUTINE g_calc_l_scale
3068 SUBROUTINE g_tke_buoyancy(tendency,g_tendency,config_flags,mu,g_mu,tke, &
3069 g_tke,xkhv,g_xkhv,BN2,g_BN2,theta,g_theta,dt,hfx,g_hfx,qfx,g_qfx, &
3070 qv,g_qv,rho,g_rho,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts, &
3075 REAL :: Tmpv1,g_Tmpv1,Tmpv2,g_Tmpv2,Tmpv3,g_Tmpv3
3076 TYPE(grid_config_rec_type) :: config_flags
3077 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
3079 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tendency,g_tendency
3080 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: xkhv,g_xkhv,tke,g_tke,BN2,g_BN2, &
3082 REAL,DIMENSION(ims:ime,jms:jme) :: mu,g_mu
3083 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: qv,g_qv,rho,g_rho
3084 REAL,DIMENSION(ims:ime,jms:jme) :: hfx,g_hfx,qfx,g_qfx
3085 INTEGER :: i,j,k,ktf
3086 INTEGER :: i_start,i_end,j_start,j_end
3087 REAL :: heat_flux,g_heat_flux,heat_flux0,g_heat_flux0
3094 i_end =min(ite,ide-1)
3098 j_end =min(jte,jde-1)
3100 IF( config_flags%open_xs .OR. config_flags%specified .OR. &
3101 config_flags%nested ) i_start =max(ids+1,its)
3103 IF( config_flags%open_xe .OR. config_flags%specified .OR. &
3104 config_flags%nested ) i_end =min(ide-2,ite)
3106 IF( config_flags%open_ys .OR. config_flags%specified .OR. &
3107 config_flags%nested ) j_start =max(jds+1,jts)
3109 IF( config_flags%open_ye .OR. config_flags%specified .OR. &
3110 config_flags%nested ) j_end =min(jde-2,jte)
3112 IF( config_flags%periodic_x ) i_start =its
3114 IF( config_flags%periodic_x ) i_end =min(ite,ide-1)
3120 g_Tmpv1 =mu(i,j)*g_xkhv(i,k,j) +g_mu(i,j)*xkhv(i,k,j)
3121 Tmpv1 =mu(i,j)*xkhv(i,k,j)
3123 g_Tmpv2 =Tmpv1*g_BN2(i,k,j) +g_Tmpv1*BN2(i,k,j)
3124 Tmpv2 =Tmpv1*BN2(i,k,j)
3126 g_tendency(i,k,j) =g_tendency(i,k,j) -g_Tmpv2
3127 tendency(i,k,j) =tendency(i,k,j) -Tmpv2
3133 ! Added by Ning Pan, 2010-08-12
3134 tl_hflux: SELECT CASE( config_flags%isfflx )
3137 ! g_heat_flux0 =g_config_flags%tke_heat_flux ! Remarked by Ning Pan, 2010-08-12
3138 heat_flux0 =config_flags%tke_heat_flux
3145 ! g_heat_flux =g_heat_flux0 ! Remarked by Ning Pan, 2010-08-12
3146 heat_flux =heat_flux0
3148 g_Tmpv1 =xkhv(i,k,j)*g_BN2(i,k,j) +g_xkhv(i,k,j)*BN2(i,k,j)
3149 Tmpv1 =xkhv(i,k,j)*BN2(i,k,j)
3151 ! Revised by Ning Pan, 2010-08-12
3152 ! g_Tmpv2 =(g/theta(i,k,j))*g_heat_flux +(-g*g_theta(i,k,j)/(theta(i,k,j) &
3153 !*theta(i,k,j)))*heat_flux
3154 g_Tmpv2 =(-g*g_theta(i,k,j)/(theta(i,k,j) &
3155 *theta(i,k,j)))*heat_flux
3156 Tmpv2 =(g/theta(i,k,j))*heat_flux
3158 g_Tmpv3 =mu(i,j)*((g_Tmpv1) -g_Tmpv2) +g_mu(i,j)*((Tmpv1) -Tmpv2)
3159 Tmpv3 =mu(i,j)*((Tmpv1) -Tmpv2)
3161 g_tendency(i,k,j) =g_tendency(i,k,j) -(g_Tmpv3/2.)
3162 tendency(i,k,j) =tendency(i,k,j) -Tmpv3/2.
3167 CASE (1) ! Added by Ning Pan, 2010-08-12
3174 g_cpm =cp*(0.8*g_qv(i,k,j))
3175 cpm =cp*(1. +0.8*qv(i,k,j))
3177 g_Tmpv1 =(g_hfx(i,j)*cpm -g_cpm*hfx(i,j))/(cpm*cpm)
3180 g_Tmpv2 =((g_Tmpv1)*rho(i,k,j) -g_rho(i,k,j)*(Tmpv1))/(rho(i,k,j)*rho(i,k,j))
3181 Tmpv2 =(Tmpv1)/rho(i,k,j)
3183 g_heat_flux =g_Tmpv2
3186 g_Tmpv1 =xkhv(i,k,j)*g_BN2(i,k,j) +g_xkhv(i,k,j)*BN2(i,k,j)
3187 Tmpv1 =xkhv(i,k,j)*BN2(i,k,j)
3189 g_Tmpv2 =(g/theta(i,k,j))*g_heat_flux +(-g*g_theta(i,k,j)/(theta(i,k,j) &
3190 *theta(i,k,j)))*heat_flux
3191 Tmpv2 =(g/theta(i,k,j))*heat_flux
3193 g_Tmpv3 =mu(i,j)*((g_Tmpv1) -g_Tmpv2) +g_mu(i,j)*((Tmpv1) -Tmpv2)
3194 Tmpv3 =mu(i,j)*((Tmpv1) -Tmpv2)
3196 g_tendency(i,k,j) =g_tendency(i,k,j) -(g_Tmpv3/2.)
3197 tendency(i,k,j) =tendency(i,k,j) -Tmpv3/2.
3202 CASE DEFAULT ! Added by Ning Pan, 2010-08-12
3203 ! Revised by Ning Pan, 2010-08-12
3204 ! CALL g_wrf_error_fatal('isfflx value invalid for diff_opt=2')
3205 CALL wrf_error_fatal( 'isfflx value invalid for diff_opt=2' )
3206 END SELECT tl_hflux ! Added by Ning Pan, 2010-08-12
3208 END SUBROUTINE g_tke_buoyancy
3210 SUBROUTINE g_tke_dissip(tendency,g_tendency,config_flags,mu,g_mu,tke, &
3211 g_tke,bn2,g_bn2,theta,g_theta,p8w,g_p8w,t8w,g_t8w,z,g_z,dx,dy,rdz, &
3212 g_rdz,rdzw,g_rdzw,isotropic,msftx,msfty,ids,ide,jds,jde,kds,kde,ims,ime,jms, &
3213 jme,kms,kme,its,ite,jts,jte,kts,kte)
3217 REAL :: Tmpv1,g_Tmpv1,Tmpv2,g_Tmpv2,Tmpv3,g_Tmpv3,Tmpv4,g_Tmpv4
3218 TYPE(grid_config_rec_type) :: config_flags
3219 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
3220 INTEGER :: isotropic
3222 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tendency,g_tendency
3223 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tke,g_tke,bn2,g_bn2,theta, &
3224 g_theta,p8w,g_p8w,t8w,g_t8w,z,g_z,rdz,g_rdz,rdzw,g_rdzw
3225 REAL,DIMENSION(ims:ime,jms:jme) :: mu,g_mu
3226 REAL,DIMENSION(ims:ime,jms:jme) :: msftx,msfty
3227 REAL,DIMENSION(its:ite,kts:kte,jts:jte) :: dthrdn,g_dthrdn
3228 REAL,DIMENSION(its:ite,kts:kte,jts:jte) :: l_scale,g_l_scale
3229 REAL,DIMENSION(its:ite) :: sumtke,g_sumtke,sumtkez,g_sumtkez
3230 INTEGER :: i,j,k,ktf,i_start,i_end,j_start,j_end
3231 REAL :: disp_len,g_disp_len,deltas,g_deltas,coefc,g_coefc,tmpdz,g_tmpdz, &
3232 len_s,g_len_s,thetasfc,g_thetasfc,thetatop,g_thetatop,len_0,g_len_0, &
3233 tketmp,g_tketmp,tmp,g_tmp,ce1,g_ce1,ce2,g_ce2,c_k,g_c_k
3235 ! g_c_k =g_config_flags%c_k ! Remarked by Ning Pan, 2010-08-12
3236 c_k =config_flags%c_k
3238 ! g_ce1 =(g_c_k/0.10)*0.19 ! Remarked by Ning Pan, 2010-08-12
3239 ce1 =(c_k/0.10)*0.19
3241 ! g_ce2 =(0.0 +-g_ce1 +(0.0 --g_ce1)*sign(1.0, 0.0 -(0.93 -ce1)))*0.5 ! Remarked by Ning Pan, 2010-08-12
3242 ce2 =max(0.0,0.93 -ce1)
3248 i_end =min(ite,ide-1)
3252 j_end =min(jte,jde-1)
3254 IF( config_flags%open_xs .OR. config_flags%specified .OR. &
3255 config_flags%nested) i_start =max(ids+1,its)
3257 IF( config_flags%open_xe .OR. config_flags%specified .OR. &
3258 config_flags%nested) i_end =min(ide-2,ite)
3260 IF( config_flags%open_ys .OR. config_flags%specified .OR. &
3261 config_flags%nested) j_start =max(jds+1,jts)
3263 IF( config_flags%open_ye .OR. config_flags%specified .OR. &
3264 config_flags%nested) j_end =min(jde-2,jte)
3266 IF( config_flags%periodic_x ) i_start =its
3268 IF( config_flags%periodic_x ) i_end =min(ite,ide-1)
3270 CALL g_calc_l_scale(config_flags,tke,g_tke,BN2,g_BN2,l_scale,g_l_scale, &
3271 i_start,i_end,ktf,j_start,j_end,dx,dy,rdzw,g_rdzw,msftx,msfty,ids,ide,jds,jde,kds, &
3272 kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
3278 g_deltas =0.33333333*(-dx/msftx(i,j) *dy/msfty(i,j)*g_rdzw(i,k,j)/(rdzw(i,k,j) &
3279 *rdzw(i,k,j)))*(dx/msftx(i,j) *dy/msfty(i,j)/rdzw(i,k,j))**(0.33333333 -1.0)
3280 deltas =(dx/msftx(i,j) *dy/msfty(i,j)/rdzw(i,k,j))**0.33333333
3282 g_tketmp =(g_tke(i,k,j) +0.0 +(g_tke(i,k,j) -0.0)*sign(1.0, tke(i,k,j) &
3284 tketmp =max(tke(i,k,j),1.0e-6)
3286 IF( k .eq. kts .or. k .eq. ktf ) THEN
3293 ! Revised by Ning Pan, 2010-08-12
3294 ! g_Tmpv1 =ce2*g_l_scale(i,k,j) +g_ce2*l_scale(i,k,j)
3295 g_Tmpv1 =ce2*g_l_scale(i,k,j)
3296 Tmpv1 =ce2*l_scale(i,k,j)
3298 g_Tmpv2 =(g_Tmpv1*deltas -g_deltas*Tmpv1)/(deltas*deltas)
3301 ! Revised by Ning Pan, 2010-08-12
3302 ! g_coefc =g_ce1 +g_Tmpv2
3308 g_Tmpv1 =mu(i,j)*g_coefc +g_mu(i,j)*coefc
3309 Tmpv1 =mu(i,j)*coefc
3311 g_Tmpv2 =Tmpv1*1.5*g_tketmp*tketmp**(1.5 -1.0) +g_Tmpv1*tketmp**1.5
3312 Tmpv2 =Tmpv1*tketmp**1.5
3314 g_Tmpv3 =(g_Tmpv2*l_scale(i,k,j) -g_l_scale(i,k,j)*Tmpv2)/(l_scale(i,k,j) &
3316 Tmpv3 =Tmpv2/l_scale(i,k,j)
3318 g_tendency(i,k,j) =g_tendency(i,k,j) -g_Tmpv3
3319 tendency(i,k,j) =tendency(i,k,j) -Tmpv3
3325 END SUBROUTINE g_tke_dissip
3327 SUBROUTINE g_tke_shear(tendency,g_tendency,config_flags,defor11,g_defor11, &
3328 defor22,g_defor22,defor33,g_defor33,defor12,g_defor12,defor13,g_defor13, &
3329 defor23,g_defor23,u,g_u,v,g_v,w,g_w,tke,g_tke,ust,g_ust,mu,g_mu, &
3330 fnm,fnp,cf1,cf2,cf3,msftx,msfty,xkmh,g_xkmh,xkmv,g_xkmv,rdx,rdy,zx,g_zx,zy, &
3331 g_zy,rdz,g_rdz,rdzw,g_rdzw,dn,dnw,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme, &
3332 kms,kme,its,ite,jts,jte,kts,kte)
3336 REAL :: Tmpv1,g_Tmpv1,Tmpv2,g_Tmpv2,Tmpv3,g_Tmpv3,Tmpv4,g_Tmpv4
3339 TYPE(grid_config_rec_type) :: config_flags
3340 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
3341 REAL :: cf1,cf2,cf3,rdx,rdy
3342 REAL,DIMENSION(kms:kme) :: fnm,fnp,dn,dnw
3343 REAL,DIMENSION(ims:ime,jms:jme) :: msftx,msfty
3344 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tendency,g_tendency
3345 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor11,g_defor11,defor22,g_defor22, &
3346 defor33,g_defor33,defor12,g_defor12,defor13,g_defor13,defor23,g_defor23, &
3347 tke,g_tke,xkmh,g_xkmh,xkmv,g_xkmv,zx,g_zx,zy,g_zy,u,g_u,v,g_v,w, &
3348 g_w,rdz,g_rdz,rdzw,g_rdzw
3349 REAL,DIMENSION(ims:ime,jms:jme) :: mu,g_mu
3350 REAL,DIMENSION(ims:ime,jms:jme) :: ust,g_ust
3351 INTEGER :: i,j,k,ktf,ktes1,ktes2,i_start,i_end,j_start,j_end,is_ext,ie_ext,js_ext,je_ext
3353 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: avg,g_avg,titau,g_titau, &
3355 REAL,DIMENSION(its:ite,kts:kte,jts:jte) :: titau12,g_titau12,tmp1,g_tmp1,zxavg, &
3356 g_zxavg,zyavg,g_zyavg
3357 REAL :: absU,g_absU,cd0,g_cd0,Cd,g_Cd
3367 i_end =min(ite,ide-1)
3371 j_end =min(jte,jde-1)
3373 IF( config_flags%open_xs .OR. config_flags%specified .OR. &
3374 config_flags%nested ) i_start =max(ids+1,its)
3376 IF( config_flags%open_xe .OR. config_flags%specified .OR. &
3377 config_flags%nested ) i_end =min(ide-2,ite)
3379 IF( config_flags%open_ys .OR. config_flags%specified .OR. &
3380 config_flags%nested ) j_start =max(jds+1,jts)
3382 IF( config_flags%open_ye .OR. config_flags%specified .OR. &
3383 config_flags%nested ) j_end =min(jde-2,jte)
3385 IF( config_flags%periodic_x ) i_start =its
3387 IF( config_flags%periodic_x ) i_end =min(ite,ide-1)
3393 g_zxavg(i,k,j) =0.25*(g_zx(i,k,j) +g_zx(i+1,k,j) +g_zx(i,k+1,j) &
3395 zxavg(i,k,j) =0.25*(zx(i,k,j) +zx(i+1,k,j) +zx(i,k+1,j) +zx(i+1,k+1,j))
3397 g_zyavg(i,k,j) =0.25*(g_zy(i,k,j) +g_zy(i,k,j+1) +g_zy(i,k+1,j) &
3399 zyavg(i,k,j) =0.25*(zy(i,k,j) +zy(i,k,j+1) +zy(i,k+1,j) +zy(i,k+1,j+1))
3409 g_Tmpv1 =0.5*mu(i,j)*g_xkmh(i,k,j) +0.5*g_mu(i,j)*xkmh(i,k,j)
3410 Tmpv1 =0.5*mu(i,j)*xkmh(i,k,j)
3412 g_Tmpv2 =Tmpv1*(2.0*(g_defor11(i,k,j))*(defor11(i,k,j))) +g_Tmpv1*(( &
3414 Tmpv2 =Tmpv1*((defor11(i,k,j))**2)
3416 g_tendency(i,k,j) =g_tendency(i,k,j) +g_Tmpv2
3417 tendency(i,k,j) =tendency(i,k,j) +Tmpv2
3427 g_Tmpv1 =0.5*mu(i,j)*g_xkmh(i,k,j) +0.5*g_mu(i,j)*xkmh(i,k,j)
3428 Tmpv1 =0.5*mu(i,j)*xkmh(i,k,j)
3430 g_Tmpv2 =Tmpv1*(2.0*(g_defor22(i,k,j))*(defor22(i,k,j))) +g_Tmpv1*(( &
3432 Tmpv2 =Tmpv1*((defor22(i,k,j))**2)
3434 g_tendency(i,k,j) =g_tendency(i,k,j) +g_Tmpv2
3435 tendency(i,k,j) =tendency(i,k,j) +Tmpv2
3445 g_Tmpv1 =0.5*mu(i,j)*g_xkmv(i,k,j) +0.5*g_mu(i,j)*xkmv(i,k,j)
3446 Tmpv1 =0.5*mu(i,j)*xkmv(i,k,j)
3448 g_Tmpv2 =Tmpv1*(2.0*(g_defor33(i,k,j))*(defor33(i,k,j))) +g_Tmpv1*(( &
3450 Tmpv2 =Tmpv1*((defor33(i,k,j))**2)
3452 g_tendency(i,k,j) =g_tendency(i,k,j) +g_Tmpv2
3453 tendency(i,k,j) =tendency(i,k,j) +Tmpv2
3463 g_avg(i,k,j) =0.25*((2.0*g_defor12(i,k,j)*defor12(i,k,j)) +(2.0*g_defor12(i, &
3464 k,j+1)*defor12(i,k,j+1)) +(2.0*g_defor12(i+1,k,j)*defor12(i+1,k,j)) +(2.0* &
3465 g_defor12(i+1,k,j+1)*defor12(i+1,k,j+1)))
3466 avg(i,k,j) =0.25*((defor12(i,k,j)**2) +(defor12(i,k,j+1)**2) +(defor12(i+1,k,j)**2) &
3467 +(defor12(i+1,k,j+1)**2))
3477 g_Tmpv1 =mu(i,j)*g_xkmh(i,k,j) +g_mu(i,j)*xkmh(i,k,j)
3478 Tmpv1 =mu(i,j)*xkmh(i,k,j)
3480 g_Tmpv2 =Tmpv1*g_avg(i,k,j) +g_Tmpv1*avg(i,k,j)
3481 Tmpv2 =Tmpv1*avg(i,k,j)
3483 g_tendency(i,k,j) =g_tendency(i,k,j) +g_Tmpv2
3484 tendency(i,k,j) =tendency(i,k,j) +Tmpv2
3492 DO i =i_start,i_end+1
3494 g_tmp2(i,k,j) =g_defor13(i,k,j)
3495 tmp2(i,k,j) =defor13(i,k,j)
3502 DO i =i_start,i_end+1
3504 g_tmp2(i,kts,j) =0.0
3507 g_tmp2(i,ktf+1,j) =0.0
3508 tmp2(i,ktf+1,j) =0.0
3517 g_avg(i,k,j) =0.25*((2.0*g_tmp2(i,k+1,j)*tmp2(i,k+1,j)) +(2.0*g_tmp2(i,k,j) &
3518 *tmp2(i,k,j)) +(2.0*g_tmp2(i+1,k+1,j)*tmp2(i+1,k+1,j)) +(2.0*g_tmp2(i+1,k,j) &
3520 avg(i,k,j) =0.25*((tmp2(i,k+1,j)**2) +(tmp2(i,k,j)**2) +(tmp2(i+1,k+1,j)**2) &
3521 +(tmp2(i+1,k,j)**2))
3531 g_Tmpv1 =mu(i,j)*g_xkmv(i,k,j) +g_mu(i,j)*xkmv(i,k,j)
3532 Tmpv1 =mu(i,j)*xkmv(i,k,j)
3534 g_Tmpv2 =Tmpv1*g_avg(i,k,j) +g_Tmpv1*avg(i,k,j)
3535 Tmpv2 =Tmpv1*avg(i,k,j)
3537 g_tendency(i,k,j) =g_tendency(i,k,j) +g_Tmpv2
3538 tendency(i,k,j) =tendency(i,k,j) +Tmpv2
3546 ! Added by Ning Pan, 2010-08-12
3547 tl_uflux: SELECT CASE( config_flags%isfflx )
3550 ! g_cd0 =g_config_flags%tke_drag_coefficient ! Remarked by Ning Pan, 2010-08-12
3551 cd0 =config_flags%tke_drag_coefficient
3556 g_absU =0.5*g_Sqrt(2.0*(g_u(i,k,j) +g_u(i+1,k,j))*(u(i,k,j) +u(i+1,k,j)) &
3557 +2.0*(g_v(i,k,j) +g_v(i,k,j+1))*(v(i,k,j) +v(i,k,j+1)), (u(i,k,j) +u(i+1,k,j)) &
3558 **2 +(v(i,k,j) +v(i,k,j+1))**2)
3559 absU =0.5*sqrt((u(i,k,j) +u(i+1,k,j))**2 +(v(i,k,j) +v(i,k,j+1))**2)
3561 ! Revised by Ning Pan, 2010-08-12
3566 g_Tmpv1 =(u(i,k,j) +u(i+1,k,j))*0.5*g_Cd +(g_u(i,k,j) +g_u(i+1,k,j))*0.5*Cd
3567 Tmpv1 =(u(i,k,j) +u(i+1,k,j))*0.5*Cd
3569 g_Tmpv2 =Tmpv1*g_absU +g_Tmpv1*absU
3572 g_Tmpv3 =Tmpv2*(g_defor13(i,kts+1,j) +g_defor13(i+1,kts+1,j)) &
3573 +g_Tmpv2*(defor13(i,kts+1,j) +defor13(i+1,kts+1,j))
3574 Tmpv3 =Tmpv2*(defor13(i,kts+1,j) +defor13(i+1,kts+1,j))
3576 g_Tmpv4 =mu(i,j)*(g_Tmpv3*0.5) +g_mu(i,j)*(Tmpv3*0.5)
3577 Tmpv4 =mu(i,j)*(Tmpv3*0.5)
3579 g_tendency(i,k,j) =g_tendency(i,k,j) +g_Tmpv4
3580 tendency(i,k,j) =tendency(i,k,j) +Tmpv4
3585 CASE (1,2) ! Added by Ning Pan, 2010-08-12
3590 g_absU =0.5*g_Sqrt(2.0*(g_u(i,k,j) +g_u(i+1,k,j))*(u(i,k,j) +u(i+1,k,j)) &
3591 +2.0*(g_v(i,k,j) +g_v(i,k,j+1))*(v(i,k,j) +v(i,k,j+1)), (u(i,k,j) +u(i+1,k,j)) &
3592 **2 +(v(i,k,j) +v(i,k,j+1))**2)
3593 absU =0.5*sqrt((u(i,k,j) +u(i+1,k,j))**2 +(v(i,k,j) +v(i,k,j+1))**2) +epsilon
3595 g_Tmpv1 =((2.0*g_ust(i,j)*ust(i,j))*(absU**2) -(2.0*g_absU*absU)*(ust(i,j) &
3596 **2))/((absU**2)*(absU**2))
3597 Tmpv1 =(ust(i,j)**2)/(absU**2)
3602 g_Tmpv1 =(u(i,k,j) +u(i+1,k,j))*0.5*g_Cd +(g_u(i,k,j) +g_u(i+1,k,j))*0.5*Cd
3603 Tmpv1 =(u(i,k,j) +u(i+1,k,j))*0.5*Cd
3605 g_Tmpv2 =Tmpv1*g_absU +g_Tmpv1*absU
3608 g_Tmpv3 =Tmpv2*(g_defor13(i,kts+1,j) +g_defor13(i+1,kts+1,j)) &
3609 +g_Tmpv2*(defor13(i,kts+1,j) +defor13(i+1,kts+1,j))
3610 Tmpv3 =Tmpv2*(defor13(i,kts+1,j) +defor13(i+1,kts+1,j))
3612 g_Tmpv4 =mu(i,j)*(g_Tmpv3*0.5) +g_mu(i,j)*(Tmpv3*0.5)
3613 Tmpv4 =mu(i,j)*(Tmpv3*0.5)
3615 g_tendency(i,k,j) =g_tendency(i,k,j) +g_Tmpv4
3616 tendency(i,k,j) =tendency(i,k,j) +Tmpv4
3621 CASE DEFAULT ! Added by Ning Pan, 2010-08-12
3622 ! Revised by Ning Pan, 2010-08-12
3623 ! CALL g_wrf_error_fatal('isfflx value invalid for diff_opt=2')
3624 CALL wrf_error_fatal('isfflx value invalid for diff_opt=2')
3625 END SELECT tl_uflux ! Added by Ning Pan, 2010-08-12
3627 DO j =j_start,j_end+1
3631 g_tmp2(i,k,j) =g_defor23(i,k,j)
3632 tmp2(i,k,j) =defor23(i,k,j)
3638 DO j =j_start,j_end+1
3641 g_tmp2(i,kts,j) =0.0
3644 g_tmp2(i,ktf+1,j) =0.0
3645 tmp2(i,ktf+1,j) =0.0
3654 g_avg(i,k,j) =0.25*((2.0*g_tmp2(i,k+1,j)*tmp2(i,k+1,j)) +(2.0*g_tmp2(i,k,j) &
3655 *tmp2(i,k,j)) +(2.0*g_tmp2(i,k+1,j+1)*tmp2(i,k+1,j+1)) +(2.0*g_tmp2(i,k,j+1) &
3657 avg(i,k,j) =0.25*((tmp2(i,k+1,j)**2) +(tmp2(i,k,j)**2) +(tmp2(i,k+1,j+1)**2) &
3658 +(tmp2(i,k,j+1)**2))
3668 g_Tmpv1 =mu(i,j)*g_xkmv(i,k,j) +g_mu(i,j)*xkmv(i,k,j)
3669 Tmpv1 =mu(i,j)*xkmv(i,k,j)
3671 g_Tmpv2 =Tmpv1*g_avg(i,k,j) +g_Tmpv1*avg(i,k,j)
3672 Tmpv2 =Tmpv1*avg(i,k,j)
3674 g_tendency(i,k,j) =g_tendency(i,k,j) +g_Tmpv2
3675 tendency(i,k,j) =tendency(i,k,j) +Tmpv2
3683 ! Added by Ning Pan, 2010-08-12
3684 tl_vflux: SELECT CASE( config_flags%isfflx )
3687 ! g_cd0 =g_config_flags%tke_drag_coefficient ! Remarked by Ning Pan, 2010-08-12
3688 cd0 =config_flags%tke_drag_coefficient
3693 g_absU =0.5*g_Sqrt(2.0*(g_u(i,k,j) +g_u(i+1,k,j))*(u(i,k,j) +u(i+1,k,j)) &
3694 +2.0*(g_v(i,k,j) +g_v(i,k,j+1))*(v(i,k,j) +v(i,k,j+1)), (u(i,k,j) +u(i+1,k,j)) &
3695 **2 +(v(i,k,j) +v(i,k,j+1))**2)
3696 absU =0.5*sqrt((u(i,k,j) +u(i+1,k,j))**2 +(v(i,k,j) +v(i,k,j+1))**2)
3698 ! Revised by Ning Pan, 2010-08-12
3703 g_Tmpv1 =(v(i,k,j) +v(i,k,j+1))*0.5*g_Cd +(g_v(i,k,j) +g_v(i,k,j+1))*0.5*Cd
3704 Tmpv1 =(v(i,k,j) +v(i,k,j+1))*0.5*Cd
3706 g_Tmpv2 =Tmpv1*g_absU +g_Tmpv1*absU
3709 g_Tmpv3 =Tmpv2*(g_defor23(i,kts+1,j) +g_defor23(i,kts+1,j+1)) &
3710 +g_Tmpv2*(defor23(i,kts+1,j) +defor23(i,kts+1,j+1))
3711 Tmpv3 =Tmpv2*(defor23(i,kts+1,j) +defor23(i,kts+1,j+1))
3713 g_Tmpv4 =mu(i,j)*(g_Tmpv3*0.5) +g_mu(i,j)*(Tmpv3*0.5)
3714 Tmpv4 =mu(i,j)*(Tmpv3*0.5)
3716 g_tendency(i,k,j) =g_tendency(i,k,j) +g_Tmpv4
3717 tendency(i,k,j) =tendency(i,k,j) +Tmpv4
3722 CASE (1,2) ! Added by Ning Pan, 2010-08-12
3727 g_absU =0.5*g_Sqrt(2.0*(g_u(i,k,j) +g_u(i+1,k,j))*(u(i,k,j) +u(i+1,k,j)) &
3728 +2.0*(g_v(i,k,j) +g_v(i,k,j+1))*(v(i,k,j) +v(i,k,j+1)), (u(i,k,j) +u(i+1,k,j)) &
3729 **2 +(v(i,k,j) +v(i,k,j+1))**2)
3730 absU =0.5*sqrt((u(i,k,j) +u(i+1,k,j))**2 +(v(i,k,j) +v(i,k,j+1))**2) +epsilon
3732 g_Tmpv1 =((2.0*g_ust(i,j)*ust(i,j))*(absU**2) -(2.0*g_absU*absU)*(ust(i,j) &
3733 **2))/((absU**2)*(absU**2))
3734 Tmpv1 =(ust(i,j)**2)/(absU**2)
3739 g_Tmpv1 =(v(i,k,j) +v(i,k,j+1))*0.5*g_Cd +(g_v(i,k,j) +g_v(i,k,j+1))*0.5*Cd
3740 Tmpv1 =(v(i,k,j) +v(i,k,j+1))*0.5*Cd
3742 g_Tmpv2 =Tmpv1*g_absU +g_Tmpv1*absU
3745 g_Tmpv3 =Tmpv2*(g_defor23(i,kts+1,j) +g_defor23(i,kts+1,j+1)) &
3746 +g_Tmpv2*(defor23(i,kts+1,j) +defor23(i,kts+1,j+1))
3747 Tmpv3 =Tmpv2*(defor23(i,kts+1,j) +defor23(i,kts+1,j+1))
3749 g_Tmpv4 =mu(i,j)*(g_Tmpv3*0.5) +g_mu(i,j)*(Tmpv3*0.5)
3750 Tmpv4 =mu(i,j)*(Tmpv3*0.5)
3752 g_tendency(i,k,j) =g_tendency(i,k,j) +g_Tmpv4
3753 tendency(i,k,j) =tendency(i,k,j) +Tmpv4
3758 CASE DEFAULT ! Added by Ning Pan, 2010-08-12
3759 ! Revised by Ning Pan, 2010-08-12
3760 ! CALL g_wrf_error_fatal('isfflx value invalid for diff_opt=2')
3761 CALL wrf_error_fatal( 'isfflx value invalid for diff_opt=2' )
3762 END SELECT tl_vflux ! Added by Ning Pan, 2010-08-12
3764 END SUBROUTINE g_tke_shear
3766 ! Generated by TAPENADE (INRIA, Tropics team)
3767 ! Tapenade 3.5 (r3785) - 22 Mar 2011 18:35
3769 ! Differentiation of compute_diff_metrics in forward (tangent) mode:
3770 ! variations of useful results: zx zy z rdzw rdz
3771 ! with respect to varying inputs: zx zy z rdzw rdz ph
3772 ! RW status of diff variables: zx:in-out zy:in-out z:in-out rdzw:in-out
3774 SUBROUTINE G_COMPUTE_DIFF_METRICS(config_flags, ph, phd, phb, z, zd, rdz&
3775 & , rdzd, rdzw, rdzwd, zx, zxd, zy, zyd, rdx, rdy, ids, ide, jds, jde, &
3776 & kds, kde, ims, ime, jms, jme, kms, kme, its, ite, jts, jte, kts, kte)
3778 TYPE(GRID_CONFIG_REC_TYPE), INTENT(IN) :: config_flags
3779 INTEGER, INTENT(IN) :: ids, ide, jds, jde, kds, kde, ims, ime, jms, &
3780 & jme, kms, kme, its, ite, jts, jte, kts, kte
3781 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: ph, phb
3782 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: phd
3783 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(OUT) :: rdz, rdzw, &
3785 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(OUT) :: rdzd, rdzwd&
3787 REAL, INTENT(IN) :: rdx, rdy
3789 REAL, DIMENSION(its - 1:ite, kts:kte, jts - 1:jte) :: z_at_w
3790 REAL, DIMENSION(its-1:ite, kts:kte, jts-1:jte) :: z_at_wd
3791 INTEGER :: i, j, k, i_start, i_end, j_start, j_end, ktf
3798 IF (kte .GT. kde - 1) THEN
3803 ! Bug fix, WCS, 22 april 2002.
3804 ! We need rdzw in halo for average to u and v points.
3808 ! Begin with dz computations.
3810 IF (jte .GT. jde - 1) THEN
3815 IF (j_start .GE. jts .AND. j_end .LE. min1) THEN
3820 IF (ite .GT. ide - 1) THEN
3826 ! Compute z at w points for rdz and rdzw computations. We'll switch z
3827 ! to z at p points before returning
3829 ! Bug fix, WCS, 22 april 2002
3831 z_at_wd(i, k, j) = phd(i, k, j)/g
3832 z_at_w(i, k, j) = (ph(i, k, j)+phb(i, k, j))/g
3837 rdzwd(i, k, j) = -((z_at_wd(i, k+1, j)-z_at_wd(i, k, j))/(z_at_w&
3838 & (i, k+1, j)-z_at_w(i, k, j))**2)
3839 rdzw(i, k, j) = 1.0/(z_at_w(i, k+1, j)-z_at_w(i, k, j))
3844 rdzd(i, k, j) = -(2.0*(z_at_wd(i, k+1, j)-z_at_wd(i, k-1, j))/(&
3845 & z_at_w(i, k+1, j)-z_at_w(i, k-1, j))**2)
3846 rdz(i, k, j) = 2.0/(z_at_w(i, k+1, j)-z_at_w(i, k-1, j))
3849 ! Bug fix, WCS, 22 april 2002; added the following code
3851 rdzd(i, 1, j) = -(2.*(z_at_wd(i, 2, j)-z_at_wd(i, 1, j))/(z_at_w(i&
3852 & , 2, j)-z_at_w(i, 1, j))**2)
3853 rdz(i, 1, j) = 2./(z_at_w(i, 2, j)-z_at_w(i, 1, j))
3857 ! Now compute zx and zy; we'll assume that the halo for ph and phb is
3860 IF (ite .GT. ide - 1) THEN
3866 IF (jte .GT. jde - 1) THEN
3873 IF (ids + 1 .LT. its) THEN
3880 zx(i, k, j) = rdx*(phb(i, k, j)-phb(i-1, k, j))/g
3886 IF (ids + 1 .LT. its) THEN
3892 zxd(i, k, j) = zxd(i, k, j) + rdx*(phd(i, k, j)-phd(i-1, k, j))/&
3894 zx(i, k, j) = zx(i, k, j) + rdx*(ph(i, k, j)-ph(i-1, k, j))/g
3898 IF (jds + 1 .LT. jts) THEN
3907 zy(i, k, j) = rdy*(phb(i, k, j)-phb(i, k, j-1))/g
3911 IF (jds + 1 .LT. jts) THEN
3919 zyd(i, k, j) = zyd(i, k, j) + rdy*(phd(i, k, j)-phd(i, k, j-1))/&
3921 zy(i, k, j) = zy(i, k, j) + rdy*(ph(i, k, j)-ph(i, k, j-1))/g
3925 ! Some b.c. on zx and zy.
3926 IF (.NOT.config_flags%periodic_x) THEN
3927 IF (ite .EQ. ide) THEN
3930 zxd(ide, k, j) = 0.0
3935 IF (its .EQ. ids) THEN
3938 zxd(ids, k, j) = 0.0
3944 IF (ite .EQ. ide) THEN
3947 zxd(ide, k, j) = 0.0
3948 zx(ide, k, j) = rdx*(phb(ide, k, j)-phb(ide-1, k, j))/g
3953 zxd(ide, k, j) = zxd(ide, k, j) + rdx*(phd(ide, k, j)-phd(ide-&
3955 zx(ide, k, j) = zx(ide, k, j) + rdx*(ph(ide, k, j)-ph(ide-1, k&
3960 IF (its .EQ. ids) THEN
3963 zxd(ids, k, j) = 0.0
3964 zx(ids, k, j) = rdx*(phb(ids, k, j)-phb(ids-1, k, j))/g
3969 zxd(ids, k, j) = zxd(ids, k, j) + rdx*(phd(ids, k, j)-phd(ids-&
3971 zx(ids, k, j) = zx(ids, k, j) + rdx*(ph(ids, k, j)-ph(ids-1, k&
3977 IF (.NOT.config_flags%periodic_y) THEN
3978 IF (jte .EQ. jde) THEN
3981 zyd(i, k, jde) = 0.0
3986 IF (jts .EQ. jds) THEN
3989 zyd(i, k, jds) = 0.0
3995 IF (jte .EQ. jde) THEN
3997 DO i =i_start, i_end
3998 zyd(i, k, jde) = 0.0
3999 zy(i, k, jde) = rdy*(phb(i, k, jde)-phb(i, k, jde-1))/g
4003 DO i =i_start, i_end
4004 zyd(i, k, jde) = zyd(i, k, jde) + rdy*(phd(i, k, jde)-phd(i, k&
4006 zy(i, k, jde) = zy(i, k, jde) + rdy*(ph(i, k, jde)-ph(i, k, &
4011 IF (jts .EQ. jds) THEN
4013 DO i =i_start, i_end
4014 zyd(i, k, jds) = 0.0
4015 zy(i, k, jds) = rdy*(phb(i, k, jds)-phb(i, k, jds-1))/g
4019 DO i =i_start, i_end
4020 zyd(i, k, jds) = zyd(i, k, jds) + rdy*(phd(i, k, jds)-phd(i, k&
4022 zy(i, k, jds) = zy(i, k, jds) + rdy*(ph(i, k, jds)-ph(i, k, &
4028 ! Calculate z at p points.
4032 zd(i, k, j) = 0.5*(phd(i, k, j)+phd(i, k+1, j))/g
4033 z(i, k, j) = 0.5*(ph(i, k, j)+phb(i, k, j)+ph(i, k+1, j)+phb(i, &
4038 END SUBROUTINE G_COMPUTE_DIFF_METRICS
4040 SUBROUTINE g_horizontal_diffusion_2(rt_tendf,g_rt_tendf,ru_tendf,g_ru_tendf, &
4041 rv_tendf,g_rv_tendf,rw_tendf,g_rw_tendf,tke_tendf,g_tke_tendf,moist_tendf, &
4042 g_moist_tendf,n_moist,chem_tendf,g_chem_tendf,n_chem,scalar_tendf, &
4043 g_scalar_tendf,n_scalar,tracer_tendf,g_tracer_tendf,n_tracer,thp,g_thp, &
4044 theta,g_theta,mu,g_mu,tke,g_tke,config_flags,defor11,g_defor11,defor22, &
4045 g_defor22,defor12,g_defor12,defor13,g_defor13,defor23,g_defor23,nba_mij, &
4046 g_nba_mij,n_nba_mij,div,g_div,moist,g_moist,chem,g_chem,scalar, &
4047 g_scalar,tracer,g_tracer,msfux,msfuy,msfvx,msfvy,msftx,msfty,xkmh,g_xkmh, &
4048 xkhh,g_xkhh,km_opt,rdx,rdy,rdz,g_rdz,rdzw,g_rdzw,fnm,fnp,cf1,cf2,cf3,zx, &
4049 g_zx,zy,g_zy,dn,dnw,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite, &
4054 REAL :: Tmpv1,g_Tmpv1
4055 TYPE(grid_config_rec_type) :: config_flags
4056 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
4057 INTEGER :: n_moist,n_chem,n_scalar,n_tracer,km_opt
4059 REAL,DIMENSION(kms:kme) :: fnm
4060 REAL,DIMENSION(kms:kme) :: fnp
4061 REAL,DIMENSION(kms:kme) :: dnw
4062 REAL,DIMENSION(kms:kme) :: dn
4063 REAL,DIMENSION(ims:ime,jms:jme) :: msfux,msfuy,msfvx,msfvy,msftx,msfty,mu,g_mu
4064 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: rt_tendf,g_rt_tendf,ru_tendf, &
4065 g_ru_tendf,rv_tendf,g_rv_tendf,rw_tendf,g_rw_tendf,tke_tendf,g_tke_tendf
4066 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_moist) :: moist_tendf,g_moist_tendf
4067 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_chem) :: chem_tendf,g_chem_tendf
4068 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_scalar) :: scalar_tendf,g_scalar_tendf
4069 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_tracer) :: tracer_tendf,g_tracer_tendf
4070 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_moist) :: moist,g_moist
4071 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_chem) :: chem,g_chem
4072 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_scalar) :: scalar,g_scalar
4073 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_tracer) :: tracer,g_tracer
4074 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor11,g_defor11,defor22,g_defor22, &
4075 defor12,g_defor12,defor13,g_defor13,defor23,g_defor23,div,g_div,xkmh, &
4076 g_xkmh,xkhh,g_xkhh,zx,g_zx,zy,g_zy,theta,g_theta,thp,g_thp,tke, &
4077 g_tke,rdz,g_rdz,rdzw,g_rdzw
4080 INTEGER :: n_nba_mij
4082 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_nba_mij) :: nba_mij,g_nba_mij
4085 CALL g_horizontal_diffusion_u_2(ru_tendf,g_ru_tendf,mu,g_mu,config_flags, &
4086 defor11,g_defor11,defor12,g_defor12,div,g_div,nba_mij,g_nba_mij, &
4087 n_nba_mij,tke(ims,kms,jms),g_tke(ims,kms,jms),msfux,msfuy,xkmh,g_xkmh,rdx,rdy, &
4088 fnm,fnp,zx,g_zx,zy,g_zy,rdzw,g_rdzw,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme, &
4089 kms,kme,its,ite,jts,jte,kts,kte)
4091 CALL g_horizontal_diffusion_v_2(rv_tendf,g_rv_tendf,mu,g_mu,config_flags, &
4092 defor12,g_defor12,defor22,g_defor22,div,g_div,nba_mij,g_nba_mij, &
4093 n_nba_mij,tke(ims,kms,jms),g_tke(ims,kms,jms),msfvx,msfvy,xkmh,g_xkmh,rdx,rdy, &
4094 fnm,fnp,zx,g_zx,zy,g_zy,rdzw,g_rdzw,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme, &
4095 kms,kme,its,ite,jts,jte,kts,kte)
4097 CALL g_horizontal_diffusion_w_2(rw_tendf,g_rw_tendf,mu,g_mu,config_flags, &
4098 defor13,g_defor13,defor23,g_defor23,div,g_div,nba_mij,g_nba_mij, &
4099 n_nba_mij,tke(ims,kms,jms),g_tke(ims,kms,jms),msftx,msfty,xkmh,g_xkmh,rdx,rdy, &
4100 fnm,fnp,zx,g_zx,zy,g_zy,rdz,g_rdz,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme, &
4101 kms,kme,its,ite,jts,jte,kts,kte)
4103 CALL g_horizontal_diffusion_s(rt_tendf,g_rt_tendf,mu,g_mu,config_flags,thp, &
4104 g_thp,msftx,msfty,msfux,msfuy,msfvx,msfvy,xkhh,g_xkhh,rdx,rdy,fnm,fnp,cf1,cf2, &
4105 cf3,zx,g_zx,zy,g_zy,rdz,g_rdz,rdzw,g_rdzw,dnw,dn,.false.,ids,ide,jds,jde, &
4106 kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
4108 IF(km_opt .eq. 2) CALL g_horizontal_diffusion_s(tke_tendf(ims,kms,jms) &
4109 ,g_tke_tendf(ims,kms,jms),mu,g_mu,config_flags,tke(ims,kms,jms),g_tke(ims, &
4110 kms,jms),msftx,msfty,msfux,msfuy,msfvx,msfvy,xkhh,g_xkhh,rdx,rdy,fnm,fnp,cf1,cf2, &
4111 cf3,zx,g_zx,zy,g_zy,rdz,g_rdz,rdzw,g_rdzw,dnw,dn,.true.,ids,ide,jds,jde, &
4112 kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
4114 IF(n_moist .ge. PARAM_FIRST_SCALAR) THEN
4116 DO im =PARAM_FIRST_SCALAR,n_moist
4118 CALL g_horizontal_diffusion_s(moist_tendf(ims,kms,jms,im),g_moist_tendf(ims, &
4119 kms,jms,im),mu,g_mu,config_flags,moist(ims,kms,jms,im),g_moist(ims,kms,jms,im) &
4120 ,msftx,msfty,msfux,msfuy,msfvx,msfvy,xkhh,g_xkhh,rdx,rdy,fnm,fnp,cf1,cf2,cf3,zx, &
4121 g_zx,zy,g_zy,rdz,g_rdz,rdzw,g_rdzw,dnw,dn,.false.,ids,ide,jds,jde,kds, &
4122 kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
4126 IF(n_chem .ge. PARAM_FIRST_SCALAR) THEN
4128 DO ic =PARAM_FIRST_SCALAR,n_chem
4130 CALL g_horizontal_diffusion_s(chem_tendf(ims,kms,jms,ic),g_chem_tendf(ims,kms, &
4131 jms,ic),mu,g_mu,config_flags,chem(ims,kms,jms,ic),g_chem(ims,kms,jms,ic) &
4132 ,msftx,msfty,msfux,msfuy,msfvx,msfvy,xkhh,g_xkhh,rdx,rdy,fnm,fnp,cf1,cf2,cf3,zx, &
4133 g_zx,zy,g_zy,rdz,g_rdz,rdzw,g_rdzw,dnw,dn,.false.,ids,ide,jds,jde,kds, &
4134 kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
4138 IF(n_tracer .ge. PARAM_FIRST_SCALAR) THEN
4140 DO ic =PARAM_FIRST_SCALAR,n_tracer
4142 CALL g_horizontal_diffusion_s(tracer_tendf(ims,kms,jms,ic),g_tracer_tendf(ims, &
4143 kms,jms,ic),mu,g_mu,config_flags,tracer(ims,kms,jms,ic),g_tracer(ims,kms,jms, &
4144 ic),msftx,msfty,msfux,msfuy,msfvx,msfvy,xkhh,g_xkhh,rdx,rdy,fnm,fnp,cf1,cf2,cf3, &
4145 zx,g_zx,zy,g_zy,rdz,g_rdz,rdzw,g_rdzw,dnw,dn,.false.,ids,ide,jds,jde,kds, &
4146 kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
4150 IF(n_scalar .ge. PARAM_FIRST_SCALAR) THEN
4152 DO is =PARAM_FIRST_SCALAR,n_scalar
4154 CALL g_horizontal_diffusion_s(scalar_tendf(ims,kms,jms,is),g_scalar_tendf(ims, &
4155 kms,jms,is),mu,g_mu,config_flags,scalar(ims,kms,jms,is),g_scalar(ims,kms,jms, &
4156 is),msftx,msfty,msfux,msfuy,msfvx,msfvy,xkhh,g_xkhh,rdx,rdy,fnm,fnp,cf1,cf2,cf3, &
4157 zx,g_zx,zy,g_zy,rdz,g_rdz,rdzw,g_rdzw,dnw,dn,.false.,ids,ide,jds,jde,kds, &
4158 kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
4162 END SUBROUTINE g_horizontal_diffusion_2
4164 SUBROUTINE g_horizontal_diffusion_u_2(tendency,g_tendency,mu,g_mu, &
4165 config_flags,defor11,g_defor11,defor12,g_defor12,div,g_div,nba_mij, &
4166 g_nba_mij,n_nba_mij,tke,g_tke,msfux,msfuy,xkmh,g_xkmh,rdx,rdy,fnm,fnp,zx, &
4167 g_zx,zy,g_zy,rdzw,g_rdzw,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme, &
4168 its,ite,jts,jte,kts,kte)
4172 REAL :: Tmpv1,g_Tmpv1,Tmpv2,g_Tmpv2,Tmpv3,g_Tmpv3,Tmpv4,g_Tmpv4
4173 TYPE(grid_config_rec_type) :: config_flags
4174 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
4175 REAL,DIMENSION(kms:kme) :: fnm
4176 REAL,DIMENSION(kms:kme) :: fnp
4177 REAL,DIMENSION(ims:ime,jms:jme) :: msfux,msfuy,mu,g_mu
4178 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tendency,g_tendency
4179 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: rdzw,g_rdzw
4180 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor11,g_defor11,defor12,g_defor12, &
4181 div,g_div,tke,g_tke,xkmh,g_xkmh,zx,g_zx,zy,g_zy
4183 INTEGER :: n_nba_mij
4185 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_nba_mij) :: nba_mij,g_nba_mij
4187 INTEGER :: i,j,k,ktf
4188 INTEGER :: i_start,i_end,j_start,j_end
4189 INTEGER :: is_ext,ie_ext,js_ext,je_ext
4190 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: titau1avg,g_titau1avg, &
4191 titau2avg,g_titau2avg,titau1,g_titau1,titau2,g_titau2,xkxavg,g_xkxavg, &
4193 REAL :: mrdx,g_mrdx,mrdy,g_mrdy,rcoup,g_rcoup
4194 REAL :: tmpzy,g_tmpzy,tmpzeta_z,g_tmpzeta_z
4195 REAL :: term1,g_term1,term2,g_term2,term3,g_term3
4205 j_end =min(jte,jde-1)
4207 IF( config_flags%open_xs .or. config_flags%specified .or. &
4208 config_flags%nested) i_start =max(ids+1,its)
4210 IF( config_flags%open_xe .or. config_flags%specified .or. &
4211 config_flags%nested) i_end =min(ide-1,ite)
4213 IF( config_flags%open_ys .or. config_flags%specified .or. &
4214 config_flags%nested) j_start =max(jds+1,jts)
4216 IF( config_flags%open_ye .or. config_flags%specified .or. &
4217 config_flags%nested) j_end =min(jde-2,jte)
4219 IF( config_flags%periodic_x ) i_start =its
4221 IF( config_flags%periodic_x ) i_end =ite
4231 CALL g_cal_titau_11_22_33(config_flags,titau1,g_titau1,mu,g_mu,tke,g_tke, &
4232 xkmh,g_xkmh,defor11,g_defor11,nba_mij(ims,kms,jms,P_m11),g_nba_mij(ims,kms, &
4233 jms,P_m11),is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms, &
4234 kme,its,ite,jts,jte,kts,kte)
4244 CALL g_cal_titau_12_21(config_flags,titau2,g_titau2,mu,g_mu,xkmh,g_xkmh, &
4245 defor12,g_defor12,nba_mij(ims,kms,jms,P_m12),g_nba_mij(ims,kms,jms,P_m12) &
4246 ,is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite, &
4253 g_titau1avg(i,k,j) =0.5*(fnm(k)*(g_titau1(i-1,k,j) +g_titau1(i,k,j)) +fnp(k) &
4254 *(g_titau1(i-1,k-1,j) +g_titau1(i,k-1,j)))
4255 titau1avg(i,k,j) =0.5*(fnm(k)*(titau1(i-1,k,j) +titau1(i,k,j)) +fnp(k)*(titau1(i-1,k- &
4256 1,j) +titau1(i,k-1,j)))
4258 g_titau2avg(i,k,j) =0.5*(fnm(k)*(g_titau2(i,k,j+1) +g_titau2(i,k,j)) +fnp(k) &
4259 *(g_titau2(i,k-1,j+1) +g_titau2(i,k-1,j)))
4260 titau2avg(i,k,j) =0.5*(fnm(k)*(titau2(i,k,j+1) +titau2(i,k,j)) +fnp(k)*(titau2(i,k-1, &
4261 j+1) +titau2(i,k-1,j)))
4263 g_tmpzy =0.25*(g_zy(i-1,k,j) +g_zy(i,k,j) +g_zy(i-1,k,j+1) +g_zy(i,k,j+1))
4264 tmpzy =0.25*(zy(i-1,k,j) +zy(i,k,j) +zy(i-1,k,j+1) +zy(i,k,j+1))
4266 g_Tmpv1 =titau1avg(i,k,j)*g_zx(i,k,j) +g_titau1avg(i,k,j)*zx(i,k,j)
4267 Tmpv1 =titau1avg(i,k,j)*zx(i,k,j)
4269 g_titau1avg(i,k,j) =g_Tmpv1
4270 titau1avg(i,k,j) =Tmpv1
4272 g_Tmpv1 =titau2avg(i,k,j)*g_tmpzy +g_titau2avg(i,k,j)*tmpzy
4273 Tmpv1 =titau2avg(i,k,j)*tmpzy
4275 g_titau2avg(i,k,j) =g_Tmpv1
4276 titau2avg(i,k,j) =Tmpv1
4285 g_titau1avg(i,kts,j) =0.0
4286 titau1avg(i,kts,j) =0.
4288 g_titau1avg(i,ktf+1,j) =0.0
4289 titau1avg(i,ktf+1,j) =0.
4291 g_titau2avg(i,kts,j) =0.0
4292 titau2avg(i,kts,j) =0.
4294 g_titau2avg(i,ktf+1,j) =0.0
4295 titau2avg(i,ktf+1,j) =0.
4304 ! g_mrdx =0.0 ! Remarked by Ning Pan, 2010-08-10
4305 mrdx =msfux(i,j) *rdx
4307 ! g_mrdy =0.0 ! Remarked by Ning Pan, 2010-08-10
4308 mrdy =msfuy(i,j) *rdy
4310 ! Revised by Ning Pan, 2010-08-10
4311 ! g_Tmpv1 =mrdx*(g_titau1(i,k,j) -g_titau1(i-1,k,j)) +g_mrdx*(titau1(i,k, &
4312 ! j) -titau1(i-1,k,j))
4313 g_Tmpv1 =mrdx*(g_titau1(i,k,j) -g_titau1(i-1,k,j))
4314 Tmpv1 =mrdx*(titau1(i,k,j) -titau1(i-1,k,j))
4316 ! Revised by Ning Pan, 2010-08-10
4317 ! g_Tmpv2 =mrdy*(g_titau2(i,k,j+1) -g_titau2(i,k,j)) +g_mrdy*(titau2(i,k, &
4318 ! j+1) -titau2(i,k,j))
4319 g_Tmpv2 =mrdy*(g_titau2(i,k,j+1) -g_titau2(i,k,j))
4320 Tmpv2 =mrdy*(titau2(i,k,j+1) -titau2(i,k,j))
4322 g_Tmpv3 =msfuy(i,j)*rdzw(i,k,j)*((g_titau1avg(i,k+1,j) -g_titau1avg(i,k,j)) &
4323 +(g_titau2avg(i,k+1,j) -g_titau2avg(i,k,j))) +msfuy(i,j)*g_rdzw(i,k,j) &
4324 *((titau1avg(i,k+1,j) -titau1avg(i,k,j)) +(titau2avg(i,k+1,j) -titau2avg(i,k,j)))
4325 Tmpv3 =msfuy(i,j)*rdzw(i,k,j)*((titau1avg(i,k+1,j) -titau1avg(i,k,j)) +(titau2avg(i, &
4326 k+1,j) -titau2avg(i,k,j)))
4328 g_tendency(i,k,j) =g_tendency(i,k,j) -(g_Tmpv1 +g_Tmpv2 -g_Tmpv3)
4329 tendency(i,k,j) =tendency(i,k,j) -(Tmpv1 +Tmpv2 -Tmpv3)
4335 END SUBROUTINE g_horizontal_diffusion_u_2
4337 SUBROUTINE g_horizontal_diffusion_v_2(tendency,g_tendency,mu,g_mu, &
4338 config_flags,defor12,g_defor12,defor22,g_defor22,div,g_div,nba_mij, &
4339 g_nba_mij,n_nba_mij,tke,g_tke,msfvx,msfvy,xkmh,g_xkmh,rdx,rdy,fnm,fnp,zx, &
4340 g_zx,zy,g_zy,rdzw,g_rdzw,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme, &
4341 its,ite,jts,jte,kts,kte)
4345 REAL :: Tmpv1,g_Tmpv1,Tmpv2,g_Tmpv2,Tmpv3,g_Tmpv3,Tmpv4,g_Tmpv4
4346 TYPE(grid_config_rec_type) :: config_flags
4347 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
4348 REAL,DIMENSION(kms:kme) :: fnm
4349 REAL,DIMENSION(kms:kme) :: fnp
4350 REAL,DIMENSION(ims:ime,jms:jme) :: msfvx,msfvy,mu,g_mu
4351 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tendency,g_tendency
4352 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor12,g_defor12,defor22,g_defor22, &
4353 div,g_div,tke,g_tke,xkmh,g_xkmh,zx,g_zx,zy,g_zy,rdzw,g_rdzw
4355 INTEGER :: n_nba_mij
4357 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_nba_mij) :: nba_mij,g_nba_mij
4359 INTEGER :: i,j,k,ktf
4360 INTEGER :: i_start,i_end,j_start,j_end
4361 INTEGER :: is_ext,ie_ext,js_ext,je_ext
4362 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: titau1avg,g_titau1avg, &
4363 titau2avg,g_titau2avg,titau1,g_titau1,titau2,g_titau2,xkxavg,g_xkxavg, &
4365 REAL :: mrdx,g_mrdx,mrdy,g_mrdy,rcoup,g_rcoup
4366 REAL :: tmpzx,g_tmpzx,tmpzeta_z,g_tmpzeta_z
4372 i_end =min(ite,ide-1)
4378 IF( config_flags%open_xs .or. config_flags%specified .or. &
4379 config_flags%nested) i_start =max(ids+1,its)
4381 IF( config_flags%open_xe .or. config_flags%specified .or. &
4382 config_flags%nested) i_end =min(ide-2,ite)
4384 IF( config_flags%open_ys .or. config_flags%specified .or. &
4385 config_flags%nested) j_start =max(jds+1,jts)
4387 IF( config_flags%open_ye .or. config_flags%specified .or. &
4388 config_flags%nested) j_end =min(jde-1,jte)
4390 IF( config_flags%periodic_x ) i_start =its
4392 IF( config_flags%periodic_x ) i_end =min(ite,ide-1)
4402 CALL g_cal_titau_12_21(config_flags,titau1,g_titau1,mu,g_mu,xkmh,g_xkmh, &
4403 defor12,g_defor12,nba_mij(ims,kms,jms,P_m12),g_nba_mij(ims,kms,jms,P_m12) &
4404 ,is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite, &
4415 CALL g_cal_titau_11_22_33(config_flags,titau2,g_titau2,mu,g_mu,tke,g_tke, &
4416 xkmh,g_xkmh,defor22,g_defor22,nba_mij(ims,kms,jms,P_m22),g_nba_mij(ims,kms, &
4417 jms,P_m22),is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms, &
4418 kme,its,ite,jts,jte,kts,kte)
4424 g_titau1avg(i,k,j) =0.5*(fnm(k)*(g_titau1(i+1,k,j) +g_titau1(i,k,j)) +fnp(k) &
4425 *(g_titau1(i+1,k-1,j) +g_titau1(i,k-1,j)))
4426 titau1avg(i,k,j) =0.5*(fnm(k)*(titau1(i+1,k,j) +titau1(i,k,j)) +fnp(k)*(titau1(i+1,k- &
4427 1,j) +titau1(i,k-1,j)))
4429 g_titau2avg(i,k,j) =0.5*(fnm(k)*(g_titau2(i,k,j-1) +g_titau2(i,k,j)) +fnp(k) &
4430 *(g_titau2(i,k-1,j-1) +g_titau2(i,k-1,j)))
4431 titau2avg(i,k,j) =0.5*(fnm(k)*(titau2(i,k,j-1) +titau2(i,k,j)) +fnp(k)*(titau2(i,k-1, &
4432 j-1) +titau2(i,k-1,j)))
4434 g_tmpzx =0.25*(g_zx(i,k,j) +g_zx(i+1,k,j) +g_zx(i,k,j-1) +g_zx(i+1,k,j-1))
4435 tmpzx =0.25*(zx(i,k,j) +zx(i+1,k,j) +zx(i,k,j-1) +zx(i+1,k,j-1))
4437 g_Tmpv1 =titau1avg(i,k,j)*g_tmpzx +g_titau1avg(i,k,j)*tmpzx
4438 Tmpv1 =titau1avg(i,k,j)*tmpzx
4440 g_titau1avg(i,k,j) =g_Tmpv1
4441 titau1avg(i,k,j) =Tmpv1
4443 g_Tmpv1 =titau2avg(i,k,j)*g_zy(i,k,j) +g_titau2avg(i,k,j)*zy(i,k,j)
4444 Tmpv1 =titau2avg(i,k,j)*zy(i,k,j)
4446 g_titau2avg(i,k,j) =g_Tmpv1
4447 titau2avg(i,k,j) =Tmpv1
4456 g_titau1avg(i,kts,j) =0.0
4457 titau1avg(i,kts,j) =0.
4459 g_titau1avg(i,ktf+1,j) =0.0
4460 titau1avg(i,ktf+1,j) =0.
4462 g_titau2avg(i,kts,j) =0.0
4463 titau2avg(i,kts,j) =0.
4465 g_titau2avg(i,ktf+1,j) =0.0
4466 titau2avg(i,ktf+1,j) =0.
4475 ! g_mrdx =0.0 ! Remarked by Ning Pan, 2010-08-10
4476 mrdx =msfvx(i,j) *rdx
4478 ! g_mrdy =0.0 ! Remarked by Ning Pan, 2010-08-10
4479 mrdy =msfvy(i,j) *rdy
4481 ! Revised by Ning Pan, 2010-08-10
4482 ! g_Tmpv1 =mrdy*(g_titau2(i,k,j) -g_titau2(i,k,j-1)) +g_mrdy*(titau2(i,k, &
4483 ! j) -titau2(i,k,j-1))
4484 g_Tmpv1 =mrdy*(g_titau2(i,k,j) -g_titau2(i,k,j-1))
4485 Tmpv1 =mrdy*(titau2(i,k,j) -titau2(i,k,j-1))
4487 ! Revised by Ning Pan, 2010-08-10
4488 ! g_Tmpv2 =mrdx*(g_titau1(i+1,k,j) -g_titau1(i,k,j)) +g_mrdx*(titau1(i+1, &
4489 ! k,j) -titau1(i,k,j))
4490 g_Tmpv2 =mrdx*(g_titau1(i+1,k,j) -g_titau1(i,k,j))
4491 Tmpv2 =mrdx*(titau1(i+1,k,j) -titau1(i,k,j))
4493 g_Tmpv3 =msfvy(i,j)*rdzw(i,k,j)*((g_titau1avg(i,k+1,j) -g_titau1avg(i,k,j)) &
4494 +(g_titau2avg(i,k+1,j) -g_titau2avg(i,k,j))) +msfvy(i,j)*g_rdzw(i,k,j) &
4495 *((titau1avg(i,k+1,j) -titau1avg(i,k,j)) +(titau2avg(i,k+1,j) -titau2avg(i,k,j)))
4496 Tmpv3 =msfvy(i,j)*rdzw(i,k,j)*((titau1avg(i,k+1,j) -titau1avg(i,k,j)) +(titau2avg(i, &
4497 k+1,j) -titau2avg(i,k,j)))
4499 g_tendency(i,k,j) =g_tendency(i,k,j) -(g_Tmpv1 +g_Tmpv2 -g_Tmpv3)
4500 tendency(i,k,j) =tendency(i,k,j) -(Tmpv1 +Tmpv2 -Tmpv3)
4506 END SUBROUTINE g_horizontal_diffusion_v_2
4508 SUBROUTINE g_horizontal_diffusion_w_2(tendency,g_tendency,mu,g_mu, &
4509 config_flags,defor13,g_defor13,defor23,g_defor23,div,g_div,nba_mij, &
4510 g_nba_mij,n_nba_mij,tke,g_tke,msftx,msfty,xkmh,g_xkmh,rdx,rdy,fnm,fnp,zx, &
4511 g_zx,zy,g_zy,rdz,g_rdz,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its, &
4512 ite,jts,jte,kts,kte)
4516 REAL :: Tmpv1,g_Tmpv1,Tmpv2,g_Tmpv2,Tmpv3,g_Tmpv3,Tmpv4,g_Tmpv4
4517 TYPE(grid_config_rec_type) :: config_flags
4518 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
4519 REAL,DIMENSION(kms:kme) :: fnm
4520 REAL,DIMENSION(kms:kme) :: fnp
4521 REAL,DIMENSION(ims:ime,jms:jme) :: msftx,msfty,mu,g_mu
4522 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tendency,g_tendency
4523 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor13,g_defor13,defor23,g_defor23, &
4524 div,g_div,tke,g_tke,xkmh,g_xkmh,zx,g_zx,zy,g_zy,rdz,g_rdz
4526 INTEGER :: n_nba_mij
4528 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_nba_mij) :: nba_mij,g_nba_mij
4530 INTEGER :: i,j,k,ktf
4531 INTEGER :: i_start,i_end,j_start,j_end
4532 INTEGER :: is_ext,ie_ext,js_ext,je_ext
4533 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: titau1avg,g_titau1avg, &
4534 titau2avg,g_titau2avg,titau1,g_titau1,titau2,g_titau2,xkxavg,g_xkxavg, &
4536 REAL :: mrdx,g_mrdx,mrdy,g_mrdy,rcoup,g_rcoup
4537 REAL :: tmpzx,g_tmpzx,tmpzy,g_tmpzy,tmpzeta_z,g_tmpzeta_z
4543 i_end =min(ite,ide-1)
4547 j_end =min(jte,jde-1)
4549 IF( config_flags%open_xs .or. config_flags%specified .or. &
4550 config_flags%nested) i_start =max(ids+1,its)
4552 IF( config_flags%open_xe .or. config_flags%specified .or. &
4553 config_flags%nested) i_end =min(ide-2,ite)
4555 IF( config_flags%open_ys .or. config_flags%specified .or. &
4556 config_flags%nested) j_start =max(jds+1,jts)
4558 IF( config_flags%open_ye .or. config_flags%specified .or. &
4559 config_flags%nested) j_end =min(jde-2,jte)
4561 IF( config_flags%periodic_x ) i_start =its
4563 IF( config_flags%periodic_x ) i_end =min(ite,ide-1)
4573 CALL g_cal_titau_13_31(config_flags,titau1,g_titau1,defor13,g_defor13, &
4574 nba_mij(ims,kms,jms,P_m13),g_nba_mij(ims,kms,jms,P_m13),mu,g_mu,xkmh,g_xkmh, &
4575 fnm,fnp,is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme, &
4576 its,ite,jts,jte,kts,kte)
4586 CALL g_cal_titau_23_32(config_flags,titau2,g_titau2,defor23,g_defor23, &
4587 nba_mij(ims,kms,jms,P_m23),g_nba_mij(ims,kms,jms,P_m23),mu,g_mu,xkmh,g_xkmh, &
4588 fnm,fnp,is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme, &
4589 its,ite,jts,jte,kts,kte)
4595 g_titau1avg(i,k,j) =0.25*(g_titau1(i+1,k+1,j) +g_titau1(i,k+1,j) &
4596 +g_titau1(i+1,k,j) +g_titau1(i,k,j))
4597 titau1avg(i,k,j) =0.25*(titau1(i+1,k+1,j) +titau1(i,k+1,j) +titau1(i+1,k,j) +titau1(i,k,j))
4599 g_titau2avg(i,k,j) =0.25*(g_titau2(i,k+1,j+1) +g_titau2(i,k+1,j) &
4600 +g_titau2(i,k,j+1) +g_titau2(i,k,j))
4601 titau2avg(i,k,j) =0.25*(titau2(i,k+1,j+1) +titau2(i,k+1,j) +titau2(i,k,j+1) +titau2(i,k,j))
4603 g_tmpzx =0.25*(g_zx(i,k,j) +g_zx(i+1,k,j) +g_zx(i,k+1,j) +g_zx(i+1,k+1,j))
4604 tmpzx =0.25*(zx(i,k,j) +zx(i+1,k,j) +zx(i,k+1,j) +zx(i+1,k+1,j))
4606 g_tmpzy =0.25*(g_zy(i,k,j) +g_zy(i,k,j+1) +g_zy(i,k+1,j) +g_zy(i,k+1,j+1))
4607 tmpzy =0.25*(zy(i,k,j) +zy(i,k,j+1) +zy(i,k+1,j) +zy(i,k+1,j+1))
4609 g_Tmpv1 =titau1avg(i,k,j)*g_tmpzx +g_titau1avg(i,k,j)*tmpzx
4610 Tmpv1 =titau1avg(i,k,j)*tmpzx
4612 g_titau1avg(i,k,j) =g_Tmpv1
4613 titau1avg(i,k,j) =Tmpv1
4615 g_Tmpv1 =titau2avg(i,k,j)*g_tmpzy +g_titau2avg(i,k,j)*tmpzy
4616 Tmpv1 =titau2avg(i,k,j)*tmpzy
4618 g_titau2avg(i,k,j) =g_Tmpv1
4619 titau2avg(i,k,j) =Tmpv1
4628 g_titau1avg(i,ktf+1,j) =0.0
4629 titau1avg(i,ktf+1,j) =0.
4631 g_titau2avg(i,ktf+1,j) =0.0
4632 titau2avg(i,ktf+1,j) =0.
4641 ! g_mrdx =0.0 ! Remarked by Ning Pan, 2010-08-10
4642 mrdx =msftx(i,j) *rdx
4644 ! g_mrdy =0.0 ! Remarked by Ning Pan, 2010-08-10
4645 mrdy =msfty(i,j) *rdy
4647 ! Revised by Ning Pan, 2010-08-10
4648 ! g_Tmpv1 =mrdx*(g_titau1(i+1,k,j) -g_titau1(i,k,j)) +g_mrdx*(titau1(i+1, &
4649 ! k,j) -titau1(i,k,j))
4650 g_Tmpv1 =mrdx*(g_titau1(i+1,k,j) -g_titau1(i,k,j))
4651 Tmpv1 =mrdx*(titau1(i+1,k,j) -titau1(i,k,j))
4653 ! Revised by Ning Pan, 2010-08-10
4654 ! g_Tmpv2 =mrdy*(g_titau2(i,k,j+1) -g_titau2(i,k,j)) +g_mrdy*(titau2(i,k, &
4655 ! j+1) -titau2(i,k,j))
4656 g_Tmpv2 =mrdy*(g_titau2(i,k,j+1) -g_titau2(i,k,j))
4657 Tmpv2 =mrdy*(titau2(i,k,j+1) -titau2(i,k,j))
4659 g_Tmpv3 =msfty(i,j)*rdz(i,k,j)*(g_titau1avg(i,k,j) -g_titau1avg(i,k-1,j) &
4660 +g_titau2avg(i,k,j) -g_titau2avg(i,k-1,j)) +msfty(i,j)*g_rdz(i,k,j) &
4661 *(titau1avg(i,k,j) -titau1avg(i,k-1,j) +titau2avg(i,k,j) -titau2avg(i,k-1,j))
4662 Tmpv3 =msfty(i,j)*rdz(i,k,j)*(titau1avg(i,k,j) -titau1avg(i,k-1,j) +titau2avg(i,k,j) &
4663 -titau2avg(i,k-1,j))
4665 g_tendency(i,k,j) =g_tendency(i,k,j) -(g_Tmpv1 +g_Tmpv2 -g_Tmpv3)
4666 tendency(i,k,j) =tendency(i,k,j) -(Tmpv1 +Tmpv2 -Tmpv3)
4672 END SUBROUTINE g_horizontal_diffusion_w_2
4674 SUBROUTINE g_horizontal_diffusion_s(tendency,g_tendency,mu,g_mu, &
4675 config_flags,var,g_var,msftx,msfty,msfux,msfuy,msfvx,msfvy,xkhh,g_xkhh,rdx,rdy, &
4676 fnm,fnp,cf1,cf2,cf3,zx,g_zx,zy,g_zy,rdz,g_rdz,rdzw,g_rdzw,dnw,dn, &
4677 doing_tke,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
4681 REAL :: Tmpv1,g_Tmpv1,Tmpv2,g_Tmpv2,Tmpv3,g_Tmpv3,Tmpv4,g_Tmpv4,Tmpv5, &
4682 g_Tmpv5,Tmpv6,g_Tmpv6,Tmpv7,g_Tmpv7,Tmpv8,g_Tmpv8,Tmpv9,g_Tmpv9
4683 TYPE(grid_config_rec_type) :: config_flags
4684 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
4685 LOGICAL :: doing_tke
4687 REAL,DIMENSION(kms:kme) :: fnm
4688 REAL,DIMENSION(kms:kme) :: fnp
4689 REAL,DIMENSION(kms:kme) :: dn
4690 REAL,DIMENSION(kms:kme) :: dnw
4691 REAL,DIMENSION(ims:ime,jms:jme) :: msfux
4692 REAL,DIMENSION(ims:ime,jms:jme) :: msfuy
4693 REAL,DIMENSION(ims:ime,jms:jme) :: msfvx
4694 REAL,DIMENSION(ims:ime,jms:jme) :: msfvy
4695 REAL,DIMENSION(ims:ime,jms:jme) :: msftx
4696 REAL,DIMENSION(ims:ime,jms:jme) :: msfty
4697 REAL,DIMENSION(ims:ime,jms:jme) :: mu,g_mu
4698 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tendency,g_tendency
4699 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: xkhh,g_xkhh,rdz,g_rdz,rdzw,g_rdzw
4700 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: var,g_var,zx,g_zx,zy,g_zy
4702 INTEGER :: i,j,k,ktf
4703 INTEGER :: i_start,i_end,j_start,j_end
4704 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: H1avg,g_H1avg,H2avg,g_H2avg, &
4705 H1,g_H1,H2,g_H2,xkxavg,g_xkxavg
4706 REAL,DIMENSION(its:ite,kts:kte,jts:jte) :: tmptendf,g_tmptendf
4707 REAL :: mrdx,g_mrdx,mrdy,g_mrdy,rcoup,g_rcoup
4708 REAL :: tmpzx,g_tmpzx,tmpzy,g_tmpzy,tmpzeta_z,g_tmpzeta_z,rdzu,g_rdzu, &
4710 INTEGER :: ktes1,ktes2
4720 i_end =min(ite,ide-1)
4724 j_end =min(jte,jde-1)
4726 IF( config_flags%open_xs .or. config_flags%specified .or. &
4727 config_flags%nested) i_start =max(ids+1,its)
4729 IF( config_flags%open_xe .or. config_flags%specified .or. &
4730 config_flags%nested) i_end =min(ide-2,ite)
4732 IF( config_flags%open_ys .or. config_flags%specified .or. &
4733 config_flags%nested) j_start =max(jds+1,jts)
4735 IF( config_flags%open_ye .or. config_flags%specified .or. &
4736 config_flags%nested) j_end =min(jde-2,jte)
4738 IF( config_flags%periodic_x ) i_start =its
4740 IF( config_flags%periodic_x ) i_end =min(ite,ide-1)
4742 IF( doing_tke ) THEN
4748 g_tmptendf(i,k,j) =g_tendency(i,k,j)
4749 tmptendf(i,k,j) =tendency(i,k,j)
4758 DO i =i_start,i_end+1
4760 g_xkxavg(i,k,j) =0.5*(g_xkhh(i-1,k,j) +g_xkhh(i,k,j))
4761 xkxavg(i,k,j) =0.5*(xkhh(i-1,k,j) +xkhh(i,k,j))
4769 DO i =i_start,i_end+1
4771 g_H1avg(i,k,j) =0.5*(fnm(k)*(g_var(i-1,k,j) +g_var(i,k,j)) +fnp(k) &
4772 *(g_var(i-1,k-1,j) +g_var(i,k-1,j)))
4773 H1avg(i,k,j) =0.5*(fnm(k)*(var(i-1,k,j) +var(i,k,j)) +fnp(k)*(var(i-1,k-1,j) +var(i,k-1,j)))
4780 DO i =i_start,i_end+1
4782 g_H1avg(i,kts,j) =0.5*(cf1*g_var(i,1,j) +cf2*g_var(i,2,j) +cf3*g_var(i,3, &
4783 j) +cf1*g_var(i-1,1,j) +cf2*g_var(i-1,2,j) +cf3*g_var(i-1,3,j))
4784 H1avg(i,kts,j) =0.5*(cf1*var(i,1,j) +cf2*var(i,2,j) +cf3*var(i,3,j) +cf1*var(i-1,1,j) &
4785 +cf2*var(i-1,2,j) +cf3*var(i-1,3,j))
4787 g_H1avg(i,ktf+1,j) =0.5*(g_var(i,ktes1,j) +((g_var(i,ktes1,j) -g_var(i, &
4788 ktes2,j))*0.5*dnw(ktes1)/dn(ktes1)) +g_var(i-1,ktes1,j) +((g_var(i-1,ktes1,j) &
4789 -g_var(i-1,ktes2,j))*0.5*dnw(ktes1)/dn(ktes1)))
4790 H1avg(i,ktf+1,j) =0.5*(var(i,ktes1,j) +(var(i,ktes1,j) -var(i,ktes2,j)) &
4791 *0.5*dnw(ktes1)/dn(ktes1) +var(i-1,ktes1,j) +(var(i-1,ktes1,j) -var(i-1,ktes2,j)) &
4792 *0.5*dnw(ktes1)/dn(ktes1))
4799 DO i =i_start,i_end+1
4801 g_tmpzx =0.5*(g_zx(i,k,j) +g_zx(i,k+1,j))
4802 tmpzx =0.5*(zx(i,k,j) +zx(i,k+1,j))
4804 g_rdzu =-2.*(-1.*g_rdzw(i,k,j)/(rdzw(i,k,j)*rdzw(i,k,j)) +(-1.*g_rdzw(i-1,k, &
4805 j)/(rdzw(i-1,k,j)*rdzw(i-1,k,j))))/((1./rdzw(i,k,j) +1./rdzw(i-1,k,j))*(1./rdzw(i,k, &
4806 j) +1./rdzw(i-1,k,j)))
4807 rdzu =2./(1./rdzw(i,k,j) +1./rdzw(i-1,k,j))
4809 g_Tmpv1 =tmpzx*(g_H1avg(i,k+1,j) -g_H1avg(i,k,j)) +g_tmpzx*(H1avg(i,k+1, &
4811 Tmpv1 =tmpzx*(H1avg(i,k+1,j) -H1avg(i,k,j))
4813 g_Tmpv2 =Tmpv1*g_rdzu +g_Tmpv1*rdzu
4816 g_Tmpv3 =-msfuy(i,j)*xkxavg(i,k,j)*(rdx*(g_var(i,k,j) -g_var(i-1,k,j)) &
4817 -g_Tmpv2) -msfuy(i,j)*g_xkxavg(i,k,j)*(rdx*(var(i,k,j) -var(i-1,k,j)) -Tmpv2)
4818 Tmpv3 =-msfuy(i,j)*xkxavg(i,k,j)*(rdx*(var(i,k,j) -var(i-1,k,j)) -Tmpv2)
4820 g_H1(i,k,j) =g_Tmpv3
4827 DO j =j_start,j_end+1
4831 g_xkxavg(i,k,j) =0.5*(g_xkhh(i,k,j-1) +g_xkhh(i,k,j))
4832 xkxavg(i,k,j) =0.5*(xkhh(i,k,j-1) +xkhh(i,k,j))
4838 DO j =j_start,j_end+1
4842 g_H2avg(i,k,j) =0.5*(fnm(k)*(g_var(i,k,j-1) +g_var(i,k,j)) +fnp(k) &
4843 *(g_var(i,k-1,j-1) +g_var(i,k-1,j)))
4844 H2avg(i,k,j) =0.5*(fnm(k)*(var(i,k,j-1) +var(i,k,j)) +fnp(k)*(var(i,k-1,j-1) +var(i,k-1,j)))
4850 DO j =j_start,j_end+1
4853 g_H2avg(i,kts,j) =0.5*(cf1*g_var(i,1,j) +cf2*g_var(i,2,j) +cf3*g_var(i,3, &
4854 j) +cf1*g_var(i,1,j-1) +cf2*g_var(i,2,j-1) +cf3*g_var(i,3,j-1))
4855 H2avg(i,kts,j) =0.5*(cf1*var(i,1,j) +cf2*var(i,2,j) +cf3*var(i,3,j) +cf1*var(i,1,j-1) &
4856 +cf2*var(i,2,j-1) +cf3*var(i,3,j-1))
4858 g_H2avg(i,ktf+1,j) =0.5*(g_var(i,ktes1,j) +((g_var(i,ktes1,j) -g_var(i, &
4859 ktes2,j))*0.5*dnw(ktes1)/dn(ktes1)) +g_var(i,ktes1,j-1) +((g_var(i,ktes1,j-1) &
4860 -g_var(i,ktes2,j-1))*0.5*dnw(ktes1)/dn(ktes1)))
4861 H2avg(i,ktf+1,j) =0.5*(var(i,ktes1,j) +(var(i,ktes1,j) -var(i,ktes2,j)) &
4862 *0.5*dnw(ktes1)/dn(ktes1) +var(i,ktes1,j-1) +(var(i,ktes1,j-1) -var(i,ktes2,j-1)) &
4863 *0.5*dnw(ktes1)/dn(ktes1))
4868 DO j =j_start,j_end+1
4872 g_tmpzy =0.5*(g_zy(i,k,j) +g_zy(i,k+1,j))
4873 tmpzy =0.5*(zy(i,k,j) +zy(i,k+1,j))
4875 g_rdzv =-2.*(-1.*g_rdzw(i,k,j)/(rdzw(i,k,j)*rdzw(i,k,j)) +(-1.*g_rdzw(i,k,j- &
4876 1)/(rdzw(i,k,j-1)*rdzw(i,k,j-1))))/((1./rdzw(i,k,j) +1./rdzw(i,k,j-1))*(1./rdzw(i,k, &
4877 j) +1./rdzw(i,k,j-1)))
4878 rdzv =2./(1./rdzw(i,k,j) +1./rdzw(i,k,j-1))
4880 g_Tmpv1 =tmpzy*(g_H2avg(i,k+1,j) -g_H2avg(i,k,j)) +g_tmpzy*(H2avg(i,k+1, &
4882 Tmpv1 =tmpzy*(H2avg(i,k+1,j) -H2avg(i,k,j))
4884 g_Tmpv2 =Tmpv1*g_rdzv +g_Tmpv1*rdzv
4887 g_Tmpv3 =-msfvy(i,j)*xkxavg(i,k,j)*(rdy*(g_var(i,k,j) -g_var(i,k,j-1)) &
4888 -g_Tmpv2) -msfvy(i,j)*g_xkxavg(i,k,j)*(rdy*(var(i,k,j) -var(i,k,j-1)) -Tmpv2)
4889 Tmpv3 =-msfvy(i,j)*xkxavg(i,k,j)*(rdy*(var(i,k,j) -var(i,k,j-1)) -Tmpv2)
4891 g_H2(i,k,j) =g_Tmpv3
4902 g_H1avg(i,k,j) =0.5*(fnm(k)*(g_H1(i+1,k,j) +g_H1(i,k,j)) +fnp(k) &
4903 *(g_H1(i+1,k-1,j) +g_H1(i,k-1,j)))
4904 H1avg(i,k,j) =0.5*(fnm(k)*(H1(i+1,k,j) +H1(i,k,j)) +fnp(k)*(H1(i+1,k-1,j) +H1(i,k-1,j)))
4906 g_H2avg(i,k,j) =0.5*(fnm(k)*(g_H2(i,k,j+1) +g_H2(i,k,j)) +fnp(k) &
4907 *(g_H2(i,k-1,j+1) +g_H2(i,k-1,j)))
4908 H2avg(i,k,j) =0.5*(fnm(k)*(H2(i,k,j+1) +H2(i,k,j)) +fnp(k)*(H2(i,k-1,j+1) +H2(i,k-1,j)))
4910 g_tmpzx =0.5*(g_zx(i,k,j) +g_zx(i+1,k,j))
4911 tmpzx =0.5*(zx(i,k,j) +zx(i+1,k,j))
4913 g_tmpzy =0.5*(g_zy(i,k,j) +g_zy(i,k,j+1))
4914 tmpzy =0.5*(zy(i,k,j) +zy(i,k,j+1))
4916 g_Tmpv1 =H1avg(i,k,j)*g_tmpzx +g_H1avg(i,k,j)*tmpzx
4917 Tmpv1 =H1avg(i,k,j)*tmpzx
4919 g_H1avg(i,k,j) =g_Tmpv1
4922 g_Tmpv1 =H2avg(i,k,j)*g_tmpzy +g_H2avg(i,k,j)*tmpzy
4923 Tmpv1 =H2avg(i,k,j)*tmpzy
4925 g_H2avg(i,k,j) =g_Tmpv1
4935 g_H1avg(i,kts,j) =0.0
4938 g_H1avg(i,ktf+1,j) =0.0
4939 H1avg(i,ktf+1,j) =0.
4941 g_H2avg(i,kts,j) =0.0
4944 g_H2avg(i,ktf+1,j) =0.0
4945 H2avg(i,ktf+1,j) =0.
4954 ! g_mrdx =0.0 ! Remarked by Ning Pan, 2010-08-10
4955 mrdx =msftx(i,j) *rdx
4957 ! g_mrdy =0.0 ! Remarked by Ning Pan, 2010-08-10
4958 mrdy =msfty(i,j) *rdy
4960 g_Tmpv1 =(mu(i+1,j) +mu(i,j))*g_H1(i+1,k,j) +(g_mu(i+1,j) +g_mu(i,j))*H1(i+1,k,j)
4961 Tmpv1 =(mu(i+1,j) +mu(i,j))*H1(i+1,k,j)
4963 g_Tmpv2 =(mu(i-1,j) +mu(i,j))*g_H1(i,k,j) +(g_mu(i-1,j) +g_mu(i,j))*H1(i,k,j)
4964 Tmpv2 =(mu(i-1,j) +mu(i,j))*H1(i,k,j)
4966 ! Revised by Ning Pan, 2010-08-10
4967 ! g_Tmpv3 =mrdx*0.5*(g_Tmpv1 -g_Tmpv2) +g_mrdx*0.5*(Tmpv1 -Tmpv2)
4968 g_Tmpv3 =mrdx*0.5*(g_Tmpv1 -g_Tmpv2)
4969 Tmpv3 =mrdx*0.5*(Tmpv1 -Tmpv2)
4971 g_Tmpv4 =(mu(i,j+1) +mu(i,j))*g_H2(i,k,j+1) +(g_mu(i,j+1) +g_mu(i,j))*H2(i,k,j+1)
4972 Tmpv4 =(mu(i,j+1) +mu(i,j))*H2(i,k,j+1)
4974 g_Tmpv5 =(mu(i,j-1) +mu(i,j))*g_H2(i,k,j) +(g_mu(i,j-1) +g_mu(i,j))*H2(i,k,j)
4975 Tmpv5 =(mu(i,j-1) +mu(i,j))*H2(i,k,j)
4977 ! Revised by Ning Pan, 2010-08-10
4978 ! g_Tmpv6 =mrdy*0.5*(g_Tmpv4 -g_Tmpv5) +g_mrdy*0.5*(Tmpv4 -Tmpv5)
4979 g_Tmpv6 =mrdy*0.5*(g_Tmpv4 -g_Tmpv5)
4980 Tmpv6 =mrdy*0.5*(Tmpv4 -Tmpv5)
4982 g_Tmpv7 =msfty(i,j)*mu(i,j)*(g_H1avg(i,k+1,j) -g_H1avg(i,k,j) &
4983 +g_H2avg(i,k+1,j) -g_H2avg(i,k,j)) +msfty(i,j)*g_mu(i,j)*(H1avg(i,k+1,j) &
4984 -H1avg(i,k,j) +H2avg(i,k+1,j) -H2avg(i,k,j))
4985 Tmpv7 =msfty(i,j)*mu(i,j)*(H1avg(i,k+1,j) -H1avg(i,k,j) +H2avg(i,k+1,j) -H2avg(i,k,j))
4987 g_Tmpv8 =Tmpv7*g_rdzw(i,k,j) +g_Tmpv7*rdzw(i,k,j)
4988 Tmpv8 =Tmpv7*rdzw(i,k,j)
4990 g_tendency(i,k,j) =g_tendency(i,k,j) -(g_Tmpv3 +g_Tmpv6 -g_Tmpv8)
4991 tendency(i,k,j) =tendency(i,k,j) -(Tmpv3 +Tmpv6 -Tmpv8)
4997 IF( doing_tke ) THEN
5003 g_tendency(i,k,j) =g_tmptendf(i,k,j) +2.*(g_tendency(i,k,j) -g_tmptendf(i,k,j))
5004 tendency(i,k,j) =tmptendf(i,k,j) +2.*(tendency(i,k,j) -tmptendf(i,k,j))
5011 END SUBROUTINE g_horizontal_diffusion_s
5013 SUBROUTINE g_vertical_diffusion_2(ru_tendf,g_ru_tendf,rv_tendf,g_rv_tendf, &
5014 rw_tendf,g_rw_tendf,rt_tendf,g_rt_tendf,tke_tendf,g_tke_tendf,moist_tendf, &
5015 g_moist_tendf,n_moist,chem_tendf,g_chem_tendf,n_chem,scalar_tendf, &
5016 g_scalar_tendf,n_scalar,tracer_tendf,g_tracer_tendf,n_tracer,u_2,g_u_2,v_2, &
5017 g_v_2,thp,g_thp,u_base,v_base,t_base,qv_base,mu,g_mu,tke,g_tke, &
5018 config_flags,defor13,g_defor13,defor23,g_defor23,defor33,g_defor33,nba_mij, &
5019 g_nba_mij,n_nba_mij,div,g_div,moist,g_moist,chem,g_chem,scalar, &
5020 g_scalar,tracer,g_tracer,xkmv,g_xkmv,xkhv,g_xkhv,km_opt,fnm,fnp,dn,dnw, &
5021 rdz,g_rdz,rdzw,g_rdzw,hfx,g_hfx,qfx,g_qfx,ust,g_ust,rho,g_rho,ids, &
5022 ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
5026 REAL :: Tmpv1,g_Tmpv1,Tmpv2,g_Tmpv2,Tmpv3,g_Tmpv3
5029 TYPE(grid_config_rec_type) :: config_flags
5030 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
5031 INTEGER :: n_moist,n_chem,n_scalar,n_tracer,km_opt
5032 REAL,DIMENSION(kms:kme) :: fnm
5033 REAL,DIMENSION(kms:kme) :: fnp
5034 REAL,DIMENSION(kms:kme) :: dnw
5035 REAL,DIMENSION(kms:kme) :: dn
5036 REAL,DIMENSION(ims:ime,jms:jme) :: mu,g_mu
5037 REAL,DIMENSION(kms:kme) :: qv_base
5038 REAL,DIMENSION(kms:kme) :: u_base
5039 REAL,DIMENSION(kms:kme) :: v_base
5040 REAL,DIMENSION(kms:kme) :: t_base
5041 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: ru_tendf,g_ru_tendf,rv_tendf, &
5042 g_rv_tendf,rw_tendf,g_rw_tendf,tke_tendf,g_tke_tendf,rt_tendf,g_rt_tendf
5043 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_moist) :: moist_tendf,g_moist_tendf
5044 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_chem) :: chem_tendf,g_chem_tendf
5045 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_scalar) :: scalar_tendf,g_scalar_tendf
5046 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_tracer) :: tracer_tendf,g_tracer_tendf
5047 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_moist) :: moist,g_moist
5048 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_chem) :: chem,g_chem
5049 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_scalar) :: scalar,g_scalar
5050 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_tracer) :: tracer,g_tracer
5051 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor13,g_defor13,defor23,g_defor23, &
5052 defor33,g_defor33,div,g_div,xkmv,g_xkmv,xkhv,g_xkhv,tke,g_tke,rdz, &
5053 g_rdz,u_2,g_u_2,v_2,g_v_2,rdzw,g_rdzw
5055 INTEGER :: n_nba_mij
5057 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_nba_mij) :: nba_mij,g_nba_mij
5058 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: rho,g_rho
5059 REAL,DIMENSION(ims:ime,jms:jme) :: hfx,g_hfx,qfx,g_qfx
5060 REAL,DIMENSION(ims:ime,jms:jme) :: ust,g_ust
5061 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: thp,g_thp
5062 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: var_mix,g_var_mix
5064 INTEGER :: i_start,i_end,j_start,j_end
5065 REAL :: V0_u,g_V0_u,V0_v,g_V0_v,tao_xz,g_tao_xz,tao_yz,g_tao_yz,ustar, &
5067 REAL :: xsfc,g_xsfc,psi1,g_psi1,vk2,g_vk2,zrough,g_zrough,lnz,g_lnz
5068 REAL :: heat_flux,g_heat_flux,moist_flux,g_moist_flux,heat_flux0,g_heat_flux0
5073 i_end =min(ite,ide-1)
5077 j_end =min(jte,jde-1)
5079 CALL g_vertical_diffusion_u_2(ru_tendf,g_ru_tendf,config_flags,mu,g_mu, &
5080 defor13,g_defor13,xkmv,g_xkmv,nba_mij,g_nba_mij,n_nba_mij,dnw,rdzw, &
5081 g_rdzw,fnm,fnp,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
5083 CALL g_vertical_diffusion_v_2(rv_tendf,g_rv_tendf,config_flags,mu,g_mu, &
5084 defor23,g_defor23,xkmv,g_xkmv,nba_mij,g_nba_mij,n_nba_mij,dnw,rdzw, &
5085 g_rdzw,fnm,fnp,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
5087 CALL g_vertical_diffusion_w_2(rw_tendf,g_rw_tendf,config_flags,mu,g_mu, &
5088 defor33,g_defor33,tke(ims,kms,jms),g_tke(ims,kms,jms),nba_mij,g_nba_mij, &
5089 n_nba_mij,div,g_div,xkmv,g_xkmv,dn,rdz,g_rdz,ids,ide,jds,jde,kds,kde,ims, &
5090 ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
5092 ! Added by Ning Pan, 2010-08-11
5093 tl_vflux: SELECT CASE( config_flags%isfflx )
5096 ! Remarked by Ning Pan, 2010-08-09
5097 ! g_cd0 =g_config_flags%tke_drag_coefficient
5098 cd0 =config_flags%tke_drag_coefficient
5109 g_V0_u =g_Sqrt((2.0*g_u_2(i,kts,j)*u_2(i,kts,j)) +(2.0*((g_v_2(i,kts,j) &
5110 +g_v_2(i,kts,j+1) +g_v_2(i-1,kts,j) +g_v_2(i-1,kts,j+1))/4)*((v_2(i,kts,j) &
5111 +v_2(i,kts,j+1) +v_2(i-1,kts,j) +v_2(i-1,kts,j+1))/4)), (u_2(i,kts,j)**2) &
5112 +(((v_2(i,kts,j) +v_2(i,kts,j+1) +v_2(i-1,kts,j) +v_2(i-1,kts,j+1))/4)**2))
5113 V0_u =sqrt((u_2(i,kts,j)**2) +(((v_2(i,kts,j) +v_2(i,kts,j+1) +v_2(i-1,kts,j) &
5114 +v_2(i-1,kts,j+1))/4)**2)) +epsilon
5116 ! Revised by Ning Pan, 2010-08-11
5117 ! g_Tmpv1 =cd0*g_V0_u +g_cd0*V0_u
5121 g_Tmpv2 =Tmpv1*g_u_2(i,kts,j) +g_Tmpv1*u_2(i,kts,j)
5122 Tmpv2 =Tmpv1*u_2(i,kts,j)
5127 g_Tmpv1 =0.25*(mu(i,j) +mu(i-1,j))*g_tao_xz +0.25*(g_mu(i,j) +g_mu(i-1,j))*tao_xz
5128 Tmpv1 =0.25*(mu(i,j) +mu(i-1,j))*tao_xz
5130 g_Tmpv2 =Tmpv1*(g_rdzw(i,kts,j) +g_rdzw(i-1,kts,j)) +g_Tmpv1*(rdzw(i, &
5131 kts,j) +rdzw(i-1,kts,j))
5132 Tmpv2 =Tmpv1*(rdzw(i,kts,j) +rdzw(i-1,kts,j))
5134 g_ru_tendf(i,kts,j) =g_ru_tendf(i,kts,j) -g_Tmpv2
5135 ru_tendf(i,kts,j) =ru_tendf(i,kts,j) -Tmpv2
5137 IF ( (config_flags%m_opt .EQ. 1) .OR. (config_flags%sfs_opt .GT. 0) ) THEN
5138 g_nba_mij(i,kts,j,P_m13) = -g_tao_xz
5139 nba_mij(i,kts,j,P_m13) = -tao_xz
5154 g_V0_v =g_Sqrt((2.0*g_v_2(i,kts,j)*v_2(i,kts,j)) +(2.0*((g_u_2(i,kts,j) &
5155 +g_u_2(i,kts,j-1) +g_u_2(i+1,kts,j) +g_u_2(i+1,kts,j-1))/4)*((u_2(i,kts,j) &
5156 +u_2(i,kts,j-1) +u_2(i+1,kts,j) +u_2(i+1,kts,j-1))/4)), (v_2(i,kts,j)**2) &
5157 +(((u_2(i,kts,j) +u_2(i,kts,j-1) +u_2(i+1,kts,j) +u_2(i+1,kts,j-1))/4)**2))
5158 V0_v =sqrt((v_2(i,kts,j)**2) +(((u_2(i,kts,j) +u_2(i,kts,j-1) +u_2(i+1,kts,j) &
5159 +u_2(i+1,kts,j-1))/4)**2)) +epsilon
5161 ! Revised by Ning Pan, 2010-08-11
5162 ! g_Tmpv1 =cd0*g_V0_v +g_cd0*V0_v
5166 g_Tmpv2 =Tmpv1*g_v_2(i,kts,j) +g_Tmpv1*v_2(i,kts,j)
5167 Tmpv2 =Tmpv1*v_2(i,kts,j)
5172 g_Tmpv1 =0.25*(mu(i,j) +mu(i,j-1))*g_tao_yz +0.25*(g_mu(i,j) +g_mu(i,j-1))*tao_yz
5173 Tmpv1 =0.25*(mu(i,j) +mu(i,j-1))*tao_yz
5175 g_Tmpv2 =Tmpv1*(g_rdzw(i,kts,j) +g_rdzw(i,kts,j-1)) +g_Tmpv1*(rdzw(i, &
5176 kts,j) +rdzw(i,kts,j-1))
5177 Tmpv2 =Tmpv1*(rdzw(i,kts,j) +rdzw(i,kts,j-1))
5179 g_rv_tendf(i,kts,j) =g_rv_tendf(i,kts,j) -g_Tmpv2
5180 rv_tendf(i,kts,j) =rv_tendf(i,kts,j) -Tmpv2
5182 IF ( (config_flags%m_opt .EQ. 1) .OR. (config_flags%sfs_opt .GT. 0) ) THEN
5183 g_nba_mij(i,kts,j,P_m23) = -g_tao_yz
5184 nba_mij(i,kts,j,P_m23) = -tao_yz
5190 CASE (1,2) ! Added by Ning Pan, 2010-08-11
5201 g_V0_u =g_Sqrt((2.0*g_u_2(i,kts,j)*u_2(i,kts,j)) +(2.0*((g_v_2(i,kts,j) &
5202 +g_v_2(i,kts,j+1) +g_v_2(i-1,kts,j) +g_v_2(i-1,kts,j+1))/4)*((v_2(i,kts,j) &
5203 +v_2(i,kts,j+1) +v_2(i-1,kts,j) +v_2(i-1,kts,j+1))/4)), (u_2(i,kts,j)**2) &
5204 +(((v_2(i,kts,j) +v_2(i,kts,j+1) +v_2(i-1,kts,j) +v_2(i-1,kts,j+1))/4)**2))
5205 V0_u =sqrt((u_2(i,kts,j)**2) +(((v_2(i,kts,j) +v_2(i,kts,j+1) +v_2(i-1,kts,j) &
5206 +v_2(i-1,kts,j+1))/4)**2)) +epsilon
5208 g_ustar =0.5*(g_ust(i,j) +g_ust(i-1,j))
5209 ustar =0.5*(ust(i,j) +ust(i-1,j))
5211 g_Tmpv1 =2.0*ustar*g_ustar
5214 g_Tmpv2 =Tmpv1*g_u_2(i,kts,j) +g_Tmpv1*u_2(i,kts,j)
5215 Tmpv2 =Tmpv1*u_2(i,kts,j)
5217 g_Tmpv3 =(g_Tmpv2*V0_u -g_V0_u*Tmpv2)/(V0_u*V0_u)
5223 g_Tmpv1 =0.25*(mu(i,j) +mu(i-1,j))*g_tao_xz +0.25*(g_mu(i,j) +g_mu(i-1,j))*tao_xz
5224 Tmpv1 =0.25*(mu(i,j) +mu(i-1,j))*tao_xz
5226 g_Tmpv2 =Tmpv1*(g_rdzw(i,kts,j) +g_rdzw(i-1,kts,j)) +g_Tmpv1*(rdzw(i, &
5227 kts,j) +rdzw(i-1,kts,j))
5228 Tmpv2 =Tmpv1*(rdzw(i,kts,j) +rdzw(i-1,kts,j))
5230 g_ru_tendf(i,kts,j) =g_ru_tendf(i,kts,j) -g_Tmpv2
5231 ru_tendf(i,kts,j) =ru_tendf(i,kts,j) -Tmpv2
5233 IF ( (config_flags%m_opt .EQ. 1) .OR. (config_flags%sfs_opt .GT. 0) ) THEN
5234 g_nba_mij(i,kts,j,P_m13) = -g_tao_xz
5235 nba_mij(i,kts,j,P_m13) = -tao_xz
5250 g_V0_v =g_Sqrt((2.0*g_v_2(i,kts,j)*v_2(i,kts,j)) +(2.0*((g_u_2(i,kts,j) &
5251 +g_u_2(i,kts,j-1) +g_u_2(i+1,kts,j) +g_u_2(i+1,kts,j-1))/4)*((u_2(i,kts,j) &
5252 +u_2(i,kts,j-1) +u_2(i+1,kts,j) +u_2(i+1,kts,j-1))/4)), (v_2(i,kts,j)**2) &
5253 +(((u_2(i,kts,j) +u_2(i,kts,j-1) +u_2(i+1,kts,j) +u_2(i+1,kts,j-1))/4)**2))
5254 V0_v =sqrt((v_2(i,kts,j)**2) +(((u_2(i,kts,j) +u_2(i,kts,j-1) +u_2(i+1,kts,j) &
5255 +u_2(i+1,kts,j-1))/4)**2)) +epsilon
5257 g_ustar =0.5*(g_ust(i,j) +g_ust(i,j-1))
5258 ustar =0.5*(ust(i,j) +ust(i,j-1))
5260 g_Tmpv1 =2.0*ustar*g_ustar
5263 g_Tmpv2 =Tmpv1*g_v_2(i,kts,j) +g_Tmpv1*v_2(i,kts,j)
5264 Tmpv2 =Tmpv1*v_2(i,kts,j)
5266 g_Tmpv3 =(g_Tmpv2*V0_v -g_V0_v*Tmpv2)/(V0_v*V0_v)
5272 g_Tmpv1 =0.25*(mu(i,j) +mu(i,j-1))*g_tao_yz +0.25*(g_mu(i,j) +g_mu(i,j-1))*tao_yz
5273 Tmpv1 =0.25*(mu(i,j) +mu(i,j-1))*tao_yz
5275 g_Tmpv2 =Tmpv1*(g_rdzw(i,kts,j) +g_rdzw(i,kts,j-1)) +g_Tmpv1*(rdzw(i, &
5276 kts,j) +rdzw(i,kts,j-1))
5277 Tmpv2 =Tmpv1*(rdzw(i,kts,j) +rdzw(i,kts,j-1))
5279 g_rv_tendf(i,kts,j) =g_rv_tendf(i,kts,j) -g_Tmpv2
5280 rv_tendf(i,kts,j) =rv_tendf(i,kts,j) -Tmpv2
5282 IF ( (config_flags%m_opt .EQ. 1) .OR. (config_flags%sfs_opt .GT. 0) ) THEN
5283 g_nba_mij(i,kts,j,P_m23) = -g_tao_yz
5284 nba_mij(i,kts,j,P_m23) = -tao_yz
5290 CASE DEFAULT ! Added by Ning Pan, 2010-08-11
5292 ! Revised by Ning Pan, 2010-08-10
5293 ! CALL g_wrf_error_fatal('isfflx value invalid for diff_opt=2')
5294 CALL wrf_error_fatal('isfflx value invalid for diff_opt=2')
5296 END SELECT tl_vflux ! Added by Ning Pan, 2010-08-11
5298 IF( config_flags%mix_full_fields ) THEN
5300 DO j =jts,min(jte,jde-1)
5302 DO i =its,min(ite,ide-1)
5304 g_var_mix(i,k,j) =g_thp(i,k,j)
5305 var_mix(i,k,j) =thp(i,k,j)
5312 DO j =jts,min(jte,jde-1)
5314 DO i =its,min(ite,ide-1)
5316 g_var_mix(i,k,j) =g_thp(i,k,j)
5317 var_mix(i,k,j) =thp(i,k,j) -t_base(k)
5324 CALL g_vertical_diffusion_s(rt_tendf,g_rt_tendf,config_flags,var_mix, &
5325 g_var_mix,mu,g_mu,xkhv,g_xkhv,dn,dnw,rdz,g_rdz,rdzw,g_rdzw,fnm,fnp, &
5326 .false.,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
5328 ! Added by Ning Pan, 2010-08-11
5329 tl_hflux: SELECT CASE( config_flags%isfflx )
5332 ! Remarked by Ning Pan, 2010-08-09
5333 ! g_heat_flux =g_config_flags%tke_heat_flux
5334 heat_flux =config_flags%tke_heat_flux
5339 g_cpm =cp*(0.8*g_moist(i,kts,j,P_QV))
5340 cpm =cp*(1. +0.8*moist(i,kts,j,P_QV))
5342 g_hfx(i,j)= heat_flux*cpm*g_rho(i,1,j) + heat_flux*g_cpm*rho(i,1,j)
5344 ! Revised by Ning Pan, 2010-08-11
5345 ! g_Tmpv1 =mu(i,j)*g_heat_flux +g_mu(i,j)*heat_flux
5346 g_Tmpv1 =g_mu(i,j)*heat_flux
5347 Tmpv1 =mu(i,j)*heat_flux
5349 g_Tmpv2 =Tmpv1*g_rdzw(i,kts,j) +g_Tmpv1*rdzw(i,kts,j)
5350 Tmpv2 =Tmpv1*rdzw(i,kts,j)
5352 g_rt_tendf(i,kts,j) =g_rt_tendf(i,kts,j) +g_Tmpv2
5353 rt_tendf(i,kts,j) =rt_tendf(i,kts,j) +Tmpv2
5358 CASE (1) ! Added by Ning Pan, 2010-08-11
5363 g_cpm =cp*(0.8*g_moist(i,kts,j,P_QV))
5364 cpm =cp*(1. +0.8*moist(i,kts,j,P_QV))
5366 g_Tmpv1 =(g_hfx(i,j)*cpm -g_cpm*hfx(i,j))/(cpm*cpm)
5369 g_Tmpv2 =(g_Tmpv1*rho(i,1,j) -g_rho(i,1,j)*Tmpv1)/(rho(i,1,j)*rho(i,1,j))
5370 Tmpv2 =Tmpv1/rho(i,1,j)
5372 g_heat_flux =g_Tmpv2
5375 g_Tmpv1 =mu(i,j)*g_heat_flux +g_mu(i,j)*heat_flux
5376 Tmpv1 =mu(i,j)*heat_flux
5378 g_Tmpv2 =Tmpv1*g_rdzw(i,kts,j) +g_Tmpv1*rdzw(i,kts,j)
5379 Tmpv2 =Tmpv1*rdzw(i,kts,j)
5381 g_rt_tendf(i,kts,j) =g_rt_tendf(i,kts,j) +g_Tmpv2
5382 rt_tendf(i,kts,j) =rt_tendf(i,kts,j) +Tmpv2
5387 CASE DEFAULT ! Added by Ning Pan, 2010-08-11
5389 ! Revised by Ning Pan, 2010-08-10
5390 ! CALL g_wrf_error_fatal('isfflx value invalid for diff_opt=2')
5391 CALL wrf_error_fatal('isfflx value invalid for diff_opt=2')
5393 END SELECT tl_hflux ! Added by Ning Pan, 2010-08-11
5395 IF(km_opt .eq. 2) THEN
5397 CALL g_vertical_diffusion_s(tke_tendf(ims,kms,jms),g_tke_tendf(ims,kms,jms) &
5398 ,config_flags,tke(ims,kms,jms),g_tke(ims,kms,jms),mu,g_mu,xkhv,g_xkhv,dn, &
5399 dnw,rdz,g_rdz,rdzw,g_rdzw,fnm,fnp,.true.,ids,ide,jds,jde,kds,kde,ims,ime,jms, &
5400 jme,kms,kme,its,ite,jts,jte,kts,kte)
5403 IF(n_moist .ge. PARAM_FIRST_SCALAR) THEN
5405 DO im =PARAM_FIRST_SCALAR,n_moist
5407 IF( (.not. config_flags%mix_full_fields) .and. (im == P_QV) ) THEN
5409 DO j =jts,min(jte,jde-1)
5411 DO i =its,min(ite,ide-1)
5413 g_var_mix(i,k,j) =g_moist(i,k,j,im)
5414 var_mix(i,k,j) =moist(i,k,j,im) -qv_base(k)
5421 DO j =jts,min(jte,jde-1)
5423 DO i =its,min(ite,ide-1)
5425 g_var_mix(i,k,j) =g_moist(i,k,j,im)
5426 var_mix(i,k,j) =moist(i,k,j,im)
5433 CALL g_vertical_diffusion_s(moist_tendf(ims,kms,jms,im),g_moist_tendf(ims,kms, &
5434 jms,im),config_flags,var_mix,g_var_mix,mu,g_mu,xkhv,g_xkhv,dn,dnw,rdz, &
5435 g_rdz,rdzw,g_rdzw,fnm,fnp,.false.,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms, &
5436 kme,its,ite,jts,jte,kts,kte)
5438 ! Added by Ning Pan, 2010-08-11
5439 tl_qflux: SELECT CASE( config_flags%isfflx )
5443 IF( im == P_QV ) THEN
5448 g_Tmpv1 =(g_qfx(i,j)*rho(i,1,j) -g_rho(i,1,j)*qfx(i,j))/(rho(i,1,j)*rho(i,1,j))
5449 Tmpv1 =qfx(i,j)/rho(i,1,j)
5451 g_Tmpv2 =(g_Tmpv1*(1. +moist(i,kts,j,P_QV)) -(g_moist(i,kts,j,P_QV))*Tmpv1) &
5452 /((1. +moist(i,kts,j,P_QV))*(1. +moist(i,kts,j,P_QV)))
5453 Tmpv2 =Tmpv1/(1. +moist(i,kts,j,P_QV))
5455 g_moist_flux =g_Tmpv2
5458 g_Tmpv1 =mu(i,j)*g_moist_flux +g_mu(i,j)*moist_flux
5459 Tmpv1 =mu(i,j)*moist_flux
5461 g_Tmpv2 =Tmpv1*g_rdzw(i,kts,j) +g_Tmpv1*rdzw(i,kts,j)
5462 Tmpv2 =Tmpv1*rdzw(i,kts,j)
5464 g_moist_tendf(i,kts,j,im) =g_moist_tendf(i,kts,j,im) +g_Tmpv2
5465 moist_tendf(i,kts,j,im) =moist_tendf(i,kts,j,im) +Tmpv2
5471 CASE DEFAULT ! Added by Ning Pan, 2010-08-11
5473 ! Revised by Ning Pan, 2010-08-10
5474 ! CALL g_wrf_error_fatal('isfflx value invalid for diff_opt=2')
5475 CALL wrf_error_fatal('isfflx value invalid for diff_opt=2')
5477 END SELECT tl_qflux ! Added by Ning Pan, 2010-08-11
5482 IF(n_chem .ge. PARAM_FIRST_SCALAR) THEN
5484 DO im =PARAM_FIRST_SCALAR,n_chem
5485 CALL g_vertical_diffusion_s(chem_tendf(ims,kms,jms,im),g_chem_tendf(ims,kms, &
5486 jms,im),config_flags,chem(ims,kms,jms,im),g_chem(ims,kms,jms,im),mu,g_mu,xkhv, &
5487 g_xkhv,dn,dnw,rdz,g_rdz,rdzw,g_rdzw,fnm,fnp,.false.,ids,ide,jds,jde,kds,kde, &
5488 ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
5492 IF(n_tracer .ge. PARAM_FIRST_SCALAR) THEN
5494 DO im =PARAM_FIRST_SCALAR,n_tracer
5496 CALL g_vertical_diffusion_s(tracer_tendf(ims,kms,jms,im),g_tracer_tendf(ims, &
5497 kms,jms,im),config_flags,tracer(ims,kms,jms,im),g_tracer(ims,kms,jms,im) &
5498 ,mu,g_mu,xkhv,g_xkhv,dn,dnw,rdz,g_rdz,rdzw,g_rdzw,fnm,fnp,.false.,ids, &
5499 ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
5503 IF(n_scalar .ge. PARAM_FIRST_SCALAR) THEN
5505 DO im =PARAM_FIRST_SCALAR,n_scalar
5507 CALL g_vertical_diffusion_s(scalar_tendf(ims,kms,jms,im),g_scalar_tendf(ims, &
5508 kms,jms,im),config_flags,scalar(ims,kms,jms,im),g_scalar(ims,kms,jms,im) &
5509 ,mu,g_mu,xkhv,g_xkhv,dn,dnw,rdz,g_rdz,rdzw,g_rdzw,fnm,fnp,.false.,ids, &
5510 ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
5514 END SUBROUTINE g_vertical_diffusion_2
5516 SUBROUTINE g_vertical_diffusion_u_2(tendency,g_tendency,config_flags,mu, &
5517 g_mu,defor13,g_defor13,xkmv,g_xkmv,nba_mij,g_nba_mij,n_nba_mij,dnw,rdzw, &
5518 g_rdzw,fnm,fnp,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
5522 REAL :: Tmpv1,g_Tmpv1
5523 TYPE(grid_config_rec_type) :: config_flags
5524 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
5525 REAL,DIMENSION(kms:kme) :: fnm
5526 REAL,DIMENSION(kms:kme) :: fnp
5527 REAL,DIMENSION(kms:kme) :: dnw
5528 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tendency,g_tendency
5529 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor13,g_defor13,xkmv,g_xkmv,rdzw,g_rdzw
5531 INTEGER :: n_nba_mij
5533 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_nba_mij) :: nba_mij,g_nba_mij
5534 REAL,DIMENSION(ims:ime,jms:jme) :: mu,g_mu
5535 INTEGER :: i,j,k,ktf
5536 INTEGER :: i_start,i_end,j_start,j_end
5537 INTEGER :: is_ext,ie_ext,js_ext,je_ext
5538 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: titau3,g_titau3
5539 REAL,DIMENSION(its:ite,jts:jte) :: zzavg,g_zzavg
5550 j_end =min(jte,jde-1)
5552 IF( config_flags%open_xs .or. config_flags%specified .or. &
5553 config_flags%nested) i_start =max(ids+1,its)
5555 IF( config_flags%open_xe .or. config_flags%specified .or. &
5556 config_flags%nested) i_end =min(ide-1,ite)
5558 IF( config_flags%open_ys .or. config_flags%specified .or. &
5559 config_flags%nested) j_start =max(jds+1,jts)
5561 IF( config_flags%open_ye .or. config_flags%specified .or. &
5562 config_flags%nested) j_end =min(jde-2,jte)
5564 IF( config_flags%periodic_x ) i_start =its
5566 IF( config_flags%periodic_x ) i_end =ite
5576 CALL g_cal_titau_13_31(config_flags,titau3,g_titau3,defor13,g_defor13, &
5577 nba_mij(ims,kms,jms,P_m13),g_nba_mij(ims,kms,jms,P_m13),mu,g_mu,xkmv,g_xkmv, &
5578 fnm,fnp,is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme, &
5579 its,ite,jts,jte,kts,kte)
5585 g_rdzu =-2.*(-1.*g_rdzw(i,k,j)/(rdzw(i,k,j)*rdzw(i,k,j)) +(-1.*g_rdzw(i-1,k, &
5586 j)/(rdzw(i-1,k,j)*rdzw(i-1,k,j))))/((1./rdzw(i,k,j) +1./rdzw(i-1,k,j))*(1./rdzw(i,k, &
5587 j) +1./rdzw(i-1,k,j)))
5588 rdzu =2./(1./rdzw(i,k,j) +1./rdzw(i-1,k,j))
5590 g_Tmpv1 =rdzu*(g_titau3(i,k+1,j) -g_titau3(i,k,j)) +g_rdzu*(titau3(i,k+ &
5591 1,j) -titau3(i,k,j))
5592 Tmpv1 =rdzu*(titau3(i,k+1,j) -titau3(i,k,j))
5594 g_tendency(i,k,j) =g_tendency(i,k,j) -g_Tmpv1
5595 tendency(i,k,j) =tendency(i,k,j) -Tmpv1
5607 g_rdzu =-2.*(-1.*g_rdzw(i,k,j)/(rdzw(i,k,j)*rdzw(i,k,j)) +(-1.*g_rdzw(i-1,k, &
5608 j)/(rdzw(i-1,k,j)*rdzw(i-1,k,j))))/((1./rdzw(i,k,j) +1./rdzw(i-1,k,j))*(1./rdzw(i,k, &
5609 j) +1./rdzw(i-1,k,j)))
5610 rdzu =2./(1./rdzw(i,k,j) +1./rdzw(i-1,k,j))
5612 g_Tmpv1 =rdzu*(g_titau3(i,k+1,j)) +g_rdzu*(titau3(i,k+1,j))
5613 Tmpv1 =rdzu*(titau3(i,k+1,j))
5615 g_tendency(i,k,j) =g_tendency(i,k,j) -g_Tmpv1
5616 tendency(i,k,j) =tendency(i,k,j) -Tmpv1
5621 END SUBROUTINE g_vertical_diffusion_u_2
5623 SUBROUTINE g_vertical_diffusion_v_2(tendency,g_tendency,config_flags,mu, &
5624 g_mu,defor23,g_defor23,xkmv,g_xkmv,nba_mij,g_nba_mij,n_nba_mij,dnw,rdzw, &
5625 g_rdzw,fnm,fnp,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
5629 REAL :: Tmpv1,g_Tmpv1
5630 TYPE(grid_config_rec_type) :: config_flags
5631 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
5632 REAL,DIMENSION(kms:kme) :: fnm
5633 REAL,DIMENSION(kms:kme) :: fnp
5634 REAL,DIMENSION(kms:kme) :: dnw
5635 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tendency,g_tendency
5636 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor23,g_defor23,xkmv,g_xkmv,rdzw,g_rdzw
5638 INTEGER :: n_nba_mij
5640 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_nba_mij) :: nba_mij,g_nba_mij
5641 REAL,DIMENSION(ims:ime,jms:jme) :: mu,g_mu
5642 INTEGER :: i,j,k,ktf
5643 INTEGER :: i_start,i_end,j_start,j_end
5644 INTEGER :: is_ext,ie_ext,js_ext,je_ext
5645 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: titau3,g_titau3
5646 REAL,DIMENSION(its:ite,jts:jte) :: zzavg,g_zzavg
5653 i_end =min(ite,ide-1)
5659 IF( config_flags%open_xs .or. config_flags%specified .or. &
5660 config_flags%nested) i_start =max(ids+1,its)
5662 IF( config_flags%open_xe .or. config_flags%specified .or. &
5663 config_flags%nested) i_end =min(ide-2,ite)
5665 IF( config_flags%open_ys .or. config_flags%specified .or. &
5666 config_flags%nested) j_start =max(jds+1,jts)
5668 IF( config_flags%open_ye .or. config_flags%specified .or. &
5669 config_flags%nested) j_end =min(jde-1,jte)
5671 IF( config_flags%periodic_x ) i_start =its
5673 IF( config_flags%periodic_x ) i_end =min(ite,ide-1)
5683 CALL g_cal_titau_23_32(config_flags,titau3,g_titau3,defor23,g_defor23, &
5684 nba_mij(ims,kms,jms,P_m23),g_nba_mij(ims,kms,jms,P_m23),mu,g_mu,xkmv,g_xkmv, &
5685 fnm,fnp,is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme, &
5686 its,ite,jts,jte,kts,kte)
5692 g_rdzv =-2.*(-1.*g_rdzw(i,k,j)/(rdzw(i,k,j)*rdzw(i,k,j)) +(-1.*g_rdzw(i,k,j- &
5693 1)/(rdzw(i,k,j-1)*rdzw(i,k,j-1))))/((1./rdzw(i,k,j) +1./rdzw(i,k,j-1))*(1./rdzw(i,k, &
5694 j) +1./rdzw(i,k,j-1)))
5695 rdzv =2./(1./rdzw(i,k,j) +1./rdzw(i,k,j-1))
5697 g_Tmpv1 =rdzv*(g_titau3(i,k+1,j) -g_titau3(i,k,j)) +g_rdzv*(titau3(i,k+ &
5698 1,j) -titau3(i,k,j))
5699 Tmpv1 =rdzv*(titau3(i,k+1,j) -titau3(i,k,j))
5701 g_tendency(i,k,j) =g_tendency(i,k,j) -g_Tmpv1
5702 tendency(i,k,j) =tendency(i,k,j) -Tmpv1
5714 g_rdzv =-2.*(-1.*g_rdzw(i,k,j)/(rdzw(i,k,j)*rdzw(i,k,j)) +(-1.*g_rdzw(i,k,j- &
5715 1)/(rdzw(i,k,j-1)*rdzw(i,k,j-1))))/((1./rdzw(i,k,j) +1./rdzw(i,k,j-1))*(1./rdzw(i,k, &
5716 j) +1./rdzw(i,k,j-1)))
5717 rdzv =2./(1./rdzw(i,k,j) +1./rdzw(i,k,j-1))
5719 g_Tmpv1 =rdzv*(g_titau3(i,k+1,j)) +g_rdzv*(titau3(i,k+1,j))
5720 Tmpv1 =rdzv*(titau3(i,k+1,j))
5722 g_tendency(i,k,j) =g_tendency(i,k,j) -g_Tmpv1
5723 tendency(i,k,j) =tendency(i,k,j) -Tmpv1
5728 END SUBROUTINE g_vertical_diffusion_v_2
5730 SUBROUTINE g_vertical_diffusion_w_2(tendency,g_tendency,config_flags,mu, &
5731 g_mu,defor33,g_defor33,tke,g_tke,nba_mij,g_nba_mij,n_nba_mij,div, &
5732 g_div,xkmv,g_xkmv,dn,rdz,g_rdz,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms, &
5733 kme,its,ite,jts,jte,kts,kte)
5737 REAL :: Tmpv1,g_Tmpv1
5738 TYPE(grid_config_rec_type) :: config_flags
5739 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
5740 REAL,DIMENSION(kms:kme) :: dn
5741 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tendency,g_tendency
5742 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor33,g_defor33,tke,g_tke,div, &
5743 g_div,xkmv,g_xkmv,rdz,g_rdz
5745 INTEGER :: n_nba_mij
5747 REAL,DIMENSION(ims:ime,kms:kme,jms:jme,n_nba_mij) :: nba_mij,g_nba_mij
5748 REAL,DIMENSION(ims:ime,jms:jme) :: mu,g_mu
5749 INTEGER :: i,j,k,ktf
5750 INTEGER :: i_start,i_end,j_start,j_end
5751 INTEGER :: is_ext,ie_ext,js_ext,je_ext
5752 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: titau3,g_titau3
5758 i_end =min(ite,ide-1)
5762 j_end =min(jte,jde-1)
5764 IF( config_flags%open_xs .or. config_flags%specified .or. &
5765 config_flags%nested) i_start =max(ids+1,its)
5767 IF( config_flags%open_xe .or. config_flags%specified .or. &
5768 config_flags%nested) i_end =min(ide-2,ite)
5770 IF( config_flags%open_ys .or. config_flags%specified .or. &
5771 config_flags%nested) j_start =max(jds+1,jts)
5773 IF( config_flags%open_ye .or. config_flags%specified .or. &
5774 config_flags%nested) j_end =min(jde-2,jte)
5776 IF( config_flags%periodic_x ) i_start =its
5778 IF( config_flags%periodic_x ) i_end =min(ite,ide-1)
5788 CALL g_cal_titau_11_22_33(config_flags,titau3,g_titau3,mu,g_mu,tke,g_tke, &
5789 xkmv,g_xkmv,defor33,g_defor33,nba_mij(ims,kms,jms,P_m33),g_nba_mij(ims,kms, &
5790 jms,P_m33),is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms, &
5791 kme,its,ite,jts,jte,kts,kte)
5797 g_Tmpv1 =rdz(i,k,j)*(g_titau3(i,k,j) -g_titau3(i,k-1,j)) +g_rdz(i,k,j) &
5798 *(titau3(i,k,j) -titau3(i,k-1,j))
5799 Tmpv1 =rdz(i,k,j)*(titau3(i,k,j) -titau3(i,k-1,j))
5801 g_tendency(i,k,j) =g_tendency(i,k,j) -g_Tmpv1
5802 tendency(i,k,j) =tendency(i,k,j) -Tmpv1
5808 END SUBROUTINE g_vertical_diffusion_w_2
5810 SUBROUTINE g_vertical_diffusion_s(tendency,g_tendency,config_flags,var, &
5811 g_var,mu,g_mu,xkhv,g_xkhv,dn,dnw,rdz,g_rdz,rdzw,g_rdzw,fnm,fnp, &
5812 doing_tke,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
5816 REAL :: Tmpv1,g_Tmpv1,Tmpv2,g_Tmpv2
5817 TYPE(grid_config_rec_type) :: config_flags
5818 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
5819 LOGICAL :: doing_tke
5820 REAL,DIMENSION(kms:kme) :: fnm
5821 REAL,DIMENSION(kms:kme) :: fnp
5822 REAL,DIMENSION(kms:kme) :: dn
5823 REAL,DIMENSION(kms:kme) :: dnw
5824 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tendency,g_tendency
5825 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: xkhv,g_xkhv
5826 REAL,DIMENSION(ims:ime,jms:jme) :: mu,g_mu
5827 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: var,g_var,rdz,g_rdz,rdzw,g_rdzw
5828 INTEGER :: i,j,k,ktf
5829 INTEGER :: i_start,i_end,j_start,j_end
5830 REAL,DIMENSION(its:ite,kts:kte,jts:jte) :: H3,g_H3,xkxavg,g_xkxavg,rravg,g_rravg
5831 REAL,DIMENSION(its:ite,kts:kte,jts:jte) :: tmptendf,g_tmptendf
5837 i_end =min(ite,ide-1)
5841 j_end =min(jte,jde-1)
5843 IF( config_flags%open_xs .or. config_flags%specified .or. &
5844 config_flags%nested) i_start =max(ids+1,its)
5846 IF( config_flags%open_xe .or. config_flags%specified .or. &
5847 config_flags%nested) i_end =min(ide-2,ite)
5849 IF( config_flags%open_ys .or. config_flags%specified .or. &
5850 config_flags%nested) j_start =max(jds+1,jts)
5852 IF( config_flags%open_ye .or. config_flags%specified .or. &
5853 config_flags%nested) j_end =min(jde-2,jte)
5855 IF( config_flags%periodic_x ) i_start =its
5857 IF( config_flags%periodic_x ) i_end =min(ite,ide-1)
5865 g_tmptendf(i,k,j) =g_tendency(i,k,j)
5866 tmptendf(i,k,j) =tendency(i,k,j)
5880 g_xkxavg(i,k,j) =fnm(k)*g_xkhv(i,k,j) +fnp(k)*g_xkhv(i,k-1,j)
5881 xkxavg(i,k,j) =fnm(k)*xkhv(i,k,j) +fnp(k)*xkhv(i,k-1,j)
5883 g_Tmpv1 =-xkxavg(i,k,j)*(g_var(i,k,j) -g_var(i,k-1,j)) -g_xkxavg(i,k,j) &
5884 *(var(i,k,j) -var(i,k-1,j))
5885 Tmpv1 =-xkxavg(i,k,j)*(var(i,k,j) -var(i,k-1,j))
5887 g_Tmpv2 =Tmpv1*g_rdz(i,k,j) +g_Tmpv1*rdz(i,k,j)
5888 Tmpv2 =Tmpv1*rdz(i,k,j)
5890 g_H3(i,k,j) =g_Tmpv2
5903 g_H3(i,ktf+1,j) =0.0
5913 g_Tmpv1 =mu(i,j)*(g_H3(i,k+1,j) -g_H3(i,k,j)) +g_mu(i,j)*(H3(i,k+1,j) -H3(i,k,j))
5914 Tmpv1 =mu(i,j)*(H3(i,k+1,j) -H3(i,k,j))
5916 g_Tmpv2 =Tmpv1*g_rdzw(i,k,j) +g_Tmpv1*rdzw(i,k,j)
5917 Tmpv2 =Tmpv1*rdzw(i,k,j)
5919 g_tendency(i,k,j) =g_tendency(i,k,j) -g_Tmpv2
5920 tendency(i,k,j) =tendency(i,k,j) -Tmpv2
5932 g_tendency(i,k,j) =g_tmptendf(i,k,j) +2.*(g_tendency(i,k,j) -g_tmptendf(i,k,j))
5933 tendency(i,k,j) =tmptendf(i,k,j) +2.*(tendency(i,k,j) -tmptendf(i,k,j))
5940 END SUBROUTINE g_vertical_diffusion_s
5942 SUBROUTINE g_cal_titau_11_22_33(config_flags,titau,g_titau,mu,g_mu,tke, &
5943 g_tke,xkx,g_xkx,defor,g_defor,mtau,g_mtau,is_ext,ie_ext,js_ext,je_ext, &
5944 ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
5948 REAL :: Tmpv1,g_Tmpv1,Tmpv2,g_Tmpv2
5949 TYPE(grid_config_rec_type) :: config_flags
5950 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
5951 INTEGER :: is_ext,ie_ext,js_ext,je_ext
5952 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: titau,g_titau
5953 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor,g_defor,xkx,g_xkx,tke,g_tke
5955 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: mtau,g_mtau
5956 REAL,DIMENSION(ims:ime,jms:jme) :: mu,g_mu
5957 INTEGER :: i,j,k,ktf,i_start,i_end,j_start,j_end
5969 IF( config_flags%open_xs .OR. config_flags%specified .OR. &
5970 config_flags%nested) i_start =max(ids+1,its)
5972 IF( config_flags%open_xe .OR. config_flags%specified .OR. &
5973 config_flags%nested) i_end =min(ide-1,ite)
5975 IF( config_flags%open_ys .OR. config_flags%specified .OR. &
5976 config_flags%nested) j_start =max(jds+1,jts)
5978 IF( config_flags%open_ye .OR. config_flags%specified .OR. &
5979 config_flags%nested) j_end =min(jde-1,jte)
5981 IF( config_flags%periodic_x ) i_start =its
5983 IF( config_flags%periodic_x ) i_end =ite
5985 i_start =i_start-is_ext
5989 j_start =j_start-js_ext
5993 IF( config_flags%sfs_opt .GT. 0 ) THEN
5999 g_Tmpv1 =mu(i,j)*g_mtau(i,k,j) +g_mu(i,j)*mtau(i,k,j)
6000 Tmpv1 =mu(i,j)*mtau(i,k,j)
6002 g_titau(i,k,j) =g_Tmpv1
6011 IF( config_flags%m_opt .EQ. 1 ) THEN
6017 g_Tmpv1 =-mu(i,j)*g_xkx(i,k,j) -g_mu(i,j)*xkx(i,k,j)
6018 Tmpv1 =-mu(i,j)*xkx(i,k,j)
6020 g_Tmpv2 =Tmpv1*g_defor(i,k,j) +g_Tmpv1*defor(i,k,j)
6021 Tmpv2 =Tmpv1*defor(i,k,j)
6023 g_titau(i,k,j) =g_Tmpv2
6026 g_Tmpv1 =-xkx(i,k,j)*g_defor(i,k,j) -g_xkx(i,k,j)*defor(i,k,j)
6027 Tmpv1 =-xkx(i,k,j)*defor(i,k,j)
6029 g_mtau(i,k,j) =g_Tmpv1
6042 g_Tmpv1 =-mu(i,j)*g_xkx(i,k,j) -g_mu(i,j)*xkx(i,k,j)
6043 Tmpv1 =-mu(i,j)*xkx(i,k,j)
6045 g_Tmpv2 =Tmpv1*g_defor(i,k,j) +g_Tmpv1*defor(i,k,j)
6046 Tmpv2 =Tmpv1*defor(i,k,j)
6048 g_titau(i,k,j) =g_Tmpv2
6057 END SUBROUTINE g_cal_titau_11_22_33
6059 SUBROUTINE g_cal_titau_12_21(config_flags,titau,g_titau,mu,g_mu,xkx, &
6060 g_xkx,defor,g_defor,mtau,g_mtau,is_ext,ie_ext,js_ext,je_ext,ids,ide,jds,jde, &
6061 kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
6065 REAL :: Tmpv1,g_Tmpv1,Tmpv2,g_Tmpv2
6066 TYPE(grid_config_rec_type) :: config_flags
6067 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
6068 INTEGER :: is_ext,ie_ext,js_ext,je_ext
6069 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: titau,g_titau
6070 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor,g_defor,xkx,g_xkx
6072 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: mtau,g_mtau
6073 REAL,DIMENSION(ims:ime,jms:jme) :: mu,g_mu
6074 INTEGER :: i,j,k,ktf,i_start,i_end,j_start,j_end
6075 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: xkxavg,g_xkxavg
6076 REAL,DIMENSION(its-1:ite+1,jts-1:jte+1) :: muavg,g_muavg
6088 IF( config_flags%open_xs .OR. config_flags%specified .OR. &
6089 config_flags%nested ) i_start =max(ids+1,its)
6091 IF( config_flags%open_xe .OR. config_flags%specified .OR. &
6092 config_flags%nested ) i_end =min(ide-1,ite)
6094 IF( config_flags%open_ys .OR. config_flags%specified .OR. &
6095 config_flags%nested ) j_start =max(jds+1,jts)
6097 IF( config_flags%open_ye .OR. config_flags%specified .OR. &
6098 config_flags%nested ) j_end =min(jde-1,jte)
6100 IF( config_flags%periodic_x ) i_start =its
6102 IF( config_flags%periodic_x ) i_end =ite
6104 i_start =i_start-is_ext
6108 j_start =j_start-js_ext
6116 g_xkxavg(i,k,j) =0.25*(g_xkx(i-1,k,j) +g_xkx(i,k,j) +g_xkx(i-1,k,j-1) &
6118 xkxavg(i,k,j) =0.25*(xkx(i-1,k,j) +xkx(i,k,j) +xkx(i-1,k,j-1) +xkx(i,k,j-1))
6127 g_muavg(i,j) =0.25*(g_mu(i-1,j) +g_mu(i,j) +g_mu(i-1,j-1) +g_mu(i,j-1))
6128 muavg(i,j) =0.25*(mu(i-1,j) +mu(i,j) +mu(i-1,j-1) +mu(i,j-1))
6133 IF( config_flags%sfs_opt .GT. 0 ) THEN
6139 g_Tmpv1 =muavg(i,j)*g_mtau(i,k,j) +g_muavg(i,j)*mtau(i,k,j)
6140 Tmpv1 =muavg(i,j)*mtau(i,k,j)
6142 g_titau(i,k,j) =g_Tmpv1
6151 IF( config_flags%m_opt .EQ. 1 ) THEN
6157 g_Tmpv1 =-muavg(i,j)*g_xkxavg(i,k,j) -g_muavg(i,j)*xkxavg(i,k,j)
6158 Tmpv1 =-muavg(i,j)*xkxavg(i,k,j)
6160 g_Tmpv2 =Tmpv1*g_defor(i,k,j) +g_Tmpv1*defor(i,k,j)
6161 Tmpv2 =Tmpv1*defor(i,k,j)
6163 g_titau(i,k,j) =g_Tmpv2
6166 g_Tmpv1 =-xkxavg(i,k,j)*g_defor(i,k,j) -g_xkxavg(i,k,j)*defor(i,k,j)
6167 Tmpv1 =-xkxavg(i,k,j)*defor(i,k,j)
6169 g_mtau(i,k,j) =g_Tmpv1
6182 g_Tmpv1 =-muavg(i,j)*g_xkxavg(i,k,j) -g_muavg(i,j)*xkxavg(i,k,j)
6183 Tmpv1 =-muavg(i,j)*xkxavg(i,k,j)
6185 g_Tmpv2 =Tmpv1*g_defor(i,k,j) +g_Tmpv1*defor(i,k,j)
6186 Tmpv2 =Tmpv1*defor(i,k,j)
6188 g_titau(i,k,j) =g_Tmpv2
6197 END SUBROUTINE g_cal_titau_12_21
6199 SUBROUTINE g_cal_titau_13_31(config_flags,titau,g_titau,defor,g_defor,mtau, &
6200 g_mtau,mu,g_mu,xkx,g_xkx,fnm,fnp,is_ext,ie_ext,js_ext,je_ext,ids,ide,jds, &
6201 jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
6205 REAL :: Tmpv1,g_Tmpv1,Tmpv2,g_Tmpv2
6206 TYPE(grid_config_rec_type) :: config_flags
6207 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
6208 INTEGER :: is_ext,ie_ext,js_ext,je_ext
6209 REAL,DIMENSION(kms:kme) :: fnm,fnp
6210 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: titau,g_titau
6211 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor,g_defor,xkx,g_xkx
6213 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: mtau,g_mtau
6214 REAL,DIMENSION(ims:ime,jms:jme) :: mu,g_mu
6215 INTEGER :: i,j,k,ktf,i_start,i_end,j_start,j_end
6216 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: xkxavg,g_xkxavg
6217 REAL,DIMENSION(its-1:ite+1,jts-1:jte+1) :: muavg,g_muavg
6227 j_end =min(jte,jde-1)
6229 IF( config_flags%open_xs .OR. config_flags%specified .OR. &
6230 config_flags%nested) i_start =max(ids+1,its)
6232 IF( config_flags%open_xe .OR. config_flags%specified .OR. &
6233 config_flags%nested) i_end =min(ide-1,ite)
6235 IF( config_flags%open_ys .OR. config_flags%specified .OR. &
6236 config_flags%nested) j_start =max(jds+1,jts)
6238 IF( config_flags%open_ye .OR. config_flags%specified .OR. &
6239 config_flags%nested) j_end =min(jde-2,jte)
6241 IF( config_flags%periodic_x ) i_start =its
6243 IF( config_flags%periodic_x ) i_end =ite
6245 i_start =i_start-is_ext
6249 j_start =j_start-js_ext
6257 g_xkxavg(i,k,j) =0.5*(fnm(k)*(g_xkx(i,k,j) +g_xkx(i-1,k,j)) +fnp(k) &
6258 *(g_xkx(i,k-1,j) +g_xkx(i-1,k-1,j)))
6259 xkxavg(i,k,j) =0.5*(fnm(k)*(xkx(i,k,j) +xkx(i-1,k,j)) +fnp(k)*(xkx(i,k-1,j) &
6269 g_muavg(i,j) =0.5*(g_mu(i,j) +g_mu(i-1,j))
6270 muavg(i,j) =0.5*(mu(i,j) +mu(i-1,j))
6275 IF( config_flags%sfs_opt .GT. 0 ) THEN
6281 g_Tmpv1 =muavg(i,j)*g_mtau(i,k,j) +g_muavg(i,j)*mtau(i,k,j)
6282 Tmpv1 =muavg(i,j)*mtau(i,k,j)
6284 g_titau(i,k,j) =g_Tmpv1
6293 IF( config_flags%m_opt .EQ. 1 ) THEN
6299 g_Tmpv1 =-muavg(i,j)*g_xkxavg(i,k,j) -g_muavg(i,j)*xkxavg(i,k,j)
6300 Tmpv1 =-muavg(i,j)*xkxavg(i,k,j)
6302 g_Tmpv2 =Tmpv1*g_defor(i,k,j) +g_Tmpv1*defor(i,k,j)
6303 Tmpv2 =Tmpv1*defor(i,k,j)
6305 g_titau(i,k,j) =g_Tmpv2
6308 g_Tmpv1 =-xkxavg(i,k,j)*g_defor(i,k,j) -g_xkxavg(i,k,j)*defor(i,k,j)
6309 Tmpv1 =-xkxavg(i,k,j)*defor(i,k,j)
6311 g_mtau(i,k,j) =g_Tmpv1
6324 g_Tmpv1 =-muavg(i,j)*g_xkxavg(i,k,j) -g_muavg(i,j)*xkxavg(i,k,j)
6325 Tmpv1 =-muavg(i,j)*xkxavg(i,k,j)
6327 g_Tmpv2 =Tmpv1*g_defor(i,k,j) +g_Tmpv1*defor(i,k,j)
6328 Tmpv2 =Tmpv1*defor(i,k,j)
6330 g_titau(i,k,j) =g_Tmpv2
6342 g_titau(i,kts,j) =0.0
6345 g_titau(i,ktf+1,j) =0.0
6346 titau(i,ktf+1,j) =0.0
6351 END SUBROUTINE g_cal_titau_13_31
6353 SUBROUTINE g_cal_titau_23_32(config_flags,titau,g_titau,defor,g_defor,mtau, &
6354 g_mtau,mu,g_mu,xkx,g_xkx,fnm,fnp,is_ext,ie_ext,js_ext,je_ext,ids,ide,jds, &
6355 jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
6359 REAL :: Tmpv1,g_Tmpv1,Tmpv2,g_Tmpv2
6360 TYPE(grid_config_rec_type) :: config_flags
6361 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
6362 INTEGER :: is_ext,ie_ext,js_ext,je_ext
6363 REAL,DIMENSION(kms:kme) :: fnm,fnp
6364 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: titau,g_titau
6365 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: defor,g_defor,xkx,g_xkx
6367 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: mtau,g_mtau
6368 REAL,DIMENSION(ims:ime,jms:jme) :: mu,g_mu
6369 INTEGER :: i,j,k,ktf,i_start,i_end,j_start,j_end
6370 REAL,DIMENSION(its-1:ite+1,kts:kte,jts-1:jte+1) :: xkxavg,g_xkxavg
6371 REAL,DIMENSION(its-1:ite+1,jts-1:jte+1) :: muavg,g_muavg
6377 i_end =min(ite,ide-1)
6383 IF( config_flags%open_xs .OR. config_flags%specified .OR. &
6384 config_flags%nested) i_start =max(ids+1,its)
6386 IF( config_flags%open_xe .OR. config_flags%specified .OR. &
6387 config_flags%nested) i_end =min(ide-2,ite)
6389 IF( config_flags%open_ys .OR. config_flags%specified .OR. &
6390 config_flags%nested) j_start =max(jds+1,jts)
6392 IF( config_flags%open_ye .OR. config_flags%specified .OR. &
6393 config_flags%nested) j_end =min(jde-1,jte)
6395 IF( config_flags%periodic_x ) i_start =its
6397 IF( config_flags%periodic_x ) i_end =min(ite,ide-1)
6399 i_start =i_start-is_ext
6403 j_start =j_start-js_ext
6411 g_xkxavg(i,k,j) =0.5*(fnm(k)*(g_xkx(i,k,j) +g_xkx(i,k,j-1)) +fnp(k) &
6412 *(g_xkx(i,k-1,j) +g_xkx(i,k-1,j-1)))
6413 xkxavg(i,k,j) =0.5*(fnm(k)*(xkx(i,k,j) +xkx(i,k,j-1)) +fnp(k)*(xkx(i,k-1,j) &
6423 g_muavg(i,j) =0.5*(g_mu(i,j) +g_mu(i,j-1))
6424 muavg(i,j) =0.5*(mu(i,j) +mu(i,j-1))
6429 IF( config_flags%sfs_opt .EQ. 1 ) THEN
6435 g_Tmpv1 =muavg(i,j)*g_mtau(i,k,j) +g_muavg(i,j)*mtau(i,k,j)
6436 Tmpv1 =muavg(i,j)*mtau(i,k,j)
6438 g_titau(i,k,j) =g_Tmpv1
6447 IF( config_flags%m_opt .EQ. 1 ) THEN
6453 g_Tmpv1 =-muavg(i,j)*g_xkxavg(i,k,j) -g_muavg(i,j)*xkxavg(i,k,j)
6454 Tmpv1 =-muavg(i,j)*xkxavg(i,k,j)
6456 g_Tmpv2 =Tmpv1*g_defor(i,k,j) +g_Tmpv1*defor(i,k,j)
6457 Tmpv2 =Tmpv1*defor(i,k,j)
6459 g_titau(i,k,j) =g_Tmpv2
6462 g_Tmpv1 =-xkxavg(i,k,j)*g_defor(i,k,j) -g_xkxavg(i,k,j)*defor(i,k,j)
6463 Tmpv1 =-xkxavg(i,k,j)*defor(i,k,j)
6465 g_mtau(i,k,j) =g_Tmpv1
6478 g_Tmpv1 =-muavg(i,j)*g_xkxavg(i,k,j) -g_muavg(i,j)*xkxavg(i,k,j)
6479 Tmpv1 =-muavg(i,j)*xkxavg(i,k,j)
6481 g_Tmpv2 =Tmpv1*g_defor(i,k,j) +g_Tmpv1*defor(i,k,j)
6482 Tmpv2 =Tmpv1*defor(i,k,j)
6484 g_titau(i,k,j) =g_Tmpv2
6496 g_titau(i,kts,j) =0.0
6499 g_titau(i,ktf+1,j) =0.0
6500 titau(i,ktf+1,j) =0.0
6505 END SUBROUTINE g_cal_titau_23_32
6507 END MODULE g_module_diffusion_em
6509 REAL Function g_Sqrt(g_x,x)
6514 g_Sqrt =0.5*g_x/sqrt(x)
6516 ! Revised by Ning Pan, 2010-08-10
6518 ! Print*,'g_Sqrt is incorrectly evaluated by 0!'
6519 ! Print*,'Aborted from compute_diff_metrics'
6521 g_Sqrt =0.5*g_x/(sqrt(x)+1.e-6)