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.
zdftke.F90 in branches/UKMO/test_moci_test_suite_namelist_read/NEMOGCM/NEMO/OPA_SRC/ZDF – NEMO

source: branches/UKMO/test_moci_test_suite_namelist_read/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftke.F90 @ 9366

Last change on this file since 9366 was 9366, checked in by andmirek, 6 years ago

#2050 first version. Compiled OK in moci test suite

File size: 52.7 KB
RevLine 
[1531]1MODULE zdftke
[1239]2   !!======================================================================
[1531]3   !!                       ***  MODULE  zdftke  ***
[1239]4   !! Ocean physics:  vertical mixing coefficient computed from the tke
5   !!                 turbulent closure parameterization
6   !!=====================================================================
[1492]7   !! History :  OPA  !  1991-03  (b. blanke)  Original code
8   !!            7.0  !  1991-11  (G. Madec)   bug fix
9   !!            7.1  !  1992-10  (G. Madec)   new mixing length and eav
10   !!            7.2  !  1993-03  (M. Guyon)   symetrical conditions
11   !!            7.3  !  1994-08  (G. Madec, M. Imbard)  nn_pdl flag
12   !!            7.5  !  1996-01  (G. Madec)   s-coordinates
13   !!            8.0  !  1997-07  (G. Madec)   lbc
14   !!            8.1  !  1999-01  (E. Stretta) new option for the mixing length
15   !!  NEMO      1.0  !  2002-06  (G. Madec) add tke_init routine
16   !!             -   !  2004-10  (C. Ethe )  1D configuration
17   !!            2.0  !  2006-07  (S. Masson)  distributed restart using iom
18   !!            3.0  !  2008-05  (C. Ethe,  G.Madec) : update TKE physics:
19   !!                 !           - tke penetration (wind steering)
20   !!                 !           - suface condition for tke & mixing length
21   !!                 !           - Langmuir cells
22   !!             -   !  2008-05  (J.-M. Molines, G. Madec)  2D form of avtb
23   !!             -   !  2008-06  (G. Madec)  style + DOCTOR name for namelist parameters
24   !!             -   !  2008-12  (G. Reffray) stable discretization of the production term
25   !!            3.2  !  2009-06  (G. Madec, S. Masson) TKE restart compatible with key_cpl
26   !!                 !                                + cleaning of the parameters + bugs correction
[2528]27   !!            3.3  !  2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
[5120]28   !!            3.6  !  2014-11  (P. Mathiot) add ice shelf capability
[1239]29   !!----------------------------------------------------------------------
[1531]30#if defined key_zdftke   ||   defined key_esopa
[1239]31   !!----------------------------------------------------------------------
[1531]32   !!   'key_zdftke'                                   TKE vertical physics
[1239]33   !!----------------------------------------------------------------------
[3625]34   !!   zdf_tke       : update momentum and tracer Kz from a tke scheme
35   !!   tke_tke       : tke time stepping: update tke at now time step (en)
36   !!   tke_avn       : compute mixing length scale and deduce avm and avt
37   !!   zdf_tke_init  : initialization, namelist read, and parameters control
38   !!   tke_rst       : read/write tke restart in ocean restart file
[1239]39   !!----------------------------------------------------------------------
[2528]40   USE oce            ! ocean: dynamics and active tracers variables
41   USE phycst         ! physical constants
42   USE dom_oce        ! domain: ocean
43   USE domvvl         ! domain: variable volume layer
[1492]44   USE sbc_oce        ! surface boundary condition: ocean
[2528]45   USE zdf_oce        ! vertical physics: ocean variables
46   USE zdfmxl         ! vertical physics: mixed layer
[1492]47   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
48   USE prtctl         ! Print control
49   USE in_out_manager ! I/O manager
50   USE iom            ! I/O manager library
[2715]51   USE lib_mpp        ! MPP library
[3294]52   USE wrk_nemo       ! work arrays
53   USE timing         ! Timing
[3625]54   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined) 
[8243]55   USE iom_def, ONLY : lwxios
[6487]56#if defined key_agrif
57   USE agrif_opa_interp
58   USE agrif_opa_update
59#endif
[7924]60   USE iom_def, ONLY : lxios_read
[1239]61
[6487]62
63
[1239]64   IMPLICIT NONE
65   PRIVATE
66
[2528]67   PUBLIC   zdf_tke        ! routine called in step module
68   PUBLIC   zdf_tke_init   ! routine called in opa module
69   PUBLIC   tke_rst        ! routine called in step module
[9366]70   PRIVATE  tke_namelist
[1239]71
[2715]72   LOGICAL , PUBLIC, PARAMETER ::   lk_zdftke = .TRUE.  !: TKE vertical mixing flag
[1239]73
[4147]74   !                      !!** Namelist  namzdf_tke  **
75   LOGICAL  ::   ln_mxl0   ! mixing length scale surface value as function of wind stress or not
76   INTEGER  ::   nn_mxl    ! type of mixing length (=0/1/2/3)
77   REAL(wp) ::   rn_mxl0   ! surface  min value of mixing length (kappa*z_o=0.4*0.1 m)  [m]
78   INTEGER  ::   nn_pdl    ! Prandtl number or not (ratio avt/avm) (=0/1)
79   REAL(wp) ::   rn_ediff  ! coefficient for avt: avt=rn_ediff*mxl*sqrt(e)
80   REAL(wp) ::   rn_ediss  ! coefficient of the Kolmogoroff dissipation
81   REAL(wp) ::   rn_ebb    ! coefficient of the surface input of tke
82   REAL(wp) ::   rn_emin   ! minimum value of tke           [m2/s2]
83   REAL(wp) ::   rn_emin0  ! surface minimum value of tke   [m2/s2]
84   REAL(wp) ::   rn_bshear ! background shear (>0) currently a numerical threshold (do not change it)
85   INTEGER  ::   nn_etau   ! type of depth penetration of surface tke (=0/1/2/3)
86   INTEGER  ::   nn_htau   ! type of tke profile of penetration (=0/1)
87   REAL(wp) ::   rn_efr    ! fraction of TKE surface value which penetrates in the ocean
[6491]88   REAL(wp) ::   rn_c      ! fraction of TKE added within the mixed layer by nn_etau
[4147]89   LOGICAL  ::   ln_lc     ! Langmuir cells (LC) as a source term of TKE or not
90   REAL(wp) ::   rn_lc     ! coef to compute vertical velocity of Langmuir cells
[1239]91
[4147]92   REAL(wp) ::   ri_cri    ! critic Richardson number (deduced from rn_ediff and rn_ediss values)
93   REAL(wp) ::   rmxl_min  ! minimum mixing length value (deduced from rn_ediff and rn_emin values)  [m]
[6491]94   REAL(wp) ::   rhtau                     ! coefficient to relate MLD to htau when nn_htau == 2
[2528]95   REAL(wp) ::   rhftau_add = 1.e-3_wp     ! add offset   applied to HF part of taum  (nn_etau=3)
96   REAL(wp) ::   rhftau_scl = 1.0_wp       ! scale factor applied to HF part of taum  (nn_etau=3)
[1239]97
[2715]98   REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   htau           ! depth of tke penetration (nn_htau)
[6491]99   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e_niw          !: TKE budget- near-inertial waves term
100   REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   efr            ! surface boundary condition for nn_etau = 4
[2715]101   REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   dissl          ! now mixing lenght of dissipation
102#if defined key_c1d
103   !                                                                        !!** 1D cfg only  **   ('key_c1d')
104   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e_dis, e_mix   !: dissipation and mixing turbulent lengh scales
105   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e_pdl, e_ric   !: prandl and local Richardson numbers
106#endif
[1492]107
[1239]108   !! * Substitutions
109#  include "domzgr_substitute.h90"
110#  include "vectopt_loop_substitute.h90"
111   !!----------------------------------------------------------------------
[2715]112   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
[2528]113   !! $Id$
114   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
[1239]115   !!----------------------------------------------------------------------
116CONTAINS
117
[2715]118   INTEGER FUNCTION zdf_tke_alloc()
119      !!----------------------------------------------------------------------
120      !!                ***  FUNCTION zdf_tke_alloc  ***
121      !!----------------------------------------------------------------------
122      ALLOCATE(                                                                    &
[6491]123         &      efr  (jpi,jpj)     , e_niw(jpi,jpj,jpk) ,                         &     
[2715]124#if defined key_c1d
125         &      e_dis(jpi,jpj,jpk) , e_mix(jpi,jpj,jpk) ,                          &
126         &      e_pdl(jpi,jpj,jpk) , e_ric(jpi,jpj,jpk) ,                          &
127#endif
[6487]128         &      htau  (jpi,jpj)    , dissl(jpi,jpj,jpk) , STAT= zdf_tke_alloc      )
[2715]129         !
130      IF( lk_mpp             )   CALL mpp_sum ( zdf_tke_alloc )
131      IF( zdf_tke_alloc /= 0 )   CALL ctl_warn('zdf_tke_alloc: failed to allocate arrays')
132      !
133   END FUNCTION zdf_tke_alloc
134
135
[1531]136   SUBROUTINE zdf_tke( kt )
[1239]137      !!----------------------------------------------------------------------
[1531]138      !!                   ***  ROUTINE zdf_tke  ***
[1239]139      !!
140      !! ** Purpose :   Compute the vertical eddy viscosity and diffusivity
[1492]141      !!              coefficients using a turbulent closure scheme (TKE).
[1239]142      !!
[1492]143      !! ** Method  :   The time evolution of the turbulent kinetic energy (tke)
144      !!              is computed from a prognostic equation :
145      !!         d(en)/dt = avm (d(u)/dz)**2             ! shear production
146      !!                  + d( avm d(en)/dz )/dz         ! diffusion of tke
147      !!                  + avt N^2                      ! stratif. destruc.
148      !!                  - rn_ediss / emxl en**(2/3)    ! Kolmogoroff dissipation
[1239]149      !!      with the boundary conditions:
[1695]150      !!         surface: en = max( rn_emin0, rn_ebb * taum )
[1239]151      !!         bottom : en = rn_emin
[1492]152      !!      The associated critical Richardson number is: ri_cri = 2/(2+rn_ediss/rn_ediff)
153      !!
154      !!        The now Turbulent kinetic energy is computed using the following
155      !!      time stepping: implicit for vertical diffusion term, linearized semi
156      !!      implicit for kolmogoroff dissipation term, and explicit forward for
157      !!      both buoyancy and shear production terms. Therefore a tridiagonal
158      !!      linear system is solved. Note that buoyancy and shear terms are
159      !!      discretized in a energy conserving form (Bruchard 2002).
160      !!
161      !!        The dissipative and mixing length scale are computed from en and
162      !!      the stratification (see tke_avn)
163      !!
164      !!        The now vertical eddy vicosity and diffusivity coefficients are
165      !!      given by:
166      !!              avm = max( avtb, rn_ediff * zmxlm * en^1/2 )
167      !!              avt = max( avmb, pdl * avm                 ) 
[1239]168      !!              eav = max( avmb, avm )
[1492]169      !!      where pdl, the inverse of the Prandtl number is 1 if nn_pdl=0 and
170      !!      given by an empirical funtion of the localRichardson number if nn_pdl=1
[1239]171      !!
172      !! ** Action  :   compute en (now turbulent kinetic energy)
173      !!                update avt, avmu, avmv (before vertical eddy coef.)
174      !!
175      !! References : Gaspar et al., JGR, 1990,
176      !!              Blanke and Delecluse, JPO, 1991
177      !!              Mellor and Blumberg, JPO 2004
178      !!              Axell, JGR, 2002
[1492]179      !!              Bruchard OM 2002
[1239]180      !!----------------------------------------------------------------------
[1492]181      INTEGER, INTENT(in) ::   kt   ! ocean time step
182      !!----------------------------------------------------------------------
[1481]183      !
[3632]184      IF( kt /= nit000 ) THEN   ! restore before value to compute tke
185         avt (:,:,:) = avt_k (:,:,:) 
186         avm (:,:,:) = avm_k (:,:,:) 
187         avmu(:,:,:) = avmu_k(:,:,:) 
188         avmv(:,:,:) = avmv_k(:,:,:) 
189      ENDIF 
190      !
[2528]191      CALL tke_tke      ! now tke (en)
[1492]192      !
[2528]193      CALL tke_avn      ! now avt, avm, avmu, avmv
194      !
[3632]195      avt_k (:,:,:) = avt (:,:,:) 
196      avm_k (:,:,:) = avm (:,:,:) 
197      avmu_k(:,:,:) = avmu(:,:,:) 
198      avmv_k(:,:,:) = avmv(:,:,:) 
199      !
[6487]200#if defined key_agrif
201      ! Update child grid f => parent grid
202      IF( .NOT.Agrif_Root() )   CALL Agrif_Update_Tke( kt )      ! children only
203#endif     
204     !
[1531]205   END SUBROUTINE zdf_tke
[1239]206
[1492]207
[1481]208   SUBROUTINE tke_tke
[1239]209      !!----------------------------------------------------------------------
[1492]210      !!                   ***  ROUTINE tke_tke  ***
211      !!
212      !! ** Purpose :   Compute the now Turbulente Kinetic Energy (TKE)
213      !!
214      !! ** Method  : - TKE surface boundary condition
[2528]215      !!              - source term due to Langmuir cells (Axell JGR 2002) (ln_lc=T)
[1492]216      !!              - source term due to shear (saved in avmu, avmv arrays)
217      !!              - Now TKE : resolution of the TKE equation by inverting
218      !!                a tridiagonal linear system by a "methode de chasse"
219      !!              - increase TKE due to surface and internal wave breaking
220      !!
221      !! ** Action  : - en : now turbulent kinetic energy)
222      !!              - avmu, avmv : production of TKE by shear at u and v-points
223      !!                (= Kz dz[Ub] * dz[Un] )
[1239]224      !! ---------------------------------------------------------------------
[1705]225      INTEGER  ::   ji, jj, jk                      ! dummy loop arguments
[2528]226!!bfr      INTEGER  ::   ikbu, ikbv, ikbum1, ikbvm1      ! temporary scalar
227!!bfr      INTEGER  ::   ikbt, ikbumm1, ikbvmm1          ! temporary scalar
[1705]228      REAL(wp) ::   zrhoa  = 1.22                   ! Air density kg/m3
229      REAL(wp) ::   zcdrag = 1.5e-3                 ! drag coefficient
230      REAL(wp) ::   zbbrau, zesh2                   ! temporary scalars
231      REAL(wp) ::   zfact1, zfact2, zfact3          !    -         -
232      REAL(wp) ::   ztx2  , zty2  , zcof            !    -         -
233      REAL(wp) ::   ztau  , zdif                    !    -         -
234      REAL(wp) ::   zus   , zwlc  , zind            !    -         -
235      REAL(wp) ::   zzd_up, zzd_lw                  !    -         -
[2528]236!!bfr      REAL(wp) ::   zebot                           !    -         -
[3294]237      INTEGER , POINTER, DIMENSION(:,:  ) :: imlc
238      REAL(wp), POINTER, DIMENSION(:,:  ) :: zhlc
239      REAL(wp), POINTER, DIMENSION(:,:,:) :: zpelc, zdiag, zd_up, zd_lw
[1239]240      !!--------------------------------------------------------------------
[1492]241      !
[3294]242      IF( nn_timing == 1 )  CALL timing_start('tke_tke')
243      !
244      CALL wrk_alloc( jpi,jpj, imlc )    ! integer
245      CALL wrk_alloc( jpi,jpj, zhlc ) 
246      CALL wrk_alloc( jpi,jpj,jpk, zpelc, zdiag, zd_up, zd_lw ) 
247      !
[1695]248      zbbrau = rn_ebb / rau0       ! Local constant initialisation
[2528]249      zfact1 = -.5_wp * rdt 
250      zfact2 = 1.5_wp * rdt * rn_ediss
251      zfact3 = 0.5_wp       * rn_ediss
[1492]252      !
[5120]253      !
[1492]254      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
255      !                     !  Surface boundary condition on tke
256      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
[5120]257      IF ( ln_isfcav ) THEN
258         DO jj = 2, jpjm1            ! en(mikt(ji,jj))   = rn_emin
259            DO ji = fs_2, fs_jpim1   ! vector opt.
260               en(ji,jj,mikt(ji,jj))=rn_emin * tmask(ji,jj,1)
261            END DO
262         END DO
263      END IF
[1695]264      DO jj = 2, jpjm1            ! en(1)   = rn_ebb taum / rau0  (min value rn_emin0)
[1481]265         DO ji = fs_2, fs_jpim1   ! vector opt.
[5120]266            en(ji,jj,1) = MAX( rn_emin0, zbbrau * taum(ji,jj) ) * tmask(ji,jj,1)
[1481]267         END DO
268      END DO
[2528]269     
270!!bfr   - start commented area
[1492]271      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
272      !                     !  Bottom boundary condition on tke
273      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
[1719]274      !
275      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
276      ! Tests to date have found the bottom boundary condition on tke to have very little effect.
277      ! The condition is coded here for completion but commented out until there is proof that the
278      ! computational cost is justified
279      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
280      !                     en(bot)   = (rn_ebb0/rau0)*0.5*sqrt(u_botfr^2+v_botfr^2) (min value rn_emin)
[1662]281!CDIR NOVERRCHK
[1719]282!!    DO jj = 2, jpjm1
[1662]283!CDIR NOVERRCHK
[1719]284!!       DO ji = fs_2, fs_jpim1   ! vector opt.
[2528]285!!          ztx2 = bfrua(ji-1,jj) * ub(ji-1,jj,mbku(ji-1,jj)) + &
286!!                 bfrua(ji  ,jj) * ub(ji  ,jj,mbku(ji  ,jj) )
287!!          zty2 = bfrva(ji,jj  ) * vb(ji,jj  ,mbkv(ji,jj  )) + &
288!!                 bfrva(ji,jj-1) * vb(ji,jj-1,mbkv(ji,jj-1) )
[1719]289!!          zebot = 0.001875_wp * SQRT( ztx2 * ztx2 + zty2 * zty2 )   !  where 0.001875 = (rn_ebb0/rau0) * 0.5 = 3.75*0.5/1000.
[2528]290!!          en (ji,jj,mbkt(ji,jj)+1) = MAX( zebot, rn_emin ) * tmask(ji,jj,1)
[1719]291!!       END DO
292!!    END DO
[2528]293!!bfr   - end commented area
[1492]294      !
295      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
[2528]296      IF( ln_lc ) THEN      !  Langmuir circulation source term added to tke       (Axell JGR 2002)
[1492]297         !                  !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[1239]298         !
[1492]299         !                        !* total energy produce by LC : cumulative sum over jk
[2528]300         zpelc(:,:,1) =  MAX( rn2b(:,:,1), 0._wp ) * fsdepw(:,:,1) * fse3w(:,:,1)
[1239]301         DO jk = 2, jpk
[2528]302            zpelc(:,:,jk)  = zpelc(:,:,jk-1) + MAX( rn2b(:,:,jk), 0._wp ) * fsdepw(:,:,jk) * fse3w(:,:,jk)
[1239]303         END DO
[1492]304         !                        !* finite Langmuir Circulation depth
[1705]305         zcof = 0.5 * 0.016 * 0.016 / ( zrhoa * zcdrag )
[2528]306         imlc(:,:) = mbkt(:,:) + 1       ! Initialization to the number of w ocean point (=2 over land)
[1239]307         DO jk = jpkm1, 2, -1
[1492]308            DO jj = 1, jpj               ! Last w-level at which zpelc>=0.5*us*us
309               DO ji = 1, jpi            !      with us=0.016*wind(starting from jpk-1)
[1705]310                  zus  = zcof * taum(ji,jj)
[1239]311                  IF( zpelc(ji,jj,jk) > zus )   imlc(ji,jj) = jk
312               END DO
313            END DO
314         END DO
[1492]315         !                               ! finite LC depth
316         DO jj = 1, jpj 
[1239]317            DO ji = 1, jpi
318               zhlc(ji,jj) = fsdepw(ji,jj,imlc(ji,jj))
319            END DO
320         END DO
[1705]321         zcof = 0.016 / SQRT( zrhoa * zcdrag )
[5120]322!CDIR NOVERRCHK
[1492]323         DO jk = 2, jpkm1         !* TKE Langmuir circulation source term added to en
[5120]324!CDIR NOVERRCHK
[1239]325            DO jj = 2, jpjm1
[5120]326!CDIR NOVERRCHK
[1239]327               DO ji = fs_2, fs_jpim1   ! vector opt.
[1705]328                  zus  = zcof * SQRT( taum(ji,jj) )           ! Stokes drift
[1492]329                  !                                           ! vertical velocity due to LC
[1239]330                  zind = 0.5 - SIGN( 0.5, fsdepw(ji,jj,jk) - zhlc(ji,jj) )
331                  zwlc = zind * rn_lc * zus * SIN( rpi * fsdepw(ji,jj,jk) / zhlc(ji,jj) )
[1492]332                  !                                           ! TKE Langmuir circulation source term
[6487]333                  en(ji,jj,jk) = en(ji,jj,jk) + rdt * ( 1._wp - fr_i(ji,jj) ) * ( zwlc * zwlc * zwlc ) /   &
334                     &   zhlc(ji,jj) * wmask(ji,jj,jk) * tmask(ji,jj,1)
[1239]335               END DO
336            END DO
337         END DO
338         !
339      ENDIF
[1492]340      !
341      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
342      !                     !  Now Turbulent kinetic energy (output in en)
343      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
344      !                     ! Resolution of a tridiagonal linear system by a "methode de chasse"
345      !                     ! computation from level 2 to jpkm1  (e(1) already computed and e(jpk)=0 ).
346      !                     ! zdiag : diagonal zd_up : upper diagonal zd_lw : lower diagonal
347      !
348      DO jk = 2, jpkm1           !* Shear production at uw- and vw-points (energy conserving form)
349         DO jj = 1, jpj                 ! here avmu, avmv used as workspace
350            DO ji = 1, jpi
351               avmu(ji,jj,jk) = avmu(ji,jj,jk) * ( un(ji,jj,jk-1) - un(ji,jj,jk) )   &
352                  &                            * ( ub(ji,jj,jk-1) - ub(ji,jj,jk) )   & 
[5120]353                  &                            / (  fse3uw_n(ji,jj,jk)               &
354                  &                              *  fse3uw_b(ji,jj,jk)  )
[1492]355               avmv(ji,jj,jk) = avmv(ji,jj,jk) * ( vn(ji,jj,jk-1) - vn(ji,jj,jk) )   &
356                  &                            * ( vb(ji,jj,jk-1) - vb(ji,jj,jk) )   &
357                  &                            / (  fse3vw_n(ji,jj,jk)               &
358                  &                              *  fse3vw_b(ji,jj,jk)  )
359            END DO
360         END DO
361      END DO
362      !
[5120]363      DO jk = 2, jpkm1           !* Matrix and right hand side in en
364         DO jj = 2, jpjm1
365            DO ji = fs_2, fs_jpim1   ! vector opt.
[1492]366               zcof   = zfact1 * tmask(ji,jj,jk)
[6498]367# if defined key_zdftmx_new
368               ! key_zdftmx_new: New internal wave-driven param: set a minimum value for Kz on TKE (ensure numerical stability)
369               zzd_up = zcof * ( MAX( avm(ji,jj,jk+1) + avm(ji,jj,jk), 2.e-5_wp ) )   &  ! upper diagonal
370                  &          / ( fse3t(ji,jj,jk  ) * fse3w(ji,jj,jk  ) )
371               zzd_lw = zcof * ( MAX( avm(ji,jj,jk) + avm(ji,jj,jk-1), 2.e-5_wp ) )   &  ! lower diagonal
372                  &          / ( fse3t(ji,jj,jk-1) * fse3w(ji,jj,jk  ) )
373# else
[1492]374               zzd_up = zcof * ( avm  (ji,jj,jk+1) + avm  (ji,jj,jk  ) )   &  ! upper diagonal
375                  &          / ( fse3t(ji,jj,jk  ) * fse3w(ji,jj,jk  ) )
376               zzd_lw = zcof * ( avm  (ji,jj,jk  ) + avm  (ji,jj,jk-1) )   &  ! lower diagonal
377                  &          / ( fse3t(ji,jj,jk-1) * fse3w(ji,jj,jk  ) )
[6498]378# endif
[1492]379                  !                                                           ! shear prod. at w-point weightened by mask
[2528]380               zesh2  =  ( avmu(ji-1,jj,jk) + avmu(ji,jj,jk) ) / MAX( 1._wp , umask(ji-1,jj,jk) + umask(ji,jj,jk) )   &
381                  &    + ( avmv(ji,jj-1,jk) + avmv(ji,jj,jk) ) / MAX( 1._wp , vmask(ji,jj-1,jk) + vmask(ji,jj,jk) )   
[1492]382                  !
383               zd_up(ji,jj,jk) = zzd_up            ! Matrix (zdiag, zd_up, zd_lw)
384               zd_lw(ji,jj,jk) = zzd_lw
[2528]385               zdiag(ji,jj,jk) = 1._wp - zzd_lw - zzd_up + zfact2 * dissl(ji,jj,jk) * tmask(ji,jj,jk)
[1239]386               !
[1492]387               !                                   ! right hand side in en
[1481]388               en(ji,jj,jk) = en(ji,jj,jk) + rdt * (  zesh2  -   avt(ji,jj,jk) * rn2(ji,jj,jk)    &
[4990]389                  &                                 + zfact3 * dissl(ji,jj,jk) * en (ji,jj,jk)  ) &
[5120]390                  &                                 * wmask(ji,jj,jk)
[1239]391            END DO
[5120]392         END DO
393      END DO
394      !                          !* Matrix inversion from level 2 (tke prescribed at level 1)
395      DO jk = 3, jpkm1                             ! First recurrence : Dk = Dk - Lk * Uk-1 / Dk-1
396         DO jj = 2, jpjm1
397            DO ji = fs_2, fs_jpim1    ! vector opt.
[1492]398               zdiag(ji,jj,jk) = zdiag(ji,jj,jk) - zd_lw(ji,jj,jk) * zd_up(ji,jj,jk-1) / zdiag(ji,jj,jk-1)
[1239]399            END DO
[5120]400         END DO
401      END DO
402      !
403      ! Second recurrence : Lk = RHSk - Lk / Dk-1 * Lk-1
404      DO jj = 2, jpjm1
405         DO ji = fs_2, fs_jpim1   ! vector opt.
406            zd_lw(ji,jj,2) = en(ji,jj,2) - zd_lw(ji,jj,2) * en(ji,jj,1)    ! Surface boudary conditions on tke
407         END DO
408      END DO
409      DO jk = 3, jpkm1
410         DO jj = 2, jpjm1
411            DO ji = fs_2, fs_jpim1    ! vector opt.
[1492]412               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)
[1239]413            END DO
[5120]414         END DO
415      END DO
416      !
417      ! thrid recurrence : Ek = ( Lk - Uk * Ek+1 ) / Dk
418      DO jj = 2, jpjm1
419         DO ji = fs_2, fs_jpim1   ! vector opt.
[1492]420            en(ji,jj,jpkm1) = zd_lw(ji,jj,jpkm1) / zdiag(ji,jj,jpkm1)
[5120]421         END DO
422      END DO
423      DO jk = jpk-2, 2, -1
424         DO jj = 2, jpjm1
425            DO ji = fs_2, fs_jpim1    ! vector opt.
[1492]426               en(ji,jj,jk) = ( zd_lw(ji,jj,jk) - zd_up(ji,jj,jk) * en(ji,jj,jk+1) ) / zdiag(ji,jj,jk)
[1239]427            END DO
[5120]428         END DO
429      END DO
430      DO jk = 2, jpkm1                             ! set the minimum value of tke
431         DO jj = 2, jpjm1
432            DO ji = fs_2, fs_jpim1   ! vector opt.
433               en(ji,jj,jk) = MAX( en(ji,jj,jk), rn_emin ) * wmask(ji,jj,jk)
[1239]434            END DO
435         END DO
436      END DO
437
[6491]438      !                                 ! Save TKE prior to nn_etau addition 
439      e_niw(:,:,:) = en(:,:,:) 
440     
[1492]441      !                            !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
442      !                            !  TKE due to surface and internal wave breaking
443      !                            !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
[6491]444      IF( nn_htau == 2 ) THEN           !* mixed-layer depth dependant length scale
445         DO jj = 2, jpjm1
446            DO ji = fs_2, fs_jpim1   ! vector opt.
447               htau(ji,jj) = rhtau * hmlp(ji,jj)
448            END DO
449         END DO
450      ENDIF
451#if defined key_iomput
452      !
453      CALL iom_put( "htau", htau(:,:) )  ! Check htau (even if constant in time)
454#endif
455      !
[2528]456      IF( nn_etau == 1 ) THEN           !* penetration below the mixed layer (rn_efr fraction)
[1492]457         DO jk = 2, jpkm1
[1239]458            DO jj = 2, jpjm1
459               DO ji = fs_2, fs_jpim1   ! vector opt.
[1492]460                  en(ji,jj,jk) = en(ji,jj,jk) + rn_efr * en(ji,jj,1) * EXP( -fsdepw(ji,jj,jk) / htau(ji,jj) )   &
[5120]461                     &                                 * ( 1._wp - fr_i(ji,jj) )  * wmask(ji,jj,jk) * tmask(ji,jj,1)
[1239]462               END DO
463            END DO
[1492]464         END DO
[2528]465      ELSEIF( nn_etau == 2 ) THEN       !* act only at the base of the mixed layer (jk=nmln)  (rn_efr fraction)
[1492]466         DO jj = 2, jpjm1
467            DO ji = fs_2, fs_jpim1   ! vector opt.
468               jk = nmln(ji,jj)
469               en(ji,jj,jk) = en(ji,jj,jk) + rn_efr * en(ji,jj,1) * EXP( -fsdepw(ji,jj,jk) / htau(ji,jj) )   &
[5120]470                  &                                 * ( 1._wp - fr_i(ji,jj) )  * wmask(ji,jj,jk) * tmask(ji,jj,1)
[1239]471            END DO
[1492]472         END DO
[2528]473      ELSEIF( nn_etau == 3 ) THEN       !* penetration belox the mixed layer (HF variability)
[1705]474!CDIR NOVERRCHK
475         DO jk = 2, jpkm1
476!CDIR NOVERRCHK
477            DO jj = 2, jpjm1
478!CDIR NOVERRCHK
479               DO ji = fs_2, fs_jpim1   ! vector opt.
480                  ztx2 = utau(ji-1,jj  ) + utau(ji,jj)
481                  zty2 = vtau(ji  ,jj-1) + vtau(ji,jj)
[4990]482                  ztau = 0.5_wp * SQRT( ztx2 * ztx2 + zty2 * zty2 ) * tmask(ji,jj,1)    ! module of the mean stress
[2528]483                  zdif = taum(ji,jj) - ztau                            ! mean of modulus - modulus of the mean
484                  zdif = rhftau_scl * MAX( 0._wp, zdif + rhftau_add )  ! apply some modifications...
[1705]485                  en(ji,jj,jk) = en(ji,jj,jk) + zbbrau * zdif * EXP( -fsdepw(ji,jj,jk) / htau(ji,jj) )   &
[5120]486                     &                        * ( 1._wp - fr_i(ji,jj) ) * wmask(ji,jj,jk) * tmask(ji,jj,1)
[1705]487               END DO
488            END DO
489         END DO
[6491]490      ELSEIF( nn_etau == 4 ) THEN       !* column integral independant of htau (rn_efr must be scaled up)
491         IF( nn_htau == 2 ) THEN        ! efr dependant on time-varying htau
492            DO jj = 2, jpjm1
493               DO ji = fs_2, fs_jpim1   ! vector opt.
494                  efr(ji,jj) = rn_efr / ( htau(ji,jj) * ( 1._wp - EXP( -bathy(ji,jj) / htau(ji,jj) ) ) )
495               END DO
496            END DO
497         ENDIF
498         DO jk = 2, jpkm1
499            DO jj = 2, jpjm1
500               DO ji = fs_2, fs_jpim1   ! vector opt.
501                  en(ji,jj,jk) = en(ji,jj,jk) + efr(ji,jj) * en(ji,jj,1) * EXP( -fsdepw(ji,jj,jk) / htau(ji,jj) )   &
502                     &                                                   * ( 1._wp - fr_i(ji,jj) )  * tmask(ji,jj,jk)
503               END DO
504            END DO
505         END DO
[1239]506      ENDIF
[1492]507      CALL lbc_lnk( en, 'W', 1. )      ! Lateral boundary conditions (sign unchanged)
508      !
[6491]509      DO jk = 2, jpkm1                             ! TKE budget: near-inertial waves term 
510         DO jj = 2, jpjm1 
511            DO ji = fs_2, fs_jpim1   ! vector opt. 
512               e_niw(ji,jj,jk) = en(ji,jj,jk) - e_niw(ji,jj,jk) 
513            END DO 
514         END DO 
515      END DO 
516     
517      CALL lbc_lnk( e_niw, 'W', 1. ) 
518      !
[3294]519      CALL wrk_dealloc( jpi,jpj, imlc )    ! integer
520      CALL wrk_dealloc( jpi,jpj, zhlc ) 
521      CALL wrk_dealloc( jpi,jpj,jpk, zpelc, zdiag, zd_up, zd_lw ) 
[2715]522      !
[3294]523      IF( nn_timing == 1 )  CALL timing_stop('tke_tke')
524      !
[1239]525   END SUBROUTINE tke_tke
526
[1492]527
528   SUBROUTINE tke_avn
[1239]529      !!----------------------------------------------------------------------
[1492]530      !!                   ***  ROUTINE tke_avn  ***
[1239]531      !!
[1492]532      !! ** Purpose :   Compute the vertical eddy viscosity and diffusivity
533      !!
534      !! ** Method  :   At this stage, en, the now TKE, is known (computed in
535      !!              the tke_tke routine). First, the now mixing lenth is
536      !!      computed from en and the strafification (N^2), then the mixings
537      !!      coefficients are computed.
538      !!              - Mixing length : a first evaluation of the mixing lengh
539      !!      scales is:
540      !!                      mxl = sqrt(2*en) / N 
541      !!      where N is the brunt-vaisala frequency, with a minimum value set
[2528]542      !!      to rmxl_min (rn_mxl0) in the interior (surface) ocean.
[1492]543      !!        The mixing and dissipative length scale are bound as follow :
544      !!         nn_mxl=0 : mxl bounded by the distance to surface and bottom.
545      !!                        zmxld = zmxlm = mxl
546      !!         nn_mxl=1 : mxl bounded by the e3w and zmxld = zmxlm = mxl
547      !!         nn_mxl=2 : mxl bounded such that the vertical derivative of mxl is
548      !!                    less than 1 (|d/dz(mxl)|<1) and zmxld = zmxlm = mxl
549      !!         nn_mxl=3 : mxl is bounded from the surface to the bottom usings
550      !!                    |d/dz(xml)|<1 to obtain lup, and from the bottom to
551      !!                    the surface to obtain ldown. the resulting length
552      !!                    scales are:
553      !!                        zmxld = sqrt( lup * ldown )
554      !!                        zmxlm = min ( lup , ldown )
555      !!              - Vertical eddy viscosity and diffusivity:
556      !!                      avm = max( avtb, rn_ediff * zmxlm * en^1/2 )
557      !!                      avt = max( avmb, pdlr * avm ) 
558      !!      with pdlr=1 if nn_pdl=0, pdlr=1/pdl=F(Ri) otherwise.
559      !!
560      !! ** Action  : - avt : now vertical eddy diffusivity (w-point)
561      !!              - avmu, avmv : now vertical eddy viscosity at uw- and vw-points
[1239]562      !!----------------------------------------------------------------------
[2715]563      INTEGER  ::   ji, jj, jk   ! dummy loop indices
564      REAL(wp) ::   zrn2, zraug, zcoef, zav     ! local scalars
565      REAL(wp) ::   zdku, zpdlr, zri, zsqen     !   -      -
566      REAL(wp) ::   zdkv, zemxl, zemlm, zemlp   !   -      -
[3294]567      REAL(wp), POINTER, DIMENSION(:,:,:) :: zmpdl, zmxlm, zmxld
[1239]568      !!--------------------------------------------------------------------
[3294]569      !
570      IF( nn_timing == 1 )  CALL timing_start('tke_avn')
[1239]571
[3294]572      CALL wrk_alloc( jpi,jpj,jpk, zmpdl, zmxlm, zmxld ) 
573
[1492]574      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
575      !                     !  Mixing length
576      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
577      !
578      !                     !* Buoyancy length scale: l=sqrt(2*e/n**2)
579      !
[5120]580      ! initialisation of interior minimum value (avoid a 2d loop with mikt)
581      zmxlm(:,:,:)  = rmxl_min   
582      zmxld(:,:,:)  = rmxl_min
583      !
[2528]584      IF( ln_mxl0 ) THEN            ! surface mixing length = F(stress) : l=vkarmn*2.e5*taum/(rau0*g)
[4990]585         DO jj = 2, jpjm1
586            DO ji = fs_2, fs_jpim1
[5120]587               zraug = vkarmn * 2.e5_wp / ( rau0 * grav )
588               zmxlm(ji,jj,1) = MAX( rn_mxl0, zraug * taum(ji,jj) * tmask(ji,jj,1) )
[4990]589            END DO
590         END DO
591      ELSE
[5120]592         zmxlm(:,:,1) = rn_mxl0
[1239]593      ENDIF
594      !
595!CDIR NOVERRCHK
[5120]596      DO jk = 2, jpkm1              ! interior value : l=sqrt(2*e/n^2)
[1239]597!CDIR NOVERRCHK
[5120]598         DO jj = 2, jpjm1
599!CDIR NOVERRCHK
600            DO ji = fs_2, fs_jpim1   ! vector opt.
[1239]601               zrn2 = MAX( rn2(ji,jj,jk), rsmall )
[5120]602               zmxlm(ji,jj,jk) = MAX(  rmxl_min,  SQRT( 2._wp * en(ji,jj,jk) / zrn2 ) )
[1239]603            END DO
604         END DO
605      END DO
[1492]606      !
607      !                     !* Physical limits for the mixing length
608      !
[5120]609      zmxld(:,:,1  ) = zmxlm(:,:,1)   ! surface set to the minimum value
[2528]610      zmxld(:,:,jpk) = rmxl_min       ! last level  set to the minimum value
[1492]611      !
[1239]612      SELECT CASE ( nn_mxl )
613      !
[5120]614      ! where wmask = 0 set zmxlm == fse3w
[1239]615      CASE ( 0 )           ! bounded by the distance to surface and bottom
[5120]616         DO jk = 2, jpkm1
617            DO jj = 2, jpjm1
618               DO ji = fs_2, fs_jpim1   ! vector opt.
[4990]619                  zemxl = MIN( fsdepw(ji,jj,jk) - fsdepw(ji,jj,mikt(ji,jj)), zmxlm(ji,jj,jk),   &
[2528]620                  &            fsdepw(ji,jj,mbkt(ji,jj)+1) - fsdepw(ji,jj,jk) )
[5120]621                  ! wmask prevent zmxlm = 0 if jk = mikt(ji,jj)
622                  zmxlm(ji,jj,jk) = zemxl * wmask(ji,jj,jk) + MIN(zmxlm(ji,jj,jk),fse3w(ji,jj,jk)) * (1 - wmask(ji,jj,jk))
623                  zmxld(ji,jj,jk) = zemxl * wmask(ji,jj,jk) + MIN(zmxlm(ji,jj,jk),fse3w(ji,jj,jk)) * (1 - wmask(ji,jj,jk))
[1239]624               END DO
625            END DO
626         END DO
627         !
628      CASE ( 1 )           ! bounded by the vertical scale factor
[5120]629         DO jk = 2, jpkm1
630            DO jj = 2, jpjm1
631               DO ji = fs_2, fs_jpim1   ! vector opt.
[1239]632                  zemxl = MIN( fse3w(ji,jj,jk), zmxlm(ji,jj,jk) )
633                  zmxlm(ji,jj,jk) = zemxl
634                  zmxld(ji,jj,jk) = zemxl
635               END DO
636            END DO
637         END DO
638         !
639      CASE ( 2 )           ! |dk[xml]| bounded by e3t :
[5120]640         DO jk = 2, jpkm1         ! from the surface to the bottom :
641            DO jj = 2, jpjm1
642               DO ji = fs_2, fs_jpim1   ! vector opt.
[1239]643                  zmxlm(ji,jj,jk) = MIN( zmxlm(ji,jj,jk-1) + fse3t(ji,jj,jk-1), zmxlm(ji,jj,jk) )
644               END DO
[5120]645            END DO
646         END DO
647         DO jk = jpkm1, 2, -1     ! from the bottom to the surface :
648            DO jj = 2, jpjm1
649               DO ji = fs_2, fs_jpim1   ! vector opt.
[1239]650                  zemxl = MIN( zmxlm(ji,jj,jk+1) + fse3t(ji,jj,jk+1), zmxlm(ji,jj,jk) )
651                  zmxlm(ji,jj,jk) = zemxl
652                  zmxld(ji,jj,jk) = zemxl
653               END DO
654            END DO
655         END DO
656         !
657      CASE ( 3 )           ! lup and ldown, |dk[xml]| bounded by e3t :
[5120]658         DO jk = 2, jpkm1         ! from the surface to the bottom : lup
659            DO jj = 2, jpjm1
660               DO ji = fs_2, fs_jpim1   ! vector opt.
[1239]661                  zmxld(ji,jj,jk) = MIN( zmxld(ji,jj,jk-1) + fse3t(ji,jj,jk-1), zmxlm(ji,jj,jk) )
662               END DO
[5120]663            END DO
664         END DO
665         DO jk = jpkm1, 2, -1     ! from the bottom to the surface : ldown
666            DO jj = 2, jpjm1
667               DO ji = fs_2, fs_jpim1   ! vector opt.
[1239]668                  zmxlm(ji,jj,jk) = MIN( zmxlm(ji,jj,jk+1) + fse3t(ji,jj,jk+1), zmxlm(ji,jj,jk) )
669               END DO
670            END DO
671         END DO
672!CDIR NOVERRCHK
673         DO jk = 2, jpkm1
674!CDIR NOVERRCHK
675            DO jj = 2, jpjm1
676!CDIR NOVERRCHK
677               DO ji = fs_2, fs_jpim1   ! vector opt.
678                  zemlm = MIN ( zmxld(ji,jj,jk),  zmxlm(ji,jj,jk) )
679                  zemlp = SQRT( zmxld(ji,jj,jk) * zmxlm(ji,jj,jk) )
680                  zmxlm(ji,jj,jk) = zemlm
681                  zmxld(ji,jj,jk) = zemlp
682               END DO
683            END DO
684         END DO
685         !
686      END SELECT
[1492]687      !
[1239]688# if defined key_c1d
[1492]689      e_dis(:,:,:) = zmxld(:,:,:)      ! c1d configuration : save mixing and dissipation turbulent length scales
[1239]690      e_mix(:,:,:) = zmxlm(:,:,:)
691# endif
692
[1492]693      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
694      !                     !  Vertical eddy viscosity and diffusivity  (avmu, avmv, avt)
695      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
[1239]696!CDIR NOVERRCHK
[1492]697      DO jk = 1, jpkm1            !* vertical eddy viscosity & diffivity at w-points
[1239]698!CDIR NOVERRCHK
699         DO jj = 2, jpjm1
700!CDIR NOVERRCHK
701            DO ji = fs_2, fs_jpim1   ! vector opt.
702               zsqen = SQRT( en(ji,jj,jk) )
703               zav   = rn_ediff * zmxlm(ji,jj,jk) * zsqen
[5120]704               avm  (ji,jj,jk) = MAX( zav,                  avmb(jk) ) * wmask(ji,jj,jk)
705               avt  (ji,jj,jk) = MAX( zav, avtb_2d(ji,jj) * avtb(jk) ) * wmask(ji,jj,jk)
[1239]706               dissl(ji,jj,jk) = zsqen / zmxld(ji,jj,jk)
707            END DO
708         END DO
709      END DO
[1492]710      CALL lbc_lnk( avm, 'W', 1. )      ! Lateral boundary conditions (sign unchanged)
711      !
[5120]712      DO jk = 2, jpkm1            !* vertical eddy viscosity at wu- and wv-points
713         DO jj = 2, jpjm1
714            DO ji = fs_2, fs_jpim1   ! vector opt.
715               avmu(ji,jj,jk) = 0.5 * ( avm(ji,jj,jk) + avm(ji+1,jj  ,jk) ) * wumask(ji,jj,jk)
716               avmv(ji,jj,jk) = 0.5 * ( avm(ji,jj,jk) + avm(ji  ,jj+1,jk) ) * wvmask(ji,jj,jk)
[4990]717            END DO
[1239]718         END DO
719      END DO
720      CALL lbc_lnk( avmu, 'U', 1. )   ;   CALL lbc_lnk( avmv, 'V', 1. )      ! Lateral boundary conditions
[1492]721      !
722      IF( nn_pdl == 1 ) THEN      !* Prandtl number case: update avt
[5120]723         DO jk = 2, jpkm1
724            DO jj = 2, jpjm1
725               DO ji = fs_2, fs_jpim1   ! vector opt.
[2528]726                  zcoef = avm(ji,jj,jk) * 2._wp * fse3w(ji,jj,jk) * fse3w(ji,jj,jk)
[1492]727                  !                                          ! shear
728                  zdku = avmu(ji-1,jj,jk) * ( un(ji-1,jj,jk-1) - un(ji-1,jj,jk) ) * ( ub(ji-1,jj,jk-1) - ub(ji-1,jj,jk) )   &
729                    &  + avmu(ji  ,jj,jk) * ( un(ji  ,jj,jk-1) - un(ji  ,jj,jk) ) * ( ub(ji  ,jj,jk-1) - ub(ji  ,jj,jk) )
730                  zdkv = avmv(ji,jj-1,jk) * ( vn(ji,jj-1,jk-1) - vn(ji,jj-1,jk) ) * ( vb(ji,jj-1,jk-1) - vb(ji,jj-1,jk) )   &
731                    &  + avmv(ji,jj  ,jk) * ( vn(ji,jj  ,jk-1) - vn(ji,jj  ,jk) ) * ( vb(ji,jj  ,jk-1) - vb(ji,jj  ,jk) )
732                  !                                          ! local Richardson number
[2528]733                  zri   = MAX( rn2b(ji,jj,jk), 0._wp ) * zcoef / (zdku + zdkv + rn_bshear )
734                  zpdlr = MAX(  0.1_wp,  0.2 / MAX( 0.2 , zri )  )
[1492]735!!gm and even better with the use of the "true" ri_crit=0.22222...  (this change the results!)
[2528]736!!gm              zpdlr = MAX(  0.1_wp,  ri_crit / MAX( ri_crit , zri )  )
[5120]737                  avt(ji,jj,jk)   = MAX( zpdlr * avt(ji,jj,jk), avtb_2d(ji,jj) * avtb(jk) ) * wmask(ji,jj,jk)
[1492]738# if defined key_c1d
[5120]739                  e_pdl(ji,jj,jk) = zpdlr * wmask(ji,jj,jk)  ! c1d configuration : save masked Prandlt number
740                  e_ric(ji,jj,jk) = zri   * wmask(ji,jj,jk)  ! c1d config. : save Ri
[1239]741# endif
742              END DO
743            END DO
744         END DO
745      ENDIF
746      CALL lbc_lnk( avt, 'W', 1. )                      ! Lateral boundary conditions on avt  (sign unchanged)
747
748      IF(ln_ctl) THEN
749         CALL prt_ctl( tab3d_1=en  , clinfo1=' tke  - e: ', tab3d_2=avt, clinfo2=' t: ', ovlap=1, kdim=jpk)
750         CALL prt_ctl( tab3d_1=avmu, clinfo1=' tke  - u: ', mask1=umask,                   &
751            &          tab3d_2=avmv, clinfo2=       ' v: ', mask2=vmask, ovlap=1, kdim=jpk )
752      ENDIF
753      !
[3294]754      CALL wrk_dealloc( jpi,jpj,jpk, zmpdl, zmxlm, zmxld ) 
755      !
756      IF( nn_timing == 1 )  CALL timing_stop('tke_avn')
757      !
[1492]758   END SUBROUTINE tke_avn
[1239]759
[1492]760
[2528]761   SUBROUTINE zdf_tke_init
[1239]762      !!----------------------------------------------------------------------
[2528]763      !!                  ***  ROUTINE zdf_tke_init  ***
[1239]764      !!                     
765      !! ** Purpose :   Initialization of the vertical eddy diffivity and
[1492]766      !!              viscosity when using a tke turbulent closure scheme
[1239]767      !!
[1601]768      !! ** Method  :   Read the namzdf_tke namelist and check the parameters
[1492]769      !!              called at the first timestep (nit000)
[1239]770      !!
[1601]771      !! ** input   :   Namlist namzdf_tke
[1239]772      !!
773      !! ** Action  :   Increase by 1 the nstop flag is setting problem encounter
774      !!----------------------------------------------------------------------
775      INTEGER ::   ji, jj, jk   ! dummy loop indices
[6487]776      INTEGER ::   ios, ierr
[1239]777      !!
[2528]778      NAMELIST/namzdf_tke/ rn_ediff, rn_ediss , rn_ebb , rn_emin  ,   &
779         &                 rn_emin0, rn_bshear, nn_mxl , ln_mxl0  ,   &
780         &                 rn_mxl0 , nn_pdl   , ln_lc  , rn_lc    ,   &
[6491]781         &                 nn_etau , nn_htau  , rn_efr , rn_c   
[1239]782      !!----------------------------------------------------------------------
[9366]783      IF(lwm) THEN
784         REWIND( numnam_ref )              ! Namelist namzdf_tke in reference namelist : Turbulent Kinetic Energy
785         READ  ( numnam_ref, namzdf_tke, IOSTAT = ios, ERR = 901)
786901      IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_tke in reference namelist', lwm )
787         REWIND( numnam_cfg )              ! Namelist namzdf_tke in configuration namelist : Turbulent Kinetic Energy
788         READ  ( numnam_cfg, namzdf_tke, IOSTAT = ios, ERR = 902 )
789902      IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_tke in configuration namelist', lwm )
790      ENDIF
[6491]791
[4624]792      IF(lwm) WRITE ( numond, namzdf_tke )
[9366]793      ! Broadcast namelist
794      CALL tke_namelist()
[2715]795      !
[2528]796      ri_cri   = 2._wp    / ( 2._wp + rn_ediss / rn_ediff )   ! resulting critical Richardson number
[6498]797# if defined key_zdftmx_new
798      ! key_zdftmx_new: New internal wave-driven param: specified value of rn_emin & rmxl_min are used
799      rn_emin  = 1.e-10_wp
800      rmxl_min = 1.e-03_wp
801      IF(lwp) THEN                  ! Control print
802         WRITE(numout,*)
803         WRITE(numout,*) 'zdf_tke_init :  New tidal mixing case: force rn_emin = 1.e-10 and rmxl_min = 1.e-3 '
804         WRITE(numout,*) '~~~~~~~~~~~~'
805      ENDIF
806# else
[2528]807      rmxl_min = 1.e-6_wp / ( rn_ediff * SQRT( rn_emin ) )    ! resulting minimum length to recover molecular viscosity
[6498]808# endif
[2715]809      !
[1492]810      IF(lwp) THEN                    !* Control print
[1239]811         WRITE(numout,*)
[2528]812         WRITE(numout,*) 'zdf_tke_init : tke turbulent closure scheme - initialisation'
813         WRITE(numout,*) '~~~~~~~~~~~~'
[1601]814         WRITE(numout,*) '   Namelist namzdf_tke : set tke mixing parameters'
[1705]815         WRITE(numout,*) '      coef. to compute avt                        rn_ediff  = ', rn_ediff
816         WRITE(numout,*) '      Kolmogoroff dissipation coef.               rn_ediss  = ', rn_ediss
817         WRITE(numout,*) '      tke surface input coef.                     rn_ebb    = ', rn_ebb
818         WRITE(numout,*) '      minimum value of tke                        rn_emin   = ', rn_emin
819         WRITE(numout,*) '      surface minimum value of tke                rn_emin0  = ', rn_emin0
820         WRITE(numout,*) '      background shear (>0)                       rn_bshear = ', rn_bshear
821         WRITE(numout,*) '      mixing length type                          nn_mxl    = ', nn_mxl
822         WRITE(numout,*) '      prandl number flag                          nn_pdl    = ', nn_pdl
823         WRITE(numout,*) '      surface mixing length = F(stress) or not    ln_mxl0   = ', ln_mxl0
[2528]824         WRITE(numout,*) '      surface  mixing length minimum value        rn_mxl0   = ', rn_mxl0
825         WRITE(numout,*) '      flag to take into acc.  Langmuir circ.      ln_lc     = ', ln_lc
826         WRITE(numout,*) '      coef to compute verticla velocity of LC     rn_lc     = ', rn_lc
[1705]827         WRITE(numout,*) '      test param. to add tke induced by wind      nn_etau   = ', nn_etau
828         WRITE(numout,*) '      flag for computation of exp. tke profile    nn_htau   = ', nn_htau
829         WRITE(numout,*) '      fraction of en which pene. the thermocline  rn_efr    = ', rn_efr
[6491]830         WRITE(numout,*) '      fraction of TKE added within the mixed layer by nn_etau rn_c    = ', rn_c
[1239]831         WRITE(numout,*)
[1601]832         WRITE(numout,*) '      critical Richardson nb with your parameters  ri_cri = ', ri_cri
[1239]833      ENDIF
[2715]834      !
835      !                              ! allocate tke arrays
836      IF( zdf_tke_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'zdf_tke_init : unable to allocate arrays' )
837      !
[1492]838      !                               !* Check of some namelist values
[4990]839      IF( nn_mxl  < 0   .OR.  nn_mxl  > 3 )   CALL ctl_stop( 'bad flag: nn_mxl is  0, 1 or 2 ' )
840      IF( nn_pdl  < 0   .OR.  nn_pdl  > 1 )   CALL ctl_stop( 'bad flag: nn_pdl is  0 or 1    ' )
[6491]841      IF( nn_htau < 0  .OR.  nn_htau > 5 )   CALL ctl_stop( 'bad flag: nn_htau is 0 to 5    ' )
[5407]842      IF( nn_etau == 3 .AND. .NOT. ln_cpl )   CALL ctl_stop( 'nn_etau == 3 : HF taum only known in coupled mode' )
[1239]843
[2528]844      IF( ln_mxl0 ) THEN
845         IF(lwp) WRITE(numout,*) '   use a surface mixing length = F(stress) :   set rn_mxl0 = rmxl_min'
846         rn_mxl0 = rmxl_min
847      ENDIF
848     
[6487]849      IF( nn_etau == 2  ) THEN
850          ierr = zdf_mxl_alloc()
851          nmln(:,:) = nlb10           ! Initialization of nmln
852      ENDIF
[1239]853
[6491]854      IF( nn_etau /= 0 .and. nn_htau == 2 ) THEN
855          ierr = zdf_mxl_alloc()
856          nmln(:,:) = nlb10           ! Initialization of nmln
857      ENDIF
858
[1492]859      !                               !* depth of penetration of surface tke
860      IF( nn_etau /= 0 ) THEN     
[6491]861         htau(:,:) = 0._wp
[1601]862         SELECT CASE( nn_htau )             ! Choice of the depth of penetration
[2528]863         CASE( 0 )                                 ! constant depth penetration (here 10 meters)
864            htau(:,:) = 10._wp
865         CASE( 1 )                                 ! F(latitude) : 0.5m to 30m poleward of 40 degrees
866            htau(:,:) = MAX(  0.5_wp, MIN( 30._wp, 45._wp* ABS( SIN( rpi/180._wp * gphit(:,:) ) ) )   )           
[6491]867         CASE( 2 )                                 ! fraction of depth-integrated TKE within mixed-layer
868            rhtau = -1._wp / LOG( 1._wp - rn_c )
869         CASE( 3 )                                 ! F(latitude) : 0.5m to 15m poleward of 20 degrees
870            htau(:,:) = MAX(  0.5_wp, MIN( 15._wp, 45._wp* ABS( SIN( rpi/180._wp * gphit(:,:) ) ) )   )
871         CASE( 4 )                                 ! F(latitude) : 0.5m to 10m/30m poleward of 13/40 degrees north/south
872            DO jj = 2, jpjm1
873               DO ji = fs_2, fs_jpim1   ! vector opt.
874                  IF( gphit(ji,jj) <= 0._wp ) THEN
875                     htau(ji,jj) = MAX(  0.5_wp, MIN( 30._wp, 45._wp* ABS( SIN( rpi/180._wp * gphit(ji,jj) ) ) )   )
876                  ELSE
877                     htau(ji,jj) = MAX(  0.5_wp, MIN( 10._wp, 45._wp* ABS( SIN( rpi/180._wp * gphit(ji,jj) ) ) )   )
878                  ENDIF
879               END DO
880            END DO
881         CASE ( 5 )                                ! F(latitude) : 0.5m to 10m poleward of 13 degrees north/south,
882            DO jj = 2, jpjm1                       !               10m to 30m between 30/45 degrees south
883               DO ji = fs_2, fs_jpim1   ! vector opt.
884                  IF( gphit(ji,jj) <= -30._wp ) THEN
885                     htau(ji,jj) = MAX(  10._wp, MIN( 30._wp, 55._wp* ABS( SIN( rpi/120._wp * ( gphit(ji,jj) + 23._wp ) ) ) )   )
886                  ELSE
887                     htau(ji,jj) = MAX(  0.5_wp, MIN( 10._wp, 45._wp* ABS( SIN( rpi/180._wp * gphit(ji,jj) ) ) )   )
888                  ENDIF
889               END DO
890            END DO
[1492]891         END SELECT
[6491]892         !
893         IF( nn_etau == 4 .AND. nn_htau /= 2 ) THEN            ! efr dependant on constant htau
894            DO jj = 2, jpjm1
895               DO ji = fs_2, fs_jpim1   ! vector opt.
896                  efr(ji,jj) = rn_efr / ( htau(ji,jj) * ( 1._wp - EXP( -bathy(ji,jj) / htau(ji,jj) ) ) )
897               END DO
898            END DO
899         ENDIF
[1492]900      ENDIF
901      !                               !* set vertical eddy coef. to the background value
[1239]902      DO jk = 1, jpk
[5120]903         avt (:,:,jk) = avtb(jk) * wmask (:,:,jk)
904         avm (:,:,jk) = avmb(jk) * wmask (:,:,jk)
905         avmu(:,:,jk) = avmb(jk) * wumask(:,:,jk)
906         avmv(:,:,jk) = avmb(jk) * wvmask(:,:,jk)
[1239]907      END DO
[2528]908      dissl(:,:,:) = 1.e-12_wp
[2715]909      !                             
910      CALL tke_rst( nit000, 'READ' )  !* read or initialize all required files
[1239]911      !
[2528]912   END SUBROUTINE zdf_tke_init
[1239]913
914
[1531]915   SUBROUTINE tke_rst( kt, cdrw )
[1239]916     !!---------------------------------------------------------------------
[1531]917     !!                   ***  ROUTINE tke_rst  ***
[1239]918     !!                     
919     !! ** Purpose :   Read or write TKE file (en) in restart file
920     !!
921     !! ** Method  :   use of IOM library
922     !!                if the restart does not contain TKE, en is either
[1537]923     !!                set to rn_emin or recomputed
[1239]924     !!----------------------------------------------------------------------
[2715]925     INTEGER         , INTENT(in) ::   kt     ! ocean time-step
926     CHARACTER(len=*), INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
[1239]927     !
[1481]928     INTEGER ::   jit, jk   ! dummy loop indices
[2715]929     INTEGER ::   id1, id2, id3, id4, id5, id6   ! local integers
[1239]930     !!----------------------------------------------------------------------
931     !
[1481]932     IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise
933        !                                   ! ---------------
934        IF( ln_rstart ) THEN                   !* Read the restart file
935           id1 = iom_varid( numror, 'en'   , ldstop = .FALSE. )
936           id2 = iom_varid( numror, 'avt'  , ldstop = .FALSE. )
937           id3 = iom_varid( numror, 'avm'  , ldstop = .FALSE. )
938           id4 = iom_varid( numror, 'avmu' , ldstop = .FALSE. )
939           id5 = iom_varid( numror, 'avmv' , ldstop = .FALSE. )
940           id6 = iom_varid( numror, 'dissl', ldstop = .FALSE. )
941           !
942           IF( id1 > 0 ) THEN                       ! 'en' exists
[7924]943              CALL iom_get( numror, jpdom_autoglo, 'en', en, lrxios = lxios_read )
[1481]944              IF( MIN( id2, id3, id4, id5, id6 ) > 0 ) THEN        ! all required arrays exist
[7924]945                 CALL iom_get( numror, jpdom_autoglo, 'avt'  , avt, lrxios = lxios_read   )
946                 CALL iom_get( numror, jpdom_autoglo, 'avm'  , avm, lrxios = lxios_read   )
947                 CALL iom_get( numror, jpdom_autoglo, 'avmu' , avmu, lrxios = lxios_read  )
948                 CALL iom_get( numror, jpdom_autoglo, 'avmv' , avmv, lrxios = lxios_read  )
949                 CALL iom_get( numror, jpdom_autoglo, 'dissl', dissl, lrxios = lxios_read )
[1492]950              ELSE                                                 ! one at least array is missing
951                 CALL tke_avn                                          ! compute avt, avm, avmu, avmv and dissl (approximation)
[1481]952              ENDIF
953           ELSE                                     ! No TKE array found: initialisation
954              IF(lwp) WRITE(numout,*) ' ===>>>> : previous run without tke scheme, en computed by iterative loop'
[1239]955              en (:,:,:) = rn_emin * tmask(:,:,:)
[1492]956              CALL tke_avn                               ! recompute avt, avm, avmu, avmv and dissl (approximation)
[5112]957              !
958              avt_k (:,:,:) = avt (:,:,:)
959              avm_k (:,:,:) = avm (:,:,:)
960              avmu_k(:,:,:) = avmu(:,:,:)
961              avmv_k(:,:,:) = avmv(:,:,:)
962              !
[1531]963              DO jit = nit000 + 1, nit000 + 10   ;   CALL zdf_tke( jit )   ;   END DO
[1239]964           ENDIF
[1481]965        ELSE                                   !* Start from rest
966           en(:,:,:) = rn_emin * tmask(:,:,:)
967           DO jk = 1, jpk                           ! set the Kz to the background value
[5120]968              avt (:,:,jk) = avtb(jk) * wmask (:,:,jk)
969              avm (:,:,jk) = avmb(jk) * wmask (:,:,jk)
970              avmu(:,:,jk) = avmb(jk) * wumask(:,:,jk)
971              avmv(:,:,jk) = avmb(jk) * wvmask(:,:,jk)
[1481]972           END DO
[1239]973        ENDIF
[1481]974        !
975     ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
976        !                                   ! -------------------
[1531]977        IF(lwp) WRITE(numout,*) '---- tke-rst ----'
[8243]978        IF( lwxios ) CALL iom_swap(      wxios_context          )
979        CALL iom_rstput( kt, nitrst, numrow, 'en'   , en    , lxios = lwxios )
980        CALL iom_rstput( kt, nitrst, numrow, 'avt'  , avt_k , lxios = lwxios )
981        CALL iom_rstput( kt, nitrst, numrow, 'avm'  , avm_k , lxios = lwxios )
982        CALL iom_rstput( kt, nitrst, numrow, 'avmu' , avmu_k, lxios = lwxios )
983        CALL iom_rstput( kt, nitrst, numrow, 'avmv' , avmv_k, lxios = lwxios )
984        CALL iom_rstput( kt, nitrst, numrow, 'dissl', dissl , lxios = lwxios )
985        IF( lwxios ) CALL iom_swap(      cxios_context          )
[1481]986        !
[1239]987     ENDIF
988     !
[1531]989   END SUBROUTINE tke_rst
[1239]990
[9366]991   SUBROUTINE tke_namelist()
992     !!---------------------------------------------------------------------
993     !!                   ***  ROUTINE tke_namelist  ***
994     !!                     
995     !! ** Purpose :   Broadcast namelist variables read by procesor lwp
996     !!
997     !! ** Method  :   use lib_mpp
998     !!----------------------------------------------------------------------
999#if defined key_mpp_mpi
1000      call mpp_bcast(rn_ediff)
1001      call mpp_bcast(rn_ediss)
1002      call mpp_bcast(rn_ebb)
1003      call mpp_bcast(rn_emin)
1004      call mpp_bcast(rn_emin0)
1005      call mpp_bcast(rn_bshear)
1006      call mpp_bcast(nn_mxl)
1007      call mpp_bcast(ln_mxl0)
1008      call mpp_bcast(rn_mxl0)
1009      call mpp_bcast(nn_pdl)
1010      call mpp_bcast(ln_lc)
1011      call mpp_bcast(rn_lc)
1012      call mpp_bcast(nn_etau)
1013      call mpp_bcast(nn_htau)
1014      call mpp_bcast(rn_efr)
1015      call mpp_bcast(rn_c)
1016#endif
1017   END SUBROUTINE tke_namelist
[1239]1018#else
1019   !!----------------------------------------------------------------------
1020   !!   Dummy module :                                        NO TKE scheme
1021   !!----------------------------------------------------------------------
[1531]1022   LOGICAL, PUBLIC, PARAMETER ::   lk_zdftke = .FALSE.   !: TKE flag
[1239]1023CONTAINS
[2528]1024   SUBROUTINE zdf_tke_init           ! Dummy routine
1025   END SUBROUTINE zdf_tke_init
1026   SUBROUTINE zdf_tke( kt )          ! Dummy routine
[1531]1027      WRITE(*,*) 'zdf_tke: You should not have seen this print! error?', kt
1028   END SUBROUTINE zdf_tke
1029   SUBROUTINE tke_rst( kt, cdrw )
[1492]1030     CHARACTER(len=*) ::   cdrw
[1531]1031     WRITE(*,*) 'tke_rst: You should not have seen this print! error?', kt, cdwr
1032   END SUBROUTINE tke_rst
[1239]1033#endif
1034
1035   !!======================================================================
[1531]1036END MODULE zdftke
Note: See TracBrowser for help on using the repository browser.