trcnxt.F90 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. MODULE trcnxt
  2. !!======================================================================
  3. !! *** MODULE trcnxt ***
  4. !! Ocean passive tracers: time stepping on passives tracers
  5. !!======================================================================
  6. !! History : 7.0 ! 1991-11 (G. Madec) Original code
  7. !! ! 1993-03 (M. Guyon) symetrical conditions
  8. !! ! 1995-02 (M. Levy) passive tracers
  9. !! ! 1996-02 (G. Madec & M. Imbard) opa release 8.0
  10. !! 8.0 ! 1996-04 (A. Weaver) Euler forward step
  11. !! 8.2 ! 1999-02 (G. Madec, N. Grima) semi-implicit pressure grad.
  12. !! NEMO 1.0 ! 2002-08 (G. Madec) F90: Free form and module
  13. !! ! 2002-08 (G. Madec) F90: Free form and module
  14. !! ! 2002-11 (C. Talandier, A-M Treguier) Open boundaries
  15. !! ! 2004-03 (C. Ethe) passive tracers
  16. !! ! 2007-02 (C. Deltel) Diagnose ML trends for passive tracers
  17. !! 2.0 ! 2006-02 (L. Debreu, C. Mazauric) Agrif implementation
  18. !! 3.0 ! 2008-06 (G. Madec) time stepping always done in trazdf
  19. !! 3.1 ! 2009-02 (G. Madec, R. Benshila) re-introduce the vvl option
  20. !! 3.3 ! 2010-06 (C. Ethe, G. Madec) Merge TRA-TRC
  21. !!----------------------------------------------------------------------
  22. #if defined key_top
  23. !!----------------------------------------------------------------------
  24. !! 'key_top' TOP models
  25. !!----------------------------------------------------------------------
  26. !! trc_nxt : time stepping on passive tracers
  27. !!----------------------------------------------------------------------
  28. USE oce_trc ! ocean dynamics and tracers variables
  29. USE trc ! ocean passive tracers variables
  30. USE lbclnk ! ocean lateral boundary conditions (or mpp link)
  31. USE prtctl_trc ! Print control for debbuging
  32. USE trd_oce
  33. USE trdtra
  34. USE tranxt
  35. # if defined key_agrif
  36. USE agrif_top_interp
  37. # endif
  38. IMPLICIT NONE
  39. PRIVATE
  40. PUBLIC trc_nxt ! routine called by step.F90
  41. PUBLIC trc_nxt_alloc ! routine called by nemogcm.F90
  42. REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:) :: r2dt
  43. REAL(wp) :: rfact1, rfact2
  44. !! * Substitutions
  45. # include "domzgr_substitute.h90"
  46. # include "vectopt_loop_substitute.h90"
  47. !!----------------------------------------------------------------------
  48. !! NEMO/TOP 3.3 , NEMO Consortium (2010)
  49. !! $Id: trcnxt.F90 4990 2014-12-15 16:42:49Z timgraham $
  50. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  51. !!----------------------------------------------------------------------
  52. CONTAINS
  53. INTEGER FUNCTION trc_nxt_alloc()
  54. !!----------------------------------------------------------------------
  55. !! *** ROUTINE trc_nxt_alloc ***
  56. !!----------------------------------------------------------------------
  57. ALLOCATE( r2dt(jpk), STAT=trc_nxt_alloc )
  58. !
  59. IF( trc_nxt_alloc /= 0 ) CALL ctl_warn('trc_nxt_alloc : failed to allocate array')
  60. !
  61. END FUNCTION trc_nxt_alloc
  62. SUBROUTINE trc_nxt( kt )
  63. !!----------------------------------------------------------------------
  64. !! *** ROUTINE trcnxt ***
  65. !!
  66. !! ** Purpose : Compute the passive tracers fields at the
  67. !! next time-step from their temporal trends and swap the fields.
  68. !!
  69. !! ** Method : Apply lateral boundary conditions on (ua,va) through
  70. !! call to lbc_lnk routine
  71. !! default:
  72. !! arrays swap
  73. !! (trn) = (tra) ; (tra) = (0,0)
  74. !! (trb) = (trn)
  75. !!
  76. !! For Arakawa or TVD Scheme :
  77. !! A Asselin time filter applied on now tracers (trn) to avoid
  78. !! the divergence of two consecutive time-steps and tr arrays
  79. !! to prepare the next time_step:
  80. !! (trb) = (trn) + atfp [ (trb) + (tra) - 2 (trn) ]
  81. !! (trn) = (tra) ; (tra) = (0,0)
  82. !!
  83. !!
  84. !! ** Action : - update trb, trn
  85. !!----------------------------------------------------------------------
  86. INTEGER, INTENT( in ) :: kt ! ocean time-step index
  87. !
  88. INTEGER :: jk, jn ! dummy loop indices
  89. REAL(wp) :: zfact ! temporary scalar
  90. CHARACTER (len=22) :: charout
  91. REAL(wp), POINTER, DIMENSION(:,:,:,:) :: ztrdt
  92. !!----------------------------------------------------------------------
  93. !
  94. IF( nn_timing == 1 ) CALL timing_start('trc_nxt')
  95. !
  96. IF( kt == nittrc000 .AND. lwp ) THEN
  97. WRITE(numout,*)
  98. WRITE(numout,*) 'trc_nxt : time stepping on passive tracers'
  99. ENDIF
  100. #if defined key_agrif
  101. CALL Agrif_trc ! AGRIF zoom boundaries
  102. #endif
  103. ! Update after tracer on domain lateral boundaries
  104. DO jn = 1, jptra
  105. CALL lbc_lnk( tra(:,:,:,jn), 'T', 1. )
  106. END DO
  107. #if defined key_bdy
  108. !! CALL bdy_trc( kt ) ! BDY open boundaries
  109. #endif
  110. ! set time step size (Euler/Leapfrog)
  111. IF( (neuler == 0 .AND. kt == nittrc000) .OR. ln_top_euler ) THEN ; r2dt(:) = rdttrc(:) ! (Euler)
  112. ELSEIF( kt <= nittrc000 + nn_dttrc ) THEN ; r2dt(:) = 2.* rdttrc(:) ! at nit000 or nit000+1 (Leapfrog)
  113. ENDIF
  114. ! trends computation initialisation
  115. IF( l_trdtrc ) THEN
  116. CALL wrk_alloc( jpi, jpj, jpk, jptra, ztrdt ) !* store now fields before applying the Asselin filter
  117. ztrdt(:,:,:,:) = trn(:,:,:,:)
  118. ENDIF
  119. ! Leap-Frog + Asselin filter time stepping
  120. IF( (neuler == 0 .AND. kt == nittrc000) .OR. ln_top_euler ) THEN ! Euler time-stepping (only swap)
  121. ! ! (only swap)
  122. DO jn = 1, jptra
  123. DO jk = 1, jpkm1
  124. trn(:,:,jk,jn) = tra(:,:,jk,jn)
  125. trb(:,:,jk,jn) = trn(:,:,jk,jn)
  126. END DO
  127. END DO
  128. !
  129. ELSE
  130. IF( .NOT. lk_offline ) THEN ! Leap-Frog + Asselin filter time stepping
  131. IF( lk_vvl ) THEN ; CALL tra_nxt_vvl( kt, nittrc000, rdttrc, 'TRC', trb, trn, tra, &
  132. & sbc_trc, sbc_trc_b, jptra ) ! variable volume level (vvl)
  133. ELSE ; CALL tra_nxt_fix( kt, nittrc000, 'TRC', trb, trn, tra, jptra ) ! fixed volume level
  134. ENDIF
  135. ELSE
  136. CALL trc_nxt_off( kt ) ! offline
  137. ENDIF
  138. ENDIF
  139. ! trends computation
  140. IF( l_trdtrc ) THEN ! trends
  141. DO jn = 1, jptra
  142. DO jk = 1, jpkm1
  143. zfact = 1.e0 / r2dt(jk)
  144. ztrdt(:,:,jk,jn) = ( trb(:,:,jk,jn) - ztrdt(:,:,jk,jn) ) * zfact
  145. CALL trd_tra( kt, 'TRC', jn, jptra_atf, ztrdt )
  146. END DO
  147. END DO
  148. CALL wrk_dealloc( jpi, jpj, jpk, jptra, ztrdt )
  149. END IF
  150. !
  151. IF(ln_ctl) THEN ! print mean trends (used for debugging)
  152. WRITE(charout, FMT="('nxt')")
  153. CALL prt_ctl_trc_info(charout)
  154. CALL prt_ctl_trc(tab4d=trn, mask=tmask, clinfo=ctrcnm)
  155. ENDIF
  156. !
  157. IF( nn_timing == 1 ) CALL timing_stop('trc_nxt')
  158. !
  159. END SUBROUTINE trc_nxt
  160. SUBROUTINE trc_nxt_off( kt )
  161. !!----------------------------------------------------------------------
  162. !! *** ROUTINE tra_nxt_vvl ***
  163. !!
  164. !! ** Purpose : Time varying volume: apply the Asselin time filter
  165. !! and swap the tracer fields.
  166. !!
  167. !! ** Method : - Apply a thickness weighted Asselin time filter on now fields.
  168. !! - save in (ta,sa) a thickness weighted average over the three
  169. !! time levels which will be used to compute rdn and thus the semi-
  170. !! implicit hydrostatic pressure gradient (ln_dynhpg_imp = T)
  171. !! - swap tracer fields to prepare the next time_step.
  172. !! This can be summurized for tempearture as:
  173. !! ztm = ( e3t_n*tn + rbcp*[ e3t_b*tb - 2 e3t_n*tn + e3t_a*ta ] ) ln_dynhpg_imp = T
  174. !! /( e3t_n + rbcp*[ e3t_b - 2 e3t_n + e3t_a ] )
  175. !! ztm = 0 otherwise
  176. !! tb = ( e3t_n*tn + atfp*[ e3t_b*tb - 2 e3t_n*tn + e3t_a*ta ] )
  177. !! /( e3t_n + atfp*[ e3t_b - 2 e3t_n + e3t_a ] )
  178. !! tn = ta
  179. !! ta = zt (NB: reset to 0 after eos_bn2 call)
  180. !!
  181. !! ** Action : - (tb,sb) and (tn,sn) ready for the next time step
  182. !! - (ta,sa) time averaged (t,s) (ln_dynhpg_imp = T)
  183. !!----------------------------------------------------------------------
  184. INTEGER , INTENT(in ) :: kt ! ocean time-step index
  185. !!
  186. INTEGER :: ji, jj, jk, jn ! dummy loop indices
  187. REAL(wp) :: ztc_a , ztc_n , ztc_b , ztc_f , ztc_d ! local scalar
  188. REAL(wp) :: ze3t_b, ze3t_n, ze3t_a, ze3t_f, ze3t_d ! - -
  189. !!----------------------------------------------------------------------
  190. !
  191. IF( kt == nittrc000 ) THEN
  192. IF(lwp) WRITE(numout,*)
  193. IF(lwp) WRITE(numout,*) 'trc_nxt_off : time stepping'
  194. IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
  195. IF( lk_vvl ) THEN
  196. rfact1 = atfp * rdttrc(1)
  197. rfact2 = rfact1 / rau0
  198. ENDIF
  199. ENDIF
  200. !
  201. DO jn = 1, jptra
  202. DO jk = 1, jpkm1
  203. DO jj = 1, jpj
  204. DO ji = 1, jpi
  205. ze3t_b = fse3t_b(ji,jj,jk)
  206. ze3t_n = fse3t_n(ji,jj,jk)
  207. ze3t_a = fse3t_a(ji,jj,jk)
  208. ! ! tracer content at Before, now and after
  209. ztc_b = trb(ji,jj,jk,jn) * ze3t_b
  210. ztc_n = trn(ji,jj,jk,jn) * ze3t_n
  211. ztc_a = tra(ji,jj,jk,jn) * ze3t_a
  212. !
  213. ze3t_d = ze3t_a - 2. * ze3t_n + ze3t_b
  214. ztc_d = ztc_a - 2. * ztc_n + ztc_b
  215. !
  216. ze3t_f = ze3t_n + atfp * ze3t_d
  217. ztc_f = ztc_n + atfp * ztc_d
  218. !
  219. IF( lk_vvl .AND. jk == mikt(ji,jj) ) THEN ! first level
  220. ze3t_f = ze3t_f - rfact2 * ( emp_b(ji,jj) - emp(ji,jj) )
  221. ztc_f = ztc_f - rfact1 * ( sbc_trc(ji,jj,jn) - sbc_trc_b(ji,jj,jn) )
  222. ENDIF
  223. ze3t_f = 1.e0 / ze3t_f
  224. trb(ji,jj,jk,jn) = ztc_f * ze3t_f ! ptb <-- ptn filtered
  225. trn(ji,jj,jk,jn) = tra(ji,jj,jk,jn) ! ptn <-- pta
  226. !
  227. END DO
  228. END DO
  229. END DO
  230. !
  231. END DO
  232. !
  233. END SUBROUTINE trc_nxt_off
  234. #else
  235. !!----------------------------------------------------------------------
  236. !! Default option Empty module
  237. !!----------------------------------------------------------------------
  238. CONTAINS
  239. SUBROUTINE trc_nxt( kt )
  240. INTEGER, INTENT(in) :: kt
  241. WRITE(*,*) 'trc_nxt: You should not have seen this print! error?', kt
  242. END SUBROUTINE trc_nxt
  243. #endif
  244. !!======================================================================
  245. END MODULE trcnxt