Skip to content

Commit 670ed29

Browse files
herrwang0Hallberg-NOAA
authored andcommitted
Refactor a few lines in vertical viscosity
* In subroutine set_viscous_BBL, move and merge `u2_bg` calculation to avoid redundancy and if-branch within do-loops. * In subroutine set_viscous_BBL, add a comment on explaining the reason to reset Ray_[uv] * In subroutine find_coupling_coef, replace an if-branch with min()
1 parent 4eae277 commit 670ed29

File tree

2 files changed

+17
-30
lines changed

2 files changed

+17
-30
lines changed

src/parameterizations/vertical/MOM_set_viscosity.F90

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ subroutine set_viscous_BBL(u, v, h, tv, visc, G, GV, US, CS, pbv)
416416

417417
if (.not.use_BBL_EOS) Rml_vel(:,:) = 0.0
418418

419+
! Resetting Ray_[uv] is required by body force drag.
419420
if (allocated(visc%Ray_u)) visc%Ray_u(:,:,:) = 0.0
420421
if (allocated(visc%Ray_v)) visc%Ray_v(:,:,:) = 0.0
421422

@@ -582,6 +583,21 @@ subroutine set_viscous_BBL(u, v, h, tv, visc, G, GV, US, CS, pbv)
582583
endif
583584
endif ; endif
584585

586+
! Set the "back ground" friction velocity scale to either the tidal amplitude or place-holder constant
587+
if (CS%BBL_use_tidal_bg) then
588+
do i=is,ie ; if (do_i(i)) then ; if (m==1) then
589+
u2_bg(I) = 0.5*( G%mask2dT(i,j)*(CS%tideamp(i,j)*CS%tideamp(i,j))+ &
590+
G%mask2dT(i+1,j)*(CS%tideamp(i+1,j)*CS%tideamp(i+1,j)) )
591+
else
592+
u2_bg(i) = 0.5*( G%mask2dT(i,j)*(CS%tideamp(i,j)*CS%tideamp(i,j))+ &
593+
G%mask2dT(i,j+1)*(CS%tideamp(i,j+1)*CS%tideamp(i,j+1)) )
594+
endif ; endif ; enddo
595+
else
596+
do i=is,ie ; if (do_i(i)) then
597+
u2_bg(i) = CS%drag_bg_vel * CS%drag_bg_vel
598+
endif ; enddo
599+
endif
600+
585601
if (use_BBL_EOS .or. CS%body_force_drag .or. .not.CS%linear_drag) then
586602
! Calculate the mean velocity magnitude over the bottommost CS%Hbbl of
587603
! the water column for determining the quadratic bottom drag.
@@ -591,18 +607,6 @@ subroutine set_viscous_BBL(u, v, h, tv, visc, G, GV, US, CS, pbv)
591607
dztot_vel = 0.0 ; dzwtot = 0.0
592608
Thtot = 0.0 ; Shtot = 0.0 ; SpV_htot = 0.0
593609

594-
! Set the "back ground" friction velocity scale to either the tidal amplitude or place-holder constant
595-
if (CS%BBL_use_tidal_bg) then
596-
if (m==1) then
597-
u2_bg(I) = 0.5*( G%mask2dT(i,j)*(CS%tideamp(i,j)*CS%tideamp(i,j))+ &
598-
G%mask2dT(i+1,j)*(CS%tideamp(i+1,j)*CS%tideamp(i+1,j)) )
599-
else
600-
u2_bg(i) = 0.5*( G%mask2dT(i,j)*(CS%tideamp(i,j)*CS%tideamp(i,j))+ &
601-
G%mask2dT(i,j+1)*(CS%tideamp(i,j+1)*CS%tideamp(i,j+1)) )
602-
endif
603-
else
604-
u2_bg(i) = CS%drag_bg_vel * CS%drag_bg_vel
605-
endif
606610
do k=nz,1,-1
607611

608612
if (htot_vel>=CS%Hbbl) exit ! terminate the k loop
@@ -802,19 +806,6 @@ subroutine set_viscous_BBL(u, v, h, tv, visc, G, GV, US, CS, pbv)
802806
if (m==1) then ; C2f = G%CoriolisBu(I,J-1) + G%CoriolisBu(I,J)
803807
else ; C2f = G%CoriolisBu(I-1,J) + G%CoriolisBu(I,J) ; endif
804808

805-
! Set the "back ground" friction velocity scale to either the tidal amplitude or place-holder constant
806-
if (CS%BBL_use_tidal_bg) then
807-
if (m==1) then
808-
u2_bg(I) = 0.5*( G%mask2dT(i,j)*(CS%tideamp(i,j)*CS%tideamp(i,j))+ &
809-
G%mask2dT(i+1,j)*(CS%tideamp(i+1,j)*CS%tideamp(i+1,j)) )
810-
else
811-
u2_bg(i) = 0.5*( G%mask2dT(i,j)*(CS%tideamp(i,j)*CS%tideamp(i,j))+ &
812-
G%mask2dT(i,j+1)*(CS%tideamp(i,j+1)*CS%tideamp(i,j+1)) )
813-
endif
814-
else
815-
u2_bg(i) = CS%drag_bg_vel * CS%drag_bg_vel
816-
endif
817-
818809
! The thickness of a rotation limited BBL ignoring stratification is
819810
! h_f ~ Cn u* / f (limit of KW99 eq. 2.20 for N->0).
820811
! The buoyancy limit of BBL thickness (h_N) is already in the variable htot from above.

src/parameterizations/vertical/MOM_vert_friction.F90

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,11 +2105,7 @@ subroutine find_coupling_coef(a_cpl, hvel, do_i, h_harm, bbl_thick, kv_bbl, z_i,
21052105
dhc = hvel(i,nz)*0.5
21062106
! These expressions assume that Kv_tot(i,nz+1) = CS%Kv, consistent with
21072107
! the suppression of turbulent mixing by the presence of a solid boundary.
2108-
if (dhc < bbl_thick(i)) then
2109-
a_cpl(i,nz+1) = kv_bbl(i) / ((dhc+h_neglect) + I_amax*kv_bbl(i))
2110-
else
2111-
a_cpl(i,nz+1) = kv_bbl(i) / ((bbl_thick(i)+h_neglect) + I_amax*kv_bbl(i))
2112-
endif
2108+
a_cpl(i,nz+1) = kv_bbl(i) / ((min(dhc, bbl_thick(i)) + h_neglect) + I_amax*kv_bbl(i))
21132109
endif ; enddo
21142110
do K=nz,2,-1 ; do i=is,ie ; if (do_i(i)) then
21152111
! botfn determines when a point is within the influence of the bottom

0 commit comments

Comments
 (0)