Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
5d4c2f0
Add GL90 as subroutine
NoraLoose Mar 20, 2022
cf806f9
Fix GL90 subroutine
NoraLoose Mar 22, 2022
91d2a5f
call viscosity routines with tv
NoraLoose Mar 22, 2022
46bcf9e
Clarify comments in GL90 routines
NoraLoose Mar 24, 2022
abcb84a
Further modify comments
NoraLoose Mar 24, 2022
d9db99f
More comments
NoraLoose Mar 24, 2022
9fbd504
Comments
NoraLoose Mar 24, 2022
4e9a106
Remove trailing spaces
NoraLoose Mar 24, 2022
1b7313e
Fix typo in grid index
NoraLoose Mar 24, 2022
3710abb
More accurate computation of N^-2 in SSW mode
NoraLoose Mar 28, 2022
298c8c5
Remove white spaces
NoraLoose Mar 29, 2022
149c8da
Just some reformatting to pass doxygen and style tests
NoraLoose Mar 30, 2022
3371e0d
Rename Kv_gl90 --> visc_gl90
NoraLoose Apr 5, 2022
df52a0d
Implement GL90 diagnostics and EBT/constant vertical structure
NoraLoose May 13, 2022
645f995
Option for minimum value for 1/N^2 in GL90 SSW
NoraLoose May 23, 2022
f3821e9
Add h_KE diagnostic
NoraLoose May 24, 2022
359657a
Compute GL90 coupling coefficient directly
NoraLoose May 27, 2022
15b73db
Implement new GL90 viscosity diagnostics at interfaces
NoraLoose Jun 1, 2022
012c7bb
Correct Kv2_gl90_[uv] diagnostic size
NoraLoose Jun 1, 2022
cdac22d
Add multiply coupling coefficient by hvel/(hvel+epsilon)
NoraLoose Jun 2, 2022
4ad7b29
Remove h/h+epsilon in a_cpl_gl90 comp
NoraLoose Jun 7, 2022
311fa22
Remove Kv2_gl90_[uv] diagnostic
NoraLoose Jun 7, 2022
7b7acfa
Add a[uv]_visc_gl90 diagnostic
NoraLoose Jun 7, 2022
f240e7b
zero a_cpl_gl90 out at bottom
NoraLoose Jun 24, 2022
56d3ceb
Constant Hbbl_gl90, to be decided by user
NoraLoose Jul 15, 2022
e3b1a33
Don't compute hvel_gl90, but simply use hvel
NoraLoose Jul 20, 2022
e1e2429
Fix doxygen and style
NoraLoose Jul 20, 2022
10b4ecd
Fix more doxygen and style
NoraLoose Jul 20, 2022
be6b5c2
Option for reading in 2d KHTH
NoraLoose Aug 8, 2022
ccd1e74
Fix option for reading 2d khth
NoraLoose Aug 9, 2022
fd1436d
Clean-up reading of KHTH
NoraLoose Aug 9, 2022
4ae3cf4
Delete I_N2_GL90 variable since it's not used
NoraLoose Aug 9, 2022
2667e16
Only read alpha_GL90 if USE_GL90_N2 = true
NoraLoose Aug 9, 2022
971b14f
Add option of spatially varying GL viscosity
NoraLoose Aug 17, 2022
557ccb9
Move KE_visc_gl90 diagnostic into MOM_vert_friction
NoraLoose Aug 19, 2022
121caa4
Clean up computation of d[uv]_dt_visc_gl90 diagnostic
NoraLoose Aug 22, 2022
078c98d
Move KE_[uv] calculation to ensure sign-definiteness
NoraLoose Aug 22, 2022
e8126c1
Add if loop for computation of d[uv]_dt_visc_gl90 diagnostic
NoraLoose Aug 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/core/MOM_dynamics_split_RK2.F90
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ subroutine step_MOM_dyn_split_RK2(u, v, h, tv, visc, Time_local, dt, forces, p_s
if (CS%debug) then
call uvchksum("before vertvisc: up", up, vp, G%HI, haloshift=0, symmetric=sym, scale=US%L_T_to_m_s)
endif
call vertvisc_coef(up, vp, h, forces, visc, dt, G, GV, US, CS%vertvisc_CSp, CS%OBC)
call vertvisc_coef(up, vp, h, forces, visc, 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)")
Expand Down Expand Up @@ -602,7 +602,7 @@ subroutine step_MOM_dyn_split_RK2(u, v, h, tv, visc, Time_local, dt, forces, p_s
call uvchksum("0 before vertvisc: [uv]p", up, vp, G%HI,haloshift=0, symmetric=sym, scale=US%L_T_to_m_s)
endif
call vertvisc_coef(up, vp, h, forces, visc, dt_pred, G, GV, US, CS%vertvisc_CSp, &
CS%OBC)
CS%OBC, VarMix)
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)
if (showCallTree) call callTree_wayPoint("done with vertvisc (step_MOM_dyn_split_RK2)")
Expand Down Expand Up @@ -798,7 +798,7 @@ subroutine step_MOM_dyn_split_RK2(u, v, h, tv, visc, Time_local, dt, forces, p_s
! 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)
call vertvisc_coef(u, v, h, forces, visc, dt, G, GV, US, CS%vertvisc_CSp, CS%OBC)
call vertvisc_coef(u, v, h, forces, visc, dt, G, GV, US, CS%vertvisc_CSp, CS%OBC, VarMix)
call vertvisc(u, v, 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 (G%nonblocking_updates) then
Expand Down
6 changes: 3 additions & 3 deletions src/core/MOM_dynamics_unsplit.F90
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ subroutine step_MOM_dyn_unsplit(u, v, h, tv, visc, Time_local, dt, forces, &
call disable_averaging(CS%diag)

dt_visc = 0.5*dt ; if (CS%use_correct_dt_visc) dt_visc = dt_pred
call vertvisc_coef(up, vp, h_av, forces, visc, dt_visc, G, GV, US, CS%vertvisc_CSp, CS%OBC)
call vertvisc_coef(up, vp, h_av, forces, visc, dt_visc, G, GV, US, CS%vertvisc_CSp, CS%OBC, VarMix)
call vertvisc(up, vp, h_av, forces, visc, dt_visc, CS%OBC, CS%ADp, CS%CDp, &
G, GV, US, CS%vertvisc_CSp, Waves=Waves)
call cpu_clock_end(id_clock_vertvisc)
Expand Down Expand Up @@ -405,7 +405,7 @@ subroutine step_MOM_dyn_unsplit(u, v, h, tv, visc, Time_local, dt, forces, &

! upp <- upp + dt/2 d/dz visc d/dz upp
call cpu_clock_begin(id_clock_vertvisc)
call vertvisc_coef(upp, vpp, hp, forces, visc, dt*0.5, G, GV, US, CS%vertvisc_CSp, CS%OBC)
call vertvisc_coef(upp, vpp, hp, forces, visc, dt*0.5, G, GV, US, CS%vertvisc_CSp, CS%OBC, VarMix)
call vertvisc(upp, vpp, hp, forces, visc, dt*0.5, CS%OBC, CS%ADp, CS%CDp, &
G, GV, US, CS%vertvisc_CSp, Waves=Waves)
call cpu_clock_end(id_clock_vertvisc)
Expand Down Expand Up @@ -489,7 +489,7 @@ subroutine step_MOM_dyn_unsplit(u, v, h, tv, visc, Time_local, dt, forces, &

! u <- u + dt d/dz visc d/dz u
call cpu_clock_begin(id_clock_vertvisc)
call vertvisc_coef(u, v, h_av, forces, visc, dt, G, GV, US, CS%vertvisc_CSp, CS%OBC)
call vertvisc_coef(u, v, h_av, forces, visc, dt, G, GV, US, CS%vertvisc_CSp, CS%OBC, VarMix)
call vertvisc(u, v, h_av, forces, visc, dt, CS%OBC, CS%ADp, CS%CDp, &
G, GV, US, CS%vertvisc_CSp, CS%taux_bot, CS%tauy_bot, Waves=Waves)
call cpu_clock_end(id_clock_vertvisc)
Expand Down
6 changes: 3 additions & 3 deletions src/core/MOM_dynamics_unsplit_RK2.F90
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ subroutine step_MOM_dyn_unsplit_RK2(u_in, v_in, h_in, tv, visc, Time_local, dt,
call set_viscous_ML(u_in, v_in, h_av, tv, forces, visc, dt_visc, G, GV, US, CS%set_visc_CSp)
call disable_averaging(CS%diag)

call vertvisc_coef(up, vp, h_av, forces, visc, dt_pred, G, GV, US, CS%vertvisc_CSp, CS%OBC)
call vertvisc_coef(up, vp, h_av, forces, visc, dt_pred, G, GV, US, CS%vertvisc_CSp, CS%OBC, VarMix)
call vertvisc(up, vp, h_av, forces, visc, dt_pred, CS%OBC, CS%ADp, CS%CDp, &
G, GV, US, CS%vertvisc_CSp)
call cpu_clock_end(id_clock_vertvisc)
Expand Down Expand Up @@ -392,10 +392,10 @@ subroutine step_MOM_dyn_unsplit_RK2(u_in, v_in, h_in, tv, visc, Time_local, dt,
! up[n] <- up* + dt d/dz visc d/dz up
! u[n] <- u*[n] + dt d/dz visc d/dz u[n]
call cpu_clock_begin(id_clock_vertvisc)
call vertvisc_coef(up, vp, h_av, forces, visc, dt, G, GV, US, CS%vertvisc_CSp, CS%OBC)
call vertvisc_coef(up, vp, h_av, forces, visc, dt, G, GV, US, CS%vertvisc_CSp, CS%OBC, VarMix)
call vertvisc(up, vp, h_av, forces, visc, dt, CS%OBC, CS%ADp, CS%CDp, &
G, GV, US, CS%vertvisc_CSp, CS%taux_bot, CS%tauy_bot)
call vertvisc_coef(u_in, v_in, h_av, forces, visc, dt, G, GV, US, CS%vertvisc_CSp, CS%OBC)
call vertvisc_coef(u_in, v_in, h_av, forces, visc, dt, G, GV, US, CS%vertvisc_CSp, CS%OBC, VarMix)
call vertvisc(u_in, v_in, h_av, forces, visc, dt, CS%OBC, CS%ADp, CS%CDp,&
G, GV, US, CS%vertvisc_CSp, CS%taux_bot, CS%tauy_bot)
call cpu_clock_end(id_clock_vertvisc)
Expand Down
4 changes: 4 additions & 0 deletions src/core/MOM_variables.F90
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ module MOM_variables
PFv => NULL(), & !< Meridional acceleration due to pressure forces [L T-2 ~> m s-2]
du_dt_visc => NULL(), &!< Zonal acceleration due to vertical viscosity [L T-2 ~> m s-2]
dv_dt_visc => NULL(), &!< Meridional acceleration due to vertical viscosity [L T-2 ~> m s-2]
du_dt_visc_gl90 => NULL(), &!< Zonal acceleration due to GL90 vertical viscosity
! (included in du_dt_visc) [L T-2 ~> m s-2]
dv_dt_visc_gl90 => NULL(), &!< Meridional acceleration due to GL90 vertical viscosity
! (included in dv_dt_visc) [L T-2 ~> m s-2]
du_dt_str => NULL(), & !< Zonal acceleration due to the surface stress (included
!! in du_dt_visc) [L T-2 ~> m s-2]
dv_dt_str => NULL(), & !< Meridional acceleration due to the surface stress (included
Expand Down
43 changes: 41 additions & 2 deletions src/diagnostics/MOM_diagnostics.F90
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ module MOM_diagnostics
integer :: id_hf_du_dt_2d = -1, id_hf_dv_dt_2d = -1
integer :: id_col_ht = -1, id_dh_dt = -1
integer :: id_KE = -1, id_dKEdt = -1
integer :: id_h_KE = -1
integer :: id_PE_to_KE = -1, id_KE_BT = -1
integer :: id_KE_Coradv = -1, id_KE_adv = -1
integer :: id_KE_visc = -1, id_KE_stress = -1
!integer :: id_KE_visc_gl90 = -1
integer :: id_KE_horvisc = -1, id_KE_dia = -1
integer :: id_uh_Rlay = -1, id_vh_Rlay = -1
integer :: id_uhGM_Rlay = -1, id_vhGM_Rlay = -1
Expand Down Expand Up @@ -941,6 +943,7 @@ subroutine calculate_energy_diagnostics(u, v, h, uh, vh, ADp, CDp, G, GV, US, CS

! Local variables
real :: KE(SZI_(G),SZJ_(G),SZK_(GV)) ! Kinetic energy per unit mass [L2 T-2 ~> m2 s-2]
real :: h_KE(SZI_(G),SZJ_(G),SZK_(GV)) ! Layer kinetic energy [L3 T-2 ~> m3 s-2]
real :: KE_term(SZI_(G),SZJ_(G),SZK_(GV)) ! A term in the kinetic energy budget
! [H L2 T-3 ~> m3 s-3 or W m-2]
real :: KE_u(SZIB_(G),SZJ_(G)) ! The area integral of a KE term in a layer at u-points
Expand All @@ -954,7 +957,7 @@ subroutine calculate_energy_diagnostics(u, v, h, uh, vh, ADp, CDp, G, GV, US, CS
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

if (.not.(CS%KE_term_on .or. (CS%id_KE > 0))) return
if (.not.(CS%KE_term_on .or. (CS%id_KE > 0) .or. (CS%id_h_KE > 0))) return

do j=js-1,je ; do i=is-1,ie
KE_u(I,j) = 0.0 ; KE_v(i,J) = 0.0
Expand All @@ -965,6 +968,12 @@ subroutine calculate_energy_diagnostics(u, v, h, uh, vh, ADp, CDp, G, GV, US, CS
+ (v(i,J,k) * v(i,J,k) + v(i,J-1,k) * v(i,J-1,k))) * 0.25
enddo ; enddo ; enddo
if (CS%id_KE > 0) call post_data(CS%id_KE, KE, CS%diag)
if (CS%id_h_KE > 0) then
do k=1,nz ; do j=js,je ; do i=is,ie
h_KE(i,j,k) = h(i,j,k) * KE(i,j,k)
enddo ; enddo ; enddo
call post_data(CS%id_h_KE, h_KE, CS%diag)
endif

if (CS%KE_term_on .and. .not.G%symmetric) then
call create_group_pass(CS%pass_KE_uv, KE_u, KE_v, G%Domain, To_North+To_East)
Expand Down Expand Up @@ -1103,6 +1112,25 @@ subroutine calculate_energy_diagnostics(u, v, h, uh, vh, ADp, CDp, G, GV, US, CS
call post_data(CS%id_KE_visc, KE_term, CS%diag)
endif

!if (CS%id_KE_visc_gl90 > 0) then
! ! Calculate the KE source from GL90 vertical viscosity [H L2 T-3 ~> m3 s-3].
! do k=1,nz
! do j=js,je ; do I=Isq,Ieq
! KE_u(I,j) = uh(I,j,k) * G%dxCu(I,j) * ADp%du_dt_visc_gl90(I,j,k)
! enddo ; enddo
! do J=Jsq,Jeq ; do i=is,ie
! KE_v(i,J) = vh(i,J,k) * G%dyCv(i,J) * ADp%dv_dt_visc_gl90(i,J,k)
! enddo ; enddo
! if (.not.G%symmetric) &
! call do_group_pass(CS%pass_KE_uv, G%domain)
! do j=js,je ; do i=is,ie
! KE_term(i,j,k) = 0.5 * G%IareaT(i,j) &
! * (KE_u(I,j) + KE_u(I-1,j) + KE_v(i,J) + KE_v(i,J-1))
! enddo ; enddo
! enddo
! call post_data(CS%id_KE_visc_gl90, KE_term, CS%diag)
!endif

if (CS%id_KE_stress > 0) then
! Calculate the KE source from surface stress (included in KE_visc) [H L2 T-3 ~> m3 s-3].
do k=1,nz
Expand Down Expand Up @@ -1738,6 +1766,9 @@ subroutine MOM_diagnostics_init(MIS, ADp, CDp, Time, G, GV, US, param_file, diag
CS%id_KE = register_diag_field('ocean_model', 'KE', diag%axesTL, Time, &
'Layer kinetic energy per unit mass', &
'm2 s-2', conversion=US%L_T_to_m_s**2)
CS%id_h_KE = register_diag_field('ocean_model', 'h_KE', diag%axesTL, Time, &
'Layer kinetic energy', &
'm3 s-2', conversion=GV%H_to_m*US%L_T_to_m_s**2)
CS%id_dKEdt = register_diag_field('ocean_model', 'dKE_dt', diag%axesTL, Time, &
'Kinetic Energy Tendency of Layer', &
'm3 s-3', conversion=GV%H_to_m*(US%L_T_to_m_s**2)*US%s_to_T)
Expand All @@ -1758,6 +1789,9 @@ subroutine MOM_diagnostics_init(MIS, ADp, CDp, Time, G, GV, US, param_file, diag
CS%id_KE_visc = register_diag_field('ocean_model', 'KE_visc', diag%axesTL, Time, &
'Kinetic Energy Source from Vertical Viscosity and Stresses', &
'm3 s-3', conversion=GV%H_to_m*(US%L_T_to_m_s**2)*US%s_to_T)
!CS%id_KE_visc_gl90 = register_diag_field('ocean_model', 'KE_visc_gl90', diag%axesTL, Time, &
! 'Kinetic Energy Source from GL90 Vertical Viscosity', &
! 'm3 s-3', conversion=GV%H_to_m*(US%L_T_to_m_s**2)*US%s_to_T)
CS%id_KE_stress = register_diag_field('ocean_model', 'KE_stress', diag%axesTL, Time, &
'Kinetic Energy Source from Surface Stresses or Body Wind Stress', &
'm3 s-3', conversion=GV%H_to_m*(US%L_T_to_m_s**2)*US%s_to_T)
Expand Down Expand Up @@ -2183,6 +2217,10 @@ subroutine set_dependent_diagnostics(MIS, ADp, CDp, G, GV, CS)
call safe_alloc_ptr(ADp%du_dt_visc,IsdB,IedB,jsd,jed,nz)
call safe_alloc_ptr(ADp%dv_dt_visc,isd,ied,JsdB,JedB,nz)
endif
!if (CS%id_KE_visc_gl90 > 0) then
! call safe_alloc_ptr(ADp%du_dt_visc_gl90,IsdB,IedB,jsd,jed,nz)
! call safe_alloc_ptr(ADp%dv_dt_visc_gl90,isd,ied,JsdB,JedB,nz)
!endif

if (CS%id_KE_stress > 0) then
call safe_alloc_ptr(ADp%du_dt_str,IsdB,IedB,jsd,jed,nz)
Expand All @@ -2197,7 +2235,8 @@ subroutine set_dependent_diagnostics(MIS, ADp, CDp, G, GV, CS)

CS%KE_term_on = ((CS%id_dKEdt > 0) .or. (CS%id_PE_to_KE > 0) .or. (CS%id_KE_BT > 0) .or. &
(CS%id_KE_Coradv > 0) .or. (CS%id_KE_adv > 0) .or. (CS%id_KE_visc > 0) .or. &
(CS%id_KE_stress > 0) .or. (CS%id_KE_horvisc > 0) .or. (CS%id_KE_dia > 0))
(CS%id_KE_visc > 0) .or. (CS%id_KE_stress > 0) .or. (CS%id_KE_horvisc > 0) .or. &
(CS%id_KE_dia > 0))

if (CS%id_h_du_dt > 0) call safe_alloc_ptr(ADp%diag_hu,IsdB,IedB,jsd,jed,nz)
if (CS%id_h_dv_dt > 0) call safe_alloc_ptr(ADp%diag_hv,isd,ied,JsdB,JedB,nz)
Expand Down
52 changes: 45 additions & 7 deletions src/parameterizations/lateral/MOM_thickness_diffuse.F90
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module MOM_thickness_diffuse
use MOM_EOS, only : calculate_density_second_derivs
use MOM_file_parser, only : get_param, log_version, param_file_type
use MOM_grid, only : ocean_grid_type
use MOM_io, only : MOM_read_data
use MOM_interface_heights, only : find_eta
use MOM_isopycnal_slopes, only : vert_fill_TS
use MOM_lateral_mixing_coeffs, only : VarMix_CS
Expand Down Expand Up @@ -81,6 +82,8 @@ module MOM_thickness_diffuse
real :: Stanley_det_coeff !< The coefficient correlating SGS temperature variance with the mean
!! temperature gradient in the deterministic part of the Stanley parameterization.
!! Negative values disable the scheme." [nondim]
logical :: read_khth ! If true, read a file containing the spatially varying
! horizontal thickness diffusivity

type(diag_ctrl), pointer :: diag => NULL() !< structure used to regulate timing of diagnostics
real, allocatable :: GMwork(:,:) !< Work by thickness diffusivity [R Z L2 T-3 ~> W m-2]
Expand All @@ -89,6 +92,7 @@ module MOM_thickness_diffuse

real, allocatable :: KH_u_GME(:,:,:) !< interface height diffusivities in u-columns [L2 T-1 ~> m2 s-1]
real, allocatable :: KH_v_GME(:,:,:) !< interface height diffusivities in v-columns [L2 T-1 ~> m2 s-1]
real, allocatable, dimension(:,:) :: khth2d !< 2D thickness diffusivity at h-points [L2 T-1 ~> m2 s-1]

!>@{
!! Diagnostic identifier
Expand Down Expand Up @@ -165,7 +169,8 @@ subroutine thickness_diffuse(h, uhtr, vhtr, tv, dt, G, GV, US, MEKE, VarMix, CDp
"Module must be initialized before it is used.")

if ((.not.CS%thickness_diffuse) &
.or. .not. (CS%Khth > 0.0 .or. VarMix%use_variable_mixing)) return
.or. .not. (CS%Khth > 0.0 .or. CS%read_khth &
.or. VarMix%use_variable_mixing)) return

is = G%isc ; ie = G%iec ; js = G%jsc ; je = G%jec ; nz = GV%ke
h_neglect = GV%H_subroundoff
Expand Down Expand Up @@ -213,9 +218,15 @@ subroutine thickness_diffuse(h, uhtr, vhtr, tv, dt, G, GV, US, MEKE, VarMix, CDp
!$OMP int_slope_v,khth_use_ebt_struct, Depth_scaled, &
!$OMP Khth_loc_v)
!$OMP do
do j=js,je ; do I=is-1,ie
Khth_loc_u(I,j) = CS%Khth
enddo ; enddo
if (.not. CS%read_khth) then
do j=js,je ; do I=is-1,ie
Khth_loc_u(I,j) = CS%Khth
enddo ; enddo
else ! read KHTH from file
do j=js,je ; do I=is-1,ie
Khth_loc_u(I,j) = 0.5 * (CS%khth2d(i,j) + CS%khth2d(i+1,j))
enddo ; enddo
endif

if (use_VarMix) then
if (use_Visbeck) then
Expand Down Expand Up @@ -301,9 +312,15 @@ subroutine thickness_diffuse(h, uhtr, vhtr, tv, dt, G, GV, US, MEKE, VarMix, CDp
endif

!$OMP do
do J=js-1,je ; do i=is,ie
Khth_loc_v(i,J) = CS%Khth
enddo ; enddo
if (.not. CS%read_khth) then
do J=js-1,je ; do i=is,ie
Khth_loc_v(i,J) = CS%Khth
enddo ; enddo
else ! read KHTH from file
do J=js-1,je ; do i=is,ie
Khth_loc_v(i,J) = 0.5 * (CS%khth2d(i,j) + CS%khth2d(i,j+1))
enddo ; enddo
endif

if (use_VarMix) then
if (use_Visbeck) then
Expand Down Expand Up @@ -1901,6 +1918,9 @@ subroutine thickness_diffuse_init(Time, G, GV, US, param_file, diag, CDp, CS)
! rotation [nondim].
logical :: default_2018_answers ! The default setting for the various 2018_ANSWERS flags.

! Local variables
character(len=200) :: khth_file

CS%initialized = .true.
CS%diag => diag

Expand All @@ -1912,6 +1932,22 @@ subroutine thickness_diffuse_init(Time, G, GV, US, param_file, diag, CDp, CS)
call get_param(param_file, mdl, "KHTH", CS%Khth, &
"The background horizontal thickness diffusivity.", &
default=0.0, units="m2 s-1", scale=US%m_to_L**2*US%T_to_s)
call get_param(param_file, mdl, "READ_KHTH", CS%read_khth, &
"If true, read a file (given by KHTH_FILE) containing the "//&
"spatially varying horizontal thickness diffusivity.", default=.false.)
if (CS%read_khth) then
if (CS%Khth > 0) then
call MOM_error(FATAL, "thickness_diffuse_init: KHTH > 0 is not "// &
"compatible with READ_KHTH = TRUE. ")
endif
call get_param(param_file, mdl, "KHTH_FILE", khth_file, &
"The file containing the spatially varying horizontal "//&
"thickness diffusivity.", default="INPUT/khth.nc")

allocate(CS%khth2d(G%isd:G%ied, G%jsd:G%jed), source=0.0)
call MOM_read_data(khth_file, 'khth', CS%khth2d(:,:), G%domain, scale=US%m_to_L**2*US%T_to_s)
call pass_var(CS%khth2d, G%domain)
endif
call get_param(param_file, mdl, "KHTH_SLOPE_CFF", CS%KHTH_Slope_Cff, &
"The nondimensional coefficient in the Visbeck formula "//&
"for the interface depth diffusivity", units="nondim", &
Expand Down Expand Up @@ -2130,6 +2166,8 @@ subroutine thickness_diffuse_end(CS, CDp)
deallocate(CS%KH_u_GME)
deallocate(CS%KH_v_GME)
endif

if (allocated(CS%khth2d)) deallocate(CS%khth2d)
end subroutine thickness_diffuse_end

!> \namespace mom_thickness_diffuse
Expand Down
Loading