forked from HYCOM/HYCOM-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mxkprf.F90
3771 lines (3770 loc) · 138 KB
/
mxkprf.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
#if defined(ROW_LAND)
#define SEA_P .true.
#define SEA_U .true.
#define SEA_V .true.
#elif defined(ROW_ALLSEA)
#define SEA_P allip(j).or.ip(i,j).ne.0
#define SEA_U alliu(j).or.iu(i,j).ne.0
#define SEA_V alliv(j).or.iv(i,j).ne.0
#else
#define SEA_P ip(i,j).ne.0
#define SEA_U iu(i,j).ne.0
#define SEA_V iv(i,j).ne.0
#endif
subroutine mxkprf(m,n)
use mod_xc ! HYCOM communication interface
use mod_cb_arrays ! HYCOM saved arrays
use mod_pipe ! HYCOM debugging interface
!
! --- hycom version 2.1
implicit none
!
integer m,n
!
! ---------------------------------------------------------
! --- k-profile vertical mixing models
! --- a) large, mc williams, doney kpp vertical diffusion
! --- b) mellor-yamada 2.5 vertical diffusion
! --- c) giss vertical diffusion
! ---------------------------------------------------------
!
logical, parameter :: lpipe_mxkprf =.false.
logical, parameter :: ldebug_dpmixl=.false.
!
real delp,dpmx,hblmax,sigmlj,thsur,thtop,alfadt,betads,zintf, &
thjmp(kdm),thloc(kdm)
integer i,j,k
character text*12
!
# include "stmt_fns.h"
!
if (mxlmy) then
call xctilr(u( 1-nbdy,1-nbdy,1,m),1,kk, 1,1, halo_uv)
call xctilr(u( 1-nbdy,1-nbdy,1,n),1,kk, 1,1, halo_uv)
call xctilr(v( 1-nbdy,1-nbdy,1,m),1,kk, 1,1, halo_vv)
call xctilr(v( 1-nbdy,1-nbdy,1,n),1,kk, 1,1, halo_vv)
call xctilr(p( 1-nbdy,1-nbdy,2 ),1,kk, 1,1, halo_ps)
call xctilr(ubavg( 1-nbdy,1-nbdy, m),1, 1, 1,1, halo_uv)
call xctilr(vbavg( 1-nbdy,1-nbdy, m),1, 1, 1,1, halo_vv)
else
call xctilr(u( 1-nbdy,1-nbdy,1,n),1,kk, 1,1, halo_uv)
call xctilr(v( 1-nbdy,1-nbdy,1,n),1,kk, 1,1, halo_vv)
call xctilr(p( 1-nbdy,1-nbdy,2 ),1,kk, 1,1, halo_ps)
endif
!
! --- except for KPP, surface boundary layer is the mixed layer
if (mxlgiss .or. mxlmy) then
hblmax = bldmax*onem
!$OMP PARALLEL DO PRIVATE(j,i) &
!$OMP SCHEDULE(STATIC,jblk)
do j=1,jj
do i=1,ii
if (SEA_P) then
dpbl(i,j) = 0.5*(dpmixl(i,j,n)+ &
dpmixl(i,j,m) ) !reduce time splitting
dpbl(i,j) = min( dpbl(i,j), hblmax ) !may not be needed
endif !ip
enddo !i
enddo !j
endif !mxlgiss,mxlmy
!
! --- diffisuvity/viscosity calculation
!
!$OMP PARALLEL DO PRIVATE(j) &
!$OMP SHARED(m,n) &
!$OMP SCHEDULE(STATIC,jblk)
do j=1,jj
call mxkprfaj(m,n, j)
enddo
!$OMP END PARALLEL DO
!
! --- optional spatial smoothing of viscosity and diffusivities on interior
! --- interfaces.
!
if (difsmo.gt.0) then
util6(1:ii,1:jj) = klist(1:ii,1:jj)
call xctilr(util6, 1, 1, 2,2, halo_ps)
! --- update halo on all layers for simplicity
call xctilr(dift(1-nbdy,1-nbdy,2),1,kk-1, 2,2, halo_ps)
call xctilr(difs(1-nbdy,1-nbdy,2),1,kk-1, 2,2, halo_ps)
call xctilr(vcty(1-nbdy,1-nbdy,2),1,kk-1, 2,2, halo_ps)
do k=2,min(difsmo+1,kk)
call psmooth_dif(dift(1-nbdy,1-nbdy,k),util6,k,2,0,ip, util1)
call psmooth_dif(difs(1-nbdy,1-nbdy,k),util6,k,2,0,ip, util1)
call psmooth_dif(vcty(1-nbdy,1-nbdy,k),util6,k,2,1,ip, util1)
enddo
call xctilr(vcty(1-nbdy,1-nbdy,kk+1),1, 1, 1,1, halo_ps)
else
call xctilr(vcty(1-nbdy,1-nbdy, 2),1,kk, 1,1, halo_ps)
endif
!
if (lpipe .and. lpipe_mxkprf) then
! --- compare two model runs.
util6(1:ii,1:jj) = klist(1:ii,1:jj)
write (text,'(a12)') 'klist '
call pipe_compare_sym1(util6,ip,text)
if (mxlmy) then
do k= 0,kk+1
write (text,'(a9,i3)') 'q2 k=',k
call pipe_compare_sym1(q2( 1-nbdy,1-nbdy,k,n),ip,text)
write (text,'(a9,i3)') 'q2l k=',k
call pipe_compare_sym1(q2l(1-nbdy,1-nbdy,k,n),ip,text)
write (text,'(a9,i3)') 'difqmy k=',k
call pipe_compare_sym1(difqmy(1-nbdy,1-nbdy,k),ip,text)
write (text,'(a9,i3)') 'diftmy k=',k
call pipe_compare_sym1(diftmy(1-nbdy,1-nbdy,k),ip,text)
write (text,'(a9,i3)') 'vctymy k=',k
call pipe_compare_sym1(vctymy(1-nbdy,1-nbdy,k),ip,text)
enddo
endif
do k= 1,kk+1
write (text,'(a9,i3)') 'dift k=',k
call pipe_compare_sym1(dift(1-nbdy,1-nbdy,k),ip,text)
write (text,'(a9,i3)') 'difs k=',k
call pipe_compare_sym1(difs(1-nbdy,1-nbdy,k),ip,text)
write (text,'(a9,i3)') 'vcty k=',k
call pipe_compare_sym1(vcty(1-nbdy,1-nbdy,k),ip,text)
enddo
endif
!
! --- final mixing of variables at p points
!
!$OMP PARALLEL DO PRIVATE(j) &
!$OMP SHARED(m,n) &
!$OMP SCHEDULE(STATIC,jblk)
do j=1,jj
call mxkprfbj(m,n, j)
enddo
!$OMP END PARALLEL DO
!
! --- final velocity mixing at u,v points
!
!$OMP PARALLEL DO PRIVATE(j) &
!$OMP SHARED(m,n) &
!$OMP SCHEDULE(STATIC,jblk)
do j=1,jj
call mxkprfcj(m,n, j)
enddo
!$OMP END PARALLEL DO
!
! --- mixed layer diagnostics
!
if (diagno .or. mxlgiss .or. mxlmy) then
!
! --- diagnose new mixed layer depth based on density jump criterion
!$OMP PARALLEL DO PRIVATE(j,i,k, &
!$OMP sigmlj,thsur,thtop,alfadt,betads,zintf, &
!$OMP thjmp,thloc) &
!$OMP SCHEDULE(STATIC,jblk)
do j=1,jj
do i=1,ii
if (SEA_P) then
!
! --- depth of mixed layer base set to interpolated depth where
! --- the density jump is equivalent to a tmljmp temperature jump.
! --- this may not vectorize, but is used infrequently.
if (locsig) then
sigmlj = -tmljmp*dsiglocdt(temp(i,j,1,n), &
saln(i,j,1,n),p(i,j,1))
else
sigmlj = -tmljmp*dsigdt(temp(i,j,1,n),saln(i,j,1,n))
endif
sigmlj = max(sigmlj,tmljmp*0.03) !cold-water fix
!
if (ldebug_dpmixl .and. i.eq.itest.and.j.eq.jtest) then
write (lp,'(i9,2i5,i3,a,2f7.4)') &
nstep,i+i0,j+j0,k, &
' sigmlj =', &
-tmljmp*dsigdt(temp(i,j,1,n),saln(i,j,1,n)), &
sigmlj
endif
!
thloc(1)=th3d(i,j,1,n)
do k=2,klist(i,j)
if (locsig) then
alfadt=dsiglocdt(ahalf*(temp(i,j,k-1,n)+ &
temp(i,j,k, n) ), &
ahalf*(saln(i,j,k-1,n)+ &
saln(i,j,k, n) ), &
p(i,j,k) )* &
(temp(i,j,k-1,n)-temp(i,j,k, n))
betads=dsiglocds(ahalf*(temp(i,j,k-1,n)+ &
temp(i,j,k, n) ), &
ahalf*(saln(i,j,k-1,n)+ &
saln(i,j,k, n) ), &
p(i,j,k) )* &
(saln(i,j,k-1,n)-saln(i,j,k, n))
thloc(k)=thloc(k-1)-alfadt-betads
else
thloc(k)=th3d(i,j,k,n)
endif
enddo !k
dpmixl(i,j,n) = -zgrid(i,j,klist(i,j)+1)*onem !bottom
thjmp(1) = 0.0
thsur = thloc(1)
do k=2,klist(i,j)
thsur = min(thloc(k),thsur) !ignore surface inversion
thjmp(k) = max(thloc(k)-thsur, &
thjmp(k-1)) !stable profile simplifies the code
!
if (ldebug_dpmixl .and. i.eq.itest.and.j.eq.jtest) then
write (lp,'(i9,2i5,i3,a,2f7.3,f7.4,f9.2)') &
nstep,i+i0,j+j0,k, &
' th,thsur,jmp,zc =', &
thloc(k),thsur,thjmp(k),-zgrid(i,j,k)
endif
!
if (thjmp(k).ge.sigmlj) then
!
! --- find the density on the interface between layers
! --- k-1 and k, using the same cubic polynominal as PQM
!
if (k.eq.2) then
! --- linear between cell centers
thtop = thjmp(1) + (thjmp(2)-thjmp(1))* &
dp(i,j,1,n)/ &
max( dp(i,j,1,n)+ &
dp(i,j,2,n) , &
onemm )
elseif (k.eq.klist(i,j)) then
! --- linear between cell centers
thtop = thjmp(k) + (thjmp(k-1)-thjmp(k))* &
dp(i,j,k,n)/ &
max( dp(i,j,k, n)+ &
dp(i,j,k-1,n) , &
onemm )
else
thsur = min(thloc(k+1),thsur)
thjmp(k+1) = max(thloc(k+1)-thsur, &
thjmp(k))
zintf = zgrid(i,j,k-1) - 0.5*dp(i,j,k-1,n)*qonem
thtop = thjmp(k-2)* &
((zintf -zgrid(i,j,k-1))* &
(zintf -zgrid(i,j,k ))* &
(zintf -zgrid(i,j,k+1)) )/ &
((zgrid(i,j,k-2)-zgrid(i,j,k-1))* &
(zgrid(i,j,k-2)-zgrid(i,j,k ))* &
(zgrid(i,j,k-2)-zgrid(i,j,k+1)) ) + &
thjmp(k-1)* &
((zintf -zgrid(i,j,k-2))* &
(zintf -zgrid(i,j,k ))* &
(zintf -zgrid(i,j,k+1)) )/ &
((zgrid(i,j,k-1)-zgrid(i,j,k-2))* &
(zgrid(i,j,k-1)-zgrid(i,j,k ))* &
(zgrid(i,j,k-1)-zgrid(i,j,k+1)) ) + &
thjmp(k )* &
((zintf -zgrid(i,j,k-2))* &
(zintf -zgrid(i,j,k-1))* &
(zintf -zgrid(i,j,k+1)) )/ &
((zgrid(i,j,k )-zgrid(i,j,k-2))* &
(zgrid(i,j,k )-zgrid(i,j,k-1))* &
(zgrid(i,j,k )-zgrid(i,j,k+1)) ) + &
thjmp(k+1)* &
((zintf -zgrid(i,j,k-2))* &
(zintf -zgrid(i,j,k-1))* &
(zintf -zgrid(i,j,k )) )/ &
((zgrid(i,j,k+1)-zgrid(i,j,k-2))* &
(zgrid(i,j,k+1)-zgrid(i,j,k-1))* &
(zgrid(i,j,k+1)-zgrid(i,j,k )) )
thtop = max( thjmp(k-1), min( thjmp(k), thtop ) )
!
if (ldebug_dpmixl .and. &
i.eq.itest.and.j.eq.jtest) then
write (lp,'(i9,2i5,i3,a,2f7.3,f7.4,f9.2)') &
nstep,i+i0,j+j0,k, &
' thi,thsur,jmp,zi =', &
thtop,thsur,thjmp(k),-zintf
endif
endif !k.eq.2:k.eq.klist:else
!
if (thtop.ge.sigmlj) then
!
! --- in bottom half of layer k-1
!
dpmixl(i,j,n) = &
-zgrid(i,j,k-1)*onem + &
0.5*dp(i,j,k-1,n)* &
(sigmlj+epsil-thjmp(k-1))/ &
(thtop +epsil-thjmp(k-1))
else
!
! --- in top half of layer k
!
dpmixl(i,j,n) = &
-zgrid(i,j,k)*onem - &
0.5*dp(i,j,k,n)* &
(1.0-(sigmlj +epsil-thtop)/ &
(thjmp(k)+epsil-thtop) )
endif !part of layer
!
if (ldebug_dpmixl .and. &
i.eq.itest.and.j.eq.jtest) then
write (lp,'(i9,2i5,i3,a,f7.3,f7.4,f9.2)') &
nstep,i+i0,j+j0,k, &
' thsur,top,dpmixl =', &
thsur,thtop,dpmixl(i,j,n)*qonem
endif
!
exit !calculated dpmixl
endif !found dpmixl layer
enddo !k
endif !ip
enddo !i
enddo !j
!
!$OMP END PARALLEL DO
!
! --- smooth the mixed layer (might end up below the bottom).
call psmooth(dpmixl(1-nbdy,1-nbdy,n),0,0,ip, util1)
!
if (ldebug_dpmixl) then
call xcsync(flush_lp)
endif
!
endif !diagno .or. mxlgiss .or. mxlmy
!
if (diagno) then
!
! --- calculate bulk mixed layer t, s, theta
!
!$OMP PARALLEL DO PRIVATE(j,i,k,delp) &
!$OMP SCHEDULE(STATIC,jblk)
do j=1,jj
do i=1,ii
if (SEA_P) then
dpmixl(i,j,n)=min(dpmixl(i,j,n),p(i,j,kk+1))
dpmixl(i,j,m)= dpmixl(i,j,n)
delp=min(p(i,j,2),dpmixl(i,j,n))
tmix(i,j)=delp*temp(i,j,1,n)
smix(i,j)=delp*saln(i,j,1,n)
do k=2,kk
delp=min(p(i,j,k+1),dpmixl(i,j,n)) &
-min(p(i,j,k ),dpmixl(i,j,n))
tmix(i,j)=tmix(i,j)+delp*temp(i,j,k,n)
smix(i,j)=smix(i,j)+delp*saln(i,j,k,n)
enddo
tmix(i,j)=tmix(i,j)/dpmixl(i,j,n)
smix(i,j)=smix(i,j)/dpmixl(i,j,n)
thmix(i,j)=sig(tmix(i,j),smix(i,j))-thbase
!
if (ldebug_dpmixl .and. &
i.eq.itest.and.j.eq.jtest) then
write (lp,'(i9,2i5,i3,a,f9.2)') &
nstep,i+i0,j+j0,k, &
' dpmixl =', &
dpmixl(i,j,n)*qonem
endif
!
endif !ip
enddo !i
enddo !j
!$OMP END PARALLEL DO
!
call xctilr(p( 1-nbdy,1-nbdy,2),1,kk, 1,1, halo_ps)
call xctilr(dpmixl(1-nbdy,1-nbdy,n),1, 1, 1,1, halo_ps)
!
!$OMP PARALLEL DO PRIVATE(j,i,k,delp,dpmx) &
!$OMP SCHEDULE(STATIC,jblk)
do j=1,jj
do i=1,ii
!
! --- calculate bulk mixed layer u
!
if (SEA_U) then
dpmx=dpmixl(i,j,n)+dpmixl(i-1,j,n)
delp=min(p(i,j,2)+p(i-1,j,2),dpmx)
umix(i,j)=delp*u(i,j,1,n)
do k=2,kk
delp= min(p(i,j,k+1)+p(i-1,j,k+1),dpmx) &
-min(p(i,j,k )+p(i-1,j,k ),dpmx)
umix(i,j)=umix(i,j)+delp*u(i,j,k,n)
enddo !k
umix(i,j)=umix(i,j)/dpmx
endif !iu
!
! --- calculate bulk mixed layer v
!
if (SEA_V) then
dpmx=dpmixl(i,j,n)+dpmixl(i,j-1,n)
delp=min(p(i,j,2)+p(i,j-1,2),dpmx)
vmix(i,j)=delp*v(i,j,1,n)
do k=2,kk
delp= min(p(i,j,k+1)+p(i,j-1,k+1),dpmx) &
-min(p(i,j,k )+p(i,j-1,k ),dpmx)
vmix(i,j)=vmix(i,j)+delp*v(i,j,k,n)
enddo !k
vmix(i,j)=vmix(i,j)/dpmx
endif !iv
enddo !i
enddo !j
!$OMP END PARALLEL DO
endif ! diagno
!
return
end
subroutine mxkprfaj(m,n, j)
use mod_xc ! HYCOM communication interface
use mod_cb_arrays ! HYCOM saved arrays
implicit none
!
integer m,n, j
!
! --- calculate viscosity and diffusivity
!
integer i
!
if (mxlkpp) then
do i=1,ii
if (SEA_P) then
call mxkppaij(m,n, i,j)
endif !ip
enddo !i
else if (mxlmy) then
do i=1,ii
if (SEA_P) then
call mxmyaij(m,n, i,j)
endif !ip
enddo !i
else if (mxlgiss) then
do i=1,ii
if (SEA_P) then
call mxgissaij(m,n, i,j)
endif !ip
enddo !i
endif
!
return
end
subroutine mxkprfbj(m,n, j)
use mod_xc ! HYCOM communication interface
use mod_cb_arrays ! HYCOM saved arrays
implicit none
!
integer m,n, j
!
! --- final mixing at p points
!
integer i
!
do i=1,ii
if (SEA_P) then
call mxkprfbij(m,n, i,j)
endif
enddo
!
return
end
subroutine mxkprfcj(m,n, j)
use mod_xc ! HYCOM communication interface
use mod_cb_arrays ! HYCOM saved arrays
implicit none
!
integer m,n, j
!
! --- final velocity mixing at u,v points
!
integer i
!
do i=1,ii
if (SEA_U) then
call mxkprfciju(m,n, i,j)
endif !iu
if (SEA_V) then
call mxkprfcijv(m,n, i,j)
endif !iv
enddo !i
!
return
end
!
subroutine mxkppaij(m,n, i,j)
use mod_xc ! HYCOM communication interface
use mod_cb_arrays ! HYCOM saved arrays
!
! --- hycom version 1.0
implicit none
!
integer m,n, i,j
!
! -------------------------------------------------------------
! --- kpp vertical diffusion, single j-row (part A)
! --- vertical coordinate is z negative below the ocean surface
!
! --- Large, W.C., J.C. McWilliams, and S.C. Doney, 1994: Oceanic
! --- vertical mixing: a review and a model with a nonlocal
! --- boundary layer paramterization. Rev. Geophys., 32, 363-403.
!
! --- quadratic interpolation and variable Cv from a presentation
! --- at the March 2003 CCSM Ocean Model Working Group Meeting
! --- on KPP Vertical Mixing by Gokhan Danabasoglu and Bill Large
! --- http://www.ccsm.ucar.edu/working_groups/Ocean/agendas/030320.html
! --- quadratic interpolation implemented here by 3-pt collocation,
! --- which is slightly different to the Danabasoglu/Large approach.
! -------------------------------------------------------------
!
real, parameter :: difmax = 9999.0e-4 !maximum diffusion/viscosity
real, parameter :: dp0bbl = 20.0 !truncation dist. for bot. b.l.
real, parameter :: ricrb = 0.45 !critical bulk Ri for bot. b.l.
real, parameter :: cv_max = 2.1 !maximum cv
real, parameter :: cv_min = 1.7 !minimum cv
real, parameter :: cv_bfq = 200.0 !cv scale factor
!
! local variables for kpp mixing
real delta ! fraction hbl lies beteen zgrid neighbors
real zrefmn ! nearsurface reference z, minimum
real zref ! nearsurface reference z
real wref,qwref ! nearsurface reference width,inverse
real uref ! nearsurface reference u
real vref ! nearsurface reference v
real bref ! nearsurface reference buoyancy
real swfrac(kdm+1) ! fractional surface shortwave radiation flux
real shsq(kdm+1) ! velocity shear squared
real alfadt(kdm+1) ! t contribution to density jump
real betads(kdm+1) ! s contribution to density jump
real swfrml ! fractional surface sw rad flux at ml base
real ritop(kdm) ! numerator of bulk richardson number
real dbloc(kdm+1) ! buoyancy jump across interface
real dvsq(kdm) ! squared current shear for bulk richardson no.
real zgridb(kdm+1) ! zgrid for bottom boundary layer
real hwide(kdm) ! layer thicknesses in m (minimum 1mm)
real dpmm(kdm) ! max(onemm,dp(i,j,:,n))
real qdpmm(kdm) ! 1.0/max(onemm,dp(i,j,:,n))
real qoneta ! 1.0/(1+eta), scale factor from dp to dp'
real pij(kdm+1) ! local copy of p(i,j,:)
real case ! 1 in case A; =0 in case B
real hbl ! boundary layer depth
real hbbl ! bottom boundary layer depth
real rib(3) ! bulk richardson number
real rrho ! double diffusion parameter
real diffdd ! double diffusion diffusivity scale
real prandtl ! prandtl number
real rigr ! local richardson number
real fri ! function of Rig for KPP shear instability
real stable ! = 1 in stable forcing; =0 in unstable
real dkm1(3) ! boundary layer diffusions at nbl-1 level
real gat1(3) ! shape functions at dnorm=1
real dat1(3) ! derivative of shape functions at dnorm=1
real blmc(kdm+1,3) ! boundary layer mixing coefficients
real bblmc(kdm+1,3) ! boundary layer mixing coefficients
real wm ! momentum velocity scale
real ws ! scalar velocity scale
real dnorm ! normalized depth
real tmn ! time averaged SST
real smn ! time averaged SSS
real dsgdt ! dsigdt(tmn,smn)
real buoyfs ! salinity surface buoyancy (into atmos.)
real buoyfl ! total surface buoyancy (into atmos.)
real buoysw ! shortwave surface buoyancy (into atmos.)
real bfsfc ! surface buoyancy forcing (into atmos.)
real bfbot ! bottom buoyancy forcing
real hekmanb ! bottom ekman layer thickness
real cormn4 ! = 4 x min. coriolis magnitude (at 4N, 4S)
real dflsiw ! internal wave diffusivity
real dflmiw ! internal wave viscosity
real dflbot(kdm+1) ! bottom intensified background viscosity
real bfq ! buoyancy frequency
real cvk ! ratio of buoyancy frequencies
real ahbl,bhbl,chbl,dhbl ! coefficients for quadratic hbl calculation
!
logical lhbl ! safe to use quadratic hbl calculation
!
integer nbl ! layer containing boundary layer base
integer nbbl ! layer containing bottom boundary layer base
integer kup2,kdn2,kup,kdn! bulk richardson number indices
!
! --- local 1-d arrays for matrix solution
real u1do(kdm+1),u1dn(kdm+1),v1do(kdm+1),v1dn(kdm+1),t1do(kdm+1), &
t1dn(kdm+1),s1do(kdm+1),s1dn(kdm+1), &
diffm(kdm+1),difft(kdm+1),diffs(kdm+1), &
ghat(kdm+1),zm(kdm+1),hm(kdm),dzb(kdm)
!
! --- local 1-d arrays for iteration loops
real uold(kdm+1),vold (kdm+1),told (kdm+1), &
sold(kdm+1),thold(kdm+1)
!
! --- tridiagonal matrix solution arrays
real tri(kdm,0:1) ! dt/dz/dz factors in trid. matrix
real tcu(kdm), & ! upper coeff for (k-1) on k line of trid.matrix
tcc(kdm), & ! central ... (k ) ..
tcl(kdm), & ! lower ..... (k-1) ..
rhs(kdm) ! right-hand-side terms
!
real dtemp,dsaln,wq,wt,wz0,wz1,wz2,ratio,q,ghatflux, &
dvdzup,dvdzdn,viscp,difsp,diftp,f1,sigg,aa1,aa2,aa3,gm,gs,gt, &
dkmp2,dstar,hblmin,hblmax,sflux1,vtsq, &
vctyh,difsh,difth,zrefo,qspcifh,hbblmin,hbblmax, &
chl, &
x0,x1,x2,y0,y1,y2
!
integer k,k1,ka,kb,nlayer,ksave,iter,jrlv
!
integer iglobal,jglobal
!
# include "stmt_fns.h"
!
cormn4 = 4.0e-5 !4 x min. coriolis magnitude (at 4N, 4S)
!
iglobal=i0+i !for debugging
jglobal=j0+j !for debugging
if (iglobal+jglobal.eq.-99) then
write(lp,*) iglobal,jglobal !prevent optimization
endif
!
! --- internal wave diffusion/viscosity
dflsiw = diws(i,j)
dflmiw = diwm(i,j)
!
! --- locate lowest substantial mass-containing layer.
pij(1)=p(i,j,1)
do k=1,kk
dpmm( k) =max(onemm,dp(i,j,k,n))
qdpmm(k) =1.0/dpmm(k)
pij( k+1)=pij(k)+dp(i,j,k,n)
p(i,j,k+1)=pij(k+1)
enddo
do k=kk,1,-1
if (dpmm(k).gt.tencm) then
exit
endif
enddo
klist(i,j)=max(k,2) !always consider at least 2 layers
!
qoneta = 1.0/oneta(i,j,n)
!
! --- dflbot (Prandtl number of one, i.e. diffusion = viscosity)
if (botdiw) then
! --- diffusion coefficent profile is: K = Kb / (1 + h/h0)**2
! --- where diwbot = Kb; diwqh0 = 1/h0 (input as h0, see forfun.f)
! --- Decloedt T. and D.S. Luther, 2009: On a Simple Empirical
! --- Parameterization of Topography-Catalyzed Diapycnal Mixing
! --- in the Abyssal Ocean. JPO, 40, pp 487-508.
! --- use Simpson's rule to estimate the average K across each layer
wz0 = 1.0 / (1.0 + (pij(kk+1)- pij(1) )*diwqh0(i,j))**2
wz1 = 1.0 / (1.0 + (pij(kk+1)-0.5*(pij(1)+ &
pij(2) ))*diwqh0(i,j))**2
wz2 = 1.0 / (1.0 + (pij(kk+1)- pij(2) )*diwqh0(i,j))**2
wq = wz0 + wz2 + 4.0*wz1 !6 times the average value over layer 1
do k= 2,kk
wt = wq
wz0 = wz2
wz1 = 1.0 / (1.0 + (pij(kk+1)-0.5*(pij(k) + &
pij(k+1) ))*diwqh0(i,j))**2
wz2 = 1.0 / (1.0 + (pij(kk+1)- pij(k+1) )*diwqh0(i,j))**2
wq = wz0 + wz2 + 4.0*wz1 !6 times the average value over layer k
dflbot(k) = (0.5/6.0)*(wt+wq)*diwbot(i,j)
enddo
dflbot(kk+1) = dflbot(kk)
else
do k= 2,kk+1
dflbot(k) = 0.0
enddo
endif !botdiw
!
! --- forcing of t,s by surface fluxes. flux positive into ocean.
!
qspcifh=1.0/spcifh
!
if (thermo .or. sstflg.gt.0 .or. srelax) then
! --- shortwave flux penetration depends on kpar or chl or jerlov water type.
if (jerlv0.le.0) then
chl = akpar(i,j,lk0)*wk0+akpar(i,j,lk1)*wk1 &
+akpar(i,j,lk2)*wk2+akpar(i,j,lk3)*wk3
endif
call swfrac_ij(chl,pij,klist(i,j)+1,qonem*oneta(i,j,n), &
jerlov(i,j),swfrac)
else
swfrac(1) = 1.0
swfrac(2:) = 0.0
endif
!
do k=1,kk
if (thermo .or. sstflg.gt.0 .or. srelax) then
if (k.eq.1) then
sflux1=surflx(i,j)-sswflx(i,j)
dtemp=(sflux1+(1.-swfrac(k+1))*sswflx(i,j))* &
delt1*g*qspcifh*(qdpmm(k)*qoneta)
if (epmass) then !only actual salt flux
dsaln= salflx(i,j)* &
delt1*g* (qdpmm(k)*qoneta)
else !water flux treated as a virtual salt flux
dsaln=(salflx(i,j)-wtrflx(i,j)*saln(i,j,1,n))* &
delt1*g* (qdpmm(k)*qoneta)
endif
!diag if (i.eq.itest.and.j.eq.jtest) then
!diag write (lp,101) nstep,i+i0,j+j0,k, &
!diag 1.0,swfrac(k+1),dtemp,dsaln
!diag call flush(lp)
!diag endif
elseif (k.le.klist(i,j)) then
dtemp=(swfrac(k)-swfrac(k+1))*sswflx(i,j)* &
delt1*g*qspcifh*(qdpmm(k)*qoneta)
dsaln=0.0
!diag if (i.eq.itest.and.j.eq.jtest) then
!diag write (lp,101) nstep,i+i0,j+j0,k, &
!diag swfrac(k),swfrac(k+1),dtemp
!diag call flush(lp)
!diag endif
else !k.gt.klist(i,j)
dtemp=0.0
dsaln=0.0
endif
else !.not.thermo ...
dtemp=0.0
dsaln=0.0
endif !thermo.or.sstflg.gt.0.or.srelax:else
!
! --- modify t and s; set old value arrays at p points for initial iteration
if (k.le.klist(i,j)) then
temp(i,j,k,n)= temp(i,j,k,n)+dtemp
saln(i,j,k,n)=max(saln(i,j,k,n)+dsaln,0.0) !must be non-negative
th3d(i,j,k,n)=sig(temp(i,j,k,n),saln(i,j,k,n))-thbase
told (k)=temp(i,j,k,n)
sold (k)=saln(i,j,k,n)
if (locsig) then
if (k.eq.1) then
thold(k)=th3d(i,j,k,n)
else
ka=k-1
alfadt(k)=dsiglocdt(ahalf*(told(ka)+told(k)), &
ahalf*(sold(ka)+sold(k)), &
p(i,j,k) )* &
(told(ka)-told(k))
betads(k)=dsiglocds(ahalf*(told(ka)+told(k)), &
ahalf*(sold(ka)+sold(k)), &
p(i,j,k) )* &
(sold(ka)-sold(k))
thold(k)=thold(ka)-alfadt(k)-betads(k)
endif
else
thold(k)=th3d(i,j,k,n)
endif
uold (k)=.5*(u(i,j,k,n)+u(i+1,j ,k,n))
vold (k)=.5*(v(i,j,k,n)+v(i ,j+1,k,n))
endif
enddo !k
!
k=klist(i,j)
ka=k+1
kb=min(ka,kk)
told (ka)=temp(i,j,kb,n)
sold (ka)=saln(i,j,kb,n)
if (locsig) then
alfadt(ka)=dsiglocdt(ahalf*(told(k)+told(ka)), &
ahalf*(sold(k)+sold(ka)), &
p(i,j,ka) )* &
(told(k)-told(ka))
betads(ka)=dsiglocds(ahalf*(told(k)+told(ka)), &
ahalf*(sold(k)+sold(ka)), &
p(i,j,ka) )* &
(sold(k)-sold(ka))
thold(ka)=thold(k)-alfadt(ka)-betads(ka)
else
thold(ka)=th3d(i,j,kb,n)
endif
uold (ka)=.5*(u(i,j,k,n)+u(i+1,j ,k,n))
vold (ka)=.5*(v(i,j,k,n)+v(i ,j+1,k,n))
!
! --- calculate z at vertical grid levels - this array is the z values in m
! --- at the mid-depth of each micom layer except for index klist+1, where it
! --- is the z value of the bottom
!
! --- calculate layer thicknesses in m
do k=1,kk
if (k.eq.1) then
hwide(k)=dpmm(k)*qonem
zgrid(i,j,k)=-.5*hwide(k)
else if (k.lt.klist(i,j)) then
hwide(k)=dpmm(k)*qonem
zgrid(i,j,k)=zgrid(i,j,k-1)-.5*(hwide(k-1)+hwide(k))
else if (k.eq.klist(i,j)) then
hwide(k)=dpmm(k)*qonem
zgrid(i,j,k)=zgrid(i,j,k-1)-.5*(hwide(k-1)+hwide(k))
zgrid(i,j,k+1)=zgrid(i,j,k)-.5*hwide(k)
else
hwide(k)=0.
endif
enddo
!
! --- perform niter iterations to execute the semi-implicit solution of the
! --- diffusion equation. at least two iterations are recommended
!
do iter=1,niter
!
! --- calculate layer variables required to estimate bulk richardson number
!
! --- calculate nearsurface reference variables,
! --- averaged over -2*epsilon*zgrid, but no more than 8m.
zrefmn = -4.0
zrefo = 1.0 ! impossible value
do k=1,klist(i,j)
zref=max(epsilon*zgrid(i,j,k),zrefmn) ! nearest to zero
if (zref.ne.zrefo) then ! new zref
wref =-2.0*zref
qwref=1.0/wref
wq=min(hwide(1),wref)*qwref
uref=uold(1)*wq
vref=vold(1)*wq
bref=-g*svref*(thold(1)+thbase)*wq
wt=0.0
do ka=2,k
wt=wt+wq
if (wt.ge.1.0) then
exit
endif
wq=min(1.0-wt,hwide(ka)*qwref)
uref=uref+uold(ka)*wq
vref=vref+vold(ka)*wq
bref=bref-g*svref*(thold(ka)+thbase)*wq
enddo
endif
zrefo=zref
!
ritop(k)=(zref-zgrid(i,j,k))* &
(bref+g*svref*(thold(k)+thbase))
dvsq(k)=(uref-uold(k))**2+(vref-vold(k))**2
!
! if (i.eq.itest.and.j.eq.jtest) then
! if (k.eq.1) then
! write(lp,'(3a)')
! & ' k z zref',
! & ' u uref v vref',
! & ' b bref ritop dvsq'
! endif
! write(lp,'(i2,f9.2,f6.2,4f7.3,2f7.3,f9.4,f7.4)')
! & k,zgrid(i,j,k),zref,
! & uold(k),uref,vold(k),vref,
! & -g*svref*(thold(k)+thbase),bref,
! & ritop(k),dvsq(k)
! call flush(lp)
! endif
!diag if (i.eq.itest.and.j.eq.jtest) then
!diag write (lp,'(i9,2i5,i3,a,f8.2,f8.3)') &
!diag nstep,i+i0,j+j0,k, &
!diag ' z,swfrac =',zgrid(i,j,k),swfrac(k)
!diag call flush(lp)
!diag endif
enddo !k=1,klist
!
! --- calculate interface variables required to estimate interior diffusivities
do k=1,klist(i,j)
k1=k+1
ka=min(k1,kk)
shsq (k1)=(uold(k)-uold(k1))**2+(vold(k)-vold(k1))**2
if (.not.locsig) then
alfadt(k1)=dsigdt(ahalf*(told(k)+told(k1)), &
ahalf*(sold(k)+sold(k1)) )* &
(told(k)-told(k1))
betads(k1)=dsigds(ahalf*(told(k)+told(k1)), &
ahalf*(sold(k)+sold(k1)) )* &
(sold(k)-sold(k1))
dbloc(k1)=-g* svref*(thold(k)-thold(ka))
else
dbloc(k1)=-g*svref*(alfadt(k1)+betads(k1))
endif
enddo
!
! --- zero 1-d arrays for viscosity/diffusivity calculations
!
do k=1,kk+1
vcty (i,j,k) =0.0
dift (i,j,k) =0.0
difs (i,j,k) =0.0
ghats(i,j,k) =0.0
blmc( k,1)=0.0
blmc( k,2)=0.0
blmc( k,3)=0.0
bblmc( k,1)=0.0
bblmc( k,2)=0.0
bblmc( k,3)=0.0
enddo
!
! --- determine interior diffusivity profiles throughout the water column
!
! --- shear instability plus background internal wave contributions
do k=2,klist(i,j)+1
if (shinst) then
q =zgrid(i,j,k-1)-zgrid(i,j,k) !0.5*(hwide(k-1)+hwide(k))
if (zgrid(i,j,k).gt.zgrid(i,j,klist(i,j)+1)-thkbot) then
q =min(q, thkbot) !in the nominal bottom boundary layer
endif
rigr=max(0.0,dbloc(k)*q/(shsq(k)+epsil))
ratio=min(rigr*qrinfy,1.0)
fri=(1.0-ratio*ratio)
fri=fri*fri*fri
vcty(i,j,k)=min(difm0*fri+dflmiw+dflbot(k),difmax)
difs(i,j,k)=min(difs0*fri+dflsiw+dflbot(k),difmax)
else
vcty(i,j,k)=dflmiw+dflbot(k)
difs(i,j,k)=dflsiw+dflbot(k)
endif
dift(i,j,k)=difs(i,j,k)
enddo
!
! --- double-diffusion (salt fingering and diffusive convection)
if (dbdiff) then
do k=2,klist(i,j)+1
!
! --- salt fingering case
if (-alfadt(k).gt.betads(k) .and. betads(k).gt.0.) then
rrho= min(-alfadt(k)/betads(k),rrho0)
diffdd=1.-((rrho-1.)/(rrho0-1.))**2
diffdd=dsfmax*diffdd*diffdd*diffdd
dift(i,j,k)=dift(i,j,k)+0.7*diffdd
difs(i,j,k)=difs(i,j,k)+diffdd
!
! --- diffusive convection case
else if ( alfadt(k).gt.0.0 .and. betads(k).lt.0.0 &
.and. -alfadt(k).gt.betads(k)) then
rrho=-alfadt(k)/betads(k)
diffdd=1.5e-6*9.*.101*exp(4.6*exp(-.54*(1./rrho-1.)))
if (rrho.gt.0.5) then
prandtl=(1.85-.85/rrho)*rrho
else
prandtl=.15*rrho
endif
dift(i,j,k)=dift(i,j,k)+diffdd
difs(i,j,k)=difs(i,j,k)+prandtl*diffdd
endif
enddo
endif
!
!diag if (i.eq.itest.and.j.eq.jtest) then
!diag write (lp,102) (nstep,iter,i+i0,j+j0,k, &
!diag hwide(k),1.e4*vcty(i,j,k),1.e4*dift(i,j,k),1.e4*difs(i,j,k), &
!diag k=1,kk+1)
!diag call flush(lp)
!diag endif
!
! --- calculate boundary layer diffusivity profiles and match these to the
! --- previously-calculated interior diffusivity profiles
!
! --- diffusivities within the surface boundary layer are parameterized
! --- as a function of boundary layer thickness times a depth-dependent
! --- turbulent velocity scale (proportional to ustar) times a third-order
! --- polynomial shape function of depth. boundary layer diffusivities depend
! --- on surface forcing (the magnitude of this forcing and whether it is
! --- stabilizing or de-stabilizing) and the magnitude and gradient of interior
! --- mixing at the boundary layer base. boundary layer diffusivity profiles
! --- are smoothly matched to interior diffusivity profiles at the boundary
! --- layer base (the profiles and their first derivatives are continuous
! --- at z=-hbl). the turbulent boundary layer depth is diagnosed first, the
! --- boundary layer diffusivity profiles are calculated, then the boundary
! --- and interior diffusivity profiles are combined.
!
! --- minimum hbl is top mid-layer + 1 cm or bldmin,
! --- maximum hbl is bottom mid-layer - 1 cm or bldmax.
!
hblmin=max( hwide(1)+0.01,bldmin)
hblmax=min(-zgrid(i,j,klist(i,j))-0.01,bldmax)
!
! --- buoyfl = total buoyancy flux (m**2/sec**3) into atmos.
! --- note: surface density increases (column is destabilized) if buoyfl > 0
! --- buoysw = shortwave radiation buoyancy flux (m**2/sec**3) into atmos.
! --- salflx, sswflx and surflx are positive into the ocean
tmn=.5*(temp(i,j,1,m)+temp(i,j,1,n))
smn=.5*(saln(i,j,1,m)+saln(i,j,1,n))
dsgdt= dsigdt(tmn,smn)
buoyfs=g*svref*(dsigds(tmn,smn)* &
(-wtrflx(i,j)*saln(i,j,1,n)+salflx(i,j))*svref)
buoyfl=buoyfs+ &
g*svref*(dsgdt *surflx(i,j) *svref/spcifh)
buoysw=g*svref*(dsgdt *sswflx(i,j) *svref/spcifh)
!
! --- diagnose the new boundary layer depth as the depth where a bulk
! --- richardson number exceeds ric
!
! --- initialize hbl and nbl to bottomed out values
kup2=1
kup =2
kdn =3
rib(kup2)=0.0
rib(kup) =0.0
nbl=klist(i,j)
hbl=hblmax
!
! --- diagnose hbl and nbl
do k=2,nbl
case=-zgrid(i,j,k)
bfsfc=buoyfl-swfrac(k)*buoysw
if (bfsfc.le.0.0) then
stable=1.0
dnorm =1.0
else
stable=0.0
dnorm =epsilon
endif
!
! --- compute turbulent velocity scales at dnorm, for
! --- hbl = case = -zgrid(i,j,k)
call wscale(i,j,case,dnorm,bfsfc,wm,ws,1)
!