NOC-MSM / SE-NEMO

Shelf Enabled Global NEMO
GNU General Public License v3.0
2 stars 1 forks source link

Test GLS v's TKE #21

Open jdha opened 3 years ago

jdha commented 2 years ago

Romain B-B namzdf_gls:

!----------------------------------------------------------------------- &namzdf_gls ! GLS vertical diffusion (ln_zdfgls =T) !----------------------------------------------------------------------- rn_emin = 1.e-7 ! minimum value of e [m2/s2] rn_epsmin = 1.e-12 ! minimum value of eps [m2/s3] ln_length_lim = .true. ! limit on the dissipation rate under stable stratification (Galperin et al., 1988) rn_clim_galp = 0.267 ! galperin limit ln_sigpsi = .true. ! Activate or not Burchard 2001 mods on psi schmidt number in the wb case rn_crban = 100. ! Craig and Banner 1994 constant for wb tke flux rn_charn = 70000. ! Charnock constant for wb induced roughness length rn_hsro = 0.02 ! Minimum surface roughness rn_hsro_i = 0.02 ! Minimum surface roughness under ice rn_frac_hs = 1.3 ! Fraction of wave height as roughness (if nn_z0_met>1) nn_z0_met = 2 ! Method for surface roughness computation (0/1/2/3) ! ! =3 requires ln_wave=T nn_z0_met_i = 3 ! Method for surface roughness computation under ice (1/2/3) nn_bc_surf = 1 ! surface condition (0/1=Dir/Neum) nn_bc_bot = 1 ! bottom condition (0/1=Dir/Neum) nn_stab_func = 2 ! stability function (0=Galp, 1= KC94, 2=CanutoA, 3=CanutoB) nn_clos = 1 ! predefined closure type (0=MY82, 1=k-eps, 2=k-w, 3=Gen) /

jdha commented 2 years ago

From Romain B-B:

"same than in TKE (mixing lenght depending on ice thick) but in GLS we can not impose a mixing length in the first level as TKE, so we impose an unrealistic roughness wich will generate the wanted mixing length... As in TKE, this "ugly trick" solves the problem in artic (because of tidal mixing now the background is very low in artic ocean and fresh water is trapped in the first layers) and it has solved also my polinia problem in antarctic !... I didn't understood really why, I suspect because with the very hudge friction there is a slowdown of ocean/ice and a decrease of to strong shear in antartica...."

jdha commented 2 years ago
MODULE zdfgls
   !!======================================================================
   !!                       ***  MODULE  zdfgls  ***
   !! Ocean physics:  vertical mixing coefficient computed from the gls 
   !!                 turbulent closure parameterization
   !!======================================================================
   !! History :  3.0  !  2009-09  (G. Reffray)  Original code
   !!            3.3  !  2010-10  (C. Bricaud)  Add in the reference
   !!            4.0  !  2017-04  (G. Madec)  remove CPP keys & avm at t-point only 
   !!             -   !  2017-05  (G. Madec)  add top friction as boundary condition
   !!----------------------------------------------------------------------

   !!----------------------------------------------------------------------
   !!   zdf_gls       : update momentum and tracer Kz from a gls scheme
   !!   zdf_gls_init  : initialization, namelist read, and parameters control
   !!   gls_rst       : read/write gls restart in ocean restart file
   !!----------------------------------------------------------------------
   USE oce            ! ocean dynamics and active tracers 
   USE dom_oce        ! ocean space and time domain
   USE domvvl         ! ocean space and time domain : variable volume layer
   USE zdfdrg  , ONLY : r_z0_top , r_z0_bot   ! top/bottom roughness
   USE zdfdrg  , ONLY : rCdU_top , rCdU_bot   ! top/bottom friction
   USE sbc_oce        ! surface boundary condition: ocean
   USE phycst         ! physical constants
   USE zdfmxl         ! mixed layer
   USE sbcwave , ONLY : hsw   ! significant wave height
   !
   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
   USE lib_mpp        ! MPP manager
   USE prtctl         ! Print control
   USE in_out_manager ! I/O manager
   USE iom            ! I/O manager library
   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)

   IMPLICIT NONE
   PRIVATE

   PUBLIC   zdf_gls        ! called in zdfphy
   PUBLIC   zdf_gls_init   ! called in zdfphy
   PUBLIC   gls_rst        ! called in zdfphy

   !
   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   hmxl_n    !: now mixing length
   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   zwall   !: wall function
   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ustar2_surf !: Squared surface velocity scale at T-points
   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ustar2_top  !: Squared top     velocity scale at T-points
   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ustar2_bot  !: Squared bottom  velocity scale at T-points

   !                              !! ** Namelist  namzdf_gls  **
   LOGICAL  ::   ln_length_lim     ! use limit on the dissipation rate under stable stratification (Galperin et al. 1988)
   LOGICAL  ::   ln_sigpsi         ! Activate Burchard (2003) modification for k-eps closure & wave breaking mixing
   INTEGER  ::   nn_bc_surf        ! surface boundary condition (=0/1)
   INTEGER  ::   nn_bc_bot         ! bottom boundary condition (=0/1)
   INTEGER  ::   nn_z0_met         ! Method for surface roughness computation
   INTEGER  ::   nn_z0_met_i       ! Method for surface roughness computation under ice
   INTEGER  ::   nn_stab_func      ! stability functions G88, KC or Canuto (=0/1/2)
   INTEGER  ::   nn_clos           ! closure 0/1/2/3 MY82/k-eps/k-w/gen
   REAL(wp) ::   rn_clim_galp      ! Holt 2008 value for k-eps: 0.267
   REAL(wp) ::   rn_epsmin         ! minimum value of dissipation (m2/s3)
   REAL(wp) ::   rn_emin           ! minimum value of TKE (m2/s2)
   REAL(wp) ::   rn_charn          ! Charnock constant for surface breaking waves mixing : 1400. (standard) or 2.e5 (Stacey value)
   REAL(wp) ::   rn_crban          ! Craig and Banner constant for surface breaking waves mixing
   REAL(wp) ::   rn_hsro           ! Minimum surface roughness
   REAL(wp) ::   rn_hsro_i         ! Surface roughness under ice in constant case nn_z0_met_i = 1
   REAL(wp) ::   rn_frac_hs        ! Fraction of wave height as surface roughness (if nn_z0_met > 1) 

   REAL(wp) ::   rcm_sf        =  0.73_wp     ! Shear free turbulence parameters
   REAL(wp) ::   ra_sf         = -2.0_wp      ! Must be negative -2 < ra_sf < -1 
   REAL(wp) ::   rl_sf         =  0.2_wp      ! 0 <rl_sf<vkarmn    
   REAL(wp) ::   rghmin        = -0.28_wp
   REAL(wp) ::   rgh0          =  0.0329_wp
   REAL(wp) ::   rghcri        =  0.03_wp
   REAL(wp) ::   ra1           =  0.92_wp
   REAL(wp) ::   ra2           =  0.74_wp
   REAL(wp) ::   rb1           = 16.60_wp
   REAL(wp) ::   rb2           = 10.10_wp         
   REAL(wp) ::   re2           =  1.33_wp         
   REAL(wp) ::   rl1           =  0.107_wp
   REAL(wp) ::   rl2           =  0.0032_wp
   REAL(wp) ::   rl3           =  0.0864_wp
   REAL(wp) ::   rl4           =  0.12_wp
   REAL(wp) ::   rl5           = 11.9_wp
   REAL(wp) ::   rl6           =  0.4_wp
   REAL(wp) ::   rl7           =  0.0_wp
   REAL(wp) ::   rl8           =  0.48_wp
   REAL(wp) ::   rm1           =  0.127_wp
   REAL(wp) ::   rm2           =  0.00336_wp
   REAL(wp) ::   rm3           =  0.0906_wp
   REAL(wp) ::   rm4           =  0.101_wp
   REAL(wp) ::   rm5           = 11.2_wp
   REAL(wp) ::   rm6           =  0.4_wp
   REAL(wp) ::   rm7           =  0.0_wp
   REAL(wp) ::   rm8           =  0.318_wp
   REAL(wp) ::   rtrans        =  0.1_wp
   REAL(wp) ::   rc02, rc02r, rc03, rc04                          ! coefficients deduced from above parameters
   REAL(wp) ::   rsbc_tke1, rsbc_tke2, rfact_tke                  !     -           -           -        -
   REAL(wp) ::   rsbc_psi1, rsbc_psi2, rfact_psi                  !     -           -           -        -
   REAL(wp) ::   rsbc_zs1, rsbc_zs2                               !     -           -           -        -
   REAL(wp) ::   rc0, rc2, rc3, rf6, rcff, rc_diff                !     -           -           -        -
   REAL(wp) ::   rs0, rs1, rs2, rs4, rs5, rs6                     !     -           -           -        -
   REAL(wp) ::   rd0, rd1, rd2, rd3, rd4, rd5                     !     -           -           -        -
   REAL(wp) ::   rsc_tke, rsc_psi, rpsi1, rpsi2, rpsi3, rsc_psi0  !     -           -           -        -
   REAL(wp) ::   rpsi3m, rpsi3p, rpp, rmm, rnn                    !     -           -           -        -
   !
   REAL(wp) ::   r2_3 = 2._wp/3._wp   ! constant=2/3

   !! * Substitutions
#  include "do_loop_substitute.h90"
   !!----------------------------------------------------------------------
   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
   !! $Id: zdfgls.F90 12489 2020-02-28 15:55:11Z davestorkey $
   !! Software governed by the CeCILL license (see ./LICENSE)
   !!----------------------------------------------------------------------
