traadv_muscl2.F90 15 KB

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