This repository has been archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
/
module_bl_shinhong.F
2390 lines (2390 loc) · 89 KB
/
module_bl_shinhong.F
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!WRF:model_layer:physics
!
module module_bl_shinhong
!
contains
!
!-------------------------------------------------------------------------------
!
subroutine shinhong(u3d,v3d,th3d,t3d,qv3d,qc3d,qi3d,p3d,p3di,pi3d, &
rublten,rvblten,rthblten, &
rqvblten,rqcblten,rqiblten,flag_qi, &
cp,g,rovcp,rd,rovg,ep1,ep2,karman,xlv,rv, &
dz8w,psfc, &
znu,znw,p_top, &
znt,ust,hpbl,psim,psih, &
xland,hfx,qfx,wspd,br, &
dt,kpbl2d, &
exch_h, &
u10,v10, &
shinhong_tke_diag,tke_pbl,el_pbl,corf, &
dx,dy, &
ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte, &
!optional
ctopo,ctopo2, &
wstar,delta, &
regime )
!-------------------------------------------------------------------------------
implicit none
!-------------------------------------------------------------------------------
!-- u3d 3d u-velocity interpolated to theta points (m/s)
!-- v3d 3d v-velocity interpolated to theta points (m/s)
!-- th3d 3d potential temperature (k)
!-- t3d temperature (k)
!-- qv3d 3d water vapor mixing ratio (kg/kg)
!-- qc3d 3d cloud mixing ratio (kg/kg)
!-- qi3d 3d ice mixing ratio (kg/kg)
! (note: if P_QI<PARAM_FIRST_SCALAR this should be zero filled)
!-- p3d 3d pressure (pa)
!-- p3di 3d pressure (pa) at interface level
!-- pi3d 3d exner function (dimensionless)
!-- rublten u tendency due to
! pbl parameterization (m/s/s)
!-- rvblten v tendency due to
! pbl parameterization (m/s/s)
!-- rthblten theta tendency due to
! pbl parameterization (K/s)
!-- rqvblten qv tendency due to
! pbl parameterization (kg/kg/s)
!-- rqcblten qc tendency due to
! pbl parameterization (kg/kg/s)
!-- rqiblten qi tendency due to
! pbl parameterization (kg/kg/s)
!-- cp heat capacity at constant pressure for dry air (j/kg/k)
!-- g acceleration due to gravity (m/s^2)
!-- rovcp r/cp
!-- rd gas constant for dry air (j/kg/k)
!-- rovg r/g
!-- ep1 constant for virtual temperature (r_v/r_d - 1)
!-- ep2 constant for specific humidity calculation
!-- karman von karman constant
!-- xlv latent heat of vaporization (j/kg)
!-- rv gas constant for water vapor (j/kg/k)
!-- dz8w dz between full levels (m)
!-- psfc pressure at the surface (pa)
!-- znu eta values on half (mass) levels
!-- znw eta values on full (w) levels
!-- p_top pressure top of the model (pa)
!-- znt roughness length (m)
!-- ust u* in similarity theory (m/s)
!-- hpbl pbl height (m)
!-- psim similarity stability function for momentum
!-- psih similarity stability function for heat
!-- xland land mask (1 for land, 2 for water)
!-- hfx upward heat flux at the surface (w/m^2)
!-- qfx upward moisture flux at the surface (kg/m^2/s)
!-- wspd wind speed at lowest model level (m/s)
!-- br bulk richardson number in surface layer
!-- u10 u-wind speed at 10 m (m/s)
!-- v10 v-wind speed at 10 m (m/s)
!-- dt time step (s)
!-- ids start index for i in domain
!-- ide end index for i in domain
!-- jds start index for j in domain
!-- jde end index for j in domain
!-- kds start index for k in domain
!-- kde end index for k in domain
!-- ims start index for i in memory
!-- ime end index for i in memory
!-- jms start index for j in memory
!-- jme end index for j in memory
!-- kms start index for k in memory
!-- kme end index for k in memory
!-- its start index for i in tile
!-- ite end index for i in tile
!-- jts start index for j in tile
!-- jte end index for j in tile
!-- kts start index for k in tile
!-- kte end index for k in tile
!-------------------------------------------------------------------------------
!
integer,parameter :: ndiff = 3
real,parameter :: rcl = 1.0
!
integer, intent(in ) :: ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte
integer, intent(in ) :: shinhong_tke_diag
!
real, intent(in ) :: dt,cp,g,rovcp,rovg,rd,xlv,rv
real, intent(in ) :: ep1,ep2,karman
real, intent(in ) :: dx,dy
!
integer, dimension( ims:ime, jms:jme ) , &
intent(out ) :: kpbl2d
!
real, dimension( ims:ime, kms:kme, jms:jme ) , &
intent(in ) :: u3d, &
v3d
real, dimension( ims:ime, kms:kme, jms:jme ) , &
intent(in ) :: qv3d, &
qc3d, &
qi3d, &
p3d, &
pi3d, &
th3d, &
t3d, &
dz8w
real, dimension( ims:ime, kms:kme, jms:jme ) , &
intent(in ) :: p3di
!
real, dimension( ims:ime, kms:kme, jms:jme ) , &
intent(inout) :: rublten, &
rvblten, &
rthblten, &
rqvblten, &
rqcblten
real, dimension( ims:ime, kms:kme, jms:jme ) , &
intent(inout) :: exch_h
real, dimension( ims:ime, kms:kme, jms:jme ) , &
intent(inout) :: tke_pbl, &
el_pbl
!
real, dimension( ims:ime, jms:jme ) , &
intent(in ) :: xland, &
hfx, &
qfx, &
corf, &
br, &
psfc
real, dimension( ims:ime, jms:jme ) , &
intent(in ) :: &
psim, &
psih
!
real, dimension( ims:ime, jms:jme ) , &
intent(inout) :: u10, &
v10
real, dimension( ims:ime, jms:jme ) , &
intent(inout) :: znt, &
ust, &
hpbl, &
wspd
!
logical, intent(in) :: flag_qi
!
! optional
!
real, dimension( ims:ime, kms:kme, jms:jme ) , &
intent(inout), optional :: rqiblten
!
real, dimension( ims:ime, jms:jme ) , &
intent(inout), optional :: wstar, &
delta
real, dimension( ims:ime, jms:jme ) , &
intent(inout), optional :: regime
!
real, dimension( ims:ime, jms:jme ) , &
intent(in ), optional :: ctopo, &
ctopo2
!
real, dimension( kms:kme ) , &
intent(in ), optional :: znu, &
znw
!
real, optional, intent(in ) :: p_top
!
! local
!
integer :: i,j,k
real, dimension( its:ite, kts:kte*ndiff ) :: rqvbl2dt, &
qv2d
real, dimension( its:ite, kts:kte ) :: pdh
real, dimension( its:ite, kts:kte+1 ) :: pdhi
real, dimension( its:ite ) :: &
dusfc, &
dvsfc, &
dtsfc, &
dqsfc
!
qv2d(its:ite,:) = 0.0
!
do j = jts,jte
do k = kts,kte+1
do i = its,ite
if(k.le.kte)pdh(i,k) = p3d(i,k,j)
pdhi(i,k) = p3di(i,k,j)
enddo
enddo
do k = kts,kte
do i = its,ite
qv2d(i,k) = qv3d(i,k,j)
qv2d(i,k+kte) = qc3d(i,k,j)
if(present(rqiblten)) qv2d(i,k+kte+kte) = qi3d(i,k,j)
enddo
enddo
!
call shinhong2d(J=j,ux=u3d(ims,kms,j),vx=v3d(ims,kms,j) &
,tx=t3d(ims,kms,j) &
,qx=qv2d(its,kts) &
,p2d=pdh(its,kts),p2di=pdhi(its,kts) &
,pi2d=pi3d(ims,kms,j) &
,utnp=rublten(ims,kms,j),vtnp=rvblten(ims,kms,j) &
,ttnp=rthblten(ims,kms,j),qtnp=rqvbl2dt(its,kts),ndiff=ndiff &
,cp=cp,g=g,rovcp=rovcp,rd=rd,rovg=rovg &
,xlv=xlv,rv=rv &
,ep1=ep1,ep2=ep2,karman=karman &
,dz8w2d=dz8w(ims,kms,j) &
,psfcpa=psfc(ims,j),znt=znt(ims,j),ust=ust(ims,j) &
,hpbl=hpbl(ims,j) &
,regime=regime(ims,j),psim=psim(ims,j) &
,psih=psih(ims,j),xland=xland(ims,j) &
,hfx=hfx(ims,j),qfx=qfx(ims,j) &
,wspd=wspd(ims,j),br=br(ims,j) &
,dusfc=dusfc,dvsfc=dvsfc,dtsfc=dtsfc,dqsfc=dqsfc &
,dt=dt,rcl=1.0,kpbl1d=kpbl2d(ims,j) &
,exch_hx=exch_h(ims,kms,j) &
,wstar=wstar(ims,j) &
,delta=delta(ims,j) &
,u10=u10(ims,j),v10=v10(ims,j) &
,ctopo=ctopo(ims,j),ctopo2=ctopo2(ims,j) &
,shinhong_tke_diag=shinhong_tke_diag &
,tke=tke_pbl(ims,kms,j),el_pbl=el_pbl(ims,kms,j) &
,corf=corf(ims,j) &
,dx=dx,dy=dy &
,ids=ids,ide=ide, jds=jds,jde=jde, kds=kds,kde=kde &
,ims=ims,ime=ime, jms=jms,jme=jme, kms=kms,kme=kme &
,its=its,ite=ite, jts=jts,jte=jte, kts=kts,kte=kte )
!
do k = kts,kte
do i = its,ite
rthblten(i,k,j) = rthblten(i,k,j)/pi3d(i,k,j)
rqvblten(i,k,j) = rqvbl2dt(i,k)
rqcblten(i,k,j) = rqvbl2dt(i,k+kte)
if(present(rqiblten)) rqiblten(i,k,j) = rqvbl2dt(i,k+kte+kte)
enddo
enddo
!
enddo
!
end subroutine shinhong
!-------------------------------------------------------------------------------
!
!-------------------------------------------------------------------------------
subroutine shinhong2d(j,ux,vx,tx,qx,p2d,p2di,pi2d, &
utnp,vtnp,ttnp,qtnp,ndiff, &
cp,g,rovcp,rd,rovg,ep1,ep2,karman,xlv,rv, &
dz8w2d,psfcpa, &
znt,ust,hpbl,psim,psih, &
xland,hfx,qfx,wspd,br, &
dusfc,dvsfc,dtsfc,dqsfc, &
dt,rcl,kpbl1d, &
exch_hx, &
wstar,delta, &
shinhong_tke_diag, &
tke,el_pbl,corf, &
u10,v10, &
ctopo,ctopo2, &
dx,dy, &
ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte, &
!optional
regime )
!-------------------------------------------------------------------------------
implicit none
!-------------------------------------------------------------------------------
!
! the shinhongpbl (shin and hong 2015) is based on the les study of shin
! and hong (2013). the major ingredients of the shinhongpbl are
! 1) the prescribed nonlocal heat transport profile fit to the les and
! 2) inclusion of explicit scale dependency functions for vertical
! transport in convective pbl.
! so, the shinhongpbl works at the gray zone resolution of convective pbl.
! note that honnert et al. (2011) first suggested explicit scale dependency
! function, and shin and hong (2013) further classified the function by
! stability (u*/w*) in convective pbl and calculated the function for
! nonlocal and local transport separately.
! vertical mixing in the stable boundary layer and free atmosphere follows
! hong (2010) and hong et al. (2006), same as the ysupbl scheme.
!
! shinhongpbl:
! coded and implemented by hyeyum hailey shin (ncar)
! summer 2014
!
! ysupbl:
! coded by song-you hong (yonsei university) and implemented by
! song-you hong (yonsei university) and jimy dudhia (ncar)
! summer 2002
!
! references:
! shin and hong (2015) mon. wea. rev.
! shin and hong (2013) j. atmos. sci.
! honnert, masson, and couvreux (2011) j. atmos. sci.
! hong (2010) quart. j. roy. met. soc
! hong, noh, and dudhia (2006), mon. wea. rev.
!
!-------------------------------------------------------------------------------
!
real,parameter :: xkzminm = 0.1,xkzminh = 0.01
real,parameter :: xkzmax = 1000.,rimin = -100.
real,parameter :: rlam = 30.,prmin = 0.25,prmax = 4.
real,parameter :: brcr_ub = 0.0,brcr_sb = 0.25,cori = 1.e-4
real,parameter :: afac = 6.8,bfac = 6.8,pfac = 2.0,pfac_q = 2.0
real,parameter :: phifac = 8.,sfcfrac = 0.1
real,parameter :: d1 = 0.02, d2 = 0.05, d3 = 0.001
real,parameter :: h1 = 0.33333335, h2 = 0.6666667
real,parameter :: ckz = 0.001,zfmin = 1.e-8,aphi5 = 5.,aphi16 = 16.
real,parameter :: tmin=1.e-2
real,parameter :: gamcrt = 3.,gamcrq = 2.e-3
real,parameter :: xka = 2.4e-5
integer,parameter :: imvdif = 1
!
! tunable parameters for tke
!
real,parameter :: epsq2l = 0.01,c_1 = 1.0,gamcre = 0.224
!
! tunable parameters for prescribed nonlocal transport profile
!
real,parameter :: mltop = 1.0,sfcfracn1 = 0.075
real,parameter :: nlfrac = 0.7,enlfrac = -0.4
real,parameter :: a11 = 1.0,a12 = -1.15
real,parameter :: ezfac = 1.5
real,parameter :: cpent = -0.4,rigsmax = 100.
real,parameter :: entfmin = 1.0, entfmax = 5.0
!
integer, intent(in ) :: ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte, &
j,ndiff
integer, intent(in ) :: shinhong_tke_diag
!
real, intent(in ) :: dt,rcl,cp,g,rovcp,rovg,rd,xlv,rv
real, intent(in ) :: ep1,ep2,karman
real, intent(in ) :: dx,dy
!
integer, dimension( ims:ime ) , &
intent(out ) :: kpbl1d
!
real, dimension( ims:ime, kms:kme ) , &
intent(in ) :: dz8w2d, &
pi2d
real, dimension( ims:ime, kms:kme ) , &
intent(in ) :: ux, &
vx
real, dimension( ims:ime, kms:kme ) , &
intent(in ) :: tx
!
real, dimension( its:ite, kts:kte*ndiff ) , &
intent(in ) :: qx
real, dimension( its:ite, kts:kte+1 ) , &
intent(in ) :: p2di
real, dimension( its:ite, kts:kte ) , &
intent(in ) :: p2d
!
real, dimension( ims:ime, kms:kme ) , &
intent(inout) :: utnp, &
vtnp, &
ttnp
real, dimension( ims:ime, kms:kme ) , &
intent(inout) :: exch_hx
real, dimension( ims:ime, kms:kme ) , &
intent(inout) :: tke, &
el_pbl
real, dimension( its:ite, kts:kte*ndiff ) , &
intent(inout) :: qtnp
!
real, dimension( ims:ime ) , &
intent(in ) :: xland, &
hfx, &
qfx
real, dimension( ims:ime ) , &
intent(in ) :: br, &
psim, &
psih, &
psfcpa
real, dimension( ims:ime ) , &
intent(in ) :: corf
!
real, dimension( ims:ime ) , &
intent(inout) :: ust, &
hpbl, &
znt
real, dimension( ims:ime ) , &
intent(inout) :: wspd
real, dimension( ims:ime ) , &
intent(inout) :: u10, &
v10
!
real, dimension( ims:ime ) , &
optional , &
intent(in ) :: ctopo, &
ctopo2
real, dimension( ims:ime ) , &
optional , &
intent(inout) :: regime
real, dimension( its:ite ) , &
intent(out ) :: wstar, &
delta
!
! local vars
!
integer :: n,i,k,l,ic,is,nwmass
integer :: klpbl, kqc, kqi
integer :: lmh,lmxl
!
real :: dt2,rdt,spdk2,fm,fh,hol1,gamfac,vpert,prnum,prnum0
real :: ss,ri,qmean,tmean,alpha,chi,zk,rl2,dk,sri
real :: brint,dtodsd,dtodsu,rdz,dsdzt,dsdzq,dsdz2,rlamdz
real :: utend,vtend,ttend,qtend
real :: dtstep,govrthv
real :: cont, conq, conw, conwrc
real :: delxy,pu1,pth1,pq1
real :: dex,hgame_c
real :: zfacdx
real :: amf1,amf2,bmf2,amf3,bmf3,amf4,bmf4,sflux0,snlflux0
real :: mlfrac,ezfrac,sfcfracn
real :: uwst,uwstx,csfac
real :: prnumfac,bfx0,hfx0,qfx0,delb,dux,dvx, &
dsdzu,dsdzv,wm3,dthx,dqx,wspd10,ross,tem1,dsig,tvcon,conpr, &
prfac,prfac2,phim8z
!
integer, dimension( its:ite ) :: kpbl
real, dimension( its:ite ) :: hol
real, dimension( its:ite ) :: deltaoh
real, dimension( its:ite ) :: rigs, &
enlfrac2, &
cslen
real, dimension( its:ite ) :: &
rhox, &
govrth, &
zl1,thermal, &
wscale, &
hgamt,hgamq, &
brdn,brup, &
phim,phih, &
dusfc,dvsfc, &
dtsfc,dqsfc, &
prpbl, &
wspd1
real, dimension( its:ite ) :: &
ust3, &
wstar3, &
hgamu,hgamv, &
wm2, we, &
bfxpbl, &
hfxpbl,qfxpbl, &
ufxpbl,vfxpbl, &
dthvx
real, dimension( its:ite ) :: &
brcr, &
sflux, &
zol1, &
brcr_sbro
real, dimension( its:ite ) :: &
efxpbl, &
hpbl_cbl, &
epshol, &
ct
!
real, dimension( its:ite, kts:kte ) :: xkzm,xkzh, &
f1,f2, &
r1,r2, &
ad,au, &
cu, &
al, &
xkzq, &
zfac
real, dimension( its:ite, kts:kte ) :: &
thx,thvx, &
del, &
dza, &
dzq, &
xkzom, &
xkzoh, &
za
real, dimension( its:ite, kts:kte ) :: &
wscalek
real, dimension( its:ite, kts:kte ) :: &
xkzml,xkzhl, &
zfacent,entfac
real, dimension( its:ite, kts:kte ) :: &
mf, &
zfacmf, &
entfacmf
real, dimension( its:ite, kts:kte ) :: &
q2x, &
hgame2d, &
tflux_e, &
qflux_e, &
tvflux_e
real, dimension( its:ite, kts:kte+1 ) :: zq
real, dimension( its:ite, kts:kte, ndiff ) :: r3,f3
!
real, dimension( kts:kte ) :: &
uxk,vxk, &
txk,thxk,thvxk, &
q2xk, &
hgame
real, dimension( kts:kte ) :: &
ps1d,pb1d,eps1d,pt1d, &
xkze1d,eflx_l1d,eflx_nl1d, &
ptke1
real, dimension( kts+1:kte ) :: &
s2,gh,rig,el, &
akmk,akhk, &
mfk,ufxpblk,vfxpblk,qfxpblk
real, dimension( kts:kte+1 ) :: zqk
real, dimension( kts:kte*ndiff ) :: qxk
!
logical, dimension( its:ite ) :: pblflg, &
sfcflg, &
stable
logical, dimension( ndiff ) :: ifvmix
!
!-------------------------------------------------------------------------------
!
klpbl = kte
lmh = 1
lmxl = 1
!
cont=cp/g
conq=xlv/g
conw=1./g
conwrc = conw*sqrt(rcl)
conpr = bfac*karman*sfcfrac
!
! k-start index for cloud and rain
!
kqc = 1 + kte
kqi = 1 + kte*2
nwmass = 3
ifvmix(:) = .true.
!
do k = kts,kte
do i = its,ite
thx(i,k) = tx(i,k)/pi2d(i,k)
enddo
enddo
!
do k = kts,kte
do i = its,ite
tvcon = (1.+ep1*qx(i,k))
thvx(i,k) = thx(i,k)*tvcon
enddo
enddo
!
do i = its,ite
tvcon = (1.+ep1*qx(i,1))
rhox(i) = psfcpa(i)/(rd*tx(i,1)*tvcon)
govrth(i) = g/thx(i,1)
enddo
!
!-----compute the height of full- and half-sigma levels above ground
! level, and the layer thicknesses.
!
do i = its,ite
zq(i,1) = 0.
enddo
!
do k = kts,kte
do i = its,ite
zq(i,k+1) = dz8w2d(i,k)+zq(i,k)
enddo
enddo
!
do k = kts,kte
do i = its,ite
za(i,k) = 0.5*(zq(i,k)+zq(i,k+1))
dzq(i,k) = zq(i,k+1)-zq(i,k)
del(i,k) = p2di(i,k)-p2di(i,k+1)
enddo
enddo
!
do i = its,ite
dza(i,1) = za(i,1)
enddo
!
do k = kts+1,kte
do i = its,ite
dza(i,k) = za(i,k)-za(i,k-1)
enddo
enddo
!
!
!-----initialize vertical tendencies and
!
utnp(its:ite,:) = 0.
vtnp(its:ite,:) = 0.
ttnp(its:ite,:) = 0.
qtnp(its:ite,:) = 0.
!
do i = its,ite
wspd1(i) = sqrt(ux(i,1)*ux(i,1)+vx(i,1)*vx(i,1))+1.e-9
enddo
!
!---- compute vertical diffusion
!
! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
! compute preliminary variables
!
dtstep = dt
dt2 = 2.*dtstep
rdt = 1./dt2
!
do i = its,ite
bfxpbl(i) = 0.0
hfxpbl(i) = 0.0
qfxpbl(i) = 0.0
ufxpbl(i) = 0.0
vfxpbl(i) = 0.0
hgamu(i) = 0.0
hgamv(i) = 0.0
delta(i) = 0.0
enddo
!
do i = its,ite
efxpbl(i) = 0.0
hpbl_cbl(i) = 0.0
epshol(i) = 0.0
ct(i) = 0.0
enddo
!
do i = its,ite
deltaoh(i) = 0.0
rigs(i) = 0.0
enlfrac2(i) = 0.0
cslen(i) = 0.0
enddo
!
do k = kts,klpbl
do i = its,ite
wscalek(i,k) = 0.0
enddo
enddo
!
do k = kts,klpbl
do i = its,ite
zfac(i,k) = 0.0
enddo
enddo
!
do k = kts,kte
do i = its,ite
q2x(i,k) = 2.*tke(i,k)
enddo
enddo
!
do k = kts,kte
do i = its,ite
el_pbl(i,k) = 0.0
hgame2d(i,k) = 0.0
tflux_e(i,k) = 0.0
qflux_e(i,k) = 0.0
tvflux_e(i,k) = 0.0
enddo
enddo
!
do k = kts,kte
do i = its,ite
mf(i,k) = 0.0
zfacmf(i,k) = 0.0
enddo
enddo
!
do k = kts,klpbl-1
do i = its,ite
xkzom(i,k) = xkzminm
xkzoh(i,k) = xkzminh
enddo
enddo
!
do i = its,ite
dusfc(i) = 0.
dvsfc(i) = 0.
dtsfc(i) = 0.
dqsfc(i) = 0.
enddo
!
do i = its,ite
hgamt(i) = 0.
hgamq(i) = 0.
wscale(i) = 0.
kpbl(i) = 1
hpbl(i) = zq(i,1)
hpbl_cbl(i) = zq(i,1)
zl1(i) = za(i,1)
thermal(i)= thvx(i,1)
pblflg(i) = .true.
sfcflg(i) = .true.
sflux(i) = hfx(i)/rhox(i)/cp + qfx(i)/rhox(i)*ep1*thx(i,1)
if(br(i).gt.0.0) sfcflg(i) = .false.
enddo
!
! compute the first guess of pbl height
!
do i = its,ite
stable(i) = .false.
brup(i) = br(i)
brcr(i) = brcr_ub
enddo
!
do k = 2,klpbl
do i = its,ite
if(.not.stable(i))then
brdn(i) = brup(i)
spdk2 = max(ux(i,k)**2+vx(i,k)**2,1.)
brup(i) = (thvx(i,k)-thermal(i))*(g*za(i,k)/thvx(i,1))/spdk2
kpbl(i) = k
stable(i) = brup(i).gt.brcr(i)
endif
enddo
enddo
!
do i = its,ite
k = kpbl(i)
if(brdn(i).ge.brcr(i))then
brint = 0.
elseif(brup(i).le.brcr(i))then
brint = 1.
else
brint = (brcr(i)-brdn(i))/(brup(i)-brdn(i))
endif
hpbl(i) = za(i,k-1)+brint*(za(i,k)-za(i,k-1))
if(hpbl(i).lt.zq(i,2)) kpbl(i) = 1
if(kpbl(i).le.1) pblflg(i) = .false.
enddo
!
do i = its,ite
fm = psim(i)
fh = psih(i)
zol1(i) = max(br(i)*fm*fm/fh,rimin)
if(sfcflg(i))then
zol1(i) = min(zol1(i),-zfmin)
else
zol1(i) = max(zol1(i),zfmin)
endif
hol1 = zol1(i)*hpbl(i)/zl1(i)*sfcfrac
epshol(i) = hol1
if(sfcflg(i))then
phim(i) = (1.-aphi16*hol1)**(-1./4.)
phih(i) = (1.-aphi16*hol1)**(-1./2.)
bfx0 = max(sflux(i),0.)
hfx0 = max(hfx(i)/rhox(i)/cp,0.)
qfx0 = max(ep1*thx(i,1)*qfx(i)/rhox(i),0.)
wstar3(i) = (govrth(i)*bfx0*hpbl(i))
wstar(i) = (wstar3(i))**h1
else
phim(i) = (1.+aphi5*hol1)
phih(i) = phim(i)
wstar(i) = 0.
wstar3(i) = 0.
endif
ust3(i) = ust(i)**3.
wscale(i) = (ust3(i)+phifac*karman*wstar3(i)*0.5)**h1
wscale(i) = min(wscale(i),ust(i)*aphi16)
wscale(i) = max(wscale(i),ust(i)/aphi5)
enddo
!
! compute the surface variables for pbl height estimation
! under unstable conditions
!
do i = its,ite
if(sfcflg(i).and.sflux(i).gt.0.0)then
gamfac = bfac/rhox(i)/wscale(i)
hgamt(i) = min(gamfac*hfx(i)/cp,gamcrt)
hgamq(i) = min(gamfac*qfx(i),gamcrq)
vpert = (hgamt(i)+ep1*thx(i,1)*hgamq(i))/bfac*afac
thermal(i) = thermal(i)+max(vpert,0.)*min(za(i,1)/(sfcfrac*hpbl(i)),1.0)
hgamt(i) = max(hgamt(i),0.0)
hgamq(i) = max(hgamq(i),0.0)
brint = -15.9*ust(i)*ust(i)/wspd(i)*wstar3(i)/(wscale(i)**4.)
hgamu(i) = brint*ux(i,1)
hgamv(i) = brint*vx(i,1)
else
pblflg(i) = .false.
endif
enddo
!
! enhance the pbl height by considering the thermal
!
do i = its,ite
if(pblflg(i))then
kpbl(i) = 1
hpbl(i) = zq(i,1)
endif
enddo
!
do i = its,ite
if(pblflg(i))then
stable(i) = .false.
brup(i) = br(i)
brcr(i) = brcr_ub
endif
enddo
!
do k = 2,klpbl
do i = its,ite
if(.not.stable(i).and.pblflg(i))then
brdn(i) = brup(i)
spdk2 = max(ux(i,k)**2+vx(i,k)**2,1.)
brup(i) = (thvx(i,k)-thermal(i))*(g*za(i,k)/thvx(i,1))/spdk2
kpbl(i) = k
stable(i) = brup(i).gt.brcr(i)
endif
enddo
enddo
!
do i = its,ite
if(pblflg(i)) then
k = kpbl(i)
if(brdn(i).ge.brcr(i))then
brint = 0.
elseif(brup(i).le.brcr(i))then
brint = 1.
else
brint = (brcr(i)-brdn(i))/(brup(i)-brdn(i))
endif
hpbl(i) = za(i,k-1)+brint*(za(i,k)-za(i,k-1))
if(hpbl(i).lt.zq(i,2)) kpbl(i) = 1
if(kpbl(i).le.1) pblflg(i) = .false.
uwst = abs(ust(i)/wstar(i)-0.5)
uwstx = -80.*uwst+14.
csfac = 0.5*(tanh(uwstx)+3.)
cslen(i) = csfac*hpbl(i)
endif
enddo
!
! stable boundary layer
!
do i = its,ite
hpbl_cbl(i) = hpbl(i)
if((.not.sfcflg(i)).and.hpbl(i).lt.zq(i,2)) then
brup(i) = br(i)
stable(i) = .false.
else
stable(i) = .true.
endif
enddo
!
do i = its,ite
if((.not.stable(i)).and.((xland(i)-1.5).ge.0))then
wspd10 = u10(i)*u10(i) + v10(i)*v10(i)
wspd10 = sqrt(wspd10)
ross = wspd10 / (cori*znt(i))
brcr_sbro(i) = min(0.16*(1.e-7*ross)**(-0.18),.3)
endif
enddo
!
do i = its,ite
if(.not.stable(i))then
if((xland(i)-1.5).ge.0)then
brcr(i) = brcr_sbro(i)
else
brcr(i) = brcr_sb
endif
endif
enddo
!
do k = 2,klpbl
do i = its,ite
if(.not.stable(i))then
brdn(i) = brup(i)
spdk2 = max(ux(i,k)**2+vx(i,k)**2,1.)
brup(i) = (thvx(i,k)-thermal(i))*(g*za(i,k)/thvx(i,1))/spdk2
kpbl(i) = k
stable(i) = brup(i).gt.brcr(i)
endif
enddo
enddo
!
do i = its,ite
if((.not.sfcflg(i)).and.hpbl(i).lt.zq(i,2)) then
k = kpbl(i)
if(brdn(i).ge.brcr(i))then
brint = 0.
elseif(brup(i).le.brcr(i))then
brint = 1.
else
brint = (brcr(i)-brdn(i))/(brup(i)-brdn(i))
endif
hpbl(i) = za(i,k-1)+brint*(za(i,k)-za(i,k-1))
if(hpbl(i).lt.zq(i,2)) kpbl(i) = 1
if(kpbl(i).le.1) pblflg(i) = .false.
endif
enddo
!
! scale dependency for nonlocal momentum and moisture transport
!
delxy=sqrt(dx*dy)
!
do i = its,ite
pu1=pu(delxy,cslen(i))
pq1=pq(delxy,cslen(i))
if(pblflg(i)) then
hgamu(i) = hgamu(i)*pu1
hgamv(i) = hgamv(i)*pu1
hgamq(i) = hgamq(i)*pq1
endif
enddo
!
! estimate the entrainment parameters
!
delxy=sqrt(dx*dy)
!
do i = its,ite
if(pblflg(i)) then
k = kpbl(i) - 1
prpbl(i) = 1.0
wm3 = wstar3(i) + 5. * ust3(i)
wm2(i) = wm3**h2
bfxpbl(i) = -0.15*thvx(i,1)/g*wm3/hpbl(i)
dthvx(i) = max(thvx(i,k+1)-thvx(i,k),tmin)
dthx = max(thx(i,k+1)-thx(i,k),tmin)
dqx = min(qx(i,k+1)-qx(i,k),0.0)
we(i) = max(bfxpbl(i)/dthvx(i),-sqrt(wm2(i)))
hfxpbl(i) = we(i)*dthx
pq1=pq(delxy,cslen(i))
qfxpbl(i) = we(i)*dqx*pq1
!
pu1=pu(delxy,cslen(i))
dux = ux(i,k+1)-ux(i,k)
dvx = vx(i,k+1)-vx(i,k)
if(dux.gt.tmin) then
ufxpbl(i) = max(prpbl(i)*we(i)*dux*pu1,-ust(i)*ust(i))
elseif(dux.lt.-tmin) then
ufxpbl(i) = min(prpbl(i)*we(i)*dux*pu1,ust(i)*ust(i))
else
ufxpbl(i) = 0.0
endif
if(dvx.gt.tmin) then
vfxpbl(i) = max(prpbl(i)*we(i)*dvx*pu1,-ust(i)*ust(i))
elseif(dvx.lt.-tmin) then
vfxpbl(i) = min(prpbl(i)*we(i)*dvx*pu1,ust(i)*ust(i))
else
vfxpbl(i) = 0.0
endif
delb = govrth(i)*d3*hpbl(i)
delta(i) = min(d1*hpbl(i) + d2*wm2(i)/delb,100.)
delb = govrth(i)*dthvx(i)
deltaoh(i) = d1*hpbl(i) + d2*wm2(i)/delb
deltaoh(i) = max(ezfac*deltaoh(i),hpbl(i)-za(i,kpbl(i)-1)-1.)
deltaoh(i) = min(deltaoh(i) ,hpbl(i))
rigs(i) = govrth(i)*dthvx(i)*deltaoh(i)/(dux**2.+dvx**2.)
rigs(i) = max(min(rigs(i), rigsmax),rimin)
enlfrac2(i) = max(min(wm3/wstar3(i)/(1.+cpent/rigs(i)),entfmax), entfmin)
enlfrac2(i) = enlfrac2(i)*enlfrac
endif
enddo
!
do k = kts,klpbl
do i = its,ite
if(pblflg(i))then
entfacmf(i,k) = sqrt(((zq(i,k+1)-hpbl(i))/deltaoh(i))**2.)
endif
if(pblflg(i).and.k.ge.kpbl(i))then
entfac(i,k) = ((zq(i,k+1)-hpbl(i))/deltaoh(i))**2.
else
entfac(i,k) = 1.e30
endif
enddo
enddo
!
! compute diffusion coefficients below pbl
!
do k = kts,klpbl
do i = its,ite
if(k.lt.kpbl(i)) then
zfac(i,k) = min(max((1.-(zq(i,k+1)-zl1(i))/(hpbl(i)-zl1(i))),zfmin),1.)
zfacent(i,k) = (1.-zfac(i,k))**3.
wscalek(i,k) = (ust3(i)+phifac*karman*wstar3(i)*(1.-zfac(i,k)))**h1
if(sfcflg(i)) then
prfac = conpr
prfac2 = 15.9*wstar3(i)/ust3(i)/(1.+4.*karman*wstar3(i)/ust3(i))
prnumfac = -3.*(max(zq(i,k+1)-sfcfrac*hpbl(i),0.))**2./hpbl(i)**2.
else
prfac = 0.
prfac2 = 0.
prnumfac = 0.