CONTAINS

   INTEGER FUNCTION zdf_gls_alloc()
      !!----------------------------------------------------------------------
      !!                ***  FUNCTION zdf_gls_alloc  ***
      !!----------------------------------------------------------------------
      ALLOCATE( hmxl_n(jpi,jpj,jpk) , ustar2_surf(jpi,jpj) ,                     &
         &      zwall (jpi,jpj,jpk) , ustar2_top (jpi,jpj) , ustar2_bot(jpi,jpj) , STAT= zdf_gls_alloc )
         !
      CALL mpp_sum ( 'zdfgls', zdf_gls_alloc )
      IF( zdf_gls_alloc /= 0 )   CALL ctl_stop( 'STOP', 'zdf_gls_alloc: failed to allocate arrays' )
   END FUNCTION zdf_gls_alloc

   SUBROUTINE zdf_gls( kt, Kbb, Kmm, p_sh2, p_avm, p_avt )
      !!----------------------------------------------------------------------
      !!                   ***  ROUTINE zdf_gls  ***
      !!
      !! ** Purpose :   Compute the vertical eddy viscosity and diffusivity
      !!              coefficients using the GLS turbulent closure scheme.
      !!----------------------------------------------------------------------
      USE zdf_oce , ONLY : en, avtb, avmb   ! ocean vertical physics
      !!
      INTEGER                   , INTENT(in   ) ::   kt             ! ocean time step
      INTEGER                   , INTENT(in   ) ::   Kbb, Kmm       ! ocean time level indices
      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   p_sh2          ! shear production term
      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   p_avm, p_avt   !  momentum and tracer Kz (w-points)
      !
      INTEGER  ::   ji, jj, jk    ! dummy loop arguments
      INTEGER  ::   ibot, ibotm1  ! local integers
      INTEGER  ::   itop, itopp1  !   -       -
      REAL(wp) ::   zesh2, zsigpsi, zcoef, zex1 , zex2  ! local scalars
      REAL(wp) ::   ztx2, zty2, zup, zdown, zcof, zdir  !   -      - 
      REAL(wp) ::   zratio, zrn2, zflxb, sh     , z_en  !   -      -
      REAL(wp) ::   prod, buoy, diss, zdiss, sm         !   -      -
      REAL(wp) ::   gh, gm, shr, dif, zsqen, zavt, zavm !   -      -
      REAL(wp) ::   zmsku, zmskv                        !   -      -
      REAL(wp), DIMENSION(jpi,jpj)     ::   zdep
      REAL(wp), DIMENSION(jpi,jpj)     ::   zkar
      REAL(wp), DIMENSION(jpi,jpj)     ::   zflxs       ! Turbulence fluxed induced by internal waves 
      REAL(wp), DIMENSION(jpi,jpj)     ::   zhsro       ! Surface roughness (surface waves)
      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   eb          ! tke at time before
      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   hmxl_b      ! mixing length at time before
      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   eps         ! dissipation rate
      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwall_psi   ! Wall function use in the wb case (ln_sigpsi)
      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   psi         ! psi at time now
      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zd_lw, zd_up, zdiag   ! lower, upper  and diagonal of the matrix
      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zstt, zstm  ! stability function on tracer and momentum
      !!--------------------------------------------------------------------
      !
      ! Preliminary computing

      ustar2_surf(:,:) = 0._wp   ;         psi(:,:,:) = 0._wp   
      ustar2_top (:,:) = 0._wp   ;   zwall_psi(:,:,:) = 0._wp
      ustar2_bot (:,:) = 0._wp

      ! Compute surface, top and bottom friction at T-points
      DO_2D_00_00
         !
         ! surface friction
         ustar2_surf(ji,jj) = r1_rho0 * taum(ji,jj) * tmask(ji,jj,1)
         !   
!!gm Rq we may add here r_ke0(_top/_bot) ?  ==>> think about that...
       ! bottom friction (explicit before friction)
       zmsku = ( 2._wp - umask(ji-1,jj,mbkt(ji,jj)) * umask(ji,jj,mbkt(ji,jj)) )
       zmskv = ( 2._wp - vmask(ji,jj-1,mbkt(ji,jj)) * vmask(ji,jj,mbkt(ji,jj)) )     ! (CAUTION: CdU<0)
       ustar2_bot(ji,jj) = - rCdU_bot(ji,jj) * SQRT(  ( zmsku*( uu(ji,jj,mbkt(ji,jj),Kbb)+uu(ji-1,jj,mbkt(ji,jj),Kbb) ) )**2  &
          &                                         + ( zmskv*( vv(ji,jj,mbkt(ji,jj),Kbb)+vv(ji,jj-1,mbkt(ji,jj),Kbb) ) )**2  )
      END_2D
      IF( ln_isfcav ) THEN       !top friction
         DO_2D_00_00
            zmsku = ( 2. - umask(ji-1,jj,mikt(ji,jj)) * umask(ji,jj,mikt(ji,jj)) )
            zmskv = ( 2. - vmask(ji,jj-1,mikt(ji,jj)) * vmask(ji,jj,mikt(ji,jj)) )     ! (CAUTION: CdU<0)
            ustar2_top(ji,jj) = - rCdU_top(ji,jj) * SQRT(  ( zmsku*( uu(ji,jj,mikt(ji,jj),Kbb)+uu(ji-1,jj,mikt(ji,jj),Kbb) ) )**2  &
               &                                         + ( zmskv*( vv(ji,jj,mikt(ji,jj),Kbb)+vv(ji,jj-1,mikt(ji,jj),Kbb) ) )**2  )
         END_2D
      ENDIF

      SELECT CASE ( nn_z0_met )      !==  Set surface roughness length  ==!
      CASE ( 0 )                          ! Constant roughness          
         zhsro(:,:) = rn_hsro
      CASE ( 1 )             ! Standard Charnock formula
         zhsro(:,:) = MAX( rsbc_zs1 * ustar2_surf(:,:) , rn_hsro )
      CASE ( 2 )             ! Roughness formulae according to Rascle et al., Ocean Modelling (2008)
!!gm faster coding : the 2 comment lines should be used
!!gm         zcof = 2._wp * 0.6_wp / 28._wp
!!gm         zdep(:,:)  = 30._wp * TANH(  zcof/ SQRT( MAX(ustar2_surf(:,:),rsmall) )  )       ! Wave age (eq. 10)
         zdep (:,:) = 30.*TANH( 2.*0.3/(28.*SQRT(MAX(ustar2_surf(:,:),rsmall))) )         ! Wave age (eq. 10)
         zhsro(:,:) = MAX(rsbc_zs2 * ustar2_surf(:,:) * zdep(:,:)**1.5, rn_hsro)          ! zhsro = rn_frac_hs * Hsw (eq. 11)
      CASE ( 3 )             ! Roughness given by the wave model (coupled or read in file)
         zhsro(:,:) = rn_frac_hs * hsw(:,:)   ! (rn_frac_hs=1.6 see Eq. (5) of Rascle et al. 2008 )
      END SELECT
      !
#if  defined key_si3 &&  defined key_cice
      SELECT CASE( nn_z0_met_i )             ! Type of scaling under sea-ice
         !
         CASE( 1 )                           ! scaling with constant sea-ice thickness rn_hsro_i defined in namelist 
            DO_2D_00_00
               zhsro(ji,jj) =  ( ( 1. - fr_i(ji,jj) ) * zhsro(ji,jj) + fr_i(ji,jj) * rn_hsro_i ) * tmask(ji,jj,1) + &
               &  + (1._wp - tmask(:,:,1)) * rn_hsro
            END_2D
            !
         CASE( 2 )                                 ! scaling with mean sea-ice thickness
            DO_2D_00_00
#if defined key_si3
               zhsro(ji,jj) = ( ( 1. - fr_i(ji,jj) ) * zhsro(ji,jj) + fr_i(ji,jj) * hm_i(ji,jj) * 2. / vkarmn ) * tmask(ji,jj,1) + &
               &  + (1._wp - tmask(:,:,1)) * rn_hsro
#elif defined key_cice
               zmaxice = MAXVAL( h_i(ji,jj,:) )
               zhsro(ji,jj) = ( ( 1. - fr_i(ji,jj) ) * zhsro(ji,jj) + fr_i(ji,jj) * zmaxice / vkarmn ) * tmask(ji,jj,1) + &
               &  + (1._wp - tmask(:,:,1)) * rn_hsro
#endif
            END_2D
                 !
         CASE( 3 )                                 ! scaling with max sea-ice thickness
            DO_2D_00_00
               zmaxice = MAXVAL( h_i(ji,jj,:) )
               zhsro(ji,jj) = ( ( 1. - fr_i(ji,jj) ) * zhsro(ji,jj) + fr_i(ji,jj) * zmaxice / vkarmn ) * tmask(ji,jj,1) + &
               &  + (1._wp - tmask(:,:,1)) * rn_hsro
            END_2D
                 !
      END SELECT
#endif
      !
      DO_3D_10_10( 2, jpkm1 )
         eps(ji,jj,jk)  = rc03 * en(ji,jj,jk) * SQRT( en(ji,jj,jk) ) / hmxl_n(ji,jj,jk)
      END_3D

      ! Save tke at before time step
      eb    (:,:,:) = en    (:,:,:)
      hmxl_b(:,:,:) = hmxl_n(:,:,:)

      IF( nn_clos == 0 ) THEN    ! Mellor-Yamada
         DO_3D_00_00( 2, jpkm1 )
            zup   = hmxl_n(ji,jj,jk) * gdepw(ji,jj,mbkt(ji,jj)+1,Kmm)
            zdown = vkarmn * gdepw(ji,jj,jk,Kmm) * ( -gdepw(ji,jj,jk,Kmm) + gdepw(ji,jj,mbkt(ji,jj)+1,Kmm) )
            zcoef = ( zup / MAX( zdown, rsmall ) )
            zwall (ji,jj,jk) = ( 1._wp + re2 * zcoef*zcoef ) * tmask(ji,jj,jk)
         END_3D
      ENDIF

      !!---------------------------------!!
      !!   Equation to prognostic k      !!
      !!---------------------------------!!
      !
      ! Now Turbulent kinetic energy (output in en)
      ! -------------------------------
      ! Resolution of a tridiagonal linear system by a "methode de chasse"
      ! computation from level 2 to jpkm1  (e(1) computed after and e(jpk)=0 ).
      ! The surface boundary condition are set after
      ! The bottom boundary condition are also set after. In standard e(bottom)=0.
      ! zdiag : diagonal zd_up : upper diagonal zd_lw : lower diagonal
      ! Warning : after this step, en : right hand side of the matrix

      DO_3D_00_00( 2, jpkm1 )
         !
         buoy = - p_avt(ji,jj,jk) * rn2(ji,jj,jk)     ! stratif. destruction
         !
         diss = eps(ji,jj,jk)                         ! dissipation
         !
         zdir = 0.5_wp + SIGN( 0.5_wp, p_sh2(ji,jj,jk) + buoy )   ! zdir =1(=0) if shear(ji,jj,jk)+buoy >0(<0)
         !
         zesh2 = zdir*(p_sh2(ji,jj,jk)+buoy)+(1._wp-zdir)*p_sh2(ji,jj,jk)          ! production term
         zdiss = zdir*(diss/en(ji,jj,jk))   +(1._wp-zdir)*(diss-buoy)/en(ji,jj,jk) ! dissipation term
