ldfslp.F90 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  1. MODULE ldfslp
  2. !!======================================================================
  3. !! *** MODULE ldfslp ***
  4. !! Ocean physics: slopes of neutral surfaces
  5. !!======================================================================
  6. !! History : OPA ! 1994-12 (G. Madec, M. Imbard) Original code
  7. !! 8.0 ! 1997-06 (G. Madec) optimization, lbc
  8. !! 8.1 ! 1999-10 (A. Jouzeau) NEW profile in the mixed layer
  9. !! NEMO 1.0 ! 2002-10 (G. Madec) Free form, F90
  10. !! - ! 2005-10 (A. Beckmann) correction for s-coordinates
  11. !! 3.3 ! 2010-10 (G. Nurser, C. Harris, G. Madec) add Griffies operator
  12. !! - ! 2010-11 (F. Dupond, G. Madec) bug correction in slopes just below the ML
  13. !!----------------------------------------------------------------------
  14. #if defined key_ldfslp || defined key_esopa
  15. !!----------------------------------------------------------------------
  16. !! 'key_ldfslp' Rotation of lateral mixing tensor
  17. !!----------------------------------------------------------------------
  18. !! ldf_slp_grif : calculates the triads of isoneutral slopes (Griffies operator)
  19. !! ldf_slp : calculates the slopes of neutral surface (Madec operator)
  20. !! ldf_slp_mxl : calculates the slopes at the base of the mixed layer (Madec operator)
  21. !! ldf_slp_init : initialization of the slopes computation
  22. !!----------------------------------------------------------------------
  23. USE oce ! ocean dynamics and tracers
  24. USE dom_oce ! ocean space and time domain
  25. USE ldftra_oce ! lateral diffusion: traceur
  26. USE ldfdyn_oce ! lateral diffusion: dynamics
  27. USE phycst ! physical constants
  28. USE zdfmxl ! mixed layer depth
  29. USE eosbn2 ! equation of states
  30. !
  31. USE in_out_manager ! I/O manager
  32. USE lbclnk ! ocean lateral boundary conditions (or mpp link)
  33. USE prtctl ! Print control
  34. USE wrk_nemo ! work arrays
  35. USE timing ! Timing
  36. USE lib_fortran ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
  37. IMPLICIT NONE
  38. PRIVATE
  39. PUBLIC ldf_slp ! routine called by step.F90
  40. PUBLIC ldf_slp_grif ! routine called by step.F90
  41. PUBLIC ldf_slp_init ! routine called by opa.F90
  42. LOGICAL , PUBLIC, PARAMETER :: lk_ldfslp = .TRUE. !: slopes flag
  43. ! !! Madec operator
  44. ! Arrays allocated in ldf_slp_init() routine once we know whether we're using the Griffies or Madec operator
  45. REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: uslp, wslpi !: i_slope at U- and W-points
  46. REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: vslp, wslpj !: j-slope at V- and W-points
  47. ! !! Griffies operator
  48. REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: wslp2 !: wslp**2 from Griffies quarter cells
  49. REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:,:) :: triadi_g, triadj_g !: skew flux slopes relative to geopotentials
  50. REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:,:) :: triadi , triadj !: isoneutral slopes relative to model-coordinate
  51. ! !! Madec operator
  52. ! Arrays allocated in ldf_slp_init() routine once we know whether we're using the Griffies or Madec operator
  53. REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: omlmask ! mask of the surface mixed layer at T-pt
  54. REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) :: uslpml, wslpiml ! i_slope at U- and W-points just below the mixed layer
  55. REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) :: vslpml, wslpjml ! j_slope at V- and W-points just below the mixed layer
  56. REAL(wp) :: repsln = 1.e-25_wp ! tiny value used as minium of di(rho), dj(rho) and dk(rho)
  57. !! * Substitutions
  58. # include "domzgr_substitute.h90"
  59. # include "ldftra_substitute.h90"
  60. # include "ldfeiv_substitute.h90"
  61. # include "vectopt_loop_substitute.h90"
  62. !!----------------------------------------------------------------------
  63. !! NEMO/OPA 4.0 , NEMO Consortium (2011)
  64. !! $Id: ldfslp.F90 4990 2014-12-15 16:42:49Z timgraham $
  65. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  66. !!----------------------------------------------------------------------
  67. CONTAINS
  68. SUBROUTINE ldf_slp( kt, prd, pn2 )
  69. !!----------------------------------------------------------------------
  70. !! *** ROUTINE ldf_slp ***
  71. !!
  72. !! ** Purpose : Compute the slopes of neutral surface (slope of isopycnal
  73. !! surfaces referenced locally) (ln_traldf_iso=T).
  74. !!
  75. !! ** Method : The slope in the i-direction is computed at U- and
  76. !! W-points (uslp, wslpi) and the slope in the j-direction is
  77. !! computed at V- and W-points (vslp, wslpj).
  78. !! They are bounded by 1/100 over the whole ocean, and within the
  79. !! surface layer they are bounded by the distance to the surface
  80. !! ( slope<= depth/l where l is the length scale of horizontal
  81. !! diffusion (here, aht=2000m2/s ==> l=20km with a typical velocity
  82. !! of 10cm/s)
  83. !! A horizontal shapiro filter is applied to the slopes
  84. !! ln_sco=T, s-coordinate, add to the previously computed slopes
  85. !! the slope of the model level surface.
  86. !! macro-tasked on horizontal slab (jk-loop) (2, jpk-1)
  87. !! [slopes already set to zero at level 1, and to zero or the ocean
  88. !! bottom slope (ln_sco=T) at level jpk in inildf]
  89. !!
  90. !! ** Action : - uslp, wslpi, and vslp, wslpj, the i- and j-slopes
  91. !! of now neutral surfaces at u-, w- and v- w-points, resp.
  92. !!----------------------------------------------------------------------
  93. INTEGER , INTENT(in) :: kt ! ocean time-step index
  94. REAL(wp), INTENT(in), DIMENSION(:,:,:) :: prd ! in situ density
  95. REAL(wp), INTENT(in), DIMENSION(:,:,:) :: pn2 ! Brunt-Vaisala frequency (locally ref.)
  96. !!
  97. INTEGER :: ji , jj , jk ! dummy loop indices
  98. INTEGER :: ii0, ii1, iku ! temporary integer
  99. INTEGER :: ij0, ij1, ikv ! temporary integer
  100. REAL(wp) :: zeps, zm1_g, zm1_2g, z1_16, zcofw ! local scalars
  101. REAL(wp) :: zci, zfi, zau, zbu, zai, zbi ! - -
  102. REAL(wp) :: zcj, zfj, zav, zbv, zaj, zbj ! - -
  103. REAL(wp) :: zck, zfk, zbw ! - -
  104. REAL(wp) :: zdepv, zdepu ! - -
  105. REAL(wp), POINTER, DIMENSION(:,:,:) :: zwz, zww
  106. REAL(wp), POINTER, DIMENSION(:,:,:) :: zdzr
  107. REAL(wp), POINTER, DIMENSION(:,:,:) :: zgru, zgrv
  108. REAL(wp), POINTER, DIMENSION(:,: ) :: zhmlpu, zhmlpv
  109. !!----------------------------------------------------------------------
  110. !
  111. IF( nn_timing == 1 ) CALL timing_start('ldf_slp')
  112. !
  113. CALL wrk_alloc( jpi,jpj,jpk, zwz, zww, zdzr, zgru, zgrv )
  114. CALL wrk_alloc( jpi,jpj, zhmlpu, zhmlpv )
  115. IF ( ln_traldf_iso .OR. ln_dynldf_iso ) THEN
  116. zeps = 1.e-20_wp !== Local constant initialization ==!
  117. z1_16 = 1.0_wp / 16._wp
  118. zm1_g = -1.0_wp / grav
  119. zm1_2g = -0.5_wp / grav
  120. !
  121. zww(:,:,:) = 0._wp
  122. zwz(:,:,:) = 0._wp
  123. !
  124. DO jk = 1, jpk !== i- & j-gradient of density ==!
  125. DO jj = 1, jpjm1
  126. DO ji = 1, fs_jpim1 ! vector opt.
  127. zgru(ji,jj,jk) = umask(ji,jj,jk) * ( prd(ji+1,jj ,jk) - prd(ji,jj,jk) )
  128. zgrv(ji,jj,jk) = vmask(ji,jj,jk) * ( prd(ji ,jj+1,jk) - prd(ji,jj,jk) )
  129. END DO
  130. END DO
  131. END DO
  132. IF( ln_zps ) THEN ! partial steps correction at the bottom ocean level
  133. DO jj = 1, jpjm1
  134. DO ji = 1, jpim1
  135. zgru(ji,jj,mbku(ji,jj)) = gru(ji,jj)
  136. zgrv(ji,jj,mbkv(ji,jj)) = grv(ji,jj)
  137. END DO
  138. END DO
  139. ENDIF
  140. IF( ln_zps .AND. ln_isfcav ) THEN ! partial steps correction at the bottom ocean level
  141. DO jj = 1, jpjm1
  142. DO ji = 1, jpim1
  143. IF ( miku(ji,jj) > 1 ) zgru(ji,jj,miku(ji,jj)) = grui(ji,jj)
  144. IF ( mikv(ji,jj) > 1 ) zgrv(ji,jj,mikv(ji,jj)) = grvi(ji,jj)
  145. END DO
  146. END DO
  147. ENDIF
  148. !
  149. !== Local vertical density gradient at T-point == ! (evaluated from N^2)
  150. ! interior value
  151. DO jk = 2, jpkm1
  152. ! ! zdzr = d/dz(prd)= - ( prd ) / grav * mk(pn2) -- at t point
  153. ! ! trick: tmask(ik ) = 0 => all pn2 = 0 => zdzr = 0
  154. ! ! else tmask(ik+1) = 0 => pn2(ik+1) = 0 => zdzr divides by 1
  155. ! ! umask(ik+1) /= 0 => all pn2 /= 0 => zdzr divides by 2
  156. ! ! NB: 1/(tmask+1) = (1-.5*tmask) substitute a / by a * ==> faster
  157. zdzr(:,:,jk) = zm1_g * ( prd(:,:,jk) + 1._wp ) &
  158. & * ( pn2(:,:,jk) + pn2(:,:,jk+1) ) * ( 1._wp - 0.5_wp * tmask(:,:,jk+1) )
  159. END DO
  160. ! surface initialisation
  161. zdzr(:,:,1) = 0._wp
  162. IF ( ln_isfcav ) THEN
  163. ! if isf need to overwrite the interior value at at the first ocean point
  164. DO jj = 1, jpjm1
  165. DO ji = 1, jpim1
  166. zdzr(ji,jj,1:mikt(ji,jj)) = 0._wp
  167. END DO
  168. END DO
  169. END IF
  170. !
  171. ! !== Slopes just below the mixed layer ==!
  172. CALL ldf_slp_mxl( prd, pn2, zgru, zgrv, zdzr ) ! output: uslpml, vslpml, wslpiml, wslpjml
  173. ! I. slopes at u and v point | uslp = d/di( prd ) / d/dz( prd )
  174. ! =========================== | vslp = d/dj( prd ) / d/dz( prd )
  175. !
  176. IF ( ln_isfcav ) THEN
  177. DO jj = 2, jpjm1
  178. DO ji = fs_2, fs_jpim1 ! vector opt.
  179. zhmlpu(ji,jj) = ( MAX(hmlpt(ji,jj) , hmlpt (ji+1,jj ), 5._wp) &
  180. & - MAX(risfdep(ji,jj), risfdep(ji+1,jj ) ) )
  181. zhmlpv(ji,jj) = ( MAX(hmlpt (ji,jj), hmlpt (ji ,jj+1), 5._wp) &
  182. & - MAX(risfdep(ji,jj), risfdep(ji ,jj+1) ) )
  183. ENDDO
  184. ENDDO
  185. ELSE
  186. DO jj = 2, jpjm1
  187. DO ji = fs_2, fs_jpim1 ! vector opt.
  188. zhmlpu(ji,jj) = MAX(hmlpt(ji,jj), hmlpt(ji+1,jj ), 5._wp)
  189. zhmlpv(ji,jj) = MAX(hmlpt(ji,jj), hmlpt(ji ,jj+1), 5._wp)
  190. ENDDO
  191. ENDDO
  192. END IF
  193. DO jk = 2, jpkm1 !* Slopes at u and v points
  194. DO jj = 2, jpjm1
  195. DO ji = fs_2, fs_jpim1 ! vector opt.
  196. ! ! horizontal and vertical density gradient at u- and v-points
  197. zau = zgru(ji,jj,jk) / e1u(ji,jj)
  198. zav = zgrv(ji,jj,jk) / e2v(ji,jj)
  199. zbu = 0.5_wp * ( zdzr(ji,jj,jk) + zdzr(ji+1,jj ,jk) )
  200. zbv = 0.5_wp * ( zdzr(ji,jj,jk) + zdzr(ji ,jj+1,jk) )
  201. ! ! bound the slopes: abs(zw.)<= 1/100 and zb..<0
  202. ! ! + kxz max= ah slope max =< e1 e3 /(pi**2 2 dt)
  203. zbu = MIN( zbu, -100._wp* ABS( zau ) , -7.e+3_wp/fse3u(ji,jj,jk)* ABS( zau ) )
  204. zbv = MIN( zbv, -100._wp* ABS( zav ) , -7.e+3_wp/fse3v(ji,jj,jk)* ABS( zav ) )
  205. ! ! uslp and vslp output in zwz and zww, resp.
  206. zfi = MAX( omlmask(ji,jj,jk), omlmask(ji+1,jj ,jk) )
  207. zfj = MAX( omlmask(ji,jj,jk), omlmask(ji ,jj+1,jk) )
  208. ! thickness of water column between surface and level k at u/v point
  209. zdepu = 0.5_wp * ( ( fsdept(ji,jj,jk) + fsdept(ji+1,jj ,jk) ) &
  210. - 2 * MAX( risfdep(ji,jj), risfdep(ji+1,jj ) ) - fse3u(ji,jj,miku(ji,jj)) )
  211. zdepv = 0.5_wp * ( ( fsdept(ji,jj,jk) + fsdept(ji ,jj+1,jk) ) &
  212. - 2 * MAX( risfdep(ji,jj), risfdep(ji ,jj+1) ) - fse3v(ji,jj,mikv(ji,jj)) )
  213. !
  214. zwz(ji,jj,jk) = ( 1. - zfi) * zau / ( zbu - zeps ) &
  215. & + zfi * uslpml(ji,jj) * zdepu / zhmlpu(ji,jj)
  216. zwz(ji,jj,jk) = zwz(ji,jj,jk) * wumask(ji,jj,jk)
  217. zww(ji,jj,jk) = ( 1. - zfj) * zav / ( zbv - zeps ) &
  218. & + zfj * vslpml(ji,jj) * zdepv / zhmlpv(ji,jj)
  219. zww(ji,jj,jk) = zww(ji,jj,jk) * wvmask(ji,jj,jk)
  220. !!gm modif to suppress omlmask.... (as in Griffies case)
  221. ! ! ! jk must be >= ML level for zf=1. otherwise zf=0.
  222. ! zfi = REAL( 1 - 1/(1 + jk / MAX( nmln(ji+1,jj), nmln(ji,jj) ) ), wp )
  223. ! zfj = REAL( 1 - 1/(1 + jk / MAX( nmln(ji,jj+1), nmln(ji,jj) ) ), wp )
  224. ! zci = 0.5 * ( fsdept(ji+1,jj,jk)+fsdept(ji,jj,jk) ) / MAX( hmlpt(ji,jj), hmlpt(ji+1,jj), 10. ) )
  225. ! zcj = 0.5 * ( fsdept(ji,jj+1,jk)+fsdept(ji,jj,jk) ) / MAX( hmlpt(ji,jj), hmlpt(ji,jj+1), 10. ) )
  226. ! zwz(ji,jj,jk) = ( zfi * zai / ( zbi - zeps ) + ( 1._wp - zfi ) * wslpiml(ji,jj) * zci ) * tmask(ji,jj,jk)
  227. ! zww(ji,jj,jk) = ( zfj * zaj / ( zbj - zeps ) + ( 1._wp - zfj ) * wslpjml(ji,jj) * zcj ) * tmask(ji,jj,jk)
  228. !!gm end modif
  229. END DO
  230. END DO
  231. END DO
  232. CALL lbc_lnk( zwz, 'U', -1. ) ; CALL lbc_lnk( zww, 'V', -1. ) ! lateral boundary conditions
  233. !
  234. ! !* horizontal Shapiro filter
  235. DO jk = 2, jpkm1
  236. DO jj = 2, jpjm1, MAX(1, jpj-3) ! rows jj=2 and =jpjm1 only
  237. DO ji = 2, jpim1
  238. uslp(ji,jj,jk) = z1_16 * ( zwz(ji-1,jj-1,jk) + zwz(ji+1,jj-1,jk) &
  239. & + zwz(ji-1,jj+1,jk) + zwz(ji+1,jj+1,jk) &
  240. & + 2.*( zwz(ji ,jj-1,jk) + zwz(ji-1,jj ,jk) &
  241. & + zwz(ji+1,jj ,jk) + zwz(ji ,jj+1,jk) ) &
  242. & + 4.* zwz(ji ,jj ,jk) )
  243. vslp(ji,jj,jk) = z1_16 * ( zww(ji-1,jj-1,jk) + zww(ji+1,jj-1,jk) &
  244. & + zww(ji-1,jj+1,jk) + zww(ji+1,jj+1,jk) &
  245. & + 2.*( zww(ji ,jj-1,jk) + zww(ji-1,jj ,jk) &
  246. & + zww(ji+1,jj ,jk) + zww(ji ,jj+1,jk) ) &
  247. & + 4.* zww(ji,jj ,jk) )
  248. END DO
  249. END DO
  250. DO jj = 3, jpj-2 ! other rows
  251. DO ji = fs_2, fs_jpim1 ! vector opt.
  252. uslp(ji,jj,jk) = z1_16 * ( zwz(ji-1,jj-1,jk) + zwz(ji+1,jj-1,jk) &
  253. & + zwz(ji-1,jj+1,jk) + zwz(ji+1,jj+1,jk) &
  254. & + 2.*( zwz(ji ,jj-1,jk) + zwz(ji-1,jj ,jk) &
  255. & + zwz(ji+1,jj ,jk) + zwz(ji ,jj+1,jk) ) &
  256. & + 4.* zwz(ji ,jj ,jk) )
  257. vslp(ji,jj,jk) = z1_16 * ( zww(ji-1,jj-1,jk) + zww(ji+1,jj-1,jk) &
  258. & + zww(ji-1,jj+1,jk) + zww(ji+1,jj+1,jk) &
  259. & + 2.*( zww(ji ,jj-1,jk) + zww(ji-1,jj ,jk) &
  260. & + zww(ji+1,jj ,jk) + zww(ji ,jj+1,jk) ) &
  261. & + 4.* zww(ji,jj ,jk) )
  262. END DO
  263. END DO
  264. ! !* decrease along coastal boundaries
  265. DO jj = 2, jpjm1
  266. DO ji = fs_2, fs_jpim1 ! vector opt.
  267. uslp(ji,jj,jk) = uslp(ji,jj,jk) * ( umask(ji,jj+1,jk) + umask(ji,jj-1,jk ) ) * 0.5_wp &
  268. & * ( umask(ji,jj ,jk) + umask(ji,jj ,jk+1) ) * 0.5_wp &
  269. & * umask(ji,jj,jk-1)
  270. vslp(ji,jj,jk) = vslp(ji,jj,jk) * ( vmask(ji+1,jj,jk) + vmask(ji-1,jj,jk ) ) * 0.5_wp &
  271. & * ( vmask(ji ,jj,jk) + vmask(ji ,jj,jk+1) ) * 0.5_wp &
  272. & * vmask(ji,jj,jk-1)
  273. END DO
  274. END DO
  275. END DO
  276. ! II. slopes at w point | wslpi = mij( d/di( prd ) / d/dz( prd )
  277. ! =========================== | wslpj = mij( d/dj( prd ) / d/dz( prd )
  278. !
  279. DO jk = 2, jpkm1
  280. DO jj = 2, jpjm1
  281. DO ji = fs_2, fs_jpim1 ! vector opt.
  282. ! !* Local vertical density gradient evaluated from N^2
  283. zbw = zm1_2g * pn2 (ji,jj,jk) * ( prd (ji,jj,jk) + prd (ji,jj,jk-1) + 2. ) * wmask(ji,jj,jk)
  284. ! !* Slopes at w point
  285. ! ! i- & j-gradient of density at w-points
  286. zci = MAX( umask(ji-1,jj,jk ) + umask(ji,jj,jk ) &
  287. & + umask(ji-1,jj,jk-1) + umask(ji,jj,jk-1) , zeps ) * e1t(ji,jj)
  288. zcj = MAX( vmask(ji,jj-1,jk ) + vmask(ji,jj,jk-1) &
  289. & + vmask(ji,jj-1,jk-1) + vmask(ji,jj,jk ) , zeps ) * e2t(ji,jj)
  290. zai = ( zgru (ji-1,jj,jk ) + zgru (ji,jj,jk-1) &
  291. & + zgru (ji-1,jj,jk-1) + zgru (ji,jj,jk ) ) / zci
  292. zaj = ( zgrv (ji,jj-1,jk ) + zgrv (ji,jj,jk-1) &
  293. & + zgrv (ji,jj-1,jk-1) + zgrv (ji,jj,jk ) ) / zcj
  294. ! ! bound the slopes: abs(zw.)<= 1/100 and zb..<0.
  295. ! ! + kxz max= ah slope max =< e1 e3 /(pi**2 2 dt)
  296. zbi = MIN( zbw ,- 100._wp* ABS( zai ) , -7.e+3_wp/fse3w(ji,jj,jk)* ABS( zai ) )
  297. zbj = MIN( zbw , -100._wp* ABS( zaj ) , -7.e+3_wp/fse3w(ji,jj,jk)* ABS( zaj ) )
  298. ! ! wslpi and wslpj with ML flattening (output in zwz and zww, resp.)
  299. zfk = MAX( omlmask(ji,jj,jk), omlmask(ji,jj,jk-1) ) ! zfk=1 in the ML otherwise zfk=0
  300. zck = ( fsdepw(ji,jj,jk) - fsdepw(ji,jj,mikt(ji,jj) ) ) / MAX( hmlp(ji,jj), 10._wp )
  301. zwz(ji,jj,jk) = ( zai / ( zbi - zeps ) * ( 1._wp - zfk ) &
  302. & + zck * wslpiml(ji,jj) * zfk ) * wmask(ji,jj,jk)
  303. zww(ji,jj,jk) = ( zaj / ( zbj - zeps ) * ( 1._wp - zfk ) &
  304. & + zck * wslpjml(ji,jj) * zfk ) * wmask(ji,jj,jk)
  305. !!gm modif to suppress omlmask.... (as in Griffies operator)
  306. ! ! ! jk must be >= ML level for zfk=1. otherwise zfk=0.
  307. ! zfk = REAL( 1 - 1/(1 + jk / nmln(ji+1,jj)), wp )
  308. ! zck = fsdepw(ji,jj,jk) / MAX( hmlp(ji,jj), 10. )
  309. ! zwz(ji,jj,jk) = ( zfk * zai / ( zbi - zeps ) + ( 1._wp - zfk ) * wslpiml(ji,jj) * zck ) * tmask(ji,jj,jk)
  310. ! zww(ji,jj,jk) = ( zfk * zaj / ( zbj - zeps ) + ( 1._wp - zfk ) * wslpjml(ji,jj) * zck ) * tmask(ji,jj,jk)
  311. !!gm end modif
  312. END DO
  313. END DO
  314. END DO
  315. CALL lbc_lnk( zwz, 'T', -1. ) ; CALL lbc_lnk( zww, 'T', -1. ) ! lateral boundary conditions
  316. !
  317. ! !* horizontal Shapiro filter
  318. DO jk = 2, jpkm1
  319. DO jj = 2, jpjm1, MAX(1, jpj-3) ! rows jj=2 and =jpjm1 only
  320. DO ji = 2, jpim1
  321. zcofw = tmask(ji,jj,jk) * z1_16
  322. wslpi(ji,jj,jk) = ( zwz(ji-1,jj-1,jk) + zwz(ji+1,jj-1,jk) &
  323. & + zwz(ji-1,jj+1,jk) + zwz(ji+1,jj+1,jk) &
  324. & + 2.*( zwz(ji ,jj-1,jk) + zwz(ji-1,jj ,jk) &
  325. & + zwz(ji+1,jj ,jk) + zwz(ji ,jj+1,jk) ) &
  326. & + 4.* zwz(ji ,jj ,jk) ) * zcofw
  327. wslpj(ji,jj,jk) = ( zww(ji-1,jj-1,jk) + zww(ji+1,jj-1,jk) &
  328. & + zww(ji-1,jj+1,jk) + zww(ji+1,jj+1,jk) &
  329. & + 2.*( zww(ji ,jj-1,jk) + zww(ji-1,jj ,jk) &
  330. & + zww(ji+1,jj ,jk) + zww(ji ,jj+1,jk) ) &
  331. & + 4.* zww(ji ,jj ,jk) ) * zcofw
  332. END DO
  333. END DO
  334. DO jj = 3, jpj-2 ! other rows
  335. DO ji = fs_2, fs_jpim1 ! vector opt.
  336. zcofw = tmask(ji,jj,jk) * z1_16
  337. wslpi(ji,jj,jk) = ( zwz(ji-1,jj-1,jk) + zwz(ji+1,jj-1,jk) &
  338. & + zwz(ji-1,jj+1,jk) + zwz(ji+1,jj+1,jk) &
  339. & + 2.*( zwz(ji ,jj-1,jk) + zwz(ji-1,jj ,jk) &
  340. & + zwz(ji+1,jj ,jk) + zwz(ji ,jj+1,jk) ) &
  341. & + 4.* zwz(ji ,jj ,jk) ) * zcofw
  342. wslpj(ji,jj,jk) = ( zww(ji-1,jj-1,jk) + zww(ji+1,jj-1,jk) &
  343. & + zww(ji-1,jj+1,jk) + zww(ji+1,jj+1,jk) &
  344. & + 2.*( zww(ji ,jj-1,jk) + zww(ji-1,jj ,jk) &
  345. & + zww(ji+1,jj ,jk) + zww(ji ,jj+1,jk) ) &
  346. & + 4.* zww(ji ,jj ,jk) ) * zcofw
  347. END DO
  348. END DO
  349. ! !* decrease along coastal boundaries
  350. DO jj = 2, jpjm1
  351. DO ji = fs_2, fs_jpim1 ! vector opt.
  352. zck = ( umask(ji,jj,jk) + umask(ji-1,jj,jk) ) &
  353. & * ( vmask(ji,jj,jk) + vmask(ji,jj-1,jk) ) * 0.25
  354. wslpi(ji,jj,jk) = wslpi(ji,jj,jk) * zck * wmask(ji,jj,jk)
  355. wslpj(ji,jj,jk) = wslpj(ji,jj,jk) * zck * wmask(ji,jj,jk)
  356. END DO
  357. END DO
  358. END DO
  359. ! III. Specific grid points
  360. ! ===========================
  361. !
  362. IF( cp_cfg == "orca" .AND. jp_cfg == 4 ) THEN ! ORCA_R4 configuration: horizontal diffusion in specific area
  363. ! ! Gibraltar Strait
  364. ij0 = 50 ; ij1 = 53
  365. ii0 = 69 ; ii1 = 71 ; uslp ( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , : ) = 0._wp
  366. ij0 = 51 ; ij1 = 53
  367. ii0 = 68 ; ii1 = 71 ; vslp ( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , : ) = 0._wp
  368. ii0 = 69 ; ii1 = 71 ; wslpi( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , : ) = 0._wp
  369. ii0 = 69 ; ii1 = 71 ; wslpj( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , : ) = 0._wp
  370. !
  371. ! ! Mediterrannean Sea
  372. ij0 = 49 ; ij1 = 56
  373. ii0 = 71 ; ii1 = 90 ; uslp ( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , : ) = 0._wp
  374. ij0 = 50 ; ij1 = 56
  375. ii0 = 70 ; ii1 = 90 ; vslp ( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , : ) = 0._wp
  376. ii0 = 71 ; ii1 = 90 ; wslpi( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , : ) = 0._wp
  377. ii0 = 71 ; ii1 = 90 ; wslpj( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , : ) = 0._wp
  378. ENDIF
  379. ! IV. Lateral boundary conditions
  380. ! ===============================
  381. CALL lbc_lnk( uslp , 'U', -1. ) ; CALL lbc_lnk( vslp , 'V', -1. )
  382. CALL lbc_lnk( wslpi, 'W', -1. ) ; CALL lbc_lnk( wslpj, 'W', -1. )
  383. IF(ln_ctl) THEN
  384. CALL prt_ctl(tab3d_1=uslp , clinfo1=' slp - u : ', tab3d_2=vslp, clinfo2=' v : ', kdim=jpk)
  385. CALL prt_ctl(tab3d_1=wslpi, clinfo1=' slp - wi: ', tab3d_2=wslpj, clinfo2=' wj: ', kdim=jpk)
  386. ENDIF
  387. !
  388. ELSEIF ( lk_vvl ) THEN
  389. IF(lwp) THEN
  390. WRITE(numout,*) ' Horizontal mixing in s-coordinate: slope = slope of s-surfaces'
  391. ENDIF
  392. ! geopotential diffusion in s-coordinates on tracers and/or momentum
  393. ! The slopes of s-surfaces are computed at each time step due to vvl
  394. ! The slopes for momentum diffusion are i- or j- averaged of those on tracers
  395. ! set the slope of diffusion to the slope of s-surfaces
  396. ! ( c a u t i o n : minus sign as fsdep has positive value )
  397. DO jj = 2, jpjm1
  398. DO ji = fs_2, fs_jpim1 ! vector opt.
  399. uslp(ji,jj,1) = -1./e1u(ji,jj) * ( fsdept_b(ji+1,jj,1) - fsdept_b(ji ,jj ,1) ) * umask(ji,jj,1)
  400. vslp(ji,jj,1) = -1./e2v(ji,jj) * ( fsdept_b(ji,jj+1,1) - fsdept_b(ji ,jj ,1) ) * vmask(ji,jj,1)
  401. wslpi(ji,jj,1) = -1./e1t(ji,jj) * ( fsdepw_b(ji+1,jj,1) - fsdepw_b(ji-1,jj,1) ) * tmask(ji,jj,1) * 0.5
  402. wslpj(ji,jj,1) = -1./e2t(ji,jj) * ( fsdepw_b(ji,jj+1,1) - fsdepw_b(ji,jj-1,1) ) * tmask(ji,jj,1) * 0.5
  403. END DO
  404. END DO
  405. DO jk = 2, jpk
  406. DO jj = 2, jpjm1
  407. DO ji = fs_2, fs_jpim1 ! vector opt.
  408. uslp(ji,jj,jk) = -1./e1u(ji,jj) * ( fsdept_b(ji+1,jj,jk) - fsdept_b(ji ,jj ,jk) ) * umask(ji,jj,jk)
  409. vslp(ji,jj,jk) = -1./e2v(ji,jj) * ( fsdept_b(ji,jj+1,jk) - fsdept_b(ji ,jj ,jk) ) * vmask(ji,jj,jk)
  410. wslpi(ji,jj,jk) = -1./e1t(ji,jj) * ( fsdepw_b(ji+1,jj,jk) - fsdepw_b(ji-1,jj,jk) ) &
  411. & * wmask(ji,jj,jk) * 0.5
  412. wslpj(ji,jj,jk) = -1./e2t(ji,jj) * ( fsdepw_b(ji,jj+1,jk) - fsdepw_b(ji,jj-1,jk) ) &
  413. & * wmask(ji,jj,jk) * 0.5
  414. END DO
  415. END DO
  416. END DO
  417. ! Lateral boundary conditions on the slopes
  418. CALL lbc_lnk( uslp , 'U', -1. ) ; CALL lbc_lnk( vslp , 'V', -1. )
  419. CALL lbc_lnk( wslpi, 'W', -1. ) ; CALL lbc_lnk( wslpj, 'W', -1. )
  420. if( kt == nit000 ) then
  421. IF(lwp) WRITE(numout,*) ' max slop: u',SQRT( MAXVAL(uslp*uslp)), ' v ', SQRT(MAXVAL(vslp)), &
  422. & ' wi', sqrt(MAXVAL(wslpi)), ' wj', sqrt(MAXVAL(wslpj))
  423. endif
  424. IF(ln_ctl) THEN
  425. CALL prt_ctl(tab3d_1=uslp , clinfo1=' slp - u : ', tab3d_2=vslp, clinfo2=' v : ', kdim=jpk)
  426. CALL prt_ctl(tab3d_1=wslpi, clinfo1=' slp - wi: ', tab3d_2=wslpj, clinfo2=' wj: ', kdim=jpk)
  427. ENDIF
  428. ENDIF
  429. CALL wrk_dealloc( jpi,jpj,jpk, zwz, zww, zdzr, zgru, zgrv )
  430. CALL wrk_dealloc( jpi,jpj, zhmlpu, zhmlpv)
  431. !
  432. IF( nn_timing == 1 ) CALL timing_stop('ldf_slp')
  433. !
  434. END SUBROUTINE ldf_slp
  435. SUBROUTINE ldf_slp_grif ( kt )
  436. !!----------------------------------------------------------------------
  437. !! *** ROUTINE ldf_slp_grif ***
  438. !!
  439. !! ** Purpose : Compute the squared slopes of neutral surfaces (slope
  440. !! of iso-pycnal surfaces referenced locally) (ln_traldf_grif=T)
  441. !! at W-points using the Griffies quarter-cells.
  442. !!
  443. !! ** Method : calculates alpha and beta at T-points
  444. !!
  445. !! ** Action : - triadi_g, triadj_g T-pts i- and j-slope triads relative to geopot. (used for eiv)
  446. !! - triadi , triadj T-pts i- and j-slope triads relative to model-coordinate
  447. !! - wslp2 squared slope of neutral surfaces at w-points.
  448. !!----------------------------------------------------------------------
  449. INTEGER, INTENT( in ) :: kt ! ocean time-step index
  450. !!
  451. INTEGER :: ji, jj, jk, jl, ip, jp, kp ! dummy loop indices
  452. INTEGER :: iku, ikv ! local integer
  453. REAL(wp) :: zfacti, zfactj ! local scalars
  454. REAL(wp) :: znot_thru_surface ! local scalars
  455. REAL(wp) :: zdit, zdis, zdjt, zdjs, zdkt, zdks, zbu, zbv, zbti, zbtj
  456. REAL(wp) :: zdxrho_raw, zti_coord, zti_raw, zti_lim, zti_g_raw, zti_g_lim
  457. REAL(wp) :: zdyrho_raw, ztj_coord, ztj_raw, ztj_lim, ztj_g_raw, ztj_g_lim
  458. REAL(wp) :: zdzrho_raw
  459. REAL(wp), POINTER, DIMENSION(:,:) :: z1_mlbw
  460. REAL(wp), POINTER, DIMENSION(:,:,:,:) :: zdxrho , zdyrho, zdzrho ! Horizontal and vertical density gradients
  461. REAL(wp), POINTER, DIMENSION(:,:,:,:) :: zti_mlb, ztj_mlb ! for Griffies operator only
  462. !!----------------------------------------------------------------------
  463. !
  464. IF( nn_timing == 1 ) CALL timing_start('ldf_slp_grif')
  465. !
  466. CALL wrk_alloc( jpi,jpj, z1_mlbw )
  467. CALL wrk_alloc( jpi,jpj,jpk,2, zdxrho , zdyrho, zdzrho, klstart = 0 )
  468. CALL wrk_alloc( jpi,jpj, 2,2, zti_mlb, ztj_mlb, kkstart = 0, klstart = 0 )
  469. !
  470. !--------------------------------!
  471. ! Some preliminary calculation !
  472. !--------------------------------!
  473. !
  474. DO jl = 0, 1 !== unmasked before density i- j-, k-gradients ==!
  475. !
  476. ip = jl ; jp = jl ! guaranteed nonzero gradients ( absolute value larger than repsln)
  477. DO jk = 1, jpkm1 ! done each pair of triad
  478. DO jj = 1, jpjm1 ! NB: not masked ==> a minimum value is set
  479. DO ji = 1, fs_jpim1 ! vector opt.
  480. zdit = ( tsb(ji+1,jj,jk,jp_tem) - tsb(ji,jj,jk,jp_tem) ) ! i-gradient of T & S at u-point
  481. zdis = ( tsb(ji+1,jj,jk,jp_sal) - tsb(ji,jj,jk,jp_sal) )
  482. zdjt = ( tsb(ji,jj+1,jk,jp_tem) - tsb(ji,jj,jk,jp_tem) ) ! j-gradient of T & S at v-point
  483. zdjs = ( tsb(ji,jj+1,jk,jp_sal) - tsb(ji,jj,jk,jp_sal) )
  484. zdxrho_raw = ( - rab_b(ji+ip,jj ,jk,jp_tem) * zdit + rab_b(ji+ip,jj ,jk,jp_sal) * zdis ) / e1u(ji,jj)
  485. zdyrho_raw = ( - rab_b(ji ,jj+jp,jk,jp_tem) * zdjt + rab_b(ji ,jj+jp,jk,jp_sal) * zdjs ) / e2v(ji,jj)
  486. zdxrho(ji+ip,jj ,jk,1-ip) = SIGN( MAX( repsln, ABS( zdxrho_raw ) ), zdxrho_raw ) ! keep the sign
  487. zdyrho(ji ,jj+jp,jk,1-jp) = SIGN( MAX( repsln, ABS( zdyrho_raw ) ), zdyrho_raw )
  488. END DO
  489. END DO
  490. END DO
  491. !
  492. IF( ln_zps .AND. l_grad_zps ) THEN ! partial steps: correction of i- & j-grad on bottom
  493. DO jj = 1, jpjm1
  494. DO ji = 1, jpim1
  495. iku = mbku(ji,jj) ; ikv = mbkv(ji,jj) ! last ocean level (u- & v-points)
  496. zdit = gtsu(ji,jj,jp_tem) ; zdjt = gtsv(ji,jj,jp_tem) ! i- & j-gradient of Temperature
  497. zdis = gtsu(ji,jj,jp_sal) ; zdjs = gtsv(ji,jj,jp_sal) ! i- & j-gradient of Salinity
  498. zdxrho_raw = ( - rab_b(ji+ip,jj ,iku,jp_tem) * zdit + rab_b(ji+ip,jj ,iku,jp_sal) * zdis ) / e1u(ji,jj)
  499. zdyrho_raw = ( - rab_b(ji ,jj+jp,ikv,jp_tem) * zdjt + rab_b(ji ,jj+jp,ikv,jp_sal) * zdjs ) / e2v(ji,jj)
  500. zdxrho(ji+ip,jj ,iku,1-ip) = SIGN( MAX( repsln, ABS( zdxrho_raw ) ), zdxrho_raw ) ! keep the sign
  501. zdyrho(ji ,jj+jp,ikv,1-jp) = SIGN( MAX( repsln, ABS( zdyrho_raw ) ), zdyrho_raw )
  502. END DO
  503. END DO
  504. ENDIF
  505. !
  506. END DO
  507. DO kp = 0, 1 !== unmasked before density i- j-, k-gradients ==!
  508. DO jk = 1, jpkm1 ! done each pair of triad
  509. DO jj = 1, jpj ! NB: not masked ==> a minimum value is set
  510. DO ji = 1, jpi ! vector opt.
  511. IF( jk+kp > 1 ) THEN ! k-gradient of T & S a jk+kp
  512. zdkt = ( tsb(ji,jj,jk+kp-1,jp_tem) - tsb(ji,jj,jk+kp,jp_tem) )
  513. zdks = ( tsb(ji,jj,jk+kp-1,jp_sal) - tsb(ji,jj,jk+kp,jp_sal) )
  514. ELSE
  515. zdkt = 0._wp ! 1st level gradient set to zero
  516. zdks = 0._wp
  517. ENDIF
  518. zdzrho_raw = ( - rab_b(ji,jj,jk,jp_tem) * zdkt + rab_b(ji,jj,jk,jp_sal) * zdks ) / fse3w(ji,jj,jk+kp)
  519. zdzrho(ji,jj,jk,kp) = - MIN( - repsln, zdzrho_raw ) ! force zdzrho >= repsln
  520. END DO
  521. END DO
  522. END DO
  523. END DO
  524. !
  525. DO jj = 1, jpj !== Reciprocal depth of the w-point below ML base ==!
  526. DO ji = 1, jpi
  527. jk = MIN( nmln(ji,jj), mbkt(ji,jj) ) + 1 ! MIN in case ML depth is the ocean depth
  528. z1_mlbw(ji,jj) = 1._wp / fsdepw(ji,jj,jk)
  529. END DO
  530. END DO
  531. !
  532. ! !== intialisations to zero ==!
  533. !
  534. wslp2 (:,:,:) = 0._wp ! wslp2 will be cumulated 3D field set to zero
  535. triadi_g(:,:,1,:,:) = 0._wp ; triadi_g(:,:,jpk,:,:) = 0._wp ! set surface and bottom slope to zero
  536. triadj_g(:,:,1,:,:) = 0._wp ; triadj_g(:,:,jpk,:,:) = 0._wp
  537. !!gm _iso set to zero missing
  538. triadi (:,:,1,:,:) = 0._wp ; triadj (:,:,jpk,:,:) = 0._wp ! set surface and bottom slope to zero
  539. triadj (:,:,1,:,:) = 0._wp ; triadj (:,:,jpk,:,:) = 0._wp
  540. !-------------------------------------!
  541. ! Triads just below the Mixed Layer !
  542. !-------------------------------------!
  543. !
  544. DO jl = 0, 1 ! calculate slope of the 4 triads immediately ONE level below mixed-layer base
  545. DO kp = 0, 1 ! with only the slope-max limit and MASKED
  546. DO jj = 1, jpjm1
  547. DO ji = 1, fs_jpim1
  548. ip = jl ; jp = jl
  549. !
  550. jk = nmln(ji+ip,jj) + 1
  551. IF( jk .GT. mbkt(ji+ip,jj) ) THEN !ML reaches bottom
  552. zti_mlb(ji+ip,jj ,1-ip,kp) = 0.0_wp
  553. ELSE
  554. ! Add s-coordinate slope at t-points (do this by *subtracting* gradient of depth)
  555. zti_g_raw = ( zdxrho(ji+ip,jj,jk-kp,1-ip) / zdzrho(ji+ip,jj,jk-kp,kp) &
  556. & - ( fsdept(ji+1,jj,jk-kp) - fsdept(ji,jj,jk-kp) ) / e1u(ji,jj) ) * umask(ji,jj,jk)
  557. zti_mlb(ji+ip,jj ,1-ip,kp) = SIGN( MIN( rn_slpmax, ABS( zti_g_raw ) ), zti_g_raw )
  558. ENDIF
  559. !
  560. jk = nmln(ji,jj+jp) + 1
  561. IF( jk .GT. mbkt(ji,jj+jp) ) THEN !ML reaches bottom
  562. ztj_mlb(ji ,jj+jp,1-jp,kp) = 0.0_wp
  563. ELSE
  564. ztj_g_raw = ( zdyrho(ji,jj+jp,jk-kp,1-jp) / zdzrho(ji,jj+jp,jk-kp,kp) &
  565. & - ( fsdept(ji,jj+1,jk-kp) - fsdept(ji,jj,jk-kp) ) / e2v(ji,jj) ) * vmask(ji,jj,jk)
  566. ztj_mlb(ji ,jj+jp,1-jp,kp) = SIGN( MIN( rn_slpmax, ABS( ztj_g_raw ) ), ztj_g_raw )
  567. ENDIF
  568. END DO
  569. END DO
  570. END DO
  571. END DO
  572. !-------------------------------------!
  573. ! Triads with surface limits !
  574. !-------------------------------------!
  575. !
  576. DO kp = 0, 1 ! k-index of triads
  577. DO jl = 0, 1
  578. ip = jl ; jp = jl ! i- and j-indices of triads (i-k and j-k planes)
  579. DO jk = 1, jpkm1
  580. ! Must mask contribution to slope from dz/dx at constant s for triads jk=1,kp=0 that poke up though ocean surface
  581. znot_thru_surface = REAL( 1-1/(jk+kp), wp ) !jk+kp=1,=0.; otherwise=1.0
  582. DO jj = 1, jpjm1
  583. DO ji = 1, fs_jpim1 ! vector opt.
  584. !
  585. ! Calculate slope relative to geopotentials used for GM skew fluxes
  586. ! Add s-coordinate slope at t-points (do this by *subtracting* gradient of depth)
  587. ! Limit by slope *relative to geopotentials* by rn_slpmax, and mask by psi-point
  588. ! masked by umask taken at the level of dz(rho)
  589. !
  590. ! raw slopes: unmasked unbounded slopes (relative to geopotential (zti_g) and model surface (zti)
  591. !
  592. zti_raw = zdxrho(ji+ip,jj ,jk,1-ip) / zdzrho(ji+ip,jj ,jk,kp) ! unmasked
  593. ztj_raw = zdyrho(ji ,jj+jp,jk,1-jp) / zdzrho(ji ,jj+jp,jk,kp)
  594. ! Must mask contribution to slope for triad jk=1,kp=0 that poke up though ocean surface
  595. zti_coord = znot_thru_surface * ( fsdept(ji+1,jj ,jk) - fsdept(ji,jj,jk) ) / e1u(ji,jj)
  596. ztj_coord = znot_thru_surface * ( fsdept(ji ,jj+1,jk) - fsdept(ji,jj,jk) ) / e2v(ji,jj) ! unmasked
  597. zti_g_raw = zti_raw - zti_coord ! ref to geopot surfaces
  598. ztj_g_raw = ztj_raw - ztj_coord
  599. zti_g_lim = SIGN( MIN( rn_slpmax, ABS( zti_g_raw ) ), zti_g_raw )
  600. ztj_g_lim = SIGN( MIN( rn_slpmax, ABS( ztj_g_raw ) ), ztj_g_raw )
  601. !
  602. ! Below ML use limited zti_g as is & mask
  603. ! Inside ML replace by linearly reducing sx_mlb towards surface & mask
  604. !
  605. zfacti = REAL( 1 - 1/(1 + (jk+kp-1)/nmln(ji+ip,jj)), wp ) ! k index of uppermost point(s) of triad is jk+kp-1
  606. zfactj = REAL( 1 - 1/(1 + (jk+kp-1)/nmln(ji,jj+jp)), wp ) ! must be .ge. nmln(ji,jj) for zfact=1
  607. ! ! otherwise zfact=0
  608. zti_g_lim = ( zfacti * zti_g_lim &
  609. & + ( 1._wp - zfacti ) * zti_mlb(ji+ip,jj,1-ip,kp) &
  610. & * fsdepw(ji+ip,jj,jk+kp) * z1_mlbw(ji+ip,jj) ) * umask(ji,jj,jk+kp)
  611. ztj_g_lim = ( zfactj * ztj_g_lim &
  612. & + ( 1._wp - zfactj ) * ztj_mlb(ji,jj+jp,1-jp,kp) &
  613. & * fsdepw(ji,jj+jp,jk+kp) * z1_mlbw(ji,jj+jp) ) * vmask(ji,jj,jk+kp)
  614. !
  615. triadi_g(ji+ip,jj ,jk,1-ip,kp) = zti_g_lim
  616. triadj_g(ji ,jj+jp,jk,1-jp,kp) = ztj_g_lim
  617. !
  618. ! Get coefficients of isoneutral diffusion tensor
  619. ! 1. Utilise gradients *relative* to s-coordinate, so add t-point slopes (*subtract* depth gradients)
  620. ! 2. We require that isoneutral diffusion gives no vertical buoyancy flux
  621. ! i.e. 33 term = (real slope* 31, 13 terms)
  622. ! To do this, retain limited sx**2 in vertical flux, but divide by real slope for 13/31 terms
  623. ! Equivalent to tapering A_iso = sx_limited**2/(real slope)**2
  624. !
  625. zti_lim = ( zti_g_lim + zti_coord ) * umask(ji,jj,jk+kp) ! remove coordinate slope => relative to coordinate surfaces
  626. ztj_lim = ( ztj_g_lim + ztj_coord ) * vmask(ji,jj,jk+kp)
  627. !
  628. IF( ln_triad_iso ) THEN
  629. zti_raw = zti_lim**2 / zti_raw
  630. ztj_raw = ztj_lim**2 / ztj_raw
  631. zti_raw = SIGN( MIN( ABS(zti_lim), ABS( zti_raw ) ), zti_raw )
  632. ztj_raw = SIGN( MIN( ABS(ztj_lim), ABS( ztj_raw ) ), ztj_raw )
  633. zti_lim = zfacti * zti_lim &
  634. & + ( 1._wp - zfacti ) * zti_raw
  635. ztj_lim = zfactj * ztj_lim &
  636. & + ( 1._wp - zfactj ) * ztj_raw
  637. ENDIF
  638. triadi(ji+ip,jj ,jk,1-ip,kp) = zti_lim
  639. triadj(ji ,jj+jp,jk,1-jp,kp) = ztj_lim
  640. !
  641. zbu = e1u(ji ,jj) * e2u(ji ,jj) * fse3u(ji ,jj,jk )
  642. zbv = e1v(ji ,jj) * e2v(ji ,jj) * fse3v(ji ,jj,jk )
  643. zbti = e1t(ji+ip,jj) * e2t(ji+ip,jj) * fse3w(ji+ip,jj,jk+kp)
  644. zbtj = e1t(ji,jj+jp) * e2t(ji,jj+jp) * fse3w(ji,jj+jp,jk+kp)
  645. !
  646. !!gm this may inhibit vectorization on Vect Computers, and even on scalar computers.... ==> to be checked
  647. wslp2 (ji+ip,jj,jk+kp) = wslp2(ji+ip,jj,jk+kp) + 0.25_wp * zbu / zbti * zti_g_lim**2 ! masked
  648. wslp2 (ji,jj+jp,jk+kp) = wslp2(ji,jj+jp,jk+kp) + 0.25_wp * zbv / zbtj * ztj_g_lim**2
  649. END DO
  650. END DO
  651. END DO
  652. END DO
  653. END DO
  654. !
  655. wslp2(:,:,1) = 0._wp ! force the surface wslp to zero
  656. CALL lbc_lnk( wslp2, 'W', 1. ) ! lateral boundary confition on wslp2 only ==>>> gm : necessary ? to be checked
  657. !
  658. CALL wrk_dealloc( jpi,jpj, z1_mlbw )
  659. CALL wrk_dealloc( jpi,jpj,jpk,2, zdxrho , zdyrho, zdzrho, klstart = 0 )
  660. CALL wrk_dealloc( jpi,jpj, 2,2, zti_mlb, ztj_mlb, kkstart = 0, klstart = 0 )
  661. !
  662. IF( nn_timing == 1 ) CALL timing_stop('ldf_slp_grif')
  663. !
  664. END SUBROUTINE ldf_slp_grif
  665. SUBROUTINE ldf_slp_mxl( prd, pn2, p_gru, p_grv, p_dzr )
  666. !!----------------------------------------------------------------------
  667. !! *** ROUTINE ldf_slp_mxl ***
  668. !!
  669. !! ** Purpose : Compute the slopes of iso-neutral surface just below
  670. !! the mixed layer.
  671. !!
  672. !! ** Method : The slope in the i-direction is computed at u- & w-points
  673. !! (uslpml, wslpiml) and the slope in the j-direction is computed
  674. !! at v- and w-points (vslpml, wslpjml) with the same bounds as
  675. !! in ldf_slp.
  676. !!
  677. !! ** Action : uslpml, wslpiml : i- & j-slopes of neutral surfaces
  678. !! vslpml, wslpjml just below the mixed layer
  679. !! omlmask : mixed layer mask
  680. !!----------------------------------------------------------------------
  681. REAL(wp), DIMENSION(:,:,:), INTENT(in) :: prd ! in situ density
  682. REAL(wp), DIMENSION(:,:,:), INTENT(in) :: pn2 ! Brunt-Vaisala frequency (locally ref.)
  683. REAL(wp), DIMENSION(:,:,:), INTENT(in) :: p_gru, p_grv ! i- & j-gradient of density (u- & v-pts)
  684. REAL(wp), DIMENSION(:,:,:), INTENT(in) :: p_dzr ! z-gradient of density (T-point)
  685. !!
  686. INTEGER :: ji , jj , jk ! dummy loop indices
  687. INTEGER :: iku, ikv, ik, ikm1 ! local integers
  688. REAL(wp) :: zeps, zm1_g, zm1_2g ! local scalars
  689. REAL(wp) :: zci, zfi, zau, zbu, zai, zbi ! - -
  690. REAL(wp) :: zcj, zfj, zav, zbv, zaj, zbj ! - -
  691. REAL(wp) :: zck, zfk, zbw ! - -
  692. !!----------------------------------------------------------------------
  693. !
  694. IF( nn_timing == 1 ) CALL timing_start('ldf_slp_mxl')
  695. !
  696. zeps = 1.e-20_wp !== Local constant initialization ==!
  697. zm1_g = -1.0_wp / grav
  698. zm1_2g = -0.5_wp / grav
  699. !
  700. uslpml (1,:) = 0._wp ; uslpml (jpi,:) = 0._wp
  701. vslpml (1,:) = 0._wp ; vslpml (jpi,:) = 0._wp
  702. wslpiml(1,:) = 0._wp ; wslpiml(jpi,:) = 0._wp
  703. wslpjml(1,:) = 0._wp ; wslpjml(jpi,:) = 0._wp
  704. !
  705. ! !== surface mixed layer mask !
  706. DO jk = 1, jpk ! =1 inside the mixed layer, =0 otherwise
  707. DO jj = 1, jpj
  708. DO ji = 1, jpi
  709. ik = nmln(ji,jj) - 1
  710. IF( jk <= ik .AND. jk >= mikt(ji,jj) ) THEN
  711. omlmask(ji,jj,jk) = 1._wp
  712. ELSE
  713. omlmask(ji,jj,jk) = 0._wp
  714. ENDIF
  715. END DO
  716. END DO
  717. END DO
  718. ! Slopes of isopycnal surfaces just before bottom of mixed layer
  719. ! --------------------------------------------------------------
  720. ! The slope are computed as in the 3D case.
  721. ! A key point here is the definition of the mixed layer at u- and v-points.
  722. ! It is assumed to be the maximum of the two neighbouring T-point mixed layer depth.
  723. ! Otherwise, a n2 value inside the mixed layer can be involved in the computation
  724. ! of the slope, resulting in a too steep diagnosed slope and thus a spurious eddy
  725. ! induce velocity field near the base of the mixed layer.
  726. !-----------------------------------------------------------------------
  727. !
  728. DO jj = 2, jpjm1
  729. DO ji = 2, jpim1
  730. ! !== Slope at u- & v-points just below the Mixed Layer ==!
  731. !
  732. ! !- vertical density gradient for u- and v-slopes (from dzr at T-point)
  733. iku = MIN( MAX( miku(ji,jj)+1, nmln(ji,jj) , nmln(ji+1,jj) ) , jpkm1 ) ! ML (MAX of T-pts, bound by jpkm1)
  734. ikv = MIN( MAX( mikv(ji,jj)+1, nmln(ji,jj) , nmln(ji,jj+1) ) , jpkm1 ) !
  735. zbu = 0.5_wp * ( p_dzr(ji,jj,iku) + p_dzr(ji+1,jj ,iku) )
  736. zbv = 0.5_wp * ( p_dzr(ji,jj,ikv) + p_dzr(ji ,jj+1,ikv) )
  737. ! !- horizontal density gradient at u- & v-points
  738. zau = p_gru(ji,jj,iku) / e1u(ji,jj)
  739. zav = p_grv(ji,jj,ikv) / e2v(ji,jj)
  740. ! !- bound the slopes: abs(zw.)<= 1/100 and zb..<0
  741. ! kxz max= ah slope max =< e1 e3 /(pi**2 2 dt)
  742. zbu = MIN( zbu , -100._wp* ABS( zau ) , -7.e+3_wp/fse3u(ji,jj,iku)* ABS( zau ) )
  743. zbv = MIN( zbv , -100._wp* ABS( zav ) , -7.e+3_wp/fse3v(ji,jj,ikv)* ABS( zav ) )
  744. ! !- Slope at u- & v-points (uslpml, vslpml)
  745. uslpml(ji,jj) = zau / ( zbu - zeps ) * umask(ji,jj,iku)
  746. vslpml(ji,jj) = zav / ( zbv - zeps ) * vmask(ji,jj,ikv)
  747. !
  748. ! !== i- & j-slopes at w-points just below the Mixed Layer ==!
  749. !
  750. ik = MIN( nmln(ji,jj) + 1, jpk )
  751. ikm1 = MAX( 1, ik-1 )
  752. ! !- vertical density gradient for w-slope (from N^2)
  753. zbw = zm1_2g * pn2 (ji,jj,ik) * ( prd (ji,jj,ik) + prd (ji,jj,ikm1) + 2. )
  754. ! !- horizontal density i- & j-gradient at w-points
  755. zci = MAX( umask(ji-1,jj,ik ) + umask(ji,jj,ik ) &
  756. & + umask(ji-1,jj,ikm1) + umask(ji,jj,ikm1) , zeps ) * e1t(ji,jj)
  757. zcj = MAX( vmask(ji,jj-1,ik ) + vmask(ji,jj,ik ) &
  758. & + vmask(ji,jj-1,ikm1) + vmask(ji,jj,ikm1) , zeps ) * e2t(ji,jj)
  759. zai = ( p_gru(ji-1,jj,ik ) + p_gru(ji,jj,ik) &
  760. & + p_gru(ji-1,jj,ikm1) + p_gru(ji,jj,ikm1 ) ) / zci * tmask(ji,jj,ik)
  761. zaj = ( p_grv(ji,jj-1,ik ) + p_grv(ji,jj,ik ) &
  762. & + p_grv(ji,jj-1,ikm1) + p_grv(ji,jj,ikm1) ) / zcj * tmask(ji,jj,ik)
  763. ! !- bound the slopes: abs(zw.)<= 1/100 and zb..<0.
  764. ! kxz max= ah slope max =< e1 e3 /(pi**2 2 dt)
  765. zbi = MIN( zbw , -100._wp* ABS( zai ) , -7.e+3_wp/fse3w(ji,jj,ik)* ABS( zai ) )
  766. zbj = MIN( zbw , -100._wp* ABS( zaj ) , -7.e+3_wp/fse3w(ji,jj,ik)* ABS( zaj ) )
  767. ! !- i- & j-slope at w-points (wslpiml, wslpjml)
  768. wslpiml(ji,jj) = zai / ( zbi - zeps ) * wmask (ji,jj,ik)
  769. wslpjml(ji,jj) = zaj / ( zbj - zeps ) * wmask (ji,jj,ik)
  770. END DO
  771. END DO
  772. !!gm this lbc_lnk should be useless....
  773. CALL lbc_lnk( uslpml , 'U', -1. ) ; CALL lbc_lnk( vslpml , 'V', -1. ) ! lateral boundary cond. (sign change)
  774. CALL lbc_lnk( wslpiml, 'W', -1. ) ; CALL lbc_lnk( wslpjml, 'W', -1. ) ! lateral boundary conditions
  775. !
  776. IF( nn_timing == 1 ) CALL timing_stop('ldf_slp_mxl')
  777. !
  778. END SUBROUTINE ldf_slp_mxl
  779. SUBROUTINE ldf_slp_init
  780. !!----------------------------------------------------------------------
  781. !! *** ROUTINE ldf_slp_init ***
  782. !!
  783. !! ** Purpose : Initialization for the isopycnal slopes computation
  784. !!
  785. !! ** Method : read the nammbf namelist and check the parameter
  786. !! values called by tra_dmp at the first timestep (nit000)
  787. !!----------------------------------------------------------------------
  788. INTEGER :: ji, jj, jk ! dummy loop indices
  789. INTEGER :: ierr ! local integer
  790. !!----------------------------------------------------------------------
  791. !
  792. IF( nn_timing == 1 ) CALL timing_start('ldf_slp_init')
  793. !
  794. IF(lwp) THEN
  795. WRITE(numout,*)
  796. WRITE(numout,*) 'ldf_slp_init : direction of lateral mixing'
  797. WRITE(numout,*) '~~~~~~~~~~~~'
  798. ENDIF
  799. IF( ln_traldf_grif ) THEN ! Griffies operator : triad of slopes
  800. ALLOCATE( triadi_g(jpi,jpj,jpk,0:1,0:1) , triadj_g(jpi,jpj,jpk,0:1,0:1) , wslp2(jpi,jpj,jpk) , STAT=ierr )
  801. ALLOCATE( triadi (jpi,jpj,jpk,0:1,0:1) , triadj (jpi,jpj,jpk,0:1,0:1) , STAT=ierr )
  802. IF( ierr > 0 ) CALL ctl_stop( 'STOP', 'ldf_slp_init : unable to allocate Griffies operator slope' )
  803. !
  804. IF( ln_dynldf_iso ) CALL ctl_stop( 'ldf_slp_init: Griffies operator on momentum not supported' )
  805. !
  806. ELSE ! Madec operator : slopes at u-, v-, and w-points
  807. ALLOCATE( uslp(jpi,jpj,jpk) , vslp(jpi,jpj,jpk) , wslpi(jpi,jpj,jpk) , wslpj(jpi,jpj,jpk) , &
  808. & omlmask(jpi,jpj,jpk) , uslpml(jpi,jpj) , vslpml(jpi,jpj) , wslpiml(jpi,jpj) , wslpjml(jpi,jpj) , STAT=ierr )
  809. IF( ierr > 0 ) CALL ctl_stop( 'STOP', 'ldf_slp_init : unable to allocate Madec operator slope ' )
  810. ! Direction of lateral diffusion (tracers and/or momentum)
  811. ! ------------------------------
  812. uslp (:,:,:) = 0._wp ; uslpml (:,:) = 0._wp ! set the slope to zero (even in s-coordinates)
  813. vslp (:,:,:) = 0._wp ; vslpml (:,:) = 0._wp
  814. wslpi(:,:,:) = 0._wp ; wslpiml(:,:) = 0._wp
  815. wslpj(:,:,:) = 0._wp ; wslpjml(:,:) = 0._wp
  816. IF(ln_sco .AND. (ln_traldf_hor .OR. ln_dynldf_hor )) THEN
  817. IF(lwp) WRITE(numout,*) ' Horizontal mixing in s-coordinate: slope = slope of s-surfaces'
  818. ! geopotential diffusion in s-coordinates on tracers and/or momentum
  819. ! The slopes of s-surfaces are computed once (no call to ldfslp in step)
  820. ! The slopes for momentum diffusion are i- or j- averaged of those on tracers
  821. ! set the slope of diffusion to the slope of s-surfaces
  822. ! ( c a u t i o n : minus sign as fsdep has positive value )
  823. DO jk = 1, jpk
  824. DO jj = 2, jpjm1
  825. DO ji = fs_2, fs_jpim1 ! vector opt.
  826. uslp (ji,jj,jk) = -1./e1u(ji,jj) * ( fsdept_b(ji+1,jj,jk) - fsdept_b(ji ,jj ,jk) ) * umask(ji,jj,jk)
  827. vslp (ji,jj,jk) = -1./e2v(ji,jj) * ( fsdept_b(ji,jj+1,jk) - fsdept_b(ji ,jj ,jk) ) * vmask(ji,jj,jk)
  828. wslpi(ji,jj,jk) = -1./e1t(ji,jj) * ( fsdepw_b(ji+1,jj,jk) - fsdepw_b(ji-1,jj,jk) ) * tmask(ji,jj,jk) * 0.5
  829. wslpj(ji,jj,jk) = -1./e2t(ji,jj) * ( fsdepw_b(ji,jj+1,jk) - fsdepw_b(ji,jj-1,jk) ) * tmask(ji,jj,jk) * 0.5
  830. END DO
  831. END DO
  832. END DO
  833. CALL lbc_lnk( uslp , 'U', -1. ) ; CALL lbc_lnk( vslp , 'V', -1. ) ! Lateral boundary conditions
  834. CALL lbc_lnk( wslpi, 'W', -1. ) ; CALL lbc_lnk( wslpj, 'W', -1. )
  835. ENDIF
  836. ENDIF
  837. !
  838. IF( nn_timing == 1 ) CALL timing_stop('ldf_slp_init')
  839. !
  840. END SUBROUTINE ldf_slp_init
  841. #else
  842. !!------------------------------------------------------------------------
  843. !! Dummy module : NO Rotation of lateral mixing tensor
  844. !!------------------------------------------------------------------------
  845. LOGICAL, PUBLIC, PARAMETER :: lk_ldfslp = .FALSE. !: slopes flag
  846. CONTAINS
  847. SUBROUTINE ldf_slp( kt, prd, pn2 ) ! Dummy routine
  848. INTEGER, INTENT(in) :: kt
  849. REAL, DIMENSION(:,:,:), INTENT(in) :: prd, pn2
  850. WRITE(*,*) 'ldf_slp: You should not have seen this print! error?', kt, prd(1,1,1), pn2(1,1,1)
  851. END SUBROUTINE ldf_slp
  852. SUBROUTINE ldf_slp_grif( kt ) ! Dummy routine
  853. INTEGER, INTENT(in) :: kt
  854. WRITE(*,*) 'ldf_slp_grif: You should not have seen this print! error?', kt
  855. END SUBROUTINE ldf_slp_grif
  856. SUBROUTINE ldf_slp_init ! Dummy routine
  857. END SUBROUTINE ldf_slp_init
  858. #endif
  859. !!======================================================================
  860. END MODULE ldfslp