/[MITgcm]/MITgcm/pkg/generic_advdiff/gad_advection.F
ViewVC logotype

Diff of /MITgcm/pkg/generic_advdiff/gad_advection.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1 by adcroft, Mon Sep 10 01:22:48 2001 UTC revision 1.50 by jmc, Thu Aug 16 02:16:37 2007 UTC
# Line 2  C $Header$ Line 2  C $Header$
2  C $Name$  C $Name$
3    
4  #include "GAD_OPTIONS.h"  #include "GAD_OPTIONS.h"
5    #undef MULTIDIM_OLD_VERSION
6    
7        SUBROUTINE GAD_ADVECTION(bi,bj,advectionScheme,tracerIdentity,  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
8       U                         Tracer,Gtracer,  CBOP
9       I                         myTime,myIter,myThid)  C !ROUTINE: GAD_ADVECTION
10  C     /==========================================================\  
11  C     | SUBROUTINE GAD_ADVECTION                                 |  C !INTERFACE: ==========================================================
12  C     | o Solves the pure advection tracer equation.             |        SUBROUTINE GAD_ADVECTION(
13  C     |==========================================================|       I     implicitAdvection, advectionScheme, vertAdvecScheme,
14  C     \==========================================================/       I     tracerIdentity,
15        IMPLICIT NONE       I     uVel, vVel, wVel, tracer,
16         O     gTracer,
17         I     bi,bj, myTime,myIter,myThid)
18    
19    C !DESCRIPTION:
20    C Calculates the tendency of a tracer due to advection.
21    C It uses the multi-dimensional method given in \ref{sect:multiDimAdvection}
22    C and can only be used for the non-linear advection schemes such as the
23    C direct-space-time method and flux-limiters.
24    C
25    C The algorithm is as follows:
26    C \begin{itemize}
27    C \item{$\theta^{(n+1/3)} = \theta^{(n)}
28    C      - \Delta t \partial_x (u\theta^{(n)}) + \theta^{(n)} \partial_x u$}
29    C \item{$\theta^{(n+2/3)} = \theta^{(n+1/3)}
30    C      - \Delta t \partial_y (v\theta^{(n+1/3)}) + \theta^{(n)} \partial_y v$}
31    C \item{$\theta^{(n+3/3)} = \theta^{(n+2/3)}
32    C      - \Delta t \partial_r (w\theta^{(n+2/3)}) + \theta^{(n)} \partial_r w$}
33    C \item{$G_\theta = ( \theta^{(n+3/3)} - \theta^{(n)} )/\Delta t$}
34    C \end{itemize}
35    C
36    C The tendency (output) is over-written by this routine.
37    
38  C     == Global variables ===  C !USES: ===============================================================
39          IMPLICIT NONE
40  #include "SIZE.h"  #include "SIZE.h"
41  #include "EEPARAMS.h"  #include "EEPARAMS.h"
42  #include "PARAMS.h"  #include "PARAMS.h"
 #include "DYNVARS.h"  
43  #include "GRID.h"  #include "GRID.h"
44  #include "GAD.h"  #include "GAD.h"
45    #ifdef ALLOW_AUTODIFF_TAMC
46  C     == Routine arguments ==  # include "tamc.h"
47        INTEGER bi,bj  # include "tamc_keys.h"
48        INTEGER advectionScheme  # ifdef ALLOW_PTRACERS
49    #  include "PTRACERS_SIZE.h"
50    # endif
51    #endif
52    #ifdef ALLOW_EXCH2
53    #include "W2_EXCH2_TOPOLOGY.h"
54    #include "W2_EXCH2_PARAMS.h"
55    #endif /* ALLOW_EXCH2 */
56    
57    C !INPUT PARAMETERS: ===================================================
58    C  implicitAdvection :: implicit vertical advection (later on)
59    C  advectionScheme   :: advection scheme to use (Horizontal plane)
60    C  vertAdvecScheme   :: advection scheme to use (vertical direction)
61    C  tracerIdentity    :: tracer identifier (required only for OBCS)
62    C  uVel              :: velocity, zonal component
63    C  vVel              :: velocity, meridional component
64    C  wVel              :: velocity, vertical component
65    C  tracer            :: tracer field
66    C  bi,bj             :: tile indices
67    C  myTime            :: current time
68    C  myIter            :: iteration number
69    C  myThid            :: thread number
70          LOGICAL implicitAdvection
71          INTEGER advectionScheme, vertAdvecScheme
72        INTEGER tracerIdentity        INTEGER tracerIdentity
73        _RL Tracer(1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr,nSx,nSy)        _RL uVel  (1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr,nSx,nSy)
74        _RL Gtracer(1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr,nSx,nSy)        _RL vVel  (1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr,nSx,nSy)
75          _RL wVel  (1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr,nSx,nSy)
76          _RL tracer(1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr,nSx,nSy)
77          INTEGER bi,bj
78        _RL myTime        _RL myTime
79        INTEGER myIter        INTEGER myIter
80        INTEGER myThid        INTEGER myThid
81    
82  C     == Local variables  C !OUTPUT PARAMETERS: ==================================================
83        _RS maskUp  (1-OLx:sNx+OLx,1-OLy:sNy+OLy)  C  gTracer           :: tendency array
84          _RL gTracer(1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr,nSx,nSy)
85    
86    C !LOCAL VARIABLES: ====================================================
87    C  maskUp        :: 2-D array for mask at W points
88    C  maskLocW      :: 2-D array for mask at West points
89    C  maskLocS      :: 2-D array for mask at South points
90    C  iMin,iMax,    :: loop range for called routines
91    C  jMin,jMax     :: loop range for called routines
92    C [iMin,iMax]Upd :: loop range to update tracer field
93    C [jMin,jMax]Upd :: loop range to update tracer field
94    C  i,j,k         :: loop indices
95    C  kUp           :: index into 2 1/2D array, toggles between 1 and 2
96    C  kDown         :: index into 2 1/2D array, toggles between 2 and 1
97    C  kp1           :: =k+1 for k<Nr, =Nr for k=Nr
98    C  xA,yA         :: areas of X and Y face of tracer cells
99    C  uFld,vFld     :: 2-D local copy of horizontal velocity, U,V components
100    C  wFld          :: 2-D local copy of vertical velocity
101    C  uTrans,vTrans :: 2-D arrays of volume transports at U,V points
102    C  rTrans        :: 2-D arrays of volume transports at W points
103    C  rTransKp1     :: vertical volume transport at interface k+1
104    C  af            :: 2-D array for horizontal advective flux
105    C  afx           :: 2-D array for horizontal advective flux, x direction
106    C  afy           :: 2-D array for horizontal advective flux, y direction
107    C  fVerT         :: 2 1/2D arrays for vertical advective flux
108    C  localTij      :: 2-D array, temporary local copy of tracer fld
109    C  localTijk     :: 3-D array, temporary local copy of tracer fld
110    C  kp1Msk        :: flag (0,1) for over-riding mask for W levels
111    C  calc_fluxes_X :: logical to indicate to calculate fluxes in X dir
112    C  calc_fluxes_Y :: logical to indicate to calculate fluxes in Y dir
113    C  interiorOnly  :: only update the interior of myTile, but not the edges
114    C  overlapOnly   :: only update the edges of myTile, but not the interior
115    C  nipass        :: number of passes in multi-dimensional method
116    C  ipass         :: number of the current pass being made
117    C  myTile        :: variables used to determine which cube face
118    C  nCFace        :: owns a tile for cube grid runs using
119    C                :: multi-dim advection.
120    C [N,S,E,W]_edge :: true if N,S,E,W edge of myTile is an Edge of the cube
121    c     _RS maskUp  (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
122          _RS maskLocW(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
123          _RS maskLocS(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
124        INTEGER iMin,iMax,jMin,jMax        INTEGER iMin,iMax,jMin,jMax
125        INTEGER i,j,k,kup,kDown,kp1        INTEGER iMinUpd,iMaxUpd,jMinUpd,jMaxUpd
126          INTEGER i,j,k,kUp,kDown
127        _RS xA      (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RS xA      (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
128        _RS yA      (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RS yA      (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
129          _RL uFld    (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
130          _RL vFld    (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
131          _RL wFld    (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
132        _RL uTrans  (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL uTrans  (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
133        _RL vTrans  (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL vTrans  (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
134        _RL rTrans  (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL rTrans  (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
135          _RL rTransKp1(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
136        _RL af      (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL af      (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
137          _RL afx     (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
138          _RL afy     (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
139        _RL fVerT   (1-OLx:sNx+OLx,1-OLy:sNy+OLy,2)        _RL fVerT   (1-OLx:sNx+OLx,1-OLy:sNy+OLy,2)
140        _RL localTij(1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL localTij(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
141        _RL localTijk(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr)        _RL localTijk(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr)
142        _RL kp1Msk        _RL kp1Msk
143          LOGICAL calc_fluxes_X, calc_fluxes_Y, withSigns
144          LOGICAL interiorOnly, overlapOnly
145          INTEGER nipass,ipass
146          INTEGER nCFace
147          LOGICAL N_edge, S_edge, E_edge, W_edge
148    #ifdef ALLOW_EXCH2
149          INTEGER myTile
150    #endif
151    #ifdef ALLOW_DIAGNOSTICS
152          CHARACTER*8 diagName
153          CHARACTER*4 GAD_DIAG_SUFX, diagSufx
154          EXTERNAL    GAD_DIAG_SUFX
155    #endif
156    CEOP
157    
158    #ifdef ALLOW_AUTODIFF_TAMC
159              act0 = tracerIdentity - 1
160              max0 = maxpass
161              act1 = bi - myBxLo(myThid)
162              max1 = myBxHi(myThid) - myBxLo(myThid) + 1
163              act2 = bj - myByLo(myThid)
164              max2 = myByHi(myThid) - myByLo(myThid) + 1
165              act3 = myThid - 1
166              max3 = nTx*nTy
167              act4 = ikey_dynamics - 1
168              igadkey = (act0 + 1)
169         &                      + act1*max0
170         &                      + act2*max0*max1
171         &                      + act3*max0*max1*max2
172         &                      + act4*max0*max1*max2*max3
173              if (tracerIdentity.GT.maxpass) then
174                 print *, 'ph-pass gad_advection ', maxpass, tracerIdentity
175                 STOP 'maxpass seems smaller than tracerIdentity'
176              endif
177    #endif /* ALLOW_AUTODIFF_TAMC */
178    
179    #ifdef ALLOW_DIAGNOSTICS
180    C--   Set diagnostic suffix for the current tracer
181          IF ( useDiagnostics ) THEN
182            diagSufx = GAD_DIAG_SUFX( tracerIdentity, myThid )
183          ENDIF
184    #endif
185    
186  C--   Set up work arrays with valid (i.e. not NaN) values  C--   Set up work arrays with valid (i.e. not NaN) values
187  C     These inital values do not alter the numerical results. They  C     These inital values do not alter the numerical results. They
# Line 60  C     uninitialised but inert locations. Line 197  C     uninitialised but inert locations.
197          rTrans(i,j)  = 0. _d 0          rTrans(i,j)  = 0. _d 0
198          fVerT(i,j,1) = 0. _d 0          fVerT(i,j,1) = 0. _d 0
199          fVerT(i,j,2) = 0. _d 0          fVerT(i,j,2) = 0. _d 0
200            rTransKp1(i,j)= 0. _d 0
201    #ifdef ALLOW_AUTODIFF_TAMC
202            localTij(i,j) = 0. _d 0
203            wfld(i,j)    = 0. _d 0
204    #endif
205         ENDDO         ENDDO
206        ENDDO        ENDDO
207    
208    C--   Set tile-specific parameters for horizontal fluxes
209          IF (useCubedSphereExchange) THEN
210           nipass=3
211    #ifdef ALLOW_AUTODIFF_TAMC
212           IF ( nipass.GT.maxcube ) STOP 'maxcube needs to be = 3'
213    #endif
214    #ifdef ALLOW_EXCH2
215           myTile = W2_myTileList(bi)
216           nCFace = exch2_myFace(myTile)
217           N_edge = exch2_isNedge(myTile).EQ.1
218           S_edge = exch2_isSedge(myTile).EQ.1
219           E_edge = exch2_isEedge(myTile).EQ.1
220           W_edge = exch2_isWedge(myTile).EQ.1
221    #else
222           nCFace = bi
223           N_edge = .TRUE.
224           S_edge = .TRUE.
225           E_edge = .TRUE.
226           W_edge = .TRUE.
227    #endif
228          ELSE
229           nipass=2
230           nCFace = bi
231           N_edge = .FALSE.
232           S_edge = .FALSE.
233           E_edge = .FALSE.
234           W_edge = .FALSE.
235          ENDIF
236    
237        iMin = 1-OLx        iMin = 1-OLx
238        iMax = sNx+OLx        iMax = sNx+OLx
239        jMin = 1-OLy        jMin = 1-OLy
# Line 70  C     uninitialised but inert locations. Line 241  C     uninitialised but inert locations.
241    
242  C--   Start of k loop for horizontal fluxes  C--   Start of k loop for horizontal fluxes
243        DO k=1,Nr        DO k=1,Nr
244    #ifdef ALLOW_AUTODIFF_TAMC
245             kkey = (igadkey-1)*Nr + k
246    CADJ STORE tracer(:,:,k,bi,bj) =
247    CADJ &     comlev1_bibj_k_gad, key=kkey, byte=isbyte
248    #endif /* ALLOW_AUTODIFF_TAMC */
249    
250  C--   Get temporary terms used by tendency routines  C--   Get temporary terms used by tendency routines
251        CALL CALC_COMMON_FACTORS (        CALL CALC_COMMON_FACTORS (
252       I         bi,bj,iMin,iMax,jMin,jMax,k,       I         uVel, vVel,
253       O         xA,yA,uTrans,vTrans,rTrans,maskUp,       O         uFld, vFld, uTrans, vTrans, xA, yA,
254       I         myThid)       I         k,bi,bj, myThid )
255    
256    #ifdef ALLOW_GMREDI
257    C--   Residual transp = Bolus transp + Eulerian transp
258          IF (useGMRedi)
259         &   CALL GMREDI_CALC_UVFLOW(
260         U                  uFld, vFld, uTrans, vTrans,
261         I                  k, bi, bj, myThid )
262    #endif /* ALLOW_GMREDI */
263    
264  C--   Make local copy of tracer array  C--   Make local copy of tracer array and mask West & South
265        DO j=1-OLy,sNy+OLy        DO j=1-OLy,sNy+OLy
266         DO i=1-OLx,sNx+OLx         DO i=1-OLx,sNx+OLx
267          localTij(i,j)=tracer(i,j,k,bi,bj)           localTij(i,j)=tracer(i,j,k,bi,bj)
268             maskLocW(i,j)=maskW(i,j,k,bi,bj)
269             maskLocS(i,j)=maskS(i,j,k,bi,bj)
270         ENDDO         ENDDO
271        ENDDO        ENDDO
272    
273  C-    Advective flux in X  cph-exch2#ifndef ALLOW_AUTODIFF_TAMC
274        DO j=1-Oly,sNy+Oly        IF (useCubedSphereExchange) THEN
275         DO i=1-Olx,sNx+Olx          withSigns = .FALSE.
276          af(i,j) = 0.          CALL FILL_CS_CORNER_UV_RS(
277         ENDDO       &            withSigns, maskLocW,maskLocS, bi,bj, myThid )
278        ENDDO        ENDIF
279        IF (advectionScheme.EQ.ENUM_FLUX_LIMIT) THEN  cph-exch2#endif
280         CALL GAD_FLUXLIMIT_ADV_X(  
281       &      bi,bj,k,deltaTtracer,uTrans,uVel,localTij,af,myThid)  C--   Multiple passes for different directions on different tiles
282        ELSEIF (advectionScheme.EQ.ENUM_DST3 ) THEN  C--   For cube need one pass for each of red, green and blue axes.
283         CALL GAD_DST3_ADV_X(        DO ipass=1,nipass
284       &       bi,bj,k,deltaTtracer,uTrans,uVel,localTij,af,myThid)  #ifdef ALLOW_AUTODIFF_TAMC
285        ELSEIF (advectionScheme.EQ.ENUM_DST3_FLUX_LIMIT ) THEN           passkey = ipass + (k-1)      *maxcube
286         CALL GAD_DST3FL_ADV_X(       &                   + (igadkey-1)*maxcube*Nr
287       &       bi,bj,k,deltaTtracer,uTrans,uVel,localTij,af,myThid)           IF (nipass .GT. maxpass) THEN
288              STOP 'GAD_ADVECTION: nipass > maxcube. check tamc.h'
289             ENDIF
290    #endif /* ALLOW_AUTODIFF_TAMC */
291    
292          interiorOnly = .FALSE.
293          overlapOnly  = .FALSE.
294          IF (useCubedSphereExchange) THEN
295    #ifdef MULTIDIM_OLD_VERSION
296    C-    CubedSphere : pass 3 times, with full update of local tracer field
297           IF (ipass.EQ.1) THEN
298            calc_fluxes_X = nCFace.EQ.1 .OR. nCFace.EQ.2
299            calc_fluxes_Y = nCFace.EQ.4 .OR. nCFace.EQ.5
300           ELSEIF (ipass.EQ.2) THEN
301            calc_fluxes_X = nCFace.EQ.3 .OR. nCFace.EQ.4
302            calc_fluxes_Y = nCFace.EQ.6 .OR. nCFace.EQ.1
303    #else /* MULTIDIM_OLD_VERSION */
304    C-    CubedSphere : pass 3 times, with partial update of local tracer field
305           IF (ipass.EQ.1) THEN
306            overlapOnly  = MOD(nCFace,3).EQ.0
307            interiorOnly = MOD(nCFace,3).NE.0
308            calc_fluxes_X = nCFace.EQ.6 .OR. nCFace.EQ.1 .OR. nCFace.EQ.2
309            calc_fluxes_Y = nCFace.EQ.3 .OR. nCFace.EQ.4 .OR. nCFace.EQ.5
310           ELSEIF (ipass.EQ.2) THEN
311            overlapOnly  = MOD(nCFace,3).EQ.2
312            calc_fluxes_X = nCFace.EQ.2 .OR. nCFace.EQ.3 .OR. nCFace.EQ.4
313            calc_fluxes_Y = nCFace.EQ.5 .OR. nCFace.EQ.6 .OR. nCFace.EQ.1
314    #endif /* MULTIDIM_OLD_VERSION */
315           ELSE
316            calc_fluxes_X = nCFace.EQ.5 .OR. nCFace.EQ.6
317            calc_fluxes_Y = nCFace.EQ.2 .OR. nCFace.EQ.3
318           ENDIF
319        ELSE        ELSE
320         STOP 'GAD_ADVECTION: adv. scheme incompatibale with mutli-dim'  C-    not CubedSphere
321            calc_fluxes_X = MOD(ipass,2).EQ.1
322            calc_fluxes_Y = .NOT.calc_fluxes_X
323        ENDIF        ENDIF
324        DO j=1-Oly,sNy+Oly  
325         DO i=1-Olx,sNx+Olx-1  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
326          localTij(i,j)=localTij(i,j)-deltaTtracer*  C--   X direction
327       &    _recip_hFacC(i,j,k,bi,bj)*recip_drF(k)  C-     Advective flux in X
328       &    *recip_rA(i,j,bi,bj)          DO j=1-Oly,sNy+Oly
329       &    *( af(i+1,j)-af(i,j)           DO i=1-Olx,sNx+Olx
330       &      -tracer(i,j,k,bi,bj)*(uTrans(i+1,j)-uTrans(i,j))            af(i,j) = 0.
331       &     )           ENDDO
332         ENDDO          ENDDO
333        ENDDO  C
334    #ifdef ALLOW_AUTODIFF_TAMC
335    # ifndef DISABLE_MULTIDIM_ADVECTION
336    CADJ STORE localTij(:,:)  =
337    CADJ &     comlev1_bibj_k_gad_pass, key=passkey, byte=isbyte
338    CADJ STORE af(:,:)  =
339    CADJ &     comlev1_bibj_k_gad_pass, key=passkey, byte=isbyte
340    # endif
341    #endif /* ALLOW_AUTODIFF_TAMC */
342    C
343          IF (calc_fluxes_X) THEN
344    
345    C-     Do not compute fluxes if
346    C       a) needed in overlap only
347    C   and b) the overlap of myTile are not cube-face Edges
348           IF ( .NOT.overlapOnly .OR. N_edge .OR. S_edge ) THEN
349    
350    cph-exch2#ifndef ALLOW_AUTODIFF_TAMC
351    C-     Internal exchange for calculations in X
352    #ifdef MULTIDIM_OLD_VERSION
353            IF ( useCubedSphereExchange ) THEN
354    #else
355            IF ( useCubedSphereExchange .AND.
356         &       ( overlapOnly .OR. ipass.EQ.1 ) ) THEN
357    #endif
358             CALL FILL_CS_CORNER_TR_RL( .TRUE., .FALSE.,
359         &                              localTij, bi,bj, myThid )
360            ENDIF
361    cph-exch2#endif
362    
363    #ifdef ALLOW_AUTODIFF_TAMC
364    # ifndef DISABLE_MULTIDIM_ADVECTION
365    CADJ STORE localTij(:,:)  =
366    CADJ &     comlev1_bibj_k_gad_pass, key=passkey, byte=isbyte
367    # endif
368    #endif /* ALLOW_AUTODIFF_TAMC */
369    
370            IF ( advectionScheme.EQ.ENUM_UPWIND_1RST
371         &     .OR. advectionScheme.EQ.ENUM_DST2 ) THEN
372              CALL GAD_DST2U1_ADV_X( bi,bj,k, advectionScheme, .TRUE.,
373         I                           dTtracerLev(k),uTrans,uFld,localTij,
374         O                           af, myThid )
375            ELSEIF (advectionScheme.EQ.ENUM_FLUX_LIMIT) THEN
376              CALL GAD_FLUXLIMIT_ADV_X( bi,bj,k, .TRUE., dTtracerLev(k),
377         I                              uTrans, uFld, maskLocW, localTij,
378         O                              af, myThid )
379            ELSEIF (advectionScheme.EQ.ENUM_DST3 ) THEN
380              CALL GAD_DST3_ADV_X(      bi,bj,k, .TRUE., dTtracerLev(k),
381         I                              uTrans, uFld, maskLocW, localTij,
382         O                              af, myThid )
383            ELSEIF (advectionScheme.EQ.ENUM_DST3_FLUX_LIMIT ) THEN
384              CALL GAD_DST3FL_ADV_X(    bi,bj,k, .TRUE., dTtracerLev(k),
385         I                              uTrans, uFld, maskLocW, localTij,
386         O                              af, myThid )
387    #ifndef ALLOW_AUTODIFF_TAMC
388            ELSEIF (advectionScheme.EQ.ENUM_OS7MP ) THEN
389              CALL GAD_OS7MP_ADV_X(     bi,bj,k, .TRUE., dTtracerLev(k),
390         I                              uTrans, uFld, maskLocW, localTij,
391         O                              af, myThid )
392    #endif
393            ELSE
394             STOP 'GAD_ADVECTION: adv. scheme incompatibale with multi-dim'
395            ENDIF
396    
397    C-     Advective flux in X : done
398           ENDIF
399    
400    cph-exch2#ifndef ALLOW_AUTODIFF_TAMC
401    C-     Internal exchange for next calculations in Y
402           IF ( overlapOnly .AND. ipass.EQ.1 ) THEN
403             CALL FILL_CS_CORNER_TR_RL(.FALSE., .FALSE.,
404         &                              localTij, bi,bj, myThid )
405           ENDIF
406    cph-exch2#endif
407    
408    C-     Update the local tracer field where needed:
409    
410    C      update in overlap-Only
411           IF ( overlapOnly ) THEN
412            iMinUpd = 1-Olx+1
413            iMaxUpd = sNx+Olx-1
414    C- notes: these 2 lines below have no real effect (because recip_hFac=0
415    C         in corner region) but safer to keep them.
416            IF ( W_edge ) iMinUpd = 1
417            IF ( E_edge ) iMaxUpd = sNx
418    
419            IF ( S_edge ) THEN
420             DO j=1-Oly,0
421              DO i=iMinUpd,iMaxUpd
422               localTij(i,j) = localTij(i,j)
423         &      -dTtracerLev(k)*recip_rhoFacC(k)
424         &       *_recip_hFacC(i,j,k,bi,bj)*recip_drF(k)
425         &       *recip_rA(i,j,bi,bj)*recip_deepFac2C(k)
426         &       *( af(i+1,j)-af(i,j)
427         &         -tracer(i,j,k,bi,bj)*(uTrans(i+1,j)-uTrans(i,j))
428         &        )
429              ENDDO
430             ENDDO
431            ENDIF
432            IF ( N_edge ) THEN
433             DO j=sNy+1,sNy+Oly
434              DO i=iMinUpd,iMaxUpd
435               localTij(i,j) = localTij(i,j)
436         &      -dTtracerLev(k)*recip_rhoFacC(k)
437         &       *_recip_hFacC(i,j,k,bi,bj)*recip_drF(k)
438         &       *recip_rA(i,j,bi,bj)*recip_deepFac2C(k)
439         &       *( af(i+1,j)-af(i,j)
440         &         -tracer(i,j,k,bi,bj)*(uTrans(i+1,j)-uTrans(i,j))
441         &        )
442              ENDDO
443             ENDDO
444            ENDIF
445    
446           ELSE
447    C      do not only update the overlap
448            jMinUpd = 1-Oly
449            jMaxUpd = sNy+Oly
450            IF ( interiorOnly .AND. S_edge ) jMinUpd = 1
451            IF ( interiorOnly .AND. N_edge ) jMaxUpd = sNy
452            DO j=jMinUpd,jMaxUpd
453             DO i=1-Olx+1,sNx+Olx-1
454               localTij(i,j) = localTij(i,j)
455         &      -dTtracerLev(k)*recip_rhoFacC(k)
456         &       *_recip_hFacC(i,j,k,bi,bj)*recip_drF(k)
457         &       *recip_rA(i,j,bi,bj)*recip_deepFac2C(k)
458         &       *( af(i+1,j)-af(i,j)
459         &         -tracer(i,j,k,bi,bj)*(uTrans(i+1,j)-uTrans(i,j))
460         &        )
461             ENDDO
462            ENDDO
463    C-      keep advective flux (for diagnostics)
464            DO j=1-Oly,sNy+Oly
465             DO i=1-Olx,sNx+Olx
466              afx(i,j) = af(i,j)
467             ENDDO
468            ENDDO
469    
470  #ifdef ALLOW_OBCS  #ifdef ALLOW_OBCS
471  C--   Apply open boundary conditions  C-     Apply open boundary conditions
472        IF (useOBCS) THEN          IF ( useOBCS ) THEN
473         IF (tracerIdentity.EQ.GAD_TEMPERATURE) THEN           IF (tracerIdentity.EQ.GAD_TEMPERATURE) THEN
474          CALL OBCS_APPLY_TLOC( bi, bj, k, localTij, myThid )            CALL OBCS_APPLY_TLOC( bi, bj, k, localTij, myThid )
475         ELSEIF (tracerIdentity.EQ.GAD_SALINITY) THEN           ELSEIF (tracerIdentity.EQ.GAD_SALINITY) THEN
476          CALL OBCS_APPLY_SLOC( bi, bj, k, localTij, myThid )            CALL OBCS_APPLY_SLOC( bi, bj, k, localTij, myThid )
477         END IF  #ifdef ALLOW_PTRACERS
478        END IF           ELSEIF (tracerIdentity.GE.GAD_TR1) THEN
479              CALL OBCS_APPLY_PTRACER( bi, bj, k,
480         &         tracerIdentity-GAD_TR1+1, localTij, myThid )
481    #endif /* ALLOW_PTRACERS */
482             ENDIF
483            ENDIF
484  #endif /* ALLOW_OBCS */  #endif /* ALLOW_OBCS */
485    
486  C-    Advective flux in Y  C-     end if/else update overlap-Only
487        DO j=1-Oly,sNy+Oly         ENDIF
488         DO i=1-Olx,sNx+Olx  
489          af(i,j) = 0.  C--   End of X direction
        ENDDO  
       ENDDO  
       IF (advectionScheme.EQ.ENUM_FLUX_LIMIT) THEN  
        CALL GAD_FLUXLIMIT_ADV_Y(  
      &       bi,bj,k,deltaTtracer,vTrans,vVel,localTij,af,myThid)  
       ELSEIF (advectionScheme.EQ.ENUM_DST3 ) THEN  
        CALL GAD_DST3_ADV_Y(  
      &       bi,bj,k,deltaTtracer,vTrans,vVel,localTij,af,myThid)  
       ELSEIF (advectionScheme.EQ.ENUM_DST3_FLUX_LIMIT ) THEN  
        CALL GAD_DST3FL_ADV_Y(  
      &       bi,bj,k,deltaTtracer,vTrans,vVel,localTij,af,myThid)  
       ELSE  
        STOP 'GAD_ADVECTION: adv. scheme incompatibale with mutli-dim'  
490        ENDIF        ENDIF
       DO j=1-Oly,sNy+Oly-1  
        DO i=1-Olx,sNx+Olx  
         localTij(i,j)=localTij(i,j)-deltaTtracer*  
      &    _recip_hFacC(i,j,k,bi,bj)*recip_drF(k)  
      &    *recip_rA(i,j,bi,bj)  
      &    *( af(i,j+1)-af(i,j)  
      &      -tracer(i,j,k,bi,bj)*(vTrans(i,j+1)-vTrans(i,j))  
      &     )  
        ENDDO  
       ENDDO  
 #ifdef ALLOW_OBCS  
 C--   Apply open boundary conditions  
       IF (useOBCS) THEN  
        IF (tracerIdentity.EQ.GAD_TEMPERATURE) THEN  
         CALL OBCS_APPLY_TLOC( bi, bj, k, localTij, myThid )  
        ELSEIF (tracerIdentity.EQ.GAD_SALINITY) THEN  
         CALL OBCS_APPLY_SLOC( bi, bj, k, localTij, myThid )  
        END IF  
       END IF  
 #endif /* ALLOW_OBCS */  
       DO j=1-Oly,sNy+Oly-1  
        DO i=1-Olx,sNx+Olx  
         localTijk(i,j,k)=localTij(i,j)  
        ENDDO  
       ENDDO  
491    
492    C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
493    C--   Y direction
494    cph-test
495    C-     Advective flux in Y
496            DO j=1-Oly,sNy+Oly
497             DO i=1-Olx,sNx+Olx
498              af(i,j) = 0.
499             ENDDO
500            ENDDO
501    C
502    #ifdef ALLOW_AUTODIFF_TAMC
503    # ifndef DISABLE_MULTIDIM_ADVECTION
504    CADJ STORE localTij(:,:)  =
505    CADJ &     comlev1_bibj_k_gad_pass, key=passkey, byte=isbyte
506    CADJ STORE af(:,:)  =
507    CADJ &     comlev1_bibj_k_gad_pass, key=passkey, byte=isbyte
508    # endif
509    #endif /* ALLOW_AUTODIFF_TAMC */
510    C
511          IF (calc_fluxes_Y) THEN
512    
513    C-     Do not compute fluxes if
514    C       a) needed in overlap only
515    C   and b) the overlap of myTile are not cube-face edges
516           IF ( .NOT.overlapOnly .OR. E_edge .OR. W_edge ) THEN
517    
518    cph-exch2#ifndef ALLOW_AUTODIFF_TAMC
519    C-     Internal exchange for calculations in Y
520    #ifdef MULTIDIM_OLD_VERSION
521            IF ( useCubedSphereExchange ) THEN
522    #else
523            IF ( useCubedSphereExchange .AND.
524         &       ( overlapOnly .OR. ipass.EQ.1 ) ) THEN
525    #endif
526             CALL FILL_CS_CORNER_TR_RL(.FALSE., .FALSE.,
527         &                              localTij, bi,bj, myThid )
528            ENDIF
529    cph-exch2#endif
530    
531    C-     Advective flux in Y
532            DO j=1-Oly,sNy+Oly
533             DO i=1-Olx,sNx+Olx
534              af(i,j) = 0.
535             ENDDO
536            ENDDO
537    
538  C--   End of K loop for horizontal fluxes  #ifdef ALLOW_AUTODIFF_TAMC
539        ENDDO  #ifndef DISABLE_MULTIDIM_ADVECTION
540    CADJ STORE localTij(:,:)  =
541    CADJ &     comlev1_bibj_k_gad_pass, key=passkey, byte=isbyte
542    #endif
543    #endif /* ALLOW_AUTODIFF_TAMC */
544    
545            IF ( advectionScheme.EQ.ENUM_UPWIND_1RST
546         &     .OR. advectionScheme.EQ.ENUM_DST2 ) THEN
547              CALL GAD_DST2U1_ADV_Y( bi,bj,k, advectionScheme, .TRUE.,
548         I                           dTtracerLev(k),vTrans,vFld,localTij,
549         O                           af, myThid )
550            ELSEIF (advectionScheme.EQ.ENUM_FLUX_LIMIT) THEN
551              CALL GAD_FLUXLIMIT_ADV_Y( bi,bj,k, .TRUE., dTtracerLev(k),
552         I                              vTrans, vFld, maskLocS, localTij,
553         O                              af, myThid )
554            ELSEIF (advectionScheme.EQ.ENUM_DST3 ) THEN
555              CALL GAD_DST3_ADV_Y(      bi,bj,k, .TRUE., dTtracerLev(k),
556         I                              vTrans, vFld, maskLocS, localTij,
557         O                              af, myThid )
558            ELSEIF (advectionScheme.EQ.ENUM_DST3_FLUX_LIMIT ) THEN
559              CALL GAD_DST3FL_ADV_Y(    bi,bj,k, .TRUE., dTtracerLev(k),
560         I                              vTrans, vFld, maskLocS, localTij,
561         O                              af, myThid )
562    #ifndef ALLOW_AUTODIFF_TAMC
563            ELSEIF (advectionScheme.EQ.ENUM_OS7MP ) THEN
564              CALL GAD_OS7MP_ADV_Y(     bi,bj,k, .TRUE., dTtracerLev(k),
565         I                              vTrans, vFld, maskLocS, localTij,
566         O                              af, myThid )
567    #endif
568            ELSE
569             STOP 'GAD_ADVECTION: adv. scheme incompatibale with mutli-dim'
570            ENDIF
571    
572  C--   Start of k loop for vertical flux  C-     Advective flux in Y : done
573        DO k=Nr,1,-1         ENDIF
574    
575  C--   kup    Cycles through 1,2 to point to w-layer above  cph-exch2#ifndef ALLOW_AUTODIFF_TAMC
576  C--   kDown  Cycles through 2,1 to point to w-layer below  C-     Internal exchange for next calculations in X
577        kup  = 1+MOD(k+1,2)         IF ( overlapOnly .AND. ipass.EQ.1 ) THEN
578        kDown= 1+MOD(k,2)           CALL FILL_CS_CORNER_TR_RL( .TRUE., .FALSE.,
579         &                              localTij, bi,bj, myThid )
580           ENDIF
581    cph-exch2#endif
582    
583  C--   Get temporary terms used by tendency routines  C-     Update the local tracer field where needed:
584        CALL CALC_COMMON_FACTORS (  
585       I         bi,bj,iMin,iMax,jMin,jMax,k,  C      update in overlap-Only
586       O         xA,yA,uTrans,vTrans,rTrans,maskUp,         IF ( overlapOnly ) THEN
587       I         myThid)          jMinUpd = 1-Oly+1
588            jMaxUpd = sNy+Oly-1
589  C-    Advective flux in R  C- notes: these 2 lines below have no real effect (because recip_hFac=0
590        DO j=1-Oly,sNy+Oly  C         in corner region) but safer to keep them.
591         DO i=1-Olx,sNx+Olx          IF ( S_edge ) jMinUpd = 1
592          af(i,j) = 0.          IF ( N_edge ) jMaxUpd = sNy
593         ENDDO  
594        ENDDO          IF ( W_edge ) THEN
595             DO j=jMinUpd,jMaxUpd
596              DO i=1-Olx,0
597               localTij(i,j) = localTij(i,j)
598         &      -dTtracerLev(k)*recip_rhoFacC(k)
599         &       *_recip_hFacC(i,j,k,bi,bj)*recip_drF(k)
600         &       *recip_rA(i,j,bi,bj)*recip_deepFac2C(k)
601         &       *( af(i,j+1)-af(i,j)
602         &         -tracer(i,j,k,bi,bj)*(vTrans(i,j+1)-vTrans(i,j))
603         &        )
604              ENDDO
605             ENDDO
606            ENDIF
607            IF ( E_edge ) THEN
608             DO j=jMinUpd,jMaxUpd
609              DO i=sNx+1,sNx+Olx
610               localTij(i,j) = localTij(i,j)
611         &      -dTtracerLev(k)*recip_rhoFacC(k)
612         &       *_recip_hFacC(i,j,k,bi,bj)*recip_drF(k)
613         &       *recip_rA(i,j,bi,bj)*recip_deepFac2C(k)
614         &       *( af(i,j+1)-af(i,j)
615         &         -tracer(i,j,k,bi,bj)*(vTrans(i,j+1)-vTrans(i,j))
616         &        )
617              ENDDO
618             ENDDO
619            ENDIF
620    
 C     Note: wVel needs to be masked  
       IF (K.GE.2) THEN  
 C-    Compute vertical advective flux in the interior:  
        IF (advectionScheme.EQ.ENUM_FLUX_LIMIT) THEN  
         CALL GAD_FLUXLIMIT_ADV_R(  
      &       bi,bj,k,deltaTtracer,rTrans,wVel,localTijk,af,myThid)  
        ELSEIF (advectionScheme.EQ.ENUM_DST3 ) THEN  
 c       CALL GAD_DST3_ADV_R(  
 c    &       bi,bj,k,deltaTtracer,rTrans,wVel,localTijk,af,myThid)  
         STOP 'GAD_ADVECTION: adv. scheme not avail. yet'  
        ELSEIF (advectionScheme.EQ.ENUM_DST3_FLUX_LIMIT ) THEN  
 c       CALL GAD_DST3FL_ADV_R(  
 c    &       bi,bj,k,deltaTtracer,rTrans,wVel,localTijk,af,myThid)  
         STOP 'GAD_ADVECTION: adv. scheme not avail. yet'  
621         ELSE         ELSE
622          STOP 'GAD_ADVECTION: adv. scheme incompatibale with mutli-dim'  C      do not only update the overlap
623            iMinUpd = 1-Olx
624            iMaxUpd = sNx+Olx
625            IF ( interiorOnly .AND. W_edge ) iMinUpd = 1
626            IF ( interiorOnly .AND. E_edge ) iMaxUpd = sNx
627            DO j=1-Oly+1,sNy+Oly-1
628             DO i=iMinUpd,iMaxUpd
629               localTij(i,j) = localTij(i,j)
630         &      -dTtracerLev(k)*recip_rhoFacC(k)
631         &       *_recip_hFacC(i,j,k,bi,bj)*recip_drF(k)
632         &       *recip_rA(i,j,bi,bj)*recip_deepFac2C(k)
633         &       *( af(i,j+1)-af(i,j)
634         &         -tracer(i,j,k,bi,bj)*(vTrans(i,j+1)-vTrans(i,j))
635         &        )
636             ENDDO
637            ENDDO
638    C-      keep advective flux (for diagnostics)
639            DO j=1-Oly,sNy+Oly
640             DO i=1-Olx,sNx+Olx
641              afy(i,j) = af(i,j)
642             ENDDO
643            ENDDO
644    
645    #ifdef ALLOW_OBCS
646    C-     Apply open boundary conditions
647            IF (useOBCS) THEN
648             IF (tracerIdentity.EQ.GAD_TEMPERATURE) THEN
649              CALL OBCS_APPLY_TLOC( bi, bj, k, localTij, myThid )
650             ELSEIF (tracerIdentity.EQ.GAD_SALINITY) THEN
651              CALL OBCS_APPLY_SLOC( bi, bj, k, localTij, myThid )
652    #ifdef ALLOW_PTRACERS
653             ELSEIF (tracerIdentity.GE.GAD_TR1) THEN
654              CALL OBCS_APPLY_PTRACER( bi, bj, k,
655         &         tracerIdentity-GAD_TR1+1, localTij, myThid )
656    #endif /* ALLOW_PTRACERS */
657             ENDIF
658            ENDIF
659    #endif /* ALLOW_OBCS */
660    
661    C      end if/else update overlap-Only
662         ENDIF         ENDIF
663  C-    Surface "correction" term at k>1 :  
664         DO j=1-Oly,sNy+Oly  C--   End of Y direction
665          DO i=1-Olx,sNx+Olx        ENDIF
666           af(i,j) = af(i,j)  
667       &           + (maskC(i,j,k,bi,bj)-maskC(i,j,k-1,bi,bj))*  C--   End of ipass loop
668       &             rTrans(i,j)*localTijk(i,j,k)        ENDDO
669    
670          IF ( implicitAdvection ) THEN
671    C-    explicit advection is done ; store tendency in gTracer:
672            DO j=1-Oly,sNy+Oly
673             DO i=1-Olx,sNx+Olx
674              gTracer(i,j,k,bi,bj)=
675         &     (localTij(i,j)-tracer(i,j,k,bi,bj))/dTtracerLev(k)
676             ENDDO
677          ENDDO          ENDDO
        ENDDO  
678        ELSE        ELSE
679  C-    Surface "correction" term at k=1 :  C-    horizontal advection done; store intermediate result in 3D array:
680         DO j=1-Oly,sNy+Oly          DO j=1-Oly,sNy+Oly
681          DO i=1-Olx,sNx+Olx           DO i=1-Olx,sNx+Olx
682           af(i,j) = rTrans(i,j)*localTijk(i,j,k)            localTijk(i,j,k)=localTij(i,j)
683             ENDDO
684          ENDDO          ENDDO
        ENDDO  
685        ENDIF        ENDIF
 C-    add the advective flux to fVerT  
       DO j=1-Oly,sNy+Oly  
        DO i=1-Olx,sNx+Olx  
         fVerT(i,j,kUp) = af(i,j)  
        ENDDO  
       ENDDO  
686    
687  C--   Divergence of fluxes  #ifdef ALLOW_DIAGNOSTICS
688        kp1=min(Nr,k+1)          IF ( useDiagnostics ) THEN
689        kp1Msk=1.            diagName = 'ADVx'//diagSufx
690        if (k.EQ.Nr) kp1Msk=0.            CALL DIAGNOSTICS_FILL(afx,diagName, k,1, 2,bi,bj, myThid)
691        DO j=1-Oly,sNy+Oly            diagName = 'ADVy'//diagSufx
692         DO i=1-Olx,sNx+Olx            CALL DIAGNOSTICS_FILL(afy,diagName, k,1, 2,bi,bj, myThid)
693          localTij(i,j)=localTijk(i,j,k)-deltaTtracer*          ENDIF
694       &    _recip_hFacC(i,j,k,bi,bj)*recip_drF(k)  #endif
695       &    *recip_rA(i,j,bi,bj)  
696       &    *( fVerT(i,j,kUp)-fVerT(i,j,kDown)  #ifdef ALLOW_DEBUG
697       &      -tracer(i,j,k,bi,bj)*rA(i,j,bi,bj)*        IF ( debugLevel .GE. debLevB
698       &        (wVel(i,j,k,bi,bj)-kp1Msk*wVel(i,j,kp1,bi,bj))       &   .AND. tracerIdentity.EQ.GAD_TEMPERATURE
699       &     )*rkFac       &   .AND. k.LE.3 .AND. myIter.EQ.1+nIter0
700          gTracer(i,j,k,bi,bj)=       &   .AND. nPx.EQ.1 .AND. nPy.EQ.1
701       &   (localTij(i,j)-tracer(i,j,k,bi,bj))/deltaTtracer       &   .AND. useCubedSphereExchange ) THEN
702         ENDDO          CALL DEBUG_CS_CORNER_UV( ' afx,afy from GAD_ADVECTION',
703         &             afx,afy, k, standardMessageUnit,bi,bj,myThid )
704          ENDIF
705    #endif /* ALLOW_DEBUG */
706    
707    C--   End of K loop for horizontal fluxes
708        ENDDO        ENDDO
709    
710    C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
711    
712          IF ( .NOT.implicitAdvection ) THEN
713    C--   Start of k loop for vertical flux
714           DO k=Nr,1,-1
715    #ifdef ALLOW_AUTODIFF_TAMC
716             kkey = (igadkey-1)*Nr + k
717    #endif /* ALLOW_AUTODIFF_TAMC */
718    C--   kUp    Cycles through 1,2 to point to w-layer above
719    C--   kDown  Cycles through 2,1 to point to w-layer below
720            kUp  = 1+MOD(k+1,2)
721            kDown= 1+MOD(k,2)
722    c       kp1=min(Nr,k+1)
723            kp1Msk=1.
724            if (k.EQ.Nr) kp1Msk=0.
725    
726    C-- Compute Vertical transport
727    #ifdef ALLOW_AIM
728    C- a hack to prevent Water-Vapor vert.transport into the stratospheric level Nr
729            IF ( k.EQ.1 .OR.
730         &     (useAIM .AND. tracerIdentity.EQ.GAD_SALINITY .AND. k.EQ.Nr)
731         &              ) THEN
732    #else
733            IF ( k.EQ.1 ) THEN
734    #endif
735    
736    #ifdef ALLOW_AUTODIFF_TAMC
737    CADJ STORE rtrans(:,:)  =
738    CADJ &     comlev1_bibj_k_gad, key=kkey, byte=isbyte
739    CADJ STORE wfld(:,:)  =
740    CADJ &     comlev1_bibj_k_gad, key=kkey, byte=isbyte
741    #endif /* ALLOW_AUTODIFF_TAMC */
742    
743    C- Surface interface :
744             DO j=1-Oly,sNy+Oly
745              DO i=1-Olx,sNx+Olx
746               rTransKp1(i,j) = kp1Msk*rTrans(i,j)
747               wFld(i,j)   = 0.
748               rTrans(i,j) = 0.
749               fVerT(i,j,kUp) = 0.
750              ENDDO
751             ENDDO
752    
753            ELSE
754    
755    #ifdef ALLOW_AUTODIFF_TAMC
756    CADJ STORE rtrans(:,:)  =
757    CADJ &     comlev1_bibj_k_gad, key=kkey, byte=isbyte
758    CADJ STORE wfld(:,:)  =
759    CADJ &     comlev1_bibj_k_gad, key=kkey, byte=isbyte
760    #endif /* ALLOW_AUTODIFF_TAMC */
761    
762    C- Interior interface :
763             DO j=1-Oly,sNy+Oly
764              DO i=1-Olx,sNx+Olx
765               rTransKp1(i,j) = kp1Msk*rTrans(i,j)
766               wFld(i,j)   = wVel(i,j,k,bi,bj)
767               rTrans(i,j) = wVel(i,j,k,bi,bj)*rA(i,j,bi,bj)
768         &                 *deepFac2F(k)*rhoFacF(k)
769         &                 *maskC(i,j,k-1,bi,bj)
770               fVerT(i,j,kUp) = 0.
771              ENDDO
772             ENDDO
773    
774    #ifdef ALLOW_GMREDI
775    C--   Residual transp = Bolus transp + Eulerian transp
776             IF (useGMRedi)
777         &     CALL GMREDI_CALC_WFLOW(
778         U                 wFld, rTrans,
779         I                 k, bi, bj, myThid )
780    #endif /* ALLOW_GMREDI */
781    
782    #ifdef ALLOW_AUTODIFF_TAMC
783    CADJ STORE localTijk(:,:,k)  
784    CADJ &     = comlev1_bibj_k_gad, key=kkey, byte=isbyte
785    CADJ STORE rTrans(:,:)  
786    CADJ &     = comlev1_bibj_k_gad, key=kkey, byte=isbyte
787    #endif /* ALLOW_AUTODIFF_TAMC */
788    
789    C-    Compute vertical advective flux in the interior:
790             IF ( vertAdvecScheme.EQ.ENUM_UPWIND_1RST
791         &      .OR. vertAdvecScheme.EQ.ENUM_DST2 ) THEN
792               CALL GAD_DST2U1_ADV_R( bi,bj,k, advectionScheme,
793         I                            dTtracerLev(k),rTrans,wFld,localTijk,
794         O                            fVerT(1-Olx,1-Oly,kUp), myThid )
795             ELSEIF( vertAdvecScheme.EQ.ENUM_FLUX_LIMIT) THEN
796               CALL GAD_FLUXLIMIT_ADV_R( bi,bj,k, dTtracerLev(k),
797         I                               rTrans, wFld, localTijk,
798         O                               fVerT(1-Olx,1-Oly,kUp), myThid )
799             ELSEIF( vertAdvecScheme.EQ.ENUM_DST3 ) THEN
800               CALL GAD_DST3_ADV_R(      bi,bj,k, dTtracerLev(k),
801         I                               rTrans, wFld, localTijk,
802         O                               fVerT(1-Olx,1-Oly,kUp), myThid )
803             ELSEIF( vertAdvecScheme.EQ.ENUM_DST3_FLUX_LIMIT ) THEN
804               CALL GAD_DST3FL_ADV_R(    bi,bj,k, dTtracerLev(k),
805         I                               rTrans, wFld, localTijk,
806         O                               fVerT(1-Olx,1-Oly,kUp), myThid )
807    #ifndef ALLOW_AUTODIFF_TAMC
808             ELSEIF (vertAdvecScheme.EQ.ENUM_OS7MP ) THEN
809               CALL GAD_OS7MP_ADV_R(     bi,bj,k, dTtracerLev(k),
810         I                               rTrans, wFld, localTijk,
811         O                               fVerT(1-Olx,1-Oly,kUp), myThid )
812    #endif
813             ELSE
814              STOP 'GAD_ADVECTION: adv. scheme incompatibale with mutli-dim'
815             ENDIF
816    
817    C- end Surface/Interior if bloc
818            ENDIF
819    
820    #ifdef ALLOW_AUTODIFF_TAMC
821    CADJ STORE rTrans(:,:)  
822    CADJ &     = comlev1_bibj_k_gad, key=kkey, byte=isbyte
823    CADJ STORE rTranskp1(:,:)  
824    CADJ &     = comlev1_bibj_k_gad, key=kkey, byte=isbyte
825    #endif /* ALLOW_AUTODIFF_TAMC */
826    
827    C--   Divergence of vertical fluxes
828            DO j=1-Oly,sNy+Oly
829             DO i=1-Olx,sNx+Olx
830              localTij(i,j) = localTijk(i,j,k)
831         &      -dTtracerLev(k)*recip_rhoFacC(k)
832         &       *_recip_hFacC(i,j,k,bi,bj)*recip_drF(k)
833         &       *recip_rA(i,j,bi,bj)*recip_deepFac2C(k)
834         &       *( fVerT(i,j,kDown)-fVerT(i,j,kUp)
835         &         -tracer(i,j,k,bi,bj)*(rTransKp1(i,j)-rTrans(i,j))
836         &        )*rkSign
837              gTracer(i,j,k,bi,bj)=
838         &     (localTij(i,j)-tracer(i,j,k,bi,bj))/dTtracerLev(k)
839             ENDDO
840            ENDDO
841    
842    #ifdef ALLOW_DIAGNOSTICS
843            IF ( useDiagnostics ) THEN
844              diagName = 'ADVr'//diagSufx
845              CALL DIAGNOSTICS_FILL( fVerT(1-Olx,1-Oly,kUp),
846         &                           diagName, k,1, 2,bi,bj, myThid)
847            ENDIF
848    #endif
849    
850  C--   End of K loop for vertical flux  C--   End of K loop for vertical flux
851        ENDDO         ENDDO
852    C--   end of if not.implicitAdvection block
853          ENDIF
854    
855        RETURN        RETURN
856        END        END

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.50

  ViewVC Help
Powered by ViewVC 1.1.22