!!gm better coding, identical results
!               zesh2 =   p_sh2(ji,jj,jk) + zdir*buoy               ! production term
!               zdiss = ( diss - (1._wp-zdir)*buoy ) / en(ji,jj,jk) ! dissipation term
!!gm
         !
         ! Compute a wall function from 1. to rsc_psi*zwall/rsc_psi0
         ! Note that as long that Dirichlet boundary conditions are NOT set at the first and last levels (GOTM style)
         ! there is no need to set a boundary condition for zwall_psi at the top and bottom boundaries.
         ! Otherwise, this should be rsc_psi/rsc_psi0
         IF( ln_sigpsi ) THEN
            zsigpsi = MIN( 1._wp, zesh2 / eps(ji,jj,jk) )     ! 0. <= zsigpsi <= 1.
            zwall_psi(ji,jj,jk) = rsc_psi /   & 
               &     (  zsigpsi * rsc_psi + (1._wp-zsigpsi) * rsc_psi0 / MAX( zwall(ji,jj,jk), 1._wp )  )
         ELSE
            zwall_psi(ji,jj,jk) = 1._wp
         ENDIF
         !
         ! building the matrix
         zcof = rfact_tke * tmask(ji,jj,jk)
         !                                        ! lower diagonal, in fact not used for jk = 2 (see surface conditions)
         zd_lw(ji,jj,jk) = zcof * ( p_avm(ji,jj,jk  ) + p_avm(ji,jj,jk-1) ) / ( e3t(ji,jj,jk-1,Kmm) * e3w(ji,jj,jk,Kmm) )
         !                                        ! upper diagonal, in fact not used for jk = ibotm1 (see bottom conditions)
         zd_up(ji,jj,jk) = zcof * ( p_avm(ji,jj,jk+1) + p_avm(ji,jj,jk  ) ) / ( e3t(ji,jj,jk  ,Kmm) * e3w(ji,jj,jk,Kmm) )
         !                                        ! diagonal
         zdiag(ji,jj,jk) = 1._wp - zd_lw(ji,jj,jk) - zd_up(ji,jj,jk)  + rn_Dt * zdiss * wmask(ji,jj,jk) 
         !                                        ! right hand side in en
         en(ji,jj,jk) = en(ji,jj,jk) + rn_Dt * zesh2 * wmask(ji,jj,jk)
      END_3D
      !
      zdiag(:,:,jpk) = 1._wp
      !
      ! Set surface condition on zwall_psi (1 at the bottom)
      zwall_psi(:,:, 1 ) = zwall_psi(:,:,2)
      zwall_psi(:,:,jpk) = 1._wp
      !
      ! Surface boundary condition on tke
      ! ---------------------------------
      !
      SELECT CASE ( nn_bc_surf )
      !
      CASE ( 0 )             ! Dirichlet boundary condition (set e at k=1 & 2) 
      ! First level
      en   (:,:,1) = MAX(  rn_emin , rc02r * ustar2_surf(:,:) * (1._wp + rsbc_tke1)**r2_3  )
      zd_lw(:,:,1) = en(:,:,1)
      zd_up(:,:,1) = 0._wp
      zdiag(:,:,1) = 1._wp
      ! 
      ! One level below
      en   (:,:,2) =  MAX(  rc02r * ustar2_surf(:,:) * (  1._wp + rsbc_tke1 * ((zhsro(:,:)+gdepw(:,:,2,Kmm))   &
         &                 / zhsro(:,:) )**(1.5_wp*ra_sf)  )**(2._wp/3._wp)                      , rn_emin   )
      zd_lw(:,:,2) = 0._wp 
      zd_up(:,:,2) = 0._wp
      zdiag(:,:,2) = 1._wp
      !
      !
      CASE ( 1 )             ! Neumann boundary condition (set d(e)/dz)
      !
      ! Dirichlet conditions at k=1
      en   (:,:,1) = MAX(  rc02r * ustar2_surf(:,:) * (1._wp + rsbc_tke1)**r2_3 , rn_emin  )
      zd_lw(:,:,1) = en(:,:,1)
      zd_up(:,:,1) = 0._wp
      zdiag(:,:,1) = 1._wp
      !
      ! at k=2, set de/dz=Fw
      !cbr
      zdiag(:,:,2) = zdiag(:,:,2) +  zd_lw(:,:,2) ! Remove zd_lw from zdiag
      zd_lw(:,:,2) = 0._wp
      zkar (:,:)   = (rl_sf + (vkarmn-rl_sf)*(1.-EXP(-rtrans*gdept(:,:,1,Kmm)/zhsro(:,:)) ))
      zflxs(:,:)   = rsbc_tke2 * ustar2_surf(:,:)**1.5_wp * zkar(:,:) &
          &                    * (  ( zhsro(:,:)+gdept(:,:,1,Kmm) ) / zhsro(:,:)  )**(1.5_wp*ra_sf)
!!gm why not   :                        * ( 1._wp + gdept(:,:,1,Kmm) / zhsro(:,:) )**(1.5_wp*ra_sf)
      en(:,:,2) = en(:,:,2) + zflxs(:,:) / e3w(:,:,2,Kmm)
      !
      !
      END SELECT

      ! Bottom boundary condition on tke
      ! --------------------------------
      !
      SELECT CASE ( nn_bc_bot )
      !
      CASE ( 0 )             ! Dirichlet 
         !                      ! en(ibot) = u*^2 / Co2 and hmxl_n(ibot) = rn_lmin
         !                      ! Balance between the production and the dissipation terms
         DO_2D_00_00
