-
Notifications
You must be signed in to change notification settings - Fork 5
/
sf_mynn.F90
2237 lines (1824 loc) · 83.1 KB
/
sf_mynn.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!=================================================================================================================
module sf_mynn
!-------------------------------------------------------------------
!Modifications implemented by Joseph Olson NOAA/GSL
!The following overviews the current state of this scheme::
!
! BOTH LAND AND WATER:
!1) Calculation of stability parameter (z/L) taken from Li et al. (2010 BLM)
! for first iteration of first time step; afterwards, exact calculation
! using a brute force iterative method described in Olson et al. (2021 NOAA
! Tech memorandum). This method replaces the iterative technique used in
! module_sf_sfclayrev.F (Jimenez et al. 2013) with mods. Either technique
! gives about the same result. The former technique is retained in this
! module (commented out) for potential subsequent benchmarking.
!2) Fixed isflux=0 option to turn off scalar fluxes, but keep momentum
! fluxes for idealized studies (credit: Anna Fitch).
!3) Kinematic viscosity varies with temperature according to Andreas (1989).
!4) Uses the blended Monin-Obukhov flux-profile relationships COARE (Fairall
! et al 2003) for the unstable regime (a blended mix of Dyer-Hicks 1974 and
! Grachev et al (2000). Uses Cheng and Brutsaert (2005) for stable conditions.
!5) The following overviews the namelist variables that control the
! aerodynamic roughness lengths (over water) and the thermal and moisture
! roughness lengths (defaults are recommended):
!
! LAND only:
! "iz0tlnd" namelist option is used to select the following options:
! (default) =0: Zilitinkevich (1995); Czil now set to 0.085
! =1: Czil_new (modified according to Chen & Zhang 2008)
! =2: Modified Yang et al (2002, 2008) - generalized for all landuse
! =3: constant zt = z0/7.4 (original form; Garratt 1992)
!
! WATER only:
! "isftcflx" namelist option is used to select the following options:
! (default) =0: z0, zt, and zq from the COARE algorithm. Set COARE_OPT (below) to
! 3.0 (Fairall et al. 2003, default)
! 3.5 (Edson et al 2013) - now with bug fix (Edson et al. 2014, JPO)
! =1: z0 from Davis et al (2008), zt & zq from COARE 3.0/3.5
! =2: z0 from Davis et al (2008), zt & zq from Garratt (1992)
! =3: z0 from Taylor and Yelland (2004), zt and zq from COARE 3.0/3.5
!
! SNOW/ICE only:
! Andreas (2002) snow/ice parameterization for thermal and
! moisture roughness is used over all gridpoints with snow deeper than
! 0.1 m. This algorithm calculates a z0 for snow (Andreas et al. 2005, BLM),
! which is only used as part of the thermal and moisture roughness
! length calculation, not to directly impact the surface winds.
!
! Misc:
!1) Added a more elaborate diagnostic for u10 & V10 for high vertical resolution
! model configurations but for most model configurations with depth of
! the lowest half-model level near 10 m, a neutral-log diagnostic is used.
!
!2) Option to activate stochastic parameter perturbations (SPP), which
! perturb z0, zt, and zq, along with many other parameters in the MYNN-
! EDMF scheme.
!
!NOTE: This code was primarily tested in combination with the RUC LSM.
! Performance with the Noah (or other) LSM is relatively unknown.
!-------------------------------------------------------------------
use ccpp_kind_types,only: kind_phys
use mynn_shared,only: esat_blend,qsat_blend,xl_blend
implicit none
private
public:: sf_mynn_run, &
sf_mynn_init, &
sf_mynn_finalize
logical,parameter:: debug_code = .false.
integer,parameter:: psi_opt = 0 ! 0 = stable: Cheng and Brustaert
! unstable: blended COARE
! 1 = GFS
real,parameter:: wmin = 0.1
real,parameter:: vconvc = 1.25
real,parameter:: snowz0 = 0.011
real,parameter:: coare_opt = 3.0 ! 3.0 or 3.5
!For debugging purposes:
real,dimension(0:1000),save:: psim_stab,psim_unstab, &
psih_stab,psih_unstab
contains
!=================================================================================================================
!>\section arg_table_sf_mynn_init
!!\html\include sf_mynn_init.html
!!
subroutine sf_mynn_init(errmsg,errflg)
!=================================================================================================================
!--- output arguments:
character(len=*),intent(out):: errmsg
integer,intent(out):: errflg
!-----------------------------------------------------------------------------------------------------------------
call psi_init(psi_opt)
errmsg = ' '
errflg = 0
end subroutine sf_mynn_init
!=================================================================================================================
!>\section arg_table_sf_mynn_finalize
!!\html\include sf_mynn_finalize.html
!!
subroutine sf_mynn_finalize(errmsg,errflg)
!=================================================================================================================
!--- output arguments:
character(len=*),intent(out):: errmsg
integer,intent(out):: errflg
!-----------------------------------------------------------------------------------------------------------------
errmsg = ' '
errflg = 0
end subroutine sf_mynn_finalize
!=================================================================================================================
!>\section arg_table_sf_mynn_run
!!\html\include sf_mynn_run.html
!!
subroutine sf_mynn_run( &
u1d,v1d,t1d,qv1d,p1d,dz8w1d,rho1d, &
u1d2,v1d2,dz2w1d,cp,g,rovcp,r,xlv, &
psfcpa,chs,chs2,cqs2,cpm,pblh,rmol, &
znt,ust,mavail,zol,mol,regime,psim, &
psih,xland,hfx,qfx,tsk,u10,v10,th2, &
t2,q2,flhc,flqc,snowh,qgh,qsfc,lh, &
gz1oz0,wspd,br,isfflx,dx,svp1,svp2, &
svp3,svpt0,ep1,ep2,karman,ch,qcg, &
itimestep,wstar,qstar,ustm,ck,cka, &
cd,cda,spp_pbl,rstoch1d,isftcflx, &
iz0tlnd,its,ite,errmsg,errflg &
)
implicit none
!=================================================================================================================
!-----------------------------
! scalars:
!-----------------------------
integer,intent(in):: its,ite
integer,intent(in):: itimestep
real(kind=kind_phys),intent(in):: svp1,svp2,svp3,svpt0,ep1,ep2
real(kind=kind_phys),intent(in):: karman,cp,g,rovcp,r,xlv
real(kind=kind_phys),parameter:: prt=1. !prandlt number
real(kind=kind_phys),parameter:: xka=2.4e-5 !molecular diffusivity
character(len=*),intent(out):: errmsg
integer,intent(out):: errflg
!-----------------------------
! namelist options
!-----------------------------
logical,intent(in):: spp_pbl
integer,intent(in):: isfflx
integer,intent(in),optional:: isftcflx,iz0tlnd
!-----------------------------
! 1d arrays
!-----------------------------
real(kind=kind_phys),intent(in),dimension(its:ite):: mavail, &
pblh, &
xland, &
tsk, &
psfcpa, &
qcg, &
snowh, &
dx
real(kind=kind_phys),intent(in),dimension(its:ite):: u1d, &
v1d, &
u1d2, &
v1d2, &
qv1d, &
p1d, &
t1d, &
dz8w1d, &
dz2w1d, &
rho1d
real(kind=kind_phys),intent(in),dimension(its:ite):: &
rstoch1d
real(kind=kind_phys),intent(inout),dimension(its:ite):: &
regime, &
hfx, &
qfx, &
lh, &
mol, &
rmol, &
qgh, &
qsfc, &
znt, &
zol, &
ust, &
cpm, &
chs2, &
cqs2, &
chs, &
ch, &
flhc, &
flqc, &
gz1oz0, &
wspd, &
br, &
psim, &
psih
!-----------------------------
! diagnostic outputs:
!-----------------------------
real(kind=kind_phys),intent(out),dimension(its:ite):: &
u10, &
v10, &
th2, &
t2, &
q2
real(kind=kind_phys),intent(out),dimension(its:ite):: &
wstar, &
qstar
real(kind=kind_phys),intent(out),dimension(its:ite),optional:: &
ck, &
cka, &
cd, &
cda, &
ustm
!-----------------------------
! local variables
!-----------------------------
integer:: n,i,k,l,yesno
real(kind=kind_phys):: ep3
real(kind=kind_phys):: pl,thcon,tvcon,e1
real(kind=kind_phys):: dthvdz,dthvm,vconv,zol2,zol10,zolza,zolz0,zolzt
real(kind=kind_phys):: dtg,psix,dtthx,dthdz,psix10,psit,psit2, &
psiq,psiq2,psiq10,dzdt
real(kind=kind_phys):: fluxc,vsgd
real(kind=kind_phys):: restar,visc,dqg,oldust,oldtst
real(kind=kind_phys),dimension(its:ite) :: &
za, & !height of lowest 1/2 sigma level(m)
za2, & !height of 2nd lowest 1/2 sigma level(m)
thv1d, & !theta-v at lowest 1/2 sigma (K)
th1d, & !theta at lowest 1/2 sigma (K)
tc1d, & !t at lowest 1/2 sigma (Celsius)
tv1d, & !tv at lowest 1/2 sigma (K)
qvsh, & !qv at lowest 1/2 sigma (spec humidity)
psih2, & !m-o stability functions at z=2 m
psim10, & !m-o stability functions at z=10 m
psih10, & !m-o stability functions at z=10 m
wspdi, &
z_q, & !moisture roughness length
z_t, & !thermalroughness length
ZNTstoch, &
govrth, & !g/theta
thgb, & !theta at ground
thvgb, & !theta-v at ground
psfc, & !press at surface (Pa/1000)
qsfcmr, & !qv at surface (mixing ratio, kg/kg)
gz2oz0, & !log((2.0+znt(i))/znt(i))
gz10oz0, & !log((10.+znt(i))/znt(i))
gz2ozt, & !log((2.0+z_t(i))/z_t(i))
gz10ozt, & !log((10.+z_t(i))/z_t(i))
gz1ozt, & !log((za(i)+z_t(i))/z_t(i))
zratio !z0/zt
!-----------------------------------------------------------------------------------------------------------------
ep3 = 1.-ep2
do i=its,ite
!convert ground & lowest layer temperature to potential temperature:
!psfc cmb
psfc(i)=psfcpa(i)/1000.
thgb(i)=tsk(i)*(100./psfc(i))**rovcp !(K)
!PL cmb
pl=p1d(i)/1000.
thcon=(100./pl)**rovcp
th1d(i)=t1d(i)*thcon !(Theta, K)
tc1d(i)=t1d(i)-273.15 !(T, Celsius)
!convert to virtual temperature
qvsh(i)=qv1d(i)/(1.+qv1d(i)) !convert to spec hum (kg/kg)
tvcon=(1.+ep1*qvsh(i))
thv1d(i)=th1d(i)*tvcon !(K)
tv1d(i)=t1d(i)*tvcon !(K)
!rho1d(i)=psfcpa(i)/(r*tv1d(i)) !now using value calculated in sfc driver
za(i)=0.5*dz8w1d(i) !height of first half-sigma level
za2(i)=dz8w1d(i) + 0.5*dz2w1d(i) !height of 2nd half-sigma level
govrth(i)=g/th1d(i)
enddo
do i=its,ite
if (tsk(i) .lt. 273.15) then
!saturation vapor pressure wrt ice (svp1=.6112; 10*mb)
e1=svp1*exp(4648*(1./273.15 - 1./tsk(i)) - &
& 11.64*log(273.15/tsk(i)) + 0.02265*(273.15 - tsk(i)))
else
!saturation vapor pressure wrt water (Bolton 1980)
e1=svp1*exp(svp2*(tsk(i)-svpt0)/(tsk(i)-svp3))
endif
!for land points, qsfc can come from lsm, only recompute over water
if (xland(i).gt.1.5 .or. qsfc(i).le.0.0) then !water
qsfc(i)=ep2*e1/(psfc(i)-ep3*e1) !specific humidity
qsfcmr(i)=ep2*e1/(psfc(i)-e1) !mixing ratio
else !land
qsfcmr(i)=qsfc(i)/(1.-qsfc(i))
endif
!qgh changed to use lowest-level air temp consistent with myjsfc change
!q2sat = qgh in LSM
if (tsk(i) .lt. 273.15) then
!saturation vapor pressure wrt ice
e1=svp1*exp(4648*(1./273.15 - 1./t1d(i)) - &
& 11.64*log(273.15/t1d(i)) + 0.02265*(273.15 - t1d(i)))
else
!saturation vapor pressure wrt water (Bolton 1980)
e1=svp1*exp(svp2*(t1d(i)-svpt0)/(t1d(i)-svp3))
endif
pl=p1d(i)/1000.
!qgh(i)=ep2*e1/(pl-ep_3*e1) !specific humidity
qgh(i)=ep2*e1/(pl-e1) !mixing ratio
cpm(i)=cp*(1.+0.84*qv1d(i))
enddo
do i=its,ite
wspd(i)=sqrt(u1d(i)*u1d(i)+v1d(i)*v1d(i))
!tgs:thvgb(i)=thgb(i)*(1.+ep1*qsfc(i)*mavail(i))
thvgb(i)=thgb(i)*(1.+ep1*qsfc(i))
dthdz=(th1d(i)-thgb(i))
dthvdz=(thv1d(i)-thvgb(i))
!--------------------------------------------------------
! Calculate the convective velocity scale (WSTAR) and
! subgrid-scale velocity (VSGD) following Beljaars (1995, QJRMS)
! and Mahrt and Sun (1995, MWR), respectively
!-------------------------------------------------------
!Use Beljaars over land and water
fluxc = max(hfx(i)/rho1d(i)/cp &
& + ep1*thvgb(i)*qfx(i)/rho1d(i),0.)
!wstar(i) = vconvc*(g/tsk(i)*pblh(i)*fluxc)**.33
if (xland(i).gt.1.5 .or. qsfc(i).le.0.0) then !water
wstar(i) = vconvc*(g/tsk(i)*pblh(i)*fluxc)**.33
else !land
!increase height scale, assuming that the non-local transoport
!from the mass-flux (plume) mixing exceedsd the pblh.
wstar(i) = vconvc*(g/tsk(i)*min(1.5*pblh(i),4000.)*fluxc)**.33
endif
!--------------------------------------------------------
! Mahrt and Sun low-res correction
! (for 13 km ~ 0.37 m/s; for 3 km == 0 m/s)
!--------------------------------------------------------
vsgd = 0.32 * (max(dx(i)/5000.-1.,0.))**.33
wspd(i)=sqrt(wspd(i)*wspd(i)+wstar(i)*wstar(i)+vsgd*vsgd)
wspd(i)=max(wspd(i),wmin)
!--------------------------------------------------------
! calculate the bulk richardson number of surface layer,
! according to Akb(1976), Eq(12).
!--------------------------------------------------------
br(i)=govrth(i)*za(i)*dthvdz/(wspd(i)*wspd(i))
if (itimestep == 1) then
!set limits according to Li et al. (2010) boundary-layer meteorol (p.158)
br(i)=max(br(i),-2.0)
br(i)=min(br(i),2.0)
else
br(i)=max(br(i),-4.0)
br(i)=min(br(i), 4.0)
endif
! if previously unstable, do not let into regimes 1 and 2 (stable)
! if (itimestep .gt. 1) then
! if(mol(i).lt.0.)br(i)=min(br(i),0.0)
!endif
enddo
1006 format(a,f7.3,a,f9.4,a,f9.5,a,f9.4)
1007 format(a,f2.0,a,f6.2,a,f7.3,a,f7.2)
!--------------------------------------------------------------------
!--------------------------------------------------------------------
!--- begin i-loop
!--------------------------------------------------------------------
!--------------------------------------------------------------------
do i=its,ite
!compute kinematic viscosity (m2/s) Andreas (1989) CRREL Rep. 89-11
!valid between -173 and 277 degrees C.
visc=1.326e-5*(1. + 6.542e-3*tc1d(i) + 8.301e-6*tc1d(i)*tc1d(i) &
- 4.84e-9*tc1d(i)*tc1d(i)*tc1d(i))
if ((xland(i)-1.5).ge.0) then
!--------------------------------------
! water
!--------------------------------------
! calculate z0 (znt)
!--------------------------------------
if ( present(isftcflx) ) then
if ( isftcflx .eq. 0 ) then
if (coare_opt .eq. 3.0) then
!COARE 3.0 (misleading subroutine name)
call charnock_1955(znt(i),ust(i),wspd(i),visc,za(i))
else
!COARE 3.5
call edson_etal_2013(znt(i),ust(i),wspd(i),visc,za(i))
endif
elseif ( isftcflx .eq. 1 .or. isftcflx .eq. 2 ) then
call davis_etal_2008(znt(i),ust(i))
elseif ( isftcflx .eq. 3 ) then
call taylor_yelland_2001(znt(i),ust(i),wspd(i))
elseif ( isftcflx .eq. 4 ) then
if (coare_opt .eq. 3.0) then
!COARE 3.0 (MISLEADING SUBROUTINE NAME)
call charnock_1955(znt(i),ust(i),wspd(i),visc,za(i))
else
!COARE 3.5
call edson_etal_2013(znt(i),ust(i),wspd(i),visc,za(i))
endif
endif
else
!default to COARE 3.0/3.5
if (coare_opt .eq. 3.0) then
!COARE 3.0
call charnock_1955(znt(i),ust(i),wspd(i),visc,za(i))
else
!COARE 3.5
call edson_etal_2013(znt(i),ust(i),wspd(i),visc,za(i))
endif
endif
!add stochastic perturbaction of ZNT
if (spp_pbl) then
zntstoch(i) = max(znt(i) + znt(i)*1.0*rstoch1d(i), 1e-6)
else
zntstoch(i) = znt(i)
endif
!compute roughness reynolds number (restar) using new znt
! AHW: Garrattt formula: Calculate roughness Reynolds number
! Kinematic viscosity of air (linear approx to
! temp dependence at sea level)
restar=max(ust(i)*zntstoch(i)/visc, 0.1)
!--------------------------------------
!calculate z_t and z_q
!--------------------------------------
if ( present(isftcflx) ) then
if ( isftcflx .eq. 0 ) then
if (coare_opt .eq. 3.0) then
call fairall_etal_2003(z_t(i),z_q(i),restar,ust(i),visc,rstoch1d(i),spp_pbl)
else
!presumably, this will be published soon, but hasn't yet
call fairall_etal_2014(z_t(i),z_q(i),restar,ust(i),visc,rstoch1d(i),spp_pbl)
endif
elseif ( isftcflx .eq. 1 ) then
if (coare_opt .eq. 3.0) then
call fairall_etal_2003(z_t(i),z_q(i),restar,ust(i),visc,rstoch1d(i),spp_pbl)
else
call fairall_etal_2014(z_t(i),z_q(i),restar,ust(i),visc,rstoch1d(i),spp_pbl)
endif
elseif ( isftcflx .eq. 2 ) then
call garratt_1992(z_t(i),z_q(i),zntstoch(i),restar,xland(i))
elseif ( isftcflx .eq. 3 ) then
if (coare_opt .eq. 3.0) then
call fairall_etal_2003(z_t(i),z_q(i),restar,ust(i),visc,rstoch1d(i),spp_pbl)
else
call fairall_etal_2014(z_t(i),z_q(i),restar,ust(i),visc,rstoch1d(i),spp_pbl)
endif
endif
else
!default to COARE 3.0/3.5
if (coare_opt .eq. 3.0) then
call fairall_etal_2003(z_t(i),z_q(i),restar,ust(i),visc,rstoch1d(i),spp_pbl)
else
call fairall_etal_2014(z_t(i),z_q(i),restar,ust(i),visc,rstoch1d(i),spp_pbl)
endif
endif
else
!add stochastic perturbaction of znt
if (spp_pbl) then
zntstoch(i) = max(znt(i) + znt(i)*1.0*rstoch1d(i), 1e-6)
else
zntstoch(i) = znt(i)
endif
!--------------------------------------
! land
!--------------------------------------
!compute roughness reynolds number (restar) using default znt
restar=max(ust(i)*zntstoch(i)/visc, 0.1)
!--------------------------------------
! get z_t and z_q
!--------------------------------------
!check for snow/ice points over land
if ( snowh(i) .ge. 0.1) then
call andreas_2002(zntstoch(i),visc,ust(i),z_t(i),z_q(i))
else
if ( present(iz0tlnd) ) then
if ( iz0tlnd .le. 1 ) then
call zilitinkevich_1995(zntstoch(i),z_t(i),z_q(i),restar,&
ust(i),karman,xland(i),iz0tlnd,spp_pbl,rstoch1d(i))
elseif ( iz0tlnd .eq. 2 ) then
call yang_2008(zntstoch(i),z_t(i),z_q(i),ust(i),mol(i),&
qstar(i),restar,visc,xland(i))
elseif ( iz0tlnd .eq. 3 ) then
!original mynn in wrf-arw used this form:
call garratt_1992(z_t(i),z_q(i),zntstoch(i),restar,xland(i))
endif
else
!default to zilitinkevich
call zilitinkevich_1995(zntstoch(i),z_t(i),z_q(i),restar,&
ust(i),karman,xland(i),0,spp_pbl,rstoch1d(i))
endif
endif
endif
zratio(i)=zntstoch(i)/z_t(i) !needed for Li et al.
gz1oz0(i)= log((za(i)+zntstoch(i))/zntstoch(i))
gz1ozt(i)= log((za(i)+zntstoch(i))/z_t(i))
gz2oz0(i)= log((2.0+zntstoch(i))/zntstoch(i))
gz2ozt(i)= log((2.0+zntstoch(i))/z_t(i))
gz10oz0(i)=log((10.+zntstoch(i))/zntstoch(i))
gz10ozt(i)=log((10.+zntstoch(i))/z_t(i))
!--------------------------------------------------------------------
!--- DIAGNOSE BASIC PARAMETERS FOR THE APPROPRIATE STABILITY CLASS:
!
! THE STABILITY CLASSES ARE DETERMINED BY BR (BULK RICHARDSON NO.).
!
! CRITERIA FOR THE CLASSES ARE AS FOLLOWS:
!
! 1. BR .GE. 0.2;
! REPRESENTS NIGHTTIME STABLE CONDITIONS (REGIME=1),
!
! 2. BR .LT. 0.2 .AND. BR .GT. 0.0;
! REPRESENTS DAMPED MECHANICAL TURBULENT CONDITIONS
! (REGIME=2),
!
! 3. BR .EQ. 0.0
! REPRESENTS FORCED CONVECTION CONDITIONS (REGIME=3),
!
! 4. BR .LT. 0.0
! REPRESENTS FREE CONVECTION CONDITIONS (REGIME=4).
!
!--------------------------------------------------------------------
if (br(i) .gt. 0.0) then
if (br(i) .gt. 0.2) then
!---class 1; stable (nighttime) conditions:
regime(i)=1.
else
!---class 2; damped mechanical turbulence:
regime(i)=2.
endif
!compute z/l first guess:
if (itimestep .le. 1) then
call li_etal_2010(zol(i),br(i),za(i)/zntstoch(i),zratio(i))
else
zol(i)=za(i)*karman*g*mol(i)/(th1d(i)*max(ust(i)*ust(i),0.0001))
zol(i)=max(zol(i),0.0)
zol(i)=min(zol(i),20.)
endif
!Use Pedros iterative function to find z/L
!zol(i)=zolri(br(i),za(i),zntstoch(i),z_t(i),zol(i),psi_opt)
!Use brute-force method
zol(i)=zolrib(br(i),za(i),zntstoch(i),z_t(i),gz1oz0(i),gz1ozt(i),zol(i),psi_opt)
zol(i)=max(zol(i),0.0)
zol(i)=min(zol(i),20.)
zolzt = zol(i)*z_t(i)/za(i) ! zt/l
zolz0 = zol(i)*zntstoch(i)/za(i) ! z0/l
zolza = zol(i)*(za(i)+zntstoch(i))/za(i) ! (z+z0/l
zol10 = zol(i)*(10.+zntstoch(i))/za(i) ! (10+z0)/l
zol2 = zol(i)*(2.+zntstoch(i))/za(i) ! (2+z0)/l
!compute psim and psih
if ((xland(i)-1.5).ge.0) then
! water
!call psi_suselj_sood_2010(psim(i),psih(i),zol(i))
!call psi_beljaars_holtslag_1991(psim(i),psih(i),zol(i))
!call psi_businger_1971(psim(i),psih(i),zol(i))
!call psi_dyerhicks(psim(i),psih(i),zol(i),z_t(i),zntstoch(i),za(i))
!call psi_cb2005(psim(i),psih(i),zolza,zolz0)
! or use tables
psim(i)=psim_stable(zolza,psi_opt)-psim_stable(zolz0,psi_opt)
psih(i)=psih_stable(zolza,psi_opt)-psih_stable(zolzt,psi_opt)
psim10(i)=psim_stable(zol10,psi_opt)-psim_stable(zolz0,psi_opt)
psih10(i)=psih_stable(zol10,psi_opt)-psih_stable(zolz0,psi_opt)
psih2(i)=psih_stable(zol2,psi_opt)-psih_stable(zolz0,psi_opt)
else
! land
!call psi_beljaars_holtslag_1991(psim(i),psih(i),zol(i))
!call psi_businger_1971(psim(i),psih(i),zol(i))
!call psi_zilitinkevich_esau_2007(psim(i),psih(i),zol(i))
!call psi_dyerhicks(psim(i),psih(i),zol(i),z_t(i),zntstoch(i),za(i))
!call psi_cb2005(psim(i),psih(i),zolza,zolz0)
! or use tables
psim(i)=psim_stable(zolza,psi_opt)-psim_stable(zolz0,psi_opt)
psih(i)=psih_stable(zolza,psi_opt)-psih_stable(zolzt,psi_opt)
psim10(i)=psim_stable(zol10,psi_opt)-psim_stable(zolz0,psi_opt)
psih10(i)=psih_stable(zol10,psi_opt)-psih_stable(zolz0,psi_opt)
psih2(i)=psih_stable(zol2,psi_opt)-psih_stable(zolz0,psi_opt)
endif
!psim10(i)=10./za(i)*psim(i)
!psih10(i)=10./za(i)*psih(i)
!psim2(i)=2./za(i)*psim(i)
!psih2(i)=2./za(i)*psih(i)
! 1.0 over monin-obukhov length
rmol(i)= zol(i)/za(i)
elseif(br(i) .eq. 0.) then
!=========================================================
!-----class 3; forced convection/neutral:
!=========================================================
regime(i)=3.
psim(i)=0.0
psih(i)=psim(i)
psim10(i)=0.
psih10(i)=0.
psih2(i)=0.
zol(i)=0.
!if (ust(i) .lt. 0.01) then
! zol(i)=br(i)*gz1oz0(i)
!else
! zol(i)=karman*govrth(i)*za(i)*mol(i)/(max(ust(i)*ust(i),0.001))
!endif
rmol(i) = zol(i)/za(i)
elseif(br(i) .lt. 0.)then
!==========================================================
!-----class 4; free convection:
!==========================================================
regime(i)=4.
!compute z/l first guess:
if (itimestep .le. 1) then
call li_etal_2010(zol(i),br(i),za(i)/zntstoch(i),zratio(i))
else
zol(i)=za(i)*karman*g*mol(i)/(th1d(i)*max(ust(i)*ust(i),0.001))
zol(i)=max(zol(i),-20.0)
zol(i)=min(zol(i),0.0)
endif
!Use Pedros iterative function to find z/L
!zol(I)=zolri(br(I),ZA(I),ZNTstoch(I),z_t(I),ZOL(I),psi_opt)
!Use alternative method
zol(i)=zolrib(br(i),za(i),zntstoch(i),z_t(i),gz1oz0(i),gz1ozt(i),zol(i),psi_opt)
zol(i)=max(zol(i),-20.0)
zol(i)=min(zol(i),0.0)
zolzt = zol(i)*z_t(i)/za(i) ! zt/l
zolz0 = zol(i)*zntstoch(i)/za(i) ! z0/l
zolza = zol(i)*(za(i)+zntstoch(i))/za(i) ! (z+z0/l
zol10 = zol(i)*(10.+zntstoch(i))/za(i) ! (10+z0)/l
zol2 = zol(i)*(2.+zntstoch(i))/za(i) ! (2+z0)/l
!compute psim and psih
if ((xland(i)-1.5).ge.0) then
! water
!call psi_suselj_sood_2010(psim(i),psih(i),zol(i))
!call psi_hogstrom_1996(psim(i),psih(i),zol(i), z_t(i), zntstoch(i), za(i))
!call psi_businger_1971(psim(i),psih(i),zol(i))
!call psi_dyerhicks(psim(i),psih(i),zol(i),z_t(i),zntstoch(i),za(i))
! use tables
psim(i)=psim_unstable(zolza,psi_opt)-psim_unstable(zolz0,psi_opt)
psih(i)=psih_unstable(zolza,psi_opt)-psih_unstable(zolzt,psi_opt)
psim10(i)=psim_unstable(zol10,psi_opt)-psim_unstable(zolz0,psi_opt)
psih10(i)=psih_unstable(zol10,psi_opt)-psih_unstable(zolz0,psi_opt)
psih2(i)=psih_unstable(zol2,psi_opt)-psih_unstable(zolz0,psi_opt)
else
! land
!call psi_hogstrom_1996(psim(i),psih(i),zol(i), z_t(i), zntstoch(i), za(i))
!call psi_businger_1971(psim(i),psih(i),zol(i))
!call psi_dyerhicks(psim(i),psih(i),zol(i),z_t(i),zntstoch(i),za(i))
! use tables
psim(i)=psim_unstable(zolza,psi_opt)-psim_unstable(zolz0,psi_opt)
psih(i)=psih_unstable(zolza,psi_opt)-psih_unstable(zolzt,psi_opt)
psim10(i)=psim_unstable(zol10,psi_opt)-psim_unstable(zolz0,psi_opt)
psih10(i)=psih_unstable(zol10,psi_opt)-psih_unstable(zolz0,psi_opt)
psih2(i)=psih_unstable(zol2,psi_opt)-psih_unstable(zolz0,psi_opt)
endif
!psim10(i)=10./za(i)*psim(i)
!psih2(i)=2./za(i)*psih(i)
!---limit psih and psim in the case of thin layers and
!---high roughness. this prevents denominator in fluxes
!---from getting too small
psih(i)=min(psih(i),0.9*gz1ozt(i))
psim(i)=min(psim(i),0.9*gz1oz0(i))
psih2(i)=min(psih2(i),0.9*gz2ozt(i))
psim10(i)=min(psim10(i),0.9*gz10oz0(i))
psih10(i)=min(psih10(i),0.9*gz10ozt(i))
rmol(i) = zol(i)/za(i)
endif
!------------------------------------------------------------
!-----compute the frictional velocity:
!------------------------------------------------------------
! Za(1982) Eqs(2.60),(2.61).
psix=gz1oz0(i)-psim(i)
psix10=gz10oz0(i)-psim10(i)
! to prevent oscillations average with old value
oldust = ust(i)
ust(i)=0.5*ust(i)+0.5*karman*wspd(i)/psix
!non-averaged: ust(i)=karman*wspd(i)/psix
! compute u* without vconv for use in hfx calc when isftcflx > 0
wspdi(i)=max(sqrt(u1d(i)*u1d(i)+v1d(i)*v1d(i)), wmin)
if ( present(ustm) ) then
ustm(i)=0.5*ustm(i)+0.5*karman*wspdi(i)/psix
endif
if ((xland(i)-1.5).lt.0.) then !land
ust(i)=max(ust(i),0.005) !further relaxing this limit - no need to go lower
!keep ustm = ust over land.
if ( present(ustm) ) ustm(i)=ust(i)
endif
!------------------------------------------------------------
!-----compute the thermal and moisture resistance (psiq and psit):
!------------------------------------------------------------
! lower limit added to prevent large flhc in soil model
! activates in unstable conditions with thin layers or high z0
gz1ozt(i)= log((za(i)+zntstoch(i))/z_t(i))
gz2ozt(i)= log((2.0+zntstoch(i))/z_t(i))
psit =max(gz1ozt(i)-psih(i) ,1.)
psit2=max(gz2ozt(i)-psih2(i),1.)
psiq=max(log((za(i)+zntstoch(i))/z_q(i))-psih(i) ,1.0)
psiq2=max(log((2.0+zntstoch(i))/z_q(i))-psih2(i) ,1.0)
psiq10=max(log((10.0+zntstoch(i))/z_q(i))-psih10(i) ,1.0)
!----------------------------------------------------
!compute the temperature scale (or friction temperature, T*)
!----------------------------------------------------
dtg=thv1d(i)-thvgb(i)
oldtst=mol(i)
mol(i)=karman*dtg/psit/prt
!t_star(i) = -hfx(i)/(ust(i)*cpm(i)*rho1d(i))
!t_star(i) = mol(i)
!----------------------------------------------------
!compute the moisture scale (or q*)
dqg=(qvsh(i)-qsfc(i))*1000. !(kg/kg -> g/kg)
qstar(i)=karman*dqg/psiq/prt
!if () then
! write(*,1001)"regime:",regime(i)," z/l:",zol(i)," u*:",ust(i)," tstar:",mol(i)
! write(*,1002)"psim:",psim(i)," psih:",psih(i)," w*:",wstar(i)," dthv:",thv1d(i)-thvgb(i)
! write(*,1003)"cpm:",cpm(i)," rho1d:",rho1d(i)," l:",zol(i)/za(i)," dth:",th1d(i)-thgb(i)
! write(*,1004)"z0/zt:",zratio(i)," z0:",zntstoch(i)," zt:",z_t(i)," za:",za(i)
! write(*,1005)"re:",restar," mavail:",mavail(i)," qsfc(i):",qsfc(i)," qvsh(i):",qvsh(i)
! print*,"visc=",visc," z0:",zntstoch(i)," t1d(i):",t1d(i)
! write(*,*)"============================================="
!endif
enddo ! end i-loop
1000 format(a,f6.1, a,f6.1, a,f5.1, a,f7.1)
1001 format(a,f2.0, a,f10.4,a,f5.3, a,f11.5)
1002 format(a,f7.2, a,f7.2, a,f7.2, a,f10.3)
1003 format(a,f7.2, a,f7.2, a,f10.3,a,f10.3)
1004 format(a,f11.3,a,f9.7, a,f9.7, a,f6.2, a,f10.3)
1005 format(a,f9.2,a,f6.4,a,f7.4,a,f7.4)
!----------------------------------------------------------
! compute surface heat and moisture fluxes
!----------------------------------------------------------
do i=its,ite
!For computing the diagnostics and fluxes (below), whether the fluxes
!are turned off or on, we need the following:
psix=gz1oz0(i)-psim(i)
psix10=gz10oz0(i)-psim10(i)
psit =max(gz1ozt(i)-psih(i), 1.0)
psit2=max(gz2ozt(i)-psih2(i),1.0)
psiq=max(log((za(i)+z_q(i))/z_q(i))-psih(i) ,1.0)
psiq2=max(log((2.0+z_q(i))/z_q(i))-psih2(i) ,1.0)
psiq10=max(log((10.0+z_q(i))/z_q(i))-psih10(i) ,1.0)
if (isfflx .lt. 1) then
qfx(i) = 0.
hfx(i) = 0.
flhc(i) = 0.
flqc(i) = 0.
lh(i) = 0.
chs(i) = 0.
ch(i) = 0.
chs2(i) = 0.
cqs2(i) = 0.
if(present(ck) .and. present(cd) .and. &
&present(cka) .and. present(cda)) then
ck(i) = 0.
cd(i) = 0.
cka(i)= 0.
cda(i)= 0.
endif
else
!------------------------------------------
! calculate the exchange coefficients for heat (flhc)
! and moisture (flqc)
!------------------------------------------
flqc(i)=rho1d(i)*mavail(i)*ust(i)*karman/psiq
flhc(i)=rho1d(i)*cpm(i)*ust(i)*karman/psit
!----------------------------------
! compute surface moisture flux:
!----------------------------------
qfx(i)=flqc(i)*(qsfcmr(i)-qv1d(i))
!joe: qfx(i)=max(qfx(i),0.) !originally did not allow neg qfx
qfx(i)=max(qfx(i),-0.02) !allows small neg qfx, like myj
lh(i)=xlv*qfx(i)
!----------------------------------
! compute surface heat flux:
!----------------------------------
if(xland(i)-1.5.gt.0.)then !water
hfx(i)=flhc(i)*(thgb(i)-th1d(i))
if ( present(isftcflx) ) then
if ( isftcflx.ne.0 ) then
! ahw: add dissipative heating term
hfx(i)=hfx(i)+rho1d(i)*ustm(i)*ustm(i)*wspdi(i)
endif
endif
elseif(xland(i)-1.5.lt.0.)then !land
hfx(i)=flhc(i)*(thgb(i)-th1d(i))
hfx(i)=max(hfx(i),-250.)
endif
!chs(i)=ust(i)*karman/(alog(karman*ust(i)*za(i) &
! /xka+za(i)/zl)-psih(i))
chs(i)=ust(i)*karman/psit
! the exchange coefficient for cloud water is assumed to be the
! same as that for heat. ch is multiplied by wspd.
!ch(i)=chs(i)
ch(i)=flhc(i)/( cpm(i)*rho1d(i) )
!these are used for 2-m diagnostics only
cqs2(i)=ust(i)*karman/psiq2
chs2(i)=ust(i)*karman/psit2
if(present(ck) .and. present(cd) .and. &
&present(cka) .and. present(cda)) then
ck(i)=(karman/psix10)*(karman/psiq10)
cd(i)=(karman/psix10)*(karman/psix10)
cka(i)=(karman/psix)*(karman/psiq)
cda(i)=(karman/psix)*(karman/psix)
endif
endif !end isfflx option
!-----------------------------------------------------
!compute diagnostics
!-----------------------------------------------------
!compute 10 m wnds
!-----------------------------------------------------
! If the lowest model level is close to 10-m, use it
! instead of the flux-based diagnostic formula.
if (za(i) .le. 7.0) then
! high vertical resolution
if(za2(i) .gt. 7.0 .and. za2(i) .lt. 13.0) then
!use 2nd model level
u10(i)=u1d2(i)
v10(i)=v1d2(i)
else
u10(i)=u1d(i)*log(10./zntstoch(i))/log(za(i)/zntstoch(i))
v10(i)=v1d(i)*log(10./zntstoch(i))/log(za(i)/zntstoch(i))
endif
elseif(za(i) .gt. 7.0 .and. za(i) .lt. 13.0) then
!moderate vertical resolution
!u10(i)=u1d(i)*psix10/psix
!v10(i)=v1d(i)*psix10/psix
!use neutral-log:
u10(i)=u1d(i)*log(10./zntstoch(i))/log(za(i)/zntstoch(i))
v10(i)=v1d(i)*log(10./zntstoch(i))/log(za(i)/zntstoch(i))
else
! very coarse vertical resolution
u10(i)=u1d(i)*psix10/psix
v10(i)=v1d(i)*psix10/psix
endif
!-----------------------------------------------------
!compute 2m t, th, and q
!these will be overwritten for land points in the lsm
!-----------------------------------------------------
dtg=th1d(i)-thgb(i)
th2(i)=thgb(i)+dtg*psit2/psit
!*** be certain that the 2-m theta is bracketed by
!*** the values at the surface and lowest model level.
if ((th1d(i)>thgb(i) .and. (th2(i)<thgb(i) .or. th2(i)>th1d(i))) .or. &
(th1d(i)<thgb(i) .and. (th2(i)>thgb(i) .or. th2(i)<th1d(i)))) then
th2(i)=thgb(i) + 2.*(th1d(i)-thgb(i))/za(i)
endif
t2(i)=th2(i)*(psfc(i)/100.)**rovcp
q2(i)=qsfcmr(i)+(qv1d(i)-qsfcmr(i))*psiq2/psiq
q2(i)= max(q2(i), min(qsfcmr(i), qv1d(i)))
q2(i)= min(q2(i), 1.05*qv1d(i))
if ( debug_code ) then
yesno = 0
if (hfx(i) > 1200. .or. hfx(i) < -700.)then
print*,"suspicious values in mynn sfclayer",&
i, "hfx: ",hfx(i)
yesno = 1
endif
if (lh(i) > 1200. .or. lh(i) < -700.)then
print*,"suspicious values in mynn sfclayer",&
i, "lh: ",lh(i)
yesno = 1
endif
if (ust(i) < 0.0 .or. ust(i) > 4.0 )then
print*,"suspicious values in mynn sfclayer",&
i, "ust: ",ust(i)
yesno = 1
endif
if (wstar(i)<0.0 .or. wstar(i) > 6.0)then
print*,"suspicious values in mynn sfclayer",&
i, "wstar: ",wstar(i)
yesno = 1
endif
if (rho1d(i)<0.0 .or. rho1d(i) > 1.6 )then
print*,"suspicious values in mynn sfclayer",&
i, "rho: ",rho1d(i)
yesno = 1
endif
if (qsfc(i)*1000. <0.0 .or. qsfc(i)*1000. >40.)then
print*,"suspicious values in mynn sfclayer",&
i, "qsfc: ",qsfc(i)
yesno = 1
endif
if (pblh(i)<0. .or. pblh(i)>6000.)then
print*,"suspicious values in mynn sfclayer",&
i, "pblh: ",pblh(i)
yesno = 1
endif
if (yesno == 1) then
print*," other info:"
write(*,1001)"regime:",regime(i)," z/l:",zol(i)," u*:",ust(i),&
" tstar:",mol(i)
write(*,1002)"psim:",psim(i)," psih:",psih(i)," w*:",wstar(i),&
" dthv:",thv1d(i)-thvgb(i)
write(*,1003)"cpm:",cpm(i)," rho1d:",rho1d(i)," l:",&
zol(i)/za(i)," dth:",th1d(i)-thgb(i)
write(*,*)" z0:",zntstoch(i)," zt:",z_t(i)," za:",za(i)
write(*,1005)"re:",restar," mavail:",mavail(i)," qsfc(i):",&
qsfc(i)," qvsh(i):",qvsh(i)
print*,"psix=",psix," z0:",zntstoch(i)," t1d(i):",t1d(i)
write(*,*)"============================================="
endif
endif
enddo !end i-loop
errmsg = ' '
errflg = 0
end subroutine sf_mynn_run
!=================================================================================================================
subroutine zilitinkevich_1995(z_0,zt,zq,restar,ustar,karman,landsea,iz0tlnd2,spp_pbl,rstoch)
!this subroutine returns the thermal and moisture roughness lengths