zdfbfr.F90 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. MODULE zdfbfr
  2. !!======================================================================
  3. !! *** MODULE zdfbfr ***
  4. !! Ocean physics: Bottom friction
  5. !!======================================================================
  6. !! History : OPA ! 1997-06 (G. Madec, A.-M. Treguier) Original code
  7. !! NEMO 1.0 ! 2002-06 (G. Madec) F90: Free form and module
  8. !! 3.2 ! 2009-09 (A.C.Coward) Correction to include barotropic contribution
  9. !! 3.3 ! 2010-10 (C. Ethe, G. Madec) reorganisation of initialisation phase
  10. !! 3.4 ! 2011-11 (H. Liu) implementation of semi-implicit bottom friction option
  11. !! ! 2012-06 (H. Liu) implementation of Log Layer bottom friction option
  12. !!----------------------------------------------------------------------
  13. !!----------------------------------------------------------------------
  14. !! zdf_bfr : update bottom friction coefficient (non-linear bottom friction only)
  15. !! zdf_bfr_init : read in namelist and control the bottom friction parameters.
  16. !!----------------------------------------------------------------------
  17. USE oce ! ocean dynamics and tracers variables
  18. USE dom_oce ! ocean space and time domain variables
  19. USE zdf_oce ! ocean vertical physics variables
  20. USE in_out_manager ! I/O manager
  21. USE lbclnk ! ocean lateral boundary conditions (or mpp link)
  22. USE lib_mpp ! distributed memory computing
  23. USE prtctl ! Print control
  24. USE timing ! Timing
  25. USE wrk_nemo ! Memory Allocation
  26. USE phycst, ONLY: vkarmn
  27. IMPLICIT NONE
  28. PRIVATE
  29. PUBLIC zdf_bfr ! called by step.F90
  30. PUBLIC zdf_bfr_init ! called by nemogcm.F90
  31. ! !!* Namelist nambfr: bottom friction namelist *
  32. INTEGER , PUBLIC :: nn_bfr ! = 0/1/2/3 type of bottom friction (PUBLIC for TAM)
  33. REAL(wp), PUBLIC :: rn_bfri1 ! bottom drag coefficient (linear case) (PUBLIC for TAM)
  34. REAL(wp), PUBLIC :: rn_bfri2 ! bottom drag coefficient (non linear case) (PUBLIC for TAM)
  35. REAL(wp), PUBLIC :: rn_bfri2_max ! Maximum bottom drag coefficient (non linear case and ln_loglayer=T) (PUBLIC for TAM)
  36. REAL(wp), PUBLIC :: rn_bfeb2 ! background bottom turbulent kinetic energy [m2/s2] (PUBLIC for TAM)
  37. REAL(wp), PUBLIC :: rn_bfrien ! local factor to enhance coefficient bfri (PUBLIC for TAM)
  38. LOGICAL , PUBLIC :: ln_bfr2d ! logical switch for 2D enhancement (PUBLIC for TAM)
  39. REAL(wp), PUBLIC :: rn_tfri1 ! top drag coefficient (linear case) (PUBLIC for TAM)
  40. REAL(wp), PUBLIC :: rn_tfri2 ! top drag coefficient (non linear case) (PUBLIC for TAM)
  41. REAL(wp), PUBLIC :: rn_tfri2_max ! Maximum top drag coefficient (non linear case and ln_loglayer=T) (PUBLIC for TAM)
  42. REAL(wp), PUBLIC :: rn_tfeb2 ! background top turbulent kinetic energy [m2/s2] (PUBLIC for TAM)
  43. REAL(wp), PUBLIC :: rn_tfrien ! local factor to enhance coefficient tfri (PUBLIC for TAM)
  44. LOGICAL , PUBLIC :: ln_tfr2d ! logical switch for 2D enhancement (PUBLIC for TAM)
  45. LOGICAL , PUBLIC :: ln_loglayer ! switch for log layer bfr coeff. (PUBLIC for TAM)
  46. REAL(wp), PUBLIC :: rn_bfrz0 ! bottom roughness for loglayer bfr coeff (PUBLIC for TAM)
  47. REAL(wp), PUBLIC :: rn_tfrz0 ! bottom roughness for loglayer bfr coeff (PUBLIC for TAM)
  48. LOGICAL , PUBLIC :: ln_bfrimp ! logical switch for implicit bottom friction
  49. REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:), PUBLIC :: bfrcoef2d, tfrcoef2d ! 2D bottom/top drag coefficient (PUBLIC for TAM)
  50. !! * Substitutions
  51. # include "vectopt_loop_substitute.h90"
  52. # include "domzgr_substitute.h90"
  53. !!----------------------------------------------------------------------
  54. !! NEMO/OPA 4.0 , NEMO Consortium (2011)
  55. !! $Id: zdfbfr.F90 4990 2014-12-15 16:42:49Z timgraham $
  56. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  57. !!----------------------------------------------------------------------
  58. CONTAINS
  59. INTEGER FUNCTION zdf_bfr_alloc()
  60. !!----------------------------------------------------------------------
  61. !! *** FUNCTION zdf_bfr_alloc ***
  62. !!----------------------------------------------------------------------
  63. ALLOCATE( bfrcoef2d(jpi,jpj), tfrcoef2d(jpi,jpj), STAT=zdf_bfr_alloc )
  64. !
  65. IF( lk_mpp ) CALL mpp_sum ( zdf_bfr_alloc )
  66. IF( zdf_bfr_alloc /= 0 ) CALL ctl_warn('zdf_bfr_alloc: failed to allocate arrays.')
  67. END FUNCTION zdf_bfr_alloc
  68. SUBROUTINE zdf_bfr( kt )
  69. !!----------------------------------------------------------------------
  70. !! *** ROUTINE zdf_bfr ***
  71. !!
  72. !! ** Purpose : compute the bottom friction coefficient.
  73. !!
  74. !! ** Method : Calculate and store part of the momentum trend due
  75. !! to bottom friction following the chosen friction type
  76. !! (free-slip, linear, or quadratic). The component
  77. !! calculated here is multiplied by the bottom velocity in
  78. !! dyn_bfr to provide the trend term.
  79. !! The coefficients are updated at each time step only
  80. !! in the quadratic case.
  81. !!
  82. !! ** Action : bfrua , bfrva bottom friction coefficients
  83. !!----------------------------------------------------------------------
  84. INTEGER, INTENT( in ) :: kt ! ocean time-step index
  85. !!
  86. INTEGER :: ji, jj ! dummy loop indices
  87. INTEGER :: ikbt, ikbu, ikbv ! local integers
  88. REAL(wp) :: zvu, zuv, zecu, zecv, ztmp ! temporary scalars
  89. REAL(wp), POINTER, DIMENSION(:,:) :: zbfrt, ztfrt
  90. !!----------------------------------------------------------------------
  91. !
  92. IF( nn_timing == 1 ) CALL timing_start('zdf_bfr')
  93. !
  94. IF( kt == nit000 .AND. lwp ) THEN
  95. WRITE(numout,*)
  96. WRITE(numout,*) 'zdf_bfr : Set bottom friction coefficient (non-linear case)'
  97. WRITE(numout,*) '~~~~~~~~'
  98. ENDIF
  99. !
  100. IF( nn_bfr == 2 ) THEN ! quadratic bottom friction only
  101. !
  102. CALL wrk_alloc( jpi, jpj, zbfrt, ztfrt )
  103. IF ( ln_loglayer.AND.lk_vvl ) THEN ! "log layer" bottom friction coefficient
  104. DO jj = 1, jpj
  105. DO ji = 1, jpi
  106. ikbt = mbkt(ji,jj)
  107. !! JC: possible WAD implementation should modify line below if layers vanish
  108. ztmp = tmask(ji,jj,ikbt) * ( vkarmn / LOG( 0.5_wp * fse3t_n(ji,jj,ikbt) / rn_bfrz0 ))**2._wp
  109. zbfrt(ji,jj) = MAX(bfrcoef2d(ji,jj), ztmp)
  110. zbfrt(ji,jj) = MIN(zbfrt(ji,jj), rn_bfri2_max)
  111. END DO
  112. END DO
  113. ! (ISF)
  114. IF ( ln_isfcav ) THEN
  115. DO jj = 1, jpj
  116. DO ji = 1, jpi
  117. ikbt = mikt(ji,jj)
  118. ! JC: possible WAD implementation should modify line below if layers vanish
  119. ztmp = (1-tmask(ji,jj,1)) * ( vkarmn / LOG( 0.5_wp * fse3t_n(ji,jj,ikbt) / rn_bfrz0 ))**2._wp
  120. ztfrt(ji,jj) = MAX(tfrcoef2d(ji,jj), ztmp)
  121. ztfrt(ji,jj) = MIN(ztfrt(ji,jj), rn_tfri2_max)
  122. END DO
  123. END DO
  124. END IF
  125. !
  126. ELSE
  127. zbfrt(:,:) = bfrcoef2d(:,:)
  128. ztfrt(:,:) = tfrcoef2d(:,:)
  129. ENDIF
  130. DO jj = 2, jpjm1
  131. DO ji = 2, jpim1
  132. ikbu = mbku(ji,jj) ! ocean bottom level at u- and v-points
  133. ikbv = mbkv(ji,jj) ! (deepest ocean u- and v-points)
  134. !
  135. zvu = 0.25 * ( vn(ji,jj ,ikbu) + vn(ji+1,jj ,ikbu) &
  136. & + vn(ji,jj-1,ikbu) + vn(ji+1,jj-1,ikbu) )
  137. zuv = 0.25 * ( un(ji,jj ,ikbv) + un(ji-1,jj ,ikbv) &
  138. & + un(ji,jj+1,ikbv) + un(ji-1,jj+1,ikbv) )
  139. !
  140. zecu = SQRT( un(ji,jj,ikbu) * un(ji,jj,ikbu) + zvu*zvu + rn_bfeb2 )
  141. zecv = SQRT( vn(ji,jj,ikbv) * vn(ji,jj,ikbv) + zuv*zuv + rn_bfeb2 )
  142. !
  143. bfrua(ji,jj) = - 0.5_wp * ( zbfrt(ji,jj) + zbfrt(ji+1,jj ) ) * zecu
  144. bfrva(ji,jj) = - 0.5_wp * ( zbfrt(ji,jj) + zbfrt(ji ,jj+1) ) * zecv
  145. !
  146. ! in case of 2 cell water column, we assume each cell feels the top and bottom friction
  147. IF ( ln_isfcav ) THEN
  148. IF ( miku(ji,jj) + 1 .GE. mbku(ji,jj) ) THEN
  149. bfrua(ji,jj) = - 0.5_wp * ( ( zbfrt(ji,jj) + zbfrt(ji+1,jj ) ) &
  150. & + ( ztfrt(ji,jj) + ztfrt(ji+1,jj ) ) ) &
  151. & * zecu * (1._wp - umask(ji,jj,1))
  152. END IF
  153. IF ( mikv(ji,jj) + 1 .GE. mbkv(ji,jj) ) THEN
  154. bfrva(ji,jj) = - 0.5_wp * ( ( zbfrt(ji,jj) + zbfrt(ji ,jj+1) ) &
  155. & + ( ztfrt(ji,jj) + ztfrt(ji ,jj+1) ) ) &
  156. & * zecv * (1._wp - vmask(ji,jj,1))
  157. END IF
  158. END IF
  159. END DO
  160. END DO
  161. CALL lbc_lnk( bfrua, 'U', 1. ) ; CALL lbc_lnk( bfrva, 'V', 1. ) ! Lateral boundary condition
  162. IF ( ln_isfcav ) THEN
  163. DO jj = 2, jpjm1
  164. DO ji = 2, jpim1
  165. ! (ISF) ========================================================================
  166. ikbu = miku(ji,jj) ! ocean top level at u- and v-points
  167. ikbv = mikv(ji,jj) ! (1st wet ocean u- and v-points)
  168. !
  169. zvu = 0.25 * ( vn(ji,jj ,ikbu) + vn(ji+1,jj ,ikbu) &
  170. & + vn(ji,jj-1,ikbu) + vn(ji+1,jj-1,ikbu) )
  171. zuv = 0.25 * ( un(ji,jj ,ikbv) + un(ji-1,jj ,ikbv) &
  172. & + un(ji,jj+1,ikbv) + un(ji-1,jj+1,ikbv) )
  173. !
  174. zecu = SQRT( un(ji,jj,ikbu) * un(ji,jj,ikbu) + zvu*zvu + rn_tfeb2 )
  175. zecv = SQRT( vn(ji,jj,ikbv) * vn(ji,jj,ikbv) + zuv*zuv + rn_tfeb2 )
  176. !
  177. tfrua(ji,jj) = - 0.5_wp * ( ztfrt(ji,jj) + ztfrt(ji+1,jj ) ) * zecu * (1._wp - umask(ji,jj,1))
  178. tfrva(ji,jj) = - 0.5_wp * ( ztfrt(ji,jj) + ztfrt(ji ,jj+1) ) * zecv * (1._wp - vmask(ji,jj,1))
  179. ! (ISF) END ====================================================================
  180. ! in case of 2 cell water column, we assume each cell feels the top and bottom friction
  181. IF ( miku(ji,jj) + 1 .GE. mbku(ji,jj) ) THEN
  182. tfrua(ji,jj) = - 0.5_wp * ( ( ztfrt(ji,jj) + ztfrt(ji+1,jj ) ) &
  183. & + ( zbfrt(ji,jj) + zbfrt(ji+1,jj ) ) ) &
  184. & * zecu * (1._wp - umask(ji,jj,1))
  185. END IF
  186. IF ( mikv(ji,jj) + 1 .GE. mbkv(ji,jj) ) THEN
  187. tfrva(ji,jj) = - 0.5_wp * ( ( ztfrt(ji,jj) + ztfrt(ji ,jj+1) ) &
  188. & + ( zbfrt(ji,jj) + zbfrt(ji ,jj+1) ) ) &
  189. & * zecv * (1._wp - vmask(ji,jj,1))
  190. END IF
  191. END DO
  192. END DO
  193. CALL lbc_lnk( tfrua, 'U', 1. ) ; CALL lbc_lnk( tfrva, 'V', 1. ) ! Lateral boundary condition
  194. END IF
  195. !
  196. !
  197. IF(ln_ctl) CALL prt_ctl( tab2d_1=bfrua, clinfo1=' bfr - u: ', mask1=umask, &
  198. & tab2d_2=bfrva, clinfo2= ' v: ', mask2=vmask,ovlap=1 )
  199. CALL wrk_dealloc( jpi,jpj,zbfrt, ztfrt )
  200. ENDIF
  201. !
  202. IF( nn_timing == 1 ) CALL timing_stop('zdf_bfr')
  203. !
  204. END SUBROUTINE zdf_bfr
  205. SUBROUTINE zdf_bfr_init
  206. !!----------------------------------------------------------------------
  207. !! *** ROUTINE zdf_bfr_init ***
  208. !!
  209. !! ** Purpose : Initialization of the bottom friction
  210. !!
  211. !! ** Method : Read the nambfr namelist and check their consistency
  212. !! called at the first timestep (nit000)
  213. !!----------------------------------------------------------------------
  214. USE iom ! I/O module for ehanced bottom friction file
  215. !!
  216. INTEGER :: inum ! logical unit for enhanced bottom friction file
  217. INTEGER :: ji, jj ! dummy loop indexes
  218. INTEGER :: ikbt, ikbu, ikbv ! temporary integers
  219. INTEGER :: ictu, ictv ! - -
  220. INTEGER :: ios
  221. REAL(wp) :: zminbfr, zmaxbfr ! temporary scalars
  222. REAL(wp) :: zmintfr, zmaxtfr ! temporary scalars
  223. REAL(wp) :: ztmp, zfru, zfrv ! - -
  224. !!
  225. NAMELIST/nambfr/ nn_bfr, rn_bfri1, rn_bfri2, rn_bfri2_max, rn_bfeb2, rn_bfrz0, ln_bfr2d, &
  226. & rn_tfri1, rn_tfri2, rn_tfri2_max, rn_tfeb2, rn_tfrz0, ln_tfr2d, &
  227. & rn_bfrien, rn_tfrien, ln_bfrimp, ln_loglayer
  228. !!----------------------------------------------------------------------
  229. !
  230. IF( nn_timing == 1 ) CALL timing_start('zdf_bfr_init')
  231. !
  232. ! !* Allocate zdfbfr arrays
  233. IF( zdf_bfr_alloc() /= 0 ) CALL ctl_stop( 'STOP', 'zdf_bfr_init : unable to allocate arrays' )
  234. !
  235. ! !* Parameter control and print
  236. !
  237. REWIND( numnam_ref ) ! Namelist nambfr in reference namelist : Bottom momentum boundary condition
  238. READ ( numnam_ref, nambfr, IOSTAT = ios, ERR = 901)
  239. 901 IF( ios /= 0 ) CALL ctl_nam ( ios , 'nambfr in reference namelist', lwp )
  240. REWIND( numnam_cfg ) ! Namelist nambfr in configuration namelist : Bottom momentum boundary condition
  241. READ ( numnam_cfg, nambfr, IOSTAT = ios, ERR = 902 )
  242. 902 IF( ios /= 0 ) CALL ctl_nam ( ios , 'nambfr in configuration namelist', lwp )
  243. IF(lwm) WRITE ( numond, nambfr )
  244. IF(lwp) WRITE(numout,*)
  245. IF(lwp) WRITE(numout,*) 'zdf_bfr_init : momentum bottom friction'
  246. IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~'
  247. IF(lwp) WRITE(numout,*) ' Namelist nam_bfr : set bottom friction parameters'
  248. !
  249. SELECT CASE (nn_bfr)
  250. !
  251. CASE( 0 )
  252. IF(lwp) WRITE(numout,*) ' free-slip '
  253. bfrua(:,:) = 0.e0
  254. bfrva(:,:) = 0.e0
  255. tfrua(:,:) = 0.e0
  256. tfrva(:,:) = 0.e0
  257. !
  258. CASE( 1 )
  259. IF(lwp) WRITE(numout,*) ' linear botton friction'
  260. IF(lwp) WRITE(numout,*) ' bottom friction coef. rn_bfri1 = ', rn_bfri1
  261. IF( ln_bfr2d ) THEN
  262. IF(lwp) WRITE(numout,*) ' read coef. enhancement distribution from file ln_bfr2d = ', ln_bfr2d
  263. IF(lwp) WRITE(numout,*) ' coef rn_bfri2 enhancement factor rn_bfrien = ',rn_bfrien
  264. ENDIF
  265. IF ( ln_isfcav ) THEN
  266. IF(lwp) WRITE(numout,*) ' top friction coef. rn_bfri1 = ', rn_tfri1
  267. IF( ln_tfr2d ) THEN
  268. IF(lwp) WRITE(numout,*) ' read coef. enhancement distribution from file ln_tfr2d = ', ln_tfr2d
  269. IF(lwp) WRITE(numout,*) ' coef rn_tfri2 enhancement factor rn_tfrien = ',rn_tfrien
  270. ENDIF
  271. END IF
  272. !
  273. IF(ln_bfr2d) THEN
  274. ! bfr_coef is a coefficient in [0,1] giving the mask where to apply the bfr enhancement
  275. CALL iom_open('bfr_coef.nc',inum)
  276. CALL iom_get (inum, jpdom_data, 'bfr_coef',bfrcoef2d,1) ! bfrcoef2d is used as tmp array
  277. CALL iom_close(inum)
  278. bfrcoef2d(:,:) = rn_bfri1 * ( 1 + rn_bfrien * bfrcoef2d(:,:) )
  279. ELSE
  280. bfrcoef2d(:,:) = rn_bfri1 ! initialize bfrcoef2d to the namelist variable
  281. ENDIF
  282. !
  283. bfrua(:,:) = - bfrcoef2d(:,:)
  284. bfrva(:,:) = - bfrcoef2d(:,:)
  285. !
  286. IF ( ln_isfcav ) THEN
  287. IF(ln_tfr2d) THEN
  288. ! tfr_coef is a coefficient in [0,1] giving the mask where to apply the bfr enhancement
  289. CALL iom_open('tfr_coef.nc',inum)
  290. CALL iom_get (inum, jpdom_data, 'tfr_coef',tfrcoef2d,1) ! tfrcoef2d is used as tmp array
  291. CALL iom_close(inum)
  292. tfrcoef2d(:,:) = rn_tfri1 * ( 1 + rn_tfrien * tfrcoef2d(:,:) )
  293. ELSE
  294. tfrcoef2d(:,:) = rn_tfri1 ! initialize tfrcoef2d to the namelist variable
  295. ENDIF
  296. !
  297. tfrua(:,:) = - tfrcoef2d(:,:)
  298. tfrva(:,:) = - tfrcoef2d(:,:)
  299. END IF
  300. !
  301. CASE( 2 )
  302. IF(lwp) WRITE(numout,*) ' quadratic bottom friction'
  303. IF(lwp) WRITE(numout,*) ' friction coef. rn_bfri2 = ', rn_bfri2
  304. IF(lwp) WRITE(numout,*) ' Max. coef. (log case) rn_bfri2_max = ', rn_bfri2_max
  305. IF(lwp) WRITE(numout,*) ' background tke rn_bfeb2 = ', rn_bfeb2
  306. IF(lwp) WRITE(numout,*) ' log formulation ln_bfr2d = ', ln_loglayer
  307. IF(lwp) WRITE(numout,*) ' bottom roughness rn_bfrz0 [m] = ', rn_bfrz0
  308. IF( rn_bfrz0<=0.e0 ) THEN
  309. WRITE(ctmp1,*) ' bottom roughness must be strictly positive'
  310. CALL ctl_stop( ctmp1 )
  311. ENDIF
  312. IF( ln_bfr2d ) THEN
  313. IF(lwp) WRITE(numout,*) ' read coef. enhancement distribution from file ln_bfr2d = ', ln_bfr2d
  314. IF(lwp) WRITE(numout,*) ' coef rn_bfri2 enhancement factor rn_bfrien = ',rn_bfrien
  315. ENDIF
  316. IF ( ln_isfcav ) THEN
  317. IF(lwp) WRITE(numout,*) ' quadratic top friction'
  318. IF(lwp) WRITE(numout,*) ' friction coef. rn_tfri2 = ', rn_tfri2
  319. IF(lwp) WRITE(numout,*) ' Max. coef. (log case) rn_tfri2_max = ', rn_tfri2_max
  320. IF(lwp) WRITE(numout,*) ' background tke rn_tfeb2 = ', rn_tfeb2
  321. IF(lwp) WRITE(numout,*) ' log formulation ln_tfr2d = ', ln_loglayer
  322. IF(lwp) WRITE(numout,*) ' top roughness rn_tfrz0 [m] = ', rn_tfrz0
  323. IF( rn_tfrz0<=0.e0 ) THEN
  324. WRITE(ctmp1,*) ' top roughness must be strictly positive'
  325. CALL ctl_stop( ctmp1 )
  326. ENDIF
  327. IF( ln_tfr2d ) THEN
  328. IF(lwp) WRITE(numout,*) ' read coef. enhancement distribution from file ln_tfr2d = ', ln_tfr2d
  329. IF(lwp) WRITE(numout,*) ' coef rn_tfri2 enhancement factor rn_tfrien = ',rn_tfrien
  330. ENDIF
  331. END IF
  332. !
  333. IF(ln_bfr2d) THEN
  334. ! bfr_coef is a coefficient in [0,1] giving the mask where to apply the bfr enhancement
  335. CALL iom_open('bfr_coef.nc',inum)
  336. CALL iom_get (inum, jpdom_data, 'bfr_coef',bfrcoef2d,1) ! bfrcoef2d is used as tmp array
  337. CALL iom_close(inum)
  338. !
  339. bfrcoef2d(:,:) = rn_bfri2 * ( 1 + rn_bfrien * bfrcoef2d(:,:) )
  340. ELSE
  341. bfrcoef2d(:,:) = rn_bfri2 ! initialize bfrcoef2d to the namelist variable
  342. ENDIF
  343. IF ( ln_isfcav ) THEN
  344. IF(ln_tfr2d) THEN
  345. ! tfr_coef is a coefficient in [0,1] giving the mask where to apply the bfr enhancement
  346. CALL iom_open('tfr_coef.nc',inum)
  347. CALL iom_get (inum, jpdom_data, 'tfr_coef',tfrcoef2d,1) ! tfrcoef2d is used as tmp array
  348. CALL iom_close(inum)
  349. !
  350. tfrcoef2d(:,:) = rn_tfri2 * ( 1 + rn_tfrien * tfrcoef2d(:,:) )
  351. ELSE
  352. tfrcoef2d(:,:) = rn_tfri2 ! initialize tfrcoef2d to the namelist variable
  353. ENDIF
  354. END IF
  355. !
  356. IF ( ln_loglayer.AND.(.NOT.lk_vvl) ) THEN ! set "log layer" bottom friction once for all
  357. DO jj = 1, jpj
  358. DO ji = 1, jpi
  359. ikbt = mbkt(ji,jj)
  360. ztmp = tmask(ji,jj,ikbt) * ( vkarmn / LOG( 0.5_wp * fse3t_n(ji,jj,ikbt) / rn_bfrz0 ))**2._wp
  361. bfrcoef2d(ji,jj) = MAX(bfrcoef2d(ji,jj), ztmp)
  362. bfrcoef2d(ji,jj) = MIN(bfrcoef2d(ji,jj), rn_bfri2_max)
  363. END DO
  364. END DO
  365. IF ( ln_isfcav ) THEN
  366. DO jj = 1, jpj
  367. DO ji = 1, jpi
  368. ikbt = mikt(ji,jj)
  369. ztmp = tmask(ji,jj,ikbt) * ( vkarmn / LOG( 0.5_wp * fse3t_n(ji,jj,ikbt) / rn_tfrz0 ))**2._wp
  370. tfrcoef2d(ji,jj) = MAX(tfrcoef2d(ji,jj), ztmp)
  371. tfrcoef2d(ji,jj) = MIN(tfrcoef2d(ji,jj), rn_tfri2_max)
  372. END DO
  373. END DO
  374. END IF
  375. ENDIF
  376. !
  377. CASE DEFAULT
  378. IF(lwp) WRITE(ctmp1,*) ' bad flag value for nn_bfr = ', nn_bfr
  379. CALL ctl_stop( ctmp1 )
  380. !
  381. END SELECT
  382. !
  383. IF(lwp) WRITE(numout,*) ' implicit bottom friction switch ln_bfrimp = ', ln_bfrimp
  384. !
  385. ! ! Make sure ln_zdfexp=.false. when use implicit bfr
  386. IF( ln_bfrimp .AND. ln_zdfexp ) THEN
  387. IF(lwp) THEN
  388. WRITE(numout,*)
  389. WRITE(numout,*) 'Implicit bottom friction can only be used when ln_zdfexp=.false.'
  390. WRITE(numout,*) ' but you set: ln_bfrimp=.true. and ln_zdfexp=.true.!!!!'
  391. WRITE(ctmp1,*) ' set either ln_zdfexp = .false or ln_bfrimp = .false.'
  392. CALL ctl_stop( ctmp1 )
  393. END IF
  394. END IF
  395. !
  396. ! Basic stability check on bottom friction coefficient
  397. !
  398. ictu = 0 ! counter for stability criterion breaches at U-pts
  399. ictv = 0 ! counter for stability criterion breaches at V-pts
  400. zminbfr = 1.e10_wp ! initialise tracker for minimum of bottom friction coefficient
  401. zmaxbfr = -1.e10_wp ! initialise tracker for maximum of bottom friction coefficient
  402. zmintfr = 1.e10_wp ! initialise tracker for minimum of bottom friction coefficient
  403. zmaxtfr = -1.e10_wp ! initialise tracker for maximum of bottom friction coefficient
  404. !
  405. DO jj = 2, jpjm1
  406. DO ji = 2, jpim1
  407. ikbu = mbku(ji,jj) ! deepest ocean level at u- and v-points
  408. ikbv = mbkv(ji,jj)
  409. zfru = 0.5 * fse3u(ji,jj,ikbu) / rdt
  410. zfrv = 0.5 * fse3v(ji,jj,ikbv) / rdt
  411. IF( ABS( bfrcoef2d(ji,jj) ) > zfru ) THEN
  412. IF( ln_ctl ) THEN
  413. WRITE(numout,*) 'BFR ', narea, nimpp+ji, njmpp+jj, ikbu
  414. WRITE(numout,*) 'BFR ', ABS( bfrcoef2d(ji,jj) ), zfru
  415. ENDIF
  416. ictu = ictu + 1
  417. ENDIF
  418. IF( ABS( bfrcoef2d(ji,jj) ) > zfrv ) THEN
  419. IF( ln_ctl ) THEN
  420. WRITE(numout,*) 'BFR ', narea, nimpp+ji, njmpp+jj, ikbv
  421. WRITE(numout,*) 'BFR ', bfrcoef2d(ji,jj), zfrv
  422. ENDIF
  423. ictv = ictv + 1
  424. ENDIF
  425. zminbfr = MIN( zminbfr, MIN( zfru, ABS( bfrcoef2d(ji,jj) ) ) )
  426. zmaxbfr = MAX( zmaxbfr, MIN( zfrv, ABS( bfrcoef2d(ji,jj) ) ) )
  427. ! (ISF)
  428. IF ( ln_isfcav ) THEN
  429. ikbu = miku(ji,jj) ! 1st wet ocean level at u- and v-points
  430. ikbv = mikv(ji,jj)
  431. zfru = 0.5 * fse3u(ji,jj,ikbu) / rdt
  432. zfrv = 0.5 * fse3v(ji,jj,ikbv) / rdt
  433. IF( ABS( tfrcoef2d(ji,jj) ) > zfru ) THEN
  434. IF( ln_ctl ) THEN
  435. WRITE(numout,*) 'TFR ', narea, nimpp+ji, njmpp+jj, ikbu
  436. WRITE(numout,*) 'TFR ', ABS( tfrcoef2d(ji,jj) ), zfru
  437. ENDIF
  438. ictu = ictu + 1
  439. ENDIF
  440. IF( ABS( tfrcoef2d(ji,jj) ) > zfrv ) THEN
  441. IF( ln_ctl ) THEN
  442. WRITE(numout,*) 'TFR ', narea, nimpp+ji, njmpp+jj, ikbv
  443. WRITE(numout,*) 'TFR ', tfrcoef2d(ji,jj), zfrv
  444. ENDIF
  445. ictv = ictv + 1
  446. ENDIF
  447. zmintfr = MIN( zmintfr, MIN( zfru, ABS( tfrcoef2d(ji,jj) ) ) )
  448. zmaxtfr = MAX( zmaxtfr, MIN( zfrv, ABS( tfrcoef2d(ji,jj) ) ) )
  449. END IF
  450. ! END ISF
  451. END DO
  452. END DO
  453. IF( lk_mpp ) THEN
  454. CALL mpp_sum( ictu )
  455. CALL mpp_sum( ictv )
  456. CALL mpp_min( zminbfr )
  457. CALL mpp_max( zmaxbfr )
  458. IF ( ln_isfcav) CALL mpp_min( zmintfr )
  459. IF ( ln_isfcav) CALL mpp_max( zmaxtfr )
  460. ENDIF
  461. IF( .NOT.ln_bfrimp) THEN
  462. IF( lwp .AND. ictu + ictv > 0 ) THEN
  463. WRITE(numout,*) ' Bottom/Top friction stability check failed at ', ictu, ' U-points '
  464. WRITE(numout,*) ' Bottom/Top friction stability check failed at ', ictv, ' V-points '
  465. WRITE(numout,*) ' Bottom friction coefficient now ranges from: ', zminbfr, ' to ', zmaxbfr
  466. IF ( ln_isfcav ) WRITE(numout,*) ' Top friction coefficient now ranges from: ', zmintfr, ' to ', zmaxtfr
  467. WRITE(numout,*) ' Bottom/Top friction coefficient will be reduced where necessary'
  468. ENDIF
  469. ENDIF
  470. !
  471. IF( nn_timing == 1 ) CALL timing_stop('zdf_bfr_init')
  472. !
  473. END SUBROUTINE zdf_bfr_init
  474. !!======================================================================
  475. END MODULE zdfbfr