!!gm This means that bottom and ocean w-level above have a specified "en" value.   Sure ????
!!   With thick deep ocean level thickness, this may be quite large, no ???
!!   in particular in ocean cavities where top stratification can be large...
            ibot   = mbkt(ji,jj) + 1      ! k   bottom level of w-point
            ibotm1 = mbkt(ji,jj)          ! k-1 bottom level of w-point but >=1
            !
            z_en =  MAX( rc02r * ustar2_bot(ji,jj), rn_emin )
            !
            ! Dirichlet condition applied at: 
            !     Bottom level (ibot)      &      Just above it (ibotm1)   
            zd_lw(ji,jj,ibot) = 0._wp   ;   zd_lw(ji,jj,ibotm1) = 0._wp
            zd_up(ji,jj,ibot) = 0._wp   ;   zd_up(ji,jj,ibotm1) = 0._wp
            zdiag(ji,jj,ibot) = 1._wp   ;   zdiag(ji,jj,ibotm1) = 1._wp
            en   (ji,jj,ibot) = z_en    ;   en   (ji,jj,ibotm1) = z_en
         END_2D
         !
         IF( ln_isfcav) THEN     ! top boundary   (ocean cavity)
            DO_2D_00_00
               itop   = mikt(ji,jj)       ! k   top w-point
               itopp1 = mikt(ji,jj) + 1   ! k+1 1st w-point below the top one
               !                                                ! mask at the ocean surface points
               z_en = MAX( rc02r * ustar2_top(ji,jj), rn_emin ) * ( 1._wp - tmask(ji,jj,1) )
               !
 !!gm TO BE VERIFIED !!!
               ! Dirichlet condition applied at: 
               !     top level (itop)         &      Just below it (itopp1)   
               zd_lw(ji,jj,itop) = 0._wp   ;   zd_lw(ji,jj,itopp1) = 0._wp
               zd_up(ji,jj,itop) = 0._wp   ;   zd_up(ji,jj,itopp1) = 0._wp
               zdiag(ji,jj,itop) = 1._wp   ;   zdiag(ji,jj,itopp1) = 1._wp
               en   (ji,jj,itop) = z_en    ;   en   (ji,jj,itopp1) = z_en
            END_2D
         ENDIF
         !
      CASE ( 1 )             ! Neumman boundary condition
         !                      
         DO_2D_00_00
            ibot   = mbkt(ji,jj) + 1      ! k   bottom level of w-point
            ibotm1 = mbkt(ji,jj)          ! k-1 bottom level of w-point but >=1
            !
            z_en =  MAX( rc02r * ustar2_bot(ji,jj), rn_emin )
            !
            ! Bottom level Dirichlet condition:
            !     Bottom level (ibot)      &      Just above it (ibotm1)   
            !         Dirichlet            !         Neumann
            zd_lw(ji,jj,ibot) = 0._wp   !   ! Remove zd_up from zdiag
            zdiag(ji,jj,ibot) = 1._wp   ;   zdiag(ji,jj,ibotm1) = zdiag(ji,jj,ibotm1) + zd_up(ji,jj,ibotm1)
            zd_up(ji,jj,ibot) = 0._wp   ;   zd_up(ji,jj,ibotm1) = 0._wp
         END_2D
         IF( ln_isfcav) THEN     ! top boundary   (ocean cavity)
            DO_2D_00_00
               itop   = mikt(ji,jj)       ! k   top w-point
               itopp1 = mikt(ji,jj) + 1   ! k+1 1st w-point below the top one
               !                                                ! mask at the ocean surface points
               z_en = MAX( rc02r * ustar2_top(ji,jj), rn_emin ) * ( 1._wp - tmask(ji,jj,1) )
               !
               ! Bottom level Dirichlet condition:
               !     Bottom level (ibot)      &      Just above it (ibotm1)   
               !         Dirichlet            !         Neumann
               zd_lw(ji,jj,itop) = 0._wp   !   ! Remove zd_up from zdiag
               zdiag(ji,jj,itop) = 1._wp   ;   zdiag(ji,jj,itopp1) = zdiag(ji,jj,itopp1) + zd_up(ji,jj,itopp1)
               zd_up(ji,jj,itop) = 0._wp   ;   zd_up(ji,jj,itopp1) = 0._wp
            END_2D
         ENDIF
         !
      END SELECT

      ! Matrix inversion (en prescribed at surface and the bottom)
      ! ----------------------------------------------------------
      !
      DO_3D_00_00( 2, jpkm1 )
         zdiag(ji,jj,jk) = zdiag(ji,jj,jk) - zd_lw(ji,jj,jk) * zd_up(ji,jj,jk-1) / zdiag(ji,jj,jk-1)
      END_3D
      DO_3D_00_00( 2, jpk )
         zd_lw(ji,jj,jk) = en(ji,jj,jk) - zd_lw(ji,jj,jk) / zdiag(ji,jj,jk-1) * zd_lw(ji,jj,jk-1)
      END_3D
      DO_3DS_00_00( jpk-1, 2, -1 )
         en(ji,jj,jk) = ( zd_lw(ji,jj,jk) - zd_up(ji,jj,jk) * en(ji,jj,jk+1) ) / zdiag(ji,jj,jk)
      END_3D
      !                                            ! set the minimum value of tke 
      en(:,:,:) = MAX( en(:,:,:), rn_emin )

      !!----------------------------------------!!
      !!   Solve prognostic equation for psi    !!
      !!----------------------------------------!!

      ! Set psi to previous time step value
      !
      SELECT CASE ( nn_clos )
      !
      CASE( 0 )               ! k-kl  (Mellor-Yamada)
         DO_3D_00_00( 2, jpkm1 )
            psi(ji,jj,jk)  = eb(ji,jj,jk) * hmxl_b(ji,jj,jk)
         END_3D
         !
      CASE( 1 )               ! k-eps
         DO_3D_00_00( 2, jpkm1 )
            psi(ji,jj,jk)  = eps(ji,jj,jk)
         END_3D
         !
      CASE( 2 )               ! k-w
         DO_3D_00_00( 2, jpkm1 )
            psi(ji,jj,jk)  = SQRT( eb(ji,jj,jk) ) / ( rc0 * hmxl_b(ji,jj,jk) )
         END_3D
         !
      CASE( 3 )               ! generic
         DO_3D_00_00( 2, jpkm1 )
            psi(ji,jj,jk)  = rc02 * eb(ji,jj,jk) * hmxl_b(ji,jj,jk)**rnn 
         END_3D
         !
      END SELECT
      !
      ! Now gls (output in psi)
      ! -------------------------------
      ! Resolution of a tridiagonal linear system by a "methode de chasse"
      ! computation from level 2 to jpkm1  (e(1) already computed and e(jpk)=0 ).
      ! zdiag : diagonal zd_up : upper diagonal zd_lw : lower diagonal
      ! Warning : after this step, en : right hand side of the matrix

      DO_3D_00_00( 2, jpkm1 )
         !
         ! psi / k
         zratio = psi(ji,jj,jk) / eb(ji,jj,jk) 
         !
         ! psi3+ : stable : B=-KhN²<0 => N²>0 if rn2>0 zdir = 1 (stable) otherwise zdir = 0 (unstable)
         zdir = 0.5_wp + SIGN( 0.5_wp, rn2(ji,jj,jk) )
         !
         rpsi3 = zdir * rpsi3m + ( 1._wp - zdir ) * rpsi3p
         !
         ! shear prod. - stratif. destruction
         prod = rpsi1 * zratio * p_sh2(ji,jj,jk)
         !
         ! stratif. destruction
         buoy = rpsi3 * zratio * (- p_avt(ji,jj,jk) * rn2(ji,jj,jk) )
         !
         ! shear prod. - stratif. destruction
         diss = rpsi2 * zratio * zwall(ji,jj,jk) * eps(ji,jj,jk)
         !
         zdir = 0.5_wp + SIGN( 0.5_wp, prod + buoy )     ! zdir =1(=0) if shear(ji,jj,jk)+buoy >0(<0)
         !
         zesh2 = zdir * ( prod + buoy )          + (1._wp - zdir ) * prod                        ! production term
         zdiss = zdir * ( diss / psi(ji,jj,jk) ) + (1._wp - zdir ) * (diss-buoy) / psi(ji,jj,jk) ! dissipation term
         !                                                        
         ! building the matrix
         zcof = rfact_psi * zwall_psi(ji,jj,jk) * tmask(ji,jj,jk)
         !                                               ! lower diagonal
         zd_lw(ji,jj,jk) = zcof * ( p_avm(ji,jj,jk  ) + p_avm(ji,jj,jk-1) ) / ( e3t(ji,jj,jk-1,Kmm) * e3w(ji,jj,jk,Kmm) )
         !                                               ! upper diagonal
         zd_up(ji,jj,jk) = zcof * ( p_avm(ji,jj,jk+1) + p_avm(ji,jj,jk  ) ) / ( e3t(ji,jj,jk  ,Kmm) * e3w(ji,jj,jk,Kmm) )
         !                                               ! diagonal
         zdiag(ji,jj,jk) = 1._wp - zd_lw(ji,jj,jk) - zd_up(ji,jj,jk) + rn_Dt * zdiss * wmask(ji,jj,jk)
         !                                               ! right hand side in psi
         psi(ji,jj,jk) = psi(ji,jj,jk) + rn_Dt * zesh2 * wmask(ji,jj,jk)
      END_3D
      !
      zdiag(:,:,jpk) = 1._wp

      ! Surface boundary condition on psi
      ! ---------------------------------
      !
      SELECT CASE ( nn_bc_surf )
      !
      CASE ( 0 )             ! Dirichlet boundary conditions
         !
         ! Surface value
         zdep    (:,:)   = zhsro(:,:) * rl_sf ! Cosmetic
         psi     (:,:,1) = rc0**rpp * en(:,:,1)**rmm * zdep(:,:)**rnn * tmask(:,:,1)
         zd_lw(:,:,1) = psi(:,:,1)
         zd_up(:,:,1) = 0._wp
         zdiag(:,:,1) = 1._wp
         !
         ! One level below
         zkar    (:,:)   = (rl_sf + (vkarmn-rl_sf)*(1._wp-EXP(-rtrans*gdepw(:,:,2,Kmm)/zhsro(:,:) )))
         zdep    (:,:)   = (zhsro(:,:) + gdepw(:,:,2,Kmm)) * zkar(:,:)
         psi     (:,:,2) = rc0**rpp * en(:,:,2)**rmm * zdep(:,:)**rnn * tmask(:,:,1)
         zd_lw(:,:,2) = 0._wp
         zd_up(:,:,2) = 0._wp
         zdiag(:,:,2) = 1._wp
         ! 
      CASE ( 1 )             ! Neumann boundary condition on d(psi)/dz
         !
         ! Surface value: Dirichlet
         zdep    (:,:)   = zhsro(:,:) * rl_sf
         psi     (:,:,1) = rc0**rpp * en(:,:,1)**rmm * zdep(:,:)**rnn * tmask(:,:,1)
         zd_lw(:,:,1) = psi(:,:,1)
         zd_up(:,:,1) = 0._wp
         zdiag(:,:,1) = 1._wp
         !
         ! Neumann condition at k=2
         zdiag(:,:,2) = zdiag(:,:,2) +  zd_lw(:,:,2) ! Remove zd_lw from zdiag
         zd_lw(:,:,2) = 0._wp
         !
         ! Set psi vertical flux at the surface:
         zkar (:,:)   = rl_sf + (vkarmn-rl_sf)*(1._wp-EXP(-rtrans*gdept(:,:,1,Kmm)/zhsro(:,:) )) ! Lengh scale slope
         zdep (:,:)   = ((zhsro(:,:) + gdept(:,:,1,Kmm)) / zhsro(:,:))**(rmm*ra_sf)
         zflxs(:,:)   = (rnn + rsbc_tke1 * (rnn + rmm*ra_sf) * zdep(:,:))*(1._wp + rsbc_tke1*zdep(:,:))**(2._wp*rmm/3._wp-1_wp)
         zdep (:,:)   = rsbc_psi1 * (zwall_psi(:,:,1)*p_avm(:,:,1)+zwall_psi(:,:,2)*p_avm(:,:,2)) * &
            &           ustar2_surf(:,:)**rmm * zkar(:,:)**rnn * (zhsro(:,:) + gdept(:,:,1,Kmm))**(rnn-1.)
         zflxs(:,:)   = zdep(:,:) * zflxs(:,:)
         psi  (:,:,2) = psi(:,:,2) + zflxs(:,:) / e3w(:,:,2,Kmm)
         !
      END SELECT

      ! Bottom boundary condition on psi
      ! --------------------------------
      !
