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/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF – NEMO

source: branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftke.F90 @ 9019

Last change on this file since 9019 was 9019, checked in by timgraham, 6 years ago

Merge of dev_CNRS_2017 into branch

  • Property svn:keywords set to Id
File size: 42.7 KB
Line 
1MODULE zdftke
2   !!======================================================================
3   !!                       ***  MODULE  zdftke  ***
4   !! Ocean physics:  vertical mixing coefficient computed from the tke
5   !!                 turbulent closure parameterization
6   !!=====================================================================
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
27   !!            3.3  !  2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
28   !!            3.6  !  2014-11  (P. Mathiot) add ice shelf capability
29   !!            4.0  !  2017-04  (G. Madec)  remove CPP ddm key & avm at t-point only
30   !!             -   !  2017-05  (G. Madec)  add top/bottom friction as boundary condition (ln_drg)
31   !!----------------------------------------------------------------------
32
33   !!----------------------------------------------------------------------
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
39   !!----------------------------------------------------------------------
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
44   USE sbc_oce        ! surface boundary condition: ocean
45   USE zdfdrg         ! vertical physics: top/bottom drag coef.
46   USE zdfmxl         ! vertical physics: mixed layer
47   !
48   USE in_out_manager ! I/O manager
49   USE iom            ! I/O manager library
50   USE lib_mpp        ! MPP library
51   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
52   USE prtctl         ! Print control
53   USE timing         ! Timing
54   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined) 
55
56   IMPLICIT NONE
57   PRIVATE
58
59   PUBLIC   zdf_tke        ! routine called in step module
60   PUBLIC   zdf_tke_init   ! routine called in opa module
61   PUBLIC   tke_rst        ! routine called in step module
62
63   !                      !!** Namelist  namzdf_tke  **
64   LOGICAL  ::   ln_mxl0   ! mixing length scale surface value as function of wind stress or not
65   INTEGER  ::   nn_mxl    ! type of mixing length (=0/1/2/3)
66   REAL(wp) ::   rn_mxl0   ! surface  min value of mixing length (kappa*z_o=0.4*0.1 m)  [m]
67   INTEGER  ::   nn_pdl    ! Prandtl number or not (ratio avt/avm) (=0/1)
68   REAL(wp) ::   rn_ediff  ! coefficient for avt: avt=rn_ediff*mxl*sqrt(e)
69   REAL(wp) ::   rn_ediss  ! coefficient of the Kolmogoroff dissipation
70   REAL(wp) ::   rn_ebb    ! coefficient of the surface input of tke
71   REAL(wp) ::   rn_emin   ! minimum value of tke           [m2/s2]
72   REAL(wp) ::   rn_emin0  ! surface minimum value of tke   [m2/s2]
73   REAL(wp) ::   rn_bshear ! background shear (>0) currently a numerical threshold (do not change it)
74   LOGICAL  ::   ln_drg    ! top/bottom friction forcing flag
75   INTEGER  ::   nn_etau   ! type of depth penetration of surface tke (=0/1/2/3)
76   INTEGER  ::      nn_htau   ! type of tke profile of penetration (=0/1)
77   REAL(wp) ::      rn_efr    ! fraction of TKE surface value which penetrates in the ocean
78   LOGICAL  ::   ln_lc     ! Langmuir cells (LC) as a source term of TKE or not
79   REAL(wp) ::      rn_lc     ! coef to compute vertical velocity of Langmuir cells
80
81   REAL(wp) ::   ri_cri    ! critic Richardson number (deduced from rn_ediff and rn_ediss values)
82   REAL(wp) ::   rmxl_min  ! minimum mixing length value (deduced from rn_ediff and rn_emin values)  [m]
83   REAL(wp) ::   rhftau_add = 1.e-3_wp     ! add offset   applied to HF part of taum  (nn_etau=3)
84   REAL(wp) ::   rhftau_scl = 1.0_wp       ! scale factor applied to HF part of taum  (nn_etau=3)
85
86   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   htau    ! depth of tke penetration (nn_htau)
87   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   dissl   ! now mixing lenght of dissipation
88   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   apdlr   ! now mixing lenght of dissipation
89
90   !! * Substitutions
91#  include "vectopt_loop_substitute.h90"
92   !!----------------------------------------------------------------------
93   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
94   !! $Id$
95   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
96   !!----------------------------------------------------------------------
97CONTAINS
98
99   INTEGER FUNCTION zdf_tke_alloc()
100      !!----------------------------------------------------------------------
101      !!                ***  FUNCTION zdf_tke_alloc  ***
102      !!----------------------------------------------------------------------
103      ALLOCATE( htau(jpi,jpj) , dissl(jpi,jpj,jpk) , apdlr(jpi,jpj,jpk) ,   STAT= zdf_tke_alloc )
104      !
105      IF( lk_mpp             )   CALL mpp_sum ( zdf_tke_alloc )
106      IF( zdf_tke_alloc /= 0 )   CALL ctl_warn('zdf_tke_alloc: failed to allocate arrays')
107      !
108   END FUNCTION zdf_tke_alloc
109
110
111   SUBROUTINE zdf_tke( kt, p_sh2, p_avm, p_avt )
112      !!----------------------------------------------------------------------
113      !!                   ***  ROUTINE zdf_tke  ***
114      !!
115      !! ** Purpose :   Compute the vertical eddy viscosity and diffusivity
116      !!              coefficients using a turbulent closure scheme (TKE).
117      !!
118      !! ** Method  :   The time evolution of the turbulent kinetic energy (tke)
119      !!              is computed from a prognostic equation :
120      !!         d(en)/dt = avm (d(u)/dz)**2             ! shear production
121      !!                  + d( avm d(en)/dz )/dz         ! diffusion of tke
122      !!                  + avt N^2                      ! stratif. destruc.
123      !!                  - rn_ediss / emxl en**(2/3)    ! Kolmogoroff dissipation
124      !!      with the boundary conditions:
125      !!         surface: en = max( rn_emin0, rn_ebb * taum )
126      !!         bottom : en = rn_emin
127      !!      The associated critical Richardson number is: ri_cri = 2/(2+rn_ediss/rn_ediff)
128      !!
129      !!        The now Turbulent kinetic energy is computed using the following
130      !!      time stepping: implicit for vertical diffusion term, linearized semi
131      !!      implicit for kolmogoroff dissipation term, and explicit forward for
132      !!      both buoyancy and shear production terms. Therefore a tridiagonal
133      !!      linear system is solved. Note that buoyancy and shear terms are
134      !!      discretized in a energy conserving form (Bruchard 2002).
135      !!
136      !!        The dissipative and mixing length scale are computed from en and
137      !!      the stratification (see tke_avn)
138      !!
139      !!        The now vertical eddy vicosity and diffusivity coefficients are
140      !!      given by:
141      !!              avm = max( avtb, rn_ediff * zmxlm * en^1/2 )
142      !!              avt = max( avmb, pdl * avm                 ) 
143      !!              eav = max( avmb, avm )
144      !!      where pdl, the inverse of the Prandtl number is 1 if nn_pdl=0 and
145      !!      given by an empirical funtion of the localRichardson number if nn_pdl=1
146      !!
147      !! ** Action  :   compute en (now turbulent kinetic energy)
148      !!                update avt, avm (before vertical eddy coef.)
149      !!
150      !! References : Gaspar et al., JGR, 1990,
151      !!              Blanke and Delecluse, JPO, 1991
152      !!              Mellor and Blumberg, JPO 2004
153      !!              Axell, JGR, 2002
154      !!              Bruchard OM 2002
155      !!----------------------------------------------------------------------
156      INTEGER                   , INTENT(in   ) ::   kt             ! ocean time step
157      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   p_sh2          ! shear production term
158      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   p_avm, p_avt   !  momentum and tracer Kz (w-points)
159      !!----------------------------------------------------------------------
160      !
161      CALL tke_tke( gdepw_n, e3t_n, e3w_n, p_sh2, p_avm, p_avt )   ! now tke (en)
162      !
163      CALL tke_avn( gdepw_n, e3t_n, e3w_n,        p_avm, p_avt )   ! now avt, avm, dissl
164      !
165  END SUBROUTINE zdf_tke
166
167
168   SUBROUTINE tke_tke( pdepw, p_e3t, p_e3w, p_sh2, p_avm, p_avt )
169      !!----------------------------------------------------------------------
170      !!                   ***  ROUTINE tke_tke  ***
171      !!
172      !! ** Purpose :   Compute the now Turbulente Kinetic Energy (TKE)
173      !!
174      !! ** Method  : - TKE surface boundary condition
175      !!              - source term due to Langmuir cells (Axell JGR 2002) (ln_lc=T)
176      !!              - source term due to shear (= Kz dz[Ub] * dz[Un] )
177      !!              - Now TKE : resolution of the TKE equation by inverting
178      !!                a tridiagonal linear system by a "methode de chasse"
179      !!              - increase TKE due to surface and internal wave breaking
180      !!             NB: when sea-ice is present, both LC parameterization
181      !!                 and TKE penetration are turned off when the ice fraction
182      !!                 is smaller than 0.25
183      !!
184      !! ** Action  : - en : now turbulent kinetic energy)
185      !! ---------------------------------------------------------------------
186      USE zdf_oce , ONLY : en   ! ocean vertical physics
187      !!
188      REAL(wp), DIMENSION(:,:,:) , INTENT(in   ) ::   pdepw          ! depth of w-points
189      REAL(wp), DIMENSION(:,:,:) , INTENT(in   ) ::   p_e3t, p_e3w   ! level thickness (t- & w-points)
190      REAL(wp), DIMENSION(:,:,:) , INTENT(in   ) ::   p_sh2          ! shear production term
191      REAL(wp), DIMENSION(:,:,:) , INTENT(in   ) ::   p_avm, p_avt   ! vertical eddy viscosity & diffusivity (w-points)
192      !
193      INTEGER ::   ji, jj, jk              ! dummy loop arguments
194      REAL(wp) ::   zetop, zebot, zmsku, zmskv ! local scalars
195      REAL(wp) ::   zrhoa  = 1.22              ! Air density kg/m3
196      REAL(wp) ::   zcdrag = 1.5e-3            ! drag coefficient
197      REAL(wp) ::   zbbrau, zri                ! local scalars
198      REAL(wp) ::   zfact1, zfact2, zfact3     !   -         -
199      REAL(wp) ::   ztx2  , zty2  , zcof       !   -         -
200      REAL(wp) ::   ztau  , zdif               !   -         -
201      REAL(wp) ::   zus   , zwlc  , zind       !   -         -
202      REAL(wp) ::   zzd_up, zzd_lw             !   -         -
203      INTEGER , DIMENSION(jpi,jpj)     ::   imlc
204      REAL(wp), DIMENSION(jpi,jpj)     ::   zhlc
205      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zpelc, zdiag, zd_up, zd_lw
206      !!--------------------------------------------------------------------
207      !
208      IF( ln_timing )   CALL timing_start('tke_tke')
209      !
210      zbbrau = rn_ebb / rau0       ! Local constant initialisation
211      zfact1 = -.5_wp * rdt 
212      zfact2 = 1.5_wp * rdt * rn_ediss
213      zfact3 = 0.5_wp       * rn_ediss
214      !
215      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
216      !                     !  Surface/top/bottom boundary condition on tke
217      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
218     
219      DO jj = 2, jpjm1            ! en(1)   = rn_ebb taum / rau0  (min value rn_emin0)
220         DO ji = fs_2, fs_jpim1   ! vector opt.
221            en(ji,jj,1) = MAX( rn_emin0, zbbrau * taum(ji,jj) ) * tmask(ji,jj,1)
222         END DO
223      END DO
224      IF ( ln_isfcav ) THEN
225         DO jj = 2, jpjm1            ! en(mikt(ji,jj))   = rn_emin
226            DO ji = fs_2, fs_jpim1   ! vector opt.
227               en(ji,jj,mikt(ji,jj)) = rn_emin * tmask(ji,jj,1)
228            END DO
229         END DO
230      ENDIF
231      !
232      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
233      !                     !  Bottom boundary condition on tke
234      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
235      !
236      !   en(bot)   = (ebb0/rau0)*0.5*sqrt(u_botfr^2+v_botfr^2) (min value rn_emin)
237      ! where ebb0 does not includes surface wave enhancement (i.e. ebb0=3.75)
238      ! Note that stress averaged is done using an wet-only calculation of u and v at t-point like in zdfsh2
239      !
240      IF( ln_drg ) THEN       !== friction used as top/bottom boundary condition on TKE
241         !
242         DO jj = 2, jpjm1           ! bottom friction
243            DO ji = fs_2, fs_jpim1     ! vector opt.
244               zmsku = ( 2. - umask(ji-1,jj,mbkt(ji,jj)) * umask(ji,jj,mbkt(ji,jj)) )
245               zmskv = ( 2. - vmask(ji,jj-1,mbkt(ji,jj)) * vmask(ji,jj,mbkt(ji,jj)) )
246               !                       ! where 0.001875 = (rn_ebb0/rau0) * 0.5 = 3.75*0.5/1000. (CAUTION CdU<0)
247               zebot = - 0.001875_wp * rCdU_bot(ji,jj) * SQRT(  ( zmsku*( ub(ji,jj,mbkt(ji,jj))+ub(ji-1,jj,mbkt(ji,jj)) ) )**2  &
248                  &                                           + ( zmskv*( vb(ji,jj,mbkt(ji,jj))+vb(ji,jj-1,mbkt(ji,jj)) ) )**2  )
249               en(ji,jj,mbkt(ji,jj)+1) = MAX( zebot, rn_emin ) * ssmask(ji,jj)
250            END DO
251         END DO
252         IF( ln_isfcav ) THEN       ! top friction
253            DO jj = 2, jpjm1
254               DO ji = fs_2, fs_jpim1   ! vector opt.
255                  zmsku = ( 2. - umask(ji-1,jj,mikt(ji,jj)) * umask(ji,jj,mikt(ji,jj)) )
256                  zmskv = ( 2. - vmask(ji,jj-1,mikt(ji,jj)) * vmask(ji,jj,mikt(ji,jj)) )
257                  !                             ! where 0.001875 = (rn_ebb0/rau0) * 0.5 = 3.75*0.5/1000.  (CAUTION CdU<0)
258                  zetop = - 0.001875_wp * rCdU_top(ji,jj) * SQRT(  ( zmsku*( ub(ji,jj,mikt(ji,jj))+ub(ji-1,jj,mikt(ji,jj)) ) )**2  &
259                     &                                           + ( zmskv*( vb(ji,jj,mikt(ji,jj))+vb(ji,jj-1,mikt(ji,jj)) ) )**2  )
260                  en(ji,jj,mikt(ji,jj)) = MAX( zetop, rn_emin ) * (1._wp - tmask(ji,jj,1))   ! masked at ocean surface
261               END DO
262            END DO
263         ENDIF
264         !
265      ENDIF
266      !
267      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
268      IF( ln_lc ) THEN      !  Langmuir circulation source term added to tke   !   (Axell JGR 2002)
269         !                  !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
270         !
271         !                        !* total energy produce by LC : cumulative sum over jk
272         zpelc(:,:,1) =  MAX( rn2b(:,:,1), 0._wp ) * pdepw(:,:,1) * p_e3w(:,:,1)
273         DO jk = 2, jpk
274            zpelc(:,:,jk)  = zpelc(:,:,jk-1) + MAX( rn2b(:,:,jk), 0._wp ) * pdepw(:,:,jk) * p_e3w(:,:,jk)
275         END DO
276         !                        !* finite Langmuir Circulation depth
277         zcof = 0.5 * 0.016 * 0.016 / ( zrhoa * zcdrag )
278         imlc(:,:) = mbkt(:,:) + 1       ! Initialization to the number of w ocean point (=2 over land)
279         DO jk = jpkm1, 2, -1
280            DO jj = 1, jpj               ! Last w-level at which zpelc>=0.5*us*us
281               DO ji = 1, jpi            !      with us=0.016*wind(starting from jpk-1)
282                  zus  = zcof * taum(ji,jj)
283                  IF( zpelc(ji,jj,jk) > zus )   imlc(ji,jj) = jk
284               END DO
285            END DO
286         END DO
287         !                               ! finite LC depth
288         DO jj = 1, jpj 
289            DO ji = 1, jpi
290               zhlc(ji,jj) = pdepw(ji,jj,imlc(ji,jj))
291            END DO
292         END DO
293         zcof = 0.016 / SQRT( zrhoa * zcdrag )
294         DO jk = 2, jpkm1         !* TKE Langmuir circulation source term added to en
295            DO jj = 2, jpjm1
296               DO ji = fs_2, fs_jpim1   ! vector opt.
297                  zus  = zcof * SQRT( taum(ji,jj) )           ! Stokes drift
298                  !                                           ! vertical velocity due to LC
299                  zind = 0.5 - SIGN( 0.5, pdepw(ji,jj,jk) - zhlc(ji,jj) )
300                  zwlc = zind * rn_lc * zus * SIN( rpi * pdepw(ji,jj,jk) / zhlc(ji,jj) )
301                  !                                           ! TKE Langmuir circulation source term
302                  en(ji,jj,jk) = en(ji,jj,jk) + rdt * MAX(0.,1._wp - 4.*fr_i(ji,jj) ) * ( zwlc * zwlc * zwlc )   &
303                     &                              / zhlc(ji,jj) * wmask(ji,jj,jk) * tmask(ji,jj,1)
304               END DO
305            END DO
306         END DO
307         !
308      ENDIF
309      !
310      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
311      !                     !  Now Turbulent kinetic energy (output in en)
312      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
313      !                     ! Resolution of a tridiagonal linear system by a "methode de chasse"
314      !                     ! computation from level 2 to jpkm1  (e(1) already computed and e(jpk)=0 ).
315      !                     ! zdiag : diagonal zd_up : upper diagonal zd_lw : lower diagonal
316      !
317      IF( nn_pdl == 1 ) THEN      !* Prandtl number = F( Ri )
318         DO jk = 2, jpkm1
319            DO jj = 2, jpjm1
320               DO ji = 2, jpim1
321                  !                             ! local Richardson number
322                  zri = MAX( rn2b(ji,jj,jk), 0._wp ) * p_avm(ji,jj,jk) / ( p_sh2(ji,jj,jk) + rn_bshear )
323                  !                             ! inverse of Prandtl number
324                  apdlr(ji,jj,jk) = MAX(  0.1_wp,  ri_cri / MAX( ri_cri , zri )  )
325               END DO
326            END DO
327         END DO
328      ENDIF
329      !         
330      DO jk = 2, jpkm1           !* Matrix and right hand side in en
331         DO jj = 2, jpjm1
332            DO ji = fs_2, fs_jpim1   ! vector opt.
333               zcof   = zfact1 * tmask(ji,jj,jk)
334               !                                   ! A minimum of 2.e-5 m2/s is imposed on TKE vertical
335               !                                   ! eddy coefficient (ensure numerical stability)
336               zzd_up = zcof * MAX(  p_avm(ji,jj,jk+1) + p_avm(ji,jj,jk  ) , 2.e-5_wp  )   &  ! upper diagonal
337                  &          /    (  p_e3t(ji,jj,jk  ) * p_e3w(ji,jj,jk  )  )
338               zzd_lw = zcof * MAX(  p_avm(ji,jj,jk  ) + p_avm(ji,jj,jk-1) , 2.e-5_wp  )   &  ! lower diagonal
339                  &          /    (  p_e3t(ji,jj,jk-1) * p_e3w(ji,jj,jk  )  )
340               !
341               zd_up(ji,jj,jk) = zzd_up            ! Matrix (zdiag, zd_up, zd_lw)
342               zd_lw(ji,jj,jk) = zzd_lw
343               zdiag(ji,jj,jk) = 1._wp - zzd_lw - zzd_up + zfact2 * dissl(ji,jj,jk) * wmask(ji,jj,jk)
344               !
345               !                                   ! right hand side in en
346               en(ji,jj,jk) = en(ji,jj,jk) + rdt * (  p_sh2(ji,jj,jk)                          &   ! shear
347                  &                                 - p_avt(ji,jj,jk) * rn2(ji,jj,jk)          &   ! stratification
348                  &                                 + zfact3 * dissl(ji,jj,jk) * en(ji,jj,jk)  &   ! dissipation
349                  &                                ) * wmask(ji,jj,jk)
350            END DO
351         END DO
352      END DO
353      !                          !* Matrix inversion from level 2 (tke prescribed at level 1)
354      DO jk = 3, jpkm1                             ! First recurrence : Dk = Dk - Lk * Uk-1 / Dk-1
355         DO jj = 2, jpjm1
356            DO ji = fs_2, fs_jpim1    ! vector opt.
357               zdiag(ji,jj,jk) = zdiag(ji,jj,jk) - zd_lw(ji,jj,jk) * zd_up(ji,jj,jk-1) / zdiag(ji,jj,jk-1)
358            END DO
359         END DO
360      END DO
361      DO jj = 2, jpjm1                             ! Second recurrence : Lk = RHSk - Lk / Dk-1 * Lk-1
362         DO ji = fs_2, fs_jpim1   ! vector opt.
363            zd_lw(ji,jj,2) = en(ji,jj,2) - zd_lw(ji,jj,2) * en(ji,jj,1)    ! Surface boudary conditions on tke
364         END DO
365      END DO
366      DO jk = 3, jpkm1
367         DO jj = 2, jpjm1
368            DO ji = fs_2, fs_jpim1    ! vector opt.
369               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)
370            END DO
371         END DO
372      END DO
373      DO jj = 2, jpjm1                             ! thrid recurrence : Ek = ( Lk - Uk * Ek+1 ) / Dk
374         DO ji = fs_2, fs_jpim1   ! vector opt.
375            en(ji,jj,jpkm1) = zd_lw(ji,jj,jpkm1) / zdiag(ji,jj,jpkm1)
376         END DO
377      END DO
378      DO jk = jpk-2, 2, -1
379         DO jj = 2, jpjm1
380            DO ji = fs_2, fs_jpim1    ! vector opt.
381               en(ji,jj,jk) = ( zd_lw(ji,jj,jk) - zd_up(ji,jj,jk) * en(ji,jj,jk+1) ) / zdiag(ji,jj,jk)
382            END DO
383         END DO
384      END DO
385      DO jk = 2, jpkm1                             ! set the minimum value of tke
386         DO jj = 2, jpjm1
387            DO ji = fs_2, fs_jpim1   ! vector opt.
388               en(ji,jj,jk) = MAX( en(ji,jj,jk), rn_emin ) * wmask(ji,jj,jk)
389            END DO
390         END DO
391      END DO
392      !
393      !                            !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
394      !                            !  TKE due to surface and internal wave breaking
395      !                            !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
396!!gm BUG : in the exp  remove the depth of ssh !!!
397!!gm       i.e. use gde3w in argument (pdepw)
398     
399     
400      IF( nn_etau == 1 ) THEN           !* penetration below the mixed layer (rn_efr fraction)
401         DO jk = 2, jpkm1
402            DO jj = 2, jpjm1
403               DO ji = fs_2, fs_jpim1   ! vector opt.
404                  en(ji,jj,jk) = en(ji,jj,jk) + rn_efr * en(ji,jj,1) * EXP( -pdepw(ji,jj,jk) / htau(ji,jj) )   &
405                     &                                 * MAX(0.,1._wp - 4.*fr_i(ji,jj) )  * wmask(ji,jj,jk) * tmask(ji,jj,1)
406               END DO
407            END DO
408         END DO
409      ELSEIF( nn_etau == 2 ) THEN       !* act only at the base of the mixed layer (jk=nmln)  (rn_efr fraction)
410         DO jj = 2, jpjm1
411            DO ji = fs_2, fs_jpim1   ! vector opt.
412               jk = nmln(ji,jj)
413               en(ji,jj,jk) = en(ji,jj,jk) + rn_efr * en(ji,jj,1) * EXP( -pdepw(ji,jj,jk) / htau(ji,jj) )   &
414                  &                                 * MAX(0.,1._wp - 4.*fr_i(ji,jj) )  * wmask(ji,jj,jk) * tmask(ji,jj,1)
415            END DO
416         END DO
417      ELSEIF( nn_etau == 3 ) THEN       !* penetration belox the mixed layer (HF variability)
418         DO jk = 2, jpkm1
419            DO jj = 2, jpjm1
420               DO ji = fs_2, fs_jpim1   ! vector opt.
421                  ztx2 = utau(ji-1,jj  ) + utau(ji,jj)
422                  zty2 = vtau(ji  ,jj-1) + vtau(ji,jj)
423                  ztau = 0.5_wp * SQRT( ztx2 * ztx2 + zty2 * zty2 ) * tmask(ji,jj,1)    ! module of the mean stress
424                  zdif = taum(ji,jj) - ztau                            ! mean of modulus - modulus of the mean
425                  zdif = rhftau_scl * MAX( 0._wp, zdif + rhftau_add )  ! apply some modifications...
426                  en(ji,jj,jk) = en(ji,jj,jk) + zbbrau * zdif * EXP( -pdepw(ji,jj,jk) / htau(ji,jj) )   &
427                     &                        * MAX(0.,1._wp - 4.*fr_i(ji,jj) ) * wmask(ji,jj,jk) * tmask(ji,jj,1)
428               END DO
429            END DO
430         END DO
431      ENDIF
432      !
433      IF( ln_timing )   CALL timing_stop('tke_tke')
434      !
435   END SUBROUTINE tke_tke
436
437
438   SUBROUTINE tke_avn( pdepw, p_e3t, p_e3w, p_avm, p_avt )
439      !!----------------------------------------------------------------------
440      !!                   ***  ROUTINE tke_avn  ***
441      !!
442      !! ** Purpose :   Compute the vertical eddy viscosity and diffusivity
443      !!
444      !! ** Method  :   At this stage, en, the now TKE, is known (computed in
445      !!              the tke_tke routine). First, the now mixing lenth is
446      !!      computed from en and the strafification (N^2), then the mixings
447      !!      coefficients are computed.
448      !!              - Mixing length : a first evaluation of the mixing lengh
449      !!      scales is:
450      !!                      mxl = sqrt(2*en) / N 
451      !!      where N is the brunt-vaisala frequency, with a minimum value set
452      !!      to rmxl_min (rn_mxl0) in the interior (surface) ocean.
453      !!        The mixing and dissipative length scale are bound as follow :
454      !!         nn_mxl=0 : mxl bounded by the distance to surface and bottom.
455      !!                        zmxld = zmxlm = mxl
456      !!         nn_mxl=1 : mxl bounded by the e3w and zmxld = zmxlm = mxl
457      !!         nn_mxl=2 : mxl bounded such that the vertical derivative of mxl is
458      !!                    less than 1 (|d/dz(mxl)|<1) and zmxld = zmxlm = mxl
459      !!         nn_mxl=3 : mxl is bounded from the surface to the bottom usings
460      !!                    |d/dz(xml)|<1 to obtain lup, and from the bottom to
461      !!                    the surface to obtain ldown. the resulting length
462      !!                    scales are:
463      !!                        zmxld = sqrt( lup * ldown )
464      !!                        zmxlm = min ( lup , ldown )
465      !!              - Vertical eddy viscosity and diffusivity:
466      !!                      avm = max( avtb, rn_ediff * zmxlm * en^1/2 )
467      !!                      avt = max( avmb, pdlr * avm ) 
468      !!      with pdlr=1 if nn_pdl=0, pdlr=1/pdl=F(Ri) otherwise.
469      !!
470      !! ** Action  : - avt, avm : now vertical eddy diffusivity and viscosity (w-point)
471      !!----------------------------------------------------------------------
472      USE zdf_oce , ONLY : en, avtb, avmb, avtb_2d   ! ocean vertical physics
473      !!
474      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   pdepw          ! depth (w-points)
475      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   p_e3t, p_e3w   ! level thickness (t- & w-points)
476      REAL(wp), DIMENSION(:,:,:), INTENT(  out) ::   p_avm, p_avt   ! vertical eddy viscosity & diffusivity (w-points)
477      !
478      INTEGER  ::   ji, jj, jk   ! dummy loop indices
479      REAL(wp) ::   zrn2, zraug, zcoef, zav   ! local scalars
480      REAL(wp) ::   zdku,   zdkv, zsqen       !   -      -
481      REAL(wp) ::   zemxl, zemlm, zemlp       !   -      -
482      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zmxlm, zmxld   ! 3D workspace
483      !!--------------------------------------------------------------------
484      !
485      IF( ln_timing )   CALL timing_start('tke_avn')
486      !
487      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
488      !                     !  Mixing length
489      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
490      !
491      !                     !* Buoyancy length scale: l=sqrt(2*e/n**2)
492      !
493      ! initialisation of interior minimum value (avoid a 2d loop with mikt)
494      zmxlm(:,:,:)  = rmxl_min   
495      zmxld(:,:,:)  = rmxl_min
496      !
497      IF( ln_mxl0 ) THEN            ! surface mixing length = F(stress) : l=vkarmn*2.e5*taum/(rau0*g)
498         zraug = vkarmn * 2.e5_wp / ( rau0 * grav )
499         DO jj = 2, jpjm1
500            DO ji = fs_2, fs_jpim1
501               zmxlm(ji,jj,1) = MAX( rn_mxl0, zraug * taum(ji,jj) * tmask(ji,jj,1) )
502            END DO
503         END DO
504      ELSE
505         zmxlm(:,:,1) = rn_mxl0
506      ENDIF
507      !
508      DO jk = 2, jpkm1              ! interior value : l=sqrt(2*e/n^2)
509         DO jj = 2, jpjm1
510            DO ji = fs_2, fs_jpim1   ! vector opt.
511               zrn2 = MAX( rn2(ji,jj,jk), rsmall )
512               zmxlm(ji,jj,jk) = MAX(  rmxl_min,  SQRT( 2._wp * en(ji,jj,jk) / zrn2 )  )
513            END DO
514         END DO
515      END DO
516      !
517      !                     !* Physical limits for the mixing length
518      !
519      zmxld(:,:, 1 ) = zmxlm(:,:,1)   ! surface set to the minimum value
520      zmxld(:,:,jpk) = rmxl_min       ! last level  set to the minimum value
521      !
522      SELECT CASE ( nn_mxl )
523      !
524 !!gm Not sure of that coding for ISF....
525      ! where wmask = 0 set zmxlm == p_e3w
526      CASE ( 0 )           ! bounded by the distance to surface and bottom
527         DO jk = 2, jpkm1
528            DO jj = 2, jpjm1
529               DO ji = fs_2, fs_jpim1   ! vector opt.
530                  zemxl = MIN( pdepw(ji,jj,jk) - pdepw(ji,jj,mikt(ji,jj)), zmxlm(ji,jj,jk),   &
531                  &            pdepw(ji,jj,mbkt(ji,jj)+1) - pdepw(ji,jj,jk) )
532                  ! wmask prevent zmxlm = 0 if jk = mikt(ji,jj)
533                  zmxlm(ji,jj,jk) = zemxl * wmask(ji,jj,jk) + MIN( zmxlm(ji,jj,jk) , p_e3w(ji,jj,jk) ) * (1 - wmask(ji,jj,jk))
534                  zmxld(ji,jj,jk) = zemxl * wmask(ji,jj,jk) + MIN( zmxlm(ji,jj,jk) , p_e3w(ji,jj,jk) ) * (1 - wmask(ji,jj,jk))
535               END DO
536            END DO
537         END DO
538         !
539      CASE ( 1 )           ! bounded by the vertical scale factor
540         DO jk = 2, jpkm1
541            DO jj = 2, jpjm1
542               DO ji = fs_2, fs_jpim1   ! vector opt.
543                  zemxl = MIN( p_e3w(ji,jj,jk), zmxlm(ji,jj,jk) )
544                  zmxlm(ji,jj,jk) = zemxl
545                  zmxld(ji,jj,jk) = zemxl
546               END DO
547            END DO
548         END DO
549         !
550      CASE ( 2 )           ! |dk[xml]| bounded by e3t :
551         DO jk = 2, jpkm1         ! from the surface to the bottom :
552            DO jj = 2, jpjm1
553               DO ji = fs_2, fs_jpim1   ! vector opt.
554                  zmxlm(ji,jj,jk) = MIN( zmxlm(ji,jj,jk-1) + p_e3t(ji,jj,jk-1), zmxlm(ji,jj,jk) )
555               END DO
556            END DO
557         END DO
558         DO jk = jpkm1, 2, -1     ! from the bottom to the surface :
559            DO jj = 2, jpjm1
560               DO ji = fs_2, fs_jpim1   ! vector opt.
561                  zemxl = MIN( zmxlm(ji,jj,jk+1) + p_e3t(ji,jj,jk+1), zmxlm(ji,jj,jk) )
562                  zmxlm(ji,jj,jk) = zemxl
563                  zmxld(ji,jj,jk) = zemxl
564               END DO
565            END DO
566         END DO
567         !
568      CASE ( 3 )           ! lup and ldown, |dk[xml]| bounded by e3t :
569         DO jk = 2, jpkm1         ! from the surface to the bottom : lup
570            DO jj = 2, jpjm1
571               DO ji = fs_2, fs_jpim1   ! vector opt.
572                  zmxld(ji,jj,jk) = MIN( zmxld(ji,jj,jk-1) + p_e3t(ji,jj,jk-1), zmxlm(ji,jj,jk) )
573               END DO
574            END DO
575         END DO
576         DO jk = jpkm1, 2, -1     ! from the bottom to the surface : ldown
577            DO jj = 2, jpjm1
578               DO ji = fs_2, fs_jpim1   ! vector opt.
579                  zmxlm(ji,jj,jk) = MIN( zmxlm(ji,jj,jk+1) + p_e3t(ji,jj,jk+1), zmxlm(ji,jj,jk) )
580               END DO
581            END DO
582         END DO
583         DO jk = 2, jpkm1
584            DO jj = 2, jpjm1
585               DO ji = fs_2, fs_jpim1   ! vector opt.
586                  zemlm = MIN ( zmxld(ji,jj,jk),  zmxlm(ji,jj,jk) )
587                  zemlp = SQRT( zmxld(ji,jj,jk) * zmxlm(ji,jj,jk) )
588                  zmxlm(ji,jj,jk) = zemlm
589                  zmxld(ji,jj,jk) = zemlp
590               END DO
591            END DO
592         END DO
593         !
594      END SELECT
595      !
596      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
597      !                     !  Vertical eddy viscosity and diffusivity  (avm and avt)
598      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
599      DO jk = 1, jpkm1            !* vertical eddy viscosity & diffivity at w-points
600         DO jj = 2, jpjm1
601            DO ji = fs_2, fs_jpim1   ! vector opt.
602               zsqen = SQRT( en(ji,jj,jk) )
603               zav   = rn_ediff * zmxlm(ji,jj,jk) * zsqen
604               p_avm(ji,jj,jk) = MAX( zav,                  avmb(jk) ) * wmask(ji,jj,jk)
605               p_avt(ji,jj,jk) = MAX( zav, avtb_2d(ji,jj) * avtb(jk) ) * wmask(ji,jj,jk)
606               dissl(ji,jj,jk) = zsqen / zmxld(ji,jj,jk)
607            END DO
608         END DO
609      END DO
610      !
611      !
612      IF( nn_pdl == 1 ) THEN      !* Prandtl number case: update avt
613         DO jk = 2, jpkm1
614            DO jj = 2, jpjm1
615               DO ji = fs_2, fs_jpim1   ! vector opt.
616                  p_avt(ji,jj,jk)   = MAX( apdlr(ji,jj,jk) * p_avt(ji,jj,jk), avtb_2d(ji,jj) * avtb(jk) ) * tmask(ji,jj,jk)
617              END DO
618            END DO
619         END DO
620      ENDIF
621      !
622      IF(ln_ctl) THEN
623         CALL prt_ctl( tab3d_1=en   , clinfo1=' tke  - e: ', tab3d_2=p_avt, clinfo2=' t: ', ovlap=1, kdim=jpk)
624         CALL prt_ctl( tab3d_1=p_avm, clinfo1=' tke  - m: ', ovlap=1, kdim=jpk )
625      ENDIF
626      !
627      IF( ln_timing )   CALL timing_stop('tke_avn')
628      !
629   END SUBROUTINE tke_avn
630
631
632   SUBROUTINE zdf_tke_init
633      !!----------------------------------------------------------------------
634      !!                  ***  ROUTINE zdf_tke_init  ***
635      !!                     
636      !! ** Purpose :   Initialization of the vertical eddy diffivity and
637      !!              viscosity when using a tke turbulent closure scheme
638      !!
639      !! ** Method  :   Read the namzdf_tke namelist and check the parameters
640      !!              called at the first timestep (nit000)
641      !!
642      !! ** input   :   Namlist namzdf_tke
643      !!
644      !! ** Action  :   Increase by 1 the nstop flag is setting problem encounter
645      !!----------------------------------------------------------------------
646      USE zdf_oce , ONLY : ln_zdfiwm   ! Internal Wave Mixing flag
647      !!
648      INTEGER ::   ji, jj, jk   ! dummy loop indices
649      INTEGER ::   ios
650      !!
651      NAMELIST/namzdf_tke/ rn_ediff, rn_ediss , rn_ebb , rn_emin  ,          &
652         &                 rn_emin0, rn_bshear, nn_mxl , ln_mxl0  ,          &
653         &                 rn_mxl0 , nn_pdl   , ln_drg , ln_lc    , rn_lc,   &
654         &                 nn_etau , nn_htau  , rn_efr   
655      !!----------------------------------------------------------------------
656      !
657      REWIND( numnam_ref )              ! Namelist namzdf_tke in reference namelist : Turbulent Kinetic Energy
658      READ  ( numnam_ref, namzdf_tke, IOSTAT = ios, ERR = 901)
659901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_tke in reference namelist', lwp )
660
661      REWIND( numnam_cfg )              ! Namelist namzdf_tke in configuration namelist : Turbulent Kinetic Energy
662      READ  ( numnam_cfg, namzdf_tke, IOSTAT = ios, ERR = 902 )
663902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_tke in configuration namelist', lwp )
664      IF(lwm) WRITE ( numond, namzdf_tke )
665      !
666      ri_cri   = 2._wp    / ( 2._wp + rn_ediss / rn_ediff )   ! resulting critical Richardson number
667      !
668      IF(lwp) THEN                    !* Control print
669         WRITE(numout,*)
670         WRITE(numout,*) 'zdf_tke_init : tke turbulent closure scheme - initialisation'
671         WRITE(numout,*) '~~~~~~~~~~~~'
672         WRITE(numout,*) '   Namelist namzdf_tke : set tke mixing parameters'
673         WRITE(numout,*) '      coef. to compute avt                        rn_ediff  = ', rn_ediff
674         WRITE(numout,*) '      Kolmogoroff dissipation coef.               rn_ediss  = ', rn_ediss
675         WRITE(numout,*) '      tke surface input coef.                     rn_ebb    = ', rn_ebb
676         WRITE(numout,*) '      minimum value of tke                        rn_emin   = ', rn_emin
677         WRITE(numout,*) '      surface minimum value of tke                rn_emin0  = ', rn_emin0
678         WRITE(numout,*) '      prandl number flag                          nn_pdl    = ', nn_pdl
679         WRITE(numout,*) '      background shear (>0)                       rn_bshear = ', rn_bshear
680         WRITE(numout,*) '      mixing length type                          nn_mxl    = ', nn_mxl
681         WRITE(numout,*) '         surface mixing length = F(stress) or not    ln_mxl0   = ', ln_mxl0
682         WRITE(numout,*) '         surface  mixing length minimum value        rn_mxl0   = ', rn_mxl0
683         WRITE(numout,*) '      top/bottom friction forcing flag            ln_drg    = ', ln_drg
684         WRITE(numout,*) '      Langmuir cells parametrization              ln_lc     = ', ln_lc
685         WRITE(numout,*) '         coef to compute vertical velocity of LC     rn_lc  = ', rn_lc
686         WRITE(numout,*) '      test param. to add tke induced by wind      nn_etau   = ', nn_etau
687         WRITE(numout,*) '          type of tke penetration profile            nn_htau   = ', nn_htau
688         WRITE(numout,*) '          fraction of TKE that penetrates            rn_efr    = ', rn_efr
689         WRITE(numout,*)
690         IF( ln_drg ) THEN
691            WRITE(numout,*) '   Namelist namdrg_top/_bot:   used values:'
692            WRITE(numout,*) '      top    ocean cavity roughness (m)          rn_z0(_top)= ', r_z0_top
693            WRITE(numout,*) '      Bottom seafloor     roughness (m)          rn_z0(_bot)= ', r_z0_bot
694         ENDIF
695         WRITE(numout,*)
696         WRITE(numout,*)
697         WRITE(numout,*) '   ==>> critical Richardson nb with your parameters  ri_cri = ', ri_cri
698         WRITE(numout,*)
699      ENDIF
700      !
701      IF( ln_zdfiwm ) THEN          ! Internal wave-driven mixing
702         rn_emin  = 1.e-10_wp             ! specific values of rn_emin & rmxl_min are used
703         rmxl_min = 1.e-03_wp             ! associated avt minimum = molecular salt diffusivity (10^-9 m2/s)
704         IF(lwp) WRITE(numout,*) '      Internal wave-driven mixing case:   force   rn_emin = 1.e-10 and rmxl_min = 1.e-3 '
705      ELSE                          ! standard case : associated avt minimum = molecular viscosity (10^-6 m2/s)
706         rmxl_min = 1.e-6_wp / ( rn_ediff * SQRT( rn_emin ) )    ! resulting minimum length to recover molecular viscosity
707         IF(lwp) WRITE(numout,*) '      minimum mixing length with your parameters rmxl_min = ', rmxl_min
708      ENDIF
709      !
710      !                              ! allocate tke arrays
711      IF( zdf_tke_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'zdf_tke_init : unable to allocate arrays' )
712      !
713      !                               !* Check of some namelist values
714      IF( nn_mxl  < 0   .OR.  nn_mxl  > 3 )   CALL ctl_stop( 'bad flag: nn_mxl is  0, 1 or 2 ' )
715      IF( nn_pdl  < 0   .OR.  nn_pdl  > 1 )   CALL ctl_stop( 'bad flag: nn_pdl is  0 or 1    ' )
716      IF( nn_htau < 0   .OR.  nn_htau > 1 )   CALL ctl_stop( 'bad flag: nn_htau is 0, 1 or 2 ' )
717      IF( nn_etau == 3 .AND. .NOT. ln_cpl )   CALL ctl_stop( 'nn_etau == 3 : HF taum only known in coupled mode' )
718      !
719      IF( ln_mxl0 ) THEN
720         IF(lwp) WRITE(numout,*) '   use a surface mixing length = F(stress) :   set rn_mxl0 = rmxl_min'
721         rn_mxl0 = rmxl_min
722      ENDIF
723     
724      IF( nn_etau == 2  )   CALL zdf_mxl( nit000 )      ! Initialization of nmln
725
726      !                               !* depth of penetration of surface tke
727      IF( nn_etau /= 0 ) THEN     
728         SELECT CASE( nn_htau )             ! Choice of the depth of penetration
729         CASE( 0 )                                 ! constant depth penetration (here 10 meters)
730            htau(:,:) = 10._wp
731         CASE( 1 )                                 ! F(latitude) : 0.5m to 30m poleward of 40 degrees
732            htau(:,:) = MAX(  0.5_wp, MIN( 30._wp, 45._wp* ABS( SIN( rpi/180._wp * gphit(:,:) ) ) )   )           
733         END SELECT
734      ENDIF
735      !                                !* read or initialize all required files
736      CALL tke_rst( nit000, 'READ' )      ! (en, avt_k, avm_k, dissl)
737      !
738   END SUBROUTINE zdf_tke_init
739
740
741   SUBROUTINE tke_rst( kt, cdrw )
742      !!---------------------------------------------------------------------
743      !!                   ***  ROUTINE tke_rst  ***
744      !!                     
745      !! ** Purpose :   Read or write TKE file (en) in restart file
746      !!
747      !! ** Method  :   use of IOM library
748      !!                if the restart does not contain TKE, en is either
749      !!                set to rn_emin or recomputed
750      !!----------------------------------------------------------------------
751      USE zdf_oce , ONLY : en, avt_k, avm_k   ! ocean vertical physics
752      !!
753      INTEGER         , INTENT(in) ::   kt     ! ocean time-step
754      CHARACTER(len=*), INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
755      !
756      INTEGER ::   jit, jk              ! dummy loop indices
757      INTEGER ::   id1, id2, id3, id4   ! local integers
758      !!----------------------------------------------------------------------
759      !
760      IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise
761         !                                   ! ---------------
762         IF( ln_rstart ) THEN                   !* Read the restart file
763            id1 = iom_varid( numror, 'en'   , ldstop = .FALSE. )
764            id2 = iom_varid( numror, 'avt_k', ldstop = .FALSE. )
765            id3 = iom_varid( numror, 'avm_k', ldstop = .FALSE. )
766            id4 = iom_varid( numror, 'dissl', ldstop = .FALSE. )
767            !
768            IF( MIN( id1, id2, id3, id4 ) > 0 ) THEN      ! fields exist
769               CALL iom_get( numror, jpdom_autoglo, 'en', en )
770               CALL iom_get( numror, jpdom_autoglo, 'avt_k', avt_k )
771               CALL iom_get( numror, jpdom_autoglo, 'avm_k', avm_k )
772               CALL iom_get( numror, jpdom_autoglo, 'dissl', dissl )
773            ELSE                                          ! start TKE from rest
774               IF(lwp) WRITE(numout,*) '   ==>>   previous run without TKE scheme, set en to background values'
775               en   (:,:,:) = rn_emin * wmask(:,:,:)
776               dissl(:,:,:) = 1.e-12_wp
777               ! avt_k, avm_k already set to the background value in zdf_phy_init
778            ENDIF
779         ELSE                                   !* Start from rest
780            IF(lwp) WRITE(numout,*) '   ==>>   start from rest: set en to the background value'
781            en   (:,:,:) = rn_emin * wmask(:,:,:)
782            dissl(:,:,:) = 1.e-12_wp
783            ! avt_k, avm_k already set to the background value in zdf_phy_init
784         ENDIF
785         !
786      ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
787         !                                   ! -------------------
788         IF(lwp) WRITE(numout,*) '---- tke-rst ----'
789         CALL iom_rstput( kt, nitrst, numrow, 'en'   , en    )
790         CALL iom_rstput( kt, nitrst, numrow, 'avt_k', avt_k )
791         CALL iom_rstput( kt, nitrst, numrow, 'avm_k', avm_k )
792         CALL iom_rstput( kt, nitrst, numrow, 'dissl', dissl )
793         !
794      ENDIF
795      !
796   END SUBROUTINE tke_rst
797
798   !!======================================================================
799END MODULE zdftke
Note: See TracBrowser for help on using the repository browser.