zdfkpp.F90 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592
  1. MODULE zdfkpp
  2. !!======================================================================
  3. !! *** MODULE zdfkpp ***
  4. !! Ocean physics: vertical mixing coefficient compute from the KPP
  5. !! turbulent closure parameterization
  6. !!=====================================================================
  7. !! History : OPA ! 2000-03 (W.G. Large, J. Chanut) Original code
  8. !! 8.1 ! 2002-06 (J.M. Molines) for real case CLIPPER
  9. !! 8.2 ! 2003-10 (Chanut J.) re-writting
  10. !! NEMO 1.0 ! 2005-01 (C. Ethe, G. Madec) Free form, F90 + creation of tra_kpp routine
  11. !! 3.3 ! 2010-10 (C. Ethe, G. Madec) reorganisation of initialisation phase + merge TRC-TRA
  12. !!----------------------------------------------------------------------
  13. #if defined key_zdfkpp || defined key_esopa
  14. !!----------------------------------------------------------------------
  15. !! 'key_zdfkpp' KPP scheme
  16. !!----------------------------------------------------------------------
  17. !! zdf_kpp : update momentum and tracer Kz from a kpp scheme
  18. !! zdf_kpp_init : initialization, namelist read, and parameters control
  19. !! tra_kpp : compute and add to the T & S trend the non-local flux
  20. !! trc_kpp : compute and add to the passive tracer trend the non-local flux (lk_top=T)
  21. !!----------------------------------------------------------------------
  22. USE oce ! ocean dynamics and active tracers
  23. USE dom_oce ! ocean space and time domain
  24. USE zdf_oce ! ocean vertical physics
  25. USE sbc_oce ! surface boundary condition: ocean
  26. USE phycst ! physical constants
  27. USE eosbn2 ! equation of state
  28. USE zdfddm ! double diffusion mixing (avs array)
  29. USE lib_mpp ! MPP library
  30. USE trd_oce ! ocean trends definition
  31. USE trdtra ! tracers trends
  32. !
  33. USE in_out_manager ! I/O manager
  34. USE lbclnk ! ocean lateral boundary conditions (or mpp link)
  35. USE prtctl ! Print control
  36. USE wrk_nemo ! work arrays
  37. USE timing ! Timing
  38. USE lib_fortran ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
  39. IMPLICIT NONE
  40. PRIVATE
  41. PUBLIC zdf_kpp ! routine called by step.F90
  42. PUBLIC zdf_kpp_init ! routine called by opa.F90
  43. PUBLIC tra_kpp ! routine called by step.F90
  44. PUBLIC trc_kpp ! routine called by trcstp.F90
  45. LOGICAL , PUBLIC, PARAMETER :: lk_zdfkpp = .TRUE. !: KPP vertical mixing flag
  46. REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: ghats !: non-local scalar mixing term (gamma/<ws>o)
  47. REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) :: wt0 !: surface temperature flux for non local flux
  48. REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) :: ws0 !: surface salinity flux for non local flux
  49. REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) :: hkpp !: boundary layer depth
  50. ! !!* Namelist namzdf_kpp *
  51. REAL(wp) :: rn_difmiw ! constant internal wave viscosity (m2/s)
  52. REAL(wp) :: rn_difsiw ! constant internal wave diffusivity (m2/s)
  53. REAL(wp) :: rn_riinfty ! local Richardson Number limit for shear instability
  54. REAL(wp) :: rn_difri ! maximum shear mixing at Rig = 0 (m2/s)
  55. REAL(wp) :: rn_bvsqcon ! Brunt-Vaisala squared (1/s**2) for maximum convection
  56. REAL(wp) :: rn_difcon ! maximum mixing in interior convection (m2/s)
  57. INTEGER :: nn_ave ! = 0/1 flag for horizontal average on avt, avmu, avmv
  58. #if defined key_zdfddm
  59. ! !!! ** Double diffusion Mixing
  60. REAL(wp) :: difssf = 1.e-03_wp ! maximum salt fingering mixing
  61. REAL(wp) :: Rrho0 = 1.9_wp ! limit for salt fingering mixing
  62. REAL(wp) :: difsdc = 1.5e-06_wp ! maximum diffusive convection mixing
  63. #endif
  64. LOGICAL :: ln_kpprimix ! Shear instability mixing
  65. ! !!! ** General constants **
  66. REAL(wp) :: epsln = 1.0e-20_wp ! a small positive number
  67. REAL(wp) :: pthird = 1._wp/3._wp ! 1/3
  68. REAL(wp) :: pfourth = 1._wp/4._wp ! 1/4
  69. ! !!! ** Boundary Layer Turbulence Parameters **
  70. REAL(wp) :: vonk = 0.4_wp ! von Karman's constant
  71. REAL(wp) :: epsilon = 0.1_wp ! nondimensional extent of the surface layer
  72. REAL(wp) :: rconc1 = 5.0_wp ! standard flux profile function parmaeters
  73. REAL(wp) :: rconc2 = 16.0_wp ! " "
  74. REAL(wp) :: rconcm = 8.38_wp ! momentum flux profile fit
  75. REAL(wp) :: rconam = 1.26_wp ! " "
  76. REAL(wp) :: rzetam = -.20_wp ! " "
  77. REAL(wp) :: rconcs = 98.96_wp ! scalar flux profile fit
  78. REAL(wp) :: rconas = -28.86_wp ! " "
  79. REAL(wp) :: rzetas = -1.0_wp ! " "
  80. ! !!! ** Boundary Layer Depth Diagnostic **
  81. REAL(wp) :: Ricr = 0.3_wp ! critical bulk Richardson Number
  82. REAL(wp) :: rcekman = 0.7_wp ! coefficient for ekman depth
  83. REAL(wp) :: rcmonob = 1.0_wp ! coefficient for Monin-Obukhov depth
  84. REAL(wp) :: rconcv = 1.7_wp ! ratio of interior buoyancy frequency to its value at entrainment depth
  85. REAL(wp) :: hbf = 1.0_wp ! fraction of bound. layer depth to which absorbed solar
  86. ! ! rad. and contributes to surf. buo. forcing
  87. REAL(wp) :: Vtc ! function of rconcv,rconcs,epsilon,vonk,Ricr
  88. ! !!! ** Nonlocal Boundary Layer Mixing **
  89. REAL(wp) :: rcstar = 5.0_wp ! coefficient for convective nonlocal transport
  90. REAL(wp) :: rcs = 1.0e-3_wp ! conversion: mm/s ==> m/s
  91. REAL(wp) :: rcg ! non-dimensional coefficient for nonlocal transport
  92. #if ! defined key_kppcustom
  93. REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) :: del ! array for reference mean values of vertical integration
  94. #endif
  95. #if defined key_kpplktb
  96. ! !!! ** Parameters for lookup table for turbulent velocity scales **
  97. INTEGER, PARAMETER :: nilktb = 892 ! number of values for zehat in KPP lookup table
  98. INTEGER, PARAMETER :: njlktb = 482 ! number of values for ustar in KPP lookup table
  99. INTEGER, PARAMETER :: nilktbm1 = nilktb-1 !
  100. INTEGER, PARAMETER :: njlktbm1 = njlktb-1 !
  101. REAL(wp), DIMENSION(nilktb,njlktb) :: wmlktb ! lookup table for the turbulent vertical velocity scale (momentum)
  102. REAL(wp), DIMENSION(nilktb,njlktb) :: wslktb ! lookup table for the turbulent vertical velocity scale (tracers)
  103. REAL(wp) :: dehatmin = -4.e-7_wp ! minimum limit for zhat in lookup table (m3/s3)
  104. REAL(wp) :: dehatmax = 0._wp ! maximum limit for zhat in lookup table (m3/s3)
  105. REAL(wp) :: ustmin = 0._wp ! minimum limit for ustar in lookup table (m/s)
  106. REAL(wp) :: ustmax = 0.04_wp ! maximum limit for ustar in lookup table (m/s)
  107. REAL(wp) :: dezehat ! delta zhat in lookup table
  108. REAL(wp) :: deustar ! delta ustar in lookup table
  109. #endif
  110. REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:) :: ratt ! attenuation coef (already defines in module traqsr,
  111. ! ! but only if the solar radiation penetration is considered)
  112. ! !!! * penetrative solar radiation coefficient *
  113. REAL(wp) :: rabs = 0.58_wp ! fraction associated with xsi1
  114. REAL(wp) :: xsi1 = 0.35_wp ! first depth of extinction
  115. REAL(wp) :: xsi2 = 23.0_wp ! second depth of extinction
  116. ! ! (default values: water type Ib)
  117. REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: etmean, eumean, evmean ! coeff. used for hor. smoothing at t-, u- & v-points
  118. #if defined key_c1d
  119. REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: rig !: gradient Richardson number
  120. REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: rib !: bulk Richardson number
  121. REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: buof !: buoyancy forcing
  122. REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: mols !: moning-Obukhov length scale
  123. REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) :: ekdp !: Ekman depth
  124. #endif
  125. INTEGER :: jip = 62 , jjp = 111
  126. !! * Substitutions
  127. # include "domzgr_substitute.h90"
  128. # include "vectopt_loop_substitute.h90"
  129. # include "zdfddm_substitute.h90"
  130. !!----------------------------------------------------------------------
  131. !! NEMO/OPA 4.0 , NEMO Consortium (2011)
  132. !! $Id: zdfkpp.F90 4990 2014-12-15 16:42:49Z timgraham $
  133. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  134. !!----------------------------------------------------------------------
  135. CONTAINS
  136. INTEGER FUNCTION zdf_kpp_alloc()
  137. !!----------------------------------------------------------------------
  138. !! *** FUNCTION zdf_kpp_alloc ***
  139. !!----------------------------------------------------------------------
  140. ALLOCATE( ghats(jpi,jpj,jpk), wt0(jpi,jpj), ws0(jpi,jpj), hkpp(jpi,jpj), &
  141. #if ! defined key_kpplktb
  142. & del(jpk,jpk), &
  143. #endif
  144. & ratt(jpk), &
  145. & etmean(jpi,jpj,jpk), eumean(jpi,jpj,jpk), evmean(jpi,jpj,jpk), &
  146. #if defined key_c1d
  147. & rig (jpi,jpj,jpk), rib(jpi,jpj,jpk), buof(jpi,jpj,jpk), &
  148. & mols(jpi,jpj,jpk), ekdp(jpi,jpj), &
  149. #endif
  150. & STAT= zdf_kpp_alloc )
  151. !
  152. IF( lk_mpp ) CALL mpp_sum ( zdf_kpp_alloc )
  153. IF( zdf_kpp_alloc /= 0 ) CALL ctl_warn('zdf_kpp_alloc: failed to allocate arrays')
  154. END FUNCTION zdf_kpp_alloc
  155. SUBROUTINE zdf_kpp( kt )
  156. !!----------------------------------------------------------------------
  157. !! *** ROUTINE zdf_kpp ***
  158. !!
  159. !! ** Purpose : Compute the vertical eddy viscosity and diffusivity
  160. !! coefficients and non local mixing using K-profile parameterization
  161. !!
  162. !! ** Method : The boundary layer depth hkpp is diagnosed at tracer points
  163. !! from profiles of buoyancy, and shear, and the surface forcing.
  164. !! Above hbl (sigma=-z/hbl <1) the mixing coefficients are computed from
  165. !!
  166. !! Kx = hkpp Wx(sigma) G(sigma)
  167. !!
  168. !! and the non local term ghat = Cs / Ws(sigma) / hkpp
  169. !! Below hkpp the coefficients are the sum of mixing due to internal waves
  170. !! shear instability and double diffusion.
  171. !!
  172. !! -1- Compute the now interior vertical mixing coefficients at all depths.
  173. !! -2- Diagnose the boundary layer depth.
  174. !! -3- Compute the now boundary layer vertical mixing coefficients.
  175. !! -4- Compute the now vertical eddy vicosity and diffusivity.
  176. !! -5- Smoothing
  177. !!
  178. !! N.B. The computation is done from jk=2 to jpkm1
  179. !! Surface value of avt avmu avmv are set once a time to zero
  180. !! in routine zdf_kpp_init.
  181. !!
  182. !! ** Action : update the non-local terms ghats
  183. !! update avt, avmu, avmv (before vertical eddy coef.)
  184. !!
  185. !! References : Large W.G., Mc Williams J.C. and Doney S.C.
  186. !! Reviews of Geophysics, 32, 4, November 1994
  187. !! Comments in the code refer to this paper, particularly
  188. !! the equation number. (LMD94, here after)
  189. !!----------------------------------------------------------------------
  190. USE oce , zviscos => ua ! temp. array for viscosities use ua as workspace
  191. USE oce , zdiffut => va ! temp. array for diffusivities use sa as workspace
  192. !!
  193. INTEGER, INTENT( in ) :: kt ! ocean time step
  194. !!
  195. INTEGER :: ji, jj, jk ! dummy loop indices
  196. INTEGER :: ikbot, jkmax, jkm1, jkp2 !
  197. REAL(wp) :: ztx, zty, zflageos, zstabl, zbuofdep,zucube !
  198. REAL(wp) :: zrhos, zalbet, zbeta, zthermal, zhalin, zatt1 !
  199. REAL(wp) :: zref, zt, zs, zh, zu, zv, zrh ! Bulk richardson number
  200. REAL(wp) :: zrib, zrinum, zdVsq, zVtsq !
  201. REAL(wp) :: zehat, zeta, zhrib, zsig, zscale, zwst, zws, zwm ! Velocity scales
  202. #if defined key_kpplktb
  203. INTEGER :: il, jl ! Lookup table or Analytical functions
  204. REAL(wp) :: ud, zfrac, ufrac, zwam, zwbm, zwas, zwbs !
  205. #else
  206. REAL(wp) :: zwsun, zwmun, zcons, zconm, zwcons, zwconm !
  207. #endif
  208. REAL(wp) :: zsr, zbw, ze, zb, zd, zc, zaw, za, zb1, za1, zkw, zk0, zcomp , zrhd,zrhdr,zbvzed ! In situ density
  209. #if ! defined key_kppcustom
  210. INTEGER :: jm ! dummy loop indices
  211. REAL(wp) :: zr1, zr2, zr3, zr4, zrhop ! Compression terms
  212. #endif
  213. REAL(wp) :: zflag, ztemp, zrn2, zdep21, zdep32, zdep43
  214. REAL(wp) :: zdku2, zdkv2, ze3sqr, zsh2, zri, zfri ! Interior richardson mixing
  215. REAL(wp), POINTER, DIMENSION(:,:) :: zmoek ! Moning-Obukov limitation
  216. REAL(wp), POINTER, DIMENSION(:) :: zmoa, zekman
  217. REAL(wp) :: zmob, zek
  218. REAL(wp), POINTER, DIMENSION(:,:) :: zdepw, zdift, zvisc ! The pipe
  219. REAL(wp), POINTER, DIMENSION(:,:) :: zdept
  220. REAL(wp), POINTER, DIMENSION(:,:) :: zriblk
  221. REAL(wp), POINTER, DIMENSION(:) :: zhmax, zria, zhbl
  222. REAL(wp) :: zflagri, zflagek, zflagmo, zflagh, zflagkb !
  223. REAL(wp), POINTER, DIMENSION(:) :: za2m, za3m, zkmpm, za2t, za3t, zkmpt ! Shape function (G)
  224. REAL(wp) :: zdelta, zdelta2, zdzup, zdzdn, zdzh, zvath, zgat1, zdat1, zkm1m, zkm1t
  225. #if defined key_zdfddm
  226. REAL(wp) :: zrw, zkm1s ! local scalars
  227. REAL(wp) :: zrrau, zdt, zds, zavdds, zavddt, zinr ! double diffusion mixing
  228. REAL(wp), POINTER, DIMENSION(:,:) :: zdifs
  229. REAL(wp), POINTER, DIMENSION(:) :: za2s, za3s, zkmps
  230. REAL(wp), POINTER, DIMENSION(:,:) :: zblcs
  231. REAL(wp), POINTER, DIMENSION(:,:,:) :: zdiffus
  232. #endif
  233. REAL(wp), POINTER, DIMENSION(:,:) :: zBo, zBosol, zustar ! Surface buoyancy forcing, friction velocity
  234. REAL(wp), POINTER, DIMENSION(:,:) :: zmask, zblcm, zblct
  235. !!--------------------------------------------------------------------
  236. !
  237. IF( nn_timing == 1 ) CALL timing_start('zdf_kpp')
  238. !
  239. CALL wrk_alloc( jpi, zmoa, zekman, zhmax, zria, zhbl )
  240. CALL wrk_alloc( jpi, za2m, za3m, zkmpm, za2t, za3t, zkmpt )
  241. CALL wrk_alloc( jpi,2, zriblk )
  242. CALL wrk_alloc( jpi,3, zmoek, kjstart = 0 )
  243. CALL wrk_alloc( jpi,3, zdept )
  244. CALL wrk_alloc( jpi,4, zdepw, zdift, zvisc )
  245. CALL wrk_alloc( jpi,jpj, zBo, zBosol, zustar )
  246. CALL wrk_alloc( jpi,jpk, zmask, zblcm, zblct )
  247. #if defined key_zdfddm
  248. CALL wrk_alloc( jpi,4, zdifs )
  249. CALL wrk_alloc( jpi, zmoa, za2s, za3s, zkmps )
  250. CALL wrk_alloc( jpi,jpk, zblcs )
  251. CALL wrk_alloc( jpi,jpi,jpk, zdiffus )
  252. #endif
  253. zviscos(:,:,:) = 0._wp
  254. zblcm (:,: ) = 0._wp
  255. zdiffut(:,:,:) = 0._wp
  256. zblct (:,: ) = 0._wp
  257. #if defined key_zdfddm
  258. zdiffus(:,:,:) = 0._wp
  259. zblcs (:,: ) = 0._wp
  260. #endif
  261. ghats (:,:,:) = 0._wp
  262. zBo (:,: ) = 0._wp
  263. zBosol (:,: ) = 0._wp
  264. zustar (:,: ) = 0._wp
  265. !
  266. !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  267. ! I. Interior diffusivity and viscosity at w points ( T interfaces)
  268. !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  269. DO jk = 2, jpkm1
  270. DO jj = 2, jpjm1
  271. DO ji = fs_2, fs_jpim1
  272. ! Mixing due to internal waves breaking
  273. ! -------------------------------------
  274. avmu(ji,jj,jk) = rn_difmiw
  275. avt (ji,jj,jk) = rn_difsiw
  276. ! Mixing due to vertical shear instability
  277. ! -------------------------------------
  278. IF( ln_kpprimix ) THEN
  279. ! Compute the gradient Richardson number at interfaces (zri):
  280. ! LMD94, eq. 27 (is vertical smoothing needed : Rig=N^2 / (dz(u))^2 + (dz(v))^2
  281. zdku2 = ( un(ji - 1,jj,jk - 1) - un(ji - 1,jj,jk) ) &
  282. & * ( un(ji - 1,jj,jk - 1) - un(ji - 1,jj,jk) ) &
  283. & + ( un(ji ,jj,jk - 1) - un(ji ,jj,jk) ) &
  284. & * ( un(ji ,jj,jk - 1) - un(ji ,jj,jk) )
  285. zdkv2 = ( vn(ji,jj - 1,jk - 1) - vn(ji,jj - 1,jk) ) &
  286. & * ( vn(ji,jj - 1,jk - 1) - vn(ji,jj - 1,jk) ) &
  287. & + ( vn(ji, jj,jk - 1) - vn(ji, jj,jk) ) &
  288. & * ( vn(ji, jj,jk - 1) - vn(ji, jj,jk) )
  289. ze3sqr = 1. / ( fse3w(ji,jj,jk) * fse3w(ji,jj,jk) )
  290. ! Square of vertical shear at interfaces
  291. zsh2 = 0.5 * ( zdku2 + zdkv2 ) * ze3sqr
  292. zri = MAX( rn2(ji,jj,jk), 0. ) / ( zsh2 + epsln )
  293. #if defined key_c1d
  294. ! save the gradient richardson number
  295. rig(ji,jj,jk) = zri * tmask(ji,jj,jk)
  296. #endif
  297. ! Evaluate f of Ri (zri) for shear instability store in zfri
  298. ! LMD94, eq. 28a,b,c, figure 3 ; Rem: p1 is 3, hard coded
  299. zfri = MAX( zri , 0. )
  300. zfri = MIN( zfri / rn_riinfty , 1.0 )
  301. zfri = ( 1.0 - zfri * zfri )
  302. zfri = zfri * zfri * zfri
  303. ! add shear contribution to mixing coef.
  304. avmu(ji,jj,jk) = avmu(ji,jj,jk) + rn_difri * zfri
  305. avt (ji,jj,jk) = avt (ji,jj,jk) + rn_difri * zfri
  306. ENDIF
  307. !
  308. #if defined key_zdfddm
  309. !
  310. ! Double diffusion mixing ; NOT IN ROUTINE ZDFDDM.F90
  311. ! -------------------------
  312. avs (ji,jj,jk) = avt (ji,jj,jk)
  313. ! R=zrau = (alpha / beta) (dk[t] / dk[s])
  314. zrw = ( fsdepw(ji,jj,jk ) - fsdept(ji,jj,jk) ) &
  315. & / ( fsdept(ji,jj,jk-1) - fsdept(ji,jj,jk) )
  316. !
  317. zaw = ( rab_n(ji,jj,jk,jp_tem) * (1. - zrw) + rab_n(ji,jj,jk-1,jp_tem) * zrw ) * tmask(ji,jj,jk)
  318. zbw = ( rab_n(ji,jj,jk,jp_sal) * (1. - zrw) + rab_n(ji,jj,jk-1,jp_sal) * zrw ) * tmask(ji,jj,jk)
  319. !
  320. zdt = zaw * ( tsn(ji,jj,jk-1,jp_tem) - tsn(ji,jj,jk,jp_tem) )
  321. zds = zbw * ( tsn(ji,jj,jk-1,jp_sal) - tsn(ji,jj,jk,jp_sal) )
  322. IF( ABS( zds) <= 1.e-20_wp ) zds = 1.e-20_wp
  323. zrrau = MAX( epsln , zdt / zds ) ! only retains positive value of zrau
  324. !
  325. IF( zrrau > 1. .AND. zds > 0.) THEN ! Salt fingering case.
  326. ! !---------------------
  327. ! Compute interior diffusivity for double diffusive mixing of salinity.
  328. ! Upper bound "zrrau" by "Rrho0"; (Rrho0=1.9, difcoefnuf=0.001).
  329. ! After that set interior diffusivity for double diffusive mixing of temperature
  330. zavdds = MIN( zrrau, Rrho0 )
  331. zavdds = ( zavdds - 1.0 ) / ( Rrho0 - 1.0 )
  332. zavdds = 1.0 - zavdds * zavdds
  333. zavdds = zavdds * zavdds * zavdds
  334. zavdds = difssf * zavdds
  335. zavddt = 0.7 * zavdds
  336. !
  337. ELSEIF( zrrau < 1. .AND. zrrau > 0. .AND. zds < 0.) THEN ! Diffusive convection case.
  338. ! !---------------------------
  339. ! Compute interior diffusivity for double diffusive mixing of temperature (Marmorino and Caldwell, 1976);
  340. ! Compute interior diffusivity for double diffusive mixing of salinity
  341. zinr = 1. / zrrau
  342. zavddt = 0.909 * EXP( 4.6 * EXP( -0.54* ( zinr - 1. ) ) )
  343. zavddt = difsdc * zavddt
  344. IF( zrrau < 0.5) THEN ; zavdds = zavddt * 0.15 * zrrau
  345. ELSE ; zavdds = zavddt * (1.85 * zrrau - 0.85 )
  346. ENDIF
  347. ELSE
  348. zavddt = 0.
  349. zavdds = 0.
  350. ENDIF
  351. ! Add double diffusion contribution to temperature and salinity mixing coefficients.
  352. avt (ji,jj,jk) = avt (ji,jj,jk) + zavddt
  353. avs (ji,jj,jk) = avs (ji,jj,jk) + zavdds
  354. #endif
  355. END DO
  356. END DO
  357. END DO
  358. ! Radiative (zBosol) and non radiative (zBo) surface buoyancy
  359. !JMM at the time zdfkpp is called, q still holds the sum q + qsr
  360. !---------------------------------------------------------------------
  361. DO jj = 2, jpjm1
  362. DO ji = fs_2, fs_jpim1
  363. zrhos = rau0 * ( 1._wp + rhd(ji,jj,1) ) * tmask(ji,jj,1)
  364. zthermal = rab_n(ji,jj,1,jp_tem) / ( rcp * zrhos + epsln )
  365. zbeta = rab_n(ji,jj,1,jp_sal)
  366. zhalin = zbeta * tsn(ji,jj,1,jp_sal) * rcs
  367. !
  368. ! Radiative surface buoyancy force
  369. zBosol(ji,jj) = grav * zthermal * qsr(ji,jj)
  370. ! Non radiative surface buoyancy force
  371. zBo (ji,jj) = grav * zthermal * qns(ji,jj) - grav * zhalin * ( emp(ji,jj)-rnf(ji,jj) ) &
  372. & - grav * zbeta * rcs * sfx(ji,jj)
  373. ! Surface Temperature flux for non-local term
  374. wt0(ji,jj) = - ( qsr(ji,jj) + qns(ji,jj) )* r1_rau0_rcp * tmask(ji,jj,1)
  375. ! Surface salinity flux for non-local term
  376. ws0(ji,jj) = - ( ( emp(ji,jj)-rnf(ji,jj) ) * tsn(ji,jj,1,jp_sal) &
  377. & + sfx(ji,jj) ) * rcs * tmask(ji,jj,1)
  378. END DO
  379. END DO
  380. zflageos = 0.5 + SIGN( 0.5, nn_eos - 1. )
  381. ! Compute surface buoyancy forcing, Monin Obukhov and Ekman depths
  382. !------------------------------------------------------------------
  383. DO jj = 2, jpjm1
  384. DO ji = fs_2, fs_jpim1
  385. ! Reference surface density = density at first T point level
  386. zrhos = rhop(ji,jj,1) + zflageos * rau0 * ( 1. - tmask(ji,jj,1) )
  387. ! Friction velocity (zustar), at T-point : LMD94 eq. 2
  388. zustar(ji,jj) = SQRT( taum(ji,jj) / ( zrhos + epsln ) )
  389. END DO
  390. END DO
  391. !CDIR NOVERRCHK
  392. ! ! ===============
  393. DO jj = 2, jpjm1 ! Vertical slab
  394. ! ! ===============
  395. !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  396. ! II Compute Boundary layer mixing coef. and diagnose the new boundary layer depth
  397. !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  398. ! Initialization
  399. jkmax = 0
  400. zdept (:,:) = 0.
  401. zdepw (:,:) = 0.
  402. zriblk(:,:) = 0.
  403. zmoek (:,:) = 0.
  404. zvisc (:,:) = 0.
  405. zdift (:,:) = 0.
  406. #if defined key_zdfddm
  407. zdifs (:,:) = 0.
  408. #endif
  409. zmask (:,:) = 0.
  410. DO ji = fs_2, fs_jpim1
  411. zria(ji ) = 0.
  412. ! Maximum boundary layer depth
  413. ikbot = mbkt(ji,jj) ! ikbot is the last T point in the water
  414. zhmax(ji) = fsdept(ji,jj,ikbot) - 0.001
  415. ! Compute Monin obukhov length scale at the surface and Ekman depth:
  416. zbuofdep = zBo(ji,jj) + zBosol(ji,jj) * ratt(1)
  417. zekman(ji) = rcekman * zustar(ji,jj) / ( ABS( ff(ji,jj) ) + epsln )
  418. zucube = zustar(ji,jj) * zustar(ji,jj) * zustar(ji,jj)
  419. zmoa(ji) = zucube / ( vonk * ( zbuofdep + epsln ) )
  420. #if defined key_c1d
  421. ! store the surface buoyancy forcing
  422. zstabl = 0.5 + SIGN( 0.5, zbuofdep )
  423. buof(ji,jj,1) = zbuofdep * tmask(ji,jj,1)
  424. ! store the moning-oboukov length scale at surface
  425. zmob = zstabl * zmoa(ji) + ( 1.0 - zstabl ) * fsdept(ji,jj,1)
  426. mols(ji,jj,1) = MIN( zmob , zhmax(ji) ) * tmask(ji,jj,1)
  427. ! store Ekman depth
  428. zek = zstabl * zekman(ji) + ( 1.0 - zstabl ) * fsdept(ji,jj,1)
  429. ekdp(ji,jj ) = MIN( zek , zhmax(ji) ) * tmask(ji,jj,1)
  430. #endif
  431. END DO
  432. ! Compute the pipe
  433. ! ---------------------
  434. DO jk = 2, jpkm1
  435. DO ji = fs_2, fs_jpim1
  436. ! Compute bfsfc = Bo + radiative contribution down to hbf*depht
  437. zbuofdep = zBo(ji,jj) + zBosol(ji,jj) * ratt(jk)
  438. ! Flag (zstabl = 1) if positive forcing
  439. zstabl = 0.5 + SIGN( 0.5, zbuofdep)
  440. ! Compute bulk richardson number zrib at depht
  441. !-------------------------------------------------------
  442. ! [Br - B(d)] * d zrinum
  443. ! Rib(z) = ----------------------- = -------------
  444. ! |Vr - V(d)|^2 + Vt(d)^2 zdVsq + zVtsq
  445. !
  446. ! First compute zt,zs,zu,zv = means in the surface layer < epsilon*depht
  447. ! Else surface values are taken at the first T level.
  448. ! For stability, resolved vertical shear is computed with "before velocities".
  449. zref = epsilon * fsdept(ji,jj,jk)
  450. #if defined key_kppcustom
  451. ! zref = gdept(1)
  452. zref = fsdept(ji,jj,1)
  453. zt = tsn(ji,jj,1,jp_tem)
  454. zs = tsn(ji,jj,1,jp_sal)
  455. zrh = rhop(ji,jj,1)
  456. zu = ( ub(ji,jj,1) + ub(ji - 1,jj ,1) ) / MAX( 1. , umask(ji,jj,1) + umask(ji - 1,jj ,1) )
  457. zv = ( vb(ji,jj,1) + vb(ji ,jj - 1,1) ) / MAX( 1. , vmask(ji,jj,1) + vmask(ji ,jj - 1,1) )
  458. #else
  459. zt = 0.
  460. zs = 0.
  461. zu = 0.
  462. zv = 0.
  463. zrh = 0.
  464. ! vertically integration over the upper epsilon*gdept(jk) ; del () array is computed once in zdf_kpp_init
  465. DO jm = 1, jpkm1
  466. zt = zt + del(jk,jm) * tsn(ji,jj,jm,jp_tem)
  467. zs = zs + del(jk,jm) * tsn(ji,jj,jm,jp_sal)
  468. zu = zu + 0.5 * del(jk,jm) &
  469. & * ( ub(ji,jj,jm) + ub(ji - 1,jj,jm) ) &
  470. & / MAX( 1. , umask(ji,jj,jm) + umask(ji - 1,jj,jm) )
  471. zv = zv + 0.5 * del(jk,jm) &
  472. & * ( vb(ji,jj,jm) + vb(ji,jj - 1,jm) ) &
  473. & / MAX( 1. , vmask(ji,jj,jm) + vmask(ji,jj - 1,jm) )
  474. zrh = zrh + del(jk,jm) * rhop(ji,jj,jm)
  475. END DO
  476. #endif
  477. zsr = SQRT( ABS( tsn(ji,jj,jk,jp_sal) ) )
  478. ! depth
  479. zh = fsdept(ji,jj,jk)
  480. ! compute compression terms on density
  481. ze = ( -3.508914e-8*zt-1.248266e-8 ) *zt-2.595994e-6
  482. zbw = ( 1.296821e-6*zt-5.782165e-9 ) *zt+1.045941e-4
  483. zb = zbw + ze * zs
  484. zd = -2.042967e-2
  485. zc = (-7.267926e-5*zt+2.598241e-3 ) *zt+0.1571896
  486. zaw = ( ( 5.939910e-6*zt+2.512549e-3 ) *zt-0.1028859 ) *zt - 4.721788
  487. za = ( zd*zsr + zc ) *zs + zaw
  488. zb1 = (-0.1909078*zt+7.390729 ) *zt-55.87545
  489. za1 = ( ( 2.326469e-3*zt+1.553190)*zt-65.00517 ) *zt+1044.077
  490. zkw = ( ( (-1.361629e-4*zt-1.852732e-2 ) *zt-30.41638 ) *zt + 2098.925 ) *zt+190925.6
  491. zk0 = ( zb1*zsr + za1 )*zs + zkw
  492. zcomp = 1.0 - zh / ( zk0 - zh * ( za - zh * zb ) )
  493. #if defined key_kppcustom
  494. ! potential density of water(zrh = zt,zs at level jk):
  495. zrhdr = zrh / zcomp
  496. #else
  497. ! potential density of water(ztref,zsref at level jk):
  498. ! compute volumic mass pure water at atm pressure
  499. IF ( nn_eos < 1 ) THEN
  500. zr1= ( ( ( ( 6.536332e-9*zt-1.120083e-6 )*zt+1.001685e-4)*zt &
  501. & -9.095290e-3 )*zt+6.793952e-2 )*zt+999.842594
  502. ! seawater volumic mass atm pressure
  503. zr2= ( ( ( 5.3875e-9*zt-8.2467e-7 ) *zt+7.6438e-5 ) *zt &
  504. & -4.0899e-3 ) *zt+0.824493
  505. zr3= ( -1.6546e-6*zt+1.0227e-4 ) *zt-5.72466e-3
  506. zr4= 4.8314e-4
  507. ! potential volumic mass (reference to the surface)
  508. zrhop= ( zr4*zs + zr3*zsr + zr2 ) *zs + zr1
  509. zrhdr = zrhop / zcomp
  510. ELSE
  511. zrhdr = zrh / zcomp
  512. ENDIF
  513. #endif
  514. ! potential density of ambiant water at level jk :
  515. zrhd = ( rhd(ji,jj,jk) * rau0 + rau0 )
  516. ! And now the Rib number numerator .
  517. zrinum = grav * ( zrhd - zrhdr ) / rau0
  518. zrinum = zrinum * ( fsdept(ji,jj,jk) - zref ) * tmask(ji,jj,jk)
  519. ! Resolved shear contribution to Rib at depth T-point (zdVsq)
  520. ztx = ( ub( ji , jj ,jk) + ub(ji - 1, jj ,jk) ) &
  521. & / MAX( 1. , umask( ji , jj ,jk) + umask(ji - 1, jj ,jk) )
  522. zty = ( vb( ji , jj ,jk) + vb(ji ,jj - 1,jk) ) &
  523. & / MAX( 1., vmask( ji , jj ,jk) + vmask(ji ,jj - 1,jk) )
  524. zdVsq = ( zu - ztx ) * ( zu - ztx ) + ( zv - zty ) * ( zv - zty )
  525. ! Scalar turbulent velocity scale zws for hbl=gdept
  526. zscale = zstabl + ( 1.0 - zstabl ) * epsilon
  527. zehat = vonk * zscale * fsdept(ji,jj,jk) * zbuofdep
  528. zucube = zustar(ji,jj) * zustar(ji,jj) * zustar(ji,jj)
  529. zeta = zehat / ( zucube + epsln )
  530. IF( zehat > 0. ) THEN
  531. ! Stable case
  532. zws = vonk * zustar(ji,jj) / ( 1.0 + rconc1 * zeta )
  533. ELSE
  534. ! Unstable case
  535. #if defined key_kpplktb
  536. ! use lookup table
  537. zd = zehat - dehatmin
  538. il = INT( zd / dezehat )
  539. il = MIN( il, nilktbm1 )
  540. il = MAX( il, 1 )
  541. ud = zustar(ji,jj) - ustmin
  542. jl = INT( ud / deustar )
  543. jl = MIN( jl, njlktbm1 )
  544. jl = MAX( jl, 1 )
  545. zfrac = zd / dezehat - FLOAT( il )
  546. ufrac = ud / deustar - FLOAT( jl )
  547. zwas = ( 1. - zfrac ) * wslktb(il,jl+1) + zfrac * wslktb(il+1,jl+1)
  548. zwbs = ( 1. - zfrac ) * wslktb(il,jl ) + zfrac * wslktb(il+1,jl )
  549. !
  550. zws = ( 1. - ufrac ) * zwbs + ufrac * zwas
  551. #else
  552. ! use analytical functions:
  553. zcons = 0.5 + SIGN( 0.5 , ( rzetas - zeta ) )
  554. zwcons = vonk * zustar(ji,jj) * ( ( ABS( rconas - rconcs * zeta ) )**pthird )
  555. zwsun = vonk * zustar(ji,jj) * SQRT( ABS ( 1.0 - rconc2 * zeta ) )
  556. !
  557. zws = zcons * zwcons + ( 1.0 - zcons) * zwsun
  558. #endif
  559. ENDIF
  560. ! Turbulent shear contribution to Rib (zVtsq) bv frequency at levels ( ie T-point jk)
  561. zrn2 = 0.5 * ( rn2(ji,jj,jk) + rn2(ji,jj,jk+1) )
  562. zbvzed = SQRT( ABS( zrn2 ) )
  563. zVtsq = fsdept(ji,jj,jk) * zws * zbvzed * Vtc
  564. ! Finally, the bulk Richardson number at depth fsdept(i,j,k)
  565. zrib = zrinum / ( zdVsq + zVtsq + epsln )
  566. ! Find subscripts around the boundary layer depth, build the pipe
  567. ! ----------------------------------------------------------------
  568. ! Flag (zflagri = 1) if zrib < Ricr
  569. zflagri = 0.5 + SIGN( 0.5, ( Ricr - zrib ) )
  570. ! Flag (zflagh = 1) if still within overall boundary layer
  571. zflagh = 0.5 + SIGN( 0.5, ( fsdept(ji,jj,1) - zdept(ji,2) ) )
  572. ! Ekman layer depth
  573. zek = zstabl * zekman(ji) + ( 1.0 - zstabl ) * zhmax(ji)
  574. zflag = 0.5 + SIGN( 0.5, ( zek - fsdept(ji,jj,jk-1) ) )
  575. zek = zflag * zek + ( 1.0 - zflag ) * zhmax(ji)
  576. zflagek = 0.5 + SIGN( 0.5, ( zek - fsdept(ji,jj,jk) ) )
  577. ! Flag (zflagmo = 1) if still within stable Monin-Obukhov and in water
  578. zmob = zucube / ( vonk * ( zbuofdep + epsln ) )
  579. ztemp = zstabl * zmob + ( 1.0 - zstabl) * zhmax(ji)
  580. ztemp = MIN( ztemp , zhmax(ji) )
  581. zflagmo = 0.5 + SIGN( 0.5, ( ztemp - fsdept(ji,jj,jk) ) )
  582. ! No limitation by Monin Obukhov or Ekman depths:
  583. ! zflagek = 1.0
  584. ! zflagmo = 0.5 + SIGN( 0.5, ( zhmax(ji) - fsdept(ji,jj,jk) ) )
  585. ! Load pipe via zflagkb for later calculations
  586. ! Flag (zflagkb = 1) if zflagh = 1 and (zflagri = 0 or zflagek = 0 or zflagmo = 0)
  587. zflagkb = zflagh * ( 1.0 - ( zflagri * zflagek * zflagmo ) )
  588. zmask(ji,jk) = zflagh
  589. jkp2 = MIN( jk+2 , ikbot )
  590. jkm1 = MAX( jk-1 , 2 )
  591. jkmax = MAX( jkmax, jk * INT( REAL( zflagh+epsln ) ) )
  592. zdept(ji,1) = zdept(ji,1) + zflagkb * fsdept(ji,jj,jk-1)
  593. zdept(ji,2) = zdept(ji,2) + zflagkb * fsdept(ji,jj,jk )
  594. zdept(ji,3) = zdept(ji,3) + zflagkb * fsdept(ji,jj,jk+1)
  595. zdepw(ji,1) = zdepw(ji,1) + zflagkb * fsdepw(ji,jj,jk-1)
  596. zdepw(ji,2) = zdepw(ji,2) + zflagkb * fsdepw(ji,jj,jk )
  597. zdepw(ji,3) = zdepw(ji,3) + zflagkb * fsdepw(ji,jj,jk+1)
  598. zdepw(ji,4) = zdepw(ji,4) + zflagkb * fsdepw(ji,jj,jkp2)
  599. zriblk(ji,1) = zriblk(ji,1) + zflagkb * zria(ji)
  600. zriblk(ji,2) = zriblk(ji,2) + zflagkb * zrib
  601. zmoek (ji,0) = zmoek (ji,0) + zflagkb * zek
  602. zmoek (ji,1) = zmoek (ji,1) + zflagkb * zmoa(ji)
  603. zmoek (ji,2) = zmoek (ji,2) + zflagkb * ztemp
  604. ! Save Monin Obukhov depth
  605. zmoa (ji) = zmob
  606. zvisc(ji,1) = zvisc(ji,1) + zflagkb * avmu(ji,jj,jkm1)
  607. zvisc(ji,2) = zvisc(ji,2) + zflagkb * avmu(ji,jj,jk )
  608. zvisc(ji,3) = zvisc(ji,3) + zflagkb * avmu(ji,jj,jk+1)
  609. zvisc(ji,4) = zvisc(ji,4) + zflagkb * avmu(ji,jj,jkp2)
  610. zdift(ji,1) = zdift(ji,1) + zflagkb * avt (ji,jj,jkm1)
  611. zdift(ji,2) = zdift(ji,2) + zflagkb * avt (ji,jj,jk )
  612. zdift(ji,3) = zdift(ji,3) + zflagkb * avt (ji,jj,jk+1)
  613. zdift(ji,4) = zdift(ji,4) + zflagkb * avt (ji,jj,jkp2)
  614. #if defined key_zdfddm
  615. zdifs(ji,1) = zdifs(ji,1) + zflagkb * avs (ji,jj,jkm1)
  616. zdifs(ji,2) = zdifs(ji,2) + zflagkb * avs (ji,jj,jk )
  617. zdifs(ji,3) = zdifs(ji,3) + zflagkb * avs (ji,jj,jk+1)
  618. zdifs(ji,4) = zdifs(ji,4) + zflagkb * avs (ji,jj,jkp2)
  619. #endif
  620. ! Save the Richardson number
  621. zria (ji) = zrib
  622. #if defined key_c1d
  623. ! store buoyancy length scale
  624. buof(ji,jj,jk) = zbuofdep * tmask(ji,jj,jk)
  625. ! store Monin Obukhov
  626. zmob = zstabl * zmob + ( 1.0 - zstabl) * fsdept(ji,jj,1)
  627. mols(ji,jj,jk) = MIN( zmob , zhmax(ji) ) * tmask(ji,jj,jk)
  628. ! Bulk Richardson number
  629. rib(ji,jj,jk) = zrib * tmask(ji,jj,jk)
  630. #endif
  631. END DO
  632. END DO
  633. !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  634. ! III PROCESS THE PIPE
  635. !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  636. DO ji = fs_2, fs_jpim1
  637. ! Find the boundary layer depth zhbl
  638. ! ----------------------------------------
  639. ! Interpolate monin Obukhov and critical Ri mumber depths
  640. ztemp = zdept(ji,2) - zdept(ji,1)
  641. zflag = ( Ricr - zriblk(ji,1) ) / ( zriblk(ji,2) - zriblk(ji,1) + epsln )
  642. zhrib = zdept(ji,1) + zflag * ztemp
  643. IF( zriblk(ji,2) < Ricr ) zhrib = zhmax(ji)
  644. IF( zmoek(ji,2) < zdept(ji,2) ) THEN
  645. IF ( zmoek(ji,1) < 0. ) THEN
  646. zmob = zdept(ji,2) - epsln
  647. ELSE
  648. zmob = ztemp + zmoek(ji,1) - zmoek(ji,2)
  649. zmob = ( zmoek(ji,1) * zdept(ji,2) - zmoek(ji,2) * zdept(ji,1) ) / zmob
  650. zmob = MAX( zmob , zdept(ji,1) + epsln )
  651. ENDIF
  652. ELSE
  653. zmob = zhmax(ji)
  654. ENDIF
  655. ztemp = MIN( zmob , zmoek(ji,0) )
  656. ! Finally, the boundary layer depth, zhbl
  657. zhbl(ji) = MAX( fsdept(ji,jj,1) + epsln, MIN( zhrib , ztemp ) )
  658. ! Save hkpp for further diagnostics (optional)
  659. hkpp(ji,jj) = zhbl(ji) * tmask(ji,jj,1)
  660. ! Correct mask if zhbl < fsdepw(ji,jj,2) for no viscosity/diffusivity enhancement at fsdepw(ji,jj,2)
  661. ! zflag = 1 if zhbl(ji) > fsdepw(ji,jj,2)
  662. IF( zhbl(ji) < fsdepw(ji,jj,2) ) zmask(ji,2) = 0.
  663. ! Velocity scales at depth zhbl
  664. ! -----------------------------------
  665. ! Compute bouyancy forcing down to zhbl
  666. ztemp = -hbf * zhbl(ji)
  667. zatt1 = 1.0 - ( rabs * EXP( ztemp / xsi1 ) + ( 1.0 - rabs ) * EXP( ztemp / xsi2 ) )
  668. zbuofdep = zBo(ji,jj) + zBosol(ji,jj) * zatt1
  669. zstabl = 0.5 + SIGN( 0.5 , zbuofdep )
  670. zbuofdep = zbuofdep + zstabl * epsln
  671. zscale = zstabl + ( 1.0 - zstabl ) * epsilon
  672. zehat = vonk * zscale * zhbl(ji) * zbuofdep
  673. zucube = zustar(ji,jj) * zustar(ji,jj) * zustar(ji,jj)
  674. zeta = zehat / ( zucube + epsln )
  675. IF( zehat > 0. ) THEN
  676. ! Stable case
  677. zws = vonk * zustar(ji,jj) / ( 1.0 + rconc1 * zeta )
  678. zwm = zws
  679. ELSE
  680. ! Unstable case
  681. #if defined key_kpplktb
  682. ! use lookup table
  683. zd = zehat - dehatmin
  684. il = INT( zd / dezehat )
  685. il = MIN( il, nilktbm1 )
  686. il = MAX( il, 1 )
  687. ud = zustar(ji,jj) - ustmin
  688. jl = INT( ud / deustar )
  689. jl = MIN( jl, njlktbm1 )
  690. jl = MAX( jl, 1 )
  691. zfrac = zd / dezehat - FLOAT( il )
  692. ufrac = ud / deustar - FLOAT( jl )
  693. zwas = ( 1. - zfrac ) * wslktb(il,jl+1) + zfrac * wslktb(il+1,jl+1)
  694. zwbs = ( 1. - zfrac ) * wslktb(il,jl ) + zfrac * wslktb(il+1,jl )
  695. zwam = ( 1. - zfrac ) * wmlktb(il,jl+1) + zfrac * wmlktb(il+1,jl+1)
  696. zwbm = ( 1. - zfrac ) * wmlktb(il,jl ) + zfrac * wmlktb(il+1,jl )
  697. !
  698. zws = ( 1. - ufrac ) * zwbs + ufrac * zwas
  699. zwm = ( 1. - ufrac ) * zwbm + ufrac * zwam
  700. #else
  701. ! use analytical functions
  702. zconm = 0.5 + SIGN( 0.5, ( rzetam - zeta) )
  703. zcons = 0.5 + SIGN( 0.5, ( rzetas - zeta) )
  704. ! Momentum : zeta < rzetam (zconm = 1)
  705. ! Scalars : zeta < rzetas (zcons = 1)
  706. zwconm = zustar(ji,jj) * vonk * ( ( ABS( rconam - rconcm * zeta) )**pthird )
  707. zwcons = zustar(ji,jj) * vonk * ( ( ABS( rconas - rconcs * zeta) )**pthird )
  708. ! Momentum : rzetam <= zeta < 0 (zconm = 0)
  709. ! Scalars : rzetas <= zeta < 0 (zcons = 0)
  710. zwmun = SQRT( ABS( 1.0 - rconc2 * zeta ) )
  711. zwsun = vonk * zustar(ji,jj) * zwmun
  712. zwmun = vonk * zustar(ji,jj) * SQRT(zwmun)
  713. !
  714. zwm = zconm * zwconm + ( 1.0 - zconm ) * zwmun
  715. zws = zcons * zwcons + ( 1.0 - zcons ) * zwsun
  716. #endif
  717. ENDIF
  718. ! Viscosity, diffusivity values and derivatives at h
  719. ! --------------------------------------------------------
  720. ! check between at which interfaces is located zhbl(ji)
  721. ! ztemp = 1, zdepw(ji,2) < zhbl < zdepw(ji,3)
  722. ! ztemp = 0, zdepw(ji,1) < zhbl < zdepw(ji,2)
  723. ztemp = 0.5 + SIGN( 0.5, ( zhbl(ji) - zdepw(ji,2) ) )
  724. zdep21 = zdepw(ji,2) - zdepw(ji,1) + epsln
  725. zdep32 = zdepw(ji,3) - zdepw(ji,2) + epsln
  726. zdep43 = zdepw(ji,4) - zdepw(ji,3) + epsln
  727. ! Compute R as in LMD94, eq D5b
  728. zdelta = ( zhbl(ji) - zdepw(ji,2) ) * ztemp / zdep32 &
  729. & + ( zhbl(ji) - zdepw(ji,1) ) * ( 1.0 - ztemp ) / zdep21
  730. ! Compute the vertical derivative of viscosities (zdzh) at z=zhbl(ji)
  731. zdzup = ( zvisc(ji,2) - zvisc(ji,3) ) * ztemp / zdep32 &
  732. & + ( zvisc(ji,1) - zvisc(ji,2) ) * ( 1.0 - ztemp ) / zdep21
  733. zdzdn = ( zvisc(ji,3) - zvisc(ji,4) ) * ztemp / zdep43 &
  734. & + ( zvisc(ji,2) - zvisc(ji,3) ) * ( 1.0 - ztemp ) / zdep32
  735. ! LMD94, eq D5b :
  736. zdzh = ( 1.0 - zdelta ) * zdzup + zdelta * zdzdn
  737. zdzh = MAX( zdzh , 0. )
  738. ! Compute viscosities (zvath) at z=zhbl(ji), LMD94 eq D5a
  739. zvath = ztemp * ( zvisc(ji,3) + zdzh * ( zdepw(ji,3) - zhbl(ji) ) ) &
  740. & + ( 1.0 - ztemp ) * ( zvisc(ji,2) + zdzh * ( zdepw(ji,2) - zhbl(ji) ) )
  741. ! Compute G (zgat1) and its derivative (zdat1) at z=hbl(ji), LMD94 eq 18
  742. ! Vertical derivative of velocity scale divided by velocity scale squared at z=hbl(ji)
  743. ! (non zero only in stable conditions)
  744. zflag = -zstabl * rconc1 * zbuofdep / ( zucube * zustar(ji,jj) + epsln )
  745. ! G at its derivative at z=hbl:
  746. zgat1 = zvath / ( zhbl(ji) * ( zwm + epsln ) )
  747. zdat1 = -zdzh / ( zwm + epsln ) - zflag * zvath / zhbl(ji)
  748. ! G coefficients, LMD94 eq 17
  749. za2m(ji) = -2.0 + 3.0 * zgat1 - zdat1
  750. za3m(ji) = 1.0 - 2.0 * zgat1 + zdat1
  751. ! Compute the vertical derivative of temperature diffusivities (zdzh) at z=zhbl(ji)
  752. zdzup = ( zdift(ji,2) - zdift(ji,3) ) * ztemp / zdep32 &
  753. & + ( zdift(ji,1) - zdift(ji,2) ) * ( 1.0 - ztemp ) / zdep21
  754. zdzdn = ( zdift(ji,3) - zdift(ji,4) ) * ztemp / zdep43 &
  755. & + ( zdift(ji,2) - zdift(ji,3) ) * ( 1.0 - ztemp ) / zdep32
  756. ! LMD94, eq D5b :
  757. zdzh = ( 1.0 - zdelta ) * zdzup + zdelta * zdzdn
  758. zdzh = MAX( zdzh , 0. )
  759. ! Compute diffusivities (zvath) at z=zhbl(ji), LMD94 eq D5a
  760. zvath = ztemp * ( zdift(ji,3) + zdzh * ( zdepw(ji,3) - zhbl(ji) ) ) &
  761. & + ( 1.0 - ztemp ) * ( zdift(ji,2) + zdzh * ( zdepw(ji,2) - zhbl(ji) ) )
  762. ! G at its derivative at z=hbl:
  763. zgat1 = zvath / ( zhbl(ji) * ( zws + epsln ) )
  764. zdat1 = -zdzh / ( zws + epsln ) - zflag * zvath / zhbl(ji)
  765. ! G coefficients, LMD94 eq 17
  766. za2t(ji) = -2.0 + 3.0 * zgat1 - zdat1
  767. za3t(ji) = 1.0 - 2.0 * zgat1 + zdat1
  768. #if defined key_zdfddm
  769. ! Compute the vertical derivative of salinities diffusivities (zdzh) at z=zhbl(ji)
  770. zdzup = ( zdifs(ji,2) - zdifs(ji,3) ) * ztemp / zdep32 &
  771. & + ( zdifs(ji,1) - zdifs(ji,2) ) * ( 1.0 - ztemp ) / zdep21
  772. zdzdn = ( zdifs(ji,3) - zdifs(ji,4) ) * ztemp / zdep43 &
  773. & + ( zdifs(ji,2) - zdifs(ji,3) ) * ( 1.0 - ztemp ) / zdep32
  774. ! LMD94, eq D5b :
  775. zdzh = ( 1.0 - zdelta ) * zdzup + zdelta * zdzdn
  776. zdzh = MAX( zdzh , 0. )
  777. ! Compute diffusivities (zvath) at z=zhbl(ji), LMD94 eq D5a
  778. zvath = ztemp * ( zdifs(ji,3) + zdzh * ( zdepw(ji,3) - zhbl(ji) ) ) &
  779. & + ( 1.0 - ztemp ) * ( zdifs(ji,2) + zdzh * ( zdepw(ji,2) - zhbl(ji) ) )
  780. ! G at its derivative at z=hbl:
  781. zgat1 = zvath / ( zhbl(ji) * ( zws + epsln ) )
  782. zdat1 = -zdzh / ( zws + epsln ) - zflag * zvath / zhbl(ji)
  783. ! G coefficients, LMD94 eq 17
  784. za2s(ji) = -2.0 + 3.0 * zgat1 - zdat1
  785. za3s(ji) = 1.0 - 2.0 * zgat1 + zdat1
  786. #endif
  787. !-------------------turn off interior matching here------
  788. ! za2(ji,1) = -2.0
  789. ! za3(ji,1) = 1.0
  790. ! za2(ji,2) = -2.0
  791. ! za3(ji,2) = 1.0
  792. !--------------------------------------------------------
  793. ! Compute Enhanced Mixing Coefficients (LMD94,eq D6)
  794. ! ---------------------------------------------------------------
  795. ! Delta
  796. zdelta = ( zhbl(ji) - zdept(ji,1) ) / ( zdept(ji,2) - zdept(ji,1) + epsln )
  797. zdelta2 = zdelta * zdelta
  798. ! Mixing coefficients at first level above h (zdept(ji,1))
  799. ! and at first interface in the pipe (zdepw(ji,2))
  800. ! At first T level above h (zdept(ji,1)) (always in the boundary layer)
  801. zsig = zdept(ji,1) / zhbl(ji)
  802. ztemp = zstabl * zsig + ( 1.0 - zstabl ) * MIN( zsig , epsilon )
  803. zehat = vonk * ztemp * zhbl(ji) * zbuofdep
  804. zeta = zehat / ( zucube + epsln)
  805. zwst = vonk * zustar(ji,jj) / ( ABS( 1.0 + rconc1 * zeta ) + epsln)
  806. zwm = zstabl * zwst + ( 1.0 - zstabl ) * zwm
  807. zws = zstabl * zwst + ( 1.0 - zstabl ) * zws
  808. zkm1m = zhbl(ji) * zwm * zsig * ( 1.0 + zsig * ( za2m(ji) + zsig * za3m(ji) ) )
  809. zkm1t = zhbl(ji) * zws * zsig * ( 1.0 + zsig * ( za2t(ji) + zsig * za3t(ji) ) )
  810. #if defined key_zdfddm
  811. zkm1s = zhbl(ji) * zws * zsig * ( 1.0 + zsig * ( za2s(ji) + zsig * za3s(ji) ) )
  812. #endif
  813. ! At first W level in the pipe (zdepw(ji,2)) (not always in the boundary layer ):
  814. zsig = MIN( zdepw(ji,2) / zhbl(ji) , 1.0 )
  815. ztemp = zstabl * zsig + ( 1.0 - zstabl ) * MIN( zsig , epsilon )
  816. zehat = vonk * ztemp * zhbl(ji) * zbuofdep
  817. zeta = zehat / ( zucube + epsln )
  818. zwst = vonk * zustar(ji,jj) / ( ABS( 1.0 + rconc1 * zeta ) + epsln)
  819. zws = zstabl * zws + ( 1.0 - zstabl ) * zws
  820. zwm = zstabl * zws + ( 1.0 - zstabl ) * zwm
  821. zkmpm(ji) = zhbl(ji) * zwm * zsig * ( 1.0 + zsig * ( za2m(ji) + zsig * za3m(ji) ) )
  822. zkmpt(ji) = zhbl(ji) * zws * zsig * ( 1.0 + zsig * ( za2t(ji) + zsig * za3t(ji) ) )
  823. #if defined key_zdfddm
  824. zkmps(ji) = zhbl(ji) * zws * zsig * ( 1.0 + zsig * ( za2s(ji) + zsig * za3s(ji) ) )
  825. #endif
  826. ! check if this point is in the boundary layer,else take interior viscosity/diffusivity:
  827. zflag = 0.5 + SIGN( 0.5, ( zhbl(ji) - zdepw(ji,2) ) )
  828. zkmpm(ji) = zkmpm(ji) * zflag + ( 1.0 - zflag ) * zvisc(ji,2)
  829. zkmpt(ji) = zkmpt(ji) * zflag + ( 1.0 - zflag ) * zdift(ji,2)
  830. #if defined key_zdfddm
  831. zkmps(ji) = zkmps(ji) * zflag + ( 1.0 - zflag ) * zdifs(ji,2)
  832. #endif
  833. ! Enhanced viscosity/diffusivity at zdepw(ji,2)
  834. ztemp = ( 1.0 - 2.0 * zdelta + zdelta2 ) * zkm1m + zdelta2 * zkmpm(ji)
  835. zkmpm(ji) = ( 1.0 - zdelta ) * zvisc(ji,2) + zdelta * ztemp
  836. ztemp = ( 1.0 - 2.0 * zdelta + zdelta2 ) * zkm1t + zdelta2 * zkmpt(ji)
  837. zkmpt(ji) = ( 1.0 - zdelta ) * zdift(ji,2) + zdelta * ztemp
  838. #if defined key_zdfddm
  839. ztemp = ( 1.0 - 2.0 * zdelta + zdelta2 ) * zkm1s + zdelta2 * zkmps(ji)
  840. zkmps(ji) = ( 1.0 - zdelta ) * zdifs(ji,2) + zdelta * ztemp
  841. #endif
  842. END DO
  843. !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  844. ! IV. Compute vertical eddy viscosity and diffusivity coefficients
  845. !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  846. DO jk = 2, jkmax
  847. ! Compute turbulent velocity scales on the interfaces
  848. ! --------------------------------------------------------
  849. DO ji = fs_2, fs_jpim1
  850. zbuofdep = zBo(ji,jj) + zBosol(ji,jj) * zatt1
  851. zstabl = 0.5 + SIGN( 0.5 , zbuofdep )
  852. zbuofdep = zbuofdep + zstabl * epsln
  853. zsig = fsdepw(ji,jj,jk) / zhbl(ji)
  854. ztemp = zstabl * zsig + ( 1. - zstabl ) * MIN( zsig , epsilon )
  855. zehat = vonk * ztemp * zhbl(ji) * zbuofdep
  856. zucube = zustar(ji,jj) * zustar(ji,jj) * zustar(ji,jj)
  857. zeta = zehat / ( zucube + epsln )
  858. IF( zehat > 0. ) THEN
  859. ! Stable case
  860. zws = vonk * zustar(ji,jj) / ( 1.0 + rconc1 * zeta )
  861. zwm = zws
  862. ELSE
  863. ! Unstable case
  864. #if defined key_kpplktb
  865. ! use lookup table
  866. zd = zehat - dehatmin
  867. il = INT( zd / dezehat )
  868. il = MIN( il, nilktbm1 )
  869. il = MAX( il, 1 )
  870. ud = zustar(ji,jj) - ustmin
  871. jl = INT( ud / deustar )
  872. jl = MIN( jl, njlktbm1 )
  873. jl = MAX( jl, 1 )
  874. zfrac = zd / dezehat - FLOAT( il )
  875. ufrac = ud / deustar - FLOAT( jl )
  876. zwas = ( 1. - zfrac ) * wslktb(il,jl+1) + zfrac * wslktb(il+1,jl+1)
  877. zwbs = ( 1. - zfrac ) * wslktb(il,jl ) + zfrac * wslktb(il+1,jl )
  878. zwam = ( 1. - zfrac ) * wmlktb(il,jl+1) + zfrac * wmlktb(il+1,jl+1)
  879. zwbm = ( 1. - zfrac ) * wmlktb(il,jl ) + zfrac * wmlktb(il+1,jl )
  880. !
  881. zws = ( 1. - ufrac ) * zwbs + ufrac * zwas
  882. zwm = ( 1. - ufrac ) * zwbm + ufrac * zwam
  883. #else
  884. ! use analytical functions
  885. zconm = 0.5 + SIGN( 0.5, ( rzetam - zeta) )
  886. zcons = 0.5 + SIGN( 0.5, ( rzetas - zeta) )
  887. ! Momentum : zeta < rzetam (zconm = 1)
  888. ! Scalars : zeta < rzetas (zcons = 1)
  889. zwconm = zustar(ji,jj) * vonk * ( ( ABS( rconam - rconcm * zeta) )**pthird )
  890. zwcons = zustar(ji,jj) * vonk * ( ( ABS( rconas - rconcs * zeta) )**pthird )
  891. ! Momentum : rzetam <= zeta < 0 (zconm = 0)
  892. ! Scalars : rzetas <= zeta < 0 (zcons = 0)
  893. zwmun = SQRT( ABS( 1.0 - rconc2 * zeta ) )
  894. zwsun = vonk * zustar(ji,jj) * zwmun
  895. zwmun = vonk * zustar(ji,jj) * SQRT(zwmun)
  896. !
  897. zwm = zconm * zwconm + ( 1.0 - zconm ) * zwmun
  898. zws = zcons * zwcons + ( 1.0 - zcons ) * zwsun
  899. #endif
  900. ENDIF
  901. zblcm(ji,jk) = zhbl(ji) * zwm * zsig * ( 1.0 + zsig * ( za2m(ji) + zsig * za3m(ji) ) )
  902. zblct(ji,jk) = zhbl(ji) * zws * zsig * ( 1.0 + zsig * ( za2t(ji) + zsig * za3t(ji) ) )
  903. #if defined key_zdfddm
  904. zblcs(ji,jk) = zhbl(ji) * zws * zsig * ( 1.0 + zsig * ( za2s(ji) + zsig * za3s(ji) ) )
  905. #endif
  906. ! Compute Nonlocal transport term = ghats * <ws>o
  907. ! ----------------------------------------------------
  908. ghats(ji,jj,jk-1) = ( 1. - zstabl ) * rcg / ( zws * zhbl(ji) + epsln ) * tmask(ji,jj,jk)
  909. END DO
  910. END DO
  911. ! Combine interior and boundary layer coefficients and nonlocal term
  912. ! -----------------------------------------------------------------------
  913. DO jk = 2, jpkm1
  914. DO ji = fs_2, fs_jpim1
  915. zflag = zmask(ji,jk) * zmask(ji,jk+1)
  916. zviscos(ji,jj,jk) = ( 1.0 - zmask(ji,jk) ) * avmu (ji,jj,jk) & ! interior viscosities
  917. & + zflag * zblcm(ji,jk ) & ! boundary layer viscosities
  918. & + zmask(ji,jk) * ( 1.0 - zflag ) * zkmpm(ji ) ! viscosity enhancement at W_level near zhbl
  919. zviscos(ji,jj,jk) = zviscos(ji,jj,jk) * tmask(ji,jj,jk)
  920. zdiffut(ji,jj,jk) = ( 1.0 - zmask(ji,jk) ) * avt (ji,jj,jk) & ! interior diffusivities
  921. & + zflag * zblct(ji,jk ) & ! boundary layer diffusivities
  922. & + zmask(ji,jk) * ( 1.0 - zflag ) * zkmpt(ji ) ! diffusivity enhancement at W_level near zhbl
  923. zdiffut(ji,jj,jk) = zdiffut(ji,jj,jk) * tmask(ji,jj,jk)
  924. #if defined key_zdfddm
  925. zdiffus(ji,jj,jk) = ( 1.0 - zmask(ji,jk) ) * avs (ji,jj,jk) & ! interior diffusivities
  926. & + zflag * zblcs(ji,jk ) & ! boundary layer diffusivities
  927. & + zmask(ji,jk) * ( 1.0 - zflag ) * zkmps(ji ) ! diffusivity enhancement at W_level near zhbl
  928. zdiffus(ji,jj,jk) = zdiffus(ji,jj,jk) * tmask(ji,jj,jk)
  929. #endif
  930. ! Non local flux in the boundary layer only
  931. ghats(ji,jj,jk-1) = zmask(ji,jk) * ghats(ji,jj,jk-1)
  932. ENDDO
  933. END DO
  934. ! ! ===============
  935. END DO ! End of slab
  936. ! ! ===============
  937. ! Lateral boundary conditions on zvicos and zdiffus (sign unchanged)
  938. CALL lbc_lnk( zviscos(:,:,:), 'U', 1. ) ; CALL lbc_lnk( zdiffut(:,:,:), 'W', 1. )
  939. #if defined key_zdfddm
  940. CALL lbc_lnk( zdiffus(:,:,:), 'W', 1. )
  941. #endif
  942. SELECT CASE ( nn_ave )
  943. !
  944. CASE ( 0 ) ! no viscosity and diffusivity smoothing
  945. DO jk = 2, jpkm1
  946. DO jj = 2, jpjm1
  947. DO ji = fs_2, fs_jpim1
  948. avmu(ji,jj,jk) = ( zviscos(ji,jj,jk) + zviscos(ji+1,jj,jk) ) &
  949. & / MAX( 1., tmask(ji,jj,jk) + tmask (ji + 1,jj,jk) ) * umask(ji,jj,jk)
  950. avmv(ji,jj,jk) = ( zviscos(ji,jj,jk) + zviscos(ji,jj+1,jk) ) &
  951. & / MAX( 1., tmask(ji,jj,jk) + tmask (ji,jj+1,jk) ) * vmask(ji,jj,jk)
  952. avt (ji,jj,jk) = zdiffut(ji,jj,jk) * tmask(ji,jj,jk)
  953. #if defined key_zdfddm
  954. avs (ji,jj,jk) = zdiffus(ji,jj,jk) * tmask(ji,jj,jk)
  955. #endif
  956. END DO
  957. END DO
  958. END DO
  959. CASE ( 1 ) ! viscosity and diffusivity smoothing
  960. !
  961. ! ( 1/2 1 1/2 ) ( 1/2 1/2 ) ( 1/2 1 1/2 )
  962. ! avt = 1/8 ( 1 2 1 ) avmu = 1/4 ( 1 1 ) avmv= 1/4 ( 1/2 1 1/2 )
  963. ! ( 1/2 1 1/2 ) ( 1/2 1/2 )
  964. DO jk = 2, jpkm1
  965. DO jj = 2, jpjm1
  966. DO ji = fs_2, fs_jpim1
  967. avmu(ji,jj,jk) = ( zviscos(ji ,jj ,jk) + zviscos(ji+1,jj ,jk) &
  968. & +.5*( zviscos(ji ,jj-1,jk) + zviscos(ji+1,jj-1,jk) &
  969. & +zviscos(ji ,jj+1,jk) + zviscos(ji+1,jj+1,jk) ) ) * eumean(ji,jj,jk)
  970. avmv(ji,jj,jk) = ( zviscos(ji ,jj ,jk) + zviscos(ji ,jj+1,jk) &
  971. & +.5*( zviscos(ji-1,jj ,jk) + zviscos(ji-1,jj+1,jk) &
  972. & +zviscos(ji+1,jj ,jk) + zviscos(ji+1,jj+1,jk) ) ) * evmean(ji,jj,jk)
  973. avt (ji,jj,jk) = ( .5*( zdiffut(ji-1,jj+1,jk) + zdiffut(ji-1,jj-1,jk) &
  974. & +zdiffut(ji+1,jj+1,jk) + zdiffut(ji+1,jj-1,jk) ) &
  975. & +1.*( zdiffut(ji-1,jj ,jk) + zdiffut(ji ,jj+1,jk) &
  976. & +zdiffut(ji ,jj-1,jk) + zdiffut(ji+1,jj ,jk) ) &
  977. & +2.* zdiffut(ji ,jj ,jk) ) * etmean(ji,jj,jk)
  978. #if defined key_zdfddm
  979. avs (ji,jj,jk) = ( .5*( zdiffus(ji-1,jj+1,jk) + zdiffus(ji-1,jj-1,jk) &
  980. & +zdiffus(ji+1,jj+1,jk) + zdiffus(ji+1,jj-1,jk) ) &
  981. & +1.*( zdiffus(ji-1,jj ,jk) + zdiffus(ji ,jj+1,jk) &
  982. & +zdiffus(ji ,jj-1,jk) + zdiffus(ji+1,jj ,jk) ) &
  983. & +2.* zdiffus(ji ,jj ,jk) ) * etmean(ji,jj,jk)
  984. #endif
  985. END DO
  986. END DO
  987. END DO
  988. END SELECT
  989. DO jk = 2, jpkm1 ! vertical slab
  990. !
  991. ! Minimum value on the eddy diffusivity
  992. ! ----------------------------------------
  993. DO jj = 2, jpjm1
  994. DO ji = fs_2, fs_jpim1 ! vector opt.
  995. avt(ji,jj,jk) = MAX( avt(ji,jj,jk), avtb(jk) ) * tmask(ji,jj,jk)
  996. #if defined key_zdfddm
  997. avs(ji,jj,jk) = MAX( avs(ji,jj,jk), avtb(jk) ) * tmask(ji,jj,jk)
  998. #endif
  999. END DO
  1000. END DO
  1001. !
  1002. ! Minimum value on the eddy viscosity
  1003. ! ----------------------------------------
  1004. DO jj = 1, jpj
  1005. DO ji = 1, jpi
  1006. avmu(ji,jj,jk) = MAX( avmu(ji,jj,jk), avmb(jk) ) * umask(ji,jj,jk)
  1007. avmv(ji,jj,jk) = MAX( avmv(ji,jj,jk), avmb(jk) ) * vmask(ji,jj,jk)
  1008. END DO
  1009. END DO
  1010. !
  1011. END DO
  1012. ! Lateral boundary conditions on avt (sign unchanged)
  1013. CALL lbc_lnk( hkpp(:,:), 'T', 1. )
  1014. ! Lateral boundary conditions on avt (sign unchanged)
  1015. CALL lbc_lnk( avt(:,:,:), 'W', 1. )
  1016. #if defined key_zdfddm
  1017. CALL lbc_lnk( avs(:,:,:), 'W', 1. )
  1018. #endif
  1019. ! Lateral boundary conditions (avmu,avmv) (U- and V- points, sign unchanged)
  1020. CALL lbc_lnk( avmu(:,:,:), 'U', 1. ) ; CALL lbc_lnk( avmv(:,:,:), 'V', 1. )
  1021. IF(ln_ctl) THEN
  1022. #if defined key_zdfddm
  1023. CALL prt_ctl(tab3d_1=avt , clinfo1=' kpp - t: ', tab3d_2=avs , clinfo2=' s: ', ovlap=1, kdim=jpk)
  1024. #else
  1025. CALL prt_ctl(tab3d_1=avt , clinfo1=' kpp - t: ', ovlap=1, kdim=jpk)
  1026. #endif
  1027. CALL prt_ctl(tab3d_1=avmu, clinfo1=' kpp - u: ', mask1=umask, &
  1028. & tab3d_2=avmv, clinfo2= ' v: ', mask2=vmask, ovlap=1, kdim=jpk)
  1029. ENDIF
  1030. CALL wrk_dealloc( jpi, zmoa, zekman, zhmax, zria, zhbl )
  1031. CALL wrk_dealloc( jpi, za2m, za3m, zkmpm, za2t, za3t, zkmpt )
  1032. CALL wrk_dealloc( jpi,2, zriblk )
  1033. CALL wrk_dealloc( jpi,3, zmoek, kjstart = 0 )
  1034. CALL wrk_dealloc( jpi,3, zdept )
  1035. CALL wrk_dealloc( jpi,4, zdepw, zdift, zvisc )
  1036. CALL wrk_dealloc( jpi,jpj, zBo, zBosol, zustar )
  1037. CALL wrk_dealloc( jpi,jpk, zmask, zblcm, zblct )
  1038. #if defined key_zdfddm
  1039. CALL wrk_dealloc( jpi,4, zdifs )
  1040. CALL wrk_dealloc( jpi, zmoa, za2s, za3s, zkmps )
  1041. CALL wrk_dealloc( jpi,jpk, zblcs )
  1042. CALL wrk_dealloc( jpi,jpi,jpk, zdiffus )
  1043. #endif
  1044. !
  1045. IF( nn_timing == 1 ) CALL timing_stop('zdf_kpp')
  1046. !
  1047. END SUBROUTINE zdf_kpp
  1048. SUBROUTINE tra_kpp( kt )
  1049. !!----------------------------------------------------------------------
  1050. !! *** ROUTINE tra_kpp ***
  1051. !!
  1052. !! ** Purpose : compute and add to the tracer trend the non-local tracer flux
  1053. !!
  1054. !! ** Method : ???
  1055. !!----------------------------------------------------------------------
  1056. REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: ztrdt, ztrds ! 3D workspace
  1057. !!----------------------------------------------------------------------
  1058. INTEGER, INTENT(in) :: kt
  1059. INTEGER :: ji, jj, jk
  1060. !
  1061. IF( nn_timing == 1 ) CALL timing_start('tra_kpp')
  1062. !
  1063. IF( kt == nit000 ) THEN
  1064. IF(lwp) WRITE(numout,*)
  1065. IF(lwp) WRITE(numout,*) 'tra_kpp : KPP non-local tracer fluxes'
  1066. IF(lwp) WRITE(numout,*) '~~~~~~~ '
  1067. ENDIF
  1068. IF( l_trdtra ) THEN !* Save ta and sa trends
  1069. ALLOCATE( ztrdt(jpi,jpj,jpk) ) ; ztrdt(:,:,:) = tsa(:,:,:,jp_tem)
  1070. ALLOCATE( ztrds(jpi,jpj,jpk) ) ; ztrds(:,:,:) = tsa(:,:,:,jp_sal)
  1071. ENDIF
  1072. ! add non-local temperature and salinity flux ( in convective case only)
  1073. DO jk = 1, jpkm1
  1074. DO jj = 2, jpjm1
  1075. DO ji = fs_2, fs_jpim1
  1076. tsa(ji,jj,jk,jp_tem) = tsa(ji,jj,jk,jp_tem) &
  1077. & - ( ghats(ji,jj,jk ) * avt (ji,jj,jk ) &
  1078. & - ghats(ji,jj,jk+1) * avt (ji,jj,jk+1) ) * wt0(ji,jj) / fse3t(ji,jj,jk)
  1079. tsa(ji,jj,jk,jp_sal) = tsa(ji,jj,jk,jp_sal) &
  1080. & - ( ghats(ji,jj,jk ) * fsavs(ji,jj,jk ) &
  1081. & - ghats(ji,jj,jk+1) * fsavs(ji,jj,jk+1) ) * ws0(ji,jj) / fse3t(ji,jj,jk)
  1082. END DO
  1083. END DO
  1084. END DO
  1085. ! save the non-local tracer flux trends for diagnostic
  1086. IF( l_trdtra ) THEN
  1087. ztrdt(:,:,:) = tsa(:,:,:,jp_tem) - ztrdt(:,:,:)
  1088. ztrds(:,:,:) = tsa(:,:,:,jp_sal) - ztrds(:,:,:)
  1089. !!bug gm jpttdzdf ==> jpttkpp
  1090. CALL trd_tra( kt, 'TRA', jp_tem, jptra_zdf, ztrdt )
  1091. CALL trd_tra( kt, 'TRA', jp_sal, jptra_zdf, ztrds )
  1092. DEALLOCATE( ztrdt ) ; DEALLOCATE( ztrds )
  1093. ENDIF
  1094. IF(ln_ctl) THEN
  1095. CALL prt_ctl( tab3d_1=tsa(:,:,:,jp_tem), clinfo1=' kpp - Ta: ', mask1=tmask, &
  1096. & tab3d_2=tsa(:,:,:,jp_sal), clinfo2= ' Sa: ', mask2=tmask, clinfo3='tra' )
  1097. ENDIF
  1098. !
  1099. IF( nn_timing == 1 ) CALL timing_stop('tra_kpp')
  1100. !
  1101. END SUBROUTINE tra_kpp
  1102. #if defined key_top
  1103. !!----------------------------------------------------------------------
  1104. !! 'key_top' TOP models
  1105. !!----------------------------------------------------------------------
  1106. SUBROUTINE trc_kpp( kt )
  1107. !!----------------------------------------------------------------------
  1108. !! *** ROUTINE trc_kpp ***
  1109. !!
  1110. !! ** Purpose : compute and add to the tracer trend the non-local
  1111. !! tracer flux
  1112. !!
  1113. !! ** Method : ???
  1114. !!
  1115. !! history :
  1116. !! 9.0 ! 2005-11 (G. Madec) Original code
  1117. !! NEMO 3.3 ! 2010-06 (C. Ethe ) Adapted to passive tracers
  1118. !!----------------------------------------------------------------------
  1119. USE trc
  1120. USE prtctl_trc ! Print control
  1121. !
  1122. INTEGER, INTENT(in) :: kt ! ocean time-step index
  1123. !
  1124. INTEGER :: ji, jj, jk, jn ! Dummy loop indices
  1125. CHARACTER (len=35) :: charout
  1126. REAL(wp) :: ztra, zflx
  1127. REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: ztrtrd
  1128. !!----------------------------------------------------------------------
  1129. IF( kt == nit000 ) THEN
  1130. IF(lwp) WRITE(numout,*)
  1131. IF(lwp) WRITE(numout,*) 'trc_kpp : KPP non-local tracer fluxes'
  1132. IF(lwp) WRITE(numout,*) '~~~~~~~ '
  1133. ENDIF
  1134. IF( l_trdtrc ) ALLOCATE( ztrtrd(jpi,jpj,jpk) )
  1135. !
  1136. DO jn = 1, jptra
  1137. !
  1138. IF( l_trdtrc ) ztrtrd(:,:,:) = tra(:,:,:,jn)
  1139. ! add non-local on passive tracer flux ( in convective case only)
  1140. DO jk = 1, jpkm1
  1141. DO jj = 2, jpjm1
  1142. DO ji = fs_2, fs_jpim1
  1143. ! Surface tracer flux for non-local term
  1144. zflx = - ( sfx (ji,jj) * tra(ji,jj,1,jn) * rcs ) * tmask(ji,jj,1)
  1145. ! compute the trend
  1146. ztra = - ( ghats(ji,jj,jk ) * fsavs(ji,jj,jk ) &
  1147. & - ghats(ji,jj,jk+1) * fsavs(ji,jj,jk+1) ) * zflx / fse3t(ji,jj,jk)
  1148. ! add the trend to the general trend
  1149. tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn) + ztra
  1150. END DO
  1151. END DO
  1152. END DO
  1153. !
  1154. IF( l_trdtrc ) THEN ! save the non-local tracer flux trends for diagnostic
  1155. ztrtrd(:,:,:) = tra(:,:,:,jn) - ztrtrd(:,:,:)
  1156. CALL trd_tra( kt, 'TRC', jn, jptra_zdf, ztrtrd(:,:,:) )
  1157. ENDIF
  1158. !
  1159. END DO
  1160. IF( l_trdtrc ) DEALLOCATE( ztrtrd )
  1161. IF( ln_ctl ) THEN
  1162. WRITE(charout, FMT="(' kpp')") ; CALL prt_ctl_trc_info(charout)
  1163. CALL prt_ctl_trc( tab4d=tra, mask=tmask, clinfo=ctrcnm, clinfo2='trd' )
  1164. ENDIF
  1165. !
  1166. END SUBROUTINE trc_kpp
  1167. #else
  1168. !!----------------------------------------------------------------------
  1169. !! NO 'key_top' DUMMY routine No TOP models
  1170. !!----------------------------------------------------------------------
  1171. SUBROUTINE trc_kpp( kt ) ! Dummy routine
  1172. INTEGER, INTENT(in) :: kt ! ocean time-step index
  1173. WRITE(*,*) 'tra_kpp: You should not have seen this print! error?', kt
  1174. END SUBROUTINE trc_kpp
  1175. #endif
  1176. SUBROUTINE zdf_kpp_init
  1177. !!----------------------------------------------------------------------
  1178. !! *** ROUTINE zdf_kpp_init ***
  1179. !!
  1180. !! ** Purpose : Initialization of the vertical eddy diffivity and
  1181. !! viscosity when using a kpp turbulent closure scheme
  1182. !!
  1183. !! ** Method : Read the namkpp namelist and check the parameters
  1184. !! called at the first timestep (nit000)
  1185. !!
  1186. !! ** input : Namlist namkpp
  1187. !!----------------------------------------------------------------------
  1188. INTEGER :: ji, jj, jk ! dummy loop indices
  1189. INTEGER :: ios ! local integer
  1190. #if ! defined key_kppcustom
  1191. INTEGER :: jm ! dummy loop indices
  1192. REAL(wp) :: zref, zdist ! tempory scalars
  1193. #endif
  1194. #if defined key_kpplktb
  1195. REAL(wp) :: zustar, zucube, zustvk, zeta, zehat ! tempory scalars
  1196. #endif
  1197. REAL(wp) :: zhbf ! tempory scalars
  1198. LOGICAL :: ll_kppcustom ! 1st ocean level taken as surface layer
  1199. LOGICAL :: ll_kpplktb ! Lookup table for turbul. velocity scales
  1200. !!
  1201. NAMELIST/namzdf_kpp/ ln_kpprimix, rn_difmiw, rn_difsiw, rn_riinfty, rn_difri, rn_bvsqcon, rn_difcon, nn_ave
  1202. !!----------------------------------------------------------------------
  1203. !
  1204. IF( nn_timing == 1 ) CALL timing_start('zdf_kpp_init')
  1205. !
  1206. REWIND( numnam_ref ) ! Namelist namzdf_kpp in reference namelist : Vertical eddy diffivity and viscosity using kpp turbulent closure scheme
  1207. READ ( numnam_ref, namzdf_kpp, IOSTAT = ios, ERR = 901)
  1208. 901 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_kpp in reference namelist', lwp )
  1209. REWIND( numnam_cfg ) ! Namelist namzdf_kpp in configuration namelist : Vertical eddy diffivity and viscosity using kpp turbulent closure scheme
  1210. READ ( numnam_cfg, namzdf_kpp, IOSTAT = ios, ERR = 902 )
  1211. 902 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_kpp in configuration namelist', lwp )
  1212. IF(lwm) WRITE ( numond, namzdf_kpp )
  1213. IF(lwp) THEN ! Control print
  1214. WRITE(numout,*)
  1215. WRITE(numout,*) 'zdf_kpp_init : K-Profile Parameterisation'
  1216. WRITE(numout,*) '~~~~~~~~~~~~'
  1217. WRITE(numout,*) ' Namelist namzdf_kpp : set tke mixing parameters'
  1218. WRITE(numout,*) ' Shear instability mixing ln_kpprimix = ', ln_kpprimix
  1219. WRITE(numout,*) ' max. internal wave viscosity rn_difmiw = ', rn_difmiw
  1220. WRITE(numout,*) ' max. internal wave diffusivity rn_difsiw = ', rn_difsiw
  1221. WRITE(numout,*) ' Richardson Number limit for shear instability rn_riinfty = ', rn_riinfty
  1222. WRITE(numout,*) ' max. shear mixing at Rig = 0 rn_difri = ', rn_difri
  1223. WRITE(numout,*) ' Brunt-Vaisala squared for max. convection rn_bvsqcon = ', rn_bvsqcon
  1224. WRITE(numout,*) ' max. mix. in interior convec. rn_difcon = ', rn_difcon
  1225. WRITE(numout,*) ' horizontal average flag nn_ave = ', nn_ave
  1226. ENDIF
  1227. ! ! allocate zdfkpp arrays
  1228. IF( zdf_kpp_alloc() /= 0 ) CALL ctl_stop( 'STOP', 'zdf_kpp_init : unable to allocate arrays' )
  1229. ll_kppcustom = .FALSE.
  1230. ll_kpplktb = .FALSE.
  1231. #if defined key_kppcustom
  1232. ll_kppcustom = .TRUE.
  1233. #endif
  1234. #if defined key_kpplktb
  1235. ll_kpplktb = .TRUE.
  1236. #endif
  1237. IF(lwp) THEN
  1238. WRITE(numout,*) ' Lookup table for turbul. velocity scales ll_kpplktb = ', ll_kpplktb
  1239. WRITE(numout,*) ' 1st ocean level taken as surface layer ll_kppcustom = ', ll_kppcustom
  1240. ENDIF
  1241. IF( lk_zdfddm) THEN
  1242. IF(lwp) THEN
  1243. WRITE(numout,*)
  1244. WRITE(numout,*) ' Double diffusion mixing on temperature and salinity '
  1245. WRITE(numout,*) ' CAUTION : done in routine zdfkpp, not in routine zdfddm '
  1246. ENDIF
  1247. ENDIF
  1248. !set constants not in namelist
  1249. !-----------------------------
  1250. Vtc = rconcv * SQRT( 0.2 / ( rconcs * epsilon ) ) / ( vonk * vonk * Ricr )
  1251. rcg = rcstar * vonk * ( rconcs * vonk * epsilon )**pthird
  1252. IF(lwp) THEN
  1253. WRITE(numout,*)
  1254. WRITE(numout,*) ' Constant value for unreso. turbul. velocity shear Vtc = ', Vtc
  1255. WRITE(numout,*) ' Non-dimensional coef. for nonlocal transport rcg = ', rcg
  1256. ENDIF
  1257. ! ratt is the attenuation coefficient for solar flux
  1258. ! Should be different is s_coordinate
  1259. DO jk = 1, jpk
  1260. zhbf = - fsdept(1,1,jk) * hbf
  1261. ratt(jk) = 1.0 - ( rabs * EXP( zhbf / xsi1 ) + ( 1.0 - rabs ) * EXP( zhbf / xsi2 ) )
  1262. ENDDO
  1263. ! Horizontal average : initialization of weighting arrays
  1264. ! -------------------
  1265. SELECT CASE ( nn_ave )
  1266. CASE ( 0 ) ! no horizontal average
  1267. IF(lwp) WRITE(numout,*) ' no horizontal average on avt, avmu, avmv'
  1268. IF(lwp) WRITE(numout,*) ' only in very high horizontal resolution !'
  1269. ! weighting mean arrays etmean, eumean and evmean
  1270. ! ( 1 1 ) ( 1 )
  1271. ! avt = 1/4 ( 1 1 ) avmu = 1/2 ( 1 1 ) avmv= 1/2 ( 1 )
  1272. !
  1273. etmean(:,:,:) = 0.e0
  1274. eumean(:,:,:) = 0.e0
  1275. evmean(:,:,:) = 0.e0
  1276. DO jk = 1, jpkm1
  1277. DO jj = 2, jpjm1
  1278. DO ji = 2, jpim1 ! vector opt.
  1279. etmean(ji,jj,jk) = tmask(ji,jj,jk) &
  1280. & / MAX( 1., umask(ji-1,jj ,jk) + umask(ji,jj,jk) &
  1281. & + vmask(ji ,jj-1,jk) + vmask(ji,jj,jk) )
  1282. eumean(ji,jj,jk) = umask(ji,jj,jk) &
  1283. & / MAX( 1., tmask(ji,jj,jk) + tmask(ji+1,jj ,jk) )
  1284. evmean(ji,jj,jk) = vmask(ji,jj,jk) &
  1285. & / MAX( 1., tmask(ji,jj,jk) + tmask(ji ,jj+1,jk) )
  1286. END DO
  1287. END DO
  1288. END DO
  1289. CASE ( 1 ) ! horizontal average
  1290. IF(lwp) WRITE(numout,*) ' horizontal average on avt, avmu, avmv'
  1291. ! weighting mean arrays etmean, eumean and evmean
  1292. ! ( 1/2 1 1/2 ) ( 1/2 1/2 ) ( 1/2 1 1/2 )
  1293. ! avt = 1/8 ( 1 2 1 ) avmu = 1/4 ( 1 1 ) avmv= 1/4 ( 1/2 1 1/2 )
  1294. ! ( 1/2 1 1/2 ) ( 1/2 1/2 )
  1295. etmean(:,:,:) = 0.e0
  1296. eumean(:,:,:) = 0.e0
  1297. evmean(:,:,:) = 0.e0
  1298. DO jk = 1, jpkm1
  1299. DO jj = 2, jpjm1
  1300. DO ji = fs_2, fs_jpim1 ! vector opt.
  1301. etmean(ji,jj,jk) = tmask(ji, jj,jk) &
  1302. & / MAX( 1., 2.* tmask(ji,jj,jk) &
  1303. & +.5 * ( tmask(ji-1,jj+1,jk) + tmask(ji-1,jj-1,jk) &
  1304. & +tmask(ji+1,jj+1,jk) + tmask(ji+1,jj-1,jk) ) &
  1305. & +1. * ( tmask(ji-1,jj ,jk) + tmask(ji ,jj+1,jk) &
  1306. & +tmask(ji ,jj-1,jk) + tmask(ji+1,jj ,jk) ) )
  1307. eumean(ji,jj,jk) = umask(ji,jj,jk) &
  1308. & / MAX( 1., tmask(ji,jj ,jk) + tmask(ji+1,jj ,jk) &
  1309. & +.5 * ( tmask(ji,jj-1,jk) + tmask(ji+1,jj-1,jk) &
  1310. & +tmask(ji,jj+1,jk) + tmask(ji+1,jj+1,jk) ) )
  1311. evmean(ji,jj,jk) = vmask(ji,jj,jk) &
  1312. & / MAX( 1., tmask(ji ,jj,jk) + tmask(ji ,jj+1,jk) &
  1313. & +.5 * ( tmask(ji-1,jj,jk) + tmask(ji-1,jj+1,jk) &
  1314. & +tmask(ji+1,jj,jk) + tmask(ji+1,jj+1,jk) ) )
  1315. END DO
  1316. END DO
  1317. END DO
  1318. CASE DEFAULT
  1319. WRITE(ctmp1,*) ' bad flag value for nn_ave = ', nn_ave
  1320. CALL ctl_stop( ctmp1 )
  1321. END SELECT
  1322. ! Initialization of vertical eddy coef. to the background value
  1323. ! -------------------------------------------------------------
  1324. DO jk = 1, jpk
  1325. avt (:,:,jk) = avtb(jk) * tmask(:,:,jk)
  1326. avmu(:,:,jk) = avmb(jk) * umask(:,:,jk)
  1327. avmv(:,:,jk) = avmb(jk) * vmask(:,:,jk)
  1328. END DO
  1329. ! zero the surface flux for non local term and kpp mixed layer depth
  1330. ! ------------------------------------------------------------------
  1331. ghats(:,:,:) = 0.
  1332. wt0 (:,: ) = 0.
  1333. ws0 (:,: ) = 0.
  1334. hkpp (:,: ) = 0. ! just a diagnostic (not essential)
  1335. #if ! defined key_kppcustom
  1336. ! compute arrays (del, wz) for reference mean values
  1337. ! (increase speed for vectorization key_kppcustom not defined)
  1338. del(1:jpk, 1:jpk) = 0.
  1339. DO jk = 1, jpk
  1340. zref = epsilon * fsdept(1,1,jk)
  1341. DO jm = 1 , jpk
  1342. zdist = zref - fsdepw(1,1,jm)
  1343. IF( zdist > 0. ) THEN
  1344. del(jk,jm) = MIN( zdist, fse3t(1,1,jm) ) / zref
  1345. ELSE
  1346. del(jk,jm) = 0.
  1347. ENDIF
  1348. ENDDO
  1349. ENDDO
  1350. #endif
  1351. #if defined key_kpplktb
  1352. ! build lookup table for turbulent velocity scales
  1353. dezehat = ( dehatmax - dehatmin ) / nilktbm1
  1354. deustar = ( ustmax - ustmin ) / njlktbm1
  1355. DO jj = 1, njlktb
  1356. zustar = ( jj - 1) * deustar + ustmin
  1357. zustvk = vonk * zustar
  1358. zucube = zustar * zustar * zustar
  1359. DO ji = 1 , nilktb
  1360. zehat = ( ji - 1 ) * dezehat + dehatmin
  1361. zeta = zehat / ( zucube + epsln )
  1362. IF( zehat >= 0 ) THEN ! Stable case
  1363. wmlktb(ji,jj) = zustvk / ABS( 1.0 + rconc1 * zeta + epsln )
  1364. wslktb(ji,jj) = wmlktb(ji,jj)
  1365. ELSE ! Unstable case
  1366. IF( zeta > rzetam ) THEN
  1367. wmlktb(ji,jj) = zustvk * ABS( 1.0 - rconc2 * zeta )**pfourth
  1368. ELSE
  1369. wmlktb(ji,jj) = zustvk * ABS( rconam - rconcm * zeta )**pthird
  1370. ENDIF
  1371. IF( zeta > rzetas ) THEN
  1372. wslktb(ji,jj) = zustvk * SQRT( ABS( 1.0 - rconc2 * zeta ) )
  1373. ELSE
  1374. wslktb(ji,jj) = zustvk * ABS( rconas - rconcs * zeta )**pthird
  1375. ENDIF
  1376. ENDIF
  1377. END DO
  1378. END DO
  1379. #endif
  1380. !
  1381. IF( nn_timing == 1 ) CALL timing_stop('zdf_kpp_init')
  1382. !
  1383. END SUBROUTINE zdf_kpp_init
  1384. #else
  1385. !!----------------------------------------------------------------------
  1386. !! Dummy module : NO KPP scheme
  1387. !!----------------------------------------------------------------------
  1388. LOGICAL, PUBLIC, PARAMETER :: lk_zdfkpp = .FALSE. !: KPP flag
  1389. CONTAINS
  1390. SUBROUTINE zdf_kpp_init ! Dummy routine
  1391. WRITE(*,*) 'zdf_kpp_init: You should not have seen this print! error?'
  1392. END SUBROUTINE zdf_kpp_init
  1393. SUBROUTINE zdf_kpp( kt ) ! Dummy routine
  1394. WRITE(*,*) 'zdf_kpp: You should not have seen this print! error?', kt
  1395. END SUBROUTINE zdf_kpp
  1396. SUBROUTINE tra_kpp( kt ) ! Dummy routine
  1397. WRITE(*,*) 'tra_kpp: You should not have seen this print! error?', kt
  1398. END SUBROUTINE tra_kpp
  1399. SUBROUTINE trc_kpp( kt ) ! Dummy routine
  1400. WRITE(*,*) 'trc_kpp: You should not have seen this print! error?', kt
  1401. END SUBROUTINE trc_kpp
  1402. #endif
  1403. !!======================================================================
  1404. END MODULE zdfkpp