!!gm should be done for ISF (top boundary cond.)
!!gm so, totally new staff needed      ===>>> think about that !
!
      SELECT CASE ( nn_bc_bot )     ! bottom boundary
      !
      CASE ( 0 )             ! Dirichlet 
         !                      ! en(ibot) = u*^2 / Co2 and hmxl_n(ibot) = vkarmn * r_z0_bot
         !                      ! Balance between the production and the dissipation terms
         DO_2D_00_00
            ibot   = mbkt(ji,jj) + 1      ! k   bottom level of w-point
            ibotm1 = mbkt(ji,jj)          ! k-1 bottom level of w-point but >=1
            zdep(ji,jj) = vkarmn * r_z0_bot
            psi (ji,jj,ibot) = rc0**rpp * en(ji,jj,ibot)**rmm * zdep(ji,jj)**rnn
            zd_lw(ji,jj,ibot) = 0._wp
            zd_up(ji,jj,ibot) = 0._wp
            zdiag(ji,jj,ibot) = 1._wp
            !
            ! Just above last level, Dirichlet condition again (GOTM like)
            zdep(ji,jj) = vkarmn * ( r_z0_bot + e3t(ji,jj,ibotm1,Kmm) )
            psi (ji,jj,ibotm1) = rc0**rpp * en(ji,jj,ibot  )**rmm * zdep(ji,jj)**rnn
            zd_lw(ji,jj,ibotm1) = 0._wp
            zd_up(ji,jj,ibotm1) = 0._wp
            zdiag(ji,jj,ibotm1) = 1._wp
         END_2D
         !
      CASE ( 1 )             ! Neumman boundary condition
         !                      
         DO_2D_00_00
            ibot   = mbkt(ji,jj) + 1      ! k   bottom level of w-point
            ibotm1 = mbkt(ji,jj)          ! k-1 bottom level of w-point but >=1
            !
            ! Bottom level Dirichlet condition:
            zdep(ji,jj) = vkarmn * r_z0_bot
            psi (ji,jj,ibot) = rc0**rpp * en(ji,jj,ibot)**rmm * zdep(ji,jj)**rnn
            !
            zd_lw(ji,jj,ibot) = 0._wp
            zd_up(ji,jj,ibot) = 0._wp
            zdiag(ji,jj,ibot) = 1._wp
            !
            ! Just above last level: Neumann condition with flux injection
            zdiag(ji,jj,ibotm1) = zdiag(ji,jj,ibotm1) + zd_up(ji,jj,ibotm1) ! Remove zd_up from zdiag
            zd_up(ji,jj,ibotm1) = 0.
            !
            ! Set psi vertical flux at the bottom:
            zdep(ji,jj) = r_z0_bot + 0.5_wp*e3t(ji,jj,ibotm1,Kmm)
            zflxb = rsbc_psi2 * ( p_avm(ji,jj,ibot) + p_avm(ji,jj,ibotm1) )   &
               &  * (0.5_wp*(en(ji,jj,ibot)+en(ji,jj,ibotm1)))**rmm * zdep(ji,jj)**(rnn-1._wp)
            psi(ji,jj,ibotm1) = psi(ji,jj,ibotm1) + zflxb / e3w(ji,jj,ibotm1,Kmm)
         END_2D
         !
      END SELECT

      ! Matrix inversion
      ! ----------------
      !
      DO_3D_00_00( 2, jpkm1 )
         zdiag(ji,jj,jk) = zdiag(ji,jj,jk) - zd_lw(ji,jj,jk) * zd_up(ji,jj,jk-1) / zdiag(ji,jj,jk-1)
      END_3D
      DO_3D_00_00( 2, jpk )
         zd_lw(ji,jj,jk) = psi(ji,jj,jk) - zd_lw(ji,jj,jk) / zdiag(ji,jj,jk-1) * zd_lw(ji,jj,jk-1)
      END_3D
      DO_3DS_00_00( jpk-1, 2, -1 )
         psi(ji,jj,jk) = ( zd_lw(ji,jj,jk) - zd_up(ji,jj,jk) * psi(ji,jj,jk+1) ) / zdiag(ji,jj,jk)
      END_3D

      ! Set dissipation
      !----------------

      SELECT CASE ( nn_clos )
      !
      CASE( 0 )               ! k-kl  (Mellor-Yamada)
         DO_3D_00_00( 1, jpkm1 )
            eps(ji,jj,jk) = rc03 * en(ji,jj,jk) * en(ji,jj,jk) * SQRT( en(ji,jj,jk) ) / MAX( psi(ji,jj,jk), rn_epsmin)
         END_3D
         !
      CASE( 1 )               ! k-eps
         DO_3D_00_00( 1, jpkm1 )
            eps(ji,jj,jk) = psi(ji,jj,jk)
         END_3D
         !
      CASE( 2 )               ! k-w
         DO_3D_00_00( 1, jpkm1 )
            eps(ji,jj,jk) = rc04 * en(ji,jj,jk) * psi(ji,jj,jk) 
         END_3D
         !
      CASE( 3 )               ! generic
         zcoef = rc0**( 3._wp  + rpp/rnn )
         zex1  =      ( 1.5_wp + rmm/rnn )
         zex2  = -1._wp / rnn
         DO_3D_00_00( 1, jpkm1 )
            eps(ji,jj,jk) = zcoef * en(ji,jj,jk)**zex1 * psi(ji,jj,jk)**zex2
         END_3D
         !
      END SELECT

      ! Limit dissipation rate under stable stratification
      ! --------------------------------------------------
      DO_3D_00_00( 1, jpkm1 )
         ! limitation
         eps   (ji,jj,jk)  = MAX( eps(ji,jj,jk), rn_epsmin )
         hmxl_n(ji,jj,jk)  = rc03 * en(ji,jj,jk) * SQRT( en(ji,jj,jk) ) / eps(ji,jj,jk)
         ! Galperin criterium (NOTE : Not required if the proper value of C3 in stable cases is calculated) 
         zrn2 = MAX( rn2(ji,jj,jk), rsmall )
         IF( ln_length_lim )   hmxl_n(ji,jj,jk) = MIN(  rn_clim_galp * SQRT( 2._wp * en(ji,jj,jk) / zrn2 ), hmxl_n(ji,jj,jk) )
      END_3D

      !
      ! Stability function and vertical viscosity and diffusivity
      ! ---------------------------------------------------------
      !
      SELECT CASE ( nn_stab_func )
      !
      CASE ( 0 , 1 )             ! Galperin or Kantha-Clayson stability functions
         DO_3D_00_00( 2, jpkm1 )
            ! zcof =  l²/q²
            zcof = hmxl_b(ji,jj,jk) * hmxl_b(ji,jj,jk) / ( 2._wp*eb(ji,jj,jk) )
            ! Gh = -N²l²/q²
            gh = - rn2(ji,jj,jk) * zcof
            gh = MIN( gh, rgh0   )
            gh = MAX( gh, rghmin )
            ! Stability functions from Kantha and Clayson (if C2=C3=0 => Galperin)
            sh = ra2*( 1._wp-6._wp*ra1/rb1 ) / ( 1.-3.*ra2*gh*(6.*ra1+rb2*( 1._wp-rc3 ) ) )
            sm = ( rb1**(-1._wp/3._wp) + ( 18._wp*ra1*ra1 + 9._wp*ra1*ra2*(1._wp-rc2) )*sh*gh ) / (1._wp-9._wp*ra1*ra2*gh)
            !
            ! Store stability function in zstt and zstm
            zstt(ji,jj,jk) = rc_diff * sh * tmask(ji,jj,jk)
            zstm(ji,jj,jk) = rc_diff * sm * tmask(ji,jj,jk)
         END_3D
         !
      CASE ( 2, 3 )               ! Canuto stability functions
         DO_3D_00_00( 2, jpkm1 )
            ! zcof =  l²/q²
            zcof = hmxl_b(ji,jj,jk)*hmxl_b(ji,jj,jk) / ( 2._wp * eb(ji,jj,jk) )
            ! Gh = -N²l²/q²
            gh = - rn2(ji,jj,jk) * zcof
            gh = MIN( gh, rgh0   )
            gh = MAX( gh, rghmin )
            gh = gh * rf6
            ! Gm =  M²l²/q² Shear number
            shr = p_sh2(ji,jj,jk) / MAX( p_avm(ji,jj,jk), rsmall )
            gm = MAX( shr * zcof , 1.e-10 )
            gm = gm * rf6
            gm = MIN ( (rd0 - rd1*gh + rd3*gh*gh) / (rd2-rd4*gh) , gm )
            ! Stability functions from Canuto
            rcff = rd0 - rd1*gh +rd2*gm + rd3*gh*gh - rd4*gh*gm + rd5*gm*gm
            sm = (rs0 - rs1*gh + rs2*gm) / rcff
            sh = (rs4 - rs5*gh + rs6*gm) / rcff
            !
            ! Store stability function in zstt and zstm
            zstt(ji,jj,jk) = rc_diff * sh * tmask(ji,jj,jk)
            zstm(ji,jj,jk) = rc_diff * sm * tmask(ji,jj,jk)
         END_3D
         !
      END SELECT

      ! Boundary conditions on stability functions for momentum (Neumann):
      ! Lines below are useless if GOTM style Dirichlet conditions are used

      zstm(:,:,1) = zstm(:,:,2)

      ! default value, in case jpk > mbkt(ji,jj)+1. Not needed but avoid a bug when looking for undefined values (-fpe0)
      zstm(:,:,jpk) = 0.  
      DO_2D_00_00
         zstm(ji,jj,mbkt(ji,jj)+1) = zstm(ji,jj,mbkt(ji,jj))
      END_2D

      zstt(:,:,  1) = wmask(:,:,  1)  ! default value not needed but avoid a bug when looking for undefined values (-fpe0)
      zstt(:,:,jpk) = wmask(:,:,jpk)  ! default value not needed but avoid a bug when looking for undefined values (-fpe0)

!!gm should be done for ISF (top boundary cond.)
!!gm so, totally new staff needed!!gm

      ! Compute diffusivities/viscosities
      ! The computation below could be restrained to jk=2 to jpkm1 if GOTM style Dirichlet conditions are used
      !  -> yes BUT p_avm(:,:1) and p_avm(:,:jpk) are used when we compute zd_lw(:,:2) and zd_up(:,:jpkm1). These values are
      !     later overwritten by surface/bottom boundaries conditions, so we don't really care of p_avm(:,:1) and p_avm(:,:jpk)
      !     for zd_lw and zd_up but they have to be defined to avoid a bug when looking for undefined values (-fpe0)
      DO_3D_00_00( 1, jpk )
         zsqen = SQRT( 2._wp * en(ji,jj,jk) ) * hmxl_n(ji,jj,jk)
         zavt  = zsqen * zstt(ji,jj,jk)
         zavm  = zsqen * zstm(ji,jj,jk)
         p_avt(ji,jj,jk) = MAX( zavt, avtb(jk) ) * wmask(ji,jj,jk) ! apply mask for zdfmxl routine
         p_avm(ji,jj,jk) = MAX( zavm, avmb(jk) )                   ! Note that avm is not masked at the surface and the bottom
      END_3D
      p_avt(:,:,1) = 0._wp
      !
      IF(sn_cfctl%l_prtctl) THEN
         CALL prt_ctl( tab3d_1=en   , clinfo1=' gls  - e: ', tab3d_2=p_avt, clinfo2=' t: ', kdim=jpk)
         CALL prt_ctl( tab3d_1=p_avm, clinfo1=' gls  - m: ', kdim=jpk )
      ENDIF
      !
   END SUBROUTINE zdf_gls

   SUBROUTINE zdf_gls_init
      !!----------------------------------------------------------------------
      !!                  ***  ROUTINE zdf_gls_init  ***
      !!                     
      !! ** Purpose :   Initialization of the vertical eddy diffivity and 
      !!              viscosity computed using a GLS turbulent closure scheme
      !!
      !! ** Method  :   Read the namzdf_gls namelist and check the parameters
      !!
      !! ** input   :   Namlist namzdf_gls
      !!
      !! ** Action  :   Increase by 1 the nstop flag is setting problem encounter
      !!
      !!----------------------------------------------------------------------
      INTEGER ::   jk    ! dummy loop indices
      INTEGER ::   ios   ! Local integer output status for namelist read
      REAL(wp)::   zcr   ! local scalar
      !!
      NAMELIST/namzdf_gls/rn_emin, rn_epsmin, ln_length_lim,        &
         &            rn_clim_galp, ln_sigpsi, rn_hsro, rn_hsro_i,  &
         &            rn_crban, rn_charn, rn_frac_hs,               &
         &            nn_bc_surf, nn_bc_bot, nn_z0_met, nn_z0_met_i &
         &            nn_stab_func, nn_clos
      !!----------------------------------------------------------
      !
      READ  ( numnam_ref, namzdf_gls, IOSTAT = ios, ERR = 901)
