forked from NordicESMhub/OsloCTM3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpbl_mixing.f90
1636 lines (1476 loc) · 60.2 KB
/
pbl_mixing.f90
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
!//=========================================================================
!// Oslo CTM3
!//=========================================================================
!// Amund Sovde Haslerud, November 2017
!//=========================================================================
!// Planetary boundary layer mixing.
!//=========================================================================
module pbl_mixing
!// ----------------------------------------------------------------------
!// MODULE: pbl_mixing
!// DECRIPTION: Routine for PBL mixing.
!//
!// This is the UCI p-pbl.f rewritten to f90, and including Holtslag
!// kprof from an earlier UCI version.
!// It uses e.g. KC(2), PRANDTL(1) and MO_LEN
!//
!// Contains
!// subroutine CNVDBL
!// subroutine BULK
!// subroutine get_keddy_L1
!// subroutine KPROF2
!// subroutine KPROF
!// real(r8) function PHIM
!// real(r8) function PHIH
!// subroutine TRIDIAG
!// subroutine INTERP
!// subroutine QXZON
!// subroutine QZONX
!// ----------------------------------------------------------------------
use cmn_size, only: LPAR
!// ----------------------------------------------------------------------
implicit none
!// ----------------------------------------------------------------------
integer, parameter :: NSUB = 3, BLPAR = LPAR*NSUB
!// ----------------------------------------------------------------------
character(len=*), parameter, private :: f90file = 'pbl_mixing.f90'
!// ----------------------------------------------------------------------
private
public CNVDBL
!// ----------------------------------------------------------------------
contains
!// ----------------------------------------------------------------------
subroutine CNVDBL(BTT,BXT,BXX,BYT,BYY,BZT,BZZ,BXY,BXZ,BYZ,AIRB,DTPBL,MP)
!// --------------------------------------------------------------------
!// new subs for planetary boundary layer mixing of tracer:
!// step = DTPBL(sec)
!// UCI method currently only uses a simple e-fold to well mixed profile.
!// CTM3 uses Holtslag.
!//
!// Amund Sovde Haslerud, November 2017
!// Updated to make NBLX1 possible with Oslo chemistry.
!// --------------------------------------------------------------------
use cmn_precision, only: r8, rMom
use cmn_size, only: NPAR, IDBLK, JDBLK
use cmn_ctm, only: NBLX, MPBLKIB, MPBLKIE, MPBLKJB, MPBLKJE, &
ETAA, ETAB, NTM, DISTX, DISTY, JMON
use cmn_met, only: P, SHF, SFT, SFQ, SFU, SFV, SLH, SMF, USTR, &
BLH, PBL_KEDDY, MO_LENGTH, PRANDTLL1, ZOFLE, U, V, T, Q
use cmn_parameters, only: R_AIR
use cmn_sfc, only: ZOI
use utilities, only: moninobukhov_length
!// --------------------------------------------------------------------
implicit none
!// --------------------------------------------------------------------
!// Input
integer,intent(in) :: MP
real(r8), intent(in) :: DTPBL
real(r8), dimension(LPAR,IDBLK,JDBLK), intent(in) :: AIRB
!// Input/Output
real(r8), dimension(LPAR,NPAR,IDBLK,JDBLK), intent(inout) :: BTT
real(rMom), dimension(LPAR,NPAR,IDBLK,JDBLK), intent(inout) :: &
BXT, BXX, BYT, BYY, BZT, BZZ, BXY, BXZ, BYZ
!// Parameters
real(r8), parameter :: DT3HR = 10800._r8 ! 3-hr e-fold
!// Locals
integer :: NBL, I,II,J,JJ,L,N
real(r8), dimension(LPAR+1) :: POFL, DZL
real(r8), dimension(LPAR) :: &
QM, QTT, QZT,QZZ,QXZ,QYZ,QXT,QXX,QYT,QYY,QXY, QM2
real(r8) :: ZBL,ZCL,ZLL,ZF,ZPP,ZMF,XBL, UMIX, FMIX
real(r8) :: SFCP, SFCS, SFCT, SFCQ, SFCU, SFCV, SFCL, SFCM, SFCD
real(r8) :: SFMU, SFNU, USTAR, MO_LEN, PRTL1
!real(r8) :: ZO, ZOW
!// Additions for KPROF
real(r8), parameter :: VK = 0.4_r8
real(r8), dimension(LPAR) :: DP, UVEL, VVEL, TOFL,QVAP,QTMPT,QTMPM
real(r8) :: SFCTH, CNST, LV, TSV, MF, DZM
integer :: NBLP1, NGMAX, NG, MID, M, K
real(r8), dimension(NSUB) :: & ! used for QZONX/QXZON
PM, PTT, PXT, PXX, PYT, PYY, PXY, PZT, PZZ, PXZ, PYZ
real(r8), dimension(BLPAR) :: &
GM, GTT, GXT, GXX, GYT, GYY, GXY, &
ZMD, ZD, DUDZ, DVDZ, DQDZ, DTHDZ, &
KC, KCZ, &
GOUT, & ! new tracer
BU, BD, BL ! matrix coefficients
!// --------------------------------------------------------------------
character(len=*), parameter :: subr = 'CNVDBL'
!// --------------------------------------------------------------------
!// Initialise prandtL1
PrandtlL1(:,:,MP) = 0.85_r8
PBL_KEDDY(:,:,MP) = 1.e-19_r8
if (NBLX .eq. 1) then
!// NBLX=1 - Prather_s bulk scheme (on mean grid)
!// calculate e-fold to bulk-mixed in 3 hour
!FMIX = 1._r8 - exp(-DTPBL / DT3HR)
UMIX = exp(-DTPBL / DT3HR)
FMIX = 1._r8 - UMIX
do J = MPBLKJB(MP), MPBLKJE(MP)
JJ = J - MPBLKJB(MP) + 1
do I = MPBLKIB(MP), MPBLKIE(MP)
II = I - MPBLKIB(MP) + 1
!// Surface properties, all in SI units from met fields.
SFCP = 100._r8 * P(I,J) ! P(mbar) to SFCP (pascals)
SFCS = SHF(I,J) ! sensible heat flux (W/m2)
SFCT = SFT(I,J) ! surface temperature (K)
SFCQ = SFQ(I,J) ! surface (2-m?) Q, u, v
!SFCU = SFU(I,J)
!SFCV = SFV(I,J)
SFCL = SLH(I,J) ! latent heat flux (W/m2)
!SFCM = SMF(I,J) ! momentum flux = (u*)^2 * density
!// surface momentum flux (SMF) = density * ustar^2 ! m/s
USTAR = USTR(I,J)
if (USTAR.le.0._r8) USTAR = 5.e-3_r8 ! USTAR should not be zero
SFCD = SFCP/(SFCT * R_AIR) ! density ! kg/m^3
SFMU = 6.2e-8_r8*SFCT ! absol.visc. 6.2d-8*T (lin fit:-30C to +40C)
SFNU = SFMU / SFCD ! kinematic visc(nu) = mu/density (m*m/s)
MO_LENGTH(II,JJ,MP) = moninobukhov_length(SFCD,SFCT,USTAR,SFCS) ! M-O length
!ZO = ZOI(I,J,JMON) ! surface roughness (m)
!!// correct water surf roughness for wind/waves:
!ZOW = min(0.135_r8*SFNU/USTAR + 1.83e-3_r8*USTAR**2, 2.e-3_r8)
!// For keddy
!// surface momentum flux (SMF) = density * ustar^2 ! m/s
SFCTH = SFCT * ((1.e5_r8 / SFCP)**0.286_r8)
LV = (2.501_r8 &
- (2.37e-3_r8 * (SFCT - 273.16_r8)) ) * 1.e6_r8
TSV = SFCTH * (1._r8 + 0.61_r8 * SFCQ)
!// determine number (fraction) of CTM levels to mix (XBL)
!// - do local heights
ZBL = BLH(I,J)
if (ZBL .gt. 0._r8) then
do L = 1, LPAR+1
POFL(L) = ETAA(L) + ETAB(L)*P(I,J)
end do
do L = 1, LPAR
DZL(L) = ZOFLE(L+1,I,J) - ZOFLE(L,I,J)
end do
ZCL = min(ZOFLE(LPAR+1,I,J)-ZOFLE(1,I,J),ZBL)
ZLL = 0._r8
NBL = 1
do L = 1,LPAR
if (ZCL .ge. 0._r8) then
ZLL = ZCL
NBL = L
end if
ZCL = ZCL - DZL(L)
end do
!// altitude fraction of layer = NBL within the mixed PBL,
!// find mass fraction
ZF = ZLL / DZL(NBL)
ZPP = POFL(NBL+1) / POFL(NBL)
ZMF = (1._r8 - ZPP**ZF) / (1._r8 - ZPP)
!// NBL = no. layers completely in PBL, XBL = NBL + fraction
!// above NBL
NBL = NBL - 1
XBL = real(NBL, r8) + ZMF
!// Get PBL_KEDDY for model surface level, but use the height of 2/3
!// as when calculating KPROF in Holtslag-scheme.
call get_keddy_L1(PBL_KEDDY(II,JJ,MP), PrandtlL1(II,JJ,MP), USTAR, &
SFCS, (SFCL/LV), MO_LEN, ZBL, VK, 0.6666667_r8*DZL(1), TSV)
QM2(:) = AIRB(:,II,JJ)
do N = 1, NTM
! do L = 1, LPAR
! QM(L) = AIRB(L,II,JJ)
! QTT(L) = BTT(L,N,II,JJ)
! QZT(L) = BZT(L,N,II,JJ)
! QZZ(L) = BZZ(L,N,II,JJ)
! QXZ(L) = BXZ(L,N,II,JJ)
! QYZ(L) = BYZ(L,N,II,JJ)
! QXT(L) = BXT(L,N,II,JJ)
! QXX(L) = BXX(L,N,II,JJ)
! QYT(L) = BYT(L,N,II,JJ)
! QYY(L) = BYY(L,N,II,JJ)
! QXY(L) = BXY(L,N,II,JJ)
! end do
!// ASH 2017: I think this should be faster
QM(:) = QM2(:)
QTT(:) = BTT(:,N,II,JJ)
QZT(:) = BZT(:,N,II,JJ)
QZZ(:) = BZZ(:,N,II,JJ)
QXZ(:) = BXZ(:,N,II,JJ)
QYZ(:) = BYZ(:,N,II,JJ)
QXT(:) = BXT(:,N,II,JJ)
QXX(:) = BXX(:,N,II,JJ)
QYT(:) = BYT(:,N,II,JJ)
QYY(:) = BYY(:,N,II,JJ)
QXY(:) = BXY(:,N,II,JJ)
call BULK(QTT,QZT,QZZ,QXZ,QYZ,QXT,QXX,QYT,QYY,QXY,QM,XBL,LPAR)
!do L = 1, LPAR
! BTT(L,N,II,JJ) = QTT(L)*FMIX + BTT(L,N,II,JJ)*(1._r8-FMIX)
! BZT(L,N,II,JJ) = QZT(L)*FMIX + BZT(L,N,II,JJ)*(1._r8-FMIX)
! BZZ(L,N,II,JJ) = QZZ(L)*FMIX + BZZ(L,N,II,JJ)*(1._r8-FMIX)
! BXZ(L,N,II,JJ) = QXZ(L)*FMIX + BXZ(L,N,II,JJ)*(1._r8-FMIX)
! BYZ(L,N,II,JJ) = QYZ(L)*FMIX + BYZ(L,N,II,JJ)*(1._r8-FMIX)
! BXT(L,N,II,JJ) = QXT(L)*FMIX + BXT(L,N,II,JJ)*(1._r8-FMIX)
! BXX(L,N,II,JJ) = QXX(L)*FMIX + BXX(L,N,II,JJ)*(1._r8-FMIX)
! BYT(L,N,II,JJ) = QYT(L)*FMIX + BYT(L,N,II,JJ)*(1._r8-FMIX)
! BYY(L,N,II,JJ) = QYY(L)*FMIX + BYY(L,N,II,JJ)*(1._r8-FMIX)
! BXY(L,N,II,JJ) = QXY(L)*FMIX + BXY(L,N,II,JJ)*(1._r8-FMIX)
!end do
!// ASH 2017: I think this should be faster
BTT(:,N,II,JJ) = QTT(:)*FMIX + BTT(:,N,II,JJ)*UMIX
BZT(:,N,II,JJ) = QZT(:)*FMIX + BZT(:,N,II,JJ)*UMIX
BZZ(:,N,II,JJ) = QZZ(:)*FMIX + BZZ(:,N,II,JJ)*UMIX
BXZ(:,N,II,JJ) = QXZ(:)*FMIX + BXZ(:,N,II,JJ)*UMIX
BYZ(:,N,II,JJ) = QYZ(:)*FMIX + BYZ(:,N,II,JJ)*UMIX
BXT(:,N,II,JJ) = QXT(:)*FMIX + BXT(:,N,II,JJ)*UMIX
BXX(:,N,II,JJ) = QXX(:)*FMIX + BXX(:,N,II,JJ)*UMIX
BYT(:,N,II,JJ) = QYT(:)*FMIX + BYT(:,N,II,JJ)*UMIX
BYY(:,N,II,JJ) = QYY(:)*FMIX + BYY(:,N,II,JJ)*UMIX
BXY(:,N,II,JJ) = QXY(:)*FMIX + BXY(:,N,II,JJ)*UMIX
end do
!Should we set AIRB(:,II,JJ) = QM(:)
end if ! end of ZBL>0
end do ! J
end do ! I
else if (NBLX .eq. 5) then
!// Holtslag kprof
MID = int(NSUB/2) + 1
do J = MPBLKJB(MP), MPBLKJE(MP)
JJ = J - MPBLKJB(MP) + 1
do I = MPBLKIB(MP), MPBLKIE(MP)
II = I - MPBLKIB(MP) + 1
!// Surface properties (all in SI units from EC met)
SFCP = 100._r8 * P(I,J) ! P(mbar) to SFCP (pascals)
SFCS = SHF(I,J) ! sensible heat flux (W/m2)
SFCT = SFT(I,J) ! surface temperature (K)
SFCQ = SFQ(I,J) ! surface (2-m?) Q, u, v
SFCU = SFU(I,J)
SFCV = SFV(I,J)
SFCL = SLH(I,J) ! latent heat flux (W/m2)
SFCM = SMF(I,J) ! momentum flux = (u*)^2 * density
!// surface momentum flux (SMF) = density * ustar^2 ! m/s
USTAR = USTR(I,J)
if (USTAR.le.0._r8) USTAR = 5.e-3_r8 ! USTAR should not be zero
SFCD = SFCP / (SFCT * R_AIR) ! density (kg/m^3)
SFMU = 6.2e-8_r8*SFCT ! absol.visc. 6.2d-8*T (lin fit:-30C to +40C)
SFNU = SFMU / SFCD ! kinematic visc(nu) = mu/density (m*m/s)
MO_LEN = -256._r8 * SFCD * SFCT * (USTAR**3) / SFCS ! M-O length
if (MO_LEN .eq. 0._r8) then
write(6,'(a,2i5,4es16.6)') f90file//':'//subr//': MO_LEN is 0! -> 0.001: '// &
'NBLX,I,J,SFCD,SFCT,USTAR,SFCS',NBLX,I,J,SFCD,SFCT,USTAR,SFCS
MO_LEN = 1.e-3_r8
end if
if (MO_LEN .ne. MO_LEN) then
write(6,'(a,2i5,4es16.6)') f90file//':'//subr//': MO_LEN is 0! -> 1000: '// &
'NBLX,I,J,SFCD,SFCT,USTAR,SFCS',NBLX,I,J,SFCD,SFCT,USTAR,SFCS
MO_LEN = 1.e3_r8
end if
MO_LENGTH(II,JJ,MP) = MO_LEN !// Set MO-length
!ZO = ZOI(I,J,JMON) ! surface roughness (m)
!// correct water surf roughness for wind/waves:
!ZOW = 0.135_r8 * SFNU / USTAR + 1.83e-3_r8 * USTAR**2
!ZOW = min(ZOW, 2.e-3_r8)
!frac_n = DTCHM2 * (real(NSTEP, r8) - 0.5_r8) / real(DTMET, r8)
!ZBL = frac_c * BLH_CUR(I,J) + (1._r8 - frac_c) * BLH_NEXT(I,J)
!// check for non-zero PBL height (< 1 m)
ZBL = BLH(I,J)
if (ZBL .ge. 1._r8) then
!// Double the BLH; originally =min(BLH(I,J)*2._r8,9000._r8)
!// There may be problems with ZBL>8500, where NG may become too
!// large.
ZBL = min(ZBL * 2._r8, 8000._r8)
!// determine number of CTM levels to mix (XBL)
!// Collect column variables to calculate height of layers
!// POFL(L) is in mbar.
do L = 1, LPAR+1
POFL(L) = ETAA(L) + ETAB(L) * P(I,J)
end do
ZLL = 0._r8
do L = 1, LPAR
DP(L) = POFL(L) - POFL(L+1)
!// R = 287.*(1-Q) + 461.5*Q; assume 0.5% bl w.v.==> R = 288.
!// delta-z = dln(P) * R * T / g; where R/g = 288/9.81 = 29.36
DZL(L) = ZOFLE(L+1,I,J) - ZOFLE(L,I,J)
ZLL = ZOFLE(L+1,I,J) !// Top of layer
end do
!// determine number of CTM layers (1:NBL) to reach ht XBL
!// then subgrid levels (1:NG, based on subdividing CTM layers)
!// ZLL is top of layer L (in meters)
ZBL = min(ZLL, ZBL)
CNST = ZBL
NBL = 1
do L = 1, LPAR
if (CNST .ge. 0._r8) then
ZLL = CNST
NBL = L
end if
CNST = CNST - DZL(L)
end do
!// altitude fraction of boundary layer in layer NBL
!// containing PBL top
ZF = ZLL / DZL(NBL)
!// convert altitude fraction ZF to mass fraction MF
CNST = POFL(NBL+1) / POFL(NBL)
MF = (1._r8 - CNST**ZF) / (1._r8 - CNST)
!// NBL is no. of layers completely in PBL, XBL includes the
!// fraction above NBL
NBL = NBL - 1
XBL = real(NBL, r8) + MF
!// if boundary layer scheme = 2,3, or 4, then need to
!// subdivide and get data.
!// collect column variables for use in creating PBL profiles
do L = 1, LPAR
UVEL(L) = U(I,J,L) / (DP(L) * DISTY(J))
VVEL(L) = V(I,J,L) / (DP(L) * DISTX(J))
TOFL(L) = T(I,J,L)
QVAP(L) = Q(I,J,L)
end do
!// surface momentum flux (SMF) = density * ustar^2 ! m/s
SFCTH = SFCT * ((1.e5_r8 / SFCP)**0.286_r8)
LV = (2.501_r8 &
- (2.37e-3_r8 * (SFT(I,J) - 273.16_r8)) ) * 1.e6_r8
TSV = SFCTH * (1._r8 + 0.61_r8 * SFCQ)
!// assume all CTM layers divided into NSUB mass-equal levels
!// include partial layers in top box (NBL+1) only if mixed
!// through, i.e., keep only the NSUB layers fully included
!// in PBL.
NG = (NSUB*NBL) + int( (XBL - real(NBL,r8)) * real(NSUB,r8) )
if (NG .gt. 1) then
if (ng.gt.100) then
write(6,'(a,i4,es16.6,i4,3es16.6)') f90file//':'//subr// &
': HOLTSLAG: NG>100',ng,xbl,nbl,mf,zbl,zf
CNST = ZBL
NBL = 1
do L = 1, LPAR
if (CNST .ge. 0._r8) then
ZLL = CNST
NBL = L
end if
CNST = CNST - DZL(L)
if (NBL+1 .ge. L) &
write(6,'(a,3i4,es16.6,i4,2es16.6)') f90file//':'//subr// &
': NBL+1 > L:',I,J,L,DZL(L),NBL,CNST,dp(l)
end do
write(6,'(a,3i4,es16.6,i4,2es16.6)') 'Consider changing 100 closer' &
//' to BLPAR or lowering max BL height'
if (NG .gt. BLPAR) then
write(6,'(a,3i4,es16.6,i4,2es16.6)') f90file//':'//subr// &
': NG > BLPAR; indicating something is wrong.'
stop
end if
end if
!// note NMAX changed to NGMAX >= NG, which includes all
!// levels*NSUB
NBLP1 = min(LPAR, NBL+1)
NGMAX = NSUB * NBLP1
!// determine PBL profiles from similarity; Ekman solution
call INTERP(POFL,TOFL,QVAP,UVEL,VVEL,SFCQ,SFCU,SFCV,SFCTH, &
ZMD,ZD,DUDZ,DVDZ,DTHDZ,DQDZ,NSUB,NBLP1)
!// loop over tracers
QM2(:) = AIRB(:,II,JJ)
do N = 1, NTM
!do L = 1, LPAR
! QM(L) = AIRB(L,II,JJ)
! !// if there is a production P (kg/s): QTT=BTT+P*DTURB
! QTT(L) = BTT(L,N,II,JJ)
! QZT(L) = BZT(L,N,II,JJ)
! QZZ(L) = BZZ(L,N,II,JJ)
! QXZ(L) = BXZ(L,N,II,JJ)
! QYZ(L) = BYZ(L,N,II,JJ)
! QXT(L) = BXT(L,N,II,JJ)
! QXX(L) = BXX(L,N,II,JJ)
! QYT(L) = BYT(L,N,II,JJ)
! QYY(L) = BYY(L,N,II,JJ)
! QXY(L) = BXY(L,N,II,JJ)
!end do
!// ASH 2017: I think this should be faster
QM(:) = QM2(:)
QTT(:) = BTT(:,N,II,JJ)
QZT(:) = BZT(:,N,II,JJ)
QZZ(:) = BZZ(:,N,II,JJ)
QXZ(:) = BXZ(:,N,II,JJ)
QYZ(:) = BYZ(:,N,II,JJ)
QXT(:) = BXT(:,N,II,JJ)
QXX(:) = BXX(:,N,II,JJ)
QYT(:) = BYT(:,N,II,JJ)
QYY(:) = BYY(:,N,II,JJ)
QXY(:) = BXY(:,N,II,JJ)
!// #2, 3, or 4 subdivide CTM layers
!// call QZONX to slice up tracer/moments into NSUB
!// sub-grid layers; ignore the Z-moments in the sub-grid
!// layers
M = 0
do L = 1, NBLP1
call QZONX(QTT(L),QZT(L),QZZ(L),QXZ(L),QYZ(L),QXT(L), &
QXX(L),QYT(L),QYY(L),QXY(L),QM(L),PTT,PZT,PZZ, &
PXZ,PYZ,PXT,PXX,PYT,PYY,PXY,PM,NSUB)
do K = 1, NSUB
M = M+1
GM(M) = PM(K)
GTT(M) = PTT(K)
GXT(M) = PXT(K)
GXX(M) = PXX(K)
GXY(M) = PXY(K)
GYT(M) = PYT(K)
GYY(M) = PYY(K)
end do
! put PM(1:3) into GM.
!// Set M = 0 before L-loop
!K = M + NSUB !// End of GM-index for this layer (3,6,9,...)
!M = M + 1 !// Beginning (1,4,7,...)
!GM(M:K) = PM(:)
!GTT(M:K) = PTT(:)
!GXT(M:K) = PXT(:)
!GXX(M:K) = PXX(:)
!GXY(M:K) = PXY(:)
!GYT(M:K) = PYT(:)
!GYY(M:K) = PYY(:)
end do
!// CGC, CGQ and CGH are removed, since they are all set
!// to zero.
!// CGH: COUNTER-GRADIENT TERM FOR HEAT
!// CGQ: COUNTER-GRADIENT TERM FOR MOISTURE
!// CGC: COUNTER-GRADIENT TERM FOR SCALAR C
!// call closure model to obtain Kc, countergradient terms
!// Kc is evaluated at where DUDZ and DVDZ defined, at
!// the edge of a box (ZD).
!// ZMD is at the middle of a box, where U, V and
!// THETA are defined.
call KPROF2 (KC, PRTL1, NGMAX, USTAR, &
SFCS, (SFCL/LV), 0._r8, MO_LEN, ZBL, VK, ZD, TSV)
!// Save PBL_KEDDY for deposition scalings
PBL_KEDDY(II,JJ,MP) = KC(2)
!// Adjustment to max from 1:MID-1
do L = 1, MID-1
KC(L) = max(KC(L), KC(MID))
end do
!// Save PrandtlL1
PrandtlL1(II,JJ,MP) = PRTL1
!// KC(M=1:NG-1) = diffusion coefficient (m*m/s)
!// between layer M and M+1
!do M = 1, NG-1
! DZM(M) = ZMD(M+1) - ZMD(M)
!end do
do M=1, NG-1
DZM = ZMD(M+1) - ZMD(M)
KCZ(M) = 0.5_r8 * DTPBL * KC(M) * (GM(M)+GM(M+1)) &
/ (DZM * DZM * GM(M) * GM(M+1))
end do
!// set up tridiagonal coeffs as dimensionless
!// (not 1/sec), so cannot do s-s
!// boundary conditions are zero-flux across layer edges
BL(1) = 0._r8
do M = 2, NG-1
BL(M) = -KCZ(M-1) * GM(M)
end do
BL(NG) = -KCZ(NG-1) * GM(NG)
BD(1) = 1._r8 + KCZ(1) * GM(2)
do M = 2, NG-1
BD(M) = 1._r8 + (KCZ(M-1) * GM(M-1) + KCZ(M) * GM(M+1))
end do
BD(NG) = 1._r8 + KCZ(NG-1) * GM(NG-1)
BU(1) = -KCZ(1) * GM(1)
do M = 2, NG-1
BU(M) = -KCZ(M) * GM(M)
end do
BU(NG) = 0._r8
!// the right-hand side is just the initial values of
!// GTT (in kg)
!// call tridiagonal solver to vertically diffuse mass
!// and 5 XY moments
call TRIDIAG (BL,BD,BU,GTT,GOUT,NG)
do M = 1, NG
GTT(M) = GOUT(M)
end do
call TRIDIAG (BL,BD,BU,GXT,GOUT,NG)
do M = 1, NG
GXT(M) = GOUT(M)
end do
call TRIDIAG (BL,BD,BU,GXX,GOUT,NG)
do M = 1, NG
GXX(M) = GOUT(M)
end do
call TRIDIAG (BL,BD,BU,GYT,GOUT,NG)
do M = 1, NG
GYT(M) = GOUT(M)
end do
call TRIDIAG (BL,BD,BU,GYY,GOUT,NG)
do M = 1, NG
GYY(M) = GOUT(M)
end do
call TRIDIAG (BL,BD,BU,GXY,GOUT,NG)
do M = 1, NG
GXY(M) = GOUT(M)
end do
!// call QXZON to recombine turbulent grid to large-scale
!// grid w/moments
QTMPT(:) = QTT(:)
QTMPM(:) = QM(:)
M = 0
do L = 1, NBLP1
do K = 1, NSUB
M = M+1
PM(K) = GM(M)
PTT(K) = GTT(M)
PXT(K) = GXT(M)
PXX(K) = GXX(M)
PXY(K) = GXY(M)
PYT(K) = GYT(M)
PYY(K) = GYY(M)
PZT(K) = 0._r8
PZZ(K) = 0._r8
PXZ(K) = 0._r8
PYZ(K) = 0._r8
end do
call QXZON(PTT,PZT,PZZ,PXZ,PYZ,PXT,PXX,PYT,PYY,PXY,PM, &
NSUB,QTT(L),QZT(L),QZZ(L),QXZ(L),QYZ(L), &
QXT(L),QXX(L),QYT(L),QYY(L),QXY(L),QM(L), &
NBLP1,L,N)
end do
!// pass resultant concentrations/moments back to CTM grid
!do L = 1, LPAR
! BTT(L,N,II,JJ) = QTT(L)
! BZT(L,N,II,JJ) = QZT(L)
! BZZ(L,N,II,JJ) = QZZ(L)
! BXZ(L,N,II,JJ) = QXZ(L)
! BYZ(L,N,II,JJ) = QYZ(L)
! BXT(L,N,II,JJ) = QXT(L)
! BXX(L,N,II,JJ) = QXX(L)
! BYT(L,N,II,JJ) = QYT(L)
! BYY(L,N,II,JJ) = QYY(L)
! BXY(L,N,II,JJ) = QXY(L)
!end do ! L
!// ASH 2017: I think this should be faster
BTT(:,N,II,JJ) = QTT(:)
BZT(:,N,II,JJ) = QZT(:)
BZZ(:,N,II,JJ) = QZZ(:)
BXZ(:,N,II,JJ) = QXZ(:)
BYZ(:,N,II,JJ) = QYZ(:)
BXT(:,N,II,JJ) = QXT(:)
BXX(:,N,II,JJ) = QXX(:)
BYT(:,N,II,JJ) = QYT(:)
BYY(:,N,II,JJ) = QYY(:)
BXY(:,N,II,JJ) = QXY(:)
end do !// N
end if !// if (NG .gt. 1) then
end if !// if (ZBL .ge. 1._r8) then
end do !// J
end do !// I
else
write(6,'(a,i4,a)') f90file//':'//subr//': NBLX=',NBLX, &
' not defined - stopping!'
stop
end if
!// --------------------------------------------------------------------
end subroutine CNVDBL
!// ----------------------------------------------------------------------
!// ----------------------------------------------------------------------
subroutine BULK(QTT,QZT,QZZ,QXZ,QYZ,QXT,QXX,QYT,QYY,QXY,QM,XBL,NQ)
!// --------------------------------------------------------------------
!// Computes tracer profile (w/moments) for a fully mixed PBL up to
!// layer = XBL
!// e.g., XBL = 1.25 --> mixed all of L=1 and lowest 25% of L=2 by mass,
!// erase all vertical moments (QZT,QZZ,QXZ,QYZ) in mixed regions
!// keep all horizontal information (QXT,QYT,QXX,QYY,QXY)
!// dates to MJP 7/97
!// --------------------------------------------------------------------
use cmn_precision, only: r8
!// --------------------------------------------------------------------
implicit none
!// --------------------------------------------------------------------
!// Input
integer, intent(in) :: NQ
real(r8), intent(in) :: XBL
!// Input/Output
real(r8), dimension(NQ), intent(inout) :: &
QTT,QZT,QZZ,QXZ,QYZ,QXT,QXX,QYT,QYY,QXY,QM
!// Locals
integer :: L, NBL
real(r8) :: FTT,FXT,FXX,FYT,FYY,FXY,FMM,FBL,FMIN
real(r8) :: FTTL,FXTL,FXXL,FYTL,FYYL,FXYL,FMML
real(r8) :: EPS,EPS1,EPS1Q,EPS0
!// --------------------------------------------------------------------
if (XBL .gt. 0.01_r8) then
NBL = int(XBL)
FBL = XBL - real(NBL,r8)
FTT = 0._r8
FXT = 0._r8
FXX = 0._r8
FYT = 0._r8
FYY = 0._r8
FXY = 0._r8
FMM = 0._r8
FMML = 0._r8
!// Add up air mass and tracer moments in boxes 1:NBL
do L = 1, NBL
FTT = FTT + QTT(L)
FXT = FXT + QXT(L)
FXX = FXX + QXX(L)
FYT = FYT + QYT(L)
FYY = FYY + QYY(L)
FXY = FXY + QXY(L)
FMM = FMM + QM(L)
end do
!// do fractional layer >NBL only if >1% of layer affected
if (FBL .gt. 0.01_r8) then
!// restrain moments in fractional box (LIMIT=2)
L = NBL+1
call QLIMIT2 (QTT(L),QZT(L),QZZ(L),QXZ(L),QYZ(L))
!// compute air mass, tracer moments in lower parcel of L
!// (into mixed layer)
FMML = FBL*QM(L) ! same as advective step QU = FBL*QM(L)
EPS = FBL
EPS1 = 1._r8 - EPS
EPS1Q = EPS1*EPS1
FTTL = EPS*(QTT(L) - EPS1*(QZT(L) - (EPS1-EPS)*QZZ(L)))
FXTL = EPS*(QXT(L) - EPS1*QXZ(L))
FYTL = EPS*(QYT(L) - EPS1*QYZ(L))
FXXL = EPS*QXX(L)
FYYL = EPS*QYY(L)
FXYL = EPS*QXY(L)
!// readjust air mass, tracer moments remaining in top of layer L
QM(L) = QM(L) - FMML
QTT(L) = QTT(L) - FTTL
QZT(L) = EPS1Q*(QZT(L) + 3._r8*EPS*QZZ(L))
QZZ(L) = EPS1*EPS1Q*QZZ(L)
QXT(L) = QXT(L) - FXTL
QXX(L) = QXX(L) - FXXL
QYT(L) = QYT(L) - FYTL
QYY(L) = QYY(L) - FYYL
QXZ(L) = EPS1Q*QXZ(L)
QYZ(L) = EPS1Q*QYZ(L)
QXY(L) = QXY(L) - FXYL
!// add partial layer to sum of lower layers (1:NBL)
FTT = FTT + FTTL
FXT = FXT + FXTL
FXX = FXX + FXXL
FYT = FYT + FYTL
FYY = FYY + FYYL
FXY = FXY + FXYL
FMM = FMM + FMML
end if
!// calculate mean mass and moments in mixed PBL & distribute
FMIN = 1._r8 / FMM
FTT = FTT * FMIN
FXT = FXT * FMIN
FXX = FXX * FMIN
FYT = FYT * FMIN
FYY = FYY * FMIN
FXY = FXY * FMIN
do L = 1, NBL
QTT(L) = FTT * QM(L)
QXT(L) = FXT * QM(L)
QXX(L) = FXX * QM(L)
QYT(L) = FYT * QM(L)
QYY(L) = FYY * QM(L)
QXY(L) = FXY * QM(L)
QZT(L) = 0._r8
QZZ(L) = 0._r8
QXZ(L) = 0._r8
QYZ(L) = 0._r8
end do
if (FBL .gt. 0.01_r8) then
L = NBL+1
FTTL = FTT * FMML
FXTL = FXT * FMML
FXXL = FXX * FMML
FYTL = FYT * FMML
FYYL = FYY * FMML
FXYL = FXY * FMML
QM(L) = QM(L) + FMML
EPS = FMML / QM(L)
EPS1 = 1._r8 - EPS
EPS0 = EPS*QTT(L) - EPS1*FTTL
QZZ(L) = EPS1*EPS1*QZZ(L) &
+ 5._r8*(EPS*EPS1*QZT(L) - (EPS1-EPS)*EPS0)
QZT(L) = EPS1*QZT(L) + 3._r8*EPS0
QTT(L) = QTT(L) + FTTL
QXZ(L) = EPS1*QXZ(L) + 3._r8*(-EPS1*FXTL + EPS*QXT(L))
QYZ(L) = EPS1*QYZ(L) + 3._r8*(-EPS1*FYTL + EPS*QYT(L))
QXT(L) = QXT(L) + FXTL
QXX(L) = QXX(L) + FXXL
QYT(L) = QYT(L) + FYTL
QYY(L) = QYY(L) + FYYL
QXY(L) = QXY(L) + FXYL
end if
end if
!// --------------------------------------------------------------------
end subroutine BULK
!// ----------------------------------------------------------------------
!// ----------------------------------------------------------------------
subroutine get_keddy_L1(keddy, PRTL1, USTAR, &
HEATV, EVAP, MOL, PBLHGT, VK, ZT, TSV )
!// --------------------------------------------------------------------
!// Description:
!// Calculates diffusivities and countergradient terms used in
!// PBL closure.
!//
!// Amund Sovde Haslerud, November 2017
!// The original KPROF differs from this routine: In KPROF2, onlt
!// KC is calculated, not KH, KM, KQ. This is to make the routine
!// faster.
!//
!// Method:
!// Holtslag and Boville (Mon. Wea. Rvw., 1990)
!//
!// History:
!// Version Date Comment
!// ------- ---- -------
!// 1.0 06/07/99 Original code. Bryan Hannegan
!//
!// --------------------------------------------------------------------
use cmn_precision, only: r8
use cmn_parameters, only: G0
!// --------------------------------------------------------------------
implicit none
!// --------------------------------------------------------------------
!// Input
real(r8), intent(in) :: &
ZT, PBLHGT, & ! layer top height, pbl height
USTAR, HEATV, EVAP, MOL, VK, TSV
!// Output
real(r8), intent(out) :: &
keddy, & !// KH for surface layer
PRTL1 !// Return PRANDTL for surface layer
!// Local parameters
real(r8) :: &
PRANDTL, &
PBLK, WSTAR, WTURB, &
ZH, ZL, ZZH, ZLSURF, ZPHIM, &
ZMOL, ZBL
integer :: K
logical :: LUNSTABLE
real(r8), parameter :: &
CONST = 7.2_r8, &
BGK = 1.e-19_r8, &
GRAV = G0
!// --------------------------------------------------------------------
!// calculate inverse of Monin-Obukov Length
ZMOL = 1._r8 / MOL
!// calculate inverser of BL Height
ZBL = 1._r8 / PBLHGT
!// Unstable or not?
LUNSTABLE = HEATV .gt. 0._r8
!// in case of unstable BL find W^*
if (LUNSTABLE) &
WSTAR = (GRAV * HEATV * PBLHGT / TSV)**(1._r8 / 3._r8)
!// Initialise PRANDTL for K=1 (PRTL1)
PRTL1 = 0.85_r8
!// Estimate K in lowest model layer. Always within PBL height.
ZH = ZT * ZBL
if (ZH .gt. 1._r8) then
ZZH = 0._r8
else
ZZH = VK * ZT * (1._r8 - ZH) * (1._r8 - ZH)
end if
!// evaluate based on stability
!// unstable PBL
if (LUNSTABLE) then
if (ZH .lt. 0.1_r8) then
!// surface layer, compute corrections at actual height
ZL = ZT * ZMOL
ZPHIM = 1._r8 / PHIM(ZL)
PBLK = ZZH * USTAR * ZPHIM
PRANDTL = PHIH(ZL) * ZPHIM
!// Set PRTL1
PRTL1 = PRANDTL
else
!// outer layer, compute stability corrections at top of
!// sfc layer (1/10 PBL)
ZLSURF = 0.1_r8 * PBLHGT * ZMOL
ZPHIM = 1._r8 / PHIM(ZLSURF)
WTURB = USTAR * ZPHIM
PRANDTL = PHIH(ZLSURF) * ZPHIM &
+ VK * 0.1_r8 * (CONST * WSTAR) / WTURB
PBLK = WTURB * ZZH
!// Set PRTL1
PRTL1 = PRANDTL
end if
keddy = max( PBLK / PRANDTL, BGK )
!// stable and neutral PBL
else
ZL = ZT * ZMOL
PBLK = ZZH * USTAR / PHIM(ZL)
keddy = max( PBLK, BGK )
!// Set PRTL1
!// For stable/neutral we approximate KM=KH, i.e. PRANDTL=1
PRTL1 = 1._r8
end if
!// --------------------------------------------------------------------
end subroutine get_keddy_L1
!// ----------------------------------------------------------------------
!// ----------------------------------------------------------------------
subroutine KPROF2(KC, PRTL1, NTOP, USTAR, &
HEATV, EVAP, WCSFC, MOL, PBLHGT, VK, ZT, TSV )
!// --------------------------------------------------------------------
!// Description:
!// Calculates diffusivities and countergradient terms used in
!// PBL closure.
!//
!// Method:
!// Holtslag and Boville (Mon. Wea. Rvw., 1990)
!//
!// Amund Sovde Haslerud, November 2017
!// The original KPROF differs from this routine: In KPROF2, onlt
!// KC is calculated, not KH, KM, KQ. This is to make the routine
!// faster.
!//
!// History:
!// Version Date Comment
!// ------- ---- -------
!// 1.0 06/07/99 Original code. Bryan Hannegan
!//
!// --------------------------------------------------------------------
use cmn_precision, only: r8
use cmn_parameters, only: G0
!// --------------------------------------------------------------------
implicit none
!// --------------------------------------------------------------------
!// Input
integer, intent(in) :: NTOP
real(r8), intent(in) :: &
ZT(NTOP), PBLHGT, &
USTAR, HEATV, EVAP, WCSFC, MOL, VK, TSV
!// Output
real(r8), intent(out) :: &
KC(NTOP)
real(r8), intent(out) :: PRTL1 !// Return PRANDTL for surface layer
!// Local parameters
real(r8) :: &
PRANDTL, &
PBLK, WSTAR, WTURB, &
ZH, ZL, ZZH, ZLSURF, ZPHIM, &
ZMOL, ZBL
integer :: K
logical :: LUNSTABLE
real(r8), parameter :: &
CONST = 7.2_r8, &
BGK = 1.e-19_r8, &
GRAV = G0
!// --------------------------------------------------------------------
!// Initialize
!// set diffusivities to background
!KC(:) = BGK
!// calculate inverse of Monin-Obukov Length
ZMOL = 1._r8 / MOL
!// calculate inverser of BL Height
ZBL = 1._r8 / PBLHGT
!// Unstable or not?
LUNSTABLE = HEATV .gt. 0._r8
!// in case of unstable BL find W^*
if (LUNSTABLE) &
WSTAR = (GRAV * HEATV * PBLHGT / TSV)**(1._r8 / 3._r8)
!// Initialise PRANDTL for K=1 (PRTL1)
PRTL1 = 0.85_r8
!// set up K-profile function
KC(NTOP) = BGK
do K = 1, NTOP - 1
!// Only calculate as long as within PBL
if (ZT(K) .lt. PBLHGT) then
ZH = ZT(K) * ZBL
if (ZH .gt. 1._r8) then
ZZH = 0._r8
else
ZZH = VK * ZT(K) * (1._r8 - ZH) * (1._r8 - ZH)
end if
!// evaluate based on stability
!// unstable PBL
if (LUNSTABLE) then
if (ZH .lt. 0.1_r8) then
!// surface layer, compute corrections at actual height
ZL = ZT(K) * ZMOL
ZPHIM = 1._r8 / PHIM(ZL)
PBLK = ZZH * USTAR * ZPHIM
PRANDTL = PHIH(ZL) * ZPHIM
!// Set PRTL1
if (K .eq. 1) PRTL1 = PRANDTL
else
!// outer layer, compute stability corrections at top of
!// sfc layer (1/10 PBL)
ZLSURF = 0.1_r8 * PBLHGT * ZMOL
ZPHIM = 1._r8 / PHIM(ZLSURF)
WTURB = USTAR * ZPHIM
PRANDTL = PHIH(ZLSURF) * ZPHIM &
+ VK * 0.1_r8 * (CONST * WSTAR) / WTURB
PBLK = WTURB * ZZH
!// Set PRTL1
if (K .eq. 1) PRTL1 = PRANDTL
end if
KC(K) = max( PBLK / PRANDTL, BGK )
!// stable and neutral PBL
else
ZL = ZT(K) * ZMOL
PBLK = ZZH * USTAR / PHIM(ZL)
KC(K) = max( PBLK, BGK )