New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
trazdf.F90 in NEMO/branches/2018/dev_r9838_ENHANCE04_RK3/src/OCE/TRA – NEMO

source: NEMO/branches/2018/dev_r9838_ENHANCE04_RK3/src/OCE/TRA/trazdf.F90 @ 10030

Last change on this file since 10030 was 10030, checked in by gm, 6 years ago

#1911 (ENHANCE-04): RK3 branch - step II.3 remove e3uw_$ e3vw_$, except e3.w_0 and use only after e3 in dyn/trazdf

  • Property svn:keywords set to Id
File size: 12.4 KB
Line 
1MODULE trazdf
2   !!==============================================================================
3   !!                 ***  MODULE  trazdf  ***
4   !! Ocean active tracers:  vertical component of the tracer mixing trend
5   !!==============================================================================
6   !! History :  1.0  !  2005-11  (G. Madec)  Original code
7   !!            3.0  !  2008-01  (C. Ethe, G. Madec)  merge TRC-TRA
8   !!            4.0  !  2017-06  (G. Madec)  remove explict time-stepping option
9   !!----------------------------------------------------------------------
10
11   !!----------------------------------------------------------------------
12   !!   tra_zdf       : Update the tracer trend with the vertical diffusion
13   !!----------------------------------------------------------------------
14   USE oce            ! ocean dynamics and tracers variables
15   USE dom_oce        ! ocean space and time domain variables
16   USE domvvl         ! variable volume
17   USE phycst         ! physical constant
18   USE zdf_oce        ! ocean vertical physics variables
19   USE sbc_oce        ! surface boundary condition: ocean
20   USE ldftra         ! lateral diffusion: eddy diffusivity
21   USE ldfslp         ! lateral diffusion: iso-neutral slope
22   USE trd_oce        ! trends: ocean variables
23   USE trdtra         ! trends: tracer trend manager
24   !
25   USE in_out_manager ! I/O manager
26   USE prtctl         ! Print control
27   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
28   USE lib_mpp        ! MPP library
29   USE timing         ! Timing
30
31   IMPLICIT NONE
32   PRIVATE
33
34   PUBLIC   tra_zdf       ! called by step.F90
35   PUBLIC   tra_zdf_imp   ! called by trczdf.F90
36
37   !! * Substitutions
38#  include "vectopt_loop_substitute.h90"
39   !!----------------------------------------------------------------------
40   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
41   !! $Id$
42   !! Software governed by the CeCILL licence     (./LICENSE)
43   !!----------------------------------------------------------------------
44CONTAINS
45
46   SUBROUTINE tra_zdf( kt )
47      !!----------------------------------------------------------------------
48      !!                  ***  ROUTINE tra_zdf  ***
49      !!
50      !! ** Purpose :   compute the vertical ocean tracer physics.
51      !!---------------------------------------------------------------------
52      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
53      !
54      INTEGER  ::   jk, jts   ! Dummy loop indices
55      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::   ztrd   ! 4D workspace
56      !!---------------------------------------------------------------------
57      !
58      IF( ln_timing )   CALL timing_start('tra_zdf')
59      !
60      IF( kt == nit000 )  THEN
61         IF(lwp)WRITE(numout,*)
62         IF(lwp)WRITE(numout,*) 'tra_zdf : implicit vertical mixing on T & S'
63         IF(lwp)WRITE(numout,*) '~~~~~~~ '
64      ENDIF
65      !
66      IF( l_trdtra )   THEN                  !* Save input tsa  trend
67         ALLOCATE( ztrd(jpi,jpj,jpk,jpts) )
68         ztrd(:,:,:,:) = tsa(:,:,:,:)
69      ENDIF
70      !
71      !                                      !* compute lateral mixing trend and add it to the general trend
72      CALL tra_zdf_imp( kt, nit000, 'TRA', rDt, tsb, tsa, jpts ) 
73
74!!gm WHY here !   and I don't like that !
75      ! DRAKKAR SSS control {
76      ! JMM avoid negative salinities near river outlet ! Ugly fix
77      ! JMM : restore negative salinities to small salinities:
78      WHERE( tsa(:,:,:,jp_sal) < 0._wp )   tsa(:,:,:,jp_sal) = 0.1_wp
79!!gm
80
81      IF( l_trdtra )   THEN                      ! save the vertical diffusive trends for further diagnostics
82         DO jts = 1, jpts
83            DO jk = 1, jpkm1
84               ztrd(:,:,jk,jts) = ( ( tsa(:,:,jk,jts)*e3t_a(:,:,jk) - tsb(:,:,jk,jts)*e3t_b(:,:,jk) ) / (e3t_n(:,:,jk)*rDt) )   &
85                  &            - ztrd(:,:,jk,jts)
86            END DO
87         END DO
88!!gm this should be moved in trdtra.F90 and done on all trends
89         CALL lbc_lnk( ztrd, 'T', 1. )
90!!gm
91         CALL trd_tra( kt, 'TRA', jp_tem, jptra_zdf, ztrd(:,:,:,jp_tem) )
92         CALL trd_tra( kt, 'TRA', jp_sal, jptra_zdf, ztrd(:,:,:,jp_sal) )
93         DEALLOCATE( ztrd )
94      ENDIF
95      !                                          ! print mean trends (used for debugging)
96      IF(ln_ctl)   CALL prt_ctl( tab3d_1=tsa(:,:,:,jp_tem), clinfo1=' zdf  - Ta: ', mask1=tmask,               &
97         &                       tab3d_2=tsa(:,:,:,jp_sal), clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
98      !
99      IF( ln_timing )   CALL timing_stop('tra_zdf')
100      !
101   END SUBROUTINE tra_zdf
102
103 
104   SUBROUTINE tra_zdf_imp( kt, kit000, cdtype, p2dt, ptb, pta, kjpt ) 
105      !!----------------------------------------------------------------------
106      !!                  ***  ROUTINE tra_zdf_imp  ***
107      !!
108      !! ** Purpose :   Compute the after tracer through a implicit computation
109      !!     of the vertical tracer diffusion (including the vertical component
110      !!     of lateral mixing (only for 2nd order operator, for fourth order
111      !!     it is already computed and add to the general trend in traldf)
112      !!
113      !! ** Method  :  The vertical diffusion of a tracer ,t , is given by:
114      !!          difft = dz( avt dz(t) ) = 1/e3t(Naa) dk+1( avt/e3w(Naa) dk(t) )
115      !!      It is computed using a backward time scheme (t=after field)
116      !!      which provide directly the after tracer field.
117      !!      If ln_zdfddm=T, use avs for salinity or for passive tracers
118      !!      Surface and bottom boundary conditions: no diffusive flux on
119      !!      both tracers (bottom, applied through the masked field avt).
120      !!      If iso-neutral mixing, add to avt the contribution due to lateral mixing.
121      !!
122      !! ** Action  : - pta  becomes the after tracer
123      !!---------------------------------------------------------------------
124      INTEGER                              , INTENT(in   ) ::   kt       ! ocean time-step index
125      INTEGER                              , INTENT(in   ) ::   kit000   ! first time step index
126      CHARACTER(len=3)                     , INTENT(in   ) ::   cdtype   ! =TRA or TRC (tracer indicator)
127      INTEGER                              , INTENT(in   ) ::   kjpt     ! number of tracers
128      REAL(wp)                             , INTENT(in   ) ::   p2dt     ! tracer time-step
129      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb      ! before and now tracer fields
130      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::   pta      ! in: tracer trend ; out: after tracer field
131      !
132      INTEGER  ::  ji, jj, jk, jn   ! dummy loop indices
133      REAL(wp) ::  zrhs             ! local scalars
134      REAL(wp), DIMENSION(jpi,jpj,jpk) ::  zwi, zwt, zwd, zws
135      !!---------------------------------------------------------------------
136      !
137      !                                               ! ============= !
138      DO jn = 1, kjpt                                 !  tracer loop  !
139         !                                            ! ============= !
140         !  Matrix construction
141         ! --------------------
142         ! Build matrix if temperature or salinity (only in double diffusion case) or first passive tracer
143         !
144         IF(  ( cdtype == 'TRA' .AND. ( jn == jp_tem .OR. ( jn == jp_sal .AND. ln_zdfddm ) ) ) .OR.   &
145            & ( cdtype == 'TRC' .AND. jn == 1 )  )  THEN
146            !
147            ! vertical mixing coef.: avt for temperature, avs for salinity and passive tracers
148            IF( cdtype == 'TRA' .AND. jn == jp_tem ) THEN   ;   zwt(:,:,2:jpk) = avt(:,:,2:jpk)
149            ELSE                                            ;   zwt(:,:,2:jpk) = avs(:,:,2:jpk)
150            ENDIF
151            zwt(:,:,1) = 0._wp
152            !
153            IF( l_ldfslp ) THEN            ! isoneutral diffusion: add the contribution
154               IF( ln_traldf_msc  ) THEN     ! MSC iso-neutral operator
155                  DO jk = 2, jpkm1
156                     DO jj = 2, jpjm1
157                        DO ji = fs_2, fs_jpim1   ! vector opt.
158                           zwt(ji,jj,jk) = zwt(ji,jj,jk) + akz(ji,jj,jk) 
159                        END DO
160                     END DO
161                  END DO
162               ELSE                          ! standard or triad iso-neutral operator
163                  DO jk = 2, jpkm1
164                     DO jj = 2, jpjm1
165                        DO ji = fs_2, fs_jpim1   ! vector opt.
166                           zwt(ji,jj,jk) = zwt(ji,jj,jk) + ah_wslp2(ji,jj,jk)
167                        END DO
168                     END DO
169                  END DO
170               ENDIF
171            ENDIF
172            !
173            ! Diagonal, lower (i), upper (s)  (including the bottom boundary condition since avt is masked)
174            DO jk = 1, jpkm1
175               DO jj = 2, jpjm1
176                  DO ji = fs_2, fs_jpim1   ! vector opt.
177                     zwi(ji,jj,jk) = - p2dt * zwt(ji,jj,jk  ) / e3w_a(ji,jj,jk  )
178                     zws(ji,jj,jk) = - p2dt * zwt(ji,jj,jk+1) / e3w_a(ji,jj,jk+1)
179                     zwd(ji,jj,jk) = e3t_a(ji,jj,jk) - zwi(ji,jj,jk) - zws(ji,jj,jk)
180                 END DO
181               END DO
182            END DO
183            !
184            !! Matrix inversion from the first level
185            !!----------------------------------------------------------------------
186            !   solve m.x = y  where m is a tri diagonal matrix ( jpk*jpk )
187            !
188            !        ( zwd1 zws1   0    0    0  )( zwx1 ) ( zwy1 )
189            !        ( zwi2 zwd2 zws2   0    0  )( zwx2 ) ( zwy2 )
190            !        (  0   zwi3 zwd3 zws3   0  )( zwx3 )=( zwy3 )
191            !        (        ...               )( ...  ) ( ...  )
192            !        (  0    0    0   zwik zwdk )( zwxk ) ( zwyk )
193            !
194            !   m is decomposed in the product of an upper and lower triangular matrix.
195            !   The 3 diagonal terms are in 3d arrays: zwd, zws, zwi.
196            !   Suffices i,s and d indicate "inferior" (below diagonal), diagonal
197            !   and "superior" (above diagonal) components of the tridiagonal system.
198            !   The solution will be in the 4d array pta.
199            !   The 3d array zwt is used as a work space array.
200            !   En route to the solution pta is used a to evaluate the rhs and then
201            !   used as a work space array: its value is modified.
202            !
203            DO jj = 2, jpjm1        !* 1st recurrence:   Tk = Dk - Ik Sk-1 / Tk-1   (increasing k)
204               DO ji = fs_2, fs_jpim1            ! done one for all passive tracers (so included in the IF instruction)
205                  zwt(ji,jj,1) = zwd(ji,jj,1)
206               END DO
207            END DO
208            DO jk = 2, jpkm1
209               DO jj = 2, jpjm1
210                  DO ji = fs_2, fs_jpim1
211                     zwt(ji,jj,jk) = zwd(ji,jj,jk) - zwi(ji,jj,jk) * zws(ji,jj,jk-1) / zwt(ji,jj,jk-1)
212                  END DO
213               END DO
214            END DO
215            !
216         ENDIF 
217         !         
218         DO jj = 2, jpjm1           !* 2nd recurrence:    Zk = Yk - Ik / Tk-1  Zk-1
219            DO ji = fs_2, fs_jpim1
220               pta(ji,jj,1,jn) = e3t_b(ji,jj,1) * ptb(ji,jj,1,jn) + p2dt * e3t_n(ji,jj,1) * pta(ji,jj,1,jn)
221            END DO
222         END DO
223         DO jk = 2, jpkm1
224            DO jj = 2, jpjm1
225               DO ji = fs_2, fs_jpim1
226                  zrhs = e3t_b(ji,jj,jk) * ptb(ji,jj,jk,jn) + p2dt * e3t_n(ji,jj,jk) * pta(ji,jj,jk,jn)   ! zrhs=right hand side
227                  pta(ji,jj,jk,jn) = zrhs - zwi(ji,jj,jk) / zwt(ji,jj,jk-1) * pta(ji,jj,jk-1,jn)
228               END DO
229            END DO
230         END DO
231         !
232         DO jj = 2, jpjm1           !* 3d recurrence:    Xk = (Zk - Sk Xk+1 ) / Tk   (result is the after tracer)
233            DO ji = fs_2, fs_jpim1
234               pta(ji,jj,jpkm1,jn) = pta(ji,jj,jpkm1,jn) / zwt(ji,jj,jpkm1) * tmask(ji,jj,jpkm1)
235            END DO
236         END DO
237         DO jk = jpk-2, 1, -1
238            DO jj = 2, jpjm1
239               DO ji = fs_2, fs_jpim1
240                  pta(ji,jj,jk,jn) = ( pta(ji,jj,jk,jn) - zws(ji,jj,jk) * pta(ji,jj,jk+1,jn) )   &
241                     &             / zwt(ji,jj,jk) * tmask(ji,jj,jk)
242               END DO
243            END DO
244         END DO
245         !                                            ! ================= !
246      END DO                                          !  end tracer loop  !
247      !                                               ! ================= !
248   END SUBROUTINE tra_zdf_imp
249
250   !!==============================================================================
251END MODULE trazdf
Note: See TracBrowser for help on using the repository browser.