901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namzdf_gls in reference namelist' )

      READ  ( numnam_cfg, namzdf_gls, IOSTAT = ios, ERR = 902 )
902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namzdf_gls in configuration namelist' )
      IF(lwm) WRITE ( numond, namzdf_gls )

      IF(lwp) THEN                     !* Control print
         WRITE(numout,*)
         WRITE(numout,*) 'zdf_gls_init : GLS turbulent closure scheme'
         WRITE(numout,*) '~~~~~~~~~~~~'
         WRITE(numout,*) '   Namelist namzdf_gls : set gls mixing parameters'
         WRITE(numout,*) '      minimum value of en                           rn_emin        = ', rn_emin
         WRITE(numout,*) '      minimum value of eps                          rn_epsmin      = ', rn_epsmin
         WRITE(numout,*) '      Limit dissipation rate under stable stratif.  ln_length_lim  = ', ln_length_lim
         WRITE(numout,*) '      Galperin limit (Standard: 0.53, Holt: 0.26)   rn_clim_galp   = ', rn_clim_galp
         WRITE(numout,*) '      TKE Surface boundary condition                nn_bc_surf     = ', nn_bc_surf
         WRITE(numout,*) '      TKE Bottom boundary condition                 nn_bc_bot      = ', nn_bc_bot
         WRITE(numout,*) '      Modify psi Schmidt number (wb case)           ln_sigpsi      = ', ln_sigpsi
         WRITE(numout,*) '      Craig and Banner coefficient                  rn_crban       = ', rn_crban
         WRITE(numout,*) '      Charnock coefficient                          rn_charn       = ', rn_charn
         WRITE(numout,*) '      Surface roughness formula                     nn_z0_met      = ', nn_z0_met
         WRITE(numout,*) '      Wave height frac. (used if nn_z0_met=2)       rn_frac_hs     = ', rn_frac_hs
         WRITE(numout,*) '      Stability functions                           nn_stab_func   = ', nn_stab_func
         WRITE(numout,*) '      Type of closure                               nn_clos        = ', nn_clos
         WRITE(numout,*) '      Surface roughness (m)                         rn_hsro        = ', rn_hsro
         WRITE(numout,*)
         WRITE(numout,*) '   Namelist namdrg_top/_bot:   used values:'
         WRITE(numout,*) '      top    ocean cavity roughness (m)             rn_z0(_top)   = ', r_z0_top
         WRITE(numout,*) '      Bottom seafloor     roughness (m)             rn_z0(_bot)   = ', r_z0_bot
         WRITE(numout,*)
      ENDIF

      !                                !* allocate GLS arrays
      IF( zdf_gls_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'zdf_gls_init : unable to allocate arrays' )

      !                                !* Check of some namelist values
      IF( nn_bc_surf < 0   .OR. nn_bc_surf   > 1 )   CALL ctl_stop( 'zdf_gls_init: bad flag: nn_bc_surf is 0 or 1' )
      IF( nn_bc_surf < 0   .OR. nn_bc_surf   > 1 )   CALL ctl_stop( 'zdf_gls_init: bad flag: nn_bc_surf is 0 or 1' )
      IF( nn_z0_met  < 0   .OR. nn_z0_met    > 3 )   CALL ctl_stop( 'zdf_gls_init: bad flag: nn_z0_met is 0, 1, 2 or 3' )
      IF( nn_z0_met == 3  .AND. .NOT.ln_wave     )   CALL ctl_stop( 'zdf_gls_init: nn_z0_met=3 requires ln_wave=T' )
      IF( nn_stab_func < 0 .OR. nn_stab_func > 3 )   CALL ctl_stop( 'zdf_gls_init: bad flag: nn_stab_func is 0, 1, 2 and 3' )
      IF( nn_clos      < 0 .OR. nn_clos      > 3 )   CALL ctl_stop( 'zdf_gls_init: bad flag: nn_clos is 0, 1, 2 or 3' )

      SELECT CASE ( nn_clos )          !* set the parameters for the chosen closure
      !
      CASE( 0 )                              ! k-kl  (Mellor-Yamada)
         !
         IF(lwp) WRITE(numout,*) '   ==>>   k-kl closure chosen (i.e. closed to the classical Mellor-Yamada)'
         IF(lwp) WRITE(numout,*)
         rpp     = 0._wp
         rmm     = 1._wp
         rnn     = 1._wp
         rsc_tke = 1.96_wp
         rsc_psi = 1.96_wp
         rpsi1   = 0.9_wp
         rpsi3p  = 1._wp
         rpsi2   = 0.5_wp
         !
         SELECT CASE ( nn_stab_func )
         CASE( 0, 1 )   ;   rpsi3m = 2.53_wp       ! G88 or KC stability functions
         CASE( 2 )      ;   rpsi3m = 2.62_wp       ! Canuto A stability functions
         CASE( 3 )      ;   rpsi3m = 2.38          ! Canuto B stability functions (caution : constant not identified)
         END SELECT
         !
      CASE( 1 )                              ! k-eps
         !
         IF(lwp) WRITE(numout,*) '   ==>>   k-eps closure chosen'
         IF(lwp) WRITE(numout,*)
         rpp     =  3._wp
         rmm     =  1.5_wp
         rnn     = -1._wp
         rsc_tke =  1._wp
         rsc_psi =  1.2_wp  ! Schmidt number for psi
         rpsi1   =  1.44_wp
         rpsi3p  =  1._wp
         rpsi2   =  1.92_wp
         !
         SELECT CASE ( nn_stab_func )
         CASE( 0, 1 )   ;   rpsi3m = -0.52_wp      ! G88 or KC stability functions
         CASE( 2 )      ;   rpsi3m = -0.629_wp     ! Canuto A stability functions
         CASE( 3 )      ;   rpsi3m = -0.566        ! Canuto B stability functions
         END SELECT
         !
      CASE( 2 )                              ! k-omega
         !
         IF(lwp) WRITE(numout,*) '   ==>>   k-omega closure chosen'
         IF(lwp) WRITE(numout,*)
         rpp     = -1._wp
         rmm     =  0.5_wp
         rnn     = -1._wp
         rsc_tke =  2._wp
         rsc_psi =  2._wp
         rpsi1   =  0.555_wp
         rpsi3p  =  1._wp
         rpsi2   =  0.833_wp
         !
         SELECT CASE ( nn_stab_func )
         CASE( 0, 1 )   ;   rpsi3m = -0.58_wp       ! G88 or KC stability functions
         CASE( 2 )      ;   rpsi3m = -0.64_wp       ! Canuto A stability functions
         CASE( 3 )      ;   rpsi3m = -0.64_wp       ! Canuto B stability functions caution : constant not identified)
         END SELECT
         !
      CASE( 3 )                              ! generic
         !
         IF(lwp) WRITE(numout,*) '   ==>>   generic closure chosen'
         IF(lwp) WRITE(numout,*)
         rpp     = 2._wp
         rmm     = 1._wp
         rnn     = -0.67_wp
         rsc_tke = 0.8_wp
         rsc_psi = 1.07_wp
         rpsi1   = 1._wp
         rpsi3p  = 1._wp
         rpsi2   = 1.22_wp
         !
         SELECT CASE ( nn_stab_func )
         CASE( 0, 1 )   ;   rpsi3m = 0.1_wp         ! G88 or KC stability functions
         CASE( 2 )      ;   rpsi3m = 0.05_wp        ! Canuto A stability functions
         CASE( 3 )      ;   rpsi3m = 0.05_wp        ! Canuto B stability functions caution : constant not identified)
         END SELECT
         !
      END SELECT

      !
      SELECT CASE ( nn_stab_func )     !* set the parameters of the stability functions
      !
      CASE ( 0 )                             ! Galperin stability functions
         !
         IF(lwp) WRITE(numout,*) '   ==>>   Stability functions from Galperin'
         rc2     =  0._wp
         rc3     =  0._wp
         rc_diff =  1._wp
         rc0     =  0.5544_wp
         rcm_sf  =  0.9884_wp
         rghmin  = -0.28_wp
         rgh0    =  0.0233_wp
         rghcri  =  0.02_wp
         !
      CASE ( 1 )                             ! Kantha-Clayson stability functions
         !
         IF(lwp) WRITE(numout,*) '   ==>>   Stability functions from Kantha-Clayson'
         rc2     =  0.7_wp
         rc3     =  0.2_wp
         rc_diff =  1._wp
         rc0     =  0.5544_wp
         rcm_sf  =  0.9884_wp
         rghmin  = -0.28_wp
         rgh0    =  0.0233_wp
         rghcri  =  0.02_wp
         !
      CASE ( 2 )                             ! Canuto A stability functions
         !
         IF(lwp) WRITE(numout,*) '   ==>>   Stability functions from Canuto A'
         rs0 = 1.5_wp * rl1 * rl5*rl5
         rs1 = -rl4*(rl6+rl7) + 2._wp*rl4*rl5*(rl1-(1._wp/3._wp)*rl2-rl3) + 1.5_wp*rl1*rl5*rl8
         rs2 = -(3._wp/8._wp) * rl1*(rl6*rl6-rl7*rl7)
         rs4 = 2._wp * rl5
         rs5 = 2._wp * rl4
         rs6 = (2._wp/3._wp) * rl5 * ( 3._wp*rl3*rl3 - rl2*rl2 ) - 0.5_wp * rl5*rl1 * (3._wp*rl3-rl2)   &
            &                                                    + 0.75_wp * rl1 * ( rl6 - rl7 )
         rd0 = 3._wp * rl5*rl5
         rd1 = rl5 * ( 7._wp*rl4 + 3._wp*rl8 )
         rd2 = rl5*rl5 * ( 3._wp*rl3*rl3 - rl2*rl2 ) - 0.75_wp*(rl6*rl6 - rl7*rl7 )
         rd3 = rl4 * ( 4._wp*rl4 + 3._wp*rl8)
         rd4 = rl4 * ( rl2 * rl6 - 3._wp*rl3*rl7 - rl5*(rl2*rl2 - rl3*rl3 ) ) + rl5*rl8 * ( 3._wp*rl3*rl3 - rl2*rl2 )
         rd5 = 0.25_wp * ( rl2*rl2 - 3._wp *rl3*rl3 ) * ( rl6*rl6 - rl7*rl7 )
         rc0 = 0.5268_wp
         rf6 = 8._wp / (rc0**6._wp)
         rc_diff = SQRT(2._wp) / (rc0**3._wp)
         rcm_sf  =  0.7310_wp
         rghmin  = -0.28_wp
         rgh0    =  0.0329_wp
         rghcri  =  0.03_wp
         !
      CASE ( 3 )                             ! Canuto B stability functions
         !
         IF(lwp) WRITE(numout,*) '   ==>>   Stability functions from Canuto B'
         rs0 = 1.5_wp * rm1 * rm5*rm5
         rs1 = -rm4 * (rm6+rm7) + 2._wp * rm4*rm5*(rm1-(1._wp/3._wp)*rm2-rm3) + 1.5_wp * rm1*rm5*rm8
         rs2 = -(3._wp/8._wp) * rm1 * (rm6*rm6-rm7*rm7 )
         rs4 = 2._wp * rm5
         rs5 = 2._wp * rm4
         rs6 = (2._wp/3._wp) * rm5 * (3._wp*rm3*rm3-rm2*rm2) - 0.5_wp * rm5*rm1*(3._wp*rm3-rm2) + 0.75_wp * rm1*(rm6-rm7)
         rd0 = 3._wp * rm5*rm5
         rd1 = rm5 * (7._wp*rm4 + 3._wp*rm8)
         rd2 = rm5*rm5 * (3._wp*rm3*rm3 - rm2*rm2) - 0.75_wp * (rm6*rm6 - rm7*rm7)
         rd3 = rm4 * ( 4._wp*rm4 + 3._wp*rm8 )
         rd4 = rm4 * ( rm2*rm6 -3._wp*rm3*rm7 - rm5*(rm2*rm2 - rm3*rm3) ) + rm5 * rm8 * ( 3._wp*rm3*rm3 - rm2*rm2 )
         rd5 = 0.25_wp * ( rm2*rm2 - 3._wp*rm3*rm3 ) * ( rm6*rm6 - rm7*rm7 )
         rc0 = 0.5268_wp            !!       rc0 = 0.5540_wp (Warner ...) to verify !
         rf6 = 8._wp / ( rc0**6._wp )
         rc_diff = SQRT(2._wp)/(rc0**3.)
         rcm_sf  =  0.7470_wp
         rghmin  = -0.28_wp
         rgh0    =  0.0444_wp
         rghcri  =  0.0414_wp
         !
      END SELECT

      !                                !* Set Schmidt number for psi diffusion in the wave breaking case
      !                                     ! See Eq. (13) of Carniel et al, OM, 30, 225-239, 2009
      !                                     !  or Eq. (17) of Burchard, JPO, 31, 3133-3145, 2001
      IF( ln_sigpsi ) THEN
         ra_sf = -1.5 ! Set kinetic energy slope, then deduce rsc_psi and rl_sf 
         ! Verification: retrieve Burchard (2001) results by uncomenting the line below:
         ! Note that the results depend on the value of rn_cm_sf which is constant (=rc0) in his work
         ! ra_sf = -SQRT(2./3.*rc0**3./rn_cm_sf*rn_sc_tke)/vkarmn
         rsc_psi0 = rsc_tke/(24.*rpsi2)*(-1.+(4.*rnn + ra_sf*(1.+4.*rmm))**2./(ra_sf**2.))
      ELSE
         rsc_psi0 = rsc_psi
      ENDIF

      !                                !* Shear free turbulence parameters
      !
      ra_sf  = -4._wp*rnn*SQRT(rsc_tke) / ( (1._wp+4._wp*rmm)*SQRT(rsc_tke) &
               &                              - SQRT(rsc_tke + 24._wp*rsc_psi0*rpsi2 ) )

      IF ( rn_crban==0._wp ) THEN
         rl_sf = vkarmn
      ELSE
         rl_sf = rc0 * SQRT(rc0/rcm_sf) * SQRT( ( (1._wp + 4._wp*rmm + 8._wp*rmm**2_wp) * rsc_tke        &
            &                                            + 12._wp*rsc_psi0*rpsi2 - (1._wp + 4._wp*rmm)   &
            &                                                     *SQRT(rsc_tke*(rsc_tke                 &
            &                                                        + 24._wp*rsc_psi0*rpsi2)) )         &
            &                                              /(12._wp*rnn**2.)                             )
      ENDIF

      !
      IF(lwp) THEN                     !* Control print
         WRITE(numout,*)
         WRITE(numout,*) '   Limit values :'
         WRITE(numout,*) '      Parameter  m = ', rmm
         WRITE(numout,*) '      Parameter  n = ', rnn
         WRITE(numout,*) '      Parameter  p = ', rpp
         WRITE(numout,*) '      rpsi1    = ', rpsi1
         WRITE(numout,*) '      rpsi2    = ', rpsi2
         WRITE(numout,*) '      rpsi3m   = ', rpsi3m
         WRITE(numout,*) '      rpsi3p   = ', rpsi3p
         WRITE(numout,*) '      rsc_tke  = ', rsc_tke
         WRITE(numout,*) '      rsc_psi  = ', rsc_psi
         WRITE(numout,*) '      rsc_psi0 = ', rsc_psi0
         WRITE(numout,*) '      rc0      = ', rc0
         WRITE(numout,*)
         WRITE(numout,*) '   Shear free turbulence parameters:'
         WRITE(numout,*) '      rcm_sf   = ', rcm_sf
         WRITE(numout,*) '      ra_sf    = ', ra_sf
         WRITE(numout,*) '      rl_sf    = ', rl_sf
      ENDIF

      !                                !* Constants initialization
      rc02  = rc0  * rc0   ;   rc02r = 1. / rc02
      rc03  = rc02 * rc0
      rc04  = rc03 * rc0
      rsbc_tke1 = -3._wp/2._wp*rn_crban*ra_sf*rl_sf                      ! Dirichlet + Wave breaking
      rsbc_tke2 = rn_Dt * rn_crban / rl_sf                                 ! Neumann + Wave breaking 
      zcr = MAX(rsmall, rsbc_tke1**(1./(-ra_sf*3._wp/2._wp))-1._wp )
      rtrans = 0.2_wp / zcr                                              ! Ad. inverse transition length between log and wave layer 
      rsbc_zs1  = rn_charn/grav                                          ! Charnock formula for surface roughness
      rsbc_zs2  = rn_frac_hs / 0.85_wp / grav * 665._wp                  ! Rascle formula for surface roughness 
      rsbc_psi1 = -0.5_wp * rn_Dt * rc0**(rpp-2._wp*rmm) / rsc_psi
      rsbc_psi2 = -0.5_wp * rn_Dt * rc0**rpp * rnn * vkarmn**rnn / rsc_psi ! Neumann + NO Wave breaking 
      !
      rfact_tke = -0.5_wp / rsc_tke * rn_Dt                                ! Cst used for the Diffusion term of tke
      rfact_psi = -0.5_wp / rsc_psi * rn_Dt                                ! Cst used for the Diffusion term of tke
      !
      !                                !* Wall proximity function
