traadv_muscl.F90 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. MODULE traadv_muscl
  2. !!======================================================================
  3. !! *** MODULE traadv_muscl ***
  4. !! Ocean tracers: horizontal & vertical advective trend
  5. !!======================================================================
  6. !! History : ! 2000-06 (A.Estublier) for passive tracers
  7. !! ! 2001-08 (E.Durand, G.Madec) adapted for T & S
  8. !! NEMO 1.0 ! 2002-06 (G. Madec) F90: Free form and module
  9. !! 3.2 ! 2010-05 (C. Ethe, G. Madec) merge TRC-TRA + switch from velocity to transport
  10. !! 3.4 ! 2012-06 (P. Oddo, M. Vichi) include the upstream where needed
  11. !!----------------------------------------------------------------------
  12. !!----------------------------------------------------------------------
  13. !! tra_adv_muscl : update the tracer trend with the horizontal
  14. !! and vertical advection trends using MUSCL scheme
  15. !!----------------------------------------------------------------------
  16. USE oce ! ocean dynamics and active tracers
  17. USE trc_oce ! share passive tracers/Ocean variables
  18. USE dom_oce ! ocean space and time domain
  19. USE trd_oce ! trends: ocean variables
  20. USE trdtra ! tracers trends manager
  21. USE dynspg_oce ! choice/control of key cpp for surface pressure gradient
  22. USE sbcrnf ! river runoffs
  23. USE diaptr ! poleward transport diagnostics
  24. !
  25. USE wrk_nemo ! Memory Allocation
  26. USE timing ! Timing
  27. USE lib_fortran ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
  28. USE in_out_manager ! I/O manager
  29. USE lib_mpp ! distribued memory computing
  30. USE lbclnk ! ocean lateral boundary condition (or mpp link)
  31. IMPLICIT NONE
  32. PRIVATE
  33. PUBLIC tra_adv_muscl ! routine called by traadv.F90
  34. REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) :: upsmsk !: mixed upstream/centered scheme near some straits
  35. ! ! and in closed seas (orca 2 and 4 configurations)
  36. REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: xind !: mixed upstream/centered index
  37. !! * Substitutions
  38. # include "domzgr_substitute.h90"
  39. # include "vectopt_loop_substitute.h90"
  40. !!----------------------------------------------------------------------
  41. !! NEMO/OPA 3.3 , NEMO Consortium (2010)
  42. !! $Id$
  43. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  44. !!----------------------------------------------------------------------
  45. CONTAINS
  46. SUBROUTINE tra_adv_muscl( kt, kit000, cdtype, p2dt, pun, pvn, pwn, &
  47. & ptb, pta, kjpt, ld_msc_ups )
  48. !!----------------------------------------------------------------------
  49. !! *** ROUTINE tra_adv_muscl ***
  50. !!
  51. !! ** Purpose : Compute the now trend due to total advection of T and
  52. !! S using a MUSCL scheme (Monotone Upstream-centered Scheme for
  53. !! Conservation Laws) and add it to the general tracer trend.
  54. !!
  55. !! ** Method : MUSCL scheme plus centered scheme at ocean boundaries
  56. !!
  57. !! ** Action : - update (ta,sa) with the now advective tracer trends
  58. !! - save trends
  59. !!
  60. !! References : Estubier, A., and M. Levy, Notes Techn. Pole de Modelisation
  61. !! IPSL, Sept. 2000 (http://www.lodyc.jussieu.fr/opa)
  62. !!----------------------------------------------------------------------
  63. INTEGER , INTENT(in ) :: kt ! ocean time-step index
  64. INTEGER , INTENT(in ) :: kit000 ! first time step index
  65. CHARACTER(len=3) , INTENT(in ) :: cdtype ! =TRA or TRC (tracer indicator)
  66. INTEGER , INTENT(in ) :: kjpt ! number of tracers
  67. LOGICAL , INTENT(in ) :: ld_msc_ups ! use upstream scheme within muscl
  68. REAL(wp), DIMENSION( jpk ), INTENT(in ) :: p2dt ! vertical profile of tracer time-step
  69. REAL(wp), DIMENSION(jpi,jpj,jpk ), INTENT(in ) :: pun, pvn, pwn ! 3 ocean velocity components
  70. REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in ) :: ptb ! before tracer field
  71. REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) :: pta ! tracer trend
  72. !
  73. INTEGER :: ji, jj, jk, jn ! dummy loop indices
  74. INTEGER :: ierr ! local integer
  75. REAL(wp) :: zu, z0u, zzwx, zw ! local scalars
  76. REAL(wp) :: zv, z0v, zzwy, z0w ! - -
  77. REAL(wp) :: ztra, zbtr, zdt, zalpha ! - -
  78. REAL(wp), POINTER, DIMENSION(:,:,:) :: zslpx, zslpy ! 3D workspace
  79. REAL(wp), POINTER, DIMENSION(:,:,:) :: zwx , zwy ! - -
  80. !!----------------------------------------------------------------------
  81. !
  82. IF( nn_timing == 1 ) CALL timing_start('tra_adv_muscl')
  83. !
  84. CALL wrk_alloc( jpi, jpj, jpk, zslpx, zslpy, zwx, zwy )
  85. !
  86. IF( kt == kit000 ) THEN
  87. IF(lwp) WRITE(numout,*)
  88. IF(lwp) WRITE(numout,*) 'tra_adv : MUSCL advection scheme on ', cdtype
  89. IF(lwp) WRITE(numout,*) ' : mixed up-stream ', ld_msc_ups
  90. IF(lwp) WRITE(numout,*) '~~~~~~~'
  91. IF(lwp) WRITE(numout,*)
  92. !
  93. !
  94. IF( ld_msc_ups ) THEN
  95. IF( .NOT. ALLOCATED( upsmsk ) ) THEN
  96. ALLOCATE( upsmsk(jpi,jpj), STAT=ierr )
  97. IF( ierr /= 0 ) CALL ctl_stop('STOP', 'tra_adv_muscl: unable to allocate upsmsk array')
  98. ENDIF
  99. upsmsk(:,:) = 0._wp ! not upstream by default
  100. ENDIF
  101. IF( .NOT. ALLOCATED( xind ) ) THEN
  102. ALLOCATE( xind(jpi,jpj,jpk), STAT=ierr )
  103. IF( ierr /= 0 ) CALL ctl_stop('STOP', 'tra_adv_muscl: unable to allocate zind array')
  104. ENDIF
  105. !
  106. !
  107. ! Upstream / MUSCL scheme indicator
  108. ! ------------------------------------
  109. !!gm useless
  110. xind(:,:,:) = 1._wp ! set equal to 1 where up-stream is not needed
  111. !!gm
  112. !
  113. IF( ld_msc_ups ) THEN
  114. DO jk = 1, jpkm1
  115. xind(:,:,jk) = 1._wp & ! =>1 where up-stream is not needed
  116. & - MAX ( rnfmsk(:,:) * rnfmsk_z(jk), & ! =>0 near runoff mouths (& closed sea outflows)
  117. & upsmsk(:,:) ) * tmask(:,:,jk) ! =>0 near some straits
  118. END DO
  119. ENDIF
  120. !
  121. ENDIF
  122. !
  123. ! ! ===========
  124. DO jn = 1, kjpt ! tracer loop
  125. ! ! ===========
  126. ! I. Horizontal advective fluxes
  127. ! ------------------------------
  128. ! first guess of the slopes
  129. zwx(:,:,jpk) = 0.e0 ; zwy(:,:,jpk) = 0.e0 ! bottom values
  130. ! interior values
  131. DO jk = 1, jpkm1
  132. DO jj = 1, jpjm1
  133. DO ji = 1, fs_jpim1 ! vector opt.
  134. zwx(ji,jj,jk) = umask(ji,jj,jk) * ( ptb(ji+1,jj,jk,jn) - ptb(ji,jj,jk,jn) )
  135. zwy(ji,jj,jk) = vmask(ji,jj,jk) * ( ptb(ji,jj+1,jk,jn) - ptb(ji,jj,jk,jn) )
  136. END DO
  137. END DO
  138. END DO
  139. !
  140. CALL lbc_lnk( zwx, 'U', -1. ) ! lateral boundary conditions on zwx, zwy (changed sign)
  141. CALL lbc_lnk( zwy, 'V', -1. )
  142. ! !-- Slopes of tracer
  143. zslpx(:,:,jpk) = 0.e0 ; zslpy(:,:,jpk) = 0.e0 ! bottom values
  144. DO jk = 1, jpkm1 ! interior values
  145. DO jj = 2, jpj
  146. DO ji = fs_2, jpi ! vector opt.
  147. zslpx(ji,jj,jk) = ( zwx(ji,jj,jk) + zwx(ji-1,jj ,jk) ) &
  148. & * ( 0.25 + SIGN( 0.25, zwx(ji,jj,jk) * zwx(ji-1,jj ,jk) ) )
  149. zslpy(ji,jj,jk) = ( zwy(ji,jj,jk) + zwy(ji ,jj-1,jk) ) &
  150. & * ( 0.25 + SIGN( 0.25, zwy(ji,jj,jk) * zwy(ji ,jj-1,jk) ) )
  151. END DO
  152. END DO
  153. END DO
  154. !
  155. DO jk = 1, jpkm1 ! Slopes limitation
  156. DO jj = 2, jpj
  157. DO ji = fs_2, jpi ! vector opt.
  158. zslpx(ji,jj,jk) = SIGN( 1., zslpx(ji,jj,jk) ) * MIN( ABS( zslpx(ji ,jj,jk) ), &
  159. & 2.*ABS( zwx (ji-1,jj,jk) ), &
  160. & 2.*ABS( zwx (ji ,jj,jk) ) )
  161. zslpy(ji,jj,jk) = SIGN( 1., zslpy(ji,jj,jk) ) * MIN( ABS( zslpy(ji,jj ,jk) ), &
  162. & 2.*ABS( zwy (ji,jj-1,jk) ), &
  163. & 2.*ABS( zwy (ji,jj ,jk) ) )
  164. END DO
  165. END DO
  166. END DO ! interior values
  167. ! !-- MUSCL horizontal advective fluxes
  168. DO jk = 1, jpkm1 ! interior values
  169. zdt = p2dt(jk)
  170. DO jj = 2, jpjm1
  171. DO ji = fs_2, fs_jpim1 ! vector opt.
  172. ! MUSCL fluxes
  173. z0u = SIGN( 0.5, pun(ji,jj,jk) )
  174. zalpha = 0.5 - z0u
  175. zu = z0u - 0.5 * pun(ji,jj,jk) * zdt / ( e1u(ji,jj) * e2u(ji,jj) * fse3u(ji,jj,jk) )
  176. zzwx = ptb(ji+1,jj,jk,jn) + xind(ji,jj,jk) * zu * zslpx(ji+1,jj,jk)
  177. zzwy = ptb(ji ,jj,jk,jn) + xind(ji,jj,jk) * zu * zslpx(ji ,jj,jk)
  178. zwx(ji,jj,jk) = pun(ji,jj,jk) * ( zalpha * zzwx + (1.-zalpha) * zzwy )
  179. !
  180. z0v = SIGN( 0.5, pvn(ji,jj,jk) )
  181. zalpha = 0.5 - z0v
  182. zv = z0v - 0.5 * pvn(ji,jj,jk) * zdt / ( e1v(ji,jj) * e2v(ji,jj) * fse3v(ji,jj,jk) )
  183. zzwx = ptb(ji,jj+1,jk,jn) + xind(ji,jj,jk) * zv * zslpy(ji,jj+1,jk)
  184. zzwy = ptb(ji,jj ,jk,jn) + xind(ji,jj,jk) * zv * zslpy(ji,jj ,jk)
  185. zwy(ji,jj,jk) = pvn(ji,jj,jk) * ( zalpha * zzwx + (1.-zalpha) * zzwy )
  186. END DO
  187. END DO
  188. END DO
  189. ! ! lateral boundary conditions on zwx, zwy (changed sign)
  190. CALL lbc_lnk( zwx, 'U', -1. ) ; CALL lbc_lnk( zwy, 'V', -1. )
  191. !
  192. ! Tracer flux divergence at t-point added to the general trend
  193. DO jk = 1, jpkm1
  194. DO jj = 2, jpjm1
  195. DO ji = fs_2, fs_jpim1 ! vector opt.
  196. zbtr = 1. / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
  197. ! horizontal advective trends
  198. ztra = - zbtr * ( zwx(ji,jj,jk) - zwx(ji-1,jj ,jk ) &
  199. & + zwy(ji,jj,jk) - zwy(ji ,jj-1,jk ) )
  200. ! add it to the general tracer trends
  201. pta(ji,jj,jk,jn) = pta(ji,jj,jk,jn) + ztra
  202. END DO
  203. END DO
  204. END DO
  205. ! ! trend diagnostics (contribution of upstream fluxes)
  206. IF( ( cdtype == 'TRA' .AND. l_trdtra ) .OR. &
  207. &( cdtype == 'TRC' .AND. l_trdtrc ) ) THEN
  208. CALL trd_tra( kt, cdtype, jn, jptra_xad, zwx, pun, ptb(:,:,:,jn) )
  209. CALL trd_tra( kt, cdtype, jn, jptra_yad, zwy, pvn, ptb(:,:,:,jn) )
  210. END IF
  211. ! ! "Poleward" heat and salt transports (contribution of upstream fluxes)
  212. IF( cdtype == 'TRA' .AND. ln_diaptr ) CALL dia_ptr_ohst_components( jn, 'adv', zwy(:,:,:) )
  213. ! II. Vertical advective fluxes
  214. ! -----------------------------
  215. ! !-- first guess of the slopes
  216. zwx (:,:, 1 ) = 0.e0 ; zwx (:,:,jpk) = 0.e0 ! surface & bottom boundary conditions
  217. DO jk = 2, jpkm1 ! interior values
  218. zwx(:,:,jk) = tmask(:,:,jk) * ( ptb(:,:,jk-1,jn) - ptb(:,:,jk,jn) )
  219. END DO
  220. ! !-- Slopes of tracer
  221. zslpx(:,:,1) = 0.e0 ! surface values
  222. DO jk = 2, jpkm1 ! interior value
  223. DO jj = 1, jpj
  224. DO ji = 1, jpi
  225. zslpx(ji,jj,jk) = ( zwx(ji,jj,jk) + zwx(ji,jj,jk+1) ) &
  226. & * ( 0.25 + SIGN( 0.25, zwx(ji,jj,jk) * zwx(ji,jj,jk+1) ) )
  227. END DO
  228. END DO
  229. END DO
  230. ! !-- Slopes limitation
  231. DO jk = 2, jpkm1 ! interior values
  232. DO jj = 1, jpj
  233. DO ji = 1, jpi
  234. zslpx(ji,jj,jk) = SIGN( 1., zslpx(ji,jj,jk) ) * MIN( ABS( zslpx(ji,jj,jk ) ), &
  235. & 2.*ABS( zwx (ji,jj,jk+1) ), &
  236. & 2.*ABS( zwx (ji,jj,jk ) ) )
  237. END DO
  238. END DO
  239. END DO
  240. ! !-- vertical advective flux
  241. ! ! surface values (bottom already set to zero)
  242. IF( lk_vvl ) THEN ; zwx(:,:, 1 ) = 0.e0 ! variable volume
  243. ELSE ; zwx(:,:, 1 ) = pwn(:,:,1) * ptb(:,:,1,jn) ! linear free surface
  244. ENDIF
  245. !
  246. DO jk = 1, jpkm1 ! interior values
  247. zdt = p2dt(jk)
  248. DO jj = 2, jpjm1
  249. DO ji = fs_2, fs_jpim1 ! vector opt.
  250. zbtr = 1. / ( e1t(ji,jj) * e2t(ji,jj) * fse3w(ji,jj,jk+1) )
  251. z0w = SIGN( 0.5, pwn(ji,jj,jk+1) )
  252. zalpha = 0.5 + z0w
  253. zw = z0w - 0.5 * pwn(ji,jj,jk+1) * zdt * zbtr
  254. zzwx = ptb(ji,jj,jk+1,jn) + xind(ji,jj,jk) * zw * zslpx(ji,jj,jk+1)
  255. zzwy = ptb(ji,jj,jk ,jn) + xind(ji,jj,jk) * zw * zslpx(ji,jj,jk )
  256. zwx(ji,jj,jk+1) = pwn(ji,jj,jk+1) * ( zalpha * zzwx + (1.-zalpha) * zzwy )
  257. END DO
  258. END DO
  259. END DO
  260. DO jk = 1, jpkm1 ! Compute & add the vertical advective trend
  261. DO jj = 2, jpjm1
  262. DO ji = fs_2, fs_jpim1 ! vector opt.
  263. zbtr = 1. / ( e1e2t(ji,jj) * fse3t(ji,jj,jk) )
  264. ! vertical advective trends
  265. ztra = - zbtr * ( zwx(ji,jj,jk) - zwx(ji,jj,jk+1) )
  266. ! add it to the general tracer trends
  267. pta(ji,jj,jk,jn) = pta(ji,jj,jk,jn) + ztra
  268. END DO
  269. END DO
  270. END DO
  271. ! ! Save the vertical advective trends for diagnostic
  272. IF( ( cdtype == 'TRA' .AND. l_trdtra ) .OR. &
  273. &( cdtype == 'TRC' .AND. l_trdtrc ) ) &
  274. CALL trd_tra( kt, cdtype, jn, jptra_zad, zwx, pwn, ptb(:,:,:,jn) )
  275. !
  276. END DO
  277. !
  278. CALL wrk_dealloc( jpi, jpj, jpk, zslpx, zslpy, zwx, zwy )
  279. !
  280. IF( nn_timing == 1 ) CALL timing_stop('tra_adv_muscl')
  281. !
  282. END SUBROUTINE tra_adv_muscl
  283. !!======================================================================
  284. END MODULE traadv_muscl