forked from mom-ocean/MOM6
-
Notifications
You must be signed in to change notification settings - Fork 59
/
MOM_vert_friction.F90
3213 lines (2929 loc) · 165 KB
/
MOM_vert_friction.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
!> Implements vertical viscosity (vertvisc)
module MOM_vert_friction
! This file is part of MOM6. See LICENSE.md for the license.
use MOM_domains, only : pass_var, To_All, Omit_corners
use MOM_domains, only : pass_vector, Scalar_Pair
use MOM_diag_mediator, only : post_data, register_diag_field, safe_alloc_ptr
use MOM_diag_mediator, only : post_product_u, post_product_sum_u
use MOM_diag_mediator, only : post_product_v, post_product_sum_v
use MOM_diag_mediator, only : diag_ctrl, query_averaging_enabled
use MOM_domains, only : create_group_pass, do_group_pass, group_pass_type
use MOM_domains, only : To_North, To_East
use MOM_debugging, only : uvchksum, hchksum
use MOM_error_handler, only : MOM_error, FATAL, WARNING, NOTE
use MOM_file_parser, only : get_param, log_param, log_version, param_file_type
use MOM_forcing_type, only : mech_forcing, find_ustar
use MOM_get_input, only : directories
use MOM_grid, only : ocean_grid_type
use MOM_io, only : MOM_read_data, slasher
use MOM_open_boundary, only : ocean_OBC_type, OBC_NONE, OBC_DIRECTION_E
use MOM_open_boundary, only : OBC_DIRECTION_W, OBC_DIRECTION_N, OBC_DIRECTION_S
use MOM_PointAccel, only : write_u_accel, write_v_accel, PointAccel_init
use MOM_PointAccel, only : PointAccel_CS
use MOM_time_manager, only : time_type, time_type_to_real, operator(-)
use MOM_unit_scaling, only : unit_scale_type
use MOM_variables, only : thermo_var_ptrs, vertvisc_type
use MOM_variables, only : cont_diag_ptrs, accel_diag_ptrs
use MOM_variables, only : ocean_internal_state
use MOM_verticalGrid, only : verticalGrid_type
use MOM_wave_interface, only : wave_parameters_CS
use MOM_set_visc, only : set_v_at_u, set_u_at_v
use MOM_lateral_mixing_coeffs, only : VarMix_CS
implicit none ; private
#include <MOM_memory.h>
public vertvisc, vertvisc_remnant, vertvisc_coef
public vertvisc_limit_vel, vertvisc_init, vertvisc_end
public updateCFLtruncationValue
public vertFPmix
! A note on unit descriptions in comments: MOM6 uses units that can be rescaled for dimensional
! consistency testing. These are noted in comments with units like Z, H, L, and T, along with
! their mks counterparts with notation like "a velocity [Z T-1 ~> m s-1]". If the units
! vary with the Boussinesq approximation, the Boussinesq variant is given first.
!> The control structure with parameters and memory for the MOM_vert_friction module
type, public :: vertvisc_CS ; private
logical :: initialized = .false. !< True if this control structure has been initialized.
real :: Hmix !< The mixed layer thickness [Z ~> m].
real :: Hmix_stress !< The mixed layer thickness over which the wind
!! stress is applied with direct_stress [H ~> m or kg m-2].
real :: Kvml_invZ2 !< The extra vertical viscosity scale in [H Z T-1 ~> m2 s-1 or Pa s] in a
!! surface mixed layer with a characteristic thickness given by Hmix,
!! and scaling proportional to (Hmix/z)^2, where z is the distance
!! from the surface; this can get very large with thin layers.
real :: Kv !< The interior vertical viscosity [H Z T-1 ~> m2 s-1 or Pa s].
real :: Hbbl !< The static bottom boundary layer thickness [Z ~> m].
real :: Hbbl_gl90 !< The static bottom boundary layer thickness used for GL90 [Z ~> m].
real :: Kv_extra_bbl !< An extra vertical viscosity in the bottom boundary layer of thickness
!! Hbbl when there is not a bottom drag law in use [H Z T-1 ~> m2 s-1 or Pa s].
real :: vonKar !< The von Karman constant as used for mixed layer viscosity [nondim]
logical :: use_GL90_in_SSW !< If true, use the GL90 parameterization in stacked shallow water mode (SSW).
!! The calculation of the GL90 viscosity coefficient uses the fact that in SSW
!! we simply have 1/N^2 = h/g^prime, where g^prime is the reduced gravity.
!! This identity does not generalize to non-SSW setups.
logical :: use_GL90_N2 !< If true, use GL90 vertical viscosity coefficient that is depth-independent;
!! this corresponds to a kappa_GM that scales as N^2 with depth.
real :: kappa_gl90 !< The scalar diffusivity used in the GL90 vertical viscosity scheme
!! [L2 H Z-1 T-1 ~> m2 s-1 or Pa s]
logical :: read_kappa_gl90 !< If true, read a file containing the spatially varying kappa_gl90
real :: alpha_gl90 !< Coefficient used to compute a depth-independent GL90 vertical
!! viscosity via Kv_gl90 = alpha_gl90 * f^2. Note that the implied
!! Kv_gl90 corresponds to a kappa_gl90 that scales as N^2 with depth.
!! [H Z T ~> m2 s or kg s m-1]
real :: maxvel !< Velocity components greater than maxvel are truncated [L T-1 ~> m s-1].
real :: vel_underflow !< Velocity components smaller than vel_underflow
!! are set to 0 [L T-1 ~> m s-1].
logical :: CFL_based_trunc !< If true, base truncations on CFL numbers, not
!! absolute velocities.
real :: CFL_trunc !< Velocity components will be truncated when they
!! are large enough that the corresponding CFL number
!! exceeds this value [nondim].
real :: CFL_report !< The value of the CFL number that will cause the
!! accelerations to be reported [nondim]. CFL_report
!! will often equal CFL_trunc.
real :: truncRampTime !< The time-scale over which to ramp up the value of
!! CFL_trunc from CFL_truncS to CFL_truncE [T ~> s]
real :: CFL_truncS !< The start value of CFL_trunc [nondim]
real :: CFL_truncE !< The end/target value of CFL_trunc [nondim]
logical :: CFLrampingIsActivated = .false. !< True if the ramping has been initialized
type(time_type) :: rampStartTime !< The time at which the ramping of CFL_trunc starts
real ALLOCABLE_, dimension(NIMEMB_PTR_,NJMEM_,NK_INTERFACE_) :: &
a_u !< The u-drag coefficient across an interface [H T-1 ~> m s-1 or Pa s m-1]
real ALLOCABLE_, dimension(NIMEMB_PTR_,NJMEM_,NK_INTERFACE_) :: &
a_u_gl90 !< The u-drag coefficient associated with GL90 across an interface [H T-1 ~> m s-1 or Pa s m-1]
real ALLOCABLE_, dimension(NIMEMB_PTR_,NJMEM_,NKMEM_) :: &
h_u !< The effective layer thickness at u-points [H ~> m or kg m-2].
real ALLOCABLE_, dimension(NIMEM_,NJMEMB_PTR_,NK_INTERFACE_) :: &
a_v !< The v-drag coefficient across an interface [H T-1 ~> m s-1 or Pa s m-1]
real ALLOCABLE_, dimension(NIMEM_,NJMEMB_PTR_,NK_INTERFACE_) :: &
a_v_gl90 !< The v-drag coefficient associated with GL90 across an interface [H T-1 ~> m s-1 or Pa s m-1]
real ALLOCABLE_, dimension(NIMEM_,NJMEMB_PTR_,NKMEM_) :: &
h_v !< The effective layer thickness at v-points [H ~> m or kg m-2].
real, pointer, dimension(:,:) :: a1_shelf_u => NULL() !< The u-momentum coupling coefficient under
!! ice shelves [H T-1 ~> m s-1 or Pa s m-1]. Retained to determine stress under shelves.
real, pointer, dimension(:,:) :: a1_shelf_v => NULL() !< The v-momentum coupling coefficient under
!! ice shelves [H T-1 ~> m s-1 or Pa s m-1]. Retained to determine stress under shelves.
logical :: split !< If true, use the split time stepping scheme.
logical :: bottomdraglaw !< If true, the bottom stress is calculated with a
!! drag law c_drag*|u|*u. The velocity magnitude
!! may be an assumed value or it may be based on the
!! actual velocity in the bottommost HBBL, depending
!! on whether linear_drag is true.
logical :: harmonic_visc !< If true, the harmonic mean thicknesses are used
!! to calculate the viscous coupling between layers
!! except near the bottom. Otherwise the arithmetic
!! mean thickness is used except near the bottom.
real :: harm_BL_val !< A scale to determine when water is in the boundary
!! layers based solely on harmonic mean thicknesses
!! for the purpose of determining the extent to which
!! the thicknesses used in the viscosities are upwinded [nondim].
logical :: direct_stress !< If true, the wind stress is distributed over the topmost Hmix_stress
!! of fluid, and an added mixed layer viscosity or a physically based
!! boundary layer turbulence parameterization is not needed for stability.
logical :: dynamic_viscous_ML !< If true, use the results from a dynamic
!! calculation, perhaps based on a bulk Richardson
!! number criterion, to determine the mixed layer
!! thickness for viscosity.
logical :: fixed_LOTW_ML !< If true, use a Law-of-the-wall prescription for the mixed layer
!! viscosity within a boundary layer that is the lesser of Hmix and the
!! total depth of the ocean in a column.
logical :: apply_LOTW_floor !< If true, use a Law-of-the-wall prescription to set a lower bound
!! on the viscous coupling between layers within the surface boundary
!! layer, based the distance of interfaces from the surface. This only
!! acts when there are large changes in the thicknesses of successive
!! layers or when the viscosity is set externally and the wind stress
!! has subsequently increased.
integer :: answer_date !< The vintage of the order of arithmetic and expressions in the viscous
!! calculations. Values below 20190101 recover the answers from the end
!! of 2018, while higher values use expressions that do not use an
!! arbitrary and hard-coded maximum viscous coupling coefficient between
!! layers. In non-Boussinesq cases, values below 20230601 recover a
!! form of the viscosity within the mixed layer that breaks up the
!! magnitude of the wind stress with BULKMIXEDLAYER, DYNAMIC_VISCOUS_ML
!! or FIXED_DEPTH_LOTW_ML, but not LOTW_VISCOUS_ML_FLOOR.
logical :: debug !< If true, write verbose checksums for debugging purposes.
integer :: nkml !< The number of layers in the mixed layer.
integer, pointer :: ntrunc !< The number of times the velocity has been
!! truncated since the last call to write_energy.
character(len=200) :: u_trunc_file !< The complete path to a file in which a column of
!! u-accelerations are written if velocity truncations occur.
character(len=200) :: v_trunc_file !< The complete path to a file in which a column of
!! v-accelerations are written if velocity truncations occur.
logical :: StokesMixing !< If true, do Stokes drift mixing via the Lagrangian current
!! (Eulerian plus Stokes drift). False by default and set
!! via STOKES_MIXING_COMBINED.
type(diag_ctrl), pointer :: diag !< A structure that is used to regulate the
!! timing of diagnostic output.
real, allocatable, dimension(:,:) :: kappa_gl90_2d !< 2D kappa_gl90 at h-points [L2 H Z-1 T-1 ~> m2 s-1 or Pa s]
!>@{ Diagnostic identifiers
integer :: id_du_dt_visc = -1, id_dv_dt_visc = -1, id_du_dt_visc_gl90 = -1, id_dv_dt_visc_gl90 = -1
integer :: id_GLwork = -1
integer :: id_au_vv = -1, id_av_vv = -1, id_au_gl90_vv = -1, id_av_gl90_vv = -1
integer :: id_du_dt_str = -1, id_dv_dt_str = -1
integer :: id_h_u = -1, id_h_v = -1, id_hML_u = -1 , id_hML_v = -1
integer :: id_FPw2x = -1 !W id_FPhbl_u = -1, id_FPhbl_v = -1
integer :: id_tauFP_u = -1, id_tauFP_v = -1 !W, id_FPtau2x_u = -1, id_FPtau2x_v = -1
integer :: id_FPtau2s_u = -1, id_FPtau2s_v = -1, id_FPtau2w_u = -1, id_FPtau2w_v = -1
integer :: id_taux_bot = -1, id_tauy_bot = -1
integer :: id_Kv_slow = -1, id_Kv_u = -1, id_Kv_v = -1
integer :: id_Kv_gl90_u = -1, id_Kv_gl90_v = -1
! integer :: id_hf_du_dt_visc = -1, id_hf_dv_dt_visc = -1
integer :: id_h_du_dt_visc = -1, id_h_dv_dt_visc = -1
integer :: id_hf_du_dt_visc_2d = -1, id_hf_dv_dt_visc_2d = -1
integer :: id_h_du_dt_str = -1, id_h_dv_dt_str = -1
integer :: id_du_dt_str_visc_rem = -1, id_dv_dt_str_visc_rem = -1
!>@}
type(PointAccel_CS), pointer :: PointAccel_CSp => NULL() !< A pointer to the control structure
!! for recording accelerations leading to velocity truncations
type(group_pass_type) :: pass_KE_uv !< A handle used for group halo passes
end type vertvisc_CS
contains
!> Add nonlocal stress increments to u^n (uold) and v^n (vold) using ui and vi.
subroutine vertFPmix(ui, vi, uold, vold, hbl_h, h, forces, dt, G, GV, US, CS, OBC)
type(ocean_grid_type), intent(in) :: G !< Ocean grid structure
type(verticalGrid_type), intent(in) :: GV !< Ocean vertical grid structure
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)), &
intent(inout) :: ui !< Zonal velocity after vertvisc [L T-1 ~> m s-1]
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)), &
intent(inout) :: vi !< Meridional velocity after vertvisc [L T-1 ~> m s-1]
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)), &
intent(inout) :: uold !< Old Zonal velocity [L T-1 ~> m s-1]
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)), &
intent(inout) :: vold !< Old Meridional velocity [L T-1 ~> m s-1]
real, dimension(SZI_(G),SZJ_(G)), intent(inout) :: hbl_h !< boundary layer depth [H ~> m]
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)), &
intent(in) :: h !< Layer thicknesses [H ~> m or kg m-2]
type(mech_forcing), intent(in) :: forces !< A structure with the driving mechanical forces
real, intent(in) :: dt !< Time increment [T ~> s]
type(unit_scale_type), intent(in) :: US !< A dimensional unit scaling type
type(vertvisc_CS), pointer :: CS !< Vertical viscosity control structure
type(ocean_OBC_type), pointer :: OBC !< Open boundary condition structure
! local variables
real, dimension(SZIB_(G),SZJ_(G)) :: hbl_u !< boundary layer depth at u-pts [H ~> m]
real, dimension(SZI_(G),SZJB_(G)) :: hbl_v !< boundary layer depth at v-pts [H ~> m]
integer, dimension(SZIB_(G),SZJ_(G)) :: kbl_u !< index of the BLD at u-pts [nondim]
integer, dimension(SZI_(G),SZJB_(G)) :: kbl_v !< index of the BLD at v-pts [nondim]
real, dimension(SZIB_(G),SZJ_(G)) :: ustar2_u !< ustar squared at u-pts [L2 T-2 ~> m2 s-2]
real, dimension(SZI_(G),SZJB_(G)) :: ustar2_v !< ustar squared at v-pts [L2 T-2 ~> m2 s-2]
real, dimension(SZIB_(G),SZJ_(G)) :: taux_u !< zonal wind stress at u-pts [R L Z T-2 ~> Pa]
real, dimension(SZI_(G),SZJB_(G)) :: tauy_v !< meridional wind stress at v-pts [R L Z T-2 ~> Pa]
!real, dimension(SZIB_(G),SZJ_(G)) :: omega_w2x_u !< angle between wind and x-axis at u-pts [rad]
!real, dimension(SZI_(G),SZJB_(G)) :: omega_w2x_v !< angle between wind and y-axis at v-pts [rad]
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)+1) :: tau_u !< kinematic zonal mtm flux at u-pts [L2 T-2 ~> m2 s-2]
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)+1) :: tau_v !< kinematic mer. mtm flux at v-pts [L2 T-2 ~> m2 s-2]
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)+1) :: tauxDG_u !< downgradient zonal mtm flux at u-pts [L2 T-2 ~> m2 s-2]
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)+1) :: tauyDG_u !< downgradient meri mtm flux at u-pts [L2 T-2 ~> m2 s-2]
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)+1) :: tauxDG_v !< downgradient zonal mtm flux at v-pts [L2 T-2 ~> m2 s-2]
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)+1) :: tauyDG_v !< downgradient meri mtm flux at v-pts [L2 T-2 ~> m2 s-2]
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)+1) :: omega_tau2s_u !< angle between mtm flux and vert shear at u-pts [rad]
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)+1) :: omega_tau2s_v !< angle between mtm flux and vert shear at v-pts [rad]
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)+1) :: omega_tau2w_u !< angle between mtm flux and wind at u-pts [rad]
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)+1) :: omega_tau2w_v !< angle between mtm flux and wind at v-pts [rad]
real :: pi, Cemp_CG, tmp, cos_tmp, sin_tmp !< constants and dummy variables [nondim]
real :: omega_tmp !< A dummy angle [radians]
real :: du, dv !< Velocity increments [L T-1 ~> m s-1]
real :: depth !< Cumulative layer thicknesses [H ~> m or kg m=2]
real :: sigma !< Fractional depth in the mixed layer [nondim]
real :: Wind_x, Wind_y !< intermediate wind stress componenents [L2 T-2 ~> m2 s-2]
real :: taux, tauy, tauxDG, tauyDG, tauxDGup, tauyDGup, ustar2, tauh !< intermediate variables [L2 T-2 ~> m2 s-2]
real :: tauNLup, tauNLdn, tauNL_CG, tauNL_DG, tauNL_X, tauNL_Y, tau_MAG !< intermediate variables [L2 T-2 ~> m2 s-2]
real :: omega_w2s, omega_tau2s, omega_s2x, omega_tau2x, omega_tau2w, omega_s2w !< intermediate angles [radians]
integer :: kblmin, kbld, kp1, k, nz !< vertical indices
integer :: i, j, is, ie, js, je, Isq, Ieq, Jsq, Jeq ! horizontal indices
is = G%isc ; ie = G%iec; js = G%jsc; je = G%jec
Isq = G%IscB ; Ieq = G%IecB ; Jsq = G%JscB ; Jeq = G%JecB ; nz = GV%ke
pi = 4. * atan2(1.,1.)
Cemp_CG = 3.6
kblmin = 1
taux_u(:,:) = 0.
tauy_v(:,:) = 0.
do j = js,je
do I = Isq,Ieq
taux_u(I,j) = forces%taux(I,j) / GV%H_to_RZ !W rho0=1035.
enddo
enddo
do J = Jsq,Jeq
do i = is,ie
tauy_v(i,J) = forces%tauy(i,J) / GV%H_to_RZ
enddo
enddo
call pass_var( hbl_h ,G%Domain, halo=1 )
call pass_vector(taux_u , tauy_v, G%Domain, To_All )
ustar2_u(:,:) = 0.
ustar2_v(:,:) = 0.
hbl_u(:,:) = 0.
hbl_v(:,:) = 0.
kbl_u(:,:) = 0
kbl_v(:,:) = 0
!omega_w2x_u(:,:) = 0.0
!omega_w2x_v(:,:) = 0.0
tauxDG_u(:,:,:) = 0.0
tauyDG_v(:,:,:) = 0.0
do j = js,je
do I = Isq,Ieq
if( (G%mask2dCu(I,j) > 0.5) ) then
tmp = MAX (1.0 ,(G%mask2dT(i,j) + G%mask2dT(i+1,j) ) )
hbl_u(I,j) = (G%mask2dT(i,j)* hbl_h(i,j) + G%mask2dT(i+1,j) * hbl_h(i+1,j)) /tmp
tmp = MAX(1.0, (G%mask2dCv(i,j) + G%mask2dCv(i,j-1) + G%mask2dCv(i+1,j) + G%mask2dCv(i+1,j-1) ) )
tauy = ( G%mask2dCv(i ,j )*tauy_v(i ,j ) + G%mask2dCv(i ,j-1)*tauy_v(i ,j-1) &
+ G%mask2dCv(i+1,j )*tauy_v(i+1,j ) + G%mask2dCv(i+1,j-1)*tauy_v(i+1,j-1) ) / tmp
ustar2_u(I,j) = sqrt( taux_u(I,j)*taux_u(I,j) + tauy*tauy )
!omega_w2x_u(I,j) = atan2( tauy , taux_u(I,j) )
tauxDG_u(I,j,1) = taux_u(I,j)
depth = 0.0
do k = 1, nz
depth = depth + CS%h_u(I,j,k)
if( (depth >= hbl_u(I,j)) .and. (kbl_u(I,j) == 0 ) .and. (k > (kblmin-1)) ) then
kbl_u(I,j) = k
hbl_u(I,j) = depth
endif
enddo
endif
enddo
enddo
do J = Jsq,Jeq
do i = is,ie
if( (G%mask2dCv(i,J) > 0.5) ) then
tmp = max( 1.0 ,(G%mask2dT(i,j) + G%mask2dT(i,j+1)))
hbl_v(i,J) = (G%mask2dT(i,j) * hbl_h(i,J) + G%mask2dT(i,j+1) * hbl_h(i,j+1)) /tmp
tmp = max(1.0, (G%mask2dCu(i,j) + G%mask2dCu(i,j+1) + G%mask2dCu(i-1,j) + G%mask2dCu(i-1,j+1)))
taux = ( G%mask2dCu(i ,j) * taux_u(i ,j) + G%mask2dCu(i ,j+1) * taux_u(i ,j+1) &
+ G%mask2dCu(i-1,j) * taux_u(i-1,j) + G%mask2dCu(i-1,j+1) * taux_u(i-1,j+1)) / tmp
ustar2_v(i,J) = sqrt(tauy_v(i,J)*tauy_v(i,J) + taux*taux)
!omega_w2x_v(i,J) = atan2( tauy_v(i,J), taux )
tauyDG_v(i,J,1) = tauy_v(i,J)
depth = 0.0
do k = 1, nz
depth = depth + CS%h_v(i,J,k)
if( (depth >= hbl_v(i,J)) .and. (kbl_v(i,J) == 0) .and. (k > (kblmin-1))) then
kbl_v(i,J) = k
hbl_v(i,J) = depth
endif
enddo
endif
enddo
enddo
if (CS%debug) then
!### These checksum calls are missing necessary dimensional scaling factors.
call uvchksum("surface tau[xy]_[uv] ", taux_u, tauy_v, G%HI, haloshift=1, scalar_pair=.true.)
call uvchksum("ustar2", ustar2_u, ustar2_v, G%HI, haloshift=0, scalar_pair=.true.)
call uvchksum(" hbl", hbl_u , hbl_v , G%HI, haloshift=0, scalar_pair=.true.)
endif
! Compute downgradient stresses
do k = 1, nz
kp1 = min( k+1 , nz)
do j = js ,je
do I = Isq , Ieq
tauxDG_u(I,j,k+1) = CS%a_u(I,j,kp1) * (ui(I,j,k) - ui(I,j,kp1))
enddo
enddo
do J = Jsq , Jeq
do i = is , ie
tauyDG_v(i,J,k+1) = CS%a_v(i,J,kp1) * (vi(i,J,k) - vi(i,J,kp1))
enddo
enddo
enddo
call pass_vector(tauxDG_u, tauyDG_v , G%Domain, To_All)
call pass_vector(ui,vi, G%Domain, To_All)
tauxDG_v(:,:,:) = 0.
tauyDG_u(:,:,:) = 0.
! Thickness weighted interpolations
do k = 1, nz
! v to u points
do j = js , je
do I = Isq, Ieq
tauyDG_u(I,j,k) = set_v_at_u(tauyDG_v, h, G, GV, I, j, k, G%mask2dCv, OBC)
enddo
enddo
! u to v points
do J = Jsq, Jeq
do i = is, ie
tauxDG_v(i,J,k) = set_u_at_v(tauxDG_u, h, G, GV, i, J, k, G%mask2dCu, OBC)
enddo
enddo
enddo
if (CS%debug) then
call uvchksum(" tauyDG_u tauxDG_v",tauyDG_u,tauxDG_v, G%HI, haloshift=0, scalar_pair=.true.)
endif
! compute angles, tau2x_[u,v], tau2w_[u,v], tau2s_[u,v], s2w_[u,v] and stress mag tau_[u,v]
omega_tau2w_u(:,:,:) = 0.0
omega_tau2w_v(:,:,:) = 0.0
omega_tau2s_u(:,:,:) = 0.0
omega_tau2s_v(:,:,:) = 0.0
tau_u(:,:,:) = 0.0
tau_v(:,:,:) = 0.0
! stress magnitude tau_[uv] & direction Omega_tau2(w,s,x)_[uv]
do j = js,je
do I = Isq,Ieq
if( (G%mask2dCu(I,j) > 0.5) ) then
! SURFACE
tauyDG_u(I,j,1) = ustar2_u(I,j) !* cos(omega_w2x_u(I,j))
tau_u(I,j,1) = ustar2_u(I,j)
Omega_tau2w_u(I,j,1) = 0.0
Omega_tau2s_u(I,j,1) = 0.0
do k=1,nz
kp1 = MIN(k+1 , nz)
tau_u(I,j,k+1) = sqrt( (tauxDG_u(I,j,k+1)*tauxDG_u(I,j,k+1)) + (tauyDG_u(I,j,k+1)*tauyDG_u(I,j,k+1)) )
Omega_tau2x = atan2( tauyDG_u(I,j,k+1) , tauxDG_u(I,j,k+1) )
omega_tmp = Omega_tau2x !- omega_w2x_u(I,j)
if ( (omega_tmp > pi ) ) omega_tmp = omega_tmp - 2.*pi
if ( (omega_tmp < (0.-pi)) ) omega_tmp = omega_tmp + 2.*pi
Omega_tau2w_u(I,j,k+1) = omega_tmp
Omega_tau2s_u(I,j,k+1) = 0.0
enddo
endif
enddo
enddo
do J = Jsq, Jeq
do i = is, ie
if( (G%mask2dCv(i,J) > 0.5) ) then
! SURFACE
tauxDG_v(i,J,1) = ustar2_v(i,J) !* sin(omega_w2x_v(i,J))
tau_v(i,J,1) = ustar2_v(i,J)
Omega_tau2w_v(i,J,1) = 0.0
Omega_tau2s_v(i,J,1) = 0.0
do k=1,nz-1
kp1 = MIN(k+1 , nz)
tau_v(i,J,k+1) = sqrt ( (tauxDG_v(i,J,k+1)*tauxDG_v(i,J,k+1)) + (tauyDG_v(i,J,k+1)*tauyDG_v(i,J,k+1)) )
omega_tau2x = atan2( tauyDG_v(i,J,k+1) , tauxDG_v(i,J,k+1) )
omega_tmp = omega_tau2x !- omega_w2x_v(i,J)
if ( (omega_tmp > pi ) ) omega_tmp = omega_tmp - 2.*pi
if ( (omega_tmp < (0.-pi)) ) omega_tmp = omega_tmp + 2.*pi
Omega_tau2w_v(i,J,k+1) = omega_tmp
Omega_tau2s_v(i,J,k+1) = 0.0
enddo
endif
enddo
enddo
! Parameterized stress orientation from the wind at interfaces (tau2x)
! and centers (tau2x) OVERWRITE to kbl-interface above hbl
do j = js,je
do I = Isq,Ieq
if( (G%mask2dCu(I,j) > 0.5) ) then
kbld = min( (kbl_u(I,j)) , (nz-2) )
if ( tau_u(I,j,kbld+2) > tau_u(I,j,kbld+1) ) kbld = kbld + 1
!### This expression is dimensionally inconsistent.
tauh = tau_u(I,j,kbld+1) + GV%H_subroundoff
! surface boundary conditions
depth = 0.
tauNLup = 0.0
do k=1, kbld
depth = depth + CS%h_u(I,j,k)
sigma = min( 1.0 , depth / hbl_u(i,j) )
! linear stress mag
tau_MAG = (ustar2_u(I,j) * (1.-sigma) ) + (tauh * sigma )
!### The following expressions are dimensionally inconsistent.
cos_tmp = tauxDG_u(I,j,k+1) / (tau_u(I,j,k+1) + GV%H_subroundoff)
sin_tmp = tauyDG_u(I,j,k+1) / (tau_u(I,j,k+1) + GV%H_subroundoff)
! rotate to wind coordinates
Wind_x = ustar2_u(I,j) !* cos(omega_w2x_u(I,j))
Wind_y = ustar2_u(I,j) !* sin(omega_w2x_u(I,j))
tauNL_DG = (Wind_x * cos_tmp + Wind_y * sin_tmp)
tauNL_CG = (Wind_y * cos_tmp - Wind_x * sin_tmp)
omega_w2s = atan2(tauNL_CG, tauNL_DG)
omega_s2w = 0.0-omega_w2s
tauNL_CG = Cemp_CG * G_sig(sigma) * tauNL_CG
tau_MAG = max(tau_MAG, tauNL_CG)
tauNL_DG = sqrt(tau_MAG*tau_MAG - tauNL_CG*tauNL_CG) - tau_u(I,j,k+1)
! back to x,y coordinates
tauNL_X = (tauNL_DG * cos_tmp - tauNL_CG * sin_tmp)
tauNL_Y = (tauNL_DG * sin_tmp + tauNL_CG * cos_tmp)
tauNLdn = tauNL_X
! nonlocal increment and update to uold
!### The following expression is dimensionally inconsistent and missing parentheses.
du = (tauNLup - tauNLdn) * (dt/CS%h_u(I,j,k) + GV%H_subroundoff)
ui(I,j,k) = uold(I,j,k) + du
uold(I,j,k) = du
tauNLup = tauNLdn
! diagnostics
Omega_tau2s_u(I,j,k+1) = atan2(tauNL_CG , (tau_u(I,j,k+1)+tauNL_DG))
tau_u(I,j,k+1) = sqrt(((tauxDG_u(I,j,k+1) + tauNL_X)**2) + ((tauyDG_u(I,j,k+1) + tauNL_Y)**2))
omega_tau2x = atan2((tauyDG_u(I,j,k+1) + tauNL_Y), (tauxDG_u(I,j,k+1) + tauNL_X))
omega_tau2w = omega_tau2x !- omega_w2x_u(I,j)
if (omega_tau2w >= pi ) omega_tau2w = omega_tau2w - 2.*pi
if (omega_tau2w <= (0.-pi) ) omega_tau2w = omega_tau2w + 2.*pi
Omega_tau2w_u(I,j,k+1) = omega_tau2w
enddo
do k= kbld+1, nz
ui(I,j,k) = uold(I,j,k)
uold(I,j,k) = 0.0
enddo
endif
enddo
enddo
! v-point dv increment
do J = Jsq,Jeq
do i = is,ie
if( (G%mask2dCv(i,J) > 0.5) ) then
kbld = min((kbl_v(i,J)), (nz-2))
if (tau_v(i,J,kbld+2) > tau_v(i,J,kbld+1)) kbld = kbld + 1
tauh = tau_v(i,J,kbld+1)
!surface boundary conditions
depth = 0.
tauNLup = 0.0
do k=1, kbld
depth = depth + CS%h_v(i,J,k)
sigma = min(1.0, depth/ hbl_v(I,J))
! linear stress
tau_MAG = (ustar2_v(i,J) * (1.-sigma)) + (tauh * sigma)
!### The following expressions are dimensionally inconsistent.
cos_tmp = tauxDG_v(i,J,k+1) / (tau_v(i,J,k+1) + GV%H_subroundoff)
sin_tmp = tauyDG_v(i,J,k+1) / (tau_v(i,J,k+1) + GV%H_subroundoff)
! rotate into wind coordinate
Wind_x = ustar2_v(i,J) !* cos(omega_w2x_v(i,J))
Wind_y = ustar2_v(i,J) !* sin(omega_w2x_v(i,J))
tauNL_DG = (Wind_x * cos_tmp + Wind_y * sin_tmp)
tauNL_CG = (Wind_y * cos_tmp - Wind_x * sin_tmp)
omega_w2s = atan2(tauNL_CG , tauNL_DG)
omega_s2w = 0.0 - omega_w2s
tauNL_CG = Cemp_CG * G_sig(sigma) * tauNL_CG
tau_MAG = max( tau_MAG , tauNL_CG )
tauNL_DG = 0.0 - tau_v(i,J,k+1) + sqrt(tau_MAG*tau_MAG - tauNL_CG*tauNL_CG)
! back to x,y coordinate
tauNL_X = (tauNL_DG * cos_tmp - tauNL_CG * sin_tmp)
tauNL_Y = (tauNL_DG * sin_tmp + tauNL_CG * cos_tmp)
tauNLdn = tauNL_Y
!### The following expression is dimensionally inconsistent, [L T-1] vs. [L2 H-1 T-1] on the right,
! and it is inconsistent with the counterpart expression for du.
dv = (tauNLup - tauNLdn) * (dt/(CS%h_v(i,J,k)) )
vi(i,J,k) = vold(i,J,k) + dv
vold(i,J,k) = dv
tauNLup = tauNLdn
! diagnostics
Omega_tau2s_v(i,J,k+1) = atan2(tauNL_CG, tau_v(i,J,k+1) + tauNL_DG)
tau_v(i,J,k+1) = sqrt(((tauxDG_v(i,J,k+1) + tauNL_X)**2) + ((tauyDG_v(i,J,k+1) + tauNL_Y)**2))
!omega_tau2x = atan2((tauyDG_v(i,J,k+1) + tauNL_Y) , (tauxDG_v(i,J,k+1) + tauNL_X))
!omega_tau2w = omega_tau2x - omega_w2x_v(i,J)
if (omega_tau2w > pi) omega_tau2w = omega_tau2w - 2.*pi
if (omega_tau2w .le. (0.-pi) ) omega_tau2w = omega_tau2w + 2.*pi
Omega_tau2w_v(i,J,k+1) = omega_tau2w
enddo
do k= kbld+1, nz
vi(i,J,k) = vold(i,J,k)
vold(i,J,k) = 0.0
enddo
endif
enddo
enddo
if (CS%debug) then
call uvchksum("FP-tau_[uv] ", tau_u, tau_v, G%HI, haloshift=0, scalar_pair=.true.)
endif
if (CS%id_tauFP_u > 0) call post_data(CS%id_tauFP_u, tau_u, CS%diag)
if (CS%id_tauFP_v > 0) call post_data(CS%id_tauFP_v, tau_v, CS%diag)
if (CS%id_FPtau2s_u > 0) call post_data(CS%id_FPtau2s_u, omega_tau2s_u, CS%diag)
if (CS%id_FPtau2s_v > 0) call post_data(CS%id_FPtau2s_v, omega_tau2s_v, CS%diag)
if (CS%id_FPtau2w_u > 0) call post_data(CS%id_FPtau2w_u, omega_tau2w_u, CS%diag)
if (CS%id_FPtau2w_v > 0) call post_data(CS%id_FPtau2w_v, omega_tau2w_v, CS%diag)
!if (CS%id_FPw2x > 0) call post_data(CS%id_FPw2x, forces%omega_w2x , CS%diag)
end subroutine vertFPmix
!> Returns the empirical shape-function given sigma [nondim]
real function G_sig(sigma)
real , intent(in) :: sigma !< Normalized boundary layer depth [nondim]
! local variables
real :: p1, c2, c3 !< Parameters used to fit and match empirical shape-functions [nondim]
! parabola
p1 = 0.287
! cubic function
c2 = 1.74392
c3 = 2.58538
G_sig = min( p1 * (1.-sigma)*(1.-sigma) , sigma * (1. + sigma * (c2*sigma - c3) ) )
end function G_sig
!> Compute coupling coefficient associated with vertical viscosity parameterization as in Greatbatch and Lamb
!! (1990), hereafter referred to as the GL90 vertical viscosity parameterization. This vertical viscosity scheme
!! redistributes momentum in the vertical, and is the equivalent of the Gent & McWilliams (1990) parameterization,
!! but in a TWA (thickness-weighted averaged) set of equations. The vertical viscosity coefficient nu is computed
!! from kappa_GM via thermal wind balance, and the following relation:
!! nu = kappa_GM * f^2 / N^2.
!! In the following subroutine kappa_GM is assumed either (a) constant or (b) horizontally varying. In both cases,
!! (a) and (b), one can additionally impose an EBT structure in the vertical for kappa_GM.
!! A third possible formulation of nu is depth-independent:
!! nu = f^2 * alpha
!! The latter formulation would be equivalent to a kappa_GM that varies as N^2 with depth.
!! The vertical viscosity del_z ( nu del_z u) is applied to the momentum equation with stress-free boundary
!! conditions at the top and bottom.
!!
!! In SSW mode, we have 1/N^2 = h/g'. The coupling coefficient is therefore equal to
!! a_cpl_gl90 = nu / h = kappa_GM * f^2 / g'
!! or
!! a_cpl_gl90 = nu / h = f^2 * alpha / h
subroutine find_coupling_coef_gl90(a_cpl_gl90, hvel, do_i, z_i, j, G, GV, CS, VarMix, work_on_u)
type(ocean_grid_type), intent(in) :: G !< Grid structure.
type(verticalGrid_type), intent(in) :: GV !< Vertical grid structure.
real, dimension(SZIB_(G),SZK_(GV)), intent(in) :: hvel !< Distance between interfaces
!! at velocity points [Z ~> m]
logical, dimension(SZIB_(G)), intent(in) :: do_i !< If true, determine coupling coefficient
!! for a column
real, dimension(SZIB_(G),SZK_(GV)+1), intent(in) :: z_i !< Estimate of interface heights above the
!! bottom, normalized by the GL90 bottom
!! boundary layer thickness [nondim]
real, dimension(SZIB_(G),SZK_(GV)+1), intent(inout) :: a_cpl_gl90 !< Coupling coefficient associated
!! with GL90 across interfaces; is not
!! included in a_cpl [H T-1 ~> m s-1 or Pa s m-1].
integer, intent(in) :: j !< j-index to find coupling coefficient for
type(vertvisc_cs), pointer :: CS !< Vertical viscosity control structure
type(VarMix_CS), intent(in) :: VarMix !< Variable mixing coefficients
logical, intent(in) :: work_on_u !< If true, u-points are being calculated,
!! otherwise they are v-points.
! local variables
logical :: kdgl90_use_vert_struct ! use vertical structure for GL90 coefficient
integer :: i, k, is, ie, nz, Isq, Ieq
real :: f2 !< Squared Coriolis parameter at a velocity grid point [T-2 ~> s-2].
real :: h_neglect ! A vertical distance that is so small it is usually lost in roundoff error
! and can be neglected [Z ~> m].
real :: botfn ! A function that is 1 at the bottom and small far from it [nondim]
real :: z2 ! The distance from the bottom, normalized by Hbbl_gl90 [nondim]
is = G%isc ; ie = G%iec
Isq = G%IscB ; Ieq = G%IecB
nz = GV%ke
h_neglect = GV%dZ_subroundoff
kdgl90_use_vert_struct = .false.
if (VarMix%use_variable_mixing) then
kdgl90_use_vert_struct = allocated(VarMix%kdgl90_struct)
endif
if (work_on_u) then
! compute coupling coefficient at u-points
do I=Isq,Ieq; if (do_i(I)) then
f2 = 0.25 * (G%CoriolisBu(I,J-1) + G%CoriolisBu(I,J))**2
do K=2,nz
if (CS%use_GL90_N2) then
a_cpl_gl90(I,K) = 2.0 * f2 * CS%alpha_gl90 / (hvel(I,k) + hvel(I,k-1) + h_neglect)
else
if (CS%read_kappa_gl90) then
a_cpl_gl90(I,K) = f2 * 0.5 * (CS%kappa_gl90_2d(i,j) + CS%kappa_gl90_2d(i+1,j)) / GV%g_prime(K)
else
a_cpl_gl90(I,K) = f2 * CS%kappa_gl90 / GV%g_prime(K)
endif
if (kdgl90_use_vert_struct) then
a_cpl_gl90(I,K) = a_cpl_gl90(I,K) * 0.5 * &
( VarMix%kdgl90_struct(i,j,k-1) + VarMix%kdgl90_struct(i+1,j,k-1) )
endif
endif
! botfn determines when a point is within the influence of the GL90 bottom boundary layer,
! going from 1 at the bottom to 0 in the interior.
z2 = z_i(I,k)
botfn = 1.0 / (1.0 + 0.09*z2*z2*z2*z2*z2*z2)
a_cpl_gl90(I,K) = a_cpl_gl90(I,K) * (1 - botfn)
enddo
endif; enddo
else
! compute viscosities at v-points
do i=is,ie; if (do_i(i)) then
f2 = 0.25 * (G%CoriolisBu(I-1,J) + G%CoriolisBu(I,J))**2
do K=2,nz
if (CS%use_GL90_N2) then
a_cpl_gl90(i,K) = 2.0 * f2 * CS%alpha_gl90 / (hvel(i,k) + hvel(i,k-1) + h_neglect)
else
if (CS%read_kappa_gl90) then
a_cpl_gl90(i,K) = f2 * 0.5 * (CS%kappa_gl90_2d(i,j) + CS%kappa_gl90_2d(i,j+1)) / GV%g_prime(K)
else
a_cpl_gl90(i,K) = f2 * CS%kappa_gl90 / GV%g_prime(K)
endif
if (kdgl90_use_vert_struct) then
a_cpl_gl90(i,K) = a_cpl_gl90(i,K) * 0.5 * &
( VarMix%kdgl90_struct(i,j,k-1) + VarMix%kdgl90_struct(i,j+1,k-1) )
endif
endif
! botfn determines when a point is within the influence of the GL90 bottom boundary layer,
! going from 1 at the bottom to 0 in the interior.
z2 = z_i(i,k)
botfn = 1.0 / (1.0 + 0.09*z2*z2*z2*z2*z2*z2)
a_cpl_gl90(i,K) = a_cpl_gl90(i,K) * (1 - botfn)
enddo
endif; enddo
endif
end subroutine find_coupling_coef_gl90
!> Perform a fully implicit vertical diffusion
!! of momentum. Stress top and bottom boundary conditions are used.
!!
!! This is solving the tridiagonal system
!! \f[ \left(h_k + a_{k + 1/2} + a_{k - 1/2} + r_k\right) u_k^{n+1}
!! = h_k u_k^n + a_{k + 1/2} u_{k+1}^{n+1} + a_{k - 1/2} u_{k-1}^{n+1} \f]
!! where \f$a_{k + 1/2} = \Delta t \nu_{k + 1/2} / h_{k + 1/2}\f$
!! is the <em>interfacial coupling thickness per time step</em>,
!! encompassing background viscosity as well as contributions from
!! enhanced mixed and bottom layer viscosities.
!! $r_k$ is a Rayleigh drag term due to channel drag.
!! There is an additional stress term on the right-hand side
!! if DIRECT_STRESS is true, applied to the surface layer.
subroutine vertvisc(u, v, h, forces, visc, dt, OBC, ADp, CDp, G, GV, US, CS, &
taux_bot, tauy_bot, Waves)
type(ocean_grid_type), intent(in) :: G !< Ocean grid structure
type(verticalGrid_type), intent(in) :: GV !< Ocean vertical grid structure
type(unit_scale_type), intent(in) :: US !< A dimensional unit scaling type
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)), &
intent(inout) :: u !< Zonal velocity [L T-1 ~> m s-1]
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)), &
intent(inout) :: v !< Meridional velocity [L T-1 ~> m s-1]
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)), &
intent(in) :: h !< Layer thickness [H ~> m or kg m-2]
type(mech_forcing), intent(in) :: forces !< A structure with the driving mechanical forces
type(vertvisc_type), intent(inout) :: visc !< Viscosities and bottom drag
real, intent(in) :: dt !< Time increment [T ~> s]
type(ocean_OBC_type), pointer :: OBC !< Open boundary condition structure
type(accel_diag_ptrs), intent(inout) :: ADp !< Accelerations in the momentum
!! equations for diagnostics
type(cont_diag_ptrs), intent(inout) :: CDp !< Continuity equation terms
type(vertvisc_CS), pointer :: CS !< Vertical viscosity control structure
real, dimension(SZIB_(G),SZJ_(G)), &
optional, intent(out) :: taux_bot !< Zonal bottom stress from ocean to
!! rock [R L Z T-2 ~> Pa]
real, dimension(SZI_(G),SZJB_(G)), &
optional, intent(out) :: tauy_bot !< Meridional bottom stress from ocean to
!! rock [R L Z T-2 ~> Pa]
type(wave_parameters_CS), &
optional, pointer :: Waves !< Container for wave/Stokes information
! Fields from forces used in this subroutine:
! taux: Zonal wind stress [R L Z T-2 ~> Pa].
! tauy: Meridional wind stress [R L Z T-2 ~> Pa].
! Local variables
real :: b1(SZIB_(G)) ! A variable used by the tridiagonal solver [H-1 ~> m-1 or m2 kg-1].
real :: c1(SZIB_(G),SZK_(GV)) ! A variable used by the tridiagonal solver [nondim].
real :: d1(SZIB_(G)) ! d1=1-c1 is used by the tridiagonal solver [nondim].
real :: Ray(SZIB_(G),SZK_(GV)) ! Ray is the Rayleigh-drag velocity [H T-1 ~> m s-1 or Pa s m-1]
real :: b_denom_1 ! The first term in the denominator of b1 [H ~> m or kg m-2].
real :: Hmix ! The mixed layer thickness over which stress
! is applied with direct_stress [H ~> m or kg m-2].
real :: I_Hmix ! The inverse of Hmix [H-1 ~> m-1 or m2 kg-1].
real :: Idt ! The inverse of the time step [T-1 ~> s-1].
real :: dt_Rho0 ! The time step divided by the mean density [T H Z-1 R-1 ~> s m3 kg-1 or s].
real :: h_neglect ! A thickness that is so small it is usually lost
! in roundoff and can be neglected [H ~> m or kg m-2].
real :: stress ! The surface stress times the time step, divided
! by the density [H L T-1 ~> m2 s-1 or kg m-1 s-1].
real :: accel_underflow ! An acceleration magnitude that is so small that values that are less
! than this are diagnosed as 0 [L T-2 ~> m s-2].
real :: zDS, h_a ! Temporary thickness variables used with direct_stress [H ~> m or kg m-2]
real :: hfr ! Temporary ratio of thicknesses used with direct_stress [nondim]
real :: surface_stress(SZIB_(G))! The same as stress, unless the wind stress
! stress is applied as a body force [H L T-1 ~> m2 s-1 or kg m-1 s-1].
real, allocatable, dimension(:,:,:) :: KE_term ! A term in the kinetic energy budget
! [H L2 T-3 ~> m3 s-3 or W m-2]
real, allocatable, dimension(:,:,:) :: KE_u ! The area integral of a KE term in a layer at u-points
! [H L4 T-3 ~> m5 s-3 or kg m2 s-3]
real, allocatable, dimension(:,:,:) :: KE_v ! The area integral of a KE term in a layer at v-points
! [H L4 T-3 ~> m5 s-3 or kg m2 s-3]
logical :: do_i(SZIB_(G))
logical :: DoStokesMixing
integer :: i, j, k, is, ie, js, je, Isq, Ieq, Jsq, Jeq, nz, n
is = G%isc ; ie = G%iec; js = G%jsc; je = G%jec
Isq = G%IscB ; Ieq = G%IecB ; Jsq = G%JscB ; Jeq = G%JecB ; nz = GV%ke
if (.not.associated(CS)) call MOM_error(FATAL,"MOM_vert_friction(visc): "// &
"Module must be initialized before it is used.")
if (.not.CS%initialized) call MOM_error(FATAL,"MOM_vert_friction(visc): "// &
"Module must be initialized before it is used.")
if (CS%id_GLwork > 0) then
allocate(KE_u(G%IsdB:G%IedB,G%jsd:G%jed,GV%ke), source=0.0)
allocate(KE_v(G%isd:G%ied,G%JsdB:G%JedB,GV%ke), source=0.0)
allocate(KE_term(G%isd:G%ied,G%jsd:G%jed,GV%ke), source=0.0)
if (.not.G%symmetric) &
call create_group_pass(CS%pass_KE_uv, KE_u, KE_v, G%Domain, To_North+To_East)
endif
if (CS%direct_stress) then
Hmix = CS%Hmix_stress
I_Hmix = 1.0 / Hmix
endif
dt_Rho0 = dt / GV%H_to_RZ
h_neglect = GV%H_subroundoff
Idt = 1.0 / dt
accel_underflow = CS%vel_underflow * Idt
!Check if Stokes mixing allowed if requested (present and associated)
DoStokesMixing=.false.
if (CS%StokesMixing) then
if (present(Waves)) DoStokesMixing = associated(Waves)
if (.not. DoStokesMixing) &
call MOM_error(FATAL,"Stokes Mixing called without allocated"//&
"Waves Control Structure")
endif
do k=1,nz ; do i=Isq,Ieq ; Ray(i,k) = 0.0 ; enddo ; enddo
! Update the zonal velocity component using a modification of a standard
! tridagonal solver.
!$OMP parallel do default(shared) firstprivate(Ray) &
!$OMP private(do_i,surface_stress,zDS,stress,h_a,hfr, &
!$OMP b_denom_1,b1,d1,c1)
do j=G%jsc,G%jec
do I=Isq,Ieq ; do_i(I) = (G%mask2dCu(I,j) > 0.0) ; enddo
! When mixing down Eulerian current + Stokes drift add before calling solver
if (DoStokesMixing) then ; do k=1,nz ; do I=Isq,Ieq
if (do_i(I)) u(I,j,k) = u(I,j,k) + Waves%Us_x(I,j,k)
enddo ; enddo ; endif
if (associated(ADp%du_dt_visc)) then ; do k=1,nz ; do I=Isq,Ieq
ADp%du_dt_visc(I,j,k) = u(I,j,k)
enddo ; enddo ; endif
if (associated(ADp%du_dt_visc_gl90)) then ; do k=1,nz ; do I=Isq,Ieq
ADp%du_dt_visc_gl90(I,j,k) = u(I,j,k)
enddo ; enddo ; endif
if (associated(ADp%du_dt_str)) then ; do k=1,nz ; do I=Isq,Ieq
ADp%du_dt_str(I,j,k) = 0.0
enddo ; enddo ; endif
! One option is to have the wind stress applied as a body force
! over the topmost Hmix fluid. If DIRECT_STRESS is not defined,
! the wind stress is applied as a stress boundary condition.
if (CS%direct_stress) then
do I=Isq,Ieq ; if (do_i(I)) then
surface_stress(I) = 0.0
zDS = 0.0
stress = dt_Rho0 * forces%taux(I,j)
do k=1,nz
h_a = 0.5 * (h(i,j,k) + h(i+1,j,k)) + h_neglect
hfr = 1.0 ; if ((zDS+h_a) > Hmix) hfr = (Hmix - zDS) / h_a
u(I,j,k) = u(I,j,k) + I_Hmix * hfr * stress
if (associated(ADp%du_dt_str)) ADp%du_dt_str(i,J,k) = (I_Hmix * hfr * stress) * Idt
zDS = zDS + h_a ; if (zDS >= Hmix) exit
enddo
endif ; enddo ! end of i loop
else ; do I=Isq,Ieq
surface_stress(I) = dt_Rho0 * (G%mask2dCu(I,j)*forces%taux(I,j))
enddo ; endif ! direct_stress
if (allocated(visc%Ray_u)) then ; do k=1,nz ; do I=Isq,Ieq
Ray(I,k) = visc%Ray_u(I,j,k)
enddo ; enddo ; endif
! perform forward elimination on the tridiagonal system
!
! denote the diagonal of the system as b_k, the subdiagonal as a_k
! and the superdiagonal as c_k. The right-hand side terms are d_k.
!
! ignoring the Rayleigh drag contribution,
! we have a_k = -dt * a_u(k)
! b_k = h_u(k) + dt * (a_u(k) + a_u(k+1))
! c_k = -dt * a_u(k+1)
!
! for forward elimination, we want to:
! calculate c'_k = - c_k / (b_k + a_k c'_(k-1))
! and d'_k = (d_k - a_k d'_(k-1)) / (b_k + a_k c'_(k-1))
! where c'_1 = c_1/b_1 and d'_1 = d_1/b_1
!
! This form is mathematically equivalent to Thomas' tridiagonal matrix algorithm, but it
! does not suffer from the acute sensitivity to truncation errors of the Thomas algorithm
! because it involves no subtraction, as discussed by Schopf & Loughe, MWR, 1995.
!
! b1 is the denominator term 1 / (b_k + a_k c'_(k-1))
! b_denom_1 is (b_k + a_k + c_k) - a_k(1 - c'_(k-1))
! = (b_k + c_k + c'_(k-1))
! this is done so that d1 = b1 * b_denom_1 = 1 - c'_(k-1)
! c1(k) is -c'_(k - 1)
! and the right-hand-side is destructively updated to be d'_k
!
do I=Isq,Ieq ; if (do_i(I)) then
b_denom_1 = CS%h_u(I,j,1) + dt * (Ray(I,1) + CS%a_u(I,j,1))
b1(I) = 1.0 / (b_denom_1 + dt*CS%a_u(I,j,2))
d1(I) = b_denom_1 * b1(I)
u(I,j,1) = b1(I) * (CS%h_u(I,j,1) * u(I,j,1) + surface_stress(I))
if (associated(ADp%du_dt_str)) &
ADp%du_dt_str(I,j,1) = b1(I) * (CS%h_u(I,j,1) * ADp%du_dt_str(I,j,1) + surface_stress(I)*Idt)
endif ; enddo
do k=2,nz ; do I=Isq,Ieq ; if (do_i(I)) then
c1(I,k) = dt * CS%a_u(I,j,K) * b1(I)
b_denom_1 = CS%h_u(I,j,k) + dt * (Ray(I,k) + CS%a_u(I,j,K)*d1(I))
b1(I) = 1.0 / (b_denom_1 + dt * CS%a_u(I,j,K+1))
d1(I) = b_denom_1 * b1(I)
u(I,j,k) = (CS%h_u(I,j,k) * u(I,j,k) + &
dt * CS%a_u(I,j,K) * u(I,j,k-1)) * b1(I)
if (associated(ADp%du_dt_str)) &
ADp%du_dt_str(I,j,k) = (CS%h_u(I,j,k) * ADp%du_dt_str(I,j,k) + &
dt * CS%a_u(I,j,K) * ADp%du_dt_str(I,j,k-1)) * b1(I)
endif ; enddo ; enddo
! back substitute to solve for the new velocities
! u_k = d'_k - c'_k x_(k+1)
do k=nz-1,1,-1 ; do I=Isq,Ieq ; if (do_i(I)) then
u(I,j,k) = u(I,j,k) + c1(I,k+1) * u(I,j,k+1)
endif ; enddo ; enddo ! i and k loops
if (associated(ADp%du_dt_str)) then
do i=is,ie ; if (abs(ADp%du_dt_str(I,j,nz)) < accel_underflow) ADp%du_dt_str(I,j,nz) = 0.0 ; enddo
do k=nz-1,1,-1 ; do I=Isq,Ieq ; if (do_i(I)) then
ADp%du_dt_str(I,j,k) = ADp%du_dt_str(I,j,k) + c1(I,k+1) * ADp%du_dt_str(I,j,k+1)
if (abs(ADp%du_dt_str(I,j,k)) < accel_underflow) ADp%du_dt_str(I,j,k) = 0.0
endif ; enddo ; enddo
endif
! compute vertical velocity tendency that arises from GL90 viscosity;
! follow tridiagonal solve method as above; to avoid corrupting u,
! use ADp%du_dt_visc_gl90 as a placeholder for updated u (due to GL90) until last do loop
if ((CS%id_du_dt_visc_gl90 > 0) .or. (CS%id_GLwork > 0)) then
if (associated(ADp%du_dt_visc_gl90)) then
do I=Isq,Ieq ; if (do_i(I)) then
b_denom_1 = CS%h_u(I,j,1) ! CS%a_u_gl90(I,j,1) is zero
b1(I) = 1.0 / (b_denom_1 + dt*CS%a_u_gl90(I,j,2))
d1(I) = b_denom_1 * b1(I)
ADp%du_dt_visc_gl90(I,j,1) = b1(I) * (CS%h_u(I,j,1) * ADp%du_dt_visc_gl90(I,j,1))
endif ; enddo
do k=2,nz ; do I=Isq,Ieq ; if (do_i(I)) then
c1(I,k) = dt * CS%a_u_gl90(I,j,K) * b1(I)
b_denom_1 = CS%h_u(I,j,k) + dt * (CS%a_u_gl90(I,j,K)*d1(I))
b1(I) = 1.0 / (b_denom_1 + dt * CS%a_u_gl90(I,j,K+1))
d1(I) = b_denom_1 * b1(I)
ADp%du_dt_visc_gl90(I,j,k) = (CS%h_u(I,j,k) * ADp%du_dt_visc_gl90(I,j,k) + &
dt * CS%a_u_gl90(I,j,K) * ADp%du_dt_visc_gl90(I,j,k-1)) * b1(I)
endif ; enddo ; enddo
! back substitute to solve for new velocities, held by ADp%du_dt_visc_gl90
do k=nz-1,1,-1 ; do I=Isq,Ieq ; if (do_i(I)) then
ADp%du_dt_visc_gl90(I,j,k) = ADp%du_dt_visc_gl90(I,j,k) + c1(I,k+1) * ADp%du_dt_visc_gl90(I,j,k+1)
endif ; enddo ; enddo ! i and k loops
do k=1,nz ; do I=Isq,Ieq ; if (do_i(I)) then
! now fill ADp%du_dt_visc_gl90(I,j,k) with actual velocity tendency due to GL90;
! note that on RHS: ADp%du_dt_visc(I,j,k) holds the original velocity value u(I,j,k)
! and ADp%du_dt_visc_gl90(I,j,k) the updated velocity due to GL90
ADp%du_dt_visc_gl90(I,j,k) = (ADp%du_dt_visc_gl90(I,j,k) - ADp%du_dt_visc(I,j,k))*Idt
if (abs(ADp%du_dt_visc_gl90(I,j,k)) < accel_underflow) ADp%du_dt_visc_gl90(I,j,k) = 0.0
endif ; enddo ; enddo ;
! to compute energetics, we need to multiply by u*h, where u is original velocity before
! velocity update; note that ADp%du_dt_visc(I,j,k) holds the original velocity value u(I,j,k)
if (CS%id_GLwork > 0) then
do k=1,nz; do I=Isq,Ieq ; if (do_i(I)) then
KE_u(I,j,k) = ADp%du_dt_visc(I,j,k) * CS%h_u(I,j,k) * G%areaCu(I,j) * ADp%du_dt_visc_gl90(I,j,k)
endif ; enddo ; enddo
endif
endif
endif
if (associated(ADp%du_dt_visc)) then ; do k=1,nz ; do I=Isq,Ieq
ADp%du_dt_visc(I,j,k) = (u(I,j,k) - ADp%du_dt_visc(I,j,k))*Idt
if (abs(ADp%du_dt_visc(I,j,k)) < accel_underflow) ADp%du_dt_visc(I,j,k) = 0.0
enddo ; enddo ; endif
if (allocated(visc%taux_shelf)) then ; do I=Isq,Ieq
visc%taux_shelf(I,j) = -GV%H_to_RZ*CS%a1_shelf_u(I,j)*u(I,j,1) ! - u_shelf?
enddo ; endif
if (PRESENT(taux_bot)) then
do I=Isq,Ieq
taux_bot(I,j) = GV%H_to_RZ * (u(I,j,nz)*CS%a_u(I,j,nz+1))
enddo
if (allocated(visc%Ray_u)) then ; do k=1,nz ; do I=Isq,Ieq
taux_bot(I,j) = taux_bot(I,j) + GV%H_to_RZ * (Ray(I,k)*u(I,j,k))
enddo ; enddo ; endif
endif
! When mixing down Eulerian current + Stokes drift subtract after calling solver
if (DoStokesMixing) then ; do k=1,nz ; do I=Isq,Ieq
if (do_i(I)) u(I,j,k) = u(I,j,k) - Waves%Us_x(I,j,k)
enddo ; enddo ; endif
enddo ! end u-component j loop
! Now work on the meridional velocity component.
!$OMP parallel do default(shared) firstprivate(Ray) &
!$OMP private(do_i,surface_stress,zDS,stress,h_a,hfr, &
!$OMP b_denom_1,b1,d1,c1)
do J=Jsq,Jeq
do i=is,ie ; do_i(i) = (G%mask2dCv(i,J) > 0.0) ; enddo
! When mixing down Eulerian current + Stokes drift add before calling solver
if (DoStokesMixing) then ; do k=1,nz ; do i=is,ie
if (do_i(i)) v(i,j,k) = v(i,j,k) + Waves%Us_y(i,j,k)
enddo ; enddo ; endif
if (associated(ADp%dv_dt_visc)) then ; do k=1,nz ; do i=is,ie
ADp%dv_dt_visc(i,J,k) = v(i,J,k)
enddo ; enddo ; endif
if (associated(ADp%dv_dt_visc_gl90)) then ; do k=1,nz ; do i=is,ie
ADp%dv_dt_visc_gl90(i,J,k) = v(i,J,k)