/[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.14 by heimbach, Tue Nov 12 20:42:24 2002 UTC revision 1.37 by jmc, Sat Oct 22 19:59:45 2005 UTC
# Line 1  Line 1 
1  C $Header$  C $Header$
2  C $Name$  C $Name$
3    
 CBOI  
 C !TITLE: pkg/generic\_advdiff  
 C !AUTHORS: adcroft@mit.edu  
 C !INTRODUCTION: Generic Advection Diffusion Package  
 C  
 C Package "generic\_advdiff" provides a common set of routines for calculating  
 C advective/diffusive fluxes for tracers (cell centered quantities on a C-grid).  
 C  
 C Many different advection schemes are available: the standard centered  
 C second order, centered fourth order and upwind biased third order schemes  
 C are known as linear methods and require some stable time-stepping method  
 C such as Adams-Bashforth. Alternatives such as flux-limited schemes are  
 C stable in the forward sense and are best combined with the multi-dimensional  
 C method provided in gad\_advection.  
 C  
 C There are two high-level routines:  
 C  \begin{itemize}  
 C  \item{GAD\_CALC\_RHS} calculates all fluxes at time level "n" and is used  
 C  for the standard linear schemes. This must be used in conjuction with  
 C  Adams-Bashforth time-stepping. Diffusive and parameterized fluxes are  
 C  always calculated here.  
 C  \item{GAD\_ADVECTION} calculates just the advective fluxes using the  
 C  non-linear schemes and can not be used in conjuction with Adams-Bashforth  
 C  time-stepping.  
 C  \end{itemize}  
 CEOI  
   
4  #include "GAD_OPTIONS.h"  #include "GAD_OPTIONS.h"
5    #undef MULTIDIM_OLD_VERSION
6    
7    C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
8  CBOP  CBOP
9  C !ROUTINE: GAD_ADVECTION  C !ROUTINE: GAD_ADVECTION
10    
11  C !INTERFACE: ==========================================================  C !INTERFACE: ==========================================================
12        SUBROUTINE GAD_ADVECTION(bi,bj,advectionScheme,tracerIdentity,        SUBROUTINE GAD_ADVECTION(
13       U                         Tracer,Gtracer,       I     implicitAdvection, advectionScheme, vertAdvecScheme,
14       I                         myTime,myIter,myThid)       I     tracerIdentity,
15         I     uVel, vVel, wVel, tracer,
16         O     gTracer,
17         I     bi,bj, myTime,myIter,myThid)
18    
19  C !DESCRIPTION:  C !DESCRIPTION:
20  C Calculates the tendancy of a tracer due to advection.  C Calculates the tendancy of a tracer due to advection.
# Line 62  C !USES: =============================== Line 40  C !USES: ===============================
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  #ifdef ALLOW_AUTODIFF_TAMC
46  # include "tamc.h"  # include "tamc.h"
47  # include "tamc_keys.h"  # include "tamc_keys.h"
48    # ifdef ALLOW_PTRACERS
49    #  include "PTRACERS_SIZE.h"
50    # endif
51  #endif  #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: ===================================================  C !INPUT PARAMETERS: ===================================================
58  C  bi,bj                :: tile indices  C  implicitAdvection :: implicit vertical advection (later on)
59  C  advectionScheme      :: advection scheme to use  C  advectionScheme   :: advection scheme to use (Horizontal plane)
60  C  tracerIdentity       :: identifier for the tracer (required only for OBCS)  C  vertAdvecScheme   :: advection scheme to use (vertical direction)
61  C  Tracer               :: tracer field  C  tracerIdentity    :: tracer identifier (required only for OBCS)
62  C  myTime               :: current time  C  uVel              :: velocity, zonal component
63  C  myIter               :: iteration number  C  vVel              :: velocity, meridional component
64  C  myThid               :: thread number  C  wVel              :: velocity, vertical component
65        INTEGER bi,bj  C  tracer            :: tracer field
66        INTEGER advectionScheme  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 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 !OUTPUT PARAMETERS: ==================================================  C !OUTPUT PARAMETERS: ==================================================
83  C  gTracer              :: tendancy array  C  gTracer           :: tendancy array
84        _RL gTracer(1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr,nSx,nSy)        _RL gTracer(1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr,nSx,nSy)
85    
86  C !LOCAL VARIABLES: ====================================================  C !LOCAL VARIABLES: ====================================================
87  C  maskUp               :: 2-D array for mask at W points  C  maskUp        :: 2-D array for mask at W points
88  C  iMin,iMax,jMin,jMax  :: loop range for called routines  C  maskLocW      :: 2-D array for mask at West points
89  C  i,j,k                :: loop indices  C  maskLocS      :: 2-D array for mask at South points
90  C  kup                  :: index into 2 1/2D array, toggles between 1 and 2  C  iMin,iMax,    :: loop range for called routines
91  C  kdown                :: index into 2 1/2D array, toggles between 2 and 1  C  jMin,jMax     :: loop range for called routines
92  C  kp1                  :: =k+1 for k<Nr, =Nr for k=Nr  C [iMin,iMax]Upd :: loop range to update tracer field
93  C  xA,yA                :: areas of X and Y face of tracer cells  C [jMin,jMax]Upd :: loop range to update tracer field
94  C  uTrans,vTrans,rTrans :: 2-D arrays of volume transports at U,V and W points  C  i,j,k         :: loop indices
95  C  rTransKp1            :: vertical volume transport at interface k+1  C  kup           :: index into 2 1/2D array, toggles between 1 and 2
96  C  af                   :: 2-D array for horizontal advective flux  C  kdown         :: index into 2 1/2D array, toggles between 2 and 1
97  C  fVerT                :: 2 1/2D arrays for vertical advective flux  C  kp1           :: =k+1 for k<Nr, =Nr for k=Nr
98  C  localTij             :: 2-D array used as temporary local copy of tracer fld  C  xA,yA         :: areas of X and Y face of tracer cells
99  C  localTijk            :: 3-D array used as temporary local copy of tracer fld  C  uTrans,vTrans :: 2-D arrays of volume transports at U,V points
100  C  kp1Msk               :: flag (0,1) to act as over-riding mask for W levels  C  rTrans        :: 2-D arrays of volume transports at W points
101  C  calc_fluxes_X        :: logical to indicate to calculate fluxes in X dir  C  rTransKp1     :: vertical volume transport at interface k+1
102  C  calc_fluxes_Y        :: logical to indicate to calculate fluxes in Y dir  C  af            :: 2-D array for horizontal advective flux
103  C  nipass               :: number of passes to make in multi-dimensional method  C  afx           :: 2-D array for horizontal advective flux, x direction
104  C  ipass                :: number of the current pass being made  C  afy           :: 2-D array for horizontal advective flux, y direction
105    C  fVerT         :: 2 1/2D arrays for vertical advective flux
106    C  localTij      :: 2-D array, temporary local copy of tracer fld
107    C  localTijk     :: 3-D array, temporary local copy of tracer fld
108    C  kp1Msk        :: flag (0,1) for over-riding mask for W levels
109    C  calc_fluxes_X :: logical to indicate to calculate fluxes in X dir
110    C  calc_fluxes_Y :: logical to indicate to calculate fluxes in Y dir
111    C  interiorOnly  :: only update the interior of myTile, but not the edges
112    C  overlapOnly   :: only update the edges of myTile, but not the interior
113    C  nipass        :: number of passes in multi-dimensional method
114    C  ipass         :: number of the current pass being made
115    C  myTile        :: variables used to determine which cube face
116    C  nCFace        :: owns a tile for cube grid runs using
117    C                :: multi-dim advection.
118    C [N,S,E,W]_edge :: true if N,S,E,W edge of myTile is an Edge of the cube
119        _RS maskUp  (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RS maskUp  (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
120          _RS maskLocW(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
121          _RS maskLocS(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
122        INTEGER iMin,iMax,jMin,jMax        INTEGER iMin,iMax,jMin,jMax
123          INTEGER iMinUpd,iMaxUpd,jMinUpd,jMaxUpd
124        INTEGER i,j,k,kup,kDown        INTEGER i,j,k,kup,kDown
125        _RS xA      (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RS xA      (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
126        _RS yA      (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RS yA      (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
# Line 119  C  ipass                :: number of the Line 129  C  ipass                :: number of the
129        _RL rTrans  (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL rTrans  (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
130        _RL rTransKp1(1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL rTransKp1(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
131        _RL af      (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL af      (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
132          _RL afx     (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
133          _RL afy     (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
134        _RL fVerT   (1-OLx:sNx+OLx,1-OLy:sNy+OLy,2)        _RL fVerT   (1-OLx:sNx+OLx,1-OLy:sNy+OLy,2)
135        _RL localTij(1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL localTij(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
136        _RL localTijk(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr)        _RL localTijk(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr)
137        _RL kp1Msk        _RL kp1Msk
138        LOGICAL calc_fluxes_X,calc_fluxes_Y        LOGICAL calc_fluxes_X, calc_fluxes_Y, withSigns
139          LOGICAL interiorOnly, overlapOnly
140        INTEGER nipass,ipass        INTEGER nipass,ipass
141          INTEGER myTile, nCFace
142          LOGICAL N_edge, S_edge, E_edge, W_edge
143    #ifdef ALLOW_DIAGNOSTICS
144          CHARACTER*8 diagName
145          CHARACTER*4 GAD_DIAG_SUFX, diagSufx
146          EXTERNAL    GAD_DIAG_SUFX
147    #endif
148  CEOP  CEOP
149    
150  #ifdef ALLOW_AUTODIFF_TAMC  #ifdef ALLOW_AUTODIFF_TAMC
# Line 142  CEOP Line 162  CEOP
162       &                      + act2*max0*max1       &                      + act2*max0*max1
163       &                      + act3*max0*max1*max2       &                      + act3*max0*max1*max2
164       &                      + act4*max0*max1*max2*max3       &                      + act4*max0*max1*max2*max3
165            if (tracerIdentity.GT.maxpass)            if (tracerIdentity.GT.maxpass) then
166       &         STOP 'maxpass seems smaller than tracerIdentity'               print *, 'ph-pass gad_advection ', maxpass, tracerIdentity
167                 STOP 'maxpass seems smaller than tracerIdentity'
168              endif
169  #endif /* ALLOW_AUTODIFF_TAMC */  #endif /* ALLOW_AUTODIFF_TAMC */
170    
171    #ifdef ALLOW_DIAGNOSTICS
172    C--   Set diagnostic suffix for the current tracer
173          IF ( useDiagnostics ) THEN
174            diagSufx = GAD_DIAG_SUFX( tracerIdentity, myThid )
175          ENDIF
176    #endif
177    
178  C--   Set up work arrays with valid (i.e. not NaN) values  C--   Set up work arrays with valid (i.e. not NaN) values
179  C     These inital values do not alter the numerical results. They  C     These inital values do not alter the numerical results. They
180  C     just ensure that all memory references are to valid floating  C     just ensure that all memory references are to valid floating
# Line 164  C     uninitialised but inert locations. Line 193  C     uninitialised but inert locations.
193         ENDDO         ENDDO
194        ENDDO        ENDDO
195    
196    C--   Set tile-specific parameters for horizontal fluxes
197          IF (useCubedSphereExchange) THEN
198           nipass=3
199    #ifdef ALLOW_AUTODIFF_TAMC
200           IF ( nipass.GT.maxcube ) STOP 'maxcube needs to be = 3'
201    #endif
202    #ifdef ALLOW_EXCH2
203           myTile = W2_myTileList(bi)
204           nCFace = exch2_myFace(myTile)
205           N_edge = exch2_isNedge(myTile).EQ.1
206           S_edge = exch2_isSedge(myTile).EQ.1
207           E_edge = exch2_isEedge(myTile).EQ.1
208           W_edge = exch2_isWedge(myTile).EQ.1
209    #else
210           nCFace = bi
211           N_edge = .TRUE.
212           S_edge = .TRUE.
213           E_edge = .TRUE.
214           W_edge = .TRUE.
215    #endif
216          ELSE
217           nipass=2
218           N_edge = .FALSE.
219           S_edge = .FALSE.
220           E_edge = .FALSE.
221           W_edge = .FALSE.
222          ENDIF
223    
224        iMin = 1-OLx        iMin = 1-OLx
225        iMax = sNx+OLx        iMax = sNx+OLx
226        jMin = 1-OLy        jMin = 1-OLy
# Line 185  C--   Get temporary terms used by tenden Line 242  C--   Get temporary terms used by tenden
242    
243  #ifdef ALLOW_GMREDI  #ifdef ALLOW_GMREDI
244  C--   Residual transp = Bolus transp + Eulerian transp  C--   Residual transp = Bolus transp + Eulerian transp
245         IF (useGMRedi)        IF (useGMRedi)
246       &   CALL GMREDI_CALC_UVFLOW(       &   CALL GMREDI_CALC_UVFLOW(
247       &            uTrans, vTrans, bi, bj, k, myThid)       &            uTrans, vTrans, bi, bj, k, myThid)
248  #endif /* ALLOW_GMREDI */  #endif /* ALLOW_GMREDI */
249    
250  C--   Make local copy of tracer array  C--   Make local copy of tracer array and mask West & South
251        DO j=1-OLy,sNy+OLy        DO j=1-OLy,sNy+OLy
252         DO i=1-OLx,sNx+OLx         DO i=1-OLx,sNx+OLx
253          localTij(i,j)=tracer(i,j,k,bi,bj)           localTij(i,j)=tracer(i,j,k,bi,bj)
254             maskLocW(i,j)=maskW(i,j,k,bi,bj)
255             maskLocS(i,j)=maskS(i,j,k,bi,bj)
256         ENDDO         ENDDO
257        ENDDO        ENDDO
258    
259    #ifndef ALLOW_AUTODIFF_TAMC
260        IF (useCubedSphereExchange) THEN        IF (useCubedSphereExchange) THEN
261         nipass=3          withSigns = .FALSE.
262  #ifdef ALLOW_AUTODIFF_TAMC          CALL FILL_CS_CORNER_UV_RS(
263         if ( nipass.GT.maxcube )       &            withSigns, maskLocW,maskLocS, bi,bj, myThid )
      &      STOP 'maxcube needs to be = 3'  
 #endif  
       ELSE  
        nipass=1  
264        ENDIF        ENDIF
265  cph       nipass=1  #endif
266    
267  C--   Multiple passes for different directions on different tiles  C--   Multiple passes for different directions on different tiles
268    C--   For cube need one pass for each of red, green and blue axes.
269        DO ipass=1,nipass        DO ipass=1,nipass
270  #ifdef ALLOW_AUTODIFF_TAMC  #ifdef ALLOW_AUTODIFF_TAMC
271           passkey = ipass + (k-1)      *maxcube           passkey = ipass + (k-1)      *maxcube
# Line 218  C--   Multiple passes for different dire Line 275  C--   Multiple passes for different dire
275           ENDIF           ENDIF
276  #endif /* ALLOW_AUTODIFF_TAMC */  #endif /* ALLOW_AUTODIFF_TAMC */
277    
278        IF (nipass.EQ.3) THEN        interiorOnly = .FALSE.
279         calc_fluxes_X=.FALSE.        overlapOnly  = .FALSE.
280         calc_fluxes_Y=.FALSE.        IF (useCubedSphereExchange) THEN
281         IF (ipass.EQ.1 .AND. (bi.EQ.1 .OR. bi.EQ.2) ) THEN  #ifdef MULTIDIM_OLD_VERSION
282          calc_fluxes_X=.TRUE.  C-    CubedSphere : pass 3 times, with full update of local tracer field
283         ELSEIF (ipass.EQ.1 .AND. (bi.EQ.4 .OR. bi.EQ.5) ) THEN         IF (ipass.EQ.1) THEN
284          calc_fluxes_Y=.TRUE.          calc_fluxes_X = nCFace.EQ.1 .OR. nCFace.EQ.2
285         ELSEIF (ipass.EQ.2 .AND. (bi.EQ.1 .OR. bi.EQ.6) ) THEN          calc_fluxes_Y = nCFace.EQ.4 .OR. nCFace.EQ.5
286          calc_fluxes_Y=.TRUE.         ELSEIF (ipass.EQ.2) THEN
287         ELSEIF (ipass.EQ.2 .AND. (bi.EQ.3 .OR. bi.EQ.4) ) THEN          calc_fluxes_X = nCFace.EQ.3 .OR. nCFace.EQ.4
288          calc_fluxes_X=.TRUE.          calc_fluxes_Y = nCFace.EQ.6 .OR. nCFace.EQ.1
289         ELSEIF (ipass.EQ.3 .AND. (bi.EQ.2 .OR. bi.EQ.3) ) THEN  #else /* MULTIDIM_OLD_VERSION */
290          calc_fluxes_Y=.TRUE.  C-    CubedSphere : pass 3 times, with partial update of local tracer field
291         ELSEIF (ipass.EQ.3 .AND. (bi.EQ.5 .OR. bi.EQ.6) ) THEN         IF (ipass.EQ.1) THEN
292          calc_fluxes_X=.TRUE.          overlapOnly  = MOD(nCFace,3).EQ.0
293            interiorOnly = MOD(nCFace,3).NE.0
294            calc_fluxes_X = nCFace.EQ.6 .OR. nCFace.EQ.1 .OR. nCFace.EQ.2
295            calc_fluxes_Y = nCFace.EQ.3 .OR. nCFace.EQ.4 .OR. nCFace.EQ.5
296           ELSEIF (ipass.EQ.2) THEN
297            overlapOnly  = MOD(nCFace,3).EQ.2
298            calc_fluxes_X = nCFace.EQ.2 .OR. nCFace.EQ.3 .OR. nCFace.EQ.4
299            calc_fluxes_Y = nCFace.EQ.5 .OR. nCFace.EQ.6 .OR. nCFace.EQ.1
300    #endif /* MULTIDIM_OLD_VERSION */
301           ELSE
302            calc_fluxes_X = nCFace.EQ.5 .OR. nCFace.EQ.6
303            calc_fluxes_Y = nCFace.EQ.2 .OR. nCFace.EQ.3
304         ENDIF         ENDIF
305        ELSE        ELSE
306         calc_fluxes_X=.TRUE.  C-    not CubedSphere
307         calc_fluxes_Y=.TRUE.          calc_fluxes_X = MOD(ipass,2).EQ.1
308            calc_fluxes_Y = .NOT.calc_fluxes_X
309        ENDIF        ENDIF
310    
311    C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
312  C--   X direction  C--   X direction
313        IF (calc_fluxes_X) THEN        IF (calc_fluxes_X) THEN
314    
315  C--   Internal exchange for calculations in X  C-     Do not compute fluxes if
316        IF (useCubedSphereExchange) THEN  C       a) needed in overlap only
317         DO j=1,Oly  C   and b) the overlap of myTile are not cube-face Edges
318          DO i=1,Olx         IF ( .NOT.overlapOnly .OR. N_edge .OR. S_edge ) THEN
319           localTij( 1-i , 1-j )=localTij( 1-j ,    i    )  
320           localTij( 1-i ,sNy+j)=localTij( 1-j , sNy+1-i )  #ifndef ALLOW_AUTODIFF_TAMC
321           localTij(sNx+i, 1-j )=localTij(sNx+j,    i    )  C-     Internal exchange for calculations in X
322           localTij(sNx+i,sNy+j)=localTij(sNx+j, sNy+1-i )  #ifdef MULTIDIM_OLD_VERSION
323          ENDDO          IF ( useCubedSphereExchange ) THEN
324         ENDDO  #else
325        ENDIF          IF ( useCubedSphereExchange .AND.
326         &       ( overlapOnly .OR. ipass.EQ.1 ) ) THEN
327    #endif
328             CALL FILL_CS_CORNER_TR_RL( .TRUE., localTij, bi,bj, myThid )
329            ENDIF
330    #endif
331    
332  C-    Advective flux in X  C-     Advective flux in X
333        DO j=1-Oly,sNy+Oly          DO j=1-Oly,sNy+Oly
334         DO i=1-Olx,sNx+Olx           DO i=1-Olx,sNx+Olx
335          af(i,j) = 0.            af(i,j) = 0.
336         ENDDO           ENDDO
337        ENDDO          ENDDO
338    
339  #ifdef ALLOW_AUTODIFF_TAMC  #ifdef ALLOW_AUTODIFF_TAMC
340  #ifndef DISABLE_MULTIDIM_ADVECTION  #ifndef DISABLE_MULTIDIM_ADVECTION
# Line 268  CADJ &     comlev1_bibj_k_gad_pass, key= Line 343  CADJ &     comlev1_bibj_k_gad_pass, key=
343  #endif  #endif
344  #endif /* ALLOW_AUTODIFF_TAMC */  #endif /* ALLOW_AUTODIFF_TAMC */
345    
346        IF (advectionScheme.EQ.ENUM_FLUX_LIMIT) THEN          IF ( advectionScheme.EQ.ENUM_UPWIND_1RST
347         CALL GAD_FLUXLIMIT_ADV_X(       &     .OR. advectionScheme.EQ.ENUM_DST2 ) THEN
348       &      bi,bj,k,deltaTtracer,uTrans,uVel,localTij,af,myThid)            CALL GAD_DST2U1_ADV_X( bi,bj,k, advectionScheme,
349        ELSEIF (advectionScheme.EQ.ENUM_DST3 ) THEN       I                           dTtracerLev(k),uTrans,uVel,localTij,
350         CALL GAD_DST3_ADV_X(       O                           af, myThid )
351       &       bi,bj,k,deltaTtracer,uTrans,uVel,localTij,af,myThid)          ELSEIF (advectionScheme.EQ.ENUM_FLUX_LIMIT) THEN
352        ELSEIF (advectionScheme.EQ.ENUM_DST3_FLUX_LIMIT ) THEN            CALL GAD_FLUXLIMIT_ADV_X( bi,bj,k, dTtracerLev(k),
353         CALL GAD_DST3FL_ADV_X(       I                              uTrans, uVel, maskLocW, localTij,
354       &       bi,bj,k,deltaTtracer,uTrans,uVel,localTij,af,myThid)       O                              af, myThid )
355        ELSE          ELSEIF (advectionScheme.EQ.ENUM_DST3 ) THEN
356         STOP 'GAD_ADVECTION: adv. scheme incompatibale with multi-dim'            CALL GAD_DST3_ADV_X(      bi,bj,k, dTtracerLev(k),
357        ENDIF       I                              uTrans, uVel, maskLocW, localTij,
358         O                              af, myThid )
359            ELSEIF (advectionScheme.EQ.ENUM_DST3_FLUX_LIMIT ) THEN
360              CALL GAD_DST3FL_ADV_X(    bi,bj,k, dTtracerLev(k),
361         I                              uTrans, uVel, maskLocW, localTij,
362         O                              af, myThid )
363            ELSE
364             STOP 'GAD_ADVECTION: adv. scheme incompatibale with multi-dim'
365            ENDIF
366    
367        DO j=1-Oly,sNy+Oly  C-     Advective flux in X : done
368         DO i=1-Olx,sNx+Olx-1         ENDIF
369          localTij(i,j)=localTij(i,j)-deltaTtracer*  
370       &    _recip_hFacC(i,j,k,bi,bj)*recip_drF(k)  #ifndef ALLOW_AUTODIFF_TAMC
371       &    *recip_rA(i,j,bi,bj)  C-     Internal exchange for next calculations in Y
372       &    *( af(i+1,j)-af(i,j)         IF ( overlapOnly .AND. ipass.EQ.1 ) THEN
373       &      -tracer(i,j,k,bi,bj)*(uTrans(i+1,j)-uTrans(i,j))           CALL FILL_CS_CORNER_TR_RL(.FALSE., localTij, bi,bj, myThid )
374       &     )         ENDIF
375         ENDDO  #endif
376        ENDDO  
377    C-     Update the local tracer field where needed:
378    
379    C      update in overlap-Only
380           IF ( overlapOnly ) THEN
381            iMinUpd = 1-Olx+1
382            iMaxUpd = sNx+Olx-1
383    C- notes: these 2 lines below have no real effect (because recip_hFac=0
384    C         in corner region) but safer to keep them.
385            IF ( W_edge ) iMinUpd = 1
386            IF ( E_edge ) iMaxUpd = sNx
387    
388            IF ( S_edge ) THEN
389             DO j=1-Oly,0
390              DO i=iMinUpd,iMaxUpd
391               localTij(i,j)=localTij(i,j)-dTtracerLev(k)*
392         &       _recip_hFacC(i,j,k,bi,bj)*recip_drF(k)
393         &       *recip_rA(i,j,bi,bj)
394         &       *( af(i+1,j)-af(i,j)
395         &         -tracer(i,j,k,bi,bj)*(uTrans(i+1,j)-uTrans(i,j))
396         &        )
397              ENDDO
398             ENDDO
399            ENDIF
400            IF ( N_edge ) THEN
401             DO j=sNy+1,sNy+Oly
402              DO i=iMinUpd,iMaxUpd
403               localTij(i,j)=localTij(i,j)-dTtracerLev(k)*
404         &       _recip_hFacC(i,j,k,bi,bj)*recip_drF(k)
405         &       *recip_rA(i,j,bi,bj)
406         &       *( af(i+1,j)-af(i,j)
407         &         -tracer(i,j,k,bi,bj)*(uTrans(i+1,j)-uTrans(i,j))
408         &        )
409              ENDDO
410             ENDDO
411            ENDIF
412    
413           ELSE
414    C      do not only update the overlap
415            jMinUpd = 1-Oly
416            jMaxUpd = sNy+Oly
417            IF ( interiorOnly .AND. S_edge ) jMinUpd = 1
418            IF ( interiorOnly .AND. N_edge ) jMaxUpd = sNy
419            DO j=jMinUpd,jMaxUpd
420             DO i=1-Olx+1,sNx+Olx-1
421               localTij(i,j)=localTij(i,j)-dTtracerLev(k)*
422         &       _recip_hFacC(i,j,k,bi,bj)*recip_drF(k)
423         &       *recip_rA(i,j,bi,bj)
424         &       *( af(i+1,j)-af(i,j)
425         &         -tracer(i,j,k,bi,bj)*(uTrans(i+1,j)-uTrans(i,j))
426         &        )
427             ENDDO
428            ENDDO
429    C-      keep advective flux (for diagnostics)
430            DO j=1-Oly,sNy+Oly
431             DO i=1-Olx,sNx+Olx
432              afx(i,j) = af(i,j)
433             ENDDO
434            ENDDO
435    
436  #ifdef ALLOW_OBCS  #ifdef ALLOW_OBCS
437  C--   Apply open boundary conditions  C-     Apply open boundary conditions
438        IF (useOBCS) THEN          IF ( useOBCS ) THEN
439         IF (tracerIdentity.EQ.GAD_TEMPERATURE) THEN           IF (tracerIdentity.EQ.GAD_TEMPERATURE) THEN
440          CALL OBCS_APPLY_TLOC( bi, bj, k, localTij, myThid )            CALL OBCS_APPLY_TLOC( bi, bj, k, localTij, myThid )
441         ELSEIF (tracerIdentity.EQ.GAD_SALINITY) THEN           ELSEIF (tracerIdentity.EQ.GAD_SALINITY) THEN
442          CALL OBCS_APPLY_SLOC( bi, bj, k, localTij, myThid )            CALL OBCS_APPLY_SLOC( bi, bj, k, localTij, myThid )
443         END IF  #ifdef ALLOW_PTRACERS
444        END IF           ELSEIF (tracerIdentity.GE.GAD_TR1) THEN
445              CALL OBCS_APPLY_PTRACER( bi, bj, k,
446         &         tracerIdentity-GAD_TR1+1, localTij, myThid )
447    #endif /* ALLOW_PTRACERS */
448             ENDIF
449            ENDIF
450  #endif /* ALLOW_OBCS */  #endif /* ALLOW_OBCS */
451    
452    C-     end if/else update overlap-Only
453           ENDIF
454            
455  C--   End of X direction  C--   End of X direction
456        ENDIF        ENDIF
457    
458    C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
459  C--   Y direction  C--   Y direction
460        IF (calc_fluxes_Y) THEN        IF (calc_fluxes_Y) THEN
461    
462  C--   Internal exchange for calculations in Y  C-     Do not compute fluxes if
463        IF (useCubedSphereExchange) THEN  C       a) needed in overlap only
464         DO j=1,Oly  C   and b) the overlap of myTile are not cube-face edges
465          DO i=1,Olx         IF ( .NOT.overlapOnly .OR. E_edge .OR. W_edge ) THEN
466           localTij( 1-i , 1-j )=localTij(   j   , 1-i )  
467           localTij( 1-i ,sNy+j)=localTij(   j   ,sNy+i)  #ifndef ALLOW_AUTODIFF_TAMC
468           localTij(sNx+i, 1-j )=localTij(sNx+1-j, 1-i )  C-     Internal exchange for calculations in Y
469           localTij(sNx+i,sNy+j)=localTij(sNx+1-j,sNy+i)  #ifdef MULTIDIM_OLD_VERSION
470          ENDDO          IF ( useCubedSphereExchange ) THEN
471         ENDDO  #else
472        ENDIF          IF ( useCubedSphereExchange .AND.
473         &       ( overlapOnly .OR. ipass.EQ.1 ) ) THEN
474    #endif
475             CALL FILL_CS_CORNER_TR_RL(.FALSE., localTij, bi,bj, myThid )
476            ENDIF
477    #endif
478    
479  C-    Advective flux in Y  C-     Advective flux in Y
480        DO j=1-Oly,sNy+Oly          DO j=1-Oly,sNy+Oly
481         DO i=1-Olx,sNx+Olx           DO i=1-Olx,sNx+Olx
482          af(i,j) = 0.            af(i,j) = 0.
483         ENDDO           ENDDO
484        ENDDO          ENDDO
485    
486  #ifdef ALLOW_AUTODIFF_TAMC  #ifdef ALLOW_AUTODIFF_TAMC
487  #ifndef DISABLE_MULTIDIM_ADVECTION  #ifndef DISABLE_MULTIDIM_ADVECTION
# Line 335  CADJ &     comlev1_bibj_k_gad_pass, key= Line 490  CADJ &     comlev1_bibj_k_gad_pass, key=
490  #endif  #endif
491  #endif /* ALLOW_AUTODIFF_TAMC */  #endif /* ALLOW_AUTODIFF_TAMC */
492    
493        IF (advectionScheme.EQ.ENUM_FLUX_LIMIT) THEN          IF ( advectionScheme.EQ.ENUM_UPWIND_1RST
494         CALL GAD_FLUXLIMIT_ADV_Y(       &     .OR. advectionScheme.EQ.ENUM_DST2 ) THEN
495       &       bi,bj,k,deltaTtracer,vTrans,vVel,localTij,af,myThid)            CALL GAD_DST2U1_ADV_Y( bi,bj,k, advectionScheme,
496        ELSEIF (advectionScheme.EQ.ENUM_DST3 ) THEN       I                           dTtracerLev(k),vTrans,vVel,localTij,
497         CALL GAD_DST3_ADV_Y(       O                           af, myThid )
498       &       bi,bj,k,deltaTtracer,vTrans,vVel,localTij,af,myThid)          ELSEIF (advectionScheme.EQ.ENUM_FLUX_LIMIT) THEN
499        ELSEIF (advectionScheme.EQ.ENUM_DST3_FLUX_LIMIT ) THEN            CALL GAD_FLUXLIMIT_ADV_Y( bi,bj,k, dTtracerLev(k),
500         CALL GAD_DST3FL_ADV_Y(       I                              vTrans, vVel, maskLocS, localTij,
501       &       bi,bj,k,deltaTtracer,vTrans,vVel,localTij,af,myThid)       O                              af, myThid )
502        ELSE          ELSEIF (advectionScheme.EQ.ENUM_DST3 ) THEN
503         STOP 'GAD_ADVECTION: adv. scheme incompatibale with mutli-dim'            CALL GAD_DST3_ADV_Y(      bi,bj,k, dTtracerLev(k),
504        ENDIF       I                              vTrans, vVel, maskLocS, localTij,
505         O                              af, myThid )
506            ELSEIF (advectionScheme.EQ.ENUM_DST3_FLUX_LIMIT ) THEN
507              CALL GAD_DST3FL_ADV_Y(    bi,bj,k, dTtracerLev(k),
508         I                              vTrans, vVel, maskLocS, localTij,
509         O                              af, myThid )
510            ELSE
511             STOP 'GAD_ADVECTION: adv. scheme incompatibale with mutli-dim'
512            ENDIF
513    
514        DO j=1-Oly,sNy+Oly-1  C-     Advective flux in Y : done
515         DO i=1-Olx,sNx+Olx         ENDIF
516          localTij(i,j)=localTij(i,j)-deltaTtracer*  
517       &    _recip_hFacC(i,j,k,bi,bj)*recip_drF(k)  #ifndef ALLOW_AUTODIFF_TAMC
518       &    *recip_rA(i,j,bi,bj)  C-     Internal exchange for next calculations in X
519       &    *( af(i,j+1)-af(i,j)         IF ( overlapOnly .AND. ipass.EQ.1 ) THEN
520       &      -tracer(i,j,k,bi,bj)*(vTrans(i,j+1)-vTrans(i,j))           CALL FILL_CS_CORNER_TR_RL( .TRUE., localTij, bi,bj, myThid )
521       &     )         ENDIF
522         ENDDO  #endif
523        ENDDO  
524    C-     Update the local tracer field where needed:
525    
526    C      update in overlap-Only
527           IF ( overlapOnly ) THEN
528            jMinUpd = 1-Oly+1
529            jMaxUpd = sNy+Oly-1
530    C- notes: these 2 lines below have no real effect (because recip_hFac=0
531    C         in corner region) but safer to keep them.
532            IF ( S_edge ) jMinUpd = 1
533            IF ( N_edge ) jMaxUpd = sNy
534    
535            IF ( W_edge ) THEN
536             DO j=jMinUpd,jMaxUpd
537              DO i=1-Olx,0
538               localTij(i,j)=localTij(i,j)-dTtracerLev(k)*
539         &       _recip_hFacC(i,j,k,bi,bj)*recip_drF(k)
540         &       *recip_rA(i,j,bi,bj)
541         &       *( af(i,j+1)-af(i,j)
542         &         -tracer(i,j,k,bi,bj)*(vTrans(i,j+1)-vTrans(i,j))
543         &        )
544              ENDDO
545             ENDDO
546            ENDIF
547            IF ( E_edge ) THEN
548             DO j=jMinUpd,jMaxUpd
549              DO i=sNx+1,sNx+Olx
550               localTij(i,j)=localTij(i,j)-dTtracerLev(k)*
551         &       _recip_hFacC(i,j,k,bi,bj)*recip_drF(k)
552         &       *recip_rA(i,j,bi,bj)
553         &       *( af(i,j+1)-af(i,j)
554         &         -tracer(i,j,k,bi,bj)*(vTrans(i,j+1)-vTrans(i,j))
555         &        )
556              ENDDO
557             ENDDO
558            ENDIF
559    
560           ELSE
561    C      do not only update the overlap
562            iMinUpd = 1-Olx
563            iMaxUpd = sNx+Olx
564            IF ( interiorOnly .AND. W_edge ) iMinUpd = 1
565            IF ( interiorOnly .AND. E_edge ) iMaxUpd = sNx
566            DO j=1-Oly+1,sNy+Oly-1
567             DO i=iMinUpd,iMaxUpd
568               localTij(i,j)=localTij(i,j)-dTtracerLev(k)*
569         &       _recip_hFacC(i,j,k,bi,bj)*recip_drF(k)
570         &       *recip_rA(i,j,bi,bj)
571         &       *( af(i,j+1)-af(i,j)
572         &         -tracer(i,j,k,bi,bj)*(vTrans(i,j+1)-vTrans(i,j))
573         &        )
574             ENDDO
575            ENDDO
576    C-      keep advective flux (for diagnostics)
577            DO j=1-Oly,sNy+Oly
578             DO i=1-Olx,sNx+Olx
579              afy(i,j) = af(i,j)
580             ENDDO
581            ENDDO
582    
583  #ifdef ALLOW_OBCS  #ifdef ALLOW_OBCS
584  C--   Apply open boundary conditions  C-     Apply open boundary conditions
585        IF (useOBCS) THEN          IF (useOBCS) THEN
586         IF (tracerIdentity.EQ.GAD_TEMPERATURE) THEN           IF (tracerIdentity.EQ.GAD_TEMPERATURE) THEN
587          CALL OBCS_APPLY_TLOC( bi, bj, k, localTij, myThid )            CALL OBCS_APPLY_TLOC( bi, bj, k, localTij, myThid )
588         ELSEIF (tracerIdentity.EQ.GAD_SALINITY) THEN           ELSEIF (tracerIdentity.EQ.GAD_SALINITY) THEN
589          CALL OBCS_APPLY_SLOC( bi, bj, k, localTij, myThid )            CALL OBCS_APPLY_SLOC( bi, bj, k, localTij, myThid )
590         END IF  #ifdef ALLOW_PTRACERS
591        END IF           ELSEIF (tracerIdentity.GE.GAD_TR1) THEN
592              CALL OBCS_APPLY_PTRACER( bi, bj, k,
593         &         tracerIdentity-GAD_TR1+1, localTij, myThid )
594    #endif /* ALLOW_PTRACERS */
595             ENDIF
596            ENDIF
597  #endif /* ALLOW_OBCS */  #endif /* ALLOW_OBCS */
598    
599    C      end if/else update overlap-Only
600           ENDIF
601    
602  C--   End of Y direction  C--   End of Y direction
603        ENDIF        ENDIF
604    
       DO j=1-Oly,sNy+Oly  
        DO i=1-Olx,sNx+Olx  
         localTijk(i,j,k)=localTij(i,j)  
        ENDDO  
       ENDDO  
   
605  C--   End of ipass loop  C--   End of ipass loop
606        ENDDO        ENDDO
607    
608          IF ( implicitAdvection ) THEN
609    C-    explicit advection is done ; store tendency in gTracer:
610            DO j=1-Oly,sNy+Oly
611             DO i=1-Olx,sNx+Olx
612              gTracer(i,j,k,bi,bj)=
613         &     (localTij(i,j)-tracer(i,j,k,bi,bj))/dTtracerLev(k)
614             ENDDO
615            ENDDO
616          ELSE
617    C-    horizontal advection done; store intermediate result in 3D array:
618           DO j=1-Oly,sNy+Oly
619            DO i=1-Olx,sNx+Olx
620             localTijk(i,j,k)=localTij(i,j)
621            ENDDO
622           ENDDO
623          ENDIF
624    
625    #ifdef ALLOW_DIAGNOSTICS
626            IF ( useDiagnostics ) THEN
627              diagName = 'ADVx'//diagSufx
628              CALL DIAGNOSTICS_FILL(afx,diagName, k,1, 2,bi,bj, myThid)
629              diagName = 'ADVy'//diagSufx
630              CALL DIAGNOSTICS_FILL(afy,diagName, k,1, 2,bi,bj, myThid)
631            ENDIF
632    #endif
633    
634    #ifdef ALLOW_DEBUG
635          IF ( debugLevel .GE. debLevB
636         &   .AND. tracerIdentity.EQ.GAD_TEMPERATURE
637         &   .AND. k.LE.3 .AND. myIter.EQ.1+nIter0
638         &   .AND. nPx.EQ.1 .AND. nPy.EQ.1
639         &   .AND. useCubedSphereExchange ) THEN
640            CALL DEBUG_CS_CORNER_UV( ' afx,afy from GAD_ADVECTION',
641         &             afx,afy, k, standardMessageUnit,bi,bj,myThid )
642          ENDIF
643    #endif /* ALLOW_DEBUG */
644    
645  C--   End of K loop for horizontal fluxes  C--   End of K loop for horizontal fluxes
646        ENDDO        ENDDO
647    
648    C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
649    
650          IF ( .NOT.implicitAdvection ) THEN
651  C--   Start of k loop for vertical flux  C--   Start of k loop for vertical flux
652        DO k=Nr,1,-1         DO k=Nr,1,-1
653  #ifdef ALLOW_AUTODIFF_TAMC  #ifdef ALLOW_AUTODIFF_TAMC
654           kkey = (ikey-1)*Nr + k           kkey = (igadkey-1)*Nr + k
655  #endif /* ALLOW_AUTODIFF_TAMC */  #endif /* ALLOW_AUTODIFF_TAMC */
   
656  C--   kup    Cycles through 1,2 to point to w-layer above  C--   kup    Cycles through 1,2 to point to w-layer above
657  C--   kDown  Cycles through 2,1 to point to w-layer below  C--   kDown  Cycles through 2,1 to point to w-layer below
658        kup  = 1+MOD(k+1,2)          kup  = 1+MOD(k+1,2)
659        kDown= 1+MOD(k,2)          kDown= 1+MOD(k,2)
660  c     kp1=min(Nr,k+1)  c       kp1=min(Nr,k+1)
661        kp1Msk=1.          kp1Msk=1.
662        if (k.EQ.Nr) kp1Msk=0.          if (k.EQ.Nr) kp1Msk=0.
   
 #ifdef ALLOW_AUTODIFF_TAMC  
 CADJ STORE localTijk(:,:,k)    
 CADJ &     = comlev1_bibj_k_gad, key=kkey, byte=isbyte  
 CADJ STORE rTrans(:,:)    
 CADJ &     = comlev1_bibj_k_gad, key=kkey, byte=isbyte  
 #endif /* ALLOW_AUTODIFF_TAMC */  
663    
664  C-- Compute Vertical transport  C-- Compute Vertical transport
665  C     Note: wVel needs to be masked  #ifdef ALLOW_AIM
666    C- a hack to prevent Water-Vapor vert.transport into the stratospheric level Nr
667            IF ( k.EQ.1 .OR.
668         &     (useAIM .AND. tracerIdentity.EQ.GAD_SALINITY .AND. k.EQ.Nr)
669         &              ) THEN
670    #else
671            IF ( k.EQ.1 ) THEN
672    #endif
673    
       IF (k.EQ.1) THEN  
674  C- Surface interface :  C- Surface interface :
675             DO j=1-Oly,sNy+Oly
676              DO i=1-Olx,sNx+Olx
677               rTransKp1(i,j) = kp1Msk*rTrans(i,j)
678               rTrans(i,j) = 0.
679               fVerT(i,j,kUp) = 0.
680              ENDDO
681             ENDDO
682    
683         DO j=1-Oly,sNy+Oly          ELSE
         DO i=1-Olx,sNx+Olx  
          rTransKp1(i,j) = rTrans(i,j)  
          rTrans(i,j) = 0.  
          fVerT(i,j,kUp) = 0.  
         ENDDO  
        ENDDO  
   
       ELSE  
684  C- Interior interface :  C- Interior interface :
685         DO j=1-Oly,sNy+Oly  
686          DO i=1-Olx,sNx+Olx           DO j=1-Oly,sNy+Oly
687           rTransKp1(i,j) = kp1Msk*rTrans(i,j)            DO i=1-Olx,sNx+Olx
688           rTrans(i,j) = wVel(i,j,k,bi,bj)*rA(i,j,bi,bj)             rTransKp1(i,j) = kp1Msk*rTrans(i,j)
689       &               *maskC(i,j,k-1,bi,bj)             rTrans(i,j) = wVel(i,j,k,bi,bj)*rA(i,j,bi,bj)
690           af(i,j) = 0.       &                 *maskC(i,j,k-1,bi,bj)
691          ENDDO             fVerT(i,j,kUp) = 0.
692         ENDDO            ENDDO
693             ENDDO
694    
695  #ifdef ALLOW_GMREDI  #ifdef ALLOW_GMREDI
696  C--   Residual transp = Bolus transp + Eulerian transp  C--   Residual transp = Bolus transp + Eulerian transp
697         IF (useGMRedi)           IF (useGMRedi)
698       &   CALL GMREDI_CALC_WFLOW(       &   CALL GMREDI_CALC_WFLOW(
699       &                    rTrans, bi, bj, k, myThid)       &                    rTrans, bi, bj, k, myThid)
700  #endif /* ALLOW_GMREDI */  #endif /* ALLOW_GMREDI */
701    
702    #ifdef ALLOW_AUTODIFF_TAMC
703    CADJ STORE localTijk(:,:,k)  
704    CADJ &     = comlev1_bibj_k_gad, key=kkey, byte=isbyte
705    CADJ STORE rTrans(:,:)  
706    CADJ &     = comlev1_bibj_k_gad, key=kkey, byte=isbyte
707    #endif /* ALLOW_AUTODIFF_TAMC */
708    
709  C-    Compute vertical advective flux in the interior:  C-    Compute vertical advective flux in the interior:
710         IF (advectionScheme.EQ.ENUM_FLUX_LIMIT) THEN           IF ( advectionScheme.EQ.ENUM_UPWIND_1RST
711          CALL GAD_FLUXLIMIT_ADV_R(       &      .OR. advectionScheme.EQ.ENUM_DST2 ) THEN
712       &       bi,bj,k,deltaTtracer,rTrans,wVel,localTijk,af,myThid)             CALL GAD_DST2U1_ADV_R( bi,bj,k, advectionScheme,
713         ELSEIF (advectionScheme.EQ.ENUM_DST3 ) THEN       I                            dTtracerLev(k),rTrans,wVel,localTijk,
714          CALL GAD_DST3_ADV_R(       O                            fVerT(1-Olx,1-Oly,kUp), myThid )
715       &       bi,bj,k,deltaTtracer,rTrans,wVel,localTijk,af,myThid)           ELSEIF (advectionScheme.EQ.ENUM_FLUX_LIMIT) THEN
716         ELSEIF (advectionScheme.EQ.ENUM_DST3_FLUX_LIMIT ) THEN             CALL GAD_FLUXLIMIT_ADV_R( bi,bj,k, dTtracerLev(k),
717          CALL GAD_DST3FL_ADV_R(       I                               rTrans, wVel, localTijk,
718       &       bi,bj,k,deltaTtracer,rTrans,wVel,localTijk,af,myThid)       O                               fVerT(1-Olx,1-Oly,kUp), myThid )
719         ELSE           ELSEIF (vertAdvecScheme.EQ.ENUM_DST3 ) THEN
720          STOP 'GAD_ADVECTION: adv. scheme incompatibale with mutli-dim'             CALL GAD_DST3_ADV_R(      bi,bj,k, dTtracerLev(k),
721         ENDIF       I                               rTrans, wVel, localTijk,
722  C-    add the advective flux to fVerT       O                               fVerT(1-Olx,1-Oly,kUp), myThid )
723         DO j=1-Oly,sNy+Oly           ELSEIF (vertAdvecScheme.EQ.ENUM_DST3_FLUX_LIMIT ) THEN
724          DO i=1-Olx,sNx+Olx             CALL GAD_DST3FL_ADV_R(    bi,bj,k, dTtracerLev(k),
725           fVerT(i,j,kUp) = af(i,j)       I                               rTrans, wVel, localTijk,
726          ENDDO       O                               fVerT(1-Olx,1-Oly,kUp), myThid )
727         ENDDO           ELSE
728              STOP 'GAD_ADVECTION: adv. scheme incompatibale with mutli-dim'
729             ENDIF
730    
731  C- end Surface/Interior if bloc  C- end Surface/Interior if bloc
732        ENDIF          ENDIF
733    
734  C--   Divergence of fluxes  #ifdef ALLOW_AUTODIFF_TAMC
735        DO j=1-Oly,sNy+Oly  CADJ STORE rTrans(:,:)  
736         DO i=1-Olx,sNx+Olx  CADJ &     = comlev1_bibj_k_gad, key=kkey, byte=isbyte
737          localTij(i,j)=localTijk(i,j,k)-deltaTtracer*  CADJ STORE rTranskp1(:,:)  
738       &    _recip_hFacC(i,j,k,bi,bj)*recip_drF(k)  CADJ &     = comlev1_bibj_k_gad, key=kkey, byte=isbyte
739       &    *recip_rA(i,j,bi,bj)  #endif /* ALLOW_AUTODIFF_TAMC */
740       &    *( fVerT(i,j,kUp)-fVerT(i,j,kDown)  
741       &      -tracer(i,j,k,bi,bj)*(rTrans(i,j)-rTransKp1(i,j))  C--   Divergence of vertical fluxes
742       &     )*rkFac          DO j=1-Oly,sNy+Oly
743          gTracer(i,j,k,bi,bj)=           DO i=1-Olx,sNx+Olx
744       &   (localTij(i,j)-tracer(i,j,k,bi,bj))/deltaTtracer            localTij(i,j)=localTijk(i,j,k)-dTtracerLev(k)*
745         ENDDO       &     _recip_hFacC(i,j,k,bi,bj)*recip_drF(k)
746        ENDDO       &     *recip_rA(i,j,bi,bj)
747         &     *( fVerT(i,j,kDown)-fVerT(i,j,kUp)
748         &       -tracer(i,j,k,bi,bj)*(rTransKp1(i,j)-rTrans(i,j))
749         &      )*rkSign
750              gTracer(i,j,k,bi,bj)=
751         &     (localTij(i,j)-tracer(i,j,k,bi,bj))/dTtracerLev(k)
752             ENDDO
753            ENDDO
754    
755    #ifdef ALLOW_DIAGNOSTICS
756            IF ( useDiagnostics ) THEN
757              diagName = 'ADVr'//diagSufx
758              CALL DIAGNOSTICS_FILL( fVerT(1-Olx,1-Oly,kUp),
759         &                           diagName, k,1, 2,bi,bj, myThid)
760            ENDIF
761    #endif
762    
763  C--   End of K loop for vertical flux  C--   End of K loop for vertical flux
764        ENDDO         ENDDO
765    C--   end of if not.implicitAdvection block
766          ENDIF
767    
768        RETURN        RETURN
769        END        END

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.37

  ViewVC Help
Powered by ViewVC 1.1.22