New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
zdfgls.F90 in NEMO/branches/2020/temporary_r4_trunk/src/OCE/ZDF – NEMO

source: NEMO/branches/2020/temporary_r4_trunk/src/OCE/ZDF/zdfgls.F90 @ 13470

Last change on this file since 13470 was 13470, checked in by smasson, 4 years ago

r4_trunk: second change of DO loops for routines to be merged, see #2523

  • Property svn:keywords set to Id
File size: 56.7 KB
Line 
1MODULE zdfgls
2   !!======================================================================
3   !!                       ***  MODULE  zdfgls  ***
4   !! Ocean physics:  vertical mixing coefficient computed from the gls
5   !!                 turbulent closure parameterization
6   !!======================================================================
7   !! History :  3.0  !  2009-09  (G. Reffray)  Original code
8   !!            3.3  !  2010-10  (C. Bricaud)  Add in the reference
9   !!            4.0  !  2017-04  (G. Madec)  remove CPP keys & avm at t-point only
10   !!             -   !  2017-05  (G. Madec)  add top friction as boundary condition
11   !!----------------------------------------------------------------------
12
13   !!----------------------------------------------------------------------
14   !!   zdf_gls       : update momentum and tracer Kz from a gls scheme
15   !!   zdf_gls_init  : initialization, namelist read, and parameters control
16   !!   gls_rst       : read/write gls restart in ocean restart file
17   !!----------------------------------------------------------------------
18   USE oce            ! ocean dynamics and active tracers
19   USE dom_oce        ! ocean space and time domain
20   USE domvvl         ! ocean space and time domain : variable volume layer
21   USE zdfdrg  , ONLY : ln_drg_OFF            ! top/bottom free-slip flag
22   USE zdfdrg  , ONLY : r_z0_top , r_z0_bot   ! top/bottom roughness
23   USE zdfdrg  , ONLY : rCdU_top , rCdU_bot   ! top/bottom friction
24   USE sbc_oce        ! surface boundary condition: ocean
25   USE phycst         ! physical constants
26   USE zdfmxl         ! mixed layer
27   USE sbcwave , ONLY : hsw   ! significant wave height
28   !
29   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
30   USE lib_mpp        ! MPP manager
31   USE prtctl         ! Print control
32   USE in_out_manager ! I/O manager
33   USE iom            ! I/O manager library
34   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
35
36   IMPLICIT NONE
37   PRIVATE
38
39   PUBLIC   zdf_gls        ! called in zdfphy
40   PUBLIC   zdf_gls_init   ! called in zdfphy
41   PUBLIC   gls_rst        ! called in zdfphy
42
43   !
44   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   hmxl_n    !: now mixing length
45   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   zwall   !: wall function
46   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ustar2_surf !: Squared surface velocity scale at T-points
47   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ustar2_top  !: Squared top     velocity scale at T-points
48   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ustar2_bot  !: Squared bottom  velocity scale at T-points
49
50   !                              !! ** Namelist  namzdf_gls  **
51   LOGICAL  ::   ln_length_lim     ! use limit on the dissipation rate under stable stratification (Galperin et al. 1988)
52   LOGICAL  ::   ln_sigpsi         ! Activate Burchard (2003) modification for k-eps closure & wave breaking mixing
53   INTEGER  ::   nn_bc_surf        ! surface boundary condition (=0/1)
54   INTEGER  ::   nn_bc_bot         ! bottom boundary condition (=0/1)
55   INTEGER  ::   nn_z0_met         ! Method for surface roughness computation
56   INTEGER  ::   nn_z0_ice         ! Roughness accounting for sea ice
57   INTEGER  ::   nn_stab_func      ! stability functions G88, KC or Canuto (=0/1/2)
58   INTEGER  ::   nn_clos           ! closure 0/1/2/3 MY82/k-eps/k-w/gen
59   REAL(wp) ::   rn_clim_galp      ! Holt 2008 value for k-eps: 0.267
60   REAL(wp) ::   rn_epsmin         ! minimum value of dissipation (m2/s3)
61   REAL(wp) ::   rn_emin           ! minimum value of TKE (m2/s2)
62   REAL(wp) ::   rn_charn          ! Charnock constant for surface breaking waves mixing : 1400. (standard) or 2.e5 (Stacey value)
63   REAL(wp) ::   rn_crban          ! Craig and Banner constant for surface breaking waves mixing
64   REAL(wp) ::   rn_hsro           ! Minimum surface roughness
65   REAL(wp) ::   rn_hsri           ! Ice ocean roughness
66   REAL(wp) ::   rn_frac_hs        ! Fraction of wave height as surface roughness (if nn_z0_met > 1)
67
68   REAL(wp) ::   rcm_sf        =  0.73_wp     ! Shear free turbulence parameters
69   REAL(wp) ::   ra_sf         = -2.0_wp      ! Must be negative -2 < ra_sf < -1
70   REAL(wp) ::   rl_sf         =  0.2_wp      ! 0 <rl_sf<vkarmn   
71   REAL(wp) ::   rghmin        = -0.28_wp
72   REAL(wp) ::   rgh0          =  0.0329_wp
73   REAL(wp) ::   rghcri        =  0.03_wp
74   REAL(wp) ::   ra1           =  0.92_wp
75   REAL(wp) ::   ra2           =  0.74_wp
76   REAL(wp) ::   rb1           = 16.60_wp
77   REAL(wp) ::   rb2           = 10.10_wp         
78   REAL(wp) ::   re2           =  1.33_wp         
79   REAL(wp) ::   rl1           =  0.107_wp
80   REAL(wp) ::   rl2           =  0.0032_wp
81   REAL(wp) ::   rl3           =  0.0864_wp
82   REAL(wp) ::   rl4           =  0.12_wp
83   REAL(wp) ::   rl5           = 11.9_wp
84   REAL(wp) ::   rl6           =  0.4_wp
85   REAL(wp) ::   rl7           =  0.0_wp
86   REAL(wp) ::   rl8           =  0.48_wp
87   REAL(wp) ::   rm1           =  0.127_wp
88   REAL(wp) ::   rm2           =  0.00336_wp
89   REAL(wp) ::   rm3           =  0.0906_wp
90   REAL(wp) ::   rm4           =  0.101_wp
91   REAL(wp) ::   rm5           = 11.2_wp
92   REAL(wp) ::   rm6           =  0.4_wp
93   REAL(wp) ::   rm7           =  0.0_wp
94   REAL(wp) ::   rm8           =  0.318_wp
95   REAL(wp) ::   rtrans        =  0.1_wp
96   REAL(wp) ::   rc02, rc02r, rc03, rc04                          ! coefficients deduced from above parameters
97   REAL(wp) ::   rsbc_tke1, rsbc_tke2, rfact_tke                  !     -           -           -        -
98   REAL(wp) ::   rsbc_psi1, rsbc_psi2, rfact_psi                  !     -           -           -        -
99   REAL(wp) ::   rsbc_zs1, rsbc_zs2                               !     -           -           -        -
100   REAL(wp) ::   rc0, rc2, rc3, rf6, rcff, rc_diff                !     -           -           -        -
101   REAL(wp) ::   rs0, rs1, rs2, rs4, rs5, rs6                     !     -           -           -        -
102   REAL(wp) ::   rd0, rd1, rd2, rd3, rd4, rd5                     !     -           -           -        -
103   REAL(wp) ::   rsc_tke, rsc_psi, rpsi1, rpsi2, rpsi3, rsc_psi0  !     -           -           -        -
104   REAL(wp) ::   rpsi3m, rpsi3p, rpp, rmm, rnn                    !     -           -           -        -
105   !
106   REAL(wp) ::   r2_3 = 2._wp/3._wp   ! constant=2/3
107
108   !! * Substitutions
109#  include "vectopt_loop_substitute.h90"
110   !!----------------------------------------------------------------------
111   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
112   !! $Id$
113   !! Software governed by the CeCILL license (see ./LICENSE)
114   !!----------------------------------------------------------------------
115CONTAINS
116
117   INTEGER FUNCTION zdf_gls_alloc()
118      !!----------------------------------------------------------------------
119      !!                ***  FUNCTION zdf_gls_alloc  ***
120      !!----------------------------------------------------------------------
121      ALLOCATE( hmxl_n(jpi,jpj,jpk) , ustar2_surf(jpi,jpj) ,                     &
122         &      zwall (jpi,jpj,jpk) , ustar2_top (jpi,jpj) , ustar2_bot(jpi,jpj) , STAT= zdf_gls_alloc )
123         !
124      CALL mpp_sum ( 'zdfgls', zdf_gls_alloc )
125      IF( zdf_gls_alloc /= 0 )   CALL ctl_stop( 'STOP', 'zdf_gls_alloc: failed to allocate arrays' )
126   END FUNCTION zdf_gls_alloc
127
128
129   SUBROUTINE zdf_gls( kt, p_sh2, p_avm, p_avt )
130      !!----------------------------------------------------------------------
131      !!                   ***  ROUTINE zdf_gls  ***
132      !!
133      !! ** Purpose :   Compute the vertical eddy viscosity and diffusivity
134      !!              coefficients using the GLS turbulent closure scheme.
135      !!----------------------------------------------------------------------
136      USE zdf_oce , ONLY : en, avtb, avmb   ! ocean vertical physics
137      !!
138      INTEGER                   , INTENT(in   ) ::   kt             ! ocean time step
139      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   p_sh2          ! shear production term
140      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   p_avm, p_avt   !  momentum and tracer Kz (w-points)
141      !
142      INTEGER  ::   ji, jj, jk    ! dummy loop arguments
143      INTEGER  ::   ibot, ibotm1  ! local integers
144      INTEGER  ::   itop, itopp1  !   -       -
145      REAL(wp) ::   zesh2, zsigpsi, zcoef, zex1 , zex2  ! local scalars
146      REAL(wp) ::   ztx2, zty2, zup, zdown, zcof, zdir  !   -      -
147      REAL(wp) ::   zratio, zrn2, zflxb, sh     , z_en  !   -      -
148      REAL(wp) ::   prod, buoy, diss, zdiss, sm         !   -      -
149      REAL(wp) ::   gh, gm, shr, dif, zsqen, zavt, zavm !   -      -
150      REAL(wp) ::   zmsku, zmskv                        !   -      -
151      REAL(wp), DIMENSION(jpi,jpj)     ::   zdep
152      REAL(wp), DIMENSION(jpi,jpj)     ::   zkar
153      REAL(wp), DIMENSION(jpi,jpj)     ::   zflxs       ! Turbulence fluxed induced by internal waves
154      REAL(wp), DIMENSION(jpi,jpj)     ::   zhsro       ! Surface roughness (surface waves)
155      REAL(wp), DIMENSION(jpi,jpj)     ::   zice_fra    ! Tapering of wave breaking under sea ice
156      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   eb          ! tke at time before
157      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   hmxl_b      ! mixing length at time before
158      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   eps         ! dissipation rate
159      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwall_psi   ! Wall function use in the wb case (ln_sigpsi)
160      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   psi         ! psi at time now
161      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zd_lw, zd_up, zdiag   ! lower, upper  and diagonal of the matrix
162      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zstt, zstm  ! stability function on tracer and momentum
163      !!--------------------------------------------------------------------
164      !
165      ! Preliminary computing
166
167      ustar2_surf(:,:) = 0._wp   ;         psi(:,:,:) = 0._wp   
168      ustar2_top (:,:) = 0._wp   ;   zwall_psi(:,:,:) = 0._wp
169      ustar2_bot (:,:) = 0._wp
170
171      SELECT CASE ( nn_z0_ice )
172      CASE( 0 )   ;   zice_fra(:,:) = 0._wp
173      CASE( 1 )   ;   zice_fra(:,:) =        TANH( fr_i(:,:) * 10._wp )
174      CASE( 2 )   ;   zice_fra(:,:) =              fr_i(:,:)
175      CASE( 3 )   ;   zice_fra(:,:) = MIN( 4._wp * fr_i(:,:) , 1._wp )
176      END SELECT
177     
178      ! Compute surface, top and bottom friction at T-points
179      DO_2D( 0, 0, 0, 0 )
180         ustar2_surf(ji,jj) = r1_rau0 * taum(ji,jj) * tmask(ji,jj,1)
181      END_2D
182      !   
183!!gm Rq we may add here r_ke0(_top/_bot) ?  ==>> think about that...
184      !   
185      IF( .NOT.ln_drg_OFF ) THEN    !== top/bottom friction   (explicit before friction)
186         DO_2D( 0, 0, 0, 0 )
187            zmsku = ( 2._wp - umask(ji-1,jj,mbkt(ji,jj)) * umask(ji,jj,mbkt(ji,jj)) )
188            zmskv = ( 2._wp - vmask(ji,jj-1,mbkt(ji,jj)) * vmask(ji,jj,mbkt(ji,jj)) )     ! (CAUTION: CdU<0)
189            ustar2_bot(ji,jj) = - rCdU_bot(ji,jj) * SQRT(  ( zmsku*( uu(ji,jj,mbkt(ji,jj),Nnn)+uu(ji-1,jj,mbkt(ji,jj),Nnn) ) )**2  &
190               &                                         + ( zmskv*( vv(ji,jj,mbkt(ji,jj),Nnn)+vv(ji,jj-1,mbkt(ji,jj),Nnn) ) )**2  )
191         END_2D
192         IF( ln_isfcav ) THEN       !top friction
193            DO_2D( 0, 0, 0, 0 )
194               zmsku = ( 2._wp - umask(ji-1,jj,mikt(ji,jj)) * umask(ji,jj,mikt(ji,jj)) )
195               zmskv = ( 2._wp - vmask(ji,jj-1,mikt(ji,jj)) * vmask(ji,jj,mikt(ji,jj)) )     ! (CAUTION: CdU<0)
196               ustar2_top(ji,jj) = - rCdU_top(ji,jj) * SQRT(  ( zmsku*( uu(ji,jj,mikt(ji,jj),Nnn)+uu(ji-1,jj,mikt(ji,jj),Nnn) ) )**2  &
197                  &                                         + ( zmskv*( vv(ji,jj,mikt(ji,jj),Nnn)+vv(ji,jj-1,mikt(ji,jj),Nnn) ) )**2  )
198            END_2D
199         ENDIF
200      ENDIF
201   
202      SELECT CASE ( nn_z0_met )      !==  Set surface roughness length  ==!
203      CASE ( 0 )                          ! Constant roughness         
204         zhsro(:,:) = rn_hsro
205      CASE ( 1 )             ! Standard Charnock formula
206         zhsro(:,:) = MAX( rsbc_zs1 * ustar2_surf(:,:) , rn_hsro )
207      CASE ( 2 )             ! Roughness formulae according to Rascle et al., Ocean Modelling (2008)
208!!gm faster coding : the 2 comment lines should be used
209!!gm         zcof = 2._wp * 0.6_wp / 28._wp
210!!gm         zdep(:,:)  = 30._wp * TANH(  zcof/ SQRT( MAX(ustar2_surf(:,:),rsmall) )  )       ! Wave age (eq. 10)
211         zdep (:,:) = 30.*TANH( 2.*0.3/(28.*SQRT(MAX(ustar2_surf(:,:),rsmall))) )         ! Wave age (eq. 10)
212         zhsro(:,:) = MAX(rsbc_zs2 * ustar2_surf(:,:) * zdep(:,:)**1.5, rn_hsro)          ! zhsro = rn_frac_hs * Hsw (eq. 11)
213      CASE ( 3 )             ! Roughness given by the wave model (coupled or read in file)
214         zhsro(:,:) = MAX(rn_frac_hs * hsw(:,:), rn_hsro)   ! (rn_frac_hs=1.6 see Eq. (5) of Rascle et al. 2008 )
215      END SELECT
216      !
217      ! adapt roughness where there is sea ice
218      zhsro(:,:) = ( (1._wp-zice_fra(:,:)) * zhsro(:,:) + zice_fra(:,:) * rn_hsri )*tmask(:,:,1)  + (1._wp - tmask(:,:,1))*rn_hsro
219      !
220      DO_3D( 1, 0, 1, 0, 2, jpkm1 )
221         eps(ji,jj,jk)  = rc03 * en(ji,jj,jk) * SQRT( en(ji,jj,jk) ) / hmxl_n(ji,jj,jk)
222      END_3D
223
224      ! Save tke at before time step
225      eb    (:,:,:) = en    (:,:,:)
226      hmxl_b(:,:,:) = hmxl_n(:,:,:)
227
228      IF( nn_clos == 0 ) THEN    ! Mellor-Yamada
229         DO_3D( 0, 0, 0, 0, 2, jpkm1 )
230            zup   = hmxl_n(ji,jj,jk) * gdepw_n(ji,jj,mbkt(ji,jj)+1)
231            zdown = vkarmn * gdepw_n(ji,jj,jk) * ( -gdepw_n(ji,jj,jk) + gdepw_n(ji,jj,mbkt(ji,jj)+1) )
232            zcoef = ( zup / MAX( zdown, rsmall ) )
233            zwall (ji,jj,jk) = ( 1._wp + re2 * zcoef*zcoef ) * tmask(ji,jj,jk)
234         END_3D
235      ENDIF
236
237      !!---------------------------------!!
238      !!   Equation to prognostic k      !!
239      !!---------------------------------!!
240      !
241      ! Now Turbulent kinetic energy (output in en)
242      ! -------------------------------
243      ! Resolution of a tridiagonal linear system by a "methode de chasse"
244      ! computation from level 2 to jpkm1  (e(1) computed after and e(jpk)=0 ).
245      ! The surface boundary condition are set after
246      ! The bottom boundary condition are also set after. In standard e(bottom)=0.
247      ! zdiag : diagonal zd_up : upper diagonal zd_lw : lower diagonal
248      ! Warning : after this step, en : right hand side of the matrix
249
250      DO_3D( 0, 0, 0, 0, 2, jpkm1 )
251         !
252         buoy = - p_avt(ji,jj,jk) * rn2(ji,jj,jk)     ! stratif. destruction
253         !
254         diss = eps(ji,jj,jk)                         ! dissipation
255         !
256         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)
257         !
258         zesh2 = zdir*(p_sh2(ji,jj,jk)+buoy)+(1._wp-zdir)*p_sh2(ji,jj,jk)          ! production term
259         zdiss = zdir*(diss/en(ji,jj,jk))   +(1._wp-zdir)*(diss-buoy)/en(ji,jj,jk) ! dissipation term
260!!gm better coding, identical results
261!               zesh2 =   p_sh2(ji,jj,jk) + zdir*buoy               ! production term
262!               zdiss = ( diss - (1._wp-zdir)*buoy ) / en(ji,jj,jk) ! dissipation term
263!!gm
264         !
265         ! Compute a wall function from 1. to rsc_psi*zwall/rsc_psi0
266         ! Note that as long that Dirichlet boundary conditions are NOT set at the first and last levels (GOTM style)
267         ! there is no need to set a boundary condition for zwall_psi at the top and bottom boundaries.
268         ! Otherwise, this should be rsc_psi/rsc_psi0
269         IF( ln_sigpsi ) THEN
270            zsigpsi = MIN( 1._wp, zesh2 / eps(ji,jj,jk) )     ! 0. <= zsigpsi <= 1.
271            zwall_psi(ji,jj,jk) = rsc_psi /   & 
272               &     (  zsigpsi * rsc_psi + (1._wp-zsigpsi) * rsc_psi0 / MAX( zwall(ji,jj,jk), 1._wp )  )
273         ELSE
274            zwall_psi(ji,jj,jk) = 1._wp
275         ENDIF
276         !
277         ! building the matrix
278         zcof = rfact_tke * tmask(ji,jj,jk)
279         !                                        ! lower diagonal, in fact not used for jk = 2 (see surface conditions)
280         zd_lw(ji,jj,jk) = zcof * ( p_avm(ji,jj,jk  ) + p_avm(ji,jj,jk-1) ) / ( e3t_n(ji,jj,jk-1) * e3w_n(ji,jj,jk) )
281         !                                        ! upper diagonal, in fact not used for jk = ibotm1 (see bottom conditions)
282         zd_up(ji,jj,jk) = zcof * ( p_avm(ji,jj,jk+1) + p_avm(ji,jj,jk  ) ) / ( e3t_n(ji,jj,jk  ) * e3w_n(ji,jj,jk) )
283         !                                        ! diagonal
284         zdiag(ji,jj,jk) = 1._wp - zd_lw(ji,jj,jk) - zd_up(ji,jj,jk)  + rdt * zdiss * wmask(ji,jj,jk) 
285         !                                        ! right hand side in en
286         en(ji,jj,jk) = en(ji,jj,jk) + rdt * zesh2 * wmask(ji,jj,jk)
287      END_3D
288      !
289      zdiag(:,:,jpk) = 1._wp
290      !
291      ! Set surface condition on zwall_psi (1 at the bottom)
292      zwall_psi(:,:, 1 ) = zwall_psi(:,:,2)
293      zwall_psi(:,:,jpk) = 1._wp
294      !
295      ! Surface boundary condition on tke
296      ! ---------------------------------
297      !
298      SELECT CASE ( nn_bc_surf )
299      !
300      CASE ( 0 )             ! Dirichlet boundary condition (set e at k=1 & 2)
301      ! First level
302      en   (:,:,1) = MAX(  rn_emin , rc02r * ustar2_surf(:,:) * (1._wp + (1._wp-zice_fra(:,:))*rsbc_tke1)**r2_3  )
303      zd_lw(:,:,1) = en(:,:,1)
304      zd_up(:,:,1) = 0._wp
305      zdiag(:,:,1) = 1._wp
306      !
307      ! One level below
308      en   (:,:,2) =  MAX(  rc02r * ustar2_surf(:,:) * (  1._wp + (1._wp-zice_fra(:,:))*rsbc_tke1 * ((zhsro(:,:)+gdepw_n(:,:,2)) &
309         &                 / zhsro(:,:) )**(1.5_wp*ra_sf)  )**(2._wp/3._wp) , rn_emin   )
310      zd_lw(:,:,2) = 0._wp 
311      zd_up(:,:,2) = 0._wp
312      zdiag(:,:,2) = 1._wp
313      !
314      !
315      CASE ( 1 )             ! Neumann boundary condition (set d(e)/dz)
316      !
317      ! Dirichlet conditions at k=1
318      en   (:,:,1) = MAX(  rc02r * ustar2_surf(:,:) * (1._wp + (1._wp-zice_fra(:,:))*rsbc_tke1)**r2_3 , rn_emin  )
319      zd_lw(:,:,1) = en(:,:,1)
320      zd_up(:,:,1) = 0._wp
321      zdiag(:,:,1) = 1._wp
322      !
323      ! at k=2, set de/dz=Fw
324      !cbr
325      zdiag(:,:,2) = zdiag(:,:,2) +  zd_lw(:,:,2) ! Remove zd_lw from zdiag
326      zd_lw(:,:,2) = 0._wp
327      zkar (:,:)   = (rl_sf + (vkarmn-rl_sf)*(1.-EXP(-rtrans*gdept_n(:,:,1)/zhsro(:,:)) ))
328      zflxs(:,:)   = rsbc_tke2 * (1._wp-zice_fra(:,:)) * ustar2_surf(:,:)**1.5_wp * zkar(:,:) &
329          &                    * (  ( zhsro(:,:)+gdept_n(:,:,1) ) / zhsro(:,:)  )**(1.5_wp*ra_sf)
330!!gm why not   :                        * ( 1._wp + gdept_n(:,:,1) / zhsro(:,:) )**(1.5_wp*ra_sf)
331      en(:,:,2) = en(:,:,2) + zflxs(:,:) / e3w_n(:,:,2)
332      !
333      !
334      END SELECT
335
336      ! Bottom boundary condition on tke
337      ! --------------------------------
338      !
339      SELECT CASE ( nn_bc_bot )
340      !
341      CASE ( 0 )             ! Dirichlet
342         !                      ! en(ibot) = u*^2 / Co2 and hmxl_n(ibot) = rn_lmin
343         !                      ! Balance between the production and the dissipation terms
344         DO_2D( 0, 0, 0, 0 )
345!!gm This means that bottom and ocean w-level above have a specified "en" value.   Sure ????
346!!   With thick deep ocean level thickness, this may be quite large, no ???
347!!   in particular in ocean cavities where top stratification can be large...
348            ibot   = mbkt(ji,jj) + 1      ! k   bottom level of w-point
349            ibotm1 = mbkt(ji,jj)          ! k-1 bottom level of w-point but >=1
350            !
351            z_en =  MAX( rc02r * ustar2_bot(ji,jj), rn_emin )
352            !
353            ! Dirichlet condition applied at:
354            !     Bottom level (ibot)      &      Just above it (ibotm1)   
355            zd_lw(ji,jj,ibot) = 0._wp   ;   zd_lw(ji,jj,ibotm1) = 0._wp
356            zd_up(ji,jj,ibot) = 0._wp   ;   zd_up(ji,jj,ibotm1) = 0._wp
357            zdiag(ji,jj,ibot) = 1._wp   ;   zdiag(ji,jj,ibotm1) = 1._wp
358            en   (ji,jj,ibot) = z_en    ;   en   (ji,jj,ibotm1) = z_en
359         END_2D
360         !
361         IF( ln_isfcav) THEN     ! top boundary   (ocean cavity)
362            DO_2D( 0, 0, 0, 0 )
363               itop   = mikt(ji,jj)       ! k   top w-point
364               itopp1 = mikt(ji,jj) + 1   ! k+1 1st w-point below the top one
365               !                                                ! mask at the ocean surface points
366               z_en = MAX( rc02r * ustar2_top(ji,jj), rn_emin ) * ( 1._wp - tmask(ji,jj,1) )
367               !
368 !!gm TO BE VERIFIED !!!
369               ! Dirichlet condition applied at:
370               !     top level (itop)         &      Just below it (itopp1)   
371               zd_lw(ji,jj,itop) = 0._wp   ;   zd_lw(ji,jj,itopp1) = 0._wp
372               zd_up(ji,jj,itop) = 0._wp   ;   zd_up(ji,jj,itopp1) = 0._wp
373               zdiag(ji,jj,itop) = 1._wp   ;   zdiag(ji,jj,itopp1) = 1._wp
374               en   (ji,jj,itop) = z_en    ;   en   (ji,jj,itopp1) = z_en
375            END_2D
376         ENDIF
377         !
378      CASE ( 1 )             ! Neumman boundary condition
379         !                     
380         DO_2D( 0, 0, 0, 0 )
381            ibot   = mbkt(ji,jj) + 1      ! k   bottom level of w-point
382            ibotm1 = mbkt(ji,jj)          ! k-1 bottom level of w-point but >=1
383            !
384            z_en =  MAX( rc02r * ustar2_bot(ji,jj), rn_emin )
385            !
386            ! Bottom level Dirichlet condition:
387            !     Bottom level (ibot)      &      Just above it (ibotm1)   
388            !         Dirichlet            !         Neumann
389            zd_lw(ji,jj,ibot) = 0._wp   !   ! Remove zd_up from zdiag
390            zdiag(ji,jj,ibot) = 1._wp   ;   zdiag(ji,jj,ibotm1) = zdiag(ji,jj,ibotm1) + zd_up(ji,jj,ibotm1)
391            zd_up(ji,jj,ibot) = 0._wp   ;   zd_up(ji,jj,ibotm1) = 0._wp
392         END_2D
393         IF( ln_isfcav) THEN     ! top boundary   (ocean cavity)
394            DO_2D( 0, 0, 0, 0 )
395               itop   = mikt(ji,jj)       ! k   top w-point
396               itopp1 = mikt(ji,jj) + 1   ! k+1 1st w-point below the top one
397               !                                                ! mask at the ocean surface points
398               z_en = MAX( rc02r * ustar2_top(ji,jj), rn_emin ) * ( 1._wp - tmask(ji,jj,1) )
399               !
400               ! Bottom level Dirichlet condition:
401               !     Bottom level (ibot)      &      Just above it (ibotm1)   
402               !         Dirichlet            !         Neumann
403               zd_lw(ji,jj,itop) = 0._wp   !   ! Remove zd_up from zdiag
404               zdiag(ji,jj,itop) = 1._wp   ;   zdiag(ji,jj,itopp1) = zdiag(ji,jj,itopp1) + zd_up(ji,jj,itopp1)
405               zd_up(ji,jj,itop) = 0._wp   ;   zd_up(ji,jj,itopp1) = 0._wp
406            END_2D
407         ENDIF
408         !
409      END SELECT
410
411      ! Matrix inversion (en prescribed at surface and the bottom)
412      ! ----------------------------------------------------------
413      !
414      DO_3D( 0, 0, 0, 0, 2, jpkm1 )
415         zdiag(ji,jj,jk) = zdiag(ji,jj,jk) - zd_lw(ji,jj,jk) * zd_up(ji,jj,jk-1) / zdiag(ji,jj,jk-1)
416      END_3D
417      DO_3D( 0, 0, 0, 0, 2, jpk )
418         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)
419      END_3D
420      DO_3D( 0, 0, 0, 0, jpk-1, 2, -1 )
421         en(ji,jj,jk) = ( zd_lw(ji,jj,jk) - zd_up(ji,jj,jk) * en(ji,jj,jk+1) ) / zdiag(ji,jj,jk)
422      END_3D
423      !                                            ! set the minimum value of tke
424      en(:,:,:) = MAX( en(:,:,:), rn_emin )
425
426      !!----------------------------------------!!
427      !!   Solve prognostic equation for psi    !!
428      !!----------------------------------------!!
429
430      ! Set psi to previous time step value
431      !
432      SELECT CASE ( nn_clos )
433      !
434      CASE( 0 )               ! k-kl  (Mellor-Yamada)
435         DO_3D( 0, 0, 0, 0, 2, jpkm1 )
436            psi(ji,jj,jk)  = eb(ji,jj,jk) * hmxl_b(ji,jj,jk)
437         END_3D
438         !
439      CASE( 1 )               ! k-eps
440         DO_3D( 0, 0, 0, 0, 2, jpkm1 )
441            psi(ji,jj,jk)  = eps(ji,jj,jk)
442         END_3D
443         !
444      CASE( 2 )               ! k-w
445         DO_3D( 0, 0, 0, 0, 2, jpkm1 )
446            psi(ji,jj,jk)  = SQRT( eb(ji,jj,jk) ) / ( rc0 * hmxl_b(ji,jj,jk) )
447         END_3D
448         !
449      CASE( 3 )               ! generic
450         DO_3D( 0, 0, 0, 0, 2, jpkm1 )
451            psi(ji,jj,jk)  = rc02 * eb(ji,jj,jk) * hmxl_b(ji,jj,jk)**rnn 
452         END_3D
453         !
454      END SELECT
455      !
456      ! Now gls (output in psi)
457      ! -------------------------------
458      ! Resolution of a tridiagonal linear system by a "methode de chasse"
459      ! computation from level 2 to jpkm1  (e(1) already computed and e(jpk)=0 ).
460      ! zdiag : diagonal zd_up : upper diagonal zd_lw : lower diagonal
461      ! Warning : after this step, en : right hand side of the matrix
462
463      DO_3D( 0, 0, 0, 0, 2, jpkm1 )
464         !
465         ! psi / k
466         zratio = psi(ji,jj,jk) / eb(ji,jj,jk) 
467         !
468         ! psi3+ : stable : B=-KhN²<0 => N²>0 if rn2>0 zdir = 1 (stable) otherwise zdir = 0 (unstable)
469         zdir = 0.5_wp + SIGN( 0.5_wp, rn2(ji,jj,jk) )
470         !
471         rpsi3 = zdir * rpsi3m + ( 1._wp - zdir ) * rpsi3p
472         !
473         ! shear prod. - stratif. destruction
474         prod = rpsi1 * zratio * p_sh2(ji,jj,jk)
475         !
476         ! stratif. destruction
477         buoy = rpsi3 * zratio * (- p_avt(ji,jj,jk) * rn2(ji,jj,jk) )
478         !
479         ! shear prod. - stratif. destruction
480         diss = rpsi2 * zratio * zwall(ji,jj,jk) * eps(ji,jj,jk)
481         !
482         zdir = 0.5_wp + SIGN( 0.5_wp, prod + buoy )     ! zdir =1(=0) if shear(ji,jj,jk)+buoy >0(<0)
483         !
484         zesh2 = zdir * ( prod + buoy )          + (1._wp - zdir ) * prod                        ! production term
485         zdiss = zdir * ( diss / psi(ji,jj,jk) ) + (1._wp - zdir ) * (diss-buoy) / psi(ji,jj,jk) ! dissipation term
486         !                                                       
487         ! building the matrix
488         zcof = rfact_psi * zwall_psi(ji,jj,jk) * tmask(ji,jj,jk)
489         !                                               ! lower diagonal
490         zd_lw(ji,jj,jk) = zcof * ( p_avm(ji,jj,jk  ) + p_avm(ji,jj,jk-1) ) / ( e3t_n(ji,jj,jk-1) * e3w_n(ji,jj,jk) )
491         !                                               ! upper diagonal
492         zd_up(ji,jj,jk) = zcof * ( p_avm(ji,jj,jk+1) + p_avm(ji,jj,jk  ) ) / ( e3t_n(ji,jj,jk  ) * e3w_n(ji,jj,jk) )
493         !                                               ! diagonal
494         zdiag(ji,jj,jk) = 1._wp - zd_lw(ji,jj,jk) - zd_up(ji,jj,jk) + rdt * zdiss * wmask(ji,jj,jk)
495         !                                               ! right hand side in psi
496         psi(ji,jj,jk) = psi(ji,jj,jk) + rdt * zesh2 * wmask(ji,jj,jk)
497      END_3D
498      !
499      zdiag(:,:,jpk) = 1._wp
500
501      ! Surface boundary condition on psi
502      ! ---------------------------------
503      !
504      SELECT CASE ( nn_bc_surf )
505      !
506      CASE ( 0 )             ! Dirichlet boundary conditions
507         !
508         ! Surface value
509         zdep    (:,:)   = zhsro(:,:) * rl_sf ! Cosmetic
510         psi     (:,:,1) = rc0**rpp * en(:,:,1)**rmm * zdep(:,:)**rnn * tmask(:,:,1)
511         zd_lw(:,:,1) = psi(:,:,1)
512         zd_up(:,:,1) = 0._wp
513         zdiag(:,:,1) = 1._wp
514         !
515         ! One level below
516         zkar    (:,:)   = (rl_sf + (vkarmn-rl_sf)*(1._wp-EXP(-rtrans*gdepw_n(:,:,2)/zhsro(:,:) )))
517         zdep    (:,:)   = (zhsro(:,:) + gdepw_n(:,:,2)) * zkar(:,:)
518         psi     (:,:,2) = rc0**rpp * en(:,:,2)**rmm * zdep(:,:)**rnn * tmask(:,:,1)
519         zd_lw(:,:,2) = 0._wp
520         zd_up(:,:,2) = 0._wp
521         zdiag(:,:,2) = 1._wp
522         !
523      CASE ( 1 )             ! Neumann boundary condition on d(psi)/dz
524         !
525         ! Surface value: Dirichlet
526         zdep    (:,:)   = zhsro(:,:) * rl_sf
527         psi     (:,:,1) = rc0**rpp * en(:,:,1)**rmm * zdep(:,:)**rnn * tmask(:,:,1)
528         zd_lw(:,:,1) = psi(:,:,1)
529         zd_up(:,:,1) = 0._wp
530         zdiag(:,:,1) = 1._wp
531         !
532         ! Neumann condition at k=2
533         zdiag(:,:,2) = zdiag(:,:,2) +  zd_lw(:,:,2) ! Remove zd_lw from zdiag
534         zd_lw(:,:,2) = 0._wp
535         !
536         ! Set psi vertical flux at the surface:
537         zkar (:,:)   = rl_sf + (vkarmn-rl_sf)*(1._wp-EXP(-rtrans*gdept_n(:,:,1)/zhsro(:,:) )) ! Lengh scale slope
538         zdep (:,:)   = ((zhsro(:,:) + gdept_n(:,:,1)) / zhsro(:,:))**(rmm*ra_sf)
539         zflxs(:,:)   = (rnn + (1._wp-zice_fra(:,:))*rsbc_tke1 * (rnn + rmm*ra_sf) * zdep(:,:)) &
540            &           *(1._wp + (1._wp-zice_fra(:,:))*rsbc_tke1*zdep(:,:))**(2._wp*rmm/3._wp-1_wp)
541         zdep (:,:)   = rsbc_psi1 * (zwall_psi(:,:,1)*p_avm(:,:,1)+zwall_psi(:,:,2)*p_avm(:,:,2)) * &
542            &           ustar2_surf(:,:)**rmm * zkar(:,:)**rnn * (zhsro(:,:) + gdept_n(:,:,1))**(rnn-1.)
543         zflxs(:,:)   = zdep(:,:) * zflxs(:,:)
544         psi  (:,:,2) = psi(:,:,2) + zflxs(:,:) / e3w_n(:,:,2)
545         !
546      END SELECT
547
548      ! Bottom boundary condition on psi
549      ! --------------------------------
550      !
551!!gm should be done for ISF (top boundary cond.)
552!!gm so, totally new staff needed      ===>>> think about that !
553!
554      SELECT CASE ( nn_bc_bot )     ! bottom boundary
555      !
556      CASE ( 0 )             ! Dirichlet
557         !                      ! en(ibot) = u*^2 / Co2 and hmxl_n(ibot) = vkarmn * r_z0_bot
558         !                      ! Balance between the production and the dissipation terms
559         DO_2D( 0, 0, 0, 0 )
560            ibot   = mbkt(ji,jj) + 1      ! k   bottom level of w-point
561            ibotm1 = mbkt(ji,jj)          ! k-1 bottom level of w-point but >=1
562            zdep(ji,jj) = vkarmn * r_z0_bot
563            psi (ji,jj,ibot) = rc0**rpp * en(ji,jj,ibot)**rmm * zdep(ji,jj)**rnn
564            zd_lw(ji,jj,ibot) = 0._wp
565            zd_up(ji,jj,ibot) = 0._wp
566            zdiag(ji,jj,ibot) = 1._wp
567            !
568            ! Just above last level, Dirichlet condition again (GOTM like)
569            zdep(ji,jj) = vkarmn * ( r_z0_bot + e3t_n(ji,jj,ibotm1) )
570            psi (ji,jj,ibotm1) = rc0**rpp * en(ji,jj,ibot  )**rmm * zdep(ji,jj)**rnn
571            zd_lw(ji,jj,ibotm1) = 0._wp
572            zd_up(ji,jj,ibotm1) = 0._wp
573            zdiag(ji,jj,ibotm1) = 1._wp
574         END_2D
575         !
576      CASE ( 1 )             ! Neumman boundary condition
577         !                     
578         DO_2D( 0, 0, 0, 0 )
579            ibot   = mbkt(ji,jj) + 1      ! k   bottom level of w-point
580            ibotm1 = mbkt(ji,jj)          ! k-1 bottom level of w-point but >=1
581            !
582            ! Bottom level Dirichlet condition:
583            zdep(ji,jj) = vkarmn * r_z0_bot
584            psi (ji,jj,ibot) = rc0**rpp * en(ji,jj,ibot)**rmm * zdep(ji,jj)**rnn
585            !
586            zd_lw(ji,jj,ibot) = 0._wp
587            zd_up(ji,jj,ibot) = 0._wp
588            zdiag(ji,jj,ibot) = 1._wp
589            !
590            ! Just above last level: Neumann condition with flux injection
591            zdiag(ji,jj,ibotm1) = zdiag(ji,jj,ibotm1) + zd_up(ji,jj,ibotm1) ! Remove zd_up from zdiag
592            zd_up(ji,jj,ibotm1) = 0.
593            !
594            ! Set psi vertical flux at the bottom:
595            zdep(ji,jj) = r_z0_bot + 0.5_wp*e3t_n(ji,jj,ibotm1)
596            zflxb = rsbc_psi2 * ( p_avm(ji,jj,ibot) + p_avm(ji,jj,ibotm1) )   &
597               &  * (0.5_wp*(en(ji,jj,ibot)+en(ji,jj,ibotm1)))**rmm * zdep(ji,jj)**(rnn-1._wp)
598            psi(ji,jj,ibotm1) = psi(ji,jj,ibotm1) + zflxb / e3w_n(ji,jj,ibotm1)
599         END_2D
600         !
601      END SELECT
602
603      ! Matrix inversion
604      ! ----------------
605      !
606      DO_3D( 0, 0, 0, 0, 2, jpkm1 )
607         zdiag(ji,jj,jk) = zdiag(ji,jj,jk) - zd_lw(ji,jj,jk) * zd_up(ji,jj,jk-1) / zdiag(ji,jj,jk-1)
608      END_3D
609      DO_3D( 0, 0, 0, 0, 2, jpk )
610         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)
611      END_3D
612      DO_3D( 0, 0, 0, 0, jpk-1, 2, -1 )
613         psi(ji,jj,jk) = ( zd_lw(ji,jj,jk) - zd_up(ji,jj,jk) * psi(ji,jj,jk+1) ) / zdiag(ji,jj,jk)
614      END_3D
615
616      ! Set dissipation
617      !----------------
618
619      SELECT CASE ( nn_clos )
620      !
621      CASE( 0 )               ! k-kl  (Mellor-Yamada)
622         DO_3D( 0, 0, 0, 0, 1, jpkm1 )
623            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)
624         END_3D
625         !
626      CASE( 1 )               ! k-eps
627         DO_3D( 0, 0, 0, 0, 1, jpkm1 )
628            eps(ji,jj,jk) = psi(ji,jj,jk)
629         END_3D
630         !
631      CASE( 2 )               ! k-w
632         DO_3D( 0, 0, 0, 0, 1, jpkm1 )
633            eps(ji,jj,jk) = rc04 * en(ji,jj,jk) * psi(ji,jj,jk) 
634         END_3D
635         !
636      CASE( 3 )               ! generic
637         zcoef = rc0**( 3._wp  + rpp/rnn )
638         zex1  =      ( 1.5_wp + rmm/rnn )
639         zex2  = -1._wp / rnn
640         DO_3D( 0, 0, 0, 0, 1, jpkm1 )
641            eps(ji,jj,jk) = zcoef * en(ji,jj,jk)**zex1 * psi(ji,jj,jk)**zex2
642         END_3D
643         !
644      END SELECT
645
646      ! Limit dissipation rate under stable stratification
647      ! --------------------------------------------------
648      DO_3D( 0, 0, 0, 0, 1, jpkm1 )
649         ! limitation
650         eps   (ji,jj,jk)  = MAX( eps(ji,jj,jk), rn_epsmin )
651         hmxl_n(ji,jj,jk)  = rc03 * en(ji,jj,jk) * SQRT( en(ji,jj,jk) ) / eps(ji,jj,jk)
652         ! Galperin criterium (NOTE : Not required if the proper value of C3 in stable cases is calculated)
653         zrn2 = MAX( rn2(ji,jj,jk), rsmall )
654         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) )
655      END_3D
656
657      !
658      ! Stability function and vertical viscosity and diffusivity
659      ! ---------------------------------------------------------
660      !
661      SELECT CASE ( nn_stab_func )
662      !
663      CASE ( 0 , 1 )             ! Galperin or Kantha-Clayson stability functions
664         DO_3D( 0, 0, 0, 0, 2, jpkm1 )
665            ! zcof =  l²/q²
666            zcof = hmxl_b(ji,jj,jk) * hmxl_b(ji,jj,jk) / ( 2._wp*eb(ji,jj,jk) )
667            ! Gh = -N²l²/q²
668            gh = - rn2(ji,jj,jk) * zcof
669            gh = MIN( gh, rgh0   )
670            gh = MAX( gh, rghmin )
671            ! Stability functions from Kantha and Clayson (if C2=C3=0 => Galperin)
672            sh = ra2*( 1._wp-6._wp*ra1/rb1 ) / ( 1.-3.*ra2*gh*(6.*ra1+rb2*( 1._wp-rc3 ) ) )
673            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)
674            !
675            ! Store stability function in zstt and zstm
676            zstt(ji,jj,jk) = rc_diff * sh * tmask(ji,jj,jk)
677            zstm(ji,jj,jk) = rc_diff * sm * tmask(ji,jj,jk)
678         END_3D
679         !
680      CASE ( 2, 3 )               ! Canuto stability functions
681         DO_3D( 0, 0, 0, 0, 2, jpkm1 )
682            ! zcof =  l²/q²
683            zcof = hmxl_b(ji,jj,jk)*hmxl_b(ji,jj,jk) / ( 2._wp * eb(ji,jj,jk) )
684            ! Gh = -N²l²/q²
685            gh = - rn2(ji,jj,jk) * zcof
686            gh = MIN( gh, rgh0   )
687            gh = MAX( gh, rghmin )
688            gh = gh * rf6
689            ! Gm =  M²l²/q² Shear number
690            shr = p_sh2(ji,jj,jk) / MAX( p_avm(ji,jj,jk), rsmall )
691            gm = MAX( shr * zcof , 1.e-10 )
692            gm = gm * rf6
693            gm = MIN ( (rd0 - rd1*gh + rd3*gh*gh) / (rd2-rd4*gh) , gm )
694            ! Stability functions from Canuto
695            rcff = rd0 - rd1*gh +rd2*gm + rd3*gh*gh - rd4*gh*gm + rd5*gm*gm
696            sm = (rs0 - rs1*gh + rs2*gm) / rcff
697            sh = (rs4 - rs5*gh + rs6*gm) / rcff
698            !
699            ! Store stability function in zstt and zstm
700            zstt(ji,jj,jk) = rc_diff * sh * tmask(ji,jj,jk)
701            zstm(ji,jj,jk) = rc_diff * sm * tmask(ji,jj,jk)
702         END_3D
703         !
704      END SELECT
705
706      ! Boundary conditions on stability functions for momentum (Neumann):
707      ! Lines below are useless if GOTM style Dirichlet conditions are used
708
709      zstm(:,:,1) = zstm(:,:,2)
710
711      ! default value, in case jpk > mbkt(ji,jj)+1. Not needed but avoid a bug when looking for undefined values (-fpe0)
712      zstm(:,:,jpk) = 0. 
713      DO_2D( 0, 0, 0, 0 )
714         zstm(ji,jj,mbkt(ji,jj)+1) = zstm(ji,jj,mbkt(ji,jj))
715      END_2D
716
717      zstt(:,:,  1) = wmask(:,:,  1)  ! default value not needed but avoid a bug when looking for undefined values (-fpe0)
718      zstt(:,:,jpk) = wmask(:,:,jpk)  ! default value not needed but avoid a bug when looking for undefined values (-fpe0)
719
720!!gm should be done for ISF (top boundary cond.)
721!!gm so, totally new staff needed!!gm
722
723      ! Compute diffusivities/viscosities
724      ! The computation below could be restrained to jk=2 to jpkm1 if GOTM style Dirichlet conditions are used
725      !  -> yes BUT p_avm(:,:1) and p_avm(:,:jpk) are used when we compute zd_lw(:,:2) and zd_up(:,:jpkm1). These values are
726      !     later overwritten by surface/bottom boundaries conditions, so we don't really care of p_avm(:,:1) and p_avm(:,:jpk)
727      !     for zd_lw and zd_up but they have to be defined to avoid a bug when looking for undefined values (-fpe0)
728      DO_3D( 0, 0, 0, 0, 1, jpk )
729         zsqen = SQRT( 2._wp * en(ji,jj,jk) ) * hmxl_n(ji,jj,jk)
730         zavt  = zsqen * zstt(ji,jj,jk)
731         zavm  = zsqen * zstm(ji,jj,jk)
732         p_avt(ji,jj,jk) = MAX( zavt, avtb(jk) ) * wmask(ji,jj,jk) ! apply mask for zdfmxl routine
733         p_avm(ji,jj,jk) = MAX( zavm, avmb(jk) )                   ! Note that avm is not masked at the surface and the bottom
734      END_3D
735      p_avt(:,:,1) = 0._wp
736      !
737      IF(ln_ctl) THEN
738         CALL prt_ctl( tab3d_1=en   , clinfo1=' gls  - e: ', tab3d_2=p_avt, clinfo2=' t: ', kdim=jpk)
739         CALL prt_ctl( tab3d_1=p_avm, clinfo1=' gls  - m: ', kdim=jpk )
740      ENDIF
741      !
742   END SUBROUTINE zdf_gls
743
744
745   SUBROUTINE zdf_gls_init
746      !!----------------------------------------------------------------------
747      !!                  ***  ROUTINE zdf_gls_init  ***
748      !!                     
749      !! ** Purpose :   Initialization of the vertical eddy diffivity and
750      !!              viscosity computed using a GLS turbulent closure scheme
751      !!
752      !! ** Method  :   Read the namzdf_gls namelist and check the parameters
753      !!
754      !! ** input   :   Namlist namzdf_gls
755      !!
756      !! ** Action  :   Increase by 1 the nstop flag is setting problem encounter
757      !!
758      !!----------------------------------------------------------------------
759      INTEGER ::   jk    ! dummy loop indices
760      INTEGER ::   ios   ! Local integer output status for namelist read
761      REAL(wp)::   zcr   ! local scalar
762      !!
763      NAMELIST/namzdf_gls/rn_emin, rn_epsmin, ln_length_lim,       &
764         &            rn_clim_galp, ln_sigpsi, rn_hsro, rn_hsri,   &
765         &            rn_crban, rn_charn, rn_frac_hs,              &
766         &            nn_bc_surf, nn_bc_bot, nn_z0_met, nn_z0_ice, &
767         &            nn_stab_func, nn_clos
768      !!----------------------------------------------------------
769      !
770      REWIND( numnam_ref )              ! Namelist namzdf_gls in reference namelist : Vertical eddy diffivity and viscosity using gls turbulent closure scheme
771      READ  ( numnam_ref, namzdf_gls, IOSTAT = ios, ERR = 901)
772901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namzdf_gls in reference namelist' )
773
774      REWIND( numnam_cfg )              ! Namelist namzdf_gls in configuration namelist : Vertical eddy diffivity and viscosity using gls turbulent closure scheme
775      READ  ( numnam_cfg, namzdf_gls, IOSTAT = ios, ERR = 902 )
776902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namzdf_gls in configuration namelist' )
777      IF(lwm) WRITE ( numond, namzdf_gls )
778
779      IF(lwp) THEN                     !* Control print
780         WRITE(numout,*)
781         WRITE(numout,*) 'zdf_gls_init : GLS turbulent closure scheme'
782         WRITE(numout,*) '~~~~~~~~~~~~'
783         WRITE(numout,*) '   Namelist namzdf_gls : set gls mixing parameters'
784         WRITE(numout,*) '      minimum value of en                           rn_emin        = ', rn_emin
785         WRITE(numout,*) '      minimum value of eps                          rn_epsmin      = ', rn_epsmin
786         WRITE(numout,*) '      Limit dissipation rate under stable stratif.  ln_length_lim  = ', ln_length_lim
787         WRITE(numout,*) '      Galperin limit (Standard: 0.53, Holt: 0.26)   rn_clim_galp   = ', rn_clim_galp
788         WRITE(numout,*) '      TKE Surface boundary condition                nn_bc_surf     = ', nn_bc_surf
789         WRITE(numout,*) '      TKE Bottom boundary condition                 nn_bc_bot      = ', nn_bc_bot
790         WRITE(numout,*) '      Modify psi Schmidt number (wb case)           ln_sigpsi      = ', ln_sigpsi
791         WRITE(numout,*) '      Craig and Banner coefficient                  rn_crban       = ', rn_crban
792         WRITE(numout,*) '      Charnock coefficient                          rn_charn       = ', rn_charn
793         WRITE(numout,*) '      Surface roughness formula                     nn_z0_met      = ', nn_z0_met
794         WRITE(numout,*) '      surface wave breaking under ice               nn_z0_ice      = ', nn_z0_ice
795         SELECT CASE( nn_z0_ice )
796         CASE( 0 )   ;   WRITE(numout,*) '   ==>>>   no impact of ice cover on surface wave breaking'
797         CASE( 1 )   ;   WRITE(numout,*) '   ==>>>   roughness uses rn_hsri and is weigthed by 1-TANH( fr_i(:,:) * 10 )'
798         CASE( 2 )   ;   WRITE(numout,*) '   ==>>>   roughness uses rn_hsri and is weighted by 1-fr_i(:,:)'
799         CASE( 3 )   ;   WRITE(numout,*) '   ==>>>   roughness uses rn_hsri and is weighted by 1-MIN( 1, 4 * fr_i(:,:) )'
800         CASE DEFAULT
801            CALL ctl_stop( 'zdf_gls_init: wrong value for nn_z0_ice, should be 0,1,2, or 3')
802         END SELECT
803         WRITE(numout,*) '      Wave height frac. (used if nn_z0_met=2)       rn_frac_hs     = ', rn_frac_hs
804         WRITE(numout,*) '      Stability functions                           nn_stab_func   = ', nn_stab_func
805         WRITE(numout,*) '      Type of closure                               nn_clos        = ', nn_clos
806         WRITE(numout,*) '      Surface roughness (m)                         rn_hsro        = ', rn_hsro
807         WRITE(numout,*) '      Ice-ocean roughness (used if nn_z0_ice/=0)    rn_hsri        = ', rn_hsri
808         WRITE(numout,*)
809         WRITE(numout,*) '   Namelist namdrg_top/_bot:   used values:'
810         WRITE(numout,*) '      top    ocean cavity roughness (m)             rn_z0(_top)   = ', r_z0_top
811         WRITE(numout,*) '      Bottom seafloor     roughness (m)             rn_z0(_bot)   = ', r_z0_bot
812         WRITE(numout,*)
813      ENDIF
814
815      !                                !* allocate GLS arrays
816      IF( zdf_gls_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'zdf_gls_init : unable to allocate arrays' )
817
818      !                                !* Check of some namelist values
819      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' )
820      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' )
821      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' )
822      IF( nn_z0_met == 3  .AND. .NOT. (ln_wave .AND. ln_sdw ) ) CALL ctl_stop( 'zdf_gls_init: nn_z0_met=3 requires ln_wave=T and ln_sdw=T' )
823      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' )
824      IF( nn_clos      < 0 .OR. nn_clos      > 3 )              CALL ctl_stop( 'zdf_gls_init: bad flag: nn_clos is 0, 1, 2 or 3' )
825
826      SELECT CASE ( nn_clos )          !* set the parameters for the chosen closure
827      !
828      CASE( 0 )                              ! k-kl  (Mellor-Yamada)
829         !
830         IF(lwp) WRITE(numout,*) '   ==>>   k-kl closure chosen (i.e. closed to the classical Mellor-Yamada)'
831         IF(lwp) WRITE(numout,*)
832         rpp     = 0._wp
833         rmm     = 1._wp
834         rnn     = 1._wp
835         rsc_tke = 1.96_wp
836         rsc_psi = 1.96_wp
837         rpsi1   = 0.9_wp
838         rpsi3p  = 1._wp
839         rpsi2   = 0.5_wp
840         !
841         SELECT CASE ( nn_stab_func )
842         CASE( 0, 1 )   ;   rpsi3m = 2.53_wp       ! G88 or KC stability functions
843         CASE( 2 )      ;   rpsi3m = 2.62_wp       ! Canuto A stability functions
844         CASE( 3 )      ;   rpsi3m = 2.38          ! Canuto B stability functions (caution : constant not identified)
845         END SELECT
846         !
847      CASE( 1 )                              ! k-eps
848         !
849         IF(lwp) WRITE(numout,*) '   ==>>   k-eps closure chosen'
850         IF(lwp) WRITE(numout,*)
851         rpp     =  3._wp
852         rmm     =  1.5_wp
853         rnn     = -1._wp
854         rsc_tke =  1._wp
855         rsc_psi =  1.2_wp  ! Schmidt number for psi
856         rpsi1   =  1.44_wp
857         rpsi3p  =  1._wp
858         rpsi2   =  1.92_wp
859         !
860         SELECT CASE ( nn_stab_func )
861         CASE( 0, 1 )   ;   rpsi3m = -0.52_wp      ! G88 or KC stability functions
862         CASE( 2 )      ;   rpsi3m = -0.629_wp     ! Canuto A stability functions
863         CASE( 3 )      ;   rpsi3m = -0.566        ! Canuto B stability functions
864         END SELECT
865         !
866      CASE( 2 )                              ! k-omega
867         !
868         IF(lwp) WRITE(numout,*) '   ==>>   k-omega closure chosen'
869         IF(lwp) WRITE(numout,*)
870         rpp     = -1._wp
871         rmm     =  0.5_wp
872         rnn     = -1._wp
873         rsc_tke =  2._wp
874         rsc_psi =  2._wp
875         rpsi1   =  0.555_wp
876         rpsi3p  =  1._wp
877         rpsi2   =  0.833_wp
878         !
879         SELECT CASE ( nn_stab_func )
880         CASE( 0, 1 )   ;   rpsi3m = -0.58_wp       ! G88 or KC stability functions
881         CASE( 2 )      ;   rpsi3m = -0.64_wp       ! Canuto A stability functions
882         CASE( 3 )      ;   rpsi3m = -0.64_wp       ! Canuto B stability functions caution : constant not identified)
883         END SELECT
884         !
885      CASE( 3 )                              ! generic
886         !
887         IF(lwp) WRITE(numout,*) '   ==>>   generic closure chosen'
888         IF(lwp) WRITE(numout,*)
889         rpp     = 2._wp
890         rmm     = 1._wp
891         rnn     = -0.67_wp
892         rsc_tke = 0.8_wp
893         rsc_psi = 1.07_wp
894         rpsi1   = 1._wp
895         rpsi3p  = 1._wp
896         rpsi2   = 1.22_wp
897         !
898         SELECT CASE ( nn_stab_func )
899         CASE( 0, 1 )   ;   rpsi3m = 0.1_wp         ! G88 or KC stability functions
900         CASE( 2 )      ;   rpsi3m = 0.05_wp        ! Canuto A stability functions
901         CASE( 3 )      ;   rpsi3m = 0.05_wp        ! Canuto B stability functions caution : constant not identified)
902         END SELECT
903         !
904      END SELECT
905
906      !
907      SELECT CASE ( nn_stab_func )     !* set the parameters of the stability functions
908      !
909      CASE ( 0 )                             ! Galperin stability functions
910         !
911         IF(lwp) WRITE(numout,*) '   ==>>   Stability functions from Galperin'
912         rc2     =  0._wp
913         rc3     =  0._wp
914         rc_diff =  1._wp
915         rc0     =  0.5544_wp
916         rcm_sf  =  0.9884_wp
917         rghmin  = -0.28_wp
918         rgh0    =  0.0233_wp
919         rghcri  =  0.02_wp
920         !
921      CASE ( 1 )                             ! Kantha-Clayson stability functions
922         !
923         IF(lwp) WRITE(numout,*) '   ==>>   Stability functions from Kantha-Clayson'
924         rc2     =  0.7_wp
925         rc3     =  0.2_wp
926         rc_diff =  1._wp
927         rc0     =  0.5544_wp
928         rcm_sf  =  0.9884_wp
929         rghmin  = -0.28_wp
930         rgh0    =  0.0233_wp
931         rghcri  =  0.02_wp
932         !
933      CASE ( 2 )                             ! Canuto A stability functions
934         !
935         IF(lwp) WRITE(numout,*) '   ==>>   Stability functions from Canuto A'
936         rs0 = 1.5_wp * rl1 * rl5*rl5
937         rs1 = -rl4*(rl6+rl7) + 2._wp*rl4*rl5*(rl1-(1._wp/3._wp)*rl2-rl3) + 1.5_wp*rl1*rl5*rl8
938         rs2 = -(3._wp/8._wp) * rl1*(rl6*rl6-rl7*rl7)
939         rs4 = 2._wp * rl5
940         rs5 = 2._wp * rl4
941         rs6 = (2._wp/3._wp) * rl5 * ( 3._wp*rl3*rl3 - rl2*rl2 ) - 0.5_wp * rl5*rl1 * (3._wp*rl3-rl2)   &
942            &                                                    + 0.75_wp * rl1 * ( rl6 - rl7 )
943         rd0 = 3._wp * rl5*rl5
944         rd1 = rl5 * ( 7._wp*rl4 + 3._wp*rl8 )
945         rd2 = rl5*rl5 * ( 3._wp*rl3*rl3 - rl2*rl2 ) - 0.75_wp*(rl6*rl6 - rl7*rl7 )
946         rd3 = rl4 * ( 4._wp*rl4 + 3._wp*rl8)
947         rd4 = rl4 * ( rl2 * rl6 - 3._wp*rl3*rl7 - rl5*(rl2*rl2 - rl3*rl3 ) ) + rl5*rl8 * ( 3._wp*rl3*rl3 - rl2*rl2 )
948         rd5 = 0.25_wp * ( rl2*rl2 - 3._wp *rl3*rl3 ) * ( rl6*rl6 - rl7*rl7 )
949         rc0 = 0.5268_wp
950         rf6 = 8._wp / (rc0**6._wp)
951         rc_diff = SQRT(2._wp) / (rc0**3._wp)
952         rcm_sf  =  0.7310_wp
953         rghmin  = -0.28_wp
954         rgh0    =  0.0329_wp
955         rghcri  =  0.03_wp
956         !
957      CASE ( 3 )                             ! Canuto B stability functions
958         !
959         IF(lwp) WRITE(numout,*) '   ==>>   Stability functions from Canuto B'
960         rs0 = 1.5_wp * rm1 * rm5*rm5
961         rs1 = -rm4 * (rm6+rm7) + 2._wp * rm4*rm5*(rm1-(1._wp/3._wp)*rm2-rm3) + 1.5_wp * rm1*rm5*rm8
962         rs2 = -(3._wp/8._wp) * rm1 * (rm6*rm6-rm7*rm7 )
963         rs4 = 2._wp * rm5
964         rs5 = 2._wp * rm4
965         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)
966         rd0 = 3._wp * rm5*rm5
967         rd1 = rm5 * (7._wp*rm4 + 3._wp*rm8)
968         rd2 = rm5*rm5 * (3._wp*rm3*rm3 - rm2*rm2) - 0.75_wp * (rm6*rm6 - rm7*rm7)
969         rd3 = rm4 * ( 4._wp*rm4 + 3._wp*rm8 )
970         rd4 = rm4 * ( rm2*rm6 -3._wp*rm3*rm7 - rm5*(rm2*rm2 - rm3*rm3) ) + rm5 * rm8 * ( 3._wp*rm3*rm3 - rm2*rm2 )
971         rd5 = 0.25_wp * ( rm2*rm2 - 3._wp*rm3*rm3 ) * ( rm6*rm6 - rm7*rm7 )
972         rc0 = 0.5268_wp            !!       rc0 = 0.5540_wp (Warner ...) to verify !
973         rf6 = 8._wp / ( rc0**6._wp )
974         rc_diff = SQRT(2._wp)/(rc0**3.)
975         rcm_sf  =  0.7470_wp
976         rghmin  = -0.28_wp
977         rgh0    =  0.0444_wp
978         rghcri  =  0.0414_wp
979         !
980      END SELECT
981   
982      !                                !* Set Schmidt number for psi diffusion in the wave breaking case
983      !                                     ! See Eq. (13) of Carniel et al, OM, 30, 225-239, 2009
984      !                                     !  or Eq. (17) of Burchard, JPO, 31, 3133-3145, 2001
985      IF( ln_sigpsi ) THEN
986         ra_sf = -1.5 ! Set kinetic energy slope, then deduce rsc_psi and rl_sf
987         ! Verification: retrieve Burchard (2001) results by uncomenting the line below:
988         ! Note that the results depend on the value of rn_cm_sf which is constant (=rc0) in his work
989         ! ra_sf = -SQRT(2./3.*rc0**3./rn_cm_sf*rn_sc_tke)/vkarmn
990         rsc_psi0 = rsc_tke/(24.*rpsi2)*(-1.+(4.*rnn + ra_sf*(1.+4.*rmm))**2./(ra_sf**2.))
991      ELSE
992         rsc_psi0 = rsc_psi
993      ENDIF
994 
995      !                                !* Shear free turbulence parameters
996      !
997      ra_sf  = -4._wp*rnn*SQRT(rsc_tke) / ( (1._wp+4._wp*rmm)*SQRT(rsc_tke) &
998               &                              - SQRT(rsc_tke + 24._wp*rsc_psi0*rpsi2 ) )
999
1000      IF ( rn_crban==0._wp ) THEN
1001         rl_sf = vkarmn
1002      ELSE
1003         rl_sf = rc0 * SQRT(rc0/rcm_sf) * SQRT( ( (1._wp + 4._wp*rmm + 8._wp*rmm**2_wp) * rsc_tke        &
1004            &                                            + 12._wp*rsc_psi0*rpsi2 - (1._wp + 4._wp*rmm)   &
1005            &                                                     *SQRT(rsc_tke*(rsc_tke                 &
1006            &                                                        + 24._wp*rsc_psi0*rpsi2)) )         &
1007            &                                              /(12._wp*rnn**2.)                             )
1008      ENDIF
1009
1010      !
1011      IF(lwp) THEN                     !* Control print
1012         WRITE(numout,*)
1013         WRITE(numout,*) '   Limit values :'
1014         WRITE(numout,*) '      Parameter  m = ', rmm
1015         WRITE(numout,*) '      Parameter  n = ', rnn
1016         WRITE(numout,*) '      Parameter  p = ', rpp
1017         WRITE(numout,*) '      rpsi1    = ', rpsi1
1018         WRITE(numout,*) '      rpsi2    = ', rpsi2
1019         WRITE(numout,*) '      rpsi3m   = ', rpsi3m
1020         WRITE(numout,*) '      rpsi3p   = ', rpsi3p
1021         WRITE(numout,*) '      rsc_tke  = ', rsc_tke
1022         WRITE(numout,*) '      rsc_psi  = ', rsc_psi
1023         WRITE(numout,*) '      rsc_psi0 = ', rsc_psi0
1024         WRITE(numout,*) '      rc0      = ', rc0
1025         WRITE(numout,*)
1026         WRITE(numout,*) '   Shear free turbulence parameters:'
1027         WRITE(numout,*) '      rcm_sf   = ', rcm_sf
1028         WRITE(numout,*) '      ra_sf    = ', ra_sf
1029         WRITE(numout,*) '      rl_sf    = ', rl_sf
1030      ENDIF
1031
1032      !                                !* Constants initialization
1033      rc02  = rc0  * rc0   ;   rc02r = 1. / rc02
1034      rc03  = rc02 * rc0
1035      rc04  = rc03 * rc0
1036      rsbc_tke1 = -3._wp/2._wp*rn_crban*ra_sf*rl_sf                      ! Dirichlet + Wave breaking
1037      rsbc_tke2 = rdt * rn_crban / rl_sf                                 ! Neumann + Wave breaking
1038      zcr = MAX(rsmall, rsbc_tke1**(1./(-ra_sf*3._wp/2._wp))-1._wp )
1039      rtrans = 0.2_wp / zcr                                              ! Ad. inverse transition length between log and wave layer
1040      rsbc_zs1  = rn_charn/grav                                          ! Charnock formula for surface roughness
1041      rsbc_zs2  = rn_frac_hs / 0.85_wp / grav * 665._wp                  ! Rascle formula for surface roughness
1042      rsbc_psi1 = -0.5_wp * rdt * rc0**(rpp-2._wp*rmm) / rsc_psi
1043      rsbc_psi2 = -0.5_wp * rdt * rc0**rpp * rnn * vkarmn**rnn / rsc_psi ! Neumann + NO Wave breaking
1044      !
1045      rfact_tke = -0.5_wp / rsc_tke * rdt                                ! Cst used for the Diffusion term of tke
1046      rfact_psi = -0.5_wp / rsc_psi * rdt                                ! Cst used for the Diffusion term of tke
1047      !
1048      !                                !* Wall proximity function
1049!!gm tmask or wmask ????
1050      zwall(:,:,:) = 1._wp * tmask(:,:,:)
1051
1052      !                                !* read or initialize all required files 
1053      CALL gls_rst( nit000, 'READ' )      ! (en, avt_k, avm_k, hmxl_n)
1054      !
1055      IF( lwxios ) THEN
1056         CALL iom_set_rstw_var_active('en')
1057         CALL iom_set_rstw_var_active('avt_k')
1058         CALL iom_set_rstw_var_active('avm_k')
1059         CALL iom_set_rstw_var_active('hmxl_n')
1060      ENDIF
1061      !
1062   END SUBROUTINE zdf_gls_init
1063
1064
1065   SUBROUTINE gls_rst( kt, cdrw )
1066      !!---------------------------------------------------------------------
1067      !!                   ***  ROUTINE gls_rst  ***
1068      !!                     
1069      !! ** Purpose :   Read or write TKE file (en) in restart file
1070      !!
1071      !! ** Method  :   use of IOM library
1072      !!                if the restart does not contain TKE, en is either
1073      !!                set to rn_emin or recomputed (nn_igls/=0)
1074      !!----------------------------------------------------------------------
1075      USE zdf_oce , ONLY : en, avt_k, avm_k   ! ocean vertical physics
1076      !!
1077      INTEGER         , INTENT(in) ::   kt     ! ocean time-step
1078      CHARACTER(len=*), INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
1079      !
1080      INTEGER ::   jit, jk   ! dummy loop indices
1081      INTEGER ::   id1, id2, id3, id4
1082      INTEGER ::   ji, jj, ikbu, ikbv
1083      REAL(wp)::   cbx, cby
1084      !!----------------------------------------------------------------------
1085      !
1086      IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise
1087         !                                   ! ---------------
1088         IF( ln_rstart ) THEN                   !* Read the restart file
1089            id1 = iom_varid( numror, 'en'    , ldstop = .FALSE. )
1090            id2 = iom_varid( numror, 'avt_k' , ldstop = .FALSE. )
1091            id3 = iom_varid( numror, 'avm_k' , ldstop = .FALSE. )
1092            id4 = iom_varid( numror, 'hmxl_n', ldstop = .FALSE. )
1093            !
1094            IF( MIN( id1, id2, id3, id4 ) > 0 ) THEN        ! all required arrays exist
1095               CALL iom_get( numror, jpdom_autoglo, 'en'    , en    , ldxios = lrxios )
1096               CALL iom_get( numror, jpdom_autoglo, 'avt_k' , avt_k , ldxios = lrxios )
1097               CALL iom_get( numror, jpdom_autoglo, 'avm_k' , avm_k , ldxios = lrxios )
1098               CALL iom_get( numror, jpdom_autoglo, 'hmxl_n', hmxl_n, ldxios = lrxios )
1099            ELSE                       
1100               IF(lwp) WRITE(numout,*)
1101               IF(lwp) WRITE(numout,*) '   ==>>   previous run without GLS scheme, set en and hmxl_n to background values'
1102               en    (:,:,:) = rn_emin
1103               hmxl_n(:,:,:) = 0.05_wp
1104               ! avt_k, avm_k already set to the background value in zdf_phy_init
1105            ENDIF
1106         ELSE                                   !* Start from rest
1107            IF(lwp) WRITE(numout,*)
1108            IF(lwp) WRITE(numout,*) '   ==>>   start from rest, set en and hmxl_n by background values'
1109            en    (:,:,:) = rn_emin
1110            hmxl_n(:,:,:) = 0.05_wp
1111            ! avt_k, avm_k already set to the background value in zdf_phy_init
1112         ENDIF
1113         !
1114      ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
1115         !                                   ! -------------------
1116         IF(lwp) WRITE(numout,*) '---- gls-rst ----'
1117         IF( lwxios ) CALL iom_swap(      cwxios_context         )
1118         CALL iom_rstput( kt, nitrst, numrow, 'en'    , en    , ldxios = lwxios )
1119         CALL iom_rstput( kt, nitrst, numrow, 'avt_k' , avt_k , ldxios = lwxios )
1120         CALL iom_rstput( kt, nitrst, numrow, 'avm_k' , avm_k , ldxios = lwxios )
1121         CALL iom_rstput( kt, nitrst, numrow, 'hmxl_n', hmxl_n, ldxios = lwxios )
1122         IF( lwxios ) CALL iom_swap(      cxios_context          )
1123         !
1124      ENDIF
1125      !
1126   END SUBROUTINE gls_rst
1127
1128   !!======================================================================
1129END MODULE zdfgls
1130
Note: See TracBrowser for help on using the repository browser.