dommsk.F90 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. MODULE dommsk
  2. !!======================================================================
  3. !! *** MODULE dommsk ***
  4. !! Ocean initialization : domain land/sea mask
  5. !!======================================================================
  6. !! History : OPA ! 1987-07 (G. Madec) Original code
  7. !! 6.0 ! 1993-03 (M. Guyon) symetrical conditions (M. Guyon)
  8. !! 7.0 ! 1996-01 (G. Madec) suppression of common work arrays
  9. !! - ! 1996-05 (G. Madec) mask computed from tmask
  10. !! 8.0 ! 1997-02 (G. Madec) mesh information put in domhgr.F
  11. !! 8.1 ! 1997-07 (G. Madec) modification of kbat and fmask
  12. !! - ! 1998-05 (G. Roullet) free surface
  13. !! 8.2 ! 2000-03 (G. Madec) no slip accurate
  14. !! - ! 2001-09 (J.-M. Molines) Open boundaries
  15. !! NEMO 1.0 ! 2002-08 (G. Madec) F90: Free form and module
  16. !! - ! 2005-11 (V. Garnier) Surface pressure gradient organization
  17. !! 3.2 ! 2009-07 (R. Benshila) Suppression of rigid-lid option
  18. !! 3.6 ! 2015-05 (P. Mathiot) ISF: add wmask,wumask and wvmask
  19. !! 4.0 ! 2016-06 (G. Madec, S. Flavoni) domain configuration / user defined interface
  20. !! 4.x ! 2020-02 (G. Madec, S. Techene) introduce ssh to h0 ratio
  21. !!----------------------------------------------------------------------
  22. !!----------------------------------------------------------------------
  23. !! dom_msk : compute land/ocean mask
  24. !!----------------------------------------------------------------------
  25. USE oce ! ocean dynamics and tracers
  26. USE dom_oce ! ocean space and time domain
  27. USE domutl !
  28. USE usrdef_fmask ! user defined fmask
  29. USE bdy_oce ! open boundary
  30. !
  31. USE in_out_manager ! I/O manager
  32. USE iom ! IOM library
  33. USE lbclnk ! ocean lateral boundary conditions (or mpp link)
  34. USE lib_mpp ! Massively Parallel Processing library
  35. #if defined key_drakkar
  36. USE fldread , ONLY : FLD_N ! for the case shlat2d
  37. #endif
  38. IMPLICIT NONE
  39. PRIVATE
  40. PUBLIC dom_msk ! routine called by inidom.F90
  41. ! !!* Namelist namlbc : lateral boundary condition *
  42. REAL(wp) :: rn_shlat ! type of lateral boundary condition on velocity
  43. LOGICAL, PUBLIC :: ln_vorlat ! consistency of vorticity boundary condition
  44. ! with analytical eqs.
  45. !! * Substitutions
  46. # include "do_loop_substitute.h90"
  47. !!----------------------------------------------------------------------
  48. !! NEMO/OCE 4.0 , NEMO Consortium (2018)
  49. !! $Id: dommsk.F90 15556 2021-11-29 15:23:06Z jchanut $
  50. !! Software governed by the CeCILL license (see ./LICENSE)
  51. !!----------------------------------------------------------------------
  52. CONTAINS
  53. SUBROUTINE dom_msk( k_top, k_bot )
  54. !!---------------------------------------------------------------------
  55. !! *** ROUTINE dom_msk ***
  56. !!
  57. !! ** Purpose : Compute land/ocean mask arrays at tracer points, hori-
  58. !! zontal velocity points (u & v), vorticity points (f) points.
  59. !!
  60. !! ** Method : The ocean/land mask at t-point is deduced from ko_top
  61. !! and ko_bot, the indices of the fist and last ocean t-levels which
  62. !! are either defined in usrdef_zgr or read in zgr_read.
  63. !! The velocity masks (umask, vmask, wmask, wumask, wvmask)
  64. !! are deduced from a product of the two neighboring tmask.
  65. !! The vorticity mask (fmask) is deduced from tmask taking
  66. !! into account the choice of lateral boundary condition (rn_shlat) :
  67. !! rn_shlat = 0, free slip (no shear along the coast)
  68. !! rn_shlat = 2, no slip (specified zero velocity at the coast)
  69. !! 0 < rn_shlat < 2, partial slip | non-linear velocity profile
  70. !! 2 < rn_shlat, strong slip | in the lateral boundary layer
  71. !!
  72. !! ** Action : tmask, umask, vmask, wmask, wumask, wvmask : land/ocean mask
  73. !! at t-, u-, v- w, wu-, and wv-points (=0. or 1.)
  74. !! fmask : land/ocean mask at f-point (=0., or =1., or
  75. !! =rn_shlat along lateral boundaries)
  76. !! ssmask , ssumask, ssvmask, ssfmask : 2D ocean mask, i.e. at least 1 wet cell in the vertical
  77. !! tmask_i : ssmask * ( excludes halo+duplicated points (NP folding) )
  78. !!----------------------------------------------------------------------
  79. INTEGER, DIMENSION(:,:), INTENT(in) :: k_top, k_bot ! first and last ocean level
  80. !
  81. INTEGER :: ji, jj, jk ! dummy loop indices
  82. INTEGER :: iktop, ikbot ! - -
  83. INTEGER :: ios, inum
  84. !!
  85. NAMELIST/namlbc/ rn_shlat, ln_vorlat
  86. NAMELIST/nambdy/ ln_bdy ,nb_bdy, ln_coords_file, cn_coords_file, &
  87. & ln_mask_file, cn_mask_file, cn_dyn2d, nn_dyn2d_dta, &
  88. & cn_dyn3d, nn_dyn3d_dta, cn_tra, nn_tra_dta, &
  89. & ln_tra_dmp, ln_dyn3d_dmp, rn_time_dmp, rn_time_dmp_out, &
  90. & cn_ice, nn_ice_dta, &
  91. & ln_vol, nn_volctl, nn_rimwidth
  92. #if defined key_drakkar
  93. REAL(wp) :: zshlat !: working variable
  94. REAL(wp), DIMENSION(:,:) , ALLOCATABLE :: zshlat2d
  95. CHARACTER(lc) :: cn_dir
  96. LOGICAL :: ln_shlat2d
  97. TYPE(FLD_N) :: sn_shlat2d
  98. !!
  99. NAMELIST/namlbc_drk/ ln_shlat2d, cn_dir, sn_shlat2d
  100. #endif
  101. !!---------------------------------------------------------------------
  102. !
  103. READ ( numnam_ref, namlbc, IOSTAT = ios, ERR = 901 )
  104. 901 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namlbc in reference namelist' )
  105. READ ( numnam_cfg, namlbc, IOSTAT = ios, ERR = 902 )
  106. 902 IF( ios > 0 ) CALL ctl_nam ( ios , 'namlbc in configuration namelist' )
  107. IF(lwm) WRITE ( numond, namlbc )
  108. #if defined key_drakkar
  109. READ ( numnam_ref, namlbc_drk, IOSTAT = ios, ERR = 905 )
  110. 905 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namlbc_drk in reference namelist' )
  111. READ ( numnam_cfg, namlbc_drk, IOSTAT = ios, ERR = 906 )
  112. 906 IF( ios > 0 ) CALL ctl_nam ( ios , 'namlbc_drk in configuration namelist' )
  113. IF(lwm) WRITE ( numond, namlbc_drk )
  114. #endif
  115. IF(lwp) THEN ! control print
  116. WRITE(numout,*)
  117. WRITE(numout,*) 'dommsk : ocean mask '
  118. WRITE(numout,*) '~~~~~~'
  119. WRITE(numout,*) ' Namelist namlbc'
  120. WRITE(numout,*) ' lateral momentum boundary cond. rn_shlat = ',rn_shlat
  121. WRITE(numout,*) ' consistency with analytical form ln_vorlat = ',ln_vorlat
  122. ENDIF
  123. !
  124. IF(lwp) WRITE(numout,*)
  125. IF ( rn_shlat == 0. ) THEN ; IF(lwp) WRITE(numout,*) ' ==>>> ocean lateral free-slip'
  126. ELSEIF ( rn_shlat == 2. ) THEN ; IF(lwp) WRITE(numout,*) ' ==>>> ocean lateral no-slip'
  127. ELSEIF ( 0. < rn_shlat .AND. rn_shlat < 2. ) THEN ; IF(lwp) WRITE(numout,*) ' ==>>> ocean lateral partial-slip'
  128. ELSEIF ( 2. < rn_shlat ) THEN ; IF(lwp) WRITE(numout,*) ' ==>>> ocean lateral strong-slip'
  129. ELSE
  130. CALL ctl_stop( 'dom_msk: wrong value for rn_shlat (i.e. a negalive value). We stop.' )
  131. ENDIF
  132. #if defined key_drakkar
  133. IF ( ln_shlat2d ) THEN
  134. IF(lwp) WRITE(numout,*) ' READ shlat as a 2D coefficient in a file '
  135. ALLOCATE (zshlat2d(jpi,jpj) )
  136. rn_shlat = 9999. ! set rn_shlat to a dummy value to force fmask modif
  137. CALL iom_open(TRIM(cn_dir)//'/'//TRIM(sn_shlat2d%clname), inum)
  138. !JMMM check iom_get 4.2 ...
  139. CALL iom_get (inum, jpdom_global, sn_shlat2d%clvar, zshlat2d, 1) !
  140. CALL iom_close(inum)
  141. ENDIF
  142. #endif
  143. ! Ocean/land mask at t-point (computed from ko_top and ko_bot)
  144. ! ----------------------------
  145. !
  146. tmask(:,:,:) = 0._wp
  147. DO_2D( nn_hls, nn_hls, nn_hls, nn_hls )
  148. iktop = k_top(ji,jj)
  149. ikbot = k_bot(ji,jj)
  150. IF( iktop /= 0 ) THEN ! water in the column
  151. tmask(ji,jj,iktop:ikbot) = 1._wp
  152. ENDIF
  153. END_2D
  154. !
  155. ! Mask corrections for bdy (read in mppini2)
  156. READ ( numnam_ref, nambdy, IOSTAT = ios, ERR = 903)
  157. 903 IF( ios /= 0 ) CALL ctl_nam ( ios , 'nambdy in reference namelist' )
  158. READ ( numnam_cfg, nambdy, IOSTAT = ios, ERR = 904 )
  159. 904 IF( ios > 0 ) CALL ctl_nam ( ios , 'nambdy in configuration namelist' )
  160. ! ------------------------
  161. IF ( ln_bdy .AND. ln_mask_file ) THEN
  162. CALL iom_open( cn_mask_file, inum )
  163. CALL iom_get ( inum, jpdom_global, 'bdy_msk', bdytmask(:,:) )
  164. CALL iom_close( inum )
  165. DO_3D( 1, 1, 1, 1, 1, jpkm1 )
  166. tmask(ji,jj,jk) = tmask(ji,jj,jk) * bdytmask(ji,jj)
  167. END_3D
  168. ENDIF
  169. ! Ocean/land mask at u-, v-, and f-points (computed from tmask)
  170. ! ----------------------------------------
  171. ! NB: at this point, fmask is designed for free slip lateral boundary condition
  172. DO_3D( 0, 0, 0, 0, 1, jpk )
  173. umask(ji,jj,jk) = tmask(ji,jj ,jk) * tmask(ji+1,jj ,jk)
  174. vmask(ji,jj,jk) = tmask(ji,jj ,jk) * tmask(ji ,jj+1,jk)
  175. fmask(ji,jj,jk) = tmask(ji,jj ,jk) * tmask(ji+1,jj ,jk) &
  176. & * tmask(ji,jj+1,jk) * tmask(ji+1,jj+1,jk)
  177. END_3D
  178. !
  179. ! In case of a coarsened grid, account her for possibly aditionnal
  180. ! masked points; these have been read in the mesh file and stored in mbku, mbkv, mbkf
  181. DO_2D( 0, 0, 0, 0 )
  182. IF ( MAXVAL(umask(ji,jj,:))/=0._wp ) umask(ji,jj,mbku(ji,jj)+1:jpk) = 0._wp
  183. IF ( MAXVAL(vmask(ji,jj,:))/=0._wp ) vmask(ji,jj,mbkv(ji,jj)+1:jpk) = 0._wp
  184. IF ( MAXVAL(fmask(ji,jj,:))/=0._wp ) fmask(ji,jj,mbkf(ji,jj)+1:jpk) = 0._wp
  185. END_2D
  186. CALL lbc_lnk( 'dommsk', umask, 'U', 1.0_wp, vmask, 'V', 1.0_wp, fmask, 'F', 1.0_wp ) ! Lateral boundary conditions
  187. ! Ocean/land mask at wu-, wv- and w points (computed from tmask)
  188. !-----------------------------------------
  189. wmask (:,:,1) = tmask(:,:,1) ! surface
  190. wumask(:,:,1) = umask(:,:,1)
  191. wvmask(:,:,1) = vmask(:,:,1)
  192. DO jk = 2, jpk ! interior values
  193. wmask (:,:,jk) = tmask(:,:,jk) * tmask(:,:,jk-1)
  194. wumask(:,:,jk) = umask(:,:,jk) * umask(:,:,jk-1)
  195. wvmask(:,:,jk) = vmask(:,:,jk) * vmask(:,:,jk-1)
  196. END DO
  197. ! Ocean/land column mask at t-, u-, and v-points (i.e. at least 1 wet cell in the vertical)
  198. ! ----------------------------------------------
  199. ssmask (:,:) = MAXVAL( tmask(:,:,:), DIM=3 )
  200. ssumask(:,:) = MAXVAL( umask(:,:,:), DIM=3 )
  201. ssvmask(:,:) = MAXVAL( vmask(:,:,:), DIM=3 )
  202. ssfmask(:,:) = MAXVAL( fmask(:,:,:), DIM=3 )
  203. IF( lk_SWE ) THEN ! Shallow Water Eq. case : redefine ssfmask
  204. DO_2D( 0, 0, 0, 0 )
  205. ssfmask(ji,jj) = MAX( ssmask(ji,jj+1), ssmask(ji+1,jj+1), &
  206. & ssmask(ji,jj ), ssmask(ji+1,jj ) )
  207. END_2D
  208. CALL lbc_lnk( 'dommsk', ssfmask, 'F', 1.0_wp )
  209. ENDIF
  210. fe3mask(:,:,:) = fmask(:,:,:)
  211. ! Interior domain mask (used for global sum) : 2D ocean mask x (halo+duplicated points) mask
  212. ! --------------------
  213. !
  214. CALL dom_uniq( tmask_i, 'T' )
  215. tmask_i(:,:) = ssmask(:,:) * tmask_i(:,:)
  216. ! Lateral boundary conditions on velocity (modify fmask)
  217. ! ---------------------------------------
  218. IF( rn_shlat /= 0._wp ) THEN ! Not free-slip lateral boundary condition
  219. !
  220. #if defined key_drakkar
  221. IF ( ln_shlat2d ) THEN ! use 2D shlat
  222. DO_3D( 0, 0, 0, 0, 1, jpk )
  223. IF( fmask(ji,jj,jk) == 0._wp ) THEN
  224. zshlat = zshlat2d(ji,jj)
  225. fmask(ji,jj,jk) = zshlat * MIN( 1._wp , MAX( umask(ji,jj,jk), umask(ji,jj+1,jk), &
  226. & vmask(ji,jj,jk), vmask(ji+1,jj,jk) ) )
  227. ENDIF
  228. END_3D
  229. ELSE
  230. #endif
  231. DO_3D( 0, 0, 0, 0, 1, jpk )
  232. IF( fmask(ji,jj,jk) == 0._wp ) THEN
  233. fmask(ji,jj,jk) = rn_shlat * MIN( 1._wp , MAX( umask(ji,jj,jk), umask(ji,jj+1,jk), &
  234. & vmask(ji,jj,jk), vmask(ji+1,jj,jk) ) )
  235. ENDIF
  236. END_3D
  237. #if defined key_drakkar
  238. ENDIF
  239. IF ( ln_shlat2d ) THEN
  240. DEALLOCATE (zshlat2d)
  241. ENDIF
  242. #endif
  243. CALL lbc_lnk( 'dommsk', fmask, 'F', 1._wp ) ! Lateral boundary conditions on fmask
  244. !
  245. ! CAUTION : The fmask may be further modified in dyn_vor_init ( dynvor.F90 ) depending on ln_vorlat
  246. !
  247. ENDIF
  248. ! User defined alteration of fmask (use to reduce ocean transport in specified straits)
  249. ! --------------------------------
  250. !
  251. CALL usr_def_fmask( cn_cfg, nn_cfg, fmask )
  252. !
  253. #if defined key_agrif
  254. ! Reset masks defining updated points over parent grids
  255. ! = 1 : updated point from child(s)
  256. ! = 0 : point not updated
  257. !
  258. tmask_upd(:,:) = 0._wp
  259. umask_upd(:,:) = 0._wp
  260. vmask_upd(:,:) = 0._wp
  261. #endif
  262. !
  263. END SUBROUTINE dom_msk
  264. !!======================================================================
  265. END MODULE dommsk