Skip to content

Commit 09774d4

Browse files
herrwang0marshallward
authored andcommitted
Use Adcroft_reciprocal for Iwt_[uv]_tot
* Correct a bug using dimensional h_neglect in calculating non-dimensional Iwt_[uv]_tot, by replacing the division with an Adcroft_reciprocal style division. * Add a parameter VISC_REM_BUG to control the defaults of all three viscous remnant bug related parameters. The individual parameters should be removed in the future.
1 parent 1d2911f commit 09774d4

4 files changed

+30
-8
lines changed

src/core/MOM_barotropic.F90

+7-4
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ subroutine btstep(U_in, V_in, eta_in, dt, bc_accel_u, bc_accel_v, forces, pbce,
10621062
Iwt_u_tot(I,j) = Iwt_u_tot(I,j) + wt_u(I,j,k)
10631063
enddo ; enddo ; enddo
10641064
do j=js,je ; do I=is-1,ie
1065-
Iwt_u_tot(I,j) = G%mask2dCu(I,j) / (Iwt_u_tot(I,j) + h_neglect)
1065+
if (abs(Iwt_u_tot(I,j)) > 0.0 ) Iwt_u_tot(I,j) = G%mask2dCu(I,j) / Iwt_u_tot(I,j)
10661066
enddo ; enddo
10671067
do k=1,nz ; do j=js,je ; do I=is-1,ie
10681068
wt_u(I,j,k) = wt_u(I,j,k) * Iwt_u_tot(I,j)
@@ -1073,7 +1073,7 @@ subroutine btstep(U_in, V_in, eta_in, dt, bc_accel_u, bc_accel_v, forces, pbce,
10731073
Iwt_v_tot(i,J) = Iwt_v_tot(i,J) + wt_v(i,J,k)
10741074
enddo ; enddo ; enddo
10751075
do J=js-1,je ; do i=is,ie
1076-
Iwt_v_tot(i,J) = G%mask2dCv(i,J) / (Iwt_v_tot(i,J) + h_neglect)
1076+
if (abs(Iwt_v_tot(i,J)) > 0.0 ) Iwt_v_tot(i,J) = G%mask2dCv(i,J) / Iwt_v_tot(i,J)
10771077
enddo ; enddo
10781078
do k=1,nz ; do J=js-1,je ; do i=is,ie
10791079
wt_v(i,J,k) = wt_v(i,J,k) * Iwt_v_tot(i,J)
@@ -4464,6 +4464,7 @@ subroutine barotropic_init(u, v, h, eta, Time, G, GV, US, param_file, diag, CS,
44644464
integer :: default_answer_date ! The default setting for the various ANSWER_DATE flags.
44654465
logical :: use_BT_cont_type
44664466
logical :: use_tides
4467+
logical :: visc_rem_bug ! Stores the value of runtime paramter VISC_REM_BUG.
44674468
character(len=48) :: thickness_units, flux_units
44684469
character*(40) :: hvel_str
44694470
integer :: is, ie, js, je, Isq, Ieq, Jsq, Jeq, nz
@@ -4612,10 +4613,12 @@ subroutine barotropic_init(u, v, h, eta, Time, G, GV, US, param_file, diag, CS,
46124613
default=default_answer_date, do_not_log=.not.GV%Boussinesq)
46134614
if (.not.GV%Boussinesq) CS%answer_date = max(CS%answer_date, 20230701)
46144615

4616+
call get_param(param_file, mdl, "VISC_REM_BUG", visc_rem_bug, default=.true., do_not_log=.true.)
46154617
call get_param(param_file, mdl, "VISC_REM_BT_WEIGHT_FIX", CS%wt_uv_fix, &
46164618
"If true, use a normalized weight function for vertical averages of "//&
4617-
"baroclinic velocity and forcing. This flag should be used with "//&
4618-
"VISC_REM_TIMESTEP_FIX.", default=.false.)
4619+
"baroclinic velocity and forcing. Default of this flag is set by "//&
4620+
"VISC_REM_BUG. This flag should be used with VISC_REM_TIMESTEP_FIX.", &
4621+
default=.not.visc_rem_bug)
46194622
call get_param(param_file, mdl, "TIDES", use_tides, &
46204623
"If true, apply tidal momentum forcing.", default=.false.)
46214624
call get_param(param_file, mdl, "CALCULATE_SAL", CS%calculate_SAL, &

src/core/MOM_continuity_PPM.F90

+4-1
Original file line numberDiff line numberDiff line change
@@ -2713,6 +2713,7 @@ subroutine continuity_PPM_init(Time, G, GV, US, param_file, diag, CS)
27132713
!> This include declares and sets the variable "version".
27142714
# include "version_variable.h"
27152715
character(len=40) :: mdl = "MOM_continuity_PPM" ! This module's name.
2716+
logical :: visc_rem_bug ! Stores the value of runtime paramter VISC_REM_BUG.
27162717

27172718
CS%initialized = .true.
27182719

@@ -2773,9 +2774,11 @@ subroutine continuity_PPM_init(Time, G, GV, US, param_file, diag, CS)
27732774
"If true, use the marginal face areas from the continuity "//&
27742775
"solver for use as the weights in the barotropic solver. "//&
27752776
"Otherwise use the transport averaged areas.", default=.true.)
2777+
call get_param(param_file, mdl, "VISC_REM_BUG", visc_rem_bug, default=.true., do_not_log=.true.)
27762778
call get_param(param_file, mdl, "VISC_REM_CONT_HVEL_FIX", CS%visc_rem_hvel_fix, &
27772779
"If true, velocity cell thickness h_[uv] from the continuity solver "//&
2778-
"is not multiplied by visc_rem_[uv].", default=.false.)
2780+
"is not multiplied by visc_rem_[uv]. Default of this flag is set by "//&
2781+
"VISC_REM_BUG.", default=.not.visc_rem_bug)
27792782
CS%diag => diag
27802783

27812784
id_clock_reconstruct = cpu_clock_id('(Ocean continuity reconstruction)', grain=CLOCK_ROUTINE)

src/core/MOM_dynamics_split_RK2.F90

+9-1
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,7 @@ subroutine initialize_dyn_split_RK2(u, v, h, tv, uh, vh, eta, Time, G, GV, US, p
13531353
type(group_pass_type) :: pass_av_h_uvh
13541354
logical :: debug_truncations
13551355
logical :: read_uv, read_h2
1356+
logical :: visc_rem_bug ! Stores the value of runtime paramter VISC_REM_BUG.
13561357

13571358
integer :: i, j, k, is, ie, js, je, isd, ied, jsd, jed, nz
13581359
integer :: IsdB, IedB, JsdB, JedB
@@ -1420,11 +1421,18 @@ subroutine initialize_dyn_split_RK2(u, v, h, tv, uh, vh, eta, Time, G, GV, US, p
14201421
call get_param(param_file, mdl, "DEBUG_OBC", CS%debug_OBC, default=.false.)
14211422
call get_param(param_file, mdl, "DEBUG_TRUNCATIONS", debug_truncations, &
14221423
default=.false.)
1424+
call get_param(param_file, mdl, "VISC_REM_BUG", visc_rem_bug, &
1425+
"If true, visc_rem_[uv] in split mode is incorrectly calculated or accounted "//&
1426+
"for in three places. This parameter controls the defaults of three individual "//&
1427+
"flags, VISC_REM_TIMESTEP_FIX in MOM_dynamics_split_RK2(b), "//&
1428+
"VISC_REM_BT_WEIGHT_FIX in MOM_barotropic, and VISC_REM_CONT_HVEL_FIX in "//&
1429+
"MOM_continuity_PPM. Eventually, the three individual flags should be removed "//&
1430+
"after tests and the default of VISC_REM_BUG should be to False.", default=.true.)
14231431
call get_param(param_file, mdl, "VISC_REM_TIMESTEP_FIX", CS%visc_rem_dt_fix, &
14241432
"If true, use dt rather than dt_pred in vertvisc_remnant() at the end of "//&
14251433
"predictor stage for the following continuity() call and btstep() call "//&
14261434
"in the corrector step. This flag should be used with "//&
1427-
"VISC_REM_BT_WEIGHT_FIX.", default=.false.)
1435+
"VISC_REM_BT_WEIGHT_FIX.", default=.not.visc_rem_bug)
14281436

14291437
allocate(CS%taux_bot(IsdB:IedB,jsd:jed), source=0.0)
14301438
allocate(CS%tauy_bot(isd:ied,JsdB:JedB), source=0.0)

src/core/MOM_dynamics_split_RK2b.F90

+10-2
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,7 @@ subroutine initialize_dyn_split_RK2b(u, v, h, tv, uh, vh, eta, Time, G, GV, US,
12771277
character(len=48) :: thickness_units, flux_units, eta_rest_name
12781278
logical :: debug_truncations
12791279
logical :: read_uv, read_h2
1280+
logical :: visc_rem_bug ! Stores the value of runtime paramter VISC_REM_BUG.
12801281

12811282
integer :: i, j, k, is, ie, js, je, isd, ied, jsd, jed, nz
12821283
integer :: IsdB, IedB, JsdB, JedB
@@ -1335,11 +1336,18 @@ subroutine initialize_dyn_split_RK2b(u, v, h, tv, uh, vh, eta, Time, G, GV, US,
13351336
call get_param(param_file, mdl, "DEBUG_OBC", CS%debug_OBC, default=.false.)
13361337
call get_param(param_file, mdl, "DEBUG_TRUNCATIONS", debug_truncations, &
13371338
default=.false.)
1339+
call get_param(param_file, mdl, "VISC_REM_BUG", visc_rem_bug, &
1340+
"If true, visc_rem_[uv] in split mode is incorrectly calculated or accounted "//&
1341+
"for in three places. This parameter controls the defaults of three individual "//&
1342+
"flags, VISC_REM_TIMESTEP_FIX in MOM_dynamics_split_RK2(b), "//&
1343+
"VISC_REM_BT_WEIGHT_FIX in MOM_barotropic, and VISC_REM_CONT_HVEL_FIX in "//&
1344+
"MOM_continuity_PPM. Eventually, the three individual flags should be removed "//&
1345+
"after tests and the default of VISC_REM_BUG should be to False.", default=.true.)
13381346
call get_param(param_file, mdl, "VISC_REM_TIMESTEP_FIX", CS%visc_rem_dt_fix, &
13391347
"If true, use dt rather than dt_pred in vertvisc_remnant() at the end of "//&
13401348
"predictor stage for the following continuity() call and btstep() call "//&
1341-
"in the corrector step. This flag should be used with "//&
1342-
"VISC_REM_BT_WEIGHT_FIX.", default=.false.)
1349+
"in the corrector step. Default of this flag is set by VISC_REM_BUG. "//&
1350+
"This flag should be used with VISC_REM_BT_WEIGHT_FIX.", default=.not.visc_rem_bug)
13431351

13441352
allocate(CS%taux_bot(IsdB:IedB,jsd:jed), source=0.0)
13451353
allocate(CS%tauy_bot(isd:ied,JsdB:JedB), source=0.0)

0 commit comments

Comments
 (0)