Index: NEMO/branches/2021/dev_r14608_AGRIF_domcfg/src/OCE/ZDF/zdfgls.F90
===================================================================
--- NEMO/branches/2021/dev_r14608_AGRIF_domcfg/src/OCE/ZDF/zdfgls.F90	(revision 14958)
+++ NEMO/branches/2021/dev_r14608_AGRIF_domcfg/src/OCE/ZDF/zdfgls.F90	(revision 14971)
@@ -26,4 +26,10 @@
    USE zdfmxl         ! mixed layer
    USE sbcwave , ONLY : hsw   ! significant wave height
+#if defined key_si3
+   USE ice, ONLY: hm_i, h_i
+#endif
+#if defined key_cice
+   USE sbc_ice, ONLY: h_i
+#endif
    !
    USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
@@ -51,4 +57,5 @@
    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_mxlice         ! type of scaling under sea-ice (=0/1/2/3)
    INTEGER  ::   nn_bc_surf        ! surface boundary condition (=0/1)
    INTEGER  ::   nn_bc_bot         ! bottom boundary condition (=0/1)
@@ -224,8 +231,26 @@
       !
       ! adapt roughness where there is sea ice
-      DO_2D( nn_hls-1, nn_hls-1, nn_hls-1, nn_hls-1 )
-         zhsro(ji,jj) = ( (1._wp-zice_fra(ji,jj)) * zhsro(ji,jj) + zice_fra(ji,jj) * rn_hsri )*tmask(ji,jj,1)  + &
-            &           (1._wp - tmask(ji,jj,1))*rn_hsro
-      END_2D
+      SELECT CASE( nn_mxlice )       ! Type of scaling under sea-ice
+      !
+      CASE( 1 )                      ! scaling with constant sea-ice roughness
+         DO_2D( nn_hls-1, nn_hls-1, nn_hls-1, nn_hls-1 )
+            zhsro(ji,jj) = ( (1._wp-zice_fra(ji,jj)) * zhsro(ji,jj) + zice_fra(ji,jj) * rn_hsri )*tmask(ji,jj,1)  + (1._wp - tmask(ji,jj,1))*rn_hsro
+         END_2D
+         !
+      CASE( 2 )                      ! scaling with mean sea-ice thickness
+#if defined key_si3
+         DO_2D( nn_hls-1, nn_hls-1, nn_hls-1, nn_hls-1 )
+            zhsro(ji,jj) = ( (1._wp-zice_fra(ji,jj)) * zhsro(ji,jj) + zice_fra(ji,jj) * hm_i(ji,jj) )*tmask(ji,jj,1)  + (1._wp - tmask(ji,jj,1))*rn_hsro
+         END_2D
+#endif
+         !
+      CASE( 3 )                      ! scaling with max sea-ice thickness
+#if defined key_si3 || defined key_cice
+         DO_2D( nn_hls-1, nn_hls-1, nn_hls-1, nn_hls-1 )
+            zhsro(ji,jj) = ( (1._wp-zice_fra(ji,jj)) * zhsro(ji,jj) + zice_fra(ji,jj) * MAXVAL(h_i(ji,jj,:)) )*tmask(ji,jj,1)  + (1._wp - tmask(ji,jj,1))*rn_hsro
+         END_2D
+#endif
+         !
+      END SELECT
       !
       DO_3D( nn_hls-1, nn_hls-1, nn_hls-1, nn_hls-1, 2, jpkm1 )  !==  Compute dissipation rate  ==!
@@ -329,4 +354,23 @@
          END_2D
          !
+         IF( ln_isfcav) THEN     ! top boundary   (ocean cavity)
+            DO_2D_OVR( nn_hls-1, nn_hls-1, nn_hls-1, nn_hls-1 )
+               IF( mikt(ji,jj) > 1 )THEN
+                  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) )
+                  !
+                  ! 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
+               ENDIF
+            END_2D
+         ENDIF
          !
       CASE ( 1 )             ! Neumann boundary condition (set d(e)/dz)
@@ -352,4 +396,24 @@
          END_2D
          !
+         IF( ln_isfcav) THEN     ! top boundary   (ocean cavity)
+            DO_2D_OVR( nn_hls-1, nn_hls-1, nn_hls-1, nn_hls-1 )
+               IF( mikt(ji,jj) > 1 )THEN
+                  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
+                  en   (ji,jj,itop) = z_en
+               ENDIF
+            END_2D
+         ENDIF
          !
       END SELECT
@@ -607,4 +671,26 @@
          END_2D
          !
+         IF( ln_isfcav) THEN     ! top boundary   (ocean cavity)
+            DO_2D( nn_hls-1, nn_hls-1, nn_hls-1, nn_hls-1 )
+               IF ( mikt(ji,jj) > 1 ) THEN
+                  itop   = mikt(ji,jj)       ! k   top w-point
+                  itopp1 = mikt(ji,jj) + 1   ! k+1 1st w-point below the top one
+                  !
+                  zdep(ji,jj) = vkarmn * r_z0_top
+                  psi (ji,jj,itop) = rc0**rpp * en(ji,jj,itop)**rmm *zdep(ji,jj)**rnn
+                  zd_lw(ji,jj,itop) = 0._wp
+                  zd_up(ji,jj,itop) = 0._wp
+                  zdiag(ji,jj,itop) = 1._wp
+                  !
+                  ! Just above last level, Dirichlet condition again (GOTM like)
+                  zdep(ji,jj) = vkarmn * ( r_z0_top + e3t(ji,jj,itopp1,Kmm) )
+                  psi (ji,jj,itopp1) = rc0**rpp * en(ji,jj,itop  )**rmm *zdep(ji,jj)**rnn
+                  zd_lw(ji,jj,itopp1) = 0._wp
+                  zd_up(ji,jj,itopp1) = 0._wp
+                  zdiag(ji,jj,itopp1) = 1._wp
+               END IF
+            END_2D
+         END IF
+         !
       CASE ( 1 )             ! Neumman boundary condition
          !
@@ -631,4 +717,33 @@
             psi(ji,jj,ibotm1) = psi(ji,jj,ibotm1) + zflxb / e3w(ji,jj,ibotm1,Kmm)
          END_2D
+         !
+         IF( ln_isfcav) THEN     ! top boundary   (ocean cavity)
+            DO_2D( nn_hls-1, nn_hls-1, nn_hls-1, nn_hls-1 )
+               IF ( mikt(ji,jj) > 1 ) THEN
+                  itop   = mikt(ji,jj)       ! k   top w-point
+                  itopp1 = mikt(ji,jj) + 1   ! k+1 1st w-point below the top one
+                  !
+                  ! Bottom level Dirichlet condition:
+                  zdep(ji,jj) = vkarmn * r_z0_top
+                  psi (ji,jj,itop) = rc0**rpp * en(ji,jj,itop)**rmm *zdep(ji,jj)**rnn
+                  !
+                  zd_lw(ji,jj,itop) = 0._wp
+                  zd_up(ji,jj,itop) = 0._wp
+                  zdiag(ji,jj,itop) = 1._wp
+                  !
+                  ! Just below cavity level: Neumann condition with flux
+                  ! injection
+                  zdiag(ji,jj,itopp1) = zdiag(ji,jj,itopp1) + zd_up(ji,jj,itopp1) ! Remove zd_up from zdiag
+                  zd_up(ji,jj,itopp1) = 0._wp
+                  !
+                  ! Set psi vertical flux below cavity:
+                  zdep(ji,jj) = r_z0_top + 0.5_wp*e3t(ji,jj,itopp1,Kmm)
+                  zflxb = rsbc_psi2 * ( p_avm(ji,jj,itop) + p_avm(ji,jj,itopp1))   &
+                     &  * (0.5_wp*(en(ji,jj,itop)+en(ji,jj,itopp1)))**rmm * zdep(ji,jj)**(rnn-1._wp)
+                  psi(ji,jj,itopp1) = psi(ji,jj,itopp1) + zflxb / e3w(ji,jj,itopp1,Kmm)
+               END IF
+            END_2D
+         END IF
+
          !
       END SELECT
@@ -799,5 +914,5 @@
       NAMELIST/namzdf_gls/rn_emin, rn_epsmin, ln_length_lim,       &
          &            rn_clim_galp, ln_sigpsi, rn_hsro, rn_hsri,   &
-         &            rn_crban, rn_charn, rn_frac_hs,              &
+         &            nn_mxlice, rn_crban, rn_charn, rn_frac_hs,   &
          &            nn_bc_surf, nn_bc_bot, nn_z0_met, nn_z0_ice, &
          &            nn_stab_func, nn_clos
@@ -839,5 +954,15 @@
          WRITE(numout,*) '      Type of closure                               nn_clos        = ', nn_clos
          WRITE(numout,*) '      Surface roughness (m)                         rn_hsro        = ', rn_hsro
-         WRITE(numout,*) '      Ice-ocean roughness (used if nn_z0_ice/=0)    rn_hsri        = ', rn_hsri
+         WRITE(numout,*) '      type of scaling under sea-ice                 nn_mxlice      = ', nn_mxlice
+         IF( nn_mxlice == 1 ) &
+            WRITE(numout,*) '      Ice-ocean roughness (used if nn_z0_ice/=0) rn_hsri        = ', rn_hsri
+         SELECT CASE( nn_mxlice )             ! Type of scaling under sea-ice
+            CASE( 0 )   ;   WRITE(numout,*) '   ==>>>   No scaling under sea-ice'
+            CASE( 1 )   ;   WRITE(numout,*) '   ==>>>   scaling with constant sea-ice thickness'
+            CASE( 2 )   ;   WRITE(numout,*) '   ==>>>   scaling with mean     sea-ice thickness'
+            CASE( 3 )   ;   WRITE(numout,*) '   ==>>>   scaling with max      sea-ice thickness'
+            CASE DEFAULT
+               CALL ctl_stop( 'zdf_tke_init: wrong value for nn_mxlice, should be 0,1,2,3 ')
+         END SELECT
          WRITE(numout,*)
       ENDIF
