forked from NCAR/MMM-physics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bl_mynn_subroutines.F90
6565 lines (5770 loc) · 249 KB
/
bl_mynn_subroutines.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
!=================================================================================================================
module bl_mynn_common
use ccpp_kind_types,only: kind_phys
implicit none
save
!--- physics constants that need to be initialized with physics constants from the host model:
real(kind=kind_phys):: cp ! defined in bl_mynn_init.
real(kind=kind_phys):: cpv ! defined in bl_mynn_init.
real(kind=kind_phys):: cice ! defined in bl_mynn_init.
real(kind=kind_phys):: cliq ! defined in bl_mynn_init.
real(kind=kind_phys):: ep_1 ! defined in bl_mynn_init.
real(kind=kind_phys):: ep_2 ! defined in bl_mynn_init.
real(kind=kind_phys):: grav ! defined in bl_mynn_init.
real(kind=kind_phys):: karman ! defined in bl_mynn_init.
real(kind=kind_phys):: p1000mb ! defined in bl_mynn_init.
real(kind=kind_phys):: rcp ! defined in bl_mynn_init.
real(kind=kind_phys):: r_d ! defined in bl_mynn_init.
real(kind=kind_phys):: r_v ! defined in bl_mynn_init.
real(kind=kind_phys):: rvovrd ! defined in bl_mynn_init.
real(kind=kind_phys):: svp1 ! defined in bl_mynn_init.
real(kind=kind_phys):: svp2 ! defined in bl_mynn_init.
real(kind=kind_phys):: svp3 ! defined in bl_mynn_init.
real(kind=kind_phys):: svpt0 ! defined in bl_mynn_init.
real(kind=kind_phys):: xlf ! defined in bl_mynn_init.
real(kind=kind_phys):: xlv ! defined in bl_mynn_init.
real(kind=kind_phys):: xls ! defined in bl_mynn_init.
!--- derived physics constants:
real(kind=kind_phys):: ep_3
real(kind=kind_phys):: gtr
real(kind=kind_phys):: p608
real(kind=kind_phys):: t0c
real(kind=kind_phys):: tv0
real(kind=kind_phys):: xlscp
real(kind=kind_phys):: xlvcp
!real(kind=kind_phys):: ev
!real(kind=kind_phys):: rk
!real(kind=kind_phys):: svp11
!real(kind=kind_phys):: tv1
!real(kind=kind_phys):: vk
!--- parameters:
real(kind=kind_phys),parameter:: tice = 240.0 !-33 (C), temp at saturation w.r.t. ice
real(kind=kind_phys),parameter:: tkmin = 253.0
real(kind=kind_phys),parameter:: tref = 300.0
real(kind=kind_phys),parameter:: onethird = 1./3.
real(kind=kind_phys),parameter:: twothirds = 2./3.
real(kind=kind_phys),parameter:: zero = 0._kind_phys
!--- physics constants also needed in subroutine bl_mynn_run:
real(kind=kind_phys),parameter:: b1 = 24.0
real(kind=kind_phys),parameter:: b2 = 15.0
real(kind=kind_phys),parameter:: cphh_st = 5.0
real(kind=kind_phys),parameter:: cphm_st = 5.0
real(kind=kind_phys),parameter:: cphh_unst = 16.0
real(kind=kind_phys),parameter:: cphm_unst = 16.0
end module bl_mynn_common
!=================================================================================================================
!>\file module_bl_mynn.F90
!! This file contains the entity of MYNN-EDMF PBL scheme.
! **********************************************************************
! * An improved Mellor-Yamada turbulence closure model *
! * *
! * Original author: M. Nakanishi (N.D.A), [email protected] *
! * Translated into F90 and implemented in WRF-ARW by: *
! * Mariusz Pagowski (NOAA-GSL) *
! * Subsequently developed by: *
! * Joseph Olson, Jaymes Kenyon (NOAA/GSL), *
! * Wayne Angevine (NOAA/CSL), Kay Suselj (NASA/JPL), *
! * Franciano Puhales (UFSM), Laura Fowler (NCAR), *
! * Elynn Wu (UCSD), and Jordan Schnell (NOAA/GSL) *
! * *
! * Contents: *
! * *
! * mynn_bl_driver - main subroutine which calls all other routines *
! * -------------- *
! * 1. mym_initialize (to be called once initially) *
! * gives the closure constants and initializes the turbulent *
! * quantities. *
! * 2. get_pblh *
! * Calculates the boundary layer height *
! * 3. scale_aware *
! * Calculates scale-adaptive tapering functions *
! * 4. mym_condensation *
! * determines the liquid water content and the cloud fraction *
! * diagnostically. *
! * 5. dmp_mf *
! * Calls the (nonlocal) mass-flux component *
! * 6. ddmf_jpl *
! * Calls the downdraft mass-flux component *
! * (-) mym_level2 (called in the other subroutines) *
! * calculates the stability functions at Level 2. *
! * (-) mym_length (called in the other subroutines) *
! * calculates the master length scale. *
! * 7. mym_turbulence *
! * calculates the vertical diffusivity coefficients and the *
! * production terms for the turbulent quantities. *
! * 8. mym_predict *
! * predicts the turbulent quantities at the next step. *
! * *
! * call mym_initialize *
! * | *
! * |<----------------+ *
! * | | *
! * call get_pblh | *
! * call scale_aware | *
! * call mym_condensation | *
! * call dmp_mf | *
! * call ddmf_jpl | *
! * call mym_turbulence | *
! * call mym_predict | *
! * | | *
! * |-----------------+ *
! * | *
! * end *
! * *
! * Variables worthy of special mention: *
! * tref : Reference temperature *
! * thl : Liquid water potential temperature *
! * qw : Total water (water vapor+liquid water) content *
! * ql : Liquid water content *
! * vt, vq : Functions for computing the buoyancy flux *
! * qke : 2 * TKE *
! * el : mixing length *
! * *
! * If the water contents are unnecessary, e.g., in the case of *
! * ocean models, thl is the potential temperature and qw, ql, vt *
! * and vq are all zero. *
! * *
! * Grid arrangement: *
! * k+1 +---------+ *
! * | | i = 1 - nx *
! * (k) | * | k = 1 - nz *
! * | | *
! * k +---------+ *
! * i (i) i+1 *
! * *
! * All the predicted variables are defined at the center (*) of *
! * the grid boxes. The diffusivity coefficients and two of their *
! * components (el and stability functions sh & sm) are, however, *
! * defined on the walls of the grid boxes. *
! * # Upper boundary values are given at k=nz. *
! * *
! * References: *
! * 1. Nakanishi, M., 2001: *
! * Boundary-Layer Meteor., 99, 349-378. *
! * 2. Nakanishi, M. and H. Niino, 2004: *
! * Boundary-Layer Meteor., 112, 1-31. *
! * 3. Nakanishi, M. and H. Niino, 2006: *
! * Boundary-Layer Meteor., 119, 397-407. *
! * 4. Nakanishi, M. and H. Niino, 2009: *
! * Jour. Meteor. Soc. Japan, 87, 895-912. *
! * 5. Olson J. and coauthors, 2019: A description of the *
! * MYNN-EDMF scheme and coupling to other components in *
! * WRF-ARW. NOAA Tech. Memo. OAR GSD, 61, 37 pp., *
! * https://doi.org/10.25923/n9wm-be49. *
! * 6. Puhales, Franciano S. and coauthors, 2020: Turbulent *
! * Kinetic Energy Budget for MYNN-EDMF PBL Scheme in WRF model.*
! * Universidade Federal de Santa Maria Technical Note. 9 pp. *
! **********************************************************************
! ==================================================================
! Notes on original implementation into WRF-ARW
! changes to original code:
! 1. code is 1D (in z)
! 2. option to advect TKE, but not the covariances and variances
! 3. Cranck-Nicholson replaced with the implicit scheme
! 4. removed terrain-dependent grid since input in WRF in actual
! distances in z[m]
! 5. cosmetic changes to adhere to WRF standard (remove common blocks,
! intent etc)
!-------------------------------------------------------------------
! Further modifications post-implementation
!
! 1. Addition of BouLac mixing length in the free atmosphere.
! 2. Changed the turbulent mixing length to be integrated from the
! surface to the top of the BL + a transition layer depth.
! v3.4.1: Option to use Kitamura/Canuto modification which removes
! the critical Richardson number and negative TKE (default).
! Hybrid PBL height diagnostic, which blends a theta-v-based
! definition in neutral/convective BL and a TKE-based definition
! in stable conditions.
! TKE budget output option
! v3.5.0: TKE advection option (bl_mynn_tkeadvect)
! v3.5.1: Fog deposition related changes.
! v3.6.0: Removed fog deposition from the calculation of tendencies
! Added mixing of qc, qi, qni
! Added output for wstar, delta, TKE_PBL, & KPBL for correct
! coupling to shcu schemes
! v3.8.0: Added subgrid scale cloud output for coupling to radiation
! schemes (activated by setting icloud_bl =1 in phys namelist).
! Added WRF_DEBUG prints (at level 3000)
! Added Tripoli and Cotton (1981) correction.
! Added namelist option bl_mynn_cloudmix to test effect of mixing
! cloud species (default = 1: on).
! Added mass-flux option (bl_mynn_edmf, = .true. for DMP mass-flux, .false.: off).
! Related options:
! bl_mynn_edmf_mom = .true. : activate momentum transport in MF scheme
! bl_mynn_edmf_tke = .true. : activate TKE transport in MF scheme
! Added mixing length option (bl_mynn_mixlength, see notes below)
! Added more sophisticated saturation checks, following Thompson scheme
! Added new cloud PDF option (bl_mynn_cloudpdf = 2) from Chaboureau
! and Bechtold (2002, JAS, with mods)
! Added capability to mix chemical species when env variable
! WRF_CHEM = 1, thanks to Wayne Angevine.
! Added scale-aware mixing length, following Junshi Ito's work
! Ito et al. (2015, BLM).
! v3.9.0 Improvement to the mass-flux scheme (dynamic number of plumes,
! better plume/cloud depth, significant speed up, better cloud
! fraction).
! Added Stochastic Parameter Perturbation (SPP) implementation.
! Many miscellaneous tweaks to the mixing lengths and stratus
! component of the subgrid clouds.
! v.4.0 Removed or added alternatives to WRF-specific functions/modules
! for the sake of portability to other models.
! the sake of portability to other models.
! Further refinement of mass-flux scheme from SCM experiments with
! Wayne Angevine: switch to linear entrainment and back to
! Simpson and Wiggert-type w-equation.
! Addition of TKE production due to radiation cooling at top of
! clouds (proto-version); not activated by default.
! Some code rewrites to move if-thens out of loops in an attempt to
! improve computational efficiency.
! New tridiagonal solver, which is supposedly 14% faster and more
! conservative. Impact seems very small.
! Many miscellaneous tweaks to the mixing lengths and stratus
! component of the subgrid-scale (SGS) clouds.
! v4.1 Big improvements in downward SW radiation due to revision of subgrid clouds
! - better cloud fraction and subgrid scale mixing ratios.
! - may experience a small cool bias during the daytime now that high
! SW-down bias is greatly reduced...
! Some tweaks to increase the turbulent mixing during the daytime for
! bl_mynn_mixlength option 2 to alleviate cool bias (very small impact).
! Improved ensemble spread from changes to SPP in MYNN
! - now perturbing eddy diffusivity and eddy viscosity directly
! - now perturbing background rh (in SGS cloud calc only)
! - now perturbing entrainment rates in mass-flux scheme
! Added IF checks (within IFDEFS) to protect mixchem code from being used
! when HRRR smoke is used (no impact on regular non-wrf chem use)
! Important bug fix for wrf chem when transporting chemical species in MF scheme
! Removed 2nd mass-flux scheme (no only bl_mynn_edmf = 1, no option 2)
! Removed unused stochastic code for mass-flux scheme
! Changed mass-flux scheme to be integrated on interface levels instead of
! mass levels - impact is small
! Added option to mix 2nd moments in MYNN as opposed to the scalar_pblmix option.
! - activated with bl_mynn_mixscalars = .true.; this sets scalar_pblmix = 0
! - added tridagonal solver used in scalar_pblmix option to duplicate tendencies
! - this alone changes the interface call considerably from v4.0.
! Slight revision to TKE production due to radiation cooling at top of clouds
! Added the non-Guassian buoyancy flux function of Bechtold and Siebesma (1998, JAS).
! - improves TKE in SGS clouds
! Added heating due to dissipation of TKE (small impact, maybe + 0.1 C daytime PBL temp)
! Misc changes made for FV3/MPAS compatibility
! v4.2 A series of small tweaks to help reduce a cold bias in the PBL:
! - slight increase in diffusion in convective conditions
! - relaxed criteria for mass-flux activation/strength
! - added capability to cycle TKE for continuity in hourly updating HRRR
! - added effects of compensational environmental subsidence in mass-flux scheme,
! which resulted in tweaks to detrainment rates.
! Bug fix for diagnostic-decay of SGS clouds - noticed by Greg Thompson. This has
! a very small, but primarily positive, impact on SW-down biases.
! Tweak to calculation of KPBL - urged by Laura Fowler - to make more intuitive.
! Tweak to temperature range of blending for saturation check (water to ice). This
! slightly reduces excessive SGS clouds in polar region. No impact warm clouds.
! Added namelist option bl_mynn_output (.false. or .true.) to suppress or activate the
! allocation and output of 10 3D variables. Most people will want this
! set to 0 (default) to save memory and disk space.
! Added new array qi_bl as opposed to using qc_bl for both SGS qc and qi. This
! gives us more control of the magnitudes which can be confounded by using
! a single array. As a results, many subroutines needed to be modified,
! especially mym_condensation.
! Added the blending of the stratus component of the SGS clouds to the mass-flux
! clouds to account for situations where stratus and cumulus may exist in the
! grid cell.
! Misc small-impact bugfixes:
! 1) dz was incorrectly indexed in mym_condensation
! 2) configurations with icloud_bl = 0 were using uninitialized arrays
! v4.5 / CCPP
! This version includes many modifications that proved valuable in the global
! framework and removes some key lingering bugs in the mixing of chemical species.
! TKE Budget output fixed (Puhales, 2020-12)
! New option for stability function: (Puhales, 2020-12)
! bl_mynn_stfunc = 0 (original, Kansas-type function, Paulson, 1970 )
! bl_mynn_stfunc = 1 (expanded range, same as used for Jimenez et al (MWR)
! see the Technical Note for this implementation (small impact).
! Improved conservation of momentum and higher-order moments.
! Important bug fixes for mixing of chemical species.
! Addition of pressure-gradient effects on updraft momentum transport.
! Addition of bl_mynn_closure option = 2.5, 2.6, or 3.0
! Addition of higher-order moments for sigma when using
! bl_mynn_cloudpdf = 2 (Chab-Becht).
! Removed WRF_CHEM dependencies.
! Many miscellaneous tweaks.
! v4.6 / CCPP
! Some code optimization. Removed many conditions from loops. Redesigned the mass-
! flux scheme to use 8 plumes instead of a variable n plumes. This results in
! the removal of the output variable "nudprafts" and adds maxwidth and ztop_plume.
! Revision option bl_mynn_cloudpdf = 2, which now ensures cloud fractions for all
! optically relevant mixing ratios (tip from Greg Thompson). Also, added flexibility
! for tuning near-surface cloud fractions to remove excess fog/low ceilings.
! Now outputs all SGS cloud mixing ratios as grid-mean values, not in-cloud. This
! results in a change in the pre-radiation code to no longer multiply mixing ratios
! by cloud fractions.
! Bug fix for the momentum transport.
! Lots of code cleanup: removal of test code, comments, changing text case, etc.
! Many misc tuning/tweaks.
!
! Many of these changes are now documented in references listed above.
!====================================================================
MODULE bl_mynn_subroutines
use ccpp_kind_types,only: kind_phys,kind_phys8
use bl_mynn_common,only: &
b1 , b2 , cice , cliq , cp , &
cpv , ep_2 , ep_3 , grav , gtr , &
karman , onethird , p1000mb , p608 , r_d , &
r_v , rcp , rvovrd , svp1 , t0c , &
tice , tkmin , tv0 , twothirds , xls , &
xlscp , xlv , xlvcp , cphh_st , cphm_st , &
cphh_unst , cphm_unst
use mynn_shared,only: esat_blend,qsat_blend,xl_blend
implicit none
private
public:: dmp_mf, &
ddmf_jpl, &
topdown_cloudrad, &
get_pblh, &
mym_condensation, &
mym_initialize, &
mynn_mix_chem, &
mym_predict, &
mym_turbulence, &
mynn_tendencies, &
phih, &
phim, &
retrieve_exchange_coeffs, &
scale_aware
!===================================================================
! From here on, these are MYNN-specific parameters:
! The parameters below depend on stability functions of module_sf_mynn.
! Closure constants
real(kind_phys), parameter :: &
&pr = 0.74, &
&g1 = 0.235, & ! NN2009 = 0.235
! &b1 = 24.0, &
! &b2 = 15.0, & ! CKmod NN2009
&c2 = 0.729, & ! 0.729, & !0.75, &
&c3 = 0.340, & ! 0.340, & !0.352, &
&c4 = 0.0, &
&c5 = 0.2, &
&a1 = b1*( 1.0-3.0*g1 )/6.0, &
! &c1 = g1 -1.0/( 3.0*a1*b1**(1.0/3.0) ), &
&c1 = g1 -1.0/( 3.0*a1*2.88449914061481660), &
&a2 = a1*( g1-c1 )/( g1*pr ), &
&g2 = b2/b1*( 1.0-c3 ) +2.0*a1/b1*( 3.0-2.0*c2 )
real(kind_phys), parameter :: &
&cc2 = 1.0-c2, &
&cc3 = 1.0-c3, &
&e1c = 3.0*a2*b2*cc3, &
&e2c = 9.0*a1*a2*cc2, &
&e3c = 9.0*a2*a2*cc2*( 1.0-c5 ), &
&e4c = 12.0*a1*a2*cc2, &
&e5c = 6.0*a1*a1
! Constants for min tke in elt integration (qmin), max z/L in els (zmax),
! and factor for eddy viscosity for TKE (Kq = Sqfac*Km):
real(kind_phys), parameter :: qmin=0.0, zmax=1.0, Sqfac=3.0
! Note that the following mixing-length constants are now specified in mym_length
! &cns=3.5, alp1=0.23, alp2=0.3, alp3=3.0, alp4=10.0, alp5=0.2
real(kind_phys), parameter :: gpw=5./3., qcgmin=1.e-8, qkemin=1.e-12
real(kind_phys), parameter :: tliq = 269. !all hydrometeors are liquid when T > tliq
! Constants for cloud PDF (mym_condensation)
real(kind_phys), parameter :: rr2=0.7071068, rrp=0.3989423
!>Use Canuto/Kitamura mod (remove Ric and negative TKE) (1:yes, 0:no)
!!For more info, see Canuto et al. (2008 JAS) and Kitamura (Journal of the
!!Meteorological Society of Japan, Vol. 88, No. 5, pp. 857-864, 2010).
!!Note that this change required further modification of other parameters
!!above (c2, c3). If you want to remove this option, set c2 and c3 constants
!!(above) back to NN2009 values (see commented out lines next to the
!!parameters above). This only removes the negative TKE problem
!!but does not necessarily improve performance - neutral impact.
real(kind_phys), parameter :: CKmod=1.
!Option to activate environmental subsidence in mass-flux scheme
logical, parameter :: env_subs = .false.
!option to print out more stuff for debugging purposes
logical, parameter :: debug_code = .false.
integer, parameter :: idbg = 23 !specific i-point to write out
CONTAINS
!=======================================================================
! SUBROUTINE mym_initialize:
!
! Input variables:
! iniflag : <>0; turbulent quantities will be initialized
! = 0; turbulent quantities have been already
! given, i.e., they will not be initialized
! nx, nz : Dimension sizes of the
! x and z directions, respectively
! tref : Reference temperature (K)
! dz(nz) : Vertical grid spacings (m)
! # dz(nz)=dz(nz-1)
! zw(nz+1) : Heights of the walls of the grid boxes (m)
! # zw(1)=0.0 and zw(k)=zw(k-1)+dz(k-1)
! exner(nx,nz) : Exner function at zw*h+zg (J/kg K)
! defined by c_p*( p_basic/1000hPa )^kappa
! This is usually computed by integrating
! d(pi0)/dz = -h*g/tref.
! rmo(nx) : Inverse of the Obukhov length (m^(-1))
! flt, flq(nx) : Turbulent fluxes of potential temperature and
! total water, respectively:
! flt=-u_*Theta_* (K m/s)
! flq=-u_*qw_* (kg/kg m/s)
! ust(nx) : Friction velocity (m/s)
! pmz(nx) : phi_m-zeta at z1*h+z0, where z1 (=0.5*dz(1))
! is the first grid point above the surafce, z0
! the roughness length and zeta=(z1*h+z0)*rmo
! phh(nx) : phi_h at z1*h+z0
! u, v(nx,nz) : Components of the horizontal wind (m/s)
! thl(nx,nz) : Liquid water potential temperature
! (K)
! qw(nx,nz) : Total water content Q_w (kg/kg)
!
! Output variables:
! ql(nx,nz) : Liquid water content (kg/kg)
! vt, vq(nx,nz) : Functions for computing the buoyancy flux
! qke(nx,nz) : Twice the turbulent kinetic energy q^2
! (m^2/s^2)
! tsq(nx,nz) : Variance of Theta_l (K^2)
! qsq(nx,nz) : Variance of Q_w
! cov(nx,nz) : Covariance of Theta_l and Q_w (K)
! el(nx,nz) : Master length scale L (m)
! defined on the walls of the grid boxes
!
! Work arrays: see subroutine mym_level2
! pd?(nx,nz,ny) : Half of the production terms at Level 2
! defined on the walls of the grid boxes
! qkw(nx,nz,ny) : q on the walls of the grid boxes (m/s)
!
! # As to dtl, ...gh, see subroutine mym_turbulence.
!
!-------------------------------------------------------------------
!>\ingroup gsd_mynn_edmf
!! This subroutine initializes the mixing length, TKE, \f$\theta^{'2}\f$,
!! \f$q^{'2}\f$, and \f$\theta^{'}q^{'}\f$.
!!\section gen_mym_ini GSD MYNN-EDMF mym_initialize General Algorithm
!> @{
SUBROUTINE mym_initialize ( &
& kts,kte,xland, &
& dz, dx, zw, &
& u, v, thl, qw, &
! & ust, rmo, pmz, phh, flt, flq, &
& zi, theta, thetav, sh, sm, &
& ust, rmo, el, &
& Qke, Tsq, Qsq, Cov, Psig_bl, cldfra_bl1D, &
& bl_mynn_mixlength, &
& edmf_w1,edmf_a1, &
& INITIALIZE_QKE, &
& spp_pbl,rstoch_col)
!
!-------------------------------------------------------------------
integer, intent(in) :: kts,kte
integer, intent(in) :: bl_mynn_mixlength
logical, intent(in) :: INITIALIZE_QKE
! real(kind_phys), intent(in) :: ust, rmo, pmz, phh, flt, flq
real(kind_phys), intent(in) :: rmo, Psig_bl, xland
real(kind_phys), intent(in) :: dx, ust, zi
real(kind_phys), dimension(kts:kte), intent(in) :: dz
real(kind_phys), dimension(kts:kte+1), intent(in) :: zw
real(kind_phys), dimension(kts:kte), intent(in) :: u,v,thl,&
&qw,cldfra_bl1D,edmf_w1,edmf_a1
real(kind_phys), dimension(kts:kte), intent(out) :: tsq,qsq,cov
real(kind_phys), dimension(kts:kte), intent(inout) :: el,qke
real(kind_phys), dimension(kts:kte) :: &
&ql,pdk,pdt,pdq,pdc,dtl,dqw,dtv, &
&gm,gh,sm,sh,qkw,vt,vq
integer :: k,l,lmax
real(kind_phys):: phm,vkz,elq,elv,b1l,b2l,pmz=1.,phh=1., &
&flt=0.,fltv=0.,flq=0.,tmpq
real(kind_phys), dimension(kts:kte) :: theta,thetav
real(kind_phys), dimension(kts:kte) :: rstoch_col
integer ::spp_pbl
!> - At first ql, vt and vq are set to zero.
DO k = kts,kte
ql(k) = 0.0
vt(k) = 0.0
vq(k) = 0.0
END DO
!
!> - Call mym_level2() to calculate the stability functions at level 2.
CALL mym_level2 ( kts,kte, &
& dz, &
& u, v, thl, thetav, qw, &
& ql, vt, vq, &
& dtl, dqw, dtv, gm, gh, sm, sh )
!
! ** Preliminary setting **
el (kts) = 0.0
IF (INITIALIZE_QKE) THEN
!qke(kts) = ust**2 * ( b1*pmz )**(2.0/3.0)
qke(kts) = 1.5 * ust**2 * ( b1*pmz )**(2.0/3.0)
DO k = kts+1,kte
!qke(k) = 0.0
!linearly taper off towards top of pbl
qke(k)=qke(kts)*MAX((ust*700. - zw(k))/(MAX(ust,0.01)*700.), 0.01)
ENDDO
ENDIF
!
phm = phh*b2 / ( b1*pmz )**(1.0/3.0)
tsq(kts) = phm*( flt/ust )**2
qsq(kts) = phm*( flq/ust )**2
cov(kts) = phm*( flt/ust )*( flq/ust )
!
DO k = kts+1,kte
vkz = karman*zw(k)
el (k) = vkz/( 1.0 + vkz/100.0 )
! qke(k) = 0.0
!
tsq(k) = 0.0
qsq(k) = 0.0
cov(k) = 0.0
END DO
!
! ** Initialization with an iterative manner **
! ** lmax is the iteration count. This is arbitrary. **
lmax = 5
!
DO l = 1,lmax
!
!> - call mym_length() to calculate the master length scale.
CALL mym_length ( &
& kts,kte,xland, &
& dz, dx, zw, &
& rmo, flt, fltv, flq, &
& vt, vq, &
& u, v, qke, &
& dtv, &
& el, &
& zi,theta, &
& qkw,Psig_bl,cldfra_bl1D, &
& bl_mynn_mixlength, &
& edmf_w1,edmf_a1 )
!
DO k = kts+1,kte
elq = el(k)*qkw(k)
pdk(k) = elq*( sm(k)*gm(k) + &
& sh(k)*gh(k) )
pdt(k) = elq* sh(k)*dtl(k)**2
pdq(k) = elq* sh(k)*dqw(k)**2
pdc(k) = elq* sh(k)*dtl(k)*dqw(k)
END DO
!
! ** Strictly, vkz*h(i,j) -> karman*( 0.5*dz(1)*h(i,j)+z0 ) **
vkz = karman*0.5*dz(kts)
elv = 0.5*( el(kts+1)+el(kts) ) / vkz
IF (INITIALIZE_QKE)THEN
!qke(kts) = ust**2 * ( b1*pmz*elv )**(2.0/3.0)
qke(kts) = 1.0 * MAX(ust,0.02)**2 * ( b1*pmz*elv )**(2.0/3.0)
ENDIF
phm = phh*b2 / ( b1*pmz/elv**2 )**(1.0/3.0)
tsq(kts) = phm*( flt/ust )**2
qsq(kts) = phm*( flq/ust )**2
cov(kts) = phm*( flt/ust )*( flq/ust )
DO k = kts+1,kte-1
b1l = b1*0.25*( el(k+1)+el(k) )
!tmpq=MAX(b1l*( pdk(k+1)+pdk(k) ),qkemin)
!add MIN to limit unreasonable QKE
tmpq=MIN(MAX(b1l*( pdk(k+1)+pdk(k) ),qkemin),125.)
! PRINT *,'tmpqqqqq',tmpq,pdk(k+1),pdk(k)
IF (INITIALIZE_QKE)THEN
qke(k) = tmpq**twothirds
ENDIF
IF ( qke(k) .LE. 0.0 ) THEN
b2l = 0.0
ELSE
b2l = b2*( b1l/b1 ) / SQRT( qke(k) )
END IF
tsq(k) = b2l*( pdt(k+1)+pdt(k) )
qsq(k) = b2l*( pdq(k+1)+pdq(k) )
cov(k) = b2l*( pdc(k+1)+pdc(k) )
END DO
END DO
!! qke(kts)=qke(kts+1)
!! tsq(kts)=tsq(kts+1)
!! qsq(kts)=qsq(kts+1)
!! cov(kts)=cov(kts+1)
IF (INITIALIZE_QKE)THEN
qke(kts)=0.5*(qke(kts)+qke(kts+1))
qke(kte)=qke(kte-1)
ENDIF
tsq(kte)=tsq(kte-1)
qsq(kte)=qsq(kte-1)
cov(kte)=cov(kte-1)
!
! RETURN
END SUBROUTINE mym_initialize
!> @}
!
! ==================================================================
! SUBROUTINE mym_level2:
!
! Input variables: see subroutine mym_initialize
!
! Output variables:
! dtl(nx,nz,ny) : Vertical gradient of Theta_l (K/m)
! dqw(nx,nz,ny) : Vertical gradient of Q_w
! dtv(nx,nz,ny) : Vertical gradient of Theta_V (K/m)
! gm (nx,nz,ny) : G_M divided by L^2/q^2 (s^(-2))
! gh (nx,nz,ny) : G_H divided by L^2/q^2 (s^(-2))
! sm (nx,nz,ny) : Stability function for momentum, at Level 2
! sh (nx,nz,ny) : Stability function for heat, at Level 2
!
! These are defined on the walls of the grid boxes.
!
!>\ingroup gsd_mynn_edmf
!! This subroutine calculates the level 2, non-dimensional wind shear
!! \f$G_M\f$ and vertical temperature gradient \f$G_H\f$ as well as
!! the level 2 stability funcitons \f$S_h\f$ and \f$S_m\f$.
!!\param kts horizontal dimension
!!\param kte vertical dimension
!!\param dz vertical grid spacings (\f$m\f$)
!!\param u west-east component of the horizontal wind (\f$m s^{-1}\f$)
!!\param v south-north component of the horizontal wind (\f$m s^{-1}\f$)
!!\param thl liquid water potential temperature
!!\param qw total water content \f$Q_w\f$
!!\param ql liquid water content (\f$kg kg^{-1}\f$)
!!\param vt
!!\param vq
!!\param dtl vertical gradient of \f$\theta_l\f$ (\f$K m^{-1}\f$)
!!\param dqw vertical gradient of \f$Q_w\f$
!!\param dtv vertical gradient of \f$\theta_V\f$ (\f$K m^{-1}\f$)
!!\param gm \f$G_M\f$ divided by \f$L^{2}/q^{2}\f$ (\f$s^{-2}\f$)
!!\param gh \f$G_H\f$ divided by \f$L^{2}/q^{2}\f$ (\f$s^{-2}\f$)
!!\param sm stability function for momentum, at Level 2
!!\param sh stability function for heat, at Level 2
!!\section gen_mym_level2 GSD MYNN-EDMF mym_level2 General Algorithm
!! @ {
SUBROUTINE mym_level2 (kts,kte, &
& dz, &
& u, v, thl, thetav, qw, &
& ql, vt, vq, &
& dtl, dqw, dtv, gm, gh, sm, sh )
!
!-------------------------------------------------------------------
integer, intent(in) :: kts,kte
#ifdef HARDCODE_VERTICAL
# define kts 1
# define kte HARDCODE_VERTICAL
#endif
real(kind_phys), dimension(kts:kte), intent(in) :: dz
real(kind_phys), dimension(kts:kte), intent(in) :: u,v, &
&thl,qw,ql,vt,vq,thetav
real(kind_phys), dimension(kts:kte), intent(out) :: &
&dtl,dqw,dtv,gm,gh,sm,sh
integer :: k
real(kind_phys):: rfc,f1,f2,rf1,rf2,smc,shc, &
&ri1,ri2,ri3,ri4,duz,dtz,dqz,vtt,vqq,dtq,dzk, &
&afk,abk,ri,rf
real(kind_phys):: a2fac
! ev = 2.5e6
! tv0 = 0.61*tref
! tv1 = 1.61*tref
! gtr = 9.81/tref
!
rfc = g1/( g1+g2 )
f1 = b1*( g1-c1 ) +3.0*a2*( 1.0 -c2 )*( 1.0-c5 ) &
& +2.0*a1*( 3.0-2.0*c2 )
f2 = b1*( g1+g2 ) -3.0*a1*( 1.0 -c2 )
rf1 = b1*( g1-c1 )/f1
rf2 = b1* g1 /f2
smc = a1 /a2* f1/f2
shc = 3.0*a2*( g1+g2 )
!
ri1 = 0.5/smc
ri2 = rf1*smc
ri3 = 4.0*rf2*smc -2.0*ri2
ri4 = ri2**2
!
DO k = kts+1,kte
dzk = 0.5 *( dz(k)+dz(k-1) )
afk = dz(k)/( dz(k)+dz(k-1) )
abk = 1.0 -afk
duz = ( u(k)-u(k-1) )**2 +( v(k)-v(k-1) )**2
duz = duz /dzk**2
dtz = ( thl(k)-thl(k-1) )/( dzk )
dqz = ( qw(k)-qw(k-1) )/( dzk )
!
vtt = 1.0 +vt(k)*abk +vt(k-1)*afk ! Beta-theta in NN09, Eq. 39
vqq = tv0 +vq(k)*abk +vq(k-1)*afk ! Beta-q
dtq = vtt*dtz +vqq*dqz
!Alternatively, use theta-v without the SGS clouds
!dtq = ( thetav(k)-thetav(k-1) )/( dzk )
!
dtl(k) = dtz
dqw(k) = dqz
dtv(k) = dtq
!? dtv(i,j,k) = dtz +tv0*dqz
!? : +( xlv/pi0(i,j,k)-tv1 )
!? : *( ql(i,j,k)-ql(i,j,k-1) )/( dzk*h(i,j) )
!
gm (k) = duz
gh (k) = -dtq*gtr
!
! ** Gradient Richardson number **
ri = -gh(k)/MAX( duz, 1.0e-10 )
!a2fac is needed for the Canuto/Kitamura mod
IF (CKmod .eq. 1) THEN
a2fac = 1./(1. + MAX(ri,0.0))
ELSE
a2fac = 1.
ENDIF
rfc = g1/( g1+g2 )
f1 = b1*( g1-c1 ) +3.0*a2*a2fac *( 1.0 -c2 )*( 1.0-c5 ) &
& +2.0*a1*( 3.0-2.0*c2 )
f2 = b1*( g1+g2 ) -3.0*a1*( 1.0 -c2 )
rf1 = b1*( g1-c1 )/f1
rf2 = b1* g1 /f2
smc = a1 /(a2*a2fac)* f1/f2
shc = 3.0*(a2*a2fac)*( g1+g2 )
ri1 = 0.5/smc
ri2 = rf1*smc
ri3 = 4.0*rf2*smc -2.0*ri2
ri4 = ri2**2
! ** Flux Richardson number **
rf = MIN( ri1*( ri + ri2-SQRT(ri**2 - ri3*ri + ri4) ), rfc )
!
sh (k) = shc*( rfc-rf )/( 1.0-rf )
sm (k) = smc*( rf1-rf )/( rf2-rf ) * sh(k)
END DO
!
! RETURN
#ifdef HARDCODE_VERTICAL
# undef kts
# undef kte
#endif
END SUBROUTINE mym_level2
!! @}
! ==================================================================
! SUBROUTINE mym_length:
!
! Input variables: see subroutine mym_initialize
!
! Output variables: see subroutine mym_initialize
!
! Work arrays:
! elt(nx,ny) : Length scale depending on the PBL depth (m)
! vsc(nx,ny) : Velocity scale q_c (m/s)
! at first, used for computing elt
!
! NOTE: the mixing lengths are meant to be calculated at the full-
! sigmal levels (or interfaces beween the model layers).
!
!>\ingroup gsd_mynn_edmf
!! This subroutine calculates the mixing lengths.
SUBROUTINE mym_length ( &
& kts,kte,xland, &
& dz, dx, zw, &
& rmo, flt, fltv, flq, &
& vt, vq, &
& u1, v1, qke, &
& dtv, &
& el, &
& zi, theta, qkw, &
& Psig_bl, cldfra_bl1D, &
& bl_mynn_mixlength, &
& edmf_w1,edmf_a1 )
!-------------------------------------------------------------------
integer, intent(in) :: kts,kte
#ifdef HARDCODE_VERTICAL
# define kts 1
# define kte HARDCODE_VERTICAL
#endif
integer, intent(in) :: bl_mynn_mixlength
real(kind_phys), dimension(kts:kte), intent(in) :: dz
real(kind_phys), dimension(kts:kte+1), intent(in) :: zw
real(kind_phys), intent(in) :: rmo,flt,fltv,flq,Psig_bl,xland
real(kind_phys), intent(in) :: dx,zi
real(kind_phys), dimension(kts:kte), intent(in) :: u1,v1, &
&qke,vt,vq,cldfra_bl1D,edmf_w1,edmf_a1
real(kind_phys), dimension(kts:kte), intent(out) :: qkw, el
real(kind_phys), dimension(kts:kte), intent(in) :: dtv
real(kind_phys):: elt,vsc
real(kind_phys), dimension(kts:kte), intent(in) :: theta
real(kind_phys), dimension(kts:kte) :: qtke,elBLmin,elBLavg,thetaw
real(kind_phys):: wt,wt2,zi2,h1,h2,hs,elBLmin0,elBLavg0,cldavg
! THE FOLLOWING CONSTANTS ARE IMPORTANT FOR REGULATING THE
! MIXING LENGTHS:
real(kind_phys):: cns, & !< for surface layer (els) in stable conditions
alp1, & !< for turbulent length scale (elt)
alp2, & !< for buoyancy length scale (elb)
alp3, & !< for buoyancy enhancement factor of elb
alp4, & !< for surface layer (els) in unstable conditions
alp5, & !< for BouLac mixing length or above PBLH
alp6 !< for mass-flux/
!THE FOLLOWING LIMITS DO NOT DIRECTLY AFFECT THE ACTUAL PBLH.
!THEY ONLY IMPOSE LIMITS ON THE CALCULATION OF THE MIXING LENGTH
!SCALES SO THAT THE BOULAC MIXING LENGTH (IN FREE ATMOS) DOES
!NOT ENCROACH UPON THE BOUNDARY LAYER MIXING LENGTH (els, elb & elt).
real(kind_phys), parameter :: minzi = 300. !< min mixed-layer height
real(kind_phys), parameter :: maxdz = 750. !< max (half) transition layer depth
!! =0.3*2500 m PBLH, so the transition
!! layer stops growing for PBLHs > 2.5 km.
real(kind_phys), parameter :: mindz = 300. !< 300 !min (half) transition layer depth
!SURFACE LAYER LENGTH SCALE MODS TO REDUCE IMPACT IN UPPER BOUNDARY LAYER
real(kind_phys), parameter :: ZSLH = 100. !< Max height correlated to surface conditions (m)
real(kind_phys), parameter :: CSL = 2. !< CSL = constant of proportionality to L O(1)
integer :: i,j,k
real(kind_phys):: afk,abk,zwk,zwk1,dzk,qdz,vflx,bv,tau_cloud, &
& wstar,elb,els,elf,el_stab,el_mf,el_stab_mf,elb_mf, &
& PBLH_PLUS_ENT,Uonset,Ugrid,wt_u,el_les
real(kind_phys), parameter :: ctau = 1000. !constant for tau_cloud
! tv0 = 0.61*tref
! gtr = 9.81/tref
SELECT CASE(bl_mynn_mixlength)
CASE (0) ! ORIGINAL MYNN MIXING LENGTH + BouLac
cns = 2.7
alp1 = 0.23
alp2 = 1.0
alp3 = 5.0
alp4 = 100.
alp5 = 0.3
! Impose limits on the height integration for elt and the transition layer depth
zi2 = MIN(10000.,zw(kte-2)) !originally integrated to model top, not just 10 km.
h1=MAX(0.3*zi2,mindz)
h1=MIN(h1,maxdz) ! 1/2 transition layer depth
h2=h1/2.0 ! 1/4 transition layer depth
qkw(kts) = SQRT(MAX(qke(kts),1.0e-10))
DO k = kts+1,kte
afk = dz(k)/( dz(k)+dz(k-1) )
abk = 1.0 -afk
qkw(k) = SQRT(MAX(qke(k)*abk+qke(k-1)*afk,1.0e-3))
END DO
elt = 1.0e-5
vsc = 1.0e-5
! ** Strictly, zwk*h(i,j) -> ( zwk*h(i,j)+z0 ) **
k = kts+1
zwk = zw(k)
DO WHILE (zwk .LE. zi2+h1)
dzk = 0.5*( dz(k)+dz(k-1) )
qdz = MAX( qkw(k)-qmin, 0.03 )*dzk
elt = elt +qdz*zwk
vsc = vsc +qdz
k = k+1
zwk = zw(k)
END DO
elt = alp1*elt/vsc
vflx = ( vt(kts)+1.0 )*flt +( vq(kts)+tv0 )*flq
vsc = ( gtr*elt*MAX( vflx, 0.0 ) )**(1.0/3.0)
! ** Strictly, el(i,k=1) is not zero. **
el(kts) = 0.0
zwk1 = zw(kts+1)
DO k = kts+1,kte
zwk = zw(k) !full-sigma levels
! ** Length scale limited by the buoyancy effect **
IF ( dtv(k) .GT. 0.0 ) THEN
bv = SQRT( gtr*dtv(k) )
elb = alp2*qkw(k) / bv &
& *( 1.0 + alp3/alp2*&
&SQRT( vsc/( bv*elt ) ) )
elf = alp2 * qkw(k)/bv
ELSE
elb = 1.0e10
elf = elb
ENDIF
! ** Length scale in the surface layer **
IF ( rmo .GT. 0.0 ) THEN
els = karman*zwk/(1.0+cns*MIN( zwk*rmo, zmax ))
ELSE
els = karman*zwk*( 1.0 - alp4* zwk*rmo )**0.2
END IF
! ** HARMONC AVERGING OF MIXING LENGTH SCALES:
! el(k) = MIN(elb/( elb/elt+elb/els+1.0 ),elf)
! el(k) = elb/( elb/elt+elb/els+1.0 )
wt=.5*TANH((zwk - (zi2+h1))/h2) + .5
el(k) = MIN(elb/( elb/elt+elb/els+1.0 ),elf)
END DO
CASE (1) !NONLOCAL (using BouLac) FORM OF MIXING LENGTH
ugrid = sqrt(u1(kts)**2 + v1(kts)**2)
uonset= 15.
wt_u = (1.0 - min(max(ugrid - uonset, 0.0)/30.0, 0.5))
cns = 2.7 !was 3.5
alp1 = 0.23
alp2 = 0.3
alp3 = 2.5 * wt_u !taper off bouyancy enhancement in shear-driven pbls
alp4 = 5.0
alp5 = 0.3
alp6 = 50.
! Impose limits on the height integration for elt and the transition layer depth
zi2=MAX(zi,300.) !minzi)
h1=MAX(0.3*zi2,300.)
h1=MIN(h1,600.) ! 1/2 transition layer depth
h2=h1/2.0 ! 1/4 transition layer depth
qtke(kts)=MAX(0.5*qke(kts), 0.01) !tke at full sigma levels
thetaw(kts)=theta(kts) !theta at full-sigma levels
qkw(kts) = SQRT(MAX(qke(kts),1.0e-10))
DO k = kts+1,kte
afk = dz(k)/( dz(k)+dz(k-1) )
abk = 1.0 -afk
qkw(k) = SQRT(MAX(qke(k)*abk+qke(k-1)*afk,1.0e-3))
qtke(k) = 0.5*(qkw(k)**2) ! q -> TKE
thetaw(k)= theta(k)*abk + theta(k-1)*afk
END DO
elt = 1.0e-5
vsc = 1.0e-5
! ** Strictly, zwk*h(i,j) -> ( zwk*h(i,j)+z0 ) **
k = kts+1
zwk = zw(k)
DO WHILE (zwk .LE. zi2+h1)
dzk = 0.5*( dz(k)+dz(k-1) )
qdz = min(max( qkw(k)-qmin, 0.03 ), 30.0)*dzk
elt = elt +qdz*zwk
vsc = vsc +qdz
k = k+1