CCPP SciDoc v7.0.0  v7.0.0
Common Community Physics Package Developed at DTC
 
Loading...
Searching...
No Matches
module_bl_mynn.F90
1
3! **********************************************************************
4! * An improved Mellor-Yamada turbulence closure model *
5! * *
6! * Original author: M. Nakanishi (N.D.A), naka@nda.ac.jp *
7! * Translated into F90 and implemented in WRF-ARW by: *
8! * Mariusz Pagowski (NOAA-GSL) *
9! * Subsequently developed by: *
10! * Joseph Olson, Jaymes Kenyon (NOAA/GSL), *
11! * Wayne Angevine (NOAA/CSL), Kay Suselj (NASA/JPL), *
12! * Franciano Puhales (UFSM), Laura Fowler (NCAR), *
13! * Elynn Wu (UCSD), and Jordan Schnell (NOAA/GSL) *
14! * *
15! * Contents: *
16! * *
17! * mynn_bl_driver - main subroutine which calls all other routines *
18! * -------------- *
19! * 1. mym_initialize (to be called once initially) *
20! * gives the closure constants and initializes the turbulent *
21! * quantities. *
22! * 2. get_pblh *
23! * Calculates the boundary layer height *
24! * 3. scale_aware *
25! * Calculates scale-adaptive tapering functions *
26! * 4. mym_condensation *
27! * determines the liquid water content and the cloud fraction *
28! * diagnostically. *
29! * 5. dmp_mf *
30! * Calls the (nonlocal) mass-flux component *
31! * 6. ddmf_jpl *
32! * Calls the downdraft mass-flux component *
33! * (-) mym_level2 (called in the other subroutines) *
34! * calculates the stability functions at Level 2. *
35! * (-) mym_length (called in the other subroutines) *
36! * calculates the master length scale. *
37! * 7. mym_turbulence *
38! * calculates the vertical diffusivity coefficients and the *
39! * production terms for the turbulent quantities. *
40! * 8. mym_predict *
41! * predicts the turbulent quantities at the next step. *
42! * *
43! * call mym_initialize *
44! * | *
45! * |<----------------+ *
46! * | | *
47! * call get_pblh | *
48! * call scale_aware | *
49! * call mym_condensation | *
50! * call dmp_mf | *
51! * call ddmf_jpl | *
52! * call mym_turbulence | *
53! * call mym_predict | *
54! * | | *
55! * |-----------------+ *
56! * | *
57! * end *
58! * *
59! * Variables worthy of special mention: *
60! * tref : Reference temperature *
61! * thl : Liquid water potential temperature *
62! * qw : Total water (water vapor+liquid water) content *
63! * ql : Liquid water content *
64! * vt, vq : Functions for computing the buoyancy flux *
65! * qke : 2 * TKE *
66! * el : mixing length *
67! * *
68! * If the water contents are unnecessary, e.g., in the case of *
69! * ocean models, thl is the potential temperature and qw, ql, vt *
70! * and vq are all zero. *
71! * *
72! * Grid arrangement: *
73! * k+1 +---------+ *
74! * | | i = 1 - nx *
75! * (k) | * | k = 1 - nz *
76! * | | *
77! * k +---------+ *
78! * i (i) i+1 *
79! * *
80! * All the predicted variables are defined at the center (*) of *
81! * the grid boxes. The diffusivity coefficients and two of their *
82! * components (el and stability functions sh & sm) are, however, *
83! * defined on the walls of the grid boxes. *
84! * # Upper boundary values are given at k=nz. *
85! * *
86! * References: *
87! * 1. Nakanishi, M., 2001: *
88! * Boundary-Layer Meteor., 99, 349-378. *
89! * 2. Nakanishi, M. and H. Niino, 2004: *
90! * Boundary-Layer Meteor., 112, 1-31. *
91! * 3. Nakanishi, M. and H. Niino, 2006: *
92! * Boundary-Layer Meteor., 119, 397-407. *
93! * 4. Nakanishi, M. and H. Niino, 2009: *
94! * Jour. Meteor. Soc. Japan, 87, 895-912. *
95! * 5. Olson J. and coauthors, 2019: A description of the *
96! * MYNN-EDMF scheme and coupling to other components in *
97! * WRF-ARW. NOAA Tech. Memo. OAR GSD, 61, 37 pp., *
98! * https://doi.org/10.25923/n9wm-be49. *
99! * 6. Puhales, Franciano S. and coauthors, 2020: Turbulent *
100! * Kinetic Energy Budget for MYNN-EDMF PBL Scheme in WRF model.*
101! * Universidade Federal de Santa Maria Technical Note. 9 pp. *
102! **********************************************************************
103! ==================================================================
104! Notes on original implementation into WRF-ARW
105! changes to original code:
106! 1. code is 1D (in z)
107! 2. option to advect TKE, but not the covariances and variances
108! 3. Cranck-Nicholson replaced with the implicit scheme
109! 4. removed terrain-dependent grid since input in WRF in actual
110! distances in z[m]
111! 5. cosmetic changes to adhere to WRF standard (remove common blocks,
112! intent etc)
113!-------------------------------------------------------------------
114! Further modifications post-implementation
115!
116! 1. Addition of BouLac mixing length in the free atmosphere.
117! 2. Changed the turbulent mixing length to be integrated from the
118! surface to the top of the BL + a transition layer depth.
119! v3.4.1: Option to use Kitamura/Canuto modification which removes
120! the critical Richardson number and negative TKE (default).
121! Hybrid PBL height diagnostic, which blends a theta-v-based
122! definition in neutral/convective BL and a TKE-based definition
123! in stable conditions.
124! TKE budget output option
125! v3.5.0: TKE advection option (bl_mynn_tkeadvect)
126! v3.5.1: Fog deposition related changes.
127! v3.6.0: Removed fog deposition from the calculation of tendencies
128! Added mixing of qc, qi, qni
129! Added output for wstar, delta, TKE_PBL, & KPBL for correct
130! coupling to shcu schemes
131! v3.8.0: Added subgrid scale cloud output for coupling to radiation
132! schemes (activated by setting icloud_bl =1 in phys namelist).
133! Added WRF_DEBUG prints (at level 3000)
134! Added Tripoli and Cotton (1981) correction.
135! Added namelist option bl_mynn_cloudmix to test effect of mixing
136! cloud species (default = 1: on).
137! Added mass-flux option (bl_mynn_edmf, = 1 for DMP mass-flux, 0: off).
138! Related options:
139! bl_mynn_edmf_mom = 1 : activate momentum transport in MF scheme
140! bl_mynn_edmf_tke = 1 : activate TKE transport in MF scheme
141! Added mixing length option (bl_mynn_mixlength, see notes below)
142! Added more sophisticated saturation checks, following Thompson scheme
143! Added new cloud PDF option (bl_mynn_cloudpdf = 2) from Chaboureau
144! and Bechtold (2002, JAS, with mods)
145! Added capability to mix chemical species when env variable
146! WRF_CHEM = 1, thanks to Wayne Angevine.
147! Added scale-aware mixing length, following Junshi Ito's work
148! Ito et al. (2015, BLM).
149! v3.9.0 Improvement to the mass-flux scheme (dynamic number of plumes,
150! better plume/cloud depth, significant speed up, better cloud
151! fraction).
152! Added Stochastic Parameter Perturbation (SPP) implementation.
153! Many miscellaneous tweaks to the mixing lengths and stratus
154! component of the subgrid clouds.
155! v.4.0 Removed or added alternatives to WRF-specific functions/modules
156! for the sake of portability to other models.
157! the sake of portability to other models.
158! Further refinement of mass-flux scheme from SCM experiments with
159! Wayne Angevine: switch to linear entrainment and back to
160! Simpson and Wiggert-type w-equation.
161! Addition of TKE production due to radiation cooling at top of
162! clouds (proto-version); not activated by default.
163! Some code rewrites to move if-thens out of loops in an attempt to
164! improve computational efficiency.
165! New tridiagonal solver, which is supposedly 14% faster and more
166! conservative. Impact seems very small.
167! Many miscellaneous tweaks to the mixing lengths and stratus
168! component of the subgrid-scale (SGS) clouds.
169! v4.1 Big improvements in downward SW radiation due to revision of subgrid clouds
170! - better cloud fraction and subgrid scale mixing ratios.
171! - may experience a small cool bias during the daytime now that high
172! SW-down bias is greatly reduced...
173! Some tweaks to increase the turbulent mixing during the daytime for
174! bl_mynn_mixlength option 2 to alleviate cool bias (very small impact).
175! Improved ensemble spread from changes to SPP in MYNN
176! - now perturbing eddy diffusivity and eddy viscosity directly
177! - now perturbing background rh (in SGS cloud calc only)
178! - now perturbing entrainment rates in mass-flux scheme
179! Added IF checks (within IFDEFS) to protect mixchem code from being used
180! when HRRR smoke is used (no impact on regular non-wrf chem use)
181! Important bug fix for wrf chem when transporting chemical species in MF scheme
182! Removed 2nd mass-flux scheme (no only bl_mynn_edmf = 1, no option 2)
183! Removed unused stochastic code for mass-flux scheme
184! Changed mass-flux scheme to be integrated on interface levels instead of
185! mass levels - impact is small
186! Added option to mix 2nd moments in MYNN as opposed to the scalar_pblmix option.
187! - activated with bl_mynn_mixscalars = 1; this sets scalar_pblmix = 0
188! - added tridagonal solver used in scalar_pblmix option to duplicate tendencies
189! - this alone changes the interface call considerably from v4.0.
190! Slight revision to TKE production due to radiation cooling at top of clouds
191! Added the non-Guassian buoyancy flux function of Bechtold and Siebesma (1998, JAS).
192! - improves TKE in SGS clouds
193! Added heating due to dissipation of TKE (small impact, maybe + 0.1 C daytime PBL temp)
194! Misc changes made for FV3/MPAS compatibility
195! v4.2 A series of small tweaks to help reduce a cold bias in the PBL:
196! - slight increase in diffusion in convective conditions
197! - relaxed criteria for mass-flux activation/strength
198! - added capability to cycle TKE for continuity in hourly updating HRRR
199! - added effects of compensational environmental subsidence in mass-flux scheme,
200! which resulted in tweaks to detrainment rates.
201! Bug fix for diagnostic-decay of SGS clouds - noticed by Greg Thompson. This has
202! a very small, but primarily positive, impact on SW-down biases.
203! Tweak to calculation of KPBL - urged by Laura Fowler - to make more intuitive.
204! Tweak to temperature range of blending for saturation check (water to ice). This
205! slightly reduces excessive SGS clouds in polar region. No impact warm clouds.
206! Added namelist option bl_mynn_output (0 or 1) to suppress or activate the
207! allocation and output of 10 3D variables. Most people will want this
208! set to 0 (default) to save memory and disk space.
209! Added new array qi_bl as opposed to using qc_bl for both SGS qc and qi. This
210! gives us more control of the magnitudes which can be confounded by using
211! a single array. As a results, many subroutines needed to be modified,
212! especially mym_condensation.
213! Added the blending of the stratus component of the SGS clouds to the mass-flux
214! clouds to account for situations where stratus and cumulus may exist in the
215! grid cell.
216! Misc small-impact bugfixes:
217! 1) dz was incorrectly indexed in mym_condensation
218! 2) configurations with icloud_bl = 0 were using uninitialized arrays
219! v4.5 / CCPP
220! This version includes many modifications that proved valuable in the global
221! framework and removes some key lingering bugs in the mixing of chemical species.
222! TKE Budget output fixed (Puhales, 2020-12)
223! New option for stability function: (Puhales, 2020-12)
224! bl_mynn_stfunc = 0 (original, Kansas-type function, Paulson, 1970 )
225! bl_mynn_stfunc = 1 (expanded range, same as used for Jimenez et al (MWR)
226! see the Technical Note for this implementation (small impact).
227! Improved conservation of momentum and higher-order moments.
228! Important bug fixes for mixing of chemical species.
229! Addition of pressure-gradient effects on updraft momentum transport.
230! Addition of bl_mynn_closure option = 2.5, 2.6, or 3.0
231! Addition of higher-order moments for sigma when using
232! bl_mynn_cloudpdf = 2 (Chab-Becht).
233! Removed WRF_CHEM dependencies.
234! Many miscellaneous tweaks.
235! v4.5.2 / CCPP
236! Some code optimization. Removed many conditions from loops. Redesigned the mass-
237! flux scheme to use 8 plumes instead of a variable n plumes. This results in
238! the removal of the output variable "nudprafts" and adds maxwidth and ztop_plume.
239! Revision option bl_mynn_cloudpdf = 2, which now ensures cloud fractions for all
240! optically relevant mixing ratios (tip from Greg Thompson). Also, added flexibility
241! for tuning near-surface cloud fractions to remove excess fog/low ceilings.
242! Now outputs all SGS cloud mixing ratios as grid-mean values, not in-cloud. This
243! results in a change in the pre-radiation code to no longer multiply mixing ratios
244! by cloud fractions.
245! Lots of code cleanup: removal of test code, comments, changing text case, etc.
246! Many misc tuning/tweaks.
247!
248! Many of these changes are now documented in references listed above.
249!====================================================================
250
253
254 use bl_mynn_common,only: &
255 cp , cpv , cliq , cice , &
256 p608 , ep_2 , ep_3 , gtr , &
257 grav , g_inv , karman , p1000mb , &
258 rcp , r_d , r_v , rk , &
259 rvovrd , svp1 , svp2 , svp3 , &
260 xlf , xlv , xls , xlscp , &
261 xlvcp , tv0 , tv1 , tref , &
262 zero , half , one , two , &
263 onethird , twothirds , tkmin , t0c , &
264 tice , kind_phys
265
266
267 IMPLICIT NONE
268
269!===================================================================
270! From here on, these are MYNN-specific parameters:
271! The parameters below depend on stability functions of module_sf_mynn.
272 real(kind_phys), parameter :: cphm_st=5.0, cphm_unst=16.0, &
273 cphh_st=5.0, cphh_unst=16.0
274
275! Closure constants
276 real(kind_phys), parameter :: &
277 &pr = 0.74, &
278 &g1 = 0.235, & ! NN2009 = 0.235
279 &b1 = 24.0, &
280 &b2 = 15.0, & ! CKmod NN2009
281 &c2 = 0.729, & ! 0.729, & !0.75, &
282 &c3 = 0.340, & ! 0.340, & !0.352, &
283 &c4 = 0.0, &
284 &c5 = 0.2, &
285 &a1 = b1*( 1.0-3.0*g1 )/6.0, &
286! &c1 = g1 -1.0/( 3.0*a1*b1**(1.0/3.0) ), &
287 &c1 = g1 -1.0/( 3.0*a1*2.88449914061481660), &
288 &a2 = a1*( g1-c1 )/( g1*pr ), &
289 &g2 = b2/b1*( 1.0-c3 ) +2.0*a1/b1*( 3.0-2.0*c2 )
290
291 real(kind_phys), parameter :: &
292 &cc2 = 1.0-c2, &
293 &cc3 = 1.0-c3, &
294 &e1c = 3.0*a2*b2*cc3, &
295 &e2c = 9.0*a1*a2*cc2, &
296 &e3c = 9.0*a2*a2*cc2*( 1.0-c5 ), &
297 &e4c = 12.0*a1*a2*cc2, &
298 &e5c = 6.0*a1*a1
299
300! Constants for min tke in elt integration (qmin), max z/L in els (zmax),
301! and factor for eddy viscosity for TKE (Kq = Sqfac*Km):
302 real(kind_phys), parameter :: qmin=0.0, zmax=1.0, sqfac=3.0
303! Note that the following mixing-length constants are now specified in mym_length
304! &cns=3.5, alp1=0.23, alp2=0.3, alp3=3.0, alp4=10.0, alp5=0.2
305
306 real(kind_phys), parameter :: gpw=5./3., qcgmin=1.e-8, qkemin=1.e-12
307 real(kind_phys), parameter :: tliq = 269. !all hydrometeors are liquid when T > tliq
308
309! Constants for cloud PDF (mym_condensation)
310 real(kind_phys), parameter :: rr2=0.7071068, rrp=0.3989423
311
320 real(kind_phys), parameter :: ckmod=1.
321
325 real(kind_phys), parameter :: scaleaware=1.
326
329 integer, parameter :: bl_mynn_topdown = 0
331 integer, parameter :: bl_mynn_edmf_dd = 0
332
334 integer, parameter :: dheat_opt = 1
335
336 !Option to activate environmental subsidence in mass-flux scheme
337 logical, parameter :: env_subs = .false.
338
339 !Option to switch flux-profile relationship for surface (from Puhales et al. 2020)
340 !0: use original Dyer-Hicks, 1: use Cheng-Brustaert and Blended COARE
341 integer, parameter :: bl_mynn_stfunc = 1
342
343 !option to print out more stuff for debugging purposes
344 logical, parameter :: debug_code = .false.
345 integer, parameter :: idbg = 23 !specific i-point to write out
346
347 ! Used in WRF-ARW module_physics_init.F
348 integer :: mynn_level
349
350
351CONTAINS
352
353! ==================================================================
361 SUBROUTINE mynn_bl_driver( &
362 &initflag,restart,cycling, &
363 &delt,dz,dx,znt, &
364 &u,v,w,th,sqv3d,sqc3d,sqi3d, &
365 &sqs3d,qnc,qni, &
366 &qnwfa,qnifa,qnbca,ozone, &
367 &p,exner,rho,t3d, &
368 &xland,ts,qsfc,ps, &
369 &ust,ch,hfx,qfx,rmol,wspd, &
370 &uoce,voce, & !ocean current
371 &qke,qke_adv, &
372 &sh3d,sm3d, &
373 &nchem,kdvel,ndvel, & !Smoke/Chem variables
374 &chem3d,vdep,smoke_dbg, &
375 &frp,emis_ant_no, & ! JLS/RAR to adjust exchange coeffs
376 &mix_chem,enh_mix,rrfs_sd, & ! end smoke/chem variables
377 &tsq,qsq,cov, &
378 &rublten,rvblten,rthblten, &
379 &rqvblten,rqcblten,rqiblten, &
380 &rqncblten,rqniblten,rqsblten, &
381 &rqnwfablten,rqnifablten, &
382 &rqnbcablten,dozone, &
383 &exch_h,exch_m, &
384 &pblh,kpbl, &
385 &el_pbl, &
386 &dqke,qwt,qshear,qbuoy,qdiss, &
387 &qc_bl,qi_bl,cldfra_bl, &
388 &bl_mynn_tkeadvect, &
389 &tke_budget, &
390 &bl_mynn_cloudpdf, &
391 &bl_mynn_mixlength, &
392 &icloud_bl, &
393 &closure, &
394 &bl_mynn_edmf, &
395 &bl_mynn_edmf_mom, &
396 &bl_mynn_edmf_tke, &
397 &bl_mynn_mixscalars, &
398 &bl_mynn_output, &
399 &bl_mynn_cloudmix,bl_mynn_mixqt, &
400 &edmf_a,edmf_w,edmf_qt, &
401 &edmf_thl,edmf_ent,edmf_qc, &
402 &sub_thl3D,sub_sqv3D, &
403 &det_thl3D,det_sqv3D, &
404 &maxwidth,maxMF,ztop_plume, &
405 &ktop_plume, &
406 &spp_pbl,pattern_spp_pbl, &
407 &rthraten, &
408 &FLAG_QC,FLAG_QI,FLAG_QNC, &
409 &FLAG_QNI,FLAG_QS, &
410 &FLAG_QNWFA,FLAG_QNIFA, &
411 &FLAG_QNBCA,FLAG_OZONE, &
412 &IDS,IDE,JDS,JDE,KDS,KDE, &
413 &IMS,IME,JMS,JME,KMS,KME, &
414 &ITS,ITE,JTS,JTE,KTS,KTE )
415
416!-------------------------------------------------------------------
417
418 integer, intent(in) :: initflag
419 !INPUT NAMELIST OPTIONS:
420 logical, intent(in) :: restart,cycling
421 integer, intent(in) :: tke_budget
422 integer, intent(in) :: bl_mynn_cloudpdf
423 integer, intent(in) :: bl_mynn_mixlength
424 integer, intent(in) :: bl_mynn_edmf
425 logical, intent(in) :: bl_mynn_tkeadvect
426 integer, intent(in) :: bl_mynn_edmf_mom
427 integer, intent(in) :: bl_mynn_edmf_tke
428 integer, intent(in) :: bl_mynn_mixscalars
429 integer, intent(in) :: bl_mynn_output
430 integer, intent(in) :: bl_mynn_cloudmix
431 integer, intent(in) :: bl_mynn_mixqt
432 integer, intent(in) :: icloud_bl
433 real(kind_phys), intent(in) :: closure
434
435 logical, intent(in) :: FLAG_QI,FLAG_QNI,FLAG_QC,FLAG_QNC,&
436 FLAG_QNWFA,FLAG_QNIFA,FLAG_QNBCA, &
437 FLAG_OZONE,FLAG_QS
438
439 logical, intent(in) :: mix_chem,enh_mix,rrfs_sd,smoke_dbg
440
441 integer, intent(in) :: &
442 & IDS,IDE,JDS,JDE,KDS,KDE &
443 &,IMS,IME,JMS,JME,KMS,KME &
444 &,ITS,ITE,JTS,JTE,KTS,KTE
445
446#ifdef HARDCODE_VERTICAL
447# define kts 1
448# define kte HARDCODE_VERTICAL
449#endif
450
451! initflag > 0 for TRUE
452! else for FALSE
453! closure : <= 2.5; Level 2.5
454! 2.5< and <3; Level 2.6
455! = 3; Level 3
456
457 real(kind_phys), intent(in) :: delt
458 real(kind_phys), dimension(:), intent(in) :: dx
459 real(kind_phys), dimension(:,:), intent(in) :: dz, &
460 &u,v,w,th,sqv3D,p,exner,rho,T3D
461 real(kind_phys), dimension(:,:), intent(in) :: &
462 &sqc3D,sqi3D,sqs3D,qni,qnc,qnwfa,qnifa,qnbca
463 real(kind_phys), dimension(:,:), intent(in):: ozone
464 real(kind_phys), dimension(:), intent(in):: ust, &
465 &ch,qsfc,ps,wspd
466 real(kind_phys), dimension(:,:), intent(inout), optional :: &
467 &Qke,Tsq,Qsq,Cov
468 real(kind_phys), dimension(:,:), intent(inout) :: &
469 &qke_adv
470 real(kind_phys), dimension(:,:), intent(inout) :: &
471 &rublten,rvblten,rthblten,rqvblten,rqcblten, &
472 &rqiblten,rqsblten,rqniblten,rqncblten, &
473 &rqnwfablten,rqnifablten,rqnbcablten
474 real(kind_phys), dimension(:,:), intent(inout) :: dozone
475 real(kind_phys), dimension(:,:), intent(in) :: rthraten
476
477 real(kind_phys), dimension(:,:), intent(out), optional :: exch_h,exch_m
478 real(kind_phys), dimension(:), intent(in) :: xland, &
479 &ts,znt,hfx,qfx,uoce,voce
480
481 !These 10 arrays are only allocated when bl_mynn_output > 0
482 real(kind_phys), dimension(:,:), intent(inout), optional :: &
483 & edmf_a,edmf_w,edmf_qt,edmf_thl,edmf_ent,edmf_qc, &
484 & sub_thl3D,sub_sqv3D,det_thl3D,det_sqv3D
485
486! real, dimension(ims:ime,kms:kme) :: &
487! & edmf_a_dd,edmf_w_dd,edmf_qt_dd,edmf_thl_dd,edmf_ent_dd,edmf_qc_dd
488
489 real(kind_phys), dimension(:), intent(inout) :: Pblh
490 real(kind_phys), dimension(:), intent(inout) :: rmol
491
492 real(kind_phys), dimension(ims:ime) :: psig_bl,psig_shcu
493
494 integer,dimension(:),intent(INOUT) :: &
495 &KPBL
496 integer,dimension(:),intent(INOUT), optional :: &
497 &ktop_plume
498
499 real(kind_phys), dimension(:), intent(out), optional :: &
500 &maxmf,maxwidth,ztop_plume
501
502 real(kind_phys), dimension(:,:), intent(inout), optional :: el_pbl
503
504 real(kind_phys), dimension(:,:), intent(inout), optional :: &
505 &qWT,qSHEAR,qBUOY,qDISS,dqke
506 ! 3D budget arrays are not allocated when tke_budget == 0
507 ! 1D (local) budget arrays are used for passing between subroutines.
508 real(kind_phys), dimension(kts:kte) :: &
509 &qwt1,qshear1,qbuoy1,qdiss1,dqke1,diss_heat
510
511 real(kind_phys), dimension(:,:), intent(out), optional :: Sh3D,Sm3D
512
513 real(kind_phys), dimension(:,:), intent(inout), optional :: &
514 &qc_bl,qi_bl,cldfra_bl
515 real(kind_phys), dimension(kts:kte) :: qc_bl1D,qi_bl1D, &
516 &cldfra_bl1D,qc_bl1D_old,qi_bl1D_old,cldfra_bl1D_old
517
518! smoke/chemical arrays
519 integer, intent(IN ) :: nchem, kdvel, ndvel
520 real(kind_phys), dimension(:,:,:), intent(INOUT), optional :: chem3d
521 real(kind_phys), dimension(:,:), intent(IN), optional :: vdep
522 real(kind_phys), dimension(:), intent(IN), optional :: frp
523 real(kind_phys), dimension(:), intent(IN) :: EMIS_ANT_NO
524 !local
525 real(kind_phys), dimension(kts:kte ,nchem) :: chem1
526 real(kind_phys), dimension(kts:kte+1,nchem) :: s_awchem1
527 real(kind_phys), dimension(ndvel) :: vd1
528 integer :: ic
529
530!local vars
531 integer :: ITF,JTF,KTF, IMD,JMD
532 integer :: i,j,k,kproblem
533 real(kind_phys), dimension(kts:kte) :: &
534 &thl,tl,qv1,qc1,qi1,qs1,sqw, &
535 &el, dfm, dfh, dfq, tcd, qcd, pdk, pdt, pdq, pdc, &
536 &vt, vq, sgm, kzero
537 real(kind_phys), dimension(kts:kte) :: &
538 &thetav,sh,sm,u1,v1,w1,p1, &
539 &ex1,dz1,th1,tk1,rho1,qke1,tsq1,qsq1,cov1, &
540 &sqv,sqi,sqc,sqs, &
541 &du1,dv1,dth1,dqv1,dqc1,dqi1,dqs1,ozone1, &
542 &k_m1,k_h1,qni1,dqni1,qnc1,dqnc1,qnwfa1,qnifa1, &
543 &qnbca1,dqnwfa1,dqnifa1,dqnbca1,dozone1
544
545 !mass-flux variables
546 real(kind_phys), dimension(kts:kte) :: &
547 &dth1mf,dqv1mf,dqc1mf,du1mf,dv1mf
548 real(kind_phys), dimension(kts:kte) :: &
549 &edmf_a1,edmf_w1,edmf_qt1,edmf_thl1, &
550 &edmf_ent1,edmf_qc1
551 real(kind_phys), dimension(kts:kte) :: &
552 &edmf_a_dd1,edmf_w_dd1,edmf_qt_dd1,edmf_thl_dd1, &
553 &edmf_ent_dd1,edmf_qc_dd1
554 real(kind_phys), dimension(kts:kte) :: &
555 &sub_thl,sub_sqv,sub_u,sub_v, &
556 &det_thl,det_sqv,det_sqc,det_u,det_v
557 real(kind_phys), dimension(kts:kte+1) :: &
558 &s_aw1,s_awthl1,s_awqt1, &
559 &s_awqv1,s_awqc1,s_awu1,s_awv1,s_awqke1, &
560 &s_awqnc1,s_awqni1,s_awqnwfa1,s_awqnifa1, &
561 &s_awqnbca1
562 real(kind_phys), dimension(kts:kte+1) :: &
563 &sd_aw1,sd_awthl1,sd_awqt1, &
564 &sd_awqv1,sd_awqc1,sd_awu1,sd_awv1,sd_awqke1
565
566 real(kind_phys), dimension(kts:kte+1) :: zw
567 real(kind_phys) :: cpm,sqcg,flt,fltv,flq,flqv,flqc, &
568 &pmz,phh,exnerg,zet,phi_m, &
569 &afk,abk,ts_decay, qc_bl2, qi_bl2, &
570 &th_sfc,wsp
571
572 !top-down diffusion
573 real(kind_phys), dimension(ITS:ITE) :: maxKHtopdown
574 real(kind_phys), dimension(kts:kte) :: KHtopdown,TKEprodTD
575
576 logical :: INITIALIZE_QKE,problem
577
578 ! Stochastic fields
579 integer, intent(IN) :: spp_pbl
580 real(kind_phys), dimension(:,:), intent(IN), optional :: pattern_spp_pbl
581 real(kind_phys), dimension(KTS:KTE) :: rstoch_col
582
583 ! Substepping TKE
584 integer :: nsub
585 real(kind_phys) :: delt2
586
587
588 if (debug_code) then !check incoming values
589 do i=its,ite
590 problem = .false.
591 do k=kts,kte
592 wsp = sqrt(u(i,k)**2 + v(i,k)**2)
593 if (abs(hfx(i)) > 1200. .or. abs(qfx(i)) > 0.001 .or. &
594 wsp > 200. .or. t3d(i,k) > 360. .or. t3d(i,k) < 160. .or. &
595 sqv3d(i,k)< 0.0 .or. sqc3d(i,k)< 0.0 ) then
596 kproblem = k
597 problem = .true.
598 print*,"Incoming problem at: i=",i," k=1"
599 print*," QFX=",qfx(i)," HFX=",hfx(i)
600 print*," wsp=",wsp," T=",t3d(i,k)
601 print*," qv=",sqv3d(i,k)," qc=",sqc3d(i,k)
602 print*," u*=",ust(i)," wspd=",wspd(i)
603 print*," xland=",xland(i)," ts=",ts(i)
604 print*," z/L=",0.5*dz(i,1)*rmol(i)," ps=",ps(i)
605 print*," znt=",znt(i)," dx=",dx(i)
606 endif
607 enddo
608 if (problem) then
609 print*,"===tk:",t3d(i,max(kproblem-3,1):min(kproblem+3,kte))
610 print*,"===qv:",sqv3d(i,max(kproblem-3,1):min(kproblem+3,kte))
611 print*,"===qc:",sqc3d(i,max(kproblem-3,1):min(kproblem+3,kte))
612 print*,"===qi:",sqi3d(i,max(kproblem-3,1):min(kproblem+3,kte))
613 print*,"====u:",u(i,max(kproblem-3,1):min(kproblem+3,kte))
614 print*,"====v:",v(i,max(kproblem-3,1):min(kproblem+3,kte))
615 endif
616 enddo
617 endif
618
619!*** Begin debugging
620 imd=(ims+ime)/2
621 jmd=(jms+jme)/2
622!*** End debugging
623
624 jtf=jte
625 itf=ite
626 ktf=kte
627
628 IF (bl_mynn_output > 0) THEN !research mode
629 edmf_a(its:ite,kts:kte)=0.
630 edmf_w(its:ite,kts:kte)=0.
631 edmf_qt(its:ite,kts:kte)=0.
632 edmf_thl(its:ite,kts:kte)=0.
633 edmf_ent(its:ite,kts:kte)=0.
634 edmf_qc(its:ite,kts:kte)=0.
635 sub_thl3d(its:ite,kts:kte)=0.
636 sub_sqv3d(its:ite,kts:kte)=0.
637 det_thl3d(its:ite,kts:kte)=0.
638 det_sqv3d(its:ite,kts:kte)=0.
639
640 !edmf_a_dd(its:ite,kts:kte)=0.
641 !edmf_w_dd(its:ite,kts:kte)=0.
642 !edmf_qt_dd(its:ite,kts:kte)=0.
643 !edmf_thl_dd(its:ite,kts:kte)=0.
644 !edmf_ent_dd(its:ite,kts:kte)=0.
645 !edmf_qc_dd(its:ite,kts:kte)=0.
646 ENDIF
647 ktop_plume(its:ite)=0 !int
648 ztop_plume(its:ite)=0.
649 maxwidth(its:ite)=0.
650 maxmf(its:ite)=0.
651 maxkhtopdown(its:ite)=0.
652 kzero(kts:kte)=0.
653
654 ! DH* CHECK HOW MUCH OF THIS INIT IF-BLOCK IS ACTUALLY NEEDED FOR RESTARTS
659 IF (initflag > 0 .and. .not.restart) THEN
660
661 !Test to see if we want to initialize qke
662 IF ( (restart .or. cycling)) THEN
663 IF (maxval(qke(its:ite,kts)) < 0.0002) THEN
664 initialize_qke = .true.
665 !print*,"QKE is too small, must initialize"
666 ELSE
667 initialize_qke = .false.
668 !print*,"Using background QKE, will not initialize"
669 ENDIF
670 ELSE ! not cycling or restarting:
671 initialize_qke = .true.
672 !print*,"not restart nor cycling, must initialize QKE"
673 ENDIF
674
675 if (.not.restart .or. .not.cycling) THEN
676 sh3d(its:ite,kts:kte)=0.
677 sm3d(its:ite,kts:kte)=0.
678 el_pbl(its:ite,kts:kte)=0.
679 tsq(its:ite,kts:kte)=0.
680 qsq(its:ite,kts:kte)=0.
681 cov(its:ite,kts:kte)=0.
682 cldfra_bl(its:ite,kts:kte)=0.
683 qc_bl(its:ite,kts:kte)=0.
684 qke(its:ite,kts:kte)=0.
685 else
686 qc_bl1d(kts:kte)=0.0
687 qi_bl1d(kts:kte)=0.0
688 cldfra_bl1d(kts:kte)=0.0
689 end if
690 dqc1(kts:kte)=0.0
691 dqi1(kts:kte)=0.0
692 dqni1(kts:kte)=0.0
693 dqnc1(kts:kte)=0.0
694 dqnwfa1(kts:kte)=0.0
695 dqnifa1(kts:kte)=0.0
696 dqnbca1(kts:kte)=0.0
697 dozone1(kts:kte)=0.0
698 qc_bl1d_old(kts:kte)=0.0
699 cldfra_bl1d_old(kts:kte)=0.0
700 edmf_a1(kts:kte)=0.0
701 edmf_w1(kts:kte)=0.0
702 edmf_qc1(kts:kte)=0.0
703 edmf_a_dd1(kts:kte)=0.0
704 edmf_w_dd1(kts:kte)=0.0
705 edmf_qc_dd1(kts:kte)=0.0
706 sgm(kts:kte)=0.0
707 vt(kts:kte)=0.0
708 vq(kts:kte)=0.0
709
710 DO k=kts,kte
711 DO i=its,itf
712 exch_m(i,k)=0.
713 exch_h(i,k)=0.
714 ENDDO
715 ENDDO
716
717 IF (tke_budget .eq. 1) THEN
718 DO k=kts,kte
719 DO i=its,itf
720 qwt(i,k)=0.
721 qshear(i,k)=0.
722 qbuoy(i,k)=0.
723 qdiss(i,k)=0.
724 dqke(i,k)=0.
725 ENDDO
726 ENDDO
727 ENDIF
728
729 DO i=its,itf
730 if (flag_qi ) then
731 sqi(:)=sqi3d(i,:)
732 else
733 sqi = 0.0
734 endif
735 if (flag_qs ) then
736 sqs(:)=sqs3d(i,:)
737 else
738 sqs = 0.0
739 endif
740 if (icloud_bl > 0) then
741 cldfra_bl1d(:)=cldfra_bl(i,:)
742 qc_bl1d(:)=qc_bl(i,:)
743 qi_bl1d(:)=qi_bl(i,:)
744 endif
745
746 do k=kts,kte !KTF
747 dz1(k)=dz(i,k)
748 u1(k) = u(i,k)
749 v1(k) = v(i,k)
750 w1(k) = w(i,k)
751 th1(k)=th(i,k)
752 tk1(k)=t3d(i,k)
753 ex1(k)=exner(i,k)
754 rho1(k)=rho(i,k)
755 sqc(k)=sqc3d(i,k) !/(1.+qv(i,k))
756 sqv(k)=sqv3d(i,k) !/(1.+qv(i,k))
757 thetav(k)=th(i,k)*(1.+p608*sqv(k))
758 !keep snow out for now - increases ceiling bias
759 sqw(k)=sqv(k)+sqc(k)+sqi(k)!+sqs(k)
760 thl(k)=th1(k) - xlvcp/ex1(k)*sqc(k) &
761 & - xlscp/ex1(k)*(sqi(k))!+sqs(k))
762 !Use form from Tripoli and Cotton (1981) with their
763 !suggested min temperature to improve accuracy.
764 !thl(k)=th(i,k)*(1.- xlvcp/MAX(tk1(k),TKmin)*sqc(k) &
765 ! & - xlscp/MAX(tk1(k),TKmin)*sqi(k))
766
767 IF (k==kts) THEN
768 zw(k)=0.
769 ELSE
770 zw(k)=zw(k-1)+dz(i,k-1)
771 ENDIF
772 IF (initialize_qke) THEN
773 !Initialize tke for initial PBLH calc only - using
774 !simple PBLH form of Koracin and Berkowicz (1988, BLM)
775 !to linearly taper off tke towards top of PBL.
776 qke1(k)=5.*ust(i) * max((ust(i)*700. - zw(k))/(max(ust(i),0.01)*700.), 0.01)
777 ELSE
778 qke1(k)=qke(i,k)
779 ENDIF
780 el(k)=el_pbl(i,k)
781 sh(k)=sh3d(i,k)
782 sm(k)=sm3d(i,k)
783 tsq1(k)=tsq(i,k)
784 qsq1(k)=qsq(i,k)
785 cov1(k)=cov(i,k)
786 if (spp_pbl==1) then
787 rstoch_col(k)=pattern_spp_pbl(i,k)
788 else
789 rstoch_col(k)=0.0
790 endif
791
792 ENDDO
793
794 zw(kte+1)=zw(kte)+dz(i,kte)
795
797 CALL get_pblh(kts,kte,pblh(i),thetav,&
798 & qke1,zw,dz1,xland(i),kpbl(i))
799
802 IF (scaleaware > 0.) THEN
803 CALL scale_aware(dx(i),pblh(i),psig_bl(i),psig_shcu(i))
804 ELSE
805 psig_bl(i)=1.0
806 psig_shcu(i)=1.0
807 ENDIF
808
809 ! DH* CHECK IF WE CAN DO WITHOUT CALLING THIS ROUTINE FOR RESTARTS
814 CALL mym_initialize ( &
815 &kts,kte,xland(i), &
816 &dz1, dx(i), zw, &
817 &u1, v1, thl, sqv, &
818 &pblh(i), th1, thetav, sh, sm, &
819 &ust(i), rmol(i), &
820 &el, qke1, tsq1, qsq1, cov1, &
821 &psig_bl(i), cldfra_bl1d, &
822 &bl_mynn_mixlength, &
823 &edmf_w1,edmf_a1, &
824 &initialize_qke, &
825 &spp_pbl,rstoch_col )
826
827 IF (.not.restart) THEN
828 !UPDATE 3D VARIABLES
829 DO k=kts,kte !KTF
830 el_pbl(i,k)=el(k)
831 sh3d(i,k)=sh(k)
832 sm3d(i,k)=sm(k)
833 qke(i,k)=qke1(k)
834 tsq(i,k)=tsq1(k)
835 qsq(i,k)=qsq1(k)
836 cov(i,k)=cov1(k)
837 ENDDO
838 !initialize qke_adv array if using advection
839 IF (bl_mynn_tkeadvect) THEN
840 DO k=kts,kte
841 qke_adv(i,k)=qke1(k)
842 ENDDO
843 ENDIF
844 ENDIF
845
846!*** Begin debugging
847! IF(I==IMD .AND. J==JMD)THEN
848! PRINT*,"MYNN DRIVER INIT: k=",1," sh=",sh(k)
849! PRINT*," sqw=",sqw(k)," thl=",thl(k)," k_m=",exch_m(i,k)
850! PRINT*," xland=",xland(i)," rmol=",rmol(i)," ust=",ust(i)
851! PRINT*," qke=",qke(i,k)," el=",el_pbl(i,k)," tsq=",Tsq(i,k)
852! PRINT*," PBLH=",PBLH(i)," u=",u(i,k)," v=",v(i,k)
853! ENDIF
854!*** End debugging
855
856 ENDDO !end i-loop
857
858 ENDIF ! end initflag
859
862 !ACF- copy qke_adv array into qke if using advection
863 IF (bl_mynn_tkeadvect) THEN
864 qke=qke_adv
865 ENDIF
866
867 DO i=its,itf
868 !Initialize some arrays
869 if (tke_budget .eq. 1) then
870 dqke(i,:)=qke(i,:)
871 endif
872 if (flag_qi ) then
873 sqi(:)=sqi3d(i,:)
874 else
875 sqi = 0.0
876 endif
877 if (flag_qs ) then
878 sqs(:)=sqs3d(i,:)
879 else
880 sqs = 0.0
881 endif
882 if (icloud_bl > 0) then
883 cldfra_bl1d(:)=cldfra_bl(i,:)
884 qc_bl1d(:) =qc_bl(i,:)
885 qi_bl1d(:) =qi_bl(i,:)
886 cldfra_bl1d_old(:)=cldfra_bl(i,:)
887 qc_bl1d_old(:)=qc_bl(i,:)
888 qi_bl1d_old(:)=qi_bl(i,:)
889 else
890 cldfra_bl1d =0.0
891 qc_bl1d =0.0
892 qi_bl1d =0.0
893 cldfra_bl1d_old=0.0
894 qc_bl1d_old =0.0
895 qi_bl1d_old =0.0
896 endif
897 dz1(kts:kte) =dz(i,kts:kte)
898 u1(kts:kte) =u(i,kts:kte)
899 v1(kts:kte) =v(i,kts:kte)
900 w1(kts:kte) =w(i,kts:kte)
901 th1(kts:kte) =th(i,kts:kte)
902 tk1(kts:kte) =t3d(i,kts:kte)
903 p1(kts:kte) =p(i,kts:kte)
904 ex1(kts:kte) =exner(i,kts:kte)
905 rho1(kts:kte) =rho(i,kts:kte)
906 sqv(kts:kte) =sqv3d(i,kts:kte) !/(1.+qv(i,kts:kte))
907 sqc(kts:kte) =sqc3d(i,kts:kte) !/(1.+qv(i,kts:kte))
908 qv1(kts:kte) =sqv(kts:kte)/(1.-sqv(kts:kte))
909 qc1(kts:kte) =sqc(kts:kte)/(1.-sqv(kts:kte))
910 qi1(kts:kte) =sqi(kts:kte)/(1.-sqv(kts:kte))
911 qs1(kts:kte) =sqs(kts:kte)/(1.-sqv(kts:kte))
912 dqc1(kts:kte) =0.0
913 dqi1(kts:kte) =0.0
914 dqs1(kts:kte) =0.0
915 dqni1(kts:kte) =0.0
916 dqnc1(kts:kte) =0.0
917 dqnwfa1(kts:kte)=0.0
918 dqnifa1(kts:kte)=0.0
919 dqnbca1(kts:kte)=0.0
920 dozone1(kts:kte)=0.0
921 IF (flag_qni ) THEN
922 qni1(kts:kte)=qni(i,kts:kte)
923 ELSE
924 qni1(kts:kte)=0.0
925 ENDIF
926 IF (flag_qnc ) THEN
927 qnc1(kts:kte)=qnc(i,kts:kte)
928 ELSE
929 qnc1(kts:kte)=0.0
930 ENDIF
931 IF (flag_qnwfa ) THEN
932 qnwfa1(kts:kte)=qnwfa(i,kts:kte)
933 ELSE
934 qnwfa1(kts:kte)=0.0
935 ENDIF
936 IF (flag_qnifa ) THEN
937 qnifa1(kts:kte)=qnifa(i,kts:kte)
938 ELSE
939 qnifa1(kts:kte)=0.0
940 ENDIF
941 IF (flag_qnbca ) THEN
942 qnbca1(kts:kte)=qnbca(i,kts:kte)
943 ELSE
944 qnbca1(kts:kte)=0.0
945 ENDIF
946 IF (flag_ozone ) THEN
947 ozone1(kts:kte)=ozone(i,kts:kte)
948 ELSE
949 ozone1(kts:kte)=0.0
950 ENDIF
951 el(kts:kte) =el_pbl(i,kts:kte)
952 qke1(kts:kte)=qke(i,kts:kte)
953 sh(kts:kte) =sh3d(i,kts:kte)
954 sm(kts:kte) =sm3d(i,kts:kte)
955 tsq1(kts:kte)=tsq(i,kts:kte)
956 qsq1(kts:kte)=qsq(i,kts:kte)
957 cov1(kts:kte)=cov(i,kts:kte)
958 if (spp_pbl==1) then
959 rstoch_col(kts:kte)=pattern_spp_pbl(i,kts:kte)
960 else
961 rstoch_col(kts:kte)=0.0
962 endif
963 !edmf
964 edmf_a1 =0.0
965 edmf_w1 =0.0
966 edmf_qc1 =0.0
967 s_aw1 =0.0
968 s_awthl1 =0.0
969 s_awqt1 =0.0
970 s_awqv1 =0.0
971 s_awqc1 =0.0
972 s_awu1 =0.0
973 s_awv1 =0.0
974 s_awqke1 =0.0
975 s_awqnc1 =0.0
976 s_awqni1 =0.0
977 s_awqnwfa1 =0.0
978 s_awqnifa1 =0.0
979 s_awqnbca1 =0.0
980 ![EWDD]
981 edmf_a_dd1 =0.0
982 edmf_w_dd1 =0.0
983 edmf_qc_dd1=0.0
984 sd_aw1 =0.0
985 sd_awthl1 =0.0
986 sd_awqt1 =0.0
987 sd_awqv1 =0.0
988 sd_awqc1 =0.0
989 sd_awu1 =0.0
990 sd_awv1 =0.0
991 sd_awqke1 =0.0
992 sub_thl =0.0
993 sub_sqv =0.0
994 sub_u =0.0
995 sub_v =0.0
996 det_thl =0.0
997 det_sqv =0.0
998 det_sqc =0.0
999 det_u =0.0
1000 det_v =0.0
1001
1002 do k = kts,kte
1003 if (k==kts) then
1004 zw(k)=0.
1005 else
1006 zw(k)=zw(k-1)+dz(i,k-1)
1007 endif
1008 !keep snow out for now - increases ceiling bias
1009 sqw(k)= sqv(k)+sqc(k)+sqi(k)!+sqs(k)
1010 thl(k)= th1(k) - xlvcp/ex1(k)*sqc(k) &
1011 & - xlscp/ex1(k)*(sqi(k))!+sqs(k))
1012 !Use form from Tripoli and Cotton (1981) with their
1013 !suggested min temperature to improve accuracy.
1014 !thl(k)=th(i,k)*(1.- xlvcp/MAX(tk1(k),TKmin)*sqc(k) &
1015 ! & - xlscp/MAX(tk1(k),TKmin)*sqi(k))
1016 thetav(k)=th1(k)*(1.+p608*sqv(k))
1017 enddo ! end k
1018 zw(kte+1)=zw(kte)+dz(i,kte)
1019
1020 !initialize smoke/chem arrays (if used):
1021 if ( mix_chem ) then
1022 do ic = 1,ndvel
1023 vd1(ic) = vdep(i,ic) ! dry deposition velocity
1024 enddo
1025 do k = kts,kte
1026 do ic = 1,nchem
1027 chem1(k,ic) = chem3d(i,k,ic)
1028 enddo
1029 enddo
1030 else
1031 do ic = 1,ndvel
1032 vd1(ic) = 0. ! dry deposition velocity
1033 enddo
1034 do k = kts,kte
1035 do ic = 1,nchem
1036 chem1(k,ic) = 0.
1037 enddo
1038 enddo
1039 endif
1040 s_awchem1 = 0.0
1041
1044 CALL get_pblh(kts,kte,pblh(i),thetav,&
1045 & qke1,zw,dz1,xland(i),kpbl(i))
1046
1051 if (scaleaware > 0.) then
1052 call scale_aware(dx(i),pblh(i),psig_bl(i),psig_shcu(i))
1053 else
1054 psig_bl(i)=1.0
1055 psig_shcu(i)=1.0
1056 endif
1057
1058 sqcg= 0.0 !ill-defined variable; qcg has been removed
1059 cpm=cp*(1.+0.84*qv1(kts))
1060 exnerg=(ps(i)/p1000mb)**rcp
1061
1062 !-----------------------------------------------------
1063 !ORIGINAL CODE
1064 !flt = hfx(i)/( rho(i,kts)*cpm ) &
1065 ! +xlvcp*ch(i)*(sqc(kts)/exner(i,kts) -sqcg/exnerg)
1066 !flq = qfx(i)/ rho(i,kts) &
1067 ! -ch(i)*(sqc(kts) -sqcg )
1068 !-----------------------------------------------------
1069 flqv = qfx(i)/rho1(kts)
1070 flqc = 0.0 !currently no sea-spray fluxes, fog settling handled elsewhere
1071 th_sfc = ts(i)/ex1(kts)
1072
1073 ! TURBULENT FLUX FOR TKE BOUNDARY CONDITIONS
1074 flq =flqv+flqc !! LATENT
1075 flt =hfx(i)/(rho1(kts)*cpm )-xlvcp*flqc/ex1(kts) !! Temperature flux
1076 fltv=flt + flqv*p608*th_sfc !! Virtual temperature flux
1077
1078 ! Update 1/L using updated sfc heat flux and friction velocity
1079 rmol(i) = -karman*gtr*fltv/max(ust(i)**3,1.0e-6)
1080 zet = 0.5*dz(i,kts)*rmol(i)
1081 zet = max(zet, -20.)
1082 zet = min(zet, 20.)
1083 !if(i.eq.idbg)print*,"updated z/L=",zet
1084 if (bl_mynn_stfunc == 0) then
1085 !Original Kansas-type stability functions
1086 if ( zet >= 0.0 ) then
1087 pmz = 1.0 + (cphm_st-1.0) * zet
1088 phh = 1.0 + cphh_st * zet
1089 else
1090 pmz = 1.0/ (1.0-cphm_unst*zet)**0.25 - zet
1091 phh = 1.0/sqrt(1.0-cphh_unst*zet)
1092 end if
1093 else
1094 !Updated stability functions (Puhales, 2020)
1095 phi_m = phim(zet)
1096 pmz = phi_m - zet
1097 phh = phih(zet)
1098 end if
1099
1104
1105 call mym_condensation (kts,kte, &
1106 &dx(i),dz1,zw,xland(i), &
1107 &thl,sqw,sqv,sqc,sqi,sqs, &
1108 &p1,ex1,tsq1,qsq1,cov1, &
1109 &sh,el,bl_mynn_cloudpdf, &
1110 &qc_bl1d,qi_bl1d,cldfra_bl1d, &
1111 &pblh(i),hfx(i), &
1112 &vt, vq, th1, sgm, rmol(i), &
1113 &spp_pbl, rstoch_col )
1114
1118 if (bl_mynn_topdown.eq.1) then
1119 call topdown_cloudrad(kts,kte,dz1,zw, &
1120 &xland(i),kpbl(i),pblh(i), &
1121 &sqc,sqi,sqw,thl,th1,ex1,p1,rho1,thetav, &
1122 &cldfra_bl1d,rthraten(i,:), &
1123 &maxkhtopdown(i),khtopdown,tkeprodtd )
1124 else
1125 maxkhtopdown(i) = 0.0
1126 khtopdown(kts:kte) = 0.0
1127 tkeprodtd(kts:kte) = 0.0
1128 endif
1129
1130 if (bl_mynn_edmf > 0) then
1131 !PRINT*,"Calling DMP Mass-Flux: i= ",i
1132 call dmp_mf( &
1133 &kts,kte,delt,zw,dz1,p1,rho1, &
1134 &bl_mynn_edmf_mom, &
1135 &bl_mynn_edmf_tke, &
1136 &bl_mynn_mixscalars, &
1137 &u1,v1,w1,th1,thl,thetav,tk1, &
1138 &sqw,sqv,sqc,qke1, &
1139 &qnc1,qni1,qnwfa1,qnifa1,qnbca1, &
1140 &ex1,vt,vq,sgm, &
1141 &ust(i),flt,fltv,flq,flqv, &
1142 &pblh(i),kpbl(i),dx(i), &
1143 &xland(i),th_sfc, &
1144 ! now outputs - tendencies
1145 ! &,dth1mf,dqv1mf,dqc1mf,du1mf,dv1mf &
1146 ! outputs - updraft properties
1147 &edmf_a1,edmf_w1,edmf_qt1, &
1148 &edmf_thl1,edmf_ent1,edmf_qc1, &
1149 ! for the solver
1150 &s_aw1,s_awthl1,s_awqt1, &
1151 &s_awqv1,s_awqc1, &
1152 &s_awu1,s_awv1,s_awqke1, &
1153 &s_awqnc1,s_awqni1, &
1154 &s_awqnwfa1,s_awqnifa1,s_awqnbca1, &
1155 &sub_thl,sub_sqv, &
1156 &sub_u,sub_v, &
1157 &det_thl,det_sqv,det_sqc, &
1158 &det_u,det_v, &
1159 ! chem/smoke mixing
1160 &nchem,chem1,s_awchem1, &
1161 &mix_chem, &
1162 &qc_bl1d,cldfra_bl1d, &
1163 &qc_bl1d_old,cldfra_bl1d_old, &
1164 &flag_qc,flag_qi, &
1165 &flag_qnc,flag_qni, &
1166 &flag_qnwfa,flag_qnifa,flag_qnbca, &
1167 &psig_shcu(i), &
1168 &maxwidth(i),ktop_plume(i), &
1169 &maxmf(i),ztop_plume(i), &
1170 &spp_pbl,rstoch_col )
1171 endif
1172
1173 if (bl_mynn_edmf_dd == 1) then
1174 call ddmf_jpl(kts,kte,delt,zw,dz1,p1, &
1175 &u1,v1,th1,thl,thetav,tk1, &
1176 &sqw,sqv,sqc,rho1,ex1, &
1177 &ust(i),flt,flq, &
1178 &pblh(i),kpbl(i), &
1179 &edmf_a_dd1,edmf_w_dd1,edmf_qt_dd1, &
1180 &edmf_thl_dd1,edmf_ent_dd1, &
1181 &edmf_qc_dd1, &
1182 &sd_aw1,sd_awthl1,sd_awqt1, &
1183 &sd_awqv1,sd_awqc1,sd_awu1,sd_awv1, &
1184 &sd_awqke1, &
1185 &qc_bl1d,cldfra_bl1d, &
1186 &rthraten(i,:) )
1187 endif
1188
1189 !Capability to substep the eddy-diffusivity portion
1190 !do nsub = 1,2
1191 delt2 = delt !*0.5 !only works if topdown=0
1192
1193 call mym_turbulence( &
1194 &kts,kte,xland(i),closure, &
1195 &dz1, dx(i), zw, &
1196 &u1, v1, thl, thetav, sqc, sqw, &
1197 &qke1, tsq1, qsq1, cov1, &
1198 &vt, vq, &
1199 &rmol(i), flt, fltv, flq, &
1200 &pblh(i),th1, &
1201 &sh,sm,el, &
1202 &dfm,dfh,dfq, &
1203 &tcd,qcd,pdk, &
1204 &pdt,pdq,pdc, &
1205 &qwt1,qshear1,qbuoy1,qdiss1, &
1206 &tke_budget, &
1207 &psig_bl(i),psig_shcu(i), &
1208 &cldfra_bl1d,bl_mynn_mixlength, &
1209 &edmf_w1,edmf_a1, &
1210 &tkeprodtd, &
1211 &spp_pbl,rstoch_col )
1212
1216 call mym_predict(kts,kte,closure, &
1217 &delt2, dz1, &
1218 &ust(i), flt, flq, pmz, phh, &
1219 &el, dfq, rho1, pdk, pdt, pdq, pdc, &
1220 &qke1, tsq1, qsq1, cov1, &
1221 &s_aw1, s_awqke1, bl_mynn_edmf_tke, &
1222 &qwt1, qdiss1, tke_budget )
1223
1224 if (dheat_opt > 0) then
1225 do k=kts,kte-1
1226 ! Set max dissipative heating rate to 7.2 K per hour
1227 diss_heat(k) = min(max(1.0*(qke1(k)**1.5)/(b1*max(0.5*(el(k)+el(k+1)),1.))/cp, 0.0),0.002)
1228 ! Limit heating above 100 mb:
1229 diss_heat(k) = diss_heat(k) * exp(-10000./max(p1(k),1.))
1230 enddo
1231 diss_heat(kte) = 0.
1232 else
1233 diss_heat(1:kte) = 0.
1234 endif
1235
1238 call mynn_tendencies(kts,kte,i, &
1239 &delt, dz1, rho1, &
1240 &u1, v1, th1, tk1, qv1, &
1241 &qc1, qi1, kzero, qnc1, qni1, & !kzero replaces qs1 - not mixing snow
1242 &ps(i), p1, ex1, thl, &
1243 &sqv, sqc, sqi, kzero, sqw, & !kzero replaces sqs - not mixing snow
1244 &qnwfa1, qnifa1, qnbca1, ozone1, &
1245 &ust(i),flt,flq,flqv,flqc, &
1246 &wspd(i),uoce(i),voce(i), &
1247 &tsq1, qsq1, cov1, &
1248 &tcd, qcd, &
1249 &dfm, dfh, dfq, &
1250 &du1, dv1, dth1, dqv1, &
1251 &dqc1, dqi1, dqs1, dqnc1, dqni1, &
1252 &dqnwfa1, dqnifa1, dqnbca1, &
1253 &dozone1, &
1254 &diss_heat, &
1255 ! mass flux components
1256 &s_aw1,s_awthl1,s_awqt1, &
1257 &s_awqv1,s_awqc1,s_awu1,s_awv1, &
1258 &s_awqnc1,s_awqni1, &
1259 &s_awqnwfa1,s_awqnifa1,s_awqnbca1, &
1260 &sd_aw1,sd_awthl1,sd_awqt1, &
1261 &sd_awqv1,sd_awqc1, &
1262 &sd_awu1,sd_awv1, &
1263 &sub_thl,sub_sqv, &
1264 &sub_u,sub_v, &
1265 &det_thl,det_sqv,det_sqc, &
1266 &det_u,det_v, &
1267 &flag_qc,flag_qi,flag_qnc, &
1268 &flag_qni,flag_qs, &
1269 &flag_qnwfa,flag_qnifa, &
1270 &flag_qnbca, &
1271 &cldfra_bl1d, &
1272 &bl_mynn_cloudmix, &
1273 &bl_mynn_mixqt, &
1274 &bl_mynn_edmf, &
1275 &bl_mynn_edmf_mom, &
1276 &bl_mynn_mixscalars )
1277
1278
1279 if ( mix_chem ) then
1280 if ( rrfs_sd ) then
1281 call mynn_mix_chem(kts,kte,i, &
1282 &delt, dz1, pblh(i), &
1283 &nchem, kdvel, ndvel, &
1284 &chem1, vd1, &
1285 &rho1,flt, &
1286 &tcd, qcd, &
1287 &dfh, &
1288 &s_aw1,s_awchem1, &
1289 &emis_ant_no(i), &
1290 &frp(i), rrfs_sd, &
1291 &enh_mix, smoke_dbg )
1292 else
1293 call mynn_mix_chem(kts,kte,i, &
1294 &delt, dz1, pblh(i), &
1295 &nchem, kdvel, ndvel, &
1296 &chem1, vd1, &
1297 &rho1,flt, &
1298 &tcd, qcd, &
1299 &dfh, &
1300 &s_aw1,s_awchem1, &
1301 &zero, &
1302 &zero, rrfs_sd, &
1303 &enh_mix, smoke_dbg )
1304 endif
1305 do ic = 1,nchem
1306 do k = kts,kte
1307 chem3d(i,k,ic) = max(1.e-12, chem1(k,ic))
1308 enddo
1309 enddo
1310 endif
1311
1312 call retrieve_exchange_coeffs(kts,kte, &
1313 &dfm, dfh, dz1, k_m1, k_h1 )
1314
1315 !UPDATE 3D ARRAYS
1316 exch_m(i,kts:kte) =k_m1(kts:kte)
1317 exch_h(i,kts:kte) =k_h1(kts:kte)
1318 rublten(i,kts:kte) =du1(kts:kte)
1319 rvblten(i,kts:kte) =dv1(kts:kte)
1320 rthblten(i,kts:kte)=dth1(kts:kte)
1321 rqvblten(i,kts:kte)=dqv1(kts:kte)
1322 if (bl_mynn_cloudmix > 0) then
1323 if (flag_qc) rqcblten(i,kts:kte)=dqc1(kts:kte)
1324 if (flag_qi) rqiblten(i,kts:kte)=dqi1(kts:kte)
1325 if (flag_qs) rqsblten(i,kts:kte)=dqs1(kts:kte)
1326 else
1327 if (flag_qc) rqcblten(i,:)=0.
1328 if (flag_qi) rqiblten(i,:)=0.
1329 if (flag_qs) rqsblten(i,:)=0.
1330 endif
1331 if (bl_mynn_cloudmix > 0 .and. bl_mynn_mixscalars > 0) then
1332 if (flag_qnc) rqncblten(i,kts:kte) =dqnc1(kts:kte)
1333 if (flag_qni) rqniblten(i,kts:kte) =dqni1(kts:kte)
1334 if (flag_qnwfa) rqnwfablten(i,kts:kte)=dqnwfa1(kts:kte)
1335 if (flag_qnifa) rqnifablten(i,kts:kte)=dqnifa1(kts:kte)
1336 if (flag_qnbca) rqnbcablten(i,kts:kte)=dqnbca1(kts:kte)
1337 else
1338 if (flag_qnc) rqncblten(i,:) =0.
1339 if (flag_qni) rqniblten(i,:) =0.
1340 if (flag_qnwfa) rqnwfablten(i,:)=0.
1341 if (flag_qnifa) rqnifablten(i,:)=0.
1342 if (flag_qnbca) rqnbcablten(i,:)=0.
1343 endif
1344 dozone(i,kts:kte)=dozone1(kts:kte)
1345 if (icloud_bl > 0) then
1346 qc_bl(i,kts:kte) =qc_bl1d(kts:kte)
1347 qi_bl(i,kts:kte) =qi_bl1d(kts:kte)
1348 cldfra_bl(i,kts:kte)=cldfra_bl1d(kts:kte)
1349 endif
1350 el_pbl(i,kts:kte)=el(kts:kte)
1351 qke(i,kts:kte) =qke1(kts:kte)
1352 tsq(i,kts:kte) =tsq1(kts:kte)
1353 qsq(i,kts:kte) =qsq1(kts:kte)
1354 cov(i,kts:kte) =cov1(kts:kte)
1355 sh3d(i,kts:kte) =sh(kts:kte)
1356 sm3d(i,kts:kte) =sm(kts:kte)
1357
1358 if (tke_budget .eq. 1) then
1359 !! TKE budget is now given in m**2/s**-3 (Puhales, 2020)
1360 !! Lower boundary condtions (using similarity relationships such as the prognostic equation for Qke)
1361 k=kts
1362 qshear1(k) =4.*(ust(i)**3*phi_m/(karman*dz(i,k)))-qshear1(k+1) !! staggered
1363 qbuoy1(k) =4.*(-ust(i)**3*zet/(karman*dz(i,k)))-qbuoy1(k+1) !! staggered
1364 !! unstaggering SHEAR and BUOY and trasfering all TKE budget to 3D array
1365 do k = kts,kte-1
1366 qshear(i,k)=0.5*(qshear1(k)+qshear1(k+1)) !!! unstaggering in z
1367 qbuoy(i,k) =0.5*(qbuoy1(k)+qbuoy1(k+1)) !!! unstaggering in z
1368 qwt(i,k) =qwt1(k)
1369 qdiss(i,k) =qdiss1(k)
1370 dqke(i,k) =(qke1(k)-dqke(i,k))*0.5/delt
1371 enddo
1372 !! Upper boundary conditions
1373 k=kte
1374 qshear(i,k) =0.
1375 qbuoy(i,k) =0.
1376 qwt(i,k) =0.
1377 qdiss(i,k) =0.
1378 dqke(i,k) =0.
1379 endif
1380
1381 !update updraft/downdraft properties
1382 if (bl_mynn_output > 0) then !research mode == 1
1383 if (bl_mynn_edmf > 0) then
1384 edmf_a(i,kts:kte) =edmf_a1(kts:kte)
1385 edmf_w(i,kts:kte) =edmf_w1(kts:kte)
1386 edmf_qt(i,kts:kte) =edmf_qt1(kts:kte)
1387 edmf_thl(i,kts:kte) =edmf_thl1(kts:kte)
1388 edmf_ent(i,kts:kte) =edmf_ent1(kts:kte)
1389 edmf_qc(i,kts:kte) =edmf_qc1(kts:kte)
1390 sub_thl3d(i,kts:kte)=sub_thl(kts:kte)
1391 sub_sqv3d(i,kts:kte)=sub_sqv(kts:kte)
1392 det_thl3d(i,kts:kte)=det_thl(kts:kte)
1393 det_sqv3d(i,kts:kte)=det_sqv(kts:kte)
1394 endif
1395 !if (bl_mynn_edmf_dd > 0) THEN
1396 ! edmf_a_dd(i,kts:kte) =edmf_a_dd1(kts:kte)
1397 ! edmf_w_dd(i,kts:kte) =edmf_w_dd1(kts:kte)
1398 ! edmf_qt_dd(i,kts:kte) =edmf_qt_dd1(kts:kte)
1399 ! edmf_thl_dd(i,kts:kte)=edmf_thl_dd1(kts:kte)
1400 ! edmf_ent_dd(i,kts:kte)=edmf_ent_dd1(kts:kte)
1401 ! edmf_qc_dd(i,kts:kte) =edmf_qc_dd1(kts:kte)
1402 !endif
1403 endif
1404
1405 !*** Begin debug prints
1406 if ( debug_code .and. (i .eq. idbg)) THEN
1407 if ( abs(qfx(i))>.001)print*,&
1408 "SUSPICIOUS VALUES AT: i=",i," QFX=",qfx(i)
1409 if ( abs(hfx(i))>1100.)print*,&
1410 "SUSPICIOUS VALUES AT: i=",i," HFX=",hfx(i)
1411 do k = kts,kte
1412 IF ( sh(k) < 0. .OR. sh(k)> 200.)print*,&
1413 "SUSPICIOUS VALUES AT: i,k=",i,k," sh=",sh(k)
1414 IF ( abs(vt(k)) > 2.0 )print*,&
1415 "SUSPICIOUS VALUES AT: i,k=",i,k," vt=",vt(k)
1416 IF ( abs(vq(k)) > 7000.)print*,&
1417 "SUSPICIOUS VALUES AT: i,k=",i,k," vq=",vq(k)
1418 IF ( qke(i,k) < -1. .OR. qke(i,k)> 200.)print*,&
1419 "SUSPICIOUS VALUES AT: i,k=",i,k," qke=",qke(i,k)
1420 IF ( el_pbl(i,k) < 0. .OR. el_pbl(i,k)> 1500.)print*,&
1421 "SUSPICIOUS VALUES AT: i,k=",i,k," el_pbl=",el_pbl(i,k)
1422 IF ( exch_m(i,k) < 0. .OR. exch_m(i,k)> 2000.)print*,&
1423 "SUSPICIOUS VALUES AT: i,k=",i,k," exxch_m=",exch_m(i,k)
1424 IF (icloud_bl > 0) then
1425 IF ( cldfra_bl(i,k) < 0.0 .OR. cldfra_bl(i,k)> 1.)THEN
1426 print*,"SUSPICIOUS VALUES: CLDFRA_BL=",cldfra_bl(i,k)," qc_bl=",qc_bl(i,k)
1427 ENDIF
1428 ENDIF
1429
1430 !IF (I==IMD .AND. J==JMD) THEN
1431 ! PRINT*,"MYNN DRIVER END: k=",k," sh=",sh(k)
1432 ! PRINT*," sqw=",sqw(k)," thl=",thl(k)," exch_m=",exch_m(i,k)
1433 ! PRINT*," xland=",xland(i)," rmol=",rmol(i)," ust=",ust(i)
1434 ! PRINT*," qke=",qke(i,k)," el=",el_pbl(i,k)," tsq=",tsq(i,k)
1435 ! PRINT*," PBLH=",PBLH(i)," u=",u(i,k)," v=",v(i,k)
1436 ! PRINT*," vq=",vq(k)," vt=",vt(k)
1437 !ENDIF
1438 enddo !end-k
1439 endif
1440
1441 enddo !end i-loop
1442
1443!ACF copy qke into qke_adv if using advection
1444 IF (bl_mynn_tkeadvect) THEN
1445 qke_adv=qke
1446 ENDIF
1447!ACF-end
1448
1449#ifdef HARDCODE_VERTICAL
1450# undef kts
1451# undef kte
1452#endif
1453
1454 END SUBROUTINE mynn_bl_driver
1456
1457!=======================================================================
1458! SUBROUTINE mym_initialize:
1459!
1460! Input variables:
1461! iniflag : <>0; turbulent quantities will be initialized
1462! = 0; turbulent quantities have been already
1463! given, i.e., they will not be initialized
1464! nx, nz : Dimension sizes of the
1465! x and z directions, respectively
1466! tref : Reference temperature (K)
1467! dz(nz) : Vertical grid spacings (m)
1468! # dz(nz)=dz(nz-1)
1469! zw(nz+1) : Heights of the walls of the grid boxes (m)
1470! # zw(1)=0.0 and zw(k)=zw(k-1)+dz(k-1)
1471! exner(nx,nz) : Exner function at zw*h+zg (J/kg K)
1472! defined by c_p*( p_basic/1000hPa )^kappa
1473! This is usually computed by integrating
1474! d(pi0)/dz = -h*g/tref.
1475! rmo(nx) : Inverse of the Obukhov length (m^(-1))
1476! flt, flq(nx) : Turbulent fluxes of potential temperature and
1477! total water, respectively:
1478! flt=-u_*Theta_* (K m/s)
1479! flq=-u_*qw_* (kg/kg m/s)
1480! ust(nx) : Friction velocity (m/s)
1481! pmz(nx) : phi_m-zeta at z1*h+z0, where z1 (=0.5*dz(1))
1482! is the first grid point above the surafce, z0
1483! the roughness length and zeta=(z1*h+z0)*rmo
1484! phh(nx) : phi_h at z1*h+z0
1485! u, v(nx,nz) : Components of the horizontal wind (m/s)
1486! thl(nx,nz) : Liquid water potential temperature
1487! (K)
1488! qw(nx,nz) : Total water content Q_w (kg/kg)
1489!
1490! Output variables:
1491! ql(nx,nz) : Liquid water content (kg/kg)
1492! vt, vq(nx,nz) : Functions for computing the buoyancy flux
1493! qke(nx,nz) : Twice the turbulent kinetic energy q^2
1494! (m^2/s^2)
1495! tsq(nx,nz) : Variance of Theta_l (K^2)
1496! qsq(nx,nz) : Variance of Q_w
1497! cov(nx,nz) : Covariance of Theta_l and Q_w (K)
1498! el(nx,nz) : Master length scale L (m)
1499! defined on the walls of the grid boxes
1500!
1501! Work arrays: see subroutine mym_level2
1502! pd?(nx,nz,ny) : Half of the production terms at Level 2
1503! defined on the walls of the grid boxes
1504! qkw(nx,nz,ny) : q on the walls of the grid boxes (m/s)
1505!
1506! # As to dtl, ...gh, see subroutine mym_turbulence.
1507!
1508!-------------------------------------------------------------------
1509
1515 SUBROUTINE mym_initialize ( &
1516 & kts,kte,xland, &
1517 & dz, dx, zw, &
1518 & u, v, thl, qw, &
1519! & ust, rmo, pmz, phh, flt, flq, &
1520 & zi, theta, thetav, sh, sm, &
1521 & ust, rmo, el, &
1522 & Qke, Tsq, Qsq, Cov, Psig_bl, cldfra_bl1D, &
1523 & bl_mynn_mixlength, &
1524 & edmf_w1,edmf_a1, &
1525 & INITIALIZE_QKE, &
1526 & spp_pbl,rstoch_col)
1527!
1528!-------------------------------------------------------------------
1529
1530 integer, intent(in) :: kts,kte
1531 integer, intent(in) :: bl_mynn_mixlength
1532 logical, intent(in) :: INITIALIZE_QKE
1533! real(kind_phys), intent(in) :: ust, rmo, pmz, phh, flt, flq
1534 real(kind_phys), intent(in) :: rmo, Psig_bl, xland
1535 real(kind_phys), intent(in) :: dx, ust, zi
1536 real(kind_phys), dimension(kts:kte), intent(in) :: dz
1537 real(kind_phys), dimension(kts:kte+1), intent(in) :: zw
1538 real(kind_phys), dimension(kts:kte), intent(in) :: u,v,thl,&
1539 &qw,cldfra_bl1D,edmf_w1,edmf_a1
1540 real(kind_phys), dimension(kts:kte), intent(out) :: tsq,qsq,cov
1541 real(kind_phys), dimension(kts:kte), intent(inout) :: el,qke
1542 real(kind_phys), dimension(kts:kte) :: &
1543 &ql,pdk,pdt,pdq,pdc,dtl,dqw,dtv, &
1544 &gm,gh,sm,sh,qkw,vt,vq
1545 integer :: k,l,lmax
1546 real(kind_phys):: phm,vkz,elq,elv,b1l,b2l,pmz=1.,phh=1., &
1547 &flt=0.,fltv=0.,flq=0.,tmpq
1548 real(kind_phys), dimension(kts:kte) :: theta,thetav
1549 real(kind_phys), dimension(kts:kte) :: rstoch_col
1550 integer ::spp_pbl
1551
1553 DO k = kts,kte
1554 ql(k) = 0.0
1555 vt(k) = 0.0
1556 vq(k) = 0.0
1557 END DO
1558!
1560 CALL mym_level2 ( kts,kte, &
1561 & dz, &
1562 & u, v, thl, thetav, qw, &
1563 & ql, vt, vq, &
1564 & dtl, dqw, dtv, gm, gh, sm, sh )
1565!
1566! ** Preliminary setting **
1567
1568 el(kts) = 0.0
1569 IF (initialize_qke) THEN
1570 !qke(kts) = ust**2 * ( b1*pmz )**(2.0/3.0)
1571 qke(kts) = 1.5 * ust**2 * ( b1*pmz )**(2.0/3.0)
1572 DO k = kts+1,kte
1573 !qke(k) = 0.0
1574 !linearly taper off towards top of pbl
1575 qke(k)=qke(kts)*max((ust*700. - zw(k))/(max(ust,0.01)*700.), 0.01)
1576 ENDDO
1577 ENDIF
1578!
1579 phm = phh*b2 / ( b1*pmz )**(1.0/3.0)
1580 tsq(kts) = phm*( flt/ust )**2
1581 qsq(kts) = phm*( flq/ust )**2
1582 cov(kts) = phm*( flt/ust )*( flq/ust )
1583!
1584 DO k = kts+1,kte
1585 vkz = karman*zw(k)
1586 el(k) = vkz/( 1.0 + vkz/100.0 )
1587! qke(k) = 0.0
1588!
1589 tsq(k) = 0.0
1590 qsq(k) = 0.0
1591 cov(k) = 0.0
1592 END DO
1593!
1594! ** Initialization with an iterative manner **
1595! ** lmax is the iteration count. This is arbitrary. **
1596 lmax = 5
1597!
1598 DO l = 1,lmax
1599!
1601 CALL mym_length ( &
1602 & kts,kte,xland, &
1603 & dz, dx, zw, &
1604 & rmo, flt, fltv, flq, &
1605 & vt, vq, &
1606 & u, v, qke, &
1607 & dtv, &
1608 & el, &
1609 & zi,theta, &
1610 & qkw,psig_bl,cldfra_bl1d, &
1611 & bl_mynn_mixlength, &
1612 & edmf_w1,edmf_a1 )
1613!
1614 DO k = kts+1,kte
1615 elq = el(k)*qkw(k)
1616 pdk(k) = elq*( sm(k)*gm(k) + &
1617 & sh(k)*gh(k) )
1618 pdt(k) = elq* sh(k)*dtl(k)**2
1619 pdq(k) = elq* sh(k)*dqw(k)**2
1620 pdc(k) = elq* sh(k)*dtl(k)*dqw(k)
1621 END DO
1622!
1623! ** Strictly, vkz*h(i,j) -> karman*( 0.5*dz(1)*h(i,j)+z0 ) **
1624 vkz = karman*0.5*dz(kts)
1625 elv = 0.5*( el(kts+1)+el(kts) ) / vkz
1626 IF (initialize_qke)THEN
1627 !qke(kts) = ust**2 * ( b1*pmz*elv )**(2.0/3.0)
1628 qke(kts) = 1.0 * max(ust,0.02)**2 * ( b1*pmz*elv )**(2.0/3.0)
1629 ENDIF
1630
1631 phm = phh*b2 / ( b1*pmz/elv**2 )**(1.0/3.0)
1632 tsq(kts) = phm*( flt/ust )**2
1633 qsq(kts) = phm*( flq/ust )**2
1634 cov(kts) = phm*( flt/ust )*( flq/ust )
1635
1636 DO k = kts+1,kte-1
1637 b1l = b1*0.25*( el(k+1)+el(k) )
1638 !tmpq=MAX(b1l*( pdk(k+1)+pdk(k) ),qkemin)
1639 !add MIN to limit unreasonable QKE
1640 tmpq=min(max(b1l*( pdk(k+1)+pdk(k) ),qkemin),125.)
1641! PRINT *,'tmpqqqqq',tmpq,pdk(k+1),pdk(k)
1642 IF (initialize_qke)THEN
1643 qke(k) = tmpq**twothirds
1644 ENDIF
1645
1646 IF ( qke(k) .LE. 0.0 ) THEN
1647 b2l = 0.0
1648 ELSE
1649 b2l = b2*( b1l/b1 ) / sqrt( qke(k) )
1650 END IF
1651
1652 tsq(k) = b2l*( pdt(k+1)+pdt(k) )
1653 qsq(k) = b2l*( pdq(k+1)+pdq(k) )
1654 cov(k) = b2l*( pdc(k+1)+pdc(k) )
1655 END DO
1656
1657 END DO
1658
1659!! qke(kts)=qke(kts+1)
1660!! tsq(kts)=tsq(kts+1)
1661!! qsq(kts)=qsq(kts+1)
1662!! cov(kts)=cov(kts+1)
1663
1664 IF (initialize_qke)THEN
1665 qke(kts)=0.5*(qke(kts)+qke(kts+1))
1666 qke(kte)=qke(kte-1)
1667 ENDIF
1668 tsq(kte)=tsq(kte-1)
1669 qsq(kte)=qsq(kte-1)
1670 cov(kte)=cov(kte-1)
1671
1672!
1673! RETURN
1674
1675 END SUBROUTINE mym_initialize
1677
1678!
1679! ==================================================================
1680! SUBROUTINE mym_level2:
1681!
1682! Input variables: see subroutine mym_initialize
1683!
1684! Output variables:
1685! dtl(nx,nz,ny) : Vertical gradient of Theta_l (K/m)
1686! dqw(nx,nz,ny) : Vertical gradient of Q_w
1687! dtv(nx,nz,ny) : Vertical gradient of Theta_V (K/m)
1688! gm (nx,nz,ny) : G_M divided by L^2/q^2 (s^(-2))
1689! gh (nx,nz,ny) : G_H divided by L^2/q^2 (s^(-2))
1690! sm (nx,nz,ny) : Stability function for momentum, at Level 2
1691! sh (nx,nz,ny) : Stability function for heat, at Level 2
1692!
1693! These are defined on the walls of the grid boxes.
1694!
1695
1719 SUBROUTINE mym_level2 (kts,kte, &
1720 & dz, &
1721 & u, v, thl, thetav, qw, &
1722 & ql, vt, vq, &
1723 & dtl, dqw, dtv, gm, gh, sm, sh )
1724!
1725!-------------------------------------------------------------------
1726
1727 integer, intent(in) :: kts,kte
1728
1729#ifdef HARDCODE_VERTICAL
1730# define kts 1
1731# define kte HARDCODE_VERTICAL
1732#endif
1733
1734 real(kind_phys), dimension(kts:kte), intent(in) :: dz
1735 real(kind_phys), dimension(kts:kte), intent(in) :: u,v, &
1736 &thl,qw,ql,vt,vq,thetav
1737 real(kind_phys), dimension(kts:kte), intent(out) :: &
1738 &dtl,dqw,dtv,gm,gh,sm,sh
1739
1740 integer :: k
1741
1742 real(kind_phys):: rfc,f1,f2,rf1,rf2,smc,shc, &
1743 &ri1,ri2,ri3,ri4,duz,dtz,dqz,vtt,vqq,dtq,dzk, &
1744 &afk,abk,ri,rf
1745
1746 real(kind_phys):: a2fac
1747
1748! ev = 2.5e6
1749! tv0 = 0.61*tref
1750! tv1 = 1.61*tref
1751! gtr = 9.81/tref
1752!
1753 rfc = g1/( g1+g2 )
1754 f1 = b1*( g1-c1 ) +3.0*a2*( 1.0 -c2 )*( 1.0-c5 ) &
1755 & +2.0*a1*( 3.0-2.0*c2 )
1756 f2 = b1*( g1+g2 ) -3.0*a1*( 1.0 -c2 )
1757 rf1 = b1*( g1-c1 )/f1
1758 rf2 = b1* g1 /f2
1759 smc = a1 /a2* f1/f2
1760 shc = 3.0*a2*( g1+g2 )
1761!
1762 ri1 = 0.5/smc
1763 ri2 = rf1*smc
1764 ri3 = 4.0*rf2*smc -2.0*ri2
1765 ri4 = ri2**2
1766!
1767 DO k = kts+1,kte
1768 dzk = 0.5 *( dz(k)+dz(k-1) )
1769 afk = dz(k)/( dz(k)+dz(k-1) )
1770 abk = 1.0 -afk
1771 duz = ( u(k)-u(k-1) )**2 +( v(k)-v(k-1) )**2
1772 duz = duz /dzk**2
1773 dtz = ( thl(k)-thl(k-1) )/( dzk )
1774 dqz = ( qw(k)-qw(k-1) )/( dzk )
1775!
1776 vtt = 1.0 +vt(k)*abk +vt(k-1)*afk ! Beta-theta in NN09, Eq. 39
1777 vqq = tv0 +vq(k)*abk +vq(k-1)*afk ! Beta-q
1778 dtq = vtt*dtz +vqq*dqz
1779 !Alternatively, use theta-v without the SGS clouds
1780 !dtq = ( thetav(k)-thetav(k-1) )/( dzk )
1781!
1782 dtl(k) = dtz
1783 dqw(k) = dqz
1784 dtv(k) = dtq
1785!? dtv(i,j,k) = dtz +tv0*dqz
1786!? : +( xlv/pi0(i,j,k)-tv1 )
1787!? : *( ql(i,j,k)-ql(i,j,k-1) )/( dzk*h(i,j) )
1788!
1789 gm(k) = duz
1790 gh(k) = -dtq*gtr
1791!
1792! ** Gradient Richardson number **
1793 ri = -gh(k)/max( duz, 1.0e-10 )
1794
1795 !a2fac is needed for the Canuto/Kitamura mod
1796 IF (ckmod .eq. 1) THEN
1797 a2fac = 1./(1. + max(ri,0.0))
1798 ELSE
1799 a2fac = 1.
1800 ENDIF
1801
1802 rfc = g1/( g1+g2 )
1803 f1 = b1*( g1-c1 ) +3.0*a2*a2fac *( 1.0 -c2 )*( 1.0-c5 ) &
1804 & +2.0*a1*( 3.0-2.0*c2 )
1805 f2 = b1*( g1+g2 ) -3.0*a1*( 1.0 -c2 )
1806 rf1 = b1*( g1-c1 )/f1
1807 rf2 = b1* g1 /f2
1808 smc = a1 /(a2*a2fac)* f1/f2
1809 shc = 3.0*(a2*a2fac)*( g1+g2 )
1810
1811 ri1 = 0.5/smc
1812 ri2 = rf1*smc
1813 ri3 = 4.0*rf2*smc -2.0*ri2
1814 ri4 = ri2**2
1815
1816! ** Flux Richardson number **
1817 rf = min( ri1*( ri + ri2-sqrt(ri**2 - ri3*ri + ri4) ), rfc )
1818!
1819 sh(k) = shc*( rfc-rf )/( 1.0-rf )
1820 sm(k) = smc*( rf1-rf )/( rf2-rf ) * sh(k)
1821 END DO
1822!
1823! RETURN
1824
1825#ifdef HARDCODE_VERTICAL
1826# undef kts
1827# undef kte
1828#endif
1829
1830 END SUBROUTINE mym_level2
1831!! @}
1832
1833! ==================================================================
1834! SUBROUTINE mym_length:
1835!
1836! Input variables: see subroutine mym_initialize
1837!
1838! Output variables: see subroutine mym_initialize
1839!
1840! Work arrays:
1841! elt(nx,ny) : Length scale depending on the PBL depth (m)
1842! vsc(nx,ny) : Velocity scale q_c (m/s)
1843! at first, used for computing elt
1844!
1845! NOTE: the mixing lengths are meant to be calculated at the full-
1846! sigmal levels (or interfaces beween the model layers).
1847!
1850 SUBROUTINE mym_length ( &
1851 & kts,kte,xland, &
1852 & dz, dx, zw, &
1853 & rmo, flt, fltv, flq, &
1854 & vt, vq, &
1855 & u1, v1, qke, &
1856 & dtv, &
1857 & el, &
1858 & zi, theta, qkw, &
1859 & Psig_bl, cldfra_bl1D, &
1860 & bl_mynn_mixlength, &
1861 & edmf_w1,edmf_a1 )
1862
1863!-------------------------------------------------------------------
1864
1865 integer, intent(in) :: kts,kte
1866
1867#ifdef HARDCODE_VERTICAL
1868# define kts 1
1869# define kte HARDCODE_VERTICAL
1870#endif
1871
1872 integer, intent(in) :: bl_mynn_mixlength
1873 real(kind_phys), dimension(kts:kte), intent(in) :: dz
1874 real(kind_phys), dimension(kts:kte+1), intent(in) :: zw
1875 real(kind_phys), intent(in) :: rmo,flt,fltv,flq,Psig_bl,xland
1876 real(kind_phys), intent(in) :: dx,zi
1877 real(kind_phys), dimension(kts:kte), intent(in) :: u1,v1, &
1878 &qke,vt,vq,cldfra_bl1D,edmf_w1,edmf_a1
1879 real(kind_phys), dimension(kts:kte), intent(out) :: qkw, el
1880 real(kind_phys), dimension(kts:kte), intent(in) :: dtv
1881 real(kind_phys):: elt,vsc
1882 real(kind_phys), dimension(kts:kte), intent(in) :: theta
1883 real(kind_phys), dimension(kts:kte) :: qtke,elBLmin,elBLavg,thetaw
1884 real(kind_phys):: wt,wt2,zi2,h1,h2,hs,elBLmin0,elBLavg0,cldavg
1885
1886 ! THE FOLLOWING CONSTANTS ARE IMPORTANT FOR REGULATING THE
1887 ! MIXING LENGTHS:
1888 real(kind_phys):: cns, & !< for surface layer (els) in stable conditions
1889 alp1, & !< for turbulent length scale (elt)
1890 alp2, & !< for buoyancy length scale (elb)
1891 alp3, & !< for buoyancy enhancement factor of elb
1892 alp4, & !< for surface layer (els) in unstable conditions
1893 alp5, & !< for BouLac mixing length or above PBLH
1894 alp6
1895
1896 !THE FOLLOWING LIMITS DO NOT DIRECTLY AFFECT THE ACTUAL PBLH.
1897 !THEY ONLY IMPOSE LIMITS ON THE CALCULATION OF THE MIXING LENGTH
1898 !SCALES SO THAT THE BOULAC MIXING LENGTH (IN FREE ATMOS) DOES
1899 !NOT ENCROACH UPON THE BOUNDARY LAYER MIXING LENGTH (els, elb & elt).
1900 real(kind_phys), parameter :: minzi = 300.
1901 real(kind_phys), parameter :: maxdz = 750.
1904 real(kind_phys), parameter :: mindz = 300.
1905
1906 !SURFACE LAYER LENGTH SCALE MODS TO REDUCE IMPACT IN UPPER BOUNDARY LAYER
1907 real(kind_phys), parameter :: ZSLH = 100.
1908 real(kind_phys), parameter :: CSL = 2.
1909
1910
1911 integer :: i,j,k
1912 real(kind_phys):: afk,abk,zwk,zwk1,dzk,qdz,vflx,bv,tau_cloud, &
1913 & wstar,elb,els,elf,el_stab,el_mf,el_stab_mf,elb_mf, &
1914 & PBLH_PLUS_ENT,Uonset,Ugrid,wt_u,el_les
1915 real(kind_phys), parameter :: ctau = 1000. !constant for tau_cloud
1916
1917! tv0 = 0.61*tref
1918! gtr = 9.81/tref
1919
1920 SELECT CASE(bl_mynn_mixlength)
1921
1922 CASE (0) ! ORIGINAL MYNN MIXING LENGTH + BouLac
1923
1924 cns = 2.7
1925 alp1 = 0.23
1926 alp2 = 1.0
1927 alp3 = 5.0
1928 alp4 = 100.
1929 alp5 = 0.3
1930
1931 ! Impose limits on the height integration for elt and the transition layer depth
1932 zi2 = min(10000.,zw(kte-2)) !originally integrated to model top, not just 10 km.
1933 h1=max(0.3*zi2,mindz)
1934 h1=min(h1,maxdz) ! 1/2 transition layer depth
1935 h2=h1/2.0 ! 1/4 transition layer depth
1936
1937 qkw(kts) = sqrt(max(qke(kts),1.0e-10))
1938 DO k = kts+1,kte
1939 afk = dz(k)/( dz(k)+dz(k-1) )
1940 abk = 1.0 -afk
1941 qkw(k) = sqrt(max(qke(k)*abk+qke(k-1)*afk,1.0e-3))
1942 END DO
1943
1944 elt = 1.0e-5
1945 vsc = 1.0e-5
1946
1947 ! ** Strictly, zwk*h(i,j) -> ( zwk*h(i,j)+z0 ) **
1948 k = kts+1
1949 zwk = zw(k)
1950 DO WHILE (zwk .LE. zi2+h1)
1951 dzk = 0.5*( dz(k)+dz(k-1) )
1952 qdz = max( qkw(k)-qmin, 0.03 )*dzk
1953 elt = elt +qdz*zwk
1954 vsc = vsc +qdz
1955 k = k+1
1956 zwk = zw(k)
1957 END DO
1958
1959 elt = alp1*elt/vsc
1960 vflx = ( vt(kts)+1.0 )*flt +( vq(kts)+tv0 )*flq
1961 vsc = ( gtr*elt*max( vflx, 0.0 ) )**(1.0/3.0)
1962
1963 ! ** Strictly, el(i,k=1) is not zero. **
1964 el(kts) = 0.0
1965 zwk1 = zw(kts+1)
1966
1967 DO k = kts+1,kte
1968 zwk = zw(k) !full-sigma levels
1969
1970 ! ** Length scale limited by the buoyancy effect **
1971 IF ( dtv(k) .GT. 0.0 ) THEN
1972 bv = sqrt( gtr*dtv(k) )
1973 elb = alp2*qkw(k) / bv &
1974 & *( 1.0 + alp3/alp2*&
1975 &sqrt( vsc/( bv*elt ) ) )
1976 elf = alp2 * qkw(k)/bv
1977
1978 ELSE
1979 elb = 1.0e10
1980 elf = elb
1981 ENDIF
1982
1983 ! ** Length scale in the surface layer **
1984 IF ( rmo .GT. 0.0 ) THEN
1985 els = karman*zwk/(1.0+cns*min( zwk*rmo, zmax ))
1986 ELSE
1987 els = karman*zwk*( 1.0 - alp4* zwk*rmo )**0.2
1988 END IF
1989
1990 ! ** HARMONC AVERGING OF MIXING LENGTH SCALES:
1991 ! el(k) = MIN(elb/( elb/elt+elb/els+1.0 ),elf)
1992 ! el(k) = elb/( elb/elt+elb/els+1.0 )
1993
1994 wt=.5*tanh((zwk - (zi2+h1))/h2) + .5
1995
1996 el(k) = min(elb/( elb/elt+elb/els+1.0 ),elf)
1997
1998 END DO
1999
2000 CASE (1) !NONLOCAL (using BouLac) FORM OF MIXING LENGTH
2001
2002 ugrid = sqrt(u1(kts)**2 + v1(kts)**2)
2003 uonset= 15.
2004 wt_u = (1.0 - min(max(ugrid - uonset, 0.0)/30.0, 0.5))
2005 cns = 2.7 !was 3.5
2006 alp1 = 0.23
2007 alp2 = 0.3
2008 alp3 = 2.5 * wt_u !taper off bouyancy enhancement in shear-driven pbls
2009 alp4 = 5.0
2010 alp5 = 0.3
2011 alp6 = 50.
2012
2013 ! Impose limits on the height integration for elt and the transition layer depth
2014 zi2=max(zi,300.) !minzi)
2015 h1=max(0.3*zi2,300.)
2016 h1=min(h1,600.) ! 1/2 transition layer depth
2017 h2=h1/2.0 ! 1/4 transition layer depth
2018
2019 qtke(kts)=max(0.5*qke(kts), 0.01) !tke at full sigma levels
2020 thetaw(kts)=theta(kts) !theta at full-sigma levels
2021 qkw(kts) = sqrt(max(qke(kts),1.0e-10))
2022
2023 DO k = kts+1,kte
2024 afk = dz(k)/( dz(k)+dz(k-1) )
2025 abk = 1.0 -afk
2026 qkw(k) = sqrt(max(qke(k)*abk+qke(k-1)*afk,1.0e-3))
2027 qtke(k) = 0.5*(qkw(k)**2) ! q -> TKE
2028 thetaw(k)= theta(k)*abk + theta(k-1)*afk
2029 END DO
2030
2031 elt = 1.0e-5
2032 vsc = 1.0e-5
2033
2034 ! ** Strictly, zwk*h(i,j) -> ( zwk*h(i,j)+z0 ) **
2035 k = kts+1
2036 zwk = zw(k)
2037 DO WHILE (zwk .LE. zi2+h1)
2038 dzk = 0.5*( dz(k)+dz(k-1) )
2039 qdz = min(max( qkw(k)-qmin, 0.03 ), 30.0)*dzk
2040 elt = elt +qdz*zwk
2041 vsc = vsc +qdz
2042 k = k+1
2043 zwk = zw(k)
2044 END DO
2045
2046 elt = min( max( alp1*elt/vsc, 10.), 400.)
2047 !avoid use of buoyancy flux functions which are ill-defined at the surface
2048 !vflx = ( vt(kts)+1.0 )*flt + ( vq(kts)+tv0 )*flq
2049 vflx = fltv
2050 vsc = ( gtr*elt*max( vflx, 0.0 ) )**onethird
2051
2052 ! ** Strictly, el(i,j,1) is not zero. **
2053 el(kts) = 0.0
2054 zwk1 = zw(kts+1) !full-sigma levels
2055
2056 ! COMPUTE BouLac mixing length
2057 CALL boulac_length(kts,kte,zw,dz,qtke,thetaw,elblmin,elblavg)
2058
2059 DO k = kts+1,kte
2060 zwk = zw(k) !full-sigma levels
2061
2062 ! ** Length scale limited by the buoyancy effect **
2063 IF ( dtv(k) .GT. 0.0 ) THEN
2064 bv = max( sqrt( gtr*dtv(k) ), 0.0001)
2065 elb = max(alp2*qkw(k), &
2066 & alp6*edmf_a1(k-1)*edmf_w1(k-1)) / bv &
2067 & *( 1.0 + alp3*sqrt( vsc/(bv*elt) ) )
2068 elb = min(elb, zwk)
2069 elf = 1.0 * qkw(k)/bv
2070 elblavg(k) = max(elblavg(k), alp6*edmf_a1(k-1)*edmf_w1(k-1)/bv)
2071 ELSE
2072 elb = 1.0e10
2073 elf = elb
2074 ENDIF
2075
2076 ! ** Length scale in the surface layer **
2077 IF ( rmo .GT. 0.0 ) THEN
2078 els = karman*zwk/(1.0+cns*min( zwk*rmo, zmax ))
2079 ELSE
2080 els = karman*zwk*( 1.0 - alp4* zwk*rmo )**0.2
2081 END IF
2082
2083 ! ** NOW BLEND THE MIXING LENGTH SCALES:
2084 wt=.5*tanh((zwk - (zi2+h1))/h2) + .5
2085
2086 !add blending to use BouLac mixing length in free atmos;
2087 !defined relative to the PBLH (zi) + transition layer (h1)
2088 !el(k) = MIN(elb/( elb/elt+elb/els+1.0 ),elf)
2089 !try squared-blending - but take out elb (makes it underdiffusive)
2090 !el(k) = SQRT( els**2/(1. + (els**2/elt**2) +(els**2/elb**2)))
2091 el(k) = sqrt( els**2/(1. + (els**2/elt**2)))
2092 el(k) = min(el(k), elb)
2093 el(k) = min(el(k), elf)
2094 el(k) = el(k)*(1.-wt) + alp5*elblavg(k)*wt
2095
2096 ! include scale-awareness, except for original MYNN
2097 el(k) = el(k)*psig_bl
2098
2099 END DO
2100
2101 CASE (2) !Local (mostly) mixing length formulation
2102
2103 uonset = 3.5 + dz(kts)*0.1
2104 ugrid = sqrt(u1(kts)**2 + v1(kts)**2)
2105 cns = 3.5 !JOE-test * (1.0 - MIN(MAX(Ugrid - Uonset, 0.0)/10.0, 1.0))
2106 alp1 = 0.22
2107 alp2 = 0.30
2108 alp3 = 2.0
2109 alp4 = 5.0
2110 alp5 = alp2 !like alp2, but for free atmosphere
2111 alp6 = 50.0 !used for MF mixing length
2112
2113 ! Impose limits on the height integration for elt and the transition layer depth
2114 !zi2=MAX(zi,minzi)
2115 zi2=max(zi, 300.)
2116 !h1=MAX(0.3*zi2,mindz)
2117 !h1=MIN(h1,maxdz) ! 1/2 transition layer depth
2118 h1=max(0.3*zi2,300.)
2119 h1=min(h1,600.)
2120 h2=h1*0.5 ! 1/4 transition layer depth
2121
2122 qtke(kts)=max(0.5*qke(kts),0.01) !tke at full sigma levels
2123 qkw(kts) = sqrt(max(qke(kts),1.0e-4))
2124
2125 DO k = kts+1,kte
2126 afk = dz(k)/( dz(k)+dz(k-1) )
2127 abk = 1.0 -afk
2128 qkw(k) = sqrt(max(qke(k)*abk+qke(k-1)*afk,1.0e-3))
2129 qtke(k) = 0.5*qkw(k)**2 ! qkw -> TKE
2130 END DO
2131
2132 elt = 1.0e-5
2133 vsc = 1.0e-5
2134
2135 ! ** Strictly, zwk*h(i,j) -> ( zwk*h(i,j)+z0 ) **
2136 pblh_plus_ent = max(zi+h1, 100.)
2137 k = kts+1
2138 zwk = zw(k)
2139 DO WHILE (zwk .LE. pblh_plus_ent)
2140 dzk = 0.5*( dz(k)+dz(k-1) )
2141 qdz = min(max( qkw(k)-qmin, 0.03 ), 30.0)*dzk
2142 elt = elt +qdz*zwk
2143 vsc = vsc +qdz
2144 k = k+1
2145 zwk = zw(k)
2146 END DO
2147
2148 elt = min( max(alp1*elt/vsc, 10.), 400.)
2149 !avoid use of buoyancy flux functions which are ill-defined at the surface
2150 !vflx = ( vt(kts)+1.0 )*flt +( vq(kts)+tv0 )*flq
2151 vflx = fltv
2152 vsc = ( gtr*elt*max( vflx, 0.0 ) )**onethird
2153
2154 ! ** Strictly, el(i,j,1) is not zero. **
2155 el(kts) = 0.0
2156 zwk1 = zw(kts+1)
2157
2158 DO k = kts+1,kte
2159 zwk = zw(k) !full-sigma levels
2160 dzk = 0.5*( dz(k)+dz(k-1) )
2161 cldavg = 0.5*(cldfra_bl1d(k-1)+cldfra_bl1d(k))
2162
2163 ! ** Length scale limited by the buoyancy effect **
2164 IF ( dtv(k) .GT. 0.0 ) THEN
2165 !impose min value on bv
2166 bv = max( sqrt( gtr*dtv(k) ), 0.001)
2167 !elb_mf = alp2*qkw(k) / bv &
2168 elb_mf = max(alp2*qkw(k), &
2169 & alp6*edmf_a1(k-1)*edmf_w1(k-1)) / bv &
2170 & *( 1.0 + alp3*sqrt( vsc/( bv*elt ) ) )
2171 elb = min(max(alp5*qkw(k), alp6*edmf_a1(k)*edmf_w1(k))/bv, zwk)
2172
2173 !tau_cloud = MIN(MAX(0.5*zi/((gtr*zi*MAX(vflx,1.0e-4))**onethird),30.),150.)
2174 wstar = 1.25*(gtr*zi*max(vflx,1.0e-4))**onethird
2175 tau_cloud = min(max(ctau * wstar/grav, 30.), 150.)
2176 !minimize influence of surface heat flux on tau far away from the PBLH.
2177 wt=.5*tanh((zwk - (zi2+h1))/h2) + .5
2178 tau_cloud = tau_cloud*(1.-wt) + 50.*wt
2179 elf = min(max(tau_cloud*sqrt(min(qtke(k),40.)), &
2180 & alp6*edmf_a1(k)*edmf_w1(k)/bv), zwk)
2181
2182 !IF (zwk > zi .AND. elf > 400.) THEN
2183 ! ! COMPUTE BouLac mixing length
2184 ! !CALL boulac_length0(k,kts,kte,zw,dz,qtke,thetaw,elBLmin0,elBLavg0)
2185 ! !elf = alp5*elBLavg0
2186 ! elf = MIN(MAX(50.*SQRT(qtke(k)), 400.), zwk)
2187 !ENDIF
2188
2189 ELSE
2190 ! use version in development for RAP/HRRR 2016
2191 ! JAYMES-
2192 ! tau_cloud is an eddy turnover timescale;
2193 ! see Teixeira and Cheinet (2004), Eq. 1, and
2194 ! Cheinet and Teixeira (2003), Eq. 7. The
2195 ! coefficient 0.5 is tuneable. Expression in
2196 ! denominator is identical to vsc (a convective
2197 ! velocity scale), except that elt is relpaced
2198 ! by zi, and zero is replaced by 1.0e-4 to
2199 ! prevent division by zero.
2200 !tau_cloud = MIN(MAX(0.5*zi/((gtr*zi*MAX(vflx,1.0e-4))**onethird),50.),150.)
2201 wstar = 1.25*(gtr*zi*max(vflx,1.0e-4))**onethird
2202 tau_cloud = min(max(ctau * wstar/grav, 50.), 200.)
2203 !minimize influence of surface heat flux on tau far away from the PBLH.
2204 wt=.5*tanh((zwk - (zi2+h1))/h2) + .5
2205 !tau_cloud = tau_cloud*(1.-wt) + 50.*wt
2206 tau_cloud = tau_cloud*(1.-wt) + max(100.,dzk*0.25)*wt
2207
2208 elb = min(tau_cloud*sqrt(min(qtke(k),40.)), zwk)
2209 !elf = elb
2210 elf = elb !/(1. + (elb/800.)) !bound free-atmos mixing length to < 800 m.
2211 elb_mf = elb
2212 END IF
2213 elf = elf/(1. + (elf/800.)) !bound free-atmos mixing length to < 800 m.
2214 elb_mf = max(elb_mf, 0.01) !to avoid divide-by-zero below
2215
2216 ! ** Length scale in the surface layer **
2217 IF ( rmo .GT. 0.0 ) THEN
2218 els = karman*zwk/(1.0+cns*min( zwk*rmo, zmax ))
2219 ELSE
2220 els = karman*zwk*( 1.0 - alp4* zwk*rmo )**0.2
2221 END IF
2222
2223 ! ** NOW BLEND THE MIXING LENGTH SCALES:
2224 wt=.5*tanh((zwk - (zi2+h1))/h2) + .5
2225
2226 !try squared-blending
2227 el(k) = sqrt( els**2/(1. + (els**2/elt**2) +(els**2/elb_mf**2)))
2228 el(k) = el(k)*(1.-wt) + elf*wt
2229
2230 ! include scale-awareness. For now, use simple asymptotic kz -> 12 m (should be ~dz).
2231 el_les= min(els/(1. + (els/12.)), elb_mf)
2232 el(k) = el(k)*psig_bl + (1.-psig_bl)*el_les
2233
2234 END DO
2235
2236 END SELECT
2237
2238
2239#ifdef HARDCODE_VERTICAL
2240# undef kts
2241# undef kte
2242#endif
2243
2244 END SUBROUTINE mym_length
2245
2246! ==================================================================
2253!\param dlu the distance a parcel can be lifted upwards give a finite
2254! amount of TKE.
2255!\param dld the distance a parcel can be displaced downwards given a
2256! finite amount of TKE.
2257!\param lb1 the minimum of the length up and length down
2258!\param lb2 the average of the length up and length down
2259 SUBROUTINE boulac_length0(k,kts,kte,zw,dz,qtke,theta,lb1,lb2)
2260!
2261! NOTE: This subroutine was taken from the BouLac scheme in WRF-ARW
2262! and modified for integration into the MYNN PBL scheme.
2263! WHILE loops were added to reduce the computational expense.
2264! This subroutine computes the length scales up and down
2265! and then computes the min, average of the up/down
2266! length scales, and also considers the distance to the
2267! surface.
2268!
2269! dlu = the distance a parcel can be lifted upwards give a finite
2270! amount of TKE.
2271! dld = the distance a parcel can be displaced downwards given a
2272! finite amount of TKE.
2273! lb1 = the minimum of the length up and length down
2274! lb2 = the average of the length up and length down
2275!-------------------------------------------------------------------
2276
2277 integer, intent(in) :: k,kts,kte
2278 real(kind_phys), dimension(kts:kte), intent(in) :: qtke,dz,theta
2279 real(kind_phys), intent(out) :: lb1,lb2
2280 real(kind_phys), dimension(kts:kte+1), intent(in) :: zw
2281
2282 !LOCAL VARS
2283 integer :: izz, found
2284 real(kind_phys):: dlu,dld
2285 real(kind_phys):: dzt, zup, beta, zup_inf, bbb, tl, zdo, zdo_sup, zzz
2286
2287
2288 !----------------------------------
2289 ! FIND DISTANCE UPWARD
2290 !----------------------------------
2291 zup=0.
2292 dlu=zw(kte+1)-zw(k)-dz(k)*0.5
2293 zzz=0.
2294 zup_inf=0.
2295 beta=gtr !Buoyancy coefficient (g/tref)
2296
2297 !print*,"FINDING Dup, k=",k," zw=",zw(k)
2298
2299 if (k .lt. kte) then !cant integrate upwards from highest level
2300 found = 0
2301 izz=k
2302 DO WHILE (found .EQ. 0)
2303
2304 if (izz .lt. kte) then
2305 dzt=dz(izz) ! layer depth above
2306 zup=zup-beta*theta(k)*dzt ! initial PE the parcel has at k
2307 !print*," ",k,izz,theta(izz),dz(izz)
2308 zup=zup+beta*(theta(izz+1)+theta(izz))*dzt*0.5 ! PE gained by lifting a parcel to izz+1
2309 zzz=zzz+dzt ! depth of layer k to izz+1
2310 !print*," PE=",zup," TKE=",qtke(k)," z=",zw(izz)
2311 if (qtke(k).lt.zup .and. qtke(k).ge.zup_inf) then
2312 bbb=(theta(izz+1)-theta(izz))/dzt
2313 if (bbb .ne. 0.) then
2314 !fractional distance up into the layer where TKE becomes < PE
2315 tl=(-beta*(theta(izz)-theta(k)) + &
2316 & sqrt( max(0.,(beta*(theta(izz)-theta(k)))**2 + &
2317 & 2.*bbb*beta*(qtke(k)-zup_inf))))/bbb/beta
2318 else
2319 if (theta(izz) .ne. theta(k))then
2320 tl=(qtke(k)-zup_inf)/(beta*(theta(izz)-theta(k)))
2321 else
2322 tl=0.
2323 endif
2324 endif
2325 dlu=zzz-dzt+tl
2326 !print*," FOUND Dup:",dlu," z=",zw(izz)," tl=",tl
2327 found =1
2328 endif
2329 zup_inf=zup
2330 izz=izz+1
2331 ELSE
2332 found = 1
2333 ENDIF
2334
2335 ENDDO
2336
2337 endif
2338
2339 !----------------------------------
2340 ! FIND DISTANCE DOWN
2341 !----------------------------------
2342 zdo=0.
2343 zdo_sup=0.
2344 dld=zw(k)
2345 zzz=0.
2346
2347 !print*,"FINDING Ddown, k=",k," zwk=",zw(k)
2348 if (k .gt. kts) then !cant integrate downwards from lowest level
2349
2350 found = 0
2351 izz=k
2352 DO WHILE (found .EQ. 0)
2353
2354 if (izz .gt. kts) then
2355 dzt=dz(izz-1)
2356 zdo=zdo+beta*theta(k)*dzt
2357 !print*," ",k,izz,theta(izz),dz(izz-1)
2358 zdo=zdo-beta*(theta(izz-1)+theta(izz))*dzt*0.5
2359 zzz=zzz+dzt
2360 !print*," PE=",zdo," TKE=",qtke(k)," z=",zw(izz)
2361 if (qtke(k).lt.zdo .and. qtke(k).ge.zdo_sup) then
2362 bbb=(theta(izz)-theta(izz-1))/dzt
2363 if (bbb .ne. 0.) then
2364 tl=(beta*(theta(izz)-theta(k))+ &
2365 & sqrt( max(0.,(beta*(theta(izz)-theta(k)))**2 + &
2366 & 2.*bbb*beta*(qtke(k)-zdo_sup))))/bbb/beta
2367 else
2368 if (theta(izz) .ne. theta(k)) then
2369 tl=(qtke(k)-zdo_sup)/(beta*(theta(izz)-theta(k)))
2370 else
2371 tl=0.
2372 endif
2373 endif
2374 dld=zzz-dzt+tl
2375 !print*," FOUND Ddown:",dld," z=",zw(izz)," tl=",tl
2376 found = 1
2377 endif
2378 zdo_sup=zdo
2379 izz=izz-1
2380 ELSE
2381 found = 1
2382 ENDIF
2383 ENDDO
2384
2385 endif
2386
2387 !----------------------------------
2388 ! GET MINIMUM (OR AVERAGE)
2389 !----------------------------------
2390 !The surface layer length scale can exceed z for large z/L,
2391 !so keep maximum distance down > z.
2392 dld = min(dld,zw(k+1))!not used in PBL anyway, only free atmos
2393 lb1 = min(dlu,dld) !minimum
2394 !JOE-fight floating point errors
2395 dlu=max(0.1,min(dlu,1000.))
2396 dld=max(0.1,min(dld,1000.))
2397 lb2 = sqrt(dlu*dld) !average - biased towards smallest
2398 !lb2 = 0.5*(dlu+dld) !average
2399
2400 if (k .eq. kte) then
2401 lb1 = 0.
2402 lb2 = 0.
2403 endif
2404 !print*,"IN MYNN-BouLac",k,lb1
2405 !print*,"IN MYNN-BouLac",k,dld,dlu
2406
2407 END SUBROUTINE boulac_length0
2408
2409! ==================================================================
2418 SUBROUTINE boulac_length(kts,kte,zw,dz,qtke,theta,lb1,lb2)
2419! dlu = the distance a parcel can be lifted upwards give a finite
2420! amount of TKE.
2421! dld = the distance a parcel can be displaced downwards given a
2422! finite amount of TKE.
2423! lb1 = the minimum of the length up and length down
2424! lb2 = the average of the length up and length down
2425!-------------------------------------------------------------------
2426
2427 integer, intent(in) :: kts,kte
2428 real(kind_phys), dimension(kts:kte), intent(in) :: qtke,dz,theta
2429 real(kind_phys), dimension(kts:kte), intent(out):: lb1,lb2
2430 real(kind_phys), dimension(kts:kte+1), intent(in) :: zw
2431
2432 !LOCAL VARS
2433 integer :: iz, izz, found
2434 real(kind_phys), dimension(kts:kte) :: dlu,dld
2435 real(kind_phys), parameter :: Lmax=2000. !soft limit
2436 real(kind_phys):: dzt, zup, beta, zup_inf, bbb, tl, zdo, zdo_sup, zzz
2437
2438 !print*,"IN MYNN-BouLac",kts, kte
2439
2440 do iz=kts,kte
2441
2442 !----------------------------------
2443 ! FIND DISTANCE UPWARD
2444 !----------------------------------
2445 zup=0.
2446 dlu(iz)=zw(kte+1)-zw(iz)-dz(iz)*0.5
2447 zzz=0.
2448 zup_inf=0.
2449 beta=gtr !Buoyancy coefficient (g/tref)
2450
2451 !print*,"FINDING Dup, k=",iz," zw=",zw(iz)
2452
2453 if (iz .lt. kte) then !cant integrate upwards from highest level
2454
2455 found = 0
2456 izz=iz
2457 DO WHILE (found .EQ. 0)
2458
2459 if (izz .lt. kte) then
2460 dzt=dz(izz) ! layer depth above
2461 zup=zup-beta*theta(iz)*dzt ! initial PE the parcel has at iz
2462 !print*," ",iz,izz,theta(izz),dz(izz)
2463 zup=zup+beta*(theta(izz+1)+theta(izz))*dzt*0.5 ! PE gained by lifting a parcel to izz+1
2464 zzz=zzz+dzt ! depth of layer iz to izz+1
2465 !print*," PE=",zup," TKE=",qtke(iz)," z=",zw(izz)
2466 if (qtke(iz).lt.zup .and. qtke(iz).ge.zup_inf) then
2467 bbb=(theta(izz+1)-theta(izz))/dzt
2468 if (bbb .ne. 0.) then
2469 !fractional distance up into the layer where TKE becomes < PE
2470 tl=(-beta*(theta(izz)-theta(iz)) + &
2471 & sqrt( max(0.,(beta*(theta(izz)-theta(iz)))**2 + &
2472 & 2.*bbb*beta*(qtke(iz)-zup_inf))))/bbb/beta
2473 else
2474 if (theta(izz) .ne. theta(iz))then
2475 tl=(qtke(iz)-zup_inf)/(beta*(theta(izz)-theta(iz)))
2476 else
2477 tl=0.
2478 endif
2479 endif
2480 dlu(iz)=zzz-dzt+tl
2481 !print*," FOUND Dup:",dlu(iz)," z=",zw(izz)," tl=",tl
2482 found =1
2483 endif
2484 zup_inf=zup
2485 izz=izz+1
2486 ELSE
2487 found = 1
2488 ENDIF
2489
2490 ENDDO
2491
2492 endif
2493
2494 !----------------------------------
2495 ! FIND DISTANCE DOWN
2496 !----------------------------------
2497 zdo=0.
2498 zdo_sup=0.
2499 dld(iz)=zw(iz)
2500 zzz=0.
2501
2502 !print*,"FINDING Ddown, k=",iz," zwk=",zw(iz)
2503 if (iz .gt. kts) then !cant integrate downwards from lowest level
2504
2505 found = 0
2506 izz=iz
2507 DO WHILE (found .EQ. 0)
2508
2509 if (izz .gt. kts) then
2510 dzt=dz(izz-1)
2511 zdo=zdo+beta*theta(iz)*dzt
2512 !print*," ",iz,izz,theta(izz),dz(izz-1)
2513 zdo=zdo-beta*(theta(izz-1)+theta(izz))*dzt*0.5
2514 zzz=zzz+dzt
2515 !print*," PE=",zdo," TKE=",qtke(iz)," z=",zw(izz)
2516 if (qtke(iz).lt.zdo .and. qtke(iz).ge.zdo_sup) then
2517 bbb=(theta(izz)-theta(izz-1))/dzt
2518 if (bbb .ne. 0.) then
2519 tl=(beta*(theta(izz)-theta(iz))+ &
2520 & sqrt( max(0.,(beta*(theta(izz)-theta(iz)))**2 + &
2521 & 2.*bbb*beta*(qtke(iz)-zdo_sup))))/bbb/beta
2522 else
2523 if (theta(izz) .ne. theta(iz)) then
2524 tl=(qtke(iz)-zdo_sup)/(beta*(theta(izz)-theta(iz)))
2525 else
2526 tl=0.
2527 endif
2528 endif
2529 dld(iz)=zzz-dzt+tl
2530 !print*," FOUND Ddown:",dld(iz)," z=",zw(izz)," tl=",tl
2531 found = 1
2532 endif
2533 zdo_sup=zdo
2534 izz=izz-1
2535 ELSE
2536 found = 1
2537 ENDIF
2538 ENDDO
2539
2540 endif
2541
2542 !----------------------------------
2543 ! GET MINIMUM (OR AVERAGE)
2544 !----------------------------------
2545 !The surface layer length scale can exceed z for large z/L,
2546 !so keep maximum distance down > z.
2547 dld(iz) = min(dld(iz),zw(iz+1))!not used in PBL anyway, only free atmos
2548 lb1(iz) = min(dlu(iz),dld(iz)) !minimum
2549 !JOE-fight floating point errors
2550 dlu(iz)=max(0.1,min(dlu(iz),1000.))
2551 dld(iz)=max(0.1,min(dld(iz),1000.))
2552 lb2(iz) = sqrt(dlu(iz)*dld(iz)) !average - biased towards smallest
2553 !lb2(iz) = 0.5*(dlu(iz)+dld(iz)) !average
2554
2555 !Apply soft limit (only impacts very large lb; lb=100 by 5%, lb=500 by 20%).
2556 lb1(iz) = lb1(iz)/(1. + (lb1(iz)/lmax))
2557 lb2(iz) = lb2(iz)/(1. + (lb2(iz)/lmax))
2558
2559 if (iz .eq. kte) then
2560 lb1(kte) = lb1(kte-1)
2561 lb2(kte) = lb2(kte-1)
2562 endif
2563 !print*,"IN MYNN-BouLac",kts, kte,lb1(iz)
2564 !print*,"IN MYNN-BouLac",iz,dld(iz),dlu(iz)
2565
2566 ENDDO
2567
2568 END SUBROUTINE boulac_length
2569!
2570! ==================================================================
2571! SUBROUTINE mym_turbulence:
2572!
2573! Input variables: see subroutine mym_initialize
2574! closure : closure level (2.5, 2.6, or 3.0)
2575!
2576! # ql, vt, vq, qke, tsq, qsq and cov are changed to input variables.
2577!
2578! Output variables: see subroutine mym_initialize
2579! dfm(nx,nz,ny) : Diffusivity coefficient for momentum,
2580! divided by dz (not dz*h(i,j)) (m/s)
2581! dfh(nx,nz,ny) : Diffusivity coefficient for heat,
2582! divided by dz (not dz*h(i,j)) (m/s)
2583! dfq(nx,nz,ny) : Diffusivity coefficient for q^2,
2584! divided by dz (not dz*h(i,j)) (m/s)
2585! tcd(nx,nz,ny) : Countergradient diffusion term for Theta_l
2586! (K/s)
2587! qcd(nx,nz,ny) : Countergradient diffusion term for Q_w
2588! (kg/kg s)
2589! pd?(nx,nz,ny) : Half of the production terms
2590!
2591! Only tcd and qcd are defined at the center of the grid boxes
2592!
2593! # DO NOT forget that tcd and qcd are added on the right-hand side
2594! of the equations for Theta_l and Q_w, respectively.
2595!
2596! Work arrays: see subroutine mym_initialize and level2
2597!
2598! # dtl, dqw, dtv, gm and gh are allowed to share storage units with
2599! dfm, dfh, dfq, tcd and qcd, respectively, for saving memory.
2600!
2619 SUBROUTINE mym_turbulence ( &
2620 & kts,kte, &
2621 & xland,closure, &
2622 & dz, dx, zw, &
2623 & u, v, thl, thetav, ql, qw, &
2624 & qke, tsq, qsq, cov, &
2625 & vt, vq, &
2626 & rmo, flt, fltv, flq, &
2627 & zi,theta, &
2628 & sh, sm, &
2629 & El, &
2630 & Dfm, Dfh, Dfq, Tcd, Qcd, Pdk, Pdt, Pdq, Pdc, &
2631 & qWT1D,qSHEAR1D,qBUOY1D,qDISS1D, &
2632 & tke_budget, &
2633 & Psig_bl,Psig_shcu,cldfra_bl1D, &
2634 & bl_mynn_mixlength, &
2635 & edmf_w1,edmf_a1, &
2636 & TKEprodTD, &
2637 & spp_pbl,rstoch_col )
2638
2639!-------------------------------------------------------------------
2640
2641 integer, intent(in) :: kts,kte
2642
2643#ifdef HARDCODE_VERTICAL
2644# define kts 1
2645# define kte HARDCODE_VERTICAL
2646#endif
2647
2648 integer, intent(in) :: bl_mynn_mixlength,tke_budget
2649 real(kind_phys), intent(in) :: closure
2650 real(kind_phys), dimension(kts:kte), intent(in) :: dz
2651 real(kind_phys), dimension(kts:kte+1), intent(in) :: zw
2652 real(kind_phys), intent(in) :: rmo,flt,fltv,flq, &
2653 &Psig_bl,Psig_shcu,xland,dx,zi
2654 real(kind_phys), dimension(kts:kte), intent(in) :: u,v,thl,thetav,qw, &
2655 &ql,vt,vq,qke,tsq,qsq,cov,cldfra_bl1D,edmf_w1,edmf_a1, &
2656 &TKEprodTD
2657
2658 real(kind_phys), dimension(kts:kte), intent(out) :: dfm,dfh,dfq, &
2659 &pdk,pdt,pdq,pdc,tcd,qcd,el
2660
2661 real(kind_phys), dimension(kts:kte), intent(inout) :: &
2662 qWT1D,qSHEAR1D,qBUOY1D,qDISS1D
2663 real(kind_phys):: q3sq_old,dlsq1,qWTP_old,qWTP_new
2664 real(kind_phys):: dudz,dvdz,dTdz,upwp,vpwp,Tpwp
2665
2666 real(kind_phys), dimension(kts:kte) :: qkw,dtl,dqw,dtv,gm,gh,sm,sh
2667
2668 integer :: k
2669! real(kind_phys):: cc2,cc3,e1c,e2c,e3c,e4c,e5c
2670 real(kind_phys):: e6c,dzk,afk,abk,vtt,vqq, &
2671 &cw25,clow,cupp,gamt,gamq,smd,gamv,elq,elh
2672
2673 real(kind_phys):: cldavg
2674 real(kind_phys), dimension(kts:kte), intent(in) :: theta
2675
2676 real(kind_phys):: a2fac, duz, ri !JOE-Canuto/Kitamura mod
2677
2678 real:: auh,aum,adh,adm,aeh,aem,Req,Rsl,Rsl2, &
2679 gmelq,sm20,sh20,sm25max,sh25max,sm25min,sh25min, &
2680 sm_pbl,sh_pbl,zi2,wt,slht,wtpr
2681
2682 DOUBLE PRECISION q2sq, t2sq, r2sq, c2sq, elsq, gmel, ghel
2683 DOUBLE PRECISION q3sq, t3sq, r3sq, c3sq, dlsq, qdiv
2684 DOUBLE PRECISION e1, e2, e3, e4, enum, eden, wden
2685
2686! Stochastic
2687 integer, intent(in) :: spp_pbl
2688 real(kind_phys), dimension(kts:kte) :: rstoch_col
2689 real(kind_phys):: Prnum, shb
2690 real(kind_phys), parameter :: Prlimit = 5.0
2691
2692!
2693! tv0 = 0.61*tref
2694! gtr = 9.81/tref
2695!
2696! cc2 = 1.0-c2
2697! cc3 = 1.0-c3
2698! e1c = 3.0*a2*b2*cc3
2699! e2c = 9.0*a1*a2*cc2
2700! e3c = 9.0*a2*a2*cc2*( 1.0-c5 )
2701! e4c = 12.0*a1*a2*cc2
2702! e5c = 6.0*a1*a1
2703!
2704
2705 CALL mym_level2 (kts,kte, &
2706 & dz, &
2707 & u, v, thl, thetav, qw, &
2708 & ql, vt, vq, &
2709 & dtl, dqw, dtv, gm, gh, sm, sh )
2710!
2711 CALL mym_length ( &
2712 & kts,kte,xland, &
2713 & dz, dx, zw, &
2714 & rmo, flt, fltv, flq, &
2715 & vt, vq, &
2716 & u, v, qke, &
2717 & dtv, &
2718 & el, &
2719 & zi,theta, &
2720 & qkw,psig_bl,cldfra_bl1d, &
2721 & bl_mynn_mixlength, &
2722 & edmf_w1,edmf_a1 )
2723!
2724
2725 DO k = kts+1,kte
2726 dzk = 0.5 *( dz(k)+dz(k-1) )
2727 afk = dz(k)/( dz(k)+dz(k-1) )
2728 abk = 1.0 -afk
2729 elsq = el(k)**2
2730 q3sq = qkw(k)**2
2731 q2sq = b1*elsq*( sm(k)*gm(k)+sh(k)*gh(k) )
2732
2733 sh20 = max(sh(k), 1e-5)
2734 sm20 = max(sm(k), 1e-5)
2735 sh(k)= max(sh(k), 1e-5)
2736
2737 !Canuto/Kitamura mod
2738 duz = ( u(k)-u(k-1) )**2 +( v(k)-v(k-1) )**2
2739 duz = duz /dzk**2
2740 ! ** Gradient Richardson number **
2741 ri = -gh(k)/max( duz, 1.0e-10 )
2742 IF (ckmod .eq. 1) THEN
2743 a2fac = 1./(1. + max(ri,0.0))
2744 ELSE
2745 a2fac = 1.
2746 ENDIF
2747 !end Canuto/Kitamura mod
2748
2749 !level 2.0 Prandtl number
2750 !Prnum = MIN(sm20/sh20, 4.0)
2751 !The form of Zilitinkevich et al. (2006) but modified
2752 !half-way towards Esau and Grachev (2007, Wind Eng)
2753 !Prnum = MIN(0.76 + 3.0*MAX(ri,0.0), Prlimit)
2754 prnum = min(0.76 + 4.0*max(ri,0.0), prlimit)
2755 !Prnum = MIN(0.76 + 5.0*MAX(ri,0.0), Prlimit)
2756!
2757! Modified: Dec/22/2005, from here, (dlsq -> elsq)
2758 gmel = gm(k)*elsq
2759 ghel = gh(k)*elsq
2760! Modified: Dec/22/2005, up to here
2761
2762 ! Level 2.0 debug prints
2763 IF ( debug_code ) THEN
2764 IF (sh(k)<0.0 .OR. sm(k)<0.0) THEN
2765 print*,"MYNN; mym_turbulence 2.0; sh=",sh(k)," k=",k
2766 print*," gm=",gm(k)," gh=",gh(k)," sm=",sm(k)
2767 print*," q2sq=",q2sq," q3sq=",q3sq," q3/q2=",q3sq/q2sq
2768 print*," qke=",qke(k)," el=",el(k)," ri=",ri
2769 print*," PBLH=",zi," u=",u(k)," v=",v(k)
2770 ENDIF
2771 ENDIF
2772
2773! ** Since qkw is set to more than 0.0, q3sq > 0.0. **
2774
2775! new stability criteria in level 2.5 (as well as level 3) - little/no impact
2776! ** Limitation on q, instead of L/q **
2777 dlsq = elsq
2778 IF ( q3sq/dlsq .LT. -gh(k) ) q3sq = -dlsq*gh(k)
2779
2780 IF ( q3sq .LT. q2sq ) THEN
2781 !Apply Helfand & Labraga mod
2782 qdiv = sqrt( q3sq/q2sq ) !HL89: (1-alfa)
2783!
2784 !Use level 2.5 stability functions
2785 !e1 = q3sq - e1c*ghel*a2fac
2786 !e2 = q3sq - e2c*ghel*a2fac
2787 !e3 = e1 + e3c*ghel*a2fac**2
2788 !e4 = e1 - e4c*ghel*a2fac
2789 !eden = e2*e4 + e3*e5c*gmel
2790 !eden = MAX( eden, 1.0d-20 )
2791 !sm(k) = q3sq*a1*( e3-3.0*c1*e4 )/eden
2792 !!JOE-Canuto/Kitamura mod
2793 !!sh(k) = q3sq*a2*( e2+3.0*c1*e5c*gmel )/eden
2794 !sh(k) = q3sq*(a2*a2fac)*( e2+3.0*c1*e5c*gmel )/eden
2795 !sm(k) = Prnum*sh(k)
2796 !sm(k) = sm(k) * qdiv
2797
2798 !Use level 2.0 functions as in original MYNN
2799 sh(k) = sh(k) * qdiv
2800 sm(k) = sm(k) * qdiv
2801 ! !sm_pbl = sm(k) * qdiv
2802 !
2803 ! !Or, use the simple Pr relationship
2804 ! sm(k) = Prnum*sh(k)
2805 !
2806 ! !or blend them:
2807 ! zi2 = MAX(zi, 300.)
2808 ! wt =.5*TANH((zw(k) - zi2)/200.) + .5
2809 ! sm(k) = sm_pbl*(1.-wt) + sm(k)*wt
2810
2811 !Recalculate terms for later use
2812 !JOE-Canuto/Kitamura mod
2813 !e1 = q3sq - e1c*ghel * qdiv**2
2814 !e2 = q3sq - e2c*ghel * qdiv**2
2815 !e3 = e1 + e3c*ghel * qdiv**2
2816 !e4 = e1 - e4c*ghel * qdiv**2
2817 e1 = q3sq - e1c*ghel*a2fac * qdiv**2
2818 e2 = q3sq - e2c*ghel*a2fac * qdiv**2
2819 e3 = e1 + e3c*ghel*a2fac**2 * qdiv**2
2820 e4 = e1 - e4c*ghel*a2fac * qdiv**2
2821 eden = e2*e4 + e3*e5c*gmel * qdiv**2
2822 eden = max( eden, 1.0d-20 )
2823 !!JOE-Canuto/Kitamura mod
2824 !!sh(k) = q3sq*a2*( e2+3.0*c1*e5c*gmel )/eden - retro 5
2825 !sh(k) = q3sq*(a2*a2fac)*( e2+3.0*c1*e5c*gmel )/eden
2826 !sm(k) = Prnum*sh(k)
2827 ELSE
2828 !JOE-Canuto/Kitamura mod
2829 !e1 = q3sq - e1c*ghel
2830 !e2 = q3sq - e2c*ghel
2831 !e3 = e1 + e3c*ghel
2832 !e4 = e1 - e4c*ghel
2833 e1 = q3sq - e1c*ghel*a2fac
2834 e2 = q3sq - e2c*ghel*a2fac
2835 e3 = e1 + e3c*ghel*a2fac**2
2836 e4 = e1 - e4c*ghel*a2fac
2837 eden = e2*e4 + e3*e5c*gmel
2838 eden = max( eden, 1.0d-20 )
2839
2840 qdiv = 1.0
2841 !Use level 2.5 stability functions
2842 sm(k) = q3sq*a1*( e3-3.0*c1*e4 )/eden
2843 ! sm_pbl = q3sq*a1*( e3-3.0*c1*e4 )/eden
2844 !!JOE-Canuto/Kitamura mod
2845 !!sh(k) = q3sq*a2*( e2+3.0*c1*e5c*gmel )/eden
2846 sh(k) = q3sq*(a2*a2fac)*( e2+3.0*c1*e5c*gmel )/eden
2847 ! sm(k) = Prnum*sh(k)
2848
2849 ! !or blend them:
2850 ! zi2 = MAX(zi, 300.)
2851 ! wt = .5*TANH((zw(k) - zi2)/200.) + .5
2852 ! sm(k) = sm_pbl*(1.-wt) + sm(k)*wt
2853 END IF !end Helfand & Labraga check
2854
2855 !Impose broad limits on Sh and Sm:
2856 gmelq = max(gmel/q3sq, 1e-8)
2857 sm25max = 4. !MIN(sm20*3.0, SQRT(.1936/gmelq))
2858 sh25max = 4. !MIN(sh20*3.0, 0.76*b2)
2859 sm25min = 0.0 !MAX(sm20*0.1, 1e-6)
2860 sh25min = 0.0 !MAX(sh20*0.1, 1e-6)
2861
2862 !JOE: Level 2.5 debug prints
2863 ! HL88 , lev2.5 criteria from eqs. 3.17, 3.19, & 3.20
2864 IF ( debug_code ) THEN
2865 IF ((sh(k)<sh25min .OR. sm(k)<sm25min .OR. &
2866 sh(k)>sh25max .OR. sm(k)>sm25max) ) THEN
2867 print*,"In mym_turbulence 2.5: k=",k
2868 print*," sm=",sm(k)," sh=",sh(k)
2869 print*," ri=",ri," Pr=",sm(k)/max(sh(k),1e-8)
2870 print*," gm=",gm(k)," gh=",gh(k)
2871 print*," q2sq=",q2sq," q3sq=",q3sq, q3sq/q2sq
2872 print*," qke=",qke(k)," el=",el(k)
2873 print*," PBLH=",zi," u=",u(k)," v=",v(k)
2874 print*," SMnum=",q3sq*a1*( e3-3.0*c1*e4)," SMdenom=",eden
2875 print*," SHnum=",q3sq*(a2*a2fac)*( e2+3.0*c1*e5c*gmel ),&
2876 " SHdenom=",eden
2877 ENDIF
2878 ENDIF
2879
2880 !Enforce constraints for level 2.5 functions
2881 IF ( sh(k) > sh25max ) sh(k) = sh25max
2882 IF ( sh(k) < sh25min ) sh(k) = sh25min
2883 !IF ( sm(k) > sm25max ) sm(k) = sm25max
2884 !IF ( sm(k) < sm25min ) sm(k) = sm25min
2885 !sm(k) = Prnum*sh(k)
2886
2887 !surface layer PR
2888 !slht = zi*0.1
2889 !wtpr = min( max( (slht - zw(k))/slht, 0.0), 1.0) ! 1 at z=0, 0 above sfc layer
2890 !Prlim = 1.0*wtpr + (1.0 - wtpr)*Prlimit
2891 !Prlim = 2.0*wtpr + (1.0 - wtpr)*Prlimit
2892 !sm(k) = MIN(sm(k), Prlim*Sh(k))
2893 !Pending more testing, keep same Pr limit in sfc layer
2894 shb = max(sh(k), 0.002)
2895 sm(k) = min(sm(k), prlimit*shb)
2896
2897! ** Level 3 : start **
2898 IF ( closure .GE. 3.0 ) THEN
2899 t2sq = qdiv*b2*elsq*sh(k)*dtl(k)**2
2900 r2sq = qdiv*b2*elsq*sh(k)*dqw(k)**2
2901 c2sq = qdiv*b2*elsq*sh(k)*dtl(k)*dqw(k)
2902 t3sq = max( tsq(k)*abk+tsq(k-1)*afk, 0.0 )
2903 r3sq = max( qsq(k)*abk+qsq(k-1)*afk, 0.0 )
2904 c3sq = cov(k)*abk+cov(k-1)*afk
2905
2906! Modified: Dec/22/2005, from here
2907 c3sq = sign( min( abs(c3sq), sqrt(t3sq*r3sq) ), c3sq )
2908!
2909 vtt = 1.0 +vt(k)*abk +vt(k-1)*afk
2910 vqq = tv0 +vq(k)*abk +vq(k-1)*afk
2911
2912 t2sq = vtt*t2sq +vqq*c2sq
2913 r2sq = vtt*c2sq +vqq*r2sq
2914 c2sq = max( vtt*t2sq+vqq*r2sq, 0.0d0 )
2915 t3sq = vtt*t3sq +vqq*c3sq
2916 r3sq = vtt*c3sq +vqq*r3sq
2917 c3sq = max( vtt*t3sq+vqq*r3sq, 0.0d0 )
2918!
2919 cw25 = e1*( e2 + 3.0*c1*e5c*gmel*qdiv**2 )/( 3.0*eden )
2920!
2921! ** Limitation on q, instead of L/q **
2922 dlsq = elsq
2923 IF ( q3sq/dlsq .LT. -gh(k) ) q3sq = -dlsq*gh(k)
2924!
2925! ** Limitation on c3sq (0.12 =< cw =< 0.76) **
2926 ! Use Janjic's (2001; p 13-17) methodology (eqs 4.11-414 and 5.7-5.10)
2927 ! to calculate an exact limit for c3sq:
2928 auh = 27.*a1*((a2*a2fac)**2)*b2*(gtr)**2
2929 aum = 54.*(a1**2)*(a2*a2fac)*b2*c1*(gtr)
2930 adh = 9.*a1*((a2*a2fac)**2)*(12.*a1 + 3.*b2)*(gtr)**2
2931 adm = 18.*(a1**2)*(a2*a2fac)*(b2 - 3.*(a2*a2fac))*(gtr)
2932
2933 aeh = (9.*a1*((a2*a2fac)**2)*b1 +9.*a1*((a2*a2fac)**2)* &
2934 (12.*a1 + 3.*b2))*(gtr)
2935 aem = 3.*a1*(a2*a2fac)*b1*(3.*(a2*a2fac) + 3.*b2*c1 + &
2936 (18.*a1*c1 - b2)) + &
2937 (18.)*(a1**2)*(a2*a2fac)*(b2 - 3.*(a2*a2fac))
2938
2939 req = -aeh/aem
2940 rsl = (auh + aum*req)/(3.*adh + 3.*adm*req)
2941 !For now, use default values, since tests showed little/no sensitivity
2942 rsl = .12 !lower limit
2943 rsl2= 1.0 - 2.*rsl !upper limit
2944 !IF (k==2)print*,"Dynamic limit RSL=",Rsl
2945 !IF (Rsl < 0.10 .OR. Rsl > 0.18) THEN
2946 ! print*,'--- ERROR: MYNN: Dynamic Cw '// &
2947 ! 'limit exceeds reasonable limits'
2948 ! print*," MYNN: Dynamic Cw limit needs attention=",Rsl
2949 !ENDIF
2950
2951 !JOE-Canuto/Kitamura mod
2952 !e2 = q3sq - e2c*ghel * qdiv**2
2953 !e3 = q3sq + e3c*ghel * qdiv**2
2954 !e4 = q3sq - e4c*ghel * qdiv**2
2955 e2 = q3sq - e2c*ghel*a2fac * qdiv**2
2956 e3 = q3sq + e3c*ghel*a2fac**2 * qdiv**2
2957 e4 = q3sq - e4c*ghel*a2fac * qdiv**2
2958 eden = e2*e4 + e3 *e5c*gmel * qdiv**2
2959
2960 !JOE-Canuto/Kitamura mod
2961 !wden = cc3*gtr**2 * dlsq**2/elsq * qdiv**2 &
2962 ! & *( e2*e4c - e3c*e5c*gmel * qdiv**2 )
2963 wden = cc3*gtr**2 * dlsq**2/elsq * qdiv**2 &
2964 & *( e2*e4c*a2fac - e3c*e5c*gmel*a2fac**2 * qdiv**2 )
2965
2966 IF ( wden .NE. 0.0 ) THEN
2967 !JOE: test dynamic limits
2968 clow = q3sq*( 0.12-cw25 )*eden/wden
2969 cupp = q3sq*( 0.76-cw25 )*eden/wden
2970 !clow = q3sq*( Rsl -cw25 )*eden/wden
2971 !cupp = q3sq*( Rsl2-cw25 )*eden/wden
2972!
2973 IF ( wden .GT. 0.0 ) THEN
2974 c3sq = min( max( c3sq, c2sq+clow ), c2sq+cupp )
2975 ELSE
2976 c3sq = max( min( c3sq, c2sq+clow ), c2sq+cupp )
2977 END IF
2978 END IF
2979!
2980 e1 = e2 + e5c*gmel * qdiv**2
2981 eden = max( eden, 1.0d-20 )
2982! Modified: Dec/22/2005, up to here
2983
2984 !JOE-Canuto/Kitamura mod
2985 !e6c = 3.0*a2*cc3*gtr * dlsq/elsq
2986 e6c = 3.0*(a2*a2fac)*cc3*gtr * dlsq/elsq
2987
2988 !============================
2989 ! ** for Gamma_theta **
2990 !! enum = qdiv*e6c*( t3sq-t2sq )
2991 IF ( t2sq .GE. 0.0 ) THEN
2992 enum = max( qdiv*e6c*( t3sq-t2sq ), 0.0d0 )
2993 ELSE
2994 enum = min( qdiv*e6c*( t3sq-t2sq ), 0.0d0 )
2995 ENDIF
2996 gamt =-e1 *enum /eden
2997
2998 !============================
2999 ! ** for Gamma_q **
3000 !! enum = qdiv*e6c*( r3sq-r2sq )
3001 IF ( r2sq .GE. 0.0 ) THEN
3002 enum = max( qdiv*e6c*( r3sq-r2sq ), 0.0d0 )
3003 ELSE
3004 enum = min( qdiv*e6c*( r3sq-r2sq ), 0.0d0 )
3005 ENDIF
3006 gamq =-e1 *enum /eden
3007
3008 !============================
3009 ! ** for Sm' and Sh'd(Theta_V)/dz **
3010 !! enum = qdiv*e6c*( c3sq-c2sq )
3011 enum = max( qdiv*e6c*( c3sq-c2sq ), 0.0d0)
3012
3013 !JOE-Canuto/Kitamura mod
3014 !smd = dlsq*enum*gtr/eden * qdiv**2 * (e3c+e4c)*a1/a2
3015 smd = dlsq*enum*gtr/eden * qdiv**2 * (e3c*a2fac**2 + &
3016 & e4c*a2fac)*a1/(a2*a2fac)
3017
3018 gamv = e1 *enum*gtr/eden
3019 sm(k) = sm(k) +smd
3020
3021 !============================
3022 ! ** For elh (see below), qdiv at Level 3 is reset to 1.0. **
3023 qdiv = 1.0
3024
3025 ! Level 3 debug prints
3026 IF ( debug_code ) THEN
3027 IF (sh(k)<-0.3 .OR. sm(k)<-0.3 .OR. &
3028 qke(k) < -0.1 .or. abs(smd) .gt. 2.0) THEN
3029 print*," MYNN; mym_turbulence3.0; sh=",sh(k)," k=",k
3030 print*," gm=",gm(k)," gh=",gh(k)," sm=",sm(k)
3031 print*," q2sq=",q2sq," q3sq=",q3sq," q3/q2=",q3sq/q2sq
3032 print*," qke=",qke(k)," el=",el(k)," ri=",ri
3033 print*," PBLH=",zi," u=",u(k)," v=",v(k)
3034 ENDIF
3035 ENDIF
3036
3037! ** Level 3 : end **
3038
3039 ELSE
3040! ** At Level 2.5, qdiv is not reset. **
3041 gamt = 0.0
3042 gamq = 0.0
3043 gamv = 0.0
3044 END IF
3045!
3046! Add min background stability function (diffusivity) within model levels
3047! with active plumes and clouds.
3048 cldavg = 0.5*(cldfra_bl1d(k-1) + cldfra_bl1d(k))
3049 IF (edmf_a1(k) > 0.001 .OR. cldavg > 0.02) THEN
3050 ! for mass-flux columns
3051 sm(k) = max(sm(k), 0.03*min(10.*edmf_a1(k)*edmf_w1(k),1.0) )
3052 sh(k) = max(sh(k), 0.03*min(10.*edmf_a1(k)*edmf_w1(k),1.0) )
3053 ! for clouds
3054 sm(k) = max(sm(k), 0.05*min(cldavg,1.0) )
3055 sh(k) = max(sh(k), 0.05*min(cldavg,1.0) )
3056 ENDIF
3057!
3058 elq = el(k)*qkw(k)
3059 elh = elq*qdiv
3060
3061 ! Production of TKE (pdk), T-variance (pdt),
3062 ! q-variance (pdq), and covariance (pdc)
3063 pdk(k) = elq*( sm(k)*gm(k) &
3064 & +sh(k)*gh(k)+gamv ) + &
3065 & 0.5*tkeprodtd(k) ! xmchen
3066 pdt(k) = elh*( sh(k)*dtl(k)+gamt )*dtl(k)
3067 pdq(k) = elh*( sh(k)*dqw(k)+gamq )*dqw(k)
3068 pdc(k) = elh*( sh(k)*dtl(k)+gamt ) &
3069 & *dqw(k)*0.5 &
3070 & + elh*( sh(k)*dqw(k)+gamq )*dtl(k)*0.5
3071
3072 ! Contergradient terms
3073 tcd(k) = elq*gamt
3074 qcd(k) = elq*gamq
3075
3076 ! Eddy Diffusivity/Viscosity divided by dz
3077 dfm(k) = elq*sm(k) / dzk
3078 dfh(k) = elq*sh(k) / dzk
3079! Modified: Dec/22/2005, from here
3080! ** In sub.mym_predict, dfq for the TKE and scalar variance **
3081! ** are set to 3.0*dfm and 1.0*dfm, respectively. (Sqfac) **
3082 dfq(k) = dfm(k)
3083! Modified: Dec/22/2005, up to here
3084
3085 IF (tke_budget .eq. 1) THEN
3086 !TKE BUDGET
3087! dudz = ( u(k)-u(k-1) )/dzk
3088! dvdz = ( v(k)-v(k-1) )/dzk
3089! dTdz = ( thl(k)-thl(k-1) )/dzk
3090
3091! upwp = -elq*sm(k)*dudz
3092! vpwp = -elq*sm(k)*dvdz
3093! Tpwp = -elq*sh(k)*dTdz
3094! Tpwp = SIGN(MAX(ABS(Tpwp),1.E-6),Tpwp)
3095
3096
3097!! TKE budget (Puhales, 2020, WRF 4.2.1) << EOB
3098
3099 !!!Shear Term
3100 !!!qSHEAR1D(k)=-(upwp*dudz + vpwp*dvdz)
3101 qshear1d(k) = elq*sm(k)*gm(k) !staggered
3102
3103 !!!Buoyancy Term
3104 !!!qBUOY1D(k)=grav*Tpwp/thl(k)
3105 !qBUOY1D(k)= elq*(sh(k)*gh(k) + gamv)
3106 !qBUOY1D(k) = elq*(sh(k)*(-dTdz*grav/thl(k)) + gamv) !! ORIGINAL CODE
3107
3108 !! Buoyncy term takes the TKEprodTD(k) production now
3109 qbuoy1d(k) = elq*(sh(k)*gh(k)+gamv)+0.5*tkeprodtd(k) ! xmchen
3110
3111 !!!Dissipation Term (now it evaluated in mym_predict)
3112 !qDISS1D(k) = (q3sq**(3./2.))/(b1*MAX(el(k),1.)) !! ORIGINAL CODE
3113
3114 !! >> EOB
3115 ENDIF
3116
3117 END DO
3118!
3119
3120 dfm(kts) = 0.0
3121 dfh(kts) = 0.0
3122 dfq(kts) = 0.0
3123 tcd(kts) = 0.0
3124 qcd(kts) = 0.0
3125
3126 tcd(kte) = 0.0
3127 qcd(kte) = 0.0
3128
3129!
3130 DO k = kts,kte-1
3131 dzk = dz(k)
3132 tcd(k) = ( tcd(k+1)-tcd(k) )/( dzk )
3133 qcd(k) = ( qcd(k+1)-qcd(k) )/( dzk )
3134 END DO
3135!
3136 if (spp_pbl==1) then
3137 DO k = kts,kte
3138 dfm(k)= dfm(k) + dfm(k)* rstoch_col(k) * 1.5 * max(exp(-max(zw(k)-8000.,0.0)/2000.),0.001)
3139 dfh(k)= dfh(k) + dfh(k)* rstoch_col(k) * 1.5 * max(exp(-max(zw(k)-8000.,0.0)/2000.),0.001)
3140 END DO
3141 endif
3142
3143! RETURN
3144#ifdef HARDCODE_VERTICAL
3145# undef kts
3146# undef kte
3147#endif
3148
3149 END SUBROUTINE mym_turbulence
3150
3151! ==================================================================
3152! SUBROUTINE mym_predict:
3153!
3154! Input variables: see subroutine mym_initialize and turbulence
3155! qke(nx,nz,ny) : qke at (n)th time level
3156! tsq, ...cov : ditto
3157!
3158! Output variables:
3159! qke(nx,nz,ny) : qke at (n+1)th time level
3160! tsq, ...cov : ditto
3161!
3162! Work arrays:
3163! qkw(nx,nz,ny) : q at the center of the grid boxes (m/s)
3164! bp (nx,nz,ny) : = 1/2*F, see below
3165! rp (nx,nz,ny) : = P-1/2*F*Q, see below
3166!
3167! # The equation for a turbulent quantity Q can be expressed as
3168! dQ/dt + Ah + Av = Dh + Dv + P - F*Q, (1)
3169! where A is the advection, D the diffusion, P the production,
3170! F*Q the dissipation and h and v denote horizontal and vertical,
3171! respectively. If Q is q^2, F is 2q/B_1L.
3172! Using the Crank-Nicholson scheme for Av, Dv and F*Q, a finite
3173! difference equation is written as
3174! Q{n+1} - Q{n} = dt *( Dh{n} - Ah{n} + P{n} )
3175! + dt/2*( Dv{n} - Av{n} - F*Q{n} )
3176! + dt/2*( Dv{n+1} - Av{n+1} - F*Q{n+1} ), (2)
3177! where n denotes the time level.
3178! When the advection and diffusion terms are discretized as
3179! dt/2*( Dv - Av ) = a(k)Q(k+1) - b(k)Q(k) + c(k)Q(k-1), (3)
3180! Eq.(2) can be rewritten as
3181! - a(k)Q(k+1) + [ 1 + b(k) + dt/2*F ]Q(k) - c(k)Q(k-1)
3182! = Q{n} + dt *( Dh{n} - Ah{n} + P{n} )
3183! + dt/2*( Dv{n} - Av{n} - F*Q{n} ), (4)
3184! where Q on the left-hand side is at (n+1)th time level.
3185!
3186! In this subroutine, a(k), b(k) and c(k) are obtained from
3187! subprogram coefvu and are passed to subprogram tinteg via
3188! common. 1/2*F and P-1/2*F*Q are stored in bp and rp,
3189! respectively. Subprogram tinteg solves Eq.(4).
3190!
3191! Modify this subroutine according to your numerical integration
3192! scheme (program).
3193!
3194!-------------------------------------------------------------------
3197 SUBROUTINE mym_predict (kts,kte, &
3198 & closure, &
3199 & delt, &
3200 & dz, &
3201 & ust, flt, flq, pmz, phh, &
3202 & el, dfq, rho, &
3203 & pdk, pdt, pdq, pdc, &
3204 & qke, tsq, qsq, cov, &
3205 & s_aw,s_awqke,bl_mynn_edmf_tke, &
3206 & qWT1D, qDISS1D,tke_budget) !! TKE budget (Puhales, 2020)
3207
3208!-------------------------------------------------------------------
3209 integer, intent(in) :: kts,kte
3210
3211#ifdef HARDCODE_VERTICAL
3212# define kts 1
3213# define kte HARDCODE_VERTICAL
3214#endif
3215
3216 real(kind_phys), intent(in) :: closure
3217 integer, intent(in) :: bl_mynn_edmf_tke,tke_budget
3218 real(kind_phys), dimension(kts:kte), intent(in) :: dz, dfq, el, rho
3219 real(kind_phys), dimension(kts:kte), intent(inout) :: pdk, pdt, pdq, pdc
3220 real(kind_phys), intent(in) :: flt, flq, pmz, phh
3221 real(kind_phys), intent(in) :: ust, delt
3222 real(kind_phys), dimension(kts:kte), intent(inout) :: qke,tsq, qsq, cov
3223! WA 8/3/15
3224 real(kind_phys), dimension(kts:kte+1), intent(inout) :: s_awqke,s_aw
3225
3226 !! TKE budget (Puhales, 2020, WRF 4.2.1) << EOB
3227 real(kind_phys), dimension(kts:kte), intent(out) :: qWT1D, qDISS1D
3228 real(kind_phys), dimension(kts:kte) :: tke_up,dzinv
3229 !! >> EOB
3230
3231 integer :: k
3232 real(kind_phys), dimension(kts:kte) :: qkw, bp, rp, df3q
3233 real(kind_phys):: vkz,pdk1,phm,pdt1,pdq1,pdc1,b1l,b2l,onoff
3234 real(kind_phys), dimension(kts:kte) :: dtz
3235 real(kind_phys), dimension(kts:kte) :: a,b,c,d,x
3236
3237 real(kind_phys), dimension(kts:kte) :: rhoinv
3238 real(kind_phys), dimension(kts:kte+1) :: rhoz,kqdz,kmdz
3239
3240 ! REGULATE THE MOMENTUM MIXING FROM THE MASS-FLUX SCHEME (on or off)
3241 IF (bl_mynn_edmf_tke == 0) THEN
3242 onoff=0.0
3243 ELSE
3244 onoff=1.0
3245 ENDIF
3246
3247! ** Strictly, vkz*h(i,j) -> karman*( 0.5*dz(1)*h(i,j)+z0 ) **
3248 vkz = karman*0.5*dz(kts)
3249!
3250! ** dfq for the TKE is 3.0*dfm. **
3251!
3252 DO k = kts,kte
3253!! qke(k) = MAX(qke(k), 0.0)
3254 qkw(k) = sqrt( max( qke(k), 0.0 ) )
3255 df3q(k)=sqfac*dfq(k)
3256 dtz(k)=delt/dz(k)
3257 END DO
3258!
3259!JOE-add conservation + stability criteria
3260 !Prepare "constants" for diffusion equation.
3261 !khdz = rho*Kh/dz = rho*dfh
3262 rhoz(kts) =rho(kts)
3263 rhoinv(kts)=1./rho(kts)
3264 kqdz(kts) =rhoz(kts)*df3q(kts)
3265 kmdz(kts) =rhoz(kts)*dfq(kts)
3266 DO k=kts+1,kte
3267 rhoz(k) =(rho(k)*dz(k-1) + rho(k-1)*dz(k))/(dz(k-1)+dz(k))
3268 rhoz(k) = max(rhoz(k),1e-4)
3269 rhoinv(k)=1./max(rho(k),1e-4)
3270 kqdz(k) = rhoz(k)*df3q(k) ! for TKE
3271 kmdz(k) = rhoz(k)*dfq(k) ! for T'2, q'2, and T'q'
3272 ENDDO
3273 rhoz(kte+1)=rhoz(kte)
3274 kqdz(kte+1)=rhoz(kte+1)*df3q(kte)
3275 kmdz(kte+1)=rhoz(kte+1)*dfq(kte)
3276
3277 !stability criteria for mf
3278 DO k=kts+1,kte-1
3279 kqdz(k) = max(kqdz(k), 0.5* s_aw(k))
3280 kqdz(k) = max(kqdz(k), -0.5*(s_aw(k)-s_aw(k+1)))
3281 kmdz(k) = max(kmdz(k), 0.5* s_aw(k))
3282 kmdz(k) = max(kmdz(k), -0.5*(s_aw(k)-s_aw(k+1)))
3283 ENDDO
3284 !end conservation mods
3285
3286 pdk1 = 2.0*ust**3*pmz/( vkz )
3287 phm = 2.0/ust *phh/( vkz )
3288 pdt1 = phm*flt**2
3289 pdq1 = phm*flq**2
3290 pdc1 = phm*flt*flq
3291!
3292! ** pdk(1)+pdk(2) corresponds to pdk1. **
3293 pdk(kts) = pdk1 - pdk(kts+1)
3294
3295!! pdt(kts) = pdt1 -pdt(kts+1)
3296!! pdq(kts) = pdq1 -pdq(kts+1)
3297!! pdc(kts) = pdc1 -pdc(kts+1)
3298 pdt(kts) = pdt(kts+1)
3299 pdq(kts) = pdq(kts+1)
3300 pdc(kts) = pdc(kts+1)
3301!
3302! ** Prediction of twice the turbulent kinetic energy **
3303!! DO k = kts+1,kte-1
3304 DO k = kts,kte-1
3305 b1l = b1*0.5*( el(k+1)+el(k) )
3306 bp(k) = 2.*qkw(k) / b1l
3307 rp(k) = pdk(k+1) + pdk(k)
3308 END DO
3309
3310!! a(1)=0.
3311!! b(1)=1.
3312!! c(1)=-1.
3313!! d(1)=0.
3314
3315! Since df3q(kts)=0.0, a(1)=0.0 and b(1)=1.+dtz(k)*df3q(k+1)+bp(k)*delt.
3316 DO k=kts,kte-1
3317! a(k-kts+1)=-dtz(k)*df3q(k)
3318! b(k-kts+1)=1.+dtz(k)*(df3q(k)+df3q(k+1))+bp(k)*delt
3319! c(k-kts+1)=-dtz(k)*df3q(k+1)
3320! d(k-kts+1)=rp(k)*delt + qke(k)
3321! WA 8/3/15 add EDMF contribution
3322! a(k)= - dtz(k)*df3q(k) + 0.5*dtz(k)*s_aw(k)*onoff
3323! b(k)=1. + dtz(k)*(df3q(k)+df3q(k+1)) &
3324! + 0.5*dtz(k)*(s_aw(k)-s_aw(k+1))*onoff + bp(k)*delt
3325! c(k)= - dtz(k)*df3q(k+1) - 0.5*dtz(k)*s_aw(k+1)*onoff
3326! d(k)=rp(k)*delt + qke(k) + dtz(k)*(s_awqke(k)-s_awqke(k+1))*onoff
3327!JOE 8/22/20 improve conservation
3328 a(k)= - dtz(k)*kqdz(k)*rhoinv(k) &
3329 & + 0.5*dtz(k)*rhoinv(k)*s_aw(k)*onoff
3330 b(k)=1. + dtz(k)*(kqdz(k)+kqdz(k+1))*rhoinv(k) &
3331 & + 0.5*dtz(k)*rhoinv(k)*(s_aw(k)-s_aw(k+1))*onoff &
3332 & + bp(k)*delt
3333 c(k)= - dtz(k)*kqdz(k+1)*rhoinv(k) &
3334 & - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1)*onoff
3335 d(k)=rp(k)*delt + qke(k) &
3336 & + dtz(k)*rhoinv(k)*(s_awqke(k)-s_awqke(k+1))*onoff
3337 ENDDO
3338
3339!! DO k=kts+1,kte-1
3340!! a(k-kts+1)=-dtz(k)*df3q(k)
3341!! b(k-kts+1)=1.+dtz(k)*(df3q(k)+df3q(k+1))
3342!! c(k-kts+1)=-dtz(k)*df3q(k+1)
3343!! d(k-kts+1)=rp(k)*delt + qke(k) - qke(k)*bp(k)*delt
3344!! ENDDO
3345
3346!! "no flux at top"
3347! a(kte)=-1. !0.
3348! b(kte)=1.
3349! c(kte)=0.
3350! d(kte)=0.
3351!! "prescribed value"
3352 a(kte)=0.
3353 b(kte)=1.
3354 c(kte)=0.
3355 d(kte)=qke(kte)
3356
3357! CALL tridiag(kte,a,b,c,d)
3358 CALL tridiag2(kte,a,b,c,d,x)
3359
3360 DO k=kts,kte
3361! qke(k)=max(d(k-kts+1), 1.e-4)
3362 qke(k)=max(x(k), 1.e-4)
3363 qke(k)=min(qke(k), 150.)
3364 ENDDO
3365
3366
3367!! TKE budget (Puhales, 2020, WRF 4.2.1) << EOB
3368 IF (tke_budget .eq. 1) THEN
3369 !! TKE Vertical transport << EOBvt
3370 tke_up=0.5*qke
3371 dzinv=1./dz
3372 k=kts
3373 qwt1d(k)=dzinv(k)*( &
3374 & (kqdz(k+1)*(tke_up(k+1)-tke_up(k))-kqdz(k)*tke_up(k)) &
3375 & + 0.5*rhoinv(k)*(s_aw(k+1)*tke_up(k+1) &
3376 & + (s_aw(k+1)-s_aw(k))*tke_up(k) &
3377 & + (s_awqke(k)-s_awqke(k+1)))*onoff) !unstaggered
3378 DO k=kts+1,kte-1
3379 qwt1d(k)=dzinv(k)*( &
3380 & (kqdz(k+1)*(tke_up(k+1)-tke_up(k))-kqdz(k)*(tke_up(k)-tke_up(k-1))) &
3381 & + 0.5*rhoinv(k)*(s_aw(k+1)*tke_up(k+1) &
3382 & + (s_aw(k+1)-s_aw(k))*tke_up(k) &
3383 & - s_aw(k)*tke_up(k-1) &
3384 & + (s_awqke(k)-s_awqke(k+1)))*onoff) !unstaggered
3385 ENDDO
3386 k=kte
3387 qwt1d(k)=dzinv(k)*(-kqdz(k)*(tke_up(k)-tke_up(k-1)) &
3388 & + 0.5*rhoinv(k)*(-s_aw(k)*tke_up(k)-s_aw(k)*tke_up(k-1)+s_awqke(k))*onoff) !unstaggered
3389 !! >> EOBvt
3390 qdiss1d=bp*tke_up !! TKE dissipation rate !unstaggered
3391 END IF
3392!! >> EOB
3393
3394 IF ( closure > 2.5 ) THEN
3395
3396 ! ** Prediction of the moisture variance **
3397 DO k = kts,kte-1
3398 b2l = b2*0.5*( el(k+1)+el(k) )
3399 bp(k) = 2.*qkw(k) / b2l
3400 rp(k) = pdq(k+1) + pdq(k)
3401 END DO
3402
3403 !zero gradient for qsq at bottom and top
3404 !a(1)=0.
3405 !b(1)=1.
3406 !c(1)=-1.
3407 !d(1)=0.
3408
3409 ! Since dfq(kts)=0.0, a(1)=0.0 and b(1)=1.+dtz(k)*dfq(k+1)+bp(k)*delt.
3410 DO k=kts,kte-1
3411 a(k)= - dtz(k)*kmdz(k)*rhoinv(k)
3412 b(k)=1. + dtz(k)*(kmdz(k)+kmdz(k+1))*rhoinv(k) + bp(k)*delt
3413 c(k)= - dtz(k)*kmdz(k+1)*rhoinv(k)
3414 d(k)=rp(k)*delt + qsq(k)
3415 ENDDO
3416
3417 a(kte)=-1. !0.
3418 b(kte)=1.
3419 c(kte)=0.
3420 d(kte)=0.
3421
3422! CALL tridiag(kte,a,b,c,d)
3423 CALL tridiag2(kte,a,b,c,d,x)
3424
3425 DO k=kts,kte
3426 !qsq(k)=d(k-kts+1)
3427 qsq(k)=max(x(k),1e-17)
3428 ENDDO
3429 ELSE
3430 !level 2.5 - use level 2 diagnostic
3431 DO k = kts,kte-1
3432 IF ( qkw(k) .LE. 0.0 ) THEN
3433 b2l = 0.0
3434 ELSE
3435 b2l = b2*0.25*( el(k+1)+el(k) )/qkw(k)
3436 END IF
3437 qsq(k) = b2l*( pdq(k+1)+pdq(k) )
3438 END DO
3439 qsq(kte)=qsq(kte-1)
3440 END IF
3441!!!!!!!!!!!!!!!!!!!!!!end level 2.6
3442
3443 IF ( closure .GE. 3.0 ) THEN
3444!
3445! ** dfq for the scalar variance is 1.0*dfm. **
3446!
3447! ** Prediction of the temperature variance **
3448!! DO k = kts+1,kte-1
3449 DO k = kts,kte-1
3450 b2l = b2*0.5*( el(k+1)+el(k) )
3451 bp(k) = 2.*qkw(k) / b2l
3452 rp(k) = pdt(k+1) + pdt(k)
3453 END DO
3454
3455!zero gradient for tsq at bottom and top
3456
3457!! a(1)=0.
3458!! b(1)=1.
3459!! c(1)=-1.
3460!! d(1)=0.
3461
3462! Since dfq(kts)=0.0, a(1)=0.0 and b(1)=1.+dtz(k)*dfq(k+1)+bp(k)*delt.
3463 DO k=kts,kte-1
3464 !a(k-kts+1)=-dtz(k)*dfq(k)
3465 !b(k-kts+1)=1.+dtz(k)*(dfq(k)+dfq(k+1))+bp(k)*delt
3466 !c(k-kts+1)=-dtz(k)*dfq(k+1)
3467 !d(k-kts+1)=rp(k)*delt + tsq(k)
3468!JOE 8/22/20 improve conservation
3469 a(k)= - dtz(k)*kmdz(k)*rhoinv(k)
3470 b(k)=1. + dtz(k)*(kmdz(k)+kmdz(k+1))*rhoinv(k) + bp(k)*delt
3471 c(k)= - dtz(k)*kmdz(k+1)*rhoinv(k)
3472 d(k)=rp(k)*delt + tsq(k)
3473 ENDDO
3474
3475!! DO k=kts+1,kte-1
3476!! a(k-kts+1)=-dtz(k)*dfq(k)
3477!! b(k-kts+1)=1.+dtz(k)*(dfq(k)+dfq(k+1))
3478!! c(k-kts+1)=-dtz(k)*dfq(k+1)
3479!! d(k-kts+1)=rp(k)*delt + tsq(k) - tsq(k)*bp(k)*delt
3480!! ENDDO
3481
3482 a(kte)=-1. !0.
3483 b(kte)=1.
3484 c(kte)=0.
3485 d(kte)=0.
3486
3487! CALL tridiag(kte,a,b,c,d)
3488 CALL tridiag2(kte,a,b,c,d,x)
3489
3490 DO k=kts,kte
3491! tsq(k)=d(k-kts+1)
3492 tsq(k)=x(k)
3493 ENDDO
3494
3495! ** Prediction of the temperature-moisture covariance **
3496!! DO k = kts+1,kte-1
3497 DO k = kts,kte-1
3498 b2l = b2*0.5*( el(k+1)+el(k) )
3499 bp(k) = 2.*qkw(k) / b2l
3500 rp(k) = pdc(k+1) + pdc(k)
3501 END DO
3502
3503!zero gradient for tqcov at bottom and top
3504
3505!! a(1)=0.
3506!! b(1)=1.
3507!! c(1)=-1.
3508!! d(1)=0.
3509
3510! Since dfq(kts)=0.0, a(1)=0.0 and b(1)=1.+dtz(k)*dfq(k+1)+bp(k)*delt.
3511 DO k=kts,kte-1
3512 !a(k-kts+1)=-dtz(k)*dfq(k)
3513 !b(k-kts+1)=1.+dtz(k)*(dfq(k)+dfq(k+1))+bp(k)*delt
3514 !c(k-kts+1)=-dtz(k)*dfq(k+1)
3515 !d(k-kts+1)=rp(k)*delt + cov(k)
3516!JOE 8/22/20 improve conservation
3517 a(k)= - dtz(k)*kmdz(k)*rhoinv(k)
3518 b(k)=1. + dtz(k)*(kmdz(k)+kmdz(k+1))*rhoinv(k) + bp(k)*delt
3519 c(k)= - dtz(k)*kmdz(k+1)*rhoinv(k)
3520 d(k)=rp(k)*delt + cov(k)
3521 ENDDO
3522
3523!! DO k=kts+1,kte-1
3524!! a(k-kts+1)=-dtz(k)*dfq(k)
3525!! b(k-kts+1)=1.+dtz(k)*(dfq(k)+dfq(k+1))
3526!! c(k-kts+1)=-dtz(k)*dfq(k+1)
3527!! d(k-kts+1)=rp(k)*delt + cov(k) - cov(k)*bp(k)*delt
3528!! ENDDO
3529
3530 a(kte)=-1. !0.
3531 b(kte)=1.
3532 c(kte)=0.
3533 d(kte)=0.
3534
3535! CALL tridiag(kte,a,b,c,d)
3536 CALL tridiag2(kte,a,b,c,d,x)
3537
3538 DO k=kts,kte
3539! cov(k)=d(k-kts+1)
3540 cov(k)=x(k)
3541 ENDDO
3542
3543 ELSE
3544
3545 !Not level 3 - default to level 2 diagnostic
3546 DO k = kts,kte-1
3547 IF ( qkw(k) .LE. 0.0 ) THEN
3548 b2l = 0.0
3549 ELSE
3550 b2l = b2*0.25*( el(k+1)+el(k) )/qkw(k)
3551 END IF
3552!
3553 tsq(k) = b2l*( pdt(k+1)+pdt(k) )
3554 cov(k) = b2l*( pdc(k+1)+pdc(k) )
3555 END DO
3556
3557 tsq(kte)=tsq(kte-1)
3558 cov(kte)=cov(kte-1)
3559
3560 END IF
3561
3562#ifdef HARDCODE_VERTICAL
3563# undef kts
3564# undef kte
3565#endif
3566
3567 END SUBROUTINE mym_predict
3568
3569! ==================================================================
3570! SUBROUTINE mym_condensation:
3571!
3572! Input variables: see subroutine mym_initialize and turbulence
3573! exner(nz) : Perturbation of the Exner function (J/kg K)
3574! defined on the walls of the grid boxes
3575! This is usually computed by integrating
3576! d(pi)/dz = h*g*tv/tref**2
3577! from the upper boundary, where tv is the
3578! virtual potential temperature minus tref.
3579!
3580! Output variables: see subroutine mym_initialize
3581! cld(nx,nz,ny) : Cloud fraction
3582!
3583! Work arrays/variables:
3584! qmq : Q_w-Q_{sl}, where Q_{sl} is the saturation
3585! specific humidity at T=Tl
3586! alp(nx,nz,ny) : Functions in the condensation process
3587! bet(nx,nz,ny) : ditto
3588! sgm(nx,nz,ny) : Combined standard deviation sigma_s
3589! multiplied by 2/alp
3590!
3591! # qmq, alp, bet and sgm are allowed to share storage units with
3592! any four of other work arrays for saving memory.
3593!
3594! # Results are sensitive particularly to values of cp and r_d.
3595! Set these values to those adopted by you.
3596!
3597!-------------------------------------------------------------------
3603 SUBROUTINE mym_condensation (kts,kte, &
3604 & dx, dz, zw, xland, &
3605 & thl, qw, qv, qc, qi, qs, &
3606 & p,exner, &
3607 & tsq, qsq, cov, &
3608 & Sh, el, bl_mynn_cloudpdf, &
3609 & qc_bl1D, qi_bl1D, &
3610 & cldfra_bl1D, &
3611 & PBLH1,HFX1, &
3612 & Vt, Vq, th, sgm, rmo, &
3613 & spp_pbl,rstoch_col )
3614
3615!-------------------------------------------------------------------
3616
3617 integer, intent(in) :: kts,kte, bl_mynn_cloudpdf
3618
3619#ifdef HARDCODE_VERTICAL
3620# define kts 1
3621# define kte HARDCODE_VERTICAL
3622#endif
3623
3624 real(kind_phys), intent(in) :: HFX1,rmo,xland
3625 real(kind_phys), intent(in) :: dx,pblh1
3626 real(kind_phys), dimension(kts:kte), intent(in) :: dz
3627 real(kind_phys), dimension(kts:kte+1), intent(in) :: zw
3628 real(kind_phys), dimension(kts:kte), intent(in) :: p,exner,thl,qw, &
3629 &qv,qc,qi,qs,tsq,qsq,cov,th
3630
3631 real(kind_phys), dimension(kts:kte), intent(inout) :: vt,vq,sgm
3632
3633 real(kind_phys), dimension(kts:kte) :: alp,a,bet,b,ql,q1,RH
3634 real(kind_phys), dimension(kts:kte), intent(out) :: qc_bl1D,qi_bl1D, &
3635 &cldfra_bl1D
3636 DOUBLE PRECISION :: t3sq, r3sq, c3sq
3637
3638 real(kind_phys):: qsl,esat,qsat,dqsl,cld0,q1k,qlk,eq1,qll, &
3639 &q2p,pt,rac,qt,t,xl,rsl,cpm,Fng,qww,alpha,beta,bb, &
3640 &ls,wt,wt2,qpct,cld_factor,fac_damp,liq_frac,ql_ice,ql_water, &
3641 &qmq,qsat_tk,q1_rh,rh_hack,dzm1,zsl,maxqc
3642 real(kind_phys), parameter :: qpct_sfc=0.025
3643 real(kind_phys), parameter :: qpct_pbl=0.030
3644 real(kind_phys), parameter :: qpct_trp=0.040
3645 real(kind_phys), parameter :: rhcrit =0.83 !for cloudpdf = 2
3646 real(kind_phys), parameter :: rhmax =1.02 !for cloudpdf = 2
3647 integer :: i,j,k
3648
3649 real(kind_phys):: erf
3650
3651 !VARIABLES FOR ALTERNATIVE SIGMA
3652 real:: dth,dtl,dqw,dzk,els
3653 real(kind_phys), dimension(kts:kte), intent(in) :: Sh,el
3654
3655 !variables for SGS BL clouds
3656 real(kind_phys) :: zagl,damp,PBLH2
3657 real(kind_phys) :: cfmax
3658
3659 !JAYMES: variables for tropopause-height estimation
3660 real(kind_phys) :: theta1, theta2, ht1, ht2
3661 integer :: k_tropo
3662
3663! Stochastic
3664 integer, intent(in) :: spp_pbl
3665 real(kind_phys), dimension(kts:kte) :: rstoch_col
3666 real(kind_phys) :: qw_pert
3667
3668! First, obtain an estimate for the tropopause height (k), using the method employed in the
3669! Thompson subgrid-cloud scheme. This height will be a consideration later when determining
3670! the "final" subgrid-cloud properties.
3671! JAYMES: added 3 Nov 2016, adapted from G. Thompson
3672
3673 DO k = kte-3, kts, -1
3674 theta1 = th(k)
3675 theta2 = th(k+2)
3676 ht1 = 44307.692 * (1.0 - (p(k)/101325.)**0.190)
3677 ht2 = 44307.692 * (1.0 - (p(k+2)/101325.)**0.190)
3678 if ( (((theta2-theta1)/(ht2-ht1)) .lt. 10./1500. ) .AND. &
3679 & (ht1.lt.19000.) .and. (ht1.gt.4000.) ) then
3680 goto 86
3681 endif
3682 ENDDO
3683 86 continue
3684 k_tropo = max(kts+2, k+2)
3685
3686 zagl = 0.
3687
3688 SELECT CASE(bl_mynn_cloudpdf)
3689
3690 CASE (0) ! ORIGINAL MYNN PARTIAL-CONDENSATION SCHEME
3691
3692 DO k = kts,kte-1
3693 t = th(k)*exner(k)
3694
3695!x if ( ct .gt. 0.0 ) then
3696! a = 17.27
3697! b = 237.3
3698!x else
3699!x a = 21.87
3700!x b = 265.5
3701!x end if
3702!
3703! ** 3.8 = 0.622*6.11 (hPa) **
3704
3705 !SATURATED VAPOR PRESSURE
3706 esat = esat_blend(t)
3707 !SATURATED SPECIFIC HUMIDITY
3708 !qsl=ep_2*esat/(p(k)-ep_3*esat)
3709 qsl=ep_2*esat/max(1.e-4,(p(k)-ep_3*esat))
3710 !dqw/dT: Clausius-Clapeyron
3711 dqsl = qsl*ep_2*xlv/( r_d*t**2 )
3712
3713 alp(k) = 1.0/( 1.0+dqsl*xlvcp )
3714 bet(k) = dqsl*exner(k)
3715
3716 !Sommeria and Deardorff (1977) scheme, as implemented
3717 !in Nakanishi and Niino (2009), Appendix B
3718 t3sq = max( tsq(k), 0.0 )
3719 r3sq = max( qsq(k), 0.0 )
3720 c3sq = cov(k)
3721 c3sq = sign( min( abs(c3sq), sqrt(t3sq*r3sq) ), c3sq )
3722 r3sq = r3sq +bet(k)**2*t3sq -2.0*bet(k)*c3sq
3723 !DEFICIT/EXCESS WATER CONTENT
3724 qmq = qw(k) -qsl
3725 !ORIGINAL STANDARD DEVIATION
3726 sgm(k) = sqrt( max( r3sq, 1.0d-10 ))
3727 !NORMALIZED DEPARTURE FROM SATURATION
3728 q1(k) = qmq / sgm(k)
3729 !CLOUD FRACTION. rr2 = 1/SQRT(2) = 0.707
3730 cldfra_bl1d(k) = 0.5*( 1.0+erf( q1(k)*rr2 ) )
3731
3732 q1k = q1(k)
3733 eq1 = rrp*exp( -0.5*q1k*q1k )
3734 qll = max( cldfra_bl1d(k)*q1k + eq1, 0.0 )
3735 !ESTIMATED LIQUID WATER CONTENT (UNNORMALIZED)
3736 ql(k) = alp(k)*sgm(k)*qll
3737 !LIMIT SPECIES TO TEMPERATURE RANGES
3738 liq_frac = min(1.0, max(0.0,(t-240.0)/29.0))
3739 qc_bl1d(k) = liq_frac*ql(k)
3740 qi_bl1d(k) = (1.0 - liq_frac)*ql(k)
3741
3742 !Now estimate the buoyancy flux functions
3743 q2p = xlvcp/exner(k)
3744 pt = thl(k) +q2p*ql(k) ! potential temp
3745
3746 !qt is a THETA-V CONVERSION FOR TOTAL WATER (i.e., THETA-V = qt*THETA)
3747 qt = 1.0 +p608*qw(k) -(1.+p608)*(qc_bl1d(k)+qi_bl1d(k))*cldfra_bl1d(k)
3748 rac = alp(k)*( cldfra_bl1d(k)-qll*eq1 )*( q2p*qt-(1.+p608)*pt )
3749
3750 !BUOYANCY FACTORS: wherever vt and vq are used, there is a
3751 !"+1" and "+tv0", respectively, so these are subtracted out here.
3752 !vt is unitless and vq has units of K.
3753 vt(k) = qt-1.0 -rac*bet(k)
3754 vq(k) = p608*pt-tv0 +rac
3755
3756 END DO
3757
3758 CASE (1, -1) !ALTERNATIVE FORM (Nakanishi & Niino 2004 BLM, eq. B6, and
3759 !Kuwano-Yoshida et al. 2010 QJRMS, eq. 7):
3760 DO k = kts,kte-1
3761 t = th(k)*exner(k)
3762 !SATURATED VAPOR PRESSURE
3763 esat = esat_blend(t)
3764 !SATURATED SPECIFIC HUMIDITY
3765 !qsl=ep_2*esat/(p(k)-ep_3*esat)
3766 qsl=ep_2*esat/max(1.e-4,(p(k)-ep_3*esat))
3767 !dqw/dT: Clausius-Clapeyron
3768 dqsl = qsl*ep_2*xlv/( r_d*t**2 )
3769
3770 alp(k) = 1.0/( 1.0+dqsl*xlvcp )
3771 bet(k) = dqsl*exner(k)
3772
3773 if (k .eq. kts) then
3774 dzk = 0.5*dz(k)
3775 else
3776 dzk = dz(k)
3777 end if
3778 dth = 0.5*(thl(k+1)+thl(k)) - 0.5*(thl(k)+thl(max(k-1,kts)))
3779 dqw = 0.5*(qw(k+1) + qw(k)) - 0.5*(qw(k) + qw(max(k-1,kts)))
3780 sgm(k) = sqrt( max( (alp(k)**2 * max(el(k)**2,0.1) * &
3781 b2 * max(sh(k),0.03))/4. * &
3782 (dqw/dzk - bet(k)*(dth/dzk ))**2 , 1.0e-10) )
3783 qmq = qw(k) -qsl
3784 q1(k) = qmq / sgm(k)
3785 cldfra_bl1d(k) = 0.5*( 1.0+erf( q1(k)*rr2 ) )
3786
3787 !now compute estimated lwc for PBL scheme's use
3788 !qll IS THE NORMALIZED LIQUID WATER CONTENT (Sommeria and
3789 !Deardorff (1977, eq 29a). rrp = 1/(sqrt(2*pi)) = 0.3989
3790 q1k = q1(k)
3791 eq1 = rrp*exp( -0.5*q1k*q1k )
3792 qll = max( cldfra_bl1d(k)*q1k + eq1, 0.0 )
3793 !ESTIMATED LIQUID WATER CONTENT (UNNORMALIZED)
3794 ql(k) = alp(k)*sgm(k)*qll
3795 liq_frac = min(1.0, max(0.0,(t-240.0)/29.0))
3796 qc_bl1d(k) = liq_frac*ql(k)
3797 qi_bl1d(k) = (1.0 - liq_frac)*ql(k)
3798
3799 !Now estimate the buoyancy flux functions
3800 q2p = xlvcp/exner(k)
3801 pt = thl(k) +q2p*ql(k) ! potential temp
3802
3803 !qt is a THETA-V CONVERSION FOR TOTAL WATER (i.e., THETA-V = qt*THETA)
3804 qt = 1.0 +p608*qw(k) -(1.+p608)*(qc_bl1d(k)+qi_bl1d(k))*cldfra_bl1d(k)
3805 rac = alp(k)*( cldfra_bl1d(k)-qll*eq1 )*( q2p*qt-(1.+p608)*pt )
3806
3807 !BUOYANCY FACTORS: wherever vt and vq are used, there is a
3808 !"+1" and "+tv0", respectively, so these are subtracted out here.
3809 !vt is unitless and vq has units of K.
3810 vt(k) = qt-1.0 -rac*bet(k)
3811 vq(k) = p608*pt-tv0 +rac
3812
3813 END DO
3814
3815 CASE (2, -2)
3816
3817 !Diagnostic statistical scheme of Chaboureau and Bechtold (2002), JAS
3818 !but with use of higher-order moments to estimate sigma
3819 pblh2=max(10._kind_phys,pblh1)
3820 zagl = 0.
3821 dzm1 = 0.
3822 DO k = kts,kte-1
3823 zagl = zagl + 0.5*(dz(k) + dzm1)
3824 dzm1 = dz(k)
3825
3826 t = th(k)*exner(k)
3827 xl = xl_blend(t) ! obtain latent heat
3828 qsat_tk= qsat_blend(t, p(k)) ! saturation water vapor mixing ratio at tk and p
3829 rh(k) = max(min(rhmax, qw(k)/max(1.e-10,qsat_tk)),0.001_kind_phys)
3830
3831 !dqw/dT: Clausius-Clapeyron
3832 dqsl = qsat_tk*ep_2*xlv/( r_d*t**2 )
3833 alp(k) = 1.0/( 1.0+dqsl*xlvcp )
3834 bet(k) = dqsl*exner(k)
3835
3836 rsl = xl*qsat_tk / (r_v*t**2) ! slope of C-C curve at t (=abs temperature)
3837 ! CB02, Eqn. 4
3838 cpm = cp + qw(k)*cpv ! CB02, sec. 2, para. 1
3839 a(k) = 1./(1. + xl*rsl/cpm) ! CB02 variable "a"
3840 b(k) = a(k)*rsl ! CB02 variable "b"
3841
3842 !SPP
3843 qw_pert= qw(k) + qw(k)*0.5*rstoch_col(k)*real(spp_pbl)
3844
3845 !This form of qmq (the numerator of Q1) no longer uses the a(k) factor
3846 qmq = qw_pert - qsat_tk ! saturation deficit/excess;
3847
3848 !Use the form of Eq. (6) in Chaboureau and Bechtold (2002)
3849 !except neglect all but the first term for sig_r
3850 r3sq = max( qsq(k), 0.0 )
3851 !Calculate sigma using higher-order moments:
3852 sgm(k) = sqrt( r3sq )
3853 !Set constraints on sigma relative to saturation water vapor
3854 sgm(k) = min( sgm(k), qsat_tk*0.666 )
3855 !sgm(k) = max( sgm(k), qsat_tk*0.035 )
3856
3857 !introduce vertical grid spacing dependence on min sgm
3858 wt = max(500. - max(dz(k)-100.,0.0), 0.0_kind_phys)/500. !=1 for dz < 100 m, =0 for dz > 600 m
3859 sgm(k) = sgm(k) + sgm(k)*0.2*(1.0-wt) !inflate sgm for coarse dz
3860
3861 !allow min sgm to vary with dz and z.
3862 qpct = qpct_pbl*wt + qpct_trp*(1.0-wt)
3863 qpct = min(qpct, max(qpct_sfc, qpct_pbl*zagl/500.) )
3864 sgm(k) = max( sgm(k), qsat_tk*qpct )
3865
3866 q1(k) = qmq / sgm(k) ! Q1, the normalized saturation
3867
3868 !Add condition for falling/settling into low-RH layers, so at least
3869 !some cloud fraction is applied for all qc, qs, and qi.
3870 rh_hack= rh(k)
3871 wt2 = min(max( zagl - pblh2, 0.0 )/300., 1.0)
3872 !ensure adequate RH & q1 when qi is at least 1e-9 (above the PBLH)
3873 if ((qi(k)+qs(k))>1.e-9 .and. (zagl .gt. pblh2)) then
3874 rh_hack =min(rhmax, rhcrit + wt2*0.045*(9.0 + log10(qi(k)+qs(k))))
3875 rh(k) =max(rh(k), rh_hack)
3876 !add rh-based q1
3877 q1_rh =-3. + 3.*(rh(k)-rhcrit)/(1.-rhcrit)
3878 q1(k) =max(q1_rh, q1(k) )
3879 endif
3880 !ensure adequate rh & q1 when qc is at least 1e-6 (above the PBLH)
3881 if (qc(k)>1.e-6 .and. (zagl .gt. pblh2)) then
3882 rh_hack =min(rhmax, rhcrit + wt2*0.08*(6.0 + log10(qc(k))))
3883 rh(k) =max(rh(k), rh_hack)
3884 !add rh-based q1
3885 q1_rh =-3. + 3.*(rh(k)-rhcrit)/(1.-rhcrit)
3886 q1(k) =max(q1_rh, q1(k) )
3887 endif
3888
3889 q1k = q1(k) ! backup Q1 for later modification
3890
3891 ! Specify cloud fraction
3892 !Original C-B cloud fraction, allows cloud fractions out to q1 = -3.5
3893 !cldfra_bl1D(K) = max(0., min(1., 0.5+0.36*atan(1.55*q1(k)))) ! Eq. 7 in CB02
3894 !Waynes LES fit - over-diffuse, when limits removed from vt & vq & fng
3895 !cldfra_bl1D(K) = max(0., min(1., 0.5+0.36*atan(1.2*(q1(k)+0.4))))
3896 !Best compromise: Improves marine stratus without adding much cold bias.
3897 cldfra_bl1d(k) = max(0., min(1., 0.5+0.36*atan(1.8*(q1(k)+0.2))))
3898
3899 ! Specify hydrometeors
3900 ! JAYMES- this option added 8 May 2015
3901 ! The cloud water formulations are taken from CB02, Eq. 8.
3902 maxqc = max(qw(k) - qsat_tk, 0.0)
3903 if (q1k < 0.) then !unsaturated
3904 ql_water = sgm(k)*exp(1.2*q1k-1.)
3905 ql_ice = sgm(k)*exp(1.2*q1k-1.)
3906 elseif (q1k > 2.) then !supersaturated
3907 ql_water = min(sgm(k)*q1k, maxqc)
3908 ql_ice = sgm(k)*q1k
3909 else !slightly saturated (0 > q1 < 2)
3910 ql_water = min(sgm(k)*(exp(-1.) + 0.66*q1k + 0.086*q1k**2), maxqc)
3911 ql_ice = sgm(k)*(exp(-1.) + 0.66*q1k + 0.086*q1k**2)
3912 endif
3913
3914 !In saturated grid cells, use average of SGS and resolved values
3915 !if ( qc(k) > 1.e-6 ) ql_water = 0.5 * ( ql_water + qc(k) )
3916 !ql_ice is actually the total frozen condensate (snow+ice),
3917 !if ( (qi(k)+qs(k)) > 1.e-9 ) ql_ice = 0.5 * ( ql_ice + (qi(k)+qs(k)) )
3918
3919 if (cldfra_bl1d(k) < 0.001) then
3920 ql_ice = 0.0
3921 ql_water = 0.0
3922 cldfra_bl1d(k) = 0.0
3923 endif
3924
3925 liq_frac = min(1.0, max(0.0, (t-tice)/(tliq-tice)))
3926 qc_bl1d(k) = liq_frac*ql_water ! apply liq_frac to ql_water and ql_ice
3927 qi_bl1d(k) = (1.0-liq_frac)*ql_ice
3928
3929 !Above tropopause: eliminate subgrid clouds from CB scheme. Note that this was
3930 !"k_tropo - 1" as of 20 Feb 2023. Changed to allow more high-level clouds.
3931 if (k .ge. k_tropo) then
3932 cldfra_bl1d(k) = 0.
3933 qc_bl1d(k) = 0.
3934 qi_bl1d(k) = 0.
3935 endif
3936
3937 !Buoyancy-flux-related calculations follow...
3938 !limiting Q1 to avoid too much diffusion in cloud layers
3939 !q1k=max(Q1(k),-2.0)
3940 if ((xland-1.5).GE.0) then ! water
3941 q1k=max(q1(k),-2.5)
3942 else ! land
3943 q1k=max(q1(k),-2.0)
3944 endif
3945 ! "Fng" represents the non-Gaussian transport factor
3946 ! (non-dimensional) from Bechtold et al. 1995
3947 ! (hereafter BCMT95), section 3(c). Their suggested
3948 ! forms for Fng (from their Eq. 20) are:
3949 !IF (q1k < -2.) THEN
3950 ! Fng = 2.-q1k
3951 !ELSE IF (q1k > 0.) THEN
3952 ! Fng = 1.
3953 !ELSE
3954 ! Fng = 1.-1.5*q1k
3955 !ENDIF
3956 ! Use the form of "Fng" from Bechtold and Siebesma (1998, JAS)
3957 if (q1k .ge. 1.0) then
3958 fng = 1.0
3959 elseif (q1k .ge. -1.7 .and. q1k .lt. 1.0) then
3960 fng = exp(-0.4*(q1k-1.0))
3961 elseif (q1k .ge. -2.5 .and. q1k .lt. -1.7) then
3962 fng = 3.0 + exp(-3.8*(q1k+1.7))
3963 else
3964 fng = min(23.9 + exp(-1.6*(q1k+2.5)), 60._kind_phys)
3965 endif
3966
3967 cfmax = min(cldfra_bl1d(k), 0.6_kind_phys)
3968 !Further limit the cf going into vt & vq near the surface
3969 zsl = min(max(25., 0.1*pblh2), 100.)
3970 wt = min(zagl/zsl, 1.0) !=0 at z=0 m, =1 above ekman layer
3971 cfmax = cfmax*wt
3972
3973 bb = b(k)*t/th(k) ! bb is "b" in BCMT95. Their "b" differs from
3974 ! "b" in CB02 (i.e., b(k) above) by a factor
3975 ! of T/theta. Strictly, b(k) above is formulated in
3976 ! terms of sat. mixing ratio, but bb in BCMT95 is
3977 ! cast in terms of sat. specific humidity. The
3978 ! conversion is neglected here.
3979 qww = 1.+0.61*qw(k)
3980 alpha = 0.61*th(k)
3981 beta = (th(k)/t)*(xl/cp) - 1.61*th(k)
3982 vt(k) = qww - cfmax*beta*bb*fng - 1.
3983 vq(k) = alpha + cfmax*beta*a(k)*fng - tv0
3984 ! vt and vq correspond to beta-theta and beta-q, respectively,
3985 ! in NN09, Eq. B8. They also correspond to the bracketed
3986 ! expressions in BCMT95, Eq. 15, since (s*ql/sigma^2) = cldfra*Fng
3987 ! The "-1" and "-tv0" terms are included for consistency with
3988 ! the legacy vt and vq formulations (above).
3989
3990 ! dampen amplification factor where need be
3991 fac_damp = min(zagl * 0.0025, 1.0)
3992 !cld_factor = 1.0 + fac_damp*MAX(0.0, ( RH(k) - 0.75 ) / 0.26 )**1.9 !HRRRv4
3993 !cld_factor = 1.0 + fac_damp*min((max(0.0, ( RH(k) - 0.92 )) / 0.25 )**2, 0.3)
3994 cld_factor = 1.0 + fac_damp*min((max(0.0, ( rh(k) - 0.92 )) / 0.145)**2, 0.37)
3995 cldfra_bl1d(k) = min( 1., cld_factor*cldfra_bl1d(k) )
3996 enddo
3997
3998 END SELECT !end cloudPDF option
3999
4000 !For testing purposes only, option for isolating on the mass-flux clouds.
4001 IF (bl_mynn_cloudpdf .LT. 0) THEN
4002 DO k = kts,kte-1
4003 cldfra_bl1d(k) = 0.0
4004 qc_bl1d(k) = 0.0
4005 qi_bl1d(k) = 0.0
4006 END DO
4007 ENDIF
4008!
4009 ql(kte) = ql(kte-1)
4010 vt(kte) = vt(kte-1)
4011 vq(kte) = vq(kte-1)
4012 qc_bl1d(kte)=0.
4013 qi_bl1d(kte)=0.
4014 cldfra_bl1d(kte)=0.
4015 RETURN
4016
4017#ifdef HARDCODE_VERTICAL
4018# undef kts
4019# undef kte
4020#endif
4021
4022 END SUBROUTINE mym_condensation
4023
4024! ==================================================================
4028 SUBROUTINE mynn_tendencies(kts,kte,i, &
4029 &delt,dz,rho, &
4030 &u,v,th,tk,qv,qc,qi,qs,qnc,qni, &
4031 &psfc,p,exner, &
4032 &thl,sqv,sqc,sqi,sqs,sqw, &
4033 &qnwfa,qnifa,qnbca,ozone, &
4034 &ust,flt,flq,flqv,flqc,wspd, &
4035 &uoce,voce, &
4036 &tsq,qsq,cov, &
4037 &tcd,qcd, &
4038 &dfm,dfh,dfq, &
4039 &Du,Dv,Dth,Dqv,Dqc,Dqi,Dqs,Dqnc,Dqni, &
4040 &Dqnwfa,Dqnifa,Dqnbca,Dozone, &
4041 &diss_heat, &
4042 &s_aw,s_awthl,s_awqt,s_awqv,s_awqc, &
4043 &s_awu,s_awv, &
4044 &s_awqnc,s_awqni, &
4045 &s_awqnwfa,s_awqnifa,s_awqnbca, &
4046 &sd_aw,sd_awthl,sd_awqt,sd_awqv, &
4047 &sd_awqc,sd_awu,sd_awv, &
4048 &sub_thl,sub_sqv, &
4049 &sub_u,sub_v, &
4050 &det_thl,det_sqv,det_sqc, &
4051 &det_u,det_v, &
4052 &FLAG_QC,FLAG_QI,FLAG_QNC,FLAG_QNI, &
4053 &FLAG_QS, &
4054 &FLAG_QNWFA,FLAG_QNIFA,FLAG_QNBCA, &
4055 &cldfra_bl1d, &
4056 &bl_mynn_cloudmix, &
4057 &bl_mynn_mixqt, &
4058 &bl_mynn_edmf, &
4059 &bl_mynn_edmf_mom, &
4060 &bl_mynn_mixscalars )
4061
4062!-------------------------------------------------------------------
4063 integer, intent(in) :: kts,kte,i
4064
4065#ifdef HARDCODE_VERTICAL
4066# define kts 1
4067# define kte HARDCODE_VERTICAL
4068#endif
4069
4070 integer, intent(in) :: bl_mynn_cloudmix,bl_mynn_mixqt, &
4071 bl_mynn_edmf,bl_mynn_edmf_mom, &
4072 bl_mynn_mixscalars
4073 logical, intent(IN) :: FLAG_QI,FLAG_QNI,FLAG_QC,FLAG_QS, &
4074 &FLAG_QNC,FLAG_QNWFA,FLAG_QNIFA,FLAG_QNBCA
4075
4076! thl - liquid water potential temperature
4077! qw - total water
4078! dfm,dfh,dfq - diffusivities i.e., dfh(k) = elq*sh(k) / dzk
4079! flt - surface flux of thl
4080! flq - surface flux of qw
4081
4082! mass-flux plumes
4083 real(kind_phys), dimension(kts:kte+1), intent(in) :: s_aw, &
4084 &s_awthl,s_awqt,s_awqnc,s_awqni,s_awqv,s_awqc,s_awu,s_awv, &
4085 &s_awqnwfa,s_awqnifa,s_awqnbca, &
4086 &sd_aw,sd_awthl,sd_awqt,sd_awqv,sd_awqc,sd_awu,sd_awv
4087! tendencies from mass-flux environmental subsidence and detrainment
4088 real(kind_phys), dimension(kts:kte), intent(in) :: sub_thl,sub_sqv, &
4089 &sub_u,sub_v,det_thl,det_sqv,det_sqc,det_u,det_v
4090 real(kind_phys), dimension(kts:kte), intent(in) :: u,v,th,tk,qv,qc,qi,&
4091 &qs,qni,qnc,rho,p,exner,dfq,dz,tsq,qsq,cov,tcd,qcd, &
4092 &cldfra_bl1d,diss_heat
4093 real(kind_phys), dimension(kts:kte), intent(inout) :: thl,sqw,sqv,sqc,&
4094 &sqi,sqs,qnwfa,qnifa,qnbca,ozone,dfm,dfh
4095 real(kind_phys), dimension(kts:kte), intent(inout) :: du,dv,dth,dqv, &
4096 &dqc,dqi,dqs,dqni,dqnc,dqnwfa,dqnifa,dqnbca,dozone
4097 real(kind_phys), intent(in) :: flt,flq,flqv,flqc,uoce,voce
4098 real(kind_phys), intent(in) :: ust,delt,psfc,wspd
4099 !debugging
4100 real(kind_phys):: wsp,wsp2,tk2,th2
4101 logical :: problem
4102 integer :: kproblem
4103
4104! real(kind_phys), intent(in) :: gradu_top,gradv_top,gradth_top,gradqv_top
4105
4106!local vars
4107
4108 real(kind_phys), dimension(kts:kte) :: dtz,dfhc,dfmc,delp
4109 real(kind_phys), dimension(kts:kte) :: sqv2,sqc2,sqi2,sqs2,sqw2, &
4110 &qni2,qnc2,qnwfa2,qnifa2,qnbca2,ozone2
4111 real(kind_phys), dimension(kts:kte) :: zfac,plumeKh,rhoinv
4112 real(kind_phys), dimension(kts:kte) :: a,b,c,d,x
4113 real(kind_phys), dimension(kts:kte+1) :: rhoz, & !rho on model interface
4114 &khdz,kmdz
4115 real(kind_phys):: rhs,gfluxm,gfluxp,dztop,maxdfh,mindfh,maxcf,maxKh,zw
4116 real(kind_phys):: t,esat,qsl,onoff,kh,km,dzk,rhosfc
4117 real(kind_phys):: ustdrag,ustdiff,qvflux
4118 real(kind_phys):: th_new,portion_qc,portion_qi,condensate,qsat
4119 integer :: k,kk
4120
4121 !Activate nonlocal mixing from the mass-flux scheme for
4122 !number concentrations and aerosols (0.0 = no; 1.0 = yes)
4123 real(kind_phys), parameter :: nonloc = 1.0
4124
4125 dztop=.5*(dz(kte)+dz(kte-1))
4126
4127 ! REGULATE THE MOMENTUM MIXING FROM THE MASS-FLUX SCHEME (on or off)
4128 ! Note that s_awu and s_awv already come in as 0.0 if bl_mynn_edmf_mom == 0, so
4129 ! we only need to zero-out the MF term
4130 IF (bl_mynn_edmf_mom == 0) THEN
4131 onoff=0.0
4132 ELSE
4133 onoff=1.0
4134 ENDIF
4135
4136 !Prepare "constants" for diffusion equation.
4137 !khdz = rho*Kh/dz = rho*dfh
4138 rhosfc = psfc/(r_d*(tk(kts)+p608*qv(kts)))
4139 dtz(kts) =delt/dz(kts)
4140 rhoz(kts) =rho(kts)
4141 rhoinv(kts)=1./rho(kts)
4142 khdz(kts) =rhoz(kts)*dfh(kts)
4143 kmdz(kts) =rhoz(kts)*dfm(kts)
4144 delp(kts) = psfc - (p(kts+1)*dz(kts) + p(kts)*dz(kts+1))/(dz(kts)+dz(kts+1))
4145 DO k=kts+1,kte
4146 dtz(k) =delt/dz(k)
4147 rhoz(k) =(rho(k)*dz(k-1) + rho(k-1)*dz(k))/(dz(k-1)+dz(k))
4148 rhoz(k) = max(rhoz(k),1e-4)
4149 rhoinv(k)=1./max(rho(k),1e-4)
4150 dzk = 0.5 *( dz(k)+dz(k-1) )
4151 khdz(k) = rhoz(k)*dfh(k)
4152 kmdz(k) = rhoz(k)*dfm(k)
4153 ENDDO
4154 DO k=kts+1,kte-1
4155 delp(k) = (p(k)*dz(k-1) + p(k-1)*dz(k))/(dz(k)+dz(k-1)) - &
4156 (p(k+1)*dz(k) + p(k)*dz(k+1))/(dz(k)+dz(k+1))
4157 ENDDO
4158 delp(kte) =delp(kte-1)
4159 rhoz(kte+1)=rhoz(kte)
4160 khdz(kte+1)=rhoz(kte+1)*dfh(kte)
4161 kmdz(kte+1)=rhoz(kte+1)*dfm(kte)
4162
4163 !stability criteria for mf
4164 DO k=kts+1,kte-1
4165 khdz(k) = max(khdz(k), 0.5*s_aw(k))
4166 khdz(k) = max(khdz(k), -0.5*(s_aw(k)-s_aw(k+1)))
4167 kmdz(k) = max(kmdz(k), 0.5*s_aw(k))
4168 kmdz(k) = max(kmdz(k), -0.5*(s_aw(k)-s_aw(k+1)))
4169 ENDDO
4170
4171 ustdrag = min(ust*ust,0.99)/wspd ! limit at ~ 20 m/s
4172 ustdiff = min(ust*ust,0.01)/wspd ! limit at ~ 2 m/s
4173 dth(kts:kte) = 0.0 ! must initialize for moisture_check routine
4174
4175!!============================================
4176!! u
4177!!============================================
4178
4179 k=kts
4180
4181!rho-weighted (drag in b-vector):
4182 a(k)= -dtz(k)*kmdz(k)*rhoinv(k)
4183 b(k)=1.+dtz(k)*(kmdz(k+1)+rhosfc*ust**2/wspd)*rhoinv(k) &
4184 & - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1)*onoff &
4185 & - 0.5*dtz(k)*rhoinv(k)*sd_aw(k+1)*onoff
4186 c(k)= -dtz(k)*kmdz(k+1)*rhoinv(k) &
4187 & - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1)*onoff &
4188 & - 0.5*dtz(k)*rhoinv(k)*sd_aw(k+1)*onoff
4189 d(k)=u(k) + dtz(k)*uoce*ust**2/wspd &
4190 & - dtz(k)*rhoinv(k)*s_awu(k+1)*onoff &
4191 & + dtz(k)*rhoinv(k)*sd_awu(k+1)*onoff &
4192 & + sub_u(k)*delt + det_u(k)*delt
4193
4194 do k=kts+1,kte-1
4195 a(k)= -dtz(k)*kmdz(k)*rhoinv(k) &
4196 & + 0.5*dtz(k)*rhoinv(k)*s_aw(k)*onoff &
4197 & + 0.5*dtz(k)*rhoinv(k)*sd_aw(k)*onoff
4198 b(k)=1.+ dtz(k)*(kmdz(k)+kmdz(k+1))*rhoinv(k) &
4199 & + 0.5*dtz(k)*rhoinv(k)*(s_aw(k)-s_aw(k+1))*onoff &
4200 & + 0.5*dtz(k)*rhoinv(k)*(sd_aw(k)-sd_aw(k+1))*onoff
4201 c(k)= - dtz(k)*kmdz(k+1)*rhoinv(k) &
4202 & - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1)*onoff &
4203 & - 0.5*dtz(k)*rhoinv(k)*sd_aw(k+1)*onoff
4204 d(k)=u(k) + dtz(k)*rhoinv(k)*(s_awu(k)-s_awu(k+1))*onoff &
4205 & - dtz(k)*rhoinv(k)*(sd_awu(k)-sd_awu(k+1))*onoff &
4206 & + sub_u(k)*delt + det_u(k)*delt
4207 enddo
4208
4209!! no flux at the top
4210! a(kte)=-1.
4211! b(kte)=1.
4212! c(kte)=0.
4213! d(kte)=0.
4214
4215!! specified gradient at the top
4216! a(kte)=-1.
4217! b(kte)=1.
4218! c(kte)=0.
4219! d(kte)=gradu_top*dztop
4220
4221!! prescribed value
4222 a(kte)=0
4223 b(kte)=1.
4224 c(kte)=0.
4225 d(kte)=u(kte)
4226
4227! CALL tridiag(kte,a,b,c,d)
4228 CALL tridiag2(kte,a,b,c,d,x)
4229! CALL tridiag3(kte,a,b,c,d,x)
4230
4231 DO k=kts,kte
4232! du(k)=(d(k-kts+1)-u(k))/delt
4233 du(k)=(x(k)-u(k))/delt
4234 ENDDO
4235
4236!!============================================
4237!! v
4238!!============================================
4239
4240 k=kts
4241
4242!rho-weighted (drag in b-vector):
4243 a(k)= -dtz(k)*kmdz(k)*rhoinv(k)
4244 b(k)=1.+dtz(k)*(kmdz(k+1) + rhosfc*ust**2/wspd)*rhoinv(k) &
4245 & - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1)*onoff &
4246 & - 0.5*dtz(k)*rhoinv(k)*sd_aw(k+1)*onoff
4247 c(k)= -dtz(k)*kmdz(k+1)*rhoinv(k) &
4248 & - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1)*onoff &
4249 & - 0.5*dtz(k)*rhoinv(k)*sd_aw(k+1)*onoff
4250 d(k)=v(k) + dtz(k)*voce*ust**2/wspd &
4251 & - dtz(k)*rhoinv(k)*s_awv(k+1)*onoff &
4252 & + dtz(k)*rhoinv(k)*sd_awv(k+1)*onoff &
4253 & + sub_v(k)*delt + det_v(k)*delt
4254
4255 do k=kts+1,kte-1
4256 a(k)= -dtz(k)*kmdz(k)*rhoinv(k) &
4257 & + 0.5*dtz(k)*rhoinv(k)*s_aw(k)*onoff &
4258 & + 0.5*dtz(k)*rhoinv(k)*sd_aw(k)*onoff
4259 b(k)=1.+dtz(k)*(kmdz(k)+kmdz(k+1))*rhoinv(k) &
4260 & + 0.5*dtz(k)*rhoinv(k)*(s_aw(k)-s_aw(k+1))*onoff &
4261 & + 0.5*dtz(k)*rhoinv(k)*(sd_aw(k)-sd_aw(k+1))*onoff
4262 c(k)= -dtz(k)*kmdz(k+1)*rhoinv(k) &
4263 & - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1)*onoff &
4264 & - 0.5*dtz(k)*rhoinv(k)*sd_aw(k+1)*onoff
4265 d(k)=v(k) + dtz(k)*rhoinv(k)*(s_awv(k)-s_awv(k+1))*onoff &
4266 & - dtz(k)*rhoinv(k)*(sd_awv(k)-sd_awv(k+1))*onoff &
4267 & + sub_v(k)*delt + det_v(k)*delt
4268 enddo
4269
4270!! no flux at the top
4271! a(kte)=-1.
4272! b(kte)=1.
4273! c(kte)=0.
4274! d(kte)=0.
4275
4276!! specified gradient at the top
4277! a(kte)=-1.
4278! b(kte)=1.
4279! c(kte)=0.
4280! d(kte)=gradv_top*dztop
4281
4282!! prescribed value
4283 a(kte)=0
4284 b(kte)=1.
4285 c(kte)=0.
4286 d(kte)=v(kte)
4287
4288! CALL tridiag(kte,a,b,c,d)
4289 CALL tridiag2(kte,a,b,c,d,x)
4290! CALL tridiag3(kte,a,b,c,d,x)
4291
4292 DO k=kts,kte
4293! dv(k)=(d(k-kts+1)-v(k))/delt
4294 dv(k)=(x(k)-v(k))/delt
4295 ENDDO
4296
4297!!============================================
4298!! thl tendency
4299!!============================================
4300 k=kts
4301
4302! a(k)=0.
4303! b(k)=1.+dtz(k)*dfh(k+1) - 0.5*dtz(k)*s_aw(k+1)
4304! c(k)= -dtz(k)*dfh(k+1) - 0.5*dtz(k)*s_aw(k+1)
4305! d(k)=thl(k) + dtz(k)*flt + tcd(k)*delt &
4306! & -dtz(k)*s_awthl(kts+1) + diss_heat(k)*delt + &
4307! & sub_thl(k)*delt + det_thl(k)*delt
4308!
4309! DO k=kts+1,kte-1
4310! a(k)= -dtz(k)*dfh(k) + 0.5*dtz(k)*s_aw(k)
4311! b(k)=1.+dtz(k)*(dfh(k)+dfh(k+1)) + 0.5*dtz(k)*(s_aw(k)-s_aw(k+1))
4312! c(k)= -dtz(k)*dfh(k+1) - 0.5*dtz(k)*s_aw(k+1)
4313! d(k)=thl(k) + tcd(k)*delt + dtz(k)*(s_awthl(k)-s_awthl(k+1)) &
4314! & + diss_heat(k)*delt + &
4315! & sub_thl(k)*delt + det_thl(k)*delt
4316! ENDDO
4317
4318!rho-weighted: rhosfc*X*rhoinv(k)
4319 a(k)= -dtz(k)*khdz(k)*rhoinv(k)
4320 b(k)=1.+dtz(k)*(khdz(k+1)+khdz(k))*rhoinv(k) - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1) - 0.5*dtz(k)*rhoinv(k)*sd_aw(k+1)
4321 c(k)= -dtz(k)*khdz(k+1)*rhoinv(k) - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1) - 0.5*dtz(k)*rhoinv(k)*sd_aw(k+1)
4322 d(k)=thl(k) + dtz(k)*rhosfc*flt*rhoinv(k) + tcd(k)*delt &
4323 & - dtz(k)*rhoinv(k)*s_awthl(k+1) -dtz(k)*rhoinv(k)*sd_awthl(k+1) + &
4324 & diss_heat(k)*delt + sub_thl(k)*delt + det_thl(k)*delt
4325
4326 DO k=kts+1,kte-1
4327 a(k)= -dtz(k)*khdz(k)*rhoinv(k) + 0.5*dtz(k)*rhoinv(k)*s_aw(k) + 0.5*dtz(k)*rhoinv(k)*sd_aw(k)
4328 b(k)=1.+dtz(k)*(khdz(k)+khdz(k+1))*rhoinv(k) + &
4329 & 0.5*dtz(k)*rhoinv(k)*(s_aw(k)-s_aw(k+1)) + 0.5*dtz(k)*rhoinv(k)*(sd_aw(k)-sd_aw(k+1))
4330 c(k)= -dtz(k)*khdz(k+1)*rhoinv(k) - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1) - 0.5*dtz(k)*rhoinv(k)*sd_aw(k+1)
4331 d(k)=thl(k) + tcd(k)*delt + &
4332 & dtz(k)*rhoinv(k)*(s_awthl(k)-s_awthl(k+1)) + dtz(k)*rhoinv(k)*(sd_awthl(k)-sd_awthl(k+1)) + &
4333 & diss_heat(k)*delt + &
4334 & sub_thl(k)*delt + det_thl(k)*delt
4335 ENDDO
4336
4337!! no flux at the top
4338! a(kte)=-1.
4339! b(kte)=1.
4340! c(kte)=0.
4341! d(kte)=0.
4342
4343!! specified gradient at the top
4344!assume gradthl_top=gradth_top
4345! a(kte)=-1.
4346! b(kte)=1.
4347! c(kte)=0.
4348! d(kte)=gradth_top*dztop
4349
4350!! prescribed value
4351 a(kte)=0.
4352 b(kte)=1.
4353 c(kte)=0.
4354 d(kte)=thl(kte)
4355
4356! CALL tridiag(kte,a,b,c,d)
4357 CALL tridiag2(kte,a,b,c,d,x)
4358! CALL tridiag3(kte,a,b,c,d,x)
4359
4360 DO k=kts,kte
4361 !thl(k)=d(k-kts+1)
4362 thl(k)=x(k)
4363 ENDDO
4364
4365IF (bl_mynn_mixqt > 0) THEN
4366 !============================================
4367 ! MIX total water (sqw = sqc + sqv + sqi)
4368 ! NOTE: no total water tendency is output; instead, we must calculate
4369 ! the saturation specific humidity and then
4370 ! subtract out the moisture excess (sqc & sqi)
4371 !============================================
4372
4373 k=kts
4374
4375! a(k)=0.
4376! b(k)=1.+dtz(k)*dfh(k+1) - 0.5*dtz(k)*s_aw(k+1)
4377! c(k)= -dtz(k)*dfh(k+1) - 0.5*dtz(k)*s_aw(k+1)
4378! !rhs= qcd(k) !+ (gfluxp - gfluxm)/dz(k)&
4379! d(k)=sqw(k) + dtz(k)*flq + qcd(k)*delt - dtz(k)*s_awqt(k+1)
4380!
4381! DO k=kts+1,kte-1
4382! a(k)= -dtz(k)*dfh(k) + 0.5*dtz(k)*s_aw(k)
4383! b(k)=1.+dtz(k)*(dfh(k)+dfh(k+1)) + 0.5*dtz(k)*(s_aw(k)-s_aw(k+1))
4384! c(k)= -dtz(k)*dfh(k+1) - 0.5*dtz(k)*s_aw(k+1)
4385! d(k)=sqw(k) + qcd(k)*delt + dtz(k)*(s_awqt(k)-s_awqt(k+1))
4386! ENDDO
4387
4388!rho-weighted:
4389 a(k)= -dtz(k)*khdz(k)*rhoinv(k)
4390 b(k)=1.+dtz(k)*(khdz(k+1)+khdz(k))*rhoinv(k) - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1) - 0.5*dtz(k)*rhoinv(k)*sd_aw(k+1)
4391 c(k)= -dtz(k)*khdz(k+1)*rhoinv(k) - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1) - 0.5*dtz(k)*rhoinv(k)*sd_aw(k+1)
4392 d(k)=sqw(k) + dtz(k)*rhosfc*flq*rhoinv(k) + qcd(k)*delt - dtz(k)*rhoinv(k)*s_awqt(k+1) - dtz(k)*rhoinv(k)*sd_awqt(k+1)
4393
4394 DO k=kts+1,kte-1
4395 a(k)= -dtz(k)*khdz(k)*rhoinv(k) + 0.5*dtz(k)*rhoinv(k)*s_aw(k) + 0.5*dtz(k)*rhoinv(k)*sd_aw(k)
4396 b(k)=1.+dtz(k)*(khdz(k)+khdz(k+1))*rhoinv(k) + &
4397 & 0.5*dtz(k)*rhoinv(k)*(s_aw(k)-s_aw(k+1)) + 0.5*dtz(k)*rhoinv(k)*(sd_aw(k)-sd_aw(k+1))
4398 c(k)= -dtz(k)*khdz(k+1)*rhoinv(k) - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1) - 0.5*dtz(k)*rhoinv(k)*sd_aw(k+1)
4399 d(k)=sqw(k) + qcd(k)*delt + dtz(k)*rhoinv(k)*(s_awqt(k)-s_awqt(k+1)) + dtz(k)*rhoinv(k)*(sd_awqt(k)-sd_awqt(k+1))
4400 ENDDO
4401
4402!! no flux at the top
4403! a(kte)=-1.
4404! b(kte)=1.
4405! c(kte)=0.
4406! d(kte)=0.
4407!! specified gradient at the top
4408!assume gradqw_top=gradqv_top
4409! a(kte)=-1.
4410! b(kte)=1.
4411! c(kte)=0.
4412! d(kte)=gradqv_top*dztop
4413!! prescribed value
4414 a(kte)=0.
4415 b(kte)=1.
4416 c(kte)=0.
4417 d(kte)=sqw(kte)
4418
4419! CALL tridiag(kte,a,b,c,d)
4420 CALL tridiag2(kte,a,b,c,d,sqw2)
4421! CALL tridiag3(kte,a,b,c,d,sqw2)
4422
4423! DO k=kts,kte
4424! sqw2(k)=d(k-kts+1)
4425! ENDDO
4426ELSE
4427 sqw2=sqw
4428ENDIF
4429
4430IF (bl_mynn_mixqt == 0) THEN
4431!============================================
4432! cloud water ( sqc ). If mixing total water (bl_mynn_mixqt > 0),
4433! then sqc will be backed out of saturation check (below).
4434!============================================
4435 IF (bl_mynn_cloudmix > 0 .AND. flag_qc) THEN
4436
4437 k=kts
4438
4439! a(k)=0.
4440! b(k)=1.+dtz(k)*dfh(k+1) - 0.5*dtz(k)*s_aw(k+1)
4441! c(k)= -dtz(k)*dfh(k+1) - 0.5*dtz(k)*s_aw(k+1)
4442! d(k)=sqc(k) + dtz(k)*flqc + qcd(k)*delt - &
4443! dtz(k)*s_awqc(k+1) + det_sqc(k)*delt
4444!
4445! DO k=kts+1,kte-1
4446! a(k)= -dtz(k)*dfh(k) + 0.5*dtz(k)*s_aw(k)
4447! b(k)=1.+dtz(k)*(dfh(k)+dfh(k+1)) + 0.5*dtz(k)*(s_aw(k)-s_aw(k+1))
4448! c(k)= -dtz(k)*dfh(k+1) - 0.5*dtz(k)*s_aw(k+1)
4449! d(k)=sqc(k) + qcd(k)*delt + dtz(k)*(s_awqc(k)-s_awqc(k+1)) + &
4450! det_sqc(k)*delt
4451! ENDDO
4452
4453!rho-weighted:
4454 a(k)= -dtz(k)*khdz(k)*rhoinv(k)
4455 b(k)=1.+dtz(k)*(khdz(k+1)+khdz(k))*rhoinv(k) - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1) - 0.5*dtz(k)*rhoinv(k)*sd_aw(k+1)
4456 c(k)= -dtz(k)*khdz(k+1)*rhoinv(k) - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1) - 0.5*dtz(k)*rhoinv(k)*sd_aw(k+1)
4457 d(k)=sqc(k) + dtz(k)*rhosfc*flqc*rhoinv(k) + qcd(k)*delt &
4458 & - dtz(k)*rhoinv(k)*s_awqc(k+1) - dtz(k)*rhoinv(k)*sd_awqc(k+1) + &
4459 & det_sqc(k)*delt
4460
4461 DO k=kts+1,kte-1
4462 a(k)= -dtz(k)*khdz(k)*rhoinv(k) + 0.5*dtz(k)*rhoinv(k)*s_aw(k) + 0.5*dtz(k)*rhoinv(k)*sd_aw(k)
4463 b(k)=1.+dtz(k)*(khdz(k)+khdz(k+1))*rhoinv(k) + &
4464 & 0.5*dtz(k)*rhoinv(k)*(s_aw(k)-s_aw(k+1)) + 0.5*dtz(k)*rhoinv(k)*(sd_aw(k)-sd_aw(k+1))
4465 c(k)= -dtz(k)*khdz(k+1)*rhoinv(k) - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1) - 0.5*dtz(k)*rhoinv(k)*sd_aw(k+1)
4466 d(k)=sqc(k) + qcd(k)*delt + dtz(k)*rhoinv(k)*(s_awqc(k)-s_awqc(k+1)) + dtz(k)*rhoinv(k)*(sd_awqc(k)-sd_awqc(k+1)) + &
4467 & det_sqc(k)*delt
4468 ENDDO
4469
4470! prescribed value
4471 a(kte)=0.
4472 b(kte)=1.
4473 c(kte)=0.
4474 d(kte)=sqc(kte)
4475
4476! CALL tridiag(kte,a,b,c,d)
4477 CALL tridiag2(kte,a,b,c,d,sqc2)
4478! CALL tridiag3(kte,a,b,c,d,sqc2)
4479
4480! DO k=kts,kte
4481! sqc2(k)=d(k-kts+1)
4482! ENDDO
4483 ELSE
4484 !If not mixing clouds, set "updated" array equal to original array
4485 sqc2=sqc
4486 ENDIF
4487ENDIF
4488
4489IF (bl_mynn_mixqt == 0) THEN
4490 !============================================
4491 ! MIX WATER VAPOR ONLY ( sqv ). If mixing total water (bl_mynn_mixqt > 0),
4492 ! then sqv will be backed out of saturation check (below).
4493 !============================================
4494
4495 k=kts
4496
4497! a(k)=0.
4498! b(k)=1.+dtz(k)*dfh(k+1) - 0.5*dtz(k)*s_aw(k+1)
4499! c(k)= -dtz(k)*dfh(k+1) - 0.5*dtz(k)*s_aw(k+1)
4500! d(k)=sqv(k) + dtz(k)*flqv + qcd(k)*delt - dtz(k)*s_awqv(k+1) + &
4501! & sub_sqv(k)*delt + det_sqv(k)*delt
4502!
4503! DO k=kts+1,kte-1
4504! a(k)= -dtz(k)*dfh(k) + 0.5*dtz(k)*s_aw(k)
4505! b(k)=1.+dtz(k)*(dfh(k)+dfh(k+1)) + 0.5*dtz(k)*(s_aw(k)-s_aw(k+1))
4506! c(k)= -dtz(k)*dfh(k+1) - 0.5*dtz(k)*s_aw(k+1)
4507! d(k)=sqv(k) + qcd(k)*delt + dtz(k)*(s_awqv(k)-s_awqv(k+1)) + &
4508! & sub_sqv(k)*delt + det_sqv(k)*delt
4509! ENDDO
4510
4511 !limit unreasonably large negative fluxes:
4512 qvflux = flqv
4513 if (qvflux < 0.0) then
4514 !do not allow specified surface flux to reduce qv below 1e-8 kg/kg
4515 qvflux = max(qvflux, (min(0.9*sqv(kts) - 1e-8, 0.0)/dtz(kts)))
4516 endif
4517
4518!rho-weighted: rhosfc*X*rhoinv(k)
4519 a(k)= -dtz(k)*khdz(k)*rhoinv(k)
4520 b(k)=1.+dtz(k)*(khdz(k+1)+khdz(k))*rhoinv(k) - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1) - 0.5*dtz(k)*rhoinv(k)*sd_aw(k+1)
4521 c(k)= -dtz(k)*khdz(k+1)*rhoinv(k) - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1) - 0.5*dtz(k)*rhoinv(k)*sd_aw(k+1)
4522 d(k)=sqv(k) + dtz(k)*rhosfc*qvflux*rhoinv(k) + qcd(k)*delt &
4523 & - dtz(k)*rhoinv(k)*s_awqv(k+1) - dtz(k)*rhoinv(k)*sd_awqv(k+1) + &
4524 & sub_sqv(k)*delt + det_sqv(k)*delt
4525
4526 DO k=kts+1,kte-1
4527 a(k)= -dtz(k)*khdz(k)*rhoinv(k) + 0.5*dtz(k)*rhoinv(k)*s_aw(k) + 0.5*dtz(k)*rhoinv(k)*sd_aw(k)
4528 b(k)=1.+dtz(k)*(khdz(k)+khdz(k+1))*rhoinv(k) + &
4529 & 0.5*dtz(k)*rhoinv(k)*(s_aw(k)-s_aw(k+1)) + 0.5*dtz(k)*rhoinv(k)*(sd_aw(k)-sd_aw(k+1))
4530 c(k)= -dtz(k)*khdz(k+1)*rhoinv(k) - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1) - 0.5*dtz(k)*rhoinv(k)*sd_aw(k+1)
4531 d(k)=sqv(k) + qcd(k)*delt + dtz(k)*rhoinv(k)*(s_awqv(k)-s_awqv(k+1)) + dtz(k)*rhoinv(k)*(sd_awqv(k)-sd_awqv(k+1)) + &
4532 & sub_sqv(k)*delt + det_sqv(k)*delt
4533 ENDDO
4534
4535! no flux at the top
4536! a(kte)=-1.
4537! b(kte)=1.
4538! c(kte)=0.
4539! d(kte)=0.
4540
4541! specified gradient at the top
4542! assume gradqw_top=gradqv_top
4543! a(kte)=-1.
4544! b(kte)=1.
4545! c(kte)=0.
4546! d(kte)=gradqv_top*dztop
4547
4548! prescribed value
4549 a(kte)=0.
4550 b(kte)=1.
4551 c(kte)=0.
4552 d(kte)=sqv(kte)
4553
4554! CALL tridiag(kte,a,b,c,d)
4555 CALL tridiag2(kte,a,b,c,d,sqv2)
4556! CALL tridiag3(kte,a,b,c,d,sqv2)
4557
4558! DO k=kts,kte
4559! sqv2(k)=d(k-kts+1)
4560! ENDDO
4561ELSE
4562 sqv2=sqv
4563ENDIF
4564
4565!============================================
4566! MIX CLOUD ICE ( sqi )
4567!============================================
4568IF (bl_mynn_cloudmix > 0 .AND. flag_qi) THEN
4569
4570 k=kts
4571!rho-weighted:
4572 a(k)= -dtz(k)*khdz(k)*rhoinv(k)
4573 b(k)=1.+dtz(k)*(khdz(k+1)+khdz(k))*rhoinv(k)
4574 c(k)= -dtz(k)*khdz(k+1)*rhoinv(k)
4575 d(k)=sqi(k)
4576
4577 DO k=kts+1,kte-1
4578 a(k)= -dtz(k)*khdz(k)*rhoinv(k)
4579 b(k)=1.+dtz(k)*(khdz(k)+khdz(k+1))*rhoinv(k)
4580 c(k)= -dtz(k)*khdz(k+1)*rhoinv(k)
4581 d(k)=sqi(k)
4582 ENDDO
4583
4584!! no flux at the top
4585! a(kte)=-1.
4586! b(kte)=1.
4587! c(kte)=0.
4588! d(kte)=0.
4589
4590!! specified gradient at the top
4591!assume gradqw_top=gradqv_top
4592! a(kte)=-1.
4593! b(kte)=1.
4594! c(kte)=0.
4595! d(kte)=gradqv_top*dztop
4596
4597!! prescribed value
4598 a(kte)=0.
4599 b(kte)=1.
4600 c(kte)=0.
4601 d(kte)=sqi(kte)
4602
4603! CALL tridiag(kte,a,b,c,d)
4604 CALL tridiag2(kte,a,b,c,d,sqi2)
4605! CALL tridiag3(kte,a,b,c,d,sqi2)
4606
4607! DO k=kts,kte
4608! sqi2(k)=d(k-kts+1)
4609! ENDDO
4610ELSE
4611 sqi2=sqi
4612ENDIF
4613
4614!============================================
4615! MIX SNOW ( sqs )
4616!============================================
4617!hard-code to not mix snow
4618IF (bl_mynn_cloudmix > 0 .AND. .false.) THEN
4619
4620 k=kts
4621!rho-weighted:
4622 a(k)= -dtz(k)*khdz(k)*rhoinv(k)
4623 b(k)=1.+dtz(k)*(khdz(k+1)+khdz(k))*rhoinv(k)
4624 c(k)= -dtz(k)*khdz(k+1)*rhoinv(k)
4625 d(k)=sqs(k)
4626
4627 DO k=kts+1,kte-1
4628 a(k)= -dtz(k)*khdz(k)*rhoinv(k)
4629 b(k)=1.+dtz(k)*(khdz(k)+khdz(k+1))*rhoinv(k)
4630 c(k)= -dtz(k)*khdz(k+1)*rhoinv(k)
4631 d(k)=sqs(k)
4632 ENDDO
4633
4634!! prescribed value
4635 a(kte)=0.
4636 b(kte)=1.
4637 c(kte)=0.
4638 d(kte)=sqs(kte)
4639
4640! CALL tridiag(kte,a,b,c,d)
4641 CALL tridiag2(kte,a,b,c,d,sqs2)
4642! CALL tridiag3(kte,a,b,c,d,sqs2)
4643
4644! DO k=kts,kte
4645! sqs2(k)=d(k-kts+1)
4646! ENDDO
4647ELSE
4648 sqs2=sqs
4649ENDIF
4650
4651!!============================================
4652!! cloud ice number concentration (qni)
4653!!============================================
4654IF (bl_mynn_cloudmix > 0 .AND. flag_qni .AND. &
4655 bl_mynn_mixscalars > 0) THEN
4656
4657 k=kts
4658
4659 a(k)= -dtz(k)*khdz(k)*rhoinv(k)
4660 b(k)=1.+dtz(k)*(khdz(k+1)+khdz(k))*rhoinv(k) - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1)*nonloc
4661 c(k)= -dtz(k)*khdz(k+1)*rhoinv(k) - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1)*nonloc
4662 d(k)=qni(k) - dtz(k)*rhoinv(k)*s_awqni(k+1)*nonloc
4663
4664 DO k=kts+1,kte-1
4665 a(k)= -dtz(k)*khdz(k)*rhoinv(k) + 0.5*dtz(k)*rhoinv(k)*s_aw(k)*nonloc
4666 b(k)=1.+dtz(k)*(khdz(k)+khdz(k+1))*rhoinv(k) + &
4667 & 0.5*dtz(k)*rhoinv(k)*(s_aw(k)-s_aw(k+1))*nonloc
4668 c(k)= -dtz(k)*khdz(k+1)*rhoinv(k) - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1)*nonloc
4669 d(k)=qni(k) + dtz(k)*rhoinv(k)*(s_awqni(k)-s_awqni(k+1))*nonloc
4670 ENDDO
4671
4672!! prescribed value
4673 a(kte)=0.
4674 b(kte)=1.
4675 c(kte)=0.
4676 d(kte)=qni(kte)
4677
4678! CALL tridiag(kte,a,b,c,d)
4679 CALL tridiag2(kte,a,b,c,d,x)
4680! CALL tridiag3(kte,a,b,c,d,x)
4681
4682 DO k=kts,kte
4683 !qni2(k)=d(k-kts+1)
4684 qni2(k)=x(k)
4685 ENDDO
4686
4687ELSE
4688 qni2=qni
4689ENDIF
4690
4691!!============================================
4692!! cloud water number concentration (qnc)
4693!! include non-local transport
4694!!============================================
4695 IF (bl_mynn_cloudmix > 0 .AND. flag_qnc .AND. &
4696 bl_mynn_mixscalars > 0) THEN
4697
4698 k=kts
4699
4700 a(k)= -dtz(k)*khdz(k)*rhoinv(k)
4701 b(k)=1.+dtz(k)*(khdz(k+1)+khdz(k))*rhoinv(k) - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1)*nonloc
4702 c(k)= -dtz(k)*khdz(k+1)*rhoinv(k) - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1)*nonloc
4703 d(k)=qnc(k) - dtz(k)*rhoinv(k)*s_awqnc(k+1)*nonloc
4704
4705 DO k=kts+1,kte-1
4706 a(k)= -dtz(k)*khdz(k)*rhoinv(k) + 0.5*dtz(k)*rhoinv(k)*s_aw(k)*nonloc
4707 b(k)=1.+dtz(k)*(khdz(k)+khdz(k+1))*rhoinv(k) + &
4708 & 0.5*dtz(k)*rhoinv(k)*(s_aw(k)-s_aw(k+1))*nonloc
4709 c(k)= -dtz(k)*khdz(k+1)*rhoinv(k) - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1)*nonloc
4710 d(k)=qnc(k) + dtz(k)*rhoinv(k)*(s_awqnc(k)-s_awqnc(k+1))*nonloc
4711 ENDDO
4712
4713!! prescribed value
4714 a(kte)=0.
4715 b(kte)=1.
4716 c(kte)=0.
4717 d(kte)=qnc(kte)
4718
4719! CALL tridiag(kte,a,b,c,d)
4720 CALL tridiag2(kte,a,b,c,d,x)
4721! CALL tridiag3(kte,a,b,c,d,x)
4722
4723 DO k=kts,kte
4724 !qnc2(k)=d(k-kts+1)
4725 qnc2(k)=x(k)
4726 ENDDO
4727
4728ELSE
4729 qnc2=qnc
4730ENDIF
4731
4732!============================================
4733! Water-friendly aerosols ( qnwfa ).
4734!============================================
4735IF (bl_mynn_cloudmix > 0 .AND. flag_qnwfa .AND. &
4736 bl_mynn_mixscalars > 0) THEN
4737
4738 k=kts
4739
4740 a(k)= -dtz(k)*khdz(k)*rhoinv(k)
4741 b(k)=1.+dtz(k)*(khdz(k) + khdz(k+1))*rhoinv(k) - &
4742 & 0.5*dtz(k)*rhoinv(k)*s_aw(k+1)*nonloc
4743 c(k)= -dtz(k)*khdz(k+1)*rhoinv(k) - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1)*nonloc
4744 d(k)=qnwfa(k) - dtz(k)*rhoinv(k)*s_awqnwfa(k+1)*nonloc
4745
4746 DO k=kts+1,kte-1
4747 a(k)= -dtz(k)*khdz(k)*rhoinv(k) + 0.5*dtz(k)*rhoinv(k)*s_aw(k)*nonloc
4748 b(k)=1.+dtz(k)*(khdz(k) + khdz(k+1))*rhoinv(k) + &
4749 & 0.5*dtz(k)*rhoinv(k)*(s_aw(k)-s_aw(k+1))*nonloc
4750 c(k)= -dtz(k)*khdz(k+1)*rhoinv(k) - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1)*nonloc
4751 d(k)=qnwfa(k) + dtz(k)*rhoinv(k)*(s_awqnwfa(k)-s_awqnwfa(k+1))*nonloc
4752 ENDDO
4753
4754! prescribed value
4755 a(kte)=0.
4756 b(kte)=1.
4757 c(kte)=0.
4758 d(kte)=qnwfa(kte)
4759
4760! CALL tridiag(kte,a,b,c,d)
4761 CALL tridiag2(kte,a,b,c,d,x)
4762! CALL tridiag3(kte,a,b,c,d,x)
4763
4764 DO k=kts,kte
4765 !qnwfa2(k)=d(k)
4766 qnwfa2(k)=x(k)
4767 ENDDO
4768
4769ELSE
4770 !If not mixing aerosols, set "updated" array equal to original array
4771 qnwfa2=qnwfa
4772ENDIF
4773
4774!============================================
4775! Ice-friendly aerosols ( qnifa ).
4776!============================================
4777IF (bl_mynn_cloudmix > 0 .AND. flag_qnifa .AND. &
4778 bl_mynn_mixscalars > 0) THEN
4779
4780 k=kts
4781
4782 a(k)= -dtz(k)*khdz(k)*rhoinv(k)
4783 b(k)=1.+dtz(k)*(khdz(k) + khdz(k+1))*rhoinv(k) - &
4784 & 0.5*dtz(k)*rhoinv(k)*s_aw(k+1)*nonloc
4785 c(k)= -dtz(k)*khdz(k+1)*rhoinv(k) - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1)*nonloc
4786 d(k)=qnifa(k) - dtz(k)*rhoinv(k)*s_awqnifa(k+1)*nonloc
4787
4788 DO k=kts+1,kte-1
4789 a(k)= -dtz(k)*khdz(k)*rhoinv(k) + 0.5*dtz(k)*rhoinv(k)*s_aw(k)*nonloc
4790 b(k)=1.+dtz(k)*(khdz(k) + khdz(k+1))*rhoinv(k) + &
4791 & 0.5*dtz(k)*rhoinv(k)*(s_aw(k)-s_aw(k+1))*nonloc
4792 c(k)= -dtz(k)*khdz(k+1)*rhoinv(k) - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1)*nonloc
4793 d(k)=qnifa(k) + dtz(k)*rhoinv(k)*(s_awqnifa(k)-s_awqnifa(k+1))*nonloc
4794 ENDDO
4795
4796! prescribed value
4797 a(kte)=0.
4798 b(kte)=1.
4799 c(kte)=0.
4800 d(kte)=qnifa(kte)
4801
4802! CALL tridiag(kte,a,b,c,d)
4803 CALL tridiag2(kte,a,b,c,d,x)
4804! CALL tridiag3(kte,a,b,c,d,x)
4805
4806 DO k=kts,kte
4807 !qnifa2(k)=d(k-kts+1)
4808 qnifa2(k)=x(k)
4809 ENDDO
4810
4811ELSE
4812 !If not mixing aerosols, set "updated" array equal to original array
4813 qnifa2=qnifa
4814ENDIF
4815
4816!============================================
4817! Black-carbon aerosols ( qnbca ).
4818!============================================
4819IF (bl_mynn_cloudmix > 0 .AND. flag_qnbca .AND. &
4820 bl_mynn_mixscalars > 0) THEN
4821
4822 k=kts
4823
4824 a(k)= -dtz(k)*khdz(k)*rhoinv(k)
4825 b(k)=1.+dtz(k)*(khdz(k) + khdz(k+1))*rhoinv(k) - &
4826 & 0.5*dtz(k)*rhoinv(k)*s_aw(k+1)*nonloc
4827 c(k)= -dtz(k)*khdz(k+1)*rhoinv(k) - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1)*nonloc
4828 d(k)=qnbca(k) - dtz(k)*rhoinv(k)*s_awqnbca(k+1)*nonloc
4829
4830 DO k=kts+1,kte-1
4831 a(k)= -dtz(k)*khdz(k)*rhoinv(k) + 0.5*dtz(k)*rhoinv(k)*s_aw(k)*nonloc
4832 b(k)=1.+dtz(k)*(khdz(k) + khdz(k+1))*rhoinv(k) + &
4833 & 0.5*dtz(k)*rhoinv(k)*(s_aw(k)-s_aw(k+1))*nonloc
4834 c(k)= -dtz(k)*khdz(k+1)*rhoinv(k) - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1)*nonloc
4835 d(k)=qnbca(k) + dtz(k)*rhoinv(k)*(s_awqnbca(k)-s_awqnbca(k+1))*nonloc
4836 ENDDO
4837
4838! prescribed value
4839 a(kte)=0.
4840 b(kte)=1.
4841 c(kte)=0.
4842 d(kte)=qnbca(kte)
4843
4844! CALL tridiag(kte,a,b,c,d)
4845 CALL tridiag2(kte,a,b,c,d,x)
4846! CALL tridiag3(kte,a,b,c,d,x)
4847
4848 DO k=kts,kte
4849 !qnbca2(k)=d(k-kts+1)
4850 qnbca2(k)=x(k)
4851 ENDDO
4852
4853ELSE
4854 !If not mixing aerosols, set "updated" array equal to original array
4855 qnbca2=qnbca
4856ENDIF
4857
4858!============================================
4859! Ozone - local mixing only
4860!============================================
4861
4862 k=kts
4863
4864!rho-weighted:
4865 a(k)= -dtz(k)*khdz(k)*rhoinv(k)
4866 b(k)=1.+dtz(k)*(khdz(k+1)+khdz(k))*rhoinv(k)
4867 c(k)= -dtz(k)*khdz(k+1)*rhoinv(k)
4868 d(k)=ozone(k)
4869
4870 DO k=kts+1,kte-1
4871 a(k)= -dtz(k)*khdz(k)*rhoinv(k)
4872 b(k)=1.+dtz(k)*(khdz(k)+khdz(k+1))*rhoinv(k)
4873 c(k)= -dtz(k)*khdz(k+1)*rhoinv(k)
4874 d(k)=ozone(k)
4875 ENDDO
4876
4877! prescribed value
4878 a(kte)=0.
4879 b(kte)=1.
4880 c(kte)=0.
4881 d(kte)=ozone(kte)
4882
4883! CALL tridiag(kte,a,b,c,d)
4884 CALL tridiag2(kte,a,b,c,d,x)
4885! CALL tridiag3(kte,a,b,c,d,x)
4886
4887 DO k=kts,kte
4888 !ozone2(k)=d(k-kts+1)
4889 dozone(k)=(x(k)-ozone(k))/delt
4890 ENDDO
4891
4892!!============================================
4893!! Compute tendencies and convert to mixing ratios for WRF.
4894!! Note that the momentum tendencies are calculated above.
4895!!============================================
4896
4897 IF (bl_mynn_mixqt > 0) THEN
4898 DO k=kts,kte
4899 !compute updated theta using updated thl and old condensate
4900 th_new = thl(k) + xlvcp/exner(k)*sqc(k) &
4901 & + xlscp/exner(k)*sqi(k)
4902
4903 t = th_new*exner(k)
4904 qsat = qsat_blend(t,p(k))
4905 !SATURATED VAPOR PRESSURE
4906 !esat=esat_blend(t)
4907 !SATURATED SPECIFIC HUMIDITY
4908 !qsl=ep_2*esat/(p(k)-ep_3*esat)
4909 !qsl=ep_2*esat/max(1.e-4,(p(k)-ep_3*esat))
4910
4911 IF (sqc(k) > 0.0 .or. sqi(k) > 0.0) THEN !initially saturated
4912 sqv2(k) = min(sqw2(k),qsat)
4913 portion_qc = sqc(k)/(sqc(k) + sqi(k))
4914 portion_qi = sqi(k)/(sqc(k) + sqi(k))
4915 condensate = max(sqw2(k) - qsat, 0.0)
4916 sqc2(k) = condensate*portion_qc
4917 sqi2(k) = condensate*portion_qi
4918 ELSE ! initially unsaturated -----
4919 sqv2(k) = sqw2(k) ! let microphys decide what to do
4920 sqi2(k) = 0.0 ! if sqw2 > qsat
4921 sqc2(k) = 0.0
4922 ENDIF
4923 ENDDO
4924 ENDIF
4925
4926
4927 !=====================
4928 ! WATER VAPOR TENDENCY
4929 !=====================
4930 DO k=kts,kte
4931 dqv(k)=(sqv2(k) - sqv(k))/delt
4932 !if (sqv2(k) < 0.0)print*,"neg qv:",sqv2(k),k
4933 ENDDO
4934
4935 IF (bl_mynn_cloudmix > 0) THEN
4936 !=====================
4937 ! CLOUD WATER TENDENCY
4938 !=====================
4939 !print*,"FLAG_QC:",FLAG_QC
4940 IF (flag_qc) THEN
4941 DO k=kts,kte
4942 dqc(k)=(sqc2(k) - sqc(k))/delt
4943 !if (sqc2(k) < 0.0)print*,"neg qc:",sqc2(k),k
4944 ENDDO
4945 ELSE
4946 DO k=kts,kte
4947 dqc(k) = 0.
4948 ENDDO
4949 ENDIF
4950
4951 !===================
4952 ! CLOUD WATER NUM CONC TENDENCY
4953 !===================
4954 IF (flag_qnc .AND. bl_mynn_mixscalars > 0) THEN
4955 DO k=kts,kte
4956 dqnc(k) = (qnc2(k)-qnc(k))/delt
4957 !IF(Dqnc(k)*delt + qnc(k) < 0.)Dqnc(k)=-qnc(k)/delt
4958 ENDDO
4959 ELSE
4960 DO k=kts,kte
4961 dqnc(k) = 0.
4962 ENDDO
4963 ENDIF
4964
4965 !===================
4966 ! CLOUD ICE TENDENCY
4967 !===================
4968 IF (flag_qi) THEN
4969 DO k=kts,kte
4970 dqi(k)=(sqi2(k) - sqi(k))/delt
4971 !if (sqi2(k) < 0.0)print*,"neg qi:",sqi2(k),k
4972 ENDDO
4973 ELSE
4974 DO k=kts,kte
4975 dqi(k) = 0.
4976 ENDDO
4977 ENDIF
4978
4979 !===================
4980 ! CLOUD SNOW TENDENCY
4981 !===================
4982 IF (.false.) THEN !disabled
4983 DO k=kts,kte
4984 dqs(k)=(sqs2(k) - sqs(k))/delt
4985 ENDDO
4986 ELSE
4987 DO k=kts,kte
4988 dqs(k) = 0.
4989 ENDDO
4990 ENDIF
4991
4992 !===================
4993 ! CLOUD ICE NUM CONC TENDENCY
4994 !===================
4995 IF (flag_qni .AND. bl_mynn_mixscalars > 0) THEN
4996 DO k=kts,kte
4997 dqni(k)=(qni2(k)-qni(k))/delt
4998 !IF(Dqni(k)*delt + qni(k) < 0.)Dqni(k)=-qni(k)/delt
4999 ENDDO
5000 ELSE
5001 DO k=kts,kte
5002 dqni(k)=0.
5003 ENDDO
5004 ENDIF
5005 ELSE !-MIX CLOUD SPECIES?
5006 !CLOUDS ARE NOT NIXED (when bl_mynn_cloudmix == 0)
5007 DO k=kts,kte
5008 dqc(k) =0.
5009 dqnc(k)=0.
5010 dqi(k) =0.
5011 dqni(k)=0.
5012 dqs(k) =0.
5013 ENDDO
5014 ENDIF
5015
5016 !ensure non-negative moist species
5017 CALL moisture_check(kte, delt, delp, exner, &
5018 sqv2, sqc2, sqi2, sqs2, thl, &
5019 dqv, dqc, dqi, dqs, dth )
5020
5021 !=====================
5022 ! OZONE TENDENCY CHECK
5023 !=====================
5024 DO k=kts,kte
5025 IF(dozone(k)*delt + ozone(k) < 0.) THEN
5026 dozone(k)=-ozone(k)*0.99/delt
5027 ENDIF
5028 ENDDO
5029
5030 !===================
5031 ! THETA TENDENCY
5032 !===================
5033 IF (flag_qi) THEN
5034 DO k=kts,kte
5035 dth(k)=(thl(k) + xlvcp/exner(k)*sqc2(k) &
5036 & + xlscp/exner(k)*(sqi2(k)+sqs(k)) &
5037 & - th(k))/delt
5038 !Use form from Tripoli and Cotton (1981) with their
5039 !suggested min temperature to improve accuracy:
5040 !Dth(k)=(thl(k)*(1.+ xlvcp/MAX(tk(k),TKmin)*sqc(k) &
5041 ! & + xlscp/MAX(tk(k),TKmin)*sqi(k)) &
5042 ! & - th(k))/delt
5043 ENDDO
5044 ELSE
5045 DO k=kts,kte
5046 dth(k)=(thl(k)+xlvcp/exner(k)*sqc2(k) - th(k))/delt
5047 !Use form from Tripoli and Cotton (1981) with their
5048 !suggested min temperature to improve accuracy.
5049 !Dth(k)=(thl(k)*(1.+ xlvcp/MAX(tk(k),TKmin)*sqc(k)) &
5050 !& - th(k))/delt
5051 ENDDO
5052 ENDIF
5053
5054 !===================
5055 ! AEROSOL TENDENCIES
5056 !===================
5057 IF (flag_qnwfa .AND. flag_qnifa .AND. &
5058 bl_mynn_mixscalars > 0) THEN
5059 DO k=kts,kte
5060 !=====================
5061 ! WATER-friendly aerosols
5062 !=====================
5063 dqnwfa(k)=(qnwfa2(k) - qnwfa(k))/delt
5064 !=====================
5065 ! Ice-friendly aerosols
5066 !=====================
5067 dqnifa(k)=(qnifa2(k) - qnifa(k))/delt
5068 ENDDO
5069 ELSE
5070 DO k=kts,kte
5071 dqnwfa(k)=0.
5072 dqnifa(k)=0.
5073 ENDDO
5074 ENDIF
5075
5076 !========================
5077 ! BLACK-CARBON TENDENCIES
5078 !========================
5079 IF (flag_qnbca .AND. bl_mynn_mixscalars > 0) THEN
5080 DO k=kts,kte
5081 dqnbca(k)=(qnbca2(k) - qnbca(k))/delt
5082 ENDDO
5083 ELSE
5084 DO k=kts,kte
5085 dqnbca(k)=0.
5086 ENDDO
5087 ENDIF
5088
5089 !ensure non-negative moist species
5090 !note: if called down here, dth needs to be updated, but
5091 ! if called before the theta-tendency calculation, do not compute dth
5092 !CALL moisture_check(kte, delt, delp, exner, &
5093 ! sqv, sqc, sqi, thl, &
5094 ! dqv, dqc, dqi, dth )
5095
5096 if (debug_code) then
5097 problem = .false.
5098 do k=kts,kte
5099 wsp = sqrt(u(k)**2 + v(k)**2)
5100 wsp2 = sqrt((u(k)+du(k)*delt)**2 + (v(k)+du(k)*delt)**2)
5101 th2 = th(k) + dth(k)*delt
5102 tk2 = th2*exner(k)
5103 if (wsp2 > 200. .or. tk2 > 360. .or. tk2 < 160.) then
5104 problem = .true.
5105 print*,"Outgoing problem at: i=",i," k=",k
5106 print*," incoming wsp=",wsp," outgoing wsp=",wsp2
5107 print*," incoming T=",th(k)*exner(k),"outgoing T:",tk2
5108 print*," du=",du(k)*delt," dv=",dv(k)*delt," dth=",dth(k)*delt
5109 print*," km=",kmdz(k)*dz(k)," kh=",khdz(k)*dz(k)
5110 print*," u*=",ust," wspd=",wspd,"rhosfc=",rhosfc
5111 print*," LH=",flq*rhosfc*1004.," HFX=",flt*rhosfc*1004.
5112 print*," drag term=",ust**2/wspd*dtz(k)*rhosfc/rho(kts)
5113 kproblem = k
5114 endif
5115 enddo
5116 if (problem) then
5117 print*,"==thl:",thl(max(kproblem-3,1):min(kproblem+3,kte))
5118 print*,"===qv:",sqv2(max(kproblem-3,1):min(kproblem+3,kte))
5119 print*,"===qc:",sqc2(max(kproblem-3,1):min(kproblem+3,kte))
5120 print*,"===qi:",sqi2(max(kproblem-3,1):min(kproblem+3,kte))
5121 print*,"====u:",u(max(kproblem-3,1):min(kproblem+3,kte))
5122 print*,"====v:",v(max(kproblem-3,1):min(kproblem+3,kte))
5123 endif
5124 endif
5125
5126#ifdef HARDCODE_VERTICAL
5127# undef kts
5128# undef kte
5129#endif
5130
5131 END SUBROUTINE mynn_tendencies
5132
5133! ==================================================================
5134 SUBROUTINE moisture_check(kte, delt, dp, exner, &
5135 qv, qc, qi, qs, th, &
5136 dqv, dqc, dqi, dqs, dth )
5137
5138 ! This subroutine was adopted from the CAM-UW ShCu scheme and
5139 ! adapted for use here.
5140 !
5141 ! If qc < qcmin, qi < qimin, or qv < qvmin happens in any layer,
5142 ! force them to be larger than minimum value by (1) condensating
5143 ! water vapor into liquid or ice, and (2) by transporting water vapor
5144 ! from the very lower layer.
5145 !
5146 ! We then update the final state variables and tendencies associated
5147 ! with this correction. If any condensation happens, update theta too.
5148 ! Note that (qv,qc,qi,th) are the final state variables after
5149 ! applying corresponding input tendencies and corrective tendencies.
5150
5151 implicit none
5152 integer, intent(in) :: kte
5153 real(kind_phys), intent(in) :: delt
5154 real(kind_phys), dimension(kte), intent(in) :: dp, exner
5155 real(kind_phys), dimension(kte), intent(inout) :: qv, qc, qi, qs, th
5156 real(kind_phys), dimension(kte), intent(inout) :: dqv, dqc, dqi, dqs, dth
5157 integer k
5158 real(kind_phys):: dqc2, dqi2, dqs2, dqv2, sum, aa, dum
5159 real(kind_phys), parameter :: qvmin = 1e-20, &
5160 qcmin = 0.0, &
5161 qimin = 0.0
5162
5163 do k = kte, 1, -1 ! From the top to the surface
5164 dqc2 = max(0.0, qcmin-qc(k)) !qc deficit (>=0)
5165 dqi2 = max(0.0, qimin-qi(k)) !qi deficit (>=0)
5166 dqs2 = max(0.0, qimin-qs(k)) !qs deficit (>=0)
5167
5168 !fix tendencies
5169 dqc(k) = dqc(k) + dqc2/delt
5170 dqi(k) = dqi(k) + dqi2/delt
5171 dqs(k) = dqs(k) + dqs2/delt
5172 dqv(k) = dqv(k) - (dqc2+dqi2+dqs2)/delt
5173 dth(k) = dth(k) + xlvcp/exner(k)*(dqc2/delt) + &
5174 xlscp/exner(k)*((dqi2+dqs2)/delt)
5175 !update species
5176 qc(k) = qc(k) + dqc2
5177 qi(k) = qi(k) + dqi2
5178 qs(k) = qs(k) + dqs2
5179 qv(k) = qv(k) - dqc2 - dqi2 - dqs2
5180 th(k) = th(k) + xlvcp/exner(k)*dqc2 + &
5181 xlscp/exner(k)*(dqi2+dqs2)
5182
5183 !then fix qv
5184 dqv2 = max(0.0, qvmin-qv(k)) !qv deficit (>=0)
5185 dqv(k) = dqv(k) + dqv2/delt
5186 qv(k) = qv(k) + dqv2
5187 if( k .ne. 1 ) then
5188 qv(k-1) = qv(k-1) - dqv2*dp(k)/dp(k-1)
5189 dqv(k-1) = dqv(k-1) - dqv2*dp(k)/dp(k-1)/delt
5190 endif
5191 qv(k) = max(qv(k),qvmin)
5192 qc(k) = max(qc(k),qcmin)
5193 qi(k) = max(qi(k),qimin)
5194 qs(k) = max(qs(k),qimin)
5195 end do
5196 ! Extra moisture used to satisfy 'qv(1)>=qvmin' is proportionally
5197 ! extracted from all the layers that has 'qv > 2*qvmin'. This fully
5198 ! preserves column moisture.
5199 if( dqv2 .gt. 1.e-20 ) then
5200 sum = 0.0
5201 do k = 1, kte
5202 if( qv(k) .gt. 2.0*qvmin ) sum = sum + qv(k)*dp(k)
5203 enddo
5204 aa = dqv2*dp(1)/max(1.e-20,sum)
5205 if( aa .lt. 0.5 ) then
5206 do k = 1, kte
5207 if( qv(k) .gt. 2.0*qvmin ) then
5208 dum = aa*qv(k)
5209 qv(k) = qv(k) - dum
5210 dqv(k) = dqv(k) - dum/delt
5211 endif
5212 enddo
5213 else
5214 ! For testing purposes only (not yet found in any output):
5215 ! write(*,*) 'Full moisture conservation is impossible'
5216 endif
5217 endif
5218
5219 return
5220
5221 END SUBROUTINE moisture_check
5222
5223! ==================================================================
5224
5225 SUBROUTINE mynn_mix_chem(kts,kte,i, &
5226 delt,dz,pblh, &
5227 nchem, kdvel, ndvel, &
5228 chem1, vd1, &
5229 rho, &
5230 flt, tcd, qcd, &
5231 dfh, &
5232 s_aw, s_awchem, &
5233 emis_ant_no, frp, rrfs_sd, &
5234 enh_mix, smoke_dbg )
5235
5236!-------------------------------------------------------------------
5237 integer, intent(in) :: kts,kte,i
5238 real(kind_phys), dimension(kts:kte), intent(in) :: dfh,dz,tcd,qcd
5239 real(kind_phys), dimension(kts:kte), intent(inout) :: rho
5240 real(kind_phys), intent(in) :: flt
5241 real(kind_phys), intent(in) :: delt,pblh
5242 integer, intent(in) :: nchem, kdvel, ndvel
5243 real(kind_phys), dimension( kts:kte+1), intent(in) :: s_aw
5244 real(kind_phys), dimension( kts:kte, nchem ), intent(inout) :: chem1
5245 real(kind_phys), dimension( kts:kte+1,nchem), intent(in) :: s_awchem
5246 real(kind_phys), dimension( ndvel ), intent(in) :: vd1
5247 real(kind_phys), intent(in) :: emis_ant_no,frp
5248 logical, intent(in) :: rrfs_sd,enh_mix,smoke_dbg
5249!local vars
5250
5251 real(kind_phys), dimension(kts:kte) :: dtz
5252 real(kind_phys), dimension(kts:kte) :: a,b,c,d,x
5253 real(kind_phys):: rhs,dztop
5254 real(kind_phys):: t,dzk
5255 real(kind_phys):: hght
5256 real(kind_phys):: khdz_old, khdz_back
5257 integer :: k,kk,kmaxfire ! JLS 12/21/21
5258 integer :: ic ! Chemical array loop index
5259
5260 integer, SAVE :: icall
5261
5262 real(kind_phys), dimension(kts:kte) :: rhoinv
5263 real(kind_phys), dimension(kts:kte+1) :: rhoz,khdz
5264 real(kind_phys), parameter :: NO_threshold = 10.0 ! For anthropogenic sources
5265 real(kind_phys), parameter :: frp_threshold = 10.0 ! RAR 02/11/22: I increased the frp threshold to enhance mixing over big fires
5266 real(kind_phys), parameter :: pblh_threshold = 100.0
5267
5268 dztop=.5*(dz(kte)+dz(kte-1))
5269
5270 DO k=kts,kte
5271 dtz(k)=delt/dz(k)
5272 ENDDO
5273
5274 !Prepare "constants" for diffusion equation.
5275 !khdz = rho*Kh/dz = rho*dfh
5276 rhoz(kts) =rho(kts)
5277 rhoinv(kts)=1./rho(kts)
5278 khdz(kts) =rhoz(kts)*dfh(kts)
5279
5280 DO k=kts+1,kte
5281 rhoz(k) =(rho(k)*dz(k-1) + rho(k-1)*dz(k))/(dz(k-1)+dz(k))
5282 rhoz(k) = max(rhoz(k),1e-4)
5283 rhoinv(k)=1./max(rho(k),1e-4)
5284 dzk = 0.5 *( dz(k)+dz(k-1) )
5285 khdz(k) = rhoz(k)*dfh(k)
5286 ENDDO
5287 rhoz(kte+1)=rhoz(kte)
5288 khdz(kte+1)=rhoz(kte+1)*dfh(kte)
5289
5290 !stability criteria for mf
5291 DO k=kts+1,kte-1
5292 khdz(k) = max(khdz(k), 0.5*s_aw(k))
5293 khdz(k) = max(khdz(k), -0.5*(s_aw(k)-s_aw(k+1)))
5294 ENDDO
5295
5296 !Enhanced mixing over fires
5297 IF ( rrfs_sd .and. enh_mix ) THEN
5298 DO k=kts+1,kte-1
5299 khdz_old = khdz(k)
5300 khdz_back = pblh * 0.15 / dz(k)
5301 !Modify based on anthropogenic emissions of NO and FRP
5302 IF ( pblh < pblh_threshold ) THEN
5303 IF ( emis_ant_no > no_threshold ) THEN
5304 khdz(k) = max(1.1*khdz(k),sqrt((emis_ant_no / no_threshold)) / dz(k) * rhoz(k)) ! JLS 12/21/21
5305! khdz(k) = MAX(khdz(k),khdz_back)
5306 ENDIF
5307 IF ( frp > frp_threshold ) THEN
5308 kmaxfire = ceiling(log(frp))
5309 khdz(k) = max(1.1*khdz(k), (1. - k/(kmaxfire*2.)) * ((log(frp))**2.- 2.*log(frp)) / dz(k)*rhoz(k)) ! JLS 12/21/21
5310! khdz(k) = MAX(khdz(k),khdz_back)
5311 ENDIF
5312 ENDIF
5313 ENDDO
5314 ENDIF
5315
5316 !============================================
5317 ! Patterned after mixing of water vapor in mynn_tendencies.
5318 !============================================
5319
5320 DO ic = 1,nchem
5321 k=kts
5322
5323 a(k)= -dtz(k)*khdz(k)*rhoinv(k)
5324 b(k)=1.+dtz(k)*(khdz(k+1)+khdz(k))*rhoinv(k) - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1)
5325 c(k)= -dtz(k)*khdz(k+1)*rhoinv(k) - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1)
5326 d(k)=chem1(k,ic) & !dtz(k)*flt !neglecting surface sources
5327 & - dtz(k)*vd1(ic)*chem1(k,ic) &
5328 & - dtz(k)*rhoinv(k)*s_awchem(k+1,ic)
5329
5330 DO k=kts+1,kte-1
5331 a(k)= -dtz(k)*khdz(k)*rhoinv(k) + 0.5*dtz(k)*rhoinv(k)*s_aw(k)
5332 b(k)=1.+dtz(k)*(khdz(k)+khdz(k+1))*rhoinv(k) + &
5333 & 0.5*dtz(k)*rhoinv(k)*(s_aw(k)-s_aw(k+1))
5334 c(k)= -dtz(k)*khdz(k+1)*rhoinv(k) - 0.5*dtz(k)*rhoinv(k)*s_aw(k+1)
5335 d(k)=chem1(k,ic) + dtz(k)*rhoinv(k)*(s_awchem(k,ic)-s_awchem(k+1,ic))
5336 ENDDO
5337
5338 ! prescribed value at top
5339 a(kte)=0.
5340 b(kte)=1.
5341 c(kte)=0.
5342 d(kte)=chem1(kte,ic)
5343
5344 CALL tridiag3(kte,a,b,c,d,x)
5345
5346 IF ( smoke_dbg ) THEN
5347 print*,'aerosol mixing ic,chem1,chem2(k,ic)',ic,(chem1(kts:kts+10,ic)),(x(kts:kts+10))
5348 print*,'aerosol PBL mixing ic,vd1(ic)',ic,vd1(ic)
5349 END IF
5350
5351 DO k=kts,kte
5352 chem1(k,ic)=x(k)
5353 ENDDO
5354 ENDDO
5355
5356 END SUBROUTINE mynn_mix_chem
5357
5358! ==================================================================
5360 SUBROUTINE retrieve_exchange_coeffs(kts,kte,&
5361 &dfm,dfh,dz,K_m,K_h)
5362
5363!-------------------------------------------------------------------
5364
5365 integer , intent(in) :: kts,kte
5366
5367 real(kind_phys), dimension(KtS:KtE), intent(in) :: dz,dfm,dfh
5368
5369 real(kind_phys), dimension(KtS:KtE), intent(out) :: K_m, K_h
5370
5371
5372 integer :: k
5373 real(kind_phys):: dzk
5374
5375 k_m(kts)=0.
5376 k_h(kts)=0.
5377
5378 DO k=kts+1,kte
5379 dzk = 0.5 *( dz(k)+dz(k-1) )
5380 k_m(k)=dfm(k)*dzk
5381 k_h(k)=dfh(k)*dzk
5382 ENDDO
5383
5384 END SUBROUTINE retrieve_exchange_coeffs
5385
5386! ==================================================================
5388 SUBROUTINE tridiag(n,a,b,c,d)
5389
5390!! to solve system of linear eqs on tridiagonal matrix n times n
5391!! after Peaceman and Rachford, 1955
5392!! a,b,c,d - are vectors of order n
5393!! a,b,c - are coefficients on the LHS
5394!! d - is initially RHS on the output becomes a solution vector
5395
5396!-------------------------------------------------------------------
5397
5398 integer, intent(in):: n
5399 real(kind_phys), dimension(n), intent(in) :: a,b
5400 real(kind_phys), dimension(n), intent(inout) :: c,d
5401
5402 integer :: i
5403 real(kind_phys):: p
5404 real(kind_phys), dimension(n) :: q
5405
5406 c(n)=0.
5407 q(1)=-c(1)/b(1)
5408 d(1)=d(1)/b(1)
5409
5410 DO i=2,n
5411 p=1./(b(i)+a(i)*q(i-1))
5412 q(i)=-c(i)*p
5413 d(i)=(d(i)-a(i)*d(i-1))*p
5414 ENDDO
5415
5416 DO i=n-1,1,-1
5417 d(i)=d(i)+q(i)*d(i+1)
5418 ENDDO
5419
5420 END SUBROUTINE tridiag
5421
5422! ==================================================================
5424 subroutine tridiag2(n,a,b,c,d,x)
5425 implicit none
5426! a - sub-diagonal (means it is the diagonal below the main diagonal)
5427! b - the main diagonal
5428! c - sup-diagonal (means it is the diagonal above the main diagonal)
5429! d - right part
5430! x - the answer
5431! n - number of unknowns (levels)
5432
5433 integer,intent(in) :: n
5434 real(kind_phys), dimension(n), intent(in) :: a,b,c,d
5435 real(kind_phys), dimension(n), intent(out):: x
5436 real(kind_phys), dimension(n) :: cp,dp
5437 real(kind_phys):: m
5438 integer :: i
5439
5440 ! initialize c-prime and d-prime
5441 cp(1) = c(1)/b(1)
5442 dp(1) = d(1)/b(1)
5443 ! solve for vectors c-prime and d-prime
5444 do i = 2,n
5445 m = b(i)-cp(i-1)*a(i)
5446 cp(i) = c(i)/m
5447 dp(i) = (d(i)-dp(i-1)*a(i))/m
5448 enddo
5449 ! initialize x
5450 x(n) = dp(n)
5451 ! solve for x from the vectors c-prime and d-prime
5452 do i = n-1, 1, -1
5453 x(i) = dp(i)-cp(i)*x(i+1)
5454 end do
5455
5456 end subroutine tridiag2
5457! ==================================================================
5459 subroutine tridiag3(kte,a,b,c,d,x)
5460
5461!ccccccccccccccccccccccccccccccc
5462! Aim: Inversion and resolution of a tridiagonal matrix
5463! A X = D
5464! Input:
5465! a(*) lower diagonal (Ai,i-1)
5466! b(*) principal diagonal (Ai,i)
5467! c(*) upper diagonal (Ai,i+1)
5468! d
5469! Output
5470! x results
5471!ccccccccccccccccccccccccccccccc
5472
5473 implicit none
5474 integer,intent(in) :: kte
5475 integer, parameter :: kts=1
5476 real(kind_phys), dimension(kte) :: a,b,c,d
5477 real(kind_phys), dimension(kte), intent(out) :: x
5478 integer :: in
5479
5480! integer kms,kme,kts,kte,in
5481! real(kind_phys)a(kms:kme,3),c(kms:kme),x(kms:kme)
5482
5483 do in=kte-1,kts,-1
5484 d(in)=d(in)-c(in)*d(in+1)/b(in+1)
5485 b(in)=b(in)-c(in)*a(in+1)/b(in+1)
5486 enddo
5487
5488 do in=kts+1,kte
5489 d(in)=d(in)-a(in)*d(in-1)/b(in-1)
5490 enddo
5491
5492 do in=kts,kte
5493 x(in)=d(in)/b(in)
5494 enddo
5495
5496 return
5497 end subroutine tridiag3
5498
5499! ==================================================================
5519 SUBROUTINE get_pblh(KTS,KTE,zi,thetav1D,qke1D,zw1D,dz1D,landsea,kzi)
5520
5521 !---------------------------------------------------------------
5522 ! NOTES ON THE PBLH FORMULATION
5523 !
5524 !The 1.5-theta-increase method defines PBL heights as the level at
5525 !which the potential temperature first exceeds the minimum potential
5526 !temperature within the boundary layer by 1.5 K. When applied to
5527 !observed temperatures, this method has been shown to produce PBL-
5528 !height estimates that are unbiased relative to profiler-based
5529 !estimates (Nielsen-Gammon et al. 2008). However, their study did not
5530 !include LLJs. Banta and Pichugina (2008) show that a TKE-based
5531 !threshold is a good estimate of the PBL height in LLJs. Therefore,
5532 !a hybrid definition is implemented that uses both methods, weighting
5533 !the TKE-method more during stable conditions (PBLH < 400 m).
5534 !A variable tke threshold (TKEeps) is used since no hard-wired
5535 !value could be found to work best in all conditions.
5536 !---------------------------------------------------------------
5537
5538 integer,intent(in) :: KTS,KTE
5539
5540#ifdef HARDCODE_VERTICAL
5541# define kts 1
5542# define kte HARDCODE_VERTICAL
5543#endif
5544
5545 real(kind_phys), intent(out) :: zi
5546 real(kind_phys), intent(in) :: landsea
5547 real(kind_phys), dimension(kts:kte), intent(in) :: thetav1D, qke1D, dz1D
5548 real(kind_phys), dimension(kts:kte+1), intent(in) :: zw1D
5549 !LOCAL VARS
5550 real(kind_phys):: PBLH_TKE,qtke,qtkem1,wt,maxqke,TKEeps,minthv
5551 real(kind_phys):: delt_thv !delta theta-v; dependent on land/sea point
5552 real(kind_phys), parameter :: sbl_lim = 200. !upper limit of stable BL height (m).
5553 real(kind_phys), parameter :: sbl_damp = 400. !transition length for blending (m).
5554 integer :: I,J,K,kthv,ktke,kzi
5555
5556 !Initialize KPBL (kzi)
5557 kzi = 2
5558
5560 k = kts+1
5561 kthv = 1
5562 minthv = 9.e9
5563 DO WHILE (zw1d(k) .LE. 200.)
5564 !DO k=kts+1,kte-1
5565 IF (minthv > thetav1d(k)) then
5566 minthv = thetav1d(k)
5567 kthv = k
5568 ENDIF
5569 k = k+1
5570 !IF (zw1D(k) .GT. sbl_lim) exit
5571 ENDDO
5572
5574 zi=0.
5575 k = kthv+1
5576 IF((landsea-1.5).GE.0)THEN
5577 ! WATER
5578 delt_thv = 1.0
5579 ELSE
5580 ! LAND
5581 delt_thv = 1.25
5582 ENDIF
5583
5584 zi=0.
5585 k = kthv+1
5586! DO WHILE (zi .EQ. 0.)
5587 DO k=kts+1,kte-1
5588 IF (thetav1d(k) .GE. (minthv + delt_thv))THEN
5589 zi = zw1d(k) - dz1d(k-1)* &
5590 & min((thetav1d(k)-(minthv + delt_thv))/ &
5591 & max(thetav1d(k)-thetav1d(k-1),1e-6),1.0)
5592 ENDIF
5593 !k = k+1
5594 IF (k .EQ. kte-1) zi = zw1d(kts+1) !EXIT SAFEGUARD
5595 IF (zi .NE. 0.0) exit
5596 ENDDO
5597 !print*,"IN GET_PBLH:",thsfc,zi
5598
5603 ktke = 1
5604 maxqke = max(qke1d(kts),0.)
5605 !Use 5% of tke max (Kosovic and Curry, 2000; JAS)
5606 !TKEeps = maxtke/20. = maxqke/40.
5607 tkeeps = maxqke/40.
5608 tkeeps = max(tkeeps,0.02) !0.025)
5609 pblh_tke=0.
5610
5611 k = ktke+1
5612! DO WHILE (PBLH_TKE .EQ. 0.)
5613 DO k=kts+1,kte-1
5614 !QKE CAN BE NEGATIVE (IF CKmod == 0)... MAKE TKE NON-NEGATIVE.
5615 qtke =max(qke1d(k)/2.,0.) ! maximum TKE
5616 qtkem1=max(qke1d(k-1)/2.,0.)
5617 IF (qtke .LE. tkeeps) THEN
5618 pblh_tke = zw1d(k) - dz1d(k-1)* &
5619 & min((tkeeps-qtke)/max(qtkem1-qtke, 1e-6), 1.0)
5620 !IN CASE OF NEAR ZERO TKE, SET PBLH = LOWEST LEVEL.
5621 pblh_tke = max(pblh_tke,zw1d(kts+1))
5622 !print *,"PBLH_TKE:",i,PBLH_TKE, Qke1D(k)/2., zw1D(kts+1)
5623 ENDIF
5624 !k = k+1
5625 IF (k .EQ. kte-1) pblh_tke = zw1d(kts+1) !EXIT SAFEGUARD
5626 IF (pblh_tke .NE. 0.) exit
5627 ENDDO
5628
5635 pblh_tke = min(pblh_tke,zi+350.)
5636 pblh_tke = max(pblh_tke,max(zi-350.,10.))
5637
5638 wt=.5*tanh((zi - sbl_lim)/sbl_damp) + .5
5639 IF (maxqke <= 0.05) THEN
5640 !Cold pool situation - default to theta_v-based def
5641 ELSE
5642 !BLEND THE TWO PBLH TYPES HERE:
5643 zi=pblh_tke*(1.-wt) + zi*wt
5644 ENDIF
5645
5646 !Compute KPBL (kzi)
5647 DO k=kts+1,kte-1
5648 IF ( zw1d(k) >= zi) THEN
5649 kzi = k-1
5650 exit
5651 ENDIF
5652 ENDDO
5653
5654#ifdef HARDCODE_VERTICAL
5655# undef kts
5656# undef kte
5657#endif
5658
5659 END SUBROUTINE get_pblh
5661
5662! ==================================================================
5681 SUBROUTINE dmp_mf( &
5682 & kts,kte,dt,zw,dz,p,rho, &
5683 & momentum_opt, &
5684 & tke_opt, &
5685 & scalar_opt, &
5686 & u,v,w,th,thl,thv,tk, &
5687 & qt,qv,qc,qke, &
5688 & qnc,qni,qnwfa,qnifa,qnbca, &
5689 & exner,vt,vq,sgm, &
5690 & ust,flt,fltv,flq,flqv, &
5691 & pblh,kpbl,dx,landsea,ts, &
5692 ! outputs - updraft properties
5693 & edmf_a,edmf_w, &
5694 & edmf_qt,edmf_thl, &
5695 & edmf_ent,edmf_qc, &
5696 ! outputs - variables needed for solver
5697 & s_aw,s_awthl,s_awqt, &
5698 & s_awqv,s_awqc, &
5699 & s_awu,s_awv,s_awqke, &
5700 & s_awqnc,s_awqni, &
5701 & s_awqnwfa,s_awqnifa, &
5702 & s_awqnbca, &
5703 & sub_thl,sub_sqv, &
5704 & sub_u,sub_v, &
5705 & det_thl,det_sqv,det_sqc, &
5706 & det_u,det_v, &
5707 ! chem/smoke
5708 & nchem,chem1,s_awchem, &
5709 & mix_chem, &
5710 ! in/outputs - subgrid scale clouds
5711 & qc_bl1d,cldfra_bl1d, &
5712 & qc_bl1D_old,cldfra_bl1D_old, &
5713 ! inputs - flags for moist arrays
5714 & F_QC,F_QI, &
5715 & F_QNC,F_QNI, &
5716 & F_QNWFA,F_QNIFA,F_QNBCA, &
5717 & Psig_shcu, &
5718 ! output info
5719 & maxwidth,ktop,maxmf,ztop, &
5720 ! inputs for stochastic perturbations
5721 & spp_pbl,rstoch_col )
5722
5723 ! inputs:
5724 integer, intent(in) :: KTS,KTE,KPBL,momentum_opt,tke_opt,scalar_opt
5725
5726#ifdef HARDCODE_VERTICAL
5727# define kts 1
5728# define kte HARDCODE_VERTICAL
5729#endif
5730
5731! Stochastic
5732 integer, intent(in) :: spp_pbl
5733 real(kind_phys), dimension(kts:kte) :: rstoch_col
5734
5735 real(kind_phys),dimension(kts:kte), intent(in) :: &
5736 &U,V,W,TH,THL,TK,QT,QV,QC, &
5737 &exner,dz,THV,P,rho,qke,qnc,qni,qnwfa,qnifa,qnbca
5738 real(kind_phys),dimension(kts:kte+1), intent(in) :: zw !height at full-sigma
5739 real(kind_phys), intent(in) :: flt,fltv,flq,flqv,Psig_shcu, &
5740 &landsea,ts,dx,dt,ust,pblh
5741 logical, optional :: F_QC,F_QI,F_QNC,F_QNI,F_QNWFA,F_QNIFA,F_QNBCA
5742
5743 ! outputs - updraft properties
5744 real(kind_phys),dimension(kts:kte), intent(out) :: edmf_a,edmf_w, &
5745 & edmf_qt,edmf_thl,edmf_ent,edmf_qc
5746 !add one local edmf variable:
5747 real(kind_phys),dimension(kts:kte) :: edmf_th
5748 ! output
5749 integer, intent(out) :: ktop
5750 real(kind_phys), intent(out) :: maxmf,ztop,maxwidth
5751 ! outputs - variables needed for solver
5752 real(kind_phys),dimension(kts:kte+1) :: s_aw, & !sum ai*rho*wis_awphi
5753 &s_awthl,s_awqt,s_awqv,s_awqc,s_awqnc,s_awqni, &
5754 &s_awqnwfa,s_awqnifa,s_awqnbca,s_awu,s_awv, &
5755 &s_awqke,s_aw2
5756
5757 real(kind_phys),dimension(kts:kte), intent(inout) :: &
5758 &qc_bl1d,cldfra_bl1d,qc_bl1d_old,cldfra_bl1d_old
5759
5760 integer, parameter :: nup=8, debug_mf=0
5761 real(kind_phys) :: nup2
5762
5763 !------------- local variables -------------------
5764 ! updraft properties defined on interfaces (k=1 is the top of the
5765 ! first model layer
5766 real(kind_phys),dimension(kts:kte+1,1:NUP) :: &
5767 &UPW,UPTHL,UPQT,UPQC,UPQV, &
5768 &UPA,UPU,UPV,UPTHV,UPQKE,UPQNC, &
5769 &UPQNI,UPQNWFA,UPQNIFA,UPQNBCA
5770 ! entrainment variables
5771 real(kind_phys),dimension(kts:kte,1:NUP) :: ENT,ENTf
5772 integer,dimension(kts:kte,1:NUP) :: ENTi
5773 ! internal variables
5774 integer :: K,I,k50
5775 real(kind_phys):: fltv2,wstar,qstar,thstar,sigmaW,sigmaQT, &
5776 &sigmaTH,z0,pwmin,pwmax,wmin,wmax,wlv,Psig_w,maxw,maxqc,wpbl
5777 real(kind_phys):: B,QTn,THLn,THVn,QCn,Un,Vn,QKEn,QNCn,QNIn, &
5778 & QNWFAn,QNIFAn,QNBCAn, &
5779 & Wn2,Wn,EntEXP,EntEXM,EntW,BCOEFF,THVkm1,THVk,Pk,rho_int
5780
5781 ! w parameters
5782 real(kind_phys), parameter :: &
5783 &Wa=2./3., &
5784 &Wb=0.002, &
5785 &Wc=1.5
5786
5787 ! Lateral entrainment parameters ( L0=100 and ENT0=0.1) were taken from
5788 ! Suselj et al (2013, jas). Note that Suselj et al (2014,waf) use L0=200 and ENT0=0.2.
5789 real(kind_phys),parameter :: &
5790 & L0=100., &
5791 & ENT0=0.1
5792
5793 ! Parameters/variables for regulating plumes:
5794 real(kind_phys), parameter :: Atot = 0.10 ! Maximum total fractional area of all updrafts
5795 real(kind_phys), parameter :: lmax = 1000.! diameter of largest plume (absolute maximum, can be smaller)
5796 real(kind_phys), parameter :: lmin = 300. ! diameter of smallest plume (absolute minimum, can be larger)
5797 real(kind_phys), parameter :: dlmin = 0. ! delta increase in the diameter of smallest plume (large fltv)
5798 real(kind_phys) :: minwidth ! actual width of smallest plume
5799 real(kind_phys) :: dl ! variable increment of plume size
5800 real(kind_phys), parameter :: dcut = 1.2 ! max diameter of plume to parameterize relative to dx (km)
5801 real(kind_phys):: d != -2.3 to -1.7 ;=-1.9 in Neggers paper; power law exponent for number density (N=Cl^d).
5802 ! Note that changing d to -2.0 makes each size plume equally contribute to the total coverage of all plumes.
5803 ! Note that changing d to -1.7 doubles the area coverage of the largest plumes relative to the smallest plumes.
5804 real(kind_phys):: cn,c,l,n,an2,hux,wspd_pbl,cloud_base,width_flx
5805
5806 ! chem/smoke
5807 integer, intent(in) :: nchem
5808 real(kind_phys),dimension(:, :) :: chem1
5809 real(kind_phys),dimension(kts:kte+1, nchem) :: s_awchem
5810 real(kind_phys),dimension(nchem) :: chemn
5811 real(kind_phys),dimension(kts:kte+1,1:NUP, nchem) :: UPCHEM
5812 integer :: ic
5813 real(kind_phys),dimension(kts:kte+1, nchem) :: edmf_chem
5814 logical, intent(in) :: mix_chem
5815
5816 !JOE: add declaration of ERF
5817 real(kind_phys):: ERF
5818
5819 logical :: superadiabatic
5820
5821 ! VARIABLES FOR CHABOUREAU-BECHTOLD CLOUD FRACTION
5822 real(kind_phys),dimension(kts:kte), intent(inout) :: vt, vq, sgm
5823 real(kind_phys):: sigq,xl,rsl,cpm,a,qmq,mf_cf,Aup,Q1,diffqt,qsat_tk,&
5824 Fng,qww,alpha,beta,bb,f,pt,t,q2p,b9,satvp,rhgrid, &
5825 Ac_mf,Ac_strat,qc_mf
5826 real(kind_phys), parameter :: cf_thresh = 0.5 ! only overwrite stratus CF less than this value
5827
5828 ! Variables for plume interpolation/saturation check
5829 real(kind_phys),dimension(kts:kte) :: exneri,dzi,rhoz
5830 real(kind_phys):: THp, QTp, QCp, QCs, esat, qsl
5831 real(kind_phys):: csigma,acfac,ac_wsp
5832
5833 !plume overshoot
5834 integer :: overshoot
5835 real(kind_phys):: bvf, Frz, dzp
5836
5837 !Flux limiter: not let mass-flux of heat between k=1&2 exceed (fluxportion)*(surface heat flux).
5838 !This limiter makes adjustments to the entire column.
5839 real(kind_phys):: adjustment, flx1
5840 real(kind_phys), parameter :: fluxportion=0.75 ! set liberally, so has minimal impact. Note that
5841 ! 0.5 starts to have a noticeable impact
5842 ! over land (decrease maxMF by 10-20%), but no impact over water.
5843
5844 !Subsidence
5845 real(kind_phys),dimension(kts:kte) :: sub_thl,sub_sqv,sub_u,sub_v, & !tendencies due to subsidence
5846 det_thl,det_sqv,det_sqc,det_u,det_v, & !tendencied due to detrainment
5847 envm_a,envm_w,envm_thl,envm_sqv,envm_sqc, &
5848 envm_u,envm_v !environmental variables defined at middle of layer
5849 real(kind_phys),dimension(kts:kte+1) :: envi_a,envi_w !environmental variables defined at model interface
5850 real(kind_phys):: temp,sublim,qc_ent,qv_ent,qt_ent,thl_ent,detrate, &
5851 detrateUV,oow,exc_fac,aratio,detturb,qc_grid,qc_sgs, &
5852 qc_plume,exc_heat,exc_moist,tk_int,tvs
5853 real(kind_phys), parameter :: Cdet = 1./45.
5854 real(kind_phys), parameter :: dzpmax = 300. !limit dz used in detrainment - can be excessing in thick layers
5855 !parameter "Csub" determines the propotion of upward vertical velocity that contributes to
5856 !environmenatal subsidence. Some portion is expected to be compensated by downdrafts instead of
5857 !gentle environmental subsidence. 1.0 assumes all upward vertical velocity in the mass-flux scheme
5858 !is compensated by "gentle" environmental subsidence.
5859 real(kind_phys), parameter :: Csub=0.25
5860
5861 !Factor for the pressure gradient effects on momentum transport
5862 real(kind_phys), parameter :: pgfac = 0.00 ! Zhang and Wu showed 0.4 is more appropriate for lower troposphere
5863 real(kind_phys):: Uk,Ukm1,Vk,Vkm1,dxsa
5864
5865! check the inputs
5866! print *,'dt',dt
5867! print *,'dz',dz
5868! print *,'u',u
5869! print *,'v',v
5870! print *,'thl',thl
5871! print *,'qt',qt
5872! print *,'ust',ust
5873! print *,'flt',flt
5874! print *,'flq',flq
5875! print *,'pblh',pblh
5876
5877! Initialize individual updraft properties
5878 upw=0.
5879 upthl=0.
5880 upthv=0.
5881 upqt=0.
5882 upa=0.
5883 upu=0.
5884 upv=0.
5885 upqc=0.
5886 upqv=0.
5887 upqke=0.
5888 upqnc=0.
5889 upqni=0.
5890 upqnwfa=0.
5891 upqnifa=0.
5892 upqnbca=0.
5893 if ( mix_chem ) then
5894 upchem(kts:kte+1,1:nup,1:nchem)=0.0
5895 endif
5896
5897 ent=0.001
5898! Initialize mean updraft properties
5899 edmf_a =0.
5900 edmf_w =0.
5901 edmf_qt =0.
5902 edmf_thl=0.
5903 edmf_ent=0.
5904 edmf_qc =0.
5905 if ( mix_chem ) then
5906 edmf_chem(kts:kte+1,1:nchem) = 0.0
5907 endif
5908
5909! Initialize the variables needed for implicit solver
5910 s_aw=0.
5911 s_awthl=0.
5912 s_awqt=0.
5913 s_awqv=0.
5914 s_awqc=0.
5915 s_awu=0.
5916 s_awv=0.
5917 s_awqke=0.
5918 s_awqnc=0.
5919 s_awqni=0.
5920 s_awqnwfa=0.
5921 s_awqnifa=0.
5922 s_awqnbca=0.
5923 if ( mix_chem ) then
5924 s_awchem(kts:kte+1,1:nchem) = 0.0
5925 endif
5926
5927! Initialize explicit tendencies for subsidence & detrainment
5928 sub_thl = 0.
5929 sub_sqv = 0.
5930 sub_u = 0.
5931 sub_v = 0.
5932 det_thl = 0.
5933 det_sqv = 0.
5934 det_sqc = 0.
5935 det_u = 0.
5936 det_v = 0.
5937 nup2 = nup !start with nup, but set to zero if activation criteria fails
5938
5939 ! Taper off MF scheme when significant resolved-scale motions
5940 ! are present This function needs to be asymetric...
5941 maxw = 0.0
5942 cloud_base = 9000.0
5943 do k=1,kte-1
5944 if (zw(k) > pblh + 500.) exit
5945
5946 wpbl = w(k)
5947 if (w(k) < 0.)wpbl = 2.*w(k)
5948 maxw = max(maxw,abs(wpbl))
5949
5950 !Find highest k-level below 50m AGL
5951 if (zw(k)<=50.)k50=k
5952
5953 !Search for cloud base
5954 qc_sgs = max(qc(k), qc_bl1d(k))
5955 if (qc_sgs> 1e-5 .and. (cldfra_bl1d(k) .ge. 0.5) .and. cloud_base == 9000.0) then
5956 cloud_base = 0.5*(zw(k)+zw(k+1))
5957 endif
5958 enddo
5959
5960 !do nothing for small w (< 1 m/s), but linearly taper off for w > 1.0 m/s
5961 maxw = max(0.,maxw - 1.0)
5962 psig_w = max(0.0, 1.0 - maxw)
5963 psig_w = min(psig_w, psig_shcu)
5964
5965 !Completely shut off MF scheme for strong resolved-scale vertical velocities.
5966 fltv2 = fltv
5967 if(psig_w == 0.0 .and. fltv > 0.0) fltv2 = -1.*fltv
5968
5969 ! If surface buoyancy is positive we do integration, otherwise no.
5970 ! Also, ensure that it is at least slightly superadiabatic up through 50 m
5971 superadiabatic = .false.
5972 if ((landsea-1.5).ge.0) then
5973 hux = -0.001 ! WATER ! dT/dz must be < - 0.1 K per 100 m.
5974 else
5975 hux = -0.005 ! LAND ! dT/dz must be < - 0.5 K per 100 m.
5976 endif
5977 tvs = ts*(1.0+p608*qv(kts))
5978 do k=1,max(1,k50-1) !use "-1" because k50 used interface heights (zw).
5979 if (k == 1) then
5980 if ((thv(k)-tvs)/(0.5*dz(k)) < hux) then
5981 superadiabatic = .true.
5982 else
5983 superadiabatic = .false.
5984 exit
5985 endif
5986 else
5987 if ((thv(k)-thv(k-1))/(0.5*(dz(k)+dz(k-1))) < hux) then
5988 superadiabatic = .true.
5989 else
5990 superadiabatic = .false.
5991 exit
5992 endif
5993 endif
5994 enddo
5995
5996 ! Determine the numer of updrafts/plumes in the grid column:
5997 ! Some of these criteria may be a little redundant but useful for bullet-proofing.
5998 ! (1) largest plume = 1.2 * dx.
5999 ! (2) Apply a scale-break, assuming no plumes with diameter larger than 1.1*PBLH can exist.
6000 ! (3) max plume size beneath clouds deck approx = 0.5 * cloud_base.
6001 ! (4) add wspd-dependent limit, when plume model breaks down. (hurricanes)
6002 ! (5) limit to reduce max plume sizes in weakly forced conditions. This is only
6003 ! meant to "soften" the activation of the mass-flux scheme.
6004 ! Criteria (1)
6005 maxwidth = min(dx*dcut, lmax)
6006 !Criteria (2)
6007 maxwidth = min(maxwidth, 1.1_kind_phys*pblh)
6008 ! Criteria (3)
6009 if ((landsea-1.5) .lt. 0) then !land
6010 maxwidth = min(maxwidth, 0.5_kind_phys*cloud_base)
6011 else !water
6012 maxwidth = min(maxwidth, 0.9_kind_phys*cloud_base)
6013 endif
6014 ! Criteria (4)
6015 wspd_pbl=sqrt(max(u(kts)**2 + v(kts)**2, 0.01_kind_phys))
6016 !Note: area fraction (acfac) is modified below
6017 ! Criteria (5) - only a function of flt (not fltv)
6018 if ((landsea-1.5).LT.0) then !land
6019 width_flx = max(min(1000.*(0.6*tanh((fltv - 0.040)/0.04) + .5),1000._kind_phys), 0._kind_phys)
6020 else !water
6021 width_flx = max(min(1000.*(0.6*tanh((fltv - 0.007)/0.02) + .5),1000._kind_phys), 0._kind_phys)
6022 endif
6023 maxwidth = min(maxwidth, width_flx)
6024 minwidth = lmin
6025 !allow min plume size to increase in large flux conditions (eddy diffusivity should be
6026 !large enough to handle the representation of small plumes).
6027 if (maxwidth .ge. (lmax - 1.0) .and. fltv .gt. 0.2)minwidth = lmin + dlmin*min((fltv-0.2)/0.3, 1._kind_phys)
6028
6029 if (maxwidth .le. minwidth) then ! deactivate MF component
6030 nup2 = 0
6031 maxwidth = 0.0
6032 endif
6033
6034 ! Initialize values for 2d output fields:
6035 ktop = 0
6036 ztop = 0.0
6037 maxmf= 0.0
6038
6039!Begin plume processing if passes criteria
6040if ( fltv2 > 0.002 .AND. (maxwidth > minwidth) .AND. superadiabatic) then
6041
6042 ! Find coef C for number size density N
6043 cn = 0.
6044 d =-1.9 !set d to value suggested by Neggers 2015 (JAMES).
6045 dl = (maxwidth - minwidth)/real(nup-1,kind=kind_phys)
6046 do i=1,nup
6047 ! diameter of plume
6048 l = minwidth + dl*real(i-1)
6049 cn = cn + l**d * (l*l)/(dx*dx) * dl ! sum fractional area of each plume
6050 enddo
6051 c = atot/cn !Normalize C according to the defined total fraction (Atot)
6052
6053 ! Make updraft area (UPA) a function of the buoyancy flux
6054 if ((landsea-1.5).LT.0) then !land
6055 acfac = .5*tanh((fltv2 - 0.02)/0.05) + .5
6056 else !water
6057 acfac = .5*tanh((fltv2 - 0.01)/0.03) + .5
6058 endif
6059 !add a windspeed-dependent adjustment to acfac that tapers off
6060 !the mass-flux scheme linearly above sfc wind speeds of 10 m/s.
6061 !Note: this effect may be better represented by an increase in
6062 !entrainment rate for high wind consitions (more ambient turbulence).
6063 if (wspd_pbl .le. 10.) then
6064 ac_wsp = 1.0
6065 else
6066 ac_wsp = 1.0 - min((wspd_pbl - 10.0)/15., 1.0)
6067 endif
6068 acfac = acfac * ac_wsp
6069
6070 ! Find the portion of the total fraction (Atot) of each plume size:
6071 an2 = 0.
6072 do i=1,nup
6073 ! diameter of plume
6074 l = minwidth + dl*real(i-1)
6075 n = c*l**d ! number density of plume n
6076 upa(1,i) = n*l*l/(dx*dx) * dl ! fractional area of plume n
6077
6078 upa(1,i) = upa(1,i)*acfac
6079 an2 = an2 + upa(1,i) ! total fractional area of all plumes
6080 !print*," plume size=",l,"; area=",UPA(1,I),"; total=",An2
6081 end do
6082
6083 ! set initial conditions for updrafts
6084 z0=50.
6085 pwmin=0.1 ! was 0.5
6086 pwmax=0.4 ! was 3.0
6087
6088 wstar=max(1.e-2,(gtr*fltv2*pblh)**(onethird))
6089 qstar=max(flq,1.0e-5)/wstar
6090 thstar=flt/wstar
6091
6092 if ((landsea-1.5) .ge. 0) then
6093 csigma = 1.34 ! WATER
6094 else
6095 csigma = 1.34 ! LAND
6096 endif
6097
6098 if (env_subs) then
6099 exc_fac = 0.0
6100 else
6101 if ((landsea-1.5).GE.0) then
6102 !water: increase factor to compensate for decreased pwmin/pwmax
6103 exc_fac = 0.58*4.0
6104 else
6105 !land: no need to increase factor - already sufficiently large superadiabatic layers
6106 exc_fac = 0.58
6107 endif
6108 endif
6109 !decrease excess for large wind speeds
6110 exc_fac = exc_fac * ac_wsp
6111
6112 !Note: sigmaW is typically about 0.5*wstar
6113 sigmaw =csigma*wstar*(z0/pblh)**(onethird)*(1 - 0.8*z0/pblh)
6114 sigmaqt=csigma*qstar*(z0/pblh)**(onethird)
6115 sigmath=csigma*thstar*(z0/pblh)**(onethird)
6116
6117 !Note: Given the pwmin & pwmax set above, these max/mins are
6118 ! rarely exceeded.
6119 wmin=min(sigmaw*pwmin,0.1)
6120 wmax=min(sigmaw*pwmax,0.5)
6121
6122 !SPECIFY SURFACE UPDRAFT PROPERTIES AT MODEL INTERFACE BETWEEN K = 1 & 2
6123 do i=1,nup
6124 wlv=wmin+(wmax-wmin)/nup2*(i-1)
6125
6126 !SURFACE UPDRAFT VERTICAL VELOCITY
6127 upw(1,i)=wmin + real(i)/real(nup)*(wmax-wmin)
6128 upu(1,i)=(u(kts)*dz(kts+1)+u(kts+1)*dz(kts))/(dz(kts)+dz(kts+1))
6129 upv(1,i)=(v(kts)*dz(kts+1)+v(kts+1)*dz(kts))/(dz(kts)+dz(kts+1))
6130 upqc(1,i)=0.0
6131 !UPQC(1,I)=(QC(KTS)*DZ(KTS+1)+QC(KTS+1)*DZ(KTS))/(DZ(KTS)+DZ(KTS+1))
6132
6133 exc_heat = exc_fac*upw(1,i)*sigmath/sigmaw
6134 upthv(1,i)=(thv(kts)*dz(kts+1)+thv(kts+1)*dz(kts))/(dz(kts)+dz(kts+1)) &
6135 & + exc_heat
6136 upthl(1,i)=(thl(kts)*dz(kts+1)+thl(kts+1)*dz(kts))/(dz(kts)+dz(kts+1)) &
6137 & + exc_heat
6138
6139 !calculate exc_moist by use of surface fluxes
6140 exc_moist=exc_fac*upw(1,i)*sigmaqt/sigmaw
6141 upqt(1,i)=(qt(kts)*dz(kts+1)+qt(kts+1)*dz(kts))/(dz(kts)+dz(kts+1))&
6142 & +exc_moist
6143
6144 upqke(1,i)=(qke(kts)*dz(kts+1)+qke(kts+1)*dz(kts))/(dz(kts)+dz(kts+1))
6145 upqnc(1,i)=(qnc(kts)*dz(kts+1)+qnc(kts+1)*dz(kts))/(dz(kts)+dz(kts+1))
6146 upqni(1,i)=(qni(kts)*dz(kts+1)+qni(kts+1)*dz(kts))/(dz(kts)+dz(kts+1))
6147 upqnwfa(1,i)=(qnwfa(kts)*dz(kts+1)+qnwfa(kts+1)*dz(kts))/(dz(kts)+dz(kts+1))
6148 upqnifa(1,i)=(qnifa(kts)*dz(kts+1)+qnifa(kts+1)*dz(kts))/(dz(kts)+dz(kts+1))
6149 upqnbca(1,i)=(qnbca(kts)*dz(kts+1)+qnbca(kts+1)*dz(kts))/(dz(kts)+dz(kts+1))
6150 enddo
6151
6152 if ( mix_chem ) then
6153 do i=1,nup
6154 do ic = 1,nchem
6155 upchem(1,i,ic)=(chem1(kts,ic)*dz(kts+1)+chem1(kts+1,ic)*dz(kts))/(dz(kts)+dz(kts+1))
6156 enddo
6157 enddo
6158 endif
6159
6160 !Initialize environmental variables which can be modified by detrainment
6161 envm_thl(kts:kte)=thl(kts:kte)
6162 envm_sqv(kts:kte)=qv(kts:kte)
6163 envm_sqc(kts:kte)=qc(kts:kte)
6164 envm_u(kts:kte)=u(kts:kte)
6165 envm_v(kts:kte)=v(kts:kte)
6166 do k=kts,kte-1
6167 rhoz(k) = (rho(k)*dz(k+1)+rho(k+1)*dz(k))/(dz(k+1)+dz(k))
6168 enddo
6169 rhoz(kte) = rho(kte)
6170
6171 !dxsa is scale-adaptive factor governing the pressure-gradient term of the momentum transport
6172 dxsa = 1. - min(max((12000.0-dx)/(12000.0-3000.0), 0.), 1.)
6173
6174 ! do integration updraft
6175 do i=1,nup
6176 qcn = 0.
6177 overshoot = 0
6178 l = minwidth + dl*real(i-1) ! diameter of plume
6179 do k=kts+1,kte-1
6180 !Entrainment from Tian and Kuang (2016)
6181 !ENT(k,i) = 0.35/(MIN(MAX(UPW(K-1,I),0.75),1.9)*l)
6182 wmin = 0.3 + l*0.0005 !* MAX(pblh-ZW(k+1), 0.0)/pblh
6183 ent(k,i) = 0.33/(min(max(upw(k-1,i),wmin),0.9)*l)
6184
6185 !Entrainment from Negggers (2015, JAMES)
6186 !ENT(k,i) = 0.02*l**-0.35 - 0.0009
6187 !ENT(k,i) = 0.04*l**-0.50 - 0.0009 !more plume diversity
6188 !ENT(k,i) = 0.04*l**-0.495 - 0.0009 !"neg1+"
6189
6190 !Minimum background entrainment
6191 ent(k,i) = max(ent(k,i),0.0003)
6192 !ENT(k,i) = max(ENT(k,i),0.05/ZW(k)) !not needed for Tian and Kuang
6193
6194 !increase entrainment for plumes extending very high.
6195 IF(zw(k) >= min(pblh+1500., 4000.))THEN
6196 ent(k,i)=ent(k,i) + (zw(k)-min(pblh+1500.,4000.))*5.0e-6
6197 ENDIF
6198
6199 !SPP
6200 ent(k,i) = ent(k,i) * (1.0 - rstoch_col(k))
6201
6202 ent(k,i) = min(ent(k,i),0.9/(zw(k+1)-zw(k)))
6203
6204 ! Define environment U & V at the model interface levels
6205 uk =(u(k)*dz(k+1)+u(k+1)*dz(k))/(dz(k+1)+dz(k))
6206 ukm1=(u(k-1)*dz(k)+u(k)*dz(k-1))/(dz(k-1)+dz(k))
6207 vk =(v(k)*dz(k+1)+v(k+1)*dz(k))/(dz(k+1)+dz(k))
6208 vkm1=(v(k-1)*dz(k)+v(k)*dz(k-1))/(dz(k-1)+dz(k))
6209
6210 ! Linear entrainment:
6211 entexp= ent(k,i)*(zw(k+1)-zw(k))
6212 entexm= entexp*0.3333 !reduce entrainment for momentum
6213 qtn =upqt(k-1,i) *(1.-entexp) + qt(k)*entexp
6214 thln=upthl(k-1,i)*(1.-entexp) + thl(k)*entexp
6215 un =upu(k-1,i) *(1.-entexm) + u(k)*entexm + dxsa*pgfac*(uk - ukm1)
6216 vn =upv(k-1,i) *(1.-entexm) + v(k)*entexm + dxsa*pgfac*(vk - vkm1)
6217 qken=upqke(k-1,i)*(1.-entexp) + qke(k)*entexp
6218 qncn=upqnc(k-1,i)*(1.-entexp) + qnc(k)*entexp
6219 qnin=upqni(k-1,i)*(1.-entexp) + qni(k)*entexp
6220 qnwfan=upqnwfa(k-1,i)*(1.-entexp) + qnwfa(k)*entexp
6221 qnifan=upqnifa(k-1,i)*(1.-entexp) + qnifa(k)*entexp
6222 qnbcan=upqnbca(k-1,i)*(1.-entexp) + qnbca(k)*entexp
6223
6224 !capture the updated qc, qt & thl modified by entranment alone,
6225 !since they will be modified later if condensation occurs.
6226 qc_ent = qcn
6227 qt_ent = qtn
6228 thl_ent = thln
6229
6230 ! Exponential Entrainment:
6231 !EntExp= exp(-ENT(K,I)*(ZW(k)-ZW(k-1)))
6232 !QTn =QT(K) *(1-EntExp)+UPQT(K-1,I)*EntExp
6233 !THLn=THL(K)*(1-EntExp)+UPTHL(K-1,I)*EntExp
6234 !Un =U(K) *(1-EntExp)+UPU(K-1,I)*EntExp
6235 !Vn =V(K) *(1-EntExp)+UPV(K-1,I)*EntExp
6236 !QKEn=QKE(k)*(1-EntExp)+UPQKE(K-1,I)*EntExp
6237
6238 if ( mix_chem ) then
6239 do ic = 1,nchem
6240 ! Exponential Entrainment:
6241 !chemn(ic) = chem(k,ic)*(1-EntExp)+UPCHEM(K-1,I,ic)*EntExp
6242 ! Linear entrainment:
6243 chemn(ic)=upchem(k-1,i,ic)*(1.-entexp) + chem1(k,ic)*entexp
6244 enddo
6245 endif
6246
6247 ! Define pressure at model interface
6248 pk =(p(k)*dz(k+1)+p(k+1)*dz(k))/(dz(k+1)+dz(k))
6249 ! Compute plume properties thvn and qcn
6250 call condensation_edmf(qtn,thln,pk,zw(k+1),thvn,qcn)
6251
6252 ! Define environment THV at the model interface levels
6253 thvk =(thv(k)*dz(k+1)+thv(k+1)*dz(k))/(dz(k+1)+dz(k))
6254 thvkm1=(thv(k-1)*dz(k)+thv(k)*dz(k-1))/(dz(k-1)+dz(k))
6255
6256! B=g*(0.5*(THVn+UPTHV(k-1,I))/THV(k-1) - 1.0)
6257 b=grav*(thvn/thvk - 1.0)
6258 IF(b>0.)THEN
6259 bcoeff = 0.15 !w typically stays < 2.5, so doesnt hit the limits nearly as much
6260 ELSE
6261 bcoeff = 0.2 !0.33
6262 ENDIF
6263
6264 ! Original StEM with exponential entrainment
6265 !EntW=exp(-2.*(Wb+Wc*ENT(K,I))*(ZW(k)-ZW(k-1)))
6266 !Wn2=UPW(K-1,I)**2*EntW + (1.-EntW)*0.5*Wa*B/(Wb+Wc*ENT(K,I))
6267 ! Original StEM with linear entrainment
6268 !Wn2=UPW(K-1,I)**2*(1.-EntExp) + EntExp*0.5*Wa*B/(Wb+Wc*ENT(K,I))
6269 !Wn2=MAX(Wn2,0.0)
6270 !WA: TEMF form
6271! IF (B>0.0 .AND. UPW(K-1,I) < 0.2 ) THEN
6272 IF (upw(k-1,i) < 0.2 ) THEN
6273 wn = upw(k-1,i) + (-2. * ent(k,i) * upw(k-1,i) + bcoeff*b / max(upw(k-1,i),0.2)) * min(zw(k)-zw(k-1), 250.)
6274 ELSE
6275 wn = upw(k-1,i) + (-2. * ent(k,i) * upw(k-1,i) + bcoeff*b / upw(k-1,i)) * min(zw(k)-zw(k-1), 250.)
6276 ENDIF
6277 !Do not allow a parcel to accelerate more than 1.25 m/s over 200 m.
6278 !Add max increase of 2.0 m/s for coarse vertical resolution.
6279 IF(wn > upw(k-1,i) + min(1.25*(zw(k)-zw(k-1))/200., 2.0) ) THEN
6280 wn = upw(k-1,i) + min(1.25*(zw(k)-zw(k-1))/200., 2.0)
6281 ENDIF
6282 !Add symmetrical max decrease in w
6283 IF(wn < upw(k-1,i) - min(1.25*(zw(k)-zw(k-1))/200., 2.0) ) THEN
6284 wn = upw(k-1,i) - min(1.25*(zw(k)-zw(k-1))/200., 2.0)
6285 ENDIF
6286 wn = min(max(wn,0.0), 3.0)
6287
6288 !Check to make sure that the plume made it up at least one level.
6289 !if it failed, then set nup2=0 and exit the mass-flux portion.
6290 IF (k==kts+1 .AND. wn == 0.) THEN
6291 nup2=0
6292 exit
6293 ENDIF
6294
6295 IF (debug_mf == 1) THEN
6296 IF (wn .GE. 3.0) THEN
6297 ! surface values
6298 print *," **** SUSPICIOUSLY LARGE W:"
6299 print *,' QCn:',qcn,' ENT=',ent(k,i),' Nup2=',nup2
6300 print *,'pblh:',pblh,' Wn:',wn,' UPW(k-1)=',upw(k-1,i)
6301 print *,'K=',k,' B=',b,' dz=',zw(k)-zw(k-1)
6302 ENDIF
6303 ENDIF
6304
6305 !Allow strongly forced plumes to overshoot if KE is sufficient
6306 IF (wn <= 0.0 .AND. overshoot == 0) THEN
6307 overshoot = 1
6308 IF ( thvk-thvkm1 .GT. 0.0 ) THEN
6309 bvf = sqrt( gtr*(thvk-thvkm1)/dz(k) )
6310 !vertical Froude number
6311 frz = upw(k-1,i)/(bvf*dz(k))
6312 !IF ( Frz >= 0.5 ) Wn = MIN(Frz,1.0)*UPW(K-1,I)
6313 dzp = dz(k)*max(min(frz,1.0),0.0) ! portion of highest layer the plume penetrates
6314 ENDIF
6315 ELSE
6316 dzp = dz(k)
6317 ENDIF
6318
6319 !minimize the plume penetratration in stratocu-topped PBL
6320 !IF (fltv2 < 0.06) THEN
6321 ! IF(ZW(k+1) >= pblh-200. .AND. qc(k) > 1e-5 .AND. I > 4) Wn=0.
6322 !ENDIF
6323
6324 !Modify environment variables (representative of the model layer - envm*)
6325 !following the updraft dynamical detrainment of Asai and Kasahara (1967, JAS).
6326 !Reminder: w is limited to be non-negative (above)
6327 aratio = min(upa(k-1,i)/(1.-upa(k-1,i)), 0.5) !limit should never get hit
6328 detturb = 0.00008
6329 oow = -0.060/max(1.0,(0.5*(wn+upw(k-1,i)))) !coef for dynamical detrainment rate
6330 detrate = min(max(oow*(wn-upw(k-1,i))/dz(k), detturb), .0002) ! dynamical detrainment rate (m^-1)
6331 detrateuv= min(max(oow*(wn-upw(k-1,i))/dz(k), detturb), .0001) ! dynamical detrainment rate (m^-1)
6332 envm_thl(k)=envm_thl(k) + (0.5*(thl_ent + upthl(k-1,i)) - thl(k))*detrate*aratio*min(dzp,dzpmax)
6333 qv_ent = 0.5*(max(qt_ent-qc_ent,0.) + max(upqt(k-1,i)-upqc(k-1,i),0.))
6334 envm_sqv(k)=envm_sqv(k) + (qv_ent-qv(k))*detrate*aratio*min(dzp,dzpmax)
6335 IF (upqc(k-1,i) > 1e-8) THEN
6336 IF (qc(k) > 1e-6) THEN
6337 qc_grid = qc(k)
6338 ELSE
6339 qc_grid = cldfra_bl1d(k)*qc_bl1d(k)
6340 ENDIF
6341 envm_sqc(k)=envm_sqc(k) + max(upa(k-1,i)*0.5*(qcn + upqc(k-1,i)) - qc_grid, 0.0)*detrate*aratio*min(dzp,dzpmax)
6342 ENDIF
6343 envm_u(k) =envm_u(k) + (0.5*(un + upu(k-1,i)) - u(k))*detrateuv*aratio*min(dzp,dzpmax)
6344 envm_v(k) =envm_v(k) + (0.5*(vn + upv(k-1,i)) - v(k))*detrateuv*aratio*min(dzp,dzpmax)
6345
6346 IF (wn > 0.) THEN
6347 !Update plume variables at current k index
6348 upw(k,i)=wn !sqrt(Wn2)
6349 upthv(k,i)=thvn
6350 upthl(k,i)=thln
6351 upqt(k,i)=qtn
6352 upqc(k,i)=qcn
6353 upu(k,i)=un
6354 upv(k,i)=vn
6355 upqke(k,i)=qken
6356 upqnc(k,i)=qncn
6357 upqni(k,i)=qnin
6358 upqnwfa(k,i)=qnwfan
6359 upqnifa(k,i)=qnifan
6360 upqnbca(k,i)=qnbcan
6361 upa(k,i)=upa(k-1,i)
6362 IF ( mix_chem ) THEN
6363 do ic = 1,nchem
6364 upchem(k,i,ic) = chemn(ic)
6365 enddo
6366 ENDIF
6367 ktop = max(ktop,k)
6368 ELSE
6369 exit !exit k-loop
6370 END IF
6371 ENDDO
6372
6373 IF (debug_mf == 1) THEN
6374 IF (maxval(upw(:,i)) > 10.0 .OR. minval(upa(:,i)) < 0.0 .OR. &
6375 maxval(upa(:,i)) > atot .OR. nup2 > 10) THEN
6376 ! surface values
6377 print *,'flq:',flq,' fltv:',fltv2,' Nup2=',nup2
6378 print *,'pblh:',pblh,' wstar:',wstar,' ktop=',ktop
6379 print *,'sigmaW=',sigmaw,' sigmaTH=',sigmath,' sigmaQT=',sigmaqt
6380 ! means
6381 print *,'u:',u
6382 print *,'v:',v
6383 print *,'thl:',thl
6384 print *,'UPA:',upa(:,i)
6385 print *,'UPW:',upw(:,i)
6386 print *,'UPTHL:',upthl(:,i)
6387 print *,'UPQT:',upqt(:,i)
6388 print *,'ENT:',ent(:,i)
6389 ENDIF
6390 ENDIF
6391 ENDDO
6392ELSE
6393 !At least one of the conditions was not met for activating the MF scheme.
6394 nup2=0.
6395END IF !end criteria check for mass-flux scheme
6396
6397ktop=min(ktop,kte-1)
6398IF (ktop == 0) THEN
6399 ztop = 0.0
6400ELSE
6401 ztop=zw(ktop)
6402ENDIF
6403
6404IF (nup2 > 0) THEN
6405 !Calculate the fluxes for each variable
6406 !All s_aw* variable are == 0 at k=1
6407 DO i=1,nup
6408 DO k=kts,kte-1
6409 s_aw(k+1) = s_aw(k+1) + rhoz(k)*upa(k,i)*upw(k,i)*psig_w
6410 s_awthl(k+1)= s_awthl(k+1) + rhoz(k)*upa(k,i)*upw(k,i)*upthl(k,i)*psig_w
6411 s_awqt(k+1) = s_awqt(k+1) + rhoz(k)*upa(k,i)*upw(k,i)*upqt(k,i)*psig_w
6412 !to conform to grid mean properties, move qc to qv in grid mean
6413 !saturated layers, so total water fluxes are preserved but
6414 !negative qc fluxes in unsaturated layers is reduced.
6415! if (qc(k) > 1e-12 .or. qc(k+1) > 1e-12) then
6416 qc_plume = upqc(k,i)
6417! else
6418! qc_plume = 0.0
6419! endif
6420 s_awqc(k+1) = s_awqc(k+1) + rhoz(k)*upa(k,i)*upw(k,i)*qc_plume*psig_w
6421 s_awqv(k+1) = s_awqt(k+1) - s_awqc(k+1)
6422 ENDDO
6423 ENDDO
6424 !momentum
6425 if (momentum_opt > 0) then
6426 do i=1,nup
6427 do k=kts,kte-1
6428 s_awu(k+1) = s_awu(k+1) + rhoz(k)*upa(k,i)*upw(k,i)*upu(k,i)*psig_w
6429 s_awv(k+1) = s_awv(k+1) + rhoz(k)*upa(k,i)*upw(k,i)*upv(k,i)*psig_w
6430 enddo
6431 enddo
6432 endif
6433 !tke
6434 if (tke_opt > 0) then
6435 do i=1,nup
6436 do k=kts,kte-1
6437 s_awqke(k+1)= s_awqke(k+1) + rhoz(k)*upa(k,i)*upw(k,i)*upqke(k,i)*psig_w
6438 enddo
6439 enddo
6440 endif
6441 !chem
6442 if ( mix_chem ) then
6443 do k=kts,kte
6444 do i=1,nup
6445 do ic = 1,nchem
6446 s_awchem(k+1,ic) = s_awchem(k+1,ic) + rhoz(k)*upa(k,i)*upw(k,i)*upchem(k,i,ic)*psig_w
6447 enddo
6448 enddo
6449 enddo
6450 endif
6451
6452 if (scalar_opt > 0) then
6453 do k=kts,kte
6454 do i=1,nup
6455 s_awqnc(k+1) = s_awqnc(k+1) + rhoz(k)*upa(k,i)*upw(k,i)*upqnc(k,i)*psig_w
6456 s_awqni(k+1) = s_awqni(k+1) + rhoz(k)*upa(k,i)*upw(k,i)*upqni(k,i)*psig_w
6457 s_awqnwfa(k+1)= s_awqnwfa(k+1) + rhoz(k)*upa(k,i)*upw(k,i)*upqnwfa(k,i)*psig_w
6458 s_awqnifa(k+1)= s_awqnifa(k+1) + rhoz(k)*upa(k,i)*upw(k,i)*upqnifa(k,i)*psig_w
6459 s_awqnbca(k+1)= s_awqnbca(k+1) + rhoz(k)*upa(k,i)*upw(k,i)*upqnbca(k,i)*psig_w
6460 enddo
6461 enddo
6462 endif
6463
6464 !Flux limiter: Check ratio of heat flux at top of first model layer
6465 !and at the surface. Make sure estimated flux out of the top of the
6466 !layer is < fluxportion*surface_heat_flux
6467 IF (s_aw(kts+1) /= 0.) THEN
6468 dzi(kts) = 0.5*(dz(kts)+dz(kts+1)) !dz centered at model interface
6469 flx1 = max(s_aw(kts+1)*(th(kts)-th(kts+1))/dzi(kts),1.0e-5)
6470 ELSE
6471 flx1 = 0.0
6472 !print*,"ERROR: s_aw(kts+1) == 0, NUP=",NUP," NUP2=",NUP2,&
6473 ! " superadiabatic=",superadiabatic," KTOP=",KTOP
6474 ENDIF
6475 adjustment=1.0
6476 !Print*,"Flux limiter in MYNN-EDMF, adjustment=",fluxportion*flt/dz(kts)/flx1
6477 !Print*,"flt/dz=",flt/dz(kts)," flx1=",flx1," s_aw(kts+1)=",s_aw(kts+1)
6478 IF (flx1 > fluxportion*flt/dz(kts) .AND. flx1>0.0) THEN
6479 adjustment= fluxportion*flt/dz(kts)/flx1
6480 s_aw = s_aw*adjustment
6481 s_awthl = s_awthl*adjustment
6482 s_awqt = s_awqt*adjustment
6483 s_awqc = s_awqc*adjustment
6484 s_awqv = s_awqv*adjustment
6485 s_awqnc = s_awqnc*adjustment
6486 s_awqni = s_awqni*adjustment
6487 s_awqnwfa = s_awqnwfa*adjustment
6488 s_awqnifa = s_awqnifa*adjustment
6489 s_awqnbca = s_awqnbca*adjustment
6490 IF (momentum_opt > 0) THEN
6491 s_awu = s_awu*adjustment
6492 s_awv = s_awv*adjustment
6493 ENDIF
6494 IF (tke_opt > 0) THEN
6495 s_awqke= s_awqke*adjustment
6496 ENDIF
6497 IF ( mix_chem ) THEN
6498 s_awchem = s_awchem*adjustment
6499 ENDIF
6500 upa = upa*adjustment
6501 ENDIF
6502 !Print*,"adjustment=",adjustment," fluxportion=",fluxportion," flt=",flt
6503
6504 !Calculate mean updraft properties for output:
6505 !all edmf_* variables at k=1 correspond to the interface at top of first model layer
6506 do k=kts,kte-1
6507 do i=1,nup
6508 edmf_a(k) =edmf_a(k) +upa(k,i)
6509 edmf_w(k) =edmf_w(k) +rhoz(k)*upa(k,i)*upw(k,i)
6510 edmf_qt(k) =edmf_qt(k) +rhoz(k)*upa(k,i)*upqt(k,i)
6511 edmf_thl(k)=edmf_thl(k)+rhoz(k)*upa(k,i)*upthl(k,i)
6512 edmf_ent(k)=edmf_ent(k)+rhoz(k)*upa(k,i)*ent(k,i)
6513 edmf_qc(k) =edmf_qc(k) +rhoz(k)*upa(k,i)*upqc(k,i)
6514 enddo
6515 enddo
6516 do k=kts,kte-1
6517 !Note that only edmf_a is multiplied by Psig_w. This takes care of the
6518 !scale-awareness of the subsidence below:
6519 if (edmf_a(k)>0.) then
6520 edmf_w(k)=edmf_w(k)/edmf_a(k)
6521 edmf_qt(k)=edmf_qt(k)/edmf_a(k)
6522 edmf_thl(k)=edmf_thl(k)/edmf_a(k)
6523 edmf_ent(k)=edmf_ent(k)/edmf_a(k)
6524 edmf_qc(k)=edmf_qc(k)/edmf_a(k)
6525 edmf_a(k)=edmf_a(k)*psig_w
6526 !FIND MAXIMUM MASS-FLUX IN THE COLUMN:
6527 if(edmf_a(k)*edmf_w(k) > maxmf) maxmf = edmf_a(k)*edmf_w(k)
6528 endif
6529 enddo ! end k
6530
6531 !smoke/chem
6532 if ( mix_chem ) then
6533 do k=kts,kte-1
6534 do i=1,nup
6535 do ic = 1,nchem
6536 edmf_chem(k,ic) = edmf_chem(k,ic) + rhoz(k)*upa(k,i)*upchem(k,i,ic)
6537 enddo
6538 enddo
6539 enddo
6540 do k=kts,kte-1
6541 if (edmf_a(k)>0.) then
6542 do ic = 1,nchem
6543 edmf_chem(k,ic) = edmf_chem(k,ic)/edmf_a(k)
6544 enddo
6545 endif
6546 enddo ! end k
6547 endif
6548
6549 !Calculate the effects environmental subsidence.
6550 !All envi_*variables are valid at the interfaces, like the edmf_* variables
6551 IF (env_subs) THEN
6552 DO k=kts+1,kte-1
6553 !First, smooth the profiles of w & a, since sharp vertical gradients
6554 !in plume variables are not likely extended to env variables
6555 !Note1: w is treated as negative further below
6556 !Note2: both w & a will be transformed into env variables further below
6557 envi_w(k) = onethird*(edmf_w(k-1)+edmf_w(k)+edmf_w(k+1))
6558 envi_a(k) = onethird*(edmf_a(k-1)+edmf_a(k)+edmf_a(k+1))*adjustment
6559 ENDDO
6560 !define env variables at k=1 (top of first model layer)
6561 envi_w(kts) = edmf_w(kts)
6562 envi_a(kts) = edmf_a(kts)
6563 !define env variables at k=kte
6564 envi_w(kte) = 0.0
6565 envi_a(kte) = edmf_a(kte)
6566 !define env variables at k=kte+1
6567 envi_w(kte+1) = 0.0
6568 envi_a(kte+1) = edmf_a(kte)
6569 !Add limiter for very long time steps (i.e. dt > 300 s)
6570 !Note that this is not a robust check - only for violations in
6571 ! the first model level.
6572 IF (envi_w(kts) > 0.9*dz(kts)/dt) THEN
6573 sublim = 0.9*dz(kts)/dt/envi_w(kts)
6574 ELSE
6575 sublim = 1.0
6576 ENDIF
6577 !Transform w & a into env variables
6578 DO k=kts,kte
6579 temp=envi_a(k)
6580 envi_a(k)=1.0-temp
6581 envi_w(k)=csub*sublim*envi_w(k)*temp/(1.-temp)
6582 ENDDO
6583 !calculate tendencies from subsidence and detrainment valid at the middle of
6584 !each model layer. The lowest model layer uses an assumes w=0 at the surface.
6585 dzi(kts) = 0.5*(dz(kts)+dz(kts+1))
6586 sub_thl(kts)= 0.5*envi_w(kts)*envi_a(kts)* &
6587 (rho(kts+1)*thl(kts+1)-rho(kts)*thl(kts))/dzi(kts)/rhoz(k)
6588 sub_sqv(kts)= 0.5*envi_w(kts)*envi_a(kts)* &
6589 (rho(kts+1)*qv(kts+1)-rho(kts)*qv(kts))/dzi(kts)/rhoz(k)
6590 DO k=kts+1,kte-1
6591 dzi(k) = 0.5*(dz(k)+dz(k+1))
6592 sub_thl(k)= 0.5*(envi_w(k)+envi_w(k-1))*0.5*(envi_a(k)+envi_a(k-1)) * &
6593 (rho(k+1)*thl(k+1)-rho(k)*thl(k))/dzi(k)/rhoz(k)
6594 sub_sqv(k)= 0.5*(envi_w(k)+envi_w(k-1))*0.5*(envi_a(k)+envi_a(k-1)) * &
6595 (rho(k+1)*qv(k+1)-rho(k)*qv(k))/dzi(k)/rhoz(k)
6596 ENDDO
6597
6598 DO k=kts,kte-1
6599 det_thl(k)=cdet*(envm_thl(k)-thl(k))*envi_a(k)*psig_w
6600 det_sqv(k)=cdet*(envm_sqv(k)-qv(k))*envi_a(k)*psig_w
6601 det_sqc(k)=cdet*(envm_sqc(k)-qc(k))*envi_a(k)*psig_w
6602 ENDDO
6603
6604 IF (momentum_opt > 0) THEN
6605 sub_u(kts)=0.5*envi_w(kts)*envi_a(kts)* &
6606 (rho(kts+1)*u(kts+1)-rho(kts)*u(kts))/dzi(kts)/rhoz(k)
6607 sub_v(kts)=0.5*envi_w(kts)*envi_a(kts)* &
6608 (rho(kts+1)*v(kts+1)-rho(kts)*v(kts))/dzi(kts)/rhoz(k)
6609 DO k=kts+1,kte-1
6610 sub_u(k)=0.5*(envi_w(k)+envi_w(k-1))*0.5*(envi_a(k)+envi_a(k-1)) * &
6611 (rho(k+1)*u(k+1)-rho(k)*u(k))/dzi(k)/rhoz(k)
6612 sub_v(k)=0.5*(envi_w(k)+envi_w(k-1))*0.5*(envi_a(k)+envi_a(k-1)) * &
6613 (rho(k+1)*v(k+1)-rho(k)*v(k))/dzi(k)/rhoz(k)
6614 ENDDO
6615
6616 DO k=kts,kte-1
6617 det_u(k) = cdet*(envm_u(k)-u(k))*envi_a(k)*psig_w
6618 det_v(k) = cdet*(envm_v(k)-v(k))*envi_a(k)*psig_w
6619 ENDDO
6620 ENDIF
6621 ENDIF !end subsidence/env detranment
6622
6623 !First, compute exner, plume theta, and dz centered at interface
6624 !Here, k=1 is the top of the first model layer. These values do not
6625 !need to be defined at k=kte (unused level).
6626 DO k=kts,kte-1
6627 exneri(k) = (exner(k)*dz(k+1)+exner(k+1)*dz(k))/(dz(k+1)+dz(k))
6628 edmf_th(k)= edmf_thl(k) + xlvcp/exneri(k)*edmf_qc(k)
6629 dzi(k) = 0.5*(dz(k)+dz(k+1))
6630 ENDDO
6631
6632!JOE: ADD CLDFRA_bl1d, qc_bl1d. Note that they have already been defined in
6633! mym_condensation. Here, a shallow-cu component is added, but no cumulus
6634! clouds can be added at k=1 (start loop at k=2).
6635 do k=kts+1,kte-2
6636 if (k > ktop) exit
6637 if(0.5*(edmf_qc(k)+edmf_qc(k-1))>0.0 .and. (cldfra_bl1d(k) < cf_thresh))THEN
6638 !interpolate plume quantities to mass levels
6639 aup = (edmf_a(k)*dzi(k-1)+edmf_a(k-1)*dzi(k))/(dzi(k-1)+dzi(k))
6640 thp = (edmf_th(k)*dzi(k-1)+edmf_th(k-1)*dzi(k))/(dzi(k-1)+dzi(k))
6641 qtp = (edmf_qt(k)*dzi(k-1)+edmf_qt(k-1)*dzi(k))/(dzi(k-1)+dzi(k))
6642 !convert TH to T
6643! t = THp*exner(k)
6644 !SATURATED VAPOR PRESSURE
6645 esat = esat_blend(tk(k))
6646 !SATURATED SPECIFIC HUMIDITY
6647 qsl=ep_2*esat/max(1.e-7,(p(k)-ep_3*esat))
6648
6649 !condensed liquid in the plume on mass levels
6650 if (edmf_qc(k)>0.0 .and. edmf_qc(k-1)>0.0) then
6651 qcp = (edmf_qc(k)*dzi(k-1)+edmf_qc(k-1)*dzi(k))/(dzi(k-1)+dzi(k))
6652 else
6653 qcp = max(edmf_qc(k),edmf_qc(k-1))
6654 endif
6655
6656 !COMPUTE CLDFRA & QC_BL FROM MASS-FLUX SCHEME and recompute vt & vq
6657 xl = xl_blend(tk(k)) ! obtain blended heat capacity
6658 qsat_tk = qsat_blend(tk(k),p(k)) ! get saturation water vapor mixing ratio
6659 ! at t and p
6660 rsl = xl*qsat_tk / (r_v*tk(k)**2) ! slope of C-C curve at t (abs temp)
6661 ! CB02, Eqn. 4
6662 cpm = cp + qt(k)*cpv ! CB02, sec. 2, para. 1
6663 a = 1./(1. + xl*rsl/cpm) ! CB02 variable "a"
6664 b9 = a*rsl ! CB02 variable "b"
6665
6666 q2p = xlvcp/exner(k)
6667 pt = thl(k) +q2p*qcp*aup ! potential temp (env + plume)
6668 bb = b9*tk(k)/pt ! bb is "b9" in BCMT95. Their "b9" differs from
6669 ! "b9" in CB02 by a factor
6670 ! of T/theta. Strictly, b9 above is formulated in
6671 ! terms of sat. mixing ratio, but bb in BCMT95 is
6672 ! cast in terms of sat. specific humidity. The
6673 ! conversion is neglected here.
6674 qww = 1.+0.61*qt(k)
6675 alpha = 0.61*pt
6676 beta = pt*xl/(tk(k)*cp) - 1.61*pt
6677 !Buoyancy flux terms have been moved to the end of this section...
6678
6679 !Now calculate convective component of the cloud fraction:
6680 if (a > 0.0) then
6681 f = min(1.0/a, 4.0) ! f is vertical profile scaling function (CB2005)
6682 else
6683 f = 1.0
6684 endif
6685
6686 !CB form:
6687 !sigq = 3.5E-3 * Aup * 0.5*(edmf_w(k)+edmf_w(k-1)) * f ! convective component of sigma (CB2005)
6688 !sigq = SQRT(sigq**2 + sgm(k)**2) ! combined conv + stratus components
6689 !Per S.DeRoode 2009?
6690 !sigq = 5. * Aup * (QTp - qt(k))
6691 sigq = 10. * aup * (qtp - qt(k))
6692 !constrain sigq wrt saturation:
6693 sigq = max(sigq, qsat_tk*0.02 )
6694 sigq = min(sigq, qsat_tk*0.25 )
6695
6696 qmq = a * (qt(k) - qsat_tk) ! saturation deficit/excess;
6697 q1 = qmq/sigq ! the numerator of Q1
6698
6699 if ((landsea-1.5).GE.0) then ! WATER
6700 !modified form from LES
6701 !mf_cf = min(max(0.5 + 0.36 * atan(1.20*(Q1+0.2)),0.01),0.6)
6702 !Original CB
6703 mf_cf = min(max(0.5 + 0.36 * atan(1.55*q1),0.01),0.6)
6704 mf_cf = max(mf_cf, 1.2 * aup)
6705 mf_cf = min(mf_cf, 5.0 * aup)
6706 else ! LAND
6707 !LES form
6708 !mf_cf = min(max(0.5 + 0.36 * atan(1.20*(Q1+0.4)),0.01),0.6)
6709 !Original CB
6710 mf_cf = min(max(0.5 + 0.36 * atan(1.55*q1),0.01),0.6)
6711 mf_cf = max(mf_cf, 1.8 * aup)
6712 mf_cf = min(mf_cf, 5.0 * aup)
6713 endif
6714
6715 !IF ( debug_code ) THEN
6716 ! print*,"In MYNN, StEM edmf"
6717 ! print*," CB: env qt=",qt(k)," qsat=",qsat_tk
6718 ! print*," k=",k," satdef=",QTp - qsat_tk," sgm=",sgm(k)
6719 ! print*," CB: sigq=",sigq," qmq=",qmq," tk=",tk(k)
6720 ! print*," CB: mf_cf=",mf_cf," cldfra_bl=",cldfra_bl1d(k)," edmf_a=",edmf_a(k)
6721 !ENDIF
6722
6723 ! Update cloud fractions and specific humidities in grid cells
6724 ! where the mass-flux scheme is active. The specific humidities
6725 ! are converted to grid means (not in-cloud quantities).
6726 if ((landsea-1.5).GE.0) then ! water
6727 if (qcp * aup > 5e-5) then
6728 qc_bl1d(k) = 1.86 * (qcp * aup) - 2.2e-5
6729 else
6730 qc_bl1d(k) = 1.18 * (qcp * aup)
6731 endif
6732 cldfra_bl1d(k) = mf_cf
6733 ac_mf = mf_cf
6734 else ! land
6735 if (qcp * aup > 5e-5) then
6736 qc_bl1d(k) = 1.86 * (qcp * aup) - 2.2e-5
6737 else
6738 qc_bl1d(k) = 1.18 * (qcp * aup)
6739 endif
6740 cldfra_bl1d(k) = mf_cf
6741 ac_mf = mf_cf
6742 endif
6743
6744 !Now recalculate the terms for the buoyancy flux for mass-flux clouds:
6745 !See mym_condensation for details on these formulations.
6746 !Use Bechtold and Siebesma (1998) piecewise estimation of Fng with
6747 !limits ,since they really should be recalculated after all the other changes...:
6748 !Only overwrite vt & vq in non-stratus condition
6749 !if ((landsea-1.5).GE.0) then ! WATER
6750 q1=max(q1,-2.25)
6751 !else
6752 ! Q1=max(Q1,-2.0)
6753 !endif
6754
6755 if (q1 .ge. 1.0) then
6756 fng = 1.0
6757 elseif (q1 .ge. -1.7 .and. q1 .lt. 1.0) then
6758 fng = exp(-0.4*(q1-1.0))
6759 elseif (q1 .ge. -2.5 .and. q1 .lt. -1.7) then
6760 fng = 3.0 + exp(-3.8*(q1+1.7))
6761 else
6762 fng = min(23.9 + exp(-1.6*(q1+2.5)), 60.)
6763 endif
6764
6765 !link the buoyancy flux function to active clouds only (c*Aup):
6766 vt(k) = qww - (1.5*aup)*beta*bb*fng - 1.
6767 vq(k) = alpha + (1.5*aup)*beta*a*fng - tv0
6768 endif !check for (qc in plume) .and. (cldfra_bl < threshold)
6769 enddo !k-loop
6770
6771ENDIF !end nup2 > 0
6772
6773!modify output (negative: dry plume, positive: moist plume)
6774if (ktop > 0) then
6775 maxqc = maxval(edmf_qc(1:ktop))
6776 if ( maxqc < 1.e-8) maxmf = -1.0*maxmf
6777endif
6778
6779!
6780! debugging
6781!
6782if (edmf_w(1) > 4.0) then
6783! surface values
6784 print *,'flq:',flq,' fltv:',fltv2
6785 print *,'pblh:',pblh,' wstar:',wstar
6786 print *,'sigmaW=',sigmaw,' sigmaTH=',sigmath,' sigmaQT=',sigmaqt
6787! means
6788! print *,'u:',u
6789! print *,'v:',v
6790! print *,'thl:',thl
6791! print *,'thv:',thv
6792! print *,'qt:',qt
6793! print *,'p:',p
6794
6795! updrafts
6796! DO I=1,NUP2
6797! print *,'up:A',i
6798! print *,UPA(:,i)
6799! print *,'up:W',i
6800! print*,UPW(:,i)
6801! print *,'up:thv',i
6802! print *,UPTHV(:,i)
6803! print *,'up:thl',i
6804! print *,UPTHL(:,i)
6805! print *,'up:qt',i
6806! print *,UPQT(:,i)
6807! print *,'up:tQC',i
6808! print *,UPQC(:,i)
6809! print *,'up:ent',i
6810! print *,ENT(:,i)
6811! ENDDO
6812
6813! mean updrafts
6814 print *,' edmf_a',edmf_a(1:14)
6815 print *,' edmf_w',edmf_w(1:14)
6816 print *,' edmf_qt:',edmf_qt(1:14)
6817 print *,' edmf_thl:',edmf_thl(1:14)
6818
6819ENDIF !END Debugging
6820
6821
6822#ifdef HARDCODE_VERTICAL
6823# undef kts
6824# undef kte
6825#endif
6826
6827END SUBROUTINE dmp_mf
6828!=================================================================
6831subroutine condensation_edmf(QT,THL,P,zagl,THV,QC)
6832!
6833! zero or one condensation for edmf: calculates THV and QC
6834!
6835real(kind_phys),intent(in) :: QT,THL,P,zagl
6836real(kind_phys),intent(out) :: THV
6837real(kind_phys),intent(inout):: QC
6838
6839integer :: niter,i
6840real(kind_phys):: diff,exn,t,th,qs,qcold
6841
6842! constants used from module_model_constants.F
6843! p1000mb
6844! rcp ... Rd/cp
6845! xlv ... latent heat for water (2.5e6)
6846! cp
6847! rvord .. r_v/r_d (1.6)
6848
6849! number of iterations
6850 niter=50
6851! minimum difference (usually converges in < 8 iterations with diff = 2e-5)
6852 diff=1.e-6
6853
6854 exn=(p/p1000mb)**rcp
6855 !QC=0. !better first guess QC is incoming from lower level, do not set to zero
6856 do i=1,niter
6857 t=exn*thl + xlvcp*qc
6858 qs=qsat_blend(t,p)
6859 qcold=qc
6860 qc=0.5*qc + 0.5*max((qt-qs),0.)
6861 if (abs(qc-qcold)<diff) exit
6862 enddo
6863
6864 t=exn*thl + xlvcp*qc
6865 qs=qsat_blend(t,p)
6866 qc=max(qt-qs,0.)
6867
6868 !Do not allow saturation below 100 m
6869 if(zagl < 100.)qc=0.
6870
6871 !THV=(THL+xlv/cp*QC).*(1+(1-rvovrd)*(QT-QC)-QC);
6872 thv=(thl+xlvcp*qc)*(1.+qt*(rvovrd-1.)-rvovrd*qc)
6873
6874! IF (QC > 0.0) THEN
6875! PRINT*,"EDMF SAT, p:",p," iterations:",i
6876! PRINT*," T=",T," THL=",THL," THV=",THV
6877! PRINT*," QS=",QS," QT=",QT," QC=",QC,"ratio=",qc/qs
6878! ENDIF
6879
6880 !THIS BASICALLY GIVE THE SAME RESULT AS THE PREVIOUS LINE
6881 !TH = THL + xlv/cp/EXN*QC
6882 !THV= TH*(1. + p608*QT)
6883
6884 !print *,'t,p,qt,qs,qc'
6885 !print *,t,p,qt,qs,qc
6886
6887
6888end subroutine condensation_edmf
6889
6890!===============================================================
6891
6892subroutine condensation_edmf_r(QT,THL,P,zagl,THV,QC)
6893!
6894! zero or one condensation for edmf: calculates THL and QC
6895! similar to condensation_edmf but with different inputs
6896!
6897real(kind_phys),intent(in) :: QT,THV,P,zagl
6898real(kind_phys),intent(out) :: THL, QC
6899
6900integer :: niter,i
6901real(kind_phys):: diff,exn,t,th,qs,qcold
6902
6903! number of iterations
6904 niter=50
6905! minimum difference
6906 diff=2.e-5
6907
6908 exn=(p/p1000mb)**rcp
6909 ! assume first that th = thv
6910 t = thv*exn
6911 !QS = qsat_blend(T,P)
6912 !QC = QS - QT
6913
6914 qc=0.
6915
6916 do i=1,niter
6917 qcold = qc
6918 t = exn*thv/(1.+qt*(rvovrd-1.)-rvovrd*qc)
6919 qs=qsat_blend(t,p)
6920 qc= max((qt-qs),0.)
6921 if (abs(qc-qcold)<diff) exit
6922 enddo
6923 thl = (t - xlv/cp*qc)/exn
6924
6925end subroutine condensation_edmf_r
6926
6927!===============================================================
6928! ===================================================================
6929! This is the downdraft mass flux scheme - analogus to edmf_JPL but
6930! flipped updraft to downdraft. This scheme is currently only tested
6931! for Stratocumulus cloud conditions. For a detailed desctiption of the
6932! model, see paper.
6933
6934SUBROUTINE ddmf_jpl(kts,kte,dt,zw,dz,p, &
6935 &u,v,th,thl,thv,tk,qt,qv,qc, &
6936 &rho,exner, &
6937 &ust,wthl,wqt,pblh,kpbl, &
6938 &edmf_a_dd,edmf_w_dd, edmf_qt_dd, &
6939 &edmf_thl_dd,edmf_ent_dd,edmf_qc_dd, &
6940 &sd_aw,sd_awthl,sd_awqt, &
6941 &sd_awqv,sd_awqc,sd_awu,sd_awv, &
6942 &sd_awqke, &
6943 &qc_bl1d,cldfra_bl1d, &
6944 &rthraten )
6945
6946 integer, intent(in) :: KTS,KTE,KPBL
6947 real(kind_phys), dimension(kts:kte), intent(in) :: &
6948 U,V,TH,THL,TK,QT,QV,QC,THV,P,rho,exner,dz
6949 real(kind_phys), dimension(kts:kte), intent(in) :: rthraten
6950 ! zw .. heights of the downdraft levels (edges of boxes)
6951 real(kind_phys), dimension(kts:kte+1), intent(in) :: ZW
6952 real(kind_phys), intent(in) :: WTHL,WQT
6953 real(kind_phys), intent(in) :: dt,ust,pblh
6954 ! outputs - downdraft properties
6955 real(kind_phys), dimension(kts:kte), intent(out) :: &
6956 edmf_a_dd,edmf_w_dd, &
6957 edmf_qt_dd,edmf_thl_dd, edmf_ent_dd,edmf_qc_dd
6958
6959 ! outputs - variables needed for solver (sd_aw - sum ai*wi, sd_awphi - sum ai*wi*phii)
6960 real(kind_phys), dimension(kts:kte+1) :: &
6961 sd_aw, sd_awthl, sd_awqt, sd_awu, &
6962 sd_awv, sd_awqc, sd_awqv, sd_awqke, sd_aw2
6963
6964 real(kind_phys), dimension(kts:kte), intent(in) :: &
6965 qc_bl1d, cldfra_bl1d
6966
6967 integer, parameter:: ndown = 5
6968 ! draw downdraft starting height randomly between cloud base and cloud top
6969 integer, dimension(1:NDOWN) :: DD_initK
6970 real(kind_phys), dimension(1:NDOWN) :: randNum
6971 ! downdraft properties
6972 real(kind_phys), dimension(kts:kte+1,1:NDOWN) :: &
6973 DOWNW,DOWNTHL,DOWNQT,DOWNQC,DOWNA,DOWNU,DOWNV,DOWNTHV
6974
6975 ! entrainment variables
6976 real(kind_phys), dimension(KTS+1:KTE+1,1:NDOWN) :: ENT,ENTf
6977 integer, dimension(KTS+1:KTE+1,1:NDOWN) :: ENTi
6978
6979 ! internal variables
6980 integer :: K,I,ki, kminrad, qlTop, p700_ind, qlBase
6981 real(kind_phys):: wthv,wstar,qstar,thstar,sigmaW,sigmaQT, &
6982 sigmaTH,z0,pwmin,pwmax,wmin,wmax,wlv,wtv,went,mindownw
6983 real(kind_phys):: B,QTn,THLn,THVn,QCn,Un,Vn,QKEn,Wn2,Wn, &
6984 THVk,Pk,EntEXP,EntW,beta_dm,EntExp_M,rho_int
6985 real(kind_phys):: jump_thetav, jump_qt, jump_thetal, &
6986 refTHL, refTHV, refQT
6987 ! DD specific internal variables
6988 real(kind_phys):: minrad,zminrad, radflux, F0, wst_rad, wst_dd
6989 logical :: cloudflg
6990 real(kind_phys):: sigq,xl,rsl,cpm,a,mf_cf,diffqt, &
6991 Fng,qww,alpha,beta,bb,f,pt,t,q2p,b9,satvp,rhgrid
6992
6993 ! w parameters
6994 real(kind_phys),parameter :: &
6995 &Wa=1., Wb=1.5, Z00=100., BCOEFF=0.2
6996 ! entrainment parameters
6997 real(kind_phys),parameter :: &
6998 &L0=80, ENT0=0.2
6999 !downdraft properties
7000 real(kind_phys):: &
7001 & dp, & !diameter of plume
7002 & dl, & !diameter increment
7003 & Adn !total area of downdrafts
7004 !additional printouts for debugging
7005 integer, parameter :: debug_mf=0
7006
7007 dl = (1000.-500.)/real(ndown)
7008 pwmin=-3. ! drawing from the negative tail -3sigma to -1sigma
7009 pwmax=-1.
7010
7011 ! initialize downdraft properties
7012 downw=0.
7013 downthl=0.
7014 downthv=0.
7015 downqt=0.
7016 downa=0.
7017 downu=0.
7018 downv=0.
7019 downqc=0.
7020 ent=0.
7021 dd_initk=0
7022
7023 edmf_a_dd =0.
7024 edmf_w_dd =0.
7025 edmf_qt_dd =0.
7026 edmf_thl_dd=0.
7027 edmf_ent_dd=0.
7028 edmf_qc_dd =0.
7029
7030 sd_aw=0.
7031 sd_awthl=0.
7032 sd_awqt=0.
7033 sd_awqv=0.
7034 sd_awqc=0.
7035 sd_awu=0.
7036 sd_awv=0.
7037 sd_awqke=0.
7038
7039 ! FIRST, CHECK FOR STRATOCUMULUS-TOPPED BOUNDARY LAYERS
7040 cloudflg=.false.
7041 minrad=100.
7042 kminrad=kpbl
7043 zminrad=pblh
7044 qltop = 1 !initialize at 0
7045 qlbase = 1
7046 wthv=wthl+svp1*wqt
7047 do k = max(3,kpbl-2),kpbl+3
7048 if (qc(k).gt. 1.e-6 .AND. cldfra_bl1d(k).gt.0.5) then
7049 cloudflg=.true. ! found Sc cloud
7050 qltop = k ! index for Sc cloud top
7051 endif
7052 enddo
7053
7054 do k = qltop, kts, -1
7055 if (qc(k) .gt. 1e-6) then
7056 qlbase = k ! index for Sc cloud base
7057 endif
7058 enddo
7059 qlbase = (qltop+qlbase)/2 ! changed base to half way through the cloud
7060
7061! call init_random_seed_1()
7062! call RANDOM_NUMBER(randNum)
7063 do i=1,ndown
7064 ! downdraft starts somewhere between cloud base to cloud top
7065 ! the probability is equally distributed
7066 dd_initk(i) = qltop ! nint(randNum(i)*real(qlTop-qlBase)) + qlBase
7067 enddo
7068
7069 ! LOOP RADFLUX
7070 f0 = 0.
7071 do k = 1, qltop ! Snippet from YSU, YSU loops until qlTop - 1
7072 radflux = rthraten(k) * exner(k) ! Converts theta/s to temperature/s
7073 radflux = radflux * cp / grav * ( p(k) - p(k+1) ) ! Converts K/s to W/m^2
7074 if ( radflux < 0.0 ) f0 = abs(radflux) + f0
7075 enddo
7076 f0 = max(f0, 1.0)
7077
7078 !Allow the total fractional area of the downdrafts to be proportional
7079 !to the radiative forcing:
7080 !for 50 W/m2, Adn = 0.10
7081 !for 100 W/m2, Adn = 0.15
7082 !for 150 W/m2, Adn = 0.20
7083 adn = min( 0.05 + f0*0.001, 0.3)
7084
7085 !found Sc cloud and cloud not at surface, trigger downdraft
7086 if (cloudflg) then
7087
7088! !get entrainent coefficient
7089! do i=1,NDOWN
7090! do k=kts+1,kte
7091! ENTf(k,i)=(ZW(k+1)-ZW(k))/L0
7092! enddo
7093! enddo
7094!
7095! ! get Poisson P(dz/L0)
7096! call Poisson(1,NDOWN,kts+1,kte,ENTf,ENTi)
7097
7098
7099! ! entrainent: Ent=Ent0/dz*P(dz/L0)
7100! do i=1,NDOWN
7101! do k=kts+1,kte
7102!! ENT(k,i)=real(ENTi(k,i))*Ent0/(ZW(k+1)-ZW(k))
7103! ENT(k,i) = 0.002
7104! ENT(k,i) = min(ENT(k,i),0.9/(ZW(k+1)-ZW(k)))
7105! enddo
7106! enddo
7107
7108 !!![EW: INVJUMP] find 700mb height then subtract trpospheric lapse rate!!!
7109 p700_ind = minloc(abs(p-70000),1)!p1D is 70000
7110 jump_thetav = thv(p700_ind) - thv(1) - (thv(p700_ind)-thv(qltop+3))/(zw(p700_ind)-zw(qltop+3))*(zw(p700_ind)-zw(qltop))
7111 jump_qt = qc(p700_ind) + qv(p700_ind) - qc(1) - qv(1)
7112 jump_thetal = thl(p700_ind) - thl(1) - (thl(p700_ind)-thl(qltop+3))/(zw(p700_ind)-zw(qltop+3))*(zw(p700_ind)-zw(qltop))
7113
7114 refthl = thl(qltop) !sum(thl(1:qlTop)) / (qlTop) ! avg over BL for now or just at qlTop
7115 refthv = thv(qltop) !sum(thv(1:qlTop)) / (qlTop)
7116 refqt = qt(qltop) !sum(qt(1:qlTop)) / (qlTop)
7117
7118 ! wstar_rad, following Lock and MacVean (1999a)
7119 wst_rad = ( grav * zw(qltop) * f0 / (refthl * rho(qltop) * cp) ) ** (0.333)
7120 wst_rad = max(wst_rad, 0.1)
7121 wstar = max(0.,(grav/thv(1)*wthv*pblh)**(onethird))
7122 went = thv(1) / ( grav * jump_thetav * zw(qltop) ) * &
7123 (0.15 * (wstar**3 + 5*ust**3) + 0.35 * wst_rad**3 )
7124 qstar = abs(went*jump_qt/wst_rad)
7125 thstar = f0/rho(qltop)/cp/wst_rad - went*jump_thetav/wst_rad
7126 !wstar_dd = mixrad + surface wst
7127 wst_dd = (0.15 * (wstar**3 + 5*ust**3) + 0.35 * wst_rad**3 ) ** (0.333)
7128
7129 print*,"qstar=",qstar," thstar=",thstar," wst_dd=",wst_dd
7130 print*,"F0=",f0," wst_rad=",wst_rad," jump_thv=",jump_thetav
7131 print*,"entrainment velocity=",went
7132
7133 sigmaw = 0.2*wst_dd ! 0.8*wst_dd !wst_rad tuning parameter ! 0.5 was good
7134 sigmaqt = 40 * qstar ! 50 was good
7135 sigmath = 1.0 * thstar! 0.5 was good
7136
7137 wmin=sigmaw*pwmin
7138 wmax=sigmaw*pwmax
7139 !print*,"sigw=",sigmaW," wmin=",wmin," wmax=",wmax
7140
7141 do i=1,ndown !downdraft now starts at different height
7142 ki = dd_initk(i)
7143
7144 wlv=wmin+(wmax-wmin)/real(ndown)*(i-1)
7145 wtv=wmin+(wmax-wmin)/real(ndown)*i
7146
7147 !DOWNW(ki,I)=0.5*(wlv+wtv)
7148 downw(ki,i)=wlv
7149 !multiply downa by cloud fraction, so it's impact will diminish if
7150 !clouds are mixed away over the course of the longer radiation time step
7151 !DOWNA(ki,I)=0.5*ERF(wtv/(sqrt(2.)*sigmaW))-0.5*ERF(wlv/(sqrt(2.)*sigmaW))
7152 downa(ki,i)=adn/real(ndown)
7153 downu(ki,i)=(u(ki-1)*dz(ki) + u(ki)*dz(ki-1)) /(dz(ki)+dz(ki-1))
7154 downv(ki,i)=(v(ki-1)*dz(ki) + v(ki)*dz(ki-1)) /(dz(ki)+dz(ki-1))
7155
7156 !reference now depends on where dd starts
7157! refTHL = 0.5 * (thl(ki) + thl(ki-1))
7158! refTHV = 0.5 * (thv(ki) + thv(ki-1))
7159! refQT = 0.5 * (qt(ki) + qt(ki-1) )
7160
7161 refthl = (thl(ki-1)*dz(ki) + thl(ki)*dz(ki-1)) /(dz(ki)+dz(ki-1))
7162 refthv = (thv(ki-1)*dz(ki) + thv(ki)*dz(ki-1)) /(dz(ki)+dz(ki-1))
7163 refqt = (qt(ki-1)*dz(ki) + qt(ki)*dz(ki-1)) /(dz(ki)+dz(ki-1))
7164
7165 !DOWNQC(ki,I) = 0.0
7166 downqc(ki,i) = (qc(ki-1)*dz(ki) + qc(ki)*dz(ki-1)) /(dz(ki)+dz(ki-1))
7167 downqt(ki,i) = refqt !+ 0.5 *DOWNW(ki,I)*sigmaQT/sigmaW
7168 downthv(ki,i)= refthv + 0.01 *downw(ki,i)*sigmath/sigmaw
7169 downthl(ki,i)= refthl + 0.01 *downw(ki,i)*sigmath/sigmaw
7170
7171 !input :: QT,THV,P,zagl, output :: THL, QC
7172! Pk =(P(ki-1)*DZ(ki)+P(ki)*DZ(ki-1))/(DZ(ki)+DZ(ki-1))
7173! call condensation_edmf_r(DOWNQT(ki,I), &
7174! & DOWNTHL(ki,I),Pk,ZW(ki), &
7175! & DOWNTHV(ki,I),DOWNQC(ki,I) )
7176
7177 enddo
7178
7179 !print*, " Begin integration of downdrafts:"
7180 DO i=1,ndown
7181 dp = 500. + dl*real(i) ! diameter of plume (meters)
7182 !print *, "Plume # =", I,"======================="
7183 DO k=dd_initk(i)-1,kts+1,-1
7184
7185 !Entrainment from Tian and Kuang (2016), with constraints
7186 wmin = 0.3 + dp*0.0005
7187 ent(k,i) = 0.33/(min(max(-1.0*downw(k+1,i),wmin),0.9)*dp)
7188
7189 !starting at the first interface level below cloud top
7190 !EntExp=exp(-ENT(K,I)*dz(k))
7191 !EntExp_M=exp(-ENT(K,I)/3.*dz(k))
7192 entexp =ent(k,i)*dz(k) !for all scalars
7193 entexp_m=ent(k,i)*0.333*dz(k) !test for momentum
7194
7195 qtn =downqt(k+1,i) *(1.-entexp) + qt(k)*entexp
7196 thln=downthl(k+1,i)*(1.-entexp) + thl(k)*entexp
7197 un =downu(k+1,i) *(1.-entexp) + u(k)*entexp_m
7198 vn =downv(k+1,i) *(1.-entexp) + v(k)*entexp_m
7199 !QKEn=DOWNQKE(k-1,I)*(1.-EntExp) + QKE(k)*EntExp
7200
7201! QTn =DOWNQT(K+1,I) +(QT(K) -DOWNQT(K+1,I)) *(1.-EntExp)
7202! THLn=DOWNTHL(K+1,I)+(THL(K)-DOWNTHL(K+1,I))*(1.-EntExp)
7203! Un =DOWNU(K+1,I) +(U(K) -DOWNU(K+1,I))*(1.-EntExp_M)
7204! Vn =DOWNV(K+1,I) +(V(K) -DOWNV(K+1,I))*(1.-EntExp_M)
7205
7206 ! given new p & z, solve for thvn & qcn
7207 pk =(p(k-1)*dz(k)+p(k)*dz(k-1))/(dz(k)+dz(k-1))
7208 call condensation_edmf(qtn,thln,pk,zw(k),thvn,qcn)
7209! B=grav*(0.5*(THVn+DOWNTHV(k+1,I))/THV(k)-1.)
7210 thvk =(thv(k-1)*dz(k)+thv(k)*dz(k-1))/(dz(k)+dz(k-1))
7211 b=grav*(thvn/thvk - 1.0)
7212! Beta_dm = 2*Wb*ENT(K,I) + 0.5/(ZW(k)-dz(k)) * &
7213! & max(1. - exp((ZW(k) -dz(k))/Z00 - 1. ) , 0.)
7214! EntW=exp(-Beta_dm * dz(k))
7215 entw=entexp
7216! if (Beta_dm >0) then
7217! Wn2=DOWNW(K+1,I)**2*EntW - Wa*B/Beta_dm * (1. - EntW)
7218! else
7219! Wn2=DOWNW(K+1,I)**2 - 2.*Wa*B*dz(k)
7220! end if
7221
7222 mindownw = min(downw(k+1,i),-0.2)
7223 wn = downw(k+1,i) + (-2.*ent(k,i)*downw(k+1,i) - &
7224 bcoeff*b/mindownw)*min(dz(k), 250.)
7225
7226 !Do not allow a parcel to accelerate more than 1.25 m/s over 200 m.
7227 !Add max acceleration of -2.0 m/s for coarse vertical resolution.
7228 IF (wn < downw(k+1,i) - min(1.25*dz(k)/200., -2.0))THEN
7229 wn = downw(k+1,i) - min(1.25*dz(k)/200., -2.0)
7230 ENDIF
7231 !Add symmetrical max decrease in velocity (less negative)
7232 IF (wn > downw(k+1,i) + min(1.25*dz(k)/200., 2.0))THEN
7233 wn = downw(k+1,i) + min(1.25*dz(k)/200., 2.0)
7234 ENDIF
7235 wn = max(min(wn,0.0), -3.0)
7236
7237 !print *, " k =", k, " z =", ZW(k)
7238 !print *, " entw =",ENT(K,I), " Bouy =", B
7239 !print *, " downthv =", THVn, " thvk =", thvk
7240 !print *, " downthl =", THLn, " thl =", thl(k)
7241 !print *, " downqt =", QTn , " qt =", qt(k)
7242 !print *, " downw+1 =",DOWNW(K+1,I), " Wn2 =", Wn
7243
7244 IF (wn .lt. 0.) THEN !terminate when velocity is too small
7245 downw(k,i) = wn !-sqrt(Wn2)
7246 downthv(k,i)= thvn
7247 downthl(k,i)= thln
7248 downqt(k,i) = qtn
7249 downqc(k,i) = qcn
7250 downu(k,i) = un
7251 downv(k,i) = vn
7252 downa(k,i) = downa(k+1,i)
7253 ELSE
7254 !plumes must go at least 2 levels
7255 if (dd_initk(i) - k .lt. 2) then
7256 downw(:,i) = 0.0
7257 downthv(:,i)= 0.0
7258 downthl(:,i)= 0.0
7259 downqt(:,i) = 0.0
7260 downqc(:,i) = 0.0
7261 downu(:,i) = 0.0
7262 downv(:,i) = 0.0
7263 endif
7264 exit
7265 ENDIF
7266 ENDDO
7267 ENDDO
7268 endif ! end cloud flag
7269
7270 downw(1,:) = 0. !make sure downdraft does not go to the surface
7271 downa(1,:) = 0.
7272
7273 ! Combine both moist and dry plume, write as one averaged plume
7274 ! Even though downdraft starts at different height, average all up to qlTop
7275 DO k=qltop,kts,-1
7276 DO i=1,ndown
7277 edmf_a_dd(k) =edmf_a_dd(k) +downa(k-1,i)
7278 edmf_w_dd(k) =edmf_w_dd(k) +downa(k-1,i)*downw(k-1,i)
7279 edmf_qt_dd(k) =edmf_qt_dd(k) +downa(k-1,i)*downqt(k-1,i)
7280 edmf_thl_dd(k)=edmf_thl_dd(k)+downa(k-1,i)*downthl(k-1,i)
7281 edmf_ent_dd(k)=edmf_ent_dd(k)+downa(k-1,i)*ent(k-1,i)
7282 edmf_qc_dd(k) =edmf_qc_dd(k) +downa(k-1,i)*downqc(k-1,i)
7283 ENDDO
7284
7285 IF (edmf_a_dd(k) >0.) THEN
7286 edmf_w_dd(k) =edmf_w_dd(k) /edmf_a_dd(k)
7287 edmf_qt_dd(k) =edmf_qt_dd(k) /edmf_a_dd(k)
7288 edmf_thl_dd(k)=edmf_thl_dd(k)/edmf_a_dd(k)
7289 edmf_ent_dd(k)=edmf_ent_dd(k)/edmf_a_dd(k)
7290 edmf_qc_dd(k) =edmf_qc_dd(k) /edmf_a_dd(k)
7291 ENDIF
7292 ENDDO
7293
7294 !
7295 ! computing variables needed for solver
7296 !
7297
7298 DO k=kts,qltop
7299 rho_int = (rho(k)*dz(k+1)+rho(k+1)*dz(k))/(dz(k+1)+dz(k))
7300 DO i=1,ndown
7301 sd_aw(k) =sd_aw(k) +rho_int*downa(k,i)*downw(k,i)
7302 sd_awthl(k)=sd_awthl(k)+rho_int*downa(k,i)*downw(k,i)*downthl(k,i)
7303 sd_awqt(k) =sd_awqt(k) +rho_int*downa(k,i)*downw(k,i)*downqt(k,i)
7304 sd_awqc(k) =sd_awqc(k) +rho_int*downa(k,i)*downw(k,i)*downqc(k,i)
7305 sd_awu(k) =sd_awu(k) +rho_int*downa(k,i)*downw(k,i)*downu(k,i)
7306 sd_awv(k) =sd_awv(k) +rho_int*downa(k,i)*downw(k,i)*downv(k,i)
7307 ENDDO
7308 sd_awqv(k) = sd_awqt(k) - sd_awqc(k)
7309 ENDDO
7310
7311END SUBROUTINE ddmf_jpl
7312!===============================================================
7313
7314
7315SUBROUTINE scale_aware(dx,PBL1,Psig_bl,Psig_shcu)
7316
7317 !---------------------------------------------------------------
7318 ! NOTES ON SCALE-AWARE FORMULATION
7319 !
7320 !JOE: add scale-aware factor (Psig) here, taken from Honnert et al. (2011,
7321 ! JAS) and/or from Hyeyum Hailey Shin and Song-You Hong (2013, JAS)
7322 !
7323 ! Psig_bl tapers local mixing
7324 ! Psig_shcu tapers nonlocal mixing
7325
7326 real(kind_phys), intent(in) :: dx,pbl1
7327 real(kind_phys), intent(out) :: Psig_bl,Psig_shcu
7328 real(kind_phys) :: dxdh
7329
7330 psig_bl=1.0
7331 psig_shcu=1.0
7332 dxdh=max(2.5*dx,10.)/min(pbl1,3000.)
7333 ! Honnert et al. 2011, TKE in PBL *** original form used until 201605
7334 !Psig_bl= ((dxdh**2) + 0.07*(dxdh**0.667))/((dxdh**2) + &
7335 ! (3./21.)*(dxdh**0.67) + (3./42.))
7336 ! Honnert et al. 2011, TKE in entrainment layer
7337 !Psig_bl= ((dxdh**2) + (4./21.)*(dxdh**0.667))/((dxdh**2) + &
7338 ! (3./20.)*(dxdh**0.67) + (7./21.))
7339 ! New form to preseve parameterized mixing - only down 5% at dx = 750 m
7340 psig_bl= ((dxdh**2) + 0.106*(dxdh**0.667))/((dxdh**2) +0.066*(dxdh**0.667) + 0.071)
7341
7342 !assume a 500 m cloud depth for shallow-cu clods
7343 dxdh=max(2.5*dx,10.)/min(pbl1+500.,3500.)
7344 ! Honnert et al. 2011, TKE in entrainment layer *** original form used until 201605
7345 !Psig_shcu= ((dxdh**2) + (4./21.)*(dxdh**0.667))/((dxdh**2) + &
7346 ! (3./20.)*(dxdh**0.67) + (7./21.))
7347
7348 ! Honnert et al. 2011, TKE in cumulus
7349 !Psig(i)= ((dxdh**2) + 1.67*(dxdh**1.4))/((dxdh**2) +1.66*(dxdh**1.4) +
7350 !0.2)
7351
7352 ! Honnert et al. 2011, w'q' in PBL
7353 !Psig(i)= 0.5 + 0.5*((dxdh**2) + 0.03*(dxdh**1.4) -
7354 !(4./13.))/((dxdh**2) + 0.03*(dxdh**1.4) + (4./13.))
7355 ! Honnert et al. 2011, w'q' in cumulus
7356 !Psig(i)= ((dxdh**2) - 0.07*(dxdh**1.4))/((dxdh**2) -0.07*(dxdh**1.4) +
7357 !0.02)
7358
7359 ! Honnert et al. 2011, q'q' in PBL
7360 !Psig(i)= 0.5 + 0.5*((dxdh**2) + 0.25*(dxdh**0.667) -0.73)/((dxdh**2)
7361 !-0.03*(dxdh**0.667) + 0.73)
7362 ! Honnert et al. 2011, q'q' in cumulus
7363 !Psig(i)= ((dxdh**2) - 0.34*(dxdh**1.4))/((dxdh**2) - 0.35*(dxdh**1.4)
7364 !+ 0.37)
7365
7366 ! Hyeyum Hailey Shin and Song-You Hong 2013, TKE in PBL (same as Honnert's above)
7367 !Psig_shcu= ((dxdh**2) + 0.070*(dxdh**0.667))/((dxdh**2)
7368 !+0.142*(dxdh**0.667) + 0.071)
7369 ! Hyeyum Hailey Shin and Song-You Hong 2013, TKE in entrainment zone *** switch to this form 201605
7370 psig_shcu= ((dxdh**2) + 0.145*(dxdh**0.667))/((dxdh**2) +0.172*(dxdh**0.667) + 0.170)
7371
7372 ! Hyeyum Hailey Shin and Song-You Hong 2013, w'theta' in PBL
7373 !Psig(i)= 0.5 + 0.5*((dxdh**2) -0.098)/((dxdh**2) + 0.106)
7374 ! Hyeyum Hailey Shin and Song-You Hong 2013, w'theta' in entrainment zone
7375 !Psig(i)= 0.5 + 0.5*((dxdh**2) - 0.112*(dxdh**0.25) -0.071)/((dxdh**2)
7376 !+ 0.054*(dxdh**0.25) + 0.10)
7377
7378 !print*,"in scale_aware; dx, dxdh, Psig(i)=",dx,dxdh,Psig(i)
7379 !If(Psig_bl(i) < 0.0 .OR. Psig(i) > 1.)print*,"dx, dxdh, Psig(i)=",dx,dxdh,Psig_bl(i)
7380 If(psig_bl > 1.0) psig_bl=1.0
7381 If(psig_bl < 0.0) psig_bl=0.0
7382
7383 If(psig_shcu > 1.0) psig_shcu=1.0
7384 If(psig_shcu < 0.0) psig_shcu=0.0
7385
7386 END SUBROUTINE scale_aware
7387
7388! =====================================================================
7396 FUNCTION esat_blend(t)
7397
7398 IMPLICIT NONE
7399
7400 real(kind_phys), intent(in):: t
7401 real(kind_phys):: esat_blend,xc,esl,esi,chi
7402 !liquid
7403 real(kind_phys), parameter:: j0= .611583699e03
7404 real(kind_phys), parameter:: j1= .444606896e02
7405 real(kind_phys), parameter:: j2= .143177157e01
7406 real(kind_phys), parameter:: j3= .264224321e-1
7407 real(kind_phys), parameter:: j4= .299291081e-3
7408 real(kind_phys), parameter:: j5= .203154182e-5
7409 real(kind_phys), parameter:: j6= .702620698e-8
7410 real(kind_phys), parameter:: j7= .379534310e-11
7411 real(kind_phys), parameter:: j8=-.321582393e-13
7412 !ice
7413 real(kind_phys), parameter:: k0= .609868993e03
7414 real(kind_phys), parameter:: k1= .499320233e02
7415 real(kind_phys), parameter:: k2= .184672631e01
7416 real(kind_phys), parameter:: k3= .402737184e-1
7417 real(kind_phys), parameter:: k4= .565392987e-3
7418 real(kind_phys), parameter:: k5= .521693933e-5
7419 real(kind_phys), parameter:: k6= .307839583e-7
7420 real(kind_phys), parameter:: k7= .105785160e-9
7421 real(kind_phys), parameter:: k8= .161444444e-12
7422
7423 xc=max(-80.,t - t0c) !note t0c = 273.15, tice is set in module mynn_common to 240
7424
7425! For 240 < t < 268.16 K, the vapor pressures are "blended" as a function of temperature,
7426! using the approach similar to Chaboureau and Bechtold (2002), JAS, p. 2363. The resulting
7427! values are returned from the function.
7428 IF (t .GE. (t0c-6.)) THEN
7429 esat_blend = j0+xc*(j1+xc*(j2+xc*(j3+xc*(j4+xc*(j5+xc*(j6+xc*(j7+xc*j8)))))))
7430 ELSE IF (t .LE. tice) THEN
7431 esat_blend = k0+xc*(k1+xc*(k2+xc*(k3+xc*(k4+xc*(k5+xc*(k6+xc*(k7+xc*k8)))))))
7432 ELSE
7433 esl = j0+xc*(j1+xc*(j2+xc*(j3+xc*(j4+xc*(j5+xc*(j6+xc*(j7+xc*j8)))))))
7434 esi = k0+xc*(k1+xc*(k2+xc*(k3+xc*(k4+xc*(k5+xc*(k6+xc*(k7+xc*k8)))))))
7435 chi = ((t0c-6.) - t)/((t0c-6.) - tice)
7436 esat_blend = (1.-chi)*esl + chi*esi
7437 END IF
7438
7439 END FUNCTION esat_blend
7440
7441! ====================================================================
7442
7447 FUNCTION qsat_blend(t, P)
7448
7449 IMPLICIT NONE
7450
7451 real(kind_phys), intent(in):: t, p
7452 real(kind_phys):: qsat_blend,xc,esl,esi,rslf,rsif,chi
7453 !liquid
7454 real(kind_phys), parameter:: j0= .611583699e03
7455 real(kind_phys), parameter:: j1= .444606896e02
7456 real(kind_phys), parameter:: j2= .143177157e01
7457 real(kind_phys), parameter:: j3= .264224321e-1
7458 real(kind_phys), parameter:: j4= .299291081e-3
7459 real(kind_phys), parameter:: j5= .203154182e-5
7460 real(kind_phys), parameter:: j6= .702620698e-8
7461 real(kind_phys), parameter:: j7= .379534310e-11
7462 real(kind_phys), parameter:: j8=-.321582393e-13
7463 !ice
7464 real(kind_phys), parameter:: k0= .609868993e03
7465 real(kind_phys), parameter:: k1= .499320233e02
7466 real(kind_phys), parameter:: k2= .184672631e01
7467 real(kind_phys), parameter:: k3= .402737184e-1
7468 real(kind_phys), parameter:: k4= .565392987e-3
7469 real(kind_phys), parameter:: k5= .521693933e-5
7470 real(kind_phys), parameter:: k6= .307839583e-7
7471 real(kind_phys), parameter:: k7= .105785160e-9
7472 real(kind_phys), parameter:: k8= .161444444e-12
7473
7474 xc=max(-80.,t - t0c)
7475
7476 IF (t .GE. (t0c-6.)) THEN
7477 esl = j0+xc*(j1+xc*(j2+xc*(j3+xc*(j4+xc*(j5+xc*(j6+xc*(j7+xc*j8)))))))
7478 esl = min(esl, p*0.15) ! Even with P=1050mb and T=55C, the sat. vap. pres only contributes to ~15% of total pres.
7479 qsat_blend = 0.622*esl/max(p-esl, 1e-5)
7480 ELSE IF (t .LE. tice) THEN
7481 esi = k0+xc*(k1+xc*(k2+xc*(k3+xc*(k4+xc*(k5+xc*(k6+xc*(k7+xc*k8)))))))
7482 esi = min(esi, p*0.15)
7483 qsat_blend = 0.622*esi/max(p-esi, 1e-5)
7484 ELSE
7485 esl = j0+xc*(j1+xc*(j2+xc*(j3+xc*(j4+xc*(j5+xc*(j6+xc*(j7+xc*j8)))))))
7486 esl = min(esl, p*0.15)
7487 esi = k0+xc*(k1+xc*(k2+xc*(k3+xc*(k4+xc*(k5+xc*(k6+xc*(k7+xc*k8)))))))
7488 esi = min(esi, p*0.15)
7489 rslf = 0.622*esl/max(p-esl, 1e-5)
7490 rsif = 0.622*esi/max(p-esi, 1e-5)
7491! chi = (268.16-t)/(268.16-240.)
7492 chi = ((t0c-6.) - t)/((t0c-6.) - tice)
7493 qsat_blend = (1.-chi)*rslf + chi*rsif
7494 END IF
7495
7496 END FUNCTION qsat_blend
7497
7498! ===================================================================
7499
7505 FUNCTION xl_blend(t)
7506
7507 IMPLICIT NONE
7508
7509 real(kind_phys), intent(in):: t
7510 real(kind_phys):: xl_blend,xlvt,xlst,chi
7511 !note: t0c = 273.15, tice is set in mynn_common
7512
7513 IF (t .GE. t0c) THEN
7514 xl_blend = xlv + (cpv-cliq)*(t-t0c) !vaporization/condensation
7515 ELSE IF (t .LE. tice) THEN
7516 xl_blend = xls + (cpv-cice)*(t-t0c) !sublimation/deposition
7517 ELSE
7518 xlvt = xlv + (cpv-cliq)*(t-t0c) !vaporization/condensation
7519 xlst = xls + (cpv-cice)*(t-t0c) !sublimation/deposition
7520! chi = (273.16-t)/(273.16-240.)
7521 chi = (t0c - t)/(t0c - tice)
7522 xl_blend = (1.-chi)*xlvt + chi*xlst !blended
7523 END IF
7524
7525 END FUNCTION xl_blend
7526
7527! ===================================================================
7528
7529 FUNCTION phim(zet)
7530 ! New stability function parameters for momentum (Puhales, 2020, WRF 4.2.1)
7531 ! The forms in unstable conditions (z/L < 0) use Grachev et al. (2000), which are a blend of
7532 ! the classical (Kansas) forms (i.e., Paulson 1970, Dyer and Hicks 1970), valid for weakly
7533 ! unstable conditions (-1 < z/L < 0). The stability functions for stable conditions use an
7534 ! updated form taken from Cheng and Brutsaert (2005), which extends the validity into very
7535 ! stable conditions [z/L ~ O(10)].
7536 IMPLICIT NONE
7537
7538 real(kind_phys), intent(in):: zet
7539 real(kind_phys):: dummy_0,dummy_1,dummy_11,dummy_2,dummy_22,dummy_3,dummy_33,dummy_4,dummy_44,dummy_psi
7540 real(kind_phys), parameter :: am_st=6.1, bm_st=2.5, rbm_st=1./bm_st
7541 real(kind_phys), parameter :: ah_st=5.3, bh_st=1.1, rbh_st=1./bh_st
7542 real(kind_phys), parameter :: am_unst=10., ah_unst=34.
7543 real(kind_phys):: phi_m,phim
7544
7545 if ( zet >= 0.0 ) then
7546 dummy_0=1+zet**bm_st
7547 dummy_1=zet+dummy_0**(rbm_st)
7548 dummy_11=1+dummy_0**(rbm_st-1)*zet**(bm_st-1)
7549 dummy_2=(-am_st/dummy_1)*dummy_11
7550 phi_m = 1-zet*dummy_2
7551 else
7552 dummy_0 = (1.0-cphm_unst*zet)**0.25
7553 phi_m = 1./dummy_0
7554 dummy_psi = 2.*log(0.5*(1.+dummy_0))+log(0.5*(1.+dummy_0**2))-2.*atan(dummy_0)+1.570796
7555
7556 dummy_0=(1.-am_unst*zet) ! parentesis arg
7557 dummy_1=dummy_0**0.333333 ! y
7558 dummy_11=-0.33333*am_unst*dummy_0**(-0.6666667) ! dy/dzet
7559 dummy_2 = 0.33333*(dummy_1**2.+dummy_1+1.) ! f
7560 dummy_22 = 0.3333*dummy_11*(2.*dummy_1+1.) ! df/dzet
7561 dummy_3 = 0.57735*(2.*dummy_1+1.) ! g
7562 dummy_33 = 1.1547*dummy_11 ! dg/dzet
7563 dummy_4 = 1.5*log(dummy_2)-1.73205*atan(dummy_3)+1.813799364 !psic
7564 dummy_44 = (1.5/dummy_2)*dummy_22-1.73205*dummy_33/(1.+dummy_3**2)! dpsic/dzet
7565
7566 dummy_0 = zet**2
7567 dummy_1 = 1./(1.+dummy_0) ! denon
7568 dummy_11 = 2.*zet ! denon/dzet
7569 dummy_2 = ((1-phi_m)/zet+dummy_11*dummy_4+dummy_0*dummy_44)*dummy_1
7570 dummy_22 = -dummy_11*(dummy_psi+dummy_0*dummy_4)*dummy_1**2
7571
7572 phi_m = 1.-zet*(dummy_2+dummy_22)
7573 end if
7574
7575 !phim = phi_m - zet
7576 phim = phi_m
7577
7578 END FUNCTION phim
7579! ===================================================================
7580
7581 FUNCTION phih(zet)
7582 ! New stability function parameters for heat (Puhales, 2020, WRF 4.2.1)
7583 ! The forms in unstable conditions (z/L < 0) use Grachev et al. (2000), which are a blend of
7584 ! the classical (Kansas) forms (i.e., Paulson 1970, Dyer and Hicks 1970), valid for weakly
7585 ! unstable conditions (-1 < z/L < 0). The stability functions for stable conditions use an
7586 ! updated form taken from Cheng and Brutsaert (2005), which extends the validity into very
7587 ! stable conditions [z/L ~ O(10)].
7588 IMPLICIT NONE
7589
7590 real(kind_phys), intent(in):: zet
7591 real(kind_phys):: dummy_0,dummy_1,dummy_11,dummy_2,dummy_22,dummy_3,dummy_33,dummy_4,dummy_44,dummy_psi
7592 real(kind_phys), parameter :: am_st=6.1, bm_st=2.5, rbm_st=1./bm_st
7593 real(kind_phys), parameter :: ah_st=5.3, bh_st=1.1, rbh_st=1./bh_st
7594 real(kind_phys), parameter :: am_unst=10., ah_unst=34.
7595 real(kind_phys):: phh,phih
7596
7597 if ( zet >= 0.0 ) then
7598 dummy_0=1+zet**bh_st
7599 dummy_1=zet+dummy_0**(rbh_st)
7600 dummy_11=1+dummy_0**(rbh_st-1)*zet**(bh_st-1)
7601 dummy_2=(-ah_st/dummy_1)*dummy_11
7602 phih = 1-zet*dummy_2
7603 else
7604 dummy_0 = (1.0-cphh_unst*zet)**0.5
7605 phh = 1./dummy_0
7606 dummy_psi = 2.*log(0.5*(1.+dummy_0))
7607
7608 dummy_0=(1.-ah_unst*zet) ! parentesis arg
7609 dummy_1=dummy_0**0.333333 ! y
7610 dummy_11=-0.33333*ah_unst*dummy_0**(-0.6666667) ! dy/dzet
7611 dummy_2 = 0.33333*(dummy_1**2.+dummy_1+1.) ! f
7612 dummy_22 = 0.3333*dummy_11*(2.*dummy_1+1.) ! df/dzet
7613 dummy_3 = 0.57735*(2.*dummy_1+1.) ! g
7614 dummy_33 = 1.1547*dummy_11 ! dg/dzet
7615 dummy_4 = 1.5*log(dummy_2)-1.73205*atan(dummy_3)+1.813799364 !psic
7616 dummy_44 = (1.5/dummy_2)*dummy_22-1.73205*dummy_33/(1.+dummy_3**2)! dpsic/dzet
7617
7618 dummy_0 = zet**2
7619 dummy_1 = 1./(1.+dummy_0) ! denon
7620 dummy_11 = 2.*zet ! ddenon/dzet
7621 dummy_2 = ((1-phh)/zet+dummy_11*dummy_4+dummy_0*dummy_44)*dummy_1
7622 dummy_22 = -dummy_11*(dummy_psi+dummy_0*dummy_4)*dummy_1**2
7623
7624 phih = 1.-zet*(dummy_2+dummy_22)
7625 end if
7626
7627END FUNCTION phih
7628! ==================================================================
7629 SUBROUTINE topdown_cloudrad(kts,kte,dz1,zw,xland,kpbl,PBLH, &
7630 &sqc,sqi,sqw,thl,th1,ex1,p1,rho1,thetav, &
7631 &cldfra_bl1D,rthraten, &
7632 &maxKHtopdown,KHtopdown,TKEprodTD )
7633
7634 !input
7635 integer, intent(in) :: kte,kts
7636 real(kind_phys), dimension(kts:kte), intent(in) :: dz1,sqc,sqi,sqw,&
7637 thl,th1,ex1,p1,rho1,thetav,cldfra_bl1D
7638 real(kind_phys), dimension(kts:kte), intent(in) :: rthraten
7639 real(kind_phys), dimension(kts:kte+1), intent(in) :: zw
7640 real(kind_phys), intent(in) :: pblh
7641 real(kind_phys), intent(in) :: xland
7642 integer , intent(in) :: kpbl
7643 !output
7644 real(kind_phys), intent(out) :: maxKHtopdown
7645 real(kind_phys), dimension(kts:kte), intent(out) :: KHtopdown,TKEprodTD
7646 !local
7647 real(kind_phys), dimension(kts:kte) :: zfac,wscalek2,zfacent
7648 real(kind_phys) :: bfx0,sflux,wm2,wm3,h1,h2,bfxpbl,dthvx,tmp1
7649 real(kind_phys) :: temps,templ,zl1,wstar3_2
7650 real(kind_phys) :: ent_eff,radsum,radflux,we,rcldb,rvls,minrad,zminrad
7651 real(kind_phys), parameter :: pfac =2.0, zfmin = 0.01, phifac=8.0
7652 integer :: k,kk,kminrad
7653 logical :: cloudflg
7654
7655 cloudflg=.false.
7656 minrad=100.
7657 kminrad=kpbl
7658 zminrad=pblh
7659 khtopdown(kts:kte)=0.0
7660 tkeprodtd(kts:kte)=0.0
7661 maxkhtopdown=0.0
7662
7663 !CHECK FOR STRATOCUMULUS-TOPPED BOUNDARY LAYERS
7664 DO kk = max(1,kpbl-2),kpbl+3
7665 if (sqc(kk).gt. 1.e-6 .OR. sqi(kk).gt. 1.e-6 .OR. &
7666 cldfra_bl1d(kk).gt.0.5) then
7667 cloudflg=.true.
7668 endif
7669 if (rthraten(kk) < minrad)then
7670 minrad=rthraten(kk)
7671 kminrad=kk
7672 zminrad=zw(kk) + 0.5*dz1(kk)
7673 endif
7674 ENDDO
7675
7676 IF (max(kminrad,kpbl) < 2)cloudflg = .false.
7677 IF (cloudflg) THEN
7678 zl1 = dz1(kts)
7679 k = max(kpbl-1, kminrad-1)
7680 !Best estimate of height of TKE source (top of downdrafts):
7681 !zminrad = 0.5*pblh(i) + 0.5*zminrad
7682
7683 templ=thl(k)*ex1(k)
7684 !rvls is ws at full level
7685 rvls=100.*6.112*exp(17.67*(templ-273.16)/(templ-29.65))*(ep_2/p1(k+1))
7686 temps=templ + (sqw(k)-rvls)/(cp/xlv + ep_2*xlv*rvls/(r_d*templ**2))
7687 rvls=100.*6.112*exp(17.67*(temps-273.15)/(temps-29.65))*(ep_2/p1(k+1))
7688 rcldb=max(sqw(k)-rvls,0.)
7689
7690 !entrainment efficiency
7691 dthvx = (thl(k+2) + th1(k+2)*p608*sqw(k+2)) &
7692 - (thl(k) + th1(k) *p608*sqw(k))
7693 dthvx = max(dthvx,0.1)
7694 tmp1 = xlvcp * rcldb/(ex1(k)*dthvx)
7695 !Originally from Nichols and Turton (1986), where a2 = 60, but lowered
7696 !here to 8, as in Grenier and Bretherton (2001).
7697 ent_eff = 0.2 + 0.2*8.*tmp1
7698
7699 radsum=0.
7700 DO kk = max(1,kpbl-3),kpbl+3
7701 radflux=rthraten(kk)*ex1(kk) !converts theta/s to temp/s
7702 radflux=radflux*cp/grav*(p1(kk)-p1(kk+1)) ! converts temp/s to W/m^2
7703 if (radflux < 0.0 ) radsum=abs(radflux)+radsum
7704 ENDDO
7705
7706 !More strict limits over land to reduce stable-layer mixouts
7707 if ((xland-1.5).GE.0)THEN ! WATER
7708 radsum=min(radsum,90.0)
7709 bfx0 = max(radsum/rho1(k)/cp,0.)
7710 else ! LAND
7711 radsum=min(0.25*radsum,30.0)!practically turn off over land
7712 bfx0 = max(radsum/rho1(k)/cp - max(sflux,0.0),0.)
7713 endif
7714
7715 !entrainment from PBL top thermals
7716 wm3 = grav/thetav(k)*bfx0*min(pblh,1500.) ! this is wstar3(i)
7717 wm2 = wm2 + wm3**h2
7718 bfxpbl = - ent_eff * bfx0
7719 dthvx = max(thetav(k+1)-thetav(k),0.1)
7720 we = max(bfxpbl/dthvx,-sqrt(wm3**h2))
7721
7722 DO kk = kts,kpbl+3
7723 !Analytic vertical profile
7724 zfac(kk) = min(max((1.-(zw(kk+1)-zl1)/(zminrad-zl1)),zfmin),1.)
7725 zfacent(kk) = 10.*max((zminrad-zw(kk+1))/zminrad,0.0)*(1.-zfac(kk))**3
7726
7727 !Calculate an eddy diffusivity profile (not used at the moment)
7728 wscalek2(kk) = (phifac*karman*wm3*(zfac(kk)))**h1
7729 !Modify shape of Kh to be similar to Lock et al (2000): use pfac = 3.0
7730 khtopdown(kk) = wscalek2(kk)*karman*(zminrad-zw(kk+1))*(1.-zfac(kk))**3 !pfac
7731 khtopdown(kk) = max(khtopdown(kk),0.0)
7732
7733 !Calculate TKE production = 2(g/TH)(w'TH'), where w'TH' = A(TH/g)wstar^3/PBLH,
7734 !A = ent_eff, and wstar is associated with the radiative cooling at top of PBL.
7735 !An analytic profile controls the magnitude of this TKE prod in the vertical.
7736 tkeprodtd(kk)=2.*ent_eff*wm3/max(pblh,100.)*zfacent(kk)
7737 tkeprodtd(kk)= max(tkeprodtd(kk),0.0)
7738 ENDDO
7739 ENDIF !end cloud check
7740 maxkhtopdown=maxval(khtopdown(:))
7741
7742 END SUBROUTINE topdown_cloudrad
7743! ==================================================================
7744! ===================================================================
7745! ===================================================================
7746
7747END MODULE module_bl_mynn
subroutine mym_turbulence(kts, kte, xland, closure, dz, dx, zw, u, v, thl, thetav, ql, qw, qke, tsq, qsq, cov, vt, vq, rmo, flt, fltv, flq, zi, theta, sh, sm, el, dfm, dfh, dfq, tcd, qcd, pdk, pdt, pdq, pdc, qwt1d, qshear1d, qbuoy1d, qdiss1d, tke_budget, psig_bl, psig_shcu, cldfra_bl1d, bl_mynn_mixlength, edmf_w1, edmf_a1, tkeprodtd, spp_pbl, rstoch_col)
This subroutine calculates the vertical diffusivity coefficients and the production terms for the tur...
subroutine get_pblh(kts, kte, zi, thetav1d, qke1d, zw1d, dz1d, landsea, kzi)
This subroutine calculates hybrid diagnotic boundary-layer height (PBLH).
subroutine dmp_mf(kts, kte, dt, zw, dz, p, rho, momentum_opt, tke_opt, scalar_opt, u, v, w, th, thl, thv, tk, qt, qv, qc, qke, qnc, qni, qnwfa, qnifa, qnbca, exner, vt, vq, sgm, ust, flt, fltv, flq, flqv, pblh, kpbl, dx, landsea, ts, edmf_a, edmf_w, edmf_qt, edmf_thl, edmf_ent, edmf_qc, s_aw, s_awthl, s_awqt, s_awqv, s_awqc, s_awu, s_awv, s_awqke, s_awqnc, s_awqni, s_awqnwfa, s_awqnifa, s_awqnbca, sub_thl, sub_sqv, sub_u, sub_v, det_thl, det_sqv, det_sqc, det_u, det_v, nchem, chem1, s_awchem, mix_chem, qc_bl1d, cldfra_bl1d, qc_bl1d_old, cldfra_bl1d_old, f_qc, f_qi, f_qnc, f_qni, f_qnwfa, f_qnifa, f_qnbca, psig_shcu, maxwidth, ktop, maxmf, ztop, spp_pbl, rstoch_col)
This subroutine is the Dynamic Multi-Plume (DMP) Mass-Flux Scheme.
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)
This subroutine calculates the mixing lengths.
subroutine mym_level2(kts, kte, dz, u, v, thl, thetav, qw, ql, vt, vq, dtl, dqw, dtv, gm, gh, sm, sh)
This subroutine calculates the level 2, non-dimensional wind shear and vertical temperature gradient...
real(kind_phys) function qsat_blend(t, p)
This function extends function "esat" and returns a "blended" saturation mixing ratio....
subroutine tridiag2(n, a, b, c, d, x)
subroutine tridiag(n, a, b, c, d)
subroutine mynn_bl_driver(initflag, restart, cycling, delt, dz, dx, znt, u, v, w, th, sqv3d, sqc3d, sqi3d, sqs3d, qnc, qni, qnwfa, qnifa, qnbca, ozone, p, exner, rho, t3d, xland, ts, qsfc, ps, ust, ch, hfx, qfx, rmol, wspd, uoce, voce, qke, qke_adv, sh3d, sm3d, nchem, kdvel, ndvel, chem3d, vdep, smoke_dbg, frp, emis_ant_no, mix_chem, enh_mix, rrfs_sd, tsq, qsq, cov, rublten, rvblten, rthblten, rqvblten, rqcblten, rqiblten, rqncblten, rqniblten, rqsblten, rqnwfablten, rqnifablten, rqnbcablten, dozone, exch_h, exch_m, pblh, kpbl, el_pbl, dqke, qwt, qshear, qbuoy, qdiss, qc_bl, qi_bl, cldfra_bl, bl_mynn_tkeadvect, tke_budget, bl_mynn_cloudpdf, bl_mynn_mixlength, icloud_bl, closure, bl_mynn_edmf, bl_mynn_edmf_mom, bl_mynn_edmf_tke, bl_mynn_mixscalars, bl_mynn_output, bl_mynn_cloudmix, bl_mynn_mixqt, edmf_a, edmf_w, edmf_qt, edmf_thl, edmf_ent, edmf_qc, sub_thl3d, sub_sqv3d, det_thl3d, det_sqv3d, maxwidth, maxmf, ztop_plume, ktop_plume, spp_pbl, pattern_spp_pbl, rthraten, flag_qc, flag_qi, flag_qnc, flag_qni, flag_qs, flag_qnwfa, flag_qnifa, flag_qnbca, flag_ozone, ids, ide, jds, jde, kds, kde, ims, ime, jms, jme, kms, kme, its, ite, jts, jte, kts, kte)
This subroutine is the MYNN-EDNF PBL driver routine,which encompassed the majority of the subroutines...
subroutine mym_condensation(kts, kte, dx, dz, zw, xland, thl, qw, qv, qc, qi, qs, p, exner, tsq, qsq, cov, sh, el, bl_mynn_cloudpdf, qc_bl1d, qi_bl1d, cldfra_bl1d, pblh1, hfx1, vt, vq, th, sgm, rmo, spp_pbl, rstoch_col)
This subroutine calculates the nonconvective component of the subgrid cloud fraction and mixing ratio...
subroutine boulac_length0(k, kts, kte, zw, dz, qtke, theta, lb1, lb2)
This subroutine was taken from the BouLac scheme in WRF-ARW and modified for integration into the MYN...
subroutine condensation_edmf(qt, thl, p, zagl, thv, qc)
This subroutine.
subroutine mym_initialize(kts, kte, xland, dz, dx, zw, u, v, thl, qw, 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)
This subroutine initializes the mixing length, TKE, , , and .
real(kind_phys) function xl_blend(t)
This function interpolates the latent heats of vaporization and sublimation into a single,...
subroutine boulac_length(kts, kte, zw, dz, qtke, theta, lb1, lb2)
This subroutine was taken from the BouLac scheme in WRF-ARW and modified for integration into the MYN...
subroutine mynn_tendencies(kts, kte, i, delt, dz, rho, u, v, th, tk, qv, qc, qi, qs, qnc, qni, psfc, p, exner, thl, sqv, sqc, sqi, sqs, sqw, qnwfa, qnifa, qnbca, ozone, ust, flt, flq, flqv, flqc, wspd, uoce, voce, tsq, qsq, cov, tcd, qcd, dfm, dfh, dfq, du, dv, dth, dqv, dqc, dqi, dqs, dqnc, dqni, dqnwfa, dqnifa, dqnbca, dozone, diss_heat, s_aw, s_awthl, s_awqt, s_awqv, s_awqc, s_awu, s_awv, s_awqnc, s_awqni, s_awqnwfa, s_awqnifa, s_awqnbca, sd_aw, sd_awthl, sd_awqt, sd_awqv, sd_awqc, sd_awu, sd_awv, sub_thl, sub_sqv, sub_u, sub_v, det_thl, det_sqv, det_sqc, det_u, det_v, flag_qc, flag_qi, flag_qnc, flag_qni, flag_qs, flag_qnwfa, flag_qnifa, flag_qnbca, cldfra_bl1d, bl_mynn_cloudmix, bl_mynn_mixqt, bl_mynn_edmf, bl_mynn_edmf_mom, bl_mynn_mixscalars)
This subroutine solves for tendencies of U, V, , qv, qc, and qi.
subroutine tridiag3(kte, a, b, c, d, x)
real(kind_phys) function esat_blend(t)
subroutine mym_predict(kts, kte, closure, delt, dz, ust, flt, flq, pmz, phh, el, dfq, rho, pdk, pdt, pdq, pdc, qke, tsq, qsq, cov, s_aw, s_awqke, bl_mynn_edmf_tke, qwt1d, qdiss1d, tke_budget)
This subroutine predicts the turbulent quantities at the next step.
subroutine retrieve_exchange_coeffs(kts, kte, dfm, dfh, dz, k_m, k_h)
This module defines model-specific constants/parameters.
This module contains the entity of MYNN-EDMF PBL scheme.