!!gm tmask or wmask ????
      zwall(:,:,:) = 1._wp * tmask(:,:,:)

      !                                !* read or initialize all required files  
      CALL gls_rst( nit000, 'READ' )      ! (en, avt_k, avm_k, hmxl_n)
      !
      IF( lwxios ) THEN
         CALL iom_set_rstw_var_active('en')
         CALL iom_set_rstw_var_active('avt_k')
         CALL iom_set_rstw_var_active('avm_k')
         CALL iom_set_rstw_var_active('hmxl_n')
      ENDIF
      !
   END SUBROUTINE zdf_gls_init

   SUBROUTINE gls_rst( kt, cdrw )
      !!---------------------------------------------------------------------
      !!                   ***  ROUTINE gls_rst  ***
      !!                     
      !! ** Purpose :   Read or write TKE file (en) in restart file
      !!
      !! ** Method  :   use of IOM library
      !!                if the restart does not contain TKE, en is either 
      !!                set to rn_emin or recomputed (nn_igls/=0)
      !!----------------------------------------------------------------------
      USE zdf_oce , ONLY : en, avt_k, avm_k   ! ocean vertical physics
      !!
      INTEGER         , INTENT(in) ::   kt     ! ocean time-step
      CHARACTER(len=*), INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
      !
      INTEGER ::   jit, jk   ! dummy loop indices
      INTEGER ::   id1, id2, id3, id4
      INTEGER ::   ji, jj, ikbu, ikbv
      REAL(wp)::   cbx, cby
      !!----------------------------------------------------------------------
      !
      IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise 
         !                                   ! ---------------
         IF( ln_rstart ) THEN                   !* Read the restart file
            id1 = iom_varid( numror, 'en'    , ldstop = .FALSE. )
            id2 = iom_varid( numror, 'avt_k' , ldstop = .FALSE. )
            id3 = iom_varid( numror, 'avm_k' , ldstop = .FALSE. )
            id4 = iom_varid( numror, 'hmxl_n', ldstop = .FALSE. )
            !
            IF( MIN( id1, id2, id3, id4 ) > 0 ) THEN        ! all required arrays exist
               CALL iom_get( numror, jpdom_autoglo, 'en'    , en    , ldxios = lrxios )
               CALL iom_get( numror, jpdom_autoglo, 'avt_k' , avt_k , ldxios = lrxios )
               CALL iom_get( numror, jpdom_autoglo, 'avm_k' , avm_k , ldxios = lrxios )
               CALL iom_get( numror, jpdom_autoglo, 'hmxl_n', hmxl_n, ldxios = lrxios )
            ELSE                        
               IF(lwp) WRITE(numout,*)
               IF(lwp) WRITE(numout,*) '   ==>>   previous run without GLS scheme, set en and hmxl_n to background values'
               en    (:,:,:) = rn_emin
               hmxl_n(:,:,:) = 0.05_wp
               ! avt_k, avm_k already set to the background value in zdf_phy_init
            ENDIF
         ELSE                                   !* Start from rest
            IF(lwp) WRITE(numout,*)
            IF(lwp) WRITE(numout,*) '   ==>>   start from rest, set en and hmxl_n by background values'
            en    (:,:,:) = rn_emin
            hmxl_n(:,:,:) = 0.05_wp
            ! avt_k, avm_k already set to the background value in zdf_phy_init
         ENDIF
         !
      ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
         !                                   ! -------------------
         IF(lwp) WRITE(numout,*) '---- gls-rst ----'
         IF( lwxios ) CALL iom_swap(      cwxios_context         )
         CALL iom_rstput( kt, nitrst, numrow, 'en'    , en    , ldxios = lwxios )
         CALL iom_rstput( kt, nitrst, numrow, 'avt_k' , avt_k , ldxios = lwxios )
         CALL iom_rstput( kt, nitrst, numrow, 'avm_k' , avm_k , ldxios = lwxios )
         CALL iom_rstput( kt, nitrst, numrow, 'hmxl_n', hmxl_n, ldxios = lwxios )
         IF( lwxios ) CALL iom_swap(      cxios_context          )
         !
      ENDIF
      !
   END SUBROUTINE gls_rst

   !!======================================================================
END MODULE zdfgls
chris-O-wilson commented 2 years ago

It seems that two variable names need to be changed in namelist_cfg for compatability with GO8pt6.

rn_hsro_i should be rn_hsri nn_z0_met_i should be nn_z0_ice .

chris-O-wilson commented 2 years ago

Runs of REF_NOTIDE with GLS (params as above) rather than TKE, both with and without EVD active, crashed after ~4 and ~1 yrs, respectively. There was relatively high abs. salinity ~34.7 in the Ross Sea (k=1), with a strong offshore lateral gradient reducing to ~34.0 at the edge of the Ross Gyre, in the former. Both runs were with an 1800s timestep. Testing again with a reduced timestep.

jasontempestholt commented 2 years ago

It would be good to try and avoid reducing timestep, as this will be expensive. but if it works, then it works!

jasontempestholt commented 2 years ago

Hi @chris-O-wilson , first thing I'd try to reduce mixing in this model is change the stability function #1 = KC94 is less diffusive (I think) so try: nn_stab_func = 1 ! stability function (0=Galp, 1= KC94, 2=CanutoA, 3=CanutoB)

In Maria's paper https://agupubs.onlinelibrary.wiley.com/doi/full/10.1029/2018JC014307 I think advocated # 4 = K3, but this might not have reached this code version. This is an updated version of the KC94.

That paper used slightly different versions of rn_emin =1e-6 (wrong way so leave) rn_epsmin = 1.0 e-9 - worth a try And rn_hsro = 0.003 (worth a try).

So maybe try a run with but KC94 and these other two parameter tweeks

Jason

jdha commented 2 years ago

For ref:

Just had a look at my NNA_R12 namelist for SZT:

!-----------------------------------------------------------------------
&namzdf_gls                !   GLS vertical diffusion                   ("key_zdfgls")
!-----------------------------------------------------------------------
   rn_emin       = 1.e-6   !  minimum value of e   [m2/s2]
   rn_epsmin     = 1.e-9  !  minimum value of eps [m2/s3]
!  rn_emin       = 1.e-7   !  minimum value of e   [m2/s2]
!  rn_epsmin     = 1.e-10  !  minimum value of eps [m2/s3]
!  rn_emin       = 1.e-6   !  minimum value of e   [m2/s2]
!  rn_epsmin     = 1.e-12  !  minimum value of eps [m2/s3]
   ln_length_lim = .true.  !  limit on the dissipation rate under stable stratification (Galperin et al., 1988)
   rn_clim_galp  = 0.267    !  galperin limit
   ln_crban      = .true.  !  Use Craig & Banner (1994) surface wave mixing parametrisation
   ln_sigpsi     = .true.  !  Activate or not Burchard 2001 mods on psi schmidt number in the wb case
   rn_crban      = 100.    !  Craig and Banner 1994 constant for wb tke flux
   rn_charn      = 100000.  !  Charnock constant for wb induced roughness length
!  rn_charn      = 70000.  !  Charnock constant for wb induced roughness length
   nn_tkebc_surf =   1     !  surface tke condition (0/1/2=Dir/Neum/Dir Mellor-Blumberg)
   nn_tkebc_bot  =   1     !  bottom tke condition (0/1=Dir/Neum)
   nn_psibc_surf =   1     !  surface psi condition (0/1/2=Dir/Neum/Dir Mellor-Blumberg)
   nn_psibc_bot  =   1     !  bottom psi condition (0/1=Dir/Neum)
   nn_stab_func  =   1     !  stability function (0=Galp, 1= KC94, 2=CanutoA, 3=CanutoB)
!  nn_stab_func  =   2     !  stability function (0=Galp, 1= KC94, 2=CanutoA, 3=CanutoB)
   nn_clos       =   1     !  predefined closure type (0=MY82, 1=k-eps, 2=k-w, 3=Gen)

The one I ran for the NNA_R12 ZPS looks a little more like Maria's pan Arctic:

!-----------------------------------------------------------------------
&namzdf_gls                !   GLS vertical diffusion                   ("key_zdfgls")
!-----------------------------------------------------------------------
   rn_emin       = 1.e-6   !  minimum value of e   [m2/s2]
   rn_epsmin     = 1.e-12  !  minimum value of eps [m2/s3]
   ln_length_lim = .true.  !  limit on the dissipation rate under stable stratification (Galperin et al., 1988)
   rn_clim_galp  = 0.26    !  galperin limit
   ln_crban      = .true.  !  Use Craig & Banner (1994) surface wave mixing parametrisation
   ln_sigpsi     = .true.  !  Activate or not Burchard 2001 mods on psi schmidt number in the wb case
   rn_crban      = 100.    !  Craig and Banner 1994 constant for wb tke flux
   rn_charn      = 70000.  !  Charnock constant for wb induced roughness length
   nn_tkebc_surf =   1     !  surface tke condition (0/1/2=Dir/Neum/Dir Mellor-Blumberg)
   nn_tkebc_bot  =   1     !  bottom tke condition (0/1=Dir/Neum)
   nn_psibc_surf =   1     !  surface psi condition (0/1/2=Dir/Neum/Dir Mellor-Blumberg)
   nn_psibc_bot  =   1     !  bottom psi condition (0/1=Dir/Neum)
   nn_stab_func  =   2     !  stability function (0=Galp, 1= KC94, 2=CanutoA, 3=CanutoB)
   nn_clos       =   1     !  predefined closure type (0=MY82, 1=k-eps, 2=k-w, 3=Gen)

Looks like we were having very similar discussions back then as we are now!

chris-O-wilson commented 2 years ago

Thanks Jason. I’ll look into it.

Chris

From: jasontempestholt @.> Date: Wednesday, 20 October 2021 at 14:46 To: NOC-MSM/SE-NEMO @.> Cc: Wilson, Chris @.>, Mention @.> Subject: Re: [NOC-MSM/SE-NEMO] Test GLS v's TKE (#21)

Caution: This email has originated from outside of the organisation. Do not click links or open attachments unless you have verified the sender and content is safe. Thank you.

Hi @chris-O-wilsonhttps://github.com/chris-O-wilson , first thing I'd try to reduce mixing in this model is change the stability function #1https://github.com/NOC-MSM/SE-NEMO/issues/1 = KC94 is less diffusive (I think) so try: nn_stab_func = 1 ! stability function (0=Galp, 1= KC94, 2=CanutoA, 3=CanutoB)

In Maria's paper https://agupubs.onlinelibrary.wiley.com/doi/full/10.1029/2018JC014307 I think advocated # 4 = K3, but this might not have reached this code version. This is an updated version of the KC94.

That paper used slightly different versions of rn_emin =1e-6 (wrong way so leave) rn_epsmin = 1.0 e-9 - worth a try And rn_hsro = 0.003 (worth a try).

So maybe try a run with but KC94 and these other two parameter tweeks

Jason

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/NOC-MSM/SE-NEMO/issues/21#issuecomment-947684159, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AF32LSN7EDTQPE436ER6Z6LUH3B35ANCNFSM4UDVFZSQ. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

This email and any attachments are intended solely for the use of the named recipients. If you are not the intended recipient you must not use, disclose, copy or distribute this email or any of its attachments and should notify the sender immediately and delete this email from your system. The National Oceanography Centre (NOC) has taken every reasonable precaution to minimise risk of this email or any attachments containing viruses or malware but the recipient should carry out its own virus and malware checks before opening the attachments. NOC does not accept any liability for any losses or damages which the recipient may sustain due to presence of any viruses. Opinions, conclusions or other information in this message and attachments that are not related directly to NOC business are solely those of the author and do not represent the views of NOC.