-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbl_ugwp.F
1114 lines (1022 loc) · 48 KB
/
bl_ugwp.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
module bl_ugwp
use ccpp_kind_types,only: kind_phys
!===============================================================================
IMPLICIT NONE
PRIVATE
PUBLIC :: bl_ugwp_run
PUBLIC :: bl_ugwp_init
PUBLIC :: bl_ugwp_final
PUBLIC :: bl_ugwp_timestep_init
PUBLIC :: bl_ugwp_timestep_final
contains
!-------------------------------------------------------------------------------
!-------------------------------------------------------------------------------
subroutine bl_ugwp_run(sina, cosa, &
rublten,rvblten, &
dtaux3d,dtauy3d, &
dtaux3d_ls,dtauy3d_ls,dtaux3d_bl,dtauy3d_bl, &
dtaux3d_ss,dtauy3d_ss,dtaux3d_fd,dtauy3d_fd, &
dusfcg,dvsfcg, &
dusfc_ls,dvsfc_ls,dusfc_bl,dvsfc_bl, &
dusfc_ss,dvsfc_ss,dusfc_fd,dvsfc_fd, &
ugwp_diags,uproj, vproj, &
t1, q1, &
prsi, prsl, prslk, zl, dz, hpbl, kpbl, br1, xland1, &
var, oc1, &
oa2d1, oa2d2, &
oa2d3, oa2d4, &
ol2d1, ol2d2, &
ol2d3, ol2d4, &
varss, oc1ss, &
oa2d1ss, oa2d2ss, &
oa2d3ss, oa2d4ss, &
ol2d1ss, ol2d2ss, &
ol2d3ss, ol2d4ss, &
g_, cp_, rd_, rv_, fv_, pi_, &
dxmeter, deltim, &
its, ite, kte, kme, &
errmsg, errflg )
!-------------------------------------------------------------------------------
!
! abstract :
! this code handles the time tendencies of u v due to the effect of mountain
! induced gravity wave drag from sub-grid scale orography. this routine
! not only treats the traditional upper-level wave breaking due to mountain
! variance (alpert 1988), but also the enhanced lower-tropospheric wave
! breaking due to mountain convexity and asymmetry (kim and arakawa 1995).
! thus, in addition to the terrain height data in a model grid gox,
! additional 10-2d topographic statistics files are needed, including
! orographic standard deviation (var), convexity (oc1), asymmetry (oa4)
! and ol (ol4). these data sets are prepared based on the 30 sec usgs orography
! hong (1999). the current scheme was implmented as in hong et al.(2008)
!
! coded by song-you hong and young-joon kim and implemented by song-you hong
!
! program history log:
! 2014-10-01 Hyun-Joo Choi (from KIAPS) flow-blocking drag of kim and doyle
! with blocked height by dividing streamline theory
! 2017-04-06 Joseph Olson (from Gert-Jan Steeneveld) added small-scale
! orographic grabity wave drag:
! 2017-09-15 Joseph Olson, with some bug fixes from Michael Toy: added the
! topographic form drag of Beljaars et al. (2004, QJRMS)
! Activation of each component is done by specifying the integer-parameters
! (defined below) to 0: inactive or 1: active
! ugwp_ms = 0 or 1: meso-scale
! ugwp_bl = 0 or 1: blocking drag
! ugwp_ss = 0 or 1: small-scale gravity wave drag
! ugwp_fd = 0 or 1: topographic form drag
!
! references:
! hong et al. (2008), wea. and forecasting
! kim and doyle (2005), Q. J. R. Meteor. Soc.
! kim and arakawa (1995), j. atmos. sci.
! alpet et al. (1988), NWP conference.
! hong (1999), NCEP office note 424.
! steeneveld et al (2008), JAMC
! Tsiringakis et al. (2017), Q. J. R. Meteor. Soc.
!
! notice : comparible or lower resolution orography files than model resolution
! are desirable in preprocess (wps) to prevent weakening of the drag
!
! input :
! dudt, dvdt - non-lin tendency for u and v wind component
! uproj, vproj - projection-relative U and V m/sec
! u1, v1 - zonal and meridional wind m/sec at t0-dt
! t1 - temperature deg k at t0-dt
! q1 - mixing ratio at t0-dt
! deltim - time step (s)
! del - positive increment of pressure across layer (pa)
! prslk, zl, prsl, prsi - pressure and height variables
! dz - layer thickness (m)
! hpbl - PBL height (m)
! kpbl - index level of PBL top
! xland1 - land mask (1 for land, 2 for water)
! oa4*, ol4*, var*, oc1* - orographic statistics
!
! output :
! dudt, dvdt - wind tendency due to gwdo
! dtaux3d_*, dtauy3d_* - diagnosed orographic gwd
! dusfcg_*, dvsfcg_* - gw surface stress
!
!-------------------------------------------------------------------------------
implicit none
!
integer, parameter :: kts = 1
integer , intent(in ) :: its, ite, kte, kme
real(kind=kind_phys) , intent(in ) :: g_, pi_, rd_, rv_, fv_,&
cp_, deltim
real(kind=kind_phys), dimension(its:ite) , intent(in ) :: dxmeter
real(kind=kind_phys), dimension(its:ite,kts:kte) , intent(inout) :: rublten, rvblten
real(kind=kind_phys), dimension(its:ite,kts:kte) , intent( out) :: dtaux3d, dtauy3d
real(kind=kind_phys), dimension(:,:), intent( out), optional :: dtaux3d_ls, dtauy3d_ls, &
dtaux3d_bl, dtauy3d_bl, &
dtaux3d_ss, dtauy3d_ss, &
dtaux3d_fd, dtauy3d_fd
real(kind=kind_phys), dimension(its:ite) , intent( out) :: dusfcg, dvsfcg
real(kind=kind_phys), dimension(:), intent( out), optional :: dusfc_ls, dvsfc_ls, &
dusfc_bl, dvsfc_bl, &
dusfc_ss, dvsfc_ss, &
dusfc_fd, dvsfc_fd
logical , intent(in ) :: ugwp_diags
real(kind=kind_phys), dimension(its:ite) , intent(in ) :: sina, cosa
real(kind=kind_phys), dimension(its:ite,kts:kte) , intent(in ) :: uproj, vproj
real(kind=kind_phys), dimension(its:ite,kts:kte) , intent(in ) :: t1, q1, prslk, zl, dz
real(kind=kind_phys), dimension(its:ite) , intent(in ) :: hpbl, xland1, br1
integer, dimension(its:ite) , intent(in ) :: kpbl
!
real(kind=kind_phys), dimension(its:ite,kts:kte) , intent(in ) :: prsl
real(kind=kind_phys), dimension(its:ite,kts:kme) , intent(in ) :: prsi
!
real(kind=kind_phys), dimension(its:ite) , intent(in ) :: var, oc1, &
oa2d1, oa2d2, oa2d3, oa2d4, &
ol2d1, ol2d2, ol2d3, ol2d4
real(kind=kind_phys), dimension(its:ite) , intent(in ) :: varss, oc1ss, &
oa2d1ss, oa2d2ss, &
oa2d3ss, oa2d4ss, &
ol2d1ss, ol2d2ss, &
ol2d3ss, ol2d4ss
character(len=*) , intent( out) :: errmsg
integer , intent( out) :: errflg
! Variables for scale-awareness:
! Small-scale GWD + turbulent form drag
real(kind=kind_phys), parameter :: dxmin_ss = 1000., dxmax_ss = 12000. ! min,max range of tapering (m)
! meso-scale GWD
real(kind=kind_phys), parameter :: dxmin_ls = 3000., dxmax_ls = 13000. ! min,max range of tapering (m)
real(kind=kind_phys), dimension(its:ite) :: ss_taper, ls_taper ! meso-scale tapering factors (-)
!
! Variables for limiting topographic standard deviation (var)
real(kind=kind_phys), parameter :: varmax_ss = 50., & ! varmax_ss not used
varmax_fd = 500., &
beta_fd = 0.2
!
real(kind=kind_phys) :: var_temp, var_temp2
!
! GSL surface drag options to regulate specific components
! Each component is tapered off automatically as a function of dx, so best to
! keep them activated (=1).
integer, parameter :: &
ugwp_ms = 1, & ! meso-scale gravity wave drag
ugwp_bl = 1, & ! blocking drag
ugwp_ss = 1, & ! small-scale gravity wave drag (Steeneveld et al. 2008)
ugwp_fd = 1 ! form drag (Beljaars et al. 2004, QJRMS)
!
real(kind=kind_phys), parameter :: ric = 0.25 ! critical richardson number
real(kind=kind_phys), parameter :: dw2min = 1.
real(kind=kind_phys), parameter :: rimin = -100.
real(kind=kind_phys), parameter :: bnv2min = 1.0e-5
real(kind=kind_phys), parameter :: efmin = 0.0
real(kind=kind_phys), parameter :: efmax = 10.0
real(kind=kind_phys), parameter :: xl = 4.0e4
real(kind=kind_phys), parameter :: critac = 1.0e-5
real(kind=kind_phys), parameter :: gmax = 1.
real(kind=kind_phys), parameter :: veleps = 1.0
real(kind=kind_phys), parameter :: factop = 0.5
real(kind=kind_phys), parameter :: frc = 1.0
real(kind=kind_phys), parameter :: ce = 0.8
real(kind=kind_phys), parameter :: cg = 0.5
real(kind=kind_phys), parameter :: sgmalolev = 0.5 ! max sigma lvl for dtfac
real(kind=kind_phys), parameter :: plolevmeso = 70.0 ! pres lvl for mesosphere OGWD reduction (Pa)
real(kind=kind_phys), parameter :: facmeso = 0.5 ! fractional velocity reduction for OGWD
integer,parameter :: kpblmin = 2
!
! local variables
!
integer :: kpblmax
integer :: latd,lond
integer :: i,k,lcap,lcapp1,nwd,idir, &
klcap,kp1,ikount,kk
!
real(kind=kind_phys) :: fdir,cs,rcsks, &
wdir,ti,rdz,temp,tem2,dw2,shr2,bvf2,rdelks, &
wtkbj,tem,gfobnv,hd,fro,rim,temc,tem1,efact, &
temv,ksmax,dtfac_meso
!
real(kind=kind_phys), dimension(its:ite,kts:kte) :: dudt, dvdt
real(kind=kind_phys), dimension(its:ite,kts:kte) :: dtaux2d_ls, dtauy2d_ls, &
dtaux2d_bl, dtauy2d_bl
real(kind=kind_phys), dimension(its:ite) :: dusfc, dvsfc
real(kind=kind_phys) :: dtaux, dtauy
logical, dimension(its:ite) :: ldrag, icrilv, flag,kloop1
logical :: prop_test
real(kind=kind_phys), dimension(its:ite) :: coefm
!
real(kind=kind_phys), dimension(its:ite) :: taub, xn, yn, ubar, vbar, fr, &
ulow, rulow, bnv, rhobar, &
oa, ol, oass, olss, &
dtfac, brvf, xlinv, delks,delks1, &
zlowtop, govrth
real(kind=kind_phys) :: cleff, blk_coeff
real(kind=kind_phys), dimension(its:ite,kts:kte+1) :: taup
real(kind=kind_phys), dimension(its:ite,kts:kte-1) :: velco
real(kind=kind_phys), dimension(its:ite,kts:kte) :: bnv2, usqj, taud_ls, taud_bl, &
rho, vtk, vtj
real(kind=kind_phys), dimension(its:ite,kts:kte) :: del
real(kind=kind_phys), dimension(its:ite,kts:kte) :: u1, v1
real(kind=kind_phys), dimension(its:ite,4) :: oa4, ol4
real(kind=kind_phys), dimension(its:ite,4) :: oa4ss, ol4ss
!
real(kind=kind_phys) :: inv_g ! inverse of gravity
!
integer, dimension(its:ite) :: kbl, klowtop
integer, parameter :: mdir=8
integer, dimension(mdir) :: nwdir
data nwdir/6,7,5,8,2,3,1,4/
!
real(kind=kind_phys) :: xnbv, tauwavex0, tauwavey0
real(kind=kind_phys), dimension(its:ite,kts:kte) :: utendwave, vtendwave, &
utendform, vtendform, &
thx, thvx
real(kind=kind_phys) :: a1, a2, wsp, H_efold, hpbl2, &
tvcon
real(kind=kind_phys), parameter :: coeff_fd = 6.325e-3_kind_phys ! TOFD coefficient group
real(kind=kind_phys) :: alpha_fd ! alpha coefficient from Beljaars et al. (2004)
integer :: kpbl2,kvar
real(kind=kind_phys), dimension(its:ite,kts:kte) :: za ! height AGL of layer centers (m)
real(kind=kind_phys) :: zs ! height MSL of surface (m)
!
! variables for flow-blocking drag
!
real(kind=kind_phys), parameter :: frmax = 10.
real(kind=kind_phys), parameter :: olmin = 1.0e-5
real(kind=kind_phys), parameter :: odmin = 0.1
real(kind=kind_phys), parameter :: odmax = 10.
!
real(kind=kind_phys) :: fbdcd
real(kind=kind_phys) :: zblk, tautem
real(kind=kind_phys) :: pe, ke
real(kind=kind_phys) :: fbdpe, fbdke
real(kind=kind_phys), dimension(its:ite) :: delx, dely
real(kind=kind_phys), dimension(its:ite,4) :: dxy4, dxy4p
real(kind=kind_phys), dimension(4) :: ol4p
real(kind=kind_phys), dimension(its:ite) :: dxy, dxyp, olp, od
real(kind=kind_phys), dimension(its:ite,kts:kte+1) :: taufb
!
integer, dimension(its:ite) :: komax
integer :: kblk
real(kind=kind_phys) :: cd
!
! misc. coefficients
!
real(kind=kind_phys), parameter :: &
a1_coeff = 0.00026615161, & ! Coefficient for TOFD from Beljaars et al. (2004)
a2_coeff = 0.005363 ! ""
!-------------------------------------------------------------------------------
!
! constants
!
lcap = kte
lcapp1 = lcap + 1
fdir = mdir / (2.0*pi_)
inv_g = 1.0/g_
!
! initialize CCPP error flag and message
!
errmsg = ''
errflg = 0
!
!--- calculate scale-aware tapering factors
!
do i = its,ite
if ( dxmeter(i) .ge. dxmax_ls ) then
ls_taper(i) = 1.
else
if ( dxmeter(i) .le. dxmin_ls) then
ls_taper(i) = 0.
else
ls_taper(i) = 0.5 * ( sin(pi_*(dxmeter(i)-0.5*(dxmax_ls+dxmin_ls))/ &
(dxmax_ls-dxmin_ls)) + 1. )
end if
end if
enddo
! Remove ss_tapering
ss_taper(:) = 1.
! Alpha coefficient for TOFD
alpha_fd = 12._kind_phys
!
! calculate length of grid for flow-blocking drag
!
delx(its:ite) = dxmeter(its:ite)
dely(its:ite) = dxmeter(its:ite)
dxy4(its:ite,1) = delx(its:ite)
dxy4(its:ite,2) = dely(its:ite)
dxy4(its:ite,3) = sqrt(delx(its:ite)**2. + dely(its:ite)**2.)
dxy4(its:ite,4) = dxy4(its:ite,3)
dxy4p(its:ite,1) = dxy4(its:ite,2)
dxy4p(its:ite,2) = dxy4(its:ite,1)
dxy4p(its:ite,3) = dxy4(its:ite,4)
dxy4p(its:ite,4) = dxy4(its:ite,3)
!
! initialize arrays, array syntax is OK for OpenMP since these are local
!
ldrag = .false. ; icrilv = .false. ; flag = .true.
!
klowtop = 0 ; kbl = 0
!
dtaux = 0. ; dtauy = 0. ; xn = 0. ; yn = 0.
ubar = 0. ; vbar = 0. ; rhobar = 0. ; ulow = 0.
oa = 0. ; ol = 0. ; oass = 0. ; olss = 0.
taub = 0.
!
usqj = 0. ; bnv2 = 0. ; vtj = 0. ; vtk = 0.
taup = 0. ; taud_ls = 0. ; taud_bl = 0.
dtaux3d = 0. ; dtauy3d = 0.
dtaux2d_ls = 0. ; dtauy2d_ls = 0. ; dtaux2d_bl = 0. ; dtauy2d_bl = 0.
!
dtfac = 1.0 ; xlinv = 1.0/xl
!
komax = 0
taufb = 0.0
!
dudt = 0.0 ; dvdt = 0.0
!
dusfc = 0.0 ; dvsfc = 0.0
dusfcg = 0.0 ; dvsfcg = 0.0
if ( ugwp_diags ) then
dusfc_ls = 0.0 ; dvsfc_ls = 0.0 ; dusfc_bl = 0.0 ; dvsfc_bl = 0.0
dusfc_ss = 0.0 ; dvsfc_ss = 0.0 ; dusfc_fd = 0.0 ; dvsfc_fd = 0.0
dtaux3d_ls = 0.0 ; dtauy3d_ls = 0.0 ; dtaux3d_bl = 0.0 ; dtauy3d_bl = 0.0
dtaux3d_ss = 0.0 ; dtauy3d_ss = 0.0 ; dtaux3d_fd = 0.0 ; dtauy3d_fd = 0.0
endif
!
do k = kts,kte
do i = its,ite
vtj(i,k) = t1(i,k) * (1.+fv_*q1(i,k))
vtk(i,k) = vtj(i,k) / prslk(i,k)
! Density (kg/m^3)
rho(i,k) = 1./rd_ * prsl(i,k) / vtj(i,k)
! Delta p (positive) between interfaces levels (Pa)
del(i,k) = prsi(i,k) - prsi(i,k+1)
! Earth-relative zonal and meridional winds (m/s)
u1(i,k) = uproj(i,k)*cosa(i) - vproj(i,k)*sina(i)
v1(i,k) = uproj(i,k)*sina(i) + vproj(i,k)*cosa(i)
enddo
enddo
!
! Calculate AGL heights of layer centers
!
do i = its,ite
zs = zl(i,1) - 0.5*dz(i,1) ! surface height (m MSL)
do k = kts,kte
za(i,k) = zl(i,k) - zs
enddo
enddo
!
do i = its,ite
zlowtop(i) = 2. * var(i)
enddo
!
do i = its,ite
kloop1(i) = .true.
enddo
!
do k = kts+1,kte
do i = its,ite
if(zlowtop(i) .gt. 0.) then
if (kloop1(i).and.zl(i,k)-zl(i,1).ge.zlowtop(i)) then
klowtop(i) = k+1
kloop1(i) = .false.
endif
endif
enddo
enddo
!
kpblmax = kte
do i = its,ite
kbl(i) = max(kpbl(i), klowtop(i))
kbl(i) = max(min(kbl(i),kpblmax),kpblmin)
enddo
!
! determine the level of maximum orographic height
!
! komax(:) = kbl(:)
komax(:) = klowtop(:) - 1 ! modification by NOAA/GSL March 2018
!
do i = its,ite
delks(i) = 1.0 / (prsi(i,1) - prsi(i,kbl(i)))
delks1(i) = 1.0 / (prsl(i,1) - prsl(i,kbl(i)))
enddo
!
! compute low level averages within pbl
!
do k = kts,kpblmax
do i = its,ite
if (k.lt.kbl(i)) then
rcsks = del(i,k) * delks(i)
rdelks = del(i,k) * delks(i)
ubar(i) = ubar(i) + rcsks * u1(i,k) ! pbl u mean
vbar(i) = vbar(i) + rcsks * v1(i,k) ! pbl v mean
rhobar(i) = rhobar(i) + rdelks * rho(i,k) ! pbl rho mean
endif
enddo
enddo
!
! figure out low-level horizontal wind direction
!
! nwd 1 2 3 4 5 6 7 8
! wd w s sw nw e n ne se
!
do i = its,ite
oa4(i,1) = oa2d1(i)
oa4(i,2) = oa2d2(i)
oa4(i,3) = oa2d3(i)
oa4(i,4) = oa2d4(i)
ol4(i,1) = ol2d1(i)
ol4(i,2) = ol2d2(i)
ol4(i,3) = ol2d3(i)
ol4(i,4) = ol2d4(i)
oa4ss(i,1) = oa2d1ss(i)
oa4ss(i,2) = oa2d2ss(i)
oa4ss(i,3) = oa2d3ss(i)
oa4ss(i,4) = oa2d4ss(i)
ol4ss(i,1) = ol2d1ss(i)
ol4ss(i,2) = ol2d2ss(i)
ol4ss(i,3) = ol2d3ss(i)
ol4ss(i,4) = ol2d4ss(i)
wdir = atan2(ubar(i),vbar(i)) + pi_
idir = mod(nint(fdir*wdir),mdir) + 1
nwd = nwdir(idir)
oa(i) = (1-2*int( (nwd-1)/4 )) * oa4(i,mod(nwd-1,4)+1)
ol(i) = ol4(i,mod(nwd-1,4)+1)
! Repeat for small-scale gwd
oass(i) = (1-2*int( (nwd-1)/4 )) * oa4ss(i,mod(nwd-1,4)+1)
olss(i) = ol4ss(i,mod(nwd-1,4)+1)
!
! compute orographic width along (ol) and perpendicular (olp) the wind direction
!
ol4p(1) = ol4(i,2)
ol4p(2) = ol4(i,1)
ol4p(3) = ol4(i,4)
ol4p(4) = ol4(i,3)
olp(i) = ol4p(mod(nwd-1,4)+1)
!
! compute orographic direction (horizontal orographic aspect ratio)
!
od(i) = olp(i)/max(ol(i),olmin)
od(i) = min(od(i),odmax)
od(i) = max(od(i),odmin)
!
! compute length of grid in the along(dxy) and cross(dxyp) wind directions
!
dxy(i) = dxy4(i,MOD(nwd-1,4)+1)
dxyp(i) = dxy4p(i,MOD(nwd-1,4)+1)
enddo
!
! END INITIALIZATION; BEGIN GWD CALCULATIONS:
!
if ( (ugwp_ms .eq. 1).or.(ugwp_bl .eq. 1) ) then
do i = its,ite
if ( ls_taper(i) .gt. 1.e-02 ) then !====
!
! saving richardson number in usqj for migwdi
!
do k = kts,kte-1
ti = 2.0 / (t1(i,k)+t1(i,k+1))
rdz = 1./(zl(i,k+1) - zl(i,k))
tem1 = u1(i,k) - u1(i,k+1)
tem2 = v1(i,k) - v1(i,k+1)
dw2 = tem1*tem1 + tem2*tem2
shr2 = max(dw2,dw2min) * rdz * rdz
bvf2 = g_*(g_/cp_+rdz*(vtj(i,k+1)-vtj(i,k))) * ti
usqj(i,k) = max(bvf2/shr2,rimin)
bnv2(i,k) = 2.0*g_*rdz*(vtk(i,k+1)-vtk(i,k))/(vtk(i,k+1)+vtk(i,k))
bnv2(i,k) = max( bnv2(i,k), bnv2min )
enddo
!
! compute the "low level" or 1/3 wind magnitude (m/s)
!
ulow(i) = max(sqrt(ubar(i)*ubar(i) + vbar(i)*vbar(i)), 1.0)
rulow(i) = 1./ulow(i)
!
do k = kts,kte-1
velco(i,k) = 0.5 * ((u1(i,k)+u1(i,k+1)) * ubar(i) &
+ (v1(i,k)+v1(i,k+1)) * vbar(i))
velco(i,k) = velco(i,k) * rulow(i)
if ((velco(i,k).lt.veleps) .and. (velco(i,k).gt.0.)) then
velco(i,k) = veleps
endif
enddo
!
! no drag when critical level in the base layer
!
ldrag(i) = velco(i,1).le.0.
!
! no drag when velco.lt.0
!
do k = kpblmin,kpblmax
if (k .lt. kbl(i)) ldrag(i) = ldrag(i) .or. velco(i,k).le.0.
enddo
!
! the low level weighted average ri is stored in usqj(1,1; im)
! the low level weighted average n**2 is stored in bnv2(1,1; im)
! this is called bnvl2 in phy_gwd_alpert_sub not bnv2
! rdelks (del(k)/delks) vert ave factor so we can * instead of /
!
wtkbj = (prsl(i,1)-prsl(i,2)) * delks1(i)
bnv2(i,1) = wtkbj * bnv2(i,1)
usqj(i,1) = wtkbj * usqj(i,1)
!
do k = kpblmin,kpblmax
if (k .lt. kbl(i)) then
rdelks = (prsl(i,k)-prsl(i,k+1)) * delks1(i)
bnv2(i,1) = bnv2(i,1) + bnv2(i,k) * rdelks
usqj(i,1) = usqj(i,1) + usqj(i,k) * rdelks
endif
enddo
!
ldrag(i) = ldrag(i) .or. bnv2(i,1).le.0.0
ldrag(i) = ldrag(i) .or. ulow(i).eq.1.0
ldrag(i) = ldrag(i) .or. var(i) .le. 0.0
! Check if mesoscale gravity waves will propagate vertically or be evanescent
! and not impart a drag force -- consider the maximum sub-grid horizontal
! topographic wavelength to be one-half the horizontal grid spacing -- calculate
! ksmax accordingly
ksmax = 4.0*pi_/dxmeter(i) ! based on wavelength = 0.5*dx(i)
if ( bnv2(i,1).gt.0.0 ) then
ldrag(i) = ldrag(i) .or. sqrt(bnv2(i,1))*rulow(i).lt.ksmax
endif
!
! set all ri low level values to the low level value
!
do k = kpblmin,kpblmax
if (k .lt. kbl(i)) usqj(i,k) = usqj(i,1)
enddo
!
if (.not.ldrag(i)) then
bnv(i) = sqrt( bnv2(i,1) )
fr(i) = bnv(i) * rulow(i) * var(i) * od(i)
fr(i) = min(fr(i),frmax)
xn(i) = ubar(i) * rulow(i)
yn(i) = vbar(i) * rulow(i)
endif
!
! compute the base level stress and store it in taub
! calculate enhancement factor, number of mountains & aspect
! ratio const. use simplified relationship between standard
! deviation & critical hgt
!
if (.not. ldrag(i)) then
efact = (oa(i) + 2.) ** (ce*fr(i)/frc)
efact = min( max(efact,efmin), efmax )
!!!!!!! cleff ("effective grid length") is highly tunable parameter
! Note: Based on tuning of FV3GFS by NOAA/GSL, the "effective length"
! is assumed constant and is tied to a "typical" horizontal wavenumber
! of topography. The relationship between this wavenumber and the
! the grid spacing is unknown at this point. A future GWD parameterization
! will need to take the Fourier breakdown of subgrid topography into account.
! For now, we are using a valuable that gives suitable results based on the
! COORDE model intercomparison article by van Niekerk et al. (2020).
! Also note that this is the inverse of the "cleff" in Kim and Doyle (2005).
cleff = 8.84e-6_kind_phys
coefm(i) = (1. + ol(i)) ** (oa(i)+1.)
xlinv(i) = coefm(i) * cleff
tem = fr(i) * fr(i) * oc1(i)
gfobnv = gmax * tem / ((tem + cg)*bnv(i))
if ( ugwp_ms .NE. 0 ) then
taub(i) = xlinv(i) * rhobar(i) * ulow(i) * ulow(i) &
* ulow(i) * gfobnv * efact
else ! We've gotten what we need for the blocking scheme
taub(i) = 0.0
end if
else
taub(i) = 0.0
xn(i) = 0.0
yn(i) = 0.0
endif
endif ! if ( ls_taper(i) .gt. 1.e-02 )
enddo ! do i = its,ite
endif ! (ugwp_ms .eq. 1).or.(ugwp_bl .eq. 1)
!=========================================================
! add small-scale wavedrag for stable boundary layer
!=========================================================
xnbv=0.
tauwavex0=0.
tauwavey0=0.
utendwave=0.
vtendwave=0.
!
if ( ugwp_ss .eq. 1 ) then
do i = its,ite
if ( ss_taper(i) .gt. 1.e-02 ) then
!
! calculating potential temperature
!
do k = kts,kte
thx(i,k) = t1(i,k)/prslk(i,k)
enddo
!
do k = kts,kte
tvcon = (1.+fv_*q1(i,k))
thvx(i,k) = thx(i,k)*tvcon
enddo
!
hpbl2 = hpbl(i)+10.
kpbl2 = kpbl(i)
!kvar = MIN(kpbl, k-level of var)
kvar = 1
do k=kts+1,MAX(kpbl(i),kts+1)
! if (za(i,k)>2.*var(i) .or. za(i,k)>2*varmax) then
if (za(i,k)>300.) then
kpbl2 = k
if (k == kpbl(i)) then
hpbl2 = hpbl(i)+10.
else
hpbl2 = za(i,k)+10.
endif
exit
endif
enddo
if ((xland1(i)-1.5).le.0. .and. 2.*varss(i).le.hpbl(i)) then
if (br1(i).gt.0. .and. thvx(i,kpbl2)-thvx(i,kts) > 0.) then
! Modify xlinv to represent wave number of "typical" small-scale topography
! cleff_ss = 3. * max(dx(i),cleff_ss)
! cleff_ss = 10. * max(dxmax_ss,cleff_ss)
! cleff_ss = 0.1 * 12000.
xlinv(i) = 0.001*pi_ ! 2km horizontal wavelength
govrth(i)=g_/(0.5*(thvx(i,kpbl2)+thvx(i,kts)))
xnbv=sqrt(govrth(i)*(thvx(i,kpbl2)-thvx(i,kts))/hpbl2)
!
! check for possibility of vertical wave propagation
! (avoids division by zero if u1(i,kpbl2).eq.0.)
if (u1(i,kpbl2).eq.0.) then
prop_test = .true.
elseif (abs(xnbv/u1(i,kpbl2)).gt.xlinv(i)) then
prop_test = .true.
else
prop_test = .false.
endif
if (prop_test) then
! Remove limit on varss
var_temp = varss(i)
! Note: This is a semi-implicit treatment of the time differencing
var_temp2 = 0.5*xnbv*xlinv(i)*(2.*var_temp)**2*rho(i,kvar) ! this is greater than zero
tauwavex0=var_temp2*u1(i,kvar)/(1.+var_temp2*deltim)
tauwavex0=tauwavex0*ss_taper(i)
else
tauwavex0=0.
endif
!
! check for possibility of vertical wave propagation
! (avoids division by zero if v1(i,kpbl2).eq.0.)
if (v1(i,kpbl2).eq.0.) then
prop_test = .true.
elseif (abs(xnbv/v1(i,kpbl2)).gt.xlinv(i)) then
prop_test = .true.
else
prop_test = .false.
endif
if (prop_test) then
! Remove limit on varss
var_temp = varss(i)
! Note: This is a semi-implicit treatment of the time differencing
var_temp2 = 0.5*xnbv*xlinv(i)*(2.*var_temp)**2*rho(i,kvar) ! this is greater than zero
tauwavey0=var_temp2*v1(i,kvar)/(1.+var_temp2*deltim)
tauwavey0=tauwavey0*ss_taper(i)
else
tauwavey0=0.
endif
do k=kts,kpbl(i) !MIN(kpbl2+1,km-1)
!original
!utendwave(i,k)=-1.*tauwavex0*2.*max((1.-za(i,k)/hpbl(i)),0.)/hpbl(i)
!vtendwave(i,k)=-1.*tauwavey0*2.*max((1.-za(i,k)/hpbl(i)),0.)/hpbl(i)
!new
utendwave(i,k)=-1.*tauwavex0*2.*max((1.-za(i,k)/hpbl2),0.)/hpbl2
vtendwave(i,k)=-1.*tauwavey0*2.*max((1.-za(i,k)/hpbl2),0.)/hpbl2
!mod-to be used in HRRRv3/RAPv4
!utendwave(i,k)=-1.*tauwavex0 * max((1.-za(i,k)/hpbl2),0.)**2
!vtendwave(i,k)=-1.*tauwavey0 * max((1.-za(i,k)/hpbl2),0.)**2
enddo
endif
endif
do k = kts,kte
dudt(i,k) = dudt(i,k) + utendwave(i,k)
dvdt(i,k) = dvdt(i,k) + vtendwave(i,k)
dtaux3d(i,k) = dtaux3d(i,k) + utendwave(i,k)
dtauy3d(i,k) = dtauy3d(i,k) + vtendwave(i,k)
dusfc(i) = dusfc(i) + utendwave(i,k) * del(i,k)
dvsfc(i) = dvsfc(i) + vtendwave(i,k) * del(i,k)
enddo
if ( ugwp_diags ) then
do k = kts,kte
dtaux3d_ss(i,k) = utendwave(i,k)
dtauy3d_ss(i,k) = vtendwave(i,k)
dusfc_ss(i) = dusfc_ss(i) + utendwave(i,k) * del(i,k)
dvsfc_ss(i) = dvsfc_ss(i) + vtendwave(i,k) * del(i,k)
enddo
endif
endif ! if ( ss_taper(i) .gt. 1.e-02 ) then
enddo ! i = its,ite
endif ! ( ugwp_ss .eq. 1 )
!===================================================================
! Topographic Form Drag from Beljaars et al. (2004, QJRMS, equ. 16):
!===================================================================
if ( ugwp_fd .eq. 1 ) THEN
do i=its,ite
if ( ss_taper(i).gt.1.E-02 ) then
utendform=0.
vtendform=0.
if ((xland1(i)-1.5) .le. 0.) then
!(IH*kflt**n1)**-1 = (0.00102*0.00035**-1.9)**-1 = 0.00026615161
var_temp = min(varss(i),varmax_fd) + &
max(0.,beta_fd*(varss(i)-varmax_fd))
a1=a1_coeff*var_temp**2
! a1=0.00026615161*MIN(varss(i),varmax)**2
! a1=0.00026615161*(0.5*varss(i))**2
! k1**(n1-n2) = 0.003**(-1.9 - -2.8) = 0.003**0.9 = 0.005363
a2=a1*a2_coeff
! Beljaars H_efold
H_efold = 1500.
do k=kts,kte
wsp=sqrt(u1(i,k)**2 + v1(i,k)**2)
! Note: In Beljaars et al. (2004):
! alpha_fd*beta*Cmd*Ccorr*2.109 = 12.*1.*0.005*0.6*2.109 = 0.0759
! lump beta*Cmd*Ccorr*2.109 into 1.*0.005*0.6*2.109 = coeff_fd ~ 6.325e-3_kind_phys
var_temp = alpha_fd*coeff_fd*EXP(-(za(i,k)/H_efold)**1.5)*a2* &
za(i,k)**(-1.2)*ss_taper(i) ! this is greater than zero
! Note: This is a semi-implicit treatment of the time differencing
! per Beljaars et al. (2004, QJRMS)
utendform(i,k) = - var_temp*wsp*u1(i,k)/(1. + var_temp*deltim*wsp)
vtendform(i,k) = - var_temp*wsp*v1(i,k)/(1. + var_temp*deltim*wsp)
if (za(i,k)/H_efold > 4.) exit
enddo
endif
do k = kts,kte
dudt(i,k) = dudt(i,k) + utendform(i,k)
dvdt(i,k) = dvdt(i,k) + vtendform(i,k)
dtaux3d(i,k) = dtaux3d(i,k) + utendform(i,k)
dtauy3d(i,k) = dtauy3d(i,k) + vtendform(i,k)
dusfc(i) = dusfc(i) + utendform(i,k) * del(i,k)
dvsfc(i) = dvsfc(i) + vtendform(i,k) * del(i,k)
enddo
if ( ugwp_diags ) then
do k = kts,kte
dtaux3d_fd(i,k) = utendform(i,k)
dtauy3d_fd(i,k) = vtendform(i,k)
dusfc_fd(i) = dusfc_fd(i) + utendform(i,k) * del(i,k)
dvsfc_fd(i) = dvsfc_fd(i) + vtendform(i,k) * del(i,k)
enddo
endif
endif ! if (ss_taper(i).gt.1.E-02)
enddo ! i=its,ite
endif ! if ( ugwp_fd .eq. 1 )
if ( ugwp_diags ) then
! Finalize dusfc and dvsfc diagnostics for gsl small-scale drag components
dusfc_ss(:) = -inv_g * dusfc_ss(:)
dvsfc_ss(:) = -inv_g * dvsfc_ss(:)
dusfc_fd(:) = -inv_g * dusfc_fd(:)
dvsfc_fd(:) = -inv_g * dvsfc_fd(:)
endif
!=======================================================
! More for the meso-scale gwd component
if ( ugwp_ms.eq.1 ) then
do i=its,ite
if ( ls_taper(i).gt.1.e-02 ) then
!
! now compute vertical structure of the stress.
!
do k = kts,kpblmax
if (k .le. kbl(i)) taup(i,k) = taub(i)
enddo
!
do k = kpblmin, kte-1 ! vertical level k loop!
kp1 = k + 1
!
! unstablelayer if ri < ric
! unstable layer if upper air vel comp along surf vel <=0 (crit lay)
! at (u-c)=0. crit layer exists and bit vector should be set (.le.)
!
if (k .ge. kbl(i)) then
icrilv(i) = icrilv(i) .or. ( usqj(i,k) .lt. ric) &
.or. (velco(i,k) .le. 0.0)
brvf(i) = max(bnv2(i,k),bnv2min) ! brunt-vaisala frequency squared
brvf(i) = sqrt(brvf(i)) ! brunt-vaisala frequency
endif
!
if (k .ge. kbl(i) .and. (.not. ldrag(i))) then
if (.not.icrilv(i) .and. taup(i,k) .gt. 0.0 ) then
temv = 1.0 / velco(i,k)
tem1 = coefm(i)/dxy(i)*(rho(i,kp1)+rho(i,k))*brvf(i)* &
velco(i,k)*0.5
hd = sqrt(taup(i,k) / tem1)
fro = brvf(i) * hd * temv
!
! rim is the minimum-richardson number by shutts (1985)
!
tem2 = sqrt(usqj(i,k))
tem = 1. + tem2 * fro
rim = usqj(i,k) * (1.-fro) / (tem * tem)
!
! check stability to employ the 'saturation hypothesis'
! of lindzen (1981) except at tropospheric downstream regions
!
if (rim .le. ric) then ! saturation hypothesis!
if ((oa(i) .le. 0.).or.(kp1 .ge. kpblmin )) then
temc = 2.0 + 1.0 / tem2
hd = velco(i,k) * (2.*sqrt(temc)-temc) / brvf(i)
taup(i,kp1) = tem1 * hd * hd
endif
else ! no wavebreaking!
taup(i,kp1) = taup(i,k)
endif
endif
endif
enddo ! k = kpblmin, kte-1
!
if (lcap.lt.kte) then
do klcap = lcapp1,kte
taup(i,klcap) = prsi(i,klcap) / prsi(i,lcap) * taup(i,lcap)
enddo
endif
endif ! if ( ls_taper(i).gt.1.e-02 )
enddo ! do i=its,ite
endif ! if ( ugwp_ms.eq.1 )
!===============================================================
!COMPUTE BLOCKING COMPONENT
!===============================================================
if ( ugwp_bl .eq. 1 ) then
! NOAA/GSL has modified blocking by removing dependency on grid spacing
! as in Lott and Miller (1997)
! Based on tuning the FV3GFS a coefficient has been found to give a physically
! reasonable value for blocking similar to that of Lott and Miller (1997)
blk_coeff = 1.92e-4_kind_phys
do i = its,ite
if ( ls_taper(i).gt.1.e-02 ) then
if (.not.ldrag(i)) then
!
!------- determine the height of flow-blocking layer
!
kblk = 0
pe = 0.0
do k = kte, kpblmin, -1
if(kblk.eq.0 .and. k.le.komax(i)) then
pe = pe + bnv2(i,k)*(zl(i,komax(i))-zl(i,k))*del(i,k)/g_/rho(i,k)
ke = 0.5*((u1(i,k))**2.+(v1(i,k))**2.)
!
!---------- apply flow-blocking drag when pe >= ke
!
if(pe.ge.ke) then
kblk = k
kblk = min(kblk,kbl(i))
zblk = za(i,kblk)
endif
endif
enddo
if(kblk.ne.0) then
!
!--------- compute flow-blocking stress
!
cd = max(2.0-1.0/od(i),0.0)
taufb(i,kts) = 0.5 * blk_coeff * rhobar(i) * coefm(i) * cd &
* olp(i) * zblk * ulow(i)**2
tautem = taufb(i,kts)/float(kblk-kts)
do k = kts+1, kblk
taufb(i,k) = taufb(i,k-1) - tautem
enddo
!
!----------sum orographic GW stress and flow-blocking stress
!
! taup(i,:) = taup(i,:) + taufb(i,:) ! Keep taup and taufb separate for now
endif
!
endif ! if (.not.ldrag(i))
endif ! if ( ls_taper(i).gt.1.e-02 )
enddo ! i = its,ite
endif ! if ( ugwp_bl .eq. 1 ) -- end blocking drag
!===========================================================
do i = its,ite
if ( (ugwp_ms .eq. 1 .or. ugwp_bl .eq. 1) .and. (ls_taper(i) .gt. 1.E-02) ) then
!
! calculate - (g)*d(tau)/d(pressure) and deceleration terms dtaux, dtauy
!
! First, set taup (momentum flux) at model top equal to that of the layer
! interface just below the top, i.e., taup(kte)
! The idea is to allow the momentum flux to go out the 'top'. This
! ensures there is no GWD force at the top layer.
!
taup(i,kte+1) = taup(i,kte)
do k = kts,kte
taud_ls(i,k) = 1. * (taup(i,k+1) - taup(i,k)) * g_ / del(i,k)
taud_bl(i,k) = 1. * (taufb(i,k+1) - taufb(i,k)) * g_ / del(i,k)
enddo
!
!
! if the gravity wave drag + blocking would force a critical line
! in the layers below pressure-based 'sigma' level = sgmalolev during the next deltim
! timestep, then only apply drag until that critical line is reached, i.e.,
! reduce drag to limit resulting wind components to zero
! Note: 'sigma' = prsi(k)/prsi(k=1), where prsi(k=1) is the surface pressure
!
do k = kts,kpblmax-1
if (prsi(i,k).ge.sgmalolev*prsi(i,1)) then
if ((taud_ls(i,k)+taud_bl(i,k)).ne.0.) &
dtfac(i) = min(dtfac(i),abs(velco(i,k) &
/(deltim*(taud_ls(i,k)+taud_bl(i,k)))))
else
exit
endif
enddo
!
do k = kts,kte
! Check if well into mesosphere -- if so, perform similar reduction of
! velocity tendency due to mesoscale GWD to prevent sudden reversal of
! wind direction (similar to above)
dtfac_meso = 1.0
if (prsl(i,k).le.plolevmeso) then
if (taud_ls(i,k).ne.0.) &
dtfac_meso = min(dtfac_meso,facmeso*abs(velco(i,k) &
/(deltim*taud_ls(i,k))))
endif
taud_ls(i,k) = taud_ls(i,k) * dtfac(i) * dtfac_meso * ls_taper(i)
taud_bl(i,k) = taud_bl(i,k) * dtfac(i) * dtfac_meso * ls_taper(i)
dtaux2d_ls(i,k) = taud_ls(i,k) * xn(i)
dtauy2d_ls(i,k) = taud_ls(i,k) * yn(i)
dtaux2d_bl(i,k) = taud_bl(i,k) * xn(i)
dtauy2d_bl(i,k) = taud_bl(i,k) * yn(i)
dudt(i,k) = dtaux2d_ls(i,k) + dtaux2d_bl(i,k) + dudt(i,k)
dvdt(i,k) = dtauy2d_ls(i,k) + dtauy2d_bl(i,k) + dvdt(i,k)
dtaux3d(i,k) = dtaux3d(i,k) + dtaux2d_ls(i,k) + dtaux2d_bl(i,k)
dtauy3d(i,k) = dtauy3d(i,k) + dtauy2d_ls(i,k) + dtauy2d_bl(i,k)
dusfc(i) = dusfc(i) + (dtaux2d_ls(i,k)+dtaux2d_bl(i,k))*del(i,k)
dvsfc(i) = dvsfc(i) + (dtauy2d_ls(i,k)+dtauy2d_bl(i,k))*del(i,k)
enddo