A note down in the middle of the file mentions that...
! At entry, it is assumed that the turbulent kinetic energy fields
! "tke" and "gls", at time level "nnew", are set to its values at
! time level "nstp" multiplied by the grid box thicknesses Hz
! (from old time step and at W-points).
... and if you look in gls_prestep.F this does indeed appear to be the last thing done to gls and tke at 4th index nnew in gls_prestep.F...
cff=0.5_r8*(Hz(i,j,k)+Hz(i,j,k+1))
...
tke(i,j,k,nnew)=cff*tke(i,j,k,nstp)
gls(i,j,k,nnew)=cff*gls(i,j,k,nstp)
... but when advection is applied in the horizontal immediately thereafter upon entering gls_corstep.F, the limits of gls_Kmin and gls_Pmin are therefore applied to the product of (interpolated) Hz and tke; gls by ...
tke(i,j,k,nnew)=MAX(tke(i,j,k,nnew),gls_Kmin(ng))
...
gls(i,j,k,nnew)=MAX(gls(i,j,k,nnew),gls_Pmin(ng))
... in three different loops over horizontal indices, (once) after adding vertical and (twice) for horizontal advection terms using FXK, FEK,FCK, FXP, FEP, FCP (and these Fxx's do appear to have the application of a factor of thickness from interpolated Huon, Hvom & Hz).
So this means that any benefit intended to model stability by applying kmin to oscillations produced by these advection terms is largely disengaged when thickness Hz, Hvom, Huon is larger than O(1) and is applied using a lower limit when it is smaller than O(1).
I attached a possible fix alt_gls_corstep.F relative to a recent distributed ROMS version.
Looking for feedback if this change looks incorrect to someone with more experience working under the hood with this code.
Likely not a critical repair impacting results, but may conceivably add to other complications associated with and numerical stability when trying to reduce gls_Kmin from its default excessively high setting (see axe grinding, PS below).
Ramsey Harcourt
APL/UW Seattle
P.S. I noticed this possible problem while looking for why vertical mixing was excessively high in deep ocean locations with low stratification, a problem pointed out to me by Guangyu Xu at UW/APL, but the source of high levels of AKs, AKt, AKv was not obvious since the high diffusivity was far from uniform as would reflect a background setting choice. After some spelunking through gls_corstep, I eventually (re-)identified the problem and immediately found my way to Malcolm Scully's 2011 identification of the problem with the default input file setting of gls_Kmin=7.6e-6 m^2/s resulting in a stealth minimum on diffusivity and viscosity scaling as gls_Kmin/N at https://myroms.org/forum/viewtopic.php?p=8433#p8433 , and a more recent 2018 re-identification and exploration of this pitfall by Jamie Pringle at https://myroms.org/forum/viewtopic.php?p=18566#p18566. I found this high-diffusivity/viscosity defect of default gls_Kmin settings particularly hard to find on the board if you don't know you are actually looking for a problem rooted in the 'gls_Kmin' setting, but easy to pull up on the board once you do. So besides the possible coding error above that I noted along the way, this is here is my plug added to other voices that the default suggested gls_Kmin=7.6e-6 setting for GLS closures should be either lowered or marked clearly on example input files or documentation as potentially leading to excessively high deep ocean vertical mixing. Like for N~1e-3/s you get AKt, AKs, Akv ~ 1e-3 m^2/s
