forked from mom-ocean/MOM6
-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathMOM_continuity_PPM.F90
2809 lines (2543 loc) · 151 KB
/
MOM_continuity_PPM.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
!> Solve the layer continuity equation using the PPM method for layer fluxes.
module MOM_continuity_PPM
! This file is part of MOM6. See LICENSE.md for the license.
use MOM_cpu_clock, only : cpu_clock_id, cpu_clock_begin, cpu_clock_end, CLOCK_ROUTINE
use MOM_diag_mediator, only : time_type, diag_ctrl
use MOM_error_handler, only : MOM_error, FATAL, WARNING, is_root_pe
use MOM_file_parser, only : get_param, log_version, param_file_type
use MOM_grid, only : ocean_grid_type
use MOM_open_boundary, only : ocean_OBC_type, OBC_segment_type, OBC_NONE
use MOM_open_boundary, only : OBC_DIRECTION_E, OBC_DIRECTION_W, OBC_DIRECTION_N, OBC_DIRECTION_S
use MOM_unit_scaling, only : unit_scale_type
use MOM_variables, only : BT_cont_type, porous_barrier_type
use MOM_verticalGrid, only : verticalGrid_type
implicit none ; private
#include <MOM_memory.h>
public continuity_PPM, continuity_PPM_init, continuity_PPM_stencil
public continuity_fluxes, continuity_adjust_vel
public zonal_mass_flux, meridional_mass_flux
public zonal_edge_thickness, meridional_edge_thickness
public continuity_zonal_convergence, continuity_merdional_convergence
public zonal_flux_thickness, meridional_flux_thickness
public zonal_BT_mass_flux, meridional_BT_mass_flux
public set_continuity_loop_bounds
!>@{ CPU time clock IDs
integer :: id_clock_reconstruct, id_clock_update, id_clock_correct
!>@}
!> Control structure for mom_continuity_ppm
type, public :: continuity_PPM_CS ; private
logical :: initialized = .false. !< True if this control structure has been initialized.
type(diag_ctrl), pointer :: diag !< Diagnostics control structure.
logical :: upwind_1st !< If true, use a first-order upwind scheme.
logical :: monotonic !< If true, use the Colella & Woodward monotonic
!! limiter; otherwise use a simple positive
!! definite limiter.
logical :: simple_2nd !< If true, use a simple second order (arithmetic
!! mean) interpolation of the edge values instead
!! of the higher order interpolation.
real :: tol_eta !< The tolerance for free-surface height
!! discrepancies between the barotropic solution and
!! the sum of the layer thicknesses [H ~> m or kg m-2].
real :: tol_vel !< The tolerance for barotropic velocity
!! discrepancies between the barotropic solution and
!! the sum of the layer thicknesses [L T-1 ~> m s-1].
real :: CFL_limit_adjust !< The maximum CFL of the adjusted velocities [nondim]
logical :: aggress_adjust !< If true, allow the adjusted velocities to have a
!! relative CFL change up to 0.5. False by default.
logical :: vol_CFL !< If true, use the ratio of the open face lengths
!! to the tracer cell areas when estimating CFL
!! numbers. Without aggress_adjust, the default is
!! false; it is always true with.
logical :: better_iter !< If true, stop corrective iterations using a
!! velocity-based criterion and only stop if the
!! iteration is better than all predecessors.
logical :: use_visc_rem_max !< If true, use more appropriate limiting bounds
!! for corrections in strongly viscous columns.
logical :: marginal_faces !< If true, use the marginal face areas from the
!! continuity solver for use as the weights in the
!! barotropic solver. Otherwise use the transport
!! averaged areas.
end type continuity_PPM_CS
!> A container for loop bounds
type, public :: cont_loop_bounds_type ; private
!>@{ Loop bounds
integer :: ish, ieh, jsh, jeh
!>@}
end type cont_loop_bounds_type
!> Finds the thickness fluxes from the continuity solver or their vertical sum without
!! actually updating the layer thicknesses.
interface continuity_fluxes
module procedure continuity_3d_fluxes, continuity_2d_fluxes
end interface continuity_fluxes
contains
!> Time steps the layer thicknesses, using a monotonically limit, directionally split PPM scheme,
!! based on Lin (1994).
subroutine continuity_PPM(u, v, hin, h, uh, vh, dt, G, GV, US, CS, OBC, pbv, uhbt, vhbt, &
visc_rem_u, visc_rem_v, u_cor, v_cor, BT_cont, du_cor, dv_cor)
type(ocean_grid_type), intent(in) :: G !< The ocean's grid structure.
type(verticalGrid_type), intent(in) :: GV !< Vertical grid structure.
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)), &
intent(in) :: u !< Zonal velocity [L T-1 ~> m s-1].
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)), &
intent(in) :: v !< Meridional velocity [L T-1 ~> m s-1].
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)), &
intent(in) :: hin !< Initial layer thickness [H ~> m or kg m-2].
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)), &
intent(inout) :: h !< Final layer thickness [H ~> m or kg m-2].
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)), &
intent(out) :: uh !< Zonal volume flux, u*h*dy [H L2 T-1 ~> m3 s-1 or kg s-1].
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)), &
intent(out) :: vh !< Meridional volume flux, v*h*dx [H L2 T-1 ~> m3 s-1 or kg s-1].
real, intent(in) :: dt !< Time increment [T ~> s].
type(unit_scale_type), intent(in) :: US !< A dimensional unit scaling type
type(continuity_PPM_CS), intent(in) :: CS !< Module's control structure.
type(ocean_OBC_type), pointer :: OBC !< Open boundaries control structure.
type(porous_barrier_type), intent(in) :: pbv !< pointers to porous barrier fractional cell metrics
real, dimension(SZIB_(G),SZJ_(G)), &
optional, intent(in) :: uhbt !< The summed volume flux through zonal faces
!! [H L2 T-1 ~> m3 s-1 or kg s-1].
real, dimension(SZI_(G),SZJB_(G)), &
optional, intent(in) :: vhbt !< The summed volume flux through meridional faces
!! [H L2 T-1 ~> m3 s-1 or kg s-1].
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)), &
optional, intent(in) :: visc_rem_u
!< The fraction of zonal momentum originally
!! in a layer that remains after a time-step of viscosity, and the
!! fraction of a time-step's worth of a barotropic acceleration that
!! a layer experiences after viscosity is applied [nondim].
!! Visc_rem_u is between 0 (at the bottom) and 1 (far above the bottom).
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)), &
optional, intent(in) :: visc_rem_v
!< The fraction of meridional momentum originally
!! in a layer that remains after a time-step of viscosity, and the
!! fraction of a time-step's worth of a barotropic acceleration that
!! a layer experiences after viscosity is applied [nondim].
!! Visc_rem_v is between 0 (at the bottom) and 1 (far above the bottom).
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)), &
optional, intent(out) :: u_cor
!< The zonal velocities that give uhbt as the depth-integrated transport [L T-1 ~> m s-1].
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)), &
optional, intent(out) :: v_cor
!< The meridional velocities that give vhbt as the depth-integrated
!! transport [L T-1 ~> m s-1].
type(BT_cont_type), optional, pointer :: BT_cont !< A structure with elements that describe
!! the effective open face areas as a function of barotropic flow.
real, dimension(SZIB_(G),SZJ_(G)), &
optional, intent(out) :: du_cor !< The zonal velocity increments from u that give uhbt
!! as the depth-integrated transports [L T-1 ~> m s-1].
real, dimension(SZI_(G),SZJB_(G)), &
optional, intent(out) :: dv_cor !< The meridional velocity increments from v that give vhbt
!! as the depth-integrated transports [L T-1 ~> m s-1].
! Local variables
real :: h_W(SZI_(G),SZJ_(G),SZK_(GV)) ! West edge thicknesses in the zonal PPM reconstruction [H ~> m or kg m-2]
real :: h_E(SZI_(G),SZJ_(G),SZK_(GV)) ! East edge thicknesses in the zonal PPM reconstruction [H ~> m or kg m-2]
real :: h_S(SZI_(G),SZJ_(G),SZK_(GV)) ! South edge thicknesses in the meridional PPM reconstruction [H ~> m or kg m-2]
real :: h_N(SZI_(G),SZJ_(G),SZK_(GV)) ! North edge thicknesses in the meridional PPM reconstruction [H ~> m or kg m-2]
real :: h_min ! The minimum layer thickness [H ~> m or kg m-2]. h_min could be 0.
type(cont_loop_bounds_type) :: LB ! A type indicating the loop range for a phase of the updates
logical :: x_first
h_min = GV%Angstrom_H
if (.not.CS%initialized) call MOM_error(FATAL, &
"MOM_continuity_PPM: Module must be initialized before it is used.")
x_first = (MOD(G%first_direction,2) == 0)
if (present(visc_rem_u) .neqv. present(visc_rem_v)) call MOM_error(FATAL, &
"MOM_continuity_PPM: Either both visc_rem_u and visc_rem_v or neither"// &
" one must be present in call to continuity_PPM.")
if (x_first) then
! First advect zonally, with loop bounds that accomodate the subsequent meridional advection.
LB = set_continuity_loop_bounds(G, CS, i_stencil=.false., j_stencil=.true.)
call zonal_edge_thickness(hin, h_W, h_E, G, GV, US, CS, OBC, LB)
call zonal_mass_flux(u, hin, h_W, h_E, uh, dt, G, GV, US, CS, OBC, pbv%por_face_areaU, &
LB, uhbt, visc_rem_u, u_cor, BT_cont, du_cor)
call continuity_zonal_convergence(h, uh, dt, G, GV, LB, hin)
! Now advect meridionally, using the updated thicknesses to determine the fluxes.
LB = set_continuity_loop_bounds(G, CS, i_stencil=.false., j_stencil=.false.)
call meridional_edge_thickness(h, h_S, h_N, G, GV, US, CS, OBC, LB)
call meridional_mass_flux(v, h, h_S, h_N, vh, dt, G, GV, US, CS, OBC, pbv%por_face_areaV, &
LB, vhbt, visc_rem_v, v_cor, BT_cont, dv_cor)
call continuity_merdional_convergence(h, vh, dt, G, GV, LB, hmin=h_min)
else ! .not. x_first
! First advect meridionally, with loop bounds that accomodate the subsequent zonal advection.
LB = set_continuity_loop_bounds(G, CS, i_stencil=.true., j_stencil=.false.)
call meridional_edge_thickness(hin, h_S, h_N, G, GV, US, CS, OBC, LB)
call meridional_mass_flux(v, hin, h_S, h_N, vh, dt, G, GV, US, CS, OBC, pbv%por_face_areaV, &
LB, vhbt, visc_rem_v, v_cor, BT_cont, dv_cor)
call continuity_merdional_convergence(h, vh, dt, G, GV, LB, hin)
! Now advect zonally, using the updated thicknesses to determine the fluxes.
LB = set_continuity_loop_bounds(G, CS, i_stencil=.false., j_stencil=.false.)
call zonal_edge_thickness(h, h_W, h_E, G, GV, US, CS, OBC, LB)
call zonal_mass_flux(u, h, h_W, h_E, uh, dt, G, GV, US, CS, OBC, pbv%por_face_areaU, &
LB, uhbt, visc_rem_u, u_cor, BT_cont, du_cor)
call continuity_zonal_convergence(h, uh, dt, G, GV, LB, hmin=h_min)
endif
end subroutine continuity_PPM
!> Finds the thickness fluxes from the continuity solver without actually updating the
!! layer thicknesses. Because the fluxes in the two directions are calculated based on the
!! input thicknesses, which are not updated between the direcitons, the fluxes returned here
!! are not the same as those that would be returned by a call to continuity.
subroutine continuity_3d_fluxes(u, v, h, uh, vh, dt, G, GV, US, CS, OBC, pbv)
type(ocean_grid_type), intent(inout) :: G !< Ocean grid structure.
type(verticalGrid_type), intent(in) :: GV !< Vertical grid structure.
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)), &
intent(in) :: u !< Zonal velocity [L T-1 ~> m s-1].
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)), &
intent(in) :: 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].
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)), &
intent(out) :: uh !< Thickness fluxes through zonal faces,
!! u*h*dy [H L2 T-1 ~> m3 s-1 or kg s-1].
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)), &
intent(out) :: vh !< Thickness fluxes through meridional faces,
!! v*h*dx [H L2 T-1 ~> m3 s-1 or kg s-1].
real, intent(in) :: dt !< Time increment [T ~> s].
type(unit_scale_type), intent(in) :: US !< A dimensional unit scaling type
type(continuity_PPM_CS), intent(in) :: CS !< Control structure for mom_continuity.
type(ocean_OBC_type), pointer :: OBC !< Open boundaries control structure.
type(porous_barrier_type), intent(in) :: pbv !< porous barrier fractional cell metrics
! Local variables
real :: h_W(SZI_(G),SZJ_(G),SZK_(GV)) ! West edge thicknesses in the zonal PPM reconstruction [H ~> m or kg m-2]
real :: h_E(SZI_(G),SZJ_(G),SZK_(GV)) ! East edge thicknesses in the zonal PPM reconstruction [H ~> m or kg m-2]
real :: h_S(SZI_(G),SZJ_(G),SZK_(GV)) ! South edge thicknesses in the meridional PPM reconstruction [H ~> m or kg m-2]
real :: h_N(SZI_(G),SZJ_(G),SZK_(GV)) ! North edge thicknesses in the meridional PPM reconstruction [H ~> m or kg m-2]
call zonal_edge_thickness(h, h_W, h_E, G, GV, US, CS, OBC)
call zonal_mass_flux(u, h, h_W, h_E, uh, dt, G, GV, US, CS, OBC, pbv%por_face_areaU)
call meridional_edge_thickness(h, h_S, h_N, G, GV, US, CS, OBC)
call meridional_mass_flux(v, h, h_S, h_N, vh, dt, G, GV, US, CS, OBC, pbv%por_face_areaV)
end subroutine continuity_3d_fluxes
!> Find the vertical sum of the thickness fluxes from the continuity solver without actually
!! updating the layer thicknesses. Because the fluxes in the two directions are calculated
!! based on the input thicknesses, which are not updated between the directions, the fluxes
!! returned here are not the same as those that would be returned by a call to continuity.
subroutine continuity_2d_fluxes(u, v, h, uhbt, vhbt, dt, G, GV, US, CS, OBC, pbv)
type(ocean_grid_type), intent(inout) :: G !< Ocean grid structure.
type(verticalGrid_type), intent(in) :: GV !< Vertical grid structure.
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)), &
intent(in) :: u !< Zonal velocity [L T-1 ~> m s-1].
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)), &
intent(in) :: 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].
real, dimension(SZIB_(G),SZJ_(G)), &
intent(out) :: uhbt !< Vertically summed thickness flux through
!! zonal faces [H L2 T-1 ~> m3 s-1 or kg s-1].
real, dimension(SZI_(G),SZJB_(G)), &
intent(out) :: vhbt !< Vertically summed thickness flux through
!! meridional faces [H L2 T-1 ~> m3 s-1 or kg s-1].
real, intent(in) :: dt !< Time increment [T ~> s].
type(unit_scale_type), intent(in) :: US !< A dimensional unit scaling type
type(continuity_PPM_CS), intent(in) :: CS !< Control structure for mom_continuity.
type(ocean_OBC_type), pointer :: OBC !< Open boundaries control structure.
type(porous_barrier_type), intent(in) :: pbv !< porous barrier fractional cell metrics
! Local variables
real :: h_W(SZI_(G),SZJ_(G),SZK_(GV)) ! West edge thicknesses in the zonal PPM reconstruction [H ~> m or kg m-2]
real :: h_E(SZI_(G),SZJ_(G),SZK_(GV)) ! East edge thicknesses in the zonal PPM reconstruction [H ~> m or kg m-2]
real :: h_S(SZI_(G),SZJ_(G),SZK_(GV)) ! South edge thicknesses in the meridional PPM reconstruction [H ~> m or kg m-2]
real :: h_N(SZI_(G),SZJ_(G),SZK_(GV)) ! North edge thicknesses in the meridional PPM reconstruction [H ~> m or kg m-2]
call zonal_edge_thickness(h, h_W, h_E, G, GV, US, CS, OBC)
call zonal_BT_mass_flux(u, h, h_W, h_E, uhbt, dt, G, GV, US, CS, OBC, pbv%por_face_areaU)
call meridional_edge_thickness(h, h_S, h_N, G, GV, US, CS, OBC)
call meridional_BT_mass_flux(v, h, h_S, h_N, vhbt, dt, G, GV, US, CS, OBC, pbv%por_face_areaV)
end subroutine continuity_2d_fluxes
!> Correct the velocities to give the specified depth-integrated transports by applying a
!! barotropic acceleration (subject to viscous drag) to the velocities.
subroutine continuity_adjust_vel(u, v, h, dt, G, GV, US, CS, OBC, pbv, uhbt, vhbt, visc_rem_u, visc_rem_v)
type(ocean_grid_type), intent(inout) :: G !< Ocean grid structure.
type(verticalGrid_type), intent(in) :: GV !< Vertical grid structure.
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)), &
intent(inout) :: u !< Zonal velocity, which will be adjusted to
!! give uhbt as the depth-integrated
!! transport [L T-1 ~> m s-1].
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)), &
intent(inout) :: v !< Meridional velocity, which will be adjusted
!! to give vhbt as the depth-integrated
!! transport [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].
real, intent(in) :: dt !< Time increment [T ~> s].
type(unit_scale_type), intent(in) :: US !< A dimensional unit scaling type
type(continuity_PPM_CS), intent(in) :: CS !< Control structure for mom_continuity.
type(ocean_OBC_type), pointer :: OBC !< Open boundaries control structure.
type(porous_barrier_type), intent(in) :: pbv !< porous barrier fractional cell metrics
real, dimension(SZIB_(G),SZJ_(G)), &
intent(in) :: uhbt !< The vertically summed thickness flux through
!! zonal faces [H L2 T-1 ~> m3 s-1 or kg s-1].
real, dimension(SZI_(G),SZJB_(G)), &
intent(in) :: vhbt !< The vertically summed thickness flux through
!! meridional faces [H L2 T-1 ~> m3 s-1 or kg s-1].
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)), &
optional, intent(in) :: visc_rem_u !< Both the fraction of the zonal momentum
!! that remains after a time-step of viscosity, and
!! the fraction of a time-step's worth of a barotropic
!! acceleration that a layer experiences after viscosity
!! is applied [nondim]. This goes between 0 (at the
!! bottom) and 1 (far above the bottom). When this
!! column is under an ice shelf, this also goes to 0
!! at the top due to the no-slip boundary condition there.
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)), &
optional, intent(in) :: visc_rem_v !< Both the fraction of the meridional momentum
!! that remains after a time-step of viscosity, and
!! the fraction of a time-step's worth of a barotropic
!! acceleration that a layer experiences after viscosity
!! is applied [nondim]. This goes between 0 (at the
!! bottom) and 1 (far above the bottom). When this
!! column is under an ice shelf, this also goes to 0
!! at the top due to the no-slip boundary condition there.
! Local variables
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)) :: u_in !< Input zonal velocity [L T-1 ~> m s-1]
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)) :: v_in !< Input meridional velocity [L T-1 ~> m s-1]
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)) :: uh !< Volume flux through zonal faces =
!! u*h*dy [H L2 T-1 ~> m3 s-1 or kg s-1].
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)) :: vh !< Volume flux through meridional faces =
!! v*h*dx [H L2 T-1 ~> m3 s-1 or kg s-1].
real :: h_W(SZI_(G),SZJ_(G),SZK_(GV)) ! West edge thicknesses in the zonal PPM reconstruction [H ~> m or kg m-2]
real :: h_E(SZI_(G),SZJ_(G),SZK_(GV)) ! East edge thicknesses in the zonal PPM reconstruction [H ~> m or kg m-2]
real :: h_S(SZI_(G),SZJ_(G),SZK_(GV)) ! South edge thicknesses in the meridional PPM reconstruction [H ~> m or kg m-2]
real :: h_N(SZI_(G),SZJ_(G),SZK_(GV)) ! North edge thicknesses in the meridional PPM reconstruction [H ~> m or kg m-2]
! It might not be necessary to separate the input velocity array from the adjusted velocities,
! but it seems safer to do so, even if it might be less efficient.
u_in(:,:,:) = u(:,:,:)
v_in(:,:,:) = v(:,:,:)
call zonal_edge_thickness(h, h_W, h_E, G, GV, US, CS, OBC)
call zonal_mass_flux(u_in, h, h_W, h_E, uh, dt, G, GV, US, CS, OBC, pbv%por_face_areaU, &
uhbt=uhbt, visc_rem_u=visc_rem_u, u_cor=u)
call meridional_edge_thickness(h, h_S, h_N, G, GV, US, CS, OBC)
call meridional_mass_flux(v_in, h, h_S, h_N, vh, dt, G, GV, US, CS, OBC, pbv%por_face_areaV, &
vhbt=vhbt, visc_rem_v=visc_rem_v, v_cor=v)
end subroutine continuity_adjust_vel
!> Updates the thicknesses due to zonal thickness fluxes.
subroutine continuity_zonal_convergence(h, uh, dt, G, GV, LB, hin, hmin)
type(ocean_grid_type), intent(in) :: G !< Ocean's grid structure
type(verticalGrid_type), intent(in) :: GV !< Ocean's vertical grid structure
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)), &
intent(inout) :: h !< Final layer thickness [H ~> m or kg m-2]
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)), &
intent(in) :: uh !< Zonal thickness flux, u*h*dy [H L2 T-1 ~> m3 s-1 or kg s-1]
real, intent(in) :: dt !< Time increment [T ~> s]
type(cont_loop_bounds_type), intent(in) :: LB !< Loop bounds structure
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)), &
optional, intent(in) :: hin !< Initial layer thickness [H ~> m or kg m-2].
!! If hin is absent, h is also the initial thickness.
real, optional, intent(in) :: hmin !< The minimum layer thickness [H ~> m or kg m-2]
real :: h_min ! The minimum layer thickness [H ~> m or kg m-2]. h_min could be 0.
integer :: i, j, k
call cpu_clock_begin(id_clock_update)
h_min = 0.0 ; if (present(hmin)) h_min = hmin
if (present(hin)) then
!$OMP parallel do default(shared)
do k=1,GV%ke ; do j=LB%jsh,LB%jeh ; do i=LB%ish,LB%ieh
h(i,j,k) = max( hin(i,j,k) - dt * G%IareaT(i,j) * (uh(I,j,k) - uh(I-1,j,k)), h_min )
enddo ; enddo ; enddo
else
!$OMP parallel do default(shared)
do k=1,GV%ke ; do j=LB%jsh,LB%jeh ; do i=LB%ish,LB%ieh
h(i,j,k) = max( h(i,j,k) - dt * G%IareaT(i,j) * (uh(I,j,k) - uh(I-1,j,k)), h_min )
enddo ; enddo ; enddo
endif
call cpu_clock_end(id_clock_update)
end subroutine continuity_zonal_convergence
!> Updates the thicknesses due to meridional thickness fluxes.
subroutine continuity_merdional_convergence(h, vh, dt, G, GV, LB, hin, hmin)
type(ocean_grid_type), intent(in) :: G !< Ocean's grid structure
type(verticalGrid_type), intent(in) :: GV !< Ocean's vertical grid structure
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)), &
intent(inout) :: h !< Final layer thickness [H ~> m or kg m-2]
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)), &
intent(in) :: vh !< Meridional thickness flux, v*h*dx [H L2 T-1 ~> m3 s-1 or kg s-1]
real, intent(in) :: dt !< Time increment [T ~> s]
type(cont_loop_bounds_type), intent(in) :: LB !< Loop bounds structure
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)), &
optional, intent(in) :: hin !< Initial layer thickness [H ~> m or kg m-2].
!! If hin is absent, h is also the initial thickness.
real, optional, intent(in) :: hmin !< The minimum layer thickness [H ~> m or kg m-2]
real :: h_min ! The minimum layer thickness [H ~> m or kg m-2]. h_min could be 0.
integer :: i, j, k
call cpu_clock_begin(id_clock_update)
h_min = 0.0 ; if (present(hmin)) h_min = hmin
if (present(hin)) then
!$OMP parallel do default(shared)
do k=1,GV%ke ; do j=LB%jsh,LB%jeh ; do i=LB%ish,LB%ieh
h(i,j,k) = max( hin(i,j,k) - dt * G%IareaT(i,j) * (vh(i,J,k) - vh(i,J-1,k)), h_min )
enddo ; enddo ; enddo
else
!$OMP parallel do default(shared)
do k=1,GV%ke ; do j=LB%jsh,LB%jeh ; do i=LB%ish,LB%ieh
h(i,j,k) = max( h(i,j,k) - dt * G%IareaT(i,j) * (vh(i,J,k) - vh(i,J-1,k)), h_min )
enddo ; enddo ; enddo
endif
call cpu_clock_end(id_clock_update)
end subroutine continuity_merdional_convergence
!> Set the reconstructed thicknesses at the eastern and western edges of tracer cells.
subroutine zonal_edge_thickness(h_in, h_W, h_E, G, GV, US, CS, OBC, LB_in)
type(ocean_grid_type), intent(in) :: G !< Ocean's grid structure.
type(verticalGrid_type), intent(in) :: GV !< Ocean's vertical grid structure.
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)), &
intent(in) :: h_in !< Tracer cell layer thickness [H ~> m or kg m-2].
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)), &
intent(out) :: h_W !< Western edge layer thickness [H ~> m or kg m-2].
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)), &
intent(out) :: h_E !< Eastern edge layer thickness [H ~> m or kg m-2].
type(unit_scale_type), intent(in) :: US !< A dimensional unit scaling type
type(continuity_PPM_CS), intent(in) :: CS !< This module's control structure.
type(ocean_OBC_type), pointer :: OBC !< Open boundaries control structure.
type(cont_loop_bounds_type), &
optional, intent(in) :: LB_in !< Loop bounds structure.
! Local variables
type(cont_loop_bounds_type) :: LB
integer :: i, j, k, ish, ieh, jsh, jeh, nz
call cpu_clock_begin(id_clock_reconstruct)
if (present(LB_in)) then
LB = LB_in
else
LB%ish = G%isc ; LB%ieh = G%iec ; LB%jsh = G%jsc ; LB%jeh = G%jec
endif
ish = LB%ish ; ieh = LB%ieh ; jsh = LB%jsh ; jeh = LB%jeh ; nz = GV%ke
if (CS%upwind_1st) then
!$OMP parallel do default(shared)
do k=1,nz ; do j=jsh,jeh ; do i=ish-1,ieh+1
h_W(i,j,k) = h_in(i,j,k) ; h_E(i,j,k) = h_in(i,j,k)
enddo ; enddo ; enddo
else
!$OMP parallel do default(shared)
do k=1,nz
call PPM_reconstruction_x(h_in(:,:,k), h_W(:,:,k), h_E(:,:,k), G, LB, &
2.0*GV%Angstrom_H, CS%monotonic, CS%simple_2nd, OBC)
enddo
endif
call cpu_clock_end(id_clock_reconstruct)
end subroutine zonal_edge_thickness
!> Set the reconstructed thicknesses at the eastern and western edges of tracer cells.
subroutine meridional_edge_thickness(h_in, h_S, h_N, G, GV, US, CS, OBC, LB_in)
type(ocean_grid_type), intent(in) :: G !< Ocean's grid structure.
type(verticalGrid_type), intent(in) :: GV !< Ocean's vertical grid structure.
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)), &
intent(in) :: h_in !< Tracer cell layer thickness [H ~> m or kg m-2].
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)), &
intent(out) :: h_S !< Southern edge layer thickness [H ~> m or kg m-2].
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)), &
intent(out) :: h_N !< Northern edge layer thickness [H ~> m or kg m-2].
type(unit_scale_type), intent(in) :: US !< A dimensional unit scaling type
type(continuity_PPM_CS), intent(in) :: CS !< This module's control structure.
type(ocean_OBC_type), pointer :: OBC !< Open boundaries control structure.
type(cont_loop_bounds_type), &
optional, intent(in) :: LB_in !< Loop bounds structure.
! Local variables
type(cont_loop_bounds_type) :: LB
integer :: i, j, k, ish, ieh, jsh, jeh, nz
call cpu_clock_begin(id_clock_reconstruct)
if (present(LB_in)) then
LB = LB_in
else
LB%ish = G%isc ; LB%ieh = G%iec ; LB%jsh = G%jsc ; LB%jeh = G%jec
endif
ish = LB%ish ; ieh = LB%ieh ; jsh = LB%jsh ; jeh = LB%jeh ; nz = GV%ke
if (CS%upwind_1st) then
!$OMP parallel do default(shared)
do k=1,nz ; do j=jsh-1,jeh+1 ; do i=ish,ieh
h_S(i,j,k) = h_in(i,j,k) ; h_N(i,j,k) = h_in(i,j,k)
enddo ; enddo ; enddo
else
!$OMP parallel do default(shared)
do k=1,nz
call PPM_reconstruction_y(h_in(:,:,k), h_S(:,:,k), h_N(:,:,k), G, LB, &
2.0*GV%Angstrom_H, CS%monotonic, CS%simple_2nd, OBC)
enddo
endif
call cpu_clock_end(id_clock_reconstruct)
end subroutine meridional_edge_thickness
!> Calculates the mass or volume fluxes through the zonal faces, and other related quantities.
subroutine zonal_mass_flux(u, h_in, h_W, h_E, uh, dt, G, GV, US, CS, OBC, por_face_areaU, &
LB_in, uhbt, visc_rem_u, u_cor, BT_cont, du_cor)
type(ocean_grid_type), intent(in) :: G !< Ocean's grid structure.
type(verticalGrid_type), intent(in) :: GV !< Ocean's vertical grid structure.
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)), &
intent(in) :: u !< Zonal velocity [L T-1 ~> m s-1].
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)), &
intent(in) :: h_in !< Layer thickness used to calculate fluxes [H ~> m or kg m-2].
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)), &
intent(in) :: h_W !< Western edge thicknesses [H ~> m or kg m-2].
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)), &
intent(in) :: h_E !< Eastern edge thicknesses [H ~> m or kg m-2].
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)), &
intent(out) :: uh !< Volume flux through zonal faces = u*h*dy
!! [H L2 T-1 ~> m3 s-1 or kg s-1].
real, intent(in) :: dt !< Time increment [T ~> s].
type(unit_scale_type), intent(in) :: US !< A dimensional unit scaling type
type(continuity_PPM_CS), intent(in) :: CS !< This module's control structure.
type(ocean_OBC_type), pointer :: OBC !< Open boundaries control structure.
real, dimension(SZIB_(G), SZJ_(G), SZK_(G)), &
intent(in) :: por_face_areaU !< fractional open area of U-faces [nondim]
type(cont_loop_bounds_type), &
optional, intent(in) :: LB_in !< Loop bounds structure.
real, dimension(SZIB_(G),SZJ_(G)), &
optional, intent(in) :: uhbt !< The summed volume flux through zonal faces
!! [H L2 T-1 ~> m3 s-1 or kg s-1].
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)), &
optional, intent(in) :: visc_rem_u
!< The fraction of zonal momentum originally in a layer that remains after a
!! time-step of viscosity, and the fraction of a time-step's worth of a barotropic
!! acceleration that a layer experiences after viscosity is applied [nondim].
!! Visc_rem_u is between 0 (at the bottom) and 1 (far above the bottom).
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)), &
optional, intent(out) :: u_cor
!< The zonal velocities (u with a barotropic correction)
!! that give uhbt as the depth-integrated transport [L T-1 ~> m s-1]
type(BT_cont_type), optional, pointer :: BT_cont !< A structure with elements that describe the
!! effective open face areas as a function of barotropic flow.
real, dimension(SZIB_(G),SZJ_(G)), &
optional, intent(out) :: du_cor !< The zonal velocity increments from u that give uhbt
!! as the depth-integrated transports [L T-1 ~> m s-1].
! Local variables
real, dimension(SZIB_(G),SZK_(GV)) :: duhdu ! Partial derivative of uh with u [H L ~> m2 or kg m-1].
real, dimension(SZIB_(G)) :: &
du, & ! Corrective barotropic change in the velocity to give uhbt [L T-1 ~> m s-1].
du_min_CFL, & ! Lower limit on du correction to avoid CFL violations [L T-1 ~> m s-1]
du_max_CFL, & ! Upper limit on du correction to avoid CFL violations [L T-1 ~> m s-1]
duhdu_tot_0, & ! Summed partial derivative of uh with u [H L ~> m2 or kg m-1].
uh_tot_0, & ! Summed transport with no barotropic correction [H L2 T-1 ~> m3 s-1 or kg s-1].
visc_rem_max ! The column maximum of visc_rem [nondim].
logical, dimension(SZIB_(G)) :: do_I
real, dimension(SZIB_(G),SZK_(GV)) :: &
visc_rem ! A 2-D copy of visc_rem_u or an array of 1's [nondim].
real, dimension(SZIB_(G)) :: FAuI ! A list of sums of zonal face areas [H L ~> m2 or kg m-1].
real :: FA_u ! A sum of zonal face areas [H L ~> m2 or kg m-1].
real :: I_vrm ! 1.0 / visc_rem_max [nondim]
real :: CFL_dt ! The maximum CFL ratio of the adjusted velocities divided by
! the time step [T-1 ~> s-1].
real :: I_dt ! 1.0 / dt [T-1 ~> s-1].
real :: du_lim ! The velocity change that give a relative CFL of 1 [L T-1 ~> m s-1].
real :: dx_E, dx_W ! Effective x-grid spacings to the east and west [L ~> m].
type(cont_loop_bounds_type) :: LB
integer :: i, j, k, ish, ieh, jsh, jeh, n, nz
integer :: l_seg ! The OBC segment number
logical :: use_visc_rem, set_BT_cont
logical :: local_specified_BC, local_Flather_OBC, local_open_BC, any_simple_OBC ! OBC-related logicals
logical :: simple_OBC_pt(SZIB_(G)) ! Indicates points in a row with specified transport OBCs
call cpu_clock_begin(id_clock_correct)
use_visc_rem = present(visc_rem_u)
set_BT_cont = .false. ; if (present(BT_cont)) set_BT_cont = (associated(BT_cont))
local_specified_BC = .false. ; local_Flather_OBC = .false. ; local_open_BC = .false.
if (associated(OBC)) then ; if (OBC%OBC_pe) then
local_specified_BC = OBC%specified_u_BCs_exist_globally
local_Flather_OBC = OBC%Flather_u_BCs_exist_globally
local_open_BC = OBC%open_u_BCs_exist_globally
endif ; endif
if (present(du_cor)) du_cor(:,:) = 0.0
if (present(LB_in)) then
LB = LB_in
else
LB%ish = G%isc ; LB%ieh = G%iec ; LB%jsh = G%jsc ; LB%jeh = G%jec
endif
ish = LB%ish ; ieh = LB%ieh ; jsh = LB%jsh ; jeh = LB%jeh ; nz = GV%ke
CFL_dt = CS%CFL_limit_adjust / dt
I_dt = 1.0 / dt
if (CS%aggress_adjust) CFL_dt = I_dt
if (.not.use_visc_rem) visc_rem(:,:) = 1.0
!$OMP parallel do default(shared) private(do_I,duhdu,du,du_max_CFL,du_min_CFL,uh_tot_0, &
!$OMP duhdu_tot_0,FAuI,visc_rem_max,I_vrm,du_lim,dx_E,dx_W, &
!$OMP simple_OBC_pt,any_simple_OBC,l_seg) &
!$OMP firstprivate(visc_rem)
do j=jsh,jeh
do I=ish-1,ieh ; do_I(I) = .true. ; enddo
! Set uh and duhdu.
do k=1,nz
if (use_visc_rem) then ; do I=ish-1,ieh
visc_rem(I,k) = visc_rem_u(I,j,k)
enddo ; endif
call zonal_flux_layer(u(:,j,k), h_in(:,j,k), h_W(:,j,k), h_E(:,j,k), &
uh(:,j,k), duhdu(:,k), visc_rem(:,k), &
dt, G, US, j, ish, ieh, do_I, CS%vol_CFL, por_face_areaU(:,j,k), OBC)
if (local_specified_BC) then
do I=ish-1,ieh ; if (OBC%segnum_u(I,j) /= OBC_NONE) then
l_seg = OBC%segnum_u(I,j)
if (OBC%segment(l_seg)%specified) uh(I,j,k) = OBC%segment(l_seg)%normal_trans(I,j,k)
endif ; enddo
endif
enddo
if (present(uhbt) .or. set_BT_cont) then
if (use_visc_rem .and. CS%use_visc_rem_max) then
visc_rem_max(:) = 0.0
do k=1,nz ; do I=ish-1,ieh
visc_rem_max(I) = max(visc_rem_max(I), visc_rem(I,k))
enddo ; enddo
else
visc_rem_max(:) = 1.0
endif
! Set limits on du that will keep the CFL number between -1 and 1.
! This should be adequate to keep the root bracketed in all cases.
do I=ish-1,ieh
I_vrm = 0.0
if (visc_rem_max(I) > 0.0) I_vrm = 1.0 / visc_rem_max(I)
if (CS%vol_CFL) then
dx_W = ratio_max(G%areaT(i,j), G%dy_Cu(I,j), 1000.0*G%dxT(i,j))
dx_E = ratio_max(G%areaT(i+1,j), G%dy_Cu(I,j), 1000.0*G%dxT(i+1,j))
else ; dx_W = G%dxT(i,j) ; dx_E = G%dxT(i+1,j) ; endif
du_max_CFL(I) = 2.0* (CFL_dt * dx_W) * I_vrm
du_min_CFL(I) = -2.0 * (CFL_dt * dx_E) * I_vrm
uh_tot_0(I) = 0.0 ; duhdu_tot_0(I) = 0.0
enddo
do k=1,nz ; do I=ish-1,ieh
duhdu_tot_0(I) = duhdu_tot_0(I) + duhdu(I,k)
uh_tot_0(I) = uh_tot_0(I) + uh(I,j,k)
enddo ; enddo
if (use_visc_rem) then
if (CS%aggress_adjust) then
do k=1,nz ; do I=ish-1,ieh
if (CS%vol_CFL) then
dx_W = ratio_max(G%areaT(i,j), G%dy_Cu(I,j), 1000.0*G%dxT(i,j))
dx_E = ratio_max(G%areaT(i+1,j), G%dy_Cu(I,j), 1000.0*G%dxT(i+1,j))
else ; dx_W = G%dxT(i,j) ; dx_E = G%dxT(i+1,j) ; endif
du_lim = 0.499*((dx_W*I_dt - u(I,j,k)) + MIN(0.0,u(I-1,j,k)))
if (du_max_CFL(I) * visc_rem(I,k) > du_lim) &
du_max_CFL(I) = du_lim / visc_rem(I,k)
du_lim = 0.499*((-dx_E*I_dt - u(I,j,k)) + MAX(0.0,u(I+1,j,k)))
if (du_min_CFL(I) * visc_rem(I,k) < du_lim) &
du_min_CFL(I) = du_lim / visc_rem(I,k)
enddo ; enddo
else
do k=1,nz ; do I=ish-1,ieh
if (CS%vol_CFL) then
dx_W = ratio_max(G%areaT(i,j), G%dy_Cu(I,j), 1000.0*G%dxT(i,j))
dx_E = ratio_max(G%areaT(i+1,j), G%dy_Cu(I,j), 1000.0*G%dxT(i+1,j))
else ; dx_W = G%dxT(i,j) ; dx_E = G%dxT(i+1,j) ; endif
if (du_max_CFL(I) * visc_rem(I,k) > dx_W*CFL_dt - u(I,j,k)*G%mask2dCu(I,j)) &
du_max_CFL(I) = (dx_W*CFL_dt - u(I,j,k)) / visc_rem(I,k)
if (du_min_CFL(I) * visc_rem(I,k) < -dx_E*CFL_dt - u(I,j,k)*G%mask2dCu(I,j)) &
du_min_CFL(I) = -(dx_E*CFL_dt + u(I,j,k)) / visc_rem(I,k)
enddo ; enddo
endif
else
if (CS%aggress_adjust) then
do k=1,nz ; do I=ish-1,ieh
if (CS%vol_CFL) then
dx_W = ratio_max(G%areaT(i,j), G%dy_Cu(I,j), 1000.0*G%dxT(i,j))
dx_E = ratio_max(G%areaT(i+1,j), G%dy_Cu(I,j), 1000.0*G%dxT(i+1,j))
else ; dx_W = G%dxT(i,j) ; dx_E = G%dxT(i+1,j) ; endif
du_max_CFL(I) = MIN(du_max_CFL(I), 0.499 * &
((dx_W*I_dt - u(I,j,k)) + MIN(0.0,u(I-1,j,k))) )
du_min_CFL(I) = MAX(du_min_CFL(I), 0.499 * &
((-dx_E*I_dt - u(I,j,k)) + MAX(0.0,u(I+1,j,k))) )
enddo ; enddo
else
do k=1,nz ; do I=ish-1,ieh
if (CS%vol_CFL) then
dx_W = ratio_max(G%areaT(i,j), G%dy_Cu(I,j), 1000.0*G%dxT(i,j))
dx_E = ratio_max(G%areaT(i+1,j), G%dy_Cu(I,j), 1000.0*G%dxT(i+1,j))
else ; dx_W = G%dxT(i,j) ; dx_E = G%dxT(i+1,j) ; endif
du_max_CFL(I) = MIN(du_max_CFL(I), dx_W*CFL_dt - u(I,j,k))
du_min_CFL(I) = MAX(du_min_CFL(I), -(dx_E*CFL_dt + u(I,j,k)))
enddo ; enddo
endif
endif
do I=ish-1,ieh
du_max_CFL(I) = max(du_max_CFL(I),0.0)
du_min_CFL(I) = min(du_min_CFL(I),0.0)
enddo
any_simple_OBC = .false.
if (present(uhbt) .or. set_BT_cont) then
if (local_specified_BC .or. local_Flather_OBC) then ; do I=ish-1,ieh
l_seg = OBC%segnum_u(I,j)
! Avoid reconciling barotropic/baroclinic transports if transport is specified
simple_OBC_pt(I) = .false.
if (l_seg /= OBC_NONE) simple_OBC_pt(I) = OBC%segment(l_seg)%specified
do_I(I) = .not.simple_OBC_pt(I)
any_simple_OBC = any_simple_OBC .or. simple_OBC_pt(I)
enddo ; else ; do I=ish-1,ieh
do_I(I) = .true.
enddo ; endif
endif
if (present(uhbt)) then
! Find du and uh.
call zonal_flux_adjust(u, h_in, h_W, h_E, uhbt(:,j), uh_tot_0, duhdu_tot_0, du, &
du_max_CFL, du_min_CFL, dt, G, GV, US, CS, visc_rem, &
j, ish, ieh, do_I, por_face_areaU, uh, OBC=OBC)
if (present(u_cor)) then ; do k=1,nz
do I=ish-1,ieh ; u_cor(I,j,k) = u(I,j,k) + du(I) * visc_rem(I,k) ; enddo
if (any_simple_OBC) then ; do I=ish-1,ieh ; if (simple_OBC_pt(I)) then
u_cor(I,j,k) = OBC%segment(OBC%segnum_u(I,j))%normal_vel(I,j,k)
endif ; enddo ; endif
enddo ; endif ! u-corrected
if (present(du_cor)) then
do I=ish-1,ieh ; du_cor(I,j) = du(I) ; enddo
endif
endif
if (set_BT_cont) then
call set_zonal_BT_cont(u, h_in, h_W, h_E, BT_cont, uh_tot_0, duhdu_tot_0,&
du_max_CFL, du_min_CFL, dt, G, GV, US, CS, visc_rem, &
visc_rem_max, j, ish, ieh, do_I, por_face_areaU)
if (any_simple_OBC) then
do I=ish-1,ieh
if (simple_OBC_pt(I)) FAuI(I) = GV%H_subroundoff*G%dy_Cu(I,j)
enddo
! NOTE: simple_OBC_pt(I) should prevent access to segment OBC_NONE
do k=1,nz ; do I=ish-1,ieh ; if (simple_OBC_pt(I)) then
if ((abs(OBC%segment(OBC%segnum_u(I,j))%normal_vel(I,j,k)) > 0.0) .and. &
(OBC%segment(OBC%segnum_u(I,j))%specified)) &
FAuI(I) = FAuI(I) + OBC%segment(OBC%segnum_u(I,j))%normal_trans(I,j,k) / &
OBC%segment(OBC%segnum_u(I,j))%normal_vel(I,j,k)
endif ; enddo ; enddo
do I=ish-1,ieh ; if (simple_OBC_pt(I)) then
BT_cont%FA_u_W0(I,j) = FAuI(I) ; BT_cont%FA_u_E0(I,j) = FAuI(I)
BT_cont%FA_u_WW(I,j) = FAuI(I) ; BT_cont%FA_u_EE(I,j) = FAuI(I)
BT_cont%uBT_WW(I,j) = 0.0 ; BT_cont%uBT_EE(I,j) = 0.0
endif ; enddo
endif
endif ! set_BT_cont
endif ! present(uhbt) or set_BT_cont
enddo ! j-loop
if (local_open_BC .and. set_BT_cont) then
do n = 1, OBC%number_of_segments
if (OBC%segment(n)%open .and. OBC%segment(n)%is_E_or_W) then
I = OBC%segment(n)%HI%IsdB
if (OBC%segment(n)%direction == OBC_DIRECTION_E) then
do j = OBC%segment(n)%HI%Jsd, OBC%segment(n)%HI%Jed
FA_u = 0.0
do k=1,nz ; FA_u = FA_u + h_in(i,j,k)*(G%dy_Cu(I,j)*por_face_areaU(I,j,k)) ; enddo
BT_cont%FA_u_W0(I,j) = FA_u ; BT_cont%FA_u_E0(I,j) = FA_u
BT_cont%FA_u_WW(I,j) = FA_u ; BT_cont%FA_u_EE(I,j) = FA_u
BT_cont%uBT_WW(I,j) = 0.0 ; BT_cont%uBT_EE(I,j) = 0.0
enddo
else
do j = OBC%segment(n)%HI%Jsd, OBC%segment(n)%HI%Jed
FA_u = 0.0
do k=1,nz ; FA_u = FA_u + h_in(i+1,j,k)*(G%dy_Cu(I,j)*por_face_areaU(I,j,k)) ; enddo
BT_cont%FA_u_W0(I,j) = FA_u ; BT_cont%FA_u_E0(I,j) = FA_u
BT_cont%FA_u_WW(I,j) = FA_u ; BT_cont%FA_u_EE(I,j) = FA_u
BT_cont%uBT_WW(I,j) = 0.0 ; BT_cont%uBT_EE(I,j) = 0.0
enddo
endif
endif
enddo
endif
if (set_BT_cont) then ; if (allocated(BT_cont%h_u)) then
if (present(u_cor)) then
call zonal_flux_thickness(u_cor, h_in, h_W, h_E, BT_cont%h_u, dt, G, GV, US, LB, &
CS%vol_CFL, CS%marginal_faces, OBC, por_face_areaU, visc_rem_u)
else
call zonal_flux_thickness(u, h_in, h_W, h_E, BT_cont%h_u, dt, G, GV, US, LB, &
CS%vol_CFL, CS%marginal_faces, OBC, por_face_areaU, visc_rem_u)
endif
endif ; endif
call cpu_clock_end(id_clock_correct)
end subroutine zonal_mass_flux
!> Calculates the vertically integrated mass or volume fluxes through the zonal faces.
subroutine zonal_BT_mass_flux(u, h_in, h_W, h_E, uhbt, dt, G, GV, US, CS, OBC, por_face_areaU, LB_in)
type(ocean_grid_type), intent(in) :: G !< Ocean's grid structure.
type(verticalGrid_type), intent(in) :: GV !< Ocean's vertical grid structure.
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)), intent(in) :: u !< Zonal velocity [L T-1 ~> m s-1]
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)), intent(in) :: h_in !< Layer thickness used to
!! calculate fluxes [H ~> m or kg m-2]
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)), intent(in) :: h_W !< Western edge thickness in the PPM
!! reconstruction [H ~> m or kg m-2].
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)), intent(in) :: h_E !< Eastern edge thickness in the PPM
!! reconstruction [H ~> m or kg m-2].
real, dimension(SZIB_(G),SZJ_(G)), intent(out) :: uhbt !< The summed volume flux through zonal
!! faces [H L2 T-1 ~> m3 s-1 or kg s-1].
real, intent(in) :: dt !< Time increment [T ~> s].
type(unit_scale_type), intent(in) :: US !< A dimensional unit scaling type
type(continuity_PPM_CS), intent(in) :: CS !< This module's control structure.G
type(ocean_OBC_type), pointer :: OBC !< Open boundary condition type
!! specifies whether, where, and what
!! open boundary conditions are used.
real, dimension(SZIB_(G),SZJ_(G),SZK_(G)), intent(in) :: por_face_areaU !< fractional open area of U-faces [nondim]
type(cont_loop_bounds_type), optional, intent(in) :: LB_in !< Loop bounds structure.
! Local variables
real :: uh(SZIB_(G)) ! Volume flux through zonal faces = u*h*dy [H L2 T-1 ~> m3 s-1 or kg s-1]
real :: duhdu(SZIB_(G)) ! Partial derivative of uh with u [H L ~> m2 or kg m-1].
logical, dimension(SZIB_(G)) :: do_I
real :: ones(SZIB_(G)) ! An array of 1's [nondim]
integer :: i, j, k, ish, ieh, jsh, jeh, nz
logical :: local_specified_BC, OBC_in_row
call cpu_clock_begin(id_clock_correct)
local_specified_BC = .false.
if (associated(OBC)) then ; if (OBC%OBC_pe) then
local_specified_BC = OBC%specified_v_BCs_exist_globally
endif ; endif
if (present(LB_in)) then
ish = LB_in%ish ; ieh = LB_in%ieh ; jsh = LB_in%jsh ; jeh = LB_in%jeh ; nz = GV%ke
else
ish = G%isc ; ieh = G%iec ; jsh = G%jsc ; jeh = G%jec ; nz = GV%ke
endif
ones(:) = 1.0 ; do_I(:) = .true.
uhbt(:,:) = 0.0
!$OMP parallel do default(shared) private(uh,duhdu,OBC_in_row)
do j=jsh,jeh
! Determining whether there are any OBC points outside of the k-loop should be more efficient.
OBC_in_row = .false.
if (local_specified_BC) then ; do I=ish-1,ieh ; if (OBC%segnum_u(I,j) /= OBC_NONE) then
if (OBC%segment(OBC%segnum_u(I,j))%specified) OBC_in_row = .true.
endif ; enddo ; endif
do k=1,nz
! This sets uh and duhdu.
call zonal_flux_layer(u(:,j,k), h_in(:,j,k), h_W(:,j,k), h_E(:,j,k), uh, duhdu, ones, &
dt, G, US, j, ish, ieh, do_I, CS%vol_CFL, por_face_areaU(:,j,k), OBC)
if (OBC_in_row) then ; do I=ish-1,ieh ; if (OBC%segnum_u(I,j) /= OBC_NONE) then
if (OBC%segment(OBC%segnum_u(I,j))%specified) uh(I) = OBC%segment(OBC%segnum_u(I,j))%normal_trans(I,j,k)
endif ; enddo ; endif
! Accumulate the barotropic transport.
do I=ish-1,ieh
uhbt(I,j) = uhbt(I,j) + uh(I)
enddo
enddo ! k-loop
enddo ! j-loop
call cpu_clock_end(id_clock_correct)
end subroutine zonal_BT_mass_flux
!> Evaluates the zonal mass or volume fluxes in a layer.
subroutine zonal_flux_layer(u, h, h_W, h_E, uh, duhdu, visc_rem, dt, G, US, j, &
ish, ieh, do_I, vol_CFL, por_face_areaU, OBC)
type(ocean_grid_type), intent(in) :: G !< Ocean's grid structure.
real, dimension(SZIB_(G)), intent(in) :: u !< Zonal velocity [L T-1 ~> m s-1].
real, dimension(SZIB_(G)), intent(in) :: visc_rem !< Both the fraction of the
!! momentum originally in a layer that remains after a time-step
!! of viscosity, and the fraction of a time-step's worth of a barotropic
!! acceleration that a layer experiences after viscosity is applied [nondim].
!! Visc_rem is between 0 (at the bottom) and 1 (far above the bottom).
real, dimension(SZI_(G)), intent(in) :: h !< Layer thickness [H ~> m or kg m-2].
real, dimension(SZI_(G)), intent(in) :: h_W !< West edge thickness [H ~> m or kg m-2].
real, dimension(SZI_(G)), intent(in) :: h_E !< East edge thickness [H ~> m or kg m-2].
real, dimension(SZIB_(G)), intent(inout) :: uh !< Zonal mass or volume
!! transport [H L2 T-1 ~> m3 s-1 or kg s-1].
real, dimension(SZIB_(G)), intent(inout) :: duhdu !< Partial derivative of uh
!! with u [H L ~> m2 or kg m-1].
real, intent(in) :: dt !< Time increment [T ~> s]
type(unit_scale_type), intent(in) :: US !< A dimensional unit scaling type
integer, intent(in) :: j !< Spatial index.
integer, intent(in) :: ish !< Start of index range.
integer, intent(in) :: ieh !< End of index range.
logical, dimension(SZIB_(G)), intent(in) :: do_I !< Which i values to work on.
logical, intent(in) :: vol_CFL !< If true, rescale the
real, dimension(SZIB_(G)), intent(in) :: por_face_areaU !< fractional open area of U-faces [nondim]
!! ratio of face areas to the cell areas when estimating the CFL number.
type(ocean_OBC_type), optional, pointer :: OBC !< Open boundaries control structure.
! Local variables
real :: CFL ! The CFL number based on the local velocity and grid spacing [nondim]
real :: curv_3 ! A measure of the thickness curvature over a grid length [H ~> m or kg m-2]
real :: h_marg ! The marginal thickness of a flux [H ~> m or kg m-2].
integer :: i
integer :: l_seg
logical :: local_open_BC
local_open_BC = .false.
if (present(OBC)) then ; if (associated(OBC)) then
local_open_BC = OBC%open_u_BCs_exist_globally
endif ; endif
do I=ish-1,ieh ; if (do_I(I)) then
! Set new values of uh and duhdu.
if (u(I) > 0.0) then
if (vol_CFL) then ; CFL = (u(I) * dt) * (G%dy_Cu(I,j) * G%IareaT(i,j))
else ; CFL = u(I) * dt * G%IdxT(i,j) ; endif
curv_3 = (h_W(i) + h_E(i)) - 2.0*h(i)
uh(I) = (G%dy_Cu(I,j) * por_face_areaU(I)) * u(I) * &
(h_E(i) + CFL * (0.5*(h_W(i) - h_E(i)) + curv_3*(CFL - 1.5)))
h_marg = h_E(i) + CFL * ((h_W(i) - h_E(i)) + 3.0*curv_3*(CFL - 1.0))
elseif (u(I) < 0.0) then
if (vol_CFL) then ; CFL = (-u(I) * dt) * (G%dy_Cu(I,j) * G%IareaT(i+1,j))
else ; CFL = -u(I) * dt * G%IdxT(i+1,j) ; endif
curv_3 = (h_W(i+1) + h_E(i+1)) - 2.0*h(i+1)
uh(I) = (G%dy_Cu(I,j) * por_face_areaU(I)) * u(I) * &
(h_W(i+1) + CFL * (0.5*(h_E(i+1)-h_W(i+1)) + curv_3*(CFL - 1.5)))
h_marg = h_W(i+1) + CFL * ((h_E(i+1)-h_W(i+1)) + 3.0*curv_3*(CFL - 1.0))
else
uh(I) = 0.0
h_marg = 0.5 * (h_W(i+1) + h_E(i))
endif
duhdu(I) = (G%dy_Cu(I,j) * por_face_areaU(I)) * h_marg * visc_rem(I)
endif ; enddo
if (local_open_BC) then
do I=ish-1,ieh ; if (do_I(I)) then ; if (OBC%segnum_u(I,j) /= OBC_NONE) then
l_seg = OBC%segnum_u(I,j)
if (OBC%segment(l_seg)%open) then
if (OBC%segment(l_seg)%direction == OBC_DIRECTION_E) then
uh(I) = (G%dy_Cu(I,j) * por_face_areaU(I)) * u(I) * h(i)
duhdu(I) = (G%dy_Cu(I,j) * por_face_areaU(I)) * h(i) * visc_rem(I)
else
uh(I) = (G%dy_Cu(I,j) * por_face_areaU(I)) * u(I) * h(i+1)
duhdu(I) = (G%dy_Cu(I,j)* por_face_areaU(I)) * h(i+1) * visc_rem(I)
endif
endif
endif ; endif ; enddo
endif
end subroutine zonal_flux_layer
!> Sets the effective interface thickness associated with the fluxes at each zonal velocity point,
!! optionally scaling back these thicknesses to account for viscosity and fractional open areas.
subroutine zonal_flux_thickness(u, h, h_W, h_E, h_u, dt, G, GV, US, LB, vol_CFL, &
marginal, OBC, por_face_areaU, visc_rem_u)
type(ocean_grid_type), intent(in) :: G !< Ocean's grid structure.
type(verticalGrid_type), intent(in) :: GV !< Ocean's vertical grid structure.
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)), intent(in) :: u !< Zonal velocity [L T-1 ~> m s-1].
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)), intent(in) :: h !< Layer thickness used to
!! calculate fluxes [H ~> m or kg m-2].
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)), intent(in) :: h_W !< West edge thickness in the
!! reconstruction [H ~> m or kg m-2].
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)), intent(in) :: h_E !< East edge thickness in the
!! reconstruction [H ~> m or kg m-2].
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)), intent(inout) :: h_u !< Effective thickness at zonal faces,
!! scaled down to account for the effects of
!! viscosity and the fractional open area
!! [H ~> m or kg m-2].
real, intent(in) :: dt !< Time increment [T ~> s].
type(unit_scale_type), intent(in) :: US !< A dimensional unit scaling type
type(cont_loop_bounds_type), intent(in) :: LB !< Loop bounds structure.
logical, intent(in) :: vol_CFL !< If true, rescale the ratio
!! of face areas to the cell areas when estimating the CFL number.
logical, intent(in) :: marginal !< If true, report the
!! marginal face thicknesses; otherwise report transport-averaged thicknesses.
real, dimension(SZIB_(G), SZJ_(G), SZK_(G)), &
intent(in) :: por_face_areaU !< fractional open area of U-faces [nondim]
type(ocean_OBC_type), pointer :: OBC !< Open boundaries control structure.