Skip to content

Commit 1652246

Browse files
committed
Fix USE_CONT_THICKNESS bug
Optionally correct a bug due to a missing halo exchange. This likely isn't needed when compiled for nonsymmetric memory, but the added halo exchange does no harm in such cases. The pass_vector call could probably be replaced with fill_symmetric_edges, except there is no subroutine fill_vector_symmetric_edges_3d. USE_CONT_THICKNESS is not yet widely used, so rather than preserving the old (incorrect) solutions by default, this bug is corrected by default. However, the previous answers can be recovered by setting the new runtime parameter USE_CONT_THICKNESS_BUG to true. This parameter is only used (and logged) when USE_CONT_THICKNESS set to true. By default, this commit does change answers in symmetric memory cases with USE_CONT_THICKNESS = True, and there is a new runtime parameter in such cases.
1 parent 1b39d07 commit 1652246

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/parameterizations/lateral/MOM_hor_visc.F90

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ module MOM_hor_visc
123123
real :: min_grid_Ah !< Minimun horizontal biharmonic viscosity used to
124124
!! limit grid Reynolds number [L4 T-1 ~> m4 s-1]
125125
logical :: use_cont_thick !< If true, thickness at velocity points adopts h[uv] in BT_cont from continuity solver.
126+
logical :: use_cont_thick_bug !< If true, retain an answer-changing bug for thickness at velocity points.
126127
type(ZB2020_CS) :: ZB2020 !< Zanna-Bolton 2020 control structure.
127128
logical :: use_ZB2020 !< If true, use Zanna-Bolton 2020 parameterization.
128129

@@ -282,9 +283,9 @@ subroutine horizontal_viscosity(u, v, h, uh, vh, diffu, diffv, MEKE, VarMix, G,
282283
type(thickness_diffuse_CS), optional, intent(in) :: TD !< Thickness diffusion control structure
283284
type(accel_diag_ptrs), optional, intent(in) :: ADp !< Acceleration diagnostics
284285
real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)), &
285-
optional, intent(in) :: hu_cont !< Layer thickness at u-points [H ~> m or kg m-2].
286+
optional, intent(inout) :: hu_cont !< Layer thickness at u-points [H ~> m or kg m-2].
286287
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)), &
287-
optional, intent(in) :: hv_cont !< Layer thickness at v-points [H ~> m or kg m-2].
288+
optional, intent(inout) :: hv_cont !< Layer thickness at v-points [H ~> m or kg m-2].
288289

289290
! Local variables
290291
real, dimension(SZIB_(G),SZJ_(G)) :: &
@@ -477,6 +478,9 @@ subroutine horizontal_viscosity(u, v, h, uh, vh, diffu, diffv, MEKE, VarMix, G,
477478
use_MEKE_Au = allocated(MEKE%Au)
478479

479480
use_cont_huv = CS%use_cont_thick .and. present(hu_cont) .and. present(hv_cont)
481+
if (use_cont_huv .and. .not.CS%use_cont_thick_bug) then
482+
call pass_vector(hu_cont, hv_cont, G%domain, To_All+Scalar_Pair, halo=2)
483+
endif
480484

481485
rescale_Kh = .false.
482486
if (VarMix%use_variable_mixing) then
@@ -709,7 +713,14 @@ subroutine horizontal_viscosity(u, v, h, uh, vh, diffu, diffv, MEKE, VarMix, G,
709713
! in OBCs, which are not ordinarily be necessary, and might not be necessary
710714
! even with OBCs if the accelerations are zeroed at OBC points, in which
711715
! case the j-loop for h_u could collapse to j=js=1,je+1. -RWH
712-
if (CS%use_land_mask) then
716+
if (use_cont_huv) then
717+
do j=js-2,je+2 ; do I=Isq-1,Ieq+1
718+
h_u(I,j) = hu_cont(I,j,k)
719+
enddo ; enddo
720+
do J=Jsq-1,Jeq+1 ; do i=is-2,ie+2
721+
h_v(i,J) = hv_cont(i,J,k)
722+
enddo ; enddo
723+
elseif (CS%use_land_mask) then
713724
do j=js-2,je+2 ; do I=is-2,Ieq+1
714725
h_u(I,j) = 0.5 * (G%mask2dT(i,j)*h(i,j,k) + G%mask2dT(i+1,j)*h(i+1,j,k))
715726
enddo ; enddo
@@ -725,16 +736,6 @@ subroutine horizontal_viscosity(u, v, h, uh, vh, diffu, diffv, MEKE, VarMix, G,
725736
enddo ; enddo
726737
endif
727738

728-
! The following should obviously be combined with the previous block if adopted.
729-
if (use_cont_huv) then
730-
do j=js-2,je+2 ; do I=Isq-1,Ieq+1
731-
h_u(I,j) = hu_cont(I,j,k)
732-
enddo ; enddo
733-
do J=Jsq-1,Jeq+1 ; do i=is-2,ie+2
734-
h_v(i,J) = hv_cont(i,J,k)
735-
enddo ; enddo
736-
endif
737-
738739
! Adjust contributions to shearing strain and interpolated values of
739740
! thicknesses on open boundaries.
740741
if (apply_OBC) then ; do n=1,OBC%number_of_segments
@@ -2140,6 +2141,11 @@ subroutine hor_visc_init(Time, G, GV, US, param_file, diag, CS, ADp)
21402141
call get_param(param_file, mdl, "USE_CONT_THICKNESS", CS%use_cont_thick, &
21412142
"If true, use thickness at velocity points from continuity solver. This option "//&
21422143
"currently only works with split mode.", default=.false.)
2144+
call get_param(param_file, mdl, "USE_CONT_THICKNESS_BUG", CS%use_cont_thick_bug, &
2145+
"If true, retain an answer-changing halo update bug when "//&
2146+
"USE_CONT_THICKNESS=True. This is not recommended.", &
2147+
default=.false., do_not_log=.not.CS%use_cont_thick)
2148+
21432149
call get_param(param_file, mdl, "LAPLACIAN", CS%Laplacian, &
21442150
"If true, use a Laplacian horizontal viscosity.", &
21452151
default=.false.)

0 commit comments

Comments
 (0)