forked from mom-ocean/MOM6
-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathMOM_dynamics_split_RK2.F90
1897 lines (1673 loc) · 103 KB
/
MOM_dynamics_split_RK2.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
!> Time step the adiabatic dynamic core of MOM using RK2 method.
module MOM_dynamics_split_RK2
! This file is part of MOM6. See LICENSE.md for the license.
use MOM_variables, only : vertvisc_type, thermo_var_ptrs, porous_barrier_type
use MOM_variables, only : BT_cont_type, alloc_bt_cont_type, dealloc_bt_cont_type
use MOM_variables, only : accel_diag_ptrs, ocean_internal_state, cont_diag_ptrs
use MOM_forcing_type, only : mech_forcing
use MOM_checksum_packages, only : MOM_thermo_chksum, MOM_state_chksum, MOM_accel_chksum
use MOM_cpu_clock, only : cpu_clock_id, cpu_clock_begin, cpu_clock_end
use MOM_cpu_clock, only : CLOCK_COMPONENT, CLOCK_SUBCOMPONENT
use MOM_cpu_clock, only : CLOCK_MODULE_DRIVER, CLOCK_MODULE, CLOCK_ROUTINE
use MOM_diag_mediator, only : diag_mediator_init, enable_averages
use MOM_diag_mediator, only : disable_averaging, post_data, 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 : register_diag_field, register_static_field
use MOM_diag_mediator, only : set_diag_mediator_grid, diag_ctrl, diag_update_remap_grids
use MOM_domains, only : To_South, To_West, To_All, CGRID_NE, SCALAR_PAIR
use MOM_domains, only : To_North, To_East, Omit_Corners
use MOM_domains, only : create_group_pass, do_group_pass, group_pass_type
use MOM_domains, only : start_group_pass, complete_group_pass, pass_var, pass_vector
use MOM_debugging, only : hchksum, uvchksum, query_debugging_checks
use MOM_error_handler, only : MOM_error, MOM_mesg, FATAL, WARNING, is_root_pe
use MOM_error_handler, only : MOM_set_verbosity, callTree_showQuery
use MOM_error_handler, only : callTree_enter, callTree_leave, callTree_waypoint
use MOM_file_parser, only : get_param, log_version, param_file_type
use MOM_get_input, only : directories
use MOM_io, only : vardesc, var_desc, EAST_FACE, NORTH_FACE
use MOM_restart, only : register_restart_field, register_restart_pair
use MOM_restart, only : query_initialized, set_initialized, save_restart
use MOM_restart, only : only_read_from_restarts
use MOM_restart, only : restart_init, is_new_run, MOM_restart_CS
use MOM_time_manager, only : time_type, time_type_to_real, operator(+)
use MOM_time_manager, only : operator(-), operator(>), operator(*), operator(/)
use MOM_ALE, only : ALE_CS, ALE_remap_velocities
use MOM_barotropic, only : barotropic_init, btstep, btcalc, bt_mass_source
use MOM_barotropic, only : register_barotropic_restarts, set_dtbt, barotropic_CS
use MOM_barotropic, only : barotropic_end
use MOM_boundary_update, only : update_OBC_data, update_OBC_CS
use MOM_continuity, only : continuity, continuity_CS
use MOM_continuity, only : continuity_init, continuity_stencil
use MOM_CoriolisAdv, only : CorAdCalc, CoriolisAdv_CS
use MOM_CoriolisAdv, only : CoriolisAdv_init, CoriolisAdv_end
use MOM_debugging, only : check_redundant
use MOM_grid, only : ocean_grid_type
use MOM_harmonic_analysis, only : harmonic_analysis_CS
use MOM_hor_index, only : hor_index_type
use MOM_hor_visc, only : horizontal_viscosity, hor_visc_CS
use MOM_hor_visc, only : hor_visc_init, hor_visc_end
use MOM_interface_heights, only : thickness_to_dz, find_col_avg_SpV
use MOM_lateral_mixing_coeffs, only : VarMix_CS
use MOM_MEKE_types, only : MEKE_type
use MOM_open_boundary, only : ocean_OBC_type, radiation_open_bdry_conds
use MOM_open_boundary, only : open_boundary_zero_normal_flow, open_boundary_query
use MOM_open_boundary, only : open_boundary_test_extern_h, update_OBC_ramp
use MOM_PressureForce, only : PressureForce, PressureForce_CS
use MOM_PressureForce, only : PressureForce_init
use MOM_set_visc, only : set_viscous_ML, set_visc_CS
use MOM_thickness_diffuse, only : thickness_diffuse_CS
use MOM_self_attr_load, only : SAL_CS
use MOM_self_attr_load, only : SAL_init, SAL_end
use MOM_tidal_forcing, only : tidal_forcing_CS
use MOM_tidal_forcing, only : tidal_forcing_init, tidal_forcing_end
use MOM_unit_scaling, only : unit_scale_type
use MOM_vert_friction, only : vertvisc, vertvisc_coef, vertvisc_remnant
use MOM_vert_friction, only : vertvisc_init, vertvisc_end, vertvisc_CS
use MOM_vert_friction, only : updateCFLtruncationValue, vertFPmix
use MOM_verticalGrid, only : verticalGrid_type, get_thickness_units
use MOM_verticalGrid, only : get_flux_units, get_tr_flux_units
use MOM_wave_interface, only : wave_parameters_CS, Stokes_PGF
implicit none ; private
#include <MOM_memory.h>
!> MOM_dynamics_split_RK2 module control structure
type, public :: MOM_dyn_split_RK2_CS ; private
real ALLOCABLE_, dimension(NIMEMB_PTR_,NJMEM_,NKMEM_) :: &
CAu, & !< CAu = f*v - u.grad(u) [L T-2 ~> m s-2]
CAu_pred, & !< The predictor step value of CAu = f*v - u.grad(u) [L T-2 ~> m s-2]
PFu, & !< PFu = -dM/dx [L T-2 ~> m s-2]
PFu_Stokes, & !< PFu_Stokes = -d/dx int_r (u_L*duS/dr) [L T-2 ~> m s-2]
diffu !< Zonal acceleration due to convergence of the along-isopycnal stress tensor [L T-2 ~> m s-2]
real ALLOCABLE_, dimension(NIMEM_,NJMEMB_PTR_,NKMEM_) :: &
CAv, & !< CAv = -f*u - u.grad(v) [L T-2 ~> m s-2]
CAv_pred, & !< The predictor step value of CAv = -f*u - u.grad(v) [L T-2 ~> m s-2]
PFv, & !< PFv = -dM/dy [L T-2 ~> m s-2]
PFv_Stokes, & !< PFv_Stokes = -d/dy int_r (v_L*dvS/dr) [L T-2 ~> m s-2]
diffv !< Meridional acceleration due to convergence of the along-isopycnal stress tensor [L T-2 ~> m s-2]
real ALLOCABLE_, dimension(NIMEMB_PTR_,NJMEM_,NKMEM_) :: visc_rem_u
!< Both the fraction of the zonal momentum originally in a
!! layer that remains after a time-step of viscosity, and the
!! fraction of a time-step worth of a barotropic acceleration
!! that a layer experiences after viscosity is applied [nondim].
!! Nondimensional between 0 (at the bottom) and 1 (far above).
real ALLOCABLE_, dimension(NIMEMB_PTR_,NJMEM_,NKMEM_) :: u_accel_bt
!< The zonal layer accelerations due to the difference between
!! the barotropic accelerations and the baroclinic accelerations
!! that were fed into the barotopic calculation [L T-2 ~> m s-2]
real ALLOCABLE_, dimension(NIMEM_,NJMEMB_PTR_,NKMEM_) :: visc_rem_v
!< Both the fraction of the meridional momentum originally in
!! a layer that remains after a time-step of viscosity, and the
!! fraction of a time-step worth of a barotropic acceleration
!! that a layer experiences after viscosity is applied [nondim].
!! Nondimensional between 0 (at the bottom) and 1 (far above).
real ALLOCABLE_, dimension(NIMEM_,NJMEMB_PTR_,NKMEM_) :: v_accel_bt
!< The meridional layer accelerations due to the difference between
!! the barotropic accelerations and the baroclinic accelerations
!! that were fed into the barotopic calculation [L T-2 ~> m s-2]
! The following variables are only used with the split time stepping scheme.
real ALLOCABLE_, dimension(NIMEM_,NJMEM_) :: eta !< Instantaneous free surface height (in Boussinesq
!! mode) or column mass anomaly (in non-Boussinesq
!! mode) [H ~> m or kg m-2]
real ALLOCABLE_, dimension(NIMEMB_PTR_,NJMEM_,NKMEM_) :: u_av !< layer x-velocity with vertical mean replaced by
!! time-mean barotropic velocity over a baroclinic
!! timestep [L T-1 ~> m s-1]
real ALLOCABLE_, dimension(NIMEM_,NJMEMB_PTR_,NKMEM_) :: v_av !< layer y-velocity with vertical mean replaced by
!! time-mean barotropic velocity over a baroclinic
!! timestep [L T-1 ~> m s-1]
real ALLOCABLE_, dimension(NIMEM_,NJMEM_,NKMEM_) :: h_av !< arithmetic mean of two successive layer
!! thicknesses [H ~> m or kg m-2]
real ALLOCABLE_, dimension(NIMEM_,NJMEM_) :: eta_PF !< instantaneous SSH used in calculating PFu and
!! PFv [H ~> m or kg m-2]
real ALLOCABLE_, dimension(NIMEMB_PTR_,NJMEM_) :: uhbt !< average x-volume or mass flux determined by the
!! barotropic solver [H L2 T-1 ~> m3 s-1 or kg s-1].
!! uhbt is roughly equal to the vertical sum of uh.
real ALLOCABLE_, dimension(NIMEM_,NJMEMB_PTR_) :: vhbt !< average y-volume or mass flux determined by the
!! barotropic solver [H L2 T-1 ~> m3 s-1 or kg s-1].
!! vhbt is roughly equal to vertical sum of vh.
real ALLOCABLE_, dimension(NIMEM_,NJMEM_,NKMEM_) :: pbce !< pbce times eta gives the baroclinic pressure
!! anomaly in each layer due to free surface height
!! anomalies [L2 H-1 T-2 ~> m s-2 or m4 kg-1 s-2].
real, pointer, dimension(:,:) :: taux_bot => NULL() !< frictional x-bottom stress from the ocean
!! to the seafloor [R L Z T-2 ~> Pa]
real, pointer, dimension(:,:) :: tauy_bot => NULL() !< frictional y-bottom stress from the ocean
!! to the seafloor [R L Z T-2 ~> Pa]
type(BT_cont_type), pointer :: BT_cont => NULL() !< A structure with elements that describe the
!! effective summed open face areas as a function
!! of barotropic flow.
! This is to allow the previous, velocity-based coupling with between the
! baroclinic and barotropic modes.
logical :: BT_use_layer_fluxes !< If true, use the summed layered fluxes plus
!! an adjustment due to a changed barotropic
!! velocity in the barotropic continuity equation.
logical :: split_bottom_stress !< If true, provide the bottom stress
!! calculated by the vertical viscosity to the
!! barotropic solver.
logical :: calc_dtbt !< If true, calculate the barotropic time-step
!! dynamically.
logical :: store_CAu !< If true, store the Coriolis and advective accelerations at the
!! end of the timestep for use in the next predictor step.
logical :: CAu_pred_stored !< If true, the Coriolis and advective accelerations at the
!! end of the timestep have been stored for use in the next
!! predictor step. This is used to accomodate various generations
!! of restart files.
logical :: calculate_SAL !< If true, calculate self-attraction and loading.
logical :: use_tides !< If true, tidal forcing is enabled.
logical :: remap_aux !< If true, apply ALE remapping to all of the auxiliary 3-D
!! variables that are needed to reproduce across restarts,
!! similarly to what is done with the primary state variables.
real :: be !< A nondimensional number from 0.5 to 1 that controls
!! the backward weighting of the time stepping scheme [nondim]
real :: begw !< A nondimensional number from 0 to 1 that controls
!! the extent to which the treatment of gravity waves
!! is forward-backward (0) or simulated backward
!! Euler (1) [nondim]. 0 is often used.
logical :: debug !< If true, write verbose checksums for debugging purposes.
logical :: debug_OBC !< If true, do debugging calls for open boundary conditions.
logical :: fpmix = .false. !< If true, applies profiles of momentum flux magnitude and direction.
logical :: module_is_initialized = .false. !< Record whether this module has been initialized.
logical :: visc_rem_dt_bug = .true. !< If true, recover a bug that uses dt_pred rather than dt for vertvisc_rem
!! at the end of predictor.
!>@{ Diagnostic IDs
integer :: id_uold = -1, id_vold = -1
integer :: id_uh = -1, id_vh = -1
integer :: id_umo = -1, id_vmo = -1
integer :: id_umo_2d = -1, id_vmo_2d = -1
integer :: id_PFu = -1, id_PFv = -1
integer :: id_CAu = -1, id_CAv = -1
integer :: id_ueffA = -1, id_veffA = -1
! integer :: id_hf_PFu = -1, id_hf_PFv = -1
integer :: id_h_PFu = -1, id_h_PFv = -1
integer :: id_hf_PFu_2d = -1, id_hf_PFv_2d = -1
integer :: id_intz_PFu_2d = -1, id_intz_PFv_2d = -1
integer :: id_PFu_visc_rem = -1, id_PFv_visc_rem = -1
! integer :: id_hf_CAu = -1, id_hf_CAv = -1
integer :: id_h_CAu = -1, id_h_CAv = -1
integer :: id_hf_CAu_2d = -1, id_hf_CAv_2d = -1
integer :: id_intz_CAu_2d = -1, id_intz_CAv_2d = -1
integer :: id_CAu_visc_rem = -1, id_CAv_visc_rem = -1
integer :: id_deta_dt = -1
! Split scheme only.
integer :: id_uav = -1, id_vav = -1
integer :: id_u_BT_accel = -1, id_v_BT_accel = -1
! integer :: id_hf_u_BT_accel = -1, id_hf_v_BT_accel = -1
integer :: id_h_u_BT_accel = -1, id_h_v_BT_accel = -1
integer :: id_hf_u_BT_accel_2d = -1, id_hf_v_BT_accel_2d = -1
integer :: id_intz_u_BT_accel_2d = -1, id_intz_v_BT_accel_2d = -1
integer :: id_u_BT_accel_visc_rem = -1, id_v_BT_accel_visc_rem = -1
!>@}
type(diag_ctrl), pointer :: diag => NULL() !< A structure that is used to regulate the
!! timing of diagnostic output.
type(accel_diag_ptrs), pointer :: ADp => NULL() !< A structure pointing to the various
!! accelerations in the momentum equations,
!! which can later be used to calculate
!! derived diagnostics like energy budgets.
type(accel_diag_ptrs), pointer :: AD_pred => NULL() !< A structure pointing to the various
!! predictor step accelerations in the momentum equations,
!! which can be used to debug truncations.
type(cont_diag_ptrs), pointer :: CDp => NULL() !< A structure with pointers to various
!! terms in the continuity equations,
!! which can later be used to calculate
!! derived diagnostics like energy budgets.
! The remainder of the structure points to child subroutines' control structures.
!> A pointer to the horizontal viscosity control structure
type(hor_visc_CS) :: hor_visc
!> A pointer to the continuity control structure
type(continuity_CS) :: continuity_CSp
!> The CoriolisAdv control structure
type(CoriolisAdv_CS) :: CoriolisAdv
!> A pointer to the PressureForce control structure
type(PressureForce_CS) :: PressureForce_CSp
!> A pointer to a structure containing interface height diffusivities
type(vertvisc_CS), pointer :: vertvisc_CSp => NULL()
!> A pointer to the set_visc control structure
type(set_visc_CS), pointer :: set_visc_CSp => NULL()
!> A pointer to the barotropic stepping control structure
type(barotropic_CS) :: barotropic_CSp
!> A pointer to the SAL control structure
type(SAL_CS) :: SAL_CSp
!> A pointer to the tidal forcing control structure
type(tidal_forcing_CS) :: tides_CSp
!> A pointer to the harmonic analysis control structure
type(harmonic_analysis_CS) :: HA_CSp
!> A pointer to the ALE control structure.
type(ALE_CS), pointer :: ALE_CSp => NULL()
type(ocean_OBC_type), pointer :: OBC => NULL() !< A pointer to an open boundary
!! condition type that specifies whether, where, and what open boundary
!! conditions are used. If no open BCs are used, this pointer stays
!! nullified. Flather OBCs use open boundary_CS as well.
!> A pointer to the update_OBC control structure
type(update_OBC_CS), pointer :: update_OBC_CSp => NULL()
type(group_pass_type) :: pass_eta !< Structure for group halo pass
type(group_pass_type) :: pass_visc_rem !< Structure for group halo pass
type(group_pass_type) :: pass_uvp !< Structure for group halo pass
type(group_pass_type) :: pass_hp_uv !< Structure for group halo pass
type(group_pass_type) :: pass_uv !< Structure for group halo pass
type(group_pass_type) :: pass_h !< Structure for group halo pass
type(group_pass_type) :: pass_av_uvh !< Structure for group halo pass
end type MOM_dyn_split_RK2_CS
public step_MOM_dyn_split_RK2
public register_restarts_dyn_split_RK2
public initialize_dyn_split_RK2
public remap_dyn_split_RK2_aux_vars
public end_dyn_split_RK2
!>@{ CPU time clock IDs
integer :: id_clock_Cor, id_clock_pres, id_clock_vertvisc
integer :: id_clock_horvisc, id_clock_mom_update
integer :: id_clock_continuity, id_clock_thick_diff
integer :: id_clock_btstep, id_clock_btcalc, id_clock_btforce
integer :: id_clock_pass, id_clock_pass_init
!>@}
contains
!> RK2 splitting for time stepping MOM adiabatic dynamics
subroutine step_MOM_dyn_split_RK2(u_inst, v_inst, h, tv, visc, Time_local, dt, forces, &
p_surf_begin, p_surf_end, uh, vh, uhtr, vhtr, eta_av, G, GV, US, CS, &
calc_dtbt, VarMix, MEKE, thickness_diffuse_CSp, pbv, Waves)
type(ocean_grid_type), intent(inout) :: 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)), &
target, intent(inout) :: u_inst !< Instantaneous zonal velocity [L T-1 ~> m s-1]
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)), &
target, intent(inout) :: v_inst !< Instantaneous meridional velocity [L T-1 ~> m s-1]
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)), &
intent(inout) :: h !< Layer thickness [H ~> m or kg m-2]
type(thermo_var_ptrs), intent(in) :: tv !< Thermodynamic type
type(vertvisc_type), intent(inout) :: visc !< Vertical visc, bottom drag, and related
type(time_type), intent(in) :: Time_local !< Model time at end of time step
real, intent(in) :: dt !< Baroclinic dynamics time step [T ~> s]
type(mech_forcing), intent(in) :: forces !< A structure with the driving mechanical forces
real, dimension(:,:), pointer :: p_surf_begin !< Surface pressure at the start of this dynamic
!! time step [R L2 T-2 ~> Pa]
real, dimension(:,:), pointer :: p_surf_end !< Surface pressure at the end of this dynamic
!! time step [R L2 T-2 ~> Pa]
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)), &
target, intent(inout) :: uh !< Zonal volume or mass transport
!! [H L2 T-1 ~> m3 s-1 or kg s-1]
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)), &
target, intent(inout) :: vh !< Meridional volume or mass transport
!! [H L2 T-1 ~> m3 s-1 or kg s-1]
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)), &
intent(inout) :: uhtr !< Accumulated zonal volume or mass transport
!! since last tracer advection [H L2 ~> m3 or kg]
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)), &
intent(inout) :: vhtr !< Accumulated meridional volume or mass transport
!! since last tracer advection [H L2 ~> m3 or kg]
real, dimension(SZI_(G),SZJ_(G)), intent(out) :: eta_av !< Free surface height or column mass
!! averaged over time step [H ~> m or kg m-2]
type(MOM_dyn_split_RK2_CS), pointer :: CS !< Module control structure
logical, intent(in) :: calc_dtbt !< If true, recalculate the barotropic time step
type(VarMix_CS), intent(inout) :: VarMix !< Variable mixing control structure
type(MEKE_type), intent(inout) :: MEKE !< MEKE fields
type(thickness_diffuse_CS), intent(inout) :: thickness_diffuse_CSp !< Pointer to a structure containing
!! interface height diffusivities
type(porous_barrier_type), intent(in) :: pbv !< porous barrier fractional cell metrics
type(wave_parameters_CS), optional, pointer :: Waves !< A pointer to a structure containing
!! fields related to the surface wave conditions
! local variables
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)) :: up ! Predicted zonal velocity [L T-1 ~> m s-1].
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)) :: vp ! Predicted meridional velocity [L T-1 ~> m s-1].
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)) :: hp ! Predicted thickness [H ~> m or kg m-2].
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)) :: dz ! Distance between the interfaces around a layer [Z ~> m]
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)) :: ueffA ! Effective Area of U-Faces [H L ~> m2]
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)) :: veffA ! Effective Area of V-Faces [H L ~> m2]
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)) :: u_bc_accel ! The summed zonal baroclinic accelerations
! of each layer calculated by the non-barotropic
! part of the model [L T-2 ~> m s-2]
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)) :: v_bc_accel ! The summed meridional baroclinic accelerations
! of each layer calculated by the non-barotropic
! part of the model [L T-2 ~> m s-2]
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)), target :: uh_in ! The zonal mass transports that would be
! obtained using the initial velocities [H L2 T-1 ~> m3 s-1 or kg s-1]
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)), target :: vh_in ! The meridional mass transports that would be
! obtained using the initial velocities [H L2 T-1 ~> m3 s-1 or kg s-1]
real, dimension(SZI_(G),SZJ_(G)) :: eta_pred ! The predictor value of the free surface height
! or column mass [H ~> m or kg m-2]
real, dimension(SZI_(G),SZJ_(G)) :: SpV_avg ! The column averaged specific volume [R-1 ~> m3 kg-1]
real, dimension(SZI_(G),SZJ_(G)) :: deta_dt ! A diagnostic of the time derivative of the free surface
! height or column mass [H T-1 ~> m s-1 or kg m-2 s-1]
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)) :: u_old_rad_OBC ! The starting zonal velocities, which are
! saved for use in the radiation open boundary condition code [L T-1 ~> m s-1]
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)) :: v_old_rad_OBC ! The starting meridional velocities, which are
! saved for use in the radiation open boundary condition code [L T-1 ~> m s-1]
! GMM, TODO: make these allocatable?
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)) :: uold ! u-velocity before vert_visc is applied, for fpmix
! [L T-1 ~> m s-1]
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)) :: vold ! v-velocity before vert_visc is applied, for fpmix
! [L T-1 ~> m s-1]
real :: pres_to_eta ! A factor that converts pressures to the units of eta
! [H T2 R-1 L-2 ~> m Pa-1 or kg m-2 Pa-1]
real, pointer, dimension(:,:) :: &
p_surf => NULL(), & ! A pointer to the surface pressure [R L2 T-2 ~> Pa]
eta_PF_start => NULL(), & ! The value of eta that corresponds to the starting pressure
! for the barotropic solver [H ~> m or kg m-2]
taux_bot => NULL(), & ! A pointer to the zonal bottom stress in some cases [R L Z T-2 ~> Pa]
tauy_bot => NULL(), & ! A pointer to the meridional bottom stress in some cases [R L Z T-2 ~> Pa]
! This pointer is just used as shorthand for CS%eta.
eta => NULL() ! A pointer to the instantaneous free surface height (in Boussinesq
! mode) or column mass anomaly (in non-Boussinesq mode) [H ~> m or kg m-2]
real, pointer, dimension(:,:,:) :: &
! These pointers are used to alter which fields are passed to btstep with various options:
u_ptr => NULL(), & ! A pointer to a zonal velocity [L T-1 ~> m s-1]
v_ptr => NULL(), & ! A pointer to a meridional velocity [L T-1 ~> m s-1]
uh_ptr => NULL(), & ! A pointer to a zonal volume or mass transport [H L2 T-1 ~> m3 s-1 or kg s-1]
vh_ptr => NULL(), & ! A pointer to a meridional volume or mass transport [H L2 T-1 ~> m3 s-1 or kg s-1]
! These pointers are just used as shorthand for CS%u_av, CS%v_av, and CS%h_av.
u_av, & ! The zonal velocity time-averaged over a time step [L T-1 ~> m s-1].
v_av, & ! The meridional velocity time-averaged over a time step [L T-1 ~> m s-1].
h_av ! The layer thickness time-averaged over a time step [H ~> m or kg m-2].
real, dimension(SZI_(G),SZJ_(G)) :: hbl ! Boundary layer depth from Cvmix [H ~> m or kg m-2]
real :: dt_pred ! The time step for the predictor part of the baroclinic time stepping [T ~> s].
real :: Idt_bc ! Inverse of the baroclinic timestep [T-1 ~> s-1]
logical :: dyn_p_surf
logical :: debug_redundant ! If true, check redundant values on PE boundaries when debugging
logical :: BT_cont_BT_thick ! If true, use the BT_cont_type to estimate the
! relative weightings of the layers in calculating
! the barotropic accelerations.
logical :: Use_Stokes_PGF ! If true, add Stokes PGF to hydrostatic PGF
!---For group halo pass
logical :: showCallTree, sym
integer :: i, j, k, is, ie, js, je, Isq, Ieq, Jsq, Jeq, nz
integer :: cont_stencil, obc_stencil
is = G%isc ; ie = G%iec ; js = G%jsc ; je = G%jec ; nz = GV%ke
Isq = G%IscB ; Ieq = G%IecB ; Jsq = G%JscB ; Jeq = G%JecB
u_av => CS%u_av ; v_av => CS%v_av ; h_av => CS%h_av ; eta => CS%eta
Idt_bc = 1.0 / dt
sym = G%Domain%symmetric ! switch to include symmetric domain in checksums
showCallTree = callTree_showQuery()
if (showCallTree) call callTree_enter("step_MOM_dyn_split_RK2(), MOM_dynamics_split_RK2.F90")
!$OMP parallel do default(shared)
do k=1,nz
do j=G%jsd,G%jed ; do i=G%isdB,G%iedB ; up(i,j,k) = 0.0 ; enddo ; enddo
do j=G%jsdB,G%jedB ; do i=G%isd,G%ied ; vp(i,j,k) = 0.0 ; enddo ; enddo
do j=G%jsd,G%jed ; do i=G%isd,G%ied ; hp(i,j,k) = h(i,j,k) ; enddo ; enddo
enddo
! Update CFL truncation value as function of time
call updateCFLtruncationValue(Time_local, CS%vertvisc_CSp, US)
if (CS%debug) then
call query_debugging_checks(do_redundant=debug_redundant)
call MOM_state_chksum("Start predictor ", u_inst, v_inst, h, uh, vh, G, GV, US, symmetric=sym)
if (debug_redundant) then
call check_redundant("Start predictor u ", u_inst, v_inst, G, unscale=US%L_T_to_m_s)
call check_redundant("Start predictor uh ", uh, vh, G, unscale=GV%H_to_MKS*US%L_to_m**2*US%s_to_T)
endif
endif
dyn_p_surf = associated(p_surf_begin) .and. associated(p_surf_end)
if (dyn_p_surf) then
p_surf => p_surf_end
call safe_alloc_ptr(eta_PF_start,G%isd,G%ied,G%jsd,G%jed)
eta_PF_start(:,:) = 0.0
else
p_surf => forces%p_surf
endif
if (associated(CS%OBC)) then
if (CS%debug_OBC) call open_boundary_test_extern_h(G, GV, CS%OBC, h)
! Update OBC ramp value as function of time
call update_OBC_ramp(Time_local, CS%OBC, US)
do k=1,nz ; do j=G%jsd,G%jed ; do I=G%IsdB,G%IedB
u_old_rad_OBC(I,j,k) = u_av(I,j,k)
enddo ; enddo ; enddo
do k=1,nz ; do J=G%JsdB,G%JedB ; do i=G%isd,G%ied
v_old_rad_OBC(i,J,k) = v_av(i,J,k)
enddo ; enddo ; enddo
endif
BT_cont_BT_thick = .false.
if (associated(CS%BT_cont)) BT_cont_BT_thick = &
(allocated(CS%BT_cont%h_u) .and. allocated(CS%BT_cont%h_v))
if (CS%split_bottom_stress) then
taux_bot => CS%taux_bot ; tauy_bot => CS%tauy_bot
endif
!--- begin set up for group halo pass
cont_stencil = continuity_stencil(CS%continuity_CSp)
obc_stencil = 2
if (associated(CS%OBC)) then
if (CS%OBC%oblique_BCs_exist_globally) obc_stencil = 3
endif
call cpu_clock_begin(id_clock_pass)
call create_group_pass(CS%pass_eta, eta, G%Domain, halo=1)
call create_group_pass(CS%pass_visc_rem, CS%visc_rem_u, CS%visc_rem_v, G%Domain, &
To_All+SCALAR_PAIR, CGRID_NE, halo=max(1,cont_stencil))
call create_group_pass(CS%pass_uvp, up, vp, G%Domain, halo=max(1,cont_stencil))
call create_group_pass(CS%pass_hp_uv, hp, G%Domain, halo=2)
call create_group_pass(CS%pass_hp_uv, u_av, v_av, G%Domain, halo=max(2,obc_stencil))
call create_group_pass(CS%pass_hp_uv, uh(:,:,:), vh(:,:,:), G%Domain, halo=max(2,obc_stencil))
call create_group_pass(CS%pass_uv, u_inst, v_inst, G%Domain, halo=max(2,cont_stencil))
call create_group_pass(CS%pass_h, h, G%Domain, halo=max(2,cont_stencil))
call create_group_pass(CS%pass_av_uvh, u_av, v_av, G%Domain, halo=max(2,obc_stencil))
call create_group_pass(CS%pass_av_uvh, uh(:,:,:), vh(:,:,:), G%Domain, halo=max(2,obc_stencil))
call cpu_clock_end(id_clock_pass)
!--- end set up for group halo pass
! PFu = d/dx M(h,T,S)
! pbce = dM/deta
if (CS%begw == 0.0) call enable_averages(dt, Time_local, CS%diag)
call cpu_clock_begin(id_clock_pres)
call PressureForce(h, tv, CS%PFu, CS%PFv, G, GV, US, CS%PressureForce_CSp, &
CS%ALE_CSp, p_surf, CS%pbce, CS%eta_PF)
if (dyn_p_surf) then
pres_to_eta = 1.0 / (GV%g_Earth * GV%H_to_RZ)
!$OMP parallel do default(shared)
do j=Jsq,Jeq+1 ; do i=Isq,Ieq+1
eta_PF_start(i,j) = CS%eta_PF(i,j) - pres_to_eta * (p_surf_begin(i,j) - p_surf_end(i,j))
enddo ; enddo
endif
! Stokes shear force contribution to pressure gradient
Use_Stokes_PGF = present(Waves)
if (Use_Stokes_PGF) then
Use_Stokes_PGF = associated(Waves)
if (Use_Stokes_PGF) Use_Stokes_PGF = Waves%Stokes_PGF
if (Use_Stokes_PGF) then
call thickness_to_dz(h, tv, dz, G, GV, US, halo_size=1)
call Stokes_PGF(G, GV, US, dz, u_inst, v_inst, CS%PFu_Stokes, CS%PFv_Stokes, Waves)
! We are adding Stokes_PGF to hydrostatic PGF here. The diag PFu/PFv
! will therefore report the sum total PGF and we avoid other
! modifications in the code. The PFu_Stokes is output within the waves routines.
if (.not.Waves%Passive_Stokes_PGF) then
do k=1,nz
do j=js,je ; do I=Isq,Ieq
CS%PFu(I,j,k) = CS%PFu(I,j,k) + CS%PFu_Stokes(I,j,k)
enddo ; enddo
enddo
do k=1,nz
do J=Jsq,Jeq ; do i=is,ie
CS%PFv(i,J,k) = CS%PFv(i,J,k) + CS%PFv_Stokes(i,J,k)
enddo ; enddo
enddo
endif
endif
endif
call cpu_clock_end(id_clock_pres)
call disable_averaging(CS%diag)
if (showCallTree) call callTree_wayPoint("done with PressureForce (step_MOM_dyn_split_RK2)")
if (associated(CS%OBC)) then ; if (CS%OBC%update_OBC) then
call update_OBC_data(CS%OBC, G, GV, US, tv, h, CS%update_OBC_CSp, Time_local)
endif ; endif
if (associated(CS%OBC) .and. CS%debug_OBC) &
call open_boundary_zero_normal_flow(CS%OBC, G, GV, CS%PFu, CS%PFv)
if (G%nonblocking_updates) &
call start_group_pass(CS%pass_eta, G%Domain, clock=id_clock_pass)
! CAu = -(f+zeta_av)/h_av vh + d/dx KE_av
if (.not.CS%CAu_pred_stored) then
! Calculate a predictor-step estimate of the Coriolis and momentum advection terms,
! if it was not already stored from the end of the previous time step.
call cpu_clock_begin(id_clock_Cor)
call CorAdCalc(u_av, v_av, h_av, uh, vh, CS%CAu_pred, CS%CAv_pred, CS%OBC, CS%AD_pred, &
G, GV, US, CS%CoriolisAdv, pbv, Waves=Waves)
call cpu_clock_end(id_clock_Cor)
if (showCallTree) call callTree_wayPoint("done with CorAdCalc (step_MOM_dyn_split_RK2)")
endif
! u_bc_accel = CAu + PFu + diffu(u[n-1])
call cpu_clock_begin(id_clock_btforce)
!$OMP parallel do default(shared)
do k=1,nz
do j=js,je ; do I=Isq,Ieq
u_bc_accel(I,j,k) = (CS%CAu_pred(I,j,k) + CS%PFu(I,j,k)) + CS%diffu(I,j,k)
enddo ; enddo
do J=Jsq,Jeq ; do i=is,ie
v_bc_accel(i,J,k) = (CS%CAv_pred(i,J,k) + CS%PFv(i,J,k)) + CS%diffv(i,J,k)
enddo ; enddo
enddo
if (associated(CS%OBC)) then
call open_boundary_zero_normal_flow(CS%OBC, G, GV, u_bc_accel, v_bc_accel)
endif
call cpu_clock_end(id_clock_btforce)
if (CS%debug) then
call MOM_accel_chksum("pre-btstep accel", CS%CAu_pred, CS%CAv_pred, CS%PFu, CS%PFv, &
CS%diffu, CS%diffv, G, GV, US, CS%pbce, u_bc_accel, v_bc_accel, &
symmetric=sym)
if (debug_redundant) then
call check_redundant("pre-btstep CS%CA ", CS%CAu_pred, CS%CAv_pred, G, unscale=US%L_T2_to_m_s2)
call check_redundant("pre-btstep CS%PF ", CS%PFu, CS%PFv, G, unscale=US%L_T2_to_m_s2)
call check_redundant("pre-btstep CS%diff ", CS%diffu, CS%diffv, G, unscale=US%L_T2_to_m_s2)
call check_redundant("pre-btstep u_bc_accel ", u_bc_accel, v_bc_accel, G, unscale=US%L_T2_to_m_s2)
endif
endif
call cpu_clock_begin(id_clock_vertvisc)
!$OMP parallel do default(shared)
do k=1,nz
do j=js,je ; do I=Isq,Ieq
up(I,j,k) = G%mask2dCu(I,j) * (u_inst(I,j,k) + dt * u_bc_accel(I,j,k))
enddo ; enddo
do J=Jsq,Jeq ; do i=is,ie
vp(i,J,k) = G%mask2dCv(i,J) * (v_inst(i,J,k) + dt * v_bc_accel(i,J,k))
enddo ; enddo
enddo
call enable_averages(dt, Time_local, CS%diag)
call set_viscous_ML(u_inst, v_inst, h, tv, forces, visc, dt, G, GV, US, CS%set_visc_CSp)
call disable_averaging(CS%diag)
if (CS%debug) then
call uvchksum("before vertvisc: up", up, vp, G%HI, haloshift=0, symmetric=sym, unscale=US%L_T_to_m_s)
endif
call thickness_to_dz(h, tv, dz, G, GV, US, halo_size=1)
call vertvisc_coef(up, vp, h, dz, forces, visc, tv, dt, G, GV, US, CS%vertvisc_CSp, CS%OBC, VarMix)
call vertvisc_remnant(visc, CS%visc_rem_u, CS%visc_rem_v, dt, G, GV, US, CS%vertvisc_CSp)
call cpu_clock_end(id_clock_vertvisc)
if (showCallTree) call callTree_wayPoint("done with vertvisc_coef (step_MOM_dyn_split_RK2)")
call cpu_clock_begin(id_clock_pass)
if (G%nonblocking_updates) then
call complete_group_pass(CS%pass_eta, G%Domain)
call start_group_pass(CS%pass_visc_rem, G%Domain)
else
call do_group_pass(CS%pass_eta, G%Domain)
call do_group_pass(CS%pass_visc_rem, G%Domain)
endif
call cpu_clock_end(id_clock_pass)
call cpu_clock_begin(id_clock_btcalc)
! Calculate the relative layer weights for determining barotropic quantities.
if (.not.BT_cont_BT_thick) &
call btcalc(h, G, GV, CS%barotropic_CSp, OBC=CS%OBC)
call bt_mass_source(h, eta, .true., G, GV, CS%barotropic_CSp)
SpV_avg(:,:) = 0.0
if ((.not.GV%Boussinesq) .and. associated(CS%OBC)) then
! Determine the column average specific volume if it is needed due to the
! use of Flather open boundary conditions in non-Boussinesq mode.
if (open_boundary_query(CS%OBC, apply_Flather_OBC=.true.)) &
call find_col_avg_SpV(h, SpV_avg, tv, G, GV, US)
endif
call cpu_clock_end(id_clock_btcalc)
if (G%nonblocking_updates) &
call complete_group_pass(CS%pass_visc_rem, G%Domain, clock=id_clock_pass)
! u_accel_bt = layer accelerations due to barotropic solver
if (associated(CS%BT_cont) .or. CS%BT_use_layer_fluxes) then
call cpu_clock_begin(id_clock_continuity)
call continuity(u_inst, v_inst, h, hp, uh_in, vh_in, dt, G, GV, US, CS%continuity_CSp, CS%OBC, pbv, &
visc_rem_u=CS%visc_rem_u, visc_rem_v=CS%visc_rem_v, BT_cont=CS%BT_cont)
call cpu_clock_end(id_clock_continuity)
if (BT_cont_BT_thick) then
call btcalc(h, G, GV, CS%barotropic_CSp, CS%BT_cont%h_u, CS%BT_cont%h_v, &
OBC=CS%OBC)
endif
if (showCallTree) call callTree_wayPoint("done with continuity[BT_cont] (step_MOM_dyn_split_RK2)")
endif
if (CS%BT_use_layer_fluxes) then
uh_ptr => uh_in ; vh_ptr => vh_in; u_ptr => u_inst ; v_ptr => v_inst
endif
call cpu_clock_begin(id_clock_btstep)
if (calc_dtbt) call set_dtbt(G, GV, US, CS%barotropic_CSp, eta, CS%pbce)
if (showCallTree) call callTree_enter("btstep(), MOM_barotropic.F90")
! This is the predictor step call to btstep.
! The CS%ADp argument here stores the weights for certain integrated diagnostics.
call btstep(u_inst, v_inst, eta, dt, u_bc_accel, v_bc_accel, forces, CS%pbce, CS%eta_PF, u_av, v_av, &
CS%u_accel_bt, CS%v_accel_bt, eta_pred, CS%uhbt, CS%vhbt, G, GV, US, &
CS%barotropic_CSp, CS%visc_rem_u, CS%visc_rem_v, SpV_avg, CS%ADp, CS%OBC, CS%BT_cont, &
eta_PF_start, taux_bot, tauy_bot, uh_ptr, vh_ptr, u_ptr, v_ptr)
if (showCallTree) call callTree_leave("btstep()")
call cpu_clock_end(id_clock_btstep)
! up = u + dt_pred*( u_bc_accel + u_accel_bt )
dt_pred = dt * CS%be
call cpu_clock_begin(id_clock_mom_update)
!$OMP parallel do default(shared)
do k=1,nz
do J=Jsq,Jeq ; do i=is,ie
vp(i,J,k) = G%mask2dCv(i,J) * (v_inst(i,J,k) + dt_pred * &
(v_bc_accel(i,J,k) + CS%v_accel_bt(i,J,k)))
enddo ; enddo
do j=js,je ; do I=Isq,Ieq
up(I,j,k) = G%mask2dCu(I,j) * (u_inst(I,j,k) + dt_pred * &
(u_bc_accel(I,j,k) + CS%u_accel_bt(I,j,k)))
enddo ; enddo
enddo
call cpu_clock_end(id_clock_mom_update)
if (CS%debug) then
call uvchksum("Predictor 1 [uv]", up, vp, G%HI, haloshift=0, symmetric=sym, unscale=US%L_T_to_m_s)
call hchksum(h, "Predictor 1 h", G%HI, haloshift=1, unscale=GV%H_to_MKS)
call uvchksum("Predictor 1 [uv]h", uh, vh, G%HI,haloshift=2, &
symmetric=sym, unscale=GV%H_to_MKS*US%L_to_m**2*US%s_to_T)
! call MOM_state_chksum("Predictor 1", up, vp, h, uh, vh, G, GV, US, haloshift=1)
call MOM_accel_chksum("Predictor accel", CS%CAu_pred, CS%CAv_pred, CS%PFu, CS%PFv, &
CS%diffu, CS%diffv, G, GV, US, CS%pbce, CS%u_accel_bt, CS%v_accel_bt, symmetric=sym)
call MOM_state_chksum("Predictor 1 init", u_inst, v_inst, h, uh, vh, G, GV, US, haloshift=1, &
symmetric=sym)
if (debug_redundant) then
call check_redundant("Predictor 1 up", up, vp, G, unscale=US%L_T_to_m_s)
call check_redundant("Predictor 1 uh", uh, vh, G, unscale=GV%H_to_MKS*US%L_to_m**2*US%s_to_T)
endif
endif
! up <- up + dt_pred d/dz visc d/dz up
! u_av <- u_av + dt_pred d/dz visc d/dz u_av
call cpu_clock_begin(id_clock_vertvisc)
if (CS%debug) then
call uvchksum("0 before vertvisc: [uv]p", up, vp, G%HI,haloshift=0, symmetric=sym, unscale=US%L_T_to_m_s)
endif
if (CS%fpmix) then
uold(:,:,:) = 0.0
vold(:,:,:) = 0.0
do k = 1, nz
do j = js , je
do I = Isq, Ieq
uold(I,j,k) = up(I,j,k)
enddo
enddo
do J = Jsq, Jeq
do i = is, ie
vold(i,J,k) = vp(i,J,k)
enddo
enddo
enddo
endif
call thickness_to_dz(h, tv, dz, G, GV, US, halo_size=1)
call vertvisc_coef(up, vp, h, dz, forces, visc, tv, dt_pred, G, GV, US, CS%vertvisc_CSp, &
CS%OBC, VarMix)
call vertvisc(up, vp, h, forces, visc, dt_pred, CS%OBC, CS%AD_pred, CS%CDp, G, &
GV, US, CS%vertvisc_CSp, CS%taux_bot, CS%tauy_bot, waves=waves)
if (CS%fpmix) then
hbl(:,:) = 0.0
if (associated(visc%h_ML)) hbl(:,:) = visc%h_ML(:,:)
call vertFPmix(up, vp, uold, vold, hbl, h, forces, &
dt_pred, G, GV, US, CS%vertvisc_CSp, CS%OBC)
call vertvisc(up, vp, h, forces, visc, dt_pred, CS%OBC, CS%ADp, CS%CDp, G, &
GV, US, CS%vertvisc_CSp, CS%taux_bot, CS%tauy_bot, waves=waves)
endif
if (showCallTree) call callTree_wayPoint("done with vertvisc (step_MOM_dyn_split_RK2)")
if (G%nonblocking_updates) then
call cpu_clock_end(id_clock_vertvisc)
call start_group_pass(CS%pass_uvp, G%Domain, clock=id_clock_pass)
call cpu_clock_begin(id_clock_vertvisc)
endif
if (CS%visc_rem_dt_bug) then
call vertvisc_remnant(visc, CS%visc_rem_u, CS%visc_rem_v, dt_pred, G, GV, US, CS%vertvisc_CSp)
else
call vertvisc_remnant(visc, CS%visc_rem_u, CS%visc_rem_v, dt, G, GV, US, CS%vertvisc_CSp)
endif
call cpu_clock_end(id_clock_vertvisc)
call do_group_pass(CS%pass_visc_rem, G%Domain, clock=id_clock_pass)
if (G%nonblocking_updates) then
call complete_group_pass(CS%pass_uvp, G%Domain, clock=id_clock_pass)
else
call do_group_pass(CS%pass_uvp, G%Domain, clock=id_clock_pass)
endif
! uh = u_av * h
! hp = h + dt * div . uh
call cpu_clock_begin(id_clock_continuity)
call continuity(up, vp, h, hp, uh, vh, dt, G, GV, US, CS%continuity_CSp, CS%OBC, pbv, &
uhbt=CS%uhbt, vhbt=CS%vhbt, visc_rem_u=CS%visc_rem_u, visc_rem_v=CS%visc_rem_v, &
u_cor=u_av, v_cor=v_av, BT_cont=CS%BT_cont)
call cpu_clock_end(id_clock_continuity)
if (showCallTree) call callTree_wayPoint("done with continuity (step_MOM_dyn_split_RK2)")
call do_group_pass(CS%pass_hp_uv, G%Domain, clock=id_clock_pass)
if (associated(CS%OBC)) then
if (CS%debug) &
call uvchksum("Pre OBC avg [uv]", u_av, v_av, G%HI, haloshift=1, symmetric=sym, unscale=US%L_T_to_m_s)
call radiation_open_bdry_conds(CS%OBC, u_av, u_old_rad_OBC, v_av, v_old_rad_OBC, G, GV, US, dt_pred)
if (CS%debug) &
call uvchksum("Post OBC avg [uv]", u_av, v_av, G%HI, haloshift=1, symmetric=sym, unscale=US%L_T_to_m_s)
! These should be done with a pass that excludes uh & vh.
! call do_group_pass(CS%pass_hp_uv, G%Domain, clock=id_clock_pass)
endif
if (G%nonblocking_updates) then
call start_group_pass(CS%pass_av_uvh, G%Domain, clock=id_clock_pass)
endif
! h_av = (h + hp)/2
!$OMP parallel do default(shared)
do k=1,nz ; do j=js-2,je+2 ; do i=is-2,ie+2
h_av(i,j,k) = 0.5*(h(i,j,k) + hp(i,j,k))
enddo ; enddo ; enddo
! The correction phase of the time step starts here.
call enable_averages(dt, Time_local, CS%diag)
! Calculate a revised estimate of the free-surface height correction to be
! used in the next call to btstep. This call is at this point so that
! hp can be changed if CS%begw /= 0.
! eta_cor = ... (hidden inside CS%barotropic_CSp)
call cpu_clock_begin(id_clock_btcalc)
call bt_mass_source(hp, eta_pred, .false., G, GV, CS%barotropic_CSp)
call cpu_clock_end(id_clock_btcalc)
if (CS%begw /= 0.0) then
! hp <- (1-begw)*h_in + begw*hp
! Back up hp to the value it would have had after a time-step of
! begw*dt. hp is not used again until recalculated by continuity.
!$OMP parallel do default(shared)
do k=1,nz ; do j=js-1,je+1 ; do i=is-1,ie+1
hp(i,j,k) = (1.0-CS%begw)*h(i,j,k) + CS%begw*hp(i,j,k)
enddo ; enddo ; enddo
! PFu = d/dx M(hp,T,S)
! pbce = dM/deta
call cpu_clock_begin(id_clock_pres)
call PressureForce(hp, tv, CS%PFu, CS%PFv, G, GV, US, CS%PressureForce_CSp, &
CS%ALE_CSp, p_surf, CS%pbce, CS%eta_PF)
! Stokes shear force contribution to pressure gradient
Use_Stokes_PGF = present(Waves)
if (Use_Stokes_PGF) then
Use_Stokes_PGF = associated(Waves)
if (Use_Stokes_PGF) Use_Stokes_PGF = Waves%Stokes_PGF
if (Use_Stokes_PGF) then
call thickness_to_dz(h, tv, dz, G, GV, US, halo_size=1)
call Stokes_PGF(G, GV, US, dz, u_inst, v_inst, CS%PFu_Stokes, CS%PFv_Stokes, Waves)
if (.not.Waves%Passive_Stokes_PGF) then
do k=1,nz
do j=js,je ; do I=Isq,Ieq
CS%PFu(I,j,k) = CS%PFu(I,j,k) + CS%PFu_Stokes(I,j,k)
enddo ; enddo
enddo
do k=1,nz
do J=Jsq,Jeq ; do i=is,ie
CS%PFv(i,J,k) = CS%PFv(i,J,k) + CS%PFv_Stokes(i,J,k)
enddo ; enddo
enddo
endif
endif
endif
call cpu_clock_end(id_clock_pres)
if (showCallTree) call callTree_wayPoint("done with PressureForce[hp=(1-b).h+b.h] (step_MOM_dyn_split_RK2)")
endif
if (G%nonblocking_updates) &
call complete_group_pass(CS%pass_av_uvh, G%Domain, clock=id_clock_pass)
if (BT_cont_BT_thick) then
call btcalc(h, G, GV, CS%barotropic_CSp, CS%BT_cont%h_u, CS%BT_cont%h_v, &
OBC=CS%OBC)
if (showCallTree) call callTree_wayPoint("done with btcalc[BT_cont_BT_thick] (step_MOM_dyn_split_RK2)")
endif
if (CS%debug) then
call MOM_state_chksum("Predictor ", up, vp, hp, uh, vh, G, GV, US, symmetric=sym)
call uvchksum("Predictor avg [uv]", u_av, v_av, G%HI, haloshift=1, symmetric=sym, unscale=US%L_T_to_m_s)
call hchksum(h_av, "Predictor avg h", G%HI, haloshift=2, unscale=GV%H_to_MKS)
! call MOM_state_chksum("Predictor avg ", u_av, v_av, h_av, uh, vh, G, GV, US)
if (debug_redundant) then
call check_redundant("Predictor up ", up, vp, G, unscale=US%L_T_to_m_s)
call check_redundant("Predictor uh ", uh, vh, G, unscale=GV%H_to_MKS*US%L_to_m**2*US%s_to_T)
endif
endif
! diffu = horizontal viscosity terms (u_av)
call cpu_clock_begin(id_clock_horvisc)
call horizontal_viscosity(u_av, v_av, h_av, uh, vh, CS%diffu, CS%diffv, &
MEKE, Varmix, G, GV, US, CS%hor_visc, tv, dt, &
OBC=CS%OBC, BT=CS%barotropic_CSp, TD=thickness_diffuse_CSp, &
ADp=CS%ADp, hu_cont=CS%BT_cont%h_u, hv_cont=CS%BT_cont%h_v)
call cpu_clock_end(id_clock_horvisc)
if (showCallTree) call callTree_wayPoint("done with horizontal_viscosity (step_MOM_dyn_split_RK2)")
! CAu = -(f+zeta_av)/h_av vh + d/dx KE_av
call cpu_clock_begin(id_clock_Cor)
call CorAdCalc(u_av, v_av, h_av, uh, vh, CS%CAu, CS%CAv, CS%OBC, CS%ADp, &
G, GV, US, CS%CoriolisAdv, pbv, Waves=Waves)
call cpu_clock_end(id_clock_Cor)
if (showCallTree) call callTree_wayPoint("done with CorAdCalc (step_MOM_dyn_split_RK2)")
! Calculate the momentum forcing terms for the barotropic equations.
! u_bc_accel = CAu + PFu + diffu(u[n-1])
call cpu_clock_begin(id_clock_btforce)
!$OMP parallel do default(shared)
do k=1,nz
do j=js,je ; do I=Isq,Ieq
u_bc_accel(I,j,k) = (CS%Cau(I,j,k) + CS%PFu(I,j,k)) + CS%diffu(I,j,k)
enddo ; enddo
do J=Jsq,Jeq ; do i=is,ie
v_bc_accel(i,J,k) = (CS%Cav(i,J,k) + CS%PFv(i,J,k)) + CS%diffv(i,J,k)
enddo ; enddo
enddo
if (associated(CS%OBC)) then
call open_boundary_zero_normal_flow(CS%OBC, G, GV, u_bc_accel, v_bc_accel)
endif
call cpu_clock_end(id_clock_btforce)
if (CS%debug) then
call MOM_accel_chksum("corr pre-btstep accel", CS%CAu, CS%CAv, CS%PFu, CS%PFv, &
CS%diffu, CS%diffv, G, GV, US, CS%pbce, u_bc_accel, v_bc_accel, &
symmetric=sym)
if (debug_redundant) then
call check_redundant("corr pre-btstep CS%CA ", CS%CAu, CS%CAv, G, unscale=US%L_T2_to_m_s2)
call check_redundant("corr pre-btstep CS%PF ", CS%PFu, CS%PFv, G, unscale=US%L_T2_to_m_s2)
call check_redundant("corr pre-btstep CS%diff ", CS%diffu, CS%diffv, G, unscale=US%L_T2_to_m_s2)
call check_redundant("corr pre-btstep u_bc_accel ", u_bc_accel, v_bc_accel, G, unscale=US%L_T2_to_m_s2)
endif
endif
! u_accel_bt = layer accelerations due to barotropic solver
! pbce = dM/deta
call cpu_clock_begin(id_clock_btstep)
if (CS%BT_use_layer_fluxes) then
uh_ptr => uh ; vh_ptr => vh ; u_ptr => u_av ; v_ptr => v_av
endif
if (showCallTree) call callTree_enter("btstep(), MOM_barotropic.F90")
! This is the corrector step call to btstep.
call btstep(u_inst, v_inst, eta, dt, u_bc_accel, v_bc_accel, forces, CS%pbce, CS%eta_PF, u_av, v_av, &
CS%u_accel_bt, CS%v_accel_bt, eta_pred, CS%uhbt, CS%vhbt, G, GV, US, &
CS%barotropic_CSp, CS%visc_rem_u, CS%visc_rem_v, SpV_avg, CS%ADp, CS%OBC, CS%BT_cont, &
eta_PF_start, taux_bot, tauy_bot, uh_ptr, vh_ptr, u_ptr, v_ptr, etaav=eta_av)
if (CS%id_deta_dt>0) then
do j=js,je ; do i=is,ie ; deta_dt(i,j) = (eta_pred(i,j) - eta(i,j))*Idt_bc ; enddo ; enddo
endif
do j=js,je ; do i=is,ie ; eta(i,j) = eta_pred(i,j) ; enddo ; enddo
call cpu_clock_end(id_clock_btstep)
if (showCallTree) call callTree_leave("btstep()")
if (CS%debug .and. debug_redundant) then
call check_redundant("u_accel_bt ", CS%u_accel_bt, CS%v_accel_bt, G, unscale=US%L_T2_to_m_s2)
endif
! u = u + dt*( u_bc_accel + u_accel_bt )
call cpu_clock_begin(id_clock_mom_update)
!$OMP parallel do default(shared)
do k=1,nz
do j=js,je ; do I=Isq,Ieq
u_inst(I,j,k) = G%mask2dCu(I,j) * (u_inst(I,j,k) + dt * &
(u_bc_accel(I,j,k) + CS%u_accel_bt(I,j,k)))
enddo ; enddo
do J=Jsq,Jeq ; do i=is,ie
v_inst(i,J,k) = G%mask2dCv(i,J) * (v_inst(i,J,k) + dt * &
(v_bc_accel(i,J,k) + CS%v_accel_bt(i,J,k)))
enddo ; enddo
enddo
call cpu_clock_end(id_clock_mom_update)
if (CS%debug) then
call uvchksum("Corrector 1 [uv]", u_inst, v_inst, G%HI, haloshift=0, symmetric=sym, unscale=US%L_T_to_m_s)
call hchksum(h, "Corrector 1 h", G%HI, haloshift=1, unscale=GV%H_to_MKS)
call uvchksum("Corrector 1 [uv]h", uh, vh, G%HI, haloshift=2, &
symmetric=sym, unscale=GV%H_to_MKS*US%L_to_m**2*US%s_to_T)
! call MOM_state_chksum("Corrector 1", u_inst, v_inst, h, uh, vh, G, GV, US, haloshift=1)
call MOM_accel_chksum("Corrector accel", CS%CAu, CS%CAv, CS%PFu, CS%PFv, &
CS%diffu, CS%diffv, G, GV, US, CS%pbce, CS%u_accel_bt, CS%v_accel_bt, &
symmetric=sym)
endif
! u <- u + dt d/dz visc d/dz u
! u_av <- u_av + dt d/dz visc d/dz u_av
call cpu_clock_begin(id_clock_vertvisc)
if (CS%fpmix) then
uold(:,:,:) = 0.0
vold(:,:,:) = 0.0
do k = 1, nz
do j = js , je
do I = Isq, Ieq
uold(I,j,k) = u_inst(I,j,k)
enddo
enddo
do J = Jsq, Jeq
do i = is, ie
vold(i,J,k) = v_inst(i,J,k)
enddo
enddo
enddo
endif
call thickness_to_dz(h, tv, dz, G, GV, US, halo_size=1)
call vertvisc_coef(u_inst, v_inst, h, dz, forces, visc, tv, dt, G, GV, US, CS%vertvisc_CSp, CS%OBC, VarMix)
call vertvisc(u_inst, v_inst, h, forces, visc, dt, CS%OBC, CS%ADp, CS%CDp, G, GV, US, &
CS%vertvisc_CSp, CS%taux_bot, CS%tauy_bot,waves=waves)
if (CS%fpmix) then
call vertFPmix(u_inst, v_inst, uold, vold, hbl, h, forces, dt, &
G, GV, US, CS%vertvisc_CSp, CS%OBC)
call vertvisc(u_inst, v_inst, h, forces, visc, dt, CS%OBC, CS%ADp, CS%CDp, G, GV, US, &
CS%vertvisc_CSp, CS%taux_bot, CS%tauy_bot, waves=waves)
endif
if (G%nonblocking_updates) then
call cpu_clock_end(id_clock_vertvisc)
call start_group_pass(CS%pass_uv, G%Domain, clock=id_clock_pass)
call cpu_clock_begin(id_clock_vertvisc)
endif
call vertvisc_remnant(visc, CS%visc_rem_u, CS%visc_rem_v, dt, G, GV, US, CS%vertvisc_CSp)
call cpu_clock_end(id_clock_vertvisc)
if (showCallTree) call callTree_wayPoint("done with vertvisc (step_MOM_dyn_split_RK2)")
! Later, h_av = (h_in + h_out)/2, but for now use h_av to store h_in.
!$OMP parallel